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.

252182 lines
6.3MB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifdef __JUCE_JUCEHEADER__
  19. #error
  20. #endif
  21. /*** Start of inlined file: juce_TargetPlatform.h ***/
  22. #ifndef __JUCE_TARGETPLATFORM_JUCEHEADER__
  23. #define __JUCE_TARGETPLATFORM_JUCEHEADER__
  24. #if (defined (_WIN32) || defined (_WIN64))
  25. #define JUCE_WIN32 1
  26. #define JUCE_WINDOWS 1
  27. #elif defined (LINUX) || defined (__linux__)
  28. #define JUCE_LINUX 1
  29. #elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
  30. #include <CoreFoundation/CoreFoundation.h> // (needed to find out what platform we're using)
  31. #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
  32. #define JUCE_IPHONE 1
  33. #else
  34. #define JUCE_MAC 1
  35. #endif
  36. #else
  37. #error "Unknown platform!"
  38. #endif
  39. #if JUCE_WINDOWS
  40. #ifdef _MSC_VER
  41. #ifdef _WIN64
  42. #define JUCE_64BIT 1
  43. #else
  44. #define JUCE_32BIT 1
  45. #endif
  46. #endif
  47. #ifdef _DEBUG
  48. #define JUCE_DEBUG 1
  49. #endif
  50. #ifdef __MINGW32__
  51. #define JUCE_MINGW 1
  52. #endif
  53. #define JUCE_LITTLE_ENDIAN 1
  54. #define JUCE_INTEL 1
  55. #endif
  56. #if JUCE_MAC
  57. #ifndef NDEBUG
  58. #define JUCE_DEBUG 1
  59. #endif
  60. #ifdef __LITTLE_ENDIAN__
  61. #define JUCE_LITTLE_ENDIAN 1
  62. #else
  63. #define JUCE_BIG_ENDIAN 1
  64. #endif
  65. #if defined (__ppc__) || defined (__ppc64__)
  66. #define JUCE_PPC 1
  67. #undef MAC_OS_X_VERSION_MAX_ALLOWED
  68. #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_4
  69. #else
  70. #define JUCE_INTEL 1
  71. #endif
  72. #ifdef __LP64__
  73. #define JUCE_64BIT 1
  74. #else
  75. #define JUCE_32BIT 1
  76. #endif
  77. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
  78. #error "Building for OSX 10.3 is no longer supported!"
  79. #endif
  80. #ifndef MAC_OS_X_VERSION_10_5
  81. #error "To build with 10.4 compatibility, use a 10.5 or 10.6 SDK and set the deployment target to 10.4"
  82. #endif
  83. #endif
  84. #if JUCE_IPHONE
  85. #ifndef NDEBUG
  86. #define JUCE_DEBUG 1
  87. #endif
  88. #ifdef __LITTLE_ENDIAN__
  89. #define JUCE_LITTLE_ENDIAN 1
  90. #else
  91. #define JUCE_BIG_ENDIAN 1
  92. #endif
  93. #endif
  94. #if JUCE_LINUX
  95. #ifdef _DEBUG
  96. #define JUCE_DEBUG 1
  97. #endif
  98. // Allow override for big-endian Linux platforms
  99. #ifndef JUCE_BIG_ENDIAN
  100. #define JUCE_LITTLE_ENDIAN 1
  101. #endif
  102. #if defined (__LP64__) || defined (_LP64)
  103. #define JUCE_64BIT 1
  104. #else
  105. #define JUCE_32BIT 1
  106. #endif
  107. #define JUCE_INTEL 1
  108. #endif
  109. // Compiler type macros.
  110. #ifdef __GNUC__
  111. #define JUCE_GCC 1
  112. #elif defined (_MSC_VER)
  113. #define JUCE_MSVC 1
  114. #if _MSC_VER >= 1400
  115. #define JUCE_USE_INTRINSICS 1
  116. #endif
  117. #else
  118. #error unknown compiler
  119. #endif
  120. #endif // __JUCE_TARGETPLATFORM_JUCEHEADER__
  121. /*** End of inlined file: juce_TargetPlatform.h ***/
  122. // FORCE_AMALGAMATOR_INCLUDE
  123. /*** Start of inlined file: juce_Config.h ***/
  124. #ifndef __JUCE_CONFIG_JUCEHEADER__
  125. #define __JUCE_CONFIG_JUCEHEADER__
  126. #ifndef JUCE_NAMESPACE
  127. #define JUCE_NAMESPACE juce
  128. #endif
  129. #ifndef JUCE_FORCE_DEBUG
  130. //#define JUCE_FORCE_DEBUG 1
  131. #endif
  132. #ifndef JUCE_LOG_ASSERTIONS
  133. // #define JUCE_LOG_ASSERTIONS 1
  134. #endif
  135. #ifndef JUCE_ASIO
  136. #define JUCE_ASIO 1
  137. #endif
  138. #ifndef JUCE_WASAPI
  139. // #define JUCE_WASAPI 1
  140. #endif
  141. #ifndef JUCE_DIRECTSOUND
  142. #define JUCE_DIRECTSOUND 1
  143. #endif
  144. #ifndef JUCE_ALSA
  145. #define JUCE_ALSA 1
  146. #endif
  147. #ifndef JUCE_JACK
  148. #define JUCE_JACK 1
  149. #endif
  150. #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC))
  151. #define JUCE_QUICKTIME 1
  152. #endif
  153. #ifndef JUCE_OPENGL
  154. #define JUCE_OPENGL 1
  155. #endif
  156. #ifndef JUCE_USE_FLAC
  157. #define JUCE_USE_FLAC 1
  158. #endif
  159. #ifndef JUCE_USE_OGGVORBIS
  160. #define JUCE_USE_OGGVORBIS 1
  161. #endif
  162. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  163. #define JUCE_USE_CDBURNER 1
  164. #endif
  165. #ifndef JUCE_USE_CDREADER
  166. #define JUCE_USE_CDREADER 1
  167. #endif
  168. #if JUCE_QUICKTIME && ! defined (JUCE_USE_CAMERA)
  169. // #define JUCE_USE_CAMERA 1
  170. #endif
  171. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  172. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  173. #endif
  174. #ifndef JUCE_USE_XINERAMA
  175. #define JUCE_USE_XINERAMA 1
  176. #endif
  177. #ifndef JUCE_USE_XSHM
  178. #define JUCE_USE_XSHM 1
  179. #endif
  180. #ifndef JUCE_PLUGINHOST_VST
  181. // #define JUCE_PLUGINHOST_VST 1
  182. #endif
  183. #ifndef JUCE_PLUGINHOST_AU
  184. // #define JUCE_PLUGINHOST_AU 1
  185. #endif
  186. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  187. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  188. #endif
  189. #ifndef JUCE_WEB_BROWSER
  190. #define JUCE_WEB_BROWSER 1
  191. #endif
  192. #ifndef JUCE_SUPPORT_CARBON
  193. #define JUCE_SUPPORT_CARBON 1
  194. #endif
  195. #ifndef JUCE_INCLUDE_ZLIB_CODE
  196. #define JUCE_INCLUDE_ZLIB_CODE 1
  197. #endif
  198. #ifndef JUCE_INCLUDE_FLAC_CODE
  199. #define JUCE_INCLUDE_FLAC_CODE 1
  200. #endif
  201. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  202. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  205. #define JUCE_INCLUDE_PNGLIB_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  208. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  209. #endif
  210. #ifndef JUCE_CHECK_MEMORY_LEAKS
  211. #define JUCE_CHECK_MEMORY_LEAKS 1
  212. #endif
  213. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  214. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  215. #endif
  216. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  217. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  218. #undef JUCE_QUICKTIME
  219. #define JUCE_QUICKTIME 0
  220. #undef JUCE_OPENGL
  221. #define JUCE_OPENGL 0
  222. #undef JUCE_USE_CDBURNER
  223. #define JUCE_USE_CDBURNER 0
  224. #undef JUCE_USE_CDREADER
  225. #define JUCE_USE_CDREADER 0
  226. #undef JUCE_WEB_BROWSER
  227. #define JUCE_WEB_BROWSER 0
  228. #undef JUCE_PLUGINHOST_AU
  229. #define JUCE_PLUGINHOST_AU 0
  230. #undef JUCE_PLUGINHOST_VST
  231. #define JUCE_PLUGINHOST_VST 0
  232. #endif
  233. #endif
  234. /*** End of inlined file: juce_Config.h ***/
  235. // FORCE_AMALGAMATOR_INCLUDE
  236. #ifndef JUCE_BUILD_CORE
  237. #define JUCE_BUILD_CORE 1
  238. #endif
  239. #ifndef JUCE_BUILD_MISC
  240. #define JUCE_BUILD_MISC 1
  241. #endif
  242. #ifndef JUCE_BUILD_GUI
  243. #define JUCE_BUILD_GUI 1
  244. #endif
  245. #ifndef JUCE_BUILD_NATIVE
  246. #define JUCE_BUILD_NATIVE 1
  247. #endif
  248. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  249. #undef JUCE_BUILD_MISC
  250. #undef JUCE_BUILD_GUI
  251. #endif
  252. //==============================================================================
  253. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  254. #if JUCE_WINDOWS
  255. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  256. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  257. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  258. #ifndef STRICT
  259. #define STRICT 1
  260. #endif
  261. #undef WIN32_LEAN_AND_MEAN
  262. #define WIN32_LEAN_AND_MEAN 1
  263. #ifdef _MSC_VER
  264. #pragma warning (push)
  265. #pragma warning (disable : 4100 4201 4514 4312 4995)
  266. #endif
  267. #define _WIN32_WINNT 0x0500
  268. #define _UNICODE 1
  269. #define UNICODE 1
  270. #ifndef _WIN32_IE
  271. #define _WIN32_IE 0x0400
  272. #endif
  273. #include <windows.h>
  274. #include <windowsx.h>
  275. #include <commdlg.h>
  276. #include <shellapi.h>
  277. #include <mmsystem.h>
  278. #include <vfw.h>
  279. #include <tchar.h>
  280. #include <stddef.h>
  281. #include <ctime>
  282. #include <wininet.h>
  283. #include <nb30.h>
  284. #include <iphlpapi.h>
  285. #include <mapi.h>
  286. #include <float.h>
  287. #include <process.h>
  288. #include <Exdisp.h>
  289. #include <exdispid.h>
  290. #include <shlobj.h>
  291. #if ! JUCE_MINGW
  292. #include <crtdbg.h>
  293. #include <comutil.h>
  294. #endif
  295. #if JUCE_OPENGL
  296. #include <gl/gl.h>
  297. #endif
  298. #undef PACKED
  299. #if JUCE_ASIO
  300. #include "iasiodrv.h"
  301. #endif
  302. #if JUCE_USE_CDBURNER
  303. #include <imapi.h>
  304. #include <imapierror.h>
  305. #endif
  306. #if JUCE_USE_CAMERA
  307. #include <dshow.h>
  308. #include <qedit.h>
  309. #include <dshowasf.h>
  310. #endif
  311. #if JUCE_WASAPI
  312. #include <MMReg.h>
  313. #include <mmdeviceapi.h>
  314. #include <Audioclient.h>
  315. #include <Avrt.h>
  316. #include <functiondiscoverykeys.h>
  317. #endif
  318. #if JUCE_QUICKTIME
  319. #include <Movies.h>
  320. #include <QTML.h>
  321. #include <QuickTimeComponents.h>
  322. #include <MediaHandlers.h>
  323. #include <ImageCodec.h>
  324. #import <QTOLibrary.dll>
  325. #import <QTOControl.dll>
  326. #endif
  327. #ifdef _MSC_VER
  328. #pragma warning (pop)
  329. #endif
  330. template <class T>
  331. class ComSmartPtr
  332. {
  333. public:
  334. ComSmartPtr() throw() : p (0) {}
  335. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  336. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  337. ~ComSmartPtr() { if (p != 0) p->Release(); }
  338. operator T*() const throw() { return p; }
  339. T& operator*() const throw() { return *p; }
  340. T** operator&() throw() { return &p; }
  341. T* operator->() const throw() { return p; }
  342. T* operator= (T* const newP)
  343. {
  344. if (newP != 0)
  345. newP->AddRef();
  346. if (p != 0)
  347. p->Release();
  348. p = newP;
  349. return newP;
  350. }
  351. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  352. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  353. {
  354. #ifndef __MINGW32__
  355. operator= (0);
  356. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  357. #else
  358. return S_FALSE;
  359. #endif
  360. }
  361. T* p;
  362. };
  363. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  364. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  365. #elif JUCE_LINUX
  366. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  367. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  368. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  369. #include <sched.h>
  370. #include <pthread.h>
  371. #include <sys/time.h>
  372. #include <errno.h>
  373. #include <sys/stat.h>
  374. #include <sys/dir.h>
  375. #include <sys/ptrace.h>
  376. #include <sys/vfs.h>
  377. #include <sys/wait.h>
  378. #include <fnmatch.h>
  379. #include <utime.h>
  380. #include <pwd.h>
  381. #include <fcntl.h>
  382. #include <dlfcn.h>
  383. #include <netdb.h>
  384. #include <arpa/inet.h>
  385. #include <netinet/in.h>
  386. #include <sys/types.h>
  387. #include <sys/ioctl.h>
  388. #include <sys/socket.h>
  389. #include <linux/if.h>
  390. #include <sys/sysinfo.h>
  391. #include <sys/file.h>
  392. #include <signal.h>
  393. #include <ft2build.h>
  394. #include FT_FREETYPE_H
  395. #include <X11/Xlib.h>
  396. #include <X11/Xatom.h>
  397. #include <X11/Xresource.h>
  398. #include <X11/Xutil.h>
  399. #include <X11/Xmd.h>
  400. #include <X11/keysym.h>
  401. #include <X11/cursorfont.h>
  402. #if JUCE_USE_XINERAMA
  403. #include <X11/extensions/Xinerama.h>
  404. #endif
  405. #if JUCE_USE_XSHM
  406. #include <X11/extensions/XShm.h>
  407. #include <sys/shm.h>
  408. #include <sys/ipc.h>
  409. #endif
  410. #if JUCE_OPENGL
  411. #include <GL/glx.h>
  412. #endif
  413. #undef KeyPress
  414. #if JUCE_ALSA
  415. #include <alsa/asoundlib.h>
  416. #endif
  417. #if JUCE_JACK
  418. #include <jack/jack.h>
  419. //#include <jack/transport.h>
  420. #endif
  421. #undef SIZEOF
  422. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  423. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  424. #elif JUCE_MAC || JUCE_IPHONE
  425. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  426. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  427. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  428. #define USE_COREGRAPHICS_RENDERING 1
  429. #if JUCE_IPHONE
  430. #import <Foundation/Foundation.h>
  431. #import <UIKit/UIKit.h>
  432. #import <AudioToolbox/AudioToolbox.h>
  433. #import <AVFoundation/AVFoundation.h>
  434. #import <CoreData/CoreData.h>
  435. #import <MobileCoreServices/MobileCoreServices.h>
  436. #include <sys/fcntl.h>
  437. #else
  438. #import <Cocoa/Cocoa.h>
  439. #import <CoreAudio/HostTime.h>
  440. #import <CoreAudio/AudioHardware.h>
  441. #import <CoreMIDI/MIDIServices.h>
  442. #import <QTKit/QTKit.h>
  443. #import <WebKit/WebKit.h>
  444. #import <DiscRecording/DiscRecording.h>
  445. #import <IOKit/IOKitLib.h>
  446. #import <IOKit/IOCFPlugIn.h>
  447. #import <IOKit/hid/IOHIDLib.h>
  448. #import <IOKit/hid/IOHIDKeys.h>
  449. #import <IOKit/pwr_mgt/IOPMLib.h>
  450. #include <Carbon/Carbon.h>
  451. #include <sys/dir.h>
  452. #include <sys/socket.h>
  453. #endif
  454. #include <sys/sysctl.h>
  455. #include <sys/stat.h>
  456. #include <sys/param.h>
  457. #include <sys/mount.h>
  458. #include <fnmatch.h>
  459. #include <utime.h>
  460. #include <dlfcn.h>
  461. #include <ifaddrs.h>
  462. #include <net/if_dl.h>
  463. #include <mach/mach_time.h>
  464. #if MACOS_10_4_OR_EARLIER
  465. #include <GLUT/glut.h>
  466. #endif
  467. #if ! CGFLOAT_DEFINED
  468. #define CGFloat float
  469. #endif
  470. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  471. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  472. #else
  473. #error "Unknown platform!"
  474. #endif
  475. #endif
  476. //==============================================================================
  477. #define DONT_SET_USING_JUCE_NAMESPACE 1
  478. #undef max
  479. #undef min
  480. #define NO_DUMMY_DECL
  481. #if JUCE_BUILD_NATIVE
  482. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  483. #endif
  484. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  485. #pragma warning (disable: 4309 4305)
  486. #endif
  487. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  488. BEGIN_JUCE_NAMESPACE
  489. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  490. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  491. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  492. class CarbonViewWrapperComponent : public Component,
  493. public ComponentMovementWatcher,
  494. public Timer
  495. {
  496. public:
  497. CarbonViewWrapperComponent()
  498. : ComponentMovementWatcher (this),
  499. wrapperWindow (0),
  500. embeddedView (0),
  501. recursiveResize (false)
  502. {
  503. }
  504. virtual ~CarbonViewWrapperComponent()
  505. {
  506. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  507. }
  508. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  509. virtual void removeView (HIViewRef embeddedView) = 0;
  510. virtual void mouseDown (int x, int y) {}
  511. virtual void paint() {}
  512. virtual bool getEmbeddedViewSize (int& w, int& h)
  513. {
  514. if (embeddedView == 0)
  515. return false;
  516. HIRect bounds;
  517. HIViewGetBounds (embeddedView, &bounds);
  518. w = jmax (1, roundToInt (bounds.size.width));
  519. h = jmax (1, roundToInt (bounds.size.height));
  520. return true;
  521. }
  522. void createWindow()
  523. {
  524. if (wrapperWindow == 0)
  525. {
  526. Rect r;
  527. r.left = getScreenX();
  528. r.top = getScreenY();
  529. r.right = r.left + getWidth();
  530. r.bottom = r.top + getHeight();
  531. CreateNewWindow (kDocumentWindowClass,
  532. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  533. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  534. &r, &wrapperWindow);
  535. jassert (wrapperWindow != 0);
  536. if (wrapperWindow == 0)
  537. return;
  538. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  539. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  540. [ownerWindow addChildWindow: carbonWindow
  541. ordered: NSWindowAbove];
  542. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  543. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  544. { kEventClassWindow, kEventWindowHandleDeactivate } };
  545. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  546. InstallWindowEventHandler (wrapperWindow, upp,
  547. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  548. windowEventTypes, this, &eventHandlerRef);
  549. setOurSizeToEmbeddedViewSize();
  550. setEmbeddedWindowToOurSize();
  551. creationTime = Time::getCurrentTime();
  552. }
  553. }
  554. void deleteWindow()
  555. {
  556. removeView (embeddedView);
  557. embeddedView = 0;
  558. if (wrapperWindow != 0)
  559. {
  560. RemoveEventHandler (eventHandlerRef);
  561. DisposeWindow (wrapperWindow);
  562. wrapperWindow = 0;
  563. }
  564. }
  565. void setOurSizeToEmbeddedViewSize()
  566. {
  567. int w, h;
  568. if (getEmbeddedViewSize (w, h))
  569. {
  570. if (w != getWidth() || h != getHeight())
  571. {
  572. startTimer (50);
  573. setSize (w, h);
  574. if (getParentComponent() != 0)
  575. getParentComponent()->setSize (w, h);
  576. }
  577. else
  578. {
  579. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  580. }
  581. }
  582. else
  583. {
  584. stopTimer();
  585. }
  586. }
  587. void setEmbeddedWindowToOurSize()
  588. {
  589. if (! recursiveResize)
  590. {
  591. recursiveResize = true;
  592. if (embeddedView != 0)
  593. {
  594. HIRect r;
  595. r.origin.x = 0;
  596. r.origin.y = 0;
  597. r.size.width = (float) getWidth();
  598. r.size.height = (float) getHeight();
  599. HIViewSetFrame (embeddedView, &r);
  600. }
  601. if (wrapperWindow != 0)
  602. {
  603. Rect wr;
  604. wr.left = getScreenX();
  605. wr.top = getScreenY();
  606. wr.right = wr.left + getWidth();
  607. wr.bottom = wr.top + getHeight();
  608. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  609. ShowWindow (wrapperWindow);
  610. }
  611. recursiveResize = false;
  612. }
  613. }
  614. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  615. {
  616. setEmbeddedWindowToOurSize();
  617. }
  618. void componentPeerChanged()
  619. {
  620. deleteWindow();
  621. createWindow();
  622. }
  623. void componentVisibilityChanged (Component&)
  624. {
  625. if (isShowing())
  626. createWindow();
  627. else
  628. deleteWindow();
  629. setEmbeddedWindowToOurSize();
  630. }
  631. static void recursiveHIViewRepaint (HIViewRef view)
  632. {
  633. HIViewSetNeedsDisplay (view, true);
  634. HIViewRef child = HIViewGetFirstSubview (view);
  635. while (child != 0)
  636. {
  637. recursiveHIViewRepaint (child);
  638. child = HIViewGetNextView (child);
  639. }
  640. }
  641. void timerCallback()
  642. {
  643. setOurSizeToEmbeddedViewSize();
  644. // To avoid strange overpainting problems when the UI is first opened, we'll
  645. // repaint it a few times during the first second that it's on-screen..
  646. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  647. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  648. }
  649. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  650. EventRef event)
  651. {
  652. switch (GetEventKind (event))
  653. {
  654. case kEventWindowHandleDeactivate:
  655. ActivateWindow (wrapperWindow, TRUE);
  656. break;
  657. case kEventWindowGetClickActivation:
  658. {
  659. getTopLevelComponent()->toFront (false);
  660. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  661. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  662. sizeof (ClickActivationResult), &howToHandleClick);
  663. HIViewSetNeedsDisplay (embeddedView, true);
  664. }
  665. break;
  666. }
  667. return noErr;
  668. }
  669. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  670. EventRef event, void* userData)
  671. {
  672. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  673. }
  674. protected:
  675. WindowRef wrapperWindow;
  676. HIViewRef embeddedView;
  677. bool recursiveResize;
  678. Time creationTime;
  679. EventHandlerRef eventHandlerRef;
  680. };
  681. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  682. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  683. END_JUCE_NAMESPACE
  684. #endif
  685. #define JUCE_AMALGAMATED_TEMPLATE 1
  686. //==============================================================================
  687. #if JUCE_BUILD_CORE
  688. /*** Start of inlined file: juce_FileLogger.cpp ***/
  689. BEGIN_JUCE_NAMESPACE
  690. FileLogger::FileLogger (const File& logFile_,
  691. const String& welcomeMessage,
  692. const int maxInitialFileSizeBytes)
  693. : logFile (logFile_)
  694. {
  695. if (maxInitialFileSizeBytes >= 0)
  696. trimFileSize (maxInitialFileSizeBytes);
  697. if (! logFile_.exists())
  698. {
  699. // do this so that the parent directories get created..
  700. logFile_.create();
  701. }
  702. logStream = logFile_.createOutputStream (256);
  703. jassert (logStream != 0);
  704. String welcome;
  705. welcome << "\r\n**********************************************************\r\n"
  706. << welcomeMessage
  707. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  708. << "\r\n";
  709. logMessage (welcome);
  710. }
  711. FileLogger::~FileLogger()
  712. {
  713. }
  714. void FileLogger::logMessage (const String& message)
  715. {
  716. if (logStream != 0)
  717. {
  718. DBG (message);
  719. const ScopedLock sl (logLock);
  720. (*logStream) << message << T("\r\n");
  721. logStream->flush();
  722. }
  723. }
  724. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  725. {
  726. if (maxFileSizeBytes <= 0)
  727. {
  728. logFile.deleteFile();
  729. }
  730. else
  731. {
  732. const int64 fileSize = logFile.getSize();
  733. if (fileSize > maxFileSizeBytes)
  734. {
  735. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  736. jassert (in != 0);
  737. if (in != 0)
  738. {
  739. in->setPosition (fileSize - maxFileSizeBytes);
  740. String content;
  741. {
  742. MemoryBlock contentToSave;
  743. contentToSave.setSize (maxFileSizeBytes + 4);
  744. contentToSave.fillWith (0);
  745. in->read (contentToSave.getData(), maxFileSizeBytes);
  746. in = 0;
  747. content = contentToSave.toString();
  748. }
  749. int newStart = 0;
  750. while (newStart < fileSize
  751. && content[newStart] != '\n'
  752. && content[newStart] != '\r')
  753. ++newStart;
  754. logFile.deleteFile();
  755. logFile.appendText (content.substring (newStart), false, false);
  756. }
  757. }
  758. }
  759. }
  760. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  761. const String& logFileName,
  762. const String& welcomeMessage,
  763. const int maxInitialFileSizeBytes)
  764. {
  765. #if JUCE_MAC
  766. File logFile ("~/Library/Logs");
  767. logFile = logFile.getChildFile (logFileSubDirectoryName)
  768. .getChildFile (logFileName);
  769. #else
  770. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  771. if (logFile.isDirectory())
  772. {
  773. logFile = logFile.getChildFile (logFileSubDirectoryName)
  774. .getChildFile (logFileName);
  775. }
  776. #endif
  777. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  778. }
  779. END_JUCE_NAMESPACE
  780. /*** End of inlined file: juce_FileLogger.cpp ***/
  781. /*** Start of inlined file: juce_Logger.cpp ***/
  782. BEGIN_JUCE_NAMESPACE
  783. Logger::Logger()
  784. {
  785. }
  786. Logger::~Logger()
  787. {
  788. }
  789. static Logger* currentLogger = 0;
  790. void Logger::setCurrentLogger (Logger* const newLogger,
  791. const bool deleteOldLogger)
  792. {
  793. Logger* const oldLogger = currentLogger;
  794. currentLogger = newLogger;
  795. if (deleteOldLogger)
  796. delete oldLogger;
  797. }
  798. void Logger::writeToLog (const String& message)
  799. {
  800. if (currentLogger != 0)
  801. currentLogger->logMessage (message);
  802. else
  803. outputDebugString (message);
  804. }
  805. #if JUCE_LOG_ASSERTIONS
  806. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  807. {
  808. String m ("JUCE Assertion failure in ");
  809. m << filename << ", line " << lineNum;
  810. Logger::writeToLog (m);
  811. }
  812. #endif
  813. END_JUCE_NAMESPACE
  814. /*** End of inlined file: juce_Logger.cpp ***/
  815. /*** Start of inlined file: juce_Random.cpp ***/
  816. BEGIN_JUCE_NAMESPACE
  817. Random::Random (const int64 seedValue) throw()
  818. : seed (seedValue)
  819. {
  820. }
  821. Random::~Random() throw()
  822. {
  823. }
  824. void Random::setSeed (const int64 newSeed) throw()
  825. {
  826. seed = newSeed;
  827. }
  828. void Random::combineSeed (const int64 seedValue) throw()
  829. {
  830. seed ^= nextInt64() ^ seedValue;
  831. }
  832. void Random::setSeedRandomly()
  833. {
  834. combineSeed ((int64) (pointer_sized_int) this);
  835. combineSeed (Time::getMillisecondCounter());
  836. combineSeed (Time::getHighResolutionTicks());
  837. combineSeed (Time::getHighResolutionTicksPerSecond());
  838. combineSeed (Time::currentTimeMillis());
  839. }
  840. int Random::nextInt() throw()
  841. {
  842. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  843. return (int) (seed >> 16);
  844. }
  845. int Random::nextInt (const int maxValue) throw()
  846. {
  847. jassert (maxValue > 0);
  848. return (nextInt() & 0x7fffffff) % maxValue;
  849. }
  850. int64 Random::nextInt64() throw()
  851. {
  852. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  853. }
  854. bool Random::nextBool() throw()
  855. {
  856. return (nextInt() & 0x80000000) != 0;
  857. }
  858. float Random::nextFloat() throw()
  859. {
  860. return ((uint32) nextInt()) / (float) 0xffffffff;
  861. }
  862. double Random::nextDouble() throw()
  863. {
  864. return ((uint32) nextInt()) / (double) 0xffffffff;
  865. }
  866. const BitArray Random::nextLargeNumber (const BitArray& maximumValue) throw()
  867. {
  868. BitArray n;
  869. do
  870. {
  871. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  872. }
  873. while (n.compare (maximumValue) >= 0);
  874. return n;
  875. }
  876. void Random::fillBitsRandomly (BitArray& arrayToChange, int startBit, int numBits) throw()
  877. {
  878. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  879. while ((startBit & 31) != 0 && numBits > 0)
  880. {
  881. arrayToChange.setBit (startBit++, nextBool());
  882. --numBits;
  883. }
  884. while (numBits >= 32)
  885. {
  886. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  887. startBit += 32;
  888. numBits -= 32;
  889. }
  890. while (--numBits >= 0)
  891. arrayToChange.setBit (startBit + numBits, nextBool());
  892. }
  893. Random& Random::getSystemRandom() throw()
  894. {
  895. static Random sysRand (1);
  896. return sysRand;
  897. }
  898. END_JUCE_NAMESPACE
  899. /*** End of inlined file: juce_Random.cpp ***/
  900. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  901. BEGIN_JUCE_NAMESPACE
  902. RelativeTime::RelativeTime (const double seconds_) throw()
  903. : seconds (seconds_)
  904. {
  905. }
  906. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  907. : seconds (other.seconds)
  908. {
  909. }
  910. RelativeTime::~RelativeTime() throw()
  911. {
  912. }
  913. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  914. {
  915. return RelativeTime (milliseconds * 0.001);
  916. }
  917. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  918. {
  919. return RelativeTime (milliseconds * 0.001);
  920. }
  921. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  922. {
  923. return RelativeTime (numberOfMinutes * 60.0);
  924. }
  925. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  926. {
  927. return RelativeTime (numberOfHours * (60.0 * 60.0));
  928. }
  929. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  930. {
  931. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  932. }
  933. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  934. {
  935. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  936. }
  937. int64 RelativeTime::inMilliseconds() const throw()
  938. {
  939. return (int64)(seconds * 1000.0);
  940. }
  941. double RelativeTime::inMinutes() const throw()
  942. {
  943. return seconds / 60.0;
  944. }
  945. double RelativeTime::inHours() const throw()
  946. {
  947. return seconds / (60.0 * 60.0);
  948. }
  949. double RelativeTime::inDays() const throw()
  950. {
  951. return seconds / (60.0 * 60.0 * 24.0);
  952. }
  953. double RelativeTime::inWeeks() const throw()
  954. {
  955. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  956. }
  957. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  958. {
  959. if (seconds < 0.001 && seconds > -0.001)
  960. return returnValueForZeroTime;
  961. String result;
  962. if (seconds < 0)
  963. result = T("-");
  964. int fieldsShown = 0;
  965. int n = abs ((int) inWeeks());
  966. if (n > 0)
  967. {
  968. result << n << ((n == 1) ? TRANS(" week ")
  969. : TRANS(" weeks "));
  970. ++fieldsShown;
  971. }
  972. n = abs ((int) inDays()) % 7;
  973. if (n > 0)
  974. {
  975. result << n << ((n == 1) ? TRANS(" day ")
  976. : TRANS(" days "));
  977. ++fieldsShown;
  978. }
  979. if (fieldsShown < 2)
  980. {
  981. n = abs ((int) inHours()) % 24;
  982. if (n > 0)
  983. {
  984. result << n << ((n == 1) ? TRANS(" hr ")
  985. : TRANS(" hrs "));
  986. ++fieldsShown;
  987. }
  988. if (fieldsShown < 2)
  989. {
  990. n = abs ((int) inMinutes()) % 60;
  991. if (n > 0)
  992. {
  993. result << n << ((n == 1) ? TRANS(" min ")
  994. : TRANS(" mins "));
  995. ++fieldsShown;
  996. }
  997. if (fieldsShown < 2)
  998. {
  999. n = abs ((int) inSeconds()) % 60;
  1000. if (n > 0)
  1001. {
  1002. result << n << ((n == 1) ? TRANS(" sec ")
  1003. : TRANS(" secs "));
  1004. ++fieldsShown;
  1005. }
  1006. if (fieldsShown < 1)
  1007. {
  1008. n = abs ((int) inMilliseconds()) % 1000;
  1009. if (n > 0)
  1010. {
  1011. result << n << TRANS(" ms");
  1012. ++fieldsShown;
  1013. }
  1014. }
  1015. }
  1016. }
  1017. }
  1018. return result.trimEnd();
  1019. }
  1020. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1021. {
  1022. seconds = other.seconds;
  1023. return *this;
  1024. }
  1025. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1026. {
  1027. return seconds == other.seconds;
  1028. }
  1029. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1030. {
  1031. return seconds != other.seconds;
  1032. }
  1033. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1034. {
  1035. return seconds > other.seconds;
  1036. }
  1037. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1038. {
  1039. return seconds < other.seconds;
  1040. }
  1041. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1042. {
  1043. return seconds >= other.seconds;
  1044. }
  1045. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1046. {
  1047. return seconds <= other.seconds;
  1048. }
  1049. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1050. {
  1051. return RelativeTime (seconds + timeToAdd.seconds);
  1052. }
  1053. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1054. {
  1055. return RelativeTime (seconds - timeToSubtract.seconds);
  1056. }
  1057. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1058. {
  1059. return RelativeTime (seconds + secondsToAdd);
  1060. }
  1061. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1062. {
  1063. return RelativeTime (seconds - secondsToSubtract);
  1064. }
  1065. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1066. {
  1067. seconds += timeToAdd.seconds;
  1068. return *this;
  1069. }
  1070. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1071. {
  1072. seconds -= timeToSubtract.seconds;
  1073. return *this;
  1074. }
  1075. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1076. {
  1077. seconds += secondsToAdd;
  1078. return *this;
  1079. }
  1080. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1081. {
  1082. seconds -= secondsToSubtract;
  1083. return *this;
  1084. }
  1085. END_JUCE_NAMESPACE
  1086. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1087. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1088. BEGIN_JUCE_NAMESPACE
  1089. void juce_initialiseStrings();
  1090. const String SystemStats::getJUCEVersion() throw()
  1091. {
  1092. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1093. + "." + String (JUCE_MINOR_VERSION)
  1094. + "." + String (JUCE_BUILDNUMBER);
  1095. }
  1096. static bool juceInitialisedNonGUI = false;
  1097. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1098. {
  1099. if (! juceInitialisedNonGUI)
  1100. {
  1101. #if JUCE_MAC || JUCE_IPHONE
  1102. const ScopedAutoReleasePool pool;
  1103. #endif
  1104. #ifdef JUCE_DEBUG
  1105. {
  1106. // Some simple test code to keep an eye on things and make sure these functions
  1107. // work ok on all platforms. Let me know if any of these assertions fail!
  1108. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1109. char a1[7];
  1110. jassert (numElementsInArray(a1) == 7);
  1111. int a2[3];
  1112. jassert (numElementsInArray(a2) == 3);
  1113. int n = 1;
  1114. Atomic::increment (n);
  1115. jassert (Atomic::incrementAndReturn (n) == 3);
  1116. Atomic::decrement (n);
  1117. jassert (Atomic::decrementAndReturn (n) == 1);
  1118. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1119. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1120. // Some quick stream tests..
  1121. int randomInt = Random::getSystemRandom().nextInt();
  1122. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1123. double randomDouble = Random::getSystemRandom().nextDouble();
  1124. String randomString;
  1125. for (int i = 50; --i >= 0;)
  1126. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1127. MemoryOutputStream mo;
  1128. mo.writeInt (randomInt);
  1129. mo.writeIntBigEndian (randomInt);
  1130. mo.writeCompressedInt (randomInt);
  1131. mo.writeString (randomString);
  1132. mo.writeInt64 (randomInt64);
  1133. mo.writeInt64BigEndian (randomInt64);
  1134. mo.writeDouble (randomDouble);
  1135. mo.writeDoubleBigEndian (randomDouble);
  1136. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1137. jassert (mi.readInt() == randomInt);
  1138. jassert (mi.readIntBigEndian() == randomInt);
  1139. jassert (mi.readCompressedInt() == randomInt);
  1140. jassert (mi.readString() == randomString);
  1141. jassert (mi.readInt64() == randomInt64);
  1142. jassert (mi.readInt64BigEndian() == randomInt64);
  1143. jassert (mi.readDouble() == randomDouble);
  1144. jassert (mi.readDoubleBigEndian() == randomDouble);
  1145. }
  1146. #endif
  1147. // Now the real initialisation..
  1148. juceInitialisedNonGUI = true;
  1149. DBG (SystemStats::getJUCEVersion());
  1150. juce_initialiseStrings();
  1151. SystemStats::initialiseStats();
  1152. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1153. }
  1154. }
  1155. #if JUCE_WINDOWS
  1156. // This is imported from the sockets code..
  1157. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1158. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1159. #endif
  1160. #if JUCE_DEBUG
  1161. extern void juce_CheckForDanglingStreams();
  1162. #endif
  1163. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1164. {
  1165. if (juceInitialisedNonGUI)
  1166. {
  1167. #if JUCE_MAC || JUCE_IPHONE
  1168. const ScopedAutoReleasePool pool;
  1169. #endif
  1170. #if JUCE_WINDOWS
  1171. // need to shut down sockets if they were used..
  1172. if (juce_CloseWin32SocketLib != 0)
  1173. (*juce_CloseWin32SocketLib)();
  1174. #endif
  1175. LocalisedStrings::setCurrentMappings (0);
  1176. Thread::stopAllThreads (3000);
  1177. #if JUCE_DEBUG
  1178. juce_CheckForDanglingStreams();
  1179. #endif
  1180. juceInitialisedNonGUI = false;
  1181. }
  1182. }
  1183. #ifdef JUCE_DLL
  1184. void* juce_Malloc (const int size)
  1185. {
  1186. return malloc (size);
  1187. }
  1188. void* juce_Calloc (const int size)
  1189. {
  1190. return calloc (1, size);
  1191. }
  1192. void* juce_Realloc (void* const block, const int size)
  1193. {
  1194. return realloc (block, size);
  1195. }
  1196. void juce_Free (void* const block)
  1197. {
  1198. free (block);
  1199. }
  1200. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1201. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1202. {
  1203. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1204. }
  1205. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1206. {
  1207. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1208. }
  1209. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1210. {
  1211. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1212. }
  1213. void juce_DebugFree (void* const block)
  1214. {
  1215. _free_dbg (block, _NORMAL_BLOCK);
  1216. }
  1217. #endif
  1218. #endif
  1219. END_JUCE_NAMESPACE
  1220. /*** End of inlined file: juce_SystemStats.cpp ***/
  1221. /*** Start of inlined file: juce_Time.cpp ***/
  1222. #ifdef _MSC_VER
  1223. #pragma warning (disable: 4514)
  1224. #pragma warning (push)
  1225. #endif
  1226. #ifndef JUCE_WINDOWS
  1227. #include <sys/time.h>
  1228. #else
  1229. #include <ctime>
  1230. #endif
  1231. #include <sys/timeb.h>
  1232. BEGIN_JUCE_NAMESPACE
  1233. #ifdef _MSC_VER
  1234. #pragma warning (pop)
  1235. #ifdef _INC_TIME_INL
  1236. #define USE_NEW_SECURE_TIME_FNS
  1237. #endif
  1238. #endif
  1239. static void millisToLocal (const int64 millis, struct tm& result) throw()
  1240. {
  1241. const int64 seconds = millis / 1000;
  1242. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1243. {
  1244. // use extended maths for dates beyond 1970 to 2037..
  1245. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1246. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1247. const int days = (int) (jdm / literal64bit (86400));
  1248. const int a = 32044 + days;
  1249. const int b = (4 * a + 3) / 146097;
  1250. const int c = a - (b * 146097) / 4;
  1251. const int d = (4 * c + 3) / 1461;
  1252. const int e = c - (d * 1461) / 4;
  1253. const int m = (5 * e + 2) / 153;
  1254. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1255. result.tm_mon = m + 2 - 12 * (m / 10);
  1256. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1257. result.tm_wday = (days + 1) % 7;
  1258. result.tm_yday = -1;
  1259. int t = (int) (jdm % literal64bit (86400));
  1260. result.tm_hour = t / 3600;
  1261. t %= 3600;
  1262. result.tm_min = t / 60;
  1263. result.tm_sec = t % 60;
  1264. result.tm_isdst = -1;
  1265. }
  1266. else
  1267. {
  1268. time_t now = (time_t) (seconds);
  1269. #if JUCE_WINDOWS
  1270. #ifdef USE_NEW_SECURE_TIME_FNS
  1271. if (now >= 0 && now <= 0x793406fff)
  1272. localtime_s (&result, &now);
  1273. else
  1274. zeromem (&result, sizeof (result));
  1275. #else
  1276. result = *localtime (&now);
  1277. #endif
  1278. #else
  1279. // more thread-safe
  1280. localtime_r (&now, &result);
  1281. #endif
  1282. }
  1283. }
  1284. Time::Time() throw()
  1285. : millisSinceEpoch (0)
  1286. {
  1287. }
  1288. Time::Time (const Time& other) throw()
  1289. : millisSinceEpoch (other.millisSinceEpoch)
  1290. {
  1291. }
  1292. Time::Time (const int64 ms) throw()
  1293. : millisSinceEpoch (ms)
  1294. {
  1295. }
  1296. Time::Time (const int year,
  1297. const int month,
  1298. const int day,
  1299. const int hours,
  1300. const int minutes,
  1301. const int seconds,
  1302. const int milliseconds,
  1303. const bool useLocalTime) throw()
  1304. {
  1305. jassert (year > 100); // year must be a 4-digit version
  1306. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1307. {
  1308. // use extended maths for dates beyond 1970 to 2037..
  1309. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1310. : 0;
  1311. const int a = (13 - month) / 12;
  1312. const int y = year + 4800 - a;
  1313. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1314. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1315. - 32045;
  1316. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1317. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1318. + milliseconds;
  1319. }
  1320. else
  1321. {
  1322. struct tm t;
  1323. t.tm_year = year - 1900;
  1324. t.tm_mon = month;
  1325. t.tm_mday = day;
  1326. t.tm_hour = hours;
  1327. t.tm_min = minutes;
  1328. t.tm_sec = seconds;
  1329. t.tm_isdst = -1;
  1330. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1331. if (millisSinceEpoch < 0)
  1332. millisSinceEpoch = 0;
  1333. else
  1334. millisSinceEpoch += milliseconds;
  1335. }
  1336. }
  1337. Time::~Time() throw()
  1338. {
  1339. }
  1340. Time& Time::operator= (const Time& other) throw()
  1341. {
  1342. millisSinceEpoch = other.millisSinceEpoch;
  1343. return *this;
  1344. }
  1345. int64 Time::currentTimeMillis() throw()
  1346. {
  1347. static uint32 lastCounterResult = 0xffffffff;
  1348. static int64 correction = 0;
  1349. const uint32 now = getMillisecondCounter();
  1350. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1351. if (now < lastCounterResult)
  1352. {
  1353. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1354. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1355. {
  1356. // get the time once using normal library calls, and store the difference needed to
  1357. // turn the millisecond counter into a real time.
  1358. #if JUCE_WINDOWS
  1359. struct _timeb t;
  1360. #ifdef USE_NEW_SECURE_TIME_FNS
  1361. _ftime_s (&t);
  1362. #else
  1363. _ftime (&t);
  1364. #endif
  1365. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1366. #else
  1367. struct timeval tv;
  1368. struct timezone tz;
  1369. gettimeofday (&tv, &tz);
  1370. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1371. #endif
  1372. }
  1373. }
  1374. lastCounterResult = now;
  1375. return correction + now;
  1376. }
  1377. uint32 juce_millisecondsSinceStartup() throw();
  1378. static uint32 lastMSCounterValue = 0;
  1379. uint32 Time::getMillisecondCounter() throw()
  1380. {
  1381. const uint32 now = juce_millisecondsSinceStartup();
  1382. if (now < lastMSCounterValue)
  1383. {
  1384. // in multi-threaded apps this might be called concurrently, so
  1385. // make sure that our last counter value only increases and doesn't
  1386. // go backwards..
  1387. if (now < lastMSCounterValue - 1000)
  1388. lastMSCounterValue = now;
  1389. }
  1390. else
  1391. {
  1392. lastMSCounterValue = now;
  1393. }
  1394. return now;
  1395. }
  1396. uint32 Time::getApproximateMillisecondCounter() throw()
  1397. {
  1398. jassert (lastMSCounterValue != 0);
  1399. return lastMSCounterValue;
  1400. }
  1401. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1402. {
  1403. for (;;)
  1404. {
  1405. const uint32 now = getMillisecondCounter();
  1406. if (now >= targetTime)
  1407. break;
  1408. const int toWait = targetTime - now;
  1409. if (toWait > 2)
  1410. {
  1411. Thread::sleep (jmin (20, toWait >> 1));
  1412. }
  1413. else
  1414. {
  1415. // xxx should consider using mutex_pause on the mac as it apparently
  1416. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1417. for (int i = 10; --i >= 0;)
  1418. Thread::yield();
  1419. }
  1420. }
  1421. }
  1422. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1423. {
  1424. return ticks / (double) getHighResolutionTicksPerSecond();
  1425. }
  1426. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1427. {
  1428. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1429. }
  1430. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1431. {
  1432. return Time (currentTimeMillis());
  1433. }
  1434. const String Time::toString (const bool includeDate,
  1435. const bool includeTime,
  1436. const bool includeSeconds,
  1437. const bool use24HourClock) const throw()
  1438. {
  1439. String result;
  1440. if (includeDate)
  1441. {
  1442. result << getDayOfMonth() << ' '
  1443. << getMonthName (true) << ' '
  1444. << getYear();
  1445. if (includeTime)
  1446. result << ' ';
  1447. }
  1448. if (includeTime)
  1449. {
  1450. if (includeSeconds)
  1451. {
  1452. result += String::formatted (T("%d:%02d:%02d "),
  1453. (use24HourClock) ? getHours()
  1454. : getHoursInAmPmFormat(),
  1455. getMinutes(),
  1456. getSeconds());
  1457. }
  1458. else
  1459. {
  1460. result += String::formatted (T("%d.%02d"),
  1461. (use24HourClock) ? getHours()
  1462. : getHoursInAmPmFormat(),
  1463. getMinutes());
  1464. }
  1465. if (! use24HourClock)
  1466. result << (isAfternoon() ? "pm" : "am");
  1467. }
  1468. return result.trimEnd();
  1469. }
  1470. const String Time::formatted (const tchar* const format) const throw()
  1471. {
  1472. String buffer;
  1473. int bufferSize = 128;
  1474. buffer.preallocateStorage (bufferSize);
  1475. struct tm t;
  1476. millisToLocal (millisSinceEpoch, t);
  1477. while (CharacterFunctions::ftime ((tchar*) (const tchar*) buffer, bufferSize, format, &t) <= 0)
  1478. {
  1479. bufferSize += 128;
  1480. buffer.preallocateStorage (bufferSize);
  1481. }
  1482. return buffer;
  1483. }
  1484. int Time::getYear() const throw()
  1485. {
  1486. struct tm t;
  1487. millisToLocal (millisSinceEpoch, t);
  1488. return t.tm_year + 1900;
  1489. }
  1490. int Time::getMonth() const throw()
  1491. {
  1492. struct tm t;
  1493. millisToLocal (millisSinceEpoch, t);
  1494. return t.tm_mon;
  1495. }
  1496. int Time::getDayOfMonth() const throw()
  1497. {
  1498. struct tm t;
  1499. millisToLocal (millisSinceEpoch, t);
  1500. return t.tm_mday;
  1501. }
  1502. int Time::getDayOfWeek() const throw()
  1503. {
  1504. struct tm t;
  1505. millisToLocal (millisSinceEpoch, t);
  1506. return t.tm_wday;
  1507. }
  1508. int Time::getHours() const throw()
  1509. {
  1510. struct tm t;
  1511. millisToLocal (millisSinceEpoch, t);
  1512. return t.tm_hour;
  1513. }
  1514. int Time::getHoursInAmPmFormat() const throw()
  1515. {
  1516. const int hours = getHours();
  1517. if (hours == 0)
  1518. return 12;
  1519. else if (hours <= 12)
  1520. return hours;
  1521. else
  1522. return hours - 12;
  1523. }
  1524. bool Time::isAfternoon() const throw()
  1525. {
  1526. return getHours() >= 12;
  1527. }
  1528. static int extendedModulo (const int64 value, const int modulo) throw()
  1529. {
  1530. return (int) (value >= 0 ? (value % modulo)
  1531. : (value - ((value / modulo) + 1) * modulo));
  1532. }
  1533. int Time::getMinutes() const throw()
  1534. {
  1535. struct tm t;
  1536. millisToLocal (millisSinceEpoch, t);
  1537. return t.tm_min;
  1538. }
  1539. int Time::getSeconds() const throw()
  1540. {
  1541. return extendedModulo (millisSinceEpoch / 1000, 60);
  1542. }
  1543. int Time::getMilliseconds() const throw()
  1544. {
  1545. return extendedModulo (millisSinceEpoch, 1000);
  1546. }
  1547. bool Time::isDaylightSavingTime() const throw()
  1548. {
  1549. struct tm t;
  1550. millisToLocal (millisSinceEpoch, t);
  1551. return t.tm_isdst != 0;
  1552. }
  1553. const String Time::getTimeZone() const throw()
  1554. {
  1555. String zone[2];
  1556. #if JUCE_WINDOWS
  1557. _tzset();
  1558. #ifdef USE_NEW_SECURE_TIME_FNS
  1559. {
  1560. char name [128];
  1561. size_t length;
  1562. for (int i = 0; i < 2; ++i)
  1563. {
  1564. zeromem (name, sizeof (name));
  1565. _get_tzname (&length, name, 127, i);
  1566. zone[i] = name;
  1567. }
  1568. }
  1569. #else
  1570. const char** const zonePtr = (const char**) _tzname;
  1571. zone[0] = zonePtr[0];
  1572. zone[1] = zonePtr[1];
  1573. #endif
  1574. #else
  1575. tzset();
  1576. const char** const zonePtr = (const char**) tzname;
  1577. zone[0] = zonePtr[0];
  1578. zone[1] = zonePtr[1];
  1579. #endif
  1580. if (isDaylightSavingTime())
  1581. {
  1582. zone[0] = zone[1];
  1583. if (zone[0].length() > 3
  1584. && zone[0].containsIgnoreCase (T("daylight"))
  1585. && zone[0].contains (T("GMT")))
  1586. zone[0] = "BST";
  1587. }
  1588. return zone[0].substring (0, 3);
  1589. }
  1590. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1591. {
  1592. return getMonthName (getMonth(), threeLetterVersion);
  1593. }
  1594. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1595. {
  1596. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1597. }
  1598. const String Time::getMonthName (int monthNumber,
  1599. const bool threeLetterVersion) throw()
  1600. {
  1601. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1602. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1603. monthNumber %= 12;
  1604. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1605. : longMonthNames [monthNumber]);
  1606. }
  1607. const String Time::getWeekdayName (int day,
  1608. const bool threeLetterVersion) throw()
  1609. {
  1610. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1611. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1612. day %= 7;
  1613. return TRANS (threeLetterVersion ? shortDayNames [day]
  1614. : longDayNames [day]);
  1615. }
  1616. END_JUCE_NAMESPACE
  1617. /*** End of inlined file: juce_Time.cpp ***/
  1618. /*** Start of inlined file: juce_BitArray.cpp ***/
  1619. BEGIN_JUCE_NAMESPACE
  1620. BitArray::BitArray() throw()
  1621. : numValues (4),
  1622. highestBit (-1),
  1623. negative (false)
  1624. {
  1625. values.calloc (numValues + 1);
  1626. }
  1627. BitArray::BitArray (const int value) throw()
  1628. : numValues (4),
  1629. highestBit (31),
  1630. negative (value < 0)
  1631. {
  1632. values.calloc (numValues + 1);
  1633. values[0] = abs (value);
  1634. highestBit = getHighestBit();
  1635. }
  1636. BitArray::BitArray (int64 value) throw()
  1637. : numValues (4),
  1638. highestBit (63),
  1639. negative (value < 0)
  1640. {
  1641. values.calloc (numValues + 1);
  1642. if (value < 0)
  1643. value = -value;
  1644. values[0] = (unsigned int) value;
  1645. values[1] = (unsigned int) (value >> 32);
  1646. highestBit = getHighestBit();
  1647. }
  1648. BitArray::BitArray (const unsigned int value) throw()
  1649. : numValues (4),
  1650. highestBit (31),
  1651. negative (false)
  1652. {
  1653. values.calloc (numValues + 1);
  1654. values[0] = value;
  1655. highestBit = getHighestBit();
  1656. }
  1657. BitArray::BitArray (const BitArray& other) throw()
  1658. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1659. highestBit (other.getHighestBit()),
  1660. negative (other.negative)
  1661. {
  1662. values.malloc (numValues + 1);
  1663. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1664. }
  1665. BitArray::~BitArray() throw()
  1666. {
  1667. }
  1668. BitArray& BitArray::operator= (const BitArray& other) throw()
  1669. {
  1670. if (this != &other)
  1671. {
  1672. highestBit = other.getHighestBit();
  1673. numValues = jmax (4, (highestBit >> 5) + 1);
  1674. negative = other.negative;
  1675. values.malloc (numValues + 1);
  1676. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1677. }
  1678. return *this;
  1679. }
  1680. // result == 0 = the same
  1681. // result < 0 = this number is smaller
  1682. // result > 0 = this number is bigger
  1683. int BitArray::compare (const BitArray& other) const throw()
  1684. {
  1685. if (isNegative() == other.isNegative())
  1686. {
  1687. const int absComp = compareAbsolute (other);
  1688. return isNegative() ? -absComp : absComp;
  1689. }
  1690. else
  1691. {
  1692. return isNegative() ? -1 : 1;
  1693. }
  1694. }
  1695. int BitArray::compareAbsolute (const BitArray& other) const throw()
  1696. {
  1697. const int h1 = getHighestBit();
  1698. const int h2 = other.getHighestBit();
  1699. if (h1 > h2)
  1700. return 1;
  1701. else if (h1 < h2)
  1702. return -1;
  1703. for (int i = (h1 >> 5) + 1; --i >= 0;)
  1704. if (values[i] != other.values[i])
  1705. return (values[i] > other.values[i]) ? 1 : -1;
  1706. return 0;
  1707. }
  1708. bool BitArray::operator== (const BitArray& other) const throw()
  1709. {
  1710. return compare (other) == 0;
  1711. }
  1712. bool BitArray::operator!= (const BitArray& other) const throw()
  1713. {
  1714. return compare (other) != 0;
  1715. }
  1716. bool BitArray::operator[] (const int bit) const throw()
  1717. {
  1718. return bit >= 0 && bit <= highestBit
  1719. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1720. }
  1721. bool BitArray::isEmpty() const throw()
  1722. {
  1723. return getHighestBit() < 0;
  1724. }
  1725. void BitArray::clear() throw()
  1726. {
  1727. if (numValues > 16)
  1728. {
  1729. numValues = 4;
  1730. values.calloc (numValues + 1);
  1731. }
  1732. else
  1733. {
  1734. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1735. }
  1736. highestBit = -1;
  1737. negative = false;
  1738. }
  1739. void BitArray::setBit (const int bit) throw()
  1740. {
  1741. if (bit >= 0)
  1742. {
  1743. if (bit > highestBit)
  1744. {
  1745. ensureSize (bit >> 5);
  1746. highestBit = bit;
  1747. }
  1748. values [bit >> 5] |= (1 << (bit & 31));
  1749. }
  1750. }
  1751. void BitArray::setBit (const int bit,
  1752. const bool shouldBeSet) throw()
  1753. {
  1754. if (shouldBeSet)
  1755. setBit (bit);
  1756. else
  1757. clearBit (bit);
  1758. }
  1759. void BitArray::clearBit (const int bit) throw()
  1760. {
  1761. if (bit >= 0 && bit <= highestBit)
  1762. values [bit >> 5] &= ~(1 << (bit & 31));
  1763. }
  1764. void BitArray::setRange (int startBit,
  1765. int numBits,
  1766. const bool shouldBeSet) throw()
  1767. {
  1768. while (--numBits >= 0)
  1769. setBit (startBit++, shouldBeSet);
  1770. }
  1771. void BitArray::insertBit (const int bit,
  1772. const bool shouldBeSet) throw()
  1773. {
  1774. if (bit >= 0)
  1775. shiftBits (1, bit);
  1776. setBit (bit, shouldBeSet);
  1777. }
  1778. void BitArray::andWith (const BitArray& other) throw()
  1779. {
  1780. // this operation will only work with the absolute values
  1781. jassert (isNegative() == other.isNegative());
  1782. int n = numValues;
  1783. while (n > other.numValues)
  1784. values[--n] = 0;
  1785. while (--n >= 0)
  1786. values[n] &= other.values[n];
  1787. if (other.highestBit < highestBit)
  1788. highestBit = other.highestBit;
  1789. highestBit = getHighestBit();
  1790. }
  1791. void BitArray::orWith (const BitArray& other) throw()
  1792. {
  1793. if (other.highestBit < 0)
  1794. return;
  1795. // this operation will only work with the absolute values
  1796. jassert (isNegative() == other.isNegative());
  1797. ensureSize (other.highestBit >> 5);
  1798. int n = (other.highestBit >> 5) + 1;
  1799. while (--n >= 0)
  1800. values[n] |= other.values[n];
  1801. if (other.highestBit > highestBit)
  1802. highestBit = other.highestBit;
  1803. highestBit = getHighestBit();
  1804. }
  1805. void BitArray::xorWith (const BitArray& other) throw()
  1806. {
  1807. if (other.highestBit < 0)
  1808. return;
  1809. // this operation will only work with the absolute values
  1810. jassert (isNegative() == other.isNegative());
  1811. ensureSize (other.highestBit >> 5);
  1812. int n = (other.highestBit >> 5) + 1;
  1813. while (--n >= 0)
  1814. values[n] ^= other.values[n];
  1815. if (other.highestBit > highestBit)
  1816. highestBit = other.highestBit;
  1817. highestBit = getHighestBit();
  1818. }
  1819. void BitArray::add (const BitArray& other) throw()
  1820. {
  1821. if (other.isNegative())
  1822. {
  1823. BitArray o (other);
  1824. o.negate();
  1825. subtract (o);
  1826. return;
  1827. }
  1828. if (isNegative())
  1829. {
  1830. if (compareAbsolute (other) < 0)
  1831. {
  1832. BitArray temp (*this);
  1833. temp.negate();
  1834. *this = other;
  1835. subtract (temp);
  1836. }
  1837. else
  1838. {
  1839. negate();
  1840. subtract (other);
  1841. negate();
  1842. }
  1843. return;
  1844. }
  1845. if (other.highestBit > highestBit)
  1846. highestBit = other.highestBit;
  1847. ++highestBit;
  1848. const int numInts = (highestBit >> 5) + 1;
  1849. ensureSize (numInts);
  1850. int64 remainder = 0;
  1851. for (int i = 0; i <= numInts; ++i)
  1852. {
  1853. if (i < numValues)
  1854. remainder += values[i];
  1855. if (i < other.numValues)
  1856. remainder += other.values[i];
  1857. values[i] = (unsigned int) remainder;
  1858. remainder >>= 32;
  1859. }
  1860. jassert (remainder == 0);
  1861. highestBit = getHighestBit();
  1862. }
  1863. void BitArray::subtract (const BitArray& other) throw()
  1864. {
  1865. if (other.isNegative())
  1866. {
  1867. BitArray o (other);
  1868. o.negate();
  1869. add (o);
  1870. return;
  1871. }
  1872. if (! isNegative())
  1873. {
  1874. if (compareAbsolute (other) < 0)
  1875. {
  1876. BitArray temp (*this);
  1877. *this = other;
  1878. subtract (temp);
  1879. negate();
  1880. return;
  1881. }
  1882. }
  1883. else
  1884. {
  1885. negate();
  1886. add (other);
  1887. negate();
  1888. return;
  1889. }
  1890. const int numInts = (highestBit >> 5) + 1;
  1891. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1892. int64 amountToSubtract = 0;
  1893. for (int i = 0; i <= numInts; ++i)
  1894. {
  1895. if (i <= maxOtherInts)
  1896. amountToSubtract += (int64)other.values[i];
  1897. if (values[i] >= amountToSubtract)
  1898. {
  1899. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1900. amountToSubtract = 0;
  1901. }
  1902. else
  1903. {
  1904. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1905. values[i] = (unsigned int) n;
  1906. amountToSubtract = 1;
  1907. }
  1908. }
  1909. }
  1910. void BitArray::multiplyBy (const BitArray& other) throw()
  1911. {
  1912. BitArray total;
  1913. highestBit = getHighestBit();
  1914. const bool wasNegative = isNegative();
  1915. setNegative (false);
  1916. for (int i = 0; i <= highestBit; ++i)
  1917. {
  1918. if (operator[](i))
  1919. {
  1920. BitArray n (other);
  1921. n.setNegative (false);
  1922. n.shiftBits (i);
  1923. total.add (n);
  1924. }
  1925. }
  1926. *this = total;
  1927. negative = wasNegative ^ other.isNegative();
  1928. }
  1929. void BitArray::divideBy (const BitArray& divisor, BitArray& remainder) throw()
  1930. {
  1931. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1932. const int divHB = divisor.getHighestBit();
  1933. const int ourHB = getHighestBit();
  1934. if (divHB < 0 || ourHB < 0)
  1935. {
  1936. // division by zero
  1937. remainder.clear();
  1938. clear();
  1939. }
  1940. else
  1941. {
  1942. remainder = *this;
  1943. remainder.setNegative (false);
  1944. const bool wasNegative = isNegative();
  1945. clear();
  1946. BitArray temp (divisor);
  1947. temp.setNegative (false);
  1948. int leftShift = ourHB - divHB;
  1949. temp.shiftBits (leftShift);
  1950. while (leftShift >= 0)
  1951. {
  1952. if (remainder.compareAbsolute (temp) >= 0)
  1953. {
  1954. remainder.subtract (temp);
  1955. setBit (leftShift);
  1956. }
  1957. if (--leftShift >= 0)
  1958. temp.shiftBits (-1);
  1959. }
  1960. negative = wasNegative ^ divisor.isNegative();
  1961. remainder.setNegative (wasNegative);
  1962. }
  1963. }
  1964. void BitArray::modulo (const BitArray& divisor) throw()
  1965. {
  1966. BitArray remainder;
  1967. divideBy (divisor, remainder);
  1968. *this = remainder;
  1969. }
  1970. static const BitArray simpleGCD (BitArray* m, BitArray* n) throw()
  1971. {
  1972. while (! m->isEmpty())
  1973. {
  1974. if (n->compareAbsolute (*m) > 0)
  1975. swapVariables (m, n);
  1976. m->subtract (*n);
  1977. }
  1978. return *n;
  1979. }
  1980. const BitArray BitArray::findGreatestCommonDivisor (BitArray n) const throw()
  1981. {
  1982. BitArray m (*this);
  1983. while (! n.isEmpty())
  1984. {
  1985. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  1986. return simpleGCD (&m, &n);
  1987. BitArray temp1 (m), temp2;
  1988. temp1.divideBy (n, temp2);
  1989. m = n;
  1990. n = temp2;
  1991. }
  1992. return m;
  1993. }
  1994. void BitArray::exponentModulo (const BitArray& exponent,
  1995. const BitArray& modulus) throw()
  1996. {
  1997. BitArray exp (exponent);
  1998. exp.modulo (modulus);
  1999. BitArray value (*this);
  2000. value.modulo (modulus);
  2001. clear();
  2002. setBit (0);
  2003. while (! exp.isEmpty())
  2004. {
  2005. if (exp [0])
  2006. {
  2007. multiplyBy (value);
  2008. this->modulo (modulus);
  2009. }
  2010. value.multiplyBy (value);
  2011. value.modulo (modulus);
  2012. exp.shiftBits (-1);
  2013. }
  2014. }
  2015. void BitArray::inverseModulo (const BitArray& modulus) throw()
  2016. {
  2017. const BitArray one (1);
  2018. if (modulus == one || modulus.isNegative())
  2019. {
  2020. clear();
  2021. return;
  2022. }
  2023. if (isNegative() || compareAbsolute (modulus) >= 0)
  2024. this->modulo (modulus);
  2025. if (*this == one)
  2026. return;
  2027. if (! (*this)[0])
  2028. {
  2029. // not invertible
  2030. clear();
  2031. return;
  2032. }
  2033. BitArray a1 (modulus);
  2034. BitArray a2 (*this);
  2035. BitArray b1 (modulus);
  2036. BitArray b2 (1);
  2037. while (a2 != one)
  2038. {
  2039. BitArray temp1, temp2, multiplier (a1);
  2040. multiplier.divideBy (a2, temp1);
  2041. temp1 = a2;
  2042. temp1.multiplyBy (multiplier);
  2043. temp2 = a1;
  2044. temp2.subtract (temp1);
  2045. a1 = a2;
  2046. a2 = temp2;
  2047. temp1 = b2;
  2048. temp1.multiplyBy (multiplier);
  2049. temp2 = b1;
  2050. temp2.subtract (temp1);
  2051. b1 = b2;
  2052. b2 = temp2;
  2053. }
  2054. while (b2.isNegative())
  2055. b2.add (modulus);
  2056. b2.modulo (modulus);
  2057. *this = b2;
  2058. }
  2059. void BitArray::shiftBits (int bits, const int startBit) throw()
  2060. {
  2061. if (highestBit < 0)
  2062. return;
  2063. if (startBit > 0)
  2064. {
  2065. if (bits < 0)
  2066. {
  2067. // right shift
  2068. for (int i = startBit; i <= highestBit; ++i)
  2069. setBit (i, operator[] (i - bits));
  2070. highestBit = getHighestBit();
  2071. }
  2072. else if (bits > 0)
  2073. {
  2074. // left shift
  2075. for (int i = highestBit + 1; --i >= startBit;)
  2076. setBit (i + bits, operator[] (i));
  2077. while (--bits >= 0)
  2078. clearBit (bits + startBit);
  2079. }
  2080. }
  2081. else
  2082. {
  2083. if (bits < 0)
  2084. {
  2085. // right shift
  2086. bits = -bits;
  2087. if (bits > highestBit)
  2088. {
  2089. clear();
  2090. }
  2091. else
  2092. {
  2093. const int wordsToMove = bits >> 5;
  2094. int top = 1 + (highestBit >> 5) - wordsToMove;
  2095. highestBit -= bits;
  2096. if (wordsToMove > 0)
  2097. {
  2098. int i;
  2099. for (i = 0; i < top; ++i)
  2100. values [i] = values [i + wordsToMove];
  2101. for (i = 0; i < wordsToMove; ++i)
  2102. values [top + i] = 0;
  2103. bits &= 31;
  2104. }
  2105. if (bits != 0)
  2106. {
  2107. const int invBits = 32 - bits;
  2108. --top;
  2109. for (int i = 0; i < top; ++i)
  2110. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2111. values[top] = (values[top] >> bits);
  2112. }
  2113. highestBit = getHighestBit();
  2114. }
  2115. }
  2116. else if (bits > 0)
  2117. {
  2118. // left shift
  2119. ensureSize (((highestBit + bits) >> 5) + 1);
  2120. const int wordsToMove = bits >> 5;
  2121. int top = 1 + (highestBit >> 5);
  2122. highestBit += bits;
  2123. if (wordsToMove > 0)
  2124. {
  2125. int i;
  2126. for (i = top; --i >= 0;)
  2127. values [i + wordsToMove] = values [i];
  2128. for (i = 0; i < wordsToMove; ++i)
  2129. values [i] = 0;
  2130. bits &= 31;
  2131. }
  2132. if (bits != 0)
  2133. {
  2134. const int invBits = 32 - bits;
  2135. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2136. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2137. values [wordsToMove] = values [wordsToMove] << bits;
  2138. }
  2139. highestBit = getHighestBit();
  2140. }
  2141. }
  2142. }
  2143. const BitArray BitArray::getBitRange (int startBit, int numBits) const throw()
  2144. {
  2145. BitArray r;
  2146. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  2147. r.ensureSize (numBits >> 5);
  2148. r.highestBit = numBits;
  2149. int i = 0;
  2150. while (numBits > 0)
  2151. {
  2152. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  2153. numBits -= 32;
  2154. startBit += 32;
  2155. }
  2156. r.highestBit = r.getHighestBit();
  2157. return r;
  2158. }
  2159. int BitArray::getBitRangeAsInt (const int startBit, int numBits) const throw()
  2160. {
  2161. if (numBits > 32)
  2162. {
  2163. jassertfalse // use getBitRange() if you need more than 32 bits..
  2164. numBits = 32;
  2165. }
  2166. numBits = jmin (numBits, highestBit + 1 - startBit);
  2167. if (numBits <= 0)
  2168. return 0;
  2169. const int pos = startBit >> 5;
  2170. const int offset = startBit & 31;
  2171. const int endSpace = 32 - numBits;
  2172. uint32 n = ((uint32) values [pos]) >> offset;
  2173. if (offset > endSpace)
  2174. n |= ((uint32) values [pos + 1]) << (32 - offset);
  2175. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  2176. }
  2177. void BitArray::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet) throw()
  2178. {
  2179. if (numBits > 32)
  2180. {
  2181. jassertfalse
  2182. numBits = 32;
  2183. }
  2184. for (int i = 0; i < numBits; ++i)
  2185. {
  2186. setBit (startBit + i, (valueToSet & 1) != 0);
  2187. valueToSet >>= 1;
  2188. }
  2189. }
  2190. bool BitArray::isNegative() const throw()
  2191. {
  2192. return negative && ! isEmpty();
  2193. }
  2194. void BitArray::setNegative (const bool neg) throw()
  2195. {
  2196. negative = neg;
  2197. }
  2198. void BitArray::negate() throw()
  2199. {
  2200. negative = (! negative) && ! isEmpty();
  2201. }
  2202. int BitArray::countNumberOfSetBits() const throw()
  2203. {
  2204. int total = 0;
  2205. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  2206. {
  2207. unsigned int n = values[i];
  2208. if (n == 0xffffffff)
  2209. {
  2210. total += 32;
  2211. }
  2212. else
  2213. {
  2214. while (n != 0)
  2215. {
  2216. total += (n & 1);
  2217. n >>= 1;
  2218. }
  2219. }
  2220. }
  2221. return total;
  2222. }
  2223. int BitArray::getHighestBit() const throw()
  2224. {
  2225. for (int i = highestBit + 1; --i >= 0;)
  2226. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2227. return i;
  2228. return -1;
  2229. }
  2230. int BitArray::findNextSetBit (int i) const throw()
  2231. {
  2232. for (; i <= highestBit; ++i)
  2233. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2234. return i;
  2235. return -1;
  2236. }
  2237. int BitArray::findNextClearBit (int i) const throw()
  2238. {
  2239. for (; i <= highestBit; ++i)
  2240. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  2241. break;
  2242. return i;
  2243. }
  2244. void BitArray::ensureSize (const int numVals) throw()
  2245. {
  2246. if (numVals + 2 >= numValues)
  2247. {
  2248. int oldSize = numValues;
  2249. numValues = ((numVals + 2) * 3) / 2;
  2250. values.realloc (numValues + 1);
  2251. while (oldSize < numValues)
  2252. values [oldSize++] = 0;
  2253. }
  2254. }
  2255. const String BitArray::toString (const int base, const int minimumNumCharacters) const throw()
  2256. {
  2257. String s;
  2258. BitArray v (*this);
  2259. if (base == 2 || base == 8 || base == 16)
  2260. {
  2261. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2262. static const tchar* const hexDigits = T("0123456789abcdef");
  2263. for (;;)
  2264. {
  2265. const int remainder = v.getBitRangeAsInt (0, bits);
  2266. v.shiftBits (-bits);
  2267. if (remainder == 0 && v.isEmpty())
  2268. break;
  2269. s = String::charToString (hexDigits [remainder]) + s;
  2270. }
  2271. }
  2272. else if (base == 10)
  2273. {
  2274. const BitArray ten (10);
  2275. BitArray remainder;
  2276. for (;;)
  2277. {
  2278. v.divideBy (ten, remainder);
  2279. if (remainder.isEmpty() && v.isEmpty())
  2280. break;
  2281. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2282. }
  2283. }
  2284. else
  2285. {
  2286. jassertfalse // can't do the specified base
  2287. return String::empty;
  2288. }
  2289. const int length = s.length();
  2290. if (length < minimumNumCharacters)
  2291. s = String::repeatedString (T("0"), minimumNumCharacters - length) + s;
  2292. return isNegative() ? T("-") + s : s;
  2293. }
  2294. void BitArray::parseString (const String& text,
  2295. const int base) throw()
  2296. {
  2297. clear();
  2298. const tchar* t = (const tchar*) text;
  2299. if (base == 2 || base == 8 || base == 16)
  2300. {
  2301. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2302. for (;;)
  2303. {
  2304. const tchar c = *t++;
  2305. const int digit = CharacterFunctions::getHexDigitValue (c);
  2306. if (((unsigned int) digit) < (unsigned int) base)
  2307. {
  2308. shiftBits (bits);
  2309. add (digit);
  2310. }
  2311. else if (c == 0)
  2312. {
  2313. break;
  2314. }
  2315. }
  2316. }
  2317. else if (base == 10)
  2318. {
  2319. const BitArray ten ((unsigned int) 10);
  2320. for (;;)
  2321. {
  2322. const tchar c = *t++;
  2323. if (c >= T('0') && c <= T('9'))
  2324. {
  2325. multiplyBy (ten);
  2326. add ((int) (c - T('0')));
  2327. }
  2328. else if (c == 0)
  2329. {
  2330. break;
  2331. }
  2332. }
  2333. }
  2334. setNegative (text.trimStart().startsWithChar (T('-')));
  2335. }
  2336. const MemoryBlock BitArray::toMemoryBlock() const throw()
  2337. {
  2338. const int numBytes = (getHighestBit() + 8) >> 3;
  2339. MemoryBlock mb ((size_t) numBytes);
  2340. for (int i = 0; i < numBytes; ++i)
  2341. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2342. return mb;
  2343. }
  2344. void BitArray::loadFromMemoryBlock (const MemoryBlock& data) throw()
  2345. {
  2346. clear();
  2347. for (int i = (int) data.getSize(); --i >= 0;)
  2348. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2349. }
  2350. END_JUCE_NAMESPACE
  2351. /*** End of inlined file: juce_BitArray.cpp ***/
  2352. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2353. BEGIN_JUCE_NAMESPACE
  2354. MemoryBlock::MemoryBlock() throw()
  2355. : size (0)
  2356. {
  2357. }
  2358. MemoryBlock::MemoryBlock (const size_t initialSize,
  2359. const bool initialiseToZero) throw()
  2360. {
  2361. if (initialSize > 0)
  2362. {
  2363. size = initialSize;
  2364. data.allocate (initialSize, initialiseToZero);
  2365. }
  2366. else
  2367. {
  2368. size = 0;
  2369. }
  2370. }
  2371. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2372. : size (other.size)
  2373. {
  2374. if (size > 0)
  2375. {
  2376. jassert (other.data != 0);
  2377. data.malloc (size);
  2378. memcpy (data, other.data, size);
  2379. }
  2380. }
  2381. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2382. const size_t sizeInBytes) throw()
  2383. : size (jmax ((size_t) 0, sizeInBytes))
  2384. {
  2385. jassert (sizeInBytes >= 0);
  2386. if (size > 0)
  2387. {
  2388. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2389. data.malloc (size);
  2390. if (dataToInitialiseFrom != 0)
  2391. memcpy (data, dataToInitialiseFrom, size);
  2392. }
  2393. }
  2394. MemoryBlock::~MemoryBlock() throw()
  2395. {
  2396. jassert (size >= 0); // should never happen
  2397. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2398. }
  2399. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2400. {
  2401. if (this != &other)
  2402. {
  2403. setSize (other.size, false);
  2404. memcpy (data, other.data, size);
  2405. }
  2406. return *this;
  2407. }
  2408. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2409. {
  2410. return matches (other.data, other.size);
  2411. }
  2412. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2413. {
  2414. return ! operator== (other);
  2415. }
  2416. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2417. {
  2418. return size == dataSize
  2419. && memcmp (data, dataToCompare, size) == 0;
  2420. }
  2421. // this will resize the block to this size
  2422. void MemoryBlock::setSize (const size_t newSize,
  2423. const bool initialiseToZero) throw()
  2424. {
  2425. if (size != newSize)
  2426. {
  2427. if (newSize <= 0)
  2428. {
  2429. data.free();
  2430. size = 0;
  2431. }
  2432. else
  2433. {
  2434. if (data != 0)
  2435. {
  2436. data.realloc (newSize);
  2437. if (initialiseToZero && (newSize > size))
  2438. zeromem (data + size, newSize - size);
  2439. }
  2440. else
  2441. {
  2442. data.allocate (newSize, initialiseToZero);
  2443. }
  2444. size = newSize;
  2445. }
  2446. }
  2447. }
  2448. void MemoryBlock::ensureSize (const size_t minimumSize,
  2449. const bool initialiseToZero) throw()
  2450. {
  2451. if (size < minimumSize)
  2452. setSize (minimumSize, initialiseToZero);
  2453. }
  2454. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2455. {
  2456. swapVariables (size, other.size);
  2457. data.swapWith (other.data);
  2458. }
  2459. void MemoryBlock::fillWith (const uint8 value) throw()
  2460. {
  2461. memset (data, (int) value, size);
  2462. }
  2463. void MemoryBlock::append (const void* const srcData,
  2464. const size_t numBytes) throw()
  2465. {
  2466. if (numBytes > 0)
  2467. {
  2468. const size_t oldSize = size;
  2469. setSize (size + numBytes);
  2470. memcpy (data + oldSize, srcData, numBytes);
  2471. }
  2472. }
  2473. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2474. {
  2475. const char* d = (const char*) src;
  2476. if (offset < 0)
  2477. {
  2478. d -= offset;
  2479. num -= offset;
  2480. offset = 0;
  2481. }
  2482. if (offset + num > size)
  2483. num = size - offset;
  2484. if (num > 0)
  2485. memcpy (data + offset, d, num);
  2486. }
  2487. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2488. {
  2489. char* d = (char*) dst;
  2490. if (offset < 0)
  2491. {
  2492. zeromem (d, -offset);
  2493. d -= offset;
  2494. num += offset;
  2495. offset = 0;
  2496. }
  2497. if (offset + num > size)
  2498. {
  2499. const size_t newNum = size - offset;
  2500. zeromem (d + newNum, num - newNum);
  2501. num = newNum;
  2502. }
  2503. if (num > 0)
  2504. memcpy (d, data + offset, num);
  2505. }
  2506. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2507. {
  2508. if (startByte < 0)
  2509. {
  2510. numBytesToRemove += startByte;
  2511. startByte = 0;
  2512. }
  2513. if (startByte + numBytesToRemove >= size)
  2514. {
  2515. setSize (startByte);
  2516. }
  2517. else if (numBytesToRemove > 0)
  2518. {
  2519. memmove (data + startByte,
  2520. data + startByte + numBytesToRemove,
  2521. size - (startByte + numBytesToRemove));
  2522. setSize (size - numBytesToRemove);
  2523. }
  2524. }
  2525. const String MemoryBlock::toString() const throw()
  2526. {
  2527. return String ((const char*) data, size);
  2528. }
  2529. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2530. {
  2531. int res = 0;
  2532. size_t byte = bitRangeStart >> 3;
  2533. int offsetInByte = bitRangeStart & 7;
  2534. size_t bitsSoFar = 0;
  2535. while (numBits > 0 && (size_t) byte < size)
  2536. {
  2537. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2538. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2539. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2540. bitsSoFar += bitsThisTime;
  2541. numBits -= bitsThisTime;
  2542. ++byte;
  2543. offsetInByte = 0;
  2544. }
  2545. return res;
  2546. }
  2547. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2548. {
  2549. size_t byte = bitRangeStart >> 3;
  2550. int offsetInByte = bitRangeStart & 7;
  2551. unsigned int mask = ~((((unsigned int)0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2552. while (numBits > 0 && (size_t) byte < size)
  2553. {
  2554. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2555. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int)0xffffffff) >> offsetInByte) << offsetInByte);
  2556. const unsigned int tempBits = bitsToSet << offsetInByte;
  2557. data[byte] = (char)((data[byte] & tempMask) | tempBits);
  2558. ++byte;
  2559. numBits -= bitsThisTime;
  2560. bitsToSet >>= bitsThisTime;
  2561. mask >>= bitsThisTime;
  2562. offsetInByte = 0;
  2563. }
  2564. }
  2565. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2566. {
  2567. ensureSize (hex.length() >> 1);
  2568. char* dest = data;
  2569. int i = 0;
  2570. for (;;)
  2571. {
  2572. int byte = 0;
  2573. for (int loop = 2; --loop >= 0;)
  2574. {
  2575. byte <<= 4;
  2576. for (;;)
  2577. {
  2578. const tchar c = hex [i++];
  2579. if (c >= T('0') && c <= T('9'))
  2580. {
  2581. byte |= c - T('0');
  2582. break;
  2583. }
  2584. else if (c >= T('a') && c <= T('z'))
  2585. {
  2586. byte |= c - (T('a') - 10);
  2587. break;
  2588. }
  2589. else if (c >= T('A') && c <= T('Z'))
  2590. {
  2591. byte |= c - (T('A') - 10);
  2592. break;
  2593. }
  2594. else if (c == 0)
  2595. {
  2596. setSize ((int) (dest - data));
  2597. return;
  2598. }
  2599. }
  2600. }
  2601. *dest++ = (char) byte;
  2602. }
  2603. }
  2604. static const char* const encodingTable
  2605. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2606. const String MemoryBlock::toBase64Encoding() const throw()
  2607. {
  2608. const size_t numChars = ((size << 3) + 5) / 6;
  2609. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2610. const int initialLen = destString.length();
  2611. destString.preallocateStorage (initialLen + 2 + numChars);
  2612. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2613. *d++ = T('.');
  2614. for (size_t i = 0; i < numChars; ++i)
  2615. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2616. *d++ = 0;
  2617. return destString;
  2618. }
  2619. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2620. {
  2621. const int startPos = s.indexOfChar (T('.')) + 1;
  2622. if (startPos <= 0)
  2623. return false;
  2624. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2625. setSize (numBytesNeeded, true);
  2626. const int numChars = s.length() - startPos;
  2627. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2628. int pos = 0;
  2629. for (int i = 0; i < numChars; ++i)
  2630. {
  2631. const char c = (char) srcChars[i];
  2632. for (int j = 0; j < 64; ++j)
  2633. {
  2634. if (encodingTable[j] == c)
  2635. {
  2636. setBitRange (pos, 6, j);
  2637. pos += 6;
  2638. break;
  2639. }
  2640. }
  2641. }
  2642. return true;
  2643. }
  2644. END_JUCE_NAMESPACE
  2645. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2646. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2647. BEGIN_JUCE_NAMESPACE
  2648. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2649. : properties (ignoreCaseOfKeyNames),
  2650. fallbackProperties (0),
  2651. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2652. {
  2653. }
  2654. PropertySet::PropertySet (const PropertySet& other) throw()
  2655. : properties (other.properties),
  2656. fallbackProperties (other.fallbackProperties),
  2657. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2658. {
  2659. }
  2660. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2661. {
  2662. properties = other.properties;
  2663. fallbackProperties = other.fallbackProperties;
  2664. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2665. propertyChanged();
  2666. return *this;
  2667. }
  2668. PropertySet::~PropertySet()
  2669. {
  2670. }
  2671. void PropertySet::clear()
  2672. {
  2673. const ScopedLock sl (lock);
  2674. if (properties.size() > 0)
  2675. {
  2676. properties.clear();
  2677. propertyChanged();
  2678. }
  2679. }
  2680. const String PropertySet::getValue (const String& keyName,
  2681. const String& defaultValue) const throw()
  2682. {
  2683. const ScopedLock sl (lock);
  2684. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2685. if (index >= 0)
  2686. return properties.getAllValues() [index];
  2687. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2688. : defaultValue;
  2689. }
  2690. int PropertySet::getIntValue (const String& keyName,
  2691. const int defaultValue) const throw()
  2692. {
  2693. const ScopedLock sl (lock);
  2694. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2695. if (index >= 0)
  2696. return properties.getAllValues() [index].getIntValue();
  2697. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2698. : defaultValue;
  2699. }
  2700. double PropertySet::getDoubleValue (const String& keyName,
  2701. const double defaultValue) const throw()
  2702. {
  2703. const ScopedLock sl (lock);
  2704. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2705. if (index >= 0)
  2706. return properties.getAllValues()[index].getDoubleValue();
  2707. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2708. : defaultValue;
  2709. }
  2710. bool PropertySet::getBoolValue (const String& keyName,
  2711. const bool defaultValue) const throw()
  2712. {
  2713. const ScopedLock sl (lock);
  2714. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2715. if (index >= 0)
  2716. return properties.getAllValues() [index].getIntValue() != 0;
  2717. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2718. : defaultValue;
  2719. }
  2720. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2721. {
  2722. XmlDocument doc (getValue (keyName));
  2723. return doc.getDocumentElement();
  2724. }
  2725. void PropertySet::setValue (const String& keyName,
  2726. const String& value) throw()
  2727. {
  2728. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2729. if (keyName.isNotEmpty())
  2730. {
  2731. const ScopedLock sl (lock);
  2732. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2733. if (index < 0 || properties.getAllValues() [index] != value)
  2734. {
  2735. properties.set (keyName, value);
  2736. propertyChanged();
  2737. }
  2738. }
  2739. }
  2740. void PropertySet::removeValue (const String& keyName) throw()
  2741. {
  2742. if (keyName.isNotEmpty())
  2743. {
  2744. const ScopedLock sl (lock);
  2745. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2746. if (index >= 0)
  2747. {
  2748. properties.remove (keyName);
  2749. propertyChanged();
  2750. }
  2751. }
  2752. }
  2753. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2754. {
  2755. setValue (keyName, String (value));
  2756. }
  2757. void PropertySet::setValue (const String& keyName, const int value) throw()
  2758. {
  2759. setValue (keyName, String (value));
  2760. }
  2761. void PropertySet::setValue (const String& keyName, const double value) throw()
  2762. {
  2763. setValue (keyName, String (value));
  2764. }
  2765. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2766. {
  2767. setValue (keyName, String ((value) ? T("1") : T("0")));
  2768. }
  2769. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2770. {
  2771. setValue (keyName, (xml == 0) ? String::empty
  2772. : xml->createDocument (String::empty, true));
  2773. }
  2774. bool PropertySet::containsKey (const String& keyName) const throw()
  2775. {
  2776. const ScopedLock sl (lock);
  2777. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2778. }
  2779. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2780. {
  2781. const ScopedLock sl (lock);
  2782. fallbackProperties = fallbackProperties_;
  2783. }
  2784. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2785. {
  2786. const ScopedLock sl (lock);
  2787. XmlElement* const xml = new XmlElement (nodeName);
  2788. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2789. {
  2790. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2791. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2792. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2793. }
  2794. return xml;
  2795. }
  2796. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2797. {
  2798. const ScopedLock sl (lock);
  2799. clear();
  2800. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2801. {
  2802. if (e->hasAttribute (T("name"))
  2803. && e->hasAttribute (T("val")))
  2804. {
  2805. properties.set (e->getStringAttribute (T("name")),
  2806. e->getStringAttribute (T("val")));
  2807. }
  2808. }
  2809. if (properties.size() > 0)
  2810. propertyChanged();
  2811. }
  2812. void PropertySet::propertyChanged()
  2813. {
  2814. }
  2815. END_JUCE_NAMESPACE
  2816. /*** End of inlined file: juce_PropertySet.cpp ***/
  2817. /*** Start of inlined file: juce_Variant.cpp ***/
  2818. BEGIN_JUCE_NAMESPACE
  2819. var::var() throw()
  2820. : type (voidType)
  2821. {
  2822. value.doubleValue = 0;
  2823. }
  2824. var::~var() throw()
  2825. {
  2826. if (type == stringType)
  2827. delete value.stringValue;
  2828. else if (type == objectType && value.objectValue != 0)
  2829. value.objectValue->decReferenceCount();
  2830. }
  2831. const var var::null;
  2832. var::var (const var& valueToCopy)
  2833. : type (valueToCopy.type),
  2834. value (valueToCopy.value)
  2835. {
  2836. if (type == stringType)
  2837. value.stringValue = new String (*(value.stringValue));
  2838. else if (type == objectType && value.objectValue != 0)
  2839. value.objectValue->incReferenceCount();
  2840. }
  2841. var::var (const int value_) throw()
  2842. : type (intType)
  2843. {
  2844. value.intValue = value_;
  2845. }
  2846. var::var (const bool value_) throw()
  2847. : type (boolType)
  2848. {
  2849. value.boolValue = value_;
  2850. }
  2851. var::var (const double value_) throw()
  2852. : type (doubleType)
  2853. {
  2854. value.doubleValue = value_;
  2855. }
  2856. var::var (const String& value_)
  2857. : type (stringType)
  2858. {
  2859. value.stringValue = new String (value_);
  2860. }
  2861. var::var (const char* const value_)
  2862. : type (stringType)
  2863. {
  2864. value.stringValue = new String (value_);
  2865. }
  2866. var::var (const juce_wchar* const value_)
  2867. : type (stringType)
  2868. {
  2869. value.stringValue = new String (value_);
  2870. }
  2871. var::var (DynamicObject* const object)
  2872. : type (objectType)
  2873. {
  2874. value.objectValue = object;
  2875. if (object != 0)
  2876. object->incReferenceCount();
  2877. }
  2878. var::var (MethodFunction method_) throw()
  2879. : type (methodType)
  2880. {
  2881. value.methodValue = method_;
  2882. }
  2883. void var::swapWith (var& other) throw()
  2884. {
  2885. swapVariables (type, other.type);
  2886. swapVariables (value, other.value);
  2887. }
  2888. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2889. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2890. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2891. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2892. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2893. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2894. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2895. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2896. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2897. var::operator int() const
  2898. {
  2899. switch (type)
  2900. {
  2901. case voidType: break;
  2902. case intType: return value.intValue;
  2903. case boolType: return value.boolValue ? 1 : 0;
  2904. case doubleType: return (int) value.doubleValue;
  2905. case stringType: return value.stringValue->getIntValue();
  2906. case objectType: break;
  2907. default: jassertfalse; break;
  2908. }
  2909. return 0;
  2910. }
  2911. var::operator bool() const
  2912. {
  2913. switch (type)
  2914. {
  2915. case voidType: break;
  2916. case intType: return value.intValue != 0;
  2917. case boolType: return value.boolValue;
  2918. case doubleType: return value.doubleValue != 0;
  2919. case stringType: return value.stringValue->getIntValue() != 0
  2920. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2921. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2922. case objectType: return value.objectValue != 0;
  2923. default: jassertfalse; break;
  2924. }
  2925. return false;
  2926. }
  2927. var::operator float() const
  2928. {
  2929. return (float) operator double();
  2930. }
  2931. var::operator double() const
  2932. {
  2933. switch (type)
  2934. {
  2935. case voidType: break;
  2936. case intType: return value.intValue;
  2937. case boolType: return value.boolValue ? 1.0 : 0.0;
  2938. case doubleType: return value.doubleValue;
  2939. case stringType: return value.stringValue->getDoubleValue();
  2940. case objectType: break;
  2941. default: jassertfalse; break;
  2942. }
  2943. return 0.0;
  2944. }
  2945. const String var::toString() const
  2946. {
  2947. switch (type)
  2948. {
  2949. case voidType: return String::empty;
  2950. case intType: return String (value.intValue);
  2951. case boolType: return value.boolValue ? T("1") : T("0");
  2952. case doubleType: return String (value.doubleValue);
  2953. case stringType: return *(value.stringValue);
  2954. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  2955. case methodType: return "Method";
  2956. default: jassertfalse; break;
  2957. }
  2958. return String::empty;
  2959. }
  2960. var::operator const String() const
  2961. {
  2962. return toString();
  2963. }
  2964. DynamicObject* var::getObject() const
  2965. {
  2966. return type == objectType ? value.objectValue : 0;
  2967. }
  2968. bool var::equals (const var& other) const throw()
  2969. {
  2970. switch (type)
  2971. {
  2972. case voidType: return other.isVoid();
  2973. case intType: return value.intValue == (int) other;
  2974. case boolType: return value.boolValue == (bool) other;
  2975. case doubleType: return value.doubleValue == (double) other;
  2976. case stringType: return (*(value.stringValue)) == other.toString();
  2977. case objectType: return value.objectValue == other.getObject();
  2978. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  2979. default: jassertfalse; break;
  2980. }
  2981. return false;
  2982. }
  2983. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  2984. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  2985. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  2986. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  2987. void var::writeToStream (OutputStream& output) const
  2988. {
  2989. switch (type)
  2990. {
  2991. case voidType: output.writeCompressedInt (0); break;
  2992. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  2993. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  2994. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  2995. case stringType:
  2996. {
  2997. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  2998. output.writeCompressedInt (len + 1);
  2999. output.writeByte (5);
  3000. HeapBlock <uint8> temp (len);
  3001. value.stringValue->copyToUTF8 (temp, len);
  3002. output.write (temp, len);
  3003. break;
  3004. }
  3005. case objectType:
  3006. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3007. default: jassertfalse; break; // Is this a corrupted object?
  3008. }
  3009. }
  3010. const var var::readFromStream (InputStream& input)
  3011. {
  3012. const int numBytes = input.readCompressedInt();
  3013. if (numBytes > 0)
  3014. {
  3015. switch (input.readByte())
  3016. {
  3017. case 1: return var (input.readInt());
  3018. case 2: return var (true);
  3019. case 3: return var (false);
  3020. case 4: return var (input.readDouble());
  3021. case 5:
  3022. {
  3023. MemoryBlock mb;
  3024. input.readIntoMemoryBlock (mb, numBytes - 1);
  3025. return var (String::fromUTF8 ((const char*) mb.getData(), (int) mb.getSize()));
  3026. }
  3027. default: input.skipNextBytes (numBytes - 1); break;
  3028. }
  3029. }
  3030. return var::null;
  3031. }
  3032. const var var::operator[] (const var::identifier& propertyName) const
  3033. {
  3034. if (type == objectType && value.objectValue != 0)
  3035. return value.objectValue->getProperty (propertyName);
  3036. return var::null;
  3037. }
  3038. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3039. {
  3040. if (type == objectType && value.objectValue != 0)
  3041. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3042. return var::null;
  3043. }
  3044. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3045. {
  3046. if (isMethod())
  3047. {
  3048. DynamicObject* const target = targetObject.getObject();
  3049. if (target != 0)
  3050. return (target->*(value.methodValue)) (arguments, numArguments);
  3051. }
  3052. return var::null;
  3053. }
  3054. const var var::call (const var::identifier& method) const
  3055. {
  3056. return invoke (method, 0, 0);
  3057. }
  3058. const var var::call (const var::identifier& method, const var& arg1) const
  3059. {
  3060. return invoke (method, &arg1, 1);
  3061. }
  3062. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3063. {
  3064. var args[] = { arg1, arg2 };
  3065. return invoke (method, args, 2);
  3066. }
  3067. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3068. {
  3069. var args[] = { arg1, arg2, arg3 };
  3070. return invoke (method, args, 3);
  3071. }
  3072. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3073. {
  3074. var args[] = { arg1, arg2, arg3, arg4 };
  3075. return invoke (method, args, 4);
  3076. }
  3077. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3078. {
  3079. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3080. return invoke (method, args, 5);
  3081. }
  3082. var::identifier::identifier() throw()
  3083. : hashCode (0)
  3084. {
  3085. }
  3086. var::identifier::identifier (const String& name_)
  3087. : name (name_),
  3088. hashCode (name_.hashCode())
  3089. {
  3090. /* An identifier string must be suitable for use as a script variable or XML
  3091. attribute, so it can only contain this limited set of characters.. */
  3092. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3093. }
  3094. var::identifier::identifier (const char* const name_)
  3095. : name (name_),
  3096. hashCode (name.hashCode())
  3097. {
  3098. /* An identifier string must be suitable for use as a script variable or XML
  3099. attribute, so it can only contain this limited set of characters.. */
  3100. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3101. }
  3102. var::identifier::~identifier()
  3103. {
  3104. }
  3105. END_JUCE_NAMESPACE
  3106. /*** End of inlined file: juce_Variant.cpp ***/
  3107. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3108. BEGIN_JUCE_NAMESPACE
  3109. NamedValueSet::NamedValue::NamedValue() throw()
  3110. {
  3111. }
  3112. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3113. : name (name_), value (value_)
  3114. {
  3115. }
  3116. NamedValueSet::NamedValueSet() throw()
  3117. {
  3118. }
  3119. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3120. : values (other.values)
  3121. {
  3122. }
  3123. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3124. {
  3125. values = other.values;
  3126. return *this;
  3127. }
  3128. NamedValueSet::~NamedValueSet()
  3129. {
  3130. }
  3131. int NamedValueSet::size() const throw()
  3132. {
  3133. return values.size();
  3134. }
  3135. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3136. {
  3137. for (int i = values.size(); --i >= 0;)
  3138. {
  3139. const NamedValue& v = values.getReference(i);
  3140. if (v.name == name)
  3141. return v.value;
  3142. }
  3143. return var::null;
  3144. }
  3145. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3146. {
  3147. const var* v = getItem (name);
  3148. return v != 0 ? *v : defaultReturnValue;
  3149. }
  3150. var* NamedValueSet::getItem (const var::identifier& name) const
  3151. {
  3152. for (int i = values.size(); --i >= 0;)
  3153. {
  3154. NamedValue& v = values.getReference(i);
  3155. if (v.name == name)
  3156. return &(v.value);
  3157. }
  3158. return 0;
  3159. }
  3160. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3161. {
  3162. for (int i = values.size(); --i >= 0;)
  3163. {
  3164. NamedValue& v = values.getReference(i);
  3165. if (v.name == name)
  3166. {
  3167. if (v.value == newValue)
  3168. return false;
  3169. v.value = newValue;
  3170. return true;
  3171. }
  3172. }
  3173. values.add (NamedValue (name, newValue));
  3174. return true;
  3175. }
  3176. bool NamedValueSet::contains (const var::identifier& name) const
  3177. {
  3178. return getItem (name) != 0;
  3179. }
  3180. bool NamedValueSet::remove (const var::identifier& name)
  3181. {
  3182. for (int i = values.size(); --i >= 0;)
  3183. {
  3184. if (values.getReference(i).name == name)
  3185. {
  3186. values.remove (i);
  3187. return true;
  3188. }
  3189. }
  3190. return false;
  3191. }
  3192. const var::identifier NamedValueSet::getName (int index) const
  3193. {
  3194. jassert (((unsigned int) index) < (unsigned int) values.size());
  3195. return values [index].name;
  3196. }
  3197. void NamedValueSet::clear()
  3198. {
  3199. values.clear();
  3200. }
  3201. END_JUCE_NAMESPACE
  3202. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3203. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3204. BEGIN_JUCE_NAMESPACE
  3205. DynamicObject::DynamicObject()
  3206. {
  3207. }
  3208. DynamicObject::~DynamicObject()
  3209. {
  3210. }
  3211. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3212. {
  3213. var* const v = properties.getItem (propertyName);
  3214. return v != 0 && ! v->isMethod();
  3215. }
  3216. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3217. {
  3218. return properties [propertyName];
  3219. }
  3220. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3221. {
  3222. properties.set (propertyName, newValue);
  3223. }
  3224. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3225. {
  3226. properties.remove (propertyName);
  3227. }
  3228. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3229. {
  3230. return getProperty (methodName).isMethod();
  3231. }
  3232. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3233. const var* parameters,
  3234. int numParameters)
  3235. {
  3236. return properties [methodName].invoke (var (this), parameters, numParameters);
  3237. }
  3238. void DynamicObject::setMethod (const var::identifier& name,
  3239. var::MethodFunction methodFunction)
  3240. {
  3241. properties.set (name, var (methodFunction));
  3242. }
  3243. void DynamicObject::clear()
  3244. {
  3245. properties.clear();
  3246. }
  3247. END_JUCE_NAMESPACE
  3248. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3249. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3250. BEGIN_JUCE_NAMESPACE
  3251. static const uint32 initialPValues [18] =
  3252. {
  3253. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
  3254. 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3255. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  3256. 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3257. 0x9216d5d9, 0x8979fb1b
  3258. };
  3259. static const uint32 initialSValues [4 * 256] =
  3260. {
  3261. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
  3262. 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3263. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  3264. 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3265. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
  3266. 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3267. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
  3268. 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3269. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  3270. 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3271. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
  3272. 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3273. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
  3274. 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3275. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  3276. 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3277. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
  3278. 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3279. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
  3280. 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3281. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  3282. 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3283. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
  3284. 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3285. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
  3286. 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3287. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  3288. 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3289. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
  3290. 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3291. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
  3292. 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3293. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  3294. 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3295. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
  3296. 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3297. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
  3298. 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3299. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  3300. 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3301. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
  3302. 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3303. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
  3304. 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3305. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  3306. 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3307. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
  3308. 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3309. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
  3310. 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3311. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  3312. 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3313. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
  3314. 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3315. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
  3316. 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3317. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  3318. 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3319. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
  3320. 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3321. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
  3322. 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3323. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  3324. 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3325. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
  3326. 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3327. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  3328. 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3329. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
  3330. 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3331. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
  3332. 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3333. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  3334. 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3335. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
  3336. 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3337. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
  3338. 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3339. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  3340. 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3341. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
  3342. 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3343. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
  3344. 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3345. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  3346. 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3347. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
  3348. 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3349. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
  3350. 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3351. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  3352. 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3353. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
  3354. 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3355. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
  3356. 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3357. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  3358. 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3359. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
  3360. 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3361. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
  3362. 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3363. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  3364. 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3365. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
  3366. 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3367. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
  3368. 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3369. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  3370. 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3371. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
  3372. 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3373. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
  3374. 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3375. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  3376. 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3377. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
  3378. 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3379. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
  3380. 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3381. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  3382. 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3383. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
  3384. 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3385. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
  3386. 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3387. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  3388. 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3389. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
  3390. 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3391. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  3392. 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3393. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
  3394. 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3395. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
  3396. 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3397. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  3398. 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3399. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
  3400. 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3401. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
  3402. 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3403. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  3404. 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3405. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
  3406. 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3407. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
  3408. 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3409. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  3410. 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3411. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
  3412. 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3413. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
  3414. 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3415. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  3416. 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3417. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
  3418. 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3419. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
  3420. 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3421. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  3422. 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3423. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
  3424. 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3425. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
  3426. 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3427. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  3428. 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3429. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
  3430. 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3431. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
  3432. 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3433. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  3434. 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3435. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
  3436. 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3437. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
  3438. 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3439. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  3440. 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3441. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
  3442. 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3443. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
  3444. 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3445. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  3446. 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3447. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
  3448. 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3449. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
  3450. 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3451. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  3452. 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3453. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
  3454. 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3455. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  3456. 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3457. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
  3458. 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3459. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
  3460. 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3461. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  3462. 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3463. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
  3464. 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3465. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
  3466. 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3467. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  3468. 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3469. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
  3470. 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3471. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
  3472. 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3473. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  3474. 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3475. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
  3476. 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3477. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
  3478. 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3479. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  3480. 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3481. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
  3482. 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3483. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
  3484. 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3485. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  3486. 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3487. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
  3488. 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3489. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
  3490. 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3491. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  3492. 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3493. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
  3494. 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3495. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
  3496. 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3497. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  3498. 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3499. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
  3500. 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3501. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
  3502. 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3503. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  3504. 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3505. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
  3506. 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3507. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
  3508. 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3509. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  3510. 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3511. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
  3512. 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3513. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
  3514. 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3515. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  3516. 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3517. };
  3518. BlowFish::BlowFish (const uint8* keyData, int keyBytes)
  3519. {
  3520. memcpy (p, initialPValues, sizeof (p));
  3521. int i, j;
  3522. for (i = 4; --i >= 0;)
  3523. {
  3524. s[i].malloc (256);
  3525. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3526. }
  3527. j = 0;
  3528. for (i = 0; i < 18; ++i)
  3529. {
  3530. uint32 d = 0;
  3531. for (int k = 0; k < 4; ++k)
  3532. {
  3533. d = (d << 8) | keyData[j];
  3534. if (++j >= keyBytes)
  3535. j = 0;
  3536. }
  3537. p[i] = initialPValues[i] ^ d;
  3538. }
  3539. uint32 l = 0, r = 0;
  3540. for (i = 0; i < 18; i += 2)
  3541. {
  3542. encrypt (l, r);
  3543. p[i] = l;
  3544. p[i + 1] = r;
  3545. }
  3546. for (i = 0; i < 4; ++i)
  3547. {
  3548. for (j = 0; j < 256; j += 2)
  3549. {
  3550. encrypt (l, r);
  3551. s[i][j] = l;
  3552. s[i][j + 1] = r;
  3553. }
  3554. }
  3555. }
  3556. BlowFish::BlowFish (const BlowFish& other)
  3557. {
  3558. for (int i = 4; --i >= 0;)
  3559. s[i].malloc (256);
  3560. operator= (other);
  3561. }
  3562. BlowFish& BlowFish::operator= (const BlowFish& other)
  3563. {
  3564. memcpy (p, other.p, sizeof (p));
  3565. for (int i = 4; --i >= 0;)
  3566. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3567. return *this;
  3568. }
  3569. BlowFish::~BlowFish()
  3570. {
  3571. }
  3572. uint32 BlowFish::F (uint32 x) const
  3573. {
  3574. uint16 a, b, c, d;
  3575. uint32 y;
  3576. d = (uint16) (x & 0xff);
  3577. x >>= 8;
  3578. c = (uint16) (x & 0xff);
  3579. x >>= 8;
  3580. b = (uint16) (x & 0xff);
  3581. x >>= 8;
  3582. a = (uint16) (x & 0xff);
  3583. y = s[0][a] + s[1][b];
  3584. y = y ^ s[2][c];
  3585. y = y + s[3][d];
  3586. return y;
  3587. }
  3588. void BlowFish::encrypt (uint32& data1,
  3589. uint32& data2) const
  3590. {
  3591. uint32 l = data1;
  3592. uint32 r = data2;
  3593. for (int i = 0; i < 16; ++i)
  3594. {
  3595. l = l ^ p[i];
  3596. r = F (l) ^ r;
  3597. const uint32 temp = l;
  3598. l = r;
  3599. r = temp;
  3600. }
  3601. const uint32 temp = l;
  3602. l = r;
  3603. r = temp;
  3604. r = r ^ p[16];
  3605. l = l ^ p[17];
  3606. data1 = l;
  3607. data2 = r;
  3608. }
  3609. void BlowFish::decrypt (uint32& data1,
  3610. uint32& data2) const
  3611. {
  3612. uint32 l = data1;
  3613. uint32 r = data2;
  3614. for (int i = 17; i > 1; --i)
  3615. {
  3616. l =l ^ p[i];
  3617. r = F (l) ^ r;
  3618. const uint32 temp = l;
  3619. l = r;
  3620. r = temp;
  3621. }
  3622. const uint32 temp = l;
  3623. l = r;
  3624. r = temp;
  3625. r = r ^ p[1];
  3626. l = l ^ p[0];
  3627. data1 = l;
  3628. data2 = r;
  3629. }
  3630. END_JUCE_NAMESPACE
  3631. /*** End of inlined file: juce_BlowFish.cpp ***/
  3632. /*** Start of inlined file: juce_MD5.cpp ***/
  3633. BEGIN_JUCE_NAMESPACE
  3634. MD5::MD5()
  3635. {
  3636. zerostruct (result);
  3637. }
  3638. MD5::MD5 (const MD5& other)
  3639. {
  3640. memcpy (result, other.result, sizeof (result));
  3641. }
  3642. MD5& MD5::operator= (const MD5& other)
  3643. {
  3644. memcpy (result, other.result, sizeof (result));
  3645. return *this;
  3646. }
  3647. MD5::MD5 (const MemoryBlock& data)
  3648. {
  3649. ProcessContext context;
  3650. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3651. context.finish (result);
  3652. }
  3653. MD5::MD5 (const char* data, const size_t numBytes)
  3654. {
  3655. ProcessContext context;
  3656. context.processBlock ((const uint8*) data, numBytes);
  3657. context.finish (result);
  3658. }
  3659. MD5::MD5 (const String& text)
  3660. {
  3661. ProcessContext context;
  3662. const int len = text.length();
  3663. const juce_wchar* const t = text;
  3664. for (int i = 0; i < len; ++i)
  3665. {
  3666. // force the string into integer-sized unicode characters, to try to make it
  3667. // get the same results on all platforms + compilers.
  3668. uint32 unicodeChar = (uint32) t[i];
  3669. ByteOrder::swapIfBigEndian (unicodeChar);
  3670. context.processBlock ((const uint8*) &unicodeChar,
  3671. sizeof (unicodeChar));
  3672. }
  3673. context.finish (result);
  3674. }
  3675. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3676. {
  3677. ProcessContext context;
  3678. if (numBytesToRead < 0)
  3679. numBytesToRead = std::numeric_limits<int64>::max();
  3680. while (numBytesToRead > 0)
  3681. {
  3682. char tempBuffer [512];
  3683. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3684. if (bytesRead <= 0)
  3685. break;
  3686. numBytesToRead -= bytesRead;
  3687. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3688. }
  3689. context.finish (result);
  3690. }
  3691. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3692. {
  3693. processStream (input, numBytesToRead);
  3694. }
  3695. MD5::MD5 (const File& file)
  3696. {
  3697. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3698. if (fin != 0)
  3699. processStream (*fin, -1);
  3700. else
  3701. zerostruct (result);
  3702. }
  3703. MD5::~MD5()
  3704. {
  3705. }
  3706. namespace MD5Functions
  3707. {
  3708. static void encode (uint8* const output, const uint32* const input, const int numBytes) throw()
  3709. {
  3710. uint32* const o = (uint32*) output;
  3711. for (int i = 0; i < (numBytes >> 2); ++i)
  3712. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3713. }
  3714. static void decode (uint32* const output, const uint8* const input, const int numBytes) throw()
  3715. {
  3716. for (int i = 0; i < (numBytes >> 2); ++i)
  3717. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3718. }
  3719. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3720. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3721. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3722. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3723. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3724. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3725. {
  3726. a += F (b, c, d) + x + ac;
  3727. a = rotateLeft (a, s) + b;
  3728. }
  3729. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3730. {
  3731. a += G (b, c, d) + x + ac;
  3732. a = rotateLeft (a, s) + b;
  3733. }
  3734. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3735. {
  3736. a += H (b, c, d) + x + ac;
  3737. a = rotateLeft (a, s) + b;
  3738. }
  3739. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3740. {
  3741. a += I (b, c, d) + x + ac;
  3742. a = rotateLeft (a, s) + b;
  3743. }
  3744. }
  3745. MD5::ProcessContext::ProcessContext()
  3746. {
  3747. state[0] = 0x67452301;
  3748. state[1] = 0xefcdab89;
  3749. state[2] = 0x98badcfe;
  3750. state[3] = 0x10325476;
  3751. count[0] = 0;
  3752. count[1] = 0;
  3753. }
  3754. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3755. {
  3756. int bufferPos = ((count[0] >> 3) & 0x3F);
  3757. count[0] += (uint32) (dataSize << 3);
  3758. if (count[0] < ((uint32) dataSize << 3))
  3759. count[1]++;
  3760. count[1] += (uint32) (dataSize >> 29);
  3761. const size_t spaceLeft = 64 - bufferPos;
  3762. size_t i = 0;
  3763. if (dataSize >= spaceLeft)
  3764. {
  3765. memcpy (buffer + bufferPos, data, spaceLeft);
  3766. transform (buffer);
  3767. i = spaceLeft;
  3768. while (i + 64 <= dataSize)
  3769. {
  3770. transform (data + i);
  3771. i += 64;
  3772. }
  3773. bufferPos = 0;
  3774. }
  3775. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3776. }
  3777. void MD5::ProcessContext::finish (uint8* const result)
  3778. {
  3779. unsigned char encodedLength[8];
  3780. MD5Functions::encode (encodedLength, count, 8);
  3781. // Pad out to 56 mod 64.
  3782. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3783. const int paddingLength = (index < 56) ? (56 - index)
  3784. : (120 - index);
  3785. uint8 paddingBuffer [64];
  3786. zeromem (paddingBuffer, paddingLength);
  3787. paddingBuffer [0] = 0x80;
  3788. processBlock (paddingBuffer, paddingLength);
  3789. processBlock (encodedLength, 8);
  3790. MD5Functions::encode (result, state, sizeof (result));
  3791. zerostruct (buffer);
  3792. }
  3793. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3794. {
  3795. using namespace MD5Functions;
  3796. uint32 a = state[0];
  3797. uint32 b = state[1];
  3798. uint32 c = state[2];
  3799. uint32 d = state[3];
  3800. uint32 x[16];
  3801. decode (x, bufferToTransform, 64);
  3802. enum Constants
  3803. {
  3804. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3805. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3806. };
  3807. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3808. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3809. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3810. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3811. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3812. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3813. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3814. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3815. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3816. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3817. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3818. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3819. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3820. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3821. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3822. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3823. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3824. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3825. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3826. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3827. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3828. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3829. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3830. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3831. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3832. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3833. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3834. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3835. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3836. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3837. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3838. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3839. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3840. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3841. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3842. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3843. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3844. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3845. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3846. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3847. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3848. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3849. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3850. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3851. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3852. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3853. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3854. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3855. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3856. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3857. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3858. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3859. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3860. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3861. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3862. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3863. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3864. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3865. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3866. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3867. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3868. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3869. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3870. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3871. state[0] += a;
  3872. state[1] += b;
  3873. state[2] += c;
  3874. state[3] += d;
  3875. zerostruct (x);
  3876. }
  3877. const MemoryBlock MD5::getRawChecksumData() const
  3878. {
  3879. return MemoryBlock (result, sizeof (result));
  3880. }
  3881. const String MD5::toHexString() const
  3882. {
  3883. return String::toHexString (result, sizeof (result), 0);
  3884. }
  3885. bool MD5::operator== (const MD5& other) const
  3886. {
  3887. return memcmp (result, other.result, sizeof (result)) == 0;
  3888. }
  3889. bool MD5::operator!= (const MD5& other) const
  3890. {
  3891. return ! operator== (other);
  3892. }
  3893. END_JUCE_NAMESPACE
  3894. /*** End of inlined file: juce_MD5.cpp ***/
  3895. /*** Start of inlined file: juce_Primes.cpp ***/
  3896. BEGIN_JUCE_NAMESPACE
  3897. namespace PrimesHelpers
  3898. {
  3899. static void createSmallSieve (const int numBits, BitArray& result) throw()
  3900. {
  3901. result.setBit (numBits);
  3902. result.clearBit (numBits); // to enlarge the array
  3903. result.setBit (0);
  3904. int n = 2;
  3905. do
  3906. {
  3907. for (int i = n + n; i < numBits; i += n)
  3908. result.setBit (i);
  3909. n = result.findNextClearBit (n + 1);
  3910. }
  3911. while (n <= (numBits >> 1));
  3912. }
  3913. static void bigSieve (const BitArray& base,
  3914. const int numBits,
  3915. BitArray& result,
  3916. const BitArray& smallSieve,
  3917. const int smallSieveSize) throw()
  3918. {
  3919. jassert (! base[0]); // must be even!
  3920. result.setBit (numBits);
  3921. result.clearBit (numBits); // to enlarge the array
  3922. int index = smallSieve.findNextClearBit (0);
  3923. do
  3924. {
  3925. const int prime = (index << 1) + 1;
  3926. BitArray r (base);
  3927. BitArray remainder;
  3928. r.divideBy (prime, remainder);
  3929. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3930. if (r.isEmpty())
  3931. i += prime;
  3932. if ((i & 1) == 0)
  3933. i += prime;
  3934. i = (i - 1) >> 1;
  3935. while (i < numBits)
  3936. {
  3937. result.setBit (i);
  3938. i += prime;
  3939. }
  3940. index = smallSieve.findNextClearBit (index + 1);
  3941. }
  3942. while (index < smallSieveSize);
  3943. }
  3944. static bool findCandidate (const BitArray& base,
  3945. const BitArray& sieve,
  3946. const int numBits,
  3947. BitArray& result,
  3948. const int certainty) throw()
  3949. {
  3950. for (int i = 0; i < numBits; ++i)
  3951. {
  3952. if (! sieve[i])
  3953. {
  3954. result = base;
  3955. result.add (BitArray ((unsigned int) ((i << 1) + 1)));
  3956. if (Primes::isProbablyPrime (result, certainty))
  3957. return true;
  3958. }
  3959. }
  3960. return false;
  3961. }
  3962. }
  3963. const BitArray Primes::createProbablePrime (const int bitLength,
  3964. const int certainty,
  3965. const int* randomSeeds,
  3966. int numRandomSeeds) throw()
  3967. {
  3968. using namespace PrimesHelpers;
  3969. int defaultSeeds [16];
  3970. if (numRandomSeeds <= 0)
  3971. {
  3972. randomSeeds = defaultSeeds;
  3973. numRandomSeeds = numElementsInArray (defaultSeeds);
  3974. Random r (0);
  3975. for (int j = 10; --j >= 0;)
  3976. {
  3977. r.setSeedRandomly();
  3978. for (int i = numRandomSeeds; --i >= 0;)
  3979. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3980. }
  3981. }
  3982. BitArray smallSieve;
  3983. const int smallSieveSize = 15000;
  3984. createSmallSieve (smallSieveSize, smallSieve);
  3985. BitArray p;
  3986. for (int i = numRandomSeeds; --i >= 0;)
  3987. {
  3988. BitArray p2;
  3989. Random r (randomSeeds[i]);
  3990. r.fillBitsRandomly (p2, 0, bitLength);
  3991. p.xorWith (p2);
  3992. }
  3993. p.setBit (bitLength - 1);
  3994. p.clearBit (0);
  3995. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3996. while (p.getHighestBit() < bitLength)
  3997. {
  3998. p.add (2 * searchLen);
  3999. BitArray sieve;
  4000. bigSieve (p, searchLen, sieve,
  4001. smallSieve, smallSieveSize);
  4002. BitArray candidate;
  4003. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  4004. return candidate;
  4005. }
  4006. jassertfalse
  4007. return BitArray();
  4008. }
  4009. static bool passesMillerRabin (const BitArray& n, int iterations) throw()
  4010. {
  4011. using namespace PrimesHelpers;
  4012. const BitArray one (1);
  4013. const BitArray two (2);
  4014. BitArray nMinusOne (n);
  4015. nMinusOne.subtract (one);
  4016. BitArray d (nMinusOne);
  4017. const int s = d.findNextSetBit (0);
  4018. d.shiftBits (-s);
  4019. BitArray smallPrimes;
  4020. int numBitsInSmallPrimes = 0;
  4021. for (;;)
  4022. {
  4023. numBitsInSmallPrimes += 256;
  4024. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  4025. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  4026. if (numPrimesFound > iterations + 1)
  4027. break;
  4028. }
  4029. int smallPrime = 2;
  4030. while (--iterations >= 0)
  4031. {
  4032. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  4033. BitArray r (smallPrime);
  4034. //r.createRandomNumber (nMinusOne);
  4035. r.exponentModulo (d, n);
  4036. if (! (r == one || r == nMinusOne))
  4037. {
  4038. for (int j = 0; j < s; ++j)
  4039. {
  4040. r.exponentModulo (two, n);
  4041. if (r == nMinusOne)
  4042. break;
  4043. }
  4044. if (r != nMinusOne)
  4045. return false;
  4046. }
  4047. }
  4048. return true;
  4049. }
  4050. bool Primes::isProbablyPrime (const BitArray& number,
  4051. const int certainty) throw()
  4052. {
  4053. if (! number[0])
  4054. return false;
  4055. if (number.getHighestBit() <= 10)
  4056. {
  4057. const int num = number.getBitRangeAsInt (0, 10);
  4058. for (int i = num / 2; --i > 1;)
  4059. if (num % i == 0)
  4060. return false;
  4061. return true;
  4062. }
  4063. else
  4064. {
  4065. const BitArray screen (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23);
  4066. if (number.findGreatestCommonDivisor (screen) != BitArray (1))
  4067. return false;
  4068. return passesMillerRabin (number, certainty);
  4069. }
  4070. }
  4071. END_JUCE_NAMESPACE
  4072. /*** End of inlined file: juce_Primes.cpp ***/
  4073. /*** Start of inlined file: juce_RSAKey.cpp ***/
  4074. BEGIN_JUCE_NAMESPACE
  4075. RSAKey::RSAKey() throw()
  4076. {
  4077. }
  4078. RSAKey::RSAKey (const String& s) throw()
  4079. {
  4080. if (s.containsChar (T(',')))
  4081. {
  4082. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  4083. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  4084. }
  4085. else
  4086. {
  4087. // the string needs to be two hex numbers, comma-separated..
  4088. jassertfalse;
  4089. }
  4090. }
  4091. RSAKey::~RSAKey() throw()
  4092. {
  4093. }
  4094. const String RSAKey::toString() const throw()
  4095. {
  4096. return part1.toString (16) + T(",") + part2.toString (16);
  4097. }
  4098. bool RSAKey::applyToValue (BitArray& value) const throw()
  4099. {
  4100. if (part1.isEmpty() || part2.isEmpty()
  4101. || value.compare (0) <= 0)
  4102. {
  4103. jassertfalse // using an uninitialised key
  4104. value.clear();
  4105. return false;
  4106. }
  4107. BitArray result;
  4108. while (! value.isEmpty())
  4109. {
  4110. result.multiplyBy (part2);
  4111. BitArray remainder;
  4112. value.divideBy (part2, remainder);
  4113. remainder.exponentModulo (part1, part2);
  4114. result.add (remainder);
  4115. }
  4116. value = result;
  4117. return true;
  4118. }
  4119. static const BitArray findBestCommonDivisor (const BitArray& p,
  4120. const BitArray& q) throw()
  4121. {
  4122. const BitArray one (1);
  4123. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  4124. // are fast to divide + multiply
  4125. for (int i = 2; i <= 65536; i *= 2)
  4126. {
  4127. const BitArray e (1 + i);
  4128. if (e.findGreatestCommonDivisor (p) == one
  4129. && e.findGreatestCommonDivisor (q) == one)
  4130. {
  4131. return e;
  4132. }
  4133. }
  4134. BitArray e (4);
  4135. while (! (e.findGreatestCommonDivisor (p) == one
  4136. && e.findGreatestCommonDivisor (q) == one))
  4137. {
  4138. e.add (one);
  4139. }
  4140. return e;
  4141. }
  4142. void RSAKey::createKeyPair (RSAKey& publicKey,
  4143. RSAKey& privateKey,
  4144. const int numBits,
  4145. const int* randomSeeds,
  4146. const int numRandomSeeds) throw()
  4147. {
  4148. jassert (numBits > 16); // not much point using less than this..
  4149. BitArray p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4150. BitArray q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4151. BitArray n (p);
  4152. n.multiplyBy (q); // n = pq
  4153. const BitArray one (1);
  4154. p.subtract (one);
  4155. q.subtract (one);
  4156. BitArray m (p);
  4157. m.multiplyBy (q); // m = (p - 1)(q - 1)
  4158. const BitArray e (findBestCommonDivisor (p, q));
  4159. BitArray d (e);
  4160. d.inverseModulo (m);
  4161. publicKey.part1 = e;
  4162. publicKey.part2 = n;
  4163. privateKey.part1 = d;
  4164. privateKey.part2 = n;
  4165. }
  4166. END_JUCE_NAMESPACE
  4167. /*** End of inlined file: juce_RSAKey.cpp ***/
  4168. /*** Start of inlined file: juce_InputStream.cpp ***/
  4169. BEGIN_JUCE_NAMESPACE
  4170. char InputStream::readByte()
  4171. {
  4172. char temp = 0;
  4173. read (&temp, 1);
  4174. return temp;
  4175. }
  4176. bool InputStream::readBool()
  4177. {
  4178. return readByte() != 0;
  4179. }
  4180. short InputStream::readShort()
  4181. {
  4182. char temp [2];
  4183. if (read (temp, 2) == 2)
  4184. return (short) ByteOrder::littleEndianShort (temp);
  4185. else
  4186. return 0;
  4187. }
  4188. short InputStream::readShortBigEndian()
  4189. {
  4190. char temp [2];
  4191. if (read (temp, 2) == 2)
  4192. return (short) ByteOrder::bigEndianShort (temp);
  4193. else
  4194. return 0;
  4195. }
  4196. int InputStream::readInt()
  4197. {
  4198. char temp [4];
  4199. if (read (temp, 4) == 4)
  4200. return (int) ByteOrder::littleEndianInt (temp);
  4201. else
  4202. return 0;
  4203. }
  4204. int InputStream::readIntBigEndian()
  4205. {
  4206. char temp [4];
  4207. if (read (temp, 4) == 4)
  4208. return (int) ByteOrder::bigEndianInt (temp);
  4209. else
  4210. return 0;
  4211. }
  4212. int InputStream::readCompressedInt()
  4213. {
  4214. const unsigned char sizeByte = readByte();
  4215. if (sizeByte == 0)
  4216. return 0;
  4217. const int numBytes = (sizeByte & 0x7f);
  4218. if (numBytes > 4)
  4219. {
  4220. jassertfalse // trying to read corrupt data - this method must only be used
  4221. // to read data that was written by OutputStream::writeCompressedInt()
  4222. return 0;
  4223. }
  4224. char bytes[4] = { 0, 0, 0, 0 };
  4225. if (read (bytes, numBytes) != numBytes)
  4226. return 0;
  4227. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4228. return (sizeByte >> 7) ? -num : num;
  4229. }
  4230. int64 InputStream::readInt64()
  4231. {
  4232. char temp [8];
  4233. if (read (temp, 8) == 8)
  4234. return (int64) ByteOrder::swapIfBigEndian (*(uint64*) temp);
  4235. else
  4236. return 0;
  4237. }
  4238. int64 InputStream::readInt64BigEndian()
  4239. {
  4240. char temp [8];
  4241. if (read (temp, 8) == 8)
  4242. return (int64) ByteOrder::swapIfLittleEndian (*(uint64*) temp);
  4243. else
  4244. return 0;
  4245. }
  4246. float InputStream::readFloat()
  4247. {
  4248. union { int asInt; float asFloat; } n;
  4249. n.asInt = readInt();
  4250. return n.asFloat;
  4251. }
  4252. float InputStream::readFloatBigEndian()
  4253. {
  4254. union { int asInt; float asFloat; } n;
  4255. n.asInt = readIntBigEndian();
  4256. return n.asFloat;
  4257. }
  4258. double InputStream::readDouble()
  4259. {
  4260. union { int64 asInt; double asDouble; } n;
  4261. n.asInt = readInt64();
  4262. return n.asDouble;
  4263. }
  4264. double InputStream::readDoubleBigEndian()
  4265. {
  4266. union { int64 asInt; double asDouble; } n;
  4267. n.asInt = readInt64BigEndian();
  4268. return n.asDouble;
  4269. }
  4270. const String InputStream::readString()
  4271. {
  4272. MemoryBlock buffer (256);
  4273. char* data = (char*) buffer.getData();
  4274. size_t i = 0;
  4275. while ((data[i] = readByte()) != 0)
  4276. {
  4277. if (++i >= buffer.getSize())
  4278. {
  4279. buffer.setSize (buffer.getSize() + 512);
  4280. data = (char*) buffer.getData();
  4281. }
  4282. }
  4283. return String::fromUTF8 (data, (int) i);
  4284. }
  4285. const String InputStream::readNextLine()
  4286. {
  4287. MemoryBlock buffer (256);
  4288. char* data = (char*) buffer.getData();
  4289. size_t i = 0;
  4290. while ((data[i] = readByte()) != 0)
  4291. {
  4292. if (data[i] == '\n')
  4293. break;
  4294. if (data[i] == '\r')
  4295. {
  4296. const int64 lastPos = getPosition();
  4297. if (readByte() != '\n')
  4298. setPosition (lastPos);
  4299. break;
  4300. }
  4301. if (++i >= buffer.getSize())
  4302. {
  4303. buffer.setSize (buffer.getSize() + 512);
  4304. data = (char*) buffer.getData();
  4305. }
  4306. }
  4307. return String::fromUTF8 (data, (int) i);
  4308. }
  4309. int InputStream::readIntoMemoryBlock (MemoryBlock& block,
  4310. int numBytes)
  4311. {
  4312. const int64 totalLength = getTotalLength();
  4313. if (totalLength >= 0)
  4314. {
  4315. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4316. totalLength - getPosition());
  4317. if (numBytes < 0)
  4318. numBytes = totalBytesRemaining;
  4319. else if (numBytes > 0)
  4320. numBytes = jmin (numBytes, totalBytesRemaining);
  4321. else
  4322. return 0;
  4323. }
  4324. const size_t originalBlockSize = block.getSize();
  4325. int totalBytesRead = 0;
  4326. if (numBytes > 0)
  4327. {
  4328. // know how many bytes we want, so we can resize the block first..
  4329. block.setSize (originalBlockSize + numBytes, false);
  4330. totalBytesRead = read (((char*) block.getData()) + originalBlockSize, numBytes);
  4331. }
  4332. else
  4333. {
  4334. // read until end of stram..
  4335. const int chunkSize = 32768;
  4336. for (;;)
  4337. {
  4338. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4339. const int bytesJustIn = read (((char*) block.getData())
  4340. + originalBlockSize
  4341. + totalBytesRead,
  4342. chunkSize);
  4343. if (bytesJustIn == 0)
  4344. break;
  4345. totalBytesRead += bytesJustIn;
  4346. }
  4347. }
  4348. // trim off any excess left at the end
  4349. block.setSize (originalBlockSize + totalBytesRead, false);
  4350. return totalBytesRead;
  4351. }
  4352. const String InputStream::readEntireStreamAsString()
  4353. {
  4354. MemoryBlock mb;
  4355. const int size = readIntoMemoryBlock (mb);
  4356. return String::createStringFromData ((const char*) mb.getData(), size);
  4357. }
  4358. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4359. {
  4360. if (numBytesToSkip > 0)
  4361. {
  4362. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4363. HeapBlock <char> temp (skipBufferSize);
  4364. while (numBytesToSkip > 0 && ! isExhausted())
  4365. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4366. }
  4367. }
  4368. END_JUCE_NAMESPACE
  4369. /*** End of inlined file: juce_InputStream.cpp ***/
  4370. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4371. BEGIN_JUCE_NAMESPACE
  4372. #if JUCE_DEBUG
  4373. static CriticalSection activeStreamLock;
  4374. static VoidArray activeStreams;
  4375. void juce_CheckForDanglingStreams()
  4376. {
  4377. /*
  4378. It's always a bad idea to leak any object, but if you're leaking output
  4379. streams, then there's a good chance that you're failing to flush a file
  4380. to disk properly, which could result in corrupted data and other similar
  4381. nastiness..
  4382. */
  4383. jassert (activeStreams.size() == 0);
  4384. };
  4385. #endif
  4386. OutputStream::OutputStream()
  4387. {
  4388. #if JUCE_DEBUG
  4389. const ScopedLock sl (activeStreamLock);
  4390. activeStreams.add (this);
  4391. #endif
  4392. }
  4393. OutputStream::~OutputStream()
  4394. {
  4395. #if JUCE_DEBUG
  4396. const ScopedLock sl (activeStreamLock);
  4397. activeStreams.removeValue (this);
  4398. #endif
  4399. }
  4400. void OutputStream::writeBool (bool b)
  4401. {
  4402. writeByte ((b) ? (char) 1
  4403. : (char) 0);
  4404. }
  4405. void OutputStream::writeByte (char byte)
  4406. {
  4407. write (&byte, 1);
  4408. }
  4409. void OutputStream::writeShort (short value)
  4410. {
  4411. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4412. write (&v, 2);
  4413. }
  4414. void OutputStream::writeShortBigEndian (short value)
  4415. {
  4416. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4417. write (&v, 2);
  4418. }
  4419. void OutputStream::writeInt (int value)
  4420. {
  4421. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4422. write (&v, 4);
  4423. }
  4424. void OutputStream::writeIntBigEndian (int value)
  4425. {
  4426. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4427. write (&v, 4);
  4428. }
  4429. void OutputStream::writeCompressedInt (int value)
  4430. {
  4431. unsigned int un = (value < 0) ? (unsigned int) -value
  4432. : (unsigned int) value;
  4433. uint8 data[5];
  4434. int num = 0;
  4435. while (un > 0)
  4436. {
  4437. data[++num] = (uint8) un;
  4438. un >>= 8;
  4439. }
  4440. data[0] = (uint8) num;
  4441. if (value < 0)
  4442. data[0] |= 0x80;
  4443. write (data, num + 1);
  4444. }
  4445. void OutputStream::writeInt64 (int64 value)
  4446. {
  4447. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4448. write (&v, 8);
  4449. }
  4450. void OutputStream::writeInt64BigEndian (int64 value)
  4451. {
  4452. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4453. write (&v, 8);
  4454. }
  4455. void OutputStream::writeFloat (float value)
  4456. {
  4457. union { int asInt; float asFloat; } n;
  4458. n.asFloat = value;
  4459. writeInt (n.asInt);
  4460. }
  4461. void OutputStream::writeFloatBigEndian (float value)
  4462. {
  4463. union { int asInt; float asFloat; } n;
  4464. n.asFloat = value;
  4465. writeIntBigEndian (n.asInt);
  4466. }
  4467. void OutputStream::writeDouble (double value)
  4468. {
  4469. union { int64 asInt; double asDouble; } n;
  4470. n.asDouble = value;
  4471. writeInt64 (n.asInt);
  4472. }
  4473. void OutputStream::writeDoubleBigEndian (double value)
  4474. {
  4475. union { int64 asInt; double asDouble; } n;
  4476. n.asDouble = value;
  4477. writeInt64BigEndian (n.asInt);
  4478. }
  4479. void OutputStream::writeString (const String& text)
  4480. {
  4481. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4482. // if lots of large, persistent strings were to be written to streams).
  4483. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4484. HeapBlock<char> temp (numBytes);
  4485. text.copyToUTF8 (temp, numBytes);
  4486. write (temp, numBytes);
  4487. }
  4488. void OutputStream::writeText (const String& text, const bool asUnicode,
  4489. const bool writeUnicodeHeaderBytes)
  4490. {
  4491. if (asUnicode)
  4492. {
  4493. if (writeUnicodeHeaderBytes)
  4494. write ("\x0ff\x0fe", 2);
  4495. const juce_wchar* src = (const juce_wchar*) text;
  4496. bool lastCharWasReturn = false;
  4497. while (*src != 0)
  4498. {
  4499. if (*src == L'\n' && ! lastCharWasReturn)
  4500. writeShort ((short) L'\r');
  4501. lastCharWasReturn = (*src == L'\r');
  4502. writeShort ((short) *src++);
  4503. }
  4504. }
  4505. else
  4506. {
  4507. const char* src = text.toUTF8();
  4508. const char* t = src;
  4509. for (;;)
  4510. {
  4511. if (*t == '\n')
  4512. {
  4513. if (t > src)
  4514. write (src, (int) (t - src));
  4515. write ("\r\n", 2);
  4516. src = t + 1;
  4517. }
  4518. else if (*t == '\r')
  4519. {
  4520. if (t[1] == '\n')
  4521. ++t;
  4522. }
  4523. else if (*t == 0)
  4524. {
  4525. if (t > src)
  4526. write (src, (int) (t - src));
  4527. break;
  4528. }
  4529. ++t;
  4530. }
  4531. }
  4532. }
  4533. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4534. {
  4535. if (numBytesToWrite < 0)
  4536. numBytesToWrite = 0x7fffffff;
  4537. int numWritten = 0;
  4538. while (numBytesToWrite > 0 && ! source.isExhausted())
  4539. {
  4540. char buffer [8192];
  4541. const int num = source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4542. if (num == 0)
  4543. break;
  4544. write (buffer, num);
  4545. numBytesToWrite -= num;
  4546. numWritten += num;
  4547. }
  4548. return numWritten;
  4549. }
  4550. OutputStream& operator<< (OutputStream& stream, const int number)
  4551. {
  4552. return stream << String (number);
  4553. }
  4554. OutputStream& operator<< (OutputStream& stream, const double number)
  4555. {
  4556. return stream << String (number);
  4557. }
  4558. OutputStream& operator<< (OutputStream& stream, const char character)
  4559. {
  4560. stream.writeByte (character);
  4561. return stream;
  4562. }
  4563. OutputStream& operator<< (OutputStream& stream, const char* const text)
  4564. {
  4565. stream.write (text, (int) strlen (text));
  4566. return stream;
  4567. }
  4568. END_JUCE_NAMESPACE
  4569. /*** End of inlined file: juce_OutputStream.cpp ***/
  4570. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4571. BEGIN_JUCE_NAMESPACE
  4572. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4573. bool* isDirectory, bool* isHidden, int64* fileSize,
  4574. Time* modTime, Time* creationTime, bool* isReadOnly);
  4575. bool juce_findFileNext (void* handle, String& resultFile,
  4576. bool* isDirectory, bool* isHidden, int64* fileSize,
  4577. Time* modTime, Time* creationTime, bool* isReadOnly);
  4578. void juce_findFileClose (void* handle);
  4579. DirectoryIterator::DirectoryIterator (const File& directory,
  4580. bool isRecursive,
  4581. const String& wc,
  4582. const int whatToLookFor_)
  4583. : wildCard (wc),
  4584. index (-1),
  4585. whatToLookFor (whatToLookFor_)
  4586. {
  4587. // you have to specify the type of files you're looking for!
  4588. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4589. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4590. String path (directory.getFullPathName());
  4591. if (! path.endsWithChar (File::separator))
  4592. path += File::separator;
  4593. String filename;
  4594. bool isDirectory, isHidden;
  4595. void* const handle = juce_findFileStart (path,
  4596. isRecursive ? T("*") : wc,
  4597. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4598. if (handle != 0)
  4599. {
  4600. do
  4601. {
  4602. if (! filename.containsOnly (T(".")))
  4603. {
  4604. bool addToList = false;
  4605. if (isDirectory)
  4606. {
  4607. if (isRecursive
  4608. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4609. || ! isHidden))
  4610. {
  4611. dirsFound.add (File (path + filename, 0));
  4612. }
  4613. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4614. }
  4615. else
  4616. {
  4617. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4618. }
  4619. // if it's recursive, we're not relying on the OS iterator
  4620. // to do the wildcard match, so do it now..
  4621. if (isRecursive && addToList)
  4622. addToList = filename.matchesWildcard (wc, true);
  4623. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4624. addToList = ! isHidden;
  4625. if (addToList)
  4626. filesFound.add (File (path + filename, 0));
  4627. }
  4628. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4629. juce_findFileClose (handle);
  4630. }
  4631. }
  4632. DirectoryIterator::~DirectoryIterator()
  4633. {
  4634. }
  4635. bool DirectoryIterator::next()
  4636. {
  4637. if (subIterator != 0)
  4638. {
  4639. if (subIterator->next())
  4640. return true;
  4641. subIterator = 0;
  4642. }
  4643. if (index >= filesFound.size() + dirsFound.size() - 1)
  4644. return false;
  4645. ++index;
  4646. if (index >= filesFound.size())
  4647. {
  4648. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4649. true, wildCard, whatToLookFor);
  4650. return next();
  4651. }
  4652. return true;
  4653. }
  4654. const File DirectoryIterator::getFile() const
  4655. {
  4656. if (subIterator != 0)
  4657. return subIterator->getFile();
  4658. return filesFound [index];
  4659. }
  4660. float DirectoryIterator::getEstimatedProgress() const
  4661. {
  4662. if (filesFound.size() + dirsFound.size() == 0)
  4663. {
  4664. return 0.0f;
  4665. }
  4666. else
  4667. {
  4668. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4669. : (float) index;
  4670. return detailedIndex / (filesFound.size() + dirsFound.size());
  4671. }
  4672. }
  4673. END_JUCE_NAMESPACE
  4674. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4675. /*** Start of inlined file: juce_File.cpp ***/
  4676. #ifdef _MSC_VER
  4677. #pragma warning (disable: 4514)
  4678. #pragma warning (push)
  4679. #endif
  4680. #if ! JUCE_WINDOWS
  4681. #include <pwd.h>
  4682. #endif
  4683. BEGIN_JUCE_NAMESPACE
  4684. #ifdef _MSC_VER
  4685. #pragma warning (pop)
  4686. #endif
  4687. void* juce_fileOpen (const String& path, bool forWriting);
  4688. void juce_fileClose (void* handle);
  4689. int juce_fileWrite (void* handle, const void* buffer, int size);
  4690. int64 juce_fileGetPosition (void* handle);
  4691. int64 juce_fileSetPosition (void* handle, int64 pos);
  4692. void juce_fileFlush (void* handle);
  4693. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4694. bool juce_isDirectory (const String& fileName);
  4695. int64 juce_getFileSize (const String& fileName);
  4696. bool juce_canWriteToFile (const String& fileName);
  4697. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4698. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4699. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4700. bool juce_deleteFile (const String& fileName);
  4701. bool juce_copyFile (const String& source, const String& dest);
  4702. bool juce_moveFile (const String& source, const String& dest);
  4703. // this must also create all paths involved in the directory.
  4704. void juce_createDirectory (const String& fileName);
  4705. bool juce_launchFile (const String& fileName, const String& parameters);
  4706. const StringArray juce_getFileSystemRoots();
  4707. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4708. // starts a directory search operation with a wildcard, returning a handle for
  4709. // use in calls to juce_findFileNext.
  4710. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4711. // the other pointers, if non-null, are set based on the properties of the file.
  4712. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4713. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4714. Time* creationTime, bool* isReadOnly);
  4715. // returns false when no more files are found
  4716. bool juce_findFileNext (void* handle, String& resultFile,
  4717. bool* isDirectory, bool* isHidden, int64* fileSize,
  4718. Time* modTime, Time* creationTime, bool* isReadOnly);
  4719. void juce_findFileClose (void* handle);
  4720. static const String juce_addTrailingSeparator (const String& path)
  4721. {
  4722. return path.endsWithChar (File::separator) ? path
  4723. : path + File::separator;
  4724. }
  4725. static const String parseAbsolutePath (String path)
  4726. {
  4727. if (path.isEmpty())
  4728. return String::empty;
  4729. #if JUCE_WINDOWS
  4730. // Windows..
  4731. path = path.replaceCharacter (T('/'), T('\\'));
  4732. if (path.startsWithChar (File::separator))
  4733. {
  4734. if (path[1] != File::separator)
  4735. {
  4736. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4737. If you're trying to parse a string that may be either a relative path or an absolute path,
  4738. you MUST provide a context against which the partial path can be evaluated - you can do
  4739. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4740. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4741. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4742. */
  4743. jassertfalse
  4744. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4745. }
  4746. }
  4747. else if (path.indexOfChar (T(':')) < 0)
  4748. {
  4749. if (path.isEmpty())
  4750. return String::empty;
  4751. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4752. If you're trying to parse a string that may be either a relative path or an absolute path,
  4753. you MUST provide a context against which the partial path can be evaluated - you can do
  4754. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4755. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4756. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4757. */
  4758. jassertfalse
  4759. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4760. }
  4761. #else
  4762. // Mac or Linux..
  4763. path = path.replaceCharacter (T('\\'), T('/'));
  4764. if (path.startsWithChar (T('~')))
  4765. {
  4766. const char* homeDir = 0;
  4767. if (path[1] == File::separator || path[1] == 0)
  4768. {
  4769. // expand a name of the form "~/abc"
  4770. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4771. + path.substring (1);
  4772. }
  4773. else
  4774. {
  4775. // expand a name of type "~dave/abc"
  4776. const String userName (path.substring (1).upToFirstOccurrenceOf (T("/"), false, false));
  4777. struct passwd* const pw = getpwnam (userName.toUTF8());
  4778. if (pw != 0)
  4779. {
  4780. String home (homeDir);
  4781. if (home.endsWithChar (File::separator))
  4782. home [home.length() - 1] = 0;
  4783. path = String (pw->pw_dir)
  4784. + path.substring (userName.length());
  4785. }
  4786. }
  4787. }
  4788. else if (! path.startsWithChar (File::separator))
  4789. {
  4790. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4791. If you're trying to parse a string that may be either a relative path or an absolute path,
  4792. you MUST provide a context against which the partial path can be evaluated - you can do
  4793. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4794. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4795. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4796. */
  4797. jassert (path.startsWith (T("./"))); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4798. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4799. }
  4800. #endif
  4801. int len = path.length();
  4802. while (--len > 0 && path [len] == File::separator)
  4803. path [len] = 0;
  4804. return path;
  4805. }
  4806. const File File::nonexistent;
  4807. File::File (const String& fullPathName)
  4808. : fullPath (parseAbsolutePath (fullPathName))
  4809. {
  4810. }
  4811. File::File (const String& path, int)
  4812. : fullPath (path)
  4813. {
  4814. }
  4815. const File File::createFileWithoutCheckingPath (const String& path)
  4816. {
  4817. return File (path, 0);
  4818. }
  4819. File::File (const File& other)
  4820. : fullPath (other.fullPath)
  4821. {
  4822. }
  4823. File& File::operator= (const String& newPath)
  4824. {
  4825. fullPath = parseAbsolutePath (newPath);
  4826. return *this;
  4827. }
  4828. File& File::operator= (const File& other)
  4829. {
  4830. fullPath = other.fullPath;
  4831. return *this;
  4832. }
  4833. #if JUCE_LINUX
  4834. #define NAMES_ARE_CASE_SENSITIVE 1
  4835. #endif
  4836. bool File::areFileNamesCaseSensitive()
  4837. {
  4838. #if NAMES_ARE_CASE_SENSITIVE
  4839. return true;
  4840. #else
  4841. return false;
  4842. #endif
  4843. }
  4844. bool File::operator== (const File& other) const
  4845. {
  4846. // case-insensitive on Windows, but not on linux.
  4847. #if NAMES_ARE_CASE_SENSITIVE
  4848. return fullPath == other.fullPath;
  4849. #else
  4850. return fullPath.equalsIgnoreCase (other.fullPath);
  4851. #endif
  4852. }
  4853. bool File::operator!= (const File& other) const
  4854. {
  4855. return ! operator== (other);
  4856. }
  4857. bool File::exists() const
  4858. {
  4859. return juce_fileExists (fullPath, false);
  4860. }
  4861. bool File::existsAsFile() const
  4862. {
  4863. return juce_fileExists (fullPath, true);
  4864. }
  4865. bool File::isDirectory() const
  4866. {
  4867. return juce_isDirectory (fullPath);
  4868. }
  4869. bool File::hasWriteAccess() const
  4870. {
  4871. if (exists())
  4872. return juce_canWriteToFile (fullPath);
  4873. #if ! JUCE_WINDOWS
  4874. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4875. return getParentDirectory().hasWriteAccess();
  4876. else
  4877. return false;
  4878. #else
  4879. // on windows, it seems that even read-only directories can still be written into,
  4880. // so checking the parent directory's permissions would return the wrong result..
  4881. else
  4882. return true;
  4883. #endif
  4884. }
  4885. bool File::setReadOnly (const bool shouldBeReadOnly,
  4886. const bool applyRecursively) const
  4887. {
  4888. bool worked = true;
  4889. if (applyRecursively && isDirectory())
  4890. {
  4891. Array <File> subFiles;
  4892. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4893. for (int i = subFiles.size(); --i >= 0;)
  4894. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4895. }
  4896. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4897. }
  4898. bool File::deleteFile() const
  4899. {
  4900. return (! exists())
  4901. || juce_deleteFile (fullPath);
  4902. }
  4903. bool File::deleteRecursively() const
  4904. {
  4905. bool worked = true;
  4906. if (isDirectory())
  4907. {
  4908. Array<File> subFiles;
  4909. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4910. for (int i = subFiles.size(); --i >= 0;)
  4911. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4912. }
  4913. return deleteFile() && worked;
  4914. }
  4915. bool File::moveFileTo (const File& newFile) const
  4916. {
  4917. if (newFile.fullPath == fullPath)
  4918. return true;
  4919. #if ! NAMES_ARE_CASE_SENSITIVE
  4920. if (*this != newFile)
  4921. #endif
  4922. if (! newFile.deleteFile())
  4923. return false;
  4924. return juce_moveFile (fullPath, newFile.fullPath);
  4925. }
  4926. bool File::copyFileTo (const File& newFile) const
  4927. {
  4928. if (*this == newFile)
  4929. return true;
  4930. if (! newFile.deleteFile())
  4931. return false;
  4932. return juce_copyFile (fullPath, newFile.fullPath);
  4933. }
  4934. bool File::copyDirectoryTo (const File& newDirectory) const
  4935. {
  4936. if (isDirectory() && newDirectory.createDirectory())
  4937. {
  4938. Array<File> subFiles;
  4939. findChildFiles (subFiles, File::findFiles, false);
  4940. int i;
  4941. for (i = 0; i < subFiles.size(); ++i)
  4942. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4943. return false;
  4944. subFiles.clear();
  4945. findChildFiles (subFiles, File::findDirectories, false);
  4946. for (i = 0; i < subFiles.size(); ++i)
  4947. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4948. return false;
  4949. return true;
  4950. }
  4951. return false;
  4952. }
  4953. const String File::getPathUpToLastSlash() const
  4954. {
  4955. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4956. if (lastSlash > 0)
  4957. return fullPath.substring (0, lastSlash);
  4958. else if (lastSlash == 0)
  4959. return separatorString;
  4960. else
  4961. return fullPath;
  4962. }
  4963. const File File::getParentDirectory() const
  4964. {
  4965. return File (getPathUpToLastSlash());
  4966. }
  4967. const String File::getFileName() const
  4968. {
  4969. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4970. }
  4971. int File::hashCode() const
  4972. {
  4973. return fullPath.hashCode();
  4974. }
  4975. int64 File::hashCode64() const
  4976. {
  4977. return fullPath.hashCode64();
  4978. }
  4979. const String File::getFileNameWithoutExtension() const
  4980. {
  4981. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4982. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  4983. if (lastDot > lastSlash)
  4984. return fullPath.substring (lastSlash, lastDot);
  4985. else
  4986. return fullPath.substring (lastSlash);
  4987. }
  4988. bool File::isAChildOf (const File& potentialParent) const
  4989. {
  4990. if (potentialParent == File::nonexistent)
  4991. return false;
  4992. const String ourPath (getPathUpToLastSlash());
  4993. #if NAMES_ARE_CASE_SENSITIVE
  4994. if (potentialParent.fullPath == ourPath)
  4995. #else
  4996. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4997. #endif
  4998. {
  4999. return true;
  5000. }
  5001. else if (potentialParent.fullPath.length() >= ourPath.length())
  5002. {
  5003. return false;
  5004. }
  5005. else
  5006. {
  5007. return getParentDirectory().isAChildOf (potentialParent);
  5008. }
  5009. }
  5010. bool File::isAbsolutePath (const String& path)
  5011. {
  5012. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  5013. #if JUCE_WINDOWS
  5014. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  5015. #else
  5016. || path.startsWithChar (T('~'));
  5017. #endif
  5018. }
  5019. const File File::getChildFile (String relativePath) const
  5020. {
  5021. if (isAbsolutePath (relativePath))
  5022. {
  5023. // the path is really absolute..
  5024. return File (relativePath);
  5025. }
  5026. else
  5027. {
  5028. // it's relative, so remove any ../ or ./ bits at the start.
  5029. String path (fullPath);
  5030. if (relativePath[0] == T('.'))
  5031. {
  5032. #if JUCE_WINDOWS
  5033. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  5034. #else
  5035. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  5036. #endif
  5037. while (relativePath[0] == T('.'))
  5038. {
  5039. if (relativePath[1] == T('.'))
  5040. {
  5041. if (relativePath [2] == 0 || relativePath[2] == separator)
  5042. {
  5043. const int lastSlash = path.lastIndexOfChar (separator);
  5044. if (lastSlash >= 0)
  5045. path = path.substring (0, lastSlash);
  5046. relativePath = relativePath.substring (3);
  5047. }
  5048. else
  5049. {
  5050. break;
  5051. }
  5052. }
  5053. else if (relativePath[1] == separator)
  5054. {
  5055. relativePath = relativePath.substring (2);
  5056. }
  5057. else
  5058. {
  5059. break;
  5060. }
  5061. }
  5062. }
  5063. return File (juce_addTrailingSeparator (path) + relativePath);
  5064. }
  5065. }
  5066. const File File::getSiblingFile (const String& fileName) const
  5067. {
  5068. return getParentDirectory().getChildFile (fileName);
  5069. }
  5070. int64 File::getSize() const
  5071. {
  5072. return juce_getFileSize (fullPath);
  5073. }
  5074. const String File::descriptionOfSizeInBytes (const int64 bytes)
  5075. {
  5076. if (bytes == 1)
  5077. {
  5078. return "1 byte";
  5079. }
  5080. else if (bytes < 1024)
  5081. {
  5082. return String ((int) bytes) + " bytes";
  5083. }
  5084. else if (bytes < 1024 * 1024)
  5085. {
  5086. return String (bytes / 1024.0, 1) + " KB";
  5087. }
  5088. else if (bytes < 1024 * 1024 * 1024)
  5089. {
  5090. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  5091. }
  5092. else
  5093. {
  5094. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  5095. }
  5096. }
  5097. bool File::create() const
  5098. {
  5099. if (! exists())
  5100. {
  5101. const File parentDir (getParentDirectory());
  5102. if (parentDir == *this || ! parentDir.createDirectory())
  5103. return false;
  5104. void* const fh = juce_fileOpen (fullPath, true);
  5105. if (fh == 0)
  5106. return false;
  5107. juce_fileClose (fh);
  5108. }
  5109. return true;
  5110. }
  5111. bool File::createDirectory() const
  5112. {
  5113. if (! isDirectory())
  5114. {
  5115. const File parentDir (getParentDirectory());
  5116. if (parentDir == *this || ! parentDir.createDirectory())
  5117. return false;
  5118. String dir (fullPath);
  5119. while (dir.endsWithChar (separator))
  5120. dir [dir.length() - 1] = 0;
  5121. juce_createDirectory (dir);
  5122. return isDirectory();
  5123. }
  5124. return true;
  5125. }
  5126. const Time File::getCreationTime() const
  5127. {
  5128. int64 m, a, c;
  5129. juce_getFileTimes (fullPath, m, a, c);
  5130. return Time (c);
  5131. }
  5132. bool File::setCreationTime (const Time& t) const
  5133. {
  5134. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  5135. }
  5136. const Time File::getLastModificationTime() const
  5137. {
  5138. int64 m, a, c;
  5139. juce_getFileTimes (fullPath, m, a, c);
  5140. return Time (m);
  5141. }
  5142. bool File::setLastModificationTime (const Time& t) const
  5143. {
  5144. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5145. }
  5146. const Time File::getLastAccessTime() const
  5147. {
  5148. int64 m, a, c;
  5149. juce_getFileTimes (fullPath, m, a, c);
  5150. return Time (a);
  5151. }
  5152. bool File::setLastAccessTime (const Time& t) const
  5153. {
  5154. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5155. }
  5156. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5157. {
  5158. if (! existsAsFile())
  5159. return false;
  5160. FileInputStream in (*this);
  5161. return getSize() == in.readIntoMemoryBlock (destBlock);
  5162. }
  5163. const String File::loadFileAsString() const
  5164. {
  5165. if (! existsAsFile())
  5166. return String::empty;
  5167. FileInputStream in (*this);
  5168. return in.readEntireStreamAsString();
  5169. }
  5170. static inline bool fileTypeMatches (const int whatToLookFor,
  5171. const bool isDir,
  5172. const bool isHidden)
  5173. {
  5174. return (whatToLookFor & (isDir ? File::findDirectories
  5175. : File::findFiles)) != 0
  5176. && ((! isHidden)
  5177. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5178. }
  5179. int File::findChildFiles (Array<File>& results,
  5180. const int whatToLookFor,
  5181. const bool searchRecursively,
  5182. const String& wildCardPattern) const
  5183. {
  5184. // you have to specify the type of files you're looking for!
  5185. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5186. int total = 0;
  5187. // find child files or directories in this directory first..
  5188. if (isDirectory())
  5189. {
  5190. const String path (juce_addTrailingSeparator (fullPath));
  5191. String filename;
  5192. bool itemIsDirectory, itemIsHidden;
  5193. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5194. &itemIsDirectory, &itemIsHidden,
  5195. 0, 0, 0, 0);
  5196. if (handle != 0)
  5197. {
  5198. do
  5199. {
  5200. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5201. && ! filename.containsOnly (T(".")))
  5202. {
  5203. results.add (File (path + filename, 0));
  5204. ++total;
  5205. }
  5206. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5207. juce_findFileClose (handle);
  5208. }
  5209. }
  5210. else
  5211. {
  5212. // trying to search for files inside a non-directory?
  5213. //jassertfalse
  5214. }
  5215. // and recurse down if required.
  5216. if (searchRecursively)
  5217. {
  5218. Array<File> subDirectories;
  5219. findChildFiles (subDirectories, File::findDirectories, false);
  5220. for (int i = 0; i < subDirectories.size(); ++i)
  5221. {
  5222. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5223. true, wildCardPattern);
  5224. }
  5225. }
  5226. return total;
  5227. }
  5228. int File::getNumberOfChildFiles (const int whatToLookFor,
  5229. const String& wildCardPattern) const
  5230. {
  5231. // you have to specify the type of files you're looking for!
  5232. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5233. int count = 0;
  5234. if (isDirectory())
  5235. {
  5236. String filename;
  5237. bool itemIsDirectory, itemIsHidden;
  5238. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5239. &itemIsDirectory, &itemIsHidden,
  5240. 0, 0, 0, 0);
  5241. if (handle != 0)
  5242. {
  5243. do
  5244. {
  5245. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5246. && ! filename.containsOnly (T(".")))
  5247. {
  5248. ++count;
  5249. }
  5250. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5251. juce_findFileClose (handle);
  5252. }
  5253. }
  5254. else
  5255. {
  5256. // trying to search for files inside a non-directory?
  5257. jassertfalse
  5258. }
  5259. return count;
  5260. }
  5261. bool File::containsSubDirectories() const
  5262. {
  5263. bool result = false;
  5264. if (isDirectory())
  5265. {
  5266. String filename;
  5267. bool itemIsDirectory, itemIsHidden;
  5268. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5269. T("*"), filename,
  5270. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5271. if (handle != 0)
  5272. {
  5273. do
  5274. {
  5275. if (itemIsDirectory)
  5276. {
  5277. result = true;
  5278. break;
  5279. }
  5280. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5281. juce_findFileClose (handle);
  5282. }
  5283. }
  5284. return result;
  5285. }
  5286. const File File::getNonexistentChildFile (const String& prefix_,
  5287. const String& suffix,
  5288. bool putNumbersInBrackets) const
  5289. {
  5290. File f (getChildFile (prefix_ + suffix));
  5291. if (f.exists())
  5292. {
  5293. int num = 2;
  5294. String prefix (prefix_);
  5295. // remove any bracketed numbers that may already be on the end..
  5296. if (prefix.trim().endsWithChar (T(')')))
  5297. {
  5298. putNumbersInBrackets = true;
  5299. const int openBracks = prefix.lastIndexOfChar (T('('));
  5300. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5301. if (openBracks > 0
  5302. && closeBracks > openBracks
  5303. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5304. {
  5305. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5306. prefix = prefix.substring (0, openBracks);
  5307. }
  5308. }
  5309. // also use brackets if it ends in a digit.
  5310. putNumbersInBrackets = putNumbersInBrackets
  5311. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5312. do
  5313. {
  5314. if (putNumbersInBrackets)
  5315. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5316. else
  5317. f = getChildFile (prefix + String (num++) + suffix);
  5318. } while (f.exists());
  5319. }
  5320. return f;
  5321. }
  5322. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5323. {
  5324. if (exists())
  5325. {
  5326. return getParentDirectory()
  5327. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5328. getFileExtension(),
  5329. putNumbersInBrackets);
  5330. }
  5331. else
  5332. {
  5333. return *this;
  5334. }
  5335. }
  5336. const String File::getFileExtension() const
  5337. {
  5338. String ext;
  5339. if (! isDirectory())
  5340. {
  5341. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5342. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5343. ext = fullPath.substring (indexOfDot);
  5344. }
  5345. return ext;
  5346. }
  5347. bool File::hasFileExtension (const String& possibleSuffix) const
  5348. {
  5349. if (possibleSuffix.isEmpty())
  5350. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5351. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5352. if (semicolon >= 0)
  5353. {
  5354. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5355. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5356. }
  5357. else
  5358. {
  5359. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5360. {
  5361. if (possibleSuffix.startsWithChar (T('.')))
  5362. return true;
  5363. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5364. if (dotPos >= 0)
  5365. return fullPath [dotPos] == T('.');
  5366. }
  5367. }
  5368. return false;
  5369. }
  5370. const File File::withFileExtension (const String& newExtension) const
  5371. {
  5372. if (fullPath.isEmpty())
  5373. return File::nonexistent;
  5374. String filePart (getFileName());
  5375. int i = filePart.lastIndexOfChar (T('.'));
  5376. if (i < 0)
  5377. i = filePart.length();
  5378. String newExt (newExtension);
  5379. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5380. newExt = T(".") + newExt;
  5381. return getSiblingFile (filePart.substring (0, i) + newExt);
  5382. }
  5383. bool File::startAsProcess (const String& parameters) const
  5384. {
  5385. return exists()
  5386. && juce_launchFile (fullPath, parameters);
  5387. }
  5388. FileInputStream* File::createInputStream() const
  5389. {
  5390. if (existsAsFile())
  5391. return new FileInputStream (*this);
  5392. else
  5393. return 0;
  5394. }
  5395. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5396. {
  5397. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5398. if (out->failedToOpen())
  5399. return 0;
  5400. return out.release();
  5401. }
  5402. bool File::appendData (const void* const dataToAppend,
  5403. const int numberOfBytes) const
  5404. {
  5405. if (numberOfBytes > 0)
  5406. {
  5407. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5408. if (out == 0)
  5409. return false;
  5410. out->write (dataToAppend, numberOfBytes);
  5411. }
  5412. return true;
  5413. }
  5414. bool File::replaceWithData (const void* const dataToWrite,
  5415. const int numberOfBytes) const
  5416. {
  5417. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5418. if (numberOfBytes <= 0)
  5419. return deleteFile();
  5420. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5421. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5422. return tempFile.overwriteTargetFileWithTemporary();
  5423. }
  5424. bool File::appendText (const String& text,
  5425. const bool asUnicode,
  5426. const bool writeUnicodeHeaderBytes) const
  5427. {
  5428. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5429. if (out != 0)
  5430. {
  5431. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5432. return true;
  5433. }
  5434. return false;
  5435. }
  5436. bool File::replaceWithText (const String& textToWrite,
  5437. const bool asUnicode,
  5438. const bool writeUnicodeHeaderBytes) const
  5439. {
  5440. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5441. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5442. return tempFile.overwriteTargetFileWithTemporary();
  5443. }
  5444. const String File::createLegalPathName (const String& original)
  5445. {
  5446. String s (original);
  5447. String start;
  5448. if (s[1] == T(':'))
  5449. {
  5450. start = s.substring (0, 2);
  5451. s = s.substring (2);
  5452. }
  5453. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5454. .substring (0, 1024);
  5455. }
  5456. const String File::createLegalFileName (const String& original)
  5457. {
  5458. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5459. const int maxLength = 128; // only the length of the filename, not the whole path
  5460. const int len = s.length();
  5461. if (len > maxLength)
  5462. {
  5463. const int lastDot = s.lastIndexOfChar (T('.'));
  5464. if (lastDot > jmax (0, len - 12))
  5465. {
  5466. s = s.substring (0, maxLength - (len - lastDot))
  5467. + s.substring (lastDot);
  5468. }
  5469. else
  5470. {
  5471. s = s.substring (0, maxLength);
  5472. }
  5473. }
  5474. return s;
  5475. }
  5476. const String File::getRelativePathFrom (const File& dir) const
  5477. {
  5478. String thisPath (fullPath);
  5479. {
  5480. int len = thisPath.length();
  5481. while (--len >= 0 && thisPath [len] == File::separator)
  5482. thisPath [len] = 0;
  5483. }
  5484. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5485. : dir.fullPath));
  5486. const int len = jmin (thisPath.length(), dirPath.length());
  5487. int commonBitLength = 0;
  5488. for (int i = 0; i < len; ++i)
  5489. {
  5490. #if NAMES_ARE_CASE_SENSITIVE
  5491. if (thisPath[i] != dirPath[i])
  5492. #else
  5493. if (CharacterFunctions::toLowerCase (thisPath[i])
  5494. != CharacterFunctions::toLowerCase (dirPath[i]))
  5495. #endif
  5496. {
  5497. break;
  5498. }
  5499. ++commonBitLength;
  5500. }
  5501. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5502. --commonBitLength;
  5503. // if the only common bit is the root, then just return the full path..
  5504. if (commonBitLength <= 0
  5505. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5506. return fullPath;
  5507. thisPath = thisPath.substring (commonBitLength);
  5508. dirPath = dirPath.substring (commonBitLength);
  5509. while (dirPath.isNotEmpty())
  5510. {
  5511. #if JUCE_WINDOWS
  5512. thisPath = T("..\\") + thisPath;
  5513. #else
  5514. thisPath = T("../") + thisPath;
  5515. #endif
  5516. const int sep = dirPath.indexOfChar (separator);
  5517. if (sep >= 0)
  5518. dirPath = dirPath.substring (sep + 1);
  5519. else
  5520. dirPath = String::empty;
  5521. }
  5522. return thisPath;
  5523. }
  5524. void File::findFileSystemRoots (Array<File>& destArray)
  5525. {
  5526. const StringArray roots (juce_getFileSystemRoots());
  5527. for (int i = 0; i < roots.size(); ++i)
  5528. destArray.add (File (roots[i]));
  5529. }
  5530. const String File::getVolumeLabel() const
  5531. {
  5532. int serialNum;
  5533. return juce_getVolumeLabel (fullPath, serialNum);
  5534. }
  5535. int File::getVolumeSerialNumber() const
  5536. {
  5537. int serialNum;
  5538. juce_getVolumeLabel (fullPath, serialNum);
  5539. return serialNum;
  5540. }
  5541. const File File::createTempFile (const String& fileNameEnding)
  5542. {
  5543. const File tempFile (getSpecialLocation (tempDirectory)
  5544. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5545. .withFileExtension (fileNameEnding));
  5546. if (tempFile.exists())
  5547. return createTempFile (fileNameEnding);
  5548. else
  5549. return tempFile;
  5550. }
  5551. END_JUCE_NAMESPACE
  5552. /*** End of inlined file: juce_File.cpp ***/
  5553. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5554. BEGIN_JUCE_NAMESPACE
  5555. void* juce_fileOpen (const String& path, bool forWriting);
  5556. void juce_fileClose (void* handle);
  5557. int juce_fileRead (void* handle, void* buffer, int size);
  5558. int64 juce_fileSetPosition (void* handle, int64 pos);
  5559. FileInputStream::FileInputStream (const File& f)
  5560. : file (f),
  5561. currentPosition (0),
  5562. needToSeek (true)
  5563. {
  5564. totalSize = f.getSize();
  5565. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5566. }
  5567. FileInputStream::~FileInputStream()
  5568. {
  5569. juce_fileClose (fileHandle);
  5570. }
  5571. int64 FileInputStream::getTotalLength()
  5572. {
  5573. return totalSize;
  5574. }
  5575. int FileInputStream::read (void* buffer, int bytesToRead)
  5576. {
  5577. int num = 0;
  5578. if (needToSeek)
  5579. {
  5580. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5581. return 0;
  5582. needToSeek = false;
  5583. }
  5584. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5585. currentPosition += num;
  5586. return num;
  5587. }
  5588. bool FileInputStream::isExhausted()
  5589. {
  5590. return currentPosition >= totalSize;
  5591. }
  5592. int64 FileInputStream::getPosition()
  5593. {
  5594. return currentPosition;
  5595. }
  5596. bool FileInputStream::setPosition (int64 pos)
  5597. {
  5598. pos = jlimit ((int64) 0, totalSize, pos);
  5599. needToSeek |= (currentPosition != pos);
  5600. currentPosition = pos;
  5601. return true;
  5602. }
  5603. END_JUCE_NAMESPACE
  5604. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5605. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5606. BEGIN_JUCE_NAMESPACE
  5607. void* juce_fileOpen (const String& path, bool forWriting);
  5608. void juce_fileClose (void* handle);
  5609. int juce_fileWrite (void* handle, const void* buffer, int size);
  5610. void juce_fileFlush (void* handle);
  5611. int64 juce_fileGetPosition (void* handle);
  5612. int64 juce_fileSetPosition (void* handle, int64 pos);
  5613. FileOutputStream::FileOutputStream (const File& f,
  5614. const int bufferSize_)
  5615. : file (f),
  5616. bufferSize (bufferSize_),
  5617. bytesInBuffer (0)
  5618. {
  5619. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5620. if (fileHandle != 0)
  5621. {
  5622. currentPosition = juce_fileGetPosition (fileHandle);
  5623. if (currentPosition < 0)
  5624. {
  5625. jassertfalse
  5626. juce_fileClose (fileHandle);
  5627. fileHandle = 0;
  5628. }
  5629. }
  5630. buffer.malloc (jmax (bufferSize_, 16));
  5631. }
  5632. FileOutputStream::~FileOutputStream()
  5633. {
  5634. flush();
  5635. juce_fileClose (fileHandle);
  5636. }
  5637. int64 FileOutputStream::getPosition()
  5638. {
  5639. return currentPosition;
  5640. }
  5641. bool FileOutputStream::setPosition (int64 newPosition)
  5642. {
  5643. if (newPosition != currentPosition)
  5644. {
  5645. flush();
  5646. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5647. }
  5648. return newPosition == currentPosition;
  5649. }
  5650. void FileOutputStream::flush()
  5651. {
  5652. if (bytesInBuffer > 0)
  5653. {
  5654. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5655. bytesInBuffer = 0;
  5656. }
  5657. juce_fileFlush (fileHandle);
  5658. }
  5659. bool FileOutputStream::write (const void* const src, const int numBytes)
  5660. {
  5661. if (bytesInBuffer + numBytes < bufferSize)
  5662. {
  5663. memcpy (buffer + bytesInBuffer, src, numBytes);
  5664. bytesInBuffer += numBytes;
  5665. currentPosition += numBytes;
  5666. }
  5667. else
  5668. {
  5669. if (bytesInBuffer > 0)
  5670. {
  5671. // flush the reservoir
  5672. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5673. bytesInBuffer = 0;
  5674. if (! wroteOk)
  5675. return false;
  5676. }
  5677. if (numBytes < bufferSize)
  5678. {
  5679. memcpy (buffer + bytesInBuffer, src, numBytes);
  5680. bytesInBuffer += numBytes;
  5681. currentPosition += numBytes;
  5682. }
  5683. else
  5684. {
  5685. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5686. currentPosition += bytesWritten;
  5687. return bytesWritten == numBytes;
  5688. }
  5689. }
  5690. return true;
  5691. }
  5692. END_JUCE_NAMESPACE
  5693. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5694. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5695. BEGIN_JUCE_NAMESPACE
  5696. FileSearchPath::FileSearchPath()
  5697. {
  5698. }
  5699. FileSearchPath::FileSearchPath (const String& path)
  5700. {
  5701. init (path);
  5702. }
  5703. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5704. : directories (other.directories)
  5705. {
  5706. }
  5707. FileSearchPath::~FileSearchPath()
  5708. {
  5709. }
  5710. FileSearchPath& FileSearchPath::operator= (const String& path)
  5711. {
  5712. init (path);
  5713. return *this;
  5714. }
  5715. void FileSearchPath::init (const String& path)
  5716. {
  5717. directories.clear();
  5718. directories.addTokens (path, T(";"), T("\""));
  5719. directories.trim();
  5720. directories.removeEmptyStrings();
  5721. for (int i = directories.size(); --i >= 0;)
  5722. directories.set (i, directories[i].unquoted());
  5723. }
  5724. int FileSearchPath::getNumPaths() const
  5725. {
  5726. return directories.size();
  5727. }
  5728. const File FileSearchPath::operator[] (const int index) const
  5729. {
  5730. return File (directories [index]);
  5731. }
  5732. const String FileSearchPath::toString() const
  5733. {
  5734. StringArray directories2 (directories);
  5735. for (int i = directories2.size(); --i >= 0;)
  5736. if (directories2[i].containsChar (T(';')))
  5737. directories2.set (i, directories2[i].quoted());
  5738. return directories2.joinIntoString (T(";"));
  5739. }
  5740. void FileSearchPath::add (const File& dir, const int insertIndex)
  5741. {
  5742. directories.insert (insertIndex, dir.getFullPathName());
  5743. }
  5744. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5745. {
  5746. for (int i = 0; i < directories.size(); ++i)
  5747. if (File (directories[i]) == dir)
  5748. return;
  5749. add (dir);
  5750. }
  5751. void FileSearchPath::remove (const int index)
  5752. {
  5753. directories.remove (index);
  5754. }
  5755. void FileSearchPath::addPath (const FileSearchPath& other)
  5756. {
  5757. for (int i = 0; i < other.getNumPaths(); ++i)
  5758. addIfNotAlreadyThere (other[i]);
  5759. }
  5760. void FileSearchPath::removeRedundantPaths()
  5761. {
  5762. for (int i = directories.size(); --i >= 0;)
  5763. {
  5764. const File d1 (directories[i]);
  5765. for (int j = directories.size(); --j >= 0;)
  5766. {
  5767. const File d2 (directories[j]);
  5768. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5769. {
  5770. directories.remove (i);
  5771. break;
  5772. }
  5773. }
  5774. }
  5775. }
  5776. void FileSearchPath::removeNonExistentPaths()
  5777. {
  5778. for (int i = directories.size(); --i >= 0;)
  5779. if (! File (directories[i]).isDirectory())
  5780. directories.remove (i);
  5781. }
  5782. int FileSearchPath::findChildFiles (Array<File>& results,
  5783. const int whatToLookFor,
  5784. const bool searchRecursively,
  5785. const String& wildCardPattern) const
  5786. {
  5787. int total = 0;
  5788. for (int i = 0; i < directories.size(); ++i)
  5789. total += operator[] (i).findChildFiles (results,
  5790. whatToLookFor,
  5791. searchRecursively,
  5792. wildCardPattern);
  5793. return total;
  5794. }
  5795. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5796. const bool checkRecursively) const
  5797. {
  5798. for (int i = directories.size(); --i >= 0;)
  5799. {
  5800. const File d (directories[i]);
  5801. if (checkRecursively)
  5802. {
  5803. if (fileToCheck.isAChildOf (d))
  5804. return true;
  5805. }
  5806. else
  5807. {
  5808. if (fileToCheck.getParentDirectory() == d)
  5809. return true;
  5810. }
  5811. }
  5812. return false;
  5813. }
  5814. END_JUCE_NAMESPACE
  5815. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5816. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5817. BEGIN_JUCE_NAMESPACE
  5818. NamedPipe::NamedPipe()
  5819. : internal (0)
  5820. {
  5821. }
  5822. NamedPipe::~NamedPipe()
  5823. {
  5824. close();
  5825. }
  5826. bool NamedPipe::openExisting (const String& pipeName)
  5827. {
  5828. currentPipeName = pipeName;
  5829. return openInternal (pipeName, false);
  5830. }
  5831. bool NamedPipe::createNewPipe (const String& pipeName)
  5832. {
  5833. currentPipeName = pipeName;
  5834. return openInternal (pipeName, true);
  5835. }
  5836. bool NamedPipe::isOpen() const
  5837. {
  5838. return internal != 0;
  5839. }
  5840. const String NamedPipe::getName() const
  5841. {
  5842. return currentPipeName;
  5843. }
  5844. // other methods for this class are implemented in the platform-specific files
  5845. END_JUCE_NAMESPACE
  5846. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5847. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5848. BEGIN_JUCE_NAMESPACE
  5849. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5850. {
  5851. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5852. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5853. suffix,
  5854. optionFlags);
  5855. }
  5856. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5857. : targetFile (targetFile_)
  5858. {
  5859. // If you use this constructor, you need to give it a valid target file!
  5860. jassert (targetFile != File::nonexistent);
  5861. createTempFile (targetFile.getParentDirectory(),
  5862. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5863. targetFile.getFileExtension(),
  5864. optionFlags);
  5865. }
  5866. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5867. const String& suffix, const int optionFlags)
  5868. {
  5869. if ((optionFlags & useHiddenFile) != 0)
  5870. name = T(".") + name;
  5871. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5872. }
  5873. TemporaryFile::~TemporaryFile()
  5874. {
  5875. // Have a few attempts at deleting the file before giving up..
  5876. for (int i = 5; --i >= 0;)
  5877. {
  5878. if (temporaryFile.deleteFile())
  5879. return;
  5880. Thread::sleep (50);
  5881. }
  5882. // Failed to delete our temporary file! Check that you've deleted all the
  5883. // file output streams that were using it!
  5884. jassertfalse;
  5885. }
  5886. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5887. {
  5888. // This method only works if you created this object with the constructor
  5889. // that takes a target file!
  5890. jassert (targetFile != File::nonexistent);
  5891. if (temporaryFile.exists())
  5892. {
  5893. // Have a few attempts at overwriting the file before giving up..
  5894. for (int i = 5; --i >= 0;)
  5895. {
  5896. if (temporaryFile.moveFileTo (targetFile))
  5897. return true;
  5898. Thread::sleep (100);
  5899. }
  5900. // Failed to overwrite the new file! Make sure you've not left any
  5901. // file streams hanging around when you call this method!
  5902. jassertfalse
  5903. }
  5904. else
  5905. {
  5906. // There's no temporary file to use. If your write failed, you should
  5907. // probably check, and not bother calling this method.
  5908. jassertfalse
  5909. }
  5910. return false;
  5911. }
  5912. END_JUCE_NAMESPACE
  5913. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5914. /*** Start of inlined file: juce_Socket.cpp ***/
  5915. #if JUCE_WINDOWS
  5916. #include <winsock2.h>
  5917. #ifdef _MSC_VER
  5918. #pragma warning (disable : 4127 4389 4018)
  5919. #endif
  5920. #else
  5921. #if JUCE_LINUX
  5922. #include <sys/types.h>
  5923. #include <sys/socket.h>
  5924. #include <sys/errno.h>
  5925. #include <unistd.h>
  5926. #include <netinet/in.h>
  5927. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5928. #include <CoreServices/CoreServices.h>
  5929. #endif
  5930. #include <fcntl.h>
  5931. #include <netdb.h>
  5932. #include <arpa/inet.h>
  5933. #include <netinet/tcp.h>
  5934. #endif
  5935. BEGIN_JUCE_NAMESPACE
  5936. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5937. typedef socklen_t juce_socklen_t;
  5938. #else
  5939. typedef int juce_socklen_t;
  5940. #endif
  5941. #if JUCE_WINDOWS
  5942. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5943. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5944. static void initWin32Sockets()
  5945. {
  5946. static CriticalSection lock;
  5947. const ScopedLock sl (lock);
  5948. if (juce_CloseWin32SocketLib == 0)
  5949. {
  5950. WSADATA wsaData;
  5951. const WORD wVersionRequested = MAKEWORD (1, 1);
  5952. WSAStartup (wVersionRequested, &wsaData);
  5953. juce_CloseWin32SocketLib = &WSACleanup;
  5954. }
  5955. }
  5956. #endif
  5957. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5958. {
  5959. const int sndBufSize = 65536;
  5960. const int rcvBufSize = 65536;
  5961. const int one = 1;
  5962. return handle > 0
  5963. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5964. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5965. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5966. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5967. }
  5968. static bool bindSocketToPort (const int handle, const int port) throw()
  5969. {
  5970. if (handle <= 0 || port <= 0)
  5971. return false;
  5972. struct sockaddr_in servTmpAddr;
  5973. zerostruct (servTmpAddr);
  5974. servTmpAddr.sin_family = PF_INET;
  5975. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5976. servTmpAddr.sin_port = htons ((uint16) port);
  5977. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5978. }
  5979. static int readSocket (const int handle,
  5980. void* const destBuffer, const int maxBytesToRead,
  5981. bool volatile& connected,
  5982. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5983. {
  5984. int bytesRead = 0;
  5985. while (bytesRead < maxBytesToRead)
  5986. {
  5987. int bytesThisTime;
  5988. #if JUCE_WINDOWS
  5989. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5990. #else
  5991. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5992. && errno == EINTR
  5993. && connected)
  5994. {
  5995. }
  5996. #endif
  5997. if (bytesThisTime <= 0 || ! connected)
  5998. {
  5999. if (bytesRead == 0)
  6000. bytesRead = -1;
  6001. break;
  6002. }
  6003. bytesRead += bytesThisTime;
  6004. if (! blockUntilSpecifiedAmountHasArrived)
  6005. break;
  6006. }
  6007. return bytesRead;
  6008. }
  6009. static int waitForReadiness (const int handle, const bool forReading,
  6010. const int timeoutMsecs) throw()
  6011. {
  6012. struct timeval timeout;
  6013. struct timeval* timeoutp;
  6014. if (timeoutMsecs >= 0)
  6015. {
  6016. timeout.tv_sec = timeoutMsecs / 1000;
  6017. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  6018. timeoutp = &timeout;
  6019. }
  6020. else
  6021. {
  6022. timeoutp = 0;
  6023. }
  6024. fd_set rset, wset;
  6025. FD_ZERO (&rset);
  6026. FD_SET (handle, &rset);
  6027. FD_ZERO (&wset);
  6028. FD_SET (handle, &wset);
  6029. fd_set* const prset = forReading ? &rset : 0;
  6030. fd_set* const pwset = forReading ? 0 : &wset;
  6031. #if JUCE_WINDOWS
  6032. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  6033. return -1;
  6034. #else
  6035. {
  6036. int result;
  6037. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  6038. && errno == EINTR)
  6039. {
  6040. }
  6041. if (result < 0)
  6042. return -1;
  6043. }
  6044. #endif
  6045. {
  6046. int opt;
  6047. juce_socklen_t len = sizeof (opt);
  6048. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  6049. || opt != 0)
  6050. return -1;
  6051. }
  6052. if ((forReading && FD_ISSET (handle, &rset))
  6053. || ((! forReading) && FD_ISSET (handle, &wset)))
  6054. return 1;
  6055. return 0;
  6056. }
  6057. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  6058. {
  6059. #if JUCE_WINDOWS
  6060. u_long nonBlocking = shouldBlock ? 0 : 1;
  6061. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  6062. return false;
  6063. #else
  6064. int socketFlags = fcntl (handle, F_GETFL, 0);
  6065. if (socketFlags == -1)
  6066. return false;
  6067. if (shouldBlock)
  6068. socketFlags &= ~O_NONBLOCK;
  6069. else
  6070. socketFlags |= O_NONBLOCK;
  6071. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  6072. return false;
  6073. #endif
  6074. return true;
  6075. }
  6076. static bool connectSocket (int volatile& handle,
  6077. const bool isDatagram,
  6078. void** serverAddress,
  6079. const String& hostName,
  6080. const int portNumber,
  6081. const int timeOutMillisecs) throw()
  6082. {
  6083. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  6084. if (hostEnt == 0)
  6085. return false;
  6086. struct in_addr targetAddress;
  6087. memcpy (&targetAddress.s_addr,
  6088. *(hostEnt->h_addr_list),
  6089. sizeof (targetAddress.s_addr));
  6090. struct sockaddr_in servTmpAddr;
  6091. zerostruct (servTmpAddr);
  6092. servTmpAddr.sin_family = PF_INET;
  6093. servTmpAddr.sin_addr = targetAddress;
  6094. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6095. if (handle < 0)
  6096. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  6097. if (handle < 0)
  6098. return false;
  6099. if (isDatagram)
  6100. {
  6101. *serverAddress = new struct sockaddr_in();
  6102. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  6103. return true;
  6104. }
  6105. setSocketBlockingState (handle, false);
  6106. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  6107. if (result < 0)
  6108. {
  6109. #if JUCE_WINDOWS
  6110. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  6111. #else
  6112. if (errno == EINPROGRESS)
  6113. #endif
  6114. {
  6115. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  6116. {
  6117. setSocketBlockingState (handle, true);
  6118. return false;
  6119. }
  6120. }
  6121. }
  6122. setSocketBlockingState (handle, true);
  6123. resetSocketOptions (handle, false, false);
  6124. return true;
  6125. }
  6126. StreamingSocket::StreamingSocket()
  6127. : portNumber (0),
  6128. handle (-1),
  6129. connected (false),
  6130. isListener (false)
  6131. {
  6132. #if JUCE_WINDOWS
  6133. initWin32Sockets();
  6134. #endif
  6135. }
  6136. StreamingSocket::StreamingSocket (const String& hostName_,
  6137. const int portNumber_,
  6138. const int handle_)
  6139. : hostName (hostName_),
  6140. portNumber (portNumber_),
  6141. handle (handle_),
  6142. connected (true),
  6143. isListener (false)
  6144. {
  6145. #if JUCE_WINDOWS
  6146. initWin32Sockets();
  6147. #endif
  6148. resetSocketOptions (handle_, false, false);
  6149. }
  6150. StreamingSocket::~StreamingSocket()
  6151. {
  6152. close();
  6153. }
  6154. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6155. {
  6156. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6157. : -1;
  6158. }
  6159. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6160. {
  6161. if (isListener || ! connected)
  6162. return -1;
  6163. #if JUCE_WINDOWS
  6164. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6165. #else
  6166. int result;
  6167. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6168. && errno == EINTR)
  6169. {
  6170. }
  6171. return result;
  6172. #endif
  6173. }
  6174. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6175. const int timeoutMsecs) const
  6176. {
  6177. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6178. : -1;
  6179. }
  6180. bool StreamingSocket::bindToPort (const int port)
  6181. {
  6182. return bindSocketToPort (handle, port);
  6183. }
  6184. bool StreamingSocket::connect (const String& remoteHostName,
  6185. const int remotePortNumber,
  6186. const int timeOutMillisecs)
  6187. {
  6188. if (isListener)
  6189. {
  6190. jassertfalse // a listener socket can't connect to another one!
  6191. return false;
  6192. }
  6193. if (connected)
  6194. close();
  6195. hostName = remoteHostName;
  6196. portNumber = remotePortNumber;
  6197. isListener = false;
  6198. connected = connectSocket (handle, false, 0, remoteHostName,
  6199. remotePortNumber, timeOutMillisecs);
  6200. if (! (connected && resetSocketOptions (handle, false, false)))
  6201. {
  6202. close();
  6203. return false;
  6204. }
  6205. return true;
  6206. }
  6207. void StreamingSocket::close()
  6208. {
  6209. #if JUCE_WINDOWS
  6210. closesocket (handle);
  6211. connected = false;
  6212. #else
  6213. if (connected)
  6214. {
  6215. connected = false;
  6216. if (isListener)
  6217. {
  6218. // need to do this to interrupt the accept() function..
  6219. StreamingSocket temp;
  6220. temp.connect ("localhost", portNumber, 1000);
  6221. }
  6222. }
  6223. ::close (handle);
  6224. #endif
  6225. hostName = String::empty;
  6226. portNumber = 0;
  6227. handle = -1;
  6228. isListener = false;
  6229. }
  6230. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6231. {
  6232. if (connected)
  6233. close();
  6234. hostName = "listener";
  6235. portNumber = newPortNumber;
  6236. isListener = true;
  6237. struct sockaddr_in servTmpAddr;
  6238. zerostruct (servTmpAddr);
  6239. servTmpAddr.sin_family = PF_INET;
  6240. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6241. if (localHostName.isNotEmpty())
  6242. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6243. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6244. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6245. if (handle < 0)
  6246. return false;
  6247. const int reuse = 1;
  6248. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6249. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6250. || listen (handle, SOMAXCONN) < 0)
  6251. {
  6252. close();
  6253. return false;
  6254. }
  6255. connected = true;
  6256. return true;
  6257. }
  6258. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6259. {
  6260. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6261. // prepare this socket as a listener.
  6262. if (connected && isListener)
  6263. {
  6264. struct sockaddr address;
  6265. juce_socklen_t len = sizeof (sockaddr);
  6266. const int newSocket = (int) accept (handle, &address, &len);
  6267. if (newSocket >= 0 && connected)
  6268. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6269. portNumber, newSocket);
  6270. }
  6271. return 0;
  6272. }
  6273. bool StreamingSocket::isLocal() const throw()
  6274. {
  6275. return hostName == T("127.0.0.1");
  6276. }
  6277. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6278. : portNumber (0),
  6279. handle (-1),
  6280. connected (true),
  6281. allowBroadcast (allowBroadcast_),
  6282. serverAddress (0)
  6283. {
  6284. #if JUCE_WINDOWS
  6285. initWin32Sockets();
  6286. #endif
  6287. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6288. bindToPort (localPortNumber);
  6289. }
  6290. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6291. const int handle_, const int localPortNumber)
  6292. : hostName (hostName_),
  6293. portNumber (portNumber_),
  6294. handle (handle_),
  6295. connected (true),
  6296. allowBroadcast (false),
  6297. serverAddress (0)
  6298. {
  6299. #if JUCE_WINDOWS
  6300. initWin32Sockets();
  6301. #endif
  6302. resetSocketOptions (handle_, true, allowBroadcast);
  6303. bindToPort (localPortNumber);
  6304. }
  6305. DatagramSocket::~DatagramSocket()
  6306. {
  6307. close();
  6308. delete ((struct sockaddr_in*) serverAddress);
  6309. serverAddress = 0;
  6310. }
  6311. void DatagramSocket::close()
  6312. {
  6313. #if JUCE_WINDOWS
  6314. closesocket (handle);
  6315. connected = false;
  6316. #else
  6317. connected = false;
  6318. ::close (handle);
  6319. #endif
  6320. hostName = String::empty;
  6321. portNumber = 0;
  6322. handle = -1;
  6323. }
  6324. bool DatagramSocket::bindToPort (const int port)
  6325. {
  6326. return bindSocketToPort (handle, port);
  6327. }
  6328. bool DatagramSocket::connect (const String& remoteHostName,
  6329. const int remotePortNumber,
  6330. const int timeOutMillisecs)
  6331. {
  6332. if (connected)
  6333. close();
  6334. hostName = remoteHostName;
  6335. portNumber = remotePortNumber;
  6336. connected = connectSocket (handle, true, &serverAddress,
  6337. remoteHostName, remotePortNumber,
  6338. timeOutMillisecs);
  6339. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6340. {
  6341. close();
  6342. return false;
  6343. }
  6344. return true;
  6345. }
  6346. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6347. {
  6348. struct sockaddr address;
  6349. juce_socklen_t len = sizeof (sockaddr);
  6350. while (waitUntilReady (true, -1) == 1)
  6351. {
  6352. char buf[1];
  6353. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6354. {
  6355. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6356. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6357. -1, -1);
  6358. }
  6359. }
  6360. return 0;
  6361. }
  6362. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6363. const int timeoutMsecs) const
  6364. {
  6365. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6366. : -1;
  6367. }
  6368. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6369. {
  6370. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6371. : -1;
  6372. }
  6373. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6374. {
  6375. // You need to call connect() first to set the server address..
  6376. jassert (serverAddress != 0 && connected);
  6377. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6378. numBytesToWrite, 0,
  6379. (const struct sockaddr*) serverAddress,
  6380. sizeof (struct sockaddr_in))
  6381. : -1;
  6382. }
  6383. bool DatagramSocket::isLocal() const throw()
  6384. {
  6385. return hostName == T("127.0.0.1");
  6386. }
  6387. END_JUCE_NAMESPACE
  6388. /*** End of inlined file: juce_Socket.cpp ***/
  6389. /*** Start of inlined file: juce_URL.cpp ***/
  6390. BEGIN_JUCE_NAMESPACE
  6391. URL::URL()
  6392. {
  6393. }
  6394. URL::URL (const String& url_)
  6395. : url (url_)
  6396. {
  6397. int i = url.indexOfChar (T('?'));
  6398. if (i >= 0)
  6399. {
  6400. do
  6401. {
  6402. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6403. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6404. if (equalsPos > i + 1)
  6405. {
  6406. if (nextAmp < 0)
  6407. {
  6408. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6409. removeEscapeChars (url.substring (equalsPos + 1)));
  6410. }
  6411. else if (nextAmp > 0 && equalsPos < nextAmp)
  6412. {
  6413. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6414. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6415. }
  6416. }
  6417. i = nextAmp;
  6418. }
  6419. while (i >= 0);
  6420. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6421. }
  6422. }
  6423. URL::URL (const URL& other)
  6424. : url (other.url),
  6425. postData (other.postData),
  6426. parameters (other.parameters),
  6427. filesToUpload (other.filesToUpload),
  6428. mimeTypes (other.mimeTypes)
  6429. {
  6430. }
  6431. URL& URL::operator= (const URL& other)
  6432. {
  6433. url = other.url;
  6434. postData = other.postData;
  6435. parameters = other.parameters;
  6436. filesToUpload = other.filesToUpload;
  6437. mimeTypes = other.mimeTypes;
  6438. return *this;
  6439. }
  6440. URL::~URL()
  6441. {
  6442. }
  6443. static const String getMangledParameters (const StringPairArray& parameters)
  6444. {
  6445. String p;
  6446. for (int i = 0; i < parameters.size(); ++i)
  6447. {
  6448. if (i > 0)
  6449. p += T("&");
  6450. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6451. << T("=")
  6452. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6453. }
  6454. return p;
  6455. }
  6456. const String URL::toString (const bool includeGetParameters) const
  6457. {
  6458. if (includeGetParameters && parameters.size() > 0)
  6459. return url + T("?") + getMangledParameters (parameters);
  6460. else
  6461. return url;
  6462. }
  6463. bool URL::isWellFormed() const
  6464. {
  6465. //xxx TODO
  6466. return url.isNotEmpty();
  6467. }
  6468. static int findStartOfDomain (const String& url)
  6469. {
  6470. int i = 0;
  6471. while (CharacterFunctions::isLetterOrDigit (url[i])
  6472. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6473. ++i;
  6474. return url[i] == T(':') ? i + 1 : 0;
  6475. }
  6476. const String URL::getDomain() const
  6477. {
  6478. int start = findStartOfDomain (url);
  6479. while (url[start] == T('/'))
  6480. ++start;
  6481. const int end1 = url.indexOfChar (start, T('/'));
  6482. const int end2 = url.indexOfChar (start, T(':'));
  6483. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6484. : jmin (end1, end2);
  6485. return url.substring (start, end);
  6486. }
  6487. const String URL::getSubPath() const
  6488. {
  6489. int start = findStartOfDomain (url);
  6490. while (url[start] == T('/'))
  6491. ++start;
  6492. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6493. return startOfPath <= 0 ? String::empty
  6494. : url.substring (startOfPath);
  6495. }
  6496. const String URL::getScheme() const
  6497. {
  6498. return url.substring (0, findStartOfDomain (url) - 1);
  6499. }
  6500. const URL URL::withNewSubPath (const String& newPath) const
  6501. {
  6502. int start = findStartOfDomain (url);
  6503. while (url[start] == T('/'))
  6504. ++start;
  6505. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6506. URL u (*this);
  6507. if (startOfPath > 0)
  6508. u.url = url.substring (0, startOfPath);
  6509. if (! u.url.endsWithChar (T('/')))
  6510. u.url << '/';
  6511. if (newPath.startsWithChar (T('/')))
  6512. u.url << newPath.substring (1);
  6513. else
  6514. u.url << newPath;
  6515. return u;
  6516. }
  6517. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6518. {
  6519. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6520. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6521. return true;
  6522. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6523. || possibleURL.containsChar (T('@'))
  6524. || possibleURL.endsWithChar (T('.'))
  6525. || (! possibleURL.containsChar (T('.'))))
  6526. return false;
  6527. if (possibleURL.startsWithIgnoreCase (T("www."))
  6528. && possibleURL.substring (5).containsChar (T('.')))
  6529. return true;
  6530. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6531. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6532. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6533. return true;
  6534. return false;
  6535. }
  6536. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6537. {
  6538. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6539. return atSign > 0
  6540. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6541. && (! possibleEmailAddress.endsWithChar (T('.')));
  6542. }
  6543. void* juce_openInternetFile (const String& url,
  6544. const String& headers,
  6545. const MemoryBlock& optionalPostData,
  6546. const bool isPost,
  6547. URL::OpenStreamProgressCallback* callback,
  6548. void* callbackContext,
  6549. int timeOutMs);
  6550. void juce_closeInternetFile (void* handle);
  6551. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6552. int juce_seekInInternetFile (void* handle, int newPosition);
  6553. int64 juce_getInternetFileContentLength (void* handle);
  6554. class WebInputStream : public InputStream
  6555. {
  6556. public:
  6557. WebInputStream (const URL& url,
  6558. const bool isPost_,
  6559. URL::OpenStreamProgressCallback* const progressCallback_,
  6560. void* const progressCallbackContext_,
  6561. const String& extraHeaders,
  6562. int timeOutMs_)
  6563. : position (0),
  6564. finished (false),
  6565. isPost (isPost_),
  6566. progressCallback (progressCallback_),
  6567. progressCallbackContext (progressCallbackContext_),
  6568. timeOutMs (timeOutMs_)
  6569. {
  6570. server = url.toString (! isPost);
  6571. if (isPost_)
  6572. createHeadersAndPostData (url);
  6573. headers += extraHeaders;
  6574. if (! headers.endsWithChar (T('\n')))
  6575. headers << "\r\n";
  6576. handle = juce_openInternetFile (server, headers, postData, isPost,
  6577. progressCallback_, progressCallbackContext_,
  6578. timeOutMs);
  6579. }
  6580. ~WebInputStream()
  6581. {
  6582. juce_closeInternetFile (handle);
  6583. }
  6584. bool isError() const
  6585. {
  6586. return handle == 0;
  6587. }
  6588. int64 getTotalLength()
  6589. {
  6590. return juce_getInternetFileContentLength (handle);
  6591. }
  6592. bool isExhausted()
  6593. {
  6594. return finished;
  6595. }
  6596. int read (void* dest, int bytes)
  6597. {
  6598. if (finished || isError())
  6599. {
  6600. return 0;
  6601. }
  6602. else
  6603. {
  6604. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6605. position += bytesRead;
  6606. if (bytesRead == 0)
  6607. finished = true;
  6608. return bytesRead;
  6609. }
  6610. }
  6611. int64 getPosition()
  6612. {
  6613. return position;
  6614. }
  6615. bool setPosition (int64 wantedPos)
  6616. {
  6617. if (wantedPos != position)
  6618. {
  6619. finished = false;
  6620. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6621. if (actualPos == wantedPos)
  6622. {
  6623. position = wantedPos;
  6624. }
  6625. else
  6626. {
  6627. if (wantedPos < position)
  6628. {
  6629. juce_closeInternetFile (handle);
  6630. position = 0;
  6631. finished = false;
  6632. handle = juce_openInternetFile (server, headers, postData, isPost,
  6633. progressCallback, progressCallbackContext,
  6634. timeOutMs);
  6635. }
  6636. skipNextBytes (wantedPos - position);
  6637. }
  6638. }
  6639. return true;
  6640. }
  6641. juce_UseDebuggingNewOperator
  6642. private:
  6643. String server, headers;
  6644. MemoryBlock postData;
  6645. int64 position;
  6646. bool finished;
  6647. const bool isPost;
  6648. void* handle;
  6649. URL::OpenStreamProgressCallback* const progressCallback;
  6650. void* const progressCallbackContext;
  6651. const int timeOutMs;
  6652. void createHeadersAndPostData (const URL& url)
  6653. {
  6654. if (url.getFilesToUpload().size() > 0)
  6655. {
  6656. // need to upload some files, so do it as multi-part...
  6657. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6658. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6659. appendUTF8ToPostData ("--" + boundary);
  6660. int i;
  6661. for (i = 0; i < url.getParameters().size(); ++i)
  6662. {
  6663. String s;
  6664. s << "\r\nContent-Disposition: form-data; name=\""
  6665. << url.getParameters().getAllKeys() [i]
  6666. << "\"\r\n\r\n"
  6667. << url.getParameters().getAllValues() [i]
  6668. << "\r\n--"
  6669. << boundary;
  6670. appendUTF8ToPostData (s);
  6671. }
  6672. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6673. {
  6674. const File f (url.getFilesToUpload().getAllValues() [i]);
  6675. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6676. String s;
  6677. s << "\r\nContent-Disposition: form-data; name=\""
  6678. << paramName
  6679. << "\"; filename=\""
  6680. << f.getFileName()
  6681. << "\"\r\n";
  6682. const String mimeType (url.getMimeTypesOfUploadFiles()
  6683. .getValue (paramName, String::empty));
  6684. if (mimeType.isNotEmpty())
  6685. s << "Content-Type: " << mimeType << "\r\n";
  6686. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6687. appendUTF8ToPostData (s);
  6688. f.loadFileAsData (postData);
  6689. s = "\r\n--" + boundary;
  6690. appendUTF8ToPostData (s);
  6691. }
  6692. appendUTF8ToPostData ("--\r\n");
  6693. }
  6694. else
  6695. {
  6696. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6697. appendUTF8ToPostData (url.getPostData());
  6698. // just a short text attachment, so use simple url encoding..
  6699. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6700. + String ((unsigned int) postData.getSize())
  6701. + "\r\n";
  6702. }
  6703. }
  6704. void appendUTF8ToPostData (const String& text)
  6705. {
  6706. postData.append (text.toUTF8(),
  6707. (int) strlen (text.toUTF8()));
  6708. }
  6709. WebInputStream (const WebInputStream&);
  6710. WebInputStream& operator= (const WebInputStream&);
  6711. };
  6712. InputStream* URL::createInputStream (const bool usePostCommand,
  6713. OpenStreamProgressCallback* const progressCallback,
  6714. void* const progressCallbackContext,
  6715. const String& extraHeaders,
  6716. const int timeOutMs) const
  6717. {
  6718. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6719. progressCallback, progressCallbackContext,
  6720. extraHeaders,
  6721. timeOutMs));
  6722. return wi->isError() ? 0 : wi.release();
  6723. }
  6724. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6725. const bool usePostCommand) const
  6726. {
  6727. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6728. if (in != 0)
  6729. {
  6730. in->readIntoMemoryBlock (destData, -1);
  6731. return true;
  6732. }
  6733. return false;
  6734. }
  6735. const String URL::readEntireTextStream (const bool usePostCommand) const
  6736. {
  6737. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6738. if (in != 0)
  6739. return in->readEntireStreamAsString();
  6740. return String::empty;
  6741. }
  6742. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6743. {
  6744. XmlDocument doc (readEntireTextStream (usePostCommand));
  6745. return doc.getDocumentElement();
  6746. }
  6747. const URL URL::withParameter (const String& parameterName,
  6748. const String& parameterValue) const
  6749. {
  6750. URL u (*this);
  6751. u.parameters.set (parameterName, parameterValue);
  6752. return u;
  6753. }
  6754. const URL URL::withFileToUpload (const String& parameterName,
  6755. const File& fileToUpload,
  6756. const String& mimeType) const
  6757. {
  6758. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6759. URL u (*this);
  6760. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6761. u.mimeTypes.set (parameterName, mimeType);
  6762. return u;
  6763. }
  6764. const URL URL::withPOSTData (const String& postData_) const
  6765. {
  6766. URL u (*this);
  6767. u.postData = postData_;
  6768. return u;
  6769. }
  6770. const StringPairArray& URL::getParameters() const
  6771. {
  6772. return parameters;
  6773. }
  6774. const StringPairArray& URL::getFilesToUpload() const
  6775. {
  6776. return filesToUpload;
  6777. }
  6778. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6779. {
  6780. return mimeTypes;
  6781. }
  6782. const String URL::removeEscapeChars (const String& s)
  6783. {
  6784. const int len = s.length();
  6785. HeapBlock <uint8> resultUTF8 (len * 4);
  6786. uint8* r = resultUTF8;
  6787. for (int i = 0; i < len; ++i)
  6788. {
  6789. char c = (char) s[i];
  6790. if (c == 0)
  6791. break;
  6792. if (c == '+')
  6793. {
  6794. c = ' ';
  6795. }
  6796. else if (c == '%')
  6797. {
  6798. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6799. i += 2;
  6800. }
  6801. *r++ = c;
  6802. }
  6803. return String::fromUTF8 (resultUTF8);
  6804. }
  6805. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6806. {
  6807. String result;
  6808. result.preallocateStorage (s.length() + 8);
  6809. const char* utf8 = s.toUTF8();
  6810. const char* legalChars = isParameter ? "_-.*!'()"
  6811. : "_-$.*!'(),";
  6812. while (*utf8 != 0)
  6813. {
  6814. const char c = *utf8++;
  6815. if (CharacterFunctions::isLetterOrDigit (c)
  6816. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6817. {
  6818. result << c;
  6819. }
  6820. else
  6821. {
  6822. const int v = (int) (uint8) c;
  6823. if (v < 0x10)
  6824. result << T("%0");
  6825. else
  6826. result << T('%');
  6827. result << String::toHexString (v);
  6828. }
  6829. }
  6830. return result;
  6831. }
  6832. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6833. bool URL::launchInDefaultBrowser() const
  6834. {
  6835. String u (toString (true));
  6836. if (u.contains (T("@")) && ! u.contains (T(":")))
  6837. u = "mailto:" + u;
  6838. return juce_launchFile (u, String::empty);
  6839. }
  6840. END_JUCE_NAMESPACE
  6841. /*** End of inlined file: juce_URL.cpp ***/
  6842. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6843. BEGIN_JUCE_NAMESPACE
  6844. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6845. const int bufferSize_,
  6846. const bool deleteSourceWhenDestroyed)
  6847. : source (source_),
  6848. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6849. bufferSize (jmax (256, bufferSize_)),
  6850. position (source_->getPosition()),
  6851. lastReadPos (0),
  6852. bufferOverlap (128)
  6853. {
  6854. const int sourceSize = (int) source_->getTotalLength();
  6855. if (sourceSize >= 0)
  6856. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6857. bufferStart = position;
  6858. buffer.malloc (bufferSize);
  6859. }
  6860. BufferedInputStream::~BufferedInputStream()
  6861. {
  6862. }
  6863. int64 BufferedInputStream::getTotalLength()
  6864. {
  6865. return source->getTotalLength();
  6866. }
  6867. int64 BufferedInputStream::getPosition()
  6868. {
  6869. return position;
  6870. }
  6871. bool BufferedInputStream::setPosition (int64 newPosition)
  6872. {
  6873. position = jmax ((int64) 0, newPosition);
  6874. return true;
  6875. }
  6876. bool BufferedInputStream::isExhausted()
  6877. {
  6878. return (position >= lastReadPos)
  6879. && source->isExhausted();
  6880. }
  6881. void BufferedInputStream::ensureBuffered()
  6882. {
  6883. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6884. if (position < bufferStart || position >= bufferEndOverlap)
  6885. {
  6886. int bytesRead;
  6887. if (position < lastReadPos
  6888. && position >= bufferEndOverlap
  6889. && position >= bufferStart)
  6890. {
  6891. const int bytesToKeep = (int) (lastReadPos - position);
  6892. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6893. bufferStart = position;
  6894. bytesRead = source->read (buffer + bytesToKeep,
  6895. bufferSize - bytesToKeep);
  6896. lastReadPos += bytesRead;
  6897. bytesRead += bytesToKeep;
  6898. }
  6899. else
  6900. {
  6901. bufferStart = position;
  6902. source->setPosition (bufferStart);
  6903. bytesRead = source->read (buffer, bufferSize);
  6904. lastReadPos = bufferStart + bytesRead;
  6905. }
  6906. while (bytesRead < bufferSize)
  6907. buffer [bytesRead++] = 0;
  6908. }
  6909. }
  6910. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6911. {
  6912. if (position >= bufferStart
  6913. && position + maxBytesToRead <= lastReadPos)
  6914. {
  6915. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6916. position += maxBytesToRead;
  6917. return maxBytesToRead;
  6918. }
  6919. else
  6920. {
  6921. if (position < bufferStart || position >= lastReadPos)
  6922. ensureBuffered();
  6923. int bytesRead = 0;
  6924. while (maxBytesToRead > 0)
  6925. {
  6926. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6927. if (bytesAvailable > 0)
  6928. {
  6929. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6930. maxBytesToRead -= bytesAvailable;
  6931. bytesRead += bytesAvailable;
  6932. position += bytesAvailable;
  6933. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6934. }
  6935. const int64 oldLastReadPos = lastReadPos;
  6936. ensureBuffered();
  6937. if (oldLastReadPos == lastReadPos)
  6938. break; // if ensureBuffered() failed to read any more data, bail out
  6939. if (isExhausted())
  6940. break;
  6941. }
  6942. return bytesRead;
  6943. }
  6944. }
  6945. const String BufferedInputStream::readString()
  6946. {
  6947. if (position >= bufferStart
  6948. && position < lastReadPos)
  6949. {
  6950. const int maxChars = (int) (lastReadPos - position);
  6951. const char* const src = buffer + (int) (position - bufferStart);
  6952. for (int i = 0; i < maxChars; ++i)
  6953. {
  6954. if (src[i] == 0)
  6955. {
  6956. position += i + 1;
  6957. return String::fromUTF8 (src, i);
  6958. }
  6959. }
  6960. }
  6961. return InputStream::readString();
  6962. }
  6963. END_JUCE_NAMESPACE
  6964. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6965. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6966. BEGIN_JUCE_NAMESPACE
  6967. FileInputSource::FileInputSource (const File& file_)
  6968. : file (file_)
  6969. {
  6970. }
  6971. FileInputSource::~FileInputSource()
  6972. {
  6973. }
  6974. InputStream* FileInputSource::createInputStream()
  6975. {
  6976. return file.createInputStream();
  6977. }
  6978. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6979. {
  6980. return file.getSiblingFile (relatedItemPath).createInputStream();
  6981. }
  6982. int64 FileInputSource::hashCode() const
  6983. {
  6984. return file.hashCode();
  6985. }
  6986. END_JUCE_NAMESPACE
  6987. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6988. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6989. BEGIN_JUCE_NAMESPACE
  6990. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6991. const size_t sourceDataSize,
  6992. const bool keepInternalCopy)
  6993. : data ((const char*) sourceData),
  6994. dataSize (sourceDataSize),
  6995. position (0)
  6996. {
  6997. if (keepInternalCopy)
  6998. {
  6999. internalCopy.append (data, sourceDataSize);
  7000. data = (const char*) internalCopy.getData();
  7001. }
  7002. }
  7003. MemoryInputStream::~MemoryInputStream()
  7004. {
  7005. }
  7006. int64 MemoryInputStream::getTotalLength()
  7007. {
  7008. return dataSize;
  7009. }
  7010. int MemoryInputStream::read (void* buffer, int howMany)
  7011. {
  7012. jassert (howMany >= 0);
  7013. const int num = jmin (howMany, (int) (dataSize - position));
  7014. memcpy (buffer, data + position, num);
  7015. position += num;
  7016. return (int) num;
  7017. }
  7018. bool MemoryInputStream::isExhausted()
  7019. {
  7020. return (position >= dataSize);
  7021. }
  7022. bool MemoryInputStream::setPosition (int64 pos)
  7023. {
  7024. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  7025. return true;
  7026. }
  7027. int64 MemoryInputStream::getPosition()
  7028. {
  7029. return position;
  7030. }
  7031. END_JUCE_NAMESPACE
  7032. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  7033. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  7034. BEGIN_JUCE_NAMESPACE
  7035. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  7036. const size_t blockSizeToIncreaseBy,
  7037. MemoryBlock* const memoryBlockToWriteTo) throw()
  7038. : data (memoryBlockToWriteTo),
  7039. position (0),
  7040. size (0),
  7041. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  7042. {
  7043. if (data == 0)
  7044. dataToDelete = data = new MemoryBlock (initialSize);
  7045. else
  7046. data->setSize (initialSize, false);
  7047. }
  7048. MemoryOutputStream::~MemoryOutputStream() throw()
  7049. {
  7050. flush();
  7051. }
  7052. void MemoryOutputStream::flush()
  7053. {
  7054. if (dataToDelete == 0)
  7055. data->setSize (size, false);
  7056. }
  7057. void MemoryOutputStream::reset() throw()
  7058. {
  7059. position = 0;
  7060. size = 0;
  7061. }
  7062. bool MemoryOutputStream::write (const void* buffer, int howMany)
  7063. {
  7064. if (howMany > 0)
  7065. {
  7066. size_t storageNeeded = position + howMany;
  7067. if (storageNeeded >= data->getSize())
  7068. {
  7069. // if we need more space, increase the block by at least 10%..
  7070. storageNeeded += jmax (blockSize, storageNeeded / 10);
  7071. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  7072. data->ensureSize (storageNeeded);
  7073. }
  7074. data->copyFrom (buffer, (int) position, howMany);
  7075. position += howMany;
  7076. size = jmax (size, position);
  7077. }
  7078. return true;
  7079. }
  7080. const char* MemoryOutputStream::getData() const throw()
  7081. {
  7082. if (data->getSize() > size)
  7083. ((char*) data->getData()) [size] = 0;
  7084. return (const char*) data->getData();
  7085. }
  7086. size_t MemoryOutputStream::getDataSize() const throw()
  7087. {
  7088. return size;
  7089. }
  7090. int64 MemoryOutputStream::getPosition()
  7091. {
  7092. return position;
  7093. }
  7094. bool MemoryOutputStream::setPosition (int64 newPosition)
  7095. {
  7096. if (newPosition <= (int64) size)
  7097. {
  7098. // ok to seek backwards
  7099. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  7100. return true;
  7101. }
  7102. else
  7103. {
  7104. // trying to make it bigger isn't a good thing to do..
  7105. return false;
  7106. }
  7107. }
  7108. END_JUCE_NAMESPACE
  7109. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  7110. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  7111. BEGIN_JUCE_NAMESPACE
  7112. SubregionStream::SubregionStream (InputStream* const sourceStream,
  7113. const int64 startPositionInSourceStream_,
  7114. const int64 lengthOfSourceStream_,
  7115. const bool deleteSourceWhenDestroyed) throw()
  7116. : source (sourceStream),
  7117. startPositionInSourceStream (startPositionInSourceStream_),
  7118. lengthOfSourceStream (lengthOfSourceStream_)
  7119. {
  7120. if (deleteSourceWhenDestroyed)
  7121. sourceToDelete = source;
  7122. setPosition (0);
  7123. }
  7124. SubregionStream::~SubregionStream() throw()
  7125. {
  7126. }
  7127. int64 SubregionStream::getTotalLength()
  7128. {
  7129. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  7130. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  7131. : srcLen;
  7132. }
  7133. int64 SubregionStream::getPosition()
  7134. {
  7135. return source->getPosition() - startPositionInSourceStream;
  7136. }
  7137. bool SubregionStream::setPosition (int64 newPosition)
  7138. {
  7139. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7140. }
  7141. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7142. {
  7143. if (lengthOfSourceStream < 0)
  7144. {
  7145. return source->read (destBuffer, maxBytesToRead);
  7146. }
  7147. else
  7148. {
  7149. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7150. if (maxBytesToRead <= 0)
  7151. return 0;
  7152. return source->read (destBuffer, maxBytesToRead);
  7153. }
  7154. }
  7155. bool SubregionStream::isExhausted()
  7156. {
  7157. if (lengthOfSourceStream >= 0)
  7158. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7159. else
  7160. return source->isExhausted();
  7161. }
  7162. END_JUCE_NAMESPACE
  7163. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7164. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7165. BEGIN_JUCE_NAMESPACE
  7166. PerformanceCounter::PerformanceCounter (const String& name_,
  7167. int runsPerPrintout,
  7168. const File& loggingFile)
  7169. : name (name_),
  7170. numRuns (0),
  7171. runsPerPrint (runsPerPrintout),
  7172. totalTime (0),
  7173. outputFile (loggingFile)
  7174. {
  7175. if (outputFile != File::nonexistent)
  7176. {
  7177. String s ("**** Counter for \"");
  7178. s << name_ << "\" started at: "
  7179. << Time::getCurrentTime().toString (true, true)
  7180. << "\r\n";
  7181. outputFile.appendText (s, false, false);
  7182. }
  7183. }
  7184. PerformanceCounter::~PerformanceCounter()
  7185. {
  7186. printStatistics();
  7187. }
  7188. void PerformanceCounter::start()
  7189. {
  7190. started = Time::getHighResolutionTicks();
  7191. }
  7192. void PerformanceCounter::stop()
  7193. {
  7194. const int64 now = Time::getHighResolutionTicks();
  7195. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7196. if (++numRuns == runsPerPrint)
  7197. printStatistics();
  7198. }
  7199. void PerformanceCounter::printStatistics()
  7200. {
  7201. if (numRuns > 0)
  7202. {
  7203. String s ("Performance count for \"");
  7204. s << name << "\" - average over " << numRuns << " run(s) = ";
  7205. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7206. if (micros > 10000)
  7207. s << (micros/1000) << " millisecs";
  7208. else
  7209. s << micros << " microsecs";
  7210. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7211. Logger::outputDebugString (s);
  7212. s << "\r\n";
  7213. if (outputFile != File::nonexistent)
  7214. outputFile.appendText (s, false, false);
  7215. numRuns = 0;
  7216. totalTime = 0;
  7217. }
  7218. }
  7219. END_JUCE_NAMESPACE
  7220. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7221. /*** Start of inlined file: juce_Uuid.cpp ***/
  7222. BEGIN_JUCE_NAMESPACE
  7223. Uuid::Uuid()
  7224. {
  7225. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7226. // to make it very very unlikely that two UUIDs will ever be the same..
  7227. static int64 macAddresses[2];
  7228. static bool hasCheckedMacAddresses = false;
  7229. if (! hasCheckedMacAddresses)
  7230. {
  7231. hasCheckedMacAddresses = true;
  7232. SystemStats::getMACAddresses (macAddresses, 2);
  7233. }
  7234. value.asInt64[0] = macAddresses[0];
  7235. value.asInt64[1] = macAddresses[1];
  7236. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7237. // whose seed will carry over between calls to this method.
  7238. Random r (macAddresses[0] ^ macAddresses[1]
  7239. ^ Random::getSystemRandom().nextInt64());
  7240. for (int i = 4; --i >= 0;)
  7241. {
  7242. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7243. value.asInt[i] ^= r.nextInt();
  7244. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7245. }
  7246. }
  7247. Uuid::~Uuid() throw()
  7248. {
  7249. }
  7250. Uuid::Uuid (const Uuid& other)
  7251. : value (other.value)
  7252. {
  7253. }
  7254. Uuid& Uuid::operator= (const Uuid& other)
  7255. {
  7256. value = other.value;
  7257. return *this;
  7258. }
  7259. bool Uuid::operator== (const Uuid& other) const
  7260. {
  7261. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7262. }
  7263. bool Uuid::operator!= (const Uuid& other) const
  7264. {
  7265. return ! operator== (other);
  7266. }
  7267. bool Uuid::isNull() const throw()
  7268. {
  7269. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7270. }
  7271. const String Uuid::toString() const
  7272. {
  7273. return String::toHexString (value.asBytes, 16, 0);
  7274. }
  7275. Uuid::Uuid (const String& uuidString)
  7276. {
  7277. operator= (uuidString);
  7278. }
  7279. Uuid& Uuid::operator= (const String& uuidString)
  7280. {
  7281. int destIndex = 0;
  7282. int i = 0;
  7283. for (;;)
  7284. {
  7285. int byte = 0;
  7286. for (int loop = 2; --loop >= 0;)
  7287. {
  7288. byte <<= 4;
  7289. for (;;)
  7290. {
  7291. const tchar c = uuidString [i++];
  7292. if (c >= T('0') && c <= T('9'))
  7293. {
  7294. byte |= c - T('0');
  7295. break;
  7296. }
  7297. else if (c >= T('a') && c <= T('z'))
  7298. {
  7299. byte |= c - (T('a') - 10);
  7300. break;
  7301. }
  7302. else if (c >= T('A') && c <= T('Z'))
  7303. {
  7304. byte |= c - (T('A') - 10);
  7305. break;
  7306. }
  7307. else if (c == 0)
  7308. {
  7309. while (destIndex < 16)
  7310. value.asBytes [destIndex++] = 0;
  7311. return *this;
  7312. }
  7313. }
  7314. }
  7315. value.asBytes [destIndex++] = (uint8) byte;
  7316. }
  7317. }
  7318. Uuid::Uuid (const uint8* const rawData)
  7319. {
  7320. operator= (rawData);
  7321. }
  7322. Uuid& Uuid::operator= (const uint8* const rawData)
  7323. {
  7324. if (rawData != 0)
  7325. memcpy (value.asBytes, rawData, 16);
  7326. else
  7327. zeromem (value.asBytes, 16);
  7328. return *this;
  7329. }
  7330. END_JUCE_NAMESPACE
  7331. /*** End of inlined file: juce_Uuid.cpp ***/
  7332. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7333. BEGIN_JUCE_NAMESPACE
  7334. class ZipFile::ZipEntryInfo
  7335. {
  7336. public:
  7337. ZipFile::ZipEntry entry;
  7338. int streamOffset;
  7339. int compressedSize;
  7340. bool compressed;
  7341. };
  7342. class ZipFile::ZipInputStream : public InputStream
  7343. {
  7344. public:
  7345. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7346. : file (file_),
  7347. zipEntryInfo (zei),
  7348. pos (0),
  7349. headerSize (0),
  7350. inputStream (0)
  7351. {
  7352. inputStream = file_.inputStream;
  7353. if (file_.inputSource != 0)
  7354. {
  7355. inputStream = file.inputSource->createInputStream();
  7356. }
  7357. else
  7358. {
  7359. #ifdef JUCE_DEBUG
  7360. file_.numOpenStreams++;
  7361. #endif
  7362. }
  7363. char buffer [30];
  7364. if (inputStream != 0
  7365. && inputStream->setPosition (zei.streamOffset)
  7366. && inputStream->read (buffer, 30) == 30
  7367. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7368. {
  7369. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7370. + ByteOrder::littleEndianShort (buffer + 28);
  7371. }
  7372. }
  7373. ~ZipInputStream() throw()
  7374. {
  7375. #ifdef JUCE_DEBUG
  7376. if (inputStream != 0 && inputStream == file.inputStream)
  7377. file.numOpenStreams--;
  7378. #endif
  7379. if (inputStream != file.inputStream)
  7380. delete inputStream;
  7381. }
  7382. int64 getTotalLength() throw()
  7383. {
  7384. return zipEntryInfo.compressedSize;
  7385. }
  7386. int read (void* buffer, int howMany) throw()
  7387. {
  7388. if (headerSize <= 0)
  7389. return 0;
  7390. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7391. if (inputStream == 0)
  7392. return 0;
  7393. int num;
  7394. if (inputStream == file.inputStream)
  7395. {
  7396. const ScopedLock sl (file.lock);
  7397. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7398. num = inputStream->read (buffer, howMany);
  7399. }
  7400. else
  7401. {
  7402. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7403. num = inputStream->read (buffer, howMany);
  7404. }
  7405. pos += num;
  7406. return num;
  7407. }
  7408. bool isExhausted() throw()
  7409. {
  7410. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7411. }
  7412. int64 getPosition() throw()
  7413. {
  7414. return pos;
  7415. }
  7416. bool setPosition (int64 newPos) throw()
  7417. {
  7418. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7419. return true;
  7420. }
  7421. private:
  7422. ZipFile& file;
  7423. ZipEntryInfo zipEntryInfo;
  7424. int64 pos;
  7425. int headerSize;
  7426. InputStream* inputStream;
  7427. ZipInputStream (const ZipInputStream&);
  7428. ZipInputStream& operator= (const ZipInputStream&);
  7429. };
  7430. ZipFile::ZipFile (InputStream* const source_,
  7431. const bool deleteStreamWhenDestroyed) throw()
  7432. : inputStream (source_)
  7433. #ifdef JUCE_DEBUG
  7434. , numOpenStreams (0)
  7435. #endif
  7436. {
  7437. if (deleteStreamWhenDestroyed)
  7438. streamToDelete = inputStream;
  7439. init();
  7440. }
  7441. ZipFile::ZipFile (const File& file)
  7442. : inputStream (0)
  7443. #ifdef JUCE_DEBUG
  7444. , numOpenStreams (0)
  7445. #endif
  7446. {
  7447. inputSource = new FileInputSource (file);
  7448. init();
  7449. }
  7450. ZipFile::ZipFile (InputSource* const inputSource_)
  7451. : inputStream (0),
  7452. inputSource (inputSource_)
  7453. #ifdef JUCE_DEBUG
  7454. , numOpenStreams (0)
  7455. #endif
  7456. {
  7457. init();
  7458. }
  7459. ZipFile::~ZipFile() throw()
  7460. {
  7461. #ifdef JUCE_DEBUG
  7462. entries.clear();
  7463. // If you hit this assertion, it means you've created a stream to read
  7464. // one of the items in the zipfile, but you've forgotten to delete that
  7465. // stream object before deleting the file.. Streams can't be kept open
  7466. // after the file is deleted because they need to share the input
  7467. // stream that the file uses to read itself.
  7468. jassert (numOpenStreams == 0);
  7469. #endif
  7470. }
  7471. int ZipFile::getNumEntries() const throw()
  7472. {
  7473. return entries.size();
  7474. }
  7475. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7476. {
  7477. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7478. return (zei != 0) ? &(zei->entry)
  7479. : 0;
  7480. }
  7481. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7482. {
  7483. for (int i = 0; i < entries.size(); ++i)
  7484. if (entries.getUnchecked (i)->entry.filename == fileName)
  7485. return i;
  7486. return -1;
  7487. }
  7488. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7489. {
  7490. return getEntry (getIndexOfFileName (fileName));
  7491. }
  7492. InputStream* ZipFile::createStreamForEntry (const int index)
  7493. {
  7494. ZipEntryInfo* const zei = entries[index];
  7495. InputStream* stream = 0;
  7496. if (zei != 0)
  7497. {
  7498. stream = new ZipInputStream (*this, *zei);
  7499. if (zei->compressed)
  7500. {
  7501. stream = new GZIPDecompressorInputStream (stream, true, true,
  7502. zei->entry.uncompressedSize);
  7503. // (much faster to unzip in big blocks using a buffer..)
  7504. stream = new BufferedInputStream (stream, 32768, true);
  7505. }
  7506. }
  7507. return stream;
  7508. }
  7509. class ZipFile::ZipFilenameComparator
  7510. {
  7511. public:
  7512. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7513. {
  7514. return first->entry.filename.compare (second->entry.filename);
  7515. }
  7516. };
  7517. void ZipFile::sortEntriesByFilename()
  7518. {
  7519. ZipFilenameComparator sorter;
  7520. entries.sort (sorter);
  7521. }
  7522. void ZipFile::init()
  7523. {
  7524. ScopedPointer <InputStream> toDelete;
  7525. InputStream* in = inputStream;
  7526. if (inputSource != 0)
  7527. {
  7528. in = inputSource->createInputStream();
  7529. toDelete = in;
  7530. }
  7531. if (in != 0)
  7532. {
  7533. int numEntries = 0;
  7534. int pos = findEndOfZipEntryTable (in, numEntries);
  7535. if (pos >= 0 && pos < in->getTotalLength())
  7536. {
  7537. const int size = (int) (in->getTotalLength() - pos);
  7538. in->setPosition (pos);
  7539. MemoryBlock headerData;
  7540. if (in->readIntoMemoryBlock (headerData, size) == size)
  7541. {
  7542. pos = 0;
  7543. for (int i = 0; i < numEntries; ++i)
  7544. {
  7545. if (pos + 46 > size)
  7546. break;
  7547. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7548. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7549. if (pos + 46 + fileNameLen > size)
  7550. break;
  7551. ZipEntryInfo* const zei = new ZipEntryInfo();
  7552. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7553. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7554. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7555. const int year = 1980 + (date >> 9);
  7556. const int month = ((date >> 5) & 15) - 1;
  7557. const int day = date & 31;
  7558. const int hours = time >> 11;
  7559. const int minutes = (time >> 5) & 63;
  7560. const int seconds = (time & 31) << 1;
  7561. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7562. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7563. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7564. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7565. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7566. entries.add (zei);
  7567. pos += 46 + fileNameLen
  7568. + ByteOrder::littleEndianShort (buffer + 30)
  7569. + ByteOrder::littleEndianShort (buffer + 32);
  7570. }
  7571. }
  7572. }
  7573. }
  7574. }
  7575. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7576. {
  7577. BufferedInputStream in (input, 8192, false);
  7578. in.setPosition (in.getTotalLength());
  7579. int64 pos = in.getPosition();
  7580. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7581. char buffer [32];
  7582. zeromem (buffer, sizeof (buffer));
  7583. while (pos > lowestPos)
  7584. {
  7585. in.setPosition (pos - 22);
  7586. pos = in.getPosition();
  7587. memcpy (buffer + 22, buffer, 4);
  7588. if (in.read (buffer, 22) != 22)
  7589. return 0;
  7590. for (int i = 0; i < 22; ++i)
  7591. {
  7592. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7593. {
  7594. in.setPosition (pos + i);
  7595. in.read (buffer, 22);
  7596. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7597. return ByteOrder::littleEndianInt (buffer + 16);
  7598. }
  7599. }
  7600. }
  7601. return 0;
  7602. }
  7603. void ZipFile::uncompressTo (const File& targetDirectory,
  7604. const bool shouldOverwriteFiles)
  7605. {
  7606. for (int i = 0; i < entries.size(); ++i)
  7607. {
  7608. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7609. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7610. if (zei.filename.endsWithChar (T('/')))
  7611. {
  7612. targetFile.createDirectory(); // (entry is a directory, not a file)
  7613. }
  7614. else
  7615. {
  7616. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7617. if (in != 0)
  7618. {
  7619. if (shouldOverwriteFiles)
  7620. targetFile.deleteFile();
  7621. if ((! targetFile.exists())
  7622. && targetFile.getParentDirectory().createDirectory())
  7623. {
  7624. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7625. if (out != 0)
  7626. {
  7627. out->writeFromInputStream (*in, -1);
  7628. out = 0;
  7629. targetFile.setCreationTime (zei.fileTime);
  7630. targetFile.setLastModificationTime (zei.fileTime);
  7631. targetFile.setLastAccessTime (zei.fileTime);
  7632. }
  7633. }
  7634. }
  7635. }
  7636. }
  7637. }
  7638. END_JUCE_NAMESPACE
  7639. /*** End of inlined file: juce_ZipFile.cpp ***/
  7640. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7641. #ifdef _MSC_VER
  7642. #pragma warning (disable: 4514 4996)
  7643. #pragma warning (push)
  7644. #endif
  7645. #include <cwctype>
  7646. #include <cctype>
  7647. #include <ctime>
  7648. #ifdef _MSC_VER
  7649. #pragma warning (pop)
  7650. #endif
  7651. BEGIN_JUCE_NAMESPACE
  7652. int CharacterFunctions::length (const char* const s) throw()
  7653. {
  7654. return (int) strlen (s);
  7655. }
  7656. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7657. {
  7658. return (int) wcslen (s);
  7659. }
  7660. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7661. {
  7662. strncpy (dest, src, maxChars);
  7663. }
  7664. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7665. {
  7666. wcsncpy (dest, src, maxChars);
  7667. }
  7668. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7669. {
  7670. mbstowcs (dest, src, maxChars);
  7671. }
  7672. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7673. {
  7674. wcstombs (dest, src, maxChars);
  7675. }
  7676. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7677. {
  7678. return (int) wcstombs (0, src, 0);
  7679. }
  7680. void CharacterFunctions::append (char* dest, const char* src) throw()
  7681. {
  7682. strcat (dest, src);
  7683. }
  7684. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7685. {
  7686. wcscat (dest, src);
  7687. }
  7688. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7689. {
  7690. return strcmp (s1, s2);
  7691. }
  7692. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7693. {
  7694. jassert (s1 != 0 && s2 != 0);
  7695. return wcscmp (s1, s2);
  7696. }
  7697. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7698. {
  7699. jassert (s1 != 0 && s2 != 0);
  7700. return strncmp (s1, s2, maxChars);
  7701. }
  7702. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7703. {
  7704. jassert (s1 != 0 && s2 != 0);
  7705. return wcsncmp (s1, s2, maxChars);
  7706. }
  7707. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7708. {
  7709. jassert (s1 != 0 && s2 != 0);
  7710. for (;;)
  7711. {
  7712. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7713. if (diff != 0)
  7714. return diff;
  7715. else if (*s1 == 0)
  7716. break;
  7717. ++s1;
  7718. ++s2;
  7719. }
  7720. return 0;
  7721. }
  7722. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7723. {
  7724. return -compare (s2, s1);
  7725. }
  7726. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7727. {
  7728. jassert (s1 != 0 && s2 != 0);
  7729. #if JUCE_WIN32
  7730. return stricmp (s1, s2);
  7731. #else
  7732. return strcasecmp (s1, s2);
  7733. #endif
  7734. }
  7735. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7736. {
  7737. jassert (s1 != 0 && s2 != 0);
  7738. #if JUCE_WIN32
  7739. return _wcsicmp (s1, s2);
  7740. #else
  7741. for (;;)
  7742. {
  7743. if (*s1 != *s2)
  7744. {
  7745. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7746. if (diff != 0)
  7747. return diff < 0 ? -1 : 1;
  7748. }
  7749. else if (*s1 == 0)
  7750. break;
  7751. ++s1;
  7752. ++s2;
  7753. }
  7754. return 0;
  7755. #endif
  7756. }
  7757. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7758. {
  7759. jassert (s1 != 0 && s2 != 0);
  7760. #if JUCE_WIN32
  7761. return strnicmp (s1, s2, maxChars);
  7762. #else
  7763. return strncasecmp (s1, s2, maxChars);
  7764. #endif
  7765. }
  7766. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7767. {
  7768. jassert (s1 != 0 && s2 != 0);
  7769. #if JUCE_WIN32
  7770. return _wcsnicmp (s1, s2, maxChars);
  7771. #else
  7772. while (--maxChars >= 0)
  7773. {
  7774. if (*s1 != *s2)
  7775. {
  7776. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7777. if (diff != 0)
  7778. return diff < 0 ? -1 : 1;
  7779. }
  7780. else if (*s1 == 0)
  7781. break;
  7782. ++s1;
  7783. ++s2;
  7784. }
  7785. return 0;
  7786. #endif
  7787. }
  7788. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7789. {
  7790. return strstr (haystack, needle);
  7791. }
  7792. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7793. {
  7794. return wcsstr (haystack, needle);
  7795. }
  7796. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7797. {
  7798. if (haystack != 0)
  7799. {
  7800. int i = 0;
  7801. if (ignoreCase)
  7802. {
  7803. const char n1 = toLowerCase (needle);
  7804. const char n2 = toUpperCase (needle);
  7805. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7806. {
  7807. while (haystack[i] != 0)
  7808. {
  7809. if (haystack[i] == n1 || haystack[i] == n2)
  7810. return i;
  7811. ++i;
  7812. }
  7813. return -1;
  7814. }
  7815. jassert (n1 == needle);
  7816. }
  7817. while (haystack[i] != 0)
  7818. {
  7819. if (haystack[i] == needle)
  7820. return i;
  7821. ++i;
  7822. }
  7823. }
  7824. return -1;
  7825. }
  7826. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7827. {
  7828. if (haystack != 0)
  7829. {
  7830. int i = 0;
  7831. if (ignoreCase)
  7832. {
  7833. const juce_wchar n1 = toLowerCase (needle);
  7834. const juce_wchar n2 = toUpperCase (needle);
  7835. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7836. {
  7837. while (haystack[i] != 0)
  7838. {
  7839. if (haystack[i] == n1 || haystack[i] == n2)
  7840. return i;
  7841. ++i;
  7842. }
  7843. return -1;
  7844. }
  7845. jassert (n1 == needle);
  7846. }
  7847. while (haystack[i] != 0)
  7848. {
  7849. if (haystack[i] == needle)
  7850. return i;
  7851. ++i;
  7852. }
  7853. }
  7854. return -1;
  7855. }
  7856. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7857. {
  7858. jassert (haystack != 0);
  7859. int i = 0;
  7860. while (haystack[i] != 0)
  7861. {
  7862. if (haystack[i] == needle)
  7863. return i;
  7864. ++i;
  7865. }
  7866. return -1;
  7867. }
  7868. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7869. {
  7870. jassert (haystack != 0);
  7871. int i = 0;
  7872. while (haystack[i] != 0)
  7873. {
  7874. if (haystack[i] == needle)
  7875. return i;
  7876. ++i;
  7877. }
  7878. return -1;
  7879. }
  7880. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7881. {
  7882. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7883. }
  7884. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7885. {
  7886. if (allowedChars == 0)
  7887. return 0;
  7888. int i = 0;
  7889. for (;;)
  7890. {
  7891. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7892. break;
  7893. ++i;
  7894. }
  7895. return i;
  7896. }
  7897. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7898. {
  7899. return (int) strftime (dest, maxChars, format, tm);
  7900. }
  7901. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7902. {
  7903. return (int) wcsftime (dest, maxChars, format, tm);
  7904. }
  7905. int CharacterFunctions::getIntValue (const char* const s) throw()
  7906. {
  7907. return atoi (s);
  7908. }
  7909. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7910. {
  7911. #if JUCE_WIN32
  7912. return _wtoi (s);
  7913. #else
  7914. int v = 0;
  7915. while (isWhitespace (*s))
  7916. ++s;
  7917. const bool isNeg = *s == T('-');
  7918. if (isNeg)
  7919. ++s;
  7920. for (;;)
  7921. {
  7922. const wchar_t c = *s++;
  7923. if (c >= T('0') && c <= T('9'))
  7924. v = v * 10 + (int) (c - T('0'));
  7925. else
  7926. break;
  7927. }
  7928. return isNeg ? -v : v;
  7929. #endif
  7930. }
  7931. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7932. {
  7933. #if JUCE_LINUX
  7934. return atoll (s);
  7935. #elif defined (JUCE_WIN32)
  7936. return _atoi64 (s);
  7937. #else
  7938. int64 v = 0;
  7939. while (isWhitespace (*s))
  7940. ++s;
  7941. const bool isNeg = *s == T('-');
  7942. if (isNeg)
  7943. ++s;
  7944. for (;;)
  7945. {
  7946. const char c = *s++;
  7947. if (c >= '0' && c <= '9')
  7948. v = v * 10 + (int64) (c - '0');
  7949. else
  7950. break;
  7951. }
  7952. return isNeg ? -v : v;
  7953. #endif
  7954. }
  7955. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7956. {
  7957. #if JUCE_WIN32
  7958. return _wtoi64 (s);
  7959. #else
  7960. int64 v = 0;
  7961. while (isWhitespace (*s))
  7962. ++s;
  7963. const bool isNeg = *s == T('-');
  7964. if (isNeg)
  7965. ++s;
  7966. for (;;)
  7967. {
  7968. const juce_wchar c = *s++;
  7969. if (c >= T('0') && c <= T('9'))
  7970. v = v * 10 + (int64) (c - T('0'));
  7971. else
  7972. break;
  7973. }
  7974. return isNeg ? -v : v;
  7975. #endif
  7976. }
  7977. static double juce_mulexp10 (const double value, int exponent) throw()
  7978. {
  7979. if (exponent == 0)
  7980. return value;
  7981. if (value == 0)
  7982. return 0;
  7983. const bool negative = (exponent < 0);
  7984. if (negative)
  7985. exponent = -exponent;
  7986. double result = 1.0, power = 10.0;
  7987. for (int bit = 1; exponent != 0; bit <<= 1)
  7988. {
  7989. if ((exponent & bit) != 0)
  7990. {
  7991. exponent ^= bit;
  7992. result *= power;
  7993. if (exponent == 0)
  7994. break;
  7995. }
  7996. power *= power;
  7997. }
  7998. return negative ? (value / result) : (value * result);
  7999. }
  8000. template <class CharType>
  8001. double juce_atof (const CharType* const original) throw()
  8002. {
  8003. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  8004. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  8005. int exponent = 0, decPointIndex = 0, digit = 0;
  8006. int lastDigit = 0, numSignificantDigits = 0;
  8007. bool isNegative = false, digitsFound = false;
  8008. const int maxSignificantDigits = 15 + 2;
  8009. const CharType* s = original;
  8010. while (CharacterFunctions::isWhitespace (*s))
  8011. ++s;
  8012. switch (*s)
  8013. {
  8014. case '-': isNegative = true; // fall-through..
  8015. case '+': ++s;
  8016. }
  8017. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  8018. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  8019. for (;;)
  8020. {
  8021. if (CharacterFunctions::isDigit (*s))
  8022. {
  8023. lastDigit = digit;
  8024. digit = *s++ - '0';
  8025. digitsFound = true;
  8026. if (decPointIndex != 0)
  8027. exponentAdjustment[1]++;
  8028. if (numSignificantDigits == 0 && digit == 0)
  8029. continue;
  8030. if (++numSignificantDigits > maxSignificantDigits)
  8031. {
  8032. if (digit > 5)
  8033. ++accumulator [decPointIndex];
  8034. else if (digit == 5 && (lastDigit & 1) != 0)
  8035. ++accumulator [decPointIndex];
  8036. if (decPointIndex > 0)
  8037. exponentAdjustment[1]--;
  8038. else
  8039. exponentAdjustment[0]++;
  8040. while (CharacterFunctions::isDigit (*s))
  8041. {
  8042. ++s;
  8043. if (decPointIndex == 0)
  8044. exponentAdjustment[0]++;
  8045. }
  8046. }
  8047. else
  8048. {
  8049. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  8050. if (accumulator [decPointIndex] > maxAccumulatorValue)
  8051. {
  8052. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  8053. + accumulator [decPointIndex];
  8054. accumulator [decPointIndex] = 0;
  8055. exponentAccumulator [decPointIndex] = 0;
  8056. }
  8057. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  8058. exponentAccumulator [decPointIndex]++;
  8059. }
  8060. }
  8061. else if (decPointIndex == 0 && *s == '.')
  8062. {
  8063. ++s;
  8064. decPointIndex = 1;
  8065. if (numSignificantDigits > maxSignificantDigits)
  8066. {
  8067. while (CharacterFunctions::isDigit (*s))
  8068. ++s;
  8069. break;
  8070. }
  8071. }
  8072. else
  8073. {
  8074. break;
  8075. }
  8076. }
  8077. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  8078. if (decPointIndex != 0)
  8079. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  8080. if ((*s == 'e' || *s == 'E') && digitsFound)
  8081. {
  8082. bool negativeExponent = false;
  8083. switch (*++s)
  8084. {
  8085. case '-': negativeExponent = true; // fall-through..
  8086. case '+': ++s;
  8087. }
  8088. while (CharacterFunctions::isDigit (*s))
  8089. exponent = (exponent * 10) + (*s++ - '0');
  8090. if (negativeExponent)
  8091. exponent = -exponent;
  8092. }
  8093. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  8094. if (decPointIndex != 0)
  8095. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  8096. return isNegative ? -r : r;
  8097. }
  8098. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  8099. {
  8100. return juce_atof <char> (s);
  8101. }
  8102. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  8103. {
  8104. return juce_atof <juce_wchar> (s);
  8105. }
  8106. char CharacterFunctions::toUpperCase (const char character) throw()
  8107. {
  8108. return (char) toupper (character);
  8109. }
  8110. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  8111. {
  8112. return towupper (character);
  8113. }
  8114. void CharacterFunctions::toUpperCase (char* s) throw()
  8115. {
  8116. #if JUCE_WIN32
  8117. strupr (s);
  8118. #else
  8119. while (*s != 0)
  8120. {
  8121. *s = toUpperCase (*s);
  8122. ++s;
  8123. }
  8124. #endif
  8125. }
  8126. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8127. {
  8128. #if JUCE_WIN32
  8129. _wcsupr (s);
  8130. #else
  8131. while (*s != 0)
  8132. {
  8133. *s = toUpperCase (*s);
  8134. ++s;
  8135. }
  8136. #endif
  8137. }
  8138. bool CharacterFunctions::isUpperCase (const char character) throw()
  8139. {
  8140. return isupper (character) != 0;
  8141. }
  8142. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8143. {
  8144. #if JUCE_WIN32
  8145. return iswupper (character) != 0;
  8146. #else
  8147. return toLowerCase (character) != character;
  8148. #endif
  8149. }
  8150. char CharacterFunctions::toLowerCase (const char character) throw()
  8151. {
  8152. return (char) tolower (character);
  8153. }
  8154. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8155. {
  8156. return towlower (character);
  8157. }
  8158. void CharacterFunctions::toLowerCase (char* s) throw()
  8159. {
  8160. #if JUCE_WIN32
  8161. strlwr (s);
  8162. #else
  8163. while (*s != 0)
  8164. {
  8165. *s = toLowerCase (*s);
  8166. ++s;
  8167. }
  8168. #endif
  8169. }
  8170. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8171. {
  8172. #if JUCE_WIN32
  8173. _wcslwr (s);
  8174. #else
  8175. while (*s != 0)
  8176. {
  8177. *s = toLowerCase (*s);
  8178. ++s;
  8179. }
  8180. #endif
  8181. }
  8182. bool CharacterFunctions::isLowerCase (const char character) throw()
  8183. {
  8184. return islower (character) != 0;
  8185. }
  8186. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8187. {
  8188. #if JUCE_WIN32
  8189. return iswlower (character) != 0;
  8190. #else
  8191. return toUpperCase (character) != character;
  8192. #endif
  8193. }
  8194. bool CharacterFunctions::isWhitespace (const char character) throw()
  8195. {
  8196. return character == T(' ') || (character <= 13 && character >= 9);
  8197. }
  8198. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8199. {
  8200. return iswspace (character) != 0;
  8201. }
  8202. bool CharacterFunctions::isDigit (const char character) throw()
  8203. {
  8204. return (character >= '0' && character <= '9');
  8205. }
  8206. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8207. {
  8208. return iswdigit (character) != 0;
  8209. }
  8210. bool CharacterFunctions::isLetter (const char character) throw()
  8211. {
  8212. return (character >= 'a' && character <= 'z')
  8213. || (character >= 'A' && character <= 'Z');
  8214. }
  8215. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8216. {
  8217. return iswalpha (character) != 0;
  8218. }
  8219. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8220. {
  8221. return (character >= 'a' && character <= 'z')
  8222. || (character >= 'A' && character <= 'Z')
  8223. || (character >= '0' && character <= '9');
  8224. }
  8225. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8226. {
  8227. return iswalnum (character) != 0;
  8228. }
  8229. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8230. {
  8231. if (digit >= '0' && digit <= '9')
  8232. return digit - '0';
  8233. else if (digit >= 'a' && digit <= 'f')
  8234. return digit - ('a' - 10);
  8235. else if (digit >= 'A' && digit <= 'F')
  8236. return digit - ('A' - 10);
  8237. return -1;
  8238. }
  8239. int CharacterFunctions::printf (char* const dest, const int maxLength, const char* const format, ...) throw()
  8240. {
  8241. va_list list;
  8242. va_start (list, format);
  8243. return vprintf (dest, maxLength, format, list);
  8244. }
  8245. int CharacterFunctions::printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw()
  8246. {
  8247. va_list list;
  8248. va_start (list, format);
  8249. return vprintf (dest, maxLength, format, list);
  8250. }
  8251. int CharacterFunctions::vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw()
  8252. {
  8253. #if JUCE_WIN32
  8254. return (int) _vsnprintf (dest, maxLength, format, args);
  8255. #else
  8256. return (int) vsnprintf (dest, maxLength, format, args);
  8257. #endif
  8258. }
  8259. int CharacterFunctions::vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw()
  8260. {
  8261. #if defined (JUCE_WIN32)
  8262. return (int) _vsnwprintf (dest, maxLength, format, args);
  8263. #else
  8264. return (int) vswprintf (dest, maxLength, format, args);
  8265. #endif
  8266. }
  8267. END_JUCE_NAMESPACE
  8268. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8269. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8270. BEGIN_JUCE_NAMESPACE
  8271. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8272. {
  8273. loadFromText (fileContents);
  8274. }
  8275. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8276. {
  8277. loadFromText (fileToLoad.loadFileAsString());
  8278. }
  8279. LocalisedStrings::~LocalisedStrings()
  8280. {
  8281. }
  8282. const String LocalisedStrings::translate (const String& text) const
  8283. {
  8284. return translations.getValue (text, text);
  8285. }
  8286. static int findCloseQuote (const String& text, int startPos)
  8287. {
  8288. tchar lastChar = 0;
  8289. for (;;)
  8290. {
  8291. const tchar c = text [startPos];
  8292. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8293. break;
  8294. lastChar = c;
  8295. ++startPos;
  8296. }
  8297. return startPos;
  8298. }
  8299. static const String unescapeString (const String& s)
  8300. {
  8301. return s.replace (T("\\\""), T("\""))
  8302. .replace (T("\\\'"), T("\'"))
  8303. .replace (T("\\t"), T("\t"))
  8304. .replace (T("\\r"), T("\r"))
  8305. .replace (T("\\n"), T("\n"));
  8306. }
  8307. void LocalisedStrings::loadFromText (const String& fileContents)
  8308. {
  8309. StringArray lines;
  8310. lines.addLines (fileContents);
  8311. for (int i = 0; i < lines.size(); ++i)
  8312. {
  8313. String line (lines[i].trim());
  8314. if (line.startsWithChar (T('"')))
  8315. {
  8316. int closeQuote = findCloseQuote (line, 1);
  8317. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8318. if (originalText.isNotEmpty())
  8319. {
  8320. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8321. closeQuote = findCloseQuote (line, openingQuote + 1);
  8322. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8323. if (newText.isNotEmpty())
  8324. translations.set (originalText, newText);
  8325. }
  8326. }
  8327. else if (line.startsWithIgnoreCase (T("language:")))
  8328. {
  8329. languageName = line.substring (9).trim();
  8330. }
  8331. else if (line.startsWithIgnoreCase (T("countries:")))
  8332. {
  8333. countryCodes.addTokens (line.substring (10).trim(), true);
  8334. countryCodes.trim();
  8335. countryCodes.removeEmptyStrings();
  8336. }
  8337. }
  8338. }
  8339. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8340. {
  8341. translations.setIgnoresCase (shouldIgnoreCase);
  8342. }
  8343. static CriticalSection currentMappingsLock;
  8344. static LocalisedStrings* currentMappings = 0;
  8345. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8346. {
  8347. const ScopedLock sl (currentMappingsLock);
  8348. delete currentMappings;
  8349. currentMappings = newTranslations;
  8350. }
  8351. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8352. {
  8353. return currentMappings;
  8354. }
  8355. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8356. {
  8357. const ScopedLock sl (currentMappingsLock);
  8358. if (currentMappings != 0)
  8359. return currentMappings->translate (text);
  8360. return text;
  8361. }
  8362. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8363. {
  8364. return translateWithCurrentMappings (String (text));
  8365. }
  8366. END_JUCE_NAMESPACE
  8367. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8368. /*** Start of inlined file: juce_String.cpp ***/
  8369. #ifdef _MSC_VER
  8370. #pragma warning (disable: 4514)
  8371. #pragma warning (push)
  8372. #endif
  8373. #include <locale>
  8374. #if JUCE_MSVC
  8375. #include <float.h>
  8376. #endif
  8377. BEGIN_JUCE_NAMESPACE
  8378. #ifdef _MSC_VER
  8379. #pragma warning (pop)
  8380. #endif
  8381. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8382. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8383. #endif
  8384. static const char* const emptyCharString = "\0\0\0\0JUCE";
  8385. static const int safeEmptyStringRefCount = 0x3fffffff;
  8386. String::InternalRefCountedStringHolder String::emptyString = { safeEmptyStringRefCount, 0, { 0 } };
  8387. static tchar decimalPoint = T('.');
  8388. void juce_initialiseStrings()
  8389. {
  8390. decimalPoint = String::fromUTF8 (localeconv()->decimal_point) [0];
  8391. }
  8392. void String::createInternal (const int numChars) throw()
  8393. {
  8394. jassert (numChars > 0);
  8395. text = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8396. + numChars * sizeof (tchar));
  8397. text->refCount = 1;
  8398. text->allocatedNumChars = numChars;
  8399. text->text[0] = 0;
  8400. }
  8401. void String::createInternal (const tchar* const t, const tchar* const textEnd) throw()
  8402. {
  8403. jassert (*(textEnd - 1) == 0); // must have a null terminator
  8404. const int numChars = (int) (textEnd - t);
  8405. createInternal (numChars - 1);
  8406. memcpy (text->text, t, numChars * sizeof (tchar));
  8407. }
  8408. void String::appendInternal (const tchar* const newText,
  8409. const int numExtraChars) throw()
  8410. {
  8411. if (numExtraChars > 0)
  8412. {
  8413. const int oldLen = CharacterFunctions::length (text->text);
  8414. const int newTotalLen = oldLen + numExtraChars;
  8415. if (text->refCount > 1)
  8416. {
  8417. // it's in use by other strings as well, so we need to make a private copy before messing with it..
  8418. InternalRefCountedStringHolder* const newTextHolder
  8419. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8420. + newTotalLen * sizeof (tchar));
  8421. newTextHolder->refCount = 1;
  8422. newTextHolder->allocatedNumChars = newTotalLen;
  8423. memcpy (newTextHolder->text, text->text, oldLen * sizeof (tchar));
  8424. memcpy (newTextHolder->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8425. InternalRefCountedStringHolder* const old = text;
  8426. text = newTextHolder;
  8427. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8428. juce_free (old);
  8429. }
  8430. else
  8431. {
  8432. // no other strings using it, so just expand it if needed..
  8433. if (newTotalLen > text->allocatedNumChars)
  8434. {
  8435. text = (InternalRefCountedStringHolder*)
  8436. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8437. + newTotalLen * sizeof (tchar));
  8438. text->allocatedNumChars = newTotalLen;
  8439. }
  8440. memcpy (text->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8441. }
  8442. text->text [newTotalLen] = 0;
  8443. }
  8444. }
  8445. void String::dupeInternalIfMultiplyReferenced() throw()
  8446. {
  8447. if (text->refCount > 1)
  8448. {
  8449. InternalRefCountedStringHolder* const old = text;
  8450. const int len = old->allocatedNumChars;
  8451. InternalRefCountedStringHolder* const newTextHolder
  8452. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8453. + len * sizeof (tchar));
  8454. newTextHolder->refCount = 1;
  8455. newTextHolder->allocatedNumChars = len;
  8456. memcpy (newTextHolder->text, old->text, (len + 1) * sizeof (tchar));
  8457. text = newTextHolder;
  8458. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8459. juce_free (old);
  8460. }
  8461. }
  8462. const String String::empty;
  8463. String::String() throw()
  8464. : text (&emptyString)
  8465. {
  8466. }
  8467. String::String (const String& other) throw()
  8468. : text (other.text)
  8469. {
  8470. Atomic::increment (text->refCount);
  8471. }
  8472. String::String (const int numChars,
  8473. const int /*dummyVariable*/) throw()
  8474. {
  8475. createInternal (numChars);
  8476. }
  8477. String::String (const char* const t) throw()
  8478. {
  8479. if (t != 0 && *t != 0)
  8480. {
  8481. const int len = CharacterFunctions::length (t);
  8482. createInternal (len);
  8483. CharacterFunctions::copy (text->text, t, len + 1);
  8484. }
  8485. else
  8486. {
  8487. text = &emptyString;
  8488. emptyString.refCount = safeEmptyStringRefCount;
  8489. }
  8490. }
  8491. String::String (const juce_wchar* const t) throw()
  8492. {
  8493. if (t != 0 && *t != 0)
  8494. {
  8495. const int len = CharacterFunctions::length (t);
  8496. createInternal (len);
  8497. memcpy (text->text, t, (len + 1) * sizeof (tchar));
  8498. }
  8499. else
  8500. {
  8501. text = &emptyString;
  8502. emptyString.refCount = safeEmptyStringRefCount;
  8503. }
  8504. }
  8505. String::String (const char* const t,
  8506. const size_t maxChars) throw()
  8507. {
  8508. int i;
  8509. for (i = 0; (size_t) i < maxChars; ++i)
  8510. if (t[i] == 0)
  8511. break;
  8512. if (i > 0)
  8513. {
  8514. createInternal (i);
  8515. CharacterFunctions::copy (text->text, t, i);
  8516. text->text [i] = 0;
  8517. }
  8518. else
  8519. {
  8520. text = &emptyString;
  8521. emptyString.refCount = safeEmptyStringRefCount;
  8522. }
  8523. }
  8524. String::String (const juce_wchar* const t,
  8525. const size_t maxChars) throw()
  8526. {
  8527. int i;
  8528. for (i = 0; (size_t) i < maxChars; ++i)
  8529. if (t[i] == 0)
  8530. break;
  8531. if (i > 0)
  8532. {
  8533. createInternal (i);
  8534. memcpy (text->text, t, i * sizeof (tchar));
  8535. text->text [i] = 0;
  8536. }
  8537. else
  8538. {
  8539. text = &emptyString;
  8540. emptyString.refCount = safeEmptyStringRefCount;
  8541. }
  8542. }
  8543. const String String::charToString (const juce_wchar character) throw()
  8544. {
  8545. tchar temp[2];
  8546. temp[0] = character;
  8547. temp[1] = 0;
  8548. return String (temp);
  8549. }
  8550. namespace IntToCharConverters
  8551. {
  8552. // pass in a pointer to the END of a buffer..
  8553. static tchar* int64ToString (tchar* t, const int64 n) throw()
  8554. {
  8555. *--t = 0;
  8556. int64 v = (n >= 0) ? n : -n;
  8557. do
  8558. {
  8559. *--t = (tchar) (T('0') + (int) (v % 10));
  8560. v /= 10;
  8561. } while (v > 0);
  8562. if (n < 0)
  8563. *--t = T('-');
  8564. return t;
  8565. }
  8566. static tchar* uint64ToString (tchar* t, int64 v) throw()
  8567. {
  8568. *--t = 0;
  8569. do
  8570. {
  8571. *--t = (tchar) (T('0') + (int) (v % 10));
  8572. v /= 10;
  8573. } while (v > 0);
  8574. return t;
  8575. }
  8576. static tchar* intToString (tchar* t, const int n) throw()
  8577. {
  8578. if (n == (int) 0x80000000) // (would cause an overflow)
  8579. return int64ToString (t, n);
  8580. *--t = 0;
  8581. int v = abs (n);
  8582. do
  8583. {
  8584. *--t = (tchar) (T('0') + (v % 10));
  8585. v /= 10;
  8586. } while (v > 0);
  8587. if (n < 0)
  8588. *--t = T('-');
  8589. return t;
  8590. }
  8591. static tchar* uintToString (tchar* t, unsigned int v) throw()
  8592. {
  8593. *--t = 0;
  8594. do
  8595. {
  8596. *--t = (tchar) (T('0') + (v % 10));
  8597. v /= 10;
  8598. } while (v > 0);
  8599. return t;
  8600. }
  8601. }
  8602. String::String (const int number) throw()
  8603. {
  8604. tchar buffer [16];
  8605. tchar* const end = buffer + numElementsInArray (buffer);
  8606. createInternal (IntToCharConverters::intToString (end, number), end);
  8607. }
  8608. String::String (const unsigned int number) throw()
  8609. {
  8610. tchar buffer [16];
  8611. tchar* const end = buffer + numElementsInArray (buffer);
  8612. createInternal (IntToCharConverters::uintToString (end, number), end);
  8613. }
  8614. String::String (const short number) throw()
  8615. {
  8616. tchar buffer [16];
  8617. tchar* const end = buffer + numElementsInArray (buffer);
  8618. createInternal (IntToCharConverters::intToString (end, (int) number), end);
  8619. }
  8620. String::String (const unsigned short number) throw()
  8621. {
  8622. tchar buffer [16];
  8623. tchar* const end = buffer + numElementsInArray (buffer);
  8624. createInternal (IntToCharConverters::uintToString (end, (unsigned int) number), end);
  8625. }
  8626. String::String (const int64 number) throw()
  8627. {
  8628. tchar buffer [32];
  8629. tchar* const end = buffer + numElementsInArray (buffer);
  8630. createInternal (IntToCharConverters::int64ToString (end, number), end);
  8631. }
  8632. String::String (const uint64 number) throw()
  8633. {
  8634. tchar buffer [32];
  8635. tchar* const end = buffer + numElementsInArray (buffer);
  8636. createInternal (IntToCharConverters::uint64ToString (end, number), end);
  8637. }
  8638. // a double-to-string routine that actually uses the number of dec. places you asked for
  8639. // without resorting to exponent notation if the number's too big or small (which is what printf does).
  8640. void String::doubleToStringWithDecPlaces (double n, int numDecPlaces) throw()
  8641. {
  8642. const int bufSize = 80;
  8643. tchar buffer [bufSize];
  8644. int len;
  8645. tchar* t;
  8646. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8647. {
  8648. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8649. t = buffer + bufSize;
  8650. *--t = (tchar) 0;
  8651. while (numDecPlaces >= 0 || v > 0)
  8652. {
  8653. if (numDecPlaces == 0)
  8654. *--t = decimalPoint;
  8655. *--t = (tchar) (T('0') + (v % 10));
  8656. v /= 10;
  8657. --numDecPlaces;
  8658. }
  8659. if (n < 0)
  8660. *--t = T('-');
  8661. len = (int) ((buffer + bufSize) - t);
  8662. }
  8663. else
  8664. {
  8665. len = CharacterFunctions::printf (buffer, bufSize, T("%.9g"), n) + 1;
  8666. t = buffer;
  8667. }
  8668. if (len > 1)
  8669. {
  8670. jassert (len < numElementsInArray (buffer));
  8671. createInternal (len - 1);
  8672. memcpy (text->text, t, len * sizeof (tchar));
  8673. }
  8674. else
  8675. {
  8676. jassert (*t == 0);
  8677. text = &emptyString;
  8678. emptyString.refCount = safeEmptyStringRefCount;
  8679. }
  8680. }
  8681. String::String (const float number,
  8682. const int numberOfDecimalPlaces) throw()
  8683. {
  8684. doubleToStringWithDecPlaces ((double) number,
  8685. numberOfDecimalPlaces);
  8686. }
  8687. String::String (const double number,
  8688. const int numberOfDecimalPlaces) throw()
  8689. {
  8690. doubleToStringWithDecPlaces (number,
  8691. numberOfDecimalPlaces);
  8692. }
  8693. String::~String() throw()
  8694. {
  8695. emptyString.refCount = safeEmptyStringRefCount;
  8696. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8697. juce_free (text);
  8698. }
  8699. void String::preallocateStorage (const size_t numChars) throw()
  8700. {
  8701. if (numChars > (size_t) text->allocatedNumChars)
  8702. {
  8703. dupeInternalIfMultiplyReferenced();
  8704. text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8705. + numChars * sizeof (tchar));
  8706. text->allocatedNumChars = (int) numChars;
  8707. }
  8708. }
  8709. int String::length() const throw()
  8710. {
  8711. return CharacterFunctions::length (text->text);
  8712. }
  8713. int String::hashCode() const throw()
  8714. {
  8715. const tchar* t = text->text;
  8716. int result = 0;
  8717. while (*t != (tchar) 0)
  8718. result = 31 * result + *t++;
  8719. return result;
  8720. }
  8721. int64 String::hashCode64() const throw()
  8722. {
  8723. const tchar* t = text->text;
  8724. int64 result = 0;
  8725. while (*t != (tchar) 0)
  8726. result = 101 * result + *t++;
  8727. return result;
  8728. }
  8729. String& String::operator= (const String& other) throw()
  8730. {
  8731. if (this != &other)
  8732. {
  8733. InternalRefCountedStringHolder* newText = other.text;
  8734. Atomic::increment (newText->refCount);
  8735. InternalRefCountedStringHolder* oldText
  8736. = (InternalRefCountedStringHolder*) Atomic::swapPointers ((void* volatile*) &text, newText);
  8737. if (Atomic::decrementAndReturn (oldText->refCount) == 0)
  8738. juce_free (oldText);
  8739. }
  8740. return *this;
  8741. }
  8742. bool operator== (const String& string1, const String& string2) throw()
  8743. {
  8744. return string1.compare (string2) == 0;
  8745. }
  8746. bool operator== (const String& string1, const char* string2) throw()
  8747. {
  8748. return string1.compare (string2) == 0;
  8749. }
  8750. bool operator== (const String& string1, const juce_wchar* string2) throw()
  8751. {
  8752. return string1.compare (string2) == 0;
  8753. }
  8754. bool operator!= (const String& string1, const String& string2) throw()
  8755. {
  8756. return string1.compare (string2) != 0;
  8757. }
  8758. bool operator!= (const String& string1, const char* string2) throw()
  8759. {
  8760. return string1.compare (string2) != 0;
  8761. }
  8762. bool operator!= (const String& string1, const juce_wchar* string2) throw()
  8763. {
  8764. return string1.compare (string2) != 0;
  8765. }
  8766. bool operator> (const String& string1, const String& string2) throw()
  8767. {
  8768. return string1.compare (string2) > 0;
  8769. }
  8770. bool operator< (const String& string1, const String& string2) throw()
  8771. {
  8772. return string1.compare (string2) < 0;
  8773. }
  8774. bool operator>= (const String& string1, const String& string2) throw()
  8775. {
  8776. return string1.compare (string2) >= 0;
  8777. }
  8778. bool operator<= (const String& string1, const String& string2) throw()
  8779. {
  8780. return string1.compare (string2) <= 0;
  8781. }
  8782. bool String::equalsIgnoreCase (const tchar* t) const throw()
  8783. {
  8784. return t != 0 ? CharacterFunctions::compareIgnoreCase (text->text, t) == 0
  8785. : isEmpty();
  8786. }
  8787. bool String::equalsIgnoreCase (const String& other) const throw()
  8788. {
  8789. return text == other.text
  8790. || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0;
  8791. }
  8792. int String::compare (const String& other) const throw()
  8793. {
  8794. return (text == other.text) ? 0 : CharacterFunctions::compare (text->text, other.text->text);
  8795. }
  8796. int String::compare (const char* other) const throw()
  8797. {
  8798. return other == 0 ? isEmpty() : CharacterFunctions::compare (text->text, other);
  8799. }
  8800. int String::compare (const juce_wchar* other) const throw()
  8801. {
  8802. return other == 0 ? isEmpty() : CharacterFunctions::compare (text->text, other);
  8803. }
  8804. int String::compareIgnoreCase (const String& other) const throw()
  8805. {
  8806. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text->text, other.text->text);
  8807. }
  8808. int String::compareLexicographically (const String& other) const throw()
  8809. {
  8810. const tchar* s1 = text->text;
  8811. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8812. ++s1;
  8813. const tchar* s2 = other.text->text;
  8814. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8815. ++s2;
  8816. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8817. }
  8818. String& String::operator+= (const tchar* const t)
  8819. {
  8820. if (t != 0)
  8821. appendInternal (t, CharacterFunctions::length (t));
  8822. return *this;
  8823. }
  8824. String& String::operator+= (const String& other)
  8825. {
  8826. if (isEmpty())
  8827. operator= (other);
  8828. else
  8829. appendInternal (other.text->text, other.length());
  8830. return *this;
  8831. }
  8832. String& String::operator+= (const char ch)
  8833. {
  8834. const tchar asString[] = { (tchar) ch, 0 };
  8835. return operator+= ((const tchar*) asString);
  8836. }
  8837. String& String::operator+= (const juce_wchar ch)
  8838. {
  8839. const tchar asString[] = { (tchar) ch, 0 };
  8840. return operator+= ((const tchar*) asString);
  8841. }
  8842. String& String::operator+= (const int number)
  8843. {
  8844. tchar buffer [16];
  8845. tchar* const end = buffer + numElementsInArray (buffer);
  8846. tchar* const start = IntToCharConverters::intToString (end, number);
  8847. appendInternal (start, end - start);
  8848. return *this;
  8849. }
  8850. String& String::operator+= (const unsigned int number)
  8851. {
  8852. tchar buffer [16];
  8853. tchar* const end = buffer + numElementsInArray (buffer);
  8854. tchar* const start = IntToCharConverters::uintToString (end, number);
  8855. appendInternal (start, end - start);
  8856. return *this;
  8857. }
  8858. void String::append (const tchar* const other, const int howMany)
  8859. {
  8860. if (howMany > 0)
  8861. {
  8862. int i;
  8863. for (i = 0; i < howMany; ++i)
  8864. if (other[i] == 0)
  8865. break;
  8866. appendInternal (other, i);
  8867. }
  8868. }
  8869. const String operator+ (const char* const string1, const String& string2)
  8870. {
  8871. String s (string1);
  8872. return s += string2;
  8873. }
  8874. const String operator+ (const juce_wchar* const string1, const String& string2)
  8875. {
  8876. String s (string1);
  8877. return s += string2;
  8878. }
  8879. const String operator+ (const char string1, const String& string2)
  8880. {
  8881. return String::charToString (string1) + string2;
  8882. }
  8883. const String operator+ (const juce_wchar string1, const String& string2)
  8884. {
  8885. return String::charToString (string1) + string2;
  8886. }
  8887. const String operator+ (String string1, const String& string2)
  8888. {
  8889. return string1 += string2;
  8890. }
  8891. const String operator+ (String string1, const char* const string2)
  8892. {
  8893. return string1 += string2;
  8894. }
  8895. const String operator+ (String string1, const juce_wchar* const string2)
  8896. {
  8897. return string1 += string2;
  8898. }
  8899. const String operator+ (String string1, const char string2)
  8900. {
  8901. return string1 += string2;
  8902. }
  8903. const String operator+ (String string1, const juce_wchar string2)
  8904. {
  8905. return string1 += string2;
  8906. }
  8907. String& operator<< (String& string1, const char characterToAppend)
  8908. {
  8909. return string1 += characterToAppend;
  8910. }
  8911. String& operator<< (String& string1, const juce_wchar characterToAppend)
  8912. {
  8913. return string1 += characterToAppend;
  8914. }
  8915. String& operator<< (String& string1, const char* const string2)
  8916. {
  8917. return string1 += string2;
  8918. }
  8919. String& operator<< (String& string1, const juce_wchar* const string2)
  8920. {
  8921. return string1 += string2;
  8922. }
  8923. String& operator<< (String& string1, const String& string2)
  8924. {
  8925. return string1 += string2;
  8926. }
  8927. String& operator<< (String& string1, const short number)
  8928. {
  8929. return string1 += (int) number;
  8930. }
  8931. String& operator<< (String& string1, const int number)
  8932. {
  8933. return string1 += number;
  8934. }
  8935. String& operator<< (String& string1, const unsigned int number)
  8936. {
  8937. return string1 += number;
  8938. }
  8939. String& operator<< (String& string1, const long number)
  8940. {
  8941. return string1 += (int) number;
  8942. }
  8943. String& operator<< (String& string1, const unsigned long number)
  8944. {
  8945. return string1 += (unsigned int) number;
  8946. }
  8947. String& operator<< (String& string1, const float number)
  8948. {
  8949. return string1 += String (number);
  8950. }
  8951. String& operator<< (String& string1, const double number)
  8952. {
  8953. return string1 += String (number);
  8954. }
  8955. OutputStream& operator<< (OutputStream& stream, const String& text)
  8956. {
  8957. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8958. // if lots of large, persistent strings were to be written to streams).
  8959. const int numBytes = text.getNumBytesAsUTF8();
  8960. HeapBlock<char> temp (numBytes + 1);
  8961. text.copyToUTF8 (temp, numBytes + 1);
  8962. stream.write (temp, numBytes);
  8963. return stream;
  8964. }
  8965. int String::indexOfChar (const tchar character) const throw()
  8966. {
  8967. const tchar* t = text->text;
  8968. for (;;)
  8969. {
  8970. if (*t == character)
  8971. return (int) (t - text->text);
  8972. if (*t++ == 0)
  8973. return -1;
  8974. }
  8975. }
  8976. int String::lastIndexOfChar (const tchar character) const throw()
  8977. {
  8978. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  8979. if (text->text[i] == character)
  8980. return i;
  8981. return -1;
  8982. }
  8983. int String::indexOf (const tchar* const t) const throw()
  8984. {
  8985. const tchar* const r = CharacterFunctions::find (text->text, t);
  8986. return (r == 0) ? -1
  8987. : (int) (r - text->text);
  8988. }
  8989. int String::indexOfChar (const int startIndex,
  8990. const tchar character) const throw()
  8991. {
  8992. if (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text))
  8993. return -1;
  8994. const tchar* t = text->text + jmax (0, startIndex);
  8995. for (;;)
  8996. {
  8997. if (*t == character)
  8998. return (int) (t - text->text);
  8999. if (*t++ == 0)
  9000. return -1;
  9001. }
  9002. }
  9003. int String::indexOfAnyOf (const tchar* const charactersToLookFor,
  9004. const int startIndex,
  9005. const bool ignoreCase) const throw()
  9006. {
  9007. if (charactersToLookFor == 0
  9008. || (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text)))
  9009. return -1;
  9010. const tchar* t = text->text + jmax (0, startIndex);
  9011. while (*t != 0)
  9012. {
  9013. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  9014. return (int) (t - text->text);
  9015. ++t;
  9016. }
  9017. return -1;
  9018. }
  9019. int String::indexOf (const int startIndex,
  9020. const tchar* const other) const throw()
  9021. {
  9022. if (other == 0 || startIndex >= CharacterFunctions::length (text->text))
  9023. return -1;
  9024. const tchar* const found = CharacterFunctions::find (text->text + jmax (0, startIndex),
  9025. other);
  9026. return (found == 0) ? -1
  9027. : (int) (found - text->text);
  9028. }
  9029. int String::indexOfIgnoreCase (const tchar* const other) const throw()
  9030. {
  9031. if (other != 0 && *other != 0)
  9032. {
  9033. const int len = CharacterFunctions::length (other);
  9034. const int end = CharacterFunctions::length (text->text) - len;
  9035. for (int i = 0; i <= end; ++i)
  9036. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9037. return i;
  9038. }
  9039. return -1;
  9040. }
  9041. int String::indexOfIgnoreCase (const int startIndex,
  9042. const tchar* const other) const throw()
  9043. {
  9044. if (other != 0 && *other != 0)
  9045. {
  9046. const int len = CharacterFunctions::length (other);
  9047. const int end = length() - len;
  9048. for (int i = jmax (0, startIndex); i <= end; ++i)
  9049. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9050. return i;
  9051. }
  9052. return -1;
  9053. }
  9054. int String::lastIndexOf (const tchar* const other) const throw()
  9055. {
  9056. if (other != 0 && *other != 0)
  9057. {
  9058. const int len = CharacterFunctions::length (other);
  9059. int i = length() - len;
  9060. if (i >= 0)
  9061. {
  9062. const tchar* n = text->text + i;
  9063. while (i >= 0)
  9064. {
  9065. if (CharacterFunctions::compare (n--, other, len) == 0)
  9066. return i;
  9067. --i;
  9068. }
  9069. }
  9070. }
  9071. return -1;
  9072. }
  9073. int String::lastIndexOfIgnoreCase (const tchar* const other) const throw()
  9074. {
  9075. if (other != 0 && *other != 0)
  9076. {
  9077. const int len = CharacterFunctions::length (other);
  9078. int i = length() - len;
  9079. if (i >= 0)
  9080. {
  9081. const tchar* n = text->text + i;
  9082. while (i >= 0)
  9083. {
  9084. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  9085. return i;
  9086. --i;
  9087. }
  9088. }
  9089. }
  9090. return -1;
  9091. }
  9092. int String::lastIndexOfAnyOf (const tchar* const charactersToLookFor,
  9093. const bool ignoreCase) const throw()
  9094. {
  9095. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9096. if (CharacterFunctions::indexOfChar (charactersToLookFor, text->text [i], ignoreCase) >= 0)
  9097. return i;
  9098. return -1;
  9099. }
  9100. bool String::contains (const tchar* const other) const throw()
  9101. {
  9102. return indexOf (other) >= 0;
  9103. }
  9104. bool String::containsChar (const tchar character) const throw()
  9105. {
  9106. return indexOfChar (character) >= 0;
  9107. }
  9108. bool String::containsIgnoreCase (const tchar* const t) const throw()
  9109. {
  9110. return indexOfIgnoreCase (t) >= 0;
  9111. }
  9112. int String::indexOfWholeWord (const tchar* const word) const throw()
  9113. {
  9114. if (word != 0 && *word != 0)
  9115. {
  9116. const int wordLen = CharacterFunctions::length (word);
  9117. const int end = length() - wordLen;
  9118. const tchar* t = text->text;
  9119. for (int i = 0; i <= end; ++i)
  9120. {
  9121. if (CharacterFunctions::compare (t, word, wordLen) == 0
  9122. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9123. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9124. {
  9125. return i;
  9126. }
  9127. ++t;
  9128. }
  9129. }
  9130. return -1;
  9131. }
  9132. int String::indexOfWholeWordIgnoreCase (const tchar* const word) const throw()
  9133. {
  9134. if (word != 0 && *word != 0)
  9135. {
  9136. const int wordLen = CharacterFunctions::length (word);
  9137. const int end = length() - wordLen;
  9138. const tchar* t = text->text;
  9139. for (int i = 0; i <= end; ++i)
  9140. {
  9141. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  9142. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9143. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9144. {
  9145. return i;
  9146. }
  9147. ++t;
  9148. }
  9149. }
  9150. return -1;
  9151. }
  9152. bool String::containsWholeWord (const tchar* const wordToLookFor) const throw()
  9153. {
  9154. return indexOfWholeWord (wordToLookFor) >= 0;
  9155. }
  9156. bool String::containsWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw()
  9157. {
  9158. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9159. }
  9160. static int indexOfMatch (const tchar* const wildcard,
  9161. const tchar* const test,
  9162. const bool ignoreCase) throw()
  9163. {
  9164. int start = 0;
  9165. while (test [start] != 0)
  9166. {
  9167. int i = 0;
  9168. for (;;)
  9169. {
  9170. const tchar wc = wildcard [i];
  9171. const tchar c = test [i + start];
  9172. if (wc == c
  9173. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9174. || (wc == T('?') && c != 0))
  9175. {
  9176. if (wc == 0)
  9177. return start;
  9178. ++i;
  9179. }
  9180. else
  9181. {
  9182. if (wc == T('*') && (wildcard [i + 1] == 0
  9183. || indexOfMatch (wildcard + i + 1,
  9184. test + start + i,
  9185. ignoreCase) >= 0))
  9186. {
  9187. return start;
  9188. }
  9189. break;
  9190. }
  9191. }
  9192. ++start;
  9193. }
  9194. return -1;
  9195. }
  9196. bool String::matchesWildcard (const tchar* wildcard, const bool ignoreCase) const throw()
  9197. {
  9198. int i = 0;
  9199. for (;;)
  9200. {
  9201. const tchar wc = wildcard [i];
  9202. const tchar c = text->text [i];
  9203. if (wc == c
  9204. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9205. || (wc == T('?') && c != 0))
  9206. {
  9207. if (wc == 0)
  9208. return true;
  9209. ++i;
  9210. }
  9211. else
  9212. {
  9213. return wc == T('*') && (wildcard [i + 1] == 0
  9214. || indexOfMatch (wildcard + i + 1,
  9215. text->text + i,
  9216. ignoreCase) >= 0);
  9217. }
  9218. }
  9219. }
  9220. void String::printf (const tchar* const pf, ...) throw()
  9221. {
  9222. va_list list;
  9223. va_start (list, pf);
  9224. vprintf (pf, list);
  9225. }
  9226. const String String::formatted (const tchar* const pf, ...) throw()
  9227. {
  9228. va_list list;
  9229. va_start (list, pf);
  9230. String result;
  9231. result.vprintf (pf, list);
  9232. return result;
  9233. }
  9234. void String::vprintf (const tchar* const pf, va_list& args) throw()
  9235. {
  9236. int bufferSize = 256;
  9237. String result (bufferSize, 0);
  9238. do
  9239. {
  9240. #if JUCE_LINUX && JUCE_64BIT
  9241. va_list tempArgs;
  9242. va_copy (tempArgs, args);
  9243. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, tempArgs);
  9244. va_end (tempArgs);
  9245. #else
  9246. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, args);
  9247. #endif
  9248. if (num > 0)
  9249. {
  9250. *this = result;
  9251. break;
  9252. }
  9253. else if (num == 0)
  9254. {
  9255. *this = String::empty;
  9256. break;
  9257. }
  9258. bufferSize += 256;
  9259. result.preallocateStorage (bufferSize);
  9260. }
  9261. while (bufferSize < 65536); // this is a sanity check to avoid situations where vprintf repeatedly
  9262. // returns -1 because of an error rather than because it needs more space.
  9263. }
  9264. const String String::repeatedString (const tchar* const stringToRepeat,
  9265. int numberOfTimesToRepeat) throw()
  9266. {
  9267. const int len = CharacterFunctions::length (stringToRepeat);
  9268. String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0);
  9269. tchar* n = result.text->text;
  9270. n[0] = 0;
  9271. while (--numberOfTimesToRepeat >= 0)
  9272. {
  9273. CharacterFunctions::append (n, stringToRepeat);
  9274. n += len;
  9275. }
  9276. return result;
  9277. }
  9278. const String String::replaceSection (int index,
  9279. int numCharsToReplace,
  9280. const tchar* const stringToInsert) const throw()
  9281. {
  9282. if (index < 0)
  9283. {
  9284. // a negative index to replace from?
  9285. jassertfalse
  9286. index = 0;
  9287. }
  9288. if (numCharsToReplace < 0)
  9289. {
  9290. // replacing a negative number of characters?
  9291. numCharsToReplace = 0;
  9292. jassertfalse;
  9293. }
  9294. const int len = length();
  9295. if (index + numCharsToReplace > len)
  9296. {
  9297. if (index > len)
  9298. {
  9299. // replacing beyond the end of the string?
  9300. index = len;
  9301. jassertfalse
  9302. }
  9303. numCharsToReplace = len - index;
  9304. }
  9305. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9306. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9307. if (newTotalLen <= 0)
  9308. return String::empty;
  9309. String result (newTotalLen, (int) 0);
  9310. memcpy (result.text->text,
  9311. text->text,
  9312. index * sizeof (tchar));
  9313. if (newStringLen > 0)
  9314. memcpy (result.text->text + index,
  9315. stringToInsert,
  9316. newStringLen * sizeof (tchar));
  9317. const int endStringLen = newTotalLen - (index + newStringLen);
  9318. if (endStringLen > 0)
  9319. memcpy (result.text->text + (index + newStringLen),
  9320. text->text + (index + numCharsToReplace),
  9321. endStringLen * sizeof (tchar));
  9322. result.text->text [newTotalLen] = 0;
  9323. return result;
  9324. }
  9325. const String String::replace (const tchar* const stringToReplace,
  9326. const tchar* const stringToInsert,
  9327. const bool ignoreCase) const throw()
  9328. {
  9329. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9330. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9331. int i = 0;
  9332. String result (*this);
  9333. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9334. : result.indexOf (i, stringToReplace))) >= 0)
  9335. {
  9336. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9337. i += stringToInsertLen;
  9338. }
  9339. return result;
  9340. }
  9341. const String String::replaceCharacter (const tchar charToReplace,
  9342. const tchar charToInsert) const throw()
  9343. {
  9344. const int index = indexOfChar (charToReplace);
  9345. if (index < 0)
  9346. return *this;
  9347. String result (*this);
  9348. result.dupeInternalIfMultiplyReferenced();
  9349. tchar* t = result.text->text + index;
  9350. while (*t != 0)
  9351. {
  9352. if (*t == charToReplace)
  9353. *t = charToInsert;
  9354. ++t;
  9355. }
  9356. return result;
  9357. }
  9358. const String String::replaceCharacters (const String& charactersToReplace,
  9359. const tchar* const charactersToInsertInstead) const throw()
  9360. {
  9361. String result (*this);
  9362. result.dupeInternalIfMultiplyReferenced();
  9363. tchar* t = result.text->text;
  9364. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9365. // the two strings passed in are supposed to be the same length!
  9366. jassert (len2 == charactersToReplace.length());
  9367. while (*t != 0)
  9368. {
  9369. const int index = charactersToReplace.indexOfChar (*t);
  9370. if (((unsigned int) index) < (unsigned int) len2)
  9371. *t = charactersToInsertInstead [index];
  9372. ++t;
  9373. }
  9374. return result;
  9375. }
  9376. bool String::startsWith (const tchar* const other) const throw()
  9377. {
  9378. return other != 0
  9379. && CharacterFunctions::compare (text->text, other, CharacterFunctions::length (other)) == 0;
  9380. }
  9381. bool String::startsWithIgnoreCase (const tchar* const other) const throw()
  9382. {
  9383. return other != 0
  9384. && CharacterFunctions::compareIgnoreCase (text->text, other, CharacterFunctions::length (other)) == 0;
  9385. }
  9386. bool String::startsWithChar (const tchar character) const throw()
  9387. {
  9388. jassert (character != 0); // strings can't contain a null character!
  9389. return text->text[0] == character;
  9390. }
  9391. bool String::endsWithChar (const tchar character) const throw()
  9392. {
  9393. jassert (character != 0); // strings can't contain a null character!
  9394. return text->text[0] != 0
  9395. && text->text [length() - 1] == character;
  9396. }
  9397. bool String::endsWith (const tchar* const other) const throw()
  9398. {
  9399. if (other == 0)
  9400. return false;
  9401. const int thisLen = length();
  9402. const int otherLen = CharacterFunctions::length (other);
  9403. return thisLen >= otherLen
  9404. && CharacterFunctions::compare (text->text + thisLen - otherLen, other) == 0;
  9405. }
  9406. bool String::endsWithIgnoreCase (const tchar* const other) const throw()
  9407. {
  9408. if (other == 0)
  9409. return false;
  9410. const int thisLen = length();
  9411. const int otherLen = CharacterFunctions::length (other);
  9412. return thisLen >= otherLen
  9413. && CharacterFunctions::compareIgnoreCase (text->text + thisLen - otherLen, other) == 0;
  9414. }
  9415. const String String::toUpperCase() const throw()
  9416. {
  9417. String result (*this);
  9418. result.dupeInternalIfMultiplyReferenced();
  9419. CharacterFunctions::toUpperCase (result.text->text);
  9420. return result;
  9421. }
  9422. const String String::toLowerCase() const throw()
  9423. {
  9424. String result (*this);
  9425. result.dupeInternalIfMultiplyReferenced();
  9426. CharacterFunctions::toLowerCase (result.text->text);
  9427. return result;
  9428. }
  9429. juce_wchar& String::operator[] (const int index) throw()
  9430. {
  9431. jassert (((unsigned int) index) <= (unsigned int) length());
  9432. dupeInternalIfMultiplyReferenced();
  9433. return text->text [index];
  9434. }
  9435. juce_wchar String::getLastCharacter() const throw()
  9436. {
  9437. return (isEmpty()) ? ((juce_wchar) 0)
  9438. : text->text [CharacterFunctions::length (text->text) - 1];
  9439. }
  9440. const String String::substring (int start, int end) const throw()
  9441. {
  9442. if (start < 0)
  9443. start = 0;
  9444. else if (end <= start)
  9445. return empty;
  9446. int len = 0;
  9447. const tchar* const t = text->text;
  9448. while (len <= end && t [len] != 0)
  9449. ++len;
  9450. if (end >= len)
  9451. {
  9452. if (start == 0)
  9453. return *this;
  9454. end = len;
  9455. }
  9456. return String (text->text + start,
  9457. end - start);
  9458. }
  9459. const String String::substring (const int start) const throw()
  9460. {
  9461. if (start <= 0)
  9462. return *this;
  9463. const int len = CharacterFunctions::length (text->text);
  9464. if (start >= len)
  9465. return empty;
  9466. else
  9467. return String (text->text + start,
  9468. len - start);
  9469. }
  9470. const String String::dropLastCharacters (const int numberToDrop) const throw()
  9471. {
  9472. return String (text->text,
  9473. jmax (0, CharacterFunctions::length (text->text) - numberToDrop));
  9474. }
  9475. const String String::getLastCharacters (const int numCharacters) const throw()
  9476. {
  9477. return String (text->text + jmax (0, CharacterFunctions::length (text->text) - jmax (0, numCharacters)));
  9478. }
  9479. const String String::fromFirstOccurrenceOf (const tchar* const sub,
  9480. const bool includeSubString,
  9481. const bool ignoreCase) const throw()
  9482. {
  9483. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9484. : indexOf (sub);
  9485. if (i < 0)
  9486. return empty;
  9487. else
  9488. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9489. }
  9490. const String String::fromLastOccurrenceOf (const tchar* const sub,
  9491. const bool includeSubString,
  9492. const bool ignoreCase) const throw()
  9493. {
  9494. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9495. : lastIndexOf (sub);
  9496. if (i < 0)
  9497. return *this;
  9498. else
  9499. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9500. }
  9501. const String String::upToFirstOccurrenceOf (const tchar* const sub,
  9502. const bool includeSubString,
  9503. const bool ignoreCase) const throw()
  9504. {
  9505. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9506. : indexOf (sub);
  9507. if (i < 0)
  9508. return *this;
  9509. else
  9510. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9511. }
  9512. const String String::upToLastOccurrenceOf (const tchar* const sub,
  9513. const bool includeSubString,
  9514. const bool ignoreCase) const throw()
  9515. {
  9516. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9517. : lastIndexOf (sub);
  9518. if (i < 0)
  9519. return *this;
  9520. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9521. }
  9522. bool String::isQuotedString() const throw()
  9523. {
  9524. const String trimmed (trimStart());
  9525. return trimmed[0] == T('"')
  9526. || trimmed[0] == T('\'');
  9527. }
  9528. const String String::unquoted() const throw()
  9529. {
  9530. String s (*this);
  9531. if (s[0] == T('"') || s[0] == T('\''))
  9532. s = s.substring (1);
  9533. const int lastCharIndex = s.length() - 1;
  9534. if (lastCharIndex >= 0
  9535. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9536. s [lastCharIndex] = 0;
  9537. return s;
  9538. }
  9539. const String String::quoted (const tchar quoteCharacter) const throw()
  9540. {
  9541. if (isEmpty())
  9542. return charToString (quoteCharacter) + quoteCharacter;
  9543. String t (*this);
  9544. if (! t.startsWithChar (quoteCharacter))
  9545. t = charToString (quoteCharacter) + t;
  9546. if (! t.endsWithChar (quoteCharacter))
  9547. t += quoteCharacter;
  9548. return t;
  9549. }
  9550. const String String::trim() const throw()
  9551. {
  9552. if (isEmpty())
  9553. return empty;
  9554. int start = 0;
  9555. while (CharacterFunctions::isWhitespace (text->text [start]))
  9556. ++start;
  9557. const int len = CharacterFunctions::length (text->text);
  9558. int end = len - 1;
  9559. while ((end >= start) && CharacterFunctions::isWhitespace (text->text [end]))
  9560. --end;
  9561. ++end;
  9562. if (end <= start)
  9563. return empty;
  9564. else if (start > 0 || end < len)
  9565. return String (text->text + start, end - start);
  9566. else
  9567. return *this;
  9568. }
  9569. const String String::trimStart() const throw()
  9570. {
  9571. if (isEmpty())
  9572. return empty;
  9573. const tchar* t = text->text;
  9574. while (CharacterFunctions::isWhitespace (*t))
  9575. ++t;
  9576. if (t == text->text)
  9577. return *this;
  9578. else
  9579. return String (t);
  9580. }
  9581. const String String::trimEnd() const throw()
  9582. {
  9583. if (isEmpty())
  9584. return empty;
  9585. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9586. while ((endT >= text->text) && CharacterFunctions::isWhitespace (*endT))
  9587. --endT;
  9588. return String (text->text, (int) (++endT - text->text));
  9589. }
  9590. const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw()
  9591. {
  9592. jassert (charactersToTrim != 0);
  9593. if (isEmpty())
  9594. return empty;
  9595. const tchar* t = text->text;
  9596. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9597. ++t;
  9598. if (t == text->text)
  9599. return *this;
  9600. else
  9601. return String (t);
  9602. }
  9603. const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw()
  9604. {
  9605. jassert (charactersToTrim != 0);
  9606. if (isEmpty())
  9607. return empty;
  9608. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9609. while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9610. --endT;
  9611. return String (text->text, (int) (++endT - text->text));
  9612. }
  9613. const String String::retainCharacters (const tchar* const charactersToRetain) const throw()
  9614. {
  9615. jassert (charactersToRetain != 0);
  9616. if (isEmpty())
  9617. return empty;
  9618. String result (text->allocatedNumChars, (int) 0);
  9619. tchar* dst = result.text->text;
  9620. const tchar* src = text->text;
  9621. while (*src != 0)
  9622. {
  9623. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9624. *dst++ = *src;
  9625. ++src;
  9626. }
  9627. *dst = 0;
  9628. return result;
  9629. }
  9630. const String String::removeCharacters (const tchar* const charactersToRemove) const throw()
  9631. {
  9632. jassert (charactersToRemove != 0);
  9633. if (isEmpty())
  9634. return empty;
  9635. String result (text->allocatedNumChars, (int) 0);
  9636. tchar* dst = result.text->text;
  9637. const tchar* src = text->text;
  9638. while (*src != 0)
  9639. {
  9640. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9641. *dst++ = *src;
  9642. ++src;
  9643. }
  9644. *dst = 0;
  9645. return result;
  9646. }
  9647. const String String::initialSectionContainingOnly (const tchar* const permittedCharacters) const throw()
  9648. {
  9649. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text->text, permittedCharacters));
  9650. }
  9651. const String String::initialSectionNotContaining (const tchar* const charactersToStopAt) const throw()
  9652. {
  9653. jassert (charactersToStopAt != 0);
  9654. const tchar* const t = text->text;
  9655. int i = 0;
  9656. while (t[i] != 0)
  9657. {
  9658. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9659. return String (text->text, i);
  9660. ++i;
  9661. }
  9662. return empty;
  9663. }
  9664. bool String::containsOnly (const tchar* const chars) const throw()
  9665. {
  9666. jassert (chars != 0);
  9667. const tchar* t = text->text;
  9668. while (*t != 0)
  9669. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9670. return false;
  9671. return true;
  9672. }
  9673. bool String::containsAnyOf (const tchar* const chars) const throw()
  9674. {
  9675. jassert (chars != 0);
  9676. const tchar* t = text->text;
  9677. while (*t != 0)
  9678. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9679. return true;
  9680. return false;
  9681. }
  9682. bool String::containsNonWhitespaceChars() const throw()
  9683. {
  9684. const tchar* t = text->text;
  9685. while (*t != 0)
  9686. if (! CharacterFunctions::isWhitespace (*t++))
  9687. return true;
  9688. return false;
  9689. }
  9690. int String::getIntValue() const throw()
  9691. {
  9692. return CharacterFunctions::getIntValue (text->text);
  9693. }
  9694. int String::getTrailingIntValue() const throw()
  9695. {
  9696. int n = 0;
  9697. int mult = 1;
  9698. const tchar* t = text->text + length();
  9699. while (--t >= text->text)
  9700. {
  9701. const tchar c = *t;
  9702. if (! CharacterFunctions::isDigit (c))
  9703. {
  9704. if (c == T('-'))
  9705. n = -n;
  9706. break;
  9707. }
  9708. n += mult * (c - T('0'));
  9709. mult *= 10;
  9710. }
  9711. return n;
  9712. }
  9713. int64 String::getLargeIntValue() const throw()
  9714. {
  9715. return CharacterFunctions::getInt64Value (text->text);
  9716. }
  9717. float String::getFloatValue() const throw()
  9718. {
  9719. return (float) CharacterFunctions::getDoubleValue (text->text);
  9720. }
  9721. double String::getDoubleValue() const throw()
  9722. {
  9723. return CharacterFunctions::getDoubleValue (text->text);
  9724. }
  9725. static const tchar* const hexDigits = T("0123456789abcdef");
  9726. const String String::toHexString (const int number) throw()
  9727. {
  9728. tchar buffer[32];
  9729. tchar* const end = buffer + 32;
  9730. tchar* t = end;
  9731. *--t = 0;
  9732. unsigned int v = (unsigned int) number;
  9733. do
  9734. {
  9735. *--t = hexDigits [v & 15];
  9736. v >>= 4;
  9737. } while (v != 0);
  9738. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9739. }
  9740. const String String::toHexString (const int64 number) throw()
  9741. {
  9742. tchar buffer[32];
  9743. tchar* const end = buffer + 32;
  9744. tchar* t = end;
  9745. *--t = 0;
  9746. uint64 v = (uint64) number;
  9747. do
  9748. {
  9749. *--t = hexDigits [(int) (v & 15)];
  9750. v >>= 4;
  9751. } while (v != 0);
  9752. return String (t, (int) (((char*) end) - (char*) t));
  9753. }
  9754. const String String::toHexString (const short number) throw()
  9755. {
  9756. return toHexString ((int) (unsigned short) number);
  9757. }
  9758. const String String::toHexString (const unsigned char* data,
  9759. const int size,
  9760. const int groupSize) throw()
  9761. {
  9762. if (size <= 0)
  9763. return empty;
  9764. int numChars = (size * 2) + 2;
  9765. if (groupSize > 0)
  9766. numChars += size / groupSize;
  9767. String s (numChars, (int) 0);
  9768. tchar* d = s.text->text;
  9769. for (int i = 0; i < size; ++i)
  9770. {
  9771. *d++ = hexDigits [(*data) >> 4];
  9772. *d++ = hexDigits [(*data) & 0xf];
  9773. ++data;
  9774. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9775. *d++ = T(' ');
  9776. }
  9777. *d = 0;
  9778. return s;
  9779. }
  9780. int String::getHexValue32() const throw()
  9781. {
  9782. int result = 0;
  9783. const tchar* c = text->text;
  9784. for (;;)
  9785. {
  9786. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9787. if (hexValue >= 0)
  9788. result = (result << 4) | hexValue;
  9789. else if (*c == 0)
  9790. break;
  9791. ++c;
  9792. }
  9793. return result;
  9794. }
  9795. int64 String::getHexValue64() const throw()
  9796. {
  9797. int64 result = 0;
  9798. const tchar* c = text->text;
  9799. for (;;)
  9800. {
  9801. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9802. if (hexValue >= 0)
  9803. result = (result << 4) | hexValue;
  9804. else if (*c == 0)
  9805. break;
  9806. ++c;
  9807. }
  9808. return result;
  9809. }
  9810. const String String::createStringFromData (const void* const data_,
  9811. const int size) throw()
  9812. {
  9813. const char* const data = (const char*) data_;
  9814. if (size <= 0 || data == 0)
  9815. {
  9816. return empty;
  9817. }
  9818. else if (size < 2)
  9819. {
  9820. return charToString (data[0]);
  9821. }
  9822. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9823. || (data[0] == (char)-1 && data[1] == (char)-2))
  9824. {
  9825. // assume it's 16-bit unicode
  9826. const bool bigEndian = (data[0] == (char)-2);
  9827. const int numChars = size / 2 - 1;
  9828. String result;
  9829. result.preallocateStorage (numChars + 2);
  9830. const uint16* const src = (const uint16*) (data + 2);
  9831. tchar* const dst = const_cast <tchar*> ((const tchar*) result);
  9832. if (bigEndian)
  9833. {
  9834. for (int i = 0; i < numChars; ++i)
  9835. dst[i] = (tchar) ByteOrder::swapIfLittleEndian (src[i]);
  9836. }
  9837. else
  9838. {
  9839. for (int i = 0; i < numChars; ++i)
  9840. dst[i] = (tchar) ByteOrder::swapIfBigEndian (src[i]);
  9841. }
  9842. dst [numChars] = 0;
  9843. return result;
  9844. }
  9845. else
  9846. {
  9847. return String::fromUTF8 (data, size);
  9848. }
  9849. }
  9850. const char* String::toUTF8() const
  9851. {
  9852. if (isEmpty())
  9853. {
  9854. return (const char*) emptyCharString;
  9855. }
  9856. else
  9857. {
  9858. String* const mutableThis = const_cast <String*> (this);
  9859. mutableThis->dupeInternalIfMultiplyReferenced();
  9860. const int currentLen = CharacterFunctions::length (text->text) + 1;
  9861. const int utf8BytesNeeded = getNumBytesAsUTF8() + 1;
  9862. mutableThis->text = (InternalRefCountedStringHolder*)
  9863. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  9864. + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded));
  9865. char* const otherCopy = (char*) (text->text + currentLen);
  9866. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9867. return otherCopy;
  9868. }
  9869. }
  9870. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9871. {
  9872. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9873. int num = 0, index = 0;
  9874. for (;;)
  9875. {
  9876. const uint32 c = (uint32) text->text [index++];
  9877. if (c >= 0x80)
  9878. {
  9879. int numExtraBytes = 1;
  9880. if (c >= 0x800)
  9881. {
  9882. ++numExtraBytes;
  9883. if (c >= 0x10000)
  9884. {
  9885. ++numExtraBytes;
  9886. if (c >= 0x200000)
  9887. {
  9888. ++numExtraBytes;
  9889. if (c >= 0x4000000)
  9890. ++numExtraBytes;
  9891. }
  9892. }
  9893. }
  9894. if (buffer != 0)
  9895. {
  9896. if (num + numExtraBytes >= maxBufferSizeBytes)
  9897. {
  9898. buffer [num++] = 0;
  9899. break;
  9900. }
  9901. else
  9902. {
  9903. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9904. while (--numExtraBytes >= 0)
  9905. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9906. }
  9907. }
  9908. else
  9909. {
  9910. num += numExtraBytes + 1;
  9911. }
  9912. }
  9913. else
  9914. {
  9915. if (buffer != 0)
  9916. {
  9917. if (num + 1 >= maxBufferSizeBytes)
  9918. {
  9919. buffer [num++] = 0;
  9920. break;
  9921. }
  9922. buffer [num] = (uint8) c;
  9923. }
  9924. ++num;
  9925. }
  9926. if (c == 0)
  9927. break;
  9928. }
  9929. return num;
  9930. }
  9931. int String::getNumBytesAsUTF8() const throw()
  9932. {
  9933. int num = 0;
  9934. const juce_wchar* t = text->text;
  9935. for (;;)
  9936. {
  9937. const uint32 c = (uint32) *t;
  9938. if (c >= 0x80)
  9939. {
  9940. ++num;
  9941. if (c >= 0x800)
  9942. {
  9943. ++num;
  9944. if (c >= 0x10000)
  9945. {
  9946. ++num;
  9947. if (c >= 0x200000)
  9948. {
  9949. ++num;
  9950. if (c >= 0x4000000)
  9951. ++num;
  9952. }
  9953. }
  9954. }
  9955. }
  9956. else if (c == 0)
  9957. break;
  9958. ++num;
  9959. ++t;
  9960. }
  9961. return num;
  9962. }
  9963. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9964. {
  9965. if (buffer == 0)
  9966. return empty;
  9967. if (bufferSizeBytes < 0)
  9968. bufferSizeBytes = std::numeric_limits<int>::max();
  9969. size_t numBytes;
  9970. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9971. if (buffer [numBytes] == 0)
  9972. break;
  9973. String result ((int) numBytes + 1, 0);
  9974. juce_wchar* dest = result.text->text;
  9975. size_t i = 0;
  9976. while (i < numBytes)
  9977. {
  9978. const char c = buffer [i++];
  9979. if (c < 0)
  9980. {
  9981. unsigned int mask = 0x7f;
  9982. int bit = 0x40;
  9983. int numExtraValues = 0;
  9984. while (bit != 0 && (c & bit) != 0)
  9985. {
  9986. bit >>= 1;
  9987. mask >>= 1;
  9988. ++numExtraValues;
  9989. }
  9990. int n = (mask & (unsigned char) c);
  9991. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9992. {
  9993. const char nextByte = buffer[i];
  9994. if ((nextByte & 0xc0) != 0x80)
  9995. break;
  9996. n <<= 6;
  9997. n |= (nextByte & 0x3f);
  9998. ++i;
  9999. }
  10000. *dest++ = (juce_wchar) n;
  10001. }
  10002. else
  10003. {
  10004. *dest++ = (juce_wchar) c;
  10005. }
  10006. }
  10007. *dest = 0;
  10008. return result;
  10009. }
  10010. const char* String::toCString() const
  10011. {
  10012. if (isEmpty())
  10013. {
  10014. return (const char*) emptyCharString;
  10015. }
  10016. else
  10017. {
  10018. String* const mutableThis = const_cast <String*> (this);
  10019. mutableThis->dupeInternalIfMultiplyReferenced();
  10020. int len = length() + 1;
  10021. mutableThis->text = (InternalRefCountedStringHolder*)
  10022. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  10023. + (len * sizeof (juce_wchar) + len));
  10024. char* otherCopy = (char*) (text->text + len);
  10025. --len;
  10026. CharacterFunctions::copy (otherCopy, text->text, len);
  10027. otherCopy [len] = 0;
  10028. return otherCopy;
  10029. }
  10030. }
  10031. #ifdef _MSC_VER
  10032. #pragma warning (disable: 4514 4996)
  10033. #pragma warning (push)
  10034. #endif
  10035. int String::getNumBytesAsCString() const throw()
  10036. {
  10037. return (int) wcstombs (0, text->text, 0);
  10038. }
  10039. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  10040. {
  10041. const int numBytes = (int) wcstombs (destBuffer, text->text, maxBufferSizeBytes);
  10042. if (destBuffer != 0 && numBytes >= 0)
  10043. destBuffer [numBytes] = 0;
  10044. return numBytes;
  10045. }
  10046. #ifdef _MSC_VER
  10047. #pragma warning (pop)
  10048. #endif
  10049. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  10050. {
  10051. const int len = jmin (maxCharsToCopy, length());
  10052. memcpy (destBuffer, text->text, len * sizeof (juce_wchar));
  10053. destBuffer [len] = 0;
  10054. }
  10055. String::Concatenator::Concatenator (String& stringToAppendTo)
  10056. : result (stringToAppendTo),
  10057. nextIndex (stringToAppendTo.length())
  10058. {
  10059. }
  10060. String::Concatenator::~Concatenator()
  10061. {
  10062. }
  10063. void String::Concatenator::append (const String& s)
  10064. {
  10065. const int len = s.length();
  10066. if (len > 0)
  10067. {
  10068. result.preallocateStorage (nextIndex + len);
  10069. s.copyToUnicode (((juce_wchar*) result) + nextIndex, len);
  10070. nextIndex += len;
  10071. }
  10072. }
  10073. END_JUCE_NAMESPACE
  10074. /*** End of inlined file: juce_String.cpp ***/
  10075. /*** Start of inlined file: juce_StringArray.cpp ***/
  10076. BEGIN_JUCE_NAMESPACE
  10077. StringArray::StringArray() throw()
  10078. {
  10079. }
  10080. StringArray::StringArray (const StringArray& other)
  10081. : strings (other.strings)
  10082. {
  10083. }
  10084. StringArray::StringArray (const juce_wchar** const initialStrings,
  10085. const int numberOfStrings)
  10086. {
  10087. for (int i = 0; i < numberOfStrings; ++i)
  10088. add (initialStrings [i]);
  10089. }
  10090. StringArray::StringArray (const char** const initialStrings,
  10091. const int numberOfStrings)
  10092. {
  10093. for (int i = 0; i < numberOfStrings; ++i)
  10094. add (initialStrings [i]);
  10095. }
  10096. StringArray::StringArray (const juce_wchar** const initialStrings)
  10097. {
  10098. int i = 0;
  10099. while (initialStrings[i] != 0)
  10100. add (initialStrings [i++]);
  10101. }
  10102. StringArray::StringArray (const char** const initialStrings)
  10103. {
  10104. int i = 0;
  10105. while (initialStrings[i] != 0)
  10106. add (initialStrings [i++]);
  10107. }
  10108. StringArray& StringArray::operator= (const StringArray& other)
  10109. {
  10110. strings = other.strings;
  10111. return *this;
  10112. }
  10113. StringArray::~StringArray()
  10114. {
  10115. }
  10116. bool StringArray::operator== (const StringArray& other) const
  10117. {
  10118. if (other.size() != size())
  10119. return false;
  10120. for (int i = size(); --i >= 0;)
  10121. if (other.strings.getReference(i) != strings.getReference(i))
  10122. return false;
  10123. return true;
  10124. }
  10125. bool StringArray::operator!= (const StringArray& other) const
  10126. {
  10127. return ! operator== (other);
  10128. }
  10129. void StringArray::clear()
  10130. {
  10131. strings.clear();
  10132. }
  10133. const String& StringArray::operator[] (const int index) const throw()
  10134. {
  10135. if (((unsigned int) index) < (unsigned int) strings.size())
  10136. return strings.getReference (index);
  10137. return String::empty;
  10138. }
  10139. void StringArray::add (const String& newString)
  10140. {
  10141. strings.add (newString);
  10142. }
  10143. void StringArray::insert (const int index, const String& newString)
  10144. {
  10145. strings.insert (index, newString);
  10146. }
  10147. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  10148. {
  10149. if (! contains (newString, ignoreCase))
  10150. add (newString);
  10151. }
  10152. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  10153. {
  10154. if (startIndex < 0)
  10155. {
  10156. jassertfalse
  10157. startIndex = 0;
  10158. }
  10159. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10160. numElementsToAdd = otherArray.size() - startIndex;
  10161. while (--numElementsToAdd >= 0)
  10162. strings.add (otherArray.strings.getReference (startIndex++));
  10163. }
  10164. void StringArray::set (const int index, const String& newString)
  10165. {
  10166. strings.set (index, newString);
  10167. }
  10168. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10169. {
  10170. if (ignoreCase)
  10171. {
  10172. for (int i = size(); --i >= 0;)
  10173. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10174. return true;
  10175. }
  10176. else
  10177. {
  10178. for (int i = size(); --i >= 0;)
  10179. if (stringToLookFor == strings.getReference(i))
  10180. return true;
  10181. }
  10182. return false;
  10183. }
  10184. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10185. {
  10186. if (i < 0)
  10187. i = 0;
  10188. const int numElements = size();
  10189. if (ignoreCase)
  10190. {
  10191. while (i < numElements)
  10192. {
  10193. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10194. return i;
  10195. ++i;
  10196. }
  10197. }
  10198. else
  10199. {
  10200. while (i < numElements)
  10201. {
  10202. if (stringToLookFor == strings.getReference (i))
  10203. return i;
  10204. ++i;
  10205. }
  10206. }
  10207. return -1;
  10208. }
  10209. void StringArray::remove (const int index)
  10210. {
  10211. strings.remove (index);
  10212. }
  10213. void StringArray::removeString (const String& stringToRemove,
  10214. const bool ignoreCase)
  10215. {
  10216. if (ignoreCase)
  10217. {
  10218. for (int i = size(); --i >= 0;)
  10219. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10220. strings.remove (i);
  10221. }
  10222. else
  10223. {
  10224. for (int i = size(); --i >= 0;)
  10225. if (stringToRemove == strings.getReference (i))
  10226. strings.remove (i);
  10227. }
  10228. }
  10229. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10230. {
  10231. if (removeWhitespaceStrings)
  10232. {
  10233. for (int i = size(); --i >= 0;)
  10234. if (! strings.getReference(i).containsNonWhitespaceChars())
  10235. strings.remove (i);
  10236. }
  10237. else
  10238. {
  10239. for (int i = size(); --i >= 0;)
  10240. if (strings.getReference(i).isEmpty())
  10241. strings.remove (i);
  10242. }
  10243. }
  10244. void StringArray::trim()
  10245. {
  10246. for (int i = size(); --i >= 0;)
  10247. {
  10248. String& s = strings.getReference(i);
  10249. s = s.trim();
  10250. }
  10251. }
  10252. class InternalStringArrayComparator_CaseSensitive
  10253. {
  10254. public:
  10255. static int compareElements (String& first, String& second) { return first.compare (second); }
  10256. };
  10257. class InternalStringArrayComparator_CaseInsensitive
  10258. {
  10259. public:
  10260. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10261. };
  10262. void StringArray::sort (const bool ignoreCase)
  10263. {
  10264. if (ignoreCase)
  10265. {
  10266. InternalStringArrayComparator_CaseInsensitive comp;
  10267. strings.sort (comp);
  10268. }
  10269. else
  10270. {
  10271. InternalStringArrayComparator_CaseSensitive comp;
  10272. strings.sort (comp);
  10273. }
  10274. }
  10275. void StringArray::move (const int currentIndex, int newIndex) throw()
  10276. {
  10277. strings.move (currentIndex, newIndex);
  10278. }
  10279. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10280. {
  10281. const int last = (numberToJoin < 0) ? size()
  10282. : jmin (size(), start + numberToJoin);
  10283. if (start < 0)
  10284. start = 0;
  10285. if (start >= last)
  10286. return String::empty;
  10287. if (start == last - 1)
  10288. return strings.getReference (start);
  10289. const int separatorLen = separator.length();
  10290. int charsNeeded = separatorLen * (last - start - 1);
  10291. for (int i = start; i < last; ++i)
  10292. charsNeeded += strings.getReference(i).length();
  10293. String result;
  10294. result.preallocateStorage (charsNeeded);
  10295. juce_wchar* dest = (juce_wchar*) result;
  10296. while (start < last)
  10297. {
  10298. const String& s = strings.getReference (start);
  10299. const int len = s.length();
  10300. if (len > 0)
  10301. {
  10302. s.copyToUnicode (dest, len);
  10303. dest += len;
  10304. }
  10305. if (++start < last && separatorLen > 0)
  10306. {
  10307. separator.copyToUnicode (dest, separatorLen);
  10308. dest += separatorLen;
  10309. }
  10310. }
  10311. *dest = 0;
  10312. return result;
  10313. }
  10314. int StringArray::addTokens (const tchar* const text, const bool preserveQuotedStrings)
  10315. {
  10316. return addTokens (text,
  10317. T(" \n\r\t"),
  10318. preserveQuotedStrings ? T("\"") : 0);
  10319. }
  10320. int StringArray::addTokens (const tchar* const text, const tchar* breakCharacters, const tchar* quoteCharacters)
  10321. {
  10322. int num = 0;
  10323. if (text != 0 && *text != 0)
  10324. {
  10325. if (breakCharacters == 0)
  10326. breakCharacters = T("");
  10327. if (quoteCharacters == 0)
  10328. quoteCharacters = T("");
  10329. bool insideQuotes = false;
  10330. tchar currentQuoteChar = 0;
  10331. int i = 0;
  10332. int tokenStart = 0;
  10333. for (;;)
  10334. {
  10335. const tchar c = text[i];
  10336. bool isBreak = (c == 0);
  10337. if (! (insideQuotes || isBreak))
  10338. {
  10339. const tchar* b = breakCharacters;
  10340. while (*b != 0)
  10341. {
  10342. if (*b++ == c)
  10343. {
  10344. isBreak = true;
  10345. break;
  10346. }
  10347. }
  10348. }
  10349. if (! isBreak)
  10350. {
  10351. bool isQuote = false;
  10352. const tchar* q = quoteCharacters;
  10353. while (*q != 0)
  10354. {
  10355. if (*q++ == c)
  10356. {
  10357. isQuote = true;
  10358. break;
  10359. }
  10360. }
  10361. if (isQuote)
  10362. {
  10363. if (insideQuotes)
  10364. {
  10365. // only break out of quotes-mode if we find a matching quote to the
  10366. // one that we opened with..
  10367. if (currentQuoteChar == c)
  10368. insideQuotes = false;
  10369. }
  10370. else
  10371. {
  10372. insideQuotes = true;
  10373. currentQuoteChar = c;
  10374. }
  10375. }
  10376. }
  10377. else
  10378. {
  10379. add (String (text + tokenStart, i - tokenStart));
  10380. ++num;
  10381. tokenStart = i + 1;
  10382. }
  10383. if (c == 0)
  10384. break;
  10385. ++i;
  10386. }
  10387. }
  10388. return num;
  10389. }
  10390. int StringArray::addLines (const tchar* text)
  10391. {
  10392. int numLines = 0;
  10393. if (text != 0)
  10394. {
  10395. while (*text != 0)
  10396. {
  10397. const tchar* const startOfLine = text;
  10398. while (*text != 0)
  10399. {
  10400. if (*text == T('\r'))
  10401. {
  10402. ++text;
  10403. if (*text == T('\n'))
  10404. ++text;
  10405. break;
  10406. }
  10407. if (*text == T('\n'))
  10408. {
  10409. ++text;
  10410. break;
  10411. }
  10412. ++text;
  10413. }
  10414. const tchar* endOfLine = text;
  10415. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10416. --endOfLine;
  10417. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10418. --endOfLine;
  10419. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10420. ++numLines;
  10421. }
  10422. }
  10423. return numLines;
  10424. }
  10425. void StringArray::removeDuplicates (const bool ignoreCase)
  10426. {
  10427. for (int i = 0; i < size() - 1; ++i)
  10428. {
  10429. const String s (strings.getReference(i));
  10430. int nextIndex = i + 1;
  10431. for (;;)
  10432. {
  10433. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10434. if (nextIndex < 0)
  10435. break;
  10436. strings.remove (nextIndex);
  10437. }
  10438. }
  10439. }
  10440. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10441. const bool appendNumberToFirstInstance,
  10442. const tchar* const preNumberString,
  10443. const tchar* const postNumberString)
  10444. {
  10445. for (int i = 0; i < size() - 1; ++i)
  10446. {
  10447. String& s = strings.getReference(i);
  10448. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10449. if (nextIndex >= 0)
  10450. {
  10451. const String original (s);
  10452. int number = 0;
  10453. if (appendNumberToFirstInstance)
  10454. s = original + preNumberString + String (++number) + postNumberString;
  10455. else
  10456. ++number;
  10457. while (nextIndex >= 0)
  10458. {
  10459. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10460. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10461. }
  10462. }
  10463. }
  10464. }
  10465. void StringArray::minimiseStorageOverheads()
  10466. {
  10467. strings.minimiseStorageOverheads();
  10468. }
  10469. END_JUCE_NAMESPACE
  10470. /*** End of inlined file: juce_StringArray.cpp ***/
  10471. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10472. BEGIN_JUCE_NAMESPACE
  10473. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10474. : ignoreCase (ignoreCase_)
  10475. {
  10476. }
  10477. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10478. : keys (other.keys),
  10479. values (other.values),
  10480. ignoreCase (other.ignoreCase)
  10481. {
  10482. }
  10483. StringPairArray::~StringPairArray() throw()
  10484. {
  10485. }
  10486. StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10487. {
  10488. keys = other.keys;
  10489. values = other.values;
  10490. return *this;
  10491. }
  10492. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10493. {
  10494. for (int i = keys.size(); --i >= 0;)
  10495. if (other [keys[i]] != values[i])
  10496. return false;
  10497. return true;
  10498. }
  10499. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10500. {
  10501. return ! operator== (other);
  10502. }
  10503. const String& StringPairArray::operator[] (const String& key) const throw()
  10504. {
  10505. return values [keys.indexOf (key, ignoreCase)];
  10506. }
  10507. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10508. {
  10509. const int i = keys.indexOf (key, ignoreCase);
  10510. if (i >= 0)
  10511. return values[i];
  10512. return defaultReturnValue;
  10513. }
  10514. void StringPairArray::set (const String& key,
  10515. const String& value) throw()
  10516. {
  10517. const int i = keys.indexOf (key, ignoreCase);
  10518. if (i >= 0)
  10519. {
  10520. values.set (i, value);
  10521. }
  10522. else
  10523. {
  10524. keys.add (key);
  10525. values.add (value);
  10526. }
  10527. }
  10528. void StringPairArray::addArray (const StringPairArray& other)
  10529. {
  10530. for (int i = 0; i < other.size(); ++i)
  10531. set (other.keys[i], other.values[i]);
  10532. }
  10533. void StringPairArray::clear() throw()
  10534. {
  10535. keys.clear();
  10536. values.clear();
  10537. }
  10538. void StringPairArray::remove (const String& key) throw()
  10539. {
  10540. remove (keys.indexOf (key, ignoreCase));
  10541. }
  10542. void StringPairArray::remove (const int index) throw()
  10543. {
  10544. keys.remove (index);
  10545. values.remove (index);
  10546. }
  10547. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10548. {
  10549. ignoreCase = shouldIgnoreCase;
  10550. }
  10551. const String StringPairArray::getDescription() const
  10552. {
  10553. String s;
  10554. for (int i = 0; i < keys.size(); ++i)
  10555. {
  10556. s << keys[i] << T(" = ") << values[i];
  10557. if (i < keys.size())
  10558. s << T(", ");
  10559. }
  10560. return s;
  10561. }
  10562. void StringPairArray::minimiseStorageOverheads() throw()
  10563. {
  10564. keys.minimiseStorageOverheads();
  10565. values.minimiseStorageOverheads();
  10566. }
  10567. END_JUCE_NAMESPACE
  10568. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10569. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10570. BEGIN_JUCE_NAMESPACE
  10571. XmlDocument::XmlDocument (const String& documentText) throw()
  10572. : originalText (documentText),
  10573. ignoreEmptyTextElements (true)
  10574. {
  10575. }
  10576. XmlDocument::XmlDocument (const File& file)
  10577. {
  10578. inputSource = new FileInputSource (file);
  10579. }
  10580. XmlDocument::~XmlDocument() throw()
  10581. {
  10582. }
  10583. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10584. {
  10585. inputSource = newSource;
  10586. }
  10587. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10588. {
  10589. ignoreEmptyTextElements = shouldBeIgnored;
  10590. }
  10591. bool XmlDocument::isXmlIdentifierCharSlow (const tchar c) throw()
  10592. {
  10593. return CharacterFunctions::isLetterOrDigit (c)
  10594. || c == T('_')
  10595. || c == T('-')
  10596. || c == T(':')
  10597. || c == T('.');
  10598. }
  10599. inline bool XmlDocument::isXmlIdentifierChar (const tchar c) const throw()
  10600. {
  10601. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10602. : isXmlIdentifierCharSlow (c);
  10603. }
  10604. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10605. {
  10606. String textToParse (originalText);
  10607. if (textToParse.isEmpty() && inputSource != 0)
  10608. {
  10609. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10610. if (in != 0)
  10611. {
  10612. MemoryBlock data;
  10613. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10614. if (data.getSize() >= 2
  10615. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10616. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10617. {
  10618. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10619. }
  10620. else
  10621. {
  10622. textToParse = String::fromUTF8 ((const char*) data.getData(), (int) data.getSize());
  10623. }
  10624. if (! onlyReadOuterDocumentElement)
  10625. originalText = textToParse;
  10626. }
  10627. }
  10628. input = textToParse;
  10629. lastError = String::empty;
  10630. errorOccurred = false;
  10631. outOfData = false;
  10632. needToLoadDTD = true;
  10633. for (int i = 0; i < 128; ++i)
  10634. identifierLookupTable[i] = isXmlIdentifierCharSlow ((tchar) i);
  10635. if (textToParse.isEmpty())
  10636. {
  10637. lastError = "not enough input";
  10638. }
  10639. else
  10640. {
  10641. skipHeader();
  10642. if (input != 0)
  10643. {
  10644. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10645. if (! errorOccurred)
  10646. return result.release();
  10647. }
  10648. else
  10649. {
  10650. lastError = "incorrect xml header";
  10651. }
  10652. }
  10653. return 0;
  10654. }
  10655. const String& XmlDocument::getLastParseError() const throw()
  10656. {
  10657. return lastError;
  10658. }
  10659. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10660. {
  10661. lastError = desc;
  10662. errorOccurred = ! carryOn;
  10663. }
  10664. const String XmlDocument::getFileContents (const String& filename) const
  10665. {
  10666. if (inputSource != 0)
  10667. {
  10668. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10669. if (in != 0)
  10670. return in->readEntireStreamAsString();
  10671. }
  10672. return String::empty;
  10673. }
  10674. tchar XmlDocument::readNextChar() throw()
  10675. {
  10676. if (*input != 0)
  10677. {
  10678. return *input++;
  10679. }
  10680. else
  10681. {
  10682. outOfData = true;
  10683. return 0;
  10684. }
  10685. }
  10686. int XmlDocument::findNextTokenLength() throw()
  10687. {
  10688. int len = 0;
  10689. tchar c = *input;
  10690. while (isXmlIdentifierChar (c))
  10691. c = input [++len];
  10692. return len;
  10693. }
  10694. void XmlDocument::skipHeader() throw()
  10695. {
  10696. const tchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10697. if (found != 0)
  10698. {
  10699. input = found;
  10700. input = CharacterFunctions::find (input, T("?>"));
  10701. if (input == 0)
  10702. return;
  10703. input += 2;
  10704. }
  10705. skipNextWhiteSpace();
  10706. const tchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10707. if (docType == 0)
  10708. return;
  10709. input = docType + 9;
  10710. int n = 1;
  10711. while (n > 0)
  10712. {
  10713. const tchar c = readNextChar();
  10714. if (outOfData)
  10715. return;
  10716. if (c == T('<'))
  10717. ++n;
  10718. else if (c == T('>'))
  10719. --n;
  10720. }
  10721. docType += 9;
  10722. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10723. }
  10724. void XmlDocument::skipNextWhiteSpace() throw()
  10725. {
  10726. for (;;)
  10727. {
  10728. tchar c = *input;
  10729. while (CharacterFunctions::isWhitespace (c))
  10730. c = *++input;
  10731. if (c == 0)
  10732. {
  10733. outOfData = true;
  10734. break;
  10735. }
  10736. else if (c == T('<'))
  10737. {
  10738. if (input[1] == T('!')
  10739. && input[2] == T('-')
  10740. && input[3] == T('-'))
  10741. {
  10742. const tchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10743. if (closeComment == 0)
  10744. {
  10745. outOfData = true;
  10746. break;
  10747. }
  10748. input = closeComment + 3;
  10749. continue;
  10750. }
  10751. else if (input[1] == T('?'))
  10752. {
  10753. const tchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10754. if (closeBracket == 0)
  10755. {
  10756. outOfData = true;
  10757. break;
  10758. }
  10759. input = closeBracket + 2;
  10760. continue;
  10761. }
  10762. }
  10763. break;
  10764. }
  10765. }
  10766. void XmlDocument::readQuotedString (String& result) throw()
  10767. {
  10768. const tchar quote = readNextChar();
  10769. while (! outOfData)
  10770. {
  10771. const tchar c = readNextChar();
  10772. if (c == quote)
  10773. break;
  10774. if (c == T('&'))
  10775. {
  10776. --input;
  10777. readEntity (result);
  10778. }
  10779. else
  10780. {
  10781. --input;
  10782. const tchar* const start = input;
  10783. for (;;)
  10784. {
  10785. const tchar character = *input;
  10786. if (character == quote)
  10787. {
  10788. result.append (start, (int) (input - start));
  10789. ++input;
  10790. return;
  10791. }
  10792. else if (character == T('&'))
  10793. {
  10794. result.append (start, (int) (input - start));
  10795. break;
  10796. }
  10797. else if (character == 0)
  10798. {
  10799. outOfData = true;
  10800. setLastError ("unmatched quotes", false);
  10801. break;
  10802. }
  10803. ++input;
  10804. }
  10805. }
  10806. }
  10807. }
  10808. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10809. {
  10810. XmlElement* node = 0;
  10811. skipNextWhiteSpace();
  10812. if (outOfData)
  10813. return 0;
  10814. input = CharacterFunctions::find (input, T("<"));
  10815. if (input != 0)
  10816. {
  10817. ++input;
  10818. int tagLen = findNextTokenLength();
  10819. if (tagLen == 0)
  10820. {
  10821. // no tag name - but allow for a gap after the '<' before giving an error
  10822. skipNextWhiteSpace();
  10823. tagLen = findNextTokenLength();
  10824. if (tagLen == 0)
  10825. {
  10826. setLastError ("tag name missing", false);
  10827. return node;
  10828. }
  10829. }
  10830. node = new XmlElement (String (input, tagLen));
  10831. input += tagLen;
  10832. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10833. // look for attributes
  10834. for (;;)
  10835. {
  10836. skipNextWhiteSpace();
  10837. const tchar c = *input;
  10838. // empty tag..
  10839. if (c == T('/') && input[1] == T('>'))
  10840. {
  10841. input += 2;
  10842. break;
  10843. }
  10844. // parse the guts of the element..
  10845. if (c == T('>'))
  10846. {
  10847. ++input;
  10848. skipNextWhiteSpace();
  10849. if (alsoParseSubElements)
  10850. readChildElements (node);
  10851. break;
  10852. }
  10853. // get an attribute..
  10854. if (isXmlIdentifierChar (c))
  10855. {
  10856. const int attNameLen = findNextTokenLength();
  10857. if (attNameLen > 0)
  10858. {
  10859. const tchar* attNameStart = input;
  10860. input += attNameLen;
  10861. skipNextWhiteSpace();
  10862. if (readNextChar() == T('='))
  10863. {
  10864. skipNextWhiteSpace();
  10865. const tchar nextChar = *input;
  10866. if (nextChar == T('"') || nextChar == T('\''))
  10867. {
  10868. XmlElement::XmlAttributeNode* const newAtt
  10869. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10870. String::empty);
  10871. readQuotedString (newAtt->value);
  10872. if (lastAttribute == 0)
  10873. node->attributes = newAtt;
  10874. else
  10875. lastAttribute->next = newAtt;
  10876. lastAttribute = newAtt;
  10877. continue;
  10878. }
  10879. }
  10880. }
  10881. }
  10882. else
  10883. {
  10884. if (! outOfData)
  10885. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10886. }
  10887. break;
  10888. }
  10889. }
  10890. return node;
  10891. }
  10892. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10893. {
  10894. XmlElement* lastChildNode = 0;
  10895. for (;;)
  10896. {
  10897. skipNextWhiteSpace();
  10898. if (outOfData)
  10899. {
  10900. setLastError ("unmatched tags", false);
  10901. break;
  10902. }
  10903. if (*input == T('<'))
  10904. {
  10905. if (input[1] == T('/'))
  10906. {
  10907. // our close tag..
  10908. input = CharacterFunctions::find (input, T(">"));
  10909. ++input;
  10910. break;
  10911. }
  10912. else if (input[1] == T('!')
  10913. && input[2] == T('[')
  10914. && input[3] == T('C')
  10915. && input[4] == T('D')
  10916. && input[5] == T('A')
  10917. && input[6] == T('T')
  10918. && input[7] == T('A')
  10919. && input[8] == T('['))
  10920. {
  10921. input += 9;
  10922. const tchar* const inputStart = input;
  10923. int len = 0;
  10924. for (;;)
  10925. {
  10926. if (*input == 0)
  10927. {
  10928. setLastError ("unterminated CDATA section", false);
  10929. outOfData = true;
  10930. break;
  10931. }
  10932. else if (input[0] == T(']')
  10933. && input[1] == T(']')
  10934. && input[2] == T('>'))
  10935. {
  10936. input += 3;
  10937. break;
  10938. }
  10939. ++input;
  10940. ++len;
  10941. }
  10942. XmlElement* const e = new XmlElement ((int) 0);
  10943. e->setText (String (inputStart, len));
  10944. if (lastChildNode != 0)
  10945. lastChildNode->nextElement = e;
  10946. else
  10947. parent->addChildElement (e);
  10948. lastChildNode = e;
  10949. }
  10950. else
  10951. {
  10952. // this is some other element, so parse and add it..
  10953. XmlElement* const n = readNextElement (true);
  10954. if (n != 0)
  10955. {
  10956. if (lastChildNode == 0)
  10957. parent->addChildElement (n);
  10958. else
  10959. lastChildNode->nextElement = n;
  10960. lastChildNode = n;
  10961. }
  10962. else
  10963. {
  10964. return;
  10965. }
  10966. }
  10967. }
  10968. else
  10969. {
  10970. // read character block..
  10971. XmlElement* const e = new XmlElement ((int)0);
  10972. if (lastChildNode != 0)
  10973. lastChildNode->nextElement = e;
  10974. else
  10975. parent->addChildElement (e);
  10976. lastChildNode = e;
  10977. String textElementContent;
  10978. for (;;)
  10979. {
  10980. const tchar c = *input;
  10981. if (c == T('<'))
  10982. break;
  10983. if (c == 0)
  10984. {
  10985. setLastError ("unmatched tags", false);
  10986. outOfData = true;
  10987. return;
  10988. }
  10989. if (c == T('&'))
  10990. {
  10991. String entity;
  10992. readEntity (entity);
  10993. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  10994. {
  10995. const tchar* const oldInput = input;
  10996. const bool oldOutOfData = outOfData;
  10997. input = (const tchar*) entity;
  10998. outOfData = false;
  10999. for (;;)
  11000. {
  11001. XmlElement* const n = readNextElement (true);
  11002. if (n == 0)
  11003. break;
  11004. if (lastChildNode == 0)
  11005. parent->addChildElement (n);
  11006. else
  11007. lastChildNode->nextElement = n;
  11008. lastChildNode = n;
  11009. }
  11010. input = oldInput;
  11011. outOfData = oldOutOfData;
  11012. }
  11013. else
  11014. {
  11015. textElementContent += entity;
  11016. }
  11017. }
  11018. else
  11019. {
  11020. const tchar* start = input;
  11021. int len = 0;
  11022. for (;;)
  11023. {
  11024. const tchar nextChar = *input;
  11025. if (nextChar == T('<') || nextChar == T('&'))
  11026. {
  11027. break;
  11028. }
  11029. else if (nextChar == 0)
  11030. {
  11031. setLastError ("unmatched tags", false);
  11032. outOfData = true;
  11033. return;
  11034. }
  11035. ++input;
  11036. ++len;
  11037. }
  11038. textElementContent.append (start, len);
  11039. }
  11040. }
  11041. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  11042. : textElementContent.isNotEmpty())
  11043. e->setText (textElementContent);
  11044. }
  11045. }
  11046. }
  11047. void XmlDocument::readEntity (String& result) throw()
  11048. {
  11049. // skip over the ampersand
  11050. ++input;
  11051. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  11052. {
  11053. input += 4;
  11054. result += T("&");
  11055. }
  11056. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  11057. {
  11058. input += 5;
  11059. result += T("\"");
  11060. }
  11061. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  11062. {
  11063. input += 5;
  11064. result += T("\'");
  11065. }
  11066. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  11067. {
  11068. input += 3;
  11069. result += T("<");
  11070. }
  11071. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  11072. {
  11073. input += 3;
  11074. result += T(">");
  11075. }
  11076. else if (*input == T('#'))
  11077. {
  11078. int charCode = 0;
  11079. ++input;
  11080. if (*input == T('x') || *input == T('X'))
  11081. {
  11082. ++input;
  11083. int numChars = 0;
  11084. while (input[0] != T(';'))
  11085. {
  11086. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  11087. if (hexValue < 0 || ++numChars > 8)
  11088. {
  11089. setLastError ("illegal escape sequence", true);
  11090. break;
  11091. }
  11092. charCode = (charCode << 4) | hexValue;
  11093. ++input;
  11094. }
  11095. ++input;
  11096. }
  11097. else if (input[0] >= T('0') && input[0] <= T('9'))
  11098. {
  11099. int numChars = 0;
  11100. while (input[0] != T(';'))
  11101. {
  11102. if (++numChars > 12)
  11103. {
  11104. setLastError ("illegal escape sequence", true);
  11105. break;
  11106. }
  11107. charCode = charCode * 10 + (input[0] - T('0'));
  11108. ++input;
  11109. }
  11110. ++input;
  11111. }
  11112. else
  11113. {
  11114. setLastError ("illegal escape sequence", true);
  11115. result += T("&");
  11116. return;
  11117. }
  11118. result << (tchar) charCode;
  11119. }
  11120. else
  11121. {
  11122. const tchar* const entityNameStart = input;
  11123. const tchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  11124. if (closingSemiColon == 0)
  11125. {
  11126. outOfData = true;
  11127. result += T("&");
  11128. }
  11129. else
  11130. {
  11131. input = closingSemiColon + 1;
  11132. result += expandExternalEntity (String (entityNameStart,
  11133. (int) (closingSemiColon - entityNameStart)));
  11134. }
  11135. }
  11136. }
  11137. const String XmlDocument::expandEntity (const String& ent)
  11138. {
  11139. if (ent.equalsIgnoreCase (T("amp")))
  11140. {
  11141. return T("&");
  11142. }
  11143. else if (ent.equalsIgnoreCase (T("quot")))
  11144. {
  11145. return T("\"");
  11146. }
  11147. else if (ent.equalsIgnoreCase (T("apos")))
  11148. {
  11149. return T("\'");
  11150. }
  11151. else if (ent.equalsIgnoreCase (T("lt")))
  11152. {
  11153. return T("<");
  11154. }
  11155. else if (ent.equalsIgnoreCase (T("gt")))
  11156. {
  11157. return T(">");
  11158. }
  11159. else if (ent[0] == T('#'))
  11160. {
  11161. if (ent[1] == T('x') || ent[1] == T('X'))
  11162. {
  11163. return String::charToString ((tchar) ent.substring (2).getHexValue32());
  11164. }
  11165. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  11166. {
  11167. return String::charToString ((tchar) ent.substring (1).getIntValue());
  11168. }
  11169. setLastError ("illegal escape sequence", false);
  11170. return T("&");
  11171. }
  11172. else
  11173. {
  11174. return expandExternalEntity (ent);
  11175. }
  11176. }
  11177. const String XmlDocument::expandExternalEntity (const String& entity)
  11178. {
  11179. if (needToLoadDTD)
  11180. {
  11181. if (dtdText.isNotEmpty())
  11182. {
  11183. while (dtdText.endsWithChar (T('>')))
  11184. dtdText = dtdText.dropLastCharacters (1);
  11185. tokenisedDTD.addTokens (dtdText, true);
  11186. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11187. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11188. {
  11189. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11190. tokenisedDTD.clear();
  11191. tokenisedDTD.addTokens (getFileContents (fn), true);
  11192. }
  11193. else
  11194. {
  11195. tokenisedDTD.clear();
  11196. const int openBracket = dtdText.indexOfChar (T('['));
  11197. if (openBracket > 0)
  11198. {
  11199. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11200. if (closeBracket > openBracket)
  11201. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11202. closeBracket), true);
  11203. }
  11204. }
  11205. for (int i = tokenisedDTD.size(); --i >= 0;)
  11206. {
  11207. if (tokenisedDTD[i].startsWithChar (T('%'))
  11208. && tokenisedDTD[i].endsWithChar (T(';')))
  11209. {
  11210. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11211. StringArray newToks;
  11212. newToks.addTokens (parsed, true);
  11213. tokenisedDTD.remove (i);
  11214. for (int j = newToks.size(); --j >= 0;)
  11215. tokenisedDTD.insert (i, newToks[j]);
  11216. }
  11217. }
  11218. }
  11219. needToLoadDTD = false;
  11220. }
  11221. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11222. {
  11223. if (tokenisedDTD[i] == entity)
  11224. {
  11225. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11226. {
  11227. String ent (tokenisedDTD [i + 1]);
  11228. while (ent.endsWithChar (T('>')))
  11229. ent = ent.dropLastCharacters (1);
  11230. ent = ent.trim().unquoted();
  11231. // check for sub-entities..
  11232. int ampersand = ent.indexOfChar (T('&'));
  11233. while (ampersand >= 0)
  11234. {
  11235. const int semiColon = ent.indexOf (i + 1, T(";"));
  11236. if (semiColon < 0)
  11237. {
  11238. setLastError ("entity without terminating semi-colon", false);
  11239. break;
  11240. }
  11241. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11242. ent = ent.substring (0, ampersand)
  11243. + resolved
  11244. + ent.substring (semiColon + 1);
  11245. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11246. }
  11247. return ent;
  11248. }
  11249. }
  11250. }
  11251. setLastError ("unknown entity", true);
  11252. return entity;
  11253. }
  11254. const String XmlDocument::getParameterEntity (const String& entity)
  11255. {
  11256. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11257. {
  11258. if (tokenisedDTD[i] == entity)
  11259. {
  11260. if (tokenisedDTD [i - 1] == T("%")
  11261. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11262. {
  11263. String ent (tokenisedDTD [i + 1]);
  11264. while (ent.endsWithChar (T('>')))
  11265. ent = ent.dropLastCharacters (1);
  11266. if (ent.equalsIgnoreCase (T("system")))
  11267. {
  11268. String filename (tokenisedDTD [i + 2]);
  11269. while (filename.endsWithChar (T('>')))
  11270. filename = filename.dropLastCharacters (1);
  11271. return getFileContents (filename);
  11272. }
  11273. else
  11274. {
  11275. return ent.trim().unquoted();
  11276. }
  11277. }
  11278. }
  11279. }
  11280. return entity;
  11281. }
  11282. END_JUCE_NAMESPACE
  11283. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11284. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11285. BEGIN_JUCE_NAMESPACE
  11286. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11287. : name (other.name),
  11288. value (other.value),
  11289. next (0)
  11290. {
  11291. }
  11292. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11293. const String& value_) throw()
  11294. : name (name_),
  11295. value (value_),
  11296. next (0)
  11297. {
  11298. }
  11299. XmlElement::XmlElement (const String& tagName_) throw()
  11300. : tagName (tagName_),
  11301. firstChildElement (0),
  11302. nextElement (0),
  11303. attributes (0)
  11304. {
  11305. // the tag name mustn't be empty, or it'll look like a text element!
  11306. jassert (tagName_.containsNonWhitespaceChars())
  11307. }
  11308. XmlElement::XmlElement (int /*dummy*/) throw()
  11309. : firstChildElement (0),
  11310. nextElement (0),
  11311. attributes (0)
  11312. {
  11313. }
  11314. XmlElement::XmlElement (const XmlElement& other) throw()
  11315. : tagName (other.tagName),
  11316. firstChildElement (0),
  11317. nextElement (0),
  11318. attributes (0)
  11319. {
  11320. copyChildrenAndAttributesFrom (other);
  11321. }
  11322. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11323. {
  11324. if (this != &other)
  11325. {
  11326. removeAllAttributes();
  11327. deleteAllChildElements();
  11328. tagName = other.tagName;
  11329. copyChildrenAndAttributesFrom (other);
  11330. }
  11331. return *this;
  11332. }
  11333. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11334. {
  11335. XmlElement* child = other.firstChildElement;
  11336. XmlElement* lastChild = 0;
  11337. while (child != 0)
  11338. {
  11339. XmlElement* const copiedChild = new XmlElement (*child);
  11340. if (lastChild != 0)
  11341. lastChild->nextElement = copiedChild;
  11342. else
  11343. firstChildElement = copiedChild;
  11344. lastChild = copiedChild;
  11345. child = child->nextElement;
  11346. }
  11347. const XmlAttributeNode* att = other.attributes;
  11348. XmlAttributeNode* lastAtt = 0;
  11349. while (att != 0)
  11350. {
  11351. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11352. if (lastAtt != 0)
  11353. lastAtt->next = newAtt;
  11354. else
  11355. attributes = newAtt;
  11356. lastAtt = newAtt;
  11357. att = att->next;
  11358. }
  11359. }
  11360. XmlElement::~XmlElement() throw()
  11361. {
  11362. XmlElement* child = firstChildElement;
  11363. while (child != 0)
  11364. {
  11365. XmlElement* const nextChild = child->nextElement;
  11366. delete child;
  11367. child = nextChild;
  11368. }
  11369. XmlAttributeNode* att = attributes;
  11370. while (att != 0)
  11371. {
  11372. XmlAttributeNode* const nextAtt = att->next;
  11373. delete att;
  11374. att = nextAtt;
  11375. }
  11376. }
  11377. namespace XmlOutputFunctions
  11378. {
  11379. static bool isLegalXmlChar (const uint32 c) throw()
  11380. {
  11381. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11382. return c < sizeof (legalChars) * 8
  11383. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11384. }
  11385. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11386. {
  11387. const juce_wchar* t = (const juce_wchar*) text;
  11388. for (;;)
  11389. {
  11390. const juce_wchar character = *t++;
  11391. if (character == 0)
  11392. {
  11393. break;
  11394. }
  11395. else if (isLegalXmlChar ((uint32) character))
  11396. {
  11397. outputStream << (char) character;
  11398. }
  11399. else
  11400. {
  11401. switch (character)
  11402. {
  11403. case '&': outputStream << "&amp;"; break;
  11404. case '"': outputStream << "&quot;"; break;
  11405. case '>': outputStream << "&gt;"; break;
  11406. case '<': outputStream << "&lt;"; break;
  11407. case '\n':
  11408. if (changeNewLines)
  11409. outputStream << "&#10;";
  11410. else
  11411. outputStream << (char) character;
  11412. break;
  11413. case '\r':
  11414. if (changeNewLines)
  11415. outputStream << "&#13;";
  11416. else
  11417. outputStream << (char) character;
  11418. break;
  11419. default:
  11420. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11421. break;
  11422. }
  11423. }
  11424. }
  11425. }
  11426. static void writeSpaces (OutputStream& out, int numSpaces) throw()
  11427. {
  11428. if (numSpaces > 0)
  11429. {
  11430. const char* const blanks = " ";
  11431. const int blankSize = (int) sizeof (blanks) - 1;
  11432. while (numSpaces > blankSize)
  11433. {
  11434. out.write (blanks, blankSize);
  11435. numSpaces -= blankSize;
  11436. }
  11437. out.write (blanks, numSpaces);
  11438. }
  11439. }
  11440. }
  11441. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11442. const int indentationLevel,
  11443. const int lineWrapLength) const throw()
  11444. {
  11445. using namespace XmlOutputFunctions;
  11446. writeSpaces (outputStream, indentationLevel);
  11447. if (! isTextElement())
  11448. {
  11449. outputStream.writeByte ('<');
  11450. outputStream << tagName;
  11451. const int attIndent = indentationLevel + tagName.length() + 1;
  11452. int lineLen = 0;
  11453. const XmlAttributeNode* att = attributes;
  11454. while (att != 0)
  11455. {
  11456. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11457. {
  11458. outputStream.write ("\r\n", 2);
  11459. writeSpaces (outputStream, attIndent);
  11460. lineLen = 0;
  11461. }
  11462. const int64 startPos = outputStream.getPosition();
  11463. outputStream.writeByte (' ');
  11464. outputStream << att->name;
  11465. outputStream.write ("=\"", 2);
  11466. escapeIllegalXmlChars (outputStream, att->value, true);
  11467. outputStream.writeByte ('"');
  11468. lineLen += (int) (outputStream.getPosition() - startPos);
  11469. att = att->next;
  11470. }
  11471. if (firstChildElement != 0)
  11472. {
  11473. XmlElement* child = firstChildElement;
  11474. if (child->nextElement == 0 && child->isTextElement())
  11475. {
  11476. outputStream.writeByte ('>');
  11477. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11478. }
  11479. else
  11480. {
  11481. if (indentationLevel >= 0)
  11482. outputStream.write (">\r\n", 3);
  11483. else
  11484. outputStream.writeByte ('>');
  11485. bool lastWasTextNode = false;
  11486. while (child != 0)
  11487. {
  11488. if (child->isTextElement())
  11489. {
  11490. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11491. writeSpaces (outputStream, indentationLevel + 2);
  11492. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11493. lastWasTextNode = true;
  11494. }
  11495. else
  11496. {
  11497. if (indentationLevel >= 0)
  11498. {
  11499. if (lastWasTextNode)
  11500. outputStream.write ("\r\n", 2);
  11501. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11502. }
  11503. else
  11504. {
  11505. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11506. }
  11507. lastWasTextNode = false;
  11508. }
  11509. child = child->nextElement;
  11510. }
  11511. if (indentationLevel >= 0)
  11512. {
  11513. if (lastWasTextNode)
  11514. outputStream.write ("\r\n", 2);
  11515. writeSpaces (outputStream, indentationLevel);
  11516. }
  11517. }
  11518. outputStream.write ("</", 2);
  11519. outputStream << tagName;
  11520. if (indentationLevel >= 0)
  11521. outputStream.write (">\r\n", 3);
  11522. else
  11523. outputStream.writeByte ('>');
  11524. }
  11525. else
  11526. {
  11527. if (indentationLevel >= 0)
  11528. outputStream.write ("/>\r\n", 4);
  11529. else
  11530. outputStream.write ("/>", 2);
  11531. }
  11532. }
  11533. else
  11534. {
  11535. if (indentationLevel >= 0)
  11536. writeSpaces (outputStream, indentationLevel + 2);
  11537. escapeIllegalXmlChars (outputStream, getText(), false);
  11538. }
  11539. }
  11540. const String XmlElement::createDocument (const String& dtdToUse,
  11541. const bool allOnOneLine,
  11542. const bool includeXmlHeader,
  11543. const String& encodingType,
  11544. const int lineWrapLength) const throw()
  11545. {
  11546. MemoryOutputStream mem (2048, 4096);
  11547. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11548. return String (mem.getData(), mem.getDataSize());
  11549. }
  11550. void XmlElement::writeToStream (OutputStream& output,
  11551. const String& dtdToUse,
  11552. const bool allOnOneLine,
  11553. const bool includeXmlHeader,
  11554. const String& encodingType,
  11555. const int lineWrapLength) const throw()
  11556. {
  11557. if (includeXmlHeader)
  11558. {
  11559. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11560. if (allOnOneLine)
  11561. output << "\"?> ";
  11562. else
  11563. output << "\"?>\r\n\r\n";
  11564. }
  11565. if (dtdToUse.isNotEmpty())
  11566. {
  11567. output << dtdToUse;
  11568. if (allOnOneLine)
  11569. output << " ";
  11570. else
  11571. output << "\r\n";
  11572. }
  11573. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11574. }
  11575. bool XmlElement::writeToFile (const File& file,
  11576. const String& dtdToUse,
  11577. const String& encodingType,
  11578. const int lineWrapLength) const throw()
  11579. {
  11580. if (file.hasWriteAccess())
  11581. {
  11582. TemporaryFile tempFile (file);
  11583. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11584. if (out != 0)
  11585. {
  11586. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11587. out = 0;
  11588. return tempFile.overwriteTargetFileWithTemporary();
  11589. }
  11590. }
  11591. return false;
  11592. }
  11593. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11594. {
  11595. #ifdef JUCE_DEBUG
  11596. // if debugging, check that the case is actually the same, because
  11597. // valid xml is case-sensitive, and although this lets it pass, it's
  11598. // better not to..
  11599. if (tagName.equalsIgnoreCase (tagNameWanted))
  11600. {
  11601. jassert (tagName == tagNameWanted);
  11602. return true;
  11603. }
  11604. else
  11605. {
  11606. return false;
  11607. }
  11608. #else
  11609. return tagName.equalsIgnoreCase (tagNameWanted);
  11610. #endif
  11611. }
  11612. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11613. {
  11614. XmlElement* e = nextElement;
  11615. while (e != 0 && ! e->hasTagName (requiredTagName))
  11616. e = e->nextElement;
  11617. return e;
  11618. }
  11619. int XmlElement::getNumAttributes() const throw()
  11620. {
  11621. const XmlAttributeNode* att = attributes;
  11622. int count = 0;
  11623. while (att != 0)
  11624. {
  11625. att = att->next;
  11626. ++count;
  11627. }
  11628. return count;
  11629. }
  11630. const String& XmlElement::getAttributeName (const int index) const throw()
  11631. {
  11632. const XmlAttributeNode* att = attributes;
  11633. int count = 0;
  11634. while (att != 0)
  11635. {
  11636. if (count == index)
  11637. return att->name;
  11638. att = att->next;
  11639. ++count;
  11640. }
  11641. return String::empty;
  11642. }
  11643. const String& XmlElement::getAttributeValue (const int index) const throw()
  11644. {
  11645. const XmlAttributeNode* att = attributes;
  11646. int count = 0;
  11647. while (att != 0)
  11648. {
  11649. if (count == index)
  11650. return att->value;
  11651. att = att->next;
  11652. ++count;
  11653. }
  11654. return String::empty;
  11655. }
  11656. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11657. {
  11658. const XmlAttributeNode* att = attributes;
  11659. while (att != 0)
  11660. {
  11661. if (att->name.equalsIgnoreCase (attributeName))
  11662. return true;
  11663. att = att->next;
  11664. }
  11665. return false;
  11666. }
  11667. const String XmlElement::getStringAttribute (const String& attributeName,
  11668. const String& defaultReturnValue) const throw()
  11669. {
  11670. const XmlAttributeNode* att = attributes;
  11671. while (att != 0)
  11672. {
  11673. if (att->name.equalsIgnoreCase (attributeName))
  11674. return att->value;
  11675. att = att->next;
  11676. }
  11677. return defaultReturnValue;
  11678. }
  11679. int XmlElement::getIntAttribute (const String& attributeName,
  11680. const int defaultReturnValue) const throw()
  11681. {
  11682. const XmlAttributeNode* att = attributes;
  11683. while (att != 0)
  11684. {
  11685. if (att->name.equalsIgnoreCase (attributeName))
  11686. return att->value.getIntValue();
  11687. att = att->next;
  11688. }
  11689. return defaultReturnValue;
  11690. }
  11691. double XmlElement::getDoubleAttribute (const String& attributeName,
  11692. const double defaultReturnValue) const throw()
  11693. {
  11694. const XmlAttributeNode* att = attributes;
  11695. while (att != 0)
  11696. {
  11697. if (att->name.equalsIgnoreCase (attributeName))
  11698. return att->value.getDoubleValue();
  11699. att = att->next;
  11700. }
  11701. return defaultReturnValue;
  11702. }
  11703. bool XmlElement::getBoolAttribute (const String& attributeName,
  11704. const bool defaultReturnValue) const throw()
  11705. {
  11706. const XmlAttributeNode* att = attributes;
  11707. while (att != 0)
  11708. {
  11709. if (att->name.equalsIgnoreCase (attributeName))
  11710. {
  11711. tchar firstChar = att->value[0];
  11712. if (CharacterFunctions::isWhitespace (firstChar))
  11713. firstChar = att->value.trimStart() [0];
  11714. return firstChar == T('1')
  11715. || firstChar == T('t')
  11716. || firstChar == T('y')
  11717. || firstChar == T('T')
  11718. || firstChar == T('Y');
  11719. }
  11720. att = att->next;
  11721. }
  11722. return defaultReturnValue;
  11723. }
  11724. bool XmlElement::compareAttribute (const String& attributeName,
  11725. const String& stringToCompareAgainst,
  11726. const bool ignoreCase) const throw()
  11727. {
  11728. const XmlAttributeNode* att = attributes;
  11729. while (att != 0)
  11730. {
  11731. if (att->name.equalsIgnoreCase (attributeName))
  11732. {
  11733. if (ignoreCase)
  11734. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11735. else
  11736. return att->value == stringToCompareAgainst;
  11737. }
  11738. att = att->next;
  11739. }
  11740. return false;
  11741. }
  11742. void XmlElement::setAttribute (const String& attributeName,
  11743. const String& value) throw()
  11744. {
  11745. #ifdef JUCE_DEBUG
  11746. // check the identifier being passed in is legal..
  11747. const tchar* t = attributeName;
  11748. while (*t != 0)
  11749. {
  11750. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11751. || *t == T('_')
  11752. || *t == T('-')
  11753. || *t == T(':'));
  11754. ++t;
  11755. }
  11756. #endif
  11757. if (attributes == 0)
  11758. {
  11759. attributes = new XmlAttributeNode (attributeName, value);
  11760. }
  11761. else
  11762. {
  11763. XmlAttributeNode* att = attributes;
  11764. for (;;)
  11765. {
  11766. if (att->name.equalsIgnoreCase (attributeName))
  11767. {
  11768. att->value = value;
  11769. break;
  11770. }
  11771. else if (att->next == 0)
  11772. {
  11773. att->next = new XmlAttributeNode (attributeName, value);
  11774. break;
  11775. }
  11776. att = att->next;
  11777. }
  11778. }
  11779. }
  11780. void XmlElement::setAttribute (const String& attributeName,
  11781. const int number) throw()
  11782. {
  11783. setAttribute (attributeName, String (number));
  11784. }
  11785. void XmlElement::setAttribute (const String& attributeName,
  11786. const double number) throw()
  11787. {
  11788. setAttribute (attributeName, String (number));
  11789. }
  11790. void XmlElement::removeAttribute (const String& attributeName) throw()
  11791. {
  11792. XmlAttributeNode* att = attributes;
  11793. XmlAttributeNode* lastAtt = 0;
  11794. while (att != 0)
  11795. {
  11796. if (att->name.equalsIgnoreCase (attributeName))
  11797. {
  11798. if (lastAtt == 0)
  11799. attributes = att->next;
  11800. else
  11801. lastAtt->next = att->next;
  11802. delete att;
  11803. break;
  11804. }
  11805. lastAtt = att;
  11806. att = att->next;
  11807. }
  11808. }
  11809. void XmlElement::removeAllAttributes() throw()
  11810. {
  11811. while (attributes != 0)
  11812. {
  11813. XmlAttributeNode* const nextAtt = attributes->next;
  11814. delete attributes;
  11815. attributes = nextAtt;
  11816. }
  11817. }
  11818. int XmlElement::getNumChildElements() const throw()
  11819. {
  11820. int count = 0;
  11821. const XmlElement* child = firstChildElement;
  11822. while (child != 0)
  11823. {
  11824. ++count;
  11825. child = child->nextElement;
  11826. }
  11827. return count;
  11828. }
  11829. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11830. {
  11831. int count = 0;
  11832. XmlElement* child = firstChildElement;
  11833. while (child != 0 && count < index)
  11834. {
  11835. child = child->nextElement;
  11836. ++count;
  11837. }
  11838. return child;
  11839. }
  11840. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11841. {
  11842. XmlElement* child = firstChildElement;
  11843. while (child != 0)
  11844. {
  11845. if (child->hasTagName (childName))
  11846. break;
  11847. child = child->nextElement;
  11848. }
  11849. return child;
  11850. }
  11851. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11852. {
  11853. if (newNode != 0)
  11854. {
  11855. if (firstChildElement == 0)
  11856. {
  11857. firstChildElement = newNode;
  11858. }
  11859. else
  11860. {
  11861. XmlElement* child = firstChildElement;
  11862. while (child->nextElement != 0)
  11863. child = child->nextElement;
  11864. child->nextElement = newNode;
  11865. // if this is non-zero, then something's probably
  11866. // gone wrong..
  11867. jassert (newNode->nextElement == 0);
  11868. }
  11869. }
  11870. }
  11871. void XmlElement::insertChildElement (XmlElement* const newNode,
  11872. int indexToInsertAt) throw()
  11873. {
  11874. if (newNode != 0)
  11875. {
  11876. removeChildElement (newNode, false);
  11877. if (indexToInsertAt == 0)
  11878. {
  11879. newNode->nextElement = firstChildElement;
  11880. firstChildElement = newNode;
  11881. }
  11882. else
  11883. {
  11884. if (firstChildElement == 0)
  11885. {
  11886. firstChildElement = newNode;
  11887. }
  11888. else
  11889. {
  11890. if (indexToInsertAt < 0)
  11891. indexToInsertAt = std::numeric_limits<int>::max();
  11892. XmlElement* child = firstChildElement;
  11893. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11894. child = child->nextElement;
  11895. newNode->nextElement = child->nextElement;
  11896. child->nextElement = newNode;
  11897. }
  11898. }
  11899. }
  11900. }
  11901. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11902. {
  11903. XmlElement* const newElement = new XmlElement (tagName);
  11904. addChildElement (newElement);
  11905. return newElement;
  11906. }
  11907. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11908. XmlElement* const newNode) throw()
  11909. {
  11910. if (newNode != 0)
  11911. {
  11912. XmlElement* child = firstChildElement;
  11913. XmlElement* previousNode = 0;
  11914. while (child != 0)
  11915. {
  11916. if (child == currentChildElement)
  11917. {
  11918. if (child != newNode)
  11919. {
  11920. if (previousNode == 0)
  11921. firstChildElement = newNode;
  11922. else
  11923. previousNode->nextElement = newNode;
  11924. newNode->nextElement = child->nextElement;
  11925. delete child;
  11926. }
  11927. return true;
  11928. }
  11929. previousNode = child;
  11930. child = child->nextElement;
  11931. }
  11932. }
  11933. return false;
  11934. }
  11935. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11936. const bool shouldDeleteTheChild) throw()
  11937. {
  11938. if (childToRemove != 0)
  11939. {
  11940. if (firstChildElement == childToRemove)
  11941. {
  11942. firstChildElement = childToRemove->nextElement;
  11943. childToRemove->nextElement = 0;
  11944. }
  11945. else
  11946. {
  11947. XmlElement* child = firstChildElement;
  11948. XmlElement* last = 0;
  11949. while (child != 0)
  11950. {
  11951. if (child == childToRemove)
  11952. {
  11953. if (last == 0)
  11954. firstChildElement = child->nextElement;
  11955. else
  11956. last->nextElement = child->nextElement;
  11957. childToRemove->nextElement = 0;
  11958. break;
  11959. }
  11960. last = child;
  11961. child = child->nextElement;
  11962. }
  11963. }
  11964. if (shouldDeleteTheChild)
  11965. delete childToRemove;
  11966. }
  11967. }
  11968. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11969. const bool ignoreOrderOfAttributes) const throw()
  11970. {
  11971. if (this != other)
  11972. {
  11973. if (other == 0 || tagName != other->tagName)
  11974. {
  11975. return false;
  11976. }
  11977. if (ignoreOrderOfAttributes)
  11978. {
  11979. int totalAtts = 0;
  11980. const XmlAttributeNode* att = attributes;
  11981. while (att != 0)
  11982. {
  11983. if (! other->compareAttribute (att->name, att->value))
  11984. return false;
  11985. att = att->next;
  11986. ++totalAtts;
  11987. }
  11988. if (totalAtts != other->getNumAttributes())
  11989. return false;
  11990. }
  11991. else
  11992. {
  11993. const XmlAttributeNode* thisAtt = attributes;
  11994. const XmlAttributeNode* otherAtt = other->attributes;
  11995. for (;;)
  11996. {
  11997. if (thisAtt == 0 || otherAtt == 0)
  11998. {
  11999. if (thisAtt == otherAtt) // both 0, so it's a match
  12000. break;
  12001. return false;
  12002. }
  12003. if (thisAtt->name != otherAtt->name
  12004. || thisAtt->value != otherAtt->value)
  12005. {
  12006. return false;
  12007. }
  12008. thisAtt = thisAtt->next;
  12009. otherAtt = otherAtt->next;
  12010. }
  12011. }
  12012. const XmlElement* thisChild = firstChildElement;
  12013. const XmlElement* otherChild = other->firstChildElement;
  12014. for (;;)
  12015. {
  12016. if (thisChild == 0 || otherChild == 0)
  12017. {
  12018. if (thisChild == otherChild) // both 0, so it's a match
  12019. break;
  12020. return false;
  12021. }
  12022. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  12023. return false;
  12024. thisChild = thisChild->nextElement;
  12025. otherChild = otherChild->nextElement;
  12026. }
  12027. }
  12028. return true;
  12029. }
  12030. void XmlElement::deleteAllChildElements() throw()
  12031. {
  12032. while (firstChildElement != 0)
  12033. {
  12034. XmlElement* const nextChild = firstChildElement->nextElement;
  12035. delete firstChildElement;
  12036. firstChildElement = nextChild;
  12037. }
  12038. }
  12039. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  12040. {
  12041. XmlElement* child = firstChildElement;
  12042. while (child != 0)
  12043. {
  12044. if (child->hasTagName (name))
  12045. {
  12046. XmlElement* const nextChild = child->nextElement;
  12047. removeChildElement (child, true);
  12048. child = nextChild;
  12049. }
  12050. else
  12051. {
  12052. child = child->nextElement;
  12053. }
  12054. }
  12055. }
  12056. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  12057. {
  12058. const XmlElement* child = firstChildElement;
  12059. while (child != 0)
  12060. {
  12061. if (child == possibleChild)
  12062. return true;
  12063. child = child->nextElement;
  12064. }
  12065. return false;
  12066. }
  12067. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  12068. {
  12069. if (this == elementToLookFor || elementToLookFor == 0)
  12070. return 0;
  12071. XmlElement* child = firstChildElement;
  12072. while (child != 0)
  12073. {
  12074. if (elementToLookFor == child)
  12075. return this;
  12076. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  12077. if (found != 0)
  12078. return found;
  12079. child = child->nextElement;
  12080. }
  12081. return 0;
  12082. }
  12083. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  12084. {
  12085. XmlElement* e = firstChildElement;
  12086. while (e != 0)
  12087. {
  12088. *elems++ = e;
  12089. e = e->nextElement;
  12090. }
  12091. }
  12092. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  12093. {
  12094. XmlElement* e = firstChildElement = elems[0];
  12095. for (int i = 1; i < num; ++i)
  12096. {
  12097. e->nextElement = elems[i];
  12098. e = e->nextElement;
  12099. }
  12100. e->nextElement = 0;
  12101. }
  12102. bool XmlElement::isTextElement() const throw()
  12103. {
  12104. return tagName.isEmpty();
  12105. }
  12106. static const tchar* const juce_xmltextContentAttributeName = T("text");
  12107. const String XmlElement::getText() const throw()
  12108. {
  12109. jassert (isTextElement()); // you're trying to get the text from an element that
  12110. // isn't actually a text element.. If this contains text sub-nodes, you
  12111. // probably want to use getAllSubText instead.
  12112. return getStringAttribute (juce_xmltextContentAttributeName);
  12113. }
  12114. void XmlElement::setText (const String& newText) throw()
  12115. {
  12116. if (isTextElement())
  12117. {
  12118. setAttribute (juce_xmltextContentAttributeName, newText);
  12119. }
  12120. else
  12121. {
  12122. jassertfalse // you can only change the text in a text element, not a normal one.
  12123. }
  12124. }
  12125. const String XmlElement::getAllSubText() const throw()
  12126. {
  12127. String result;
  12128. String::Concatenator concatenator (result);
  12129. const XmlElement* child = firstChildElement;
  12130. while (child != 0)
  12131. {
  12132. if (child->isTextElement())
  12133. concatenator.append (child->getText());
  12134. child = child->nextElement;
  12135. }
  12136. return result;
  12137. }
  12138. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  12139. const String& defaultReturnValue) const throw()
  12140. {
  12141. const XmlElement* const child = getChildByName (childTagName);
  12142. if (child != 0)
  12143. return child->getAllSubText();
  12144. return defaultReturnValue;
  12145. }
  12146. XmlElement* XmlElement::createTextElement (const String& text) throw()
  12147. {
  12148. XmlElement* const e = new XmlElement ((int) 0);
  12149. e->setAttribute (juce_xmltextContentAttributeName, text);
  12150. return e;
  12151. }
  12152. void XmlElement::addTextElement (const String& text) throw()
  12153. {
  12154. addChildElement (createTextElement (text));
  12155. }
  12156. void XmlElement::deleteAllTextElements() throw()
  12157. {
  12158. XmlElement* child = firstChildElement;
  12159. while (child != 0)
  12160. {
  12161. XmlElement* const next = child->nextElement;
  12162. if (child->isTextElement())
  12163. removeChildElement (child, true);
  12164. child = next;
  12165. }
  12166. }
  12167. END_JUCE_NAMESPACE
  12168. /*** End of inlined file: juce_XmlElement.cpp ***/
  12169. /*** Start of inlined file: juce_InterProcessLock.cpp ***/
  12170. BEGIN_JUCE_NAMESPACE
  12171. // (implemented in the platform-specific code files)
  12172. END_JUCE_NAMESPACE
  12173. /*** End of inlined file: juce_InterProcessLock.cpp ***/
  12174. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  12175. BEGIN_JUCE_NAMESPACE
  12176. ReadWriteLock::ReadWriteLock() throw()
  12177. : numWaitingWriters (0),
  12178. numWriters (0),
  12179. writerThreadId (0)
  12180. {
  12181. }
  12182. ReadWriteLock::~ReadWriteLock() throw()
  12183. {
  12184. jassert (readerThreads.size() == 0);
  12185. jassert (numWriters == 0);
  12186. }
  12187. void ReadWriteLock::enterRead() const throw()
  12188. {
  12189. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12190. const ScopedLock sl (accessLock);
  12191. for (;;)
  12192. {
  12193. jassert (readerThreads.size() % 2 == 0);
  12194. int i;
  12195. for (i = 0; i < readerThreads.size(); i += 2)
  12196. if (readerThreads.getUnchecked(i) == threadId)
  12197. break;
  12198. if (i < readerThreads.size()
  12199. || numWriters + numWaitingWriters == 0
  12200. || (threadId == writerThreadId && numWriters > 0))
  12201. {
  12202. if (i < readerThreads.size())
  12203. {
  12204. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12205. }
  12206. else
  12207. {
  12208. readerThreads.add (threadId);
  12209. readerThreads.add ((Thread::ThreadID) 1);
  12210. }
  12211. return;
  12212. }
  12213. const ScopedUnlock ul (accessLock);
  12214. waitEvent.wait (100);
  12215. }
  12216. }
  12217. void ReadWriteLock::exitRead() const throw()
  12218. {
  12219. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12220. const ScopedLock sl (accessLock);
  12221. for (int i = 0; i < readerThreads.size(); i += 2)
  12222. {
  12223. if (readerThreads.getUnchecked(i) == threadId)
  12224. {
  12225. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12226. if (newCount == 0)
  12227. {
  12228. readerThreads.removeRange (i, 2);
  12229. waitEvent.signal();
  12230. }
  12231. else
  12232. {
  12233. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12234. }
  12235. return;
  12236. }
  12237. }
  12238. jassertfalse // unlocking a lock that wasn't locked..
  12239. }
  12240. void ReadWriteLock::enterWrite() const throw()
  12241. {
  12242. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12243. const ScopedLock sl (accessLock);
  12244. for (;;)
  12245. {
  12246. if (readerThreads.size() + numWriters == 0
  12247. || threadId == writerThreadId
  12248. || (readerThreads.size() == 2
  12249. && readerThreads.getUnchecked(0) == threadId))
  12250. {
  12251. writerThreadId = threadId;
  12252. ++numWriters;
  12253. break;
  12254. }
  12255. ++numWaitingWriters;
  12256. accessLock.exit();
  12257. waitEvent.wait (100);
  12258. accessLock.enter();
  12259. --numWaitingWriters;
  12260. }
  12261. }
  12262. bool ReadWriteLock::tryEnterWrite() const throw()
  12263. {
  12264. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12265. const ScopedLock sl (accessLock);
  12266. if (readerThreads.size() + numWriters == 0
  12267. || threadId == writerThreadId
  12268. || (readerThreads.size() == 2
  12269. && readerThreads.getUnchecked(0) == threadId))
  12270. {
  12271. writerThreadId = threadId;
  12272. ++numWriters;
  12273. return true;
  12274. }
  12275. return false;
  12276. }
  12277. void ReadWriteLock::exitWrite() const throw()
  12278. {
  12279. const ScopedLock sl (accessLock);
  12280. // check this thread actually had the lock..
  12281. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12282. if (--numWriters == 0)
  12283. {
  12284. writerThreadId = 0;
  12285. waitEvent.signal();
  12286. }
  12287. }
  12288. END_JUCE_NAMESPACE
  12289. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12290. /*** Start of inlined file: juce_Thread.cpp ***/
  12291. BEGIN_JUCE_NAMESPACE
  12292. // these functions are implemented in the platform-specific code.
  12293. void* juce_createThread (void* userData);
  12294. void juce_killThread (void* handle);
  12295. bool juce_setThreadPriority (void* handle, int priority);
  12296. void juce_setCurrentThreadName (const String& name);
  12297. #if JUCE_WIN32
  12298. void juce_CloseThreadHandle (void* handle);
  12299. #endif
  12300. void Thread::threadEntryPoint (Thread* const thread)
  12301. {
  12302. {
  12303. const ScopedLock sl (runningThreadsLock);
  12304. runningThreads.add (thread);
  12305. }
  12306. JUCE_TRY
  12307. {
  12308. thread->threadId_ = Thread::getCurrentThreadId();
  12309. if (thread->threadName_.isNotEmpty())
  12310. juce_setCurrentThreadName (thread->threadName_);
  12311. if (thread->startSuspensionEvent_.wait (10000))
  12312. {
  12313. if (thread->affinityMask_ != 0)
  12314. setCurrentThreadAffinityMask (thread->affinityMask_);
  12315. thread->run();
  12316. }
  12317. }
  12318. JUCE_CATCH_ALL_ASSERT
  12319. {
  12320. const ScopedLock sl (runningThreadsLock);
  12321. jassert (runningThreads.contains (thread));
  12322. runningThreads.removeValue (thread);
  12323. }
  12324. #if JUCE_WIN32
  12325. juce_CloseThreadHandle (thread->threadHandle_);
  12326. #endif
  12327. thread->threadHandle_ = 0;
  12328. thread->threadId_ = 0;
  12329. }
  12330. // used to wrap the incoming call from the platform-specific code
  12331. void JUCE_API juce_threadEntryPoint (void* userData)
  12332. {
  12333. Thread::threadEntryPoint ((Thread*) userData);
  12334. }
  12335. Thread::Thread (const String& threadName)
  12336. : threadName_ (threadName),
  12337. threadHandle_ (0),
  12338. threadPriority_ (5),
  12339. threadId_ (0),
  12340. affinityMask_ (0),
  12341. threadShouldExit_ (false)
  12342. {
  12343. }
  12344. Thread::~Thread()
  12345. {
  12346. stopThread (100);
  12347. }
  12348. void Thread::startThread()
  12349. {
  12350. const ScopedLock sl (startStopLock);
  12351. threadShouldExit_ = false;
  12352. if (threadHandle_ == 0)
  12353. {
  12354. threadHandle_ = juce_createThread ((void*) this);
  12355. juce_setThreadPriority (threadHandle_, threadPriority_);
  12356. startSuspensionEvent_.signal();
  12357. }
  12358. }
  12359. void Thread::startThread (const int priority)
  12360. {
  12361. const ScopedLock sl (startStopLock);
  12362. if (threadHandle_ == 0)
  12363. {
  12364. threadPriority_ = priority;
  12365. startThread();
  12366. }
  12367. else
  12368. {
  12369. setPriority (priority);
  12370. }
  12371. }
  12372. bool Thread::isThreadRunning() const
  12373. {
  12374. return threadHandle_ != 0;
  12375. }
  12376. void Thread::signalThreadShouldExit()
  12377. {
  12378. threadShouldExit_ = true;
  12379. }
  12380. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12381. {
  12382. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12383. jassert (getThreadId() != getCurrentThreadId());
  12384. const int sleepMsPerIteration = 5;
  12385. int count = timeOutMilliseconds / sleepMsPerIteration;
  12386. while (isThreadRunning())
  12387. {
  12388. if (timeOutMilliseconds > 0 && --count < 0)
  12389. return false;
  12390. sleep (sleepMsPerIteration);
  12391. }
  12392. return true;
  12393. }
  12394. void Thread::stopThread (const int timeOutMilliseconds)
  12395. {
  12396. // agh! You can't stop the thread that's calling this method! How on earth
  12397. // would that work??
  12398. jassert (getCurrentThreadId() != getThreadId());
  12399. const ScopedLock sl (startStopLock);
  12400. if (isThreadRunning())
  12401. {
  12402. signalThreadShouldExit();
  12403. notify();
  12404. if (timeOutMilliseconds != 0)
  12405. waitForThreadToExit (timeOutMilliseconds);
  12406. if (isThreadRunning())
  12407. {
  12408. // very bad karma if this point is reached, as
  12409. // there are bound to be locks and events left in
  12410. // silly states when a thread is killed by force..
  12411. jassertfalse
  12412. Logger::writeToLog ("!! killing thread by force !!");
  12413. juce_killThread (threadHandle_);
  12414. threadHandle_ = 0;
  12415. threadId_ = 0;
  12416. const ScopedLock sl2 (runningThreadsLock);
  12417. runningThreads.removeValue (this);
  12418. }
  12419. }
  12420. }
  12421. bool Thread::setPriority (const int priority)
  12422. {
  12423. const ScopedLock sl (startStopLock);
  12424. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12425. if (worked)
  12426. threadPriority_ = priority;
  12427. return worked;
  12428. }
  12429. bool Thread::setCurrentThreadPriority (const int priority)
  12430. {
  12431. return juce_setThreadPriority (0, priority);
  12432. }
  12433. void Thread::setAffinityMask (const uint32 affinityMask)
  12434. {
  12435. affinityMask_ = affinityMask;
  12436. }
  12437. bool Thread::wait (const int timeOutMilliseconds) const
  12438. {
  12439. return defaultEvent_.wait (timeOutMilliseconds);
  12440. }
  12441. void Thread::notify() const
  12442. {
  12443. defaultEvent_.signal();
  12444. }
  12445. int Thread::getNumRunningThreads()
  12446. {
  12447. return runningThreads.size();
  12448. }
  12449. Thread* Thread::getCurrentThread()
  12450. {
  12451. const ThreadID thisId = getCurrentThreadId();
  12452. const ScopedLock sl (runningThreadsLock);
  12453. for (int i = runningThreads.size(); --i >= 0;)
  12454. {
  12455. Thread* const t = runningThreads.getUnchecked(i);
  12456. if (t->threadId_ == thisId)
  12457. return t;
  12458. }
  12459. return 0;
  12460. }
  12461. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12462. {
  12463. {
  12464. const ScopedLock sl (runningThreadsLock);
  12465. for (int i = runningThreads.size(); --i >= 0;)
  12466. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12467. }
  12468. for (;;)
  12469. {
  12470. Thread* firstThread;
  12471. {
  12472. const ScopedLock sl (runningThreadsLock);
  12473. firstThread = runningThreads.getFirst();
  12474. }
  12475. if (firstThread == 0)
  12476. break;
  12477. firstThread->stopThread (timeOutMilliseconds);
  12478. }
  12479. }
  12480. Array<Thread*> Thread::runningThreads;
  12481. CriticalSection Thread::runningThreadsLock;
  12482. END_JUCE_NAMESPACE
  12483. /*** End of inlined file: juce_Thread.cpp ***/
  12484. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12485. BEGIN_JUCE_NAMESPACE
  12486. ThreadPoolJob::ThreadPoolJob (const String& name)
  12487. : jobName (name),
  12488. pool (0),
  12489. shouldStop (false),
  12490. isActive (false),
  12491. shouldBeDeleted (false)
  12492. {
  12493. }
  12494. ThreadPoolJob::~ThreadPoolJob()
  12495. {
  12496. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12497. // to remove it first!
  12498. jassert (pool == 0 || ! pool->contains (this));
  12499. }
  12500. const String ThreadPoolJob::getJobName() const
  12501. {
  12502. return jobName;
  12503. }
  12504. void ThreadPoolJob::setJobName (const String& newName)
  12505. {
  12506. jobName = newName;
  12507. }
  12508. void ThreadPoolJob::signalJobShouldExit()
  12509. {
  12510. shouldStop = true;
  12511. }
  12512. class ThreadPool::ThreadPoolThread : public Thread
  12513. {
  12514. public:
  12515. ThreadPoolThread (ThreadPool& pool_)
  12516. : Thread (T("Pool")),
  12517. pool (pool_),
  12518. busy (false)
  12519. {
  12520. }
  12521. ~ThreadPoolThread()
  12522. {
  12523. }
  12524. void run()
  12525. {
  12526. while (! threadShouldExit())
  12527. {
  12528. if (! pool.runNextJob())
  12529. wait (500);
  12530. }
  12531. }
  12532. private:
  12533. ThreadPool& pool;
  12534. bool volatile busy;
  12535. ThreadPoolThread (const ThreadPoolThread&);
  12536. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12537. };
  12538. ThreadPool::ThreadPool (const int numThreads,
  12539. const bool startThreadsOnlyWhenNeeded,
  12540. const int stopThreadsWhenNotUsedTimeoutMs)
  12541. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12542. priority (5)
  12543. {
  12544. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12545. for (int i = jmax (1, numThreads); --i >= 0;)
  12546. threads.add (new ThreadPoolThread (*this));
  12547. if (! startThreadsOnlyWhenNeeded)
  12548. for (int i = threads.size(); --i >= 0;)
  12549. threads.getUnchecked(i)->startThread (priority);
  12550. }
  12551. ThreadPool::~ThreadPool()
  12552. {
  12553. removeAllJobs (true, 4000);
  12554. int i;
  12555. for (i = threads.size(); --i >= 0;)
  12556. threads.getUnchecked(i)->signalThreadShouldExit();
  12557. for (i = threads.size(); --i >= 0;)
  12558. threads.getUnchecked(i)->stopThread (500);
  12559. }
  12560. void ThreadPool::addJob (ThreadPoolJob* const job)
  12561. {
  12562. jassert (job != 0);
  12563. jassert (job->pool == 0);
  12564. if (job->pool == 0)
  12565. {
  12566. job->pool = this;
  12567. job->shouldStop = false;
  12568. job->isActive = false;
  12569. {
  12570. const ScopedLock sl (lock);
  12571. jobs.add (job);
  12572. int numRunning = 0;
  12573. for (int i = threads.size(); --i >= 0;)
  12574. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12575. ++numRunning;
  12576. if (numRunning < threads.size())
  12577. {
  12578. bool startedOne = false;
  12579. int n = 1000;
  12580. while (--n >= 0 && ! startedOne)
  12581. {
  12582. for (int i = threads.size(); --i >= 0;)
  12583. {
  12584. if (! threads.getUnchecked(i)->isThreadRunning())
  12585. {
  12586. threads.getUnchecked(i)->startThread (priority);
  12587. startedOne = true;
  12588. break;
  12589. }
  12590. }
  12591. if (! startedOne)
  12592. Thread::sleep (2);
  12593. }
  12594. }
  12595. }
  12596. for (int i = threads.size(); --i >= 0;)
  12597. threads.getUnchecked(i)->notify();
  12598. }
  12599. }
  12600. int ThreadPool::getNumJobs() const
  12601. {
  12602. return jobs.size();
  12603. }
  12604. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12605. {
  12606. const ScopedLock sl (lock);
  12607. return (ThreadPoolJob*) jobs [index];
  12608. }
  12609. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12610. {
  12611. const ScopedLock sl (lock);
  12612. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12613. }
  12614. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12615. {
  12616. const ScopedLock sl (lock);
  12617. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12618. }
  12619. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12620. const int timeOutMs) const
  12621. {
  12622. if (job != 0)
  12623. {
  12624. const uint32 start = Time::getMillisecondCounter();
  12625. while (contains (job))
  12626. {
  12627. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12628. return false;
  12629. jobFinishedSignal.wait (2);
  12630. }
  12631. }
  12632. return true;
  12633. }
  12634. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12635. const bool interruptIfRunning,
  12636. const int timeOutMs)
  12637. {
  12638. bool dontWait = true;
  12639. if (job != 0)
  12640. {
  12641. const ScopedLock sl (lock);
  12642. if (jobs.contains (job))
  12643. {
  12644. if (job->isActive)
  12645. {
  12646. if (interruptIfRunning)
  12647. job->signalJobShouldExit();
  12648. dontWait = false;
  12649. }
  12650. else
  12651. {
  12652. jobs.removeValue (job);
  12653. }
  12654. }
  12655. }
  12656. return dontWait || waitForJobToFinish (job, timeOutMs);
  12657. }
  12658. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12659. const int timeOutMs,
  12660. const bool deleteInactiveJobs,
  12661. ThreadPool::JobSelector* selectedJobsToRemove)
  12662. {
  12663. Array <ThreadPoolJob*> jobsToWaitFor;
  12664. {
  12665. const ScopedLock sl (lock);
  12666. for (int i = jobs.size(); --i >= 0;)
  12667. {
  12668. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12669. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12670. {
  12671. if (job->isActive)
  12672. {
  12673. jobsToWaitFor.add (job);
  12674. if (interruptRunningJobs)
  12675. job->signalJobShouldExit();
  12676. }
  12677. else
  12678. {
  12679. jobs.remove (i);
  12680. if (deleteInactiveJobs)
  12681. delete job;
  12682. }
  12683. }
  12684. }
  12685. }
  12686. const uint32 start = Time::getMillisecondCounter();
  12687. for (;;)
  12688. {
  12689. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12690. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12691. jobsToWaitFor.remove (i);
  12692. if (jobsToWaitFor.size() == 0)
  12693. break;
  12694. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12695. return false;
  12696. jobFinishedSignal.wait (20);
  12697. }
  12698. return true;
  12699. }
  12700. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12701. {
  12702. StringArray s;
  12703. const ScopedLock sl (lock);
  12704. for (int i = 0; i < jobs.size(); ++i)
  12705. {
  12706. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12707. if (job->isActive || ! onlyReturnActiveJobs)
  12708. s.add (job->getJobName());
  12709. }
  12710. return s;
  12711. }
  12712. bool ThreadPool::setThreadPriorities (const int newPriority)
  12713. {
  12714. bool ok = true;
  12715. if (priority != newPriority)
  12716. {
  12717. priority = newPriority;
  12718. for (int i = threads.size(); --i >= 0;)
  12719. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12720. ok = false;
  12721. }
  12722. return ok;
  12723. }
  12724. bool ThreadPool::runNextJob()
  12725. {
  12726. ThreadPoolJob* job = 0;
  12727. {
  12728. const ScopedLock sl (lock);
  12729. for (int i = 0; i < jobs.size(); ++i)
  12730. {
  12731. job = jobs[i];
  12732. if (job != 0 && ! (job->isActive || job->shouldStop))
  12733. break;
  12734. job = 0;
  12735. }
  12736. if (job != 0)
  12737. job->isActive = true;
  12738. }
  12739. if (job != 0)
  12740. {
  12741. JUCE_TRY
  12742. {
  12743. ThreadPoolJob::JobStatus result = job->runJob();
  12744. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12745. const ScopedLock sl (lock);
  12746. if (jobs.contains (job))
  12747. {
  12748. job->isActive = false;
  12749. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12750. {
  12751. job->pool = 0;
  12752. job->shouldStop = true;
  12753. jobs.removeValue (job);
  12754. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12755. delete job;
  12756. jobFinishedSignal.signal();
  12757. }
  12758. else
  12759. {
  12760. // move the job to the end of the queue if it wants another go
  12761. jobs.move (jobs.indexOf (job), -1);
  12762. }
  12763. }
  12764. }
  12765. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12766. catch (...)
  12767. {
  12768. const ScopedLock sl (lock);
  12769. jobs.removeValue (job);
  12770. }
  12771. #endif
  12772. }
  12773. else
  12774. {
  12775. if (threadStopTimeout > 0
  12776. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12777. {
  12778. const ScopedLock sl (lock);
  12779. if (jobs.size() == 0)
  12780. for (int i = threads.size(); --i >= 0;)
  12781. threads.getUnchecked(i)->signalThreadShouldExit();
  12782. }
  12783. else
  12784. {
  12785. return false;
  12786. }
  12787. }
  12788. return true;
  12789. }
  12790. END_JUCE_NAMESPACE
  12791. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12792. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12793. BEGIN_JUCE_NAMESPACE
  12794. TimeSliceThread::TimeSliceThread (const String& threadName)
  12795. : Thread (threadName),
  12796. index (0),
  12797. clientBeingCalled (0),
  12798. clientsChanged (false)
  12799. {
  12800. }
  12801. TimeSliceThread::~TimeSliceThread()
  12802. {
  12803. stopThread (2000);
  12804. }
  12805. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12806. {
  12807. const ScopedLock sl (listLock);
  12808. clients.addIfNotAlreadyThere (client);
  12809. clientsChanged = true;
  12810. notify();
  12811. }
  12812. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12813. {
  12814. const ScopedLock sl1 (listLock);
  12815. clientsChanged = true;
  12816. // if there's a chance we're in the middle of calling this client, we need to
  12817. // also lock the outer lock..
  12818. if (clientBeingCalled == client)
  12819. {
  12820. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12821. const ScopedLock sl2 (callbackLock);
  12822. const ScopedLock sl3 (listLock);
  12823. clients.removeValue (client);
  12824. }
  12825. else
  12826. {
  12827. clients.removeValue (client);
  12828. }
  12829. }
  12830. int TimeSliceThread::getNumClients() const
  12831. {
  12832. return clients.size();
  12833. }
  12834. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12835. {
  12836. const ScopedLock sl (listLock);
  12837. return clients [i];
  12838. }
  12839. void TimeSliceThread::run()
  12840. {
  12841. int numCallsSinceBusy = 0;
  12842. while (! threadShouldExit())
  12843. {
  12844. int timeToWait = 500;
  12845. {
  12846. const ScopedLock sl (callbackLock);
  12847. {
  12848. const ScopedLock sl2 (listLock);
  12849. if (clients.size() > 0)
  12850. {
  12851. index = (index + 1) % clients.size();
  12852. clientBeingCalled = clients [index];
  12853. }
  12854. else
  12855. {
  12856. index = 0;
  12857. clientBeingCalled = 0;
  12858. }
  12859. if (clientsChanged)
  12860. {
  12861. clientsChanged = false;
  12862. numCallsSinceBusy = 0;
  12863. }
  12864. }
  12865. if (clientBeingCalled != 0)
  12866. {
  12867. if (clientBeingCalled->useTimeSlice())
  12868. numCallsSinceBusy = 0;
  12869. else
  12870. ++numCallsSinceBusy;
  12871. if (numCallsSinceBusy >= clients.size())
  12872. timeToWait = 500;
  12873. else if (index == 0)
  12874. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12875. else
  12876. timeToWait = 0;
  12877. }
  12878. }
  12879. if (timeToWait > 0)
  12880. wait (timeToWait);
  12881. }
  12882. }
  12883. END_JUCE_NAMESPACE
  12884. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12885. #endif
  12886. #if JUCE_BUILD_MISC
  12887. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12888. BEGIN_JUCE_NAMESPACE
  12889. class ValueTreeSetPropertyAction : public UndoableAction
  12890. {
  12891. public:
  12892. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12893. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12894. : target (target_), name (name_), newValue (newValue_),
  12895. isAddingNewProperty (isAddingNewProperty_),
  12896. isDeletingProperty (isDeletingProperty_)
  12897. {
  12898. if (! isAddingNewProperty)
  12899. oldValue = target_->getProperty (name_);
  12900. }
  12901. ~ValueTreeSetPropertyAction() {}
  12902. bool perform()
  12903. {
  12904. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12905. if (isDeletingProperty)
  12906. target->removeProperty (name, 0);
  12907. else
  12908. target->setProperty (name, newValue, 0);
  12909. return true;
  12910. }
  12911. bool undo()
  12912. {
  12913. if (isAddingNewProperty)
  12914. target->removeProperty (name, 0);
  12915. else
  12916. target->setProperty (name, oldValue, 0);
  12917. return true;
  12918. }
  12919. int getSizeInUnits()
  12920. {
  12921. return (int) sizeof (*this); //xxx should be more accurate
  12922. }
  12923. private:
  12924. const ValueTree::SharedObjectPtr target;
  12925. const var::identifier name;
  12926. const var newValue;
  12927. var oldValue;
  12928. const bool isAddingNewProperty, isDeletingProperty;
  12929. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12930. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12931. };
  12932. class ValueTreeChildChangeAction : public UndoableAction
  12933. {
  12934. public:
  12935. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12936. const ValueTree::SharedObjectPtr& newChild_)
  12937. : target (target_),
  12938. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12939. childIndex (childIndex_),
  12940. isDeleting (newChild_ == 0)
  12941. {
  12942. jassert (child != 0);
  12943. }
  12944. ~ValueTreeChildChangeAction() {}
  12945. bool perform()
  12946. {
  12947. if (isDeleting)
  12948. target->removeChild (childIndex, 0);
  12949. else
  12950. target->addChild (child, childIndex, 0);
  12951. return true;
  12952. }
  12953. bool undo()
  12954. {
  12955. if (isDeleting)
  12956. target->addChild (child, childIndex, 0);
  12957. else
  12958. target->removeChild (childIndex, 0);
  12959. return true;
  12960. }
  12961. int getSizeInUnits()
  12962. {
  12963. return (int) sizeof (*this); //xxx should be more accurate
  12964. }
  12965. private:
  12966. const ValueTree::SharedObjectPtr target, child;
  12967. const int childIndex;
  12968. const bool isDeleting;
  12969. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12970. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12971. };
  12972. ValueTree::SharedObject::SharedObject (const String& type_)
  12973. : type (type_), parent (0)
  12974. {
  12975. }
  12976. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12977. : type (other.type), properties (other.properties), parent (0)
  12978. {
  12979. for (int i = 0; i < other.children.size(); ++i)
  12980. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12981. }
  12982. ValueTree::SharedObject::~SharedObject()
  12983. {
  12984. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12985. for (int i = children.size(); --i >= 0;)
  12986. {
  12987. const SharedObjectPtr c (children.getUnchecked(i));
  12988. c->parent = 0;
  12989. children.remove (i);
  12990. c->sendParentChangeMessage();
  12991. }
  12992. }
  12993. void ValueTree::deliverPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12994. {
  12995. for (int i = listeners.size(); --i >= 0;)
  12996. {
  12997. ValueTree::Listener* const l = listeners[i];
  12998. if (l != 0)
  12999. l->valueTreePropertyChanged (tree, property);
  13000. }
  13001. }
  13002. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  13003. {
  13004. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13005. {
  13006. ValueTree* const v = valueTreesWithListeners[i];
  13007. if (v != 0)
  13008. v->deliverPropertyChangeMessage (tree, property);
  13009. }
  13010. }
  13011. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  13012. {
  13013. ValueTree tree (this);
  13014. ValueTree::SharedObject* t = this;
  13015. while (t != 0)
  13016. {
  13017. t->sendPropertyChangeMessage (tree, property);
  13018. t = t->parent;
  13019. }
  13020. }
  13021. void ValueTree::deliverChildChangeMessage (ValueTree& tree)
  13022. {
  13023. for (int i = listeners.size(); --i >= 0;)
  13024. {
  13025. ValueTree::Listener* const l = listeners[i];
  13026. if (l != 0)
  13027. l->valueTreeChildrenChanged (tree);
  13028. }
  13029. }
  13030. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  13031. {
  13032. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13033. {
  13034. ValueTree* const v = valueTreesWithListeners[i];
  13035. if (v != 0)
  13036. v->deliverChildChangeMessage (tree);
  13037. }
  13038. }
  13039. void ValueTree::SharedObject::sendChildChangeMessage()
  13040. {
  13041. ValueTree tree (this);
  13042. ValueTree::SharedObject* t = this;
  13043. while (t != 0)
  13044. {
  13045. t->sendChildChangeMessage (tree);
  13046. t = t->parent;
  13047. }
  13048. }
  13049. void ValueTree::deliverParentChangeMessage (ValueTree& tree)
  13050. {
  13051. for (int i = listeners.size(); --i >= 0;)
  13052. {
  13053. ValueTree::Listener* const l = listeners[i];
  13054. if (l != 0)
  13055. l->valueTreeParentChanged (tree);
  13056. }
  13057. }
  13058. void ValueTree::SharedObject::sendParentChangeMessage()
  13059. {
  13060. ValueTree tree (this);
  13061. int i;
  13062. for (i = children.size(); --i >= 0;)
  13063. {
  13064. SharedObject* const t = children[i];
  13065. if (t != 0)
  13066. t->sendParentChangeMessage();
  13067. }
  13068. for (i = valueTreesWithListeners.size(); --i >= 0;)
  13069. {
  13070. ValueTree* const v = valueTreesWithListeners[i];
  13071. if (v != 0)
  13072. v->deliverParentChangeMessage (tree);
  13073. }
  13074. }
  13075. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  13076. {
  13077. return properties [name];
  13078. }
  13079. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13080. {
  13081. if (undoManager == 0)
  13082. {
  13083. if (properties.set (name, newValue))
  13084. sendPropertyChangeMessage (name);
  13085. }
  13086. else
  13087. {
  13088. var* const existingValue = properties.getItem (name);
  13089. if (existingValue != 0)
  13090. {
  13091. if (*existingValue != newValue)
  13092. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  13093. }
  13094. else
  13095. {
  13096. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  13097. }
  13098. }
  13099. }
  13100. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  13101. {
  13102. return properties.contains (name);
  13103. }
  13104. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13105. {
  13106. if (undoManager == 0)
  13107. {
  13108. if (properties.remove (name))
  13109. sendPropertyChangeMessage (name);
  13110. }
  13111. else
  13112. {
  13113. if (properties.contains (name))
  13114. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  13115. }
  13116. }
  13117. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  13118. {
  13119. if (undoManager == 0)
  13120. {
  13121. while (properties.size() > 0)
  13122. {
  13123. const var::identifier name (properties.getName (properties.size() - 1));
  13124. properties.remove (name);
  13125. sendPropertyChangeMessage (name);
  13126. }
  13127. }
  13128. else
  13129. {
  13130. for (int i = properties.size(); --i >= 0;)
  13131. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  13132. }
  13133. }
  13134. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  13135. {
  13136. for (int i = 0; i < children.size(); ++i)
  13137. if (children.getUnchecked(i)->type == typeToMatch)
  13138. return (SharedObject*) children.getUnchecked(i);
  13139. return (SharedObject*) 0;
  13140. }
  13141. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13142. {
  13143. for (int i = 0; i < children.size(); ++i)
  13144. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  13145. return (SharedObject*) children.getUnchecked(i);
  13146. return (SharedObject*) 0;
  13147. }
  13148. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  13149. {
  13150. const SharedObject* p = parent;
  13151. while (p != 0)
  13152. {
  13153. if (p == possibleParent)
  13154. return true;
  13155. p = p->parent;
  13156. }
  13157. return false;
  13158. }
  13159. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  13160. {
  13161. if (child != 0 && child->parent != this)
  13162. {
  13163. if (child != this && ! isAChildOf (child))
  13164. {
  13165. // You should always make sure that a child is removed from its previous parent before
  13166. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  13167. // undomanager should be used when removing it from its current parent..
  13168. jassert (child->parent == 0);
  13169. if (child->parent != 0)
  13170. {
  13171. jassert (child->parent->children.indexOf (child) >= 0);
  13172. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  13173. }
  13174. if (undoManager == 0)
  13175. {
  13176. children.insert (index, child);
  13177. child->parent = this;
  13178. sendChildChangeMessage();
  13179. child->sendParentChangeMessage();
  13180. }
  13181. else
  13182. {
  13183. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  13184. }
  13185. }
  13186. else
  13187. {
  13188. // You're attempting to create a recursive loop! A node
  13189. // can't be a child of one of its own children!
  13190. jassertfalse
  13191. }
  13192. }
  13193. }
  13194. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  13195. {
  13196. const SharedObjectPtr child (children [childIndex]);
  13197. if (child != 0)
  13198. {
  13199. if (undoManager == 0)
  13200. {
  13201. children.remove (childIndex);
  13202. child->parent = 0;
  13203. sendChildChangeMessage();
  13204. child->sendParentChangeMessage();
  13205. }
  13206. else
  13207. {
  13208. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13209. }
  13210. }
  13211. }
  13212. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13213. {
  13214. while (children.size() > 0)
  13215. removeChild (children.size() - 1, undoManager);
  13216. }
  13217. ValueTree::ValueTree (const String& type_)
  13218. : object (new ValueTree::SharedObject (type_))
  13219. {
  13220. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13221. }
  13222. ValueTree::ValueTree (SharedObject* const object_)
  13223. : object (object_)
  13224. {
  13225. }
  13226. ValueTree::ValueTree (const ValueTree& other)
  13227. : object (other.object)
  13228. {
  13229. }
  13230. ValueTree& ValueTree::operator= (const ValueTree& other)
  13231. {
  13232. if (listeners.size() > 0)
  13233. {
  13234. if (object != 0)
  13235. object->valueTreesWithListeners.removeValue (this);
  13236. if (other.object != 0)
  13237. other.object->valueTreesWithListeners.add (this);
  13238. }
  13239. object = other.object;
  13240. return *this;
  13241. }
  13242. ValueTree::~ValueTree()
  13243. {
  13244. if (listeners.size() > 0 && object != 0)
  13245. object->valueTreesWithListeners.removeValue (this);
  13246. }
  13247. bool ValueTree::operator== (const ValueTree& other) const
  13248. {
  13249. return object == other.object;
  13250. }
  13251. bool ValueTree::operator!= (const ValueTree& other) const
  13252. {
  13253. return object != other.object;
  13254. }
  13255. ValueTree ValueTree::createCopy() const
  13256. {
  13257. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13258. }
  13259. bool ValueTree::hasType (const String& typeName) const
  13260. {
  13261. return object != 0 && object->type == typeName;
  13262. }
  13263. const String ValueTree::getType() const
  13264. {
  13265. return object != 0 ? object->type : String::empty;
  13266. }
  13267. ValueTree ValueTree::getParent() const
  13268. {
  13269. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13270. }
  13271. const var& ValueTree::operator[] (const var::identifier& name) const
  13272. {
  13273. return object == 0 ? var::null : object->getProperty (name);
  13274. }
  13275. const var& ValueTree::getProperty (const var::identifier& name) const
  13276. {
  13277. return object == 0 ? var::null : object->getProperty (name);
  13278. }
  13279. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13280. {
  13281. jassert (name.name.isNotEmpty());
  13282. if (object != 0 && name.name.isNotEmpty())
  13283. object->setProperty (name, newValue, undoManager);
  13284. }
  13285. bool ValueTree::hasProperty (const var::identifier& name) const
  13286. {
  13287. return object != 0 && object->hasProperty (name);
  13288. }
  13289. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13290. {
  13291. if (object != 0)
  13292. object->removeProperty (name, undoManager);
  13293. }
  13294. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13295. {
  13296. if (object != 0)
  13297. object->removeAllProperties (undoManager);
  13298. }
  13299. int ValueTree::getNumProperties() const
  13300. {
  13301. return object == 0 ? 0 : object->properties.size();
  13302. }
  13303. const var::identifier ValueTree::getPropertyName (int index) const
  13304. {
  13305. return (object == 0) ? var::identifier()
  13306. : object->properties.getName (index);
  13307. }
  13308. class ValueTreePropertyValueSource : public Value::ValueSource,
  13309. public ValueTree::Listener
  13310. {
  13311. public:
  13312. ValueTreePropertyValueSource (const ValueTree& tree_,
  13313. const var::identifier& property_,
  13314. UndoManager* const undoManager_)
  13315. : tree (tree_),
  13316. property (property_),
  13317. undoManager (undoManager_)
  13318. {
  13319. tree.addListener (this);
  13320. }
  13321. ~ValueTreePropertyValueSource()
  13322. {
  13323. tree.removeListener (this);
  13324. }
  13325. const var getValue() const
  13326. {
  13327. return tree [property];
  13328. }
  13329. void setValue (const var& newValue)
  13330. {
  13331. tree.setProperty (property, newValue, undoManager);
  13332. }
  13333. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13334. {
  13335. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13336. sendChangeMessage (false);
  13337. }
  13338. void valueTreeChildrenChanged (ValueTree&) {}
  13339. void valueTreeParentChanged (ValueTree&) {}
  13340. private:
  13341. ValueTree tree;
  13342. const var::identifier property;
  13343. UndoManager* const undoManager;
  13344. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13345. };
  13346. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13347. {
  13348. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13349. }
  13350. int ValueTree::getNumChildren() const
  13351. {
  13352. return object == 0 ? 0 : object->children.size();
  13353. }
  13354. ValueTree ValueTree::getChild (int index) const
  13355. {
  13356. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13357. }
  13358. ValueTree ValueTree::getChildWithName (const String& type) const
  13359. {
  13360. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13361. }
  13362. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13363. {
  13364. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13365. }
  13366. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13367. {
  13368. return object != 0 && object->isAChildOf (possibleParent.object);
  13369. }
  13370. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13371. {
  13372. if (object != 0)
  13373. object->addChild (child.object, index, undoManager);
  13374. }
  13375. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13376. {
  13377. if (object != 0)
  13378. object->removeChild (childIndex, undoManager);
  13379. }
  13380. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13381. {
  13382. if (object != 0)
  13383. object->removeChild (object->children.indexOf (child.object), undoManager);
  13384. }
  13385. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13386. {
  13387. if (object != 0)
  13388. object->removeAllChildren (undoManager);
  13389. }
  13390. void ValueTree::addListener (Listener* listener)
  13391. {
  13392. if (listener != 0)
  13393. {
  13394. if (listeners.size() == 0 && object != 0)
  13395. object->valueTreesWithListeners.add (this);
  13396. listeners.add (listener);
  13397. }
  13398. }
  13399. void ValueTree::removeListener (Listener* listener)
  13400. {
  13401. listeners.removeValue (listener);
  13402. if (listeners.size() == 0 && object != 0)
  13403. object->valueTreesWithListeners.removeValue (this);
  13404. }
  13405. XmlElement* ValueTree::SharedObject::createXml() const
  13406. {
  13407. XmlElement* xml = new XmlElement (type);
  13408. int i;
  13409. for (i = 0; i < properties.size(); ++i)
  13410. {
  13411. var::identifier name (properties.getName(i));
  13412. const var& v = properties [name];
  13413. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13414. xml->setAttribute (name.name, v.toString());
  13415. }
  13416. for (i = 0; i < children.size(); ++i)
  13417. xml->addChildElement (children.getUnchecked(i)->createXml());
  13418. return xml;
  13419. }
  13420. XmlElement* ValueTree::createXml() const
  13421. {
  13422. return object != 0 ? object->createXml() : 0;
  13423. }
  13424. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13425. {
  13426. ValueTree v (xml.getTagName());
  13427. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13428. for (int i = 0; i < numAtts; ++i)
  13429. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13430. forEachXmlChildElement (xml, e)
  13431. {
  13432. v.addChild (fromXml (*e), -1, 0);
  13433. }
  13434. return v;
  13435. }
  13436. void ValueTree::writeToStream (OutputStream& output)
  13437. {
  13438. output.writeString (getType());
  13439. const int numProps = getNumProperties();
  13440. output.writeCompressedInt (numProps);
  13441. int i;
  13442. for (i = 0; i < numProps; ++i)
  13443. {
  13444. const var::identifier name (getPropertyName(i));
  13445. output.writeString (name.name);
  13446. getProperty(name).writeToStream (output);
  13447. }
  13448. const int numChildren = getNumChildren();
  13449. output.writeCompressedInt (numChildren);
  13450. for (i = 0; i < numChildren; ++i)
  13451. getChild (i).writeToStream (output);
  13452. }
  13453. ValueTree ValueTree::readFromStream (InputStream& input)
  13454. {
  13455. String type (input.readString());
  13456. if (type.isEmpty())
  13457. return ValueTree ((SharedObject*) 0);
  13458. ValueTree v (type);
  13459. const int numProps = input.readCompressedInt();
  13460. if (numProps < 0)
  13461. {
  13462. jassertfalse // trying to read corrupted data!
  13463. return v;
  13464. }
  13465. int i;
  13466. for (i = 0; i < numProps; ++i)
  13467. {
  13468. const String name (input.readString());
  13469. jassert (name.isNotEmpty());
  13470. const var value (var::readFromStream (input));
  13471. v.setProperty (name, value, 0);
  13472. }
  13473. const int numChildren = input.readCompressedInt();
  13474. for (i = 0; i < numChildren; ++i)
  13475. v.addChild (readFromStream (input), -1, 0);
  13476. return v;
  13477. }
  13478. END_JUCE_NAMESPACE
  13479. /*** End of inlined file: juce_ValueTree.cpp ***/
  13480. /*** Start of inlined file: juce_Value.cpp ***/
  13481. BEGIN_JUCE_NAMESPACE
  13482. Value::ValueSource::ValueSource()
  13483. {
  13484. }
  13485. Value::ValueSource::~ValueSource()
  13486. {
  13487. }
  13488. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13489. {
  13490. if (synchronous)
  13491. {
  13492. for (int i = valuesWithListeners.size(); --i >= 0;)
  13493. {
  13494. Value* const v = valuesWithListeners[i];
  13495. if (v != 0)
  13496. v->callListeners();
  13497. }
  13498. }
  13499. else
  13500. {
  13501. triggerAsyncUpdate();
  13502. }
  13503. }
  13504. void Value::ValueSource::handleAsyncUpdate()
  13505. {
  13506. sendChangeMessage (true);
  13507. }
  13508. class SimpleValueSource : public Value::ValueSource
  13509. {
  13510. public:
  13511. SimpleValueSource()
  13512. {
  13513. }
  13514. SimpleValueSource (const var& initialValue)
  13515. : value (initialValue)
  13516. {
  13517. }
  13518. ~SimpleValueSource()
  13519. {
  13520. }
  13521. const var getValue() const
  13522. {
  13523. return value;
  13524. }
  13525. void setValue (const var& newValue)
  13526. {
  13527. if (newValue != value)
  13528. {
  13529. value = newValue;
  13530. sendChangeMessage (false);
  13531. }
  13532. }
  13533. private:
  13534. var value;
  13535. SimpleValueSource (const SimpleValueSource&);
  13536. SimpleValueSource& operator= (const SimpleValueSource&);
  13537. };
  13538. Value::Value()
  13539. : value (new SimpleValueSource())
  13540. {
  13541. }
  13542. Value::Value (ValueSource* const value_)
  13543. : value (value_)
  13544. {
  13545. jassert (value_ != 0);
  13546. }
  13547. Value::Value (const var& initialValue)
  13548. : value (new SimpleValueSource (initialValue))
  13549. {
  13550. }
  13551. Value::Value (const Value& other)
  13552. : value (other.value)
  13553. {
  13554. }
  13555. Value& Value::operator= (const Value& other)
  13556. {
  13557. value = other.value;
  13558. return *this;
  13559. }
  13560. Value::~Value()
  13561. {
  13562. if (listeners.size() > 0)
  13563. value->valuesWithListeners.removeValue (this);
  13564. }
  13565. const var Value::getValue() const
  13566. {
  13567. return value->getValue();
  13568. }
  13569. void Value::setValue (const var& newValue)
  13570. {
  13571. value->setValue (newValue);
  13572. }
  13573. const String Value::toString() const
  13574. {
  13575. return value->getValue().toString();
  13576. }
  13577. Value& Value::operator= (const var& newValue)
  13578. {
  13579. value->setValue (newValue);
  13580. return *this;
  13581. }
  13582. void Value::referTo (const Value& valueToReferTo)
  13583. {
  13584. if (valueToReferTo.value != value)
  13585. {
  13586. if (listeners.size() > 0)
  13587. {
  13588. value->valuesWithListeners.removeValue (this);
  13589. valueToReferTo.value->valuesWithListeners.add (this);
  13590. }
  13591. value = valueToReferTo.value;
  13592. callListeners();
  13593. }
  13594. }
  13595. bool Value::refersToSameSourceAs (const Value& other) const
  13596. {
  13597. return value == other.value;
  13598. }
  13599. bool Value::operator== (const Value& other) const
  13600. {
  13601. return value == other.value || value->getValue() == other.getValue();
  13602. }
  13603. bool Value::operator!= (const Value& other) const
  13604. {
  13605. return value != other.value && value->getValue() != other.getValue();
  13606. }
  13607. void Value::addListener (Listener* const listener)
  13608. {
  13609. if (listener != 0)
  13610. {
  13611. if (listeners.size() == 0)
  13612. value->valuesWithListeners.add (this);
  13613. listeners.add (listener);
  13614. }
  13615. }
  13616. void Value::removeListener (Listener* const listener)
  13617. {
  13618. listeners.removeValue (listener);
  13619. if (listeners.size() == 0)
  13620. value->valuesWithListeners.removeValue (this);
  13621. }
  13622. void Value::callListeners()
  13623. {
  13624. Value valueCopy (*this); // Use a copy in case this object gets deleted by a callback
  13625. for (int i = listeners.size(); --i >= 0;)
  13626. {
  13627. Listener* const l = listeners[i];
  13628. if (l != 0)
  13629. l->valueChanged (valueCopy);
  13630. }
  13631. }
  13632. END_JUCE_NAMESPACE
  13633. /*** End of inlined file: juce_Value.cpp ***/
  13634. /*** Start of inlined file: juce_Application.cpp ***/
  13635. #if JUCE_MSVC
  13636. #pragma warning (push)
  13637. #pragma warning (disable: 4245 4514 4100)
  13638. #include <crtdbg.h>
  13639. #pragma warning (pop)
  13640. #endif
  13641. BEGIN_JUCE_NAMESPACE
  13642. void juce_setCurrentThreadName (const String& name);
  13643. static JUCEApplication* appInstance = 0;
  13644. JUCEApplication::JUCEApplication()
  13645. : appReturnValue (0),
  13646. stillInitialising (true)
  13647. {
  13648. }
  13649. JUCEApplication::~JUCEApplication()
  13650. {
  13651. if (appLock != 0)
  13652. {
  13653. appLock->exit();
  13654. appLock = 0;
  13655. }
  13656. }
  13657. JUCEApplication* JUCEApplication::getInstance() throw()
  13658. {
  13659. return appInstance;
  13660. }
  13661. bool JUCEApplication::isInitialising() const throw()
  13662. {
  13663. return stillInitialising;
  13664. }
  13665. const String JUCEApplication::getApplicationVersion()
  13666. {
  13667. return String::empty;
  13668. }
  13669. bool JUCEApplication::moreThanOneInstanceAllowed()
  13670. {
  13671. return true;
  13672. }
  13673. void JUCEApplication::anotherInstanceStarted (const String&)
  13674. {
  13675. }
  13676. void JUCEApplication::systemRequestedQuit()
  13677. {
  13678. quit();
  13679. }
  13680. void JUCEApplication::quit()
  13681. {
  13682. MessageManager::getInstance()->stopDispatchLoop();
  13683. }
  13684. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13685. {
  13686. appReturnValue = newReturnValue;
  13687. }
  13688. void JUCEApplication::unhandledException (const std::exception*,
  13689. const String&,
  13690. const int)
  13691. {
  13692. jassertfalse
  13693. }
  13694. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13695. const char* const sourceFile,
  13696. const int lineNumber)
  13697. {
  13698. if (appInstance != 0)
  13699. appInstance->unhandledException (e, sourceFile, lineNumber);
  13700. }
  13701. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13702. {
  13703. return 0;
  13704. }
  13705. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13706. {
  13707. commands.add (StandardApplicationCommandIDs::quit);
  13708. }
  13709. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13710. {
  13711. if (commandID == StandardApplicationCommandIDs::quit)
  13712. {
  13713. result.setInfo (TRANS("Quit"),
  13714. TRANS("Quits the application"),
  13715. "Application",
  13716. 0);
  13717. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13718. }
  13719. }
  13720. bool JUCEApplication::perform (const InvocationInfo& info)
  13721. {
  13722. if (info.commandID == StandardApplicationCommandIDs::quit)
  13723. {
  13724. systemRequestedQuit();
  13725. return true;
  13726. }
  13727. return false;
  13728. }
  13729. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13730. {
  13731. if (! app->initialiseApp (commandLine))
  13732. return 0;
  13733. // now loop until a quit message is received..
  13734. JUCE_TRY
  13735. {
  13736. MessageManager::getInstance()->runDispatchLoop();
  13737. }
  13738. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13739. catch (const std::exception& e)
  13740. {
  13741. app->unhandledException (&e, __FILE__, __LINE__);
  13742. }
  13743. catch (...)
  13744. {
  13745. app->unhandledException (0, __FILE__, __LINE__);
  13746. }
  13747. #endif
  13748. return shutdownAppAndClearUp();
  13749. }
  13750. bool JUCEApplication::initialiseApp (String& commandLine)
  13751. {
  13752. jassert (appInstance == 0);
  13753. appInstance = this;
  13754. commandLineParameters = commandLine.trim();
  13755. commandLine = String::empty;
  13756. initialiseJuce_GUI();
  13757. #if ! JUCE_IPHONE
  13758. jassert (appLock == 0); // initialiseApp must only be called once!
  13759. if (! moreThanOneInstanceAllowed())
  13760. {
  13761. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13762. if (! appLock->enter(0))
  13763. {
  13764. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13765. delete appInstance;
  13766. appInstance = 0;
  13767. DBG ("Another instance is running - quitting...");
  13768. return false;
  13769. }
  13770. }
  13771. #endif
  13772. // let the app do its setting-up..
  13773. initialise (commandLineParameters);
  13774. // register for broadcast new app messages
  13775. MessageManager::getInstance()->registerBroadcastListener (this);
  13776. stillInitialising = false;
  13777. return true;
  13778. }
  13779. int JUCEApplication::shutdownAppAndClearUp()
  13780. {
  13781. jassert (appInstance != 0);
  13782. ScopedPointer<JUCEApplication> app (appInstance);
  13783. int returnValue = 0;
  13784. MessageManager::getInstance()->deregisterBroadcastListener ((JUCEApplication*) app);
  13785. static bool reentrancyCheck = false;
  13786. if (! reentrancyCheck)
  13787. {
  13788. reentrancyCheck = true;
  13789. JUCE_TRY
  13790. {
  13791. // give the app a chance to clean up..
  13792. app->shutdown();
  13793. }
  13794. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13795. catch (const std::exception& e)
  13796. {
  13797. app->unhandledException (&e, __FILE__, __LINE__);
  13798. }
  13799. catch (...)
  13800. {
  13801. app->unhandledException (0, __FILE__, __LINE__);
  13802. }
  13803. #endif
  13804. JUCE_TRY
  13805. {
  13806. shutdownJuce_GUI();
  13807. returnValue = app->getApplicationReturnValue();
  13808. appInstance = 0;
  13809. app = 0;
  13810. }
  13811. JUCE_CATCH_ALL_ASSERT
  13812. reentrancyCheck = false;
  13813. }
  13814. return returnValue;
  13815. }
  13816. #if JUCE_IPHONE
  13817. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13818. #endif
  13819. #if ! JUCE_WINDOWS
  13820. extern const char* juce_Argv0;
  13821. #endif
  13822. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13823. {
  13824. #if ! JUCE_WINDOWS
  13825. juce_Argv0 = argv[0];
  13826. #endif
  13827. #if JUCE_IPHONE
  13828. const ScopedAutoReleasePool pool;
  13829. return juce_IPhoneMain (argc, argv, newApp);
  13830. #else
  13831. #if JUCE_MAC
  13832. const ScopedAutoReleasePool pool;
  13833. #endif
  13834. String cmd;
  13835. for (int i = 1; i < argc; ++i)
  13836. cmd << argv[i] << ' ';
  13837. return JUCEApplication::main (cmd, newApp);
  13838. #endif
  13839. }
  13840. void JUCEApplication::actionListenerCallback (const String& message)
  13841. {
  13842. if (message.startsWith (getApplicationName() + "/"))
  13843. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13844. }
  13845. static bool juceInitialisedGUI = false;
  13846. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13847. {
  13848. if (! juceInitialisedGUI)
  13849. {
  13850. #if JUCE_MAC || JUCE_IPHONE
  13851. const ScopedAutoReleasePool pool;
  13852. #endif
  13853. juceInitialisedGUI = true;
  13854. initialiseJuce_NonGUI();
  13855. MessageManager::getInstance();
  13856. LookAndFeel::setDefaultLookAndFeel (0);
  13857. juce_setCurrentThreadName ("Juce Message Thread");
  13858. #if JUCE_WINDOWS && JUCE_DEBUG
  13859. // This section is just for catching people who mess up their project settings and
  13860. // turn RTTI off..
  13861. try
  13862. {
  13863. TextButton tb (String::empty);
  13864. Component* c = &tb;
  13865. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13866. c = dynamic_cast <Button*> (c);
  13867. }
  13868. catch (...)
  13869. {
  13870. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13871. // got as far as this catch statement, then why haven't you got exception catching
  13872. // turned on in the debugger???
  13873. jassertfalse
  13874. }
  13875. #endif
  13876. }
  13877. }
  13878. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13879. {
  13880. if (juceInitialisedGUI)
  13881. {
  13882. #if JUCE_MAC
  13883. const ScopedAutoReleasePool pool;
  13884. #endif
  13885. {
  13886. DeletedAtShutdown::deleteAll();
  13887. LookAndFeel::clearDefaultLookAndFeel();
  13888. }
  13889. delete MessageManager::getInstance();
  13890. shutdownJuce_NonGUI();
  13891. juceInitialisedGUI = false;
  13892. }
  13893. }
  13894. END_JUCE_NAMESPACE
  13895. /*** End of inlined file: juce_Application.cpp ***/
  13896. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13897. BEGIN_JUCE_NAMESPACE
  13898. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13899. : commandID (commandID_),
  13900. flags (0)
  13901. {
  13902. }
  13903. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13904. const String& description_,
  13905. const String& categoryName_,
  13906. const int flags_) throw()
  13907. {
  13908. shortName = shortName_;
  13909. description = description_;
  13910. categoryName = categoryName_;
  13911. flags = flags_;
  13912. }
  13913. void ApplicationCommandInfo::setActive (const bool b) throw()
  13914. {
  13915. if (b)
  13916. flags &= ~isDisabled;
  13917. else
  13918. flags |= isDisabled;
  13919. }
  13920. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13921. {
  13922. if (b)
  13923. flags |= isTicked;
  13924. else
  13925. flags &= ~isTicked;
  13926. }
  13927. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13928. {
  13929. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13930. }
  13931. END_JUCE_NAMESPACE
  13932. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13933. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13934. BEGIN_JUCE_NAMESPACE
  13935. ApplicationCommandManager::ApplicationCommandManager()
  13936. : firstTarget (0)
  13937. {
  13938. keyMappings = new KeyPressMappingSet (this);
  13939. Desktop::getInstance().addFocusChangeListener (this);
  13940. }
  13941. ApplicationCommandManager::~ApplicationCommandManager()
  13942. {
  13943. Desktop::getInstance().removeFocusChangeListener (this);
  13944. keyMappings = 0;
  13945. }
  13946. void ApplicationCommandManager::clearCommands()
  13947. {
  13948. commands.clear();
  13949. keyMappings->clearAllKeyPresses();
  13950. triggerAsyncUpdate();
  13951. }
  13952. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13953. {
  13954. // zero isn't a valid command ID!
  13955. jassert (newCommand.commandID != 0);
  13956. // the name isn't optional!
  13957. jassert (newCommand.shortName.isNotEmpty());
  13958. if (getCommandForID (newCommand.commandID) == 0)
  13959. {
  13960. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13961. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13962. commands.add (newInfo);
  13963. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13964. triggerAsyncUpdate();
  13965. }
  13966. else
  13967. {
  13968. // trying to re-register the same command with different parameters?
  13969. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13970. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13971. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13972. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13973. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13974. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13975. }
  13976. }
  13977. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13978. {
  13979. if (target != 0)
  13980. {
  13981. Array <CommandID> commandIDs;
  13982. target->getAllCommands (commandIDs);
  13983. for (int i = 0; i < commandIDs.size(); ++i)
  13984. {
  13985. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13986. target->getCommandInfo (info.commandID, info);
  13987. registerCommand (info);
  13988. }
  13989. }
  13990. }
  13991. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13992. {
  13993. for (int i = commands.size(); --i >= 0;)
  13994. {
  13995. if (commands.getUnchecked (i)->commandID == commandID)
  13996. {
  13997. commands.remove (i);
  13998. triggerAsyncUpdate();
  13999. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  14000. for (int j = keys.size(); --j >= 0;)
  14001. keyMappings->removeKeyPress (keys.getReference (j));
  14002. }
  14003. }
  14004. }
  14005. void ApplicationCommandManager::commandStatusChanged()
  14006. {
  14007. triggerAsyncUpdate();
  14008. }
  14009. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  14010. {
  14011. for (int i = commands.size(); --i >= 0;)
  14012. if (commands.getUnchecked(i)->commandID == commandID)
  14013. return commands.getUnchecked(i);
  14014. return 0;
  14015. }
  14016. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  14017. {
  14018. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14019. return (ci != 0) ? ci->shortName : String::empty;
  14020. }
  14021. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  14022. {
  14023. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14024. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  14025. : String::empty;
  14026. }
  14027. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  14028. {
  14029. StringArray s;
  14030. for (int i = 0; i < commands.size(); ++i)
  14031. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  14032. return s;
  14033. }
  14034. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  14035. {
  14036. Array <CommandID> results;
  14037. for (int i = 0; i < commands.size(); ++i)
  14038. if (commands.getUnchecked(i)->categoryName == categoryName)
  14039. results.add (commands.getUnchecked(i)->commandID);
  14040. return results;
  14041. }
  14042. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14043. {
  14044. ApplicationCommandTarget::InvocationInfo info (commandID);
  14045. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14046. return invoke (info, asynchronously);
  14047. }
  14048. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  14049. {
  14050. // This call isn't thread-safe for use from a non-UI thread without locking the message
  14051. // manager first..
  14052. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  14053. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  14054. if (target == 0)
  14055. return false;
  14056. ApplicationCommandInfo commandInfo (0);
  14057. target->getCommandInfo (info_.commandID, commandInfo);
  14058. ApplicationCommandTarget::InvocationInfo info (info_);
  14059. info.commandFlags = commandInfo.flags;
  14060. sendListenerInvokeCallback (info);
  14061. const bool ok = target->invoke (info, asynchronously);
  14062. commandStatusChanged();
  14063. return ok;
  14064. }
  14065. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  14066. {
  14067. return firstTarget != 0 ? firstTarget
  14068. : findDefaultComponentTarget();
  14069. }
  14070. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  14071. {
  14072. firstTarget = newTarget;
  14073. }
  14074. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  14075. ApplicationCommandInfo& upToDateInfo)
  14076. {
  14077. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  14078. if (target == 0)
  14079. target = JUCEApplication::getInstance();
  14080. if (target != 0)
  14081. target = target->getTargetForCommand (commandID);
  14082. if (target != 0)
  14083. target->getCommandInfo (commandID, upToDateInfo);
  14084. return target;
  14085. }
  14086. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  14087. {
  14088. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  14089. if (target == 0 && c != 0)
  14090. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14091. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14092. return target;
  14093. }
  14094. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  14095. {
  14096. Component* c = Component::getCurrentlyFocusedComponent();
  14097. if (c == 0)
  14098. {
  14099. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  14100. if (activeWindow != 0)
  14101. {
  14102. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  14103. if (c == 0)
  14104. c = activeWindow;
  14105. }
  14106. }
  14107. if (c == 0 && Process::isForegroundProcess())
  14108. {
  14109. // getting a bit desperate now - try all desktop comps..
  14110. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  14111. {
  14112. ApplicationCommandTarget* const target
  14113. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  14114. ->getPeer()->getLastFocusedSubcomponent());
  14115. if (target != 0)
  14116. return target;
  14117. }
  14118. }
  14119. if (c != 0)
  14120. {
  14121. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  14122. // if we're focused on a ResizableWindow, chances are that it's the content
  14123. // component that really should get the event. And if not, the event will
  14124. // still be passed up to the top level window anyway, so let's send it to the
  14125. // content comp.
  14126. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  14127. c = resizableWindow->getContentComponent();
  14128. ApplicationCommandTarget* const target = findTargetForComponent (c);
  14129. if (target != 0)
  14130. return target;
  14131. }
  14132. return JUCEApplication::getInstance();
  14133. }
  14134. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  14135. {
  14136. jassert (listener != 0);
  14137. if (listener != 0)
  14138. listeners.add (listener);
  14139. }
  14140. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  14141. {
  14142. listeners.removeValue (listener);
  14143. }
  14144. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const
  14145. {
  14146. for (int i = listeners.size(); --i >= 0;)
  14147. {
  14148. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandInvoked (info);
  14149. i = jmin (i, listeners.size());
  14150. }
  14151. }
  14152. void ApplicationCommandManager::handleAsyncUpdate()
  14153. {
  14154. for (int i = listeners.size(); --i >= 0;)
  14155. {
  14156. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandListChanged();
  14157. i = jmin (i, listeners.size());
  14158. }
  14159. }
  14160. void ApplicationCommandManager::globalFocusChanged (Component*)
  14161. {
  14162. commandStatusChanged();
  14163. }
  14164. END_JUCE_NAMESPACE
  14165. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  14166. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14167. BEGIN_JUCE_NAMESPACE
  14168. ApplicationCommandTarget::ApplicationCommandTarget()
  14169. {
  14170. }
  14171. ApplicationCommandTarget::~ApplicationCommandTarget()
  14172. {
  14173. messageInvoker = 0;
  14174. }
  14175. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  14176. {
  14177. if (isCommandActive (info.commandID))
  14178. {
  14179. if (async)
  14180. {
  14181. if (messageInvoker == 0)
  14182. messageInvoker = new CommandTargetMessageInvoker (this);
  14183. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  14184. return true;
  14185. }
  14186. else
  14187. {
  14188. const bool success = perform (info);
  14189. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  14190. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  14191. // returns the command's info.
  14192. return success;
  14193. }
  14194. }
  14195. return false;
  14196. }
  14197. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  14198. {
  14199. Component* c = dynamic_cast <Component*> (this);
  14200. if (c != 0)
  14201. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14202. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14203. return 0;
  14204. }
  14205. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  14206. {
  14207. ApplicationCommandTarget* target = this;
  14208. int depth = 0;
  14209. while (target != 0)
  14210. {
  14211. Array <CommandID> commandIDs;
  14212. target->getAllCommands (commandIDs);
  14213. if (commandIDs.contains (commandID))
  14214. return target;
  14215. target = target->getNextCommandTarget();
  14216. ++depth;
  14217. jassert (depth < 100); // could be a recursive command chain??
  14218. jassert (target != this); // definitely a recursive command chain!
  14219. if (depth > 100 || target == this)
  14220. break;
  14221. }
  14222. if (target == 0)
  14223. {
  14224. target = JUCEApplication::getInstance();
  14225. if (target != 0)
  14226. {
  14227. Array <CommandID> commandIDs;
  14228. target->getAllCommands (commandIDs);
  14229. if (commandIDs.contains (commandID))
  14230. return target;
  14231. }
  14232. }
  14233. return 0;
  14234. }
  14235. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14236. {
  14237. ApplicationCommandInfo info (commandID);
  14238. info.flags = ApplicationCommandInfo::isDisabled;
  14239. getCommandInfo (commandID, info);
  14240. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14241. }
  14242. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14243. {
  14244. ApplicationCommandTarget* target = this;
  14245. int depth = 0;
  14246. while (target != 0)
  14247. {
  14248. if (target->tryToInvoke (info, async))
  14249. return true;
  14250. target = target->getNextCommandTarget();
  14251. ++depth;
  14252. jassert (depth < 100); // could be a recursive command chain??
  14253. jassert (target != this); // definitely a recursive command chain!
  14254. if (depth > 100 || target == this)
  14255. break;
  14256. }
  14257. if (target == 0)
  14258. {
  14259. target = JUCEApplication::getInstance();
  14260. if (target != 0)
  14261. return target->tryToInvoke (info, async);
  14262. }
  14263. return false;
  14264. }
  14265. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14266. {
  14267. ApplicationCommandTarget::InvocationInfo info (commandID);
  14268. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14269. return invoke (info, asynchronously);
  14270. }
  14271. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14272. : commandID (commandID_),
  14273. commandFlags (0),
  14274. invocationMethod (direct),
  14275. originatingComponent (0),
  14276. isKeyDown (false),
  14277. millisecsSinceKeyPressed (0)
  14278. {
  14279. }
  14280. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14281. : owner (owner_)
  14282. {
  14283. }
  14284. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14285. {
  14286. }
  14287. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14288. {
  14289. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14290. owner->tryToInvoke (*info, false);
  14291. }
  14292. END_JUCE_NAMESPACE
  14293. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14294. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14295. BEGIN_JUCE_NAMESPACE
  14296. juce_ImplementSingleton (ApplicationProperties)
  14297. ApplicationProperties::ApplicationProperties() throw()
  14298. : msBeforeSaving (3000),
  14299. options (PropertiesFile::storeAsBinary),
  14300. commonSettingsAreReadOnly (0)
  14301. {
  14302. }
  14303. ApplicationProperties::~ApplicationProperties()
  14304. {
  14305. closeFiles();
  14306. clearSingletonInstance();
  14307. }
  14308. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14309. const String& fileNameSuffix,
  14310. const String& folderName_,
  14311. const int millisecondsBeforeSaving,
  14312. const int propertiesFileOptions) throw()
  14313. {
  14314. appName = applicationName;
  14315. fileSuffix = fileNameSuffix;
  14316. folderName = folderName_;
  14317. msBeforeSaving = millisecondsBeforeSaving;
  14318. options = propertiesFileOptions;
  14319. }
  14320. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14321. const bool testCommonSettings,
  14322. const bool showWarningDialogOnFailure)
  14323. {
  14324. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14325. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14326. if (! (userOk && commonOk))
  14327. {
  14328. if (showWarningDialogOnFailure)
  14329. {
  14330. String filenames;
  14331. if (userProps != 0 && ! userOk)
  14332. filenames << '\n' << userProps->getFile().getFullPathName();
  14333. if (commonProps != 0 && ! commonOk)
  14334. filenames << '\n' << commonProps->getFile().getFullPathName();
  14335. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14336. appName + TRANS(" - Unable to save settings"),
  14337. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14338. + appName + TRANS(" needs to be able to write to the following files:\n")
  14339. + filenames
  14340. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14341. }
  14342. return false;
  14343. }
  14344. return true;
  14345. }
  14346. void ApplicationProperties::openFiles() throw()
  14347. {
  14348. // You need to call setStorageParameters() before trying to get hold of the
  14349. // properties!
  14350. jassert (appName.isNotEmpty());
  14351. if (appName.isNotEmpty())
  14352. {
  14353. if (userProps == 0)
  14354. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14355. false, msBeforeSaving, options);
  14356. if (commonProps == 0)
  14357. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14358. true, msBeforeSaving, options);
  14359. userProps->setFallbackPropertySet (commonProps);
  14360. }
  14361. }
  14362. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14363. {
  14364. if (userProps == 0)
  14365. openFiles();
  14366. return userProps;
  14367. }
  14368. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14369. {
  14370. if (commonProps == 0)
  14371. openFiles();
  14372. if (returnUserPropsIfReadOnly)
  14373. {
  14374. if (commonSettingsAreReadOnly == 0)
  14375. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14376. if (commonSettingsAreReadOnly > 0)
  14377. return userProps;
  14378. }
  14379. return commonProps;
  14380. }
  14381. bool ApplicationProperties::saveIfNeeded()
  14382. {
  14383. return (userProps == 0 || userProps->saveIfNeeded())
  14384. && (commonProps == 0 || commonProps->saveIfNeeded());
  14385. }
  14386. void ApplicationProperties::closeFiles()
  14387. {
  14388. userProps = 0;
  14389. commonProps = 0;
  14390. }
  14391. END_JUCE_NAMESPACE
  14392. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14393. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14394. BEGIN_JUCE_NAMESPACE
  14395. static VoidArray objectsToDelete;
  14396. static CriticalSection lock;
  14397. DeletedAtShutdown::DeletedAtShutdown()
  14398. {
  14399. const ScopedLock sl (lock);
  14400. objectsToDelete.add (this);
  14401. }
  14402. DeletedAtShutdown::~DeletedAtShutdown()
  14403. {
  14404. const ScopedLock sl (lock);
  14405. objectsToDelete.removeValue (this);
  14406. }
  14407. void DeletedAtShutdown::deleteAll()
  14408. {
  14409. // make a local copy of the array, so it can't get into a loop if something
  14410. // creates another DeletedAtShutdown object during its destructor.
  14411. VoidArray localCopy;
  14412. {
  14413. const ScopedLock sl (lock);
  14414. localCopy = objectsToDelete;
  14415. }
  14416. for (int i = localCopy.size(); --i >= 0;)
  14417. {
  14418. JUCE_TRY
  14419. {
  14420. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14421. // double-check that it's not already been deleted during another object's destructor.
  14422. {
  14423. const ScopedLock sl (lock);
  14424. if (! objectsToDelete.contains (deletee))
  14425. deletee = 0;
  14426. }
  14427. delete deletee;
  14428. }
  14429. JUCE_CATCH_EXCEPTION
  14430. }
  14431. // if no objects got re-created during shutdown, this should have been emptied by their
  14432. // destructors
  14433. jassert (objectsToDelete.size() == 0);
  14434. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14435. }
  14436. END_JUCE_NAMESPACE
  14437. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14438. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14439. BEGIN_JUCE_NAMESPACE
  14440. static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP"));
  14441. static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP"));
  14442. static const tchar* const propertyFileXmlTag = T("PROPERTIES");
  14443. static const tchar* const propertyTagName = T("VALUE");
  14444. PropertiesFile::PropertiesFile (const File& f,
  14445. const int millisecondsBeforeSaving,
  14446. const int options_)
  14447. : PropertySet (ignoreCaseOfKeyNames),
  14448. file (f),
  14449. timerInterval (millisecondsBeforeSaving),
  14450. options (options_),
  14451. needsWriting (false)
  14452. {
  14453. // You need to correctly specify just one storage format for the file
  14454. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14455. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14456. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14457. ScopedPointer <InputStream> fileStream (f.createInputStream());
  14458. if (fileStream != 0)
  14459. {
  14460. int magicNumber = fileStream->readInt();
  14461. if (magicNumber == propFileMagicNumberCompressed)
  14462. {
  14463. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true),
  14464. true);
  14465. magicNumber = propFileMagicNumber;
  14466. }
  14467. if (magicNumber == propFileMagicNumber)
  14468. {
  14469. BufferedInputStream in (fileStream.release(), 2048, true);
  14470. int numValues = in.readInt();
  14471. while (--numValues >= 0 && ! in.isExhausted())
  14472. {
  14473. const String key (in.readString());
  14474. const String value (in.readString());
  14475. jassert (key.isNotEmpty());
  14476. if (key.isNotEmpty())
  14477. getAllProperties().set (key, value);
  14478. }
  14479. }
  14480. else
  14481. {
  14482. // Not a binary props file - let's see if it's XML..
  14483. fileStream = 0;
  14484. XmlDocument parser (f);
  14485. ScopedPointer <XmlElement> doc (parser.getDocumentElement (true));
  14486. if (doc != 0 && doc->hasTagName (propertyFileXmlTag))
  14487. {
  14488. doc = parser.getDocumentElement();
  14489. if (doc != 0)
  14490. {
  14491. forEachXmlChildElementWithTagName (*doc, e, propertyTagName)
  14492. {
  14493. const String name (e->getStringAttribute (T("name")));
  14494. if (name.isNotEmpty())
  14495. {
  14496. getAllProperties().set (name,
  14497. e->getFirstChildElement() != 0
  14498. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14499. : e->getStringAttribute (T("val")));
  14500. }
  14501. }
  14502. }
  14503. else
  14504. {
  14505. // must be a pretty broken XML file we're trying to parse here!
  14506. jassertfalse
  14507. }
  14508. }
  14509. }
  14510. }
  14511. }
  14512. PropertiesFile::~PropertiesFile()
  14513. {
  14514. saveIfNeeded();
  14515. }
  14516. bool PropertiesFile::saveIfNeeded()
  14517. {
  14518. const ScopedLock sl (getLock());
  14519. return (! needsWriting) || save();
  14520. }
  14521. bool PropertiesFile::needsToBeSaved() const
  14522. {
  14523. const ScopedLock sl (getLock());
  14524. return needsWriting;
  14525. }
  14526. bool PropertiesFile::save()
  14527. {
  14528. const ScopedLock sl (getLock());
  14529. stopTimer();
  14530. if (file == File::nonexistent
  14531. || file.isDirectory()
  14532. || ! file.getParentDirectory().createDirectory())
  14533. return false;
  14534. if ((options & storeAsXML) != 0)
  14535. {
  14536. XmlElement doc (propertyFileXmlTag);
  14537. for (int i = 0; i < getAllProperties().size(); ++i)
  14538. {
  14539. XmlElement* const e = doc.createNewChildElement (propertyTagName);
  14540. e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]);
  14541. // if the value seems to contain xml, store it as such..
  14542. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14543. XmlElement* const childElement = xmlContent.getDocumentElement();
  14544. if (childElement != 0)
  14545. e->addChildElement (childElement);
  14546. else
  14547. e->setAttribute (T("val"), getAllProperties().getAllValues() [i]);
  14548. }
  14549. return doc.writeToFile (file, String::empty);
  14550. }
  14551. else
  14552. {
  14553. TemporaryFile tempFile (file);
  14554. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14555. if (out != 0)
  14556. {
  14557. if ((options & storeAsCompressedBinary) != 0)
  14558. {
  14559. out->writeInt (propFileMagicNumberCompressed);
  14560. out->flush();
  14561. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14562. }
  14563. else
  14564. {
  14565. // have you set up the storage option flags correctly?
  14566. jassert ((options & storeAsBinary) != 0);
  14567. out->writeInt (propFileMagicNumber);
  14568. }
  14569. const int numProperties = getAllProperties().size();
  14570. out->writeInt (numProperties);
  14571. for (int i = 0; i < numProperties; ++i)
  14572. {
  14573. out->writeString (getAllProperties().getAllKeys() [i]);
  14574. out->writeString (getAllProperties().getAllValues() [i]);
  14575. }
  14576. out = 0;
  14577. if (tempFile.overwriteTargetFileWithTemporary())
  14578. {
  14579. needsWriting = false;
  14580. return true;
  14581. }
  14582. }
  14583. }
  14584. return false;
  14585. }
  14586. void PropertiesFile::timerCallback()
  14587. {
  14588. saveIfNeeded();
  14589. }
  14590. void PropertiesFile::propertyChanged()
  14591. {
  14592. sendChangeMessage (this);
  14593. needsWriting = true;
  14594. if (timerInterval > 0)
  14595. startTimer (timerInterval);
  14596. else if (timerInterval == 0)
  14597. saveIfNeeded();
  14598. }
  14599. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14600. const String& fileNameSuffix,
  14601. const String& folderName,
  14602. const bool commonToAllUsers)
  14603. {
  14604. // mustn't have illegal characters in this name..
  14605. jassert (applicationName == File::createLegalFileName (applicationName));
  14606. #if JUCE_MAC || JUCE_IPHONE
  14607. File dir (commonToAllUsers ? "/Library/Preferences"
  14608. : "~/Library/Preferences");
  14609. if (folderName.isNotEmpty())
  14610. dir = dir.getChildFile (folderName);
  14611. #endif
  14612. #ifdef JUCE_LINUX
  14613. const File dir ((commonToAllUsers ? T("/var/") : T("~/"))
  14614. + (folderName.isNotEmpty() ? folderName
  14615. : (T(".") + applicationName)));
  14616. #endif
  14617. #if JUCE_WIN32
  14618. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14619. : File::userApplicationDataDirectory));
  14620. if (dir == File::nonexistent)
  14621. return File::nonexistent;
  14622. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14623. : applicationName);
  14624. #endif
  14625. return dir.getChildFile (applicationName)
  14626. .withFileExtension (fileNameSuffix);
  14627. }
  14628. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14629. const String& fileNameSuffix,
  14630. const String& folderName,
  14631. const bool commonToAllUsers,
  14632. const int millisecondsBeforeSaving,
  14633. const int propertiesFileOptions)
  14634. {
  14635. const File file (getDefaultAppSettingsFile (applicationName,
  14636. fileNameSuffix,
  14637. folderName,
  14638. commonToAllUsers));
  14639. jassert (file != File::nonexistent);
  14640. if (file == File::nonexistent)
  14641. return 0;
  14642. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14643. }
  14644. END_JUCE_NAMESPACE
  14645. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14646. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14647. BEGIN_JUCE_NAMESPACE
  14648. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14649. const String& fileWildcard_,
  14650. const String& openFileDialogTitle_,
  14651. const String& saveFileDialogTitle_)
  14652. : changedSinceSave (false),
  14653. fileExtension (fileExtension_),
  14654. fileWildcard (fileWildcard_),
  14655. openFileDialogTitle (openFileDialogTitle_),
  14656. saveFileDialogTitle (saveFileDialogTitle_)
  14657. {
  14658. }
  14659. FileBasedDocument::~FileBasedDocument()
  14660. {
  14661. }
  14662. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14663. {
  14664. changedSinceSave = hasChanged;
  14665. }
  14666. void FileBasedDocument::changed()
  14667. {
  14668. changedSinceSave = true;
  14669. sendChangeMessage (this);
  14670. }
  14671. void FileBasedDocument::setFile (const File& newFile)
  14672. {
  14673. if (documentFile != newFile)
  14674. {
  14675. documentFile = newFile;
  14676. changedSinceSave = true;
  14677. }
  14678. }
  14679. bool FileBasedDocument::loadFrom (const File& newFile,
  14680. const bool showMessageOnFailure)
  14681. {
  14682. MouseCursor::showWaitCursor();
  14683. const File oldFile (documentFile);
  14684. documentFile = newFile;
  14685. String error;
  14686. if (newFile.existsAsFile())
  14687. {
  14688. error = loadDocument (newFile);
  14689. if (error.isEmpty())
  14690. {
  14691. setChangedFlag (false);
  14692. MouseCursor::hideWaitCursor();
  14693. setLastDocumentOpened (newFile);
  14694. return true;
  14695. }
  14696. }
  14697. else
  14698. {
  14699. error = "The file doesn't exist";
  14700. }
  14701. documentFile = oldFile;
  14702. MouseCursor::hideWaitCursor();
  14703. if (showMessageOnFailure)
  14704. {
  14705. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14706. TRANS("Failed to open file..."),
  14707. TRANS("There was an error while trying to load the file:\n\n")
  14708. + newFile.getFullPathName()
  14709. + T("\n\n")
  14710. + error);
  14711. }
  14712. return false;
  14713. }
  14714. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14715. {
  14716. FileChooser fc (openFileDialogTitle,
  14717. getLastDocumentOpened(),
  14718. fileWildcard);
  14719. if (fc.browseForFileToOpen())
  14720. return loadFrom (fc.getResult(), showMessageOnFailure);
  14721. return false;
  14722. }
  14723. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14724. const bool showMessageOnFailure)
  14725. {
  14726. return saveAs (documentFile,
  14727. false,
  14728. askUserForFileIfNotSpecified,
  14729. showMessageOnFailure);
  14730. }
  14731. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14732. const bool warnAboutOverwritingExistingFiles,
  14733. const bool askUserForFileIfNotSpecified,
  14734. const bool showMessageOnFailure)
  14735. {
  14736. if (newFile == File::nonexistent)
  14737. {
  14738. if (askUserForFileIfNotSpecified)
  14739. {
  14740. return saveAsInteractive (true);
  14741. }
  14742. else
  14743. {
  14744. // can't save to an unspecified file
  14745. jassertfalse
  14746. return failedToWriteToFile;
  14747. }
  14748. }
  14749. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14750. {
  14751. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14752. TRANS("File already exists"),
  14753. TRANS("There's already a file called:\n\n")
  14754. + newFile.getFullPathName()
  14755. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14756. TRANS("overwrite"),
  14757. TRANS("cancel")))
  14758. {
  14759. return userCancelledSave;
  14760. }
  14761. }
  14762. MouseCursor::showWaitCursor();
  14763. const File oldFile (documentFile);
  14764. documentFile = newFile;
  14765. String error (saveDocument (newFile));
  14766. if (error.isEmpty())
  14767. {
  14768. setChangedFlag (false);
  14769. MouseCursor::hideWaitCursor();
  14770. return savedOk;
  14771. }
  14772. documentFile = oldFile;
  14773. MouseCursor::hideWaitCursor();
  14774. if (showMessageOnFailure)
  14775. {
  14776. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14777. TRANS("Error writing to file..."),
  14778. TRANS("An error occurred while trying to save \"")
  14779. + getDocumentTitle()
  14780. + TRANS("\" to the file:\n\n")
  14781. + newFile.getFullPathName()
  14782. + T("\n\n")
  14783. + error);
  14784. }
  14785. return failedToWriteToFile;
  14786. }
  14787. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14788. {
  14789. if (! hasChangedSinceSaved())
  14790. return savedOk;
  14791. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14792. TRANS("Closing document..."),
  14793. TRANS("Do you want to save the changes to \"")
  14794. + getDocumentTitle() + T("\"?"),
  14795. TRANS("save"),
  14796. TRANS("discard changes"),
  14797. TRANS("cancel"));
  14798. if (r == 1)
  14799. {
  14800. // save changes
  14801. return save (true, true);
  14802. }
  14803. else if (r == 2)
  14804. {
  14805. // discard changes
  14806. return savedOk;
  14807. }
  14808. return userCancelledSave;
  14809. }
  14810. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14811. {
  14812. File f;
  14813. if (documentFile.existsAsFile())
  14814. f = documentFile;
  14815. else
  14816. f = getLastDocumentOpened();
  14817. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14818. if (legalFilename.isEmpty())
  14819. legalFilename = "unnamed";
  14820. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14821. f = f.getSiblingFile (legalFilename);
  14822. else
  14823. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14824. f = f.withFileExtension (fileExtension)
  14825. .getNonexistentSibling (true);
  14826. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14827. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14828. {
  14829. setLastDocumentOpened (fc.getResult());
  14830. File chosen (fc.getResult());
  14831. if (chosen.getFileExtension().isEmpty())
  14832. {
  14833. chosen = chosen.withFileExtension (fileExtension);
  14834. if (chosen.exists())
  14835. {
  14836. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14837. TRANS("File already exists"),
  14838. TRANS("There's already a file called:\n\n")
  14839. + chosen.getFullPathName()
  14840. + T("\n\nAre you sure you want to overwrite it?"),
  14841. TRANS("overwrite"),
  14842. TRANS("cancel")))
  14843. {
  14844. return userCancelledSave;
  14845. }
  14846. }
  14847. }
  14848. return saveAs (chosen, false, false, true);
  14849. }
  14850. return userCancelledSave;
  14851. }
  14852. END_JUCE_NAMESPACE
  14853. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14854. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14855. BEGIN_JUCE_NAMESPACE
  14856. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14857. : maxNumberOfItems (10)
  14858. {
  14859. }
  14860. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14861. {
  14862. }
  14863. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14864. {
  14865. maxNumberOfItems = jmax (1, newMaxNumber);
  14866. while (getNumFiles() > maxNumberOfItems)
  14867. files.remove (getNumFiles() - 1);
  14868. }
  14869. int RecentlyOpenedFilesList::getNumFiles() const
  14870. {
  14871. return files.size();
  14872. }
  14873. const File RecentlyOpenedFilesList::getFile (const int index) const
  14874. {
  14875. return File (files [index]);
  14876. }
  14877. void RecentlyOpenedFilesList::clear()
  14878. {
  14879. files.clear();
  14880. }
  14881. void RecentlyOpenedFilesList::addFile (const File& file)
  14882. {
  14883. const String path (file.getFullPathName());
  14884. files.removeString (path, true);
  14885. files.insert (0, path);
  14886. setMaxNumberOfItems (maxNumberOfItems);
  14887. }
  14888. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14889. {
  14890. for (int i = getNumFiles(); --i >= 0;)
  14891. if (! getFile(i).exists())
  14892. files.remove (i);
  14893. }
  14894. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14895. const int baseItemId,
  14896. const bool showFullPaths,
  14897. const bool dontAddNonExistentFiles,
  14898. const File** filesToAvoid)
  14899. {
  14900. int num = 0;
  14901. for (int i = 0; i < getNumFiles(); ++i)
  14902. {
  14903. const File f (getFile(i));
  14904. if ((! dontAddNonExistentFiles) || f.exists())
  14905. {
  14906. bool needsAvoiding = false;
  14907. if (filesToAvoid != 0)
  14908. {
  14909. const File** avoid = filesToAvoid;
  14910. while (*avoid != 0)
  14911. {
  14912. if (f == **avoid)
  14913. {
  14914. needsAvoiding = true;
  14915. break;
  14916. }
  14917. ++avoid;
  14918. }
  14919. }
  14920. if (! needsAvoiding)
  14921. {
  14922. menuToAddTo.addItem (baseItemId + i,
  14923. showFullPaths ? f.getFullPathName()
  14924. : f.getFileName());
  14925. ++num;
  14926. }
  14927. }
  14928. }
  14929. return num;
  14930. }
  14931. const String RecentlyOpenedFilesList::toString() const
  14932. {
  14933. return files.joinIntoString (T("\n"));
  14934. }
  14935. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14936. {
  14937. clear();
  14938. files.addLines (stringifiedVersion);
  14939. setMaxNumberOfItems (maxNumberOfItems);
  14940. }
  14941. END_JUCE_NAMESPACE
  14942. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14943. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14944. BEGIN_JUCE_NAMESPACE
  14945. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14946. const int minimumTransactions)
  14947. : totalUnitsStored (0),
  14948. nextIndex (0),
  14949. newTransaction (true),
  14950. reentrancyCheck (false)
  14951. {
  14952. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14953. minimumTransactions);
  14954. }
  14955. UndoManager::~UndoManager()
  14956. {
  14957. clearUndoHistory();
  14958. }
  14959. void UndoManager::clearUndoHistory()
  14960. {
  14961. transactions.clear();
  14962. transactionNames.clear();
  14963. totalUnitsStored = 0;
  14964. nextIndex = 0;
  14965. sendChangeMessage (this);
  14966. }
  14967. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14968. {
  14969. return totalUnitsStored;
  14970. }
  14971. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14972. const int minimumTransactions)
  14973. {
  14974. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14975. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14976. }
  14977. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14978. {
  14979. if (command != 0)
  14980. {
  14981. if (actionName.isNotEmpty())
  14982. currentTransactionName = actionName;
  14983. if (reentrancyCheck)
  14984. {
  14985. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14986. // undo() methods, or else these actions won't actually get done.
  14987. return false;
  14988. }
  14989. else
  14990. {
  14991. bool success = false;
  14992. JUCE_TRY
  14993. {
  14994. success = command->perform();
  14995. }
  14996. JUCE_CATCH_EXCEPTION
  14997. jassert (success);
  14998. if (success)
  14999. {
  15000. if (nextIndex > 0 && ! newTransaction)
  15001. {
  15002. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  15003. jassert (commandSet != 0);
  15004. if (commandSet == 0)
  15005. return false;
  15006. commandSet->add (command);
  15007. }
  15008. else
  15009. {
  15010. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  15011. commandSet->add (command);
  15012. transactions.insert (nextIndex, commandSet);
  15013. transactionNames.insert (nextIndex, currentTransactionName);
  15014. ++nextIndex;
  15015. }
  15016. totalUnitsStored += command->getSizeInUnits();
  15017. newTransaction = false;
  15018. }
  15019. while (nextIndex < transactions.size())
  15020. {
  15021. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  15022. for (int i = lastSet->size(); --i >= 0;)
  15023. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  15024. transactions.removeLast();
  15025. transactionNames.remove (transactionNames.size() - 1);
  15026. }
  15027. while (nextIndex > 0
  15028. && totalUnitsStored > maxNumUnitsToKeep
  15029. && transactions.size() > minimumTransactionsToKeep)
  15030. {
  15031. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  15032. for (int i = firstSet->size(); --i >= 0;)
  15033. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  15034. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  15035. transactions.remove (0);
  15036. transactionNames.remove (0);
  15037. --nextIndex;
  15038. }
  15039. sendChangeMessage (this);
  15040. return success;
  15041. }
  15042. }
  15043. return false;
  15044. }
  15045. void UndoManager::beginNewTransaction (const String& actionName)
  15046. {
  15047. newTransaction = true;
  15048. currentTransactionName = actionName;
  15049. }
  15050. void UndoManager::setCurrentTransactionName (const String& newName)
  15051. {
  15052. currentTransactionName = newName;
  15053. }
  15054. bool UndoManager::canUndo() const
  15055. {
  15056. return nextIndex > 0;
  15057. }
  15058. bool UndoManager::canRedo() const
  15059. {
  15060. return nextIndex < transactions.size();
  15061. }
  15062. const String UndoManager::getUndoDescription() const
  15063. {
  15064. return transactionNames [nextIndex - 1];
  15065. }
  15066. const String UndoManager::getRedoDescription() const
  15067. {
  15068. return transactionNames [nextIndex];
  15069. }
  15070. bool UndoManager::undo()
  15071. {
  15072. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15073. if (commandSet == 0)
  15074. return false;
  15075. reentrancyCheck = true;
  15076. bool failed = false;
  15077. for (int i = commandSet->size(); --i >= 0;)
  15078. {
  15079. if (! commandSet->getUnchecked(i)->undo())
  15080. {
  15081. jassertfalse
  15082. failed = true;
  15083. break;
  15084. }
  15085. }
  15086. reentrancyCheck = false;
  15087. if (failed)
  15088. {
  15089. clearUndoHistory();
  15090. }
  15091. else
  15092. {
  15093. --nextIndex;
  15094. }
  15095. beginNewTransaction();
  15096. sendChangeMessage (this);
  15097. return true;
  15098. }
  15099. bool UndoManager::redo()
  15100. {
  15101. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  15102. if (commandSet == 0)
  15103. return false;
  15104. reentrancyCheck = true;
  15105. bool failed = false;
  15106. for (int i = 0; i < commandSet->size(); ++i)
  15107. {
  15108. if (! commandSet->getUnchecked(i)->perform())
  15109. {
  15110. jassertfalse
  15111. failed = true;
  15112. break;
  15113. }
  15114. }
  15115. reentrancyCheck = false;
  15116. if (failed)
  15117. {
  15118. clearUndoHistory();
  15119. }
  15120. else
  15121. {
  15122. ++nextIndex;
  15123. }
  15124. beginNewTransaction();
  15125. sendChangeMessage (this);
  15126. return true;
  15127. }
  15128. bool UndoManager::undoCurrentTransactionOnly()
  15129. {
  15130. return newTransaction ? false
  15131. : undo();
  15132. }
  15133. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  15134. {
  15135. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15136. if (commandSet != 0 && ! newTransaction)
  15137. {
  15138. for (int i = 0; i < commandSet->size(); ++i)
  15139. actionsFound.add (commandSet->getUnchecked(i));
  15140. }
  15141. }
  15142. int UndoManager::getNumActionsInCurrentTransaction() const
  15143. {
  15144. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15145. if (commandSet != 0 && ! newTransaction)
  15146. return commandSet->size();
  15147. return 0;
  15148. }
  15149. END_JUCE_NAMESPACE
  15150. /*** End of inlined file: juce_UndoManager.cpp ***/
  15151. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  15152. BEGIN_JUCE_NAMESPACE
  15153. static const char* const aiffFormatName = "AIFF file";
  15154. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  15155. class AiffAudioFormatReader : public AudioFormatReader
  15156. {
  15157. public:
  15158. int bytesPerFrame;
  15159. int64 dataChunkStart;
  15160. bool littleEndian;
  15161. AiffAudioFormatReader (InputStream* in)
  15162. : AudioFormatReader (in, TRANS (aiffFormatName))
  15163. {
  15164. if (input->readInt() == chunkName ("FORM"))
  15165. {
  15166. const int len = input->readIntBigEndian();
  15167. const int64 end = input->getPosition() + len;
  15168. const int nextType = input->readInt();
  15169. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  15170. {
  15171. bool hasGotVer = false;
  15172. bool hasGotData = false;
  15173. bool hasGotType = false;
  15174. while (input->getPosition() < end)
  15175. {
  15176. const int type = input->readInt();
  15177. const uint32 length = (uint32) input->readIntBigEndian();
  15178. const int64 chunkEnd = input->getPosition() + length;
  15179. if (type == chunkName ("FVER"))
  15180. {
  15181. hasGotVer = true;
  15182. const int ver = input->readIntBigEndian();
  15183. if (ver != 0 && ver != (int)0xa2805140)
  15184. break;
  15185. }
  15186. else if (type == chunkName ("COMM"))
  15187. {
  15188. hasGotType = true;
  15189. numChannels = (unsigned int)input->readShortBigEndian();
  15190. lengthInSamples = input->readIntBigEndian();
  15191. bitsPerSample = input->readShortBigEndian();
  15192. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15193. unsigned char sampleRateBytes[10];
  15194. input->read (sampleRateBytes, 10);
  15195. const int byte0 = sampleRateBytes[0];
  15196. if ((byte0 & 0x80) != 0
  15197. || byte0 <= 0x3F || byte0 > 0x40
  15198. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15199. break;
  15200. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15201. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15202. sampleRate = (int) sampRate;
  15203. if (length <= 18)
  15204. {
  15205. // some types don't have a chunk large enough to include a compression
  15206. // type, so assume it's just big-endian pcm
  15207. littleEndian = false;
  15208. }
  15209. else
  15210. {
  15211. const int compType = input->readInt();
  15212. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15213. {
  15214. littleEndian = false;
  15215. }
  15216. else if (compType == chunkName ("sowt"))
  15217. {
  15218. littleEndian = true;
  15219. }
  15220. else
  15221. {
  15222. sampleRate = 0;
  15223. break;
  15224. }
  15225. }
  15226. }
  15227. else if (type == chunkName ("SSND"))
  15228. {
  15229. hasGotData = true;
  15230. const int offset = input->readIntBigEndian();
  15231. dataChunkStart = input->getPosition() + 4 + offset;
  15232. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15233. }
  15234. else if ((hasGotVer && hasGotData && hasGotType)
  15235. || chunkEnd < input->getPosition()
  15236. || input->isExhausted())
  15237. {
  15238. break;
  15239. }
  15240. input->setPosition (chunkEnd);
  15241. }
  15242. }
  15243. }
  15244. }
  15245. ~AiffAudioFormatReader()
  15246. {
  15247. }
  15248. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15249. int64 startSampleInFile, int numSamples)
  15250. {
  15251. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15252. if (samplesAvailable < numSamples)
  15253. {
  15254. for (int i = numDestChannels; --i >= 0;)
  15255. if (destSamples[i] != 0)
  15256. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15257. numSamples = (int) samplesAvailable;
  15258. }
  15259. if (numSamples <= 0)
  15260. return true;
  15261. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15262. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15263. char tempBuffer [tempBufSize];
  15264. while (numSamples > 0)
  15265. {
  15266. int* left = destSamples[0];
  15267. if (left != 0)
  15268. left += startOffsetInDestBuffer;
  15269. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15270. if (right != 0)
  15271. right += startOffsetInDestBuffer;
  15272. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15273. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15274. if (bytesRead < numThisTime * bytesPerFrame)
  15275. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15276. if (bitsPerSample == 16)
  15277. {
  15278. if (littleEndian)
  15279. {
  15280. const short* src = (const short*) tempBuffer;
  15281. if (numChannels > 1)
  15282. {
  15283. if (left == 0)
  15284. {
  15285. for (int i = numThisTime; --i >= 0;)
  15286. {
  15287. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15288. ++src;
  15289. }
  15290. }
  15291. else if (right == 0)
  15292. {
  15293. for (int i = numThisTime; --i >= 0;)
  15294. {
  15295. ++src;
  15296. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15297. }
  15298. }
  15299. else
  15300. {
  15301. for (int i = numThisTime; --i >= 0;)
  15302. {
  15303. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15304. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15305. }
  15306. }
  15307. }
  15308. else
  15309. {
  15310. for (int i = numThisTime; --i >= 0;)
  15311. {
  15312. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15313. }
  15314. }
  15315. }
  15316. else
  15317. {
  15318. const char* src = (const char*) tempBuffer;
  15319. if (numChannels > 1)
  15320. {
  15321. if (left == 0)
  15322. {
  15323. for (int i = numThisTime; --i >= 0;)
  15324. {
  15325. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15326. src += 4;
  15327. }
  15328. }
  15329. else if (right == 0)
  15330. {
  15331. for (int i = numThisTime; --i >= 0;)
  15332. {
  15333. src += 2;
  15334. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15335. src += 2;
  15336. }
  15337. }
  15338. else
  15339. {
  15340. for (int i = numThisTime; --i >= 0;)
  15341. {
  15342. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15343. src += 2;
  15344. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15345. src += 2;
  15346. }
  15347. }
  15348. }
  15349. else
  15350. {
  15351. for (int i = numThisTime; --i >= 0;)
  15352. {
  15353. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15354. src += 2;
  15355. }
  15356. }
  15357. }
  15358. }
  15359. else if (bitsPerSample == 24)
  15360. {
  15361. const char* src = (const char*)tempBuffer;
  15362. if (littleEndian)
  15363. {
  15364. if (numChannels > 1)
  15365. {
  15366. if (left == 0)
  15367. {
  15368. for (int i = numThisTime; --i >= 0;)
  15369. {
  15370. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15371. src += 6;
  15372. }
  15373. }
  15374. else if (right == 0)
  15375. {
  15376. for (int i = numThisTime; --i >= 0;)
  15377. {
  15378. src += 3;
  15379. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15380. src += 3;
  15381. }
  15382. }
  15383. else
  15384. {
  15385. for (int i = numThisTime; --i >= 0;)
  15386. {
  15387. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15388. src += 3;
  15389. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15390. src += 3;
  15391. }
  15392. }
  15393. }
  15394. else
  15395. {
  15396. for (int i = numThisTime; --i >= 0;)
  15397. {
  15398. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15399. src += 3;
  15400. }
  15401. }
  15402. }
  15403. else
  15404. {
  15405. if (numChannels > 1)
  15406. {
  15407. if (left == 0)
  15408. {
  15409. for (int i = numThisTime; --i >= 0;)
  15410. {
  15411. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15412. src += 6;
  15413. }
  15414. }
  15415. else if (right == 0)
  15416. {
  15417. for (int i = numThisTime; --i >= 0;)
  15418. {
  15419. src += 3;
  15420. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15421. src += 3;
  15422. }
  15423. }
  15424. else
  15425. {
  15426. for (int i = numThisTime; --i >= 0;)
  15427. {
  15428. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15429. src += 3;
  15430. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15431. src += 3;
  15432. }
  15433. }
  15434. }
  15435. else
  15436. {
  15437. for (int i = numThisTime; --i >= 0;)
  15438. {
  15439. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15440. src += 3;
  15441. }
  15442. }
  15443. }
  15444. }
  15445. else if (bitsPerSample == 32)
  15446. {
  15447. const unsigned int* src = (const unsigned int*) tempBuffer;
  15448. unsigned int* l = (unsigned int*) left;
  15449. unsigned int* r = (unsigned int*) right;
  15450. if (littleEndian)
  15451. {
  15452. if (numChannels > 1)
  15453. {
  15454. if (l == 0)
  15455. {
  15456. for (int i = numThisTime; --i >= 0;)
  15457. {
  15458. ++src;
  15459. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15460. }
  15461. }
  15462. else if (r == 0)
  15463. {
  15464. for (int i = numThisTime; --i >= 0;)
  15465. {
  15466. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15467. ++src;
  15468. }
  15469. }
  15470. else
  15471. {
  15472. for (int i = numThisTime; --i >= 0;)
  15473. {
  15474. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15475. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15476. }
  15477. }
  15478. }
  15479. else
  15480. {
  15481. for (int i = numThisTime; --i >= 0;)
  15482. {
  15483. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15484. }
  15485. }
  15486. }
  15487. else
  15488. {
  15489. if (numChannels > 1)
  15490. {
  15491. if (l == 0)
  15492. {
  15493. for (int i = numThisTime; --i >= 0;)
  15494. {
  15495. ++src;
  15496. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15497. }
  15498. }
  15499. else if (r == 0)
  15500. {
  15501. for (int i = numThisTime; --i >= 0;)
  15502. {
  15503. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15504. ++src;
  15505. }
  15506. }
  15507. else
  15508. {
  15509. for (int i = numThisTime; --i >= 0;)
  15510. {
  15511. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15512. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15513. }
  15514. }
  15515. }
  15516. else
  15517. {
  15518. for (int i = numThisTime; --i >= 0;)
  15519. {
  15520. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15521. }
  15522. }
  15523. }
  15524. left = (int*) l;
  15525. right = (int*) r;
  15526. }
  15527. else if (bitsPerSample == 8)
  15528. {
  15529. const char* src = (const char*) tempBuffer;
  15530. if (numChannels > 1)
  15531. {
  15532. if (left == 0)
  15533. {
  15534. for (int i = numThisTime; --i >= 0;)
  15535. {
  15536. *right++ = ((int) *src++) << 24;
  15537. ++src;
  15538. }
  15539. }
  15540. else if (right == 0)
  15541. {
  15542. for (int i = numThisTime; --i >= 0;)
  15543. {
  15544. ++src;
  15545. *left++ = ((int) *src++) << 24;
  15546. }
  15547. }
  15548. else
  15549. {
  15550. for (int i = numThisTime; --i >= 0;)
  15551. {
  15552. *left++ = ((int) *src++) << 24;
  15553. *right++ = ((int) *src++) << 24;
  15554. }
  15555. }
  15556. }
  15557. else
  15558. {
  15559. for (int i = numThisTime; --i >= 0;)
  15560. {
  15561. *left++ = ((int) *src++) << 24;
  15562. }
  15563. }
  15564. }
  15565. startOffsetInDestBuffer += numThisTime;
  15566. numSamples -= numThisTime;
  15567. }
  15568. if (numSamples > 0)
  15569. {
  15570. for (int i = numDestChannels; --i >= 0;)
  15571. if (destSamples[i] != 0)
  15572. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15573. sizeof (int) * numSamples);
  15574. }
  15575. return true;
  15576. }
  15577. juce_UseDebuggingNewOperator
  15578. private:
  15579. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15580. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15581. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15582. };
  15583. class AiffAudioFormatWriter : public AudioFormatWriter
  15584. {
  15585. MemoryBlock tempBlock;
  15586. uint32 lengthInSamples, bytesWritten;
  15587. int64 headerPosition;
  15588. bool writeFailed;
  15589. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15590. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15591. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15592. void writeHeader()
  15593. {
  15594. const bool couldSeekOk = output->setPosition (headerPosition);
  15595. (void) couldSeekOk;
  15596. // if this fails, you've given it an output stream that can't seek! It needs
  15597. // to be able to seek back to write the header
  15598. jassert (couldSeekOk);
  15599. const int headerLen = 54;
  15600. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15601. audioBytes += (audioBytes & 1);
  15602. output->writeInt (chunkName ("FORM"));
  15603. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15604. output->writeInt (chunkName ("AIFF"));
  15605. output->writeInt (chunkName ("COMM"));
  15606. output->writeIntBigEndian (18);
  15607. output->writeShortBigEndian ((short) numChannels);
  15608. output->writeIntBigEndian (lengthInSamples);
  15609. output->writeShortBigEndian ((short) bitsPerSample);
  15610. uint8 sampleRateBytes[10];
  15611. zeromem (sampleRateBytes, 10);
  15612. if (sampleRate <= 1)
  15613. {
  15614. sampleRateBytes[0] = 0x3f;
  15615. sampleRateBytes[1] = 0xff;
  15616. sampleRateBytes[2] = 0x80;
  15617. }
  15618. else
  15619. {
  15620. int mask = 0x40000000;
  15621. sampleRateBytes[0] = 0x40;
  15622. if (sampleRate >= mask)
  15623. {
  15624. jassertfalse
  15625. sampleRateBytes[1] = 0x1d;
  15626. }
  15627. else
  15628. {
  15629. int n = (int) sampleRate;
  15630. int i;
  15631. for (i = 0; i <= 32 ; ++i)
  15632. {
  15633. if ((n & mask) != 0)
  15634. break;
  15635. mask >>= 1;
  15636. }
  15637. n = n << (i + 1);
  15638. sampleRateBytes[1] = (uint8) (29 - i);
  15639. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15640. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15641. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15642. sampleRateBytes[5] = (uint8) (n & 0xff);
  15643. }
  15644. }
  15645. output->write (sampleRateBytes, 10);
  15646. output->writeInt (chunkName ("SSND"));
  15647. output->writeIntBigEndian (audioBytes + 8);
  15648. output->writeInt (0);
  15649. output->writeInt (0);
  15650. jassert (output->getPosition() == headerLen);
  15651. }
  15652. public:
  15653. AiffAudioFormatWriter (OutputStream* out,
  15654. const double sampleRate_,
  15655. const unsigned int chans,
  15656. const int bits)
  15657. : AudioFormatWriter (out,
  15658. TRANS (aiffFormatName),
  15659. sampleRate_,
  15660. chans,
  15661. bits),
  15662. lengthInSamples (0),
  15663. bytesWritten (0),
  15664. writeFailed (false)
  15665. {
  15666. headerPosition = out->getPosition();
  15667. writeHeader();
  15668. }
  15669. ~AiffAudioFormatWriter()
  15670. {
  15671. if ((bytesWritten & 1) != 0)
  15672. output->writeByte (0);
  15673. writeHeader();
  15674. }
  15675. bool write (const int** data, int numSamples)
  15676. {
  15677. if (writeFailed)
  15678. return false;
  15679. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15680. tempBlock.ensureSize (bytes, false);
  15681. char* buffer = (char*) tempBlock.getData();
  15682. const int* left = data[0];
  15683. const int* right = data[1];
  15684. if (right == 0)
  15685. right = left;
  15686. if (bitsPerSample == 16)
  15687. {
  15688. short* b = (short*) buffer;
  15689. if (numChannels > 1)
  15690. {
  15691. for (int i = numSamples; --i >= 0;)
  15692. {
  15693. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15694. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15695. }
  15696. }
  15697. else
  15698. {
  15699. for (int i = numSamples; --i >= 0;)
  15700. {
  15701. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15702. }
  15703. }
  15704. }
  15705. else if (bitsPerSample == 24)
  15706. {
  15707. char* b = (char*) buffer;
  15708. if (numChannels > 1)
  15709. {
  15710. for (int i = numSamples; --i >= 0;)
  15711. {
  15712. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15713. b += 3;
  15714. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15715. b += 3;
  15716. }
  15717. }
  15718. else
  15719. {
  15720. for (int i = numSamples; --i >= 0;)
  15721. {
  15722. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15723. b += 3;
  15724. }
  15725. }
  15726. }
  15727. else if (bitsPerSample == 32)
  15728. {
  15729. uint32* b = (uint32*) buffer;
  15730. if (numChannels > 1)
  15731. {
  15732. for (int i = numSamples; --i >= 0;)
  15733. {
  15734. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15735. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15736. }
  15737. }
  15738. else
  15739. {
  15740. for (int i = numSamples; --i >= 0;)
  15741. {
  15742. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15743. }
  15744. }
  15745. }
  15746. else if (bitsPerSample == 8)
  15747. {
  15748. char* b = (char*) buffer;
  15749. if (numChannels > 1)
  15750. {
  15751. for (int i = numSamples; --i >= 0;)
  15752. {
  15753. *b++ = (char) (*left++ >> 24);
  15754. *b++ = (char) (*right++ >> 24);
  15755. }
  15756. }
  15757. else
  15758. {
  15759. for (int i = numSamples; --i >= 0;)
  15760. {
  15761. *b++ = (char) (*left++ >> 24);
  15762. }
  15763. }
  15764. }
  15765. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15766. || ! output->write (buffer, bytes))
  15767. {
  15768. // failed to write to disk, so let's try writing the header.
  15769. // If it's just run out of disk space, then if it does manage
  15770. // to write the header, we'll still have a useable file..
  15771. writeHeader();
  15772. writeFailed = true;
  15773. return false;
  15774. }
  15775. else
  15776. {
  15777. bytesWritten += bytes;
  15778. lengthInSamples += numSamples;
  15779. return true;
  15780. }
  15781. }
  15782. juce_UseDebuggingNewOperator
  15783. };
  15784. AiffAudioFormat::AiffAudioFormat()
  15785. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15786. {
  15787. }
  15788. AiffAudioFormat::~AiffAudioFormat()
  15789. {
  15790. }
  15791. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15792. {
  15793. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15794. return Array <int> (rates);
  15795. }
  15796. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15797. {
  15798. const int depths[] = { 8, 16, 24, 0 };
  15799. return Array <int> (depths);
  15800. }
  15801. bool AiffAudioFormat::canDoStereo()
  15802. {
  15803. return true;
  15804. }
  15805. bool AiffAudioFormat::canDoMono()
  15806. {
  15807. return true;
  15808. }
  15809. #if JUCE_MAC
  15810. bool AiffAudioFormat::canHandleFile (const File& f)
  15811. {
  15812. if (AudioFormat::canHandleFile (f))
  15813. return true;
  15814. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15815. return type == 'AIFF' || type == 'AIFC'
  15816. || type == 'aiff' || type == 'aifc';
  15817. }
  15818. #endif
  15819. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15820. const bool deleteStreamIfOpeningFails)
  15821. {
  15822. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15823. if (w->sampleRate != 0)
  15824. return w.release();
  15825. if (! deleteStreamIfOpeningFails)
  15826. w->input = 0;
  15827. return 0;
  15828. }
  15829. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15830. double sampleRate,
  15831. unsigned int chans,
  15832. int bitsPerSample,
  15833. const StringPairArray& /*metadataValues*/,
  15834. int /*qualityOptionIndex*/)
  15835. {
  15836. if (getPossibleBitDepths().contains (bitsPerSample))
  15837. {
  15838. return new AiffAudioFormatWriter (out,
  15839. sampleRate,
  15840. chans,
  15841. bitsPerSample);
  15842. }
  15843. return 0;
  15844. }
  15845. END_JUCE_NAMESPACE
  15846. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15847. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15848. BEGIN_JUCE_NAMESPACE
  15849. #if JUCE_MAC && JUCE_USE_CDREADER
  15850. // Mac version doesn't need any native code because it's all done with files..
  15851. // Windows + Linux versions are in the platform-dependent code sections.
  15852. static void findCDs (Array<File>& cds)
  15853. {
  15854. File volumes ("/Volumes");
  15855. volumes.findChildFiles (cds, File::findDirectories, false);
  15856. for (int i = cds.size(); --i >= 0;)
  15857. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15858. cds.remove (i);
  15859. }
  15860. const StringArray AudioCDReader::getAvailableCDNames()
  15861. {
  15862. Array<File> cds;
  15863. findCDs (cds);
  15864. StringArray names;
  15865. for (int i = 0; i < cds.size(); ++i)
  15866. names.add (cds.getReference(i).getFileName());
  15867. return names;
  15868. }
  15869. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15870. {
  15871. Array<File> cds;
  15872. findCDs (cds);
  15873. if (cds[index] != File::nonexistent)
  15874. return new AudioCDReader (cds[index]);
  15875. else
  15876. return 0;
  15877. }
  15878. AudioCDReader::AudioCDReader (const File& volume)
  15879. : AudioFormatReader (0, "CD Audio"),
  15880. volumeDir (volume),
  15881. currentReaderTrack (-1),
  15882. reader (0)
  15883. {
  15884. sampleRate = 44100.0;
  15885. bitsPerSample = 16;
  15886. numChannels = 2;
  15887. usesFloatingPointData = false;
  15888. refreshTrackLengths();
  15889. }
  15890. AudioCDReader::~AudioCDReader()
  15891. {
  15892. }
  15893. static int getTrackNumber (const File& file)
  15894. {
  15895. return file.getFileName()
  15896. .initialSectionContainingOnly (T("0123456789"))
  15897. .getIntValue();
  15898. }
  15899. int AudioCDReader::compareElements (const File& first, const File& second)
  15900. {
  15901. const int firstTrack = getTrackNumber (first);
  15902. const int secondTrack = getTrackNumber (second);
  15903. jassert (firstTrack > 0 && secondTrack > 0);
  15904. return firstTrack - secondTrack;
  15905. }
  15906. void AudioCDReader::refreshTrackLengths()
  15907. {
  15908. tracks.clear();
  15909. trackStartSamples.clear();
  15910. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15911. tracks.sort (*this);
  15912. AiffAudioFormat format;
  15913. int sample = 0;
  15914. for (int i = 0; i < tracks.size(); ++i)
  15915. {
  15916. trackStartSamples.add (sample);
  15917. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15918. if (in != 0)
  15919. {
  15920. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15921. if (r != 0)
  15922. sample += (int) r->lengthInSamples;
  15923. }
  15924. }
  15925. trackStartSamples.add (sample);
  15926. lengthInSamples = sample;
  15927. }
  15928. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15929. int64 startSampleInFile, int numSamples)
  15930. {
  15931. while (numSamples > 0)
  15932. {
  15933. int track = -1;
  15934. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15935. {
  15936. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15937. {
  15938. track = i;
  15939. break;
  15940. }
  15941. }
  15942. if (track < 0)
  15943. return false;
  15944. if (track != currentReaderTrack)
  15945. {
  15946. reader = 0;
  15947. FileInputStream* const in = tracks [track].createInputStream();
  15948. if (in != 0)
  15949. {
  15950. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15951. AiffAudioFormat format;
  15952. reader = format.createReaderFor (bin, true);
  15953. if (reader == 0)
  15954. currentReaderTrack = -1;
  15955. else
  15956. currentReaderTrack = track;
  15957. }
  15958. }
  15959. if (reader == 0)
  15960. return false;
  15961. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15962. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15963. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15964. numSamples -= numAvailable;
  15965. startSampleInFile += numAvailable;
  15966. }
  15967. return true;
  15968. }
  15969. bool AudioCDReader::isCDStillPresent() const
  15970. {
  15971. return volumeDir.exists();
  15972. }
  15973. int AudioCDReader::getNumTracks() const
  15974. {
  15975. return tracks.size();
  15976. }
  15977. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15978. {
  15979. return trackStartSamples [trackNum];
  15980. }
  15981. bool AudioCDReader::isTrackAudio (int trackNum) const
  15982. {
  15983. return tracks [trackNum] != File::nonexistent;
  15984. }
  15985. void AudioCDReader::enableIndexScanning (bool b)
  15986. {
  15987. // any way to do this on a Mac??
  15988. }
  15989. int AudioCDReader::getLastIndex() const
  15990. {
  15991. return 0;
  15992. }
  15993. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15994. {
  15995. return Array <int>();
  15996. }
  15997. int AudioCDReader::getCDDBId()
  15998. {
  15999. return 0; //xxx
  16000. }
  16001. #endif
  16002. END_JUCE_NAMESPACE
  16003. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  16004. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  16005. BEGIN_JUCE_NAMESPACE
  16006. AudioFormatReader::AudioFormatReader (InputStream* const in,
  16007. const String& formatName_)
  16008. : sampleRate (0),
  16009. bitsPerSample (0),
  16010. lengthInSamples (0),
  16011. numChannels (0),
  16012. usesFloatingPointData (false),
  16013. input (in),
  16014. formatName (formatName_)
  16015. {
  16016. }
  16017. AudioFormatReader::~AudioFormatReader()
  16018. {
  16019. delete input;
  16020. }
  16021. bool AudioFormatReader::read (int** destSamples,
  16022. int numDestChannels,
  16023. int64 startSampleInSource,
  16024. int numSamplesToRead,
  16025. const bool fillLeftoverChannelsWithCopies)
  16026. {
  16027. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  16028. int startOffsetInDestBuffer = 0;
  16029. if (startSampleInSource < 0)
  16030. {
  16031. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  16032. for (int i = numDestChannels; --i >= 0;)
  16033. if (destSamples[i] != 0)
  16034. zeromem (destSamples[i], sizeof (int) * silence);
  16035. startOffsetInDestBuffer += silence;
  16036. numSamplesToRead -= silence;
  16037. startSampleInSource = 0;
  16038. }
  16039. if (numSamplesToRead <= 0)
  16040. return true;
  16041. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  16042. startSampleInSource, numSamplesToRead))
  16043. return false;
  16044. if (numDestChannels > (int) numChannels)
  16045. {
  16046. if (fillLeftoverChannelsWithCopies)
  16047. {
  16048. int* lastFullChannel = destSamples[0];
  16049. for (int i = numDestChannels; --i > 0;)
  16050. {
  16051. if (destSamples[i] != 0)
  16052. {
  16053. lastFullChannel = destSamples[i];
  16054. break;
  16055. }
  16056. }
  16057. if (lastFullChannel != 0)
  16058. for (int i = numChannels; i < numDestChannels; ++i)
  16059. if (destSamples[i] != 0)
  16060. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  16061. }
  16062. else
  16063. {
  16064. for (int i = numChannels; i < numDestChannels; ++i)
  16065. if (destSamples[i] != 0)
  16066. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  16067. }
  16068. }
  16069. return true;
  16070. }
  16071. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  16072. {
  16073. float mn = buffer[0];
  16074. float mx = mn;
  16075. for (int i = 1; i < num; ++i)
  16076. {
  16077. const float s = buffer[i];
  16078. if (s > mx) mx = s;
  16079. if (s < mn) mn = s;
  16080. }
  16081. maxVal = mx;
  16082. minVal = mn;
  16083. }
  16084. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  16085. int64 numSamples,
  16086. float& lowestLeft, float& highestLeft,
  16087. float& lowestRight, float& highestRight)
  16088. {
  16089. if (numSamples <= 0)
  16090. {
  16091. lowestLeft = 0;
  16092. lowestRight = 0;
  16093. highestLeft = 0;
  16094. highestRight = 0;
  16095. return;
  16096. }
  16097. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  16098. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16099. int* tempBuffer[3];
  16100. tempBuffer[0] = (int*) tempSpace.getData();
  16101. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16102. tempBuffer[2] = 0;
  16103. if (usesFloatingPointData)
  16104. {
  16105. float lmin = 1.0e6f;
  16106. float lmax = -lmin;
  16107. float rmin = lmin;
  16108. float rmax = lmax;
  16109. while (numSamples > 0)
  16110. {
  16111. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16112. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16113. numSamples -= numToDo;
  16114. startSampleInFile += numToDo;
  16115. float bufmin, bufmax;
  16116. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  16117. lmin = jmin (lmin, bufmin);
  16118. lmax = jmax (lmax, bufmax);
  16119. if (numChannels > 1)
  16120. {
  16121. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  16122. rmin = jmin (rmin, bufmin);
  16123. rmax = jmax (rmax, bufmax);
  16124. }
  16125. }
  16126. if (numChannels <= 1)
  16127. {
  16128. rmax = lmax;
  16129. rmin = lmin;
  16130. }
  16131. lowestLeft = lmin;
  16132. highestLeft = lmax;
  16133. lowestRight = rmin;
  16134. highestRight = rmax;
  16135. }
  16136. else
  16137. {
  16138. int lmax = std::numeric_limits<int>::min();
  16139. int lmin = std::numeric_limits<int>::max();
  16140. int rmax = std::numeric_limits<int>::min();
  16141. int rmin = std::numeric_limits<int>::max();
  16142. while (numSamples > 0)
  16143. {
  16144. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16145. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16146. numSamples -= numToDo;
  16147. startSampleInFile += numToDo;
  16148. for (int j = numChannels; --j >= 0;)
  16149. {
  16150. int bufMax = std::numeric_limits<int>::min();
  16151. int bufMin = std::numeric_limits<int>::max();
  16152. const int* const b = tempBuffer[j];
  16153. for (int i = 0; i < numToDo; ++i)
  16154. {
  16155. const int samp = b[i];
  16156. if (samp < bufMin)
  16157. bufMin = samp;
  16158. if (samp > bufMax)
  16159. bufMax = samp;
  16160. }
  16161. if (j == 0)
  16162. {
  16163. lmax = jmax (lmax, bufMax);
  16164. lmin = jmin (lmin, bufMin);
  16165. }
  16166. else
  16167. {
  16168. rmax = jmax (rmax, bufMax);
  16169. rmin = jmin (rmin, bufMin);
  16170. }
  16171. }
  16172. }
  16173. if (numChannels <= 1)
  16174. {
  16175. rmax = lmax;
  16176. rmin = lmin;
  16177. }
  16178. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  16179. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  16180. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  16181. highestRight = rmax / (float) std::numeric_limits<int>::max();
  16182. }
  16183. }
  16184. int64 AudioFormatReader::searchForLevel (int64 startSample,
  16185. int64 numSamplesToSearch,
  16186. const double magnitudeRangeMinimum,
  16187. const double magnitudeRangeMaximum,
  16188. const int minimumConsecutiveSamples)
  16189. {
  16190. if (numSamplesToSearch == 0)
  16191. return -1;
  16192. const int bufferSize = 4096;
  16193. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16194. int* tempBuffer[3];
  16195. tempBuffer[0] = (int*) tempSpace.getData();
  16196. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16197. tempBuffer[2] = 0;
  16198. int consecutive = 0;
  16199. int64 firstMatchPos = -1;
  16200. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16201. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  16202. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  16203. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16204. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16205. while (numSamplesToSearch != 0)
  16206. {
  16207. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16208. int64 bufferStart = startSample;
  16209. if (numSamplesToSearch < 0)
  16210. bufferStart -= numThisTime;
  16211. if (bufferStart >= (int) lengthInSamples)
  16212. break;
  16213. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16214. int num = numThisTime;
  16215. while (--num >= 0)
  16216. {
  16217. if (numSamplesToSearch < 0)
  16218. --startSample;
  16219. bool matches = false;
  16220. const int index = (int) (startSample - bufferStart);
  16221. if (usesFloatingPointData)
  16222. {
  16223. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16224. if (sample1 >= magnitudeRangeMinimum
  16225. && sample1 <= magnitudeRangeMaximum)
  16226. {
  16227. matches = true;
  16228. }
  16229. else if (numChannels > 1)
  16230. {
  16231. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16232. matches = (sample2 >= magnitudeRangeMinimum
  16233. && sample2 <= magnitudeRangeMaximum);
  16234. }
  16235. }
  16236. else
  16237. {
  16238. const int sample1 = abs (tempBuffer[0] [index]);
  16239. if (sample1 >= intMagnitudeRangeMinimum
  16240. && sample1 <= intMagnitudeRangeMaximum)
  16241. {
  16242. matches = true;
  16243. }
  16244. else if (numChannels > 1)
  16245. {
  16246. const int sample2 = abs (tempBuffer[1][index]);
  16247. matches = (sample2 >= intMagnitudeRangeMinimum
  16248. && sample2 <= intMagnitudeRangeMaximum);
  16249. }
  16250. }
  16251. if (matches)
  16252. {
  16253. if (firstMatchPos < 0)
  16254. firstMatchPos = startSample;
  16255. if (++consecutive >= minimumConsecutiveSamples)
  16256. {
  16257. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16258. return -1;
  16259. return firstMatchPos;
  16260. }
  16261. }
  16262. else
  16263. {
  16264. consecutive = 0;
  16265. firstMatchPos = -1;
  16266. }
  16267. if (numSamplesToSearch > 0)
  16268. ++startSample;
  16269. }
  16270. if (numSamplesToSearch > 0)
  16271. numSamplesToSearch -= numThisTime;
  16272. else
  16273. numSamplesToSearch += numThisTime;
  16274. }
  16275. return -1;
  16276. }
  16277. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16278. const String& formatName_,
  16279. const double rate,
  16280. const unsigned int numChannels_,
  16281. const unsigned int bitsPerSample_)
  16282. : sampleRate (rate),
  16283. numChannels (numChannels_),
  16284. bitsPerSample (bitsPerSample_),
  16285. usesFloatingPointData (false),
  16286. output (out),
  16287. formatName (formatName_)
  16288. {
  16289. }
  16290. AudioFormatWriter::~AudioFormatWriter()
  16291. {
  16292. delete output;
  16293. }
  16294. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16295. int64 startSample,
  16296. int64 numSamplesToRead)
  16297. {
  16298. const int bufferSize = 16384;
  16299. const int maxChans = 128;
  16300. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16301. int* buffers [maxChans];
  16302. for (int i = maxChans; --i >= 0;)
  16303. buffers[i] = 0;
  16304. if (numSamplesToRead < 0)
  16305. numSamplesToRead = reader.lengthInSamples;
  16306. while (numSamplesToRead > 0)
  16307. {
  16308. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16309. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16310. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16311. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16312. return false;
  16313. if (reader.usesFloatingPointData != isFloatingPoint())
  16314. {
  16315. int** bufferChan = buffers;
  16316. while (*bufferChan != 0)
  16317. {
  16318. int* b = *bufferChan++;
  16319. if (isFloatingPoint())
  16320. {
  16321. // int -> float
  16322. const double factor = 1.0 / std::numeric_limits<int>::max();
  16323. for (int i = 0; i < numToDo; ++i)
  16324. ((float*) b)[i] = (float) (factor * b[i]);
  16325. }
  16326. else
  16327. {
  16328. // float -> int
  16329. for (int i = 0; i < numToDo; ++i)
  16330. {
  16331. const double samp = *(const float*) b;
  16332. if (samp <= -1.0)
  16333. *b++ = std::numeric_limits<int>::min();
  16334. else if (samp >= 1.0)
  16335. *b++ = std::numeric_limits<int>::max();
  16336. else
  16337. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16338. }
  16339. }
  16340. }
  16341. }
  16342. if (! write ((const int**) buffers, numToDo))
  16343. return false;
  16344. numSamplesToRead -= numToDo;
  16345. startSample += numToDo;
  16346. }
  16347. return true;
  16348. }
  16349. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16350. int numSamplesToRead,
  16351. const int samplesPerBlock)
  16352. {
  16353. const int maxChans = 128;
  16354. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16355. int* buffers [maxChans];
  16356. while (numSamplesToRead > 0)
  16357. {
  16358. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16359. AudioSourceChannelInfo info;
  16360. info.buffer = &tempBuffer;
  16361. info.startSample = 0;
  16362. info.numSamples = numToDo;
  16363. info.clearActiveBufferRegion();
  16364. source.getNextAudioBlock (info);
  16365. int i;
  16366. for (i = maxChans; --i >= 0;)
  16367. buffers[i] = 0;
  16368. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16369. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16370. if (! isFloatingPoint())
  16371. {
  16372. int** bufferChan = buffers;
  16373. while (*bufferChan != 0)
  16374. {
  16375. int* b = *bufferChan++;
  16376. // float -> int
  16377. for (int j = numToDo; --j >= 0;)
  16378. {
  16379. const double samp = *(const float*) b;
  16380. if (samp <= -1.0)
  16381. *b++ = std::numeric_limits<int>::min();
  16382. else if (samp >= 1.0)
  16383. *b++ = std::numeric_limits<int>::max();
  16384. else
  16385. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16386. }
  16387. }
  16388. }
  16389. if (! write ((const int**) buffers, numToDo))
  16390. return false;
  16391. numSamplesToRead -= numToDo;
  16392. }
  16393. return true;
  16394. }
  16395. AudioFormat::AudioFormat (const String& name,
  16396. const tchar** const extensions)
  16397. : formatName (name),
  16398. fileExtensions (extensions)
  16399. {
  16400. }
  16401. AudioFormat::~AudioFormat()
  16402. {
  16403. }
  16404. const String& AudioFormat::getFormatName() const
  16405. {
  16406. return formatName;
  16407. }
  16408. const StringArray& AudioFormat::getFileExtensions() const
  16409. {
  16410. return fileExtensions;
  16411. }
  16412. bool AudioFormat::canHandleFile (const File& f)
  16413. {
  16414. for (int i = 0; i < fileExtensions.size(); ++i)
  16415. if (f.hasFileExtension (fileExtensions[i]))
  16416. return true;
  16417. return false;
  16418. }
  16419. bool AudioFormat::isCompressed()
  16420. {
  16421. return false;
  16422. }
  16423. const StringArray AudioFormat::getQualityOptions()
  16424. {
  16425. return StringArray();
  16426. }
  16427. END_JUCE_NAMESPACE
  16428. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16429. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16430. BEGIN_JUCE_NAMESPACE
  16431. AudioFormatManager::AudioFormatManager()
  16432. : defaultFormatIndex (0)
  16433. {
  16434. }
  16435. AudioFormatManager::~AudioFormatManager()
  16436. {
  16437. clearFormats();
  16438. clearSingletonInstance();
  16439. }
  16440. juce_ImplementSingleton (AudioFormatManager);
  16441. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16442. const bool makeThisTheDefaultFormat)
  16443. {
  16444. jassert (newFormat != 0);
  16445. if (newFormat != 0)
  16446. {
  16447. #ifdef JUCE_DEBUG
  16448. for (int i = getNumKnownFormats(); --i >= 0;)
  16449. {
  16450. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16451. {
  16452. jassertfalse // trying to add the same format twice!
  16453. }
  16454. }
  16455. #endif
  16456. if (makeThisTheDefaultFormat)
  16457. defaultFormatIndex = knownFormats.size();
  16458. knownFormats.add (newFormat);
  16459. }
  16460. }
  16461. void AudioFormatManager::registerBasicFormats()
  16462. {
  16463. #if JUCE_MAC
  16464. registerFormat (new AiffAudioFormat(), true);
  16465. registerFormat (new WavAudioFormat(), false);
  16466. #else
  16467. registerFormat (new WavAudioFormat(), true);
  16468. registerFormat (new AiffAudioFormat(), false);
  16469. #endif
  16470. #if JUCE_USE_FLAC
  16471. registerFormat (new FlacAudioFormat(), false);
  16472. #endif
  16473. #if JUCE_USE_OGGVORBIS
  16474. registerFormat (new OggVorbisAudioFormat(), false);
  16475. #endif
  16476. }
  16477. void AudioFormatManager::clearFormats()
  16478. {
  16479. for (int i = getNumKnownFormats(); --i >= 0;)
  16480. delete getKnownFormat(i);
  16481. knownFormats.clear();
  16482. defaultFormatIndex = 0;
  16483. }
  16484. int AudioFormatManager::getNumKnownFormats() const
  16485. {
  16486. return knownFormats.size();
  16487. }
  16488. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16489. {
  16490. return (AudioFormat*) knownFormats [index];
  16491. }
  16492. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16493. {
  16494. return getKnownFormat (defaultFormatIndex);
  16495. }
  16496. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16497. {
  16498. String e (fileExtension);
  16499. if (! e.startsWithChar (T('.')))
  16500. e = T(".") + e;
  16501. for (int i = 0; i < getNumKnownFormats(); ++i)
  16502. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16503. return getKnownFormat(i);
  16504. return 0;
  16505. }
  16506. const String AudioFormatManager::getWildcardForAllFormats() const
  16507. {
  16508. StringArray allExtensions;
  16509. int i;
  16510. for (i = 0; i < getNumKnownFormats(); ++i)
  16511. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16512. allExtensions.trim();
  16513. allExtensions.removeEmptyStrings();
  16514. String s;
  16515. for (i = 0; i < allExtensions.size(); ++i)
  16516. {
  16517. s << T('*');
  16518. if (! allExtensions[i].startsWithChar (T('.')))
  16519. s << T('.');
  16520. s << allExtensions[i];
  16521. if (i < allExtensions.size() - 1)
  16522. s << T(';');
  16523. }
  16524. return s;
  16525. }
  16526. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16527. {
  16528. // you need to actually register some formats before the manager can
  16529. // use them to open a file!
  16530. jassert (knownFormats.size() > 0);
  16531. for (int i = 0; i < getNumKnownFormats(); ++i)
  16532. {
  16533. AudioFormat* const af = getKnownFormat(i);
  16534. if (af->canHandleFile (file))
  16535. {
  16536. InputStream* const in = file.createInputStream();
  16537. if (in != 0)
  16538. {
  16539. AudioFormatReader* const r = af->createReaderFor (in, true);
  16540. if (r != 0)
  16541. return r;
  16542. }
  16543. }
  16544. }
  16545. return 0;
  16546. }
  16547. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16548. {
  16549. // you need to actually register some formats before the manager can
  16550. // use them to open a file!
  16551. jassert (knownFormats.size() > 0);
  16552. ScopedPointer <InputStream> in (audioFileStream);
  16553. if (in != 0)
  16554. {
  16555. const int64 originalStreamPos = in->getPosition();
  16556. for (int i = 0; i < getNumKnownFormats(); ++i)
  16557. {
  16558. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16559. if (r != 0)
  16560. {
  16561. in.release();
  16562. return r;
  16563. }
  16564. in->setPosition (originalStreamPos);
  16565. // the stream that is passed-in must be capable of being repositioned so
  16566. // that all the formats can have a go at opening it.
  16567. jassert (in->getPosition() == originalStreamPos);
  16568. }
  16569. }
  16570. return 0;
  16571. }
  16572. END_JUCE_NAMESPACE
  16573. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16574. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16575. BEGIN_JUCE_NAMESPACE
  16576. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16577. const int64 startSample_,
  16578. const int64 length_,
  16579. const bool deleteSourceWhenDeleted_)
  16580. : AudioFormatReader (0, source_->getFormatName()),
  16581. source (source_),
  16582. startSample (startSample_),
  16583. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16584. {
  16585. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16586. sampleRate = source->sampleRate;
  16587. bitsPerSample = source->bitsPerSample;
  16588. lengthInSamples = length;
  16589. numChannels = source->numChannels;
  16590. usesFloatingPointData = source->usesFloatingPointData;
  16591. }
  16592. AudioSubsectionReader::~AudioSubsectionReader()
  16593. {
  16594. if (deleteSourceWhenDeleted)
  16595. delete source;
  16596. }
  16597. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16598. int64 startSampleInFile, int numSamples)
  16599. {
  16600. if (startSampleInFile + numSamples > length)
  16601. {
  16602. for (int i = numDestChannels; --i >= 0;)
  16603. if (destSamples[i] != 0)
  16604. zeromem (destSamples[i], sizeof (int) * numSamples);
  16605. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16606. if (numSamples <= 0)
  16607. return true;
  16608. }
  16609. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16610. startSampleInFile + startSample, numSamples);
  16611. }
  16612. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16613. int64 numSamples,
  16614. float& lowestLeft,
  16615. float& highestLeft,
  16616. float& lowestRight,
  16617. float& highestRight)
  16618. {
  16619. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16620. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16621. source->readMaxLevels (startSampleInFile + startSample,
  16622. numSamples,
  16623. lowestLeft,
  16624. highestLeft,
  16625. lowestRight,
  16626. highestRight);
  16627. }
  16628. END_JUCE_NAMESPACE
  16629. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16630. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16631. BEGIN_JUCE_NAMESPACE
  16632. const int timeBeforeDeletingReader = 2000;
  16633. struct AudioThumbnailDataFormat
  16634. {
  16635. char thumbnailMagic[4];
  16636. int samplesPerThumbSample;
  16637. int64 totalSamples; // source samples
  16638. int64 numFinishedSamples; // source samples
  16639. int numThumbnailSamples;
  16640. int numChannels;
  16641. int sampleRate;
  16642. char future[16];
  16643. char data[1];
  16644. void swapEndiannessIfNeeded() throw()
  16645. {
  16646. #if JUCE_BIG_ENDIAN
  16647. flip (samplesPerThumbSample);
  16648. flip (totalSamples);
  16649. flip (numFinishedSamples);
  16650. flip (numThumbnailSamples);
  16651. flip (numChannels);
  16652. flip (sampleRate);
  16653. #endif
  16654. }
  16655. private:
  16656. #if JUCE_BIG_ENDIAN
  16657. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16658. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16659. #endif
  16660. };
  16661. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16662. AudioFormatManager& formatManagerToUse_,
  16663. AudioThumbnailCache& cacheToUse)
  16664. : formatManagerToUse (formatManagerToUse_),
  16665. cache (cacheToUse),
  16666. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16667. {
  16668. clear();
  16669. }
  16670. AudioThumbnail::~AudioThumbnail()
  16671. {
  16672. cache.removeThumbnail (this);
  16673. const ScopedLock sl (readerLock);
  16674. reader = 0;
  16675. }
  16676. void AudioThumbnail::setSource (InputSource* const newSource)
  16677. {
  16678. cache.removeThumbnail (this);
  16679. timerCallback(); // stops the timer and deletes the reader
  16680. source = newSource;
  16681. clear();
  16682. if (newSource != 0
  16683. && ! (cache.loadThumb (*this, newSource->hashCode())
  16684. && isFullyLoaded()))
  16685. {
  16686. {
  16687. const ScopedLock sl (readerLock);
  16688. reader = createReader();
  16689. }
  16690. if (reader != 0)
  16691. {
  16692. initialiseFromAudioFile (*reader);
  16693. cache.addThumbnail (this);
  16694. }
  16695. }
  16696. sendChangeMessage (this);
  16697. }
  16698. bool AudioThumbnail::useTimeSlice()
  16699. {
  16700. const ScopedLock sl (readerLock);
  16701. if (isFullyLoaded())
  16702. {
  16703. if (reader != 0)
  16704. startTimer (timeBeforeDeletingReader);
  16705. cache.removeThumbnail (this);
  16706. return false;
  16707. }
  16708. if (reader == 0)
  16709. reader = createReader();
  16710. if (reader != 0)
  16711. {
  16712. readNextBlockFromAudioFile (*reader);
  16713. stopTimer();
  16714. sendChangeMessage (this);
  16715. const bool justFinished = isFullyLoaded();
  16716. if (justFinished)
  16717. cache.storeThumb (*this, source->hashCode());
  16718. return ! justFinished;
  16719. }
  16720. return false;
  16721. }
  16722. AudioFormatReader* AudioThumbnail::createReader() const
  16723. {
  16724. if (source != 0)
  16725. {
  16726. InputStream* const audioFileStream = source->createInputStream();
  16727. if (audioFileStream != 0)
  16728. return formatManagerToUse.createReaderFor (audioFileStream);
  16729. }
  16730. return 0;
  16731. }
  16732. void AudioThumbnail::timerCallback()
  16733. {
  16734. stopTimer();
  16735. const ScopedLock sl (readerLock);
  16736. reader = 0;
  16737. }
  16738. void AudioThumbnail::clear()
  16739. {
  16740. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16741. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16742. d->thumbnailMagic[0] = 'j';
  16743. d->thumbnailMagic[1] = 'a';
  16744. d->thumbnailMagic[2] = 't';
  16745. d->thumbnailMagic[3] = 'm';
  16746. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16747. d->totalSamples = 0;
  16748. d->numFinishedSamples = 0;
  16749. d->numThumbnailSamples = 0;
  16750. d->numChannels = 0;
  16751. d->sampleRate = 0;
  16752. numSamplesCached = 0;
  16753. cacheNeedsRefilling = true;
  16754. }
  16755. void AudioThumbnail::loadFrom (InputStream& input)
  16756. {
  16757. const ScopedLock sl (readerLock);
  16758. data.setSize (0);
  16759. input.readIntoMemoryBlock (data);
  16760. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16761. d->swapEndiannessIfNeeded();
  16762. if (! (d->thumbnailMagic[0] == 'j'
  16763. && d->thumbnailMagic[1] == 'a'
  16764. && d->thumbnailMagic[2] == 't'
  16765. && d->thumbnailMagic[3] == 'm'))
  16766. {
  16767. clear();
  16768. }
  16769. numSamplesCached = 0;
  16770. cacheNeedsRefilling = true;
  16771. }
  16772. void AudioThumbnail::saveTo (OutputStream& output) const
  16773. {
  16774. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16775. d->swapEndiannessIfNeeded();
  16776. output.write (data.getData(), (int) data.getSize());
  16777. d->swapEndiannessIfNeeded();
  16778. }
  16779. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16780. {
  16781. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16782. d->totalSamples = fileReader.lengthInSamples;
  16783. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16784. d->numFinishedSamples = 0;
  16785. d->sampleRate = roundToInt (fileReader.sampleRate);
  16786. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16787. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16788. d = (AudioThumbnailDataFormat*) data.getData();
  16789. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16790. return d->totalSamples > 0;
  16791. }
  16792. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16793. {
  16794. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16795. if (d->numFinishedSamples < d->totalSamples)
  16796. {
  16797. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16798. generateSection (fileReader,
  16799. d->numFinishedSamples,
  16800. numToDo);
  16801. d->numFinishedSamples += numToDo;
  16802. }
  16803. cacheNeedsRefilling = true;
  16804. return (d->numFinishedSamples < d->totalSamples);
  16805. }
  16806. int AudioThumbnail::getNumChannels() const throw()
  16807. {
  16808. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16809. jassert (d != 0);
  16810. return d->numChannels;
  16811. }
  16812. double AudioThumbnail::getTotalLength() const throw()
  16813. {
  16814. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16815. jassert (d != 0);
  16816. if (d->sampleRate > 0)
  16817. return d->totalSamples / (double)d->sampleRate;
  16818. else
  16819. return 0.0;
  16820. }
  16821. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16822. int64 startSample,
  16823. int numSamples)
  16824. {
  16825. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16826. jassert (d != 0);
  16827. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16828. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16829. char* l = getChannelData (0);
  16830. char* r = getChannelData (1);
  16831. for (int i = firstDataPos; i < lastDataPos; ++i)
  16832. {
  16833. const int sourceStart = i * d->samplesPerThumbSample;
  16834. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16835. float lowestLeft, highestLeft, lowestRight, highestRight;
  16836. fileReader.readMaxLevels (sourceStart,
  16837. sourceEnd - sourceStart,
  16838. lowestLeft,
  16839. highestLeft,
  16840. lowestRight,
  16841. highestRight);
  16842. int n = i * 2;
  16843. if (r != 0)
  16844. {
  16845. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16846. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16847. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16848. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16849. }
  16850. else
  16851. {
  16852. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16853. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16854. }
  16855. }
  16856. }
  16857. char* AudioThumbnail::getChannelData (int channel) const
  16858. {
  16859. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16860. jassert (d != 0);
  16861. if (channel >= 0 && channel < d->numChannels)
  16862. return d->data + (channel * 2 * d->numThumbnailSamples);
  16863. return 0;
  16864. }
  16865. bool AudioThumbnail::isFullyLoaded() const throw()
  16866. {
  16867. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16868. jassert (d != 0);
  16869. return d->numFinishedSamples >= d->totalSamples;
  16870. }
  16871. void AudioThumbnail::refillCache (const int numSamples,
  16872. double startTime,
  16873. const double timePerPixel)
  16874. {
  16875. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16876. jassert (d != 0);
  16877. if (numSamples <= 0
  16878. || timePerPixel <= 0.0
  16879. || d->sampleRate <= 0)
  16880. {
  16881. numSamplesCached = 0;
  16882. cacheNeedsRefilling = true;
  16883. return;
  16884. }
  16885. if (numSamples == numSamplesCached
  16886. && numChannelsCached == d->numChannels
  16887. && startTime == cachedStart
  16888. && timePerPixel == cachedTimePerPixel
  16889. && ! cacheNeedsRefilling)
  16890. {
  16891. return;
  16892. }
  16893. numSamplesCached = numSamples;
  16894. numChannelsCached = d->numChannels;
  16895. cachedStart = startTime;
  16896. cachedTimePerPixel = timePerPixel;
  16897. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16898. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16899. const ScopedLock sl (readerLock);
  16900. cacheNeedsRefilling = false;
  16901. if (needExtraDetail && reader == 0)
  16902. reader = createReader();
  16903. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16904. {
  16905. startTimer (timeBeforeDeletingReader);
  16906. char* cacheData = (char*) cachedLevels.getData();
  16907. int sample = roundToInt (startTime * d->sampleRate);
  16908. for (int i = numSamples; --i >= 0;)
  16909. {
  16910. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16911. if (sample >= 0)
  16912. {
  16913. if (sample >= reader->lengthInSamples)
  16914. break;
  16915. float lmin, lmax, rmin, rmax;
  16916. reader->readMaxLevels (sample,
  16917. jmax (1, nextSample - sample),
  16918. lmin, lmax, rmin, rmax);
  16919. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16920. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16921. if (numChannelsCached > 1)
  16922. {
  16923. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16924. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16925. }
  16926. cacheData += 2 * numChannelsCached;
  16927. }
  16928. startTime += timePerPixel;
  16929. sample = nextSample;
  16930. }
  16931. }
  16932. else
  16933. {
  16934. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16935. {
  16936. char* const channelData = getChannelData (channelNum);
  16937. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  16938. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16939. startTime = cachedStart;
  16940. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16941. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16942. for (int i = numSamples; --i >= 0;)
  16943. {
  16944. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16945. if (sample >= 0 && channelData != 0)
  16946. {
  16947. char mx = -128;
  16948. char mn = 127;
  16949. while (sample <= nextSample)
  16950. {
  16951. if (sample >= numFinished)
  16952. break;
  16953. const int n = sample << 1;
  16954. const char sampMin = channelData [n];
  16955. const char sampMax = channelData [n + 1];
  16956. if (sampMin < mn)
  16957. mn = sampMin;
  16958. if (sampMax > mx)
  16959. mx = sampMax;
  16960. ++sample;
  16961. }
  16962. if (mn <= mx)
  16963. {
  16964. cacheData[0] = mn;
  16965. cacheData[1] = mx;
  16966. }
  16967. else
  16968. {
  16969. cacheData[0] = 1;
  16970. cacheData[1] = 0;
  16971. }
  16972. }
  16973. else
  16974. {
  16975. cacheData[0] = 1;
  16976. cacheData[1] = 0;
  16977. }
  16978. cacheData += numChannelsCached * 2;
  16979. startTime += timePerPixel;
  16980. sample = nextSample;
  16981. }
  16982. }
  16983. }
  16984. }
  16985. void AudioThumbnail::drawChannel (Graphics& g,
  16986. int x, int y, int w, int h,
  16987. double startTime,
  16988. double endTime,
  16989. int channelNum,
  16990. const float verticalZoomFactor)
  16991. {
  16992. refillCache (w, startTime, (endTime - startTime) / w);
  16993. if (numSamplesCached >= w
  16994. && channelNum >= 0
  16995. && channelNum < numChannelsCached)
  16996. {
  16997. const float topY = (float) y;
  16998. const float bottomY = topY + h;
  16999. const float midY = topY + h * 0.5f;
  17000. const float vscale = verticalZoomFactor * h / 256.0f;
  17001. const Rectangle<int> clip (g.getClipBounds());
  17002. const int skipLeft = jlimit (0, w, clip.getX() - x);
  17003. w -= skipLeft;
  17004. x += skipLeft;
  17005. const char* cacheData = ((const char*) cachedLevels.getData())
  17006. + (channelNum << 1)
  17007. + skipLeft * (numChannelsCached << 1);
  17008. while (--w >= 0)
  17009. {
  17010. const char mn = cacheData[0];
  17011. const char mx = cacheData[1];
  17012. cacheData += numChannelsCached << 1;
  17013. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  17014. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  17015. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  17016. ++x;
  17017. if (x >= clip.getRight())
  17018. break;
  17019. }
  17020. }
  17021. }
  17022. END_JUCE_NAMESPACE
  17023. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  17024. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  17025. BEGIN_JUCE_NAMESPACE
  17026. struct ThumbnailCacheEntry
  17027. {
  17028. int64 hash;
  17029. uint32 lastUsed;
  17030. MemoryBlock data;
  17031. juce_UseDebuggingNewOperator
  17032. };
  17033. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  17034. : TimeSliceThread (T("thumb cache")),
  17035. maxNumThumbsToStore (maxNumThumbsToStore_)
  17036. {
  17037. startThread (2);
  17038. }
  17039. AudioThumbnailCache::~AudioThumbnailCache()
  17040. {
  17041. }
  17042. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  17043. {
  17044. for (int i = thumbs.size(); --i >= 0;)
  17045. {
  17046. if (thumbs[i]->hash == hashCode)
  17047. {
  17048. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  17049. thumbs[i]->data.getSize(),
  17050. false);
  17051. thumb.loadFrom (in);
  17052. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  17053. return true;
  17054. }
  17055. }
  17056. return false;
  17057. }
  17058. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  17059. const int64 hashCode)
  17060. {
  17061. MemoryOutputStream out;
  17062. thumb.saveTo (out);
  17063. ThumbnailCacheEntry* te = 0;
  17064. for (int i = thumbs.size(); --i >= 0;)
  17065. {
  17066. if (thumbs[i]->hash == hashCode)
  17067. {
  17068. te = thumbs[i];
  17069. break;
  17070. }
  17071. }
  17072. if (te == 0)
  17073. {
  17074. te = new ThumbnailCacheEntry();
  17075. te->hash = hashCode;
  17076. if (thumbs.size() < maxNumThumbsToStore)
  17077. {
  17078. thumbs.add (te);
  17079. }
  17080. else
  17081. {
  17082. int oldest = 0;
  17083. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  17084. int i;
  17085. for (i = thumbs.size(); --i >= 0;)
  17086. if (thumbs[i]->lastUsed < oldestTime)
  17087. oldest = i;
  17088. thumbs.set (i, te);
  17089. }
  17090. }
  17091. te->lastUsed = Time::getMillisecondCounter();
  17092. te->data.setSize (0);
  17093. te->data.append (out.getData(), out.getDataSize());
  17094. }
  17095. void AudioThumbnailCache::clear()
  17096. {
  17097. thumbs.clear();
  17098. }
  17099. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  17100. {
  17101. addTimeSliceClient (thumb);
  17102. }
  17103. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  17104. {
  17105. removeTimeSliceClient (thumb);
  17106. }
  17107. END_JUCE_NAMESPACE
  17108. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  17109. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17110. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  17111. #if ! JUCE_WINDOWS
  17112. #include <QuickTime/Movies.h>
  17113. #include <QuickTime/QTML.h>
  17114. #include <QuickTime/QuickTimeComponents.h>
  17115. #include <QuickTime/MediaHandlers.h>
  17116. #include <QuickTime/ImageCodec.h>
  17117. #else
  17118. #if JUCE_MSVC
  17119. #pragma warning (push)
  17120. #pragma warning (disable : 4100)
  17121. #endif
  17122. #include <Movies.h>
  17123. #include <QTML.h>
  17124. #include <QuickTimeComponents.h>
  17125. #include <MediaHandlers.h>
  17126. #include <ImageCodec.h>
  17127. #if JUCE_MSVC
  17128. #pragma warning (pop)
  17129. #endif
  17130. #endif
  17131. BEGIN_JUCE_NAMESPACE
  17132. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  17133. static const char* const quickTimeFormatName = "QuickTime file";
  17134. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  17135. class QTAudioReader : public AudioFormatReader
  17136. {
  17137. public:
  17138. QTAudioReader (InputStream* const input_, const int trackNum_)
  17139. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  17140. ok (false),
  17141. movie (0),
  17142. trackNum (trackNum_),
  17143. lastSampleRead (0),
  17144. lastThreadId (0),
  17145. extractor (0),
  17146. dataHandle (0)
  17147. {
  17148. bufferList.calloc (256, 1);
  17149. #ifdef WIN32
  17150. if (InitializeQTML (0) != noErr)
  17151. return;
  17152. #endif
  17153. if (EnterMovies() != noErr)
  17154. return;
  17155. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  17156. if (! opened)
  17157. return;
  17158. {
  17159. const int numTracks = GetMovieTrackCount (movie);
  17160. int trackCount = 0;
  17161. for (int i = 1; i <= numTracks; ++i)
  17162. {
  17163. track = GetMovieIndTrack (movie, i);
  17164. media = GetTrackMedia (track);
  17165. OSType mediaType;
  17166. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  17167. if (mediaType == SoundMediaType
  17168. && trackCount++ == trackNum_)
  17169. {
  17170. ok = true;
  17171. break;
  17172. }
  17173. }
  17174. }
  17175. if (! ok)
  17176. return;
  17177. ok = false;
  17178. lengthInSamples = GetMediaDecodeDuration (media);
  17179. usesFloatingPointData = false;
  17180. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  17181. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  17182. / GetMediaTimeScale (media);
  17183. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  17184. unsigned long output_layout_size;
  17185. err = MovieAudioExtractionGetPropertyInfo (extractor,
  17186. kQTPropertyClass_MovieAudioExtraction_Audio,
  17187. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17188. 0, &output_layout_size, 0);
  17189. if (err != noErr)
  17190. return;
  17191. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17192. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17193. err = MovieAudioExtractionGetProperty (extractor,
  17194. kQTPropertyClass_MovieAudioExtraction_Audio,
  17195. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17196. output_layout_size, qt_audio_channel_layout, 0);
  17197. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17198. err = MovieAudioExtractionSetProperty (extractor,
  17199. kQTPropertyClass_MovieAudioExtraction_Audio,
  17200. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17201. output_layout_size,
  17202. qt_audio_channel_layout);
  17203. err = MovieAudioExtractionGetProperty (extractor,
  17204. kQTPropertyClass_MovieAudioExtraction_Audio,
  17205. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17206. sizeof (inputStreamDesc),
  17207. &inputStreamDesc, 0);
  17208. if (err != noErr)
  17209. return;
  17210. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17211. | kAudioFormatFlagIsPacked
  17212. | kAudioFormatFlagsNativeEndian;
  17213. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17214. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17215. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17216. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17217. err = MovieAudioExtractionSetProperty (extractor,
  17218. kQTPropertyClass_MovieAudioExtraction_Audio,
  17219. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17220. sizeof (inputStreamDesc),
  17221. &inputStreamDesc);
  17222. if (err != noErr)
  17223. return;
  17224. Boolean allChannelsDiscrete = false;
  17225. err = MovieAudioExtractionSetProperty (extractor,
  17226. kQTPropertyClass_MovieAudioExtraction_Movie,
  17227. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17228. sizeof (allChannelsDiscrete),
  17229. &allChannelsDiscrete);
  17230. if (err != noErr)
  17231. return;
  17232. bufferList->mNumberBuffers = 1;
  17233. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17234. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17235. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17236. sampleRate = inputStreamDesc.mSampleRate;
  17237. bitsPerSample = 16;
  17238. numChannels = inputStreamDesc.mChannelsPerFrame;
  17239. detachThread();
  17240. ok = true;
  17241. }
  17242. ~QTAudioReader()
  17243. {
  17244. if (dataHandle != 0)
  17245. DisposeHandle (dataHandle);
  17246. if (extractor != 0)
  17247. {
  17248. MovieAudioExtractionEnd (extractor);
  17249. extractor = 0;
  17250. }
  17251. checkThreadIsAttached();
  17252. DisposeMovie (movie);
  17253. juce_free (bufferList->mBuffers[0].mData);
  17254. #if JUCE_MAC
  17255. ExitMoviesOnThread ();
  17256. #endif
  17257. }
  17258. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17259. int64 startSampleInFile, int numSamples)
  17260. {
  17261. checkThreadIsAttached();
  17262. while (numSamples > 0)
  17263. {
  17264. if (! loadFrame ((int) startSampleInFile))
  17265. return false;
  17266. const int numToDo = jmin (numSamples, samplesPerFrame);
  17267. for (int j = numDestChannels; --j >= 0;)
  17268. {
  17269. if (destSamples[j] != 0)
  17270. {
  17271. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17272. for (int i = 0; i < numToDo; ++i)
  17273. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17274. }
  17275. }
  17276. startOffsetInDestBuffer += numToDo;
  17277. startSampleInFile += numToDo;
  17278. numSamples -= numToDo;
  17279. }
  17280. detachThread();
  17281. return true;
  17282. }
  17283. bool loadFrame (const int sampleNum)
  17284. {
  17285. if (lastSampleRead != sampleNum)
  17286. {
  17287. TimeRecord time;
  17288. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17289. time.base = 0;
  17290. time.value.hi = 0;
  17291. time.value.lo = (UInt32) sampleNum;
  17292. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17293. kQTPropertyClass_MovieAudioExtraction_Movie,
  17294. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17295. sizeof (time), &time);
  17296. if (err != noErr)
  17297. return false;
  17298. }
  17299. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17300. UInt32 outFlags = 0;
  17301. UInt32 actualNumSamples = samplesPerFrame;
  17302. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17303. bufferList, &outFlags);
  17304. lastSampleRead = sampleNum + samplesPerFrame;
  17305. return err == noErr;
  17306. }
  17307. juce_UseDebuggingNewOperator
  17308. bool ok;
  17309. private:
  17310. Movie movie;
  17311. Media media;
  17312. Track track;
  17313. const int trackNum;
  17314. double trackUnitsPerFrame;
  17315. int samplesPerFrame;
  17316. int lastSampleRead;
  17317. Thread::ThreadID lastThreadId;
  17318. MovieAudioExtractionRef extractor;
  17319. AudioStreamBasicDescription inputStreamDesc;
  17320. HeapBlock <AudioBufferList> bufferList;
  17321. Handle dataHandle;
  17322. void checkThreadIsAttached()
  17323. {
  17324. #if JUCE_MAC
  17325. if (Thread::getCurrentThreadId() != lastThreadId)
  17326. EnterMoviesOnThread (0);
  17327. AttachMovieToCurrentThread (movie);
  17328. #endif
  17329. }
  17330. void detachThread()
  17331. {
  17332. #if JUCE_MAC
  17333. DetachMovieFromCurrentThread (movie);
  17334. #endif
  17335. }
  17336. };
  17337. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17338. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17339. {
  17340. }
  17341. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17342. {
  17343. }
  17344. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17345. {
  17346. return Array<int>();
  17347. }
  17348. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17349. {
  17350. return Array<int>();
  17351. }
  17352. bool QuickTimeAudioFormat::canDoStereo()
  17353. {
  17354. return true;
  17355. }
  17356. bool QuickTimeAudioFormat::canDoMono()
  17357. {
  17358. return true;
  17359. }
  17360. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17361. const bool deleteStreamIfOpeningFails)
  17362. {
  17363. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17364. if (r->ok)
  17365. return r.release();
  17366. if (! deleteStreamIfOpeningFails)
  17367. r->input = 0;
  17368. return 0;
  17369. }
  17370. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17371. double /*sampleRateToUse*/,
  17372. unsigned int /*numberOfChannels*/,
  17373. int /*bitsPerSample*/,
  17374. const StringPairArray& /*metadataValues*/,
  17375. int /*qualityOptionIndex*/)
  17376. {
  17377. jassertfalse // not yet implemented!
  17378. return 0;
  17379. }
  17380. END_JUCE_NAMESPACE
  17381. #endif
  17382. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17383. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17384. BEGIN_JUCE_NAMESPACE
  17385. static const char* const wavFormatName = "WAV file";
  17386. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17387. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17388. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17389. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17390. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17391. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17392. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17393. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17394. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17395. const String& originator,
  17396. const String& originatorRef,
  17397. const Time& date,
  17398. const int64 timeReferenceSamples,
  17399. const String& codingHistory)
  17400. {
  17401. StringPairArray m;
  17402. m.set (bwavDescription, description);
  17403. m.set (bwavOriginator, originator);
  17404. m.set (bwavOriginatorRef, originatorRef);
  17405. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17406. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17407. m.set (bwavTimeReference, String (timeReferenceSamples));
  17408. m.set (bwavCodingHistory, codingHistory);
  17409. return m;
  17410. }
  17411. #if JUCE_MSVC
  17412. #pragma pack (push, 1)
  17413. #define PACKED
  17414. #elif JUCE_GCC
  17415. #define PACKED __attribute__((packed))
  17416. #else
  17417. #define PACKED
  17418. #endif
  17419. struct BWAVChunk
  17420. {
  17421. char description [256];
  17422. char originator [32];
  17423. char originatorRef [32];
  17424. char originationDate [10];
  17425. char originationTime [8];
  17426. uint32 timeRefLow;
  17427. uint32 timeRefHigh;
  17428. uint16 version;
  17429. uint8 umid[64];
  17430. uint8 reserved[190];
  17431. char codingHistory[1];
  17432. void copyTo (StringPairArray& values) const
  17433. {
  17434. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17435. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17436. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17437. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17438. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17439. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17440. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17441. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17442. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17443. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17444. }
  17445. static MemoryBlock createFrom (const StringPairArray& values)
  17446. {
  17447. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17448. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17449. data.fillWith (0);
  17450. BWAVChunk* b = (BWAVChunk*) data.getData();
  17451. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17452. // as they get called in the right order..
  17453. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17454. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17455. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17456. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17457. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17458. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17459. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17460. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17461. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17462. if (b->description[0] != 0
  17463. || b->originator[0] != 0
  17464. || b->originationDate[0] != 0
  17465. || b->originationTime[0] != 0
  17466. || b->codingHistory[0] != 0
  17467. || time != 0)
  17468. {
  17469. return data;
  17470. }
  17471. return MemoryBlock();
  17472. }
  17473. } PACKED;
  17474. struct SMPLChunk
  17475. {
  17476. struct SampleLoop
  17477. {
  17478. uint32 identifier;
  17479. uint32 type;
  17480. uint32 start;
  17481. uint32 end;
  17482. uint32 fraction;
  17483. uint32 playCount;
  17484. } PACKED;
  17485. uint32 manufacturer;
  17486. uint32 product;
  17487. uint32 samplePeriod;
  17488. uint32 midiUnityNote;
  17489. uint32 midiPitchFraction;
  17490. uint32 smpteFormat;
  17491. uint32 smpteOffset;
  17492. uint32 numSampleLoops;
  17493. uint32 samplerData;
  17494. SampleLoop loops[1];
  17495. void copyTo (StringPairArray& values, const int totalSize) const
  17496. {
  17497. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17498. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17499. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17500. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17501. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17502. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17503. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17504. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17505. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17506. for (uint32 i = 0; i < numSampleLoops; ++i)
  17507. {
  17508. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17509. break;
  17510. const String prefix ("Loop" + String(i));
  17511. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17512. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17513. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17514. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17515. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17516. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17517. }
  17518. }
  17519. static MemoryBlock createFrom (const StringPairArray& values)
  17520. {
  17521. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17522. if (numLoops <= 0)
  17523. return MemoryBlock();
  17524. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17525. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17526. data.fillWith (0);
  17527. SMPLChunk* s = (SMPLChunk*) data.getData();
  17528. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17529. // as they get called in the right order..
  17530. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17531. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17532. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17533. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17534. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17535. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17536. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17537. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17538. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17539. for (int i = 0; i < numLoops; ++i)
  17540. {
  17541. const String prefix ("Loop" + String(i));
  17542. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17543. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17544. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17545. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17546. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17547. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17548. }
  17549. return data;
  17550. }
  17551. } PACKED;
  17552. struct ExtensibleWavSubFormat
  17553. {
  17554. uint32 data1;
  17555. uint16 data2;
  17556. uint16 data3;
  17557. uint8 data4[8];
  17558. } PACKED;
  17559. #if JUCE_MSVC
  17560. #pragma pack (pop)
  17561. #endif
  17562. #undef PACKED
  17563. class WavAudioFormatReader : public AudioFormatReader
  17564. {
  17565. int bytesPerFrame;
  17566. int64 dataChunkStart, dataLength;
  17567. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17568. WavAudioFormatReader (const WavAudioFormatReader&);
  17569. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17570. public:
  17571. int64 bwavChunkStart, bwavSize;
  17572. WavAudioFormatReader (InputStream* const in)
  17573. : AudioFormatReader (in, TRANS (wavFormatName)),
  17574. dataLength (0),
  17575. bwavChunkStart (0),
  17576. bwavSize (0)
  17577. {
  17578. if (input->readInt() == chunkName ("RIFF"))
  17579. {
  17580. const uint32 len = (uint32) input->readInt();
  17581. const int64 end = input->getPosition() + len;
  17582. bool hasGotType = false;
  17583. bool hasGotData = false;
  17584. if (input->readInt() == chunkName ("WAVE"))
  17585. {
  17586. while (input->getPosition() < end
  17587. && ! input->isExhausted())
  17588. {
  17589. const int chunkType = input->readInt();
  17590. uint32 length = (uint32) input->readInt();
  17591. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17592. if (chunkType == chunkName ("fmt "))
  17593. {
  17594. // read the format chunk
  17595. const unsigned short format = input->readShort();
  17596. const short numChans = input->readShort();
  17597. sampleRate = input->readInt();
  17598. const int bytesPerSec = input->readInt();
  17599. numChannels = numChans;
  17600. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17601. bitsPerSample = 8 * bytesPerFrame / numChans;
  17602. if (format == 3)
  17603. {
  17604. usesFloatingPointData = true;
  17605. }
  17606. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17607. {
  17608. if (length < 40) // too short
  17609. {
  17610. bytesPerFrame = 0;
  17611. }
  17612. else
  17613. {
  17614. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17615. ExtensibleWavSubFormat subFormat;
  17616. subFormat.data1 = input->readInt();
  17617. subFormat.data2 = input->readShort();
  17618. subFormat.data3 = input->readShort();
  17619. input->read (subFormat.data4, sizeof (subFormat.data4));
  17620. const ExtensibleWavSubFormat pcmFormat
  17621. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17622. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17623. {
  17624. const ExtensibleWavSubFormat ambisonicFormat
  17625. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17626. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17627. bytesPerFrame = 0;
  17628. }
  17629. }
  17630. }
  17631. else if (format != 1)
  17632. {
  17633. bytesPerFrame = 0;
  17634. }
  17635. hasGotType = true;
  17636. }
  17637. else if (chunkType == chunkName ("data"))
  17638. {
  17639. // get the data chunk's position
  17640. dataLength = length;
  17641. dataChunkStart = input->getPosition();
  17642. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17643. hasGotData = true;
  17644. }
  17645. else if (chunkType == chunkName ("bext"))
  17646. {
  17647. bwavChunkStart = input->getPosition();
  17648. bwavSize = length;
  17649. // Broadcast-wav extension chunk..
  17650. HeapBlock <BWAVChunk> bwav;
  17651. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17652. input->read (bwav, length);
  17653. bwav->copyTo (metadataValues);
  17654. }
  17655. else if (chunkType == chunkName ("smpl"))
  17656. {
  17657. HeapBlock <SMPLChunk> smpl;
  17658. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17659. input->read (smpl, length);
  17660. smpl->copyTo (metadataValues, length);
  17661. }
  17662. else if (chunkEnd <= input->getPosition())
  17663. {
  17664. break;
  17665. }
  17666. input->setPosition (chunkEnd);
  17667. }
  17668. }
  17669. }
  17670. }
  17671. ~WavAudioFormatReader()
  17672. {
  17673. }
  17674. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17675. int64 startSampleInFile, int numSamples)
  17676. {
  17677. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17678. if (samplesAvailable < numSamples)
  17679. {
  17680. for (int i = numDestChannels; --i >= 0;)
  17681. if (destSamples[i] != 0)
  17682. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17683. numSamples = (int) samplesAvailable;
  17684. }
  17685. if (numSamples <= 0)
  17686. return true;
  17687. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17688. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17689. char tempBuffer [tempBufSize];
  17690. while (numSamples > 0)
  17691. {
  17692. int* left = destSamples[0];
  17693. if (left != 0)
  17694. left += startOffsetInDestBuffer;
  17695. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17696. if (right != 0)
  17697. right += startOffsetInDestBuffer;
  17698. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17699. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17700. if (bytesRead < numThisTime * bytesPerFrame)
  17701. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17702. if (bitsPerSample == 16)
  17703. {
  17704. const short* src = (const short*) tempBuffer;
  17705. if (numChannels > 1)
  17706. {
  17707. if (left == 0)
  17708. {
  17709. for (int i = numThisTime; --i >= 0;)
  17710. {
  17711. ++src;
  17712. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17713. }
  17714. }
  17715. else if (right == 0)
  17716. {
  17717. for (int i = numThisTime; --i >= 0;)
  17718. {
  17719. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17720. ++src;
  17721. }
  17722. }
  17723. else
  17724. {
  17725. for (int i = numThisTime; --i >= 0;)
  17726. {
  17727. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17728. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17729. }
  17730. }
  17731. }
  17732. else
  17733. {
  17734. for (int i = numThisTime; --i >= 0;)
  17735. {
  17736. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17737. }
  17738. }
  17739. }
  17740. else if (bitsPerSample == 24)
  17741. {
  17742. const char* src = (const char*) tempBuffer;
  17743. if (numChannels > 1)
  17744. {
  17745. if (left == 0)
  17746. {
  17747. for (int i = numThisTime; --i >= 0;)
  17748. {
  17749. src += 3;
  17750. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17751. src += 3;
  17752. }
  17753. }
  17754. else if (right == 0)
  17755. {
  17756. for (int i = numThisTime; --i >= 0;)
  17757. {
  17758. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17759. src += 6;
  17760. }
  17761. }
  17762. else
  17763. {
  17764. for (int i = 0; i < numThisTime; ++i)
  17765. {
  17766. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17767. src += 3;
  17768. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17769. src += 3;
  17770. }
  17771. }
  17772. }
  17773. else
  17774. {
  17775. for (int i = 0; i < numThisTime; ++i)
  17776. {
  17777. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17778. src += 3;
  17779. }
  17780. }
  17781. }
  17782. else if (bitsPerSample == 32)
  17783. {
  17784. const unsigned int* src = (const unsigned int*) tempBuffer;
  17785. unsigned int* l = (unsigned int*) left;
  17786. unsigned int* r = (unsigned int*) right;
  17787. if (numChannels > 1)
  17788. {
  17789. if (l == 0)
  17790. {
  17791. for (int i = numThisTime; --i >= 0;)
  17792. {
  17793. ++src;
  17794. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17795. }
  17796. }
  17797. else if (r == 0)
  17798. {
  17799. for (int i = numThisTime; --i >= 0;)
  17800. {
  17801. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17802. ++src;
  17803. }
  17804. }
  17805. else
  17806. {
  17807. for (int i = numThisTime; --i >= 0;)
  17808. {
  17809. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17810. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17811. }
  17812. }
  17813. }
  17814. else
  17815. {
  17816. for (int i = numThisTime; --i >= 0;)
  17817. {
  17818. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17819. }
  17820. }
  17821. left = (int*)l;
  17822. right = (int*)r;
  17823. }
  17824. else if (bitsPerSample == 8)
  17825. {
  17826. const unsigned char* src = (const unsigned char*) tempBuffer;
  17827. if (numChannels > 1)
  17828. {
  17829. if (left == 0)
  17830. {
  17831. for (int i = numThisTime; --i >= 0;)
  17832. {
  17833. ++src;
  17834. *right++ = ((int) *src++ - 128) << 24;
  17835. }
  17836. }
  17837. else if (right == 0)
  17838. {
  17839. for (int i = numThisTime; --i >= 0;)
  17840. {
  17841. *left++ = ((int) *src++ - 128) << 24;
  17842. ++src;
  17843. }
  17844. }
  17845. else
  17846. {
  17847. for (int i = numThisTime; --i >= 0;)
  17848. {
  17849. *left++ = ((int) *src++ - 128) << 24;
  17850. *right++ = ((int) *src++ - 128) << 24;
  17851. }
  17852. }
  17853. }
  17854. else
  17855. {
  17856. for (int i = numThisTime; --i >= 0;)
  17857. {
  17858. *left++ = ((int)*src++ - 128) << 24;
  17859. }
  17860. }
  17861. }
  17862. startOffsetInDestBuffer += numThisTime;
  17863. numSamples -= numThisTime;
  17864. }
  17865. if (numSamples > 0)
  17866. {
  17867. for (int i = numDestChannels; --i >= 0;)
  17868. if (destSamples[i] != 0)
  17869. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17870. sizeof (int) * numSamples);
  17871. }
  17872. return true;
  17873. }
  17874. juce_UseDebuggingNewOperator
  17875. };
  17876. class WavAudioFormatWriter : public AudioFormatWriter
  17877. {
  17878. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17879. uint32 lengthInSamples, bytesWritten;
  17880. int64 headerPosition;
  17881. bool writeFailed;
  17882. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17883. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17884. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17885. void writeHeader()
  17886. {
  17887. const bool seekedOk = output->setPosition (headerPosition);
  17888. (void) seekedOk;
  17889. // if this fails, you've given it an output stream that can't seek! It needs
  17890. // to be able to seek back to write the header
  17891. jassert (seekedOk);
  17892. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17893. output->writeInt (chunkName ("RIFF"));
  17894. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17895. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17896. output->writeInt (chunkName ("WAVE"));
  17897. output->writeInt (chunkName ("fmt "));
  17898. output->writeInt (16);
  17899. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17900. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17901. output->writeShort ((short) numChannels);
  17902. output->writeInt ((int) sampleRate);
  17903. output->writeInt (bytesPerFrame * (int) sampleRate);
  17904. output->writeShort ((short) bytesPerFrame);
  17905. output->writeShort ((short) bitsPerSample);
  17906. if (bwavChunk.getSize() > 0)
  17907. {
  17908. output->writeInt (chunkName ("bext"));
  17909. output->writeInt ((int) bwavChunk.getSize());
  17910. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17911. }
  17912. if (smplChunk.getSize() > 0)
  17913. {
  17914. output->writeInt (chunkName ("smpl"));
  17915. output->writeInt ((int) smplChunk.getSize());
  17916. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17917. }
  17918. output->writeInt (chunkName ("data"));
  17919. output->writeInt (lengthInSamples * bytesPerFrame);
  17920. usesFloatingPointData = (bitsPerSample == 32);
  17921. }
  17922. public:
  17923. WavAudioFormatWriter (OutputStream* const out,
  17924. const double sampleRate_,
  17925. const unsigned int numChannels_,
  17926. const int bits,
  17927. const StringPairArray& metadataValues)
  17928. : AudioFormatWriter (out,
  17929. TRANS (wavFormatName),
  17930. sampleRate_,
  17931. numChannels_,
  17932. bits),
  17933. lengthInSamples (0),
  17934. bytesWritten (0),
  17935. writeFailed (false)
  17936. {
  17937. if (metadataValues.size() > 0)
  17938. {
  17939. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17940. smplChunk = SMPLChunk::createFrom (metadataValues);
  17941. }
  17942. headerPosition = out->getPosition();
  17943. writeHeader();
  17944. }
  17945. ~WavAudioFormatWriter()
  17946. {
  17947. writeHeader();
  17948. }
  17949. bool write (const int** data, int numSamples)
  17950. {
  17951. if (writeFailed)
  17952. return false;
  17953. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17954. tempBlock.ensureSize (bytes, false);
  17955. char* buffer = (char*) tempBlock.getData();
  17956. const int* left = data[0];
  17957. const int* right = data[1];
  17958. if (right == 0)
  17959. right = left;
  17960. if (bitsPerSample == 16)
  17961. {
  17962. short* b = (short*) buffer;
  17963. if (numChannels > 1)
  17964. {
  17965. for (int i = numSamples; --i >= 0;)
  17966. {
  17967. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17968. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17969. }
  17970. }
  17971. else
  17972. {
  17973. for (int i = numSamples; --i >= 0;)
  17974. {
  17975. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17976. }
  17977. }
  17978. }
  17979. else if (bitsPerSample == 24)
  17980. {
  17981. char* b = (char*) buffer;
  17982. if (numChannels > 1)
  17983. {
  17984. for (int i = numSamples; --i >= 0;)
  17985. {
  17986. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17987. b += 3;
  17988. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17989. b += 3;
  17990. }
  17991. }
  17992. else
  17993. {
  17994. for (int i = numSamples; --i >= 0;)
  17995. {
  17996. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17997. b += 3;
  17998. }
  17999. }
  18000. }
  18001. else if (bitsPerSample == 32)
  18002. {
  18003. unsigned int* b = (unsigned int*) buffer;
  18004. if (numChannels > 1)
  18005. {
  18006. for (int i = numSamples; --i >= 0;)
  18007. {
  18008. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18009. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  18010. }
  18011. }
  18012. else
  18013. {
  18014. for (int i = numSamples; --i >= 0;)
  18015. {
  18016. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18017. }
  18018. }
  18019. }
  18020. else if (bitsPerSample == 8)
  18021. {
  18022. unsigned char* b = (unsigned char*) buffer;
  18023. if (numChannels > 1)
  18024. {
  18025. for (int i = numSamples; --i >= 0;)
  18026. {
  18027. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18028. *b++ = (unsigned char) (128 + (*right++ >> 24));
  18029. }
  18030. }
  18031. else
  18032. {
  18033. for (int i = numSamples; --i >= 0;)
  18034. {
  18035. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18036. }
  18037. }
  18038. }
  18039. if (bytesWritten + bytes >= (uint32) 0xfff00000
  18040. || ! output->write (buffer, bytes))
  18041. {
  18042. // failed to write to disk, so let's try writing the header.
  18043. // If it's just run out of disk space, then if it does manage
  18044. // to write the header, we'll still have a useable file..
  18045. writeHeader();
  18046. writeFailed = true;
  18047. return false;
  18048. }
  18049. else
  18050. {
  18051. bytesWritten += bytes;
  18052. lengthInSamples += numSamples;
  18053. return true;
  18054. }
  18055. }
  18056. juce_UseDebuggingNewOperator
  18057. };
  18058. WavAudioFormat::WavAudioFormat()
  18059. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  18060. {
  18061. }
  18062. WavAudioFormat::~WavAudioFormat()
  18063. {
  18064. }
  18065. const Array <int> WavAudioFormat::getPossibleSampleRates()
  18066. {
  18067. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  18068. return Array <int> (rates);
  18069. }
  18070. const Array <int> WavAudioFormat::getPossibleBitDepths()
  18071. {
  18072. const int depths[] = { 8, 16, 24, 32, 0 };
  18073. return Array <int> (depths);
  18074. }
  18075. bool WavAudioFormat::canDoStereo()
  18076. {
  18077. return true;
  18078. }
  18079. bool WavAudioFormat::canDoMono()
  18080. {
  18081. return true;
  18082. }
  18083. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  18084. const bool deleteStreamIfOpeningFails)
  18085. {
  18086. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  18087. if (r->sampleRate != 0)
  18088. return r.release();
  18089. if (! deleteStreamIfOpeningFails)
  18090. r->input = 0;
  18091. return 0;
  18092. }
  18093. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  18094. double sampleRate,
  18095. unsigned int numChannels,
  18096. int bitsPerSample,
  18097. const StringPairArray& metadataValues,
  18098. int /*qualityOptionIndex*/)
  18099. {
  18100. if (getPossibleBitDepths().contains (bitsPerSample))
  18101. {
  18102. return new WavAudioFormatWriter (out,
  18103. sampleRate,
  18104. numChannels,
  18105. bitsPerSample,
  18106. metadataValues);
  18107. }
  18108. return 0;
  18109. }
  18110. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18111. {
  18112. TemporaryFile tempFile (file);
  18113. WavAudioFormat wav;
  18114. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18115. if (reader != 0)
  18116. {
  18117. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18118. if (outStream != 0)
  18119. {
  18120. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18121. reader->numChannels, reader->bitsPerSample,
  18122. metadata, 0));
  18123. if (writer != 0)
  18124. {
  18125. outStream.release();
  18126. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18127. writer = 0;
  18128. reader = 0;
  18129. return ok && tempFile.overwriteTargetFileWithTemporary();
  18130. }
  18131. }
  18132. }
  18133. return false;
  18134. }
  18135. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18136. {
  18137. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18138. if (reader != 0)
  18139. {
  18140. const int64 bwavPos = reader->bwavChunkStart;
  18141. const int64 bwavSize = reader->bwavSize;
  18142. reader = 0;
  18143. if (bwavSize > 0)
  18144. {
  18145. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18146. if (chunk.getSize() <= (size_t) bwavSize)
  18147. {
  18148. // the new one will fit in the space available, so write it directly..
  18149. const int64 oldSize = wavFile.getSize();
  18150. {
  18151. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18152. out->setPosition (bwavPos);
  18153. out->write (chunk.getData(), (int) chunk.getSize());
  18154. out->setPosition (oldSize);
  18155. }
  18156. jassert (wavFile.getSize() == oldSize);
  18157. return true;
  18158. }
  18159. }
  18160. }
  18161. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18162. }
  18163. END_JUCE_NAMESPACE
  18164. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  18165. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18166. BEGIN_JUCE_NAMESPACE
  18167. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18168. const bool deleteReaderWhenThisIsDeleted)
  18169. : reader (reader_),
  18170. deleteReader (deleteReaderWhenThisIsDeleted),
  18171. nextPlayPos (0),
  18172. looping (false)
  18173. {
  18174. jassert (reader != 0);
  18175. }
  18176. AudioFormatReaderSource::~AudioFormatReaderSource()
  18177. {
  18178. releaseResources();
  18179. if (deleteReader)
  18180. delete reader;
  18181. }
  18182. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18183. {
  18184. nextPlayPos = newPosition;
  18185. }
  18186. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18187. {
  18188. looping = shouldLoop;
  18189. }
  18190. int AudioFormatReaderSource::getNextReadPosition() const
  18191. {
  18192. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18193. : nextPlayPos;
  18194. }
  18195. int AudioFormatReaderSource::getTotalLength() const
  18196. {
  18197. return (int) reader->lengthInSamples;
  18198. }
  18199. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18200. double /*sampleRate*/)
  18201. {
  18202. }
  18203. void AudioFormatReaderSource::releaseResources()
  18204. {
  18205. }
  18206. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18207. {
  18208. if (info.numSamples > 0)
  18209. {
  18210. const int start = nextPlayPos;
  18211. if (looping)
  18212. {
  18213. const int newStart = start % (int) reader->lengthInSamples;
  18214. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18215. if (newEnd > newStart)
  18216. {
  18217. info.buffer->readFromAudioReader (reader,
  18218. info.startSample,
  18219. newEnd - newStart,
  18220. newStart,
  18221. true, true);
  18222. }
  18223. else
  18224. {
  18225. const int endSamps = (int) reader->lengthInSamples - newStart;
  18226. info.buffer->readFromAudioReader (reader,
  18227. info.startSample,
  18228. endSamps,
  18229. newStart,
  18230. true, true);
  18231. info.buffer->readFromAudioReader (reader,
  18232. info.startSample + endSamps,
  18233. newEnd,
  18234. 0,
  18235. true, true);
  18236. }
  18237. nextPlayPos = newEnd;
  18238. }
  18239. else
  18240. {
  18241. info.buffer->readFromAudioReader (reader,
  18242. info.startSample,
  18243. info.numSamples,
  18244. start,
  18245. true, true);
  18246. nextPlayPos += info.numSamples;
  18247. }
  18248. }
  18249. }
  18250. END_JUCE_NAMESPACE
  18251. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18252. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18253. BEGIN_JUCE_NAMESPACE
  18254. AudioSourcePlayer::AudioSourcePlayer()
  18255. : source (0),
  18256. sampleRate (0),
  18257. bufferSize (0),
  18258. tempBuffer (2, 8),
  18259. lastGain (1.0f),
  18260. gain (1.0f)
  18261. {
  18262. }
  18263. AudioSourcePlayer::~AudioSourcePlayer()
  18264. {
  18265. setSource (0);
  18266. }
  18267. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18268. {
  18269. if (source != newSource)
  18270. {
  18271. AudioSource* const oldSource = source;
  18272. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18273. newSource->prepareToPlay (bufferSize, sampleRate);
  18274. {
  18275. const ScopedLock sl (readLock);
  18276. source = newSource;
  18277. }
  18278. if (oldSource != 0)
  18279. oldSource->releaseResources();
  18280. }
  18281. }
  18282. void AudioSourcePlayer::setGain (const float newGain) throw()
  18283. {
  18284. gain = newGain;
  18285. }
  18286. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18287. int totalNumInputChannels,
  18288. float** outputChannelData,
  18289. int totalNumOutputChannels,
  18290. int numSamples)
  18291. {
  18292. // these should have been prepared by audioDeviceAboutToStart()...
  18293. jassert (sampleRate > 0 && bufferSize > 0);
  18294. const ScopedLock sl (readLock);
  18295. if (source != 0)
  18296. {
  18297. AudioSourceChannelInfo info;
  18298. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18299. // messy stuff needed to compact the channels down into an array
  18300. // of non-zero pointers..
  18301. for (i = 0; i < totalNumInputChannels; ++i)
  18302. {
  18303. if (inputChannelData[i] != 0)
  18304. {
  18305. inputChans [numInputs++] = inputChannelData[i];
  18306. if (numInputs >= numElementsInArray (inputChans))
  18307. break;
  18308. }
  18309. }
  18310. for (i = 0; i < totalNumOutputChannels; ++i)
  18311. {
  18312. if (outputChannelData[i] != 0)
  18313. {
  18314. outputChans [numOutputs++] = outputChannelData[i];
  18315. if (numOutputs >= numElementsInArray (outputChans))
  18316. break;
  18317. }
  18318. }
  18319. if (numInputs > numOutputs)
  18320. {
  18321. // if there aren't enough output channels for the number of
  18322. // inputs, we need to create some temporary extra ones (can't
  18323. // use the input data in case it gets written to)
  18324. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18325. false, false, true);
  18326. for (i = 0; i < numOutputs; ++i)
  18327. {
  18328. channels[numActiveChans] = outputChans[i];
  18329. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18330. ++numActiveChans;
  18331. }
  18332. for (i = numOutputs; i < numInputs; ++i)
  18333. {
  18334. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18335. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18336. ++numActiveChans;
  18337. }
  18338. }
  18339. else
  18340. {
  18341. for (i = 0; i < numInputs; ++i)
  18342. {
  18343. channels[numActiveChans] = outputChans[i];
  18344. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18345. ++numActiveChans;
  18346. }
  18347. for (i = numInputs; i < numOutputs; ++i)
  18348. {
  18349. channels[numActiveChans] = outputChans[i];
  18350. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18351. ++numActiveChans;
  18352. }
  18353. }
  18354. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18355. info.buffer = &buffer;
  18356. info.startSample = 0;
  18357. info.numSamples = numSamples;
  18358. source->getNextAudioBlock (info);
  18359. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18360. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18361. lastGain = gain;
  18362. }
  18363. else
  18364. {
  18365. for (int i = 0; i < totalNumOutputChannels; ++i)
  18366. if (outputChannelData[i] != 0)
  18367. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18368. }
  18369. }
  18370. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18371. {
  18372. sampleRate = device->getCurrentSampleRate();
  18373. bufferSize = device->getCurrentBufferSizeSamples();
  18374. zeromem (channels, sizeof (channels));
  18375. if (source != 0)
  18376. source->prepareToPlay (bufferSize, sampleRate);
  18377. }
  18378. void AudioSourcePlayer::audioDeviceStopped()
  18379. {
  18380. if (source != 0)
  18381. source->releaseResources();
  18382. sampleRate = 0.0;
  18383. bufferSize = 0;
  18384. tempBuffer.setSize (2, 8);
  18385. }
  18386. END_JUCE_NAMESPACE
  18387. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18388. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18389. BEGIN_JUCE_NAMESPACE
  18390. AudioTransportSource::AudioTransportSource()
  18391. : source (0),
  18392. resamplerSource (0),
  18393. bufferingSource (0),
  18394. positionableSource (0),
  18395. masterSource (0),
  18396. gain (1.0f),
  18397. lastGain (1.0f),
  18398. playing (false),
  18399. stopped (true),
  18400. sampleRate (44100.0),
  18401. sourceSampleRate (0.0),
  18402. blockSize (128),
  18403. readAheadBufferSize (0),
  18404. isPrepared (false),
  18405. inputStreamEOF (false)
  18406. {
  18407. }
  18408. AudioTransportSource::~AudioTransportSource()
  18409. {
  18410. setSource (0);
  18411. releaseResources();
  18412. }
  18413. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18414. int readAheadBufferSize_,
  18415. double sourceSampleRateToCorrectFor)
  18416. {
  18417. if (source == newSource)
  18418. {
  18419. if (source == 0)
  18420. return;
  18421. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18422. }
  18423. readAheadBufferSize = readAheadBufferSize_;
  18424. sourceSampleRate = sourceSampleRateToCorrectFor;
  18425. ResamplingAudioSource* newResamplerSource = 0;
  18426. BufferingAudioSource* newBufferingSource = 0;
  18427. PositionableAudioSource* newPositionableSource = 0;
  18428. AudioSource* newMasterSource = 0;
  18429. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18430. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18431. AudioSource* oldMasterSource = masterSource;
  18432. if (newSource != 0)
  18433. {
  18434. newPositionableSource = newSource;
  18435. if (readAheadBufferSize_ > 0)
  18436. newPositionableSource = newBufferingSource
  18437. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18438. newPositionableSource->setNextReadPosition (0);
  18439. if (sourceSampleRateToCorrectFor != 0)
  18440. newMasterSource = newResamplerSource
  18441. = new ResamplingAudioSource (newPositionableSource, false);
  18442. else
  18443. newMasterSource = newPositionableSource;
  18444. if (isPrepared)
  18445. {
  18446. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18447. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18448. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18449. }
  18450. }
  18451. {
  18452. const ScopedLock sl (callbackLock);
  18453. source = newSource;
  18454. resamplerSource = newResamplerSource;
  18455. bufferingSource = newBufferingSource;
  18456. masterSource = newMasterSource;
  18457. positionableSource = newPositionableSource;
  18458. playing = false;
  18459. }
  18460. if (oldMasterSource != 0)
  18461. oldMasterSource->releaseResources();
  18462. }
  18463. void AudioTransportSource::start()
  18464. {
  18465. if ((! playing) && masterSource != 0)
  18466. {
  18467. {
  18468. const ScopedLock sl (callbackLock);
  18469. playing = true;
  18470. stopped = false;
  18471. inputStreamEOF = false;
  18472. }
  18473. sendChangeMessage (this);
  18474. }
  18475. }
  18476. void AudioTransportSource::stop()
  18477. {
  18478. if (playing)
  18479. {
  18480. {
  18481. const ScopedLock sl (callbackLock);
  18482. playing = false;
  18483. }
  18484. int n = 500;
  18485. while (--n >= 0 && ! stopped)
  18486. Thread::sleep (2);
  18487. sendChangeMessage (this);
  18488. }
  18489. }
  18490. void AudioTransportSource::setPosition (double newPosition)
  18491. {
  18492. if (sampleRate > 0.0)
  18493. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18494. }
  18495. double AudioTransportSource::getCurrentPosition() const
  18496. {
  18497. if (sampleRate > 0.0)
  18498. return getNextReadPosition() / sampleRate;
  18499. else
  18500. return 0.0;
  18501. }
  18502. void AudioTransportSource::setNextReadPosition (int newPosition)
  18503. {
  18504. if (positionableSource != 0)
  18505. {
  18506. if (sampleRate > 0 && sourceSampleRate > 0)
  18507. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18508. positionableSource->setNextReadPosition (newPosition);
  18509. }
  18510. }
  18511. int AudioTransportSource::getNextReadPosition() const
  18512. {
  18513. if (positionableSource != 0)
  18514. {
  18515. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18516. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18517. }
  18518. return 0;
  18519. }
  18520. int AudioTransportSource::getTotalLength() const
  18521. {
  18522. const ScopedLock sl (callbackLock);
  18523. if (positionableSource != 0)
  18524. {
  18525. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18526. return roundToInt (positionableSource->getTotalLength() * ratio);
  18527. }
  18528. return 0;
  18529. }
  18530. bool AudioTransportSource::isLooping() const
  18531. {
  18532. const ScopedLock sl (callbackLock);
  18533. return positionableSource != 0
  18534. && positionableSource->isLooping();
  18535. }
  18536. void AudioTransportSource::setGain (const float newGain) throw()
  18537. {
  18538. gain = newGain;
  18539. }
  18540. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18541. double sampleRate_)
  18542. {
  18543. const ScopedLock sl (callbackLock);
  18544. sampleRate = sampleRate_;
  18545. blockSize = samplesPerBlockExpected;
  18546. if (masterSource != 0)
  18547. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18548. if (resamplerSource != 0 && sourceSampleRate != 0)
  18549. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18550. isPrepared = true;
  18551. }
  18552. void AudioTransportSource::releaseResources()
  18553. {
  18554. const ScopedLock sl (callbackLock);
  18555. if (masterSource != 0)
  18556. masterSource->releaseResources();
  18557. isPrepared = false;
  18558. }
  18559. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18560. {
  18561. const ScopedLock sl (callbackLock);
  18562. inputStreamEOF = false;
  18563. if (masterSource != 0 && ! stopped)
  18564. {
  18565. masterSource->getNextAudioBlock (info);
  18566. if (! playing)
  18567. {
  18568. // just stopped playing, so fade out the last block..
  18569. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18570. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18571. if (info.numSamples > 256)
  18572. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18573. }
  18574. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18575. && ! positionableSource->isLooping())
  18576. {
  18577. playing = false;
  18578. inputStreamEOF = true;
  18579. sendChangeMessage (this);
  18580. }
  18581. stopped = ! playing;
  18582. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18583. {
  18584. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18585. lastGain, gain);
  18586. }
  18587. }
  18588. else
  18589. {
  18590. info.clearActiveBufferRegion();
  18591. stopped = true;
  18592. }
  18593. lastGain = gain;
  18594. }
  18595. END_JUCE_NAMESPACE
  18596. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18597. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18598. BEGIN_JUCE_NAMESPACE
  18599. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18600. public Thread,
  18601. private Timer
  18602. {
  18603. public:
  18604. SharedBufferingAudioSourceThread()
  18605. : Thread ("Audio Buffer")
  18606. {
  18607. }
  18608. ~SharedBufferingAudioSourceThread()
  18609. {
  18610. stopThread (10000);
  18611. clearSingletonInstance();
  18612. }
  18613. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18614. void addSource (BufferingAudioSource* source)
  18615. {
  18616. const ScopedLock sl (lock);
  18617. if (! sources.contains ((void*) source))
  18618. {
  18619. sources.add ((void*) source);
  18620. startThread();
  18621. stopTimer();
  18622. }
  18623. notify();
  18624. }
  18625. void removeSource (BufferingAudioSource* source)
  18626. {
  18627. const ScopedLock sl (lock);
  18628. sources.removeValue ((void*) source);
  18629. if (sources.size() == 0)
  18630. startTimer (5000);
  18631. }
  18632. private:
  18633. VoidArray sources;
  18634. CriticalSection lock;
  18635. void run()
  18636. {
  18637. while (! threadShouldExit())
  18638. {
  18639. bool busy = false;
  18640. for (int i = sources.size(); --i >= 0;)
  18641. {
  18642. if (threadShouldExit())
  18643. return;
  18644. const ScopedLock sl (lock);
  18645. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18646. if (b != 0 && b->readNextBufferChunk())
  18647. busy = true;
  18648. }
  18649. if (! busy)
  18650. wait (500);
  18651. }
  18652. }
  18653. void timerCallback()
  18654. {
  18655. stopTimer();
  18656. if (sources.size() == 0)
  18657. deleteInstance();
  18658. }
  18659. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18660. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18661. };
  18662. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18663. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18664. const bool deleteSourceWhenDeleted_,
  18665. int numberOfSamplesToBuffer_)
  18666. : source (source_),
  18667. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18668. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18669. buffer (2, 0),
  18670. bufferValidStart (0),
  18671. bufferValidEnd (0),
  18672. nextPlayPos (0),
  18673. wasSourceLooping (false)
  18674. {
  18675. jassert (source_ != 0);
  18676. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18677. // not using a larger buffer..
  18678. }
  18679. BufferingAudioSource::~BufferingAudioSource()
  18680. {
  18681. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18682. if (thread != 0)
  18683. thread->removeSource (this);
  18684. if (deleteSourceWhenDeleted)
  18685. delete source;
  18686. }
  18687. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18688. {
  18689. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18690. sampleRate = sampleRate_;
  18691. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18692. buffer.clear();
  18693. bufferValidStart = 0;
  18694. bufferValidEnd = 0;
  18695. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18696. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18697. buffer.getNumSamples() / 2))
  18698. {
  18699. SharedBufferingAudioSourceThread::getInstance()->notify();
  18700. Thread::sleep (5);
  18701. }
  18702. }
  18703. void BufferingAudioSource::releaseResources()
  18704. {
  18705. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18706. if (thread != 0)
  18707. thread->removeSource (this);
  18708. buffer.setSize (2, 0);
  18709. source->releaseResources();
  18710. }
  18711. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18712. {
  18713. const ScopedLock sl (bufferStartPosLock);
  18714. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18715. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18716. if (validStart == validEnd)
  18717. {
  18718. // total cache miss
  18719. info.clearActiveBufferRegion();
  18720. }
  18721. else
  18722. {
  18723. if (validStart > 0)
  18724. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18725. if (validEnd < info.numSamples)
  18726. info.buffer->clear (info.startSample + validEnd,
  18727. info.numSamples - validEnd); // partial cache miss at end
  18728. if (validStart < validEnd)
  18729. {
  18730. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18731. {
  18732. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18733. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18734. if (startBufferIndex < endBufferIndex)
  18735. {
  18736. info.buffer->copyFrom (chan, info.startSample + validStart,
  18737. buffer,
  18738. chan, startBufferIndex,
  18739. validEnd - validStart);
  18740. }
  18741. else
  18742. {
  18743. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18744. info.buffer->copyFrom (chan, info.startSample + validStart,
  18745. buffer,
  18746. chan, startBufferIndex,
  18747. initialSize);
  18748. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18749. buffer,
  18750. chan, 0,
  18751. (validEnd - validStart) - initialSize);
  18752. }
  18753. }
  18754. }
  18755. nextPlayPos += info.numSamples;
  18756. if (source->isLooping() && nextPlayPos > 0)
  18757. nextPlayPos %= source->getTotalLength();
  18758. }
  18759. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18760. if (thread != 0)
  18761. thread->notify();
  18762. }
  18763. int BufferingAudioSource::getNextReadPosition() const
  18764. {
  18765. return (source->isLooping() && nextPlayPos > 0)
  18766. ? nextPlayPos % source->getTotalLength()
  18767. : nextPlayPos;
  18768. }
  18769. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18770. {
  18771. const ScopedLock sl (bufferStartPosLock);
  18772. nextPlayPos = newPosition;
  18773. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18774. if (thread != 0)
  18775. thread->notify();
  18776. }
  18777. bool BufferingAudioSource::readNextBufferChunk()
  18778. {
  18779. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18780. {
  18781. const ScopedLock sl (bufferStartPosLock);
  18782. if (wasSourceLooping != isLooping())
  18783. {
  18784. wasSourceLooping = isLooping();
  18785. bufferValidStart = 0;
  18786. bufferValidEnd = 0;
  18787. }
  18788. newBVS = jmax (0, nextPlayPos);
  18789. newBVE = newBVS + buffer.getNumSamples() - 4;
  18790. sectionToReadStart = 0;
  18791. sectionToReadEnd = 0;
  18792. const int maxChunkSize = 2048;
  18793. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18794. {
  18795. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18796. sectionToReadStart = newBVS;
  18797. sectionToReadEnd = newBVE;
  18798. bufferValidStart = 0;
  18799. bufferValidEnd = 0;
  18800. }
  18801. else if (abs (newBVS - bufferValidStart) > 512
  18802. || abs (newBVE - bufferValidEnd) > 512)
  18803. {
  18804. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18805. sectionToReadStart = bufferValidEnd;
  18806. sectionToReadEnd = newBVE;
  18807. bufferValidStart = newBVS;
  18808. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18809. }
  18810. }
  18811. if (sectionToReadStart != sectionToReadEnd)
  18812. {
  18813. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18814. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18815. if (bufferIndexStart < bufferIndexEnd)
  18816. {
  18817. readBufferSection (sectionToReadStart,
  18818. sectionToReadEnd - sectionToReadStart,
  18819. bufferIndexStart);
  18820. }
  18821. else
  18822. {
  18823. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18824. readBufferSection (sectionToReadStart,
  18825. initialSize,
  18826. bufferIndexStart);
  18827. readBufferSection (sectionToReadStart + initialSize,
  18828. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18829. 0);
  18830. }
  18831. const ScopedLock sl2 (bufferStartPosLock);
  18832. bufferValidStart = newBVS;
  18833. bufferValidEnd = newBVE;
  18834. return true;
  18835. }
  18836. else
  18837. {
  18838. return false;
  18839. }
  18840. }
  18841. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18842. {
  18843. if (source->getNextReadPosition() != start)
  18844. source->setNextReadPosition (start);
  18845. AudioSourceChannelInfo info;
  18846. info.buffer = &buffer;
  18847. info.startSample = bufferOffset;
  18848. info.numSamples = length;
  18849. source->getNextAudioBlock (info);
  18850. }
  18851. END_JUCE_NAMESPACE
  18852. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18853. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18854. BEGIN_JUCE_NAMESPACE
  18855. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18856. const bool deleteSourceWhenDeleted_)
  18857. : requiredNumberOfChannels (2),
  18858. source (source_),
  18859. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18860. buffer (2, 16)
  18861. {
  18862. remappedInfo.buffer = &buffer;
  18863. remappedInfo.startSample = 0;
  18864. }
  18865. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18866. {
  18867. if (deleteSourceWhenDeleted)
  18868. delete source;
  18869. }
  18870. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18871. {
  18872. const ScopedLock sl (lock);
  18873. requiredNumberOfChannels = requiredNumberOfChannels_;
  18874. }
  18875. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18876. {
  18877. const ScopedLock sl (lock);
  18878. remappedInputs.clear();
  18879. remappedOutputs.clear();
  18880. }
  18881. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18882. {
  18883. const ScopedLock sl (lock);
  18884. while (remappedInputs.size() < destIndex)
  18885. remappedInputs.add (-1);
  18886. remappedInputs.set (destIndex, sourceIndex);
  18887. }
  18888. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18889. {
  18890. const ScopedLock sl (lock);
  18891. while (remappedOutputs.size() < sourceIndex)
  18892. remappedOutputs.add (-1);
  18893. remappedOutputs.set (sourceIndex, destIndex);
  18894. }
  18895. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18896. {
  18897. const ScopedLock sl (lock);
  18898. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18899. return remappedInputs.getUnchecked (inputChannelIndex);
  18900. return -1;
  18901. }
  18902. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18903. {
  18904. const ScopedLock sl (lock);
  18905. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18906. return remappedOutputs .getUnchecked (outputChannelIndex);
  18907. return -1;
  18908. }
  18909. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18910. {
  18911. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18912. }
  18913. void ChannelRemappingAudioSource::releaseResources()
  18914. {
  18915. source->releaseResources();
  18916. }
  18917. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18918. {
  18919. const ScopedLock sl (lock);
  18920. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18921. const int numChans = bufferToFill.buffer->getNumChannels();
  18922. int i;
  18923. for (i = 0; i < buffer.getNumChannels(); ++i)
  18924. {
  18925. const int remappedChan = getRemappedInputChannel (i);
  18926. if (remappedChan >= 0 && remappedChan < numChans)
  18927. {
  18928. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18929. remappedChan,
  18930. bufferToFill.startSample,
  18931. bufferToFill.numSamples);
  18932. }
  18933. else
  18934. {
  18935. buffer.clear (i, 0, bufferToFill.numSamples);
  18936. }
  18937. }
  18938. remappedInfo.numSamples = bufferToFill.numSamples;
  18939. source->getNextAudioBlock (remappedInfo);
  18940. bufferToFill.clearActiveBufferRegion();
  18941. for (i = 0; i < requiredNumberOfChannels; ++i)
  18942. {
  18943. const int remappedChan = getRemappedOutputChannel (i);
  18944. if (remappedChan >= 0 && remappedChan < numChans)
  18945. {
  18946. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18947. buffer, i, 0, bufferToFill.numSamples);
  18948. }
  18949. }
  18950. }
  18951. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18952. {
  18953. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18954. String ins, outs;
  18955. int i;
  18956. const ScopedLock sl (lock);
  18957. for (i = 0; i < remappedInputs.size(); ++i)
  18958. ins << remappedInputs.getUnchecked(i) << T(' ');
  18959. for (i = 0; i < remappedOutputs.size(); ++i)
  18960. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18961. e->setAttribute (T("inputs"), ins.trimEnd());
  18962. e->setAttribute (T("outputs"), outs.trimEnd());
  18963. return e;
  18964. }
  18965. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18966. {
  18967. if (e.hasTagName (T("MAPPINGS")))
  18968. {
  18969. const ScopedLock sl (lock);
  18970. clearAllMappings();
  18971. StringArray ins, outs;
  18972. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  18973. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  18974. int i;
  18975. for (i = 0; i < ins.size(); ++i)
  18976. remappedInputs.add (ins[i].getIntValue());
  18977. for (i = 0; i < outs.size(); ++i)
  18978. remappedOutputs.add (outs[i].getIntValue());
  18979. }
  18980. }
  18981. END_JUCE_NAMESPACE
  18982. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18983. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18984. BEGIN_JUCE_NAMESPACE
  18985. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18986. const bool deleteInputWhenDeleted_)
  18987. : input (inputSource),
  18988. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18989. {
  18990. jassert (inputSource != 0);
  18991. for (int i = 2; --i >= 0;)
  18992. iirFilters.add (new IIRFilter());
  18993. }
  18994. IIRFilterAudioSource::~IIRFilterAudioSource()
  18995. {
  18996. if (deleteInputWhenDeleted)
  18997. delete input;
  18998. }
  18999. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  19000. {
  19001. for (int i = iirFilters.size(); --i >= 0;)
  19002. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  19003. }
  19004. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19005. {
  19006. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19007. for (int i = iirFilters.size(); --i >= 0;)
  19008. iirFilters.getUnchecked(i)->reset();
  19009. }
  19010. void IIRFilterAudioSource::releaseResources()
  19011. {
  19012. input->releaseResources();
  19013. }
  19014. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  19015. {
  19016. input->getNextAudioBlock (bufferToFill);
  19017. const int numChannels = bufferToFill.buffer->getNumChannels();
  19018. while (numChannels > iirFilters.size())
  19019. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  19020. for (int i = 0; i < numChannels; ++i)
  19021. iirFilters.getUnchecked(i)
  19022. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  19023. bufferToFill.numSamples);
  19024. }
  19025. END_JUCE_NAMESPACE
  19026. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  19027. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  19028. BEGIN_JUCE_NAMESPACE
  19029. MixerAudioSource::MixerAudioSource()
  19030. : tempBuffer (2, 0),
  19031. currentSampleRate (0.0),
  19032. bufferSizeExpected (0)
  19033. {
  19034. }
  19035. MixerAudioSource::~MixerAudioSource()
  19036. {
  19037. removeAllInputs();
  19038. }
  19039. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  19040. {
  19041. if (input != 0 && ! inputs.contains (input))
  19042. {
  19043. double localRate;
  19044. int localBufferSize;
  19045. {
  19046. const ScopedLock sl (lock);
  19047. localRate = currentSampleRate;
  19048. localBufferSize = bufferSizeExpected;
  19049. }
  19050. if (localRate != 0.0)
  19051. input->prepareToPlay (localBufferSize, localRate);
  19052. const ScopedLock sl (lock);
  19053. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  19054. inputs.add (input);
  19055. }
  19056. }
  19057. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  19058. {
  19059. if (input != 0)
  19060. {
  19061. int index;
  19062. {
  19063. const ScopedLock sl (lock);
  19064. index = inputs.indexOf ((void*) input);
  19065. if (index >= 0)
  19066. {
  19067. inputsToDelete.shiftBits (index, 1);
  19068. inputs.remove (index);
  19069. }
  19070. }
  19071. if (index >= 0)
  19072. {
  19073. input->releaseResources();
  19074. if (deleteInput)
  19075. delete input;
  19076. }
  19077. }
  19078. }
  19079. void MixerAudioSource::removeAllInputs()
  19080. {
  19081. VoidArray inputsCopy;
  19082. BitArray inputsToDeleteCopy;
  19083. {
  19084. const ScopedLock sl (lock);
  19085. inputsCopy = inputs;
  19086. inputsToDeleteCopy = inputsToDelete;
  19087. }
  19088. for (int i = inputsCopy.size(); --i >= 0;)
  19089. if (inputsToDeleteCopy[i])
  19090. delete (AudioSource*) inputsCopy[i];
  19091. }
  19092. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19093. {
  19094. tempBuffer.setSize (2, samplesPerBlockExpected);
  19095. const ScopedLock sl (lock);
  19096. currentSampleRate = sampleRate;
  19097. bufferSizeExpected = samplesPerBlockExpected;
  19098. for (int i = inputs.size(); --i >= 0;)
  19099. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  19100. sampleRate);
  19101. }
  19102. void MixerAudioSource::releaseResources()
  19103. {
  19104. const ScopedLock sl (lock);
  19105. for (int i = inputs.size(); --i >= 0;)
  19106. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19107. tempBuffer.setSize (2, 0);
  19108. currentSampleRate = 0;
  19109. bufferSizeExpected = 0;
  19110. }
  19111. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19112. {
  19113. const ScopedLock sl (lock);
  19114. if (inputs.size() > 0)
  19115. {
  19116. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19117. if (inputs.size() > 1)
  19118. {
  19119. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19120. info.buffer->getNumSamples());
  19121. AudioSourceChannelInfo info2;
  19122. info2.buffer = &tempBuffer;
  19123. info2.numSamples = info.numSamples;
  19124. info2.startSample = 0;
  19125. for (int i = 1; i < inputs.size(); ++i)
  19126. {
  19127. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19128. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19129. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19130. }
  19131. }
  19132. }
  19133. else
  19134. {
  19135. info.clearActiveBufferRegion();
  19136. }
  19137. }
  19138. END_JUCE_NAMESPACE
  19139. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  19140. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  19141. BEGIN_JUCE_NAMESPACE
  19142. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19143. const bool deleteInputWhenDeleted_)
  19144. : input (inputSource),
  19145. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19146. ratio (1.0),
  19147. lastRatio (1.0),
  19148. buffer (2, 0),
  19149. sampsInBuffer (0)
  19150. {
  19151. jassert (input != 0);
  19152. }
  19153. ResamplingAudioSource::~ResamplingAudioSource()
  19154. {
  19155. if (deleteInputWhenDeleted)
  19156. delete input;
  19157. }
  19158. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19159. {
  19160. jassert (samplesInPerOutputSample > 0);
  19161. const ScopedLock sl (ratioLock);
  19162. ratio = jmax (0.0, samplesInPerOutputSample);
  19163. }
  19164. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19165. double sampleRate)
  19166. {
  19167. const ScopedLock sl (ratioLock);
  19168. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19169. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19170. buffer.clear();
  19171. sampsInBuffer = 0;
  19172. bufferPos = 0;
  19173. subSampleOffset = 0.0;
  19174. createLowPass (ratio);
  19175. resetFilters();
  19176. }
  19177. void ResamplingAudioSource::releaseResources()
  19178. {
  19179. input->releaseResources();
  19180. buffer.setSize (2, 0);
  19181. }
  19182. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19183. {
  19184. const ScopedLock sl (ratioLock);
  19185. if (lastRatio != ratio)
  19186. {
  19187. createLowPass (ratio);
  19188. lastRatio = ratio;
  19189. }
  19190. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19191. int bufferSize = buffer.getNumSamples();
  19192. if (bufferSize < sampsNeeded + 8)
  19193. {
  19194. bufferPos %= bufferSize;
  19195. bufferSize = sampsNeeded + 32;
  19196. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19197. }
  19198. bufferPos %= bufferSize;
  19199. int endOfBufferPos = bufferPos + sampsInBuffer;
  19200. while (sampsNeeded > sampsInBuffer)
  19201. {
  19202. endOfBufferPos %= bufferSize;
  19203. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19204. bufferSize - endOfBufferPos);
  19205. AudioSourceChannelInfo readInfo;
  19206. readInfo.buffer = &buffer;
  19207. readInfo.numSamples = numToDo;
  19208. readInfo.startSample = endOfBufferPos;
  19209. input->getNextAudioBlock (readInfo);
  19210. if (ratio > 1.0001)
  19211. {
  19212. // for down-sampling, pre-apply the filter..
  19213. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19214. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19215. }
  19216. sampsInBuffer += numToDo;
  19217. endOfBufferPos += numToDo;
  19218. }
  19219. float* dl = info.buffer->getSampleData (0, info.startSample);
  19220. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19221. const float* const bl = buffer.getSampleData (0, 0);
  19222. const float* const br = buffer.getSampleData (1, 0);
  19223. int nextPos = (bufferPos + 1) % bufferSize;
  19224. for (int m = info.numSamples; --m >= 0;)
  19225. {
  19226. const float alpha = (float) subSampleOffset;
  19227. const float invAlpha = 1.0f - alpha;
  19228. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19229. if (dr != 0)
  19230. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19231. subSampleOffset += ratio;
  19232. jassert (sampsInBuffer > 0);
  19233. while (subSampleOffset >= 1.0)
  19234. {
  19235. if (++bufferPos >= bufferSize)
  19236. bufferPos = 0;
  19237. --sampsInBuffer;
  19238. nextPos = (bufferPos + 1) % bufferSize;
  19239. subSampleOffset -= 1.0;
  19240. }
  19241. }
  19242. if (ratio < 0.9999)
  19243. {
  19244. // for up-sampling, apply the filter after transposing..
  19245. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19246. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19247. }
  19248. else if (ratio <= 1.0001)
  19249. {
  19250. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19251. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19252. {
  19253. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19254. FilterState& fs = filterStates[i];
  19255. if (info.numSamples > 1)
  19256. {
  19257. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19258. }
  19259. else
  19260. {
  19261. fs.y2 = fs.y1;
  19262. fs.x2 = fs.x1;
  19263. }
  19264. fs.y1 = fs.x1 = *endOfBuffer;
  19265. }
  19266. }
  19267. jassert (sampsInBuffer >= 0);
  19268. }
  19269. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19270. {
  19271. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19272. : 0.5 * frequencyRatio;
  19273. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19274. const double nSquared = n * n;
  19275. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19276. setFilterCoefficients (c1,
  19277. c1 * 2.0f,
  19278. c1,
  19279. 1.0,
  19280. c1 * 2.0 * (1.0 - nSquared),
  19281. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19282. }
  19283. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19284. {
  19285. const double a = 1.0 / c4;
  19286. c1 *= a;
  19287. c2 *= a;
  19288. c3 *= a;
  19289. c5 *= a;
  19290. c6 *= a;
  19291. coefficients[0] = c1;
  19292. coefficients[1] = c2;
  19293. coefficients[2] = c3;
  19294. coefficients[3] = c4;
  19295. coefficients[4] = c5;
  19296. coefficients[5] = c6;
  19297. }
  19298. void ResamplingAudioSource::resetFilters()
  19299. {
  19300. zeromem (filterStates, sizeof (filterStates));
  19301. }
  19302. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19303. {
  19304. while (--num >= 0)
  19305. {
  19306. const double in = *samples;
  19307. double out = coefficients[0] * in
  19308. + coefficients[1] * fs.x1
  19309. + coefficients[2] * fs.x2
  19310. - coefficients[4] * fs.y1
  19311. - coefficients[5] * fs.y2;
  19312. #if JUCE_INTEL
  19313. if (! (out < -1.0e-8 || out > 1.0e-8))
  19314. out = 0;
  19315. #endif
  19316. fs.x2 = fs.x1;
  19317. fs.x1 = in;
  19318. fs.y2 = fs.y1;
  19319. fs.y1 = out;
  19320. *samples++ = (float) out;
  19321. }
  19322. }
  19323. END_JUCE_NAMESPACE
  19324. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19325. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19326. BEGIN_JUCE_NAMESPACE
  19327. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19328. : frequency (1000.0),
  19329. sampleRate (44100.0),
  19330. currentPhase (0.0),
  19331. phasePerSample (0.0),
  19332. amplitude (0.5f)
  19333. {
  19334. }
  19335. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19336. {
  19337. }
  19338. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19339. {
  19340. amplitude = newAmplitude;
  19341. }
  19342. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19343. {
  19344. frequency = newFrequencyHz;
  19345. phasePerSample = 0.0;
  19346. }
  19347. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19348. double sampleRate_)
  19349. {
  19350. currentPhase = 0.0;
  19351. phasePerSample = 0.0;
  19352. sampleRate = sampleRate_;
  19353. }
  19354. void ToneGeneratorAudioSource::releaseResources()
  19355. {
  19356. }
  19357. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19358. {
  19359. if (phasePerSample == 0.0)
  19360. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19361. for (int i = 0; i < info.numSamples; ++i)
  19362. {
  19363. const float sample = amplitude * (float) sin (currentPhase);
  19364. currentPhase += phasePerSample;
  19365. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19366. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19367. }
  19368. }
  19369. END_JUCE_NAMESPACE
  19370. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19371. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19372. BEGIN_JUCE_NAMESPACE
  19373. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19374. : sampleRate (0),
  19375. bufferSize (0),
  19376. useDefaultInputChannels (true),
  19377. useDefaultOutputChannels (true)
  19378. {
  19379. }
  19380. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19381. {
  19382. return outputDeviceName == other.outputDeviceName
  19383. && inputDeviceName == other.inputDeviceName
  19384. && sampleRate == other.sampleRate
  19385. && bufferSize == other.bufferSize
  19386. && inputChannels == other.inputChannels
  19387. && useDefaultInputChannels == other.useDefaultInputChannels
  19388. && outputChannels == other.outputChannels
  19389. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19390. }
  19391. AudioDeviceManager::AudioDeviceManager()
  19392. : currentAudioDevice (0),
  19393. numInputChansNeeded (0),
  19394. numOutputChansNeeded (2),
  19395. listNeedsScanning (true),
  19396. useInputNames (false),
  19397. inputLevelMeasurementEnabledCount (0),
  19398. inputLevel (0),
  19399. tempBuffer (2, 2),
  19400. defaultMidiOutput (0),
  19401. cpuUsageMs (0),
  19402. timeToCpuScale (0)
  19403. {
  19404. callbackHandler.owner = this;
  19405. }
  19406. AudioDeviceManager::~AudioDeviceManager()
  19407. {
  19408. currentAudioDevice = 0;
  19409. defaultMidiOutput = 0;
  19410. }
  19411. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19412. {
  19413. if (availableDeviceTypes.size() == 0)
  19414. {
  19415. createAudioDeviceTypes (availableDeviceTypes);
  19416. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19417. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19418. if (availableDeviceTypes.size() > 0)
  19419. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19420. }
  19421. }
  19422. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19423. {
  19424. scanDevicesIfNeeded();
  19425. return availableDeviceTypes;
  19426. }
  19427. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19428. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19429. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19430. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19431. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19432. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19433. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19434. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19435. {
  19436. #if JUCE_WINDOWS
  19437. #if JUCE_WASAPI
  19438. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19439. list.add (juce_createAudioIODeviceType_WASAPI());
  19440. #endif
  19441. #if JUCE_DIRECTSOUND
  19442. list.add (juce_createAudioIODeviceType_DirectSound());
  19443. #endif
  19444. #if JUCE_ASIO
  19445. list.add (juce_createAudioIODeviceType_ASIO());
  19446. #endif
  19447. #endif
  19448. #if JUCE_MAC
  19449. list.add (juce_createAudioIODeviceType_CoreAudio());
  19450. #endif
  19451. #if JUCE_IPHONE
  19452. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19453. #endif
  19454. #if JUCE_LINUX && JUCE_ALSA
  19455. list.add (juce_createAudioIODeviceType_ALSA());
  19456. #endif
  19457. #if JUCE_LINUX && JUCE_JACK
  19458. list.add (juce_createAudioIODeviceType_JACK());
  19459. #endif
  19460. }
  19461. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19462. const int numOutputChannelsNeeded,
  19463. const XmlElement* const e,
  19464. const bool selectDefaultDeviceOnFailure,
  19465. const String& preferredDefaultDeviceName,
  19466. const AudioDeviceSetup* preferredSetupOptions)
  19467. {
  19468. scanDevicesIfNeeded();
  19469. numInputChansNeeded = numInputChannelsNeeded;
  19470. numOutputChansNeeded = numOutputChannelsNeeded;
  19471. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19472. {
  19473. lastExplicitSettings = new XmlElement (*e);
  19474. String error;
  19475. AudioDeviceSetup setup;
  19476. if (preferredSetupOptions != 0)
  19477. setup = *preferredSetupOptions;
  19478. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19479. {
  19480. setup.inputDeviceName = setup.outputDeviceName
  19481. = e->getStringAttribute (T("audioDeviceName"));
  19482. }
  19483. else
  19484. {
  19485. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19486. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19487. }
  19488. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19489. if (currentDeviceType.isEmpty())
  19490. {
  19491. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19492. if (type != 0)
  19493. currentDeviceType = type->getTypeName();
  19494. else if (availableDeviceTypes.size() > 0)
  19495. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19496. }
  19497. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19498. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19499. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19500. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19501. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19502. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19503. error = setAudioDeviceSetup (setup, true);
  19504. midiInsFromXml.clear();
  19505. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19506. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19507. const StringArray allMidiIns (MidiInput::getDevices());
  19508. for (int i = allMidiIns.size(); --i >= 0;)
  19509. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19510. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19511. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19512. false, preferredDefaultDeviceName);
  19513. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19514. return error;
  19515. }
  19516. else
  19517. {
  19518. AudioDeviceSetup setup;
  19519. if (preferredSetupOptions != 0)
  19520. {
  19521. setup = *preferredSetupOptions;
  19522. }
  19523. else if (preferredDefaultDeviceName.isNotEmpty())
  19524. {
  19525. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19526. {
  19527. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19528. StringArray outs (type->getDeviceNames (false));
  19529. int i;
  19530. for (i = 0; i < outs.size(); ++i)
  19531. {
  19532. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19533. {
  19534. setup.outputDeviceName = outs[i];
  19535. break;
  19536. }
  19537. }
  19538. StringArray ins (type->getDeviceNames (true));
  19539. for (i = 0; i < ins.size(); ++i)
  19540. {
  19541. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19542. {
  19543. setup.inputDeviceName = ins[i];
  19544. break;
  19545. }
  19546. }
  19547. }
  19548. }
  19549. insertDefaultDeviceNames (setup);
  19550. return setAudioDeviceSetup (setup, false);
  19551. }
  19552. }
  19553. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19554. {
  19555. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19556. if (type != 0)
  19557. {
  19558. if (setup.outputDeviceName.isEmpty())
  19559. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19560. if (setup.inputDeviceName.isEmpty())
  19561. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19562. }
  19563. }
  19564. XmlElement* AudioDeviceManager::createStateXml() const
  19565. {
  19566. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19567. }
  19568. void AudioDeviceManager::scanDevicesIfNeeded()
  19569. {
  19570. if (listNeedsScanning)
  19571. {
  19572. listNeedsScanning = false;
  19573. createDeviceTypesIfNeeded();
  19574. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19575. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19576. }
  19577. }
  19578. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19579. {
  19580. scanDevicesIfNeeded();
  19581. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19582. {
  19583. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19584. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19585. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19586. {
  19587. return type;
  19588. }
  19589. }
  19590. return 0;
  19591. }
  19592. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19593. {
  19594. setup = currentSetup;
  19595. }
  19596. void AudioDeviceManager::deleteCurrentDevice()
  19597. {
  19598. currentAudioDevice = 0;
  19599. currentSetup.inputDeviceName = String::empty;
  19600. currentSetup.outputDeviceName = String::empty;
  19601. }
  19602. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19603. const bool treatAsChosenDevice)
  19604. {
  19605. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19606. {
  19607. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19608. && currentDeviceType != type)
  19609. {
  19610. currentDeviceType = type;
  19611. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19612. insertDefaultDeviceNames (s);
  19613. setAudioDeviceSetup (s, treatAsChosenDevice);
  19614. sendChangeMessage (this);
  19615. break;
  19616. }
  19617. }
  19618. }
  19619. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19620. {
  19621. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19622. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19623. return availableDeviceTypes[i];
  19624. return availableDeviceTypes[0];
  19625. }
  19626. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19627. const bool treatAsChosenDevice)
  19628. {
  19629. jassert (&newSetup != &currentSetup); // this will have no effect
  19630. if (newSetup == currentSetup && currentAudioDevice != 0)
  19631. return String::empty;
  19632. if (! (newSetup == currentSetup))
  19633. sendChangeMessage (this);
  19634. stopDevice();
  19635. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19636. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19637. String error;
  19638. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19639. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19640. {
  19641. deleteCurrentDevice();
  19642. if (treatAsChosenDevice)
  19643. updateXml();
  19644. return String::empty;
  19645. }
  19646. if (currentSetup.inputDeviceName != newInputDeviceName
  19647. || currentSetup.outputDeviceName != newOutputDeviceName
  19648. || currentAudioDevice == 0)
  19649. {
  19650. deleteCurrentDevice();
  19651. scanDevicesIfNeeded();
  19652. if (newOutputDeviceName.isNotEmpty()
  19653. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19654. {
  19655. return "No such device: " + newOutputDeviceName;
  19656. }
  19657. if (newInputDeviceName.isNotEmpty()
  19658. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19659. {
  19660. return "No such device: " + newInputDeviceName;
  19661. }
  19662. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19663. if (currentAudioDevice == 0)
  19664. 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!";
  19665. else
  19666. error = currentAudioDevice->getLastError();
  19667. if (error.isNotEmpty())
  19668. {
  19669. deleteCurrentDevice();
  19670. return error;
  19671. }
  19672. if (newSetup.useDefaultInputChannels)
  19673. {
  19674. inputChannels.clear();
  19675. inputChannels.setRange (0, numInputChansNeeded, true);
  19676. }
  19677. if (newSetup.useDefaultOutputChannels)
  19678. {
  19679. outputChannels.clear();
  19680. outputChannels.setRange (0, numOutputChansNeeded, true);
  19681. }
  19682. if (newInputDeviceName.isEmpty())
  19683. inputChannels.clear();
  19684. if (newOutputDeviceName.isEmpty())
  19685. outputChannels.clear();
  19686. }
  19687. if (! newSetup.useDefaultInputChannels)
  19688. inputChannels = newSetup.inputChannels;
  19689. if (! newSetup.useDefaultOutputChannels)
  19690. outputChannels = newSetup.outputChannels;
  19691. currentSetup = newSetup;
  19692. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19693. error = currentAudioDevice->open (inputChannels,
  19694. outputChannels,
  19695. currentSetup.sampleRate,
  19696. currentSetup.bufferSize);
  19697. if (error.isEmpty())
  19698. {
  19699. currentDeviceType = currentAudioDevice->getTypeName();
  19700. currentAudioDevice->start (&callbackHandler);
  19701. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19702. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19703. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19704. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19705. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19706. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19707. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19708. if (treatAsChosenDevice)
  19709. updateXml();
  19710. }
  19711. else
  19712. {
  19713. deleteCurrentDevice();
  19714. }
  19715. return error;
  19716. }
  19717. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19718. {
  19719. jassert (currentAudioDevice != 0);
  19720. if (rate > 0)
  19721. {
  19722. bool ok = false;
  19723. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19724. {
  19725. const double sr = currentAudioDevice->getSampleRate (i);
  19726. if (sr == rate)
  19727. ok = true;
  19728. }
  19729. if (! ok)
  19730. rate = 0;
  19731. }
  19732. if (rate == 0)
  19733. {
  19734. double lowestAbove44 = 0.0;
  19735. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19736. {
  19737. const double sr = currentAudioDevice->getSampleRate (i);
  19738. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19739. lowestAbove44 = sr;
  19740. }
  19741. if (lowestAbove44 == 0.0)
  19742. rate = currentAudioDevice->getSampleRate (0);
  19743. else
  19744. rate = lowestAbove44;
  19745. }
  19746. return rate;
  19747. }
  19748. void AudioDeviceManager::stopDevice()
  19749. {
  19750. if (currentAudioDevice != 0)
  19751. currentAudioDevice->stop();
  19752. testSound = 0;
  19753. }
  19754. void AudioDeviceManager::closeAudioDevice()
  19755. {
  19756. stopDevice();
  19757. currentAudioDevice = 0;
  19758. }
  19759. void AudioDeviceManager::restartLastAudioDevice()
  19760. {
  19761. if (currentAudioDevice == 0)
  19762. {
  19763. if (currentSetup.inputDeviceName.isEmpty()
  19764. && currentSetup.outputDeviceName.isEmpty())
  19765. {
  19766. // This method will only reload the last device that was running
  19767. // before closeAudioDevice() was called - you need to actually open
  19768. // one first, with setAudioDevice().
  19769. jassertfalse
  19770. return;
  19771. }
  19772. AudioDeviceSetup s (currentSetup);
  19773. setAudioDeviceSetup (s, false);
  19774. }
  19775. }
  19776. void AudioDeviceManager::updateXml()
  19777. {
  19778. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19779. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19780. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19781. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19782. if (currentAudioDevice != 0)
  19783. {
  19784. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19785. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19786. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19787. if (! currentSetup.useDefaultInputChannels)
  19788. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19789. if (! currentSetup.useDefaultOutputChannels)
  19790. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19791. }
  19792. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19793. {
  19794. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19795. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19796. }
  19797. if (midiInsFromXml.size() > 0)
  19798. {
  19799. // Add any midi devices that have been enabled before, but which aren't currently
  19800. // open because the device has been disconnected.
  19801. const StringArray availableMidiDevices (MidiInput::getDevices());
  19802. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19803. {
  19804. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19805. {
  19806. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19807. m->setAttribute ("name", midiInsFromXml[i]);
  19808. }
  19809. }
  19810. }
  19811. if (defaultMidiOutputName.isNotEmpty())
  19812. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19813. }
  19814. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19815. {
  19816. {
  19817. const ScopedLock sl (audioCallbackLock);
  19818. if (callbacks.contains (newCallback))
  19819. return;
  19820. }
  19821. if (currentAudioDevice != 0 && newCallback != 0)
  19822. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19823. const ScopedLock sl (audioCallbackLock);
  19824. callbacks.add (newCallback);
  19825. }
  19826. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19827. {
  19828. if (callback != 0)
  19829. {
  19830. bool needsDeinitialising = currentAudioDevice != 0;
  19831. {
  19832. const ScopedLock sl (audioCallbackLock);
  19833. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19834. callbacks.removeValue (callback);
  19835. }
  19836. if (needsDeinitialising)
  19837. callback->audioDeviceStopped();
  19838. }
  19839. }
  19840. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19841. int numInputChannels,
  19842. float** outputChannelData,
  19843. int numOutputChannels,
  19844. int numSamples)
  19845. {
  19846. const ScopedLock sl (audioCallbackLock);
  19847. if (inputLevelMeasurementEnabledCount > 0)
  19848. {
  19849. for (int j = 0; j < numSamples; ++j)
  19850. {
  19851. float s = 0;
  19852. for (int i = 0; i < numInputChannels; ++i)
  19853. s += fabsf (inputChannelData[i][j]);
  19854. s /= numInputChannels;
  19855. const double decayFactor = 0.99992;
  19856. if (s > inputLevel)
  19857. inputLevel = s;
  19858. else if (inputLevel > 0.001f)
  19859. inputLevel *= decayFactor;
  19860. else
  19861. inputLevel = 0;
  19862. }
  19863. }
  19864. if (callbacks.size() > 0)
  19865. {
  19866. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19867. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19868. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19869. outputChannelData, numOutputChannels, numSamples);
  19870. float** const tempChans = tempBuffer.getArrayOfChannels();
  19871. for (int i = callbacks.size(); --i > 0;)
  19872. {
  19873. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19874. tempChans, numOutputChannels, numSamples);
  19875. for (int chan = 0; chan < numOutputChannels; ++chan)
  19876. {
  19877. const float* const src = tempChans [chan];
  19878. float* const dst = outputChannelData [chan];
  19879. if (src != 0 && dst != 0)
  19880. for (int j = 0; j < numSamples; ++j)
  19881. dst[j] += src[j];
  19882. }
  19883. }
  19884. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19885. const double filterAmount = 0.2;
  19886. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19887. }
  19888. else
  19889. {
  19890. for (int i = 0; i < numOutputChannels; ++i)
  19891. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19892. }
  19893. if (testSound != 0)
  19894. {
  19895. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19896. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19897. for (int i = 0; i < numOutputChannels; ++i)
  19898. for (int j = 0; j < numSamps; ++j)
  19899. outputChannelData [i][j] += src[j];
  19900. testSoundPosition += numSamps;
  19901. if (testSoundPosition >= testSound->getNumSamples())
  19902. testSound = 0;
  19903. }
  19904. }
  19905. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19906. {
  19907. cpuUsageMs = 0;
  19908. const double sampleRate = device->getCurrentSampleRate();
  19909. const int blockSize = device->getCurrentBufferSizeSamples();
  19910. if (sampleRate > 0.0 && blockSize > 0)
  19911. {
  19912. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19913. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19914. }
  19915. {
  19916. const ScopedLock sl (audioCallbackLock);
  19917. for (int i = callbacks.size(); --i >= 0;)
  19918. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19919. }
  19920. sendChangeMessage (this);
  19921. }
  19922. void AudioDeviceManager::audioDeviceStoppedInt()
  19923. {
  19924. cpuUsageMs = 0;
  19925. timeToCpuScale = 0;
  19926. sendChangeMessage (this);
  19927. const ScopedLock sl (audioCallbackLock);
  19928. for (int i = callbacks.size(); --i >= 0;)
  19929. callbacks.getUnchecked(i)->audioDeviceStopped();
  19930. }
  19931. double AudioDeviceManager::getCpuUsage() const
  19932. {
  19933. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19934. }
  19935. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19936. const bool enabled)
  19937. {
  19938. if (enabled != isMidiInputEnabled (name))
  19939. {
  19940. if (enabled)
  19941. {
  19942. const int index = MidiInput::getDevices().indexOf (name);
  19943. if (index >= 0)
  19944. {
  19945. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19946. if (min != 0)
  19947. {
  19948. enabledMidiInputs.add (min);
  19949. min->start();
  19950. }
  19951. }
  19952. }
  19953. else
  19954. {
  19955. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19956. if (enabledMidiInputs[i]->getName() == name)
  19957. enabledMidiInputs.remove (i);
  19958. }
  19959. updateXml();
  19960. sendChangeMessage (this);
  19961. }
  19962. }
  19963. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19964. {
  19965. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19966. if (enabledMidiInputs[i]->getName() == name)
  19967. return true;
  19968. return false;
  19969. }
  19970. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19971. MidiInputCallback* callback)
  19972. {
  19973. removeMidiInputCallback (name, callback);
  19974. if (name.isEmpty())
  19975. {
  19976. midiCallbacks.add (callback);
  19977. midiCallbackDevices.add (0);
  19978. }
  19979. else
  19980. {
  19981. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19982. {
  19983. if (enabledMidiInputs[i]->getName() == name)
  19984. {
  19985. const ScopedLock sl (midiCallbackLock);
  19986. midiCallbacks.add (callback);
  19987. midiCallbackDevices.add (enabledMidiInputs[i]);
  19988. break;
  19989. }
  19990. }
  19991. }
  19992. }
  19993. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19994. MidiInputCallback* /*callback*/)
  19995. {
  19996. const ScopedLock sl (midiCallbackLock);
  19997. for (int i = midiCallbacks.size(); --i >= 0;)
  19998. {
  19999. String devName;
  20000. if (midiCallbackDevices.getUnchecked(i) != 0)
  20001. devName = midiCallbackDevices.getUnchecked(i)->getName();
  20002. if (devName == name)
  20003. {
  20004. midiCallbacks.remove (i);
  20005. midiCallbackDevices.remove (i);
  20006. }
  20007. }
  20008. }
  20009. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  20010. const MidiMessage& message)
  20011. {
  20012. if (! message.isActiveSense())
  20013. {
  20014. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  20015. const ScopedLock sl (midiCallbackLock);
  20016. for (int i = midiCallbackDevices.size(); --i >= 0;)
  20017. {
  20018. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  20019. if (md == source || (md == 0 && isDefaultSource))
  20020. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  20021. }
  20022. }
  20023. }
  20024. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  20025. {
  20026. if (defaultMidiOutputName != deviceName)
  20027. {
  20028. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  20029. {
  20030. const ScopedLock sl (audioCallbackLock);
  20031. oldCallbacks = callbacks;
  20032. callbacks.clear();
  20033. }
  20034. if (currentAudioDevice != 0)
  20035. for (int i = oldCallbacks.size(); --i >= 0;)
  20036. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  20037. defaultMidiOutput = 0;
  20038. defaultMidiOutputName = deviceName;
  20039. if (deviceName.isNotEmpty())
  20040. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  20041. if (currentAudioDevice != 0)
  20042. for (int i = oldCallbacks.size(); --i >= 0;)
  20043. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  20044. {
  20045. const ScopedLock sl (audioCallbackLock);
  20046. callbacks = oldCallbacks;
  20047. }
  20048. updateXml();
  20049. sendChangeMessage (this);
  20050. }
  20051. }
  20052. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  20053. int numInputChannels,
  20054. float** outputChannelData,
  20055. int numOutputChannels,
  20056. int numSamples)
  20057. {
  20058. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  20059. }
  20060. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  20061. {
  20062. owner->audioDeviceAboutToStartInt (device);
  20063. }
  20064. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  20065. {
  20066. owner->audioDeviceStoppedInt();
  20067. }
  20068. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  20069. {
  20070. owner->handleIncomingMidiMessageInt (source, message);
  20071. }
  20072. void AudioDeviceManager::playTestSound()
  20073. {
  20074. { // cunningly nested to swap, unlock and delete in that order.
  20075. ScopedPointer <AudioSampleBuffer> oldSound;
  20076. {
  20077. const ScopedLock sl (audioCallbackLock);
  20078. oldSound = testSound;
  20079. }
  20080. }
  20081. testSoundPosition = 0;
  20082. if (currentAudioDevice != 0)
  20083. {
  20084. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  20085. const int soundLength = (int) sampleRate;
  20086. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  20087. float* samples = newSound->getSampleData (0);
  20088. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  20089. const float amplitude = 0.5f;
  20090. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  20091. for (int i = 0; i < soundLength; ++i)
  20092. samples[i] = amplitude * (float) sin (i * phasePerSample);
  20093. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  20094. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  20095. const ScopedLock sl (audioCallbackLock);
  20096. testSound = newSound;
  20097. }
  20098. }
  20099. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  20100. {
  20101. const ScopedLock sl (audioCallbackLock);
  20102. if (enableMeasurement)
  20103. ++inputLevelMeasurementEnabledCount;
  20104. else
  20105. --inputLevelMeasurementEnabledCount;
  20106. inputLevel = 0;
  20107. }
  20108. double AudioDeviceManager::getCurrentInputLevel() const
  20109. {
  20110. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20111. return inputLevel;
  20112. }
  20113. END_JUCE_NAMESPACE
  20114. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  20115. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  20116. BEGIN_JUCE_NAMESPACE
  20117. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20118. : name (deviceName),
  20119. typeName (typeName_)
  20120. {
  20121. }
  20122. AudioIODevice::~AudioIODevice()
  20123. {
  20124. }
  20125. bool AudioIODevice::hasControlPanel() const
  20126. {
  20127. return false;
  20128. }
  20129. bool AudioIODevice::showControlPanel()
  20130. {
  20131. jassertfalse // this should only be called for devices which return true from
  20132. // their hasControlPanel() method.
  20133. return false;
  20134. }
  20135. END_JUCE_NAMESPACE
  20136. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  20137. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  20138. BEGIN_JUCE_NAMESPACE
  20139. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20140. : typeName (name)
  20141. {
  20142. }
  20143. AudioIODeviceType::~AudioIODeviceType()
  20144. {
  20145. }
  20146. END_JUCE_NAMESPACE
  20147. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  20148. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  20149. BEGIN_JUCE_NAMESPACE
  20150. MidiOutput::MidiOutput() throw()
  20151. : Thread ("midi out"),
  20152. internal (0),
  20153. firstMessage (0)
  20154. {
  20155. }
  20156. MidiOutput::PendingMessage::PendingMessage (const uint8* const data,
  20157. const int len,
  20158. const double sampleNumber) throw()
  20159. : message (data, len, sampleNumber)
  20160. {
  20161. }
  20162. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20163. const double millisecondCounterToStartAt,
  20164. double samplesPerSecondForBuffer) throw()
  20165. {
  20166. // You've got to call startBackgroundThread() for this to actually work..
  20167. jassert (isThreadRunning());
  20168. // this needs to be a value in the future - RTFM for this method!
  20169. jassert (millisecondCounterToStartAt > 0);
  20170. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20171. MidiBuffer::Iterator i (buffer);
  20172. const uint8* data;
  20173. int len, time;
  20174. while (i.getNextEvent (data, len, time))
  20175. {
  20176. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20177. PendingMessage* const m
  20178. = new PendingMessage (data, len, eventTime);
  20179. const ScopedLock sl (lock);
  20180. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20181. {
  20182. m->next = firstMessage;
  20183. firstMessage = m;
  20184. }
  20185. else
  20186. {
  20187. PendingMessage* mm = firstMessage;
  20188. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20189. mm = mm->next;
  20190. m->next = mm->next;
  20191. mm->next = m;
  20192. }
  20193. }
  20194. notify();
  20195. }
  20196. void MidiOutput::clearAllPendingMessages() throw()
  20197. {
  20198. const ScopedLock sl (lock);
  20199. while (firstMessage != 0)
  20200. {
  20201. PendingMessage* const m = firstMessage;
  20202. firstMessage = firstMessage->next;
  20203. delete m;
  20204. }
  20205. }
  20206. void MidiOutput::startBackgroundThread() throw()
  20207. {
  20208. startThread (9);
  20209. }
  20210. void MidiOutput::stopBackgroundThread() throw()
  20211. {
  20212. stopThread (5000);
  20213. }
  20214. void MidiOutput::run()
  20215. {
  20216. while (! threadShouldExit())
  20217. {
  20218. uint32 now = Time::getMillisecondCounter();
  20219. uint32 eventTime = 0;
  20220. uint32 timeToWait = 500;
  20221. PendingMessage* message;
  20222. {
  20223. const ScopedLock sl (lock);
  20224. message = firstMessage;
  20225. if (message != 0)
  20226. {
  20227. eventTime = roundToInt (message->message.getTimeStamp());
  20228. if (eventTime > now + 20)
  20229. {
  20230. timeToWait = eventTime - (now + 20);
  20231. message = 0;
  20232. }
  20233. else
  20234. {
  20235. firstMessage = message->next;
  20236. }
  20237. }
  20238. }
  20239. if (message != 0)
  20240. {
  20241. if (eventTime > now)
  20242. {
  20243. Time::waitForMillisecondCounter (eventTime);
  20244. if (threadShouldExit())
  20245. break;
  20246. }
  20247. if (eventTime > now - 200)
  20248. sendMessageNow (message->message);
  20249. delete message;
  20250. }
  20251. else
  20252. {
  20253. jassert (timeToWait < 1000 * 30);
  20254. wait (timeToWait);
  20255. }
  20256. }
  20257. clearAllPendingMessages();
  20258. }
  20259. END_JUCE_NAMESPACE
  20260. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20261. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20262. BEGIN_JUCE_NAMESPACE
  20263. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20264. {
  20265. const double maxVal = (double) 0x7fff;
  20266. char* intData = (char*) dest;
  20267. if (dest != (void*) source || destBytesPerSample <= 4)
  20268. {
  20269. for (int i = 0; i < numSamples; ++i)
  20270. {
  20271. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20272. intData += destBytesPerSample;
  20273. }
  20274. }
  20275. else
  20276. {
  20277. intData += destBytesPerSample * numSamples;
  20278. for (int i = numSamples; --i >= 0;)
  20279. {
  20280. intData -= destBytesPerSample;
  20281. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20282. }
  20283. }
  20284. }
  20285. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20286. {
  20287. const double maxVal = (double) 0x7fff;
  20288. char* intData = (char*) dest;
  20289. if (dest != (void*) source || destBytesPerSample <= 4)
  20290. {
  20291. for (int i = 0; i < numSamples; ++i)
  20292. {
  20293. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20294. intData += destBytesPerSample;
  20295. }
  20296. }
  20297. else
  20298. {
  20299. intData += destBytesPerSample * numSamples;
  20300. for (int i = numSamples; --i >= 0;)
  20301. {
  20302. intData -= destBytesPerSample;
  20303. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20304. }
  20305. }
  20306. }
  20307. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20308. {
  20309. const double maxVal = (double) 0x7fffff;
  20310. char* intData = (char*) dest;
  20311. if (dest != (void*) source || destBytesPerSample <= 4)
  20312. {
  20313. for (int i = 0; i < numSamples; ++i)
  20314. {
  20315. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20316. intData += destBytesPerSample;
  20317. }
  20318. }
  20319. else
  20320. {
  20321. intData += destBytesPerSample * numSamples;
  20322. for (int i = numSamples; --i >= 0;)
  20323. {
  20324. intData -= destBytesPerSample;
  20325. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20326. }
  20327. }
  20328. }
  20329. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20330. {
  20331. const double maxVal = (double) 0x7fffff;
  20332. char* intData = (char*) dest;
  20333. if (dest != (void*) source || destBytesPerSample <= 4)
  20334. {
  20335. for (int i = 0; i < numSamples; ++i)
  20336. {
  20337. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20338. intData += destBytesPerSample;
  20339. }
  20340. }
  20341. else
  20342. {
  20343. intData += destBytesPerSample * numSamples;
  20344. for (int i = numSamples; --i >= 0;)
  20345. {
  20346. intData -= destBytesPerSample;
  20347. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20348. }
  20349. }
  20350. }
  20351. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20352. {
  20353. const double maxVal = (double) 0x7fffffff;
  20354. char* intData = (char*) dest;
  20355. if (dest != (void*) source || destBytesPerSample <= 4)
  20356. {
  20357. for (int i = 0; i < numSamples; ++i)
  20358. {
  20359. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20360. intData += destBytesPerSample;
  20361. }
  20362. }
  20363. else
  20364. {
  20365. intData += destBytesPerSample * numSamples;
  20366. for (int i = numSamples; --i >= 0;)
  20367. {
  20368. intData -= destBytesPerSample;
  20369. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20370. }
  20371. }
  20372. }
  20373. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20374. {
  20375. const double maxVal = (double) 0x7fffffff;
  20376. char* intData = (char*) dest;
  20377. if (dest != (void*) source || destBytesPerSample <= 4)
  20378. {
  20379. for (int i = 0; i < numSamples; ++i)
  20380. {
  20381. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20382. intData += destBytesPerSample;
  20383. }
  20384. }
  20385. else
  20386. {
  20387. intData += destBytesPerSample * numSamples;
  20388. for (int i = numSamples; --i >= 0;)
  20389. {
  20390. intData -= destBytesPerSample;
  20391. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20392. }
  20393. }
  20394. }
  20395. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20396. {
  20397. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20398. char* d = (char*) dest;
  20399. for (int i = 0; i < numSamples; ++i)
  20400. {
  20401. *(float*) d = source[i];
  20402. #if JUCE_BIG_ENDIAN
  20403. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20404. #endif
  20405. d += destBytesPerSample;
  20406. }
  20407. }
  20408. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20409. {
  20410. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20411. char* d = (char*) dest;
  20412. for (int i = 0; i < numSamples; ++i)
  20413. {
  20414. *(float*) d = source[i];
  20415. #if JUCE_LITTLE_ENDIAN
  20416. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20417. #endif
  20418. d += destBytesPerSample;
  20419. }
  20420. }
  20421. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20422. {
  20423. const float scale = 1.0f / 0x7fff;
  20424. const char* intData = (const char*) source;
  20425. if (source != (void*) dest || srcBytesPerSample >= 4)
  20426. {
  20427. for (int i = 0; i < numSamples; ++i)
  20428. {
  20429. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20430. intData += srcBytesPerSample;
  20431. }
  20432. }
  20433. else
  20434. {
  20435. intData += srcBytesPerSample * numSamples;
  20436. for (int i = numSamples; --i >= 0;)
  20437. {
  20438. intData -= srcBytesPerSample;
  20439. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20440. }
  20441. }
  20442. }
  20443. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20444. {
  20445. const float scale = 1.0f / 0x7fff;
  20446. const char* intData = (const char*) source;
  20447. if (source != (void*) dest || srcBytesPerSample >= 4)
  20448. {
  20449. for (int i = 0; i < numSamples; ++i)
  20450. {
  20451. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20452. intData += srcBytesPerSample;
  20453. }
  20454. }
  20455. else
  20456. {
  20457. intData += srcBytesPerSample * numSamples;
  20458. for (int i = numSamples; --i >= 0;)
  20459. {
  20460. intData -= srcBytesPerSample;
  20461. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20462. }
  20463. }
  20464. }
  20465. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20466. {
  20467. const float scale = 1.0f / 0x7fffff;
  20468. const char* intData = (const char*) source;
  20469. if (source != (void*) dest || srcBytesPerSample >= 4)
  20470. {
  20471. for (int i = 0; i < numSamples; ++i)
  20472. {
  20473. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20474. intData += srcBytesPerSample;
  20475. }
  20476. }
  20477. else
  20478. {
  20479. intData += srcBytesPerSample * numSamples;
  20480. for (int i = numSamples; --i >= 0;)
  20481. {
  20482. intData -= srcBytesPerSample;
  20483. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20484. }
  20485. }
  20486. }
  20487. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20488. {
  20489. const float scale = 1.0f / 0x7fffff;
  20490. const char* intData = (const char*) source;
  20491. if (source != (void*) dest || srcBytesPerSample >= 4)
  20492. {
  20493. for (int i = 0; i < numSamples; ++i)
  20494. {
  20495. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20496. intData += srcBytesPerSample;
  20497. }
  20498. }
  20499. else
  20500. {
  20501. intData += srcBytesPerSample * numSamples;
  20502. for (int i = numSamples; --i >= 0;)
  20503. {
  20504. intData -= srcBytesPerSample;
  20505. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20506. }
  20507. }
  20508. }
  20509. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20510. {
  20511. const float scale = 1.0f / 0x7fffffff;
  20512. const char* intData = (const char*) source;
  20513. if (source != (void*) dest || srcBytesPerSample >= 4)
  20514. {
  20515. for (int i = 0; i < numSamples; ++i)
  20516. {
  20517. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20518. intData += srcBytesPerSample;
  20519. }
  20520. }
  20521. else
  20522. {
  20523. intData += srcBytesPerSample * numSamples;
  20524. for (int i = numSamples; --i >= 0;)
  20525. {
  20526. intData -= srcBytesPerSample;
  20527. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20528. }
  20529. }
  20530. }
  20531. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20532. {
  20533. const float scale = 1.0f / 0x7fffffff;
  20534. const char* intData = (const char*) source;
  20535. if (source != (void*) dest || srcBytesPerSample >= 4)
  20536. {
  20537. for (int i = 0; i < numSamples; ++i)
  20538. {
  20539. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20540. intData += srcBytesPerSample;
  20541. }
  20542. }
  20543. else
  20544. {
  20545. intData += srcBytesPerSample * numSamples;
  20546. for (int i = numSamples; --i >= 0;)
  20547. {
  20548. intData -= srcBytesPerSample;
  20549. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20550. }
  20551. }
  20552. }
  20553. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20554. {
  20555. const char* s = (const char*) source;
  20556. for (int i = 0; i < numSamples; ++i)
  20557. {
  20558. dest[i] = *(float*)s;
  20559. #if JUCE_BIG_ENDIAN
  20560. uint32* const d = (uint32*) (dest + i);
  20561. *d = ByteOrder::swap (*d);
  20562. #endif
  20563. s += srcBytesPerSample;
  20564. }
  20565. }
  20566. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20567. {
  20568. const char* s = (const char*) source;
  20569. for (int i = 0; i < numSamples; ++i)
  20570. {
  20571. dest[i] = *(float*)s;
  20572. #if JUCE_LITTLE_ENDIAN
  20573. uint32* const d = (uint32*) (dest + i);
  20574. *d = ByteOrder::swap (*d);
  20575. #endif
  20576. s += srcBytesPerSample;
  20577. }
  20578. }
  20579. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20580. const float* const source,
  20581. void* const dest,
  20582. const int numSamples)
  20583. {
  20584. switch (destFormat)
  20585. {
  20586. case int16LE:
  20587. convertFloatToInt16LE (source, dest, numSamples);
  20588. break;
  20589. case int16BE:
  20590. convertFloatToInt16BE (source, dest, numSamples);
  20591. break;
  20592. case int24LE:
  20593. convertFloatToInt24LE (source, dest, numSamples);
  20594. break;
  20595. case int24BE:
  20596. convertFloatToInt24BE (source, dest, numSamples);
  20597. break;
  20598. case int32LE:
  20599. convertFloatToInt32LE (source, dest, numSamples);
  20600. break;
  20601. case int32BE:
  20602. convertFloatToInt32BE (source, dest, numSamples);
  20603. break;
  20604. case float32LE:
  20605. convertFloatToFloat32LE (source, dest, numSamples);
  20606. break;
  20607. case float32BE:
  20608. convertFloatToFloat32BE (source, dest, numSamples);
  20609. break;
  20610. default:
  20611. jassertfalse
  20612. break;
  20613. }
  20614. }
  20615. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20616. const void* const source,
  20617. float* const dest,
  20618. const int numSamples)
  20619. {
  20620. switch (sourceFormat)
  20621. {
  20622. case int16LE:
  20623. convertInt16LEToFloat (source, dest, numSamples);
  20624. break;
  20625. case int16BE:
  20626. convertInt16BEToFloat (source, dest, numSamples);
  20627. break;
  20628. case int24LE:
  20629. convertInt24LEToFloat (source, dest, numSamples);
  20630. break;
  20631. case int24BE:
  20632. convertInt24BEToFloat (source, dest, numSamples);
  20633. break;
  20634. case int32LE:
  20635. convertInt32LEToFloat (source, dest, numSamples);
  20636. break;
  20637. case int32BE:
  20638. convertInt32BEToFloat (source, dest, numSamples);
  20639. break;
  20640. case float32LE:
  20641. convertFloat32LEToFloat (source, dest, numSamples);
  20642. break;
  20643. case float32BE:
  20644. convertFloat32BEToFloat (source, dest, numSamples);
  20645. break;
  20646. default:
  20647. jassertfalse
  20648. break;
  20649. }
  20650. }
  20651. void AudioDataConverters::interleaveSamples (const float** const source,
  20652. float* const dest,
  20653. const int numSamples,
  20654. const int numChannels)
  20655. {
  20656. for (int chan = 0; chan < numChannels; ++chan)
  20657. {
  20658. int i = chan;
  20659. const float* src = source [chan];
  20660. for (int j = 0; j < numSamples; ++j)
  20661. {
  20662. dest [i] = src [j];
  20663. i += numChannels;
  20664. }
  20665. }
  20666. }
  20667. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20668. float** const dest,
  20669. const int numSamples,
  20670. const int numChannels)
  20671. {
  20672. for (int chan = 0; chan < numChannels; ++chan)
  20673. {
  20674. int i = chan;
  20675. float* dst = dest [chan];
  20676. for (int j = 0; j < numSamples; ++j)
  20677. {
  20678. dst [j] = source [i];
  20679. i += numChannels;
  20680. }
  20681. }
  20682. }
  20683. END_JUCE_NAMESPACE
  20684. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20685. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20686. BEGIN_JUCE_NAMESPACE
  20687. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20688. const int numSamples) throw()
  20689. : numChannels (numChannels_),
  20690. size (numSamples)
  20691. {
  20692. jassert (numSamples >= 0);
  20693. jassert (numChannels_ > 0);
  20694. allocateData();
  20695. }
  20696. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20697. : numChannels (other.numChannels),
  20698. size (other.size)
  20699. {
  20700. allocateData();
  20701. const size_t numBytes = size * sizeof (float);
  20702. for (int i = 0; i < numChannels; ++i)
  20703. memcpy (channels[i], other.channels[i], numBytes);
  20704. }
  20705. void AudioSampleBuffer::allocateData()
  20706. {
  20707. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20708. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20709. allocatedData.malloc (allocatedBytes);
  20710. channels = (float**) allocatedData;
  20711. float* chan = (float*) (allocatedData + channelListSize);
  20712. for (int i = 0; i < numChannels; ++i)
  20713. {
  20714. channels[i] = chan;
  20715. chan += size;
  20716. }
  20717. channels [numChannels] = 0;
  20718. }
  20719. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20720. const int numChannels_,
  20721. const int numSamples) throw()
  20722. : numChannels (numChannels_),
  20723. size (numSamples),
  20724. allocatedBytes (0)
  20725. {
  20726. jassert (numChannels_ > 0);
  20727. allocateChannels (dataToReferTo);
  20728. }
  20729. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20730. const int newNumChannels,
  20731. const int newNumSamples) throw()
  20732. {
  20733. jassert (newNumChannels > 0);
  20734. allocatedBytes = 0;
  20735. allocatedData.free();
  20736. numChannels = newNumChannels;
  20737. size = newNumSamples;
  20738. allocateChannels (dataToReferTo);
  20739. }
  20740. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20741. {
  20742. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20743. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20744. {
  20745. channels = (float**) preallocatedChannelSpace;
  20746. }
  20747. else
  20748. {
  20749. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20750. channels = (float**) allocatedData;
  20751. }
  20752. for (int i = 0; i < numChannels; ++i)
  20753. {
  20754. // you have to pass in the same number of valid pointers as numChannels
  20755. jassert (dataToReferTo[i] != 0);
  20756. channels[i] = dataToReferTo[i];
  20757. }
  20758. channels [numChannels] = 0;
  20759. }
  20760. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20761. {
  20762. if (this != &other)
  20763. {
  20764. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20765. const size_t numBytes = size * sizeof (float);
  20766. for (int i = 0; i < numChannels; ++i)
  20767. memcpy (channels[i], other.channels[i], numBytes);
  20768. }
  20769. return *this;
  20770. }
  20771. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20772. {
  20773. }
  20774. void AudioSampleBuffer::setSize (const int newNumChannels,
  20775. const int newNumSamples,
  20776. const bool keepExistingContent,
  20777. const bool clearExtraSpace,
  20778. const bool avoidReallocating) throw()
  20779. {
  20780. jassert (newNumChannels > 0);
  20781. if (newNumSamples != size || newNumChannels != numChannels)
  20782. {
  20783. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20784. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20785. if (keepExistingContent)
  20786. {
  20787. HeapBlock <char> newData;
  20788. newData.allocate (newTotalBytes, clearExtraSpace);
  20789. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20790. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20791. float** const newChannels = (float**) newData;
  20792. float* newChan = (float*) (newData + channelListSize);
  20793. for (int i = 0; i < numChansToCopy; ++i)
  20794. {
  20795. memcpy (newChan, channels[i], numBytesToCopy);
  20796. newChannels[i] = newChan;
  20797. newChan += newNumSamples;
  20798. }
  20799. allocatedData.swapWith (newData);
  20800. allocatedBytes = (int) newTotalBytes;
  20801. channels = (float**) allocatedData;
  20802. }
  20803. else
  20804. {
  20805. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20806. {
  20807. if (clearExtraSpace)
  20808. zeromem (allocatedData, newTotalBytes);
  20809. }
  20810. else
  20811. {
  20812. allocatedBytes = newTotalBytes;
  20813. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20814. channels = (float**) allocatedData;
  20815. }
  20816. float* chan = (float*) (allocatedData + channelListSize);
  20817. for (int i = 0; i < newNumChannels; ++i)
  20818. {
  20819. channels[i] = chan;
  20820. chan += newNumSamples;
  20821. }
  20822. }
  20823. channels [newNumChannels] = 0;
  20824. size = newNumSamples;
  20825. numChannels = newNumChannels;
  20826. }
  20827. }
  20828. void AudioSampleBuffer::clear() throw()
  20829. {
  20830. for (int i = 0; i < numChannels; ++i)
  20831. zeromem (channels[i], size * sizeof (float));
  20832. }
  20833. void AudioSampleBuffer::clear (const int startSample,
  20834. const int numSamples) throw()
  20835. {
  20836. jassert (startSample >= 0 && startSample + numSamples <= size);
  20837. for (int i = 0; i < numChannels; ++i)
  20838. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20839. }
  20840. void AudioSampleBuffer::clear (const int channel,
  20841. const int startSample,
  20842. const int numSamples) throw()
  20843. {
  20844. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20845. jassert (startSample >= 0 && startSample + numSamples <= size);
  20846. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20847. }
  20848. void AudioSampleBuffer::applyGain (const int channel,
  20849. const int startSample,
  20850. int numSamples,
  20851. const float gain) throw()
  20852. {
  20853. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20854. jassert (startSample >= 0 && startSample + numSamples <= size);
  20855. if (gain != 1.0f)
  20856. {
  20857. float* d = channels [channel] + startSample;
  20858. if (gain == 0.0f)
  20859. {
  20860. zeromem (d, sizeof (float) * numSamples);
  20861. }
  20862. else
  20863. {
  20864. while (--numSamples >= 0)
  20865. *d++ *= gain;
  20866. }
  20867. }
  20868. }
  20869. void AudioSampleBuffer::applyGainRamp (const int channel,
  20870. const int startSample,
  20871. int numSamples,
  20872. float startGain,
  20873. float endGain) throw()
  20874. {
  20875. if (startGain == endGain)
  20876. {
  20877. applyGain (channel, startSample, numSamples, startGain);
  20878. }
  20879. else
  20880. {
  20881. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20882. jassert (startSample >= 0 && startSample + numSamples <= size);
  20883. const float increment = (endGain - startGain) / numSamples;
  20884. float* d = channels [channel] + startSample;
  20885. while (--numSamples >= 0)
  20886. {
  20887. *d++ *= startGain;
  20888. startGain += increment;
  20889. }
  20890. }
  20891. }
  20892. void AudioSampleBuffer::applyGain (const int startSample,
  20893. const int numSamples,
  20894. const float gain) throw()
  20895. {
  20896. for (int i = 0; i < numChannels; ++i)
  20897. applyGain (i, startSample, numSamples, gain);
  20898. }
  20899. void AudioSampleBuffer::addFrom (const int destChannel,
  20900. const int destStartSample,
  20901. const AudioSampleBuffer& source,
  20902. const int sourceChannel,
  20903. const int sourceStartSample,
  20904. int numSamples,
  20905. const float gain) throw()
  20906. {
  20907. jassert (&source != this || sourceChannel != destChannel);
  20908. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20909. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20910. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20911. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20912. if (gain != 0.0f && numSamples > 0)
  20913. {
  20914. float* d = channels [destChannel] + destStartSample;
  20915. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20916. if (gain != 1.0f)
  20917. {
  20918. while (--numSamples >= 0)
  20919. *d++ += gain * *s++;
  20920. }
  20921. else
  20922. {
  20923. while (--numSamples >= 0)
  20924. *d++ += *s++;
  20925. }
  20926. }
  20927. }
  20928. void AudioSampleBuffer::addFrom (const int destChannel,
  20929. const int destStartSample,
  20930. const float* source,
  20931. int numSamples,
  20932. const float gain) throw()
  20933. {
  20934. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20935. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20936. jassert (source != 0);
  20937. if (gain != 0.0f && numSamples > 0)
  20938. {
  20939. float* d = channels [destChannel] + destStartSample;
  20940. if (gain != 1.0f)
  20941. {
  20942. while (--numSamples >= 0)
  20943. *d++ += gain * *source++;
  20944. }
  20945. else
  20946. {
  20947. while (--numSamples >= 0)
  20948. *d++ += *source++;
  20949. }
  20950. }
  20951. }
  20952. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20953. const int destStartSample,
  20954. const float* source,
  20955. int numSamples,
  20956. float startGain,
  20957. const float endGain) throw()
  20958. {
  20959. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20960. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20961. jassert (source != 0);
  20962. if (startGain == endGain)
  20963. {
  20964. addFrom (destChannel,
  20965. destStartSample,
  20966. source,
  20967. numSamples,
  20968. startGain);
  20969. }
  20970. else
  20971. {
  20972. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20973. {
  20974. const float increment = (endGain - startGain) / numSamples;
  20975. float* d = channels [destChannel] + destStartSample;
  20976. while (--numSamples >= 0)
  20977. {
  20978. *d++ += startGain * *source++;
  20979. startGain += increment;
  20980. }
  20981. }
  20982. }
  20983. }
  20984. void AudioSampleBuffer::copyFrom (const int destChannel,
  20985. const int destStartSample,
  20986. const AudioSampleBuffer& source,
  20987. const int sourceChannel,
  20988. const int sourceStartSample,
  20989. int numSamples) throw()
  20990. {
  20991. jassert (&source != this || sourceChannel != destChannel);
  20992. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20993. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20994. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20995. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20996. if (numSamples > 0)
  20997. {
  20998. memcpy (channels [destChannel] + destStartSample,
  20999. source.channels [sourceChannel] + sourceStartSample,
  21000. sizeof (float) * numSamples);
  21001. }
  21002. }
  21003. void AudioSampleBuffer::copyFrom (const int destChannel,
  21004. const int destStartSample,
  21005. const float* source,
  21006. int numSamples) throw()
  21007. {
  21008. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21009. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21010. jassert (source != 0);
  21011. if (numSamples > 0)
  21012. {
  21013. memcpy (channels [destChannel] + destStartSample,
  21014. source,
  21015. sizeof (float) * numSamples);
  21016. }
  21017. }
  21018. void AudioSampleBuffer::copyFrom (const int destChannel,
  21019. const int destStartSample,
  21020. const float* source,
  21021. int numSamples,
  21022. const float gain) throw()
  21023. {
  21024. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21025. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21026. jassert (source != 0);
  21027. if (numSamples > 0)
  21028. {
  21029. float* d = channels [destChannel] + destStartSample;
  21030. if (gain != 1.0f)
  21031. {
  21032. if (gain == 0)
  21033. {
  21034. zeromem (d, sizeof (float) * numSamples);
  21035. }
  21036. else
  21037. {
  21038. while (--numSamples >= 0)
  21039. *d++ = gain * *source++;
  21040. }
  21041. }
  21042. else
  21043. {
  21044. memcpy (d, source, sizeof (float) * numSamples);
  21045. }
  21046. }
  21047. }
  21048. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  21049. const int destStartSample,
  21050. const float* source,
  21051. int numSamples,
  21052. float startGain,
  21053. float endGain) throw()
  21054. {
  21055. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21056. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21057. jassert (source != 0);
  21058. if (startGain == endGain)
  21059. {
  21060. copyFrom (destChannel,
  21061. destStartSample,
  21062. source,
  21063. numSamples,
  21064. startGain);
  21065. }
  21066. else
  21067. {
  21068. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  21069. {
  21070. const float increment = (endGain - startGain) / numSamples;
  21071. float* d = channels [destChannel] + destStartSample;
  21072. while (--numSamples >= 0)
  21073. {
  21074. *d++ = startGain * *source++;
  21075. startGain += increment;
  21076. }
  21077. }
  21078. }
  21079. }
  21080. void AudioSampleBuffer::findMinMax (const int channel,
  21081. const int startSample,
  21082. int numSamples,
  21083. float& minVal,
  21084. float& maxVal) const throw()
  21085. {
  21086. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21087. jassert (startSample >= 0 && startSample + numSamples <= size);
  21088. if (numSamples <= 0)
  21089. {
  21090. minVal = 0.0f;
  21091. maxVal = 0.0f;
  21092. }
  21093. else
  21094. {
  21095. const float* d = channels [channel] + startSample;
  21096. float mn = *d++;
  21097. float mx = mn;
  21098. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  21099. {
  21100. const float samp = *d++;
  21101. if (samp > mx)
  21102. mx = samp;
  21103. if (samp < mn)
  21104. mn = samp;
  21105. }
  21106. maxVal = mx;
  21107. minVal = mn;
  21108. }
  21109. }
  21110. float AudioSampleBuffer::getMagnitude (const int channel,
  21111. const int startSample,
  21112. const int numSamples) const throw()
  21113. {
  21114. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21115. jassert (startSample >= 0 && startSample + numSamples <= size);
  21116. float mn, mx;
  21117. findMinMax (channel, startSample, numSamples, mn, mx);
  21118. return jmax (mn, -mn, mx, -mx);
  21119. }
  21120. float AudioSampleBuffer::getMagnitude (const int startSample,
  21121. const int numSamples) const throw()
  21122. {
  21123. float mag = 0.0f;
  21124. for (int i = 0; i < numChannels; ++i)
  21125. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21126. return mag;
  21127. }
  21128. float AudioSampleBuffer::getRMSLevel (const int channel,
  21129. const int startSample,
  21130. const int numSamples) const throw()
  21131. {
  21132. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21133. jassert (startSample >= 0 && startSample + numSamples <= size);
  21134. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21135. return 0.0f;
  21136. const float* const data = channels [channel] + startSample;
  21137. double sum = 0.0;
  21138. for (int i = 0; i < numSamples; ++i)
  21139. {
  21140. const float sample = data [i];
  21141. sum += sample * sample;
  21142. }
  21143. return (float) sqrt (sum / numSamples);
  21144. }
  21145. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21146. const int startSample,
  21147. const int numSamples,
  21148. const int readerStartSample,
  21149. const bool useLeftChan,
  21150. const bool useRightChan) throw()
  21151. {
  21152. jassert (reader != 0);
  21153. jassert (startSample >= 0 && startSample + numSamples <= size);
  21154. if (numSamples > 0)
  21155. {
  21156. int* chans[3];
  21157. if (useLeftChan == useRightChan)
  21158. {
  21159. chans[0] = (int*) getSampleData (0, startSample);
  21160. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21161. }
  21162. else if (useLeftChan || (reader->numChannels == 1))
  21163. {
  21164. chans[0] = (int*) getSampleData (0, startSample);
  21165. chans[1] = 0;
  21166. }
  21167. else if (useRightChan)
  21168. {
  21169. chans[0] = 0;
  21170. chans[1] = (int*) getSampleData (0, startSample);
  21171. }
  21172. chans[2] = 0;
  21173. reader->read (chans, 2, readerStartSample, numSamples, true);
  21174. if (! reader->usesFloatingPointData)
  21175. {
  21176. for (int j = 0; j < 2; ++j)
  21177. {
  21178. float* const d = (float*) (chans[j]);
  21179. if (d != 0)
  21180. {
  21181. const float multiplier = 1.0f / 0x7fffffff;
  21182. for (int i = 0; i < numSamples; ++i)
  21183. d[i] = *(int*)(d + i) * multiplier;
  21184. }
  21185. }
  21186. }
  21187. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21188. {
  21189. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21190. memcpy (getSampleData (1, startSample),
  21191. getSampleData (0, startSample),
  21192. sizeof (float) * numSamples);
  21193. }
  21194. }
  21195. }
  21196. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21197. const int startSample,
  21198. const int numSamples) const throw()
  21199. {
  21200. jassert (startSample >= 0 && startSample + numSamples <= size);
  21201. if (numSamples > 0)
  21202. {
  21203. int* chans [3];
  21204. if (writer->isFloatingPoint())
  21205. {
  21206. chans[0] = (int*) getSampleData (0, startSample);
  21207. if (numChannels > 1)
  21208. chans[1] = (int*) getSampleData (1, startSample);
  21209. else
  21210. chans[1] = 0;
  21211. chans[2] = 0;
  21212. writer->write ((const int**) chans, numSamples);
  21213. }
  21214. else
  21215. {
  21216. HeapBlock <int> tempBuffer (numSamples * 2);
  21217. chans[0] = tempBuffer;
  21218. if (numChannels > 1)
  21219. chans[1] = chans[0] + numSamples;
  21220. else
  21221. chans[1] = 0;
  21222. chans[2] = 0;
  21223. for (int j = 0; j < 2; ++j)
  21224. {
  21225. int* const dest = chans[j];
  21226. if (dest != 0)
  21227. {
  21228. const float* const src = channels [j] + startSample;
  21229. for (int i = 0; i < numSamples; ++i)
  21230. {
  21231. const double samp = src[i];
  21232. if (samp <= -1.0)
  21233. dest[i] = std::numeric_limits<int>::min();
  21234. else if (samp >= 1.0)
  21235. dest[i] = std::numeric_limits<int>::max();
  21236. else
  21237. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21238. }
  21239. }
  21240. }
  21241. writer->write ((const int**) chans, numSamples);
  21242. }
  21243. }
  21244. }
  21245. END_JUCE_NAMESPACE
  21246. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21247. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21248. BEGIN_JUCE_NAMESPACE
  21249. IIRFilter::IIRFilter() throw()
  21250. : active (false)
  21251. {
  21252. reset();
  21253. }
  21254. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21255. : active (other.active)
  21256. {
  21257. const ScopedLock sl (other.processLock);
  21258. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21259. reset();
  21260. }
  21261. IIRFilter::~IIRFilter() throw()
  21262. {
  21263. }
  21264. void IIRFilter::reset() throw()
  21265. {
  21266. const ScopedLock sl (processLock);
  21267. x1 = 0;
  21268. x2 = 0;
  21269. y1 = 0;
  21270. y2 = 0;
  21271. }
  21272. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21273. {
  21274. float out = coefficients[0] * in
  21275. + coefficients[1] * x1
  21276. + coefficients[2] * x2
  21277. - coefficients[4] * y1
  21278. - coefficients[5] * y2;
  21279. #if JUCE_INTEL
  21280. if (! (out < -1.0e-8 || out > 1.0e-8))
  21281. out = 0;
  21282. #endif
  21283. x2 = x1;
  21284. x1 = in;
  21285. y2 = y1;
  21286. y1 = out;
  21287. return out;
  21288. }
  21289. void IIRFilter::processSamples (float* const samples,
  21290. const int numSamples) throw()
  21291. {
  21292. const ScopedLock sl (processLock);
  21293. if (active)
  21294. {
  21295. for (int i = 0; i < numSamples; ++i)
  21296. {
  21297. const float in = samples[i];
  21298. float out = coefficients[0] * in
  21299. + coefficients[1] * x1
  21300. + coefficients[2] * x2
  21301. - coefficients[4] * y1
  21302. - coefficients[5] * y2;
  21303. #if JUCE_INTEL
  21304. if (! (out < -1.0e-8 || out > 1.0e-8))
  21305. out = 0;
  21306. #endif
  21307. x2 = x1;
  21308. x1 = in;
  21309. y2 = y1;
  21310. y1 = out;
  21311. samples[i] = out;
  21312. }
  21313. }
  21314. }
  21315. void IIRFilter::makeLowPass (const double sampleRate,
  21316. const double frequency) throw()
  21317. {
  21318. jassert (sampleRate > 0);
  21319. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21320. const double nSquared = n * n;
  21321. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21322. setCoefficients (c1,
  21323. c1 * 2.0f,
  21324. c1,
  21325. 1.0,
  21326. c1 * 2.0 * (1.0 - nSquared),
  21327. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21328. }
  21329. void IIRFilter::makeHighPass (const double sampleRate,
  21330. const double frequency) throw()
  21331. {
  21332. const double n = tan (double_Pi * frequency / sampleRate);
  21333. const double nSquared = n * n;
  21334. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21335. setCoefficients (c1,
  21336. c1 * -2.0f,
  21337. c1,
  21338. 1.0,
  21339. c1 * 2.0 * (nSquared - 1.0),
  21340. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21341. }
  21342. void IIRFilter::makeLowShelf (const double sampleRate,
  21343. const double cutOffFrequency,
  21344. const double Q,
  21345. const float gainFactor) throw()
  21346. {
  21347. jassert (sampleRate > 0);
  21348. jassert (Q > 0);
  21349. const double A = jmax (0.0f, gainFactor);
  21350. const double aminus1 = A - 1.0;
  21351. const double aplus1 = A + 1.0;
  21352. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21353. const double coso = cos (omega);
  21354. const double beta = sin (omega) * sqrt (A) / Q;
  21355. const double aminus1TimesCoso = aminus1 * coso;
  21356. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21357. A * 2.0 * (aminus1 - aplus1 * coso),
  21358. A * (aplus1 - aminus1TimesCoso - beta),
  21359. aplus1 + aminus1TimesCoso + beta,
  21360. -2.0 * (aminus1 + aplus1 * coso),
  21361. aplus1 + aminus1TimesCoso - beta);
  21362. }
  21363. void IIRFilter::makeHighShelf (const double sampleRate,
  21364. const double cutOffFrequency,
  21365. const double Q,
  21366. const float gainFactor) throw()
  21367. {
  21368. jassert (sampleRate > 0);
  21369. jassert (Q > 0);
  21370. const double A = jmax (0.0f, gainFactor);
  21371. const double aminus1 = A - 1.0;
  21372. const double aplus1 = A + 1.0;
  21373. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21374. const double coso = cos (omega);
  21375. const double beta = sin (omega) * sqrt (A) / Q;
  21376. const double aminus1TimesCoso = aminus1 * coso;
  21377. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21378. A * -2.0 * (aminus1 + aplus1 * coso),
  21379. A * (aplus1 + aminus1TimesCoso - beta),
  21380. aplus1 - aminus1TimesCoso + beta,
  21381. 2.0 * (aminus1 - aplus1 * coso),
  21382. aplus1 - aminus1TimesCoso - beta);
  21383. }
  21384. void IIRFilter::makeBandPass (const double sampleRate,
  21385. const double centreFrequency,
  21386. const double Q,
  21387. const float gainFactor) throw()
  21388. {
  21389. jassert (sampleRate > 0);
  21390. jassert (Q > 0);
  21391. const double A = jmax (0.0f, gainFactor);
  21392. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21393. const double alpha = 0.5 * sin (omega) / Q;
  21394. const double c2 = -2.0 * cos (omega);
  21395. const double alphaTimesA = alpha * A;
  21396. const double alphaOverA = alpha / A;
  21397. setCoefficients (1.0 + alphaTimesA,
  21398. c2,
  21399. 1.0 - alphaTimesA,
  21400. 1.0 + alphaOverA,
  21401. c2,
  21402. 1.0 - alphaOverA);
  21403. }
  21404. void IIRFilter::makeInactive() throw()
  21405. {
  21406. const ScopedLock sl (processLock);
  21407. active = false;
  21408. }
  21409. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21410. {
  21411. const ScopedLock sl (processLock);
  21412. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21413. active = other.active;
  21414. }
  21415. void IIRFilter::setCoefficients (double c1,
  21416. double c2,
  21417. double c3,
  21418. double c4,
  21419. double c5,
  21420. double c6) throw()
  21421. {
  21422. const double a = 1.0 / c4;
  21423. c1 *= a;
  21424. c2 *= a;
  21425. c3 *= a;
  21426. c5 *= a;
  21427. c6 *= a;
  21428. const ScopedLock sl (processLock);
  21429. coefficients[0] = (float) c1;
  21430. coefficients[1] = (float) c2;
  21431. coefficients[2] = (float) c3;
  21432. coefficients[3] = (float) c4;
  21433. coefficients[4] = (float) c5;
  21434. coefficients[5] = (float) c6;
  21435. active = true;
  21436. }
  21437. END_JUCE_NAMESPACE
  21438. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21439. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21440. BEGIN_JUCE_NAMESPACE
  21441. MidiBuffer::MidiBuffer() throw()
  21442. : bytesUsed (0)
  21443. {
  21444. }
  21445. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21446. : bytesUsed (0)
  21447. {
  21448. addEvent (message, 0);
  21449. }
  21450. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21451. : data (other.data),
  21452. bytesUsed (other.bytesUsed)
  21453. {
  21454. }
  21455. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21456. {
  21457. bytesUsed = other.bytesUsed;
  21458. data = other.data;
  21459. return *this;
  21460. }
  21461. void MidiBuffer::swap (MidiBuffer& other)
  21462. {
  21463. data.swapWith (other.data);
  21464. swapVariables <int> (bytesUsed, other.bytesUsed);
  21465. }
  21466. MidiBuffer::~MidiBuffer() throw()
  21467. {
  21468. }
  21469. void MidiBuffer::clear() throw()
  21470. {
  21471. bytesUsed = 0;
  21472. }
  21473. void MidiBuffer::clear (const int startSample,
  21474. const int numSamples) throw()
  21475. {
  21476. uint8* const start = findEventAfter (data, startSample - 1);
  21477. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21478. if (end > start)
  21479. {
  21480. const size_t bytesToMove = (size_t) (bytesUsed - (end - (uint8*) data.getData()));
  21481. if (bytesToMove > 0)
  21482. memmove (start, end, bytesToMove);
  21483. bytesUsed -= (int) (end - start);
  21484. }
  21485. }
  21486. void MidiBuffer::addEvent (const MidiMessage& m,
  21487. const int sampleNumber) throw()
  21488. {
  21489. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21490. }
  21491. static int findActualEventLength (const uint8* const data,
  21492. const int maxBytes) throw()
  21493. {
  21494. unsigned int byte = (unsigned int) *data;
  21495. int size = 0;
  21496. if (byte == 0xf0 || byte == 0xf7)
  21497. {
  21498. const uint8* d = data + 1;
  21499. while (d < data + maxBytes)
  21500. if (*d++ == 0xf7)
  21501. break;
  21502. size = (int) (d - data);
  21503. }
  21504. else if (byte == 0xff)
  21505. {
  21506. int n;
  21507. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21508. size = jmin (maxBytes, n + 2 + bytesLeft);
  21509. }
  21510. else if (byte >= 0x80)
  21511. {
  21512. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21513. }
  21514. return size;
  21515. }
  21516. void MidiBuffer::addEvent (const uint8* const newData,
  21517. const int maxBytes,
  21518. const int sampleNumber) throw()
  21519. {
  21520. const int numBytes = findActualEventLength (newData, maxBytes);
  21521. if (numBytes > 0)
  21522. {
  21523. int spaceNeeded = bytesUsed + numBytes + 6;
  21524. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21525. uint8* d = findEventAfter ((uint8*) data.getData(), sampleNumber);
  21526. const size_t bytesToMove = (size_t) (bytesUsed - (d - (uint8*) data.getData()));
  21527. if (bytesToMove > 0)
  21528. memmove (d + numBytes + 6,
  21529. d,
  21530. bytesToMove);
  21531. *(int*) d = sampleNumber;
  21532. d += 4;
  21533. *(uint16*) d = (uint16) numBytes;
  21534. d += 2;
  21535. memcpy (d, newData, numBytes);
  21536. bytesUsed += numBytes + 6;
  21537. }
  21538. }
  21539. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21540. const int startSample,
  21541. const int numSamples,
  21542. const int sampleDeltaToAdd) throw()
  21543. {
  21544. Iterator i (otherBuffer);
  21545. i.setNextSamplePosition (startSample);
  21546. const uint8* eventData;
  21547. int eventSize, position;
  21548. while (i.getNextEvent (eventData, eventSize, position)
  21549. && (position < startSample + numSamples || numSamples < 0))
  21550. {
  21551. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21552. }
  21553. }
  21554. bool MidiBuffer::isEmpty() const throw()
  21555. {
  21556. return bytesUsed == 0;
  21557. }
  21558. int MidiBuffer::getNumEvents() const throw()
  21559. {
  21560. int n = 0;
  21561. const uint8* d = (uint8*) data.getData();
  21562. const uint8* const end = d + bytesUsed;
  21563. while (d < end)
  21564. {
  21565. d += 4;
  21566. d += 2 + *(const uint16*) d;
  21567. ++n;
  21568. }
  21569. return n;
  21570. }
  21571. int MidiBuffer::getFirstEventTime() const throw()
  21572. {
  21573. return (bytesUsed > 0) ? *(const int*) data.getData() : 0;
  21574. }
  21575. int MidiBuffer::getLastEventTime() const throw()
  21576. {
  21577. if (bytesUsed == 0)
  21578. return 0;
  21579. const uint8* d = (uint8*) data.getData();
  21580. const uint8* const endData = d + bytesUsed;
  21581. for (;;)
  21582. {
  21583. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21584. if (nextOne >= endData)
  21585. return *(const int*) d;
  21586. d = nextOne;
  21587. }
  21588. }
  21589. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21590. {
  21591. const uint8* const endData = ((uint8*) data.getData()) + bytesUsed;
  21592. while (d < endData && *(int*) d <= samplePosition)
  21593. {
  21594. d += 4;
  21595. d += 2 + *(uint16*) d;
  21596. }
  21597. return d;
  21598. }
  21599. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21600. : buffer (buffer_),
  21601. data ((uint8*) buffer_.data.getData())
  21602. {
  21603. }
  21604. MidiBuffer::Iterator::~Iterator() throw()
  21605. {
  21606. }
  21607. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21608. {
  21609. data = buffer.data;
  21610. const uint8* dataEnd = ((uint8*) buffer.data.getData()) + buffer.bytesUsed;
  21611. while (data < dataEnd && *(int*) data < samplePosition)
  21612. {
  21613. data += 4;
  21614. data += 2 + *(uint16*) data;
  21615. }
  21616. }
  21617. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21618. int& numBytes,
  21619. int& samplePosition) throw()
  21620. {
  21621. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21622. return false;
  21623. samplePosition = *(int*) data;
  21624. data += 4;
  21625. numBytes = *(uint16*) data;
  21626. data += 2;
  21627. midiData = data;
  21628. data += numBytes;
  21629. return true;
  21630. }
  21631. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21632. int& samplePosition) throw()
  21633. {
  21634. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21635. return false;
  21636. samplePosition = *(int*) data;
  21637. data += 4;
  21638. const int numBytes = *(uint16*) data;
  21639. data += 2;
  21640. result = MidiMessage (data, numBytes, samplePosition);
  21641. data += numBytes;
  21642. return true;
  21643. }
  21644. END_JUCE_NAMESPACE
  21645. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21646. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21647. BEGIN_JUCE_NAMESPACE
  21648. namespace MidiFileHelpers
  21649. {
  21650. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21651. {
  21652. unsigned int buffer = v & 0x7F;
  21653. while ((v >>= 7) != 0)
  21654. {
  21655. buffer <<= 8;
  21656. buffer |= ((v & 0x7F) | 0x80);
  21657. }
  21658. for (;;)
  21659. {
  21660. out.writeByte ((char) buffer);
  21661. if (buffer & 0x80)
  21662. buffer >>= 8;
  21663. else
  21664. break;
  21665. }
  21666. }
  21667. static bool parseMidiHeader (const char* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21668. {
  21669. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21670. data += 4;
  21671. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21672. {
  21673. bool ok = false;
  21674. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21675. {
  21676. for (int i = 0; i < 8; ++i)
  21677. {
  21678. ch = ByteOrder::bigEndianInt (data);
  21679. data += 4;
  21680. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21681. {
  21682. ok = true;
  21683. break;
  21684. }
  21685. }
  21686. }
  21687. if (! ok)
  21688. return false;
  21689. }
  21690. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21691. data += 4;
  21692. fileType = (short) ByteOrder::bigEndianShort (data);
  21693. data += 2;
  21694. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21695. data += 2;
  21696. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21697. data += 2;
  21698. bytesRemaining -= 6;
  21699. data += bytesRemaining;
  21700. return true;
  21701. }
  21702. static double convertTicksToSeconds (const double time,
  21703. const MidiMessageSequence& tempoEvents,
  21704. const int timeFormat)
  21705. {
  21706. if (timeFormat > 0)
  21707. {
  21708. int numer = 4, denom = 4;
  21709. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21710. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21711. double secsPerTick = 0.5 * tickLen;
  21712. const int numEvents = tempoEvents.getNumEvents();
  21713. for (int i = 0; i < numEvents; ++i)
  21714. {
  21715. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21716. if (time <= m.getTimeStamp())
  21717. break;
  21718. if (timeFormat > 0)
  21719. {
  21720. correctedTempoTime = correctedTempoTime
  21721. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21722. }
  21723. else
  21724. {
  21725. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21726. }
  21727. tempoTime = m.getTimeStamp();
  21728. if (m.isTempoMetaEvent())
  21729. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21730. else if (m.isTimeSignatureMetaEvent())
  21731. m.getTimeSignatureInfo (numer, denom);
  21732. while (i + 1 < numEvents)
  21733. {
  21734. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21735. if (m2.getTimeStamp() == tempoTime)
  21736. {
  21737. ++i;
  21738. if (m2.isTempoMetaEvent())
  21739. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21740. else if (m2.isTimeSignatureMetaEvent())
  21741. m2.getTimeSignatureInfo (numer, denom);
  21742. }
  21743. else
  21744. {
  21745. break;
  21746. }
  21747. }
  21748. }
  21749. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21750. }
  21751. else
  21752. {
  21753. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21754. }
  21755. }
  21756. }
  21757. MidiFile::MidiFile() throw()
  21758. : timeFormat ((short) (unsigned short) 0xe728)
  21759. {
  21760. }
  21761. MidiFile::~MidiFile() throw()
  21762. {
  21763. clear();
  21764. }
  21765. void MidiFile::clear() throw()
  21766. {
  21767. tracks.clear();
  21768. }
  21769. int MidiFile::getNumTracks() const throw()
  21770. {
  21771. return tracks.size();
  21772. }
  21773. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21774. {
  21775. return tracks [index];
  21776. }
  21777. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21778. {
  21779. tracks.add (new MidiMessageSequence (trackSequence));
  21780. }
  21781. short MidiFile::getTimeFormat() const throw()
  21782. {
  21783. return timeFormat;
  21784. }
  21785. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21786. {
  21787. timeFormat = (short)ticks;
  21788. }
  21789. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21790. const int subframeResolution) throw()
  21791. {
  21792. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21793. }
  21794. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21795. {
  21796. for (int i = tracks.size(); --i >= 0;)
  21797. {
  21798. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21799. for (int j = 0; j < numEvents; ++j)
  21800. {
  21801. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21802. if (m.isTempoMetaEvent())
  21803. tempoChangeEvents.addEvent (m);
  21804. }
  21805. }
  21806. }
  21807. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21808. {
  21809. for (int i = tracks.size(); --i >= 0;)
  21810. {
  21811. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21812. for (int j = 0; j < numEvents; ++j)
  21813. {
  21814. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21815. if (m.isTimeSignatureMetaEvent())
  21816. timeSigEvents.addEvent (m);
  21817. }
  21818. }
  21819. }
  21820. double MidiFile::getLastTimestamp() const
  21821. {
  21822. double t = 0.0;
  21823. for (int i = tracks.size(); --i >= 0;)
  21824. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21825. return t;
  21826. }
  21827. bool MidiFile::readFrom (InputStream& sourceStream)
  21828. {
  21829. clear();
  21830. MemoryBlock data;
  21831. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21832. // (put a sanity-check on the file size, as midi files are generally small)
  21833. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21834. {
  21835. size_t size = data.getSize();
  21836. const char* d = (char*) data.getData();
  21837. short fileType, expectedTracks;
  21838. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21839. {
  21840. size -= (int) (d - (char*) data.getData());
  21841. int track = 0;
  21842. while (size > 0 && track < expectedTracks)
  21843. {
  21844. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21845. d += 4;
  21846. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21847. d += 4;
  21848. if (chunkSize <= 0)
  21849. break;
  21850. if (size < 0)
  21851. return false;
  21852. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21853. {
  21854. readNextTrack (d, chunkSize);
  21855. }
  21856. size -= chunkSize + 8;
  21857. d += chunkSize;
  21858. ++track;
  21859. }
  21860. return true;
  21861. }
  21862. }
  21863. return false;
  21864. }
  21865. // a comparator that puts all the note-offs before note-ons that have the same time
  21866. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21867. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21868. {
  21869. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21870. if (diff == 0)
  21871. {
  21872. if (first->message.isNoteOff() && second->message.isNoteOn())
  21873. return -1;
  21874. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21875. return 1;
  21876. else
  21877. return 0;
  21878. }
  21879. else
  21880. {
  21881. return (diff > 0) ? 1 : -1;
  21882. }
  21883. }
  21884. void MidiFile::readNextTrack (const char* data, int size)
  21885. {
  21886. double time = 0;
  21887. char lastStatusByte = 0;
  21888. MidiMessageSequence result;
  21889. while (size > 0)
  21890. {
  21891. int bytesUsed;
  21892. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21893. data += bytesUsed;
  21894. size -= bytesUsed;
  21895. time += delay;
  21896. int messSize = 0;
  21897. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21898. if (messSize <= 0)
  21899. break;
  21900. size -= messSize;
  21901. data += messSize;
  21902. result.addEvent (mm);
  21903. const char firstByte = *(mm.getRawData());
  21904. if ((firstByte & 0xf0) != 0xf0)
  21905. lastStatusByte = firstByte;
  21906. }
  21907. // use a sort that puts all the note-offs before note-ons that have the same time
  21908. result.list.sort (*this, true);
  21909. result.updateMatchedPairs();
  21910. addTrack (result);
  21911. }
  21912. void MidiFile::convertTimestampTicksToSeconds()
  21913. {
  21914. MidiMessageSequence tempoEvents;
  21915. findAllTempoEvents (tempoEvents);
  21916. findAllTimeSigEvents (tempoEvents);
  21917. for (int i = 0; i < tracks.size(); ++i)
  21918. {
  21919. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21920. for (int j = ms.getNumEvents(); --j >= 0;)
  21921. {
  21922. MidiMessage& m = ms.getEventPointer(j)->message;
  21923. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21924. tempoEvents,
  21925. timeFormat));
  21926. }
  21927. }
  21928. }
  21929. bool MidiFile::writeTo (OutputStream& out)
  21930. {
  21931. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21932. out.writeIntBigEndian (6);
  21933. out.writeShortBigEndian (1); // type
  21934. out.writeShortBigEndian ((short) tracks.size());
  21935. out.writeShortBigEndian (timeFormat);
  21936. for (int i = 0; i < tracks.size(); ++i)
  21937. writeTrack (out, i);
  21938. out.flush();
  21939. return true;
  21940. }
  21941. void MidiFile::writeTrack (OutputStream& mainOut,
  21942. const int trackNum)
  21943. {
  21944. MemoryOutputStream out;
  21945. const MidiMessageSequence& ms = *tracks[trackNum];
  21946. int lastTick = 0;
  21947. char lastStatusByte = 0;
  21948. for (int i = 0; i < ms.getNumEvents(); ++i)
  21949. {
  21950. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21951. const int tick = roundToInt (mm.getTimeStamp());
  21952. const int delta = jmax (0, tick - lastTick);
  21953. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21954. lastTick = tick;
  21955. const char statusByte = *(mm.getRawData());
  21956. if ((statusByte == lastStatusByte)
  21957. && ((statusByte & 0xf0) != 0xf0)
  21958. && i > 0
  21959. && mm.getRawDataSize() > 1)
  21960. {
  21961. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21962. }
  21963. else
  21964. {
  21965. out.write (mm.getRawData(), mm.getRawDataSize());
  21966. }
  21967. lastStatusByte = statusByte;
  21968. }
  21969. out.writeByte (0);
  21970. const MidiMessage m (MidiMessage::endOfTrack());
  21971. out.write (m.getRawData(),
  21972. m.getRawDataSize());
  21973. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21974. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21975. mainOut.write (out.getData(), (int) out.getDataSize());
  21976. }
  21977. END_JUCE_NAMESPACE
  21978. /*** End of inlined file: juce_MidiFile.cpp ***/
  21979. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21980. BEGIN_JUCE_NAMESPACE
  21981. MidiKeyboardState::MidiKeyboardState()
  21982. {
  21983. zeromem (noteStates, sizeof (noteStates));
  21984. }
  21985. MidiKeyboardState::~MidiKeyboardState()
  21986. {
  21987. }
  21988. void MidiKeyboardState::reset()
  21989. {
  21990. const ScopedLock sl (lock);
  21991. zeromem (noteStates, sizeof (noteStates));
  21992. eventsToAdd.clear();
  21993. }
  21994. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21995. {
  21996. jassert (midiChannel >= 0 && midiChannel <= 16);
  21997. return ((unsigned int) n) < 128
  21998. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21999. }
  22000. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  22001. {
  22002. return ((unsigned int) n) < 128
  22003. && (noteStates[n] & midiChannelMask) != 0;
  22004. }
  22005. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  22006. {
  22007. jassert (midiChannel >= 0 && midiChannel <= 16);
  22008. jassert (((unsigned int) midiNoteNumber) < 128);
  22009. const ScopedLock sl (lock);
  22010. if (((unsigned int) midiNoteNumber) < 128)
  22011. {
  22012. const int timeNow = (int) Time::getMillisecondCounter();
  22013. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  22014. eventsToAdd.clear (0, timeNow - 500);
  22015. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  22016. }
  22017. }
  22018. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  22019. {
  22020. if (((unsigned int) midiNoteNumber) < 128)
  22021. {
  22022. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  22023. for (int i = listeners.size(); --i >= 0;)
  22024. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22025. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  22026. }
  22027. }
  22028. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  22029. {
  22030. const ScopedLock sl (lock);
  22031. if (isNoteOn (midiChannel, midiNoteNumber))
  22032. {
  22033. const int timeNow = (int) Time::getMillisecondCounter();
  22034. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  22035. eventsToAdd.clear (0, timeNow - 500);
  22036. noteOffInternal (midiChannel, midiNoteNumber);
  22037. }
  22038. }
  22039. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  22040. {
  22041. if (isNoteOn (midiChannel, midiNoteNumber))
  22042. {
  22043. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  22044. for (int i = listeners.size(); --i >= 0;)
  22045. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22046. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  22047. }
  22048. }
  22049. void MidiKeyboardState::allNotesOff (const int midiChannel)
  22050. {
  22051. const ScopedLock sl (lock);
  22052. if (midiChannel <= 0)
  22053. {
  22054. for (int i = 1; i <= 16; ++i)
  22055. allNotesOff (i);
  22056. }
  22057. else
  22058. {
  22059. for (int i = 0; i < 128; ++i)
  22060. noteOff (midiChannel, i);
  22061. }
  22062. }
  22063. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  22064. {
  22065. if (message.isNoteOn())
  22066. {
  22067. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  22068. }
  22069. else if (message.isNoteOff())
  22070. {
  22071. noteOffInternal (message.getChannel(), message.getNoteNumber());
  22072. }
  22073. else if (message.isAllNotesOff())
  22074. {
  22075. for (int i = 0; i < 128; ++i)
  22076. noteOffInternal (message.getChannel(), i);
  22077. }
  22078. }
  22079. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  22080. const int startSample,
  22081. const int numSamples,
  22082. const bool injectIndirectEvents)
  22083. {
  22084. MidiBuffer::Iterator i (buffer);
  22085. MidiMessage message (0xf4, 0.0);
  22086. int time;
  22087. const ScopedLock sl (lock);
  22088. while (i.getNextEvent (message, time))
  22089. processNextMidiEvent (message);
  22090. if (injectIndirectEvents)
  22091. {
  22092. MidiBuffer::Iterator i2 (eventsToAdd);
  22093. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  22094. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  22095. while (i2.getNextEvent (message, time))
  22096. {
  22097. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  22098. buffer.addEvent (message, startSample + pos);
  22099. }
  22100. }
  22101. eventsToAdd.clear();
  22102. }
  22103. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22104. {
  22105. const ScopedLock sl (lock);
  22106. listeners.addIfNotAlreadyThere (listener);
  22107. }
  22108. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22109. {
  22110. const ScopedLock sl (lock);
  22111. listeners.removeValue (listener);
  22112. }
  22113. END_JUCE_NAMESPACE
  22114. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  22115. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  22116. BEGIN_JUCE_NAMESPACE
  22117. int MidiMessage::readVariableLengthVal (const uint8* data,
  22118. int& numBytesUsed) throw()
  22119. {
  22120. numBytesUsed = 0;
  22121. int v = 0;
  22122. int i;
  22123. do
  22124. {
  22125. i = (int) *data++;
  22126. if (++numBytesUsed > 6)
  22127. break;
  22128. v = (v << 7) + (i & 0x7f);
  22129. } while (i & 0x80);
  22130. return v;
  22131. }
  22132. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22133. {
  22134. // this method only works for valid starting bytes of a short midi message
  22135. jassert (firstByte >= 0x80
  22136. && firstByte != 0xf0
  22137. && firstByte != 0xf7);
  22138. static const char messageLengths[] =
  22139. {
  22140. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22141. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22142. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22143. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22144. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22145. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22146. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22147. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22148. };
  22149. return messageLengths [firstByte & 0x7f];
  22150. }
  22151. MidiMessage::MidiMessage (const uint8* const d,
  22152. const int dataSize,
  22153. const double t) throw()
  22154. : timeStamp (t),
  22155. message (0),
  22156. size (dataSize)
  22157. {
  22158. jassert (dataSize > 0);
  22159. if (dataSize <= 4)
  22160. data = (uint8*) &message;
  22161. else
  22162. data = (uint8*) juce_malloc (dataSize);
  22163. memcpy (data, d, dataSize);
  22164. // check that the length matches the data..
  22165. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22166. }
  22167. MidiMessage::MidiMessage (const int byte1,
  22168. const double t) throw()
  22169. : timeStamp (t),
  22170. data ((uint8*) &message),
  22171. size (1)
  22172. {
  22173. data[0] = (uint8) byte1;
  22174. // check that the length matches the data..
  22175. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22176. }
  22177. MidiMessage::MidiMessage (const int byte1,
  22178. const int byte2,
  22179. const double t) throw()
  22180. : timeStamp (t),
  22181. data ((uint8*) &message),
  22182. size (2)
  22183. {
  22184. data[0] = (uint8) byte1;
  22185. data[1] = (uint8) byte2;
  22186. // check that the length matches the data..
  22187. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22188. }
  22189. MidiMessage::MidiMessage (const int byte1,
  22190. const int byte2,
  22191. const int byte3,
  22192. const double t) throw()
  22193. : timeStamp (t),
  22194. data ((uint8*) &message),
  22195. size (3)
  22196. {
  22197. data[0] = (uint8) byte1;
  22198. data[1] = (uint8) byte2;
  22199. data[2] = (uint8) byte3;
  22200. // check that the length matches the data..
  22201. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22202. }
  22203. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22204. : timeStamp (other.timeStamp),
  22205. message (other.message),
  22206. size (other.size)
  22207. {
  22208. if (other.data != (uint8*) &other.message)
  22209. {
  22210. data = (uint8*) juce_malloc (size);
  22211. memcpy (data, other.data, size);
  22212. }
  22213. else
  22214. {
  22215. data = (uint8*) &message;
  22216. }
  22217. }
  22218. MidiMessage::MidiMessage (const MidiMessage& other,
  22219. const double newTimeStamp) throw()
  22220. : timeStamp (newTimeStamp),
  22221. message (other.message),
  22222. size (other.size)
  22223. {
  22224. if (other.data != (uint8*) &other.message)
  22225. {
  22226. data = (uint8*) juce_malloc (size);
  22227. memcpy (data, other.data, size);
  22228. }
  22229. else
  22230. {
  22231. data = (uint8*) &message;
  22232. }
  22233. }
  22234. MidiMessage::MidiMessage (const uint8* src,
  22235. int sz,
  22236. int& numBytesUsed,
  22237. const uint8 lastStatusByte,
  22238. double t) throw()
  22239. : timeStamp (t),
  22240. data ((uint8*) &message),
  22241. message (0)
  22242. {
  22243. unsigned int byte = (unsigned int) *src;
  22244. if (byte < 0x80)
  22245. {
  22246. byte = (unsigned int) (uint8) lastStatusByte;
  22247. numBytesUsed = -1;
  22248. }
  22249. else
  22250. {
  22251. numBytesUsed = 0;
  22252. --sz;
  22253. ++src;
  22254. }
  22255. if (byte >= 0x80)
  22256. {
  22257. if (byte == 0xf0)
  22258. {
  22259. const uint8* d = (const uint8*) src;
  22260. while (d < src + sz)
  22261. {
  22262. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22263. {
  22264. if (*d == 0xf7) // include an 0xf7 if we hit one
  22265. ++d;
  22266. break;
  22267. }
  22268. ++d;
  22269. }
  22270. size = 1 + (int) (d - src);
  22271. data = (uint8*) juce_malloc (size);
  22272. *data = (uint8) byte;
  22273. memcpy (data + 1, src, size - 1);
  22274. }
  22275. else if (byte == 0xff)
  22276. {
  22277. int n;
  22278. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22279. size = jmin (sz + 1, n + 2 + bytesLeft);
  22280. data = (uint8*) juce_malloc (size);
  22281. *data = (uint8) byte;
  22282. memcpy (data + 1, src, size - 1);
  22283. }
  22284. else
  22285. {
  22286. size = getMessageLengthFromFirstByte ((uint8) byte);
  22287. *data = (uint8) byte;
  22288. if (size > 1)
  22289. {
  22290. data[1] = src[0];
  22291. if (size > 2)
  22292. data[2] = src[1];
  22293. }
  22294. }
  22295. numBytesUsed += size;
  22296. }
  22297. else
  22298. {
  22299. message = 0;
  22300. size = 0;
  22301. }
  22302. }
  22303. MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22304. {
  22305. if (this != &other)
  22306. {
  22307. timeStamp = other.timeStamp;
  22308. size = other.size;
  22309. message = other.message;
  22310. if (data != (uint8*) &message)
  22311. juce_free (data);
  22312. if (other.data != (uint8*) &other.message)
  22313. {
  22314. data = (uint8*) juce_malloc (size);
  22315. memcpy (data, other.data, size);
  22316. }
  22317. else
  22318. {
  22319. data = (uint8*) &message;
  22320. }
  22321. }
  22322. return *this;
  22323. }
  22324. MidiMessage::~MidiMessage() throw()
  22325. {
  22326. if (data != (uint8*) &message)
  22327. juce_free (data);
  22328. }
  22329. int MidiMessage::getChannel() const throw()
  22330. {
  22331. if ((data[0] & 0xf0) != 0xf0)
  22332. return (data[0] & 0xf) + 1;
  22333. else
  22334. return 0;
  22335. }
  22336. bool MidiMessage::isForChannel (const int channel) const throw()
  22337. {
  22338. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22339. return ((data[0] & 0xf) == channel - 1)
  22340. && ((data[0] & 0xf0) != 0xf0);
  22341. }
  22342. void MidiMessage::setChannel (const int channel) throw()
  22343. {
  22344. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22345. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22346. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22347. | (uint8)(channel - 1));
  22348. }
  22349. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22350. {
  22351. return ((data[0] & 0xf0) == 0x90)
  22352. && (returnTrueForVelocity0 || data[2] != 0);
  22353. }
  22354. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22355. {
  22356. return ((data[0] & 0xf0) == 0x80)
  22357. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22358. }
  22359. bool MidiMessage::isNoteOnOrOff() const throw()
  22360. {
  22361. const int d = data[0] & 0xf0;
  22362. return (d == 0x90) || (d == 0x80);
  22363. }
  22364. int MidiMessage::getNoteNumber() const throw()
  22365. {
  22366. return data[1];
  22367. }
  22368. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22369. {
  22370. if (isNoteOnOrOff())
  22371. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22372. }
  22373. uint8 MidiMessage::getVelocity() const throw()
  22374. {
  22375. if (isNoteOnOrOff())
  22376. return data[2];
  22377. else
  22378. return 0;
  22379. }
  22380. float MidiMessage::getFloatVelocity() const throw()
  22381. {
  22382. return getVelocity() * (1.0f / 127.0f);
  22383. }
  22384. void MidiMessage::setVelocity (const float newVelocity) throw()
  22385. {
  22386. if (isNoteOnOrOff())
  22387. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22388. }
  22389. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22390. {
  22391. if (isNoteOnOrOff())
  22392. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22393. }
  22394. bool MidiMessage::isAftertouch() const throw()
  22395. {
  22396. return (data[0] & 0xf0) == 0xa0;
  22397. }
  22398. int MidiMessage::getAfterTouchValue() const throw()
  22399. {
  22400. return data[2];
  22401. }
  22402. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22403. const int noteNum,
  22404. const int aftertouchValue) throw()
  22405. {
  22406. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22407. jassert (((unsigned int) noteNum) <= 127);
  22408. jassert (((unsigned int) aftertouchValue) <= 127);
  22409. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22410. noteNum & 0x7f,
  22411. aftertouchValue & 0x7f);
  22412. }
  22413. bool MidiMessage::isChannelPressure() const throw()
  22414. {
  22415. return (data[0] & 0xf0) == 0xd0;
  22416. }
  22417. int MidiMessage::getChannelPressureValue() const throw()
  22418. {
  22419. jassert (isChannelPressure());
  22420. return data[1];
  22421. }
  22422. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22423. const int pressure) throw()
  22424. {
  22425. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22426. jassert (((unsigned int) pressure) <= 127);
  22427. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22428. pressure & 0x7f);
  22429. }
  22430. bool MidiMessage::isProgramChange() const throw()
  22431. {
  22432. return (data[0] & 0xf0) == 0xc0;
  22433. }
  22434. int MidiMessage::getProgramChangeNumber() const throw()
  22435. {
  22436. return data[1];
  22437. }
  22438. const MidiMessage MidiMessage::programChange (const int channel,
  22439. const int programNumber) throw()
  22440. {
  22441. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22442. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22443. programNumber & 0x7f);
  22444. }
  22445. bool MidiMessage::isPitchWheel() const throw()
  22446. {
  22447. return (data[0] & 0xf0) == 0xe0;
  22448. }
  22449. int MidiMessage::getPitchWheelValue() const throw()
  22450. {
  22451. return data[1] | (data[2] << 7);
  22452. }
  22453. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22454. const int position) throw()
  22455. {
  22456. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22457. jassert (((unsigned int) position) <= 0x3fff);
  22458. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22459. position & 127,
  22460. (position >> 7) & 127);
  22461. }
  22462. bool MidiMessage::isController() const throw()
  22463. {
  22464. return (data[0] & 0xf0) == 0xb0;
  22465. }
  22466. int MidiMessage::getControllerNumber() const throw()
  22467. {
  22468. jassert (isController());
  22469. return data[1];
  22470. }
  22471. int MidiMessage::getControllerValue() const throw()
  22472. {
  22473. jassert (isController());
  22474. return data[2];
  22475. }
  22476. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22477. const int controllerType,
  22478. const int value) throw()
  22479. {
  22480. // the channel must be between 1 and 16 inclusive
  22481. jassert (channel > 0 && channel <= 16);
  22482. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22483. controllerType & 127,
  22484. value & 127);
  22485. }
  22486. const MidiMessage MidiMessage::noteOn (const int channel,
  22487. const int noteNumber,
  22488. const float velocity) throw()
  22489. {
  22490. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22491. }
  22492. const MidiMessage MidiMessage::noteOn (const int channel,
  22493. const int noteNumber,
  22494. const uint8 velocity) throw()
  22495. {
  22496. jassert (channel > 0 && channel <= 16);
  22497. jassert (((unsigned int) noteNumber) <= 127);
  22498. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22499. noteNumber & 127,
  22500. jlimit (0, 127, roundToInt (velocity)));
  22501. }
  22502. const MidiMessage MidiMessage::noteOff (const int channel,
  22503. const int noteNumber) throw()
  22504. {
  22505. jassert (channel > 0 && channel <= 16);
  22506. jassert (((unsigned int) noteNumber) <= 127);
  22507. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22508. }
  22509. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22510. {
  22511. jassert (channel > 0 && channel <= 16);
  22512. return controllerEvent (channel, 123, 0);
  22513. }
  22514. bool MidiMessage::isAllNotesOff() const throw()
  22515. {
  22516. return (data[0] & 0xf0) == 0xb0
  22517. && data[1] == 123;
  22518. }
  22519. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22520. {
  22521. return controllerEvent (channel, 120, 0);
  22522. }
  22523. bool MidiMessage::isAllSoundOff() const throw()
  22524. {
  22525. return (data[0] & 0xf0) == 0xb0
  22526. && data[1] == 120;
  22527. }
  22528. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22529. {
  22530. return controllerEvent (channel, 121, 0);
  22531. }
  22532. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22533. {
  22534. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22535. uint8 buf[8];
  22536. buf[0] = 0xf0;
  22537. buf[1] = 0x7f;
  22538. buf[2] = 0x7f;
  22539. buf[3] = 0x04;
  22540. buf[4] = 0x01;
  22541. buf[5] = (uint8) (vol & 0x7f);
  22542. buf[6] = (uint8) (vol >> 7);
  22543. buf[7] = 0xf7;
  22544. return MidiMessage (buf, 8);
  22545. }
  22546. bool MidiMessage::isSysEx() const throw()
  22547. {
  22548. return *data == 0xf0;
  22549. }
  22550. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22551. const int dataSize) throw()
  22552. {
  22553. MemoryBlock mm (dataSize + 2);
  22554. uint8* const m = (uint8*) mm.getData();
  22555. m[0] = 0xf0;
  22556. memcpy (m + 1, sysexData, dataSize);
  22557. m[dataSize + 1] = 0xf7;
  22558. return MidiMessage (m, dataSize + 2);
  22559. }
  22560. const uint8* MidiMessage::getSysExData() const throw()
  22561. {
  22562. return (isSysEx()) ? getRawData() + 1
  22563. : 0;
  22564. }
  22565. int MidiMessage::getSysExDataSize() const throw()
  22566. {
  22567. return (isSysEx()) ? size - 2
  22568. : 0;
  22569. }
  22570. bool MidiMessage::isMetaEvent() const throw()
  22571. {
  22572. return *data == 0xff;
  22573. }
  22574. bool MidiMessage::isActiveSense() const throw()
  22575. {
  22576. return *data == 0xfe;
  22577. }
  22578. int MidiMessage::getMetaEventType() const throw()
  22579. {
  22580. if (*data != 0xff)
  22581. return -1;
  22582. else
  22583. return data[1];
  22584. }
  22585. int MidiMessage::getMetaEventLength() const throw()
  22586. {
  22587. if (*data == 0xff)
  22588. {
  22589. int n;
  22590. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22591. }
  22592. return 0;
  22593. }
  22594. const uint8* MidiMessage::getMetaEventData() const throw()
  22595. {
  22596. int n;
  22597. const uint8* d = data + 2;
  22598. readVariableLengthVal (d, n);
  22599. return d + n;
  22600. }
  22601. bool MidiMessage::isTrackMetaEvent() const throw()
  22602. {
  22603. return getMetaEventType() == 0;
  22604. }
  22605. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22606. {
  22607. return getMetaEventType() == 47;
  22608. }
  22609. bool MidiMessage::isTextMetaEvent() const throw()
  22610. {
  22611. const int t = getMetaEventType();
  22612. return t > 0 && t < 16;
  22613. }
  22614. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22615. {
  22616. return String ((const char*) getMetaEventData(),
  22617. getMetaEventLength());
  22618. }
  22619. bool MidiMessage::isTrackNameEvent() const throw()
  22620. {
  22621. return (data[1] == 3)
  22622. && (*data == 0xff);
  22623. }
  22624. bool MidiMessage::isTempoMetaEvent() const throw()
  22625. {
  22626. return (data[1] == 81)
  22627. && (*data == 0xff);
  22628. }
  22629. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22630. {
  22631. return (data[1] == 0x20)
  22632. && (*data == 0xff)
  22633. && (data[2] == 1);
  22634. }
  22635. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22636. {
  22637. return data[3] + 1;
  22638. }
  22639. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22640. {
  22641. if (! isTempoMetaEvent())
  22642. return 0.0;
  22643. const uint8* const d = getMetaEventData();
  22644. return (((unsigned int) d[0] << 16)
  22645. | ((unsigned int) d[1] << 8)
  22646. | d[2])
  22647. / 1000000.0;
  22648. }
  22649. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22650. {
  22651. if (timeFormat > 0)
  22652. {
  22653. if (! isTempoMetaEvent())
  22654. return 0.5 / timeFormat;
  22655. return getTempoSecondsPerQuarterNote() / timeFormat;
  22656. }
  22657. else
  22658. {
  22659. const int frameCode = (-timeFormat) >> 8;
  22660. double framesPerSecond;
  22661. switch (frameCode)
  22662. {
  22663. case 24: framesPerSecond = 24.0; break;
  22664. case 25: framesPerSecond = 25.0; break;
  22665. case 29: framesPerSecond = 29.97; break;
  22666. case 30: framesPerSecond = 30.0; break;
  22667. default: framesPerSecond = 30.0; break;
  22668. }
  22669. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22670. }
  22671. }
  22672. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22673. {
  22674. uint8 d[8];
  22675. d[0] = 0xff;
  22676. d[1] = 81;
  22677. d[2] = 3;
  22678. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22679. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22680. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22681. return MidiMessage (d, 6, 0.0);
  22682. }
  22683. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22684. {
  22685. return (data[1] == 0x58)
  22686. && (*data == (uint8) 0xff);
  22687. }
  22688. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22689. int& denominator) const throw()
  22690. {
  22691. if (isTimeSignatureMetaEvent())
  22692. {
  22693. const uint8* const d = getMetaEventData();
  22694. numerator = d[0];
  22695. denominator = 1 << d[1];
  22696. }
  22697. else
  22698. {
  22699. numerator = 4;
  22700. denominator = 4;
  22701. }
  22702. }
  22703. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22704. const int denominator) throw()
  22705. {
  22706. uint8 d[8];
  22707. d[0] = 0xff;
  22708. d[1] = 0x58;
  22709. d[2] = 0x04;
  22710. d[3] = (uint8) numerator;
  22711. int n = 1;
  22712. int powerOfTwo = 0;
  22713. while (n < denominator)
  22714. {
  22715. n <<= 1;
  22716. ++powerOfTwo;
  22717. }
  22718. d[4] = (uint8) powerOfTwo;
  22719. d[5] = 0x01;
  22720. d[6] = 96;
  22721. return MidiMessage (d, 7, 0.0);
  22722. }
  22723. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22724. {
  22725. uint8 d[8];
  22726. d[0] = 0xff;
  22727. d[1] = 0x20;
  22728. d[2] = 0x01;
  22729. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22730. return MidiMessage (d, 4, 0.0);
  22731. }
  22732. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22733. {
  22734. return getMetaEventType() == 89;
  22735. }
  22736. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22737. {
  22738. return (int) *getMetaEventData();
  22739. }
  22740. const MidiMessage MidiMessage::endOfTrack() throw()
  22741. {
  22742. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22743. }
  22744. bool MidiMessage::isSongPositionPointer() const throw()
  22745. {
  22746. return *data == 0xf2;
  22747. }
  22748. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22749. {
  22750. return data[1] | (data[2] << 7);
  22751. }
  22752. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22753. {
  22754. return MidiMessage (0xf2,
  22755. positionInMidiBeats & 127,
  22756. (positionInMidiBeats >> 7) & 127);
  22757. }
  22758. bool MidiMessage::isMidiStart() const throw()
  22759. {
  22760. return *data == 0xfa;
  22761. }
  22762. const MidiMessage MidiMessage::midiStart() throw()
  22763. {
  22764. return MidiMessage (0xfa);
  22765. }
  22766. bool MidiMessage::isMidiContinue() const throw()
  22767. {
  22768. return *data == 0xfb;
  22769. }
  22770. const MidiMessage MidiMessage::midiContinue() throw()
  22771. {
  22772. return MidiMessage (0xfb);
  22773. }
  22774. bool MidiMessage::isMidiStop() const throw()
  22775. {
  22776. return *data == 0xfc;
  22777. }
  22778. const MidiMessage MidiMessage::midiStop() throw()
  22779. {
  22780. return MidiMessage (0xfc);
  22781. }
  22782. bool MidiMessage::isMidiClock() const throw()
  22783. {
  22784. return *data == 0xf8;
  22785. }
  22786. const MidiMessage MidiMessage::midiClock() throw()
  22787. {
  22788. return MidiMessage (0xf8);
  22789. }
  22790. bool MidiMessage::isQuarterFrame() const throw()
  22791. {
  22792. return *data == 0xf1;
  22793. }
  22794. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22795. {
  22796. return ((int) data[1]) >> 4;
  22797. }
  22798. int MidiMessage::getQuarterFrameValue() const throw()
  22799. {
  22800. return ((int) data[1]) & 0x0f;
  22801. }
  22802. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22803. const int value) throw()
  22804. {
  22805. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22806. }
  22807. bool MidiMessage::isFullFrame() const throw()
  22808. {
  22809. return data[0] == 0xf0
  22810. && data[1] == 0x7f
  22811. && size >= 10
  22812. && data[3] == 0x01
  22813. && data[4] == 0x01;
  22814. }
  22815. void MidiMessage::getFullFrameParameters (int& hours,
  22816. int& minutes,
  22817. int& seconds,
  22818. int& frames,
  22819. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22820. {
  22821. jassert (isFullFrame());
  22822. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22823. hours = data[5] & 0x1f;
  22824. minutes = data[6];
  22825. seconds = data[7];
  22826. frames = data[8];
  22827. }
  22828. const MidiMessage MidiMessage::fullFrame (const int hours,
  22829. const int minutes,
  22830. const int seconds,
  22831. const int frames,
  22832. MidiMessage::SmpteTimecodeType timecodeType)
  22833. {
  22834. uint8 d[10];
  22835. d[0] = 0xf0;
  22836. d[1] = 0x7f;
  22837. d[2] = 0x7f;
  22838. d[3] = 0x01;
  22839. d[4] = 0x01;
  22840. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22841. d[6] = (uint8) minutes;
  22842. d[7] = (uint8) seconds;
  22843. d[8] = (uint8) frames;
  22844. d[9] = 0xf7;
  22845. return MidiMessage (d, 10, 0.0);
  22846. }
  22847. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22848. {
  22849. return data[0] == 0xf0
  22850. && data[1] == 0x7f
  22851. && data[3] == 0x06
  22852. && size > 5;
  22853. }
  22854. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22855. {
  22856. jassert (isMidiMachineControlMessage());
  22857. return (MidiMachineControlCommand) data[4];
  22858. }
  22859. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22860. {
  22861. uint8 d[6];
  22862. d[0] = 0xf0;
  22863. d[1] = 0x7f;
  22864. d[2] = 0x00;
  22865. d[3] = 0x06;
  22866. d[4] = (uint8) command;
  22867. d[5] = 0xf7;
  22868. return MidiMessage (d, 6, 0.0);
  22869. }
  22870. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22871. int& minutes,
  22872. int& seconds,
  22873. int& frames) const throw()
  22874. {
  22875. if (size >= 12
  22876. && data[0] == 0xf0
  22877. && data[1] == 0x7f
  22878. && data[3] == 0x06
  22879. && data[4] == 0x44
  22880. && data[5] == 0x06
  22881. && data[6] == 0x01)
  22882. {
  22883. hours = data[7] % 24; // (that some machines send out hours > 24)
  22884. minutes = data[8];
  22885. seconds = data[9];
  22886. frames = data[10];
  22887. return true;
  22888. }
  22889. return false;
  22890. }
  22891. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22892. int minutes,
  22893. int seconds,
  22894. int frames)
  22895. {
  22896. uint8 d[12];
  22897. d[0] = 0xf0;
  22898. d[1] = 0x7f;
  22899. d[2] = 0x00;
  22900. d[3] = 0x06;
  22901. d[4] = 0x44;
  22902. d[5] = 0x06;
  22903. d[6] = 0x01;
  22904. d[7] = (uint8) hours;
  22905. d[8] = (uint8) minutes;
  22906. d[9] = (uint8) seconds;
  22907. d[10] = (uint8) frames;
  22908. d[11] = 0xf7;
  22909. return MidiMessage (d, 12, 0.0);
  22910. }
  22911. const String MidiMessage::getMidiNoteName (int note,
  22912. bool useSharps,
  22913. bool includeOctaveNumber,
  22914. int octaveNumForMiddleC) throw()
  22915. {
  22916. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22917. "F", "F#", "G", "G#", "A",
  22918. "A#", "B" };
  22919. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22920. "F", "Gb", "G", "Ab", "A",
  22921. "Bb", "B" };
  22922. if (((unsigned int) note) < 128)
  22923. {
  22924. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22925. : flatNoteNames [note % 12]);
  22926. if (includeOctaveNumber)
  22927. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22928. else
  22929. return s;
  22930. }
  22931. return String::empty;
  22932. }
  22933. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22934. {
  22935. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22936. return 440.0 * pow (2.0, noteNumber / 12.0);
  22937. }
  22938. const String MidiMessage::getGMInstrumentName (int n) throw()
  22939. {
  22940. const char *names[] =
  22941. {
  22942. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22943. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22944. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22945. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22946. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22947. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22948. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22949. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22950. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22951. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22952. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22953. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22954. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22955. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22956. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22957. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22958. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22959. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22960. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22961. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22962. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22963. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22964. "Applause", "Gunshot"
  22965. };
  22966. return (((unsigned int) n) < 128) ? names[n]
  22967. : (const char*)0;
  22968. }
  22969. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22970. {
  22971. const char* names[] =
  22972. {
  22973. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22974. "Bass", "Strings", "Ensemble", "Brass",
  22975. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22976. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22977. };
  22978. return (((unsigned int) n) <= 15) ? names[n]
  22979. : (const char*)0;
  22980. }
  22981. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22982. {
  22983. const char* names[] =
  22984. {
  22985. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22986. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22987. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22988. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22989. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22990. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22991. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22992. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22993. "Mute Triangle", "Open Triangle"
  22994. };
  22995. return (n >= 35 && n <= 81) ? names [n - 35]
  22996. : (const char*)0;
  22997. }
  22998. const String MidiMessage::getControllerName (int n) throw()
  22999. {
  23000. const char* names[] =
  23001. {
  23002. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  23003. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  23004. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  23005. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  23006. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  23007. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  23008. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  23009. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  23010. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  23011. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  23012. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  23013. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  23014. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  23015. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  23016. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  23017. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  23018. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  23019. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  23020. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  23021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  23022. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  23023. "Poly Operation"
  23024. };
  23025. return (((unsigned int) n) < 128) ? names[n]
  23026. : (const char*)0;
  23027. }
  23028. END_JUCE_NAMESPACE
  23029. /*** End of inlined file: juce_MidiMessage.cpp ***/
  23030. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  23031. BEGIN_JUCE_NAMESPACE
  23032. MidiMessageCollector::MidiMessageCollector()
  23033. : lastCallbackTime (0),
  23034. sampleRate (44100.0001)
  23035. {
  23036. }
  23037. MidiMessageCollector::~MidiMessageCollector()
  23038. {
  23039. }
  23040. void MidiMessageCollector::reset (const double sampleRate_)
  23041. {
  23042. jassert (sampleRate_ > 0);
  23043. const ScopedLock sl (midiCallbackLock);
  23044. sampleRate = sampleRate_;
  23045. incomingMessages.clear();
  23046. lastCallbackTime = Time::getMillisecondCounterHiRes();
  23047. }
  23048. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  23049. {
  23050. // you need to call reset() to set the correct sample rate before using this object
  23051. jassert (sampleRate != 44100.0001);
  23052. // the messages that come in here need to be time-stamped correctly - see MidiInput
  23053. // for details of what the number should be.
  23054. jassert (message.getTimeStamp() != 0);
  23055. const ScopedLock sl (midiCallbackLock);
  23056. const int sampleNumber
  23057. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  23058. incomingMessages.addEvent (message, sampleNumber);
  23059. // if the messages don't get used for over a second, we'd better
  23060. // get rid of any old ones to avoid the queue getting too big
  23061. if (sampleNumber > sampleRate)
  23062. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  23063. }
  23064. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  23065. const int numSamples)
  23066. {
  23067. // you need to call reset() to set the correct sample rate before using this object
  23068. jassert (sampleRate != 44100.0001);
  23069. const double timeNow = Time::getMillisecondCounterHiRes();
  23070. const double msElapsed = timeNow - lastCallbackTime;
  23071. const ScopedLock sl (midiCallbackLock);
  23072. lastCallbackTime = timeNow;
  23073. if (! incomingMessages.isEmpty())
  23074. {
  23075. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  23076. int startSample = 0;
  23077. int scale = 1 << 16;
  23078. const uint8* midiData;
  23079. int numBytes, samplePosition;
  23080. MidiBuffer::Iterator iter (incomingMessages);
  23081. if (numSourceSamples > numSamples)
  23082. {
  23083. // if our list of events is longer than the buffer we're being
  23084. // asked for, scale them down to squeeze them all in..
  23085. const int maxBlockLengthToUse = numSamples << 5;
  23086. if (numSourceSamples > maxBlockLengthToUse)
  23087. {
  23088. startSample = numSourceSamples - maxBlockLengthToUse;
  23089. numSourceSamples = maxBlockLengthToUse;
  23090. iter.setNextSamplePosition (startSample);
  23091. }
  23092. scale = (numSamples << 10) / numSourceSamples;
  23093. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23094. {
  23095. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  23096. destBuffer.addEvent (midiData, numBytes,
  23097. jlimit (0, numSamples - 1, samplePosition));
  23098. }
  23099. }
  23100. else
  23101. {
  23102. // if our event list is shorter than the number we need, put them
  23103. // towards the end of the buffer
  23104. startSample = numSamples - numSourceSamples;
  23105. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23106. {
  23107. destBuffer.addEvent (midiData, numBytes,
  23108. jlimit (0, numSamples - 1, samplePosition + startSample));
  23109. }
  23110. }
  23111. incomingMessages.clear();
  23112. }
  23113. }
  23114. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23115. {
  23116. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23117. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23118. addMessageToQueue (m);
  23119. }
  23120. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23121. {
  23122. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23123. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23124. addMessageToQueue (m);
  23125. }
  23126. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23127. {
  23128. addMessageToQueue (message);
  23129. }
  23130. END_JUCE_NAMESPACE
  23131. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  23132. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  23133. BEGIN_JUCE_NAMESPACE
  23134. MidiMessageSequence::MidiMessageSequence()
  23135. {
  23136. }
  23137. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23138. {
  23139. list.ensureStorageAllocated (other.list.size());
  23140. for (int i = 0; i < other.list.size(); ++i)
  23141. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23142. }
  23143. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23144. {
  23145. MidiMessageSequence otherCopy (other);
  23146. swapWith (otherCopy);
  23147. return *this;
  23148. }
  23149. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23150. {
  23151. list.swapWithArray (other.list);
  23152. }
  23153. MidiMessageSequence::~MidiMessageSequence()
  23154. {
  23155. }
  23156. void MidiMessageSequence::clear()
  23157. {
  23158. list.clear();
  23159. }
  23160. int MidiMessageSequence::getNumEvents() const
  23161. {
  23162. return list.size();
  23163. }
  23164. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23165. {
  23166. return list [index];
  23167. }
  23168. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23169. {
  23170. const MidiEventHolder* const meh = list [index];
  23171. if (meh != 0 && meh->noteOffObject != 0)
  23172. return meh->noteOffObject->message.getTimeStamp();
  23173. else
  23174. return 0.0;
  23175. }
  23176. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23177. {
  23178. const MidiEventHolder* const meh = list [index];
  23179. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23180. }
  23181. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23182. {
  23183. return list.indexOf (event);
  23184. }
  23185. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23186. {
  23187. const int numEvents = list.size();
  23188. int i;
  23189. for (i = 0; i < numEvents; ++i)
  23190. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23191. break;
  23192. return i;
  23193. }
  23194. double MidiMessageSequence::getStartTime() const
  23195. {
  23196. if (list.size() > 0)
  23197. return list.getUnchecked(0)->message.getTimeStamp();
  23198. else
  23199. return 0;
  23200. }
  23201. double MidiMessageSequence::getEndTime() const
  23202. {
  23203. if (list.size() > 0)
  23204. return list.getLast()->message.getTimeStamp();
  23205. else
  23206. return 0;
  23207. }
  23208. double MidiMessageSequence::getEventTime (const int index) const
  23209. {
  23210. if (((unsigned int) index) < (unsigned int) list.size())
  23211. return list.getUnchecked (index)->message.getTimeStamp();
  23212. return 0.0;
  23213. }
  23214. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23215. double timeAdjustment)
  23216. {
  23217. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23218. timeAdjustment += newMessage.getTimeStamp();
  23219. newOne->message.setTimeStamp (timeAdjustment);
  23220. int i;
  23221. for (i = list.size(); --i >= 0;)
  23222. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23223. break;
  23224. list.insert (i + 1, newOne);
  23225. }
  23226. void MidiMessageSequence::deleteEvent (const int index,
  23227. const bool deleteMatchingNoteUp)
  23228. {
  23229. if (((unsigned int) index) < (unsigned int) list.size())
  23230. {
  23231. if (deleteMatchingNoteUp)
  23232. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23233. list.remove (index);
  23234. }
  23235. }
  23236. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23237. double timeAdjustment,
  23238. double firstAllowableTime,
  23239. double endOfAllowableDestTimes)
  23240. {
  23241. firstAllowableTime -= timeAdjustment;
  23242. endOfAllowableDestTimes -= timeAdjustment;
  23243. for (int i = 0; i < other.list.size(); ++i)
  23244. {
  23245. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23246. const double t = m.getTimeStamp();
  23247. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23248. {
  23249. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23250. newOne->message.setTimeStamp (timeAdjustment + t);
  23251. list.add (newOne);
  23252. }
  23253. }
  23254. sort();
  23255. }
  23256. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23257. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23258. {
  23259. const double diff = first->message.getTimeStamp()
  23260. - second->message.getTimeStamp();
  23261. return (diff > 0) - (diff < 0);
  23262. }
  23263. void MidiMessageSequence::sort()
  23264. {
  23265. list.sort (*this, true);
  23266. }
  23267. void MidiMessageSequence::updateMatchedPairs()
  23268. {
  23269. for (int i = 0; i < list.size(); ++i)
  23270. {
  23271. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23272. if (m1.isNoteOn())
  23273. {
  23274. list.getUnchecked(i)->noteOffObject = 0;
  23275. const int note = m1.getNoteNumber();
  23276. const int chan = m1.getChannel();
  23277. const int len = list.size();
  23278. for (int j = i + 1; j < len; ++j)
  23279. {
  23280. const MidiMessage& m = list.getUnchecked(j)->message;
  23281. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23282. {
  23283. if (m.isNoteOff())
  23284. {
  23285. list.getUnchecked(i)->noteOffObject = list[j];
  23286. break;
  23287. }
  23288. else if (m.isNoteOn())
  23289. {
  23290. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23291. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23292. list.getUnchecked(i)->noteOffObject = list[j];
  23293. break;
  23294. }
  23295. }
  23296. }
  23297. }
  23298. }
  23299. }
  23300. void MidiMessageSequence::addTimeToMessages (const double delta)
  23301. {
  23302. for (int i = list.size(); --i >= 0;)
  23303. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23304. + delta);
  23305. }
  23306. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23307. MidiMessageSequence& destSequence,
  23308. const bool alsoIncludeMetaEvents) const
  23309. {
  23310. for (int i = 0; i < list.size(); ++i)
  23311. {
  23312. const MidiMessage& mm = list.getUnchecked(i)->message;
  23313. if (mm.isForChannel (channelNumberToExtract)
  23314. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23315. {
  23316. destSequence.addEvent (mm);
  23317. }
  23318. }
  23319. }
  23320. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23321. {
  23322. for (int i = 0; i < list.size(); ++i)
  23323. {
  23324. const MidiMessage& mm = list.getUnchecked(i)->message;
  23325. if (mm.isSysEx())
  23326. destSequence.addEvent (mm);
  23327. }
  23328. }
  23329. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23330. {
  23331. for (int i = list.size(); --i >= 0;)
  23332. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23333. list.remove(i);
  23334. }
  23335. void MidiMessageSequence::deleteSysExMessages()
  23336. {
  23337. for (int i = list.size(); --i >= 0;)
  23338. if (list.getUnchecked(i)->message.isSysEx())
  23339. list.remove(i);
  23340. }
  23341. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23342. const double time,
  23343. OwnedArray<MidiMessage>& dest)
  23344. {
  23345. bool doneProg = false;
  23346. bool donePitchWheel = false;
  23347. Array <int> doneControllers;
  23348. doneControllers.ensureStorageAllocated (32);
  23349. for (int i = list.size(); --i >= 0;)
  23350. {
  23351. const MidiMessage& mm = list.getUnchecked(i)->message;
  23352. if (mm.isForChannel (channelNumber)
  23353. && mm.getTimeStamp() <= time)
  23354. {
  23355. if (mm.isProgramChange())
  23356. {
  23357. if (! doneProg)
  23358. {
  23359. dest.add (new MidiMessage (mm, 0.0));
  23360. doneProg = true;
  23361. }
  23362. }
  23363. else if (mm.isController())
  23364. {
  23365. if (! doneControllers.contains (mm.getControllerNumber()))
  23366. {
  23367. dest.add (new MidiMessage (mm, 0.0));
  23368. doneControllers.add (mm.getControllerNumber());
  23369. }
  23370. }
  23371. else if (mm.isPitchWheel())
  23372. {
  23373. if (! donePitchWheel)
  23374. {
  23375. dest.add (new MidiMessage (mm, 0.0));
  23376. donePitchWheel = true;
  23377. }
  23378. }
  23379. }
  23380. }
  23381. }
  23382. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23383. : message (message_),
  23384. noteOffObject (0)
  23385. {
  23386. }
  23387. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23388. {
  23389. }
  23390. END_JUCE_NAMESPACE
  23391. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23392. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23393. BEGIN_JUCE_NAMESPACE
  23394. AudioPluginFormat::AudioPluginFormat() throw()
  23395. {
  23396. }
  23397. AudioPluginFormat::~AudioPluginFormat()
  23398. {
  23399. }
  23400. END_JUCE_NAMESPACE
  23401. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23402. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23403. BEGIN_JUCE_NAMESPACE
  23404. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23405. {
  23406. }
  23407. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23408. {
  23409. clearSingletonInstance();
  23410. }
  23411. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23412. void AudioPluginFormatManager::addDefaultFormats()
  23413. {
  23414. #ifdef JUCE_DEBUG
  23415. // you should only call this method once!
  23416. for (int i = formats.size(); --i >= 0;)
  23417. {
  23418. #if JUCE_PLUGINHOST_VST
  23419. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23420. #endif
  23421. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23422. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23423. #endif
  23424. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23425. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23426. #endif
  23427. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23428. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23429. #endif
  23430. }
  23431. #endif
  23432. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23433. formats.add (new AudioUnitPluginFormat());
  23434. #endif
  23435. #if JUCE_PLUGINHOST_VST
  23436. formats.add (new VSTPluginFormat());
  23437. #endif
  23438. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23439. formats.add (new DirectXPluginFormat());
  23440. #endif
  23441. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23442. formats.add (new LADSPAPluginFormat());
  23443. #endif
  23444. }
  23445. int AudioPluginFormatManager::getNumFormats() throw()
  23446. {
  23447. return formats.size();
  23448. }
  23449. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23450. {
  23451. return formats [index];
  23452. }
  23453. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23454. {
  23455. formats.add (format);
  23456. }
  23457. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23458. String& errorMessage) const
  23459. {
  23460. AudioPluginInstance* result = 0;
  23461. for (int i = 0; i < formats.size(); ++i)
  23462. {
  23463. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23464. if (result != 0)
  23465. break;
  23466. }
  23467. if (result == 0)
  23468. {
  23469. if (! doesPluginStillExist (description))
  23470. errorMessage = TRANS ("This plug-in file no longer exists");
  23471. else
  23472. errorMessage = TRANS ("This plug-in failed to load correctly");
  23473. }
  23474. return result;
  23475. }
  23476. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23477. {
  23478. for (int i = 0; i < formats.size(); ++i)
  23479. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23480. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23481. return false;
  23482. }
  23483. END_JUCE_NAMESPACE
  23484. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23485. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23486. #define JUCE_PLUGIN_HOST 1
  23487. BEGIN_JUCE_NAMESPACE
  23488. AudioPluginInstance::AudioPluginInstance()
  23489. {
  23490. }
  23491. AudioPluginInstance::~AudioPluginInstance()
  23492. {
  23493. }
  23494. END_JUCE_NAMESPACE
  23495. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23496. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23497. BEGIN_JUCE_NAMESPACE
  23498. KnownPluginList::KnownPluginList()
  23499. {
  23500. }
  23501. KnownPluginList::~KnownPluginList()
  23502. {
  23503. }
  23504. void KnownPluginList::clear()
  23505. {
  23506. if (types.size() > 0)
  23507. {
  23508. types.clear();
  23509. sendChangeMessage (this);
  23510. }
  23511. }
  23512. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23513. {
  23514. for (int i = 0; i < types.size(); ++i)
  23515. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23516. return types.getUnchecked(i);
  23517. return 0;
  23518. }
  23519. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23520. {
  23521. for (int i = 0; i < types.size(); ++i)
  23522. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23523. return types.getUnchecked(i);
  23524. return 0;
  23525. }
  23526. bool KnownPluginList::addType (const PluginDescription& type)
  23527. {
  23528. for (int i = types.size(); --i >= 0;)
  23529. {
  23530. if (types.getUnchecked(i)->isDuplicateOf (type))
  23531. {
  23532. // strange - found a duplicate plugin with different info..
  23533. jassert (types.getUnchecked(i)->name == type.name);
  23534. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23535. *types.getUnchecked(i) = type;
  23536. return false;
  23537. }
  23538. }
  23539. types.add (new PluginDescription (type));
  23540. sendChangeMessage (this);
  23541. return true;
  23542. }
  23543. void KnownPluginList::removeType (const int index) throw()
  23544. {
  23545. types.remove (index);
  23546. sendChangeMessage (this);
  23547. }
  23548. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23549. {
  23550. if (fileOrIdentifier.startsWithChar (T('/'))
  23551. || fileOrIdentifier[1] == T(':'))
  23552. {
  23553. return File (fileOrIdentifier).getLastModificationTime();
  23554. }
  23555. return Time (0);
  23556. }
  23557. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23558. {
  23559. return t1 != t2 || t1 == Time (0);
  23560. }
  23561. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23562. {
  23563. if (getTypeForFile (fileOrIdentifier) == 0)
  23564. return false;
  23565. for (int i = types.size(); --i >= 0;)
  23566. {
  23567. const PluginDescription* const d = types.getUnchecked(i);
  23568. if (d->fileOrIdentifier == fileOrIdentifier
  23569. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23570. {
  23571. return false;
  23572. }
  23573. }
  23574. return true;
  23575. }
  23576. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23577. const bool dontRescanIfAlreadyInList,
  23578. OwnedArray <PluginDescription>& typesFound,
  23579. AudioPluginFormat& format)
  23580. {
  23581. bool addedOne = false;
  23582. if (dontRescanIfAlreadyInList
  23583. && getTypeForFile (fileOrIdentifier) != 0)
  23584. {
  23585. bool needsRescanning = false;
  23586. for (int i = types.size(); --i >= 0;)
  23587. {
  23588. const PluginDescription* const d = types.getUnchecked(i);
  23589. if (d->fileOrIdentifier == fileOrIdentifier)
  23590. {
  23591. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23592. needsRescanning = true;
  23593. else
  23594. typesFound.add (new PluginDescription (*d));
  23595. }
  23596. }
  23597. if (! needsRescanning)
  23598. return false;
  23599. }
  23600. OwnedArray <PluginDescription> found;
  23601. format.findAllTypesForFile (found, fileOrIdentifier);
  23602. for (int i = 0; i < found.size(); ++i)
  23603. {
  23604. PluginDescription* const desc = found.getUnchecked(i);
  23605. jassert (desc != 0);
  23606. if (addType (*desc))
  23607. addedOne = true;
  23608. typesFound.add (new PluginDescription (*desc));
  23609. }
  23610. return addedOne;
  23611. }
  23612. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23613. OwnedArray <PluginDescription>& typesFound)
  23614. {
  23615. for (int i = 0; i < files.size(); ++i)
  23616. {
  23617. bool loaded = false;
  23618. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23619. {
  23620. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23621. if (scanAndAddFile (files[i], true, typesFound, *format))
  23622. loaded = true;
  23623. }
  23624. if (! loaded)
  23625. {
  23626. const File f (files[i]);
  23627. if (f.isDirectory())
  23628. {
  23629. StringArray s;
  23630. {
  23631. Array<File> subFiles;
  23632. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23633. for (int j = 0; j < subFiles.size(); ++j)
  23634. s.add (subFiles.getReference(j).getFullPathName());
  23635. }
  23636. scanAndAddDragAndDroppedFiles (s, typesFound);
  23637. }
  23638. }
  23639. }
  23640. }
  23641. class PluginSorter
  23642. {
  23643. public:
  23644. KnownPluginList::SortMethod method;
  23645. PluginSorter() throw() {}
  23646. int compareElements (const PluginDescription* const first,
  23647. const PluginDescription* const second) const throw()
  23648. {
  23649. int diff = 0;
  23650. if (method == KnownPluginList::sortByCategory)
  23651. diff = first->category.compareLexicographically (second->category);
  23652. else if (method == KnownPluginList::sortByManufacturer)
  23653. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23654. else if (method == KnownPluginList::sortByFileSystemLocation)
  23655. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23656. .upToLastOccurrenceOf (T("/"), false, false)
  23657. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23658. .upToLastOccurrenceOf (T("/"), false, false));
  23659. if (diff == 0)
  23660. diff = first->name.compareLexicographically (second->name);
  23661. return diff;
  23662. }
  23663. };
  23664. void KnownPluginList::sort (const SortMethod method)
  23665. {
  23666. if (method != defaultOrder)
  23667. {
  23668. PluginSorter sorter;
  23669. sorter.method = method;
  23670. types.sort (sorter, true);
  23671. sendChangeMessage (this);
  23672. }
  23673. }
  23674. XmlElement* KnownPluginList::createXml() const
  23675. {
  23676. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23677. for (int i = 0; i < types.size(); ++i)
  23678. e->addChildElement (types.getUnchecked(i)->createXml());
  23679. return e;
  23680. }
  23681. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23682. {
  23683. clear();
  23684. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23685. {
  23686. forEachXmlChildElement (xml, e)
  23687. {
  23688. PluginDescription info;
  23689. if (info.loadFromXml (*e))
  23690. addType (info);
  23691. }
  23692. }
  23693. }
  23694. const int menuIdBase = 0x324503f4;
  23695. // This is used to turn a bunch of paths into a nested menu structure.
  23696. struct PluginFilesystemTree
  23697. {
  23698. private:
  23699. String folder;
  23700. OwnedArray <PluginFilesystemTree> subFolders;
  23701. Array <PluginDescription*> plugins;
  23702. void addPlugin (PluginDescription* const pd, const String& path)
  23703. {
  23704. if (path.isEmpty())
  23705. {
  23706. plugins.add (pd);
  23707. }
  23708. else
  23709. {
  23710. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23711. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23712. for (int i = subFolders.size(); --i >= 0;)
  23713. {
  23714. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23715. {
  23716. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23717. return;
  23718. }
  23719. }
  23720. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23721. newFolder->folder = firstSubFolder;
  23722. subFolders.add (newFolder);
  23723. newFolder->addPlugin (pd, remainingPath);
  23724. }
  23725. }
  23726. // removes any deeply nested folders that don't contain any actual plugins
  23727. void optimise()
  23728. {
  23729. for (int i = subFolders.size(); --i >= 0;)
  23730. {
  23731. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23732. sub->optimise();
  23733. if (sub->plugins.size() == 0)
  23734. {
  23735. for (int j = 0; j < sub->subFolders.size(); ++j)
  23736. subFolders.add (sub->subFolders.getUnchecked(j));
  23737. sub->subFolders.clear (false);
  23738. subFolders.remove (i);
  23739. }
  23740. }
  23741. }
  23742. public:
  23743. void buildTree (const Array <PluginDescription*>& allPlugins)
  23744. {
  23745. for (int i = 0; i < allPlugins.size(); ++i)
  23746. {
  23747. String path (allPlugins.getUnchecked(i)
  23748. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23749. .upToLastOccurrenceOf (T("/"), false, false));
  23750. if (path.substring (1, 2) == T(":"))
  23751. path = path.substring (2);
  23752. addPlugin (allPlugins.getUnchecked(i), path);
  23753. }
  23754. optimise();
  23755. }
  23756. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23757. {
  23758. int i;
  23759. for (i = 0; i < subFolders.size(); ++i)
  23760. {
  23761. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23762. PopupMenu subMenu;
  23763. sub->addToMenu (subMenu, allPlugins);
  23764. #if JUCE_MAC
  23765. // avoid the special AU formatting nonsense on Mac..
  23766. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23767. #else
  23768. m.addSubMenu (sub->folder, subMenu);
  23769. #endif
  23770. }
  23771. for (i = 0; i < plugins.size(); ++i)
  23772. {
  23773. PluginDescription* const plugin = plugins.getUnchecked(i);
  23774. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23775. plugin->name, true, false);
  23776. }
  23777. }
  23778. };
  23779. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23780. {
  23781. Array <PluginDescription*> sorted;
  23782. {
  23783. PluginSorter sorter;
  23784. sorter.method = sortMethod;
  23785. for (int i = 0; i < types.size(); ++i)
  23786. sorted.addSorted (sorter, types.getUnchecked(i));
  23787. }
  23788. if (sortMethod == sortByCategory
  23789. || sortMethod == sortByManufacturer)
  23790. {
  23791. String lastSubMenuName;
  23792. PopupMenu sub;
  23793. for (int i = 0; i < sorted.size(); ++i)
  23794. {
  23795. const PluginDescription* const pd = sorted.getUnchecked(i);
  23796. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23797. : pd->manufacturerName);
  23798. if (! thisSubMenuName.containsNonWhitespaceChars())
  23799. thisSubMenuName = T("Other");
  23800. if (thisSubMenuName != lastSubMenuName)
  23801. {
  23802. if (sub.getNumItems() > 0)
  23803. {
  23804. menu.addSubMenu (lastSubMenuName, sub);
  23805. sub.clear();
  23806. }
  23807. lastSubMenuName = thisSubMenuName;
  23808. }
  23809. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23810. }
  23811. if (sub.getNumItems() > 0)
  23812. menu.addSubMenu (lastSubMenuName, sub);
  23813. }
  23814. else if (sortMethod == sortByFileSystemLocation)
  23815. {
  23816. PluginFilesystemTree root;
  23817. root.buildTree (sorted);
  23818. root.addToMenu (menu, types);
  23819. }
  23820. else
  23821. {
  23822. for (int i = 0; i < sorted.size(); ++i)
  23823. {
  23824. const PluginDescription* const pd = sorted.getUnchecked(i);
  23825. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23826. }
  23827. }
  23828. }
  23829. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23830. {
  23831. const int i = menuResultCode - menuIdBase;
  23832. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23833. }
  23834. END_JUCE_NAMESPACE
  23835. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23836. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23837. BEGIN_JUCE_NAMESPACE
  23838. PluginDescription::PluginDescription() throw()
  23839. : uid (0),
  23840. isInstrument (false),
  23841. numInputChannels (0),
  23842. numOutputChannels (0)
  23843. {
  23844. }
  23845. PluginDescription::~PluginDescription() throw()
  23846. {
  23847. }
  23848. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23849. : name (other.name),
  23850. pluginFormatName (other.pluginFormatName),
  23851. category (other.category),
  23852. manufacturerName (other.manufacturerName),
  23853. version (other.version),
  23854. fileOrIdentifier (other.fileOrIdentifier),
  23855. lastFileModTime (other.lastFileModTime),
  23856. uid (other.uid),
  23857. isInstrument (other.isInstrument),
  23858. numInputChannels (other.numInputChannels),
  23859. numOutputChannels (other.numOutputChannels)
  23860. {
  23861. }
  23862. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23863. {
  23864. name = other.name;
  23865. pluginFormatName = other.pluginFormatName;
  23866. category = other.category;
  23867. manufacturerName = other.manufacturerName;
  23868. version = other.version;
  23869. fileOrIdentifier = other.fileOrIdentifier;
  23870. uid = other.uid;
  23871. isInstrument = other.isInstrument;
  23872. lastFileModTime = other.lastFileModTime;
  23873. numInputChannels = other.numInputChannels;
  23874. numOutputChannels = other.numOutputChannels;
  23875. return *this;
  23876. }
  23877. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23878. {
  23879. return fileOrIdentifier == other.fileOrIdentifier
  23880. && uid == other.uid;
  23881. }
  23882. const String PluginDescription::createIdentifierString() const throw()
  23883. {
  23884. return pluginFormatName
  23885. + T("-") + name
  23886. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23887. + T("-") + String::toHexString (uid);
  23888. }
  23889. XmlElement* PluginDescription::createXml() const
  23890. {
  23891. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23892. e->setAttribute (T("name"), name);
  23893. e->setAttribute (T("format"), pluginFormatName);
  23894. e->setAttribute (T("category"), category);
  23895. e->setAttribute (T("manufacturer"), manufacturerName);
  23896. e->setAttribute (T("version"), version);
  23897. e->setAttribute (T("file"), fileOrIdentifier);
  23898. e->setAttribute (T("uid"), String::toHexString (uid));
  23899. e->setAttribute (T("isInstrument"), isInstrument);
  23900. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23901. e->setAttribute (T("numInputs"), numInputChannels);
  23902. e->setAttribute (T("numOutputs"), numOutputChannels);
  23903. return e;
  23904. }
  23905. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23906. {
  23907. if (xml.hasTagName (T("PLUGIN")))
  23908. {
  23909. name = xml.getStringAttribute (T("name"));
  23910. pluginFormatName = xml.getStringAttribute (T("format"));
  23911. category = xml.getStringAttribute (T("category"));
  23912. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23913. version = xml.getStringAttribute (T("version"));
  23914. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23915. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23916. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23917. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23918. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23919. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23920. return true;
  23921. }
  23922. return false;
  23923. }
  23924. END_JUCE_NAMESPACE
  23925. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23926. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23927. BEGIN_JUCE_NAMESPACE
  23928. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23929. AudioPluginFormat& formatToLookFor,
  23930. FileSearchPath directoriesToSearch,
  23931. const bool recursive,
  23932. const File& deadMansPedalFile_)
  23933. : list (listToAddTo),
  23934. format (formatToLookFor),
  23935. deadMansPedalFile (deadMansPedalFile_),
  23936. nextIndex (0),
  23937. progress (0)
  23938. {
  23939. directoriesToSearch.removeRedundantPaths();
  23940. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23941. // If any plugins have crashed recently when being loaded, move them to the
  23942. // end of the list to give the others a chance to load correctly..
  23943. const StringArray crashedPlugins (getDeadMansPedalFile());
  23944. for (int i = 0; i < crashedPlugins.size(); ++i)
  23945. {
  23946. const String f = crashedPlugins[i];
  23947. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23948. if (f == filesOrIdentifiersToScan[j])
  23949. filesOrIdentifiersToScan.move (j, -1);
  23950. }
  23951. }
  23952. PluginDirectoryScanner::~PluginDirectoryScanner()
  23953. {
  23954. }
  23955. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23956. {
  23957. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23958. }
  23959. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23960. {
  23961. String file (filesOrIdentifiersToScan [nextIndex]);
  23962. if (file.isNotEmpty())
  23963. {
  23964. if (! list.isListingUpToDate (file))
  23965. {
  23966. OwnedArray <PluginDescription> typesFound;
  23967. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23968. StringArray crashedPlugins (getDeadMansPedalFile());
  23969. crashedPlugins.removeString (file);
  23970. crashedPlugins.add (file);
  23971. setDeadMansPedalFile (crashedPlugins);
  23972. list.scanAndAddFile (file,
  23973. dontRescanIfAlreadyInList,
  23974. typesFound,
  23975. format);
  23976. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23977. crashedPlugins.removeString (file);
  23978. setDeadMansPedalFile (crashedPlugins);
  23979. if (typesFound.size() == 0)
  23980. failedFiles.add (file);
  23981. }
  23982. ++nextIndex;
  23983. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23984. }
  23985. return nextIndex < filesOrIdentifiersToScan.size();
  23986. }
  23987. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23988. {
  23989. StringArray lines;
  23990. if (deadMansPedalFile != File::nonexistent)
  23991. {
  23992. lines.addLines (deadMansPedalFile.loadFileAsString());
  23993. lines.removeEmptyStrings();
  23994. }
  23995. return lines;
  23996. }
  23997. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23998. {
  23999. if (deadMansPedalFile != File::nonexistent)
  24000. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  24001. }
  24002. END_JUCE_NAMESPACE
  24003. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  24004. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  24005. BEGIN_JUCE_NAMESPACE
  24006. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  24007. const File& deadMansPedalFile_,
  24008. PropertiesFile* const propertiesToUse_)
  24009. : list (listToEdit),
  24010. deadMansPedalFile (deadMansPedalFile_),
  24011. propertiesToUse (propertiesToUse_)
  24012. {
  24013. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  24014. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  24015. optionsButton->addButtonListener (this);
  24016. optionsButton->setTriggeredOnMouseDown (true);
  24017. setSize (400, 600);
  24018. list.addChangeListener (this);
  24019. }
  24020. PluginListComponent::~PluginListComponent()
  24021. {
  24022. list.removeChangeListener (this);
  24023. deleteAllChildren();
  24024. }
  24025. void PluginListComponent::resized()
  24026. {
  24027. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  24028. optionsButton->changeWidthToFitText (24);
  24029. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  24030. }
  24031. void PluginListComponent::changeListenerCallback (void*)
  24032. {
  24033. listBox->updateContent();
  24034. listBox->repaint();
  24035. }
  24036. int PluginListComponent::getNumRows()
  24037. {
  24038. return list.getNumTypes();
  24039. }
  24040. void PluginListComponent::paintListBoxItem (int row,
  24041. Graphics& g,
  24042. int width, int height,
  24043. bool rowIsSelected)
  24044. {
  24045. if (rowIsSelected)
  24046. g.fillAll (findColour (TextEditor::highlightColourId));
  24047. const PluginDescription* const pd = list.getType (row);
  24048. if (pd != 0)
  24049. {
  24050. GlyphArrangement ga;
  24051. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  24052. g.setColour (Colours::black);
  24053. ga.draw (g);
  24054. float x, y, r, b;
  24055. ga.getBoundingBox (0, -1, x, y, r, b, false);
  24056. String desc;
  24057. desc << pd->pluginFormatName
  24058. << (pd->isInstrument ? " instrument" : " effect")
  24059. << " - "
  24060. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  24061. << " / "
  24062. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  24063. if (pd->manufacturerName.isNotEmpty())
  24064. desc << " - " << pd->manufacturerName;
  24065. if (pd->version.isNotEmpty())
  24066. desc << " - " << pd->version;
  24067. if (pd->category.isNotEmpty())
  24068. desc << " - category: '" << pd->category << '\'';
  24069. g.setColour (Colours::grey);
  24070. ga.clear();
  24071. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  24072. ga.draw (g);
  24073. }
  24074. }
  24075. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  24076. {
  24077. list.removeType (lastRowSelected);
  24078. }
  24079. void PluginListComponent::buttonClicked (Button* b)
  24080. {
  24081. if (optionsButton == b)
  24082. {
  24083. PopupMenu menu;
  24084. menu.addItem (1, TRANS("Clear list"));
  24085. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  24086. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  24087. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  24088. menu.addSeparator();
  24089. menu.addItem (2, TRANS("Sort alphabetically"));
  24090. menu.addItem (3, TRANS("Sort by category"));
  24091. menu.addItem (4, TRANS("Sort by manufacturer"));
  24092. menu.addSeparator();
  24093. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  24094. {
  24095. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  24096. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  24097. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  24098. }
  24099. const int r = menu.showAt (optionsButton);
  24100. if (r == 1)
  24101. {
  24102. list.clear();
  24103. }
  24104. else if (r == 2)
  24105. {
  24106. list.sort (KnownPluginList::sortAlphabetically);
  24107. }
  24108. else if (r == 3)
  24109. {
  24110. list.sort (KnownPluginList::sortByCategory);
  24111. }
  24112. else if (r == 4)
  24113. {
  24114. list.sort (KnownPluginList::sortByManufacturer);
  24115. }
  24116. else if (r == 5)
  24117. {
  24118. const SparseSet <int> selected (listBox->getSelectedRows());
  24119. for (int i = list.getNumTypes(); --i >= 0;)
  24120. if (selected.contains (i))
  24121. list.removeType (i);
  24122. }
  24123. else if (r == 6)
  24124. {
  24125. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24126. if (desc != 0)
  24127. {
  24128. if (File (desc->fileOrIdentifier).existsAsFile())
  24129. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24130. }
  24131. }
  24132. else if (r == 7)
  24133. {
  24134. for (int i = list.getNumTypes(); --i >= 0;)
  24135. {
  24136. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24137. {
  24138. list.removeType (i);
  24139. }
  24140. }
  24141. }
  24142. else if (r != 0)
  24143. {
  24144. typeToScan = r - 10;
  24145. startTimer (1);
  24146. }
  24147. }
  24148. }
  24149. void PluginListComponent::timerCallback()
  24150. {
  24151. stopTimer();
  24152. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24153. }
  24154. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24155. {
  24156. return true;
  24157. }
  24158. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24159. {
  24160. OwnedArray <PluginDescription> typesFound;
  24161. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24162. }
  24163. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24164. {
  24165. if (format == 0)
  24166. return;
  24167. FileSearchPath path (format->getDefaultLocationsToSearch());
  24168. if (propertiesToUse != 0)
  24169. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24170. {
  24171. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24172. FileSearchPathListComponent pathList;
  24173. pathList.setSize (500, 300);
  24174. pathList.setPath (path);
  24175. aw.addCustomComponent (&pathList);
  24176. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24177. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24178. if (aw.runModalLoop() == 0)
  24179. return;
  24180. path = pathList.getPath();
  24181. }
  24182. if (propertiesToUse != 0)
  24183. {
  24184. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24185. propertiesToUse->saveIfNeeded();
  24186. }
  24187. double progress = 0.0;
  24188. AlertWindow aw (TRANS("Scanning for plugins..."),
  24189. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24190. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24191. aw.addProgressBarComponent (progress);
  24192. aw.enterModalState();
  24193. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24194. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24195. for (;;)
  24196. {
  24197. aw.setMessage (TRANS("Testing:\n\n")
  24198. + scanner.getNextPluginFileThatWillBeScanned());
  24199. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24200. if (! scanner.scanNextFile (true))
  24201. break;
  24202. if (! aw.isCurrentlyModal())
  24203. break;
  24204. progress = scanner.getProgress();
  24205. }
  24206. if (scanner.getFailedFiles().size() > 0)
  24207. {
  24208. StringArray shortNames;
  24209. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24210. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24211. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24212. TRANS("Scan complete"),
  24213. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24214. + shortNames.joinIntoString (", "));
  24215. }
  24216. }
  24217. END_JUCE_NAMESPACE
  24218. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24219. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24220. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24221. #include <AudioUnit/AudioUnit.h>
  24222. #include <AudioUnit/AUCocoaUIView.h>
  24223. #include <CoreAudioKit/AUGenericView.h>
  24224. #if JUCE_SUPPORT_CARBON
  24225. #include <AudioToolbox/AudioUnitUtilities.h>
  24226. #include <AudioUnit/AudioUnitCarbonView.h>
  24227. #endif
  24228. BEGIN_JUCE_NAMESPACE
  24229. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24230. #endif
  24231. #if JUCE_MAC
  24232. // Change this to disable logging of various activities
  24233. #ifndef AU_LOGGING
  24234. #define AU_LOGGING 1
  24235. #endif
  24236. #if AU_LOGGING
  24237. #define log(a) Logger::writeToLog(a);
  24238. #else
  24239. #define log(a)
  24240. #endif
  24241. static int insideCallback = 0;
  24242. static const String osTypeToString (OSType type) throw()
  24243. {
  24244. char s[4];
  24245. s[0] = (char) (((uint32) type) >> 24);
  24246. s[1] = (char) (((uint32) type) >> 16);
  24247. s[2] = (char) (((uint32) type) >> 8);
  24248. s[3] = (char) ((uint32) type);
  24249. return String (s, 4);
  24250. }
  24251. static OSType stringToOSType (const String& s1) throw()
  24252. {
  24253. const String s (s1 + " ");
  24254. return (((OSType) (unsigned char) s[0]) << 24)
  24255. | (((OSType) (unsigned char) s[1]) << 16)
  24256. | (((OSType) (unsigned char) s[2]) << 8)
  24257. | ((OSType) (unsigned char) s[3]);
  24258. }
  24259. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24260. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24261. {
  24262. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24263. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24264. String s (auIdentifierPrefix);
  24265. if (desc.componentType == kAudioUnitType_MusicDevice)
  24266. s << "Synths/";
  24267. else if (desc.componentType == kAudioUnitType_MusicEffect
  24268. || desc.componentType == kAudioUnitType_Effect)
  24269. s << "Effects/";
  24270. else if (desc.componentType == kAudioUnitType_Generator)
  24271. s << "Generators/";
  24272. else if (desc.componentType == kAudioUnitType_Panner)
  24273. s << "Panners/";
  24274. s << osTypeToString (desc.componentType)
  24275. << T(",")
  24276. << osTypeToString (desc.componentSubType)
  24277. << T(",")
  24278. << osTypeToString (desc.componentManufacturer);
  24279. return s;
  24280. }
  24281. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24282. {
  24283. Handle componentNameHandle = NewHandle (sizeof (void*));
  24284. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24285. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24286. {
  24287. ComponentDescription desc;
  24288. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24289. {
  24290. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24291. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24292. if (nameString != 0 && nameString[0] != 0)
  24293. {
  24294. const String all ((const char*) nameString + 1, nameString[0]);
  24295. DBG ("name: "+ all);
  24296. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24297. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24298. }
  24299. if (infoString != 0 && infoString[0] != 0)
  24300. {
  24301. const String all ((const char*) infoString + 1, infoString[0]);
  24302. DBG ("info: " + all);
  24303. }
  24304. if (name.isEmpty())
  24305. name = "<Unknown>";
  24306. }
  24307. DisposeHandle (componentNameHandle);
  24308. DisposeHandle (componentInfoHandle);
  24309. }
  24310. }
  24311. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24312. String& name, String& version, String& manufacturer)
  24313. {
  24314. zerostruct (desc);
  24315. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24316. {
  24317. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24318. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24319. StringArray tokens;
  24320. tokens.addTokens (s, T(","), 0);
  24321. tokens.trim();
  24322. tokens.removeEmptyStrings();
  24323. if (tokens.size() == 3)
  24324. {
  24325. desc.componentType = stringToOSType (tokens[0]);
  24326. desc.componentSubType = stringToOSType (tokens[1]);
  24327. desc.componentManufacturer = stringToOSType (tokens[2]);
  24328. ComponentRecord* comp = FindNextComponent (0, &desc);
  24329. if (comp != 0)
  24330. {
  24331. getAUDetails (comp, name, manufacturer);
  24332. return true;
  24333. }
  24334. }
  24335. }
  24336. return false;
  24337. }
  24338. class AudioUnitPluginWindowCarbon;
  24339. class AudioUnitPluginWindowCocoa;
  24340. class AudioUnitPluginInstance : public AudioPluginInstance
  24341. {
  24342. public:
  24343. ~AudioUnitPluginInstance();
  24344. // AudioPluginInstance methods:
  24345. void fillInPluginDescription (PluginDescription& desc) const
  24346. {
  24347. desc.name = pluginName;
  24348. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24349. desc.uid = ((int) componentDesc.componentType)
  24350. ^ ((int) componentDesc.componentSubType)
  24351. ^ ((int) componentDesc.componentManufacturer);
  24352. desc.lastFileModTime = 0;
  24353. desc.pluginFormatName = "AudioUnit";
  24354. desc.category = getCategory();
  24355. desc.manufacturerName = manufacturer;
  24356. desc.version = version;
  24357. desc.numInputChannels = getNumInputChannels();
  24358. desc.numOutputChannels = getNumOutputChannels();
  24359. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24360. }
  24361. const String getName() const { return pluginName; }
  24362. bool acceptsMidi() const { return wantsMidiMessages; }
  24363. bool producesMidi() const { return false; }
  24364. // AudioProcessor methods:
  24365. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24366. void releaseResources();
  24367. void processBlock (AudioSampleBuffer& buffer,
  24368. MidiBuffer& midiMessages);
  24369. AudioProcessorEditor* createEditor();
  24370. const String getInputChannelName (const int index) const;
  24371. bool isInputChannelStereoPair (int index) const;
  24372. const String getOutputChannelName (const int index) const;
  24373. bool isOutputChannelStereoPair (int index) const;
  24374. int getNumParameters();
  24375. float getParameter (int index);
  24376. void setParameter (int index, float newValue);
  24377. const String getParameterName (int index);
  24378. const String getParameterText (int index);
  24379. bool isParameterAutomatable (int index) const;
  24380. int getNumPrograms();
  24381. int getCurrentProgram();
  24382. void setCurrentProgram (int index);
  24383. const String getProgramName (int index);
  24384. void changeProgramName (int index, const String& newName);
  24385. void getStateInformation (MemoryBlock& destData);
  24386. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24387. void setStateInformation (const void* data, int sizeInBytes);
  24388. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24389. juce_UseDebuggingNewOperator
  24390. private:
  24391. friend class AudioUnitPluginWindowCarbon;
  24392. friend class AudioUnitPluginWindowCocoa;
  24393. friend class AudioUnitPluginFormat;
  24394. ComponentDescription componentDesc;
  24395. String pluginName, manufacturer, version;
  24396. String fileOrIdentifier;
  24397. CriticalSection lock;
  24398. bool initialised, wantsMidiMessages, wasPlaying;
  24399. HeapBlock <AudioBufferList> outputBufferList;
  24400. AudioTimeStamp timeStamp;
  24401. AudioSampleBuffer* currentBuffer;
  24402. AudioUnit audioUnit;
  24403. Array <int> parameterIds;
  24404. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24405. void initialise();
  24406. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24407. const AudioTimeStamp* inTimeStamp,
  24408. UInt32 inBusNumber,
  24409. UInt32 inNumberFrames,
  24410. AudioBufferList* ioData) const;
  24411. static OSStatus renderGetInputCallback (void* inRefCon,
  24412. AudioUnitRenderActionFlags* ioActionFlags,
  24413. const AudioTimeStamp* inTimeStamp,
  24414. UInt32 inBusNumber,
  24415. UInt32 inNumberFrames,
  24416. AudioBufferList* ioData)
  24417. {
  24418. return ((AudioUnitPluginInstance*) inRefCon)
  24419. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24420. }
  24421. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24422. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24423. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24424. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24425. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24426. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24427. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24428. {
  24429. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24430. }
  24431. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24432. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24433. Float64* outCurrentMeasureDownBeat)
  24434. {
  24435. return ((AudioUnitPluginInstance*) inHostUserData)
  24436. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24437. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24438. }
  24439. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24440. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24441. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24442. {
  24443. return ((AudioUnitPluginInstance*) inHostUserData)
  24444. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24445. outCurrentSampleInTimeLine, outIsCycling,
  24446. outCycleStartBeat, outCycleEndBeat);
  24447. }
  24448. void getNumChannels (int& numIns, int& numOuts)
  24449. {
  24450. numIns = 0;
  24451. numOuts = 0;
  24452. AUChannelInfo supportedChannels [128];
  24453. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24454. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24455. 0, supportedChannels, &supportedChannelsSize) == noErr
  24456. && supportedChannelsSize > 0)
  24457. {
  24458. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24459. {
  24460. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24461. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24462. }
  24463. }
  24464. else
  24465. {
  24466. // (this really means the plugin will take any number of ins/outs as long
  24467. // as they are the same)
  24468. numIns = numOuts = 2;
  24469. }
  24470. }
  24471. const String getCategory() const;
  24472. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24473. };
  24474. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24475. : fileOrIdentifier (fileOrIdentifier),
  24476. initialised (false),
  24477. wantsMidiMessages (false),
  24478. audioUnit (0),
  24479. currentBuffer (0)
  24480. {
  24481. try
  24482. {
  24483. ++insideCallback;
  24484. log (T("Opening AU: ") + fileOrIdentifier);
  24485. if (getComponentDescFromFile (fileOrIdentifier))
  24486. {
  24487. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24488. if (comp != 0)
  24489. {
  24490. audioUnit = (AudioUnit) OpenComponent (comp);
  24491. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24492. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24493. }
  24494. }
  24495. --insideCallback;
  24496. }
  24497. catch (...)
  24498. {
  24499. --insideCallback;
  24500. }
  24501. }
  24502. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24503. {
  24504. {
  24505. const ScopedLock sl (lock);
  24506. jassert (insideCallback == 0);
  24507. if (audioUnit != 0)
  24508. {
  24509. AudioUnitUninitialize (audioUnit);
  24510. CloseComponent (audioUnit);
  24511. audioUnit = 0;
  24512. }
  24513. }
  24514. }
  24515. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24516. {
  24517. zerostruct (componentDesc);
  24518. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24519. return true;
  24520. const File file (fileOrIdentifier);
  24521. if (! file.hasFileExtension (T(".component")))
  24522. return false;
  24523. const char* const utf8 = fileOrIdentifier.toUTF8();
  24524. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24525. strlen (utf8), file.isDirectory());
  24526. if (url != 0)
  24527. {
  24528. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24529. CFRelease (url);
  24530. if (bundleRef != 0)
  24531. {
  24532. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24533. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24534. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24535. if (pluginName.isEmpty())
  24536. pluginName = file.getFileNameWithoutExtension();
  24537. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24538. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24539. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24540. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24541. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24542. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24543. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24544. UseResFile (resFileId);
  24545. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24546. {
  24547. Handle h = Get1IndResource ('thng', i);
  24548. if (h != 0)
  24549. {
  24550. HLock (h);
  24551. const uint32* const types = (const uint32*) *h;
  24552. if (types[0] == kAudioUnitType_MusicDevice
  24553. || types[0] == kAudioUnitType_MusicEffect
  24554. || types[0] == kAudioUnitType_Effect
  24555. || types[0] == kAudioUnitType_Generator
  24556. || types[0] == kAudioUnitType_Panner)
  24557. {
  24558. componentDesc.componentType = types[0];
  24559. componentDesc.componentSubType = types[1];
  24560. componentDesc.componentManufacturer = types[2];
  24561. break;
  24562. }
  24563. HUnlock (h);
  24564. ReleaseResource (h);
  24565. }
  24566. }
  24567. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24568. CFRelease (bundleRef);
  24569. }
  24570. }
  24571. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24572. }
  24573. void AudioUnitPluginInstance::initialise()
  24574. {
  24575. if (initialised || audioUnit == 0)
  24576. return;
  24577. log (T("Initialising AU: ") + pluginName);
  24578. parameterIds.clear();
  24579. {
  24580. UInt32 paramListSize = 0;
  24581. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24582. 0, 0, &paramListSize);
  24583. if (paramListSize > 0)
  24584. {
  24585. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24586. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24587. 0, &parameterIds.getReference(0), &paramListSize);
  24588. }
  24589. }
  24590. {
  24591. AURenderCallbackStruct info;
  24592. zerostruct (info);
  24593. info.inputProcRefCon = this;
  24594. info.inputProc = renderGetInputCallback;
  24595. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24596. 0, &info, sizeof (info));
  24597. }
  24598. {
  24599. HostCallbackInfo info;
  24600. zerostruct (info);
  24601. info.hostUserData = this;
  24602. info.beatAndTempoProc = getBeatAndTempoCallback;
  24603. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24604. info.transportStateProc = getTransportStateCallback;
  24605. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24606. 0, &info, sizeof (info));
  24607. }
  24608. int numIns, numOuts;
  24609. getNumChannels (numIns, numOuts);
  24610. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24611. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24612. setLatencySamples (0);
  24613. }
  24614. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24615. int samplesPerBlockExpected)
  24616. {
  24617. initialise();
  24618. if (initialised)
  24619. {
  24620. int numIns, numOuts;
  24621. getNumChannels (numIns, numOuts);
  24622. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24623. Float64 latencySecs = 0.0;
  24624. UInt32 latencySize = sizeof (latencySecs);
  24625. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24626. 0, &latencySecs, &latencySize);
  24627. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24628. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24629. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24630. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24631. AudioStreamBasicDescription stream;
  24632. zerostruct (stream);
  24633. stream.mSampleRate = sampleRate_;
  24634. stream.mFormatID = kAudioFormatLinearPCM;
  24635. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24636. stream.mFramesPerPacket = 1;
  24637. stream.mBytesPerPacket = 4;
  24638. stream.mBytesPerFrame = 4;
  24639. stream.mBitsPerChannel = 32;
  24640. stream.mChannelsPerFrame = numIns;
  24641. OSStatus err = AudioUnitSetProperty (audioUnit,
  24642. kAudioUnitProperty_StreamFormat,
  24643. kAudioUnitScope_Input,
  24644. 0, &stream, sizeof (stream));
  24645. stream.mChannelsPerFrame = numOuts;
  24646. err = AudioUnitSetProperty (audioUnit,
  24647. kAudioUnitProperty_StreamFormat,
  24648. kAudioUnitScope_Output,
  24649. 0, &stream, sizeof (stream));
  24650. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24651. outputBufferList->mNumberBuffers = numOuts;
  24652. for (int i = numOuts; --i >= 0;)
  24653. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24654. zerostruct (timeStamp);
  24655. timeStamp.mSampleTime = 0;
  24656. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24657. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24658. currentBuffer = 0;
  24659. wasPlaying = false;
  24660. }
  24661. }
  24662. void AudioUnitPluginInstance::releaseResources()
  24663. {
  24664. if (initialised)
  24665. {
  24666. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24667. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24668. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24669. outputBufferList.free();
  24670. currentBuffer = 0;
  24671. }
  24672. }
  24673. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24674. const AudioTimeStamp* inTimeStamp,
  24675. UInt32 inBusNumber,
  24676. UInt32 inNumberFrames,
  24677. AudioBufferList* ioData) const
  24678. {
  24679. if (inBusNumber == 0
  24680. && currentBuffer != 0)
  24681. {
  24682. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24683. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24684. {
  24685. if (i < currentBuffer->getNumChannels())
  24686. {
  24687. memcpy (ioData->mBuffers[i].mData,
  24688. currentBuffer->getSampleData (i, 0),
  24689. sizeof (float) * inNumberFrames);
  24690. }
  24691. else
  24692. {
  24693. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24694. }
  24695. }
  24696. }
  24697. return noErr;
  24698. }
  24699. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24700. MidiBuffer& midiMessages)
  24701. {
  24702. const int numSamples = buffer.getNumSamples();
  24703. if (initialised)
  24704. {
  24705. AudioUnitRenderActionFlags flags = 0;
  24706. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24707. for (int i = getNumOutputChannels(); --i >= 0;)
  24708. {
  24709. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24710. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24711. }
  24712. currentBuffer = &buffer;
  24713. if (wantsMidiMessages)
  24714. {
  24715. const uint8* midiEventData;
  24716. int midiEventSize, midiEventPosition;
  24717. MidiBuffer::Iterator i (midiMessages);
  24718. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24719. {
  24720. if (midiEventSize <= 3)
  24721. MusicDeviceMIDIEvent (audioUnit,
  24722. midiEventData[0], midiEventData[1], midiEventData[2],
  24723. midiEventPosition);
  24724. else
  24725. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24726. }
  24727. midiMessages.clear();
  24728. }
  24729. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24730. 0, numSamples, outputBufferList);
  24731. timeStamp.mSampleTime += numSamples;
  24732. }
  24733. else
  24734. {
  24735. // Not initialised, so just bypass..
  24736. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24737. buffer.clear (i, 0, buffer.getNumSamples());
  24738. }
  24739. }
  24740. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24741. {
  24742. AudioPlayHead* const ph = getPlayHead();
  24743. AudioPlayHead::CurrentPositionInfo result;
  24744. if (ph != 0 && ph->getCurrentPosition (result))
  24745. {
  24746. if (outCurrentBeat != 0)
  24747. *outCurrentBeat = result.ppqPosition;
  24748. if (outCurrentTempo != 0)
  24749. *outCurrentTempo = result.bpm;
  24750. }
  24751. else
  24752. {
  24753. if (outCurrentBeat != 0)
  24754. *outCurrentBeat = 0;
  24755. if (outCurrentTempo != 0)
  24756. *outCurrentTempo = 120.0;
  24757. }
  24758. return noErr;
  24759. }
  24760. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24761. Float32* outTimeSig_Numerator,
  24762. UInt32* outTimeSig_Denominator,
  24763. Float64* outCurrentMeasureDownBeat) const
  24764. {
  24765. AudioPlayHead* const ph = getPlayHead();
  24766. AudioPlayHead::CurrentPositionInfo result;
  24767. if (ph != 0 && ph->getCurrentPosition (result))
  24768. {
  24769. if (outTimeSig_Numerator != 0)
  24770. *outTimeSig_Numerator = result.timeSigNumerator;
  24771. if (outTimeSig_Denominator != 0)
  24772. *outTimeSig_Denominator = result.timeSigDenominator;
  24773. if (outDeltaSampleOffsetToNextBeat != 0)
  24774. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24775. if (outCurrentMeasureDownBeat != 0)
  24776. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24777. }
  24778. else
  24779. {
  24780. if (outDeltaSampleOffsetToNextBeat != 0)
  24781. *outDeltaSampleOffsetToNextBeat = 0;
  24782. if (outTimeSig_Numerator != 0)
  24783. *outTimeSig_Numerator = 4;
  24784. if (outTimeSig_Denominator != 0)
  24785. *outTimeSig_Denominator = 4;
  24786. if (outCurrentMeasureDownBeat != 0)
  24787. *outCurrentMeasureDownBeat = 0;
  24788. }
  24789. return noErr;
  24790. }
  24791. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24792. Boolean* outTransportStateChanged,
  24793. Float64* outCurrentSampleInTimeLine,
  24794. Boolean* outIsCycling,
  24795. Float64* outCycleStartBeat,
  24796. Float64* outCycleEndBeat)
  24797. {
  24798. AudioPlayHead* const ph = getPlayHead();
  24799. AudioPlayHead::CurrentPositionInfo result;
  24800. if (ph != 0 && ph->getCurrentPosition (result))
  24801. {
  24802. if (outIsPlaying != 0)
  24803. *outIsPlaying = result.isPlaying;
  24804. if (outTransportStateChanged != 0)
  24805. {
  24806. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24807. wasPlaying = result.isPlaying;
  24808. }
  24809. if (outCurrentSampleInTimeLine != 0)
  24810. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24811. if (outIsCycling != 0)
  24812. *outIsCycling = false;
  24813. if (outCycleStartBeat != 0)
  24814. *outCycleStartBeat = 0;
  24815. if (outCycleEndBeat != 0)
  24816. *outCycleEndBeat = 0;
  24817. }
  24818. else
  24819. {
  24820. if (outIsPlaying != 0)
  24821. *outIsPlaying = false;
  24822. if (outTransportStateChanged != 0)
  24823. *outTransportStateChanged = false;
  24824. if (outCurrentSampleInTimeLine != 0)
  24825. *outCurrentSampleInTimeLine = 0;
  24826. if (outIsCycling != 0)
  24827. *outIsCycling = false;
  24828. if (outCycleStartBeat != 0)
  24829. *outCycleStartBeat = 0;
  24830. if (outCycleEndBeat != 0)
  24831. *outCycleEndBeat = 0;
  24832. }
  24833. return noErr;
  24834. }
  24835. static VoidArray activeWindows;
  24836. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24837. {
  24838. public:
  24839. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24840. : AudioProcessorEditor (&plugin_),
  24841. plugin (plugin_),
  24842. wrapper (0)
  24843. {
  24844. addAndMakeVisible (wrapper = new NSViewComponent());
  24845. activeWindows.add (this);
  24846. setOpaque (true);
  24847. setVisible (true);
  24848. setSize (100, 100);
  24849. createView (createGenericViewIfNeeded);
  24850. }
  24851. ~AudioUnitPluginWindowCocoa()
  24852. {
  24853. const bool wasValid = isValid();
  24854. wrapper->setView (0);
  24855. activeWindows.removeValue (this);
  24856. if (wasValid)
  24857. plugin.editorBeingDeleted (this);
  24858. delete wrapper;
  24859. }
  24860. bool isValid() const { return wrapper->getView() != 0; }
  24861. void paint (Graphics& g)
  24862. {
  24863. g.fillAll (Colours::white);
  24864. }
  24865. void resized()
  24866. {
  24867. wrapper->setSize (getWidth(), getHeight());
  24868. }
  24869. private:
  24870. AudioUnitPluginInstance& plugin;
  24871. NSViewComponent* wrapper;
  24872. bool createView (const bool createGenericViewIfNeeded)
  24873. {
  24874. NSView* pluginView = 0;
  24875. UInt32 dataSize = 0;
  24876. Boolean isWritable = false;
  24877. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24878. 0, &dataSize, &isWritable) == noErr
  24879. && dataSize != 0
  24880. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24881. 0, &dataSize, &isWritable) == noErr)
  24882. {
  24883. HeapBlock <AudioUnitCocoaViewInfo> info;
  24884. info.calloc (dataSize, 1);
  24885. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24886. 0, info, &dataSize) == noErr)
  24887. {
  24888. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24889. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24890. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24891. Class viewClass = [viewBundle classNamed: viewClassName];
  24892. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24893. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24894. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24895. {
  24896. id factory = [[[viewClass alloc] init] autorelease];
  24897. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24898. withSize: NSMakeSize (getWidth(), getHeight())];
  24899. }
  24900. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24901. {
  24902. CFRelease (info->mCocoaAUViewClass[i]);
  24903. CFRelease (info->mCocoaAUViewBundleLocation);
  24904. }
  24905. }
  24906. }
  24907. if (createGenericViewIfNeeded && (pluginView == 0))
  24908. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24909. wrapper->setView (pluginView);
  24910. if (pluginView != 0)
  24911. setSize ([pluginView frame].size.width,
  24912. [pluginView frame].size.height);
  24913. return pluginView != 0;
  24914. }
  24915. };
  24916. #if JUCE_SUPPORT_CARBON
  24917. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24918. {
  24919. public:
  24920. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24921. : AudioProcessorEditor (&plugin_),
  24922. plugin (plugin_),
  24923. viewComponent (0)
  24924. {
  24925. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24926. activeWindows.add (this);
  24927. setOpaque (true);
  24928. setVisible (true);
  24929. setSize (400, 300);
  24930. ComponentDescription viewList [16];
  24931. UInt32 viewListSize = sizeof (viewList);
  24932. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24933. 0, &viewList, &viewListSize);
  24934. componentRecord = FindNextComponent (0, &viewList[0]);
  24935. }
  24936. ~AudioUnitPluginWindowCarbon()
  24937. {
  24938. deleteAndZero (innerWrapper);
  24939. activeWindows.removeValue (this);
  24940. if (isValid())
  24941. plugin.editorBeingDeleted (this);
  24942. }
  24943. bool isValid() const throw() { return componentRecord != 0; }
  24944. void paint (Graphics& g)
  24945. {
  24946. g.fillAll (Colours::black);
  24947. }
  24948. void resized()
  24949. {
  24950. innerWrapper->setSize (getWidth(), getHeight());
  24951. }
  24952. bool keyStateChanged (const bool)
  24953. {
  24954. return false;
  24955. }
  24956. bool keyPressed (const KeyPress&)
  24957. {
  24958. return false;
  24959. }
  24960. void broughtToFront()
  24961. {
  24962. activeWindows.removeValue (this);
  24963. activeWindows.add (this);
  24964. }
  24965. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24966. AudioUnitCarbonView getViewComponent()
  24967. {
  24968. if (viewComponent == 0 && componentRecord != 0)
  24969. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24970. return viewComponent;
  24971. }
  24972. void closeViewComponent()
  24973. {
  24974. if (viewComponent != 0)
  24975. {
  24976. CloseComponent (viewComponent);
  24977. viewComponent = 0;
  24978. }
  24979. }
  24980. juce_UseDebuggingNewOperator
  24981. private:
  24982. AudioUnitPluginInstance& plugin;
  24983. ComponentRecord* componentRecord;
  24984. AudioUnitCarbonView viewComponent;
  24985. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24986. {
  24987. public:
  24988. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24989. : owner (owner_)
  24990. {
  24991. }
  24992. ~InnerWrapperComponent()
  24993. {
  24994. deleteWindow();
  24995. }
  24996. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24997. {
  24998. log (T("Opening AU GUI: ") + owner->plugin.getName());
  24999. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  25000. if (viewComponent == 0)
  25001. return 0;
  25002. Float32Point pos = { 0, 0 };
  25003. Float32Point size = { 250, 200 };
  25004. HIViewRef pluginView = 0;
  25005. AudioUnitCarbonViewCreate (viewComponent,
  25006. owner->getAudioUnit(),
  25007. windowRef,
  25008. rootView,
  25009. &pos,
  25010. &size,
  25011. (ControlRef*) &pluginView);
  25012. return pluginView;
  25013. }
  25014. void removeView (HIViewRef)
  25015. {
  25016. log (T("Closing AU GUI: ") + owner->plugin.getName());
  25017. owner->closeViewComponent();
  25018. }
  25019. private:
  25020. AudioUnitPluginWindowCarbon* const owner;
  25021. };
  25022. friend class InnerWrapperComponent;
  25023. InnerWrapperComponent* innerWrapper;
  25024. };
  25025. #endif
  25026. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  25027. {
  25028. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  25029. if (! ((AudioUnitPluginWindowCocoa*) w)->isValid())
  25030. w = 0;
  25031. #if JUCE_SUPPORT_CARBON
  25032. if (w == 0)
  25033. {
  25034. w = new AudioUnitPluginWindowCarbon (*this);
  25035. if (! ((AudioUnitPluginWindowCarbon*) w)->isValid())
  25036. w = 0;
  25037. }
  25038. #endif
  25039. if (w == 0)
  25040. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  25041. return w.release();
  25042. }
  25043. const String AudioUnitPluginInstance::getCategory() const
  25044. {
  25045. const char* result = 0;
  25046. switch (componentDesc.componentType)
  25047. {
  25048. case kAudioUnitType_Effect:
  25049. case kAudioUnitType_MusicEffect:
  25050. result = "Effect";
  25051. break;
  25052. case kAudioUnitType_MusicDevice:
  25053. result = "Synth";
  25054. break;
  25055. case kAudioUnitType_Generator:
  25056. result = "Generator";
  25057. break;
  25058. case kAudioUnitType_Panner:
  25059. result = "Panner";
  25060. break;
  25061. default:
  25062. break;
  25063. }
  25064. return result;
  25065. }
  25066. int AudioUnitPluginInstance::getNumParameters()
  25067. {
  25068. return parameterIds.size();
  25069. }
  25070. float AudioUnitPluginInstance::getParameter (int index)
  25071. {
  25072. const ScopedLock sl (lock);
  25073. Float32 value = 0.0f;
  25074. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25075. {
  25076. AudioUnitGetParameter (audioUnit,
  25077. (UInt32) parameterIds.getUnchecked (index),
  25078. kAudioUnitScope_Global, 0,
  25079. &value);
  25080. }
  25081. return value;
  25082. }
  25083. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  25084. {
  25085. const ScopedLock sl (lock);
  25086. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25087. {
  25088. AudioUnitSetParameter (audioUnit,
  25089. (UInt32) parameterIds.getUnchecked (index),
  25090. kAudioUnitScope_Global, 0,
  25091. newValue, 0);
  25092. }
  25093. }
  25094. const String AudioUnitPluginInstance::getParameterName (int index)
  25095. {
  25096. AudioUnitParameterInfo info;
  25097. zerostruct (info);
  25098. UInt32 sz = sizeof (info);
  25099. String name;
  25100. if (AudioUnitGetProperty (audioUnit,
  25101. kAudioUnitProperty_ParameterInfo,
  25102. kAudioUnitScope_Global,
  25103. parameterIds [index], &info, &sz) == noErr)
  25104. {
  25105. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25106. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25107. else
  25108. name = String (info.name, sizeof (info.name));
  25109. }
  25110. return name;
  25111. }
  25112. const String AudioUnitPluginInstance::getParameterText (int index)
  25113. {
  25114. return String (getParameter (index));
  25115. }
  25116. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25117. {
  25118. AudioUnitParameterInfo info;
  25119. UInt32 sz = sizeof (info);
  25120. if (AudioUnitGetProperty (audioUnit,
  25121. kAudioUnitProperty_ParameterInfo,
  25122. kAudioUnitScope_Global,
  25123. parameterIds [index], &info, &sz) == noErr)
  25124. {
  25125. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25126. }
  25127. return true;
  25128. }
  25129. int AudioUnitPluginInstance::getNumPrograms()
  25130. {
  25131. CFArrayRef presets;
  25132. UInt32 sz = sizeof (CFArrayRef);
  25133. int num = 0;
  25134. if (AudioUnitGetProperty (audioUnit,
  25135. kAudioUnitProperty_FactoryPresets,
  25136. kAudioUnitScope_Global,
  25137. 0, &presets, &sz) == noErr)
  25138. {
  25139. num = (int) CFArrayGetCount (presets);
  25140. CFRelease (presets);
  25141. }
  25142. return num;
  25143. }
  25144. int AudioUnitPluginInstance::getCurrentProgram()
  25145. {
  25146. AUPreset current;
  25147. current.presetNumber = 0;
  25148. UInt32 sz = sizeof (AUPreset);
  25149. AudioUnitGetProperty (audioUnit,
  25150. kAudioUnitProperty_FactoryPresets,
  25151. kAudioUnitScope_Global,
  25152. 0, &current, &sz);
  25153. return current.presetNumber;
  25154. }
  25155. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25156. {
  25157. AUPreset current;
  25158. current.presetNumber = newIndex;
  25159. current.presetName = 0;
  25160. AudioUnitSetProperty (audioUnit,
  25161. kAudioUnitProperty_FactoryPresets,
  25162. kAudioUnitScope_Global,
  25163. 0, &current, sizeof (AUPreset));
  25164. }
  25165. const String AudioUnitPluginInstance::getProgramName (int index)
  25166. {
  25167. String s;
  25168. CFArrayRef presets;
  25169. UInt32 sz = sizeof (CFArrayRef);
  25170. if (AudioUnitGetProperty (audioUnit,
  25171. kAudioUnitProperty_FactoryPresets,
  25172. kAudioUnitScope_Global,
  25173. 0, &presets, &sz) == noErr)
  25174. {
  25175. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25176. {
  25177. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25178. if (p != 0 && p->presetNumber == index)
  25179. {
  25180. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25181. break;
  25182. }
  25183. }
  25184. CFRelease (presets);
  25185. }
  25186. return s;
  25187. }
  25188. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25189. {
  25190. jassertfalse // xxx not implemented!
  25191. }
  25192. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25193. {
  25194. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25195. return T("Input ") + String (index + 1);
  25196. return String::empty;
  25197. }
  25198. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25199. {
  25200. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25201. return false;
  25202. return true;
  25203. }
  25204. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25205. {
  25206. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25207. return T("Output ") + String (index + 1);
  25208. return String::empty;
  25209. }
  25210. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25211. {
  25212. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25213. return false;
  25214. return true;
  25215. }
  25216. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25217. {
  25218. getCurrentProgramStateInformation (destData);
  25219. }
  25220. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25221. {
  25222. CFPropertyListRef propertyList = 0;
  25223. UInt32 sz = sizeof (CFPropertyListRef);
  25224. if (AudioUnitGetProperty (audioUnit,
  25225. kAudioUnitProperty_ClassInfo,
  25226. kAudioUnitScope_Global,
  25227. 0, &propertyList, &sz) == noErr)
  25228. {
  25229. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25230. CFWriteStreamOpen (stream);
  25231. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25232. CFWriteStreamClose (stream);
  25233. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25234. destData.setSize (bytesWritten);
  25235. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25236. CFRelease (data);
  25237. CFRelease (stream);
  25238. CFRelease (propertyList);
  25239. }
  25240. }
  25241. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25242. {
  25243. setCurrentProgramStateInformation (data, sizeInBytes);
  25244. }
  25245. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25246. {
  25247. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25248. (const UInt8*) data,
  25249. sizeInBytes,
  25250. kCFAllocatorNull);
  25251. CFReadStreamOpen (stream);
  25252. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25253. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25254. stream,
  25255. 0,
  25256. kCFPropertyListImmutable,
  25257. &format,
  25258. 0);
  25259. CFRelease (stream);
  25260. if (propertyList != 0)
  25261. AudioUnitSetProperty (audioUnit,
  25262. kAudioUnitProperty_ClassInfo,
  25263. kAudioUnitScope_Global,
  25264. 0, &propertyList, sizeof (propertyList));
  25265. }
  25266. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25267. {
  25268. }
  25269. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25270. {
  25271. }
  25272. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25273. const String& fileOrIdentifier)
  25274. {
  25275. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25276. return;
  25277. PluginDescription desc;
  25278. desc.fileOrIdentifier = fileOrIdentifier;
  25279. desc.uid = 0;
  25280. try
  25281. {
  25282. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25283. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25284. if (auInstance != 0)
  25285. {
  25286. auInstance->fillInPluginDescription (desc);
  25287. results.add (new PluginDescription (desc));
  25288. }
  25289. }
  25290. catch (...)
  25291. {
  25292. // crashed while loading...
  25293. }
  25294. }
  25295. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25296. {
  25297. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25298. {
  25299. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25300. if (result->audioUnit != 0)
  25301. {
  25302. result->initialise();
  25303. return result.release();
  25304. }
  25305. }
  25306. return 0;
  25307. }
  25308. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25309. const bool /*recursive*/)
  25310. {
  25311. StringArray result;
  25312. ComponentRecord* comp = 0;
  25313. ComponentDescription desc;
  25314. zerostruct (desc);
  25315. for (;;)
  25316. {
  25317. zerostruct (desc);
  25318. comp = FindNextComponent (comp, &desc);
  25319. if (comp == 0)
  25320. break;
  25321. GetComponentInfo (comp, &desc, 0, 0, 0);
  25322. if (desc.componentType == kAudioUnitType_MusicDevice
  25323. || desc.componentType == kAudioUnitType_MusicEffect
  25324. || desc.componentType == kAudioUnitType_Effect
  25325. || desc.componentType == kAudioUnitType_Generator
  25326. || desc.componentType == kAudioUnitType_Panner)
  25327. {
  25328. const String s (createAUPluginIdentifier (desc));
  25329. DBG (s);
  25330. result.add (s);
  25331. }
  25332. }
  25333. return result;
  25334. }
  25335. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25336. {
  25337. ComponentDescription desc;
  25338. String name, version, manufacturer;
  25339. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25340. return FindNextComponent (0, &desc) != 0;
  25341. const File f (fileOrIdentifier);
  25342. return f.hasFileExtension (T(".component"))
  25343. && f.isDirectory();
  25344. }
  25345. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25346. {
  25347. ComponentDescription desc;
  25348. String name, version, manufacturer;
  25349. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25350. if (name.isEmpty())
  25351. name = fileOrIdentifier;
  25352. return name;
  25353. }
  25354. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25355. {
  25356. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25357. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25358. else
  25359. return File (desc.fileOrIdentifier).exists();
  25360. }
  25361. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25362. {
  25363. return FileSearchPath ("/(Default AudioUnit locations)");
  25364. }
  25365. #endif
  25366. END_JUCE_NAMESPACE
  25367. #undef log
  25368. #endif
  25369. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25370. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25371. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25372. #define JUCE_MAC_VST_INCLUDED 1
  25373. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25374. #if JUCE_PLUGINHOST_VST
  25375. #if (defined (_WIN32) || defined (_WIN64))
  25376. #undef _WIN32_WINNT
  25377. #define _WIN32_WINNT 0x500
  25378. #undef STRICT
  25379. #define STRICT
  25380. #include <windows.h>
  25381. #include <float.h>
  25382. #pragma warning (disable : 4312 4355)
  25383. #elif defined (LINUX) || defined (__linux__)
  25384. #include <float.h>
  25385. #include <sys/time.h>
  25386. #include <X11/Xlib.h>
  25387. #include <X11/Xutil.h>
  25388. #include <X11/Xatom.h>
  25389. #undef Font
  25390. #undef KeyPress
  25391. #undef Drawable
  25392. #undef Time
  25393. #else
  25394. #ifndef JUCE_MAC_VST_INCLUDED
  25395. // On the mac, this file needs to be compiled indirectly, by using
  25396. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25397. #error
  25398. #endif
  25399. #include <Cocoa/Cocoa.h>
  25400. #include <Carbon/Carbon.h>
  25401. #endif
  25402. #if ! (JUCE_MAC && JUCE_64BIT)
  25403. BEGIN_JUCE_NAMESPACE
  25404. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25405. #endif
  25406. #undef PRAGMA_ALIGN_SUPPORTED
  25407. #define VST_FORCE_DEPRECATED 0
  25408. #ifdef _MSC_VER
  25409. #pragma warning (push)
  25410. #pragma warning (disable: 4996)
  25411. #endif
  25412. #include "pluginterfaces/vst2.x/aeffectx.h"
  25413. #ifdef _MSC_VER
  25414. #pragma warning (pop)
  25415. #endif
  25416. #if JUCE_LINUX
  25417. #define Font JUCE_NAMESPACE::Font
  25418. #define KeyPress JUCE_NAMESPACE::KeyPress
  25419. #define Drawable JUCE_NAMESPACE::Drawable
  25420. #define Time JUCE_NAMESPACE::Time
  25421. #endif
  25422. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25423. #ifdef __aeffect__
  25424. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25425. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25426. class VSTMidiEventList
  25427. {
  25428. public:
  25429. VSTMidiEventList()
  25430. : numEventsUsed (0), numEventsAllocated (0)
  25431. {
  25432. }
  25433. ~VSTMidiEventList()
  25434. {
  25435. freeEvents();
  25436. }
  25437. void clear()
  25438. {
  25439. numEventsUsed = 0;
  25440. if (events != 0)
  25441. events->numEvents = 0;
  25442. }
  25443. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25444. {
  25445. ensureSize (numEventsUsed + 1);
  25446. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25447. events->numEvents = ++numEventsUsed;
  25448. if (numBytes <= 4)
  25449. {
  25450. if (e->type == kVstSysExType)
  25451. {
  25452. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25453. e->type = kVstMidiType;
  25454. e->byteSize = sizeof (VstMidiEvent);
  25455. e->noteLength = 0;
  25456. e->noteOffset = 0;
  25457. e->detune = 0;
  25458. e->noteOffVelocity = 0;
  25459. }
  25460. e->deltaFrames = frameOffset;
  25461. memcpy (e->midiData, midiData, numBytes);
  25462. }
  25463. else
  25464. {
  25465. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25466. if (se->type == kVstSysExType)
  25467. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25468. else
  25469. se->sysexDump = (char*) juce_malloc (numBytes);
  25470. memcpy (se->sysexDump, midiData, numBytes);
  25471. se->type = kVstSysExType;
  25472. se->byteSize = sizeof (VstMidiSysexEvent);
  25473. se->deltaFrames = frameOffset;
  25474. se->flags = 0;
  25475. se->dumpBytes = numBytes;
  25476. se->resvd1 = 0;
  25477. se->resvd2 = 0;
  25478. }
  25479. }
  25480. // Handy method to pull the events out of an event buffer supplied by the host
  25481. // or plugin.
  25482. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25483. {
  25484. for (int i = 0; i < events->numEvents; ++i)
  25485. {
  25486. const VstEvent* const e = events->events[i];
  25487. if (e != 0)
  25488. {
  25489. if (e->type == kVstMidiType)
  25490. {
  25491. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25492. 4, e->deltaFrames);
  25493. }
  25494. else if (e->type == kVstSysExType)
  25495. {
  25496. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25497. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25498. e->deltaFrames);
  25499. }
  25500. }
  25501. }
  25502. }
  25503. void ensureSize (int numEventsNeeded)
  25504. {
  25505. if (numEventsNeeded > numEventsAllocated)
  25506. {
  25507. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25508. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25509. if (events == 0)
  25510. events.calloc (size, 1);
  25511. else
  25512. events.realloc (size, 1);
  25513. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25514. {
  25515. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25516. (int) sizeof (VstMidiSysexEvent)));
  25517. e->type = kVstMidiType;
  25518. e->byteSize = sizeof (VstMidiEvent);
  25519. events->events[i] = (VstEvent*) e;
  25520. }
  25521. numEventsAllocated = numEventsNeeded;
  25522. }
  25523. }
  25524. void freeEvents()
  25525. {
  25526. if (events != 0)
  25527. {
  25528. for (int i = numEventsAllocated; --i >= 0;)
  25529. {
  25530. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25531. if (e->type == kVstSysExType)
  25532. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25533. juce_free (e);
  25534. }
  25535. events.free();
  25536. numEventsUsed = 0;
  25537. numEventsAllocated = 0;
  25538. }
  25539. }
  25540. HeapBlock <VstEvents> events;
  25541. private:
  25542. int numEventsUsed, numEventsAllocated;
  25543. };
  25544. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25545. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25546. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25547. #if ! JUCE_WIN32
  25548. #define _fpreset()
  25549. #define _clearfp()
  25550. #endif
  25551. extern void juce_callAnyTimersSynchronously();
  25552. const int fxbVersionNum = 1;
  25553. struct fxProgram
  25554. {
  25555. long chunkMagic; // 'CcnK'
  25556. long byteSize; // of this chunk, excl. magic + byteSize
  25557. long fxMagic; // 'FxCk'
  25558. long version;
  25559. long fxID; // fx unique id
  25560. long fxVersion;
  25561. long numParams;
  25562. char prgName[28];
  25563. float params[1]; // variable no. of parameters
  25564. };
  25565. struct fxSet
  25566. {
  25567. long chunkMagic; // 'CcnK'
  25568. long byteSize; // of this chunk, excl. magic + byteSize
  25569. long fxMagic; // 'FxBk'
  25570. long version;
  25571. long fxID; // fx unique id
  25572. long fxVersion;
  25573. long numPrograms;
  25574. char future[128];
  25575. fxProgram programs[1]; // variable no. of programs
  25576. };
  25577. struct fxChunkSet
  25578. {
  25579. long chunkMagic; // 'CcnK'
  25580. long byteSize; // of this chunk, excl. magic + byteSize
  25581. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25582. long version;
  25583. long fxID; // fx unique id
  25584. long fxVersion;
  25585. long numPrograms;
  25586. char future[128];
  25587. long chunkSize;
  25588. char chunk[8]; // variable
  25589. };
  25590. struct fxProgramSet
  25591. {
  25592. long chunkMagic; // 'CcnK'
  25593. long byteSize; // of this chunk, excl. magic + byteSize
  25594. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25595. long version;
  25596. long fxID; // fx unique id
  25597. long fxVersion;
  25598. long numPrograms;
  25599. char name[28];
  25600. long chunkSize;
  25601. char chunk[8]; // variable
  25602. };
  25603. static long vst_swap (const long x) throw()
  25604. {
  25605. #ifdef JUCE_LITTLE_ENDIAN
  25606. return (long) ByteOrder::swap ((uint32) x);
  25607. #else
  25608. return x;
  25609. #endif
  25610. }
  25611. static float vst_swapFloat (const float x) throw()
  25612. {
  25613. #ifdef JUCE_LITTLE_ENDIAN
  25614. union { uint32 asInt; float asFloat; } n;
  25615. n.asFloat = x;
  25616. n.asInt = ByteOrder::swap (n.asInt);
  25617. return n.asFloat;
  25618. #else
  25619. return x;
  25620. #endif
  25621. }
  25622. typedef AEffect* (*MainCall) (audioMasterCallback);
  25623. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25624. static int shellUIDToCreate = 0;
  25625. static int insideVSTCallback = 0;
  25626. class VSTPluginWindow;
  25627. // Change this to disable logging of various VST activities
  25628. #ifndef VST_LOGGING
  25629. #define VST_LOGGING 1
  25630. #endif
  25631. #if VST_LOGGING
  25632. #define log(a) Logger::writeToLog(a);
  25633. #else
  25634. #define log(a)
  25635. #endif
  25636. #if JUCE_MAC && JUCE_PPC
  25637. static void* NewCFMFromMachO (void* const machofp) throw()
  25638. {
  25639. void* result = juce_malloc (8);
  25640. ((void**) result)[0] = machofp;
  25641. ((void**) result)[1] = result;
  25642. return result;
  25643. }
  25644. #endif
  25645. #if JUCE_LINUX
  25646. extern Display* display;
  25647. extern XContext improbableNumber;
  25648. typedef void (*EventProcPtr) (XEvent* ev);
  25649. static bool xErrorTriggered;
  25650. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25651. {
  25652. xErrorTriggered = true;
  25653. return 0;
  25654. }
  25655. static int getPropertyFromXWindow (Window handle, Atom atom)
  25656. {
  25657. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25658. xErrorTriggered = false;
  25659. int userSize;
  25660. unsigned long bytes, userCount;
  25661. unsigned char* data;
  25662. Atom userType;
  25663. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25664. &userType, &userSize, &userCount, &bytes, &data);
  25665. XSetErrorHandler (oldErrorHandler);
  25666. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25667. : 0;
  25668. }
  25669. static Window getChildWindow (Window windowToCheck)
  25670. {
  25671. Window rootWindow, parentWindow;
  25672. Window* childWindows;
  25673. unsigned int numChildren;
  25674. XQueryTree (display,
  25675. windowToCheck,
  25676. &rootWindow,
  25677. &parentWindow,
  25678. &childWindows,
  25679. &numChildren);
  25680. if (numChildren > 0)
  25681. return childWindows [0];
  25682. return 0;
  25683. }
  25684. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25685. {
  25686. if (e.mods.isLeftButtonDown())
  25687. {
  25688. ev.xbutton.button = Button1;
  25689. ev.xbutton.state |= Button1Mask;
  25690. }
  25691. else if (e.mods.isRightButtonDown())
  25692. {
  25693. ev.xbutton.button = Button3;
  25694. ev.xbutton.state |= Button3Mask;
  25695. }
  25696. else if (e.mods.isMiddleButtonDown())
  25697. {
  25698. ev.xbutton.button = Button2;
  25699. ev.xbutton.state |= Button2Mask;
  25700. }
  25701. }
  25702. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25703. {
  25704. if (e.mods.isLeftButtonDown())
  25705. ev.xmotion.state |= Button1Mask;
  25706. else if (e.mods.isRightButtonDown())
  25707. ev.xmotion.state |= Button3Mask;
  25708. else if (e.mods.isMiddleButtonDown())
  25709. ev.xmotion.state |= Button2Mask;
  25710. }
  25711. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25712. {
  25713. if (e.mods.isLeftButtonDown())
  25714. ev.xcrossing.state |= Button1Mask;
  25715. else if (e.mods.isRightButtonDown())
  25716. ev.xcrossing.state |= Button3Mask;
  25717. else if (e.mods.isMiddleButtonDown())
  25718. ev.xcrossing.state |= Button2Mask;
  25719. }
  25720. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25721. {
  25722. if (increment < 0)
  25723. {
  25724. ev.xbutton.button = Button5;
  25725. ev.xbutton.state |= Button5Mask;
  25726. }
  25727. else if (increment > 0)
  25728. {
  25729. ev.xbutton.button = Button4;
  25730. ev.xbutton.state |= Button4Mask;
  25731. }
  25732. }
  25733. #endif
  25734. static VoidArray activeModules;
  25735. class ModuleHandle : public ReferenceCountedObject
  25736. {
  25737. public:
  25738. File file;
  25739. MainCall moduleMain;
  25740. String pluginName;
  25741. static ModuleHandle* findOrCreateModule (const File& file)
  25742. {
  25743. for (int i = activeModules.size(); --i >= 0;)
  25744. {
  25745. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25746. if (module->file == file)
  25747. return module;
  25748. }
  25749. _fpreset(); // (doesn't do any harm)
  25750. ++insideVSTCallback;
  25751. shellUIDToCreate = 0;
  25752. log ("Attempting to load VST: " + file.getFullPathName());
  25753. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25754. if (! m->open())
  25755. m = 0;
  25756. --insideVSTCallback;
  25757. _fpreset(); // (doesn't do any harm)
  25758. return m.release();
  25759. }
  25760. ModuleHandle (const File& file_)
  25761. : file (file_),
  25762. moduleMain (0),
  25763. #if JUCE_WIN32 || JUCE_LINUX
  25764. hModule (0)
  25765. #elif JUCE_MAC
  25766. fragId (0),
  25767. resHandle (0),
  25768. bundleRef (0),
  25769. resFileId (0)
  25770. #endif
  25771. {
  25772. activeModules.add (this);
  25773. #if JUCE_WIN32 || JUCE_LINUX
  25774. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25775. #elif JUCE_MAC
  25776. FSRef ref;
  25777. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25778. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25779. #endif
  25780. }
  25781. ~ModuleHandle()
  25782. {
  25783. activeModules.removeValue (this);
  25784. close();
  25785. }
  25786. juce_UseDebuggingNewOperator
  25787. #if JUCE_WIN32 || JUCE_LINUX
  25788. void* hModule;
  25789. String fullParentDirectoryPathName;
  25790. bool open()
  25791. {
  25792. #if JUCE_WIN32
  25793. static bool timePeriodSet = false;
  25794. if (! timePeriodSet)
  25795. {
  25796. timePeriodSet = true;
  25797. timeBeginPeriod (2);
  25798. }
  25799. #endif
  25800. pluginName = file.getFileNameWithoutExtension();
  25801. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25802. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25803. if (moduleMain == 0)
  25804. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25805. return moduleMain != 0;
  25806. }
  25807. void close()
  25808. {
  25809. _fpreset(); // (doesn't do any harm)
  25810. PlatformUtilities::freeDynamicLibrary (hModule);
  25811. }
  25812. void closeEffect (AEffect* eff)
  25813. {
  25814. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25815. }
  25816. #else
  25817. CFragConnectionID fragId;
  25818. Handle resHandle;
  25819. CFBundleRef bundleRef;
  25820. FSSpec parentDirFSSpec;
  25821. short resFileId;
  25822. bool open()
  25823. {
  25824. bool ok = false;
  25825. const String filename (file.getFullPathName());
  25826. if (file.hasFileExtension (T(".vst")))
  25827. {
  25828. const char* const utf8 = filename.toUTF8();
  25829. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25830. strlen (utf8), file.isDirectory());
  25831. if (url != 0)
  25832. {
  25833. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25834. CFRelease (url);
  25835. if (bundleRef != 0)
  25836. {
  25837. if (CFBundleLoadExecutable (bundleRef))
  25838. {
  25839. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25840. if (moduleMain == 0)
  25841. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25842. if (moduleMain != 0)
  25843. {
  25844. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25845. if (name != 0)
  25846. {
  25847. if (CFGetTypeID (name) == CFStringGetTypeID())
  25848. {
  25849. char buffer[1024];
  25850. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25851. pluginName = buffer;
  25852. }
  25853. }
  25854. if (pluginName.isEmpty())
  25855. pluginName = file.getFileNameWithoutExtension();
  25856. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25857. ok = true;
  25858. }
  25859. }
  25860. if (! ok)
  25861. {
  25862. CFBundleUnloadExecutable (bundleRef);
  25863. CFRelease (bundleRef);
  25864. bundleRef = 0;
  25865. }
  25866. }
  25867. }
  25868. }
  25869. #if JUCE_PPC
  25870. else
  25871. {
  25872. FSRef fn;
  25873. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25874. {
  25875. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25876. if (resFileId != -1)
  25877. {
  25878. const int numEffs = Count1Resources ('aEff');
  25879. for (int i = 0; i < numEffs; ++i)
  25880. {
  25881. resHandle = Get1IndResource ('aEff', i + 1);
  25882. if (resHandle != 0)
  25883. {
  25884. OSType type;
  25885. Str255 name;
  25886. SInt16 id;
  25887. GetResInfo (resHandle, &id, &type, name);
  25888. pluginName = String ((const char*) name + 1, name[0]);
  25889. DetachResource (resHandle);
  25890. HLock (resHandle);
  25891. Ptr ptr;
  25892. Str255 errorText;
  25893. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25894. name, kPrivateCFragCopy,
  25895. &fragId, &ptr, errorText);
  25896. if (err == noErr)
  25897. {
  25898. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25899. ok = true;
  25900. }
  25901. else
  25902. {
  25903. HUnlock (resHandle);
  25904. }
  25905. break;
  25906. }
  25907. }
  25908. if (! ok)
  25909. CloseResFile (resFileId);
  25910. }
  25911. }
  25912. }
  25913. #endif
  25914. return ok;
  25915. }
  25916. void close()
  25917. {
  25918. #if JUCE_PPC
  25919. if (fragId != 0)
  25920. {
  25921. if (moduleMain != 0)
  25922. disposeMachOFromCFM ((void*) moduleMain);
  25923. CloseConnection (&fragId);
  25924. HUnlock (resHandle);
  25925. if (resFileId != 0)
  25926. CloseResFile (resFileId);
  25927. }
  25928. else
  25929. #endif
  25930. if (bundleRef != 0)
  25931. {
  25932. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25933. if (CFGetRetainCount (bundleRef) == 1)
  25934. CFBundleUnloadExecutable (bundleRef);
  25935. if (CFGetRetainCount (bundleRef) > 0)
  25936. CFRelease (bundleRef);
  25937. }
  25938. }
  25939. void closeEffect (AEffect* eff)
  25940. {
  25941. #if JUCE_PPC
  25942. if (fragId != 0)
  25943. {
  25944. VoidArray thingsToDelete;
  25945. thingsToDelete.add ((void*) eff->dispatcher);
  25946. thingsToDelete.add ((void*) eff->process);
  25947. thingsToDelete.add ((void*) eff->setParameter);
  25948. thingsToDelete.add ((void*) eff->getParameter);
  25949. thingsToDelete.add ((void*) eff->processReplacing);
  25950. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25951. for (int i = thingsToDelete.size(); --i >= 0;)
  25952. disposeMachOFromCFM (thingsToDelete[i]);
  25953. }
  25954. else
  25955. #endif
  25956. {
  25957. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25958. }
  25959. }
  25960. #if JUCE_PPC
  25961. static void* newMachOFromCFM (void* cfmfp)
  25962. {
  25963. if (cfmfp == 0)
  25964. return 0;
  25965. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25966. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25967. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25968. mfp[2] = 0x800c0000;
  25969. mfp[3] = 0x804c0004;
  25970. mfp[4] = 0x7c0903a6;
  25971. mfp[5] = 0x4e800420;
  25972. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25973. return mfp;
  25974. }
  25975. static void disposeMachOFromCFM (void* ptr)
  25976. {
  25977. juce_free (ptr);
  25978. }
  25979. void coerceAEffectFunctionCalls (AEffect* eff)
  25980. {
  25981. if (fragId != 0)
  25982. {
  25983. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25984. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25985. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25986. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25987. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25988. }
  25989. }
  25990. #endif
  25991. #endif
  25992. };
  25993. class VSTPluginInstance : public AudioPluginInstance,
  25994. private Timer,
  25995. private AsyncUpdater
  25996. {
  25997. public:
  25998. ~VSTPluginInstance();
  25999. // AudioPluginInstance methods:
  26000. void fillInPluginDescription (PluginDescription& desc) const
  26001. {
  26002. desc.name = name;
  26003. desc.fileOrIdentifier = module->file.getFullPathName();
  26004. desc.uid = getUID();
  26005. desc.lastFileModTime = module->file.getLastModificationTime();
  26006. desc.pluginFormatName = "VST";
  26007. desc.category = getCategory();
  26008. {
  26009. char buffer [kVstMaxVendorStrLen + 8];
  26010. zerostruct (buffer);
  26011. dispatch (effGetVendorString, 0, 0, buffer, 0);
  26012. desc.manufacturerName = buffer;
  26013. }
  26014. desc.version = getVersion();
  26015. desc.numInputChannels = getNumInputChannels();
  26016. desc.numOutputChannels = getNumOutputChannels();
  26017. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  26018. }
  26019. const String getName() const { return name; }
  26020. int getUID() const throw();
  26021. bool acceptsMidi() const { return wantsMidiMessages; }
  26022. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  26023. // AudioProcessor methods:
  26024. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  26025. void releaseResources();
  26026. void processBlock (AudioSampleBuffer& buffer,
  26027. MidiBuffer& midiMessages);
  26028. AudioProcessorEditor* createEditor();
  26029. const String getInputChannelName (const int index) const;
  26030. bool isInputChannelStereoPair (int index) const;
  26031. const String getOutputChannelName (const int index) const;
  26032. bool isOutputChannelStereoPair (int index) const;
  26033. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  26034. float getParameter (int index);
  26035. void setParameter (int index, float newValue);
  26036. const String getParameterName (int index);
  26037. const String getParameterText (int index);
  26038. bool isParameterAutomatable (int index) const;
  26039. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  26040. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  26041. void setCurrentProgram (int index);
  26042. const String getProgramName (int index);
  26043. void changeProgramName (int index, const String& newName);
  26044. void getStateInformation (MemoryBlock& destData);
  26045. void getCurrentProgramStateInformation (MemoryBlock& destData);
  26046. void setStateInformation (const void* data, int sizeInBytes);
  26047. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  26048. void timerCallback();
  26049. void handleAsyncUpdate();
  26050. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  26051. juce_UseDebuggingNewOperator
  26052. private:
  26053. friend class VSTPluginWindow;
  26054. friend class VSTPluginFormat;
  26055. AEffect* effect;
  26056. String name;
  26057. CriticalSection lock;
  26058. bool wantsMidiMessages, initialised, isPowerOn;
  26059. mutable StringArray programNames;
  26060. AudioSampleBuffer tempBuffer;
  26061. CriticalSection midiInLock;
  26062. MidiBuffer incomingMidi;
  26063. VSTMidiEventList midiEventsToSend;
  26064. VstTimeInfo vstHostTime;
  26065. HeapBlock <float*> channels;
  26066. ReferenceCountedObjectPtr <ModuleHandle> module;
  26067. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  26068. bool restoreProgramSettings (const fxProgram* const prog);
  26069. const String getCurrentProgramName();
  26070. void setParamsInProgramBlock (fxProgram* const prog) throw();
  26071. void updateStoredProgramNames();
  26072. void initialise();
  26073. void handleMidiFromPlugin (const VstEvents* const events);
  26074. void createTempParameterStore (MemoryBlock& dest);
  26075. void restoreFromTempParameterStore (const MemoryBlock& mb);
  26076. const String getParameterLabel (int index) const;
  26077. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  26078. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  26079. void setChunkData (const char* data, int size, bool isPreset);
  26080. bool loadFromFXBFile (const void* data, int numBytes);
  26081. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  26082. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  26083. const String getVersion() const throw();
  26084. const String getCategory() const throw();
  26085. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  26086. void setPower (const bool on);
  26087. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  26088. };
  26089. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  26090. : effect (0),
  26091. wantsMidiMessages (false),
  26092. initialised (false),
  26093. isPowerOn (false),
  26094. tempBuffer (1, 1),
  26095. module (module_)
  26096. {
  26097. try
  26098. {
  26099. _fpreset();
  26100. ++insideVSTCallback;
  26101. name = module->pluginName;
  26102. log (T("Creating VST instance: ") + name);
  26103. #if JUCE_MAC
  26104. if (module->resFileId != 0)
  26105. UseResFile (module->resFileId);
  26106. #if JUCE_PPC
  26107. if (module->fragId != 0)
  26108. {
  26109. static void* audioMasterCoerced = 0;
  26110. if (audioMasterCoerced == 0)
  26111. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26112. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26113. }
  26114. else
  26115. #endif
  26116. #endif
  26117. {
  26118. effect = module->moduleMain (&audioMaster);
  26119. }
  26120. --insideVSTCallback;
  26121. if (effect != 0 && effect->magic == kEffectMagic)
  26122. {
  26123. #if JUCE_PPC
  26124. module->coerceAEffectFunctionCalls (effect);
  26125. #endif
  26126. jassert (effect->resvd2 == 0);
  26127. jassert (effect->object != 0);
  26128. _fpreset(); // some dodgy plugs fuck around with this
  26129. }
  26130. else
  26131. {
  26132. effect = 0;
  26133. }
  26134. }
  26135. catch (...)
  26136. {
  26137. --insideVSTCallback;
  26138. }
  26139. }
  26140. VSTPluginInstance::~VSTPluginInstance()
  26141. {
  26142. {
  26143. const ScopedLock sl (lock);
  26144. jassert (insideVSTCallback == 0);
  26145. if (effect != 0 && effect->magic == kEffectMagic)
  26146. {
  26147. try
  26148. {
  26149. #if JUCE_MAC
  26150. if (module->resFileId != 0)
  26151. UseResFile (module->resFileId);
  26152. #endif
  26153. // Must delete any editors before deleting the plugin instance!
  26154. jassert (getActiveEditor() == 0);
  26155. _fpreset(); // some dodgy plugs fuck around with this
  26156. module->closeEffect (effect);
  26157. }
  26158. catch (...)
  26159. {}
  26160. }
  26161. module = 0;
  26162. effect = 0;
  26163. }
  26164. }
  26165. void VSTPluginInstance::initialise()
  26166. {
  26167. if (initialised || effect == 0)
  26168. return;
  26169. log (T("Initialising VST: ") + module->pluginName);
  26170. initialised = true;
  26171. dispatch (effIdentify, 0, 0, 0, 0);
  26172. // this code would ask the plugin for its name, but so few plugins
  26173. // actually bother implementing this correctly, that it's better to
  26174. // just ignore it and use the file name instead.
  26175. if (getSampleRate() > 0)
  26176. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26177. if (getBlockSize() > 0)
  26178. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26179. dispatch (effOpen, 0, 0, 0, 0);
  26180. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26181. getSampleRate(), getBlockSize());
  26182. if (getNumPrograms() > 1)
  26183. setCurrentProgram (0);
  26184. else
  26185. dispatch (effSetProgram, 0, 0, 0, 0);
  26186. int i;
  26187. for (i = effect->numInputs; --i >= 0;)
  26188. dispatch (effConnectInput, i, 1, 0, 0);
  26189. for (i = effect->numOutputs; --i >= 0;)
  26190. dispatch (effConnectOutput, i, 1, 0, 0);
  26191. updateStoredProgramNames();
  26192. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26193. setLatencySamples (effect->initialDelay);
  26194. }
  26195. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26196. int samplesPerBlockExpected)
  26197. {
  26198. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26199. sampleRate_, samplesPerBlockExpected);
  26200. setLatencySamples (effect->initialDelay);
  26201. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26202. vstHostTime.tempo = 120.0;
  26203. vstHostTime.timeSigNumerator = 4;
  26204. vstHostTime.timeSigDenominator = 4;
  26205. vstHostTime.sampleRate = sampleRate_;
  26206. vstHostTime.samplePos = 0;
  26207. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26208. initialise();
  26209. if (initialised)
  26210. {
  26211. wantsMidiMessages = wantsMidiMessages
  26212. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26213. if (wantsMidiMessages)
  26214. midiEventsToSend.ensureSize (256);
  26215. else
  26216. midiEventsToSend.freeEvents();
  26217. incomingMidi.clear();
  26218. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26219. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26220. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26221. if (! isPowerOn)
  26222. setPower (true);
  26223. // dodgy hack to force some plugins to initialise the sample rate..
  26224. if ((! hasEditor()) && getNumParameters() > 0)
  26225. {
  26226. const float old = getParameter (0);
  26227. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26228. setParameter (0, old);
  26229. }
  26230. dispatch (effStartProcess, 0, 0, 0, 0);
  26231. }
  26232. }
  26233. void VSTPluginInstance::releaseResources()
  26234. {
  26235. if (initialised)
  26236. {
  26237. dispatch (effStopProcess, 0, 0, 0, 0);
  26238. setPower (false);
  26239. }
  26240. tempBuffer.setSize (1, 1);
  26241. incomingMidi.clear();
  26242. midiEventsToSend.freeEvents();
  26243. channels.free();
  26244. }
  26245. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26246. MidiBuffer& midiMessages)
  26247. {
  26248. const int numSamples = buffer.getNumSamples();
  26249. if (initialised)
  26250. {
  26251. AudioPlayHead* playHead = getPlayHead();
  26252. if (playHead != 0)
  26253. {
  26254. AudioPlayHead::CurrentPositionInfo position;
  26255. playHead->getCurrentPosition (position);
  26256. vstHostTime.tempo = position.bpm;
  26257. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26258. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26259. vstHostTime.ppqPos = position.ppqPosition;
  26260. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26261. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26262. if (position.isPlaying)
  26263. vstHostTime.flags |= kVstTransportPlaying;
  26264. else
  26265. vstHostTime.flags &= ~kVstTransportPlaying;
  26266. }
  26267. #if JUCE_WIN32
  26268. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26269. #elif JUCE_LINUX
  26270. timeval micro;
  26271. gettimeofday (&micro, 0);
  26272. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26273. #elif JUCE_MAC
  26274. UnsignedWide micro;
  26275. Microseconds (&micro);
  26276. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26277. #endif
  26278. if (wantsMidiMessages)
  26279. {
  26280. midiEventsToSend.clear();
  26281. midiEventsToSend.ensureSize (1);
  26282. MidiBuffer::Iterator iter (midiMessages);
  26283. const uint8* midiData;
  26284. int numBytesOfMidiData, samplePosition;
  26285. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26286. {
  26287. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26288. jlimit (0, numSamples - 1, samplePosition));
  26289. }
  26290. try
  26291. {
  26292. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26293. }
  26294. catch (...)
  26295. {}
  26296. }
  26297. int i;
  26298. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26299. for (i = 0; i < maxChans; ++i)
  26300. channels[i] = buffer.getSampleData (i);
  26301. channels [maxChans] = 0;
  26302. _clearfp();
  26303. if ((effect->flags & effFlagsCanReplacing) != 0)
  26304. {
  26305. try
  26306. {
  26307. effect->processReplacing (effect, channels, channels, numSamples);
  26308. }
  26309. catch (...)
  26310. {}
  26311. }
  26312. else
  26313. {
  26314. tempBuffer.setSize (effect->numOutputs, numSamples);
  26315. tempBuffer.clear();
  26316. float* outs [64];
  26317. for (i = effect->numOutputs; --i >= 0;)
  26318. outs[i] = tempBuffer.getSampleData (i);
  26319. outs [effect->numOutputs] = 0;
  26320. try
  26321. {
  26322. effect->process (effect, channels, outs, numSamples);
  26323. }
  26324. catch (...)
  26325. {}
  26326. for (i = effect->numOutputs; --i >= 0;)
  26327. buffer.copyFrom (i, 0, outs[i], numSamples);
  26328. }
  26329. }
  26330. else
  26331. {
  26332. // Not initialised, so just bypass..
  26333. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26334. buffer.clear (i, 0, buffer.getNumSamples());
  26335. }
  26336. {
  26337. // copy any incoming midi..
  26338. const ScopedLock sl (midiInLock);
  26339. midiMessages = incomingMidi;
  26340. incomingMidi.clear();
  26341. }
  26342. }
  26343. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26344. {
  26345. if (events != 0)
  26346. {
  26347. const ScopedLock sl (midiInLock);
  26348. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26349. }
  26350. }
  26351. static Array <VSTPluginWindow*> activeVSTWindows;
  26352. class VSTPluginWindow : public AudioProcessorEditor,
  26353. #if ! JUCE_MAC
  26354. public ComponentMovementWatcher,
  26355. #endif
  26356. public Timer
  26357. {
  26358. public:
  26359. VSTPluginWindow (VSTPluginInstance& plugin_)
  26360. : AudioProcessorEditor (&plugin_),
  26361. #if ! JUCE_MAC
  26362. ComponentMovementWatcher (this),
  26363. #endif
  26364. plugin (plugin_),
  26365. isOpen (false),
  26366. wasShowing (false),
  26367. pluginRefusesToResize (false),
  26368. pluginWantsKeys (false),
  26369. alreadyInside (false),
  26370. recursiveResize (false)
  26371. {
  26372. #if JUCE_WIN32
  26373. sizeCheckCount = 0;
  26374. pluginHWND = 0;
  26375. #elif JUCE_LINUX
  26376. pluginWindow = None;
  26377. pluginProc = None;
  26378. #else
  26379. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26380. #endif
  26381. activeVSTWindows.add (this);
  26382. setSize (1, 1);
  26383. setOpaque (true);
  26384. setVisible (true);
  26385. }
  26386. ~VSTPluginWindow()
  26387. {
  26388. #if JUCE_MAC
  26389. innerWrapper = 0;
  26390. #else
  26391. closePluginWindow();
  26392. #endif
  26393. activeVSTWindows.removeValue (this);
  26394. plugin.editorBeingDeleted (this);
  26395. }
  26396. #if ! JUCE_MAC
  26397. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26398. {
  26399. if (recursiveResize)
  26400. return;
  26401. Component* const topComp = getTopLevelComponent();
  26402. if (topComp->getPeer() != 0)
  26403. {
  26404. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26405. recursiveResize = true;
  26406. #if JUCE_WIN32
  26407. if (pluginHWND != 0)
  26408. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26409. #elif JUCE_LINUX
  26410. if (pluginWindow != 0)
  26411. {
  26412. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26413. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26414. XMapRaised (display, pluginWindow);
  26415. }
  26416. #endif
  26417. recursiveResize = false;
  26418. }
  26419. }
  26420. void componentVisibilityChanged (Component&)
  26421. {
  26422. const bool isShowingNow = isShowing();
  26423. if (wasShowing != isShowingNow)
  26424. {
  26425. wasShowing = isShowingNow;
  26426. if (isShowingNow)
  26427. openPluginWindow();
  26428. else
  26429. closePluginWindow();
  26430. }
  26431. componentMovedOrResized (true, true);
  26432. }
  26433. void componentPeerChanged()
  26434. {
  26435. closePluginWindow();
  26436. openPluginWindow();
  26437. }
  26438. #endif
  26439. bool keyStateChanged (const bool)
  26440. {
  26441. return pluginWantsKeys;
  26442. }
  26443. bool keyPressed (const KeyPress&)
  26444. {
  26445. return pluginWantsKeys;
  26446. }
  26447. #if JUCE_MAC
  26448. void paint (Graphics& g)
  26449. {
  26450. g.fillAll (Colours::black);
  26451. }
  26452. #else
  26453. void paint (Graphics& g)
  26454. {
  26455. if (isOpen)
  26456. {
  26457. ComponentPeer* const peer = getPeer();
  26458. if (peer != 0)
  26459. {
  26460. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26461. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26462. #if JUCE_LINUX
  26463. if (pluginWindow != 0)
  26464. {
  26465. const Rectangle<int> clip (g.getClipBounds());
  26466. XEvent ev;
  26467. zerostruct (ev);
  26468. ev.xexpose.type = Expose;
  26469. ev.xexpose.display = display;
  26470. ev.xexpose.window = pluginWindow;
  26471. ev.xexpose.x = clip.getX();
  26472. ev.xexpose.y = clip.getY();
  26473. ev.xexpose.width = clip.getWidth();
  26474. ev.xexpose.height = clip.getHeight();
  26475. sendEventToChild (&ev);
  26476. }
  26477. #endif
  26478. }
  26479. }
  26480. else
  26481. {
  26482. g.fillAll (Colours::black);
  26483. }
  26484. }
  26485. #endif
  26486. void timerCallback()
  26487. {
  26488. #if JUCE_WIN32
  26489. if (--sizeCheckCount <= 0)
  26490. {
  26491. sizeCheckCount = 10;
  26492. checkPluginWindowSize();
  26493. }
  26494. #endif
  26495. try
  26496. {
  26497. static bool reentrant = false;
  26498. if (! reentrant)
  26499. {
  26500. reentrant = true;
  26501. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26502. reentrant = false;
  26503. }
  26504. }
  26505. catch (...)
  26506. {}
  26507. }
  26508. void mouseDown (const MouseEvent& e)
  26509. {
  26510. #if JUCE_LINUX
  26511. if (pluginWindow == 0)
  26512. return;
  26513. toFront (true);
  26514. XEvent ev;
  26515. zerostruct (ev);
  26516. ev.xbutton.display = display;
  26517. ev.xbutton.type = ButtonPress;
  26518. ev.xbutton.window = pluginWindow;
  26519. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26520. ev.xbutton.time = CurrentTime;
  26521. ev.xbutton.x = e.x;
  26522. ev.xbutton.y = e.y;
  26523. ev.xbutton.x_root = e.getScreenX();
  26524. ev.xbutton.y_root = e.getScreenY();
  26525. translateJuceToXButtonModifiers (e, ev);
  26526. sendEventToChild (&ev);
  26527. #elif JUCE_WIN32
  26528. (void) e;
  26529. toFront (true);
  26530. #endif
  26531. }
  26532. void broughtToFront()
  26533. {
  26534. activeVSTWindows.removeValue (this);
  26535. activeVSTWindows.add (this);
  26536. #if JUCE_MAC
  26537. dispatch (effEditTop, 0, 0, 0, 0);
  26538. #endif
  26539. }
  26540. juce_UseDebuggingNewOperator
  26541. private:
  26542. VSTPluginInstance& plugin;
  26543. bool isOpen, wasShowing, recursiveResize;
  26544. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26545. #if JUCE_WIN32
  26546. HWND pluginHWND;
  26547. void* originalWndProc;
  26548. int sizeCheckCount;
  26549. #elif JUCE_LINUX
  26550. Window pluginWindow;
  26551. EventProcPtr pluginProc;
  26552. #endif
  26553. #if JUCE_MAC
  26554. void openPluginWindow (WindowRef parentWindow)
  26555. {
  26556. if (isOpen || parentWindow == 0)
  26557. return;
  26558. isOpen = true;
  26559. ERect* rect = 0;
  26560. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26561. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26562. // do this before and after like in the steinberg example
  26563. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26564. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26565. // Install keyboard hooks
  26566. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26567. // double-check it's not too tiny
  26568. int w = 250, h = 150;
  26569. if (rect != 0)
  26570. {
  26571. w = rect->right - rect->left;
  26572. h = rect->bottom - rect->top;
  26573. if (w == 0 || h == 0)
  26574. {
  26575. w = 250;
  26576. h = 150;
  26577. }
  26578. }
  26579. w = jmax (w, 32);
  26580. h = jmax (h, 32);
  26581. setSize (w, h);
  26582. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26583. repaint();
  26584. }
  26585. #else
  26586. void openPluginWindow()
  26587. {
  26588. if (isOpen || getWindowHandle() == 0)
  26589. return;
  26590. log (T("Opening VST UI: ") + plugin.name);
  26591. isOpen = true;
  26592. ERect* rect = 0;
  26593. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26594. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26595. // do this before and after like in the steinberg example
  26596. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26597. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26598. // Install keyboard hooks
  26599. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26600. #if JUCE_WIN32
  26601. originalWndProc = 0;
  26602. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26603. if (pluginHWND == 0)
  26604. {
  26605. isOpen = false;
  26606. setSize (300, 150);
  26607. return;
  26608. }
  26609. #pragma warning (push)
  26610. #pragma warning (disable: 4244)
  26611. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26612. if (! pluginWantsKeys)
  26613. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26614. #pragma warning (pop)
  26615. int w, h;
  26616. RECT r;
  26617. GetWindowRect (pluginHWND, &r);
  26618. w = r.right - r.left;
  26619. h = r.bottom - r.top;
  26620. if (rect != 0)
  26621. {
  26622. const int rw = rect->right - rect->left;
  26623. const int rh = rect->bottom - rect->top;
  26624. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26625. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26626. {
  26627. // very dodgy logic to decide which size is right.
  26628. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26629. {
  26630. SetWindowPos (pluginHWND, 0,
  26631. 0, 0, rw, rh,
  26632. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26633. GetWindowRect (pluginHWND, &r);
  26634. w = r.right - r.left;
  26635. h = r.bottom - r.top;
  26636. pluginRefusesToResize = (w != rw) || (h != rh);
  26637. w = rw;
  26638. h = rh;
  26639. }
  26640. }
  26641. }
  26642. #elif JUCE_LINUX
  26643. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26644. if (pluginWindow != 0)
  26645. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26646. XInternAtom (display, "_XEventProc", False));
  26647. int w = 250, h = 150;
  26648. if (rect != 0)
  26649. {
  26650. w = rect->right - rect->left;
  26651. h = rect->bottom - rect->top;
  26652. if (w == 0 || h == 0)
  26653. {
  26654. w = 250;
  26655. h = 150;
  26656. }
  26657. }
  26658. if (pluginWindow != 0)
  26659. XMapRaised (display, pluginWindow);
  26660. #endif
  26661. // double-check it's not too tiny
  26662. w = jmax (w, 32);
  26663. h = jmax (h, 32);
  26664. setSize (w, h);
  26665. #if JUCE_WIN32
  26666. checkPluginWindowSize();
  26667. #endif
  26668. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26669. repaint();
  26670. }
  26671. #endif
  26672. #if ! JUCE_MAC
  26673. void closePluginWindow()
  26674. {
  26675. if (isOpen)
  26676. {
  26677. log (T("Closing VST UI: ") + plugin.getName());
  26678. isOpen = false;
  26679. dispatch (effEditClose, 0, 0, 0, 0);
  26680. #if JUCE_WIN32
  26681. #pragma warning (push)
  26682. #pragma warning (disable: 4244)
  26683. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26684. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26685. #pragma warning (pop)
  26686. stopTimer();
  26687. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26688. DestroyWindow (pluginHWND);
  26689. pluginHWND = 0;
  26690. #elif JUCE_LINUX
  26691. stopTimer();
  26692. pluginWindow = 0;
  26693. pluginProc = 0;
  26694. #endif
  26695. }
  26696. }
  26697. #endif
  26698. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26699. {
  26700. return plugin.dispatch (opcode, index, value, ptr, opt);
  26701. }
  26702. #if JUCE_WIN32
  26703. void checkPluginWindowSize() throw()
  26704. {
  26705. RECT r;
  26706. GetWindowRect (pluginHWND, &r);
  26707. const int w = r.right - r.left;
  26708. const int h = r.bottom - r.top;
  26709. if (isShowing() && w > 0 && h > 0
  26710. && (w != getWidth() || h != getHeight())
  26711. && ! pluginRefusesToResize)
  26712. {
  26713. setSize (w, h);
  26714. sizeCheckCount = 0;
  26715. }
  26716. }
  26717. // hooks to get keyboard events from VST windows..
  26718. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26719. {
  26720. for (int i = activeVSTWindows.size(); --i >= 0;)
  26721. {
  26722. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26723. if (w->pluginHWND == hW)
  26724. {
  26725. if (message == WM_CHAR
  26726. || message == WM_KEYDOWN
  26727. || message == WM_SYSKEYDOWN
  26728. || message == WM_KEYUP
  26729. || message == WM_SYSKEYUP
  26730. || message == WM_APPCOMMAND)
  26731. {
  26732. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26733. message, wParam, lParam);
  26734. }
  26735. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26736. (HWND) w->pluginHWND,
  26737. message,
  26738. wParam,
  26739. lParam);
  26740. }
  26741. }
  26742. return DefWindowProc (hW, message, wParam, lParam);
  26743. }
  26744. #endif
  26745. #if JUCE_LINUX
  26746. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26747. void sendEventToChild (XEvent* event)
  26748. {
  26749. if (pluginProc != 0)
  26750. {
  26751. // if the plugin publishes an event procedure, pass the event directly..
  26752. pluginProc (event);
  26753. }
  26754. else if (pluginWindow != 0)
  26755. {
  26756. // if the plugin has a window, then send the event to the window so that
  26757. // its message thread will pick it up..
  26758. XSendEvent (display, pluginWindow, False, 0L, event);
  26759. XFlush (display);
  26760. }
  26761. }
  26762. void mouseEnter (const MouseEvent& e)
  26763. {
  26764. if (pluginWindow != 0)
  26765. {
  26766. XEvent ev;
  26767. zerostruct (ev);
  26768. ev.xcrossing.display = display;
  26769. ev.xcrossing.type = EnterNotify;
  26770. ev.xcrossing.window = pluginWindow;
  26771. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26772. ev.xcrossing.time = CurrentTime;
  26773. ev.xcrossing.x = e.x;
  26774. ev.xcrossing.y = e.y;
  26775. ev.xcrossing.x_root = e.getScreenX();
  26776. ev.xcrossing.y_root = e.getScreenY();
  26777. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26778. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26779. translateJuceToXCrossingModifiers (e, ev);
  26780. sendEventToChild (&ev);
  26781. }
  26782. }
  26783. void mouseExit (const MouseEvent& e)
  26784. {
  26785. if (pluginWindow != 0)
  26786. {
  26787. XEvent ev;
  26788. zerostruct (ev);
  26789. ev.xcrossing.display = display;
  26790. ev.xcrossing.type = LeaveNotify;
  26791. ev.xcrossing.window = pluginWindow;
  26792. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26793. ev.xcrossing.time = CurrentTime;
  26794. ev.xcrossing.x = e.x;
  26795. ev.xcrossing.y = e.y;
  26796. ev.xcrossing.x_root = e.getScreenX();
  26797. ev.xcrossing.y_root = e.getScreenY();
  26798. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26799. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26800. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26801. translateJuceToXCrossingModifiers (e, ev);
  26802. sendEventToChild (&ev);
  26803. }
  26804. }
  26805. void mouseMove (const MouseEvent& e)
  26806. {
  26807. if (pluginWindow != 0)
  26808. {
  26809. XEvent ev;
  26810. zerostruct (ev);
  26811. ev.xmotion.display = display;
  26812. ev.xmotion.type = MotionNotify;
  26813. ev.xmotion.window = pluginWindow;
  26814. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26815. ev.xmotion.time = CurrentTime;
  26816. ev.xmotion.is_hint = NotifyNormal;
  26817. ev.xmotion.x = e.x;
  26818. ev.xmotion.y = e.y;
  26819. ev.xmotion.x_root = e.getScreenX();
  26820. ev.xmotion.y_root = e.getScreenY();
  26821. sendEventToChild (&ev);
  26822. }
  26823. }
  26824. void mouseDrag (const MouseEvent& e)
  26825. {
  26826. if (pluginWindow != 0)
  26827. {
  26828. XEvent ev;
  26829. zerostruct (ev);
  26830. ev.xmotion.display = display;
  26831. ev.xmotion.type = MotionNotify;
  26832. ev.xmotion.window = pluginWindow;
  26833. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26834. ev.xmotion.time = CurrentTime;
  26835. ev.xmotion.x = e.x ;
  26836. ev.xmotion.y = e.y;
  26837. ev.xmotion.x_root = e.getScreenX();
  26838. ev.xmotion.y_root = e.getScreenY();
  26839. ev.xmotion.is_hint = NotifyNormal;
  26840. translateJuceToXMotionModifiers (e, ev);
  26841. sendEventToChild (&ev);
  26842. }
  26843. }
  26844. void mouseUp (const MouseEvent& e)
  26845. {
  26846. if (pluginWindow != 0)
  26847. {
  26848. XEvent ev;
  26849. zerostruct (ev);
  26850. ev.xbutton.display = display;
  26851. ev.xbutton.type = ButtonRelease;
  26852. ev.xbutton.window = pluginWindow;
  26853. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26854. ev.xbutton.time = CurrentTime;
  26855. ev.xbutton.x = e.x;
  26856. ev.xbutton.y = e.y;
  26857. ev.xbutton.x_root = e.getScreenX();
  26858. ev.xbutton.y_root = e.getScreenY();
  26859. translateJuceToXButtonModifiers (e, ev);
  26860. sendEventToChild (&ev);
  26861. }
  26862. }
  26863. void mouseWheelMove (const MouseEvent& e,
  26864. float incrementX,
  26865. float incrementY)
  26866. {
  26867. if (pluginWindow != 0)
  26868. {
  26869. XEvent ev;
  26870. zerostruct (ev);
  26871. ev.xbutton.display = display;
  26872. ev.xbutton.type = ButtonPress;
  26873. ev.xbutton.window = pluginWindow;
  26874. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26875. ev.xbutton.time = CurrentTime;
  26876. ev.xbutton.x = e.x;
  26877. ev.xbutton.y = e.y;
  26878. ev.xbutton.x_root = e.getScreenX();
  26879. ev.xbutton.y_root = e.getScreenY();
  26880. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26881. sendEventToChild (&ev);
  26882. // TODO - put a usleep here ?
  26883. ev.xbutton.type = ButtonRelease;
  26884. sendEventToChild (&ev);
  26885. }
  26886. }
  26887. #endif
  26888. #if JUCE_MAC
  26889. #if ! JUCE_SUPPORT_CARBON
  26890. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26891. #endif
  26892. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26893. {
  26894. public:
  26895. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26896. : owner (owner_),
  26897. alreadyInside (false)
  26898. {
  26899. }
  26900. ~InnerWrapperComponent()
  26901. {
  26902. deleteWindow();
  26903. }
  26904. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26905. {
  26906. owner->openPluginWindow (windowRef);
  26907. return 0;
  26908. }
  26909. void removeView (HIViewRef)
  26910. {
  26911. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26912. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26913. }
  26914. bool getEmbeddedViewSize (int& w, int& h)
  26915. {
  26916. ERect* rect = 0;
  26917. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26918. w = rect->right - rect->left;
  26919. h = rect->bottom - rect->top;
  26920. return true;
  26921. }
  26922. void mouseDown (int x, int y)
  26923. {
  26924. if (! alreadyInside)
  26925. {
  26926. alreadyInside = true;
  26927. getTopLevelComponent()->toFront (true);
  26928. owner->dispatch (effEditMouse, x, y, 0, 0);
  26929. alreadyInside = false;
  26930. }
  26931. else
  26932. {
  26933. PostEvent (::mouseDown, 0);
  26934. }
  26935. }
  26936. void paint()
  26937. {
  26938. ComponentPeer* const peer = getPeer();
  26939. if (peer != 0)
  26940. {
  26941. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26942. ERect r;
  26943. r.left = pos.getX();
  26944. r.right = r.left + getWidth();
  26945. r.top = pos.getY();
  26946. r.bottom = r.top + getHeight();
  26947. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26948. }
  26949. }
  26950. private:
  26951. VSTPluginWindow* const owner;
  26952. bool alreadyInside;
  26953. };
  26954. friend class InnerWrapperComponent;
  26955. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26956. void resized()
  26957. {
  26958. innerWrapper->setSize (getWidth(), getHeight());
  26959. }
  26960. #endif
  26961. };
  26962. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26963. {
  26964. if (hasEditor())
  26965. return new VSTPluginWindow (*this);
  26966. return 0;
  26967. }
  26968. void VSTPluginInstance::handleAsyncUpdate()
  26969. {
  26970. // indicates that something about the plugin has changed..
  26971. updateHostDisplay();
  26972. }
  26973. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26974. {
  26975. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26976. {
  26977. changeProgramName (getCurrentProgram(), prog->prgName);
  26978. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26979. setParameter (i, vst_swapFloat (prog->params[i]));
  26980. return true;
  26981. }
  26982. return false;
  26983. }
  26984. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26985. const int dataSize)
  26986. {
  26987. if (dataSize < 28)
  26988. return false;
  26989. const fxSet* const set = (const fxSet*) data;
  26990. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26991. || vst_swap (set->version) > fxbVersionNum)
  26992. return false;
  26993. if (vst_swap (set->fxMagic) == 'FxBk')
  26994. {
  26995. // bank of programs
  26996. if (vst_swap (set->numPrograms) >= 0)
  26997. {
  26998. const int oldProg = getCurrentProgram();
  26999. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  27000. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27001. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  27002. {
  27003. if (i != oldProg)
  27004. {
  27005. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  27006. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27007. return false;
  27008. if (vst_swap (set->numPrograms) > 0)
  27009. setCurrentProgram (i);
  27010. if (! restoreProgramSettings (prog))
  27011. return false;
  27012. }
  27013. }
  27014. if (vst_swap (set->numPrograms) > 0)
  27015. setCurrentProgram (oldProg);
  27016. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  27017. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27018. return false;
  27019. if (! restoreProgramSettings (prog))
  27020. return false;
  27021. }
  27022. }
  27023. else if (vst_swap (set->fxMagic) == 'FxCk')
  27024. {
  27025. // single program
  27026. const fxProgram* const prog = (const fxProgram*) data;
  27027. if (vst_swap (prog->chunkMagic) != 'CcnK')
  27028. return false;
  27029. changeProgramName (getCurrentProgram(), prog->prgName);
  27030. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  27031. setParameter (i, vst_swapFloat (prog->params[i]));
  27032. }
  27033. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  27034. {
  27035. // non-preset chunk
  27036. const fxChunkSet* const cset = (const fxChunkSet*) data;
  27037. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  27038. return false;
  27039. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  27040. }
  27041. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  27042. {
  27043. // preset chunk
  27044. const fxProgramSet* const cset = (const fxProgramSet*) data;
  27045. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  27046. return false;
  27047. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  27048. changeProgramName (getCurrentProgram(), cset->name);
  27049. }
  27050. else
  27051. {
  27052. return false;
  27053. }
  27054. return true;
  27055. }
  27056. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  27057. {
  27058. const int numParams = getNumParameters();
  27059. prog->chunkMagic = vst_swap ('CcnK');
  27060. prog->byteSize = 0;
  27061. prog->fxMagic = vst_swap ('FxCk');
  27062. prog->version = vst_swap (fxbVersionNum);
  27063. prog->fxID = vst_swap (getUID());
  27064. prog->fxVersion = vst_swap (getVersionNumber());
  27065. prog->numParams = vst_swap (numParams);
  27066. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  27067. for (int i = 0; i < numParams; ++i)
  27068. prog->params[i] = vst_swapFloat (getParameter (i));
  27069. }
  27070. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  27071. {
  27072. const int numPrograms = getNumPrograms();
  27073. const int numParams = getNumParameters();
  27074. if (usesChunks())
  27075. {
  27076. if (isFXB)
  27077. {
  27078. MemoryBlock chunk;
  27079. getChunkData (chunk, false, maxSizeMB);
  27080. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  27081. dest.setSize (totalLen, true);
  27082. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  27083. set->chunkMagic = vst_swap ('CcnK');
  27084. set->byteSize = 0;
  27085. set->fxMagic = vst_swap ('FBCh');
  27086. set->version = vst_swap (fxbVersionNum);
  27087. set->fxID = vst_swap (getUID());
  27088. set->fxVersion = vst_swap (getVersionNumber());
  27089. set->numPrograms = vst_swap (numPrograms);
  27090. set->chunkSize = vst_swap ((long) chunk.getSize());
  27091. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27092. }
  27093. else
  27094. {
  27095. MemoryBlock chunk;
  27096. getChunkData (chunk, true, maxSizeMB);
  27097. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  27098. dest.setSize (totalLen, true);
  27099. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  27100. set->chunkMagic = vst_swap ('CcnK');
  27101. set->byteSize = 0;
  27102. set->fxMagic = vst_swap ('FPCh');
  27103. set->version = vst_swap (fxbVersionNum);
  27104. set->fxID = vst_swap (getUID());
  27105. set->fxVersion = vst_swap (getVersionNumber());
  27106. set->numPrograms = vst_swap (numPrograms);
  27107. set->chunkSize = vst_swap ((long) chunk.getSize());
  27108. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  27109. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27110. }
  27111. }
  27112. else
  27113. {
  27114. if (isFXB)
  27115. {
  27116. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27117. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27118. dest.setSize (len, true);
  27119. fxSet* const set = (fxSet*) dest.getData();
  27120. set->chunkMagic = vst_swap ('CcnK');
  27121. set->byteSize = 0;
  27122. set->fxMagic = vst_swap ('FxBk');
  27123. set->version = vst_swap (fxbVersionNum);
  27124. set->fxID = vst_swap (getUID());
  27125. set->fxVersion = vst_swap (getVersionNumber());
  27126. set->numPrograms = vst_swap (numPrograms);
  27127. const int oldProgram = getCurrentProgram();
  27128. MemoryBlock oldSettings;
  27129. createTempParameterStore (oldSettings);
  27130. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27131. for (int i = 0; i < numPrograms; ++i)
  27132. {
  27133. if (i != oldProgram)
  27134. {
  27135. setCurrentProgram (i);
  27136. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27137. }
  27138. }
  27139. setCurrentProgram (oldProgram);
  27140. restoreFromTempParameterStore (oldSettings);
  27141. }
  27142. else
  27143. {
  27144. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27145. dest.setSize (totalLen, true);
  27146. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27147. }
  27148. }
  27149. return true;
  27150. }
  27151. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27152. {
  27153. if (usesChunks())
  27154. {
  27155. void* data = 0;
  27156. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27157. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27158. {
  27159. mb.setSize (bytes);
  27160. mb.copyFrom (data, 0, bytes);
  27161. }
  27162. }
  27163. }
  27164. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27165. {
  27166. if (size > 0 && usesChunks())
  27167. {
  27168. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27169. if (! isPreset)
  27170. updateStoredProgramNames();
  27171. }
  27172. }
  27173. void VSTPluginInstance::timerCallback()
  27174. {
  27175. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27176. stopTimer();
  27177. }
  27178. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27179. {
  27180. const ScopedLock sl (lock);
  27181. ++insideVSTCallback;
  27182. int result = 0;
  27183. try
  27184. {
  27185. if (effect != 0)
  27186. {
  27187. #if JUCE_MAC
  27188. if (module->resFileId != 0)
  27189. UseResFile (module->resFileId);
  27190. CGrafPtr oldPort;
  27191. if (getActiveEditor() != 0)
  27192. {
  27193. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  27194. GetPort (&oldPort);
  27195. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27196. SetOrigin (-pos.getX(), -pos.getY());
  27197. }
  27198. #endif
  27199. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27200. #if JUCE_MAC
  27201. if (getActiveEditor() != 0)
  27202. SetPort (oldPort);
  27203. module->resFileId = CurResFile();
  27204. #endif
  27205. --insideVSTCallback;
  27206. return result;
  27207. }
  27208. }
  27209. catch (...)
  27210. {
  27211. }
  27212. --insideVSTCallback;
  27213. return result;
  27214. }
  27215. // handles non plugin-specific callbacks..
  27216. static const int defaultVSTSampleRateValue = 16384;
  27217. static const int defaultVSTBlockSizeValue = 512;
  27218. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27219. {
  27220. (void) index;
  27221. (void) value;
  27222. (void) opt;
  27223. switch (opcode)
  27224. {
  27225. case audioMasterCanDo:
  27226. {
  27227. static const char* canDos[] = { "supplyIdle",
  27228. "sendVstEvents",
  27229. "sendVstMidiEvent",
  27230. "sendVstTimeInfo",
  27231. "receiveVstEvents",
  27232. "receiveVstMidiEvent",
  27233. "supportShell",
  27234. "shellCategory" };
  27235. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27236. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27237. return 1;
  27238. return 0;
  27239. }
  27240. case audioMasterVersion:
  27241. return 0x2400;
  27242. case audioMasterCurrentId:
  27243. return shellUIDToCreate;
  27244. case audioMasterGetNumAutomatableParameters:
  27245. return 0;
  27246. case audioMasterGetAutomationState:
  27247. return 1;
  27248. case audioMasterGetVendorVersion:
  27249. return 0x0101;
  27250. case audioMasterGetVendorString:
  27251. case audioMasterGetProductString:
  27252. {
  27253. String hostName ("Juce VST Host");
  27254. if (JUCEApplication::getInstance() != 0)
  27255. hostName = JUCEApplication::getInstance()->getApplicationName();
  27256. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27257. }
  27258. break;
  27259. case audioMasterGetSampleRate:
  27260. return (VstIntPtr) defaultVSTSampleRateValue;
  27261. case audioMasterGetBlockSize:
  27262. return (VstIntPtr) defaultVSTBlockSizeValue;
  27263. case audioMasterSetOutputSampleRate:
  27264. return 0;
  27265. default:
  27266. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27267. break;
  27268. }
  27269. return 0;
  27270. }
  27271. // handles callbacks for a specific plugin
  27272. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27273. {
  27274. switch (opcode)
  27275. {
  27276. case audioMasterAutomate:
  27277. sendParamChangeMessageToListeners (index, opt);
  27278. break;
  27279. case audioMasterProcessEvents:
  27280. handleMidiFromPlugin ((const VstEvents*) ptr);
  27281. break;
  27282. case audioMasterGetTime:
  27283. #ifdef _MSC_VER
  27284. #pragma warning (push)
  27285. #pragma warning (disable: 4311)
  27286. #endif
  27287. return (VstIntPtr) &vstHostTime;
  27288. #ifdef _MSC_VER
  27289. #pragma warning (pop)
  27290. #endif
  27291. break;
  27292. case audioMasterIdle:
  27293. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27294. {
  27295. ++insideVSTCallback;
  27296. #if JUCE_MAC
  27297. if (getActiveEditor() != 0)
  27298. dispatch (effEditIdle, 0, 0, 0, 0);
  27299. #endif
  27300. juce_callAnyTimersSynchronously();
  27301. handleUpdateNowIfNeeded();
  27302. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27303. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27304. --insideVSTCallback;
  27305. }
  27306. break;
  27307. case audioMasterUpdateDisplay:
  27308. triggerAsyncUpdate();
  27309. break;
  27310. case audioMasterTempoAt:
  27311. // returns (10000 * bpm)
  27312. break;
  27313. case audioMasterNeedIdle:
  27314. startTimer (50);
  27315. break;
  27316. case audioMasterSizeWindow:
  27317. if (getActiveEditor() != 0)
  27318. getActiveEditor()->setSize (index, value);
  27319. return 1;
  27320. case audioMasterGetSampleRate:
  27321. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27322. case audioMasterGetBlockSize:
  27323. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27324. case audioMasterWantMidi:
  27325. wantsMidiMessages = true;
  27326. break;
  27327. case audioMasterGetDirectory:
  27328. #if JUCE_MAC
  27329. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27330. #else
  27331. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27332. #endif
  27333. case audioMasterGetAutomationState:
  27334. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27335. break;
  27336. // none of these are handled (yet)..
  27337. case audioMasterBeginEdit:
  27338. case audioMasterEndEdit:
  27339. case audioMasterSetTime:
  27340. case audioMasterPinConnected:
  27341. case audioMasterGetParameterQuantization:
  27342. case audioMasterIOChanged:
  27343. case audioMasterGetInputLatency:
  27344. case audioMasterGetOutputLatency:
  27345. case audioMasterGetPreviousPlug:
  27346. case audioMasterGetNextPlug:
  27347. case audioMasterWillReplaceOrAccumulate:
  27348. case audioMasterGetCurrentProcessLevel:
  27349. case audioMasterOfflineStart:
  27350. case audioMasterOfflineRead:
  27351. case audioMasterOfflineWrite:
  27352. case audioMasterOfflineGetCurrentPass:
  27353. case audioMasterOfflineGetCurrentMetaPass:
  27354. case audioMasterVendorSpecific:
  27355. case audioMasterSetIcon:
  27356. case audioMasterGetLanguage:
  27357. case audioMasterOpenWindow:
  27358. case audioMasterCloseWindow:
  27359. break;
  27360. default:
  27361. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27362. }
  27363. return 0;
  27364. }
  27365. // entry point for all callbacks from the plugin
  27366. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27367. {
  27368. try
  27369. {
  27370. if (effect != 0 && effect->resvd2 != 0)
  27371. {
  27372. return ((VSTPluginInstance*)(effect->resvd2))
  27373. ->handleCallback (opcode, index, value, ptr, opt);
  27374. }
  27375. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27376. }
  27377. catch (...)
  27378. {
  27379. return 0;
  27380. }
  27381. }
  27382. const String VSTPluginInstance::getVersion() const throw()
  27383. {
  27384. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27385. String s;
  27386. if (v == 0 || v == -1)
  27387. v = getVersionNumber();
  27388. if (v != 0)
  27389. {
  27390. int versionBits[4];
  27391. int n = 0;
  27392. while (v != 0)
  27393. {
  27394. versionBits [n++] = (v & 0xff);
  27395. v >>= 8;
  27396. }
  27397. s << 'V';
  27398. while (n > 0)
  27399. {
  27400. s << versionBits [--n];
  27401. if (n > 0)
  27402. s << '.';
  27403. }
  27404. }
  27405. return s;
  27406. }
  27407. int VSTPluginInstance::getUID() const throw()
  27408. {
  27409. int uid = effect != 0 ? effect->uniqueID : 0;
  27410. if (uid == 0)
  27411. uid = module->file.hashCode();
  27412. return uid;
  27413. }
  27414. const String VSTPluginInstance::getCategory() const throw()
  27415. {
  27416. const char* result = 0;
  27417. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27418. {
  27419. case kPlugCategEffect:
  27420. result = "Effect";
  27421. break;
  27422. case kPlugCategSynth:
  27423. result = "Synth";
  27424. break;
  27425. case kPlugCategAnalysis:
  27426. result = "Anaylsis";
  27427. break;
  27428. case kPlugCategMastering:
  27429. result = "Mastering";
  27430. break;
  27431. case kPlugCategSpacializer:
  27432. result = "Spacial";
  27433. break;
  27434. case kPlugCategRoomFx:
  27435. result = "Reverb";
  27436. break;
  27437. case kPlugSurroundFx:
  27438. result = "Surround";
  27439. break;
  27440. case kPlugCategRestoration:
  27441. result = "Restoration";
  27442. break;
  27443. case kPlugCategGenerator:
  27444. result = "Tone generation";
  27445. break;
  27446. default:
  27447. break;
  27448. }
  27449. return result;
  27450. }
  27451. float VSTPluginInstance::getParameter (int index)
  27452. {
  27453. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27454. {
  27455. try
  27456. {
  27457. const ScopedLock sl (lock);
  27458. return effect->getParameter (effect, index);
  27459. }
  27460. catch (...)
  27461. {
  27462. }
  27463. }
  27464. return 0.0f;
  27465. }
  27466. void VSTPluginInstance::setParameter (int index, float newValue)
  27467. {
  27468. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27469. {
  27470. try
  27471. {
  27472. const ScopedLock sl (lock);
  27473. if (effect->getParameter (effect, index) != newValue)
  27474. effect->setParameter (effect, index, newValue);
  27475. }
  27476. catch (...)
  27477. {
  27478. }
  27479. }
  27480. }
  27481. const String VSTPluginInstance::getParameterName (int index)
  27482. {
  27483. if (effect != 0)
  27484. {
  27485. jassert (index >= 0 && index < effect->numParams);
  27486. char nm [256];
  27487. zerostruct (nm);
  27488. dispatch (effGetParamName, index, 0, nm, 0);
  27489. return String (nm).trim();
  27490. }
  27491. return String::empty;
  27492. }
  27493. const String VSTPluginInstance::getParameterLabel (int index) const
  27494. {
  27495. if (effect != 0)
  27496. {
  27497. jassert (index >= 0 && index < effect->numParams);
  27498. char nm [256];
  27499. zerostruct (nm);
  27500. dispatch (effGetParamLabel, index, 0, nm, 0);
  27501. return String (nm).trim();
  27502. }
  27503. return String::empty;
  27504. }
  27505. const String VSTPluginInstance::getParameterText (int index)
  27506. {
  27507. if (effect != 0)
  27508. {
  27509. jassert (index >= 0 && index < effect->numParams);
  27510. char nm [256];
  27511. zerostruct (nm);
  27512. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27513. return String (nm).trim();
  27514. }
  27515. return String::empty;
  27516. }
  27517. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27518. {
  27519. if (effect != 0)
  27520. {
  27521. jassert (index >= 0 && index < effect->numParams);
  27522. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27523. }
  27524. return false;
  27525. }
  27526. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27527. {
  27528. dest.setSize (64 + 4 * getNumParameters());
  27529. dest.fillWith (0);
  27530. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27531. float* const p = (float*) (((char*) dest.getData()) + 64);
  27532. for (int i = 0; i < getNumParameters(); ++i)
  27533. p[i] = getParameter(i);
  27534. }
  27535. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27536. {
  27537. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27538. float* p = (float*) (((char*) m.getData()) + 64);
  27539. for (int i = 0; i < getNumParameters(); ++i)
  27540. setParameter (i, p[i]);
  27541. }
  27542. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27543. {
  27544. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27545. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27546. }
  27547. const String VSTPluginInstance::getProgramName (int index)
  27548. {
  27549. if (index == getCurrentProgram())
  27550. {
  27551. return getCurrentProgramName();
  27552. }
  27553. else if (effect != 0)
  27554. {
  27555. char nm [256];
  27556. zerostruct (nm);
  27557. if (dispatch (effGetProgramNameIndexed,
  27558. jlimit (0, getNumPrograms(), index),
  27559. -1, nm, 0) != 0)
  27560. {
  27561. return String (nm).trim();
  27562. }
  27563. }
  27564. return programNames [index];
  27565. }
  27566. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27567. {
  27568. if (index == getCurrentProgram())
  27569. {
  27570. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27571. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27572. }
  27573. else
  27574. {
  27575. jassertfalse // xxx not implemented!
  27576. }
  27577. }
  27578. void VSTPluginInstance::updateStoredProgramNames()
  27579. {
  27580. if (effect != 0 && getNumPrograms() > 0)
  27581. {
  27582. char nm [256];
  27583. zerostruct (nm);
  27584. // only do this if the plugin can't use indexed names..
  27585. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27586. {
  27587. const int oldProgram = getCurrentProgram();
  27588. MemoryBlock oldSettings;
  27589. createTempParameterStore (oldSettings);
  27590. for (int i = 0; i < getNumPrograms(); ++i)
  27591. {
  27592. setCurrentProgram (i);
  27593. getCurrentProgramName(); // (this updates the list)
  27594. }
  27595. setCurrentProgram (oldProgram);
  27596. restoreFromTempParameterStore (oldSettings);
  27597. }
  27598. }
  27599. }
  27600. const String VSTPluginInstance::getCurrentProgramName()
  27601. {
  27602. if (effect != 0)
  27603. {
  27604. char nm [256];
  27605. zerostruct (nm);
  27606. dispatch (effGetProgramName, 0, 0, nm, 0);
  27607. const int index = getCurrentProgram();
  27608. if (programNames[index].isEmpty())
  27609. {
  27610. while (programNames.size() < index)
  27611. programNames.add (String::empty);
  27612. programNames.set (index, String (nm).trim());
  27613. }
  27614. return String (nm).trim();
  27615. }
  27616. return String::empty;
  27617. }
  27618. const String VSTPluginInstance::getInputChannelName (const int index) const
  27619. {
  27620. if (index >= 0 && index < getNumInputChannels())
  27621. {
  27622. VstPinProperties pinProps;
  27623. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27624. return String (pinProps.label, sizeof (pinProps.label));
  27625. }
  27626. return String::empty;
  27627. }
  27628. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27629. {
  27630. if (index < 0 || index >= getNumInputChannels())
  27631. return false;
  27632. VstPinProperties pinProps;
  27633. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27634. return (pinProps.flags & kVstPinIsStereo) != 0;
  27635. return true;
  27636. }
  27637. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27638. {
  27639. if (index >= 0 && index < getNumOutputChannels())
  27640. {
  27641. VstPinProperties pinProps;
  27642. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27643. return String (pinProps.label, sizeof (pinProps.label));
  27644. }
  27645. return String::empty;
  27646. }
  27647. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27648. {
  27649. if (index < 0 || index >= getNumOutputChannels())
  27650. return false;
  27651. VstPinProperties pinProps;
  27652. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27653. return (pinProps.flags & kVstPinIsStereo) != 0;
  27654. return true;
  27655. }
  27656. void VSTPluginInstance::setPower (const bool on)
  27657. {
  27658. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27659. isPowerOn = on;
  27660. }
  27661. const int defaultMaxSizeMB = 64;
  27662. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27663. {
  27664. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27665. }
  27666. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27667. {
  27668. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27669. }
  27670. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27671. {
  27672. loadFromFXBFile (data, sizeInBytes);
  27673. }
  27674. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27675. {
  27676. loadFromFXBFile (data, sizeInBytes);
  27677. }
  27678. VSTPluginFormat::VSTPluginFormat()
  27679. {
  27680. }
  27681. VSTPluginFormat::~VSTPluginFormat()
  27682. {
  27683. }
  27684. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27685. const String& fileOrIdentifier)
  27686. {
  27687. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27688. return;
  27689. PluginDescription desc;
  27690. desc.fileOrIdentifier = fileOrIdentifier;
  27691. desc.uid = 0;
  27692. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27693. if (instance == 0)
  27694. return;
  27695. try
  27696. {
  27697. #if JUCE_MAC
  27698. if (instance->module->resFileId != 0)
  27699. UseResFile (instance->module->resFileId);
  27700. #endif
  27701. instance->fillInPluginDescription (desc);
  27702. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27703. if (category != kPlugCategShell)
  27704. {
  27705. // Normal plugin...
  27706. results.add (new PluginDescription (desc));
  27707. ++insideVSTCallback;
  27708. instance->dispatch (effOpen, 0, 0, 0, 0);
  27709. --insideVSTCallback;
  27710. }
  27711. else
  27712. {
  27713. // It's a shell plugin, so iterate all the subtypes...
  27714. char shellEffectName [64];
  27715. for (;;)
  27716. {
  27717. zerostruct (shellEffectName);
  27718. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27719. if (uid == 0)
  27720. {
  27721. break;
  27722. }
  27723. else
  27724. {
  27725. desc.uid = uid;
  27726. desc.name = shellEffectName;
  27727. bool alreadyThere = false;
  27728. for (int i = results.size(); --i >= 0;)
  27729. {
  27730. PluginDescription* const d = results.getUnchecked(i);
  27731. if (d->isDuplicateOf (desc))
  27732. {
  27733. alreadyThere = true;
  27734. break;
  27735. }
  27736. }
  27737. if (! alreadyThere)
  27738. results.add (new PluginDescription (desc));
  27739. }
  27740. }
  27741. }
  27742. }
  27743. catch (...)
  27744. {
  27745. // crashed while loading...
  27746. }
  27747. }
  27748. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27749. {
  27750. ScopedPointer <VSTPluginInstance> result;
  27751. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27752. {
  27753. File file (desc.fileOrIdentifier);
  27754. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27755. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27756. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27757. if (module != 0)
  27758. {
  27759. shellUIDToCreate = desc.uid;
  27760. result = new VSTPluginInstance (module);
  27761. if (result->effect != 0)
  27762. {
  27763. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27764. result->initialise();
  27765. }
  27766. else
  27767. {
  27768. result = 0;
  27769. }
  27770. }
  27771. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27772. }
  27773. return result.release();
  27774. }
  27775. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27776. {
  27777. const File f (fileOrIdentifier);
  27778. #if JUCE_MAC
  27779. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27780. return true;
  27781. #if JUCE_PPC
  27782. FSRef fileRef;
  27783. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27784. {
  27785. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27786. if (resFileId != -1)
  27787. {
  27788. const int numEffects = Count1Resources ('aEff');
  27789. CloseResFile (resFileId);
  27790. if (numEffects > 0)
  27791. return true;
  27792. }
  27793. }
  27794. #endif
  27795. return false;
  27796. #elif JUCE_WIN32
  27797. return f.existsAsFile()
  27798. && f.hasFileExtension (T(".dll"));
  27799. #elif JUCE_LINUX
  27800. return f.existsAsFile()
  27801. && f.hasFileExtension (T(".so"));
  27802. #endif
  27803. }
  27804. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27805. {
  27806. return fileOrIdentifier;
  27807. }
  27808. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27809. {
  27810. return File (desc.fileOrIdentifier).exists();
  27811. }
  27812. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27813. {
  27814. StringArray results;
  27815. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27816. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27817. return results;
  27818. }
  27819. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27820. {
  27821. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27822. // .component or .vst directories.
  27823. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27824. while (iter.next())
  27825. {
  27826. const File f (iter.getFile());
  27827. bool isPlugin = false;
  27828. if (fileMightContainThisPluginType (f.getFullPathName()))
  27829. {
  27830. isPlugin = true;
  27831. results.add (f.getFullPathName());
  27832. }
  27833. if (recursive && (! isPlugin) && f.isDirectory())
  27834. recursiveFileSearch (results, f, true);
  27835. }
  27836. }
  27837. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27838. {
  27839. #if JUCE_MAC
  27840. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27841. #elif JUCE_WIN32
  27842. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27843. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27844. #elif JUCE_LINUX
  27845. return FileSearchPath ("/usr/lib/vst");
  27846. #endif
  27847. }
  27848. END_JUCE_NAMESPACE
  27849. #endif
  27850. #undef log
  27851. #endif
  27852. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27853. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27854. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27855. BEGIN_JUCE_NAMESPACE
  27856. AudioProcessor::AudioProcessor()
  27857. : playHead (0),
  27858. activeEditor (0),
  27859. sampleRate (0),
  27860. blockSize (0),
  27861. numInputChannels (0),
  27862. numOutputChannels (0),
  27863. latencySamples (0),
  27864. suspended (false),
  27865. nonRealtime (false)
  27866. {
  27867. }
  27868. AudioProcessor::~AudioProcessor()
  27869. {
  27870. // ooh, nasty - the editor should have been deleted before the filter
  27871. // that it refers to is deleted..
  27872. jassert (activeEditor == 0);
  27873. #ifdef JUCE_DEBUG
  27874. // This will fail if you've called beginParameterChangeGesture() for one
  27875. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27876. jassert (changingParams.countNumberOfSetBits() == 0);
  27877. #endif
  27878. }
  27879. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27880. {
  27881. playHead = newPlayHead;
  27882. }
  27883. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27884. {
  27885. const ScopedLock sl (listenerLock);
  27886. listeners.addIfNotAlreadyThere (newListener);
  27887. }
  27888. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27889. {
  27890. const ScopedLock sl (listenerLock);
  27891. listeners.removeValue (listenerToRemove);
  27892. }
  27893. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27894. const int numOuts,
  27895. const double sampleRate_,
  27896. const int blockSize_) throw()
  27897. {
  27898. numInputChannels = numIns;
  27899. numOutputChannels = numOuts;
  27900. sampleRate = sampleRate_;
  27901. blockSize = blockSize_;
  27902. }
  27903. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27904. {
  27905. nonRealtime = nonRealtime_;
  27906. }
  27907. void AudioProcessor::setLatencySamples (const int newLatency)
  27908. {
  27909. if (latencySamples != newLatency)
  27910. {
  27911. latencySamples = newLatency;
  27912. updateHostDisplay();
  27913. }
  27914. }
  27915. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27916. const float newValue)
  27917. {
  27918. setParameter (parameterIndex, newValue);
  27919. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27920. }
  27921. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27922. {
  27923. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27924. for (int i = listeners.size(); --i >= 0;)
  27925. {
  27926. AudioProcessorListener* l;
  27927. {
  27928. const ScopedLock sl (listenerLock);
  27929. l = (AudioProcessorListener*) listeners [i];
  27930. }
  27931. if (l != 0)
  27932. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27933. }
  27934. }
  27935. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27936. {
  27937. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27938. #ifdef JUCE_DEBUG
  27939. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27940. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27941. jassert (! changingParams [parameterIndex]);
  27942. changingParams.setBit (parameterIndex);
  27943. #endif
  27944. for (int i = listeners.size(); --i >= 0;)
  27945. {
  27946. AudioProcessorListener* l;
  27947. {
  27948. const ScopedLock sl (listenerLock);
  27949. l = (AudioProcessorListener*) listeners [i];
  27950. }
  27951. if (l != 0)
  27952. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27953. }
  27954. }
  27955. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27956. {
  27957. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27958. #ifdef JUCE_DEBUG
  27959. // This means you've called endParameterChangeGesture without having previously called
  27960. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27961. // calls matched correctly.
  27962. jassert (changingParams [parameterIndex]);
  27963. changingParams.clearBit (parameterIndex);
  27964. #endif
  27965. for (int i = listeners.size(); --i >= 0;)
  27966. {
  27967. AudioProcessorListener* l;
  27968. {
  27969. const ScopedLock sl (listenerLock);
  27970. l = (AudioProcessorListener*) listeners [i];
  27971. }
  27972. if (l != 0)
  27973. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27974. }
  27975. }
  27976. void AudioProcessor::updateHostDisplay()
  27977. {
  27978. for (int i = listeners.size(); --i >= 0;)
  27979. {
  27980. AudioProcessorListener* l;
  27981. {
  27982. const ScopedLock sl (listenerLock);
  27983. l = (AudioProcessorListener*) listeners [i];
  27984. }
  27985. if (l != 0)
  27986. l->audioProcessorChanged (this);
  27987. }
  27988. }
  27989. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27990. {
  27991. return true;
  27992. }
  27993. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27994. {
  27995. return false;
  27996. }
  27997. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27998. {
  27999. const ScopedLock sl (callbackLock);
  28000. suspended = shouldBeSuspended;
  28001. }
  28002. void AudioProcessor::reset()
  28003. {
  28004. }
  28005. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  28006. {
  28007. const ScopedLock sl (callbackLock);
  28008. jassert (activeEditor == editor);
  28009. if (activeEditor == editor)
  28010. activeEditor = 0;
  28011. }
  28012. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  28013. {
  28014. if (activeEditor != 0)
  28015. return activeEditor;
  28016. AudioProcessorEditor* const ed = createEditor();
  28017. if (ed != 0)
  28018. {
  28019. // you must give your editor comp a size before returning it..
  28020. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  28021. const ScopedLock sl (callbackLock);
  28022. activeEditor = ed;
  28023. }
  28024. return ed;
  28025. }
  28026. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  28027. {
  28028. getStateInformation (destData);
  28029. }
  28030. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  28031. {
  28032. setStateInformation (data, sizeInBytes);
  28033. }
  28034. // magic number to identify memory blocks that we've stored as XML
  28035. const uint32 magicXmlNumber = 0x21324356;
  28036. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  28037. JUCE_NAMESPACE::MemoryBlock& destData)
  28038. {
  28039. const String xmlString (xml.createDocument (String::empty, true, false));
  28040. const int stringLength = xmlString.getNumBytesAsUTF8();
  28041. destData.setSize (stringLength + 10);
  28042. char* const d = (char*) destData.getData();
  28043. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  28044. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  28045. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  28046. }
  28047. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  28048. const int sizeInBytes)
  28049. {
  28050. if (sizeInBytes > 8
  28051. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  28052. {
  28053. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  28054. if (stringLength > 0)
  28055. {
  28056. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  28057. jmin ((sizeInBytes - 8), stringLength)));
  28058. return doc.getDocumentElement();
  28059. }
  28060. }
  28061. return 0;
  28062. }
  28063. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  28064. {
  28065. }
  28066. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  28067. {
  28068. }
  28069. END_JUCE_NAMESPACE
  28070. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  28071. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  28072. BEGIN_JUCE_NAMESPACE
  28073. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  28074. : owner (owner_)
  28075. {
  28076. // the filter must be valid..
  28077. jassert (owner != 0);
  28078. }
  28079. AudioProcessorEditor::~AudioProcessorEditor()
  28080. {
  28081. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  28082. // filter for some reason..
  28083. jassert (owner->getActiveEditor() != this);
  28084. }
  28085. END_JUCE_NAMESPACE
  28086. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  28087. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  28088. BEGIN_JUCE_NAMESPACE
  28089. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  28090. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  28091. : id (id_),
  28092. processor (processor_),
  28093. isPrepared (false)
  28094. {
  28095. jassert (processor_ != 0);
  28096. }
  28097. AudioProcessorGraph::Node::~Node()
  28098. {
  28099. delete processor;
  28100. }
  28101. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  28102. AudioProcessorGraph* const graph)
  28103. {
  28104. if (! isPrepared)
  28105. {
  28106. isPrepared = true;
  28107. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28108. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28109. if (ioProc != 0)
  28110. ioProc->setParentGraph (graph);
  28111. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28112. processor->getNumOutputChannels(),
  28113. sampleRate, blockSize);
  28114. processor->prepareToPlay (sampleRate, blockSize);
  28115. }
  28116. }
  28117. void AudioProcessorGraph::Node::unprepare()
  28118. {
  28119. if (isPrepared)
  28120. {
  28121. isPrepared = false;
  28122. processor->releaseResources();
  28123. }
  28124. }
  28125. AudioProcessorGraph::AudioProcessorGraph()
  28126. : lastNodeId (0),
  28127. renderingBuffers (1, 1),
  28128. currentAudioOutputBuffer (1, 1)
  28129. {
  28130. }
  28131. AudioProcessorGraph::~AudioProcessorGraph()
  28132. {
  28133. clearRenderingSequence();
  28134. clear();
  28135. }
  28136. const String AudioProcessorGraph::getName() const
  28137. {
  28138. return "Audio Graph";
  28139. }
  28140. void AudioProcessorGraph::clear()
  28141. {
  28142. nodes.clear();
  28143. connections.clear();
  28144. triggerAsyncUpdate();
  28145. }
  28146. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28147. {
  28148. for (int i = nodes.size(); --i >= 0;)
  28149. if (nodes.getUnchecked(i)->id == nodeId)
  28150. return nodes.getUnchecked(i);
  28151. return 0;
  28152. }
  28153. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28154. uint32 nodeId)
  28155. {
  28156. if (newProcessor == 0)
  28157. {
  28158. jassertfalse
  28159. return 0;
  28160. }
  28161. if (nodeId == 0)
  28162. {
  28163. nodeId = ++lastNodeId;
  28164. }
  28165. else
  28166. {
  28167. // you can't add a node with an id that already exists in the graph..
  28168. jassert (getNodeForId (nodeId) == 0);
  28169. removeNode (nodeId);
  28170. }
  28171. lastNodeId = nodeId;
  28172. Node* const n = new Node (nodeId, newProcessor);
  28173. nodes.add (n);
  28174. triggerAsyncUpdate();
  28175. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28176. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28177. if (ioProc != 0)
  28178. ioProc->setParentGraph (this);
  28179. return n;
  28180. }
  28181. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28182. {
  28183. disconnectNode (nodeId);
  28184. for (int i = nodes.size(); --i >= 0;)
  28185. {
  28186. if (nodes.getUnchecked(i)->id == nodeId)
  28187. {
  28188. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28189. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28190. if (ioProc != 0)
  28191. ioProc->setParentGraph (0);
  28192. nodes.remove (i);
  28193. triggerAsyncUpdate();
  28194. return true;
  28195. }
  28196. }
  28197. return false;
  28198. }
  28199. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28200. const int sourceChannelIndex,
  28201. const uint32 destNodeId,
  28202. const int destChannelIndex) const
  28203. {
  28204. for (int i = connections.size(); --i >= 0;)
  28205. {
  28206. const Connection* const c = connections.getUnchecked(i);
  28207. if (c->sourceNodeId == sourceNodeId
  28208. && c->destNodeId == destNodeId
  28209. && c->sourceChannelIndex == sourceChannelIndex
  28210. && c->destChannelIndex == destChannelIndex)
  28211. {
  28212. return c;
  28213. }
  28214. }
  28215. return 0;
  28216. }
  28217. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28218. const uint32 possibleDestNodeId) const
  28219. {
  28220. for (int i = connections.size(); --i >= 0;)
  28221. {
  28222. const Connection* const c = connections.getUnchecked(i);
  28223. if (c->sourceNodeId == possibleSourceNodeId
  28224. && c->destNodeId == possibleDestNodeId)
  28225. {
  28226. return true;
  28227. }
  28228. }
  28229. return false;
  28230. }
  28231. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28232. const int sourceChannelIndex,
  28233. const uint32 destNodeId,
  28234. const int destChannelIndex) const
  28235. {
  28236. if (sourceChannelIndex < 0
  28237. || destChannelIndex < 0
  28238. || sourceNodeId == destNodeId
  28239. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28240. return false;
  28241. const Node* const source = getNodeForId (sourceNodeId);
  28242. if (source == 0
  28243. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28244. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28245. return false;
  28246. const Node* const dest = getNodeForId (destNodeId);
  28247. if (dest == 0
  28248. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28249. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28250. return false;
  28251. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28252. destNodeId, destChannelIndex) == 0;
  28253. }
  28254. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28255. const int sourceChannelIndex,
  28256. const uint32 destNodeId,
  28257. const int destChannelIndex)
  28258. {
  28259. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28260. return false;
  28261. Connection* const c = new Connection();
  28262. c->sourceNodeId = sourceNodeId;
  28263. c->sourceChannelIndex = sourceChannelIndex;
  28264. c->destNodeId = destNodeId;
  28265. c->destChannelIndex = destChannelIndex;
  28266. connections.add (c);
  28267. triggerAsyncUpdate();
  28268. return true;
  28269. }
  28270. void AudioProcessorGraph::removeConnection (const int index)
  28271. {
  28272. connections.remove (index);
  28273. triggerAsyncUpdate();
  28274. }
  28275. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28276. const uint32 destNodeId, const int destChannelIndex)
  28277. {
  28278. bool doneAnything = false;
  28279. for (int i = connections.size(); --i >= 0;)
  28280. {
  28281. const Connection* const c = connections.getUnchecked(i);
  28282. if (c->sourceNodeId == sourceNodeId
  28283. && c->destNodeId == destNodeId
  28284. && c->sourceChannelIndex == sourceChannelIndex
  28285. && c->destChannelIndex == destChannelIndex)
  28286. {
  28287. removeConnection (i);
  28288. doneAnything = true;
  28289. triggerAsyncUpdate();
  28290. }
  28291. }
  28292. return doneAnything;
  28293. }
  28294. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28295. {
  28296. bool doneAnything = false;
  28297. for (int i = connections.size(); --i >= 0;)
  28298. {
  28299. const Connection* const c = connections.getUnchecked(i);
  28300. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28301. {
  28302. removeConnection (i);
  28303. doneAnything = true;
  28304. triggerAsyncUpdate();
  28305. }
  28306. }
  28307. return doneAnything;
  28308. }
  28309. bool AudioProcessorGraph::removeIllegalConnections()
  28310. {
  28311. bool doneAnything = false;
  28312. for (int i = connections.size(); --i >= 0;)
  28313. {
  28314. const Connection* const c = connections.getUnchecked(i);
  28315. const Node* const source = getNodeForId (c->sourceNodeId);
  28316. const Node* const dest = getNodeForId (c->destNodeId);
  28317. if (source == 0 || dest == 0
  28318. || (c->sourceChannelIndex != midiChannelIndex
  28319. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28320. || (c->sourceChannelIndex == midiChannelIndex
  28321. && ! source->processor->producesMidi())
  28322. || (c->destChannelIndex != midiChannelIndex
  28323. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28324. || (c->destChannelIndex == midiChannelIndex
  28325. && ! dest->processor->acceptsMidi()))
  28326. {
  28327. removeConnection (i);
  28328. doneAnything = true;
  28329. triggerAsyncUpdate();
  28330. }
  28331. }
  28332. return doneAnything;
  28333. }
  28334. namespace GraphRenderingOps
  28335. {
  28336. class AudioGraphRenderingOp
  28337. {
  28338. public:
  28339. AudioGraphRenderingOp() {}
  28340. virtual ~AudioGraphRenderingOp() {}
  28341. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28342. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28343. const int numSamples) = 0;
  28344. juce_UseDebuggingNewOperator
  28345. };
  28346. class ClearChannelOp : public AudioGraphRenderingOp
  28347. {
  28348. public:
  28349. ClearChannelOp (const int channelNum_)
  28350. : channelNum (channelNum_)
  28351. {}
  28352. ~ClearChannelOp() {}
  28353. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28354. {
  28355. sharedBufferChans.clear (channelNum, 0, numSamples);
  28356. }
  28357. private:
  28358. const int channelNum;
  28359. ClearChannelOp (const ClearChannelOp&);
  28360. ClearChannelOp& operator= (const ClearChannelOp&);
  28361. };
  28362. class CopyChannelOp : public AudioGraphRenderingOp
  28363. {
  28364. public:
  28365. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28366. : srcChannelNum (srcChannelNum_),
  28367. dstChannelNum (dstChannelNum_)
  28368. {}
  28369. ~CopyChannelOp() {}
  28370. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28371. {
  28372. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28373. }
  28374. private:
  28375. const int srcChannelNum, dstChannelNum;
  28376. CopyChannelOp (const CopyChannelOp&);
  28377. CopyChannelOp& operator= (const CopyChannelOp&);
  28378. };
  28379. class AddChannelOp : public AudioGraphRenderingOp
  28380. {
  28381. public:
  28382. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28383. : srcChannelNum (srcChannelNum_),
  28384. dstChannelNum (dstChannelNum_)
  28385. {}
  28386. ~AddChannelOp() {}
  28387. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28388. {
  28389. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28390. }
  28391. private:
  28392. const int srcChannelNum, dstChannelNum;
  28393. AddChannelOp (const AddChannelOp&);
  28394. AddChannelOp& operator= (const AddChannelOp&);
  28395. };
  28396. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28397. {
  28398. public:
  28399. ClearMidiBufferOp (const int bufferNum_)
  28400. : bufferNum (bufferNum_)
  28401. {}
  28402. ~ClearMidiBufferOp() {}
  28403. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28404. {
  28405. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28406. }
  28407. private:
  28408. const int bufferNum;
  28409. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28410. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28411. };
  28412. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28413. {
  28414. public:
  28415. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28416. : srcBufferNum (srcBufferNum_),
  28417. dstBufferNum (dstBufferNum_)
  28418. {}
  28419. ~CopyMidiBufferOp() {}
  28420. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28421. {
  28422. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28423. }
  28424. private:
  28425. const int srcBufferNum, dstBufferNum;
  28426. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28427. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28428. };
  28429. class AddMidiBufferOp : public AudioGraphRenderingOp
  28430. {
  28431. public:
  28432. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28433. : srcBufferNum (srcBufferNum_),
  28434. dstBufferNum (dstBufferNum_)
  28435. {}
  28436. ~AddMidiBufferOp() {}
  28437. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28438. {
  28439. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28440. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28441. }
  28442. private:
  28443. const int srcBufferNum, dstBufferNum;
  28444. AddMidiBufferOp (const AddMidiBufferOp&);
  28445. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28446. };
  28447. class ProcessBufferOp : public AudioGraphRenderingOp
  28448. {
  28449. public:
  28450. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28451. const Array <int>& audioChannelsToUse_,
  28452. const int totalChans_,
  28453. const int midiBufferToUse_)
  28454. : node (node_),
  28455. processor (node_->processor),
  28456. audioChannelsToUse (audioChannelsToUse_),
  28457. totalChans (jmax (1, totalChans_)),
  28458. midiBufferToUse (midiBufferToUse_)
  28459. {
  28460. channels.calloc (totalChans);
  28461. while (audioChannelsToUse.size() < totalChans)
  28462. audioChannelsToUse.add (0);
  28463. }
  28464. ~ProcessBufferOp()
  28465. {
  28466. }
  28467. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28468. {
  28469. for (int i = totalChans; --i >= 0;)
  28470. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28471. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28472. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28473. }
  28474. const AudioProcessorGraph::Node::Ptr node;
  28475. AudioProcessor* const processor;
  28476. private:
  28477. Array <int> audioChannelsToUse;
  28478. HeapBlock <float*> channels;
  28479. int totalChans;
  28480. int midiBufferToUse;
  28481. ProcessBufferOp (const ProcessBufferOp&);
  28482. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28483. };
  28484. class RenderingOpSequenceCalculator
  28485. {
  28486. public:
  28487. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28488. const VoidArray& orderedNodes_,
  28489. VoidArray& renderingOps)
  28490. : graph (graph_),
  28491. orderedNodes (orderedNodes_)
  28492. {
  28493. nodeIds.add (-2); // first buffer is read-only zeros
  28494. channels.add (0);
  28495. midiNodeIds.add (-2);
  28496. for (int i = 0; i < orderedNodes.size(); ++i)
  28497. {
  28498. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28499. renderingOps, i);
  28500. markAnyUnusedBuffersAsFree (i);
  28501. }
  28502. }
  28503. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28504. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28505. juce_UseDebuggingNewOperator
  28506. private:
  28507. AudioProcessorGraph& graph;
  28508. const VoidArray& orderedNodes;
  28509. Array <int> nodeIds, channels, midiNodeIds;
  28510. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28511. VoidArray& renderingOps,
  28512. const int ourRenderingIndex)
  28513. {
  28514. const int numIns = node->processor->getNumInputChannels();
  28515. const int numOuts = node->processor->getNumOutputChannels();
  28516. const int totalChans = jmax (numIns, numOuts);
  28517. Array <int> audioChannelsToUse;
  28518. int midiBufferToUse = -1;
  28519. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28520. {
  28521. // get a list of all the inputs to this node
  28522. Array <int> sourceNodes, sourceOutputChans;
  28523. for (int i = graph.getNumConnections(); --i >= 0;)
  28524. {
  28525. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28526. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28527. {
  28528. sourceNodes.add (c->sourceNodeId);
  28529. sourceOutputChans.add (c->sourceChannelIndex);
  28530. }
  28531. }
  28532. int bufIndex = -1;
  28533. if (sourceNodes.size() == 0)
  28534. {
  28535. // unconnected input channel
  28536. if (inputChan >= numOuts)
  28537. {
  28538. bufIndex = getReadOnlyEmptyBuffer();
  28539. jassert (bufIndex >= 0);
  28540. }
  28541. else
  28542. {
  28543. bufIndex = getFreeBuffer (false);
  28544. renderingOps.add (new ClearChannelOp (bufIndex));
  28545. }
  28546. }
  28547. else if (sourceNodes.size() == 1)
  28548. {
  28549. // channel with a straightforward single input..
  28550. const int srcNode = sourceNodes.getUnchecked(0);
  28551. const int srcChan = sourceOutputChans.getUnchecked(0);
  28552. bufIndex = getBufferContaining (srcNode, srcChan);
  28553. if (bufIndex < 0)
  28554. {
  28555. // if not found, this is probably a feedback loop
  28556. bufIndex = getReadOnlyEmptyBuffer();
  28557. jassert (bufIndex >= 0);
  28558. }
  28559. if (inputChan < numOuts
  28560. && isBufferNeededLater (ourRenderingIndex,
  28561. inputChan,
  28562. srcNode, srcChan))
  28563. {
  28564. // can't mess up this channel because it's needed later by another node, so we
  28565. // need to use a copy of it..
  28566. const int newFreeBuffer = getFreeBuffer (false);
  28567. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28568. bufIndex = newFreeBuffer;
  28569. }
  28570. }
  28571. else
  28572. {
  28573. // channel with a mix of several inputs..
  28574. // try to find a re-usable channel from our inputs..
  28575. int reusableInputIndex = -1;
  28576. for (int i = 0; i < sourceNodes.size(); ++i)
  28577. {
  28578. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28579. sourceOutputChans.getUnchecked(i));
  28580. if (sourceBufIndex >= 0
  28581. && ! isBufferNeededLater (ourRenderingIndex,
  28582. inputChan,
  28583. sourceNodes.getUnchecked(i),
  28584. sourceOutputChans.getUnchecked(i)))
  28585. {
  28586. // we've found one of our input chans that can be re-used..
  28587. reusableInputIndex = i;
  28588. bufIndex = sourceBufIndex;
  28589. break;
  28590. }
  28591. }
  28592. if (reusableInputIndex < 0)
  28593. {
  28594. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28595. bufIndex = getFreeBuffer (false);
  28596. jassert (bufIndex != 0);
  28597. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28598. sourceOutputChans.getUnchecked (0));
  28599. if (srcIndex < 0)
  28600. {
  28601. // if not found, this is probably a feedback loop
  28602. renderingOps.add (new ClearChannelOp (bufIndex));
  28603. }
  28604. else
  28605. {
  28606. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28607. }
  28608. reusableInputIndex = 0;
  28609. }
  28610. for (int j = 0; j < sourceNodes.size(); ++j)
  28611. {
  28612. if (j != reusableInputIndex)
  28613. {
  28614. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28615. sourceOutputChans.getUnchecked(j));
  28616. if (srcIndex >= 0)
  28617. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28618. }
  28619. }
  28620. }
  28621. jassert (bufIndex >= 0);
  28622. audioChannelsToUse.add (bufIndex);
  28623. if (inputChan < numOuts)
  28624. markBufferAsContaining (bufIndex, node->id, inputChan);
  28625. }
  28626. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28627. {
  28628. const int bufIndex = getFreeBuffer (false);
  28629. jassert (bufIndex != 0);
  28630. audioChannelsToUse.add (bufIndex);
  28631. markBufferAsContaining (bufIndex, node->id, outputChan);
  28632. }
  28633. // Now the same thing for midi..
  28634. Array <int> midiSourceNodes;
  28635. for (int i = graph.getNumConnections(); --i >= 0;)
  28636. {
  28637. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28638. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28639. midiSourceNodes.add (c->sourceNodeId);
  28640. }
  28641. if (midiSourceNodes.size() == 0)
  28642. {
  28643. // No midi inputs..
  28644. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28645. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28646. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28647. }
  28648. else if (midiSourceNodes.size() == 1)
  28649. {
  28650. // One midi input..
  28651. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28652. AudioProcessorGraph::midiChannelIndex);
  28653. if (midiBufferToUse >= 0)
  28654. {
  28655. if (isBufferNeededLater (ourRenderingIndex,
  28656. AudioProcessorGraph::midiChannelIndex,
  28657. midiSourceNodes.getUnchecked(0),
  28658. AudioProcessorGraph::midiChannelIndex))
  28659. {
  28660. // can't mess up this channel because it's needed later by another node, so we
  28661. // need to use a copy of it..
  28662. const int newFreeBuffer = getFreeBuffer (true);
  28663. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28664. midiBufferToUse = newFreeBuffer;
  28665. }
  28666. }
  28667. else
  28668. {
  28669. // probably a feedback loop, so just use an empty one..
  28670. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28671. }
  28672. }
  28673. else
  28674. {
  28675. // More than one midi input being mixed..
  28676. int reusableInputIndex = -1;
  28677. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28678. {
  28679. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28680. AudioProcessorGraph::midiChannelIndex);
  28681. if (sourceBufIndex >= 0
  28682. && ! isBufferNeededLater (ourRenderingIndex,
  28683. AudioProcessorGraph::midiChannelIndex,
  28684. midiSourceNodes.getUnchecked(i),
  28685. AudioProcessorGraph::midiChannelIndex))
  28686. {
  28687. // we've found one of our input buffers that can be re-used..
  28688. reusableInputIndex = i;
  28689. midiBufferToUse = sourceBufIndex;
  28690. break;
  28691. }
  28692. }
  28693. if (reusableInputIndex < 0)
  28694. {
  28695. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28696. midiBufferToUse = getFreeBuffer (true);
  28697. jassert (midiBufferToUse >= 0);
  28698. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28699. AudioProcessorGraph::midiChannelIndex);
  28700. if (srcIndex >= 0)
  28701. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28702. else
  28703. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28704. reusableInputIndex = 0;
  28705. }
  28706. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28707. {
  28708. if (j != reusableInputIndex)
  28709. {
  28710. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28711. AudioProcessorGraph::midiChannelIndex);
  28712. if (srcIndex >= 0)
  28713. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28714. }
  28715. }
  28716. }
  28717. if (node->processor->producesMidi())
  28718. markBufferAsContaining (midiBufferToUse, node->id,
  28719. AudioProcessorGraph::midiChannelIndex);
  28720. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28721. totalChans, midiBufferToUse));
  28722. }
  28723. int getFreeBuffer (const bool forMidi)
  28724. {
  28725. if (forMidi)
  28726. {
  28727. for (int i = 1; i < midiNodeIds.size(); ++i)
  28728. if (midiNodeIds.getUnchecked(i) < 0)
  28729. return i;
  28730. midiNodeIds.add (-1);
  28731. return midiNodeIds.size() - 1;
  28732. }
  28733. else
  28734. {
  28735. for (int i = 1; i < nodeIds.size(); ++i)
  28736. if (nodeIds.getUnchecked(i) < 0)
  28737. return i;
  28738. nodeIds.add (-1);
  28739. channels.add (0);
  28740. return nodeIds.size() - 1;
  28741. }
  28742. }
  28743. int getReadOnlyEmptyBuffer() const
  28744. {
  28745. return 0;
  28746. }
  28747. int getBufferContaining (const int nodeId, const int outputChannel) const
  28748. {
  28749. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28750. {
  28751. for (int i = midiNodeIds.size(); --i >= 0;)
  28752. if (midiNodeIds.getUnchecked(i) == nodeId)
  28753. return i;
  28754. }
  28755. else
  28756. {
  28757. for (int i = nodeIds.size(); --i >= 0;)
  28758. if (nodeIds.getUnchecked(i) == nodeId
  28759. && channels.getUnchecked(i) == outputChannel)
  28760. return i;
  28761. }
  28762. return -1;
  28763. }
  28764. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28765. {
  28766. int i;
  28767. for (i = 0; i < nodeIds.size(); ++i)
  28768. {
  28769. if (nodeIds.getUnchecked(i) >= 0
  28770. && ! isBufferNeededLater (stepIndex, -1,
  28771. nodeIds.getUnchecked(i),
  28772. channels.getUnchecked(i)))
  28773. {
  28774. nodeIds.set (i, -1);
  28775. }
  28776. }
  28777. for (i = 0; i < midiNodeIds.size(); ++i)
  28778. {
  28779. if (midiNodeIds.getUnchecked(i) >= 0
  28780. && ! isBufferNeededLater (stepIndex, -1,
  28781. midiNodeIds.getUnchecked(i),
  28782. AudioProcessorGraph::midiChannelIndex))
  28783. {
  28784. midiNodeIds.set (i, -1);
  28785. }
  28786. }
  28787. }
  28788. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28789. int inputChannelOfIndexToIgnore,
  28790. const int nodeId,
  28791. const int outputChanIndex) const
  28792. {
  28793. while (stepIndexToSearchFrom < orderedNodes.size())
  28794. {
  28795. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28796. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28797. {
  28798. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28799. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28800. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28801. return true;
  28802. }
  28803. else
  28804. {
  28805. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28806. if (i != inputChannelOfIndexToIgnore
  28807. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28808. node->id, i) != 0)
  28809. return true;
  28810. }
  28811. inputChannelOfIndexToIgnore = -1;
  28812. ++stepIndexToSearchFrom;
  28813. }
  28814. return false;
  28815. }
  28816. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28817. {
  28818. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28819. {
  28820. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28821. midiNodeIds.set (bufferNum, nodeId);
  28822. }
  28823. else
  28824. {
  28825. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28826. nodeIds.set (bufferNum, nodeId);
  28827. channels.set (bufferNum, outputIndex);
  28828. }
  28829. }
  28830. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28831. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28832. };
  28833. }
  28834. void AudioProcessorGraph::clearRenderingSequence()
  28835. {
  28836. const ScopedLock sl (renderLock);
  28837. for (int i = renderingOps.size(); --i >= 0;)
  28838. {
  28839. GraphRenderingOps::AudioGraphRenderingOp* const r
  28840. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28841. renderingOps.remove (i);
  28842. delete r;
  28843. }
  28844. }
  28845. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28846. const uint32 possibleDestinationId,
  28847. const int recursionCheck) const
  28848. {
  28849. if (recursionCheck > 0)
  28850. {
  28851. for (int i = connections.size(); --i >= 0;)
  28852. {
  28853. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28854. if (c->destNodeId == possibleDestinationId
  28855. && (c->sourceNodeId == possibleInputId
  28856. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28857. return true;
  28858. }
  28859. }
  28860. return false;
  28861. }
  28862. void AudioProcessorGraph::buildRenderingSequence()
  28863. {
  28864. VoidArray newRenderingOps;
  28865. int numRenderingBuffersNeeded = 2;
  28866. int numMidiBuffersNeeded = 1;
  28867. {
  28868. MessageManagerLock mml;
  28869. VoidArray orderedNodes;
  28870. int i;
  28871. for (i = 0; i < nodes.size(); ++i)
  28872. {
  28873. Node* const node = nodes.getUnchecked(i);
  28874. node->prepare (getSampleRate(), getBlockSize(), this);
  28875. int j = 0;
  28876. for (; j < orderedNodes.size(); ++j)
  28877. if (isAnInputTo (node->id,
  28878. ((Node*) orderedNodes.getUnchecked (j))->id,
  28879. nodes.size() + 1))
  28880. break;
  28881. orderedNodes.insert (j, node);
  28882. }
  28883. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28884. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28885. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28886. }
  28887. VoidArray oldRenderingOps (renderingOps);
  28888. {
  28889. // swap over to the new rendering sequence..
  28890. const ScopedLock sl (renderLock);
  28891. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28892. renderingBuffers.clear();
  28893. for (int i = midiBuffers.size(); --i >= 0;)
  28894. midiBuffers.getUnchecked(i)->clear();
  28895. while (midiBuffers.size() < numMidiBuffersNeeded)
  28896. midiBuffers.add (new MidiBuffer());
  28897. renderingOps = newRenderingOps;
  28898. }
  28899. for (int i = oldRenderingOps.size(); --i >= 0;)
  28900. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28901. }
  28902. void AudioProcessorGraph::handleAsyncUpdate()
  28903. {
  28904. buildRenderingSequence();
  28905. }
  28906. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28907. {
  28908. currentAudioInputBuffer = 0;
  28909. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28910. currentMidiInputBuffer = 0;
  28911. currentMidiOutputBuffer.clear();
  28912. clearRenderingSequence();
  28913. buildRenderingSequence();
  28914. }
  28915. void AudioProcessorGraph::releaseResources()
  28916. {
  28917. for (int i = 0; i < nodes.size(); ++i)
  28918. nodes.getUnchecked(i)->unprepare();
  28919. renderingBuffers.setSize (1, 1);
  28920. midiBuffers.clear();
  28921. currentAudioInputBuffer = 0;
  28922. currentAudioOutputBuffer.setSize (1, 1);
  28923. currentMidiInputBuffer = 0;
  28924. currentMidiOutputBuffer.clear();
  28925. }
  28926. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28927. {
  28928. const int numSamples = buffer.getNumSamples();
  28929. const ScopedLock sl (renderLock);
  28930. currentAudioInputBuffer = &buffer;
  28931. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28932. currentAudioOutputBuffer.clear();
  28933. currentMidiInputBuffer = &midiMessages;
  28934. currentMidiOutputBuffer.clear();
  28935. int i;
  28936. for (i = 0; i < renderingOps.size(); ++i)
  28937. {
  28938. GraphRenderingOps::AudioGraphRenderingOp* const op
  28939. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28940. op->perform (renderingBuffers, midiBuffers, numSamples);
  28941. }
  28942. for (i = 0; i < buffer.getNumChannels(); ++i)
  28943. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28944. midiMessages.clear();
  28945. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28946. }
  28947. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28948. {
  28949. return "Input " + String (channelIndex + 1);
  28950. }
  28951. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28952. {
  28953. return "Output " + String (channelIndex + 1);
  28954. }
  28955. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28956. {
  28957. return true;
  28958. }
  28959. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28960. {
  28961. return true;
  28962. }
  28963. bool AudioProcessorGraph::acceptsMidi() const
  28964. {
  28965. return true;
  28966. }
  28967. bool AudioProcessorGraph::producesMidi() const
  28968. {
  28969. return true;
  28970. }
  28971. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28972. {
  28973. }
  28974. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28975. {
  28976. }
  28977. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28978. : type (type_),
  28979. graph (0)
  28980. {
  28981. }
  28982. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28983. {
  28984. }
  28985. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28986. {
  28987. switch (type)
  28988. {
  28989. case audioOutputNode:
  28990. return "Audio Output";
  28991. case audioInputNode:
  28992. return "Audio Input";
  28993. case midiOutputNode:
  28994. return "Midi Output";
  28995. case midiInputNode:
  28996. return "Midi Input";
  28997. default:
  28998. break;
  28999. }
  29000. return String::empty;
  29001. }
  29002. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  29003. {
  29004. d.name = getName();
  29005. d.uid = d.name.hashCode();
  29006. d.category = "I/O devices";
  29007. d.pluginFormatName = "Internal";
  29008. d.manufacturerName = "Raw Material Software";
  29009. d.version = "1.0";
  29010. d.isInstrument = false;
  29011. d.numInputChannels = getNumInputChannels();
  29012. if (type == audioOutputNode && graph != 0)
  29013. d.numInputChannels = graph->getNumInputChannels();
  29014. d.numOutputChannels = getNumOutputChannels();
  29015. if (type == audioInputNode && graph != 0)
  29016. d.numOutputChannels = graph->getNumOutputChannels();
  29017. }
  29018. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  29019. {
  29020. jassert (graph != 0);
  29021. }
  29022. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  29023. {
  29024. }
  29025. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  29026. MidiBuffer& midiMessages)
  29027. {
  29028. jassert (graph != 0);
  29029. switch (type)
  29030. {
  29031. case audioOutputNode:
  29032. {
  29033. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  29034. buffer.getNumChannels()); --i >= 0;)
  29035. {
  29036. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  29037. }
  29038. break;
  29039. }
  29040. case audioInputNode:
  29041. {
  29042. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  29043. buffer.getNumChannels()); --i >= 0;)
  29044. {
  29045. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  29046. }
  29047. break;
  29048. }
  29049. case midiOutputNode:
  29050. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  29051. break;
  29052. case midiInputNode:
  29053. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  29054. break;
  29055. default:
  29056. break;
  29057. }
  29058. }
  29059. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  29060. {
  29061. return type == midiOutputNode;
  29062. }
  29063. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  29064. {
  29065. return type == midiInputNode;
  29066. }
  29067. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  29068. {
  29069. switch (type)
  29070. {
  29071. case audioOutputNode:
  29072. return "Output " + String (channelIndex + 1);
  29073. case midiOutputNode:
  29074. return "Midi Output";
  29075. default:
  29076. break;
  29077. }
  29078. return String::empty;
  29079. }
  29080. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  29081. {
  29082. switch (type)
  29083. {
  29084. case audioInputNode:
  29085. return "Input " + String (channelIndex + 1);
  29086. case midiInputNode:
  29087. return "Midi Input";
  29088. default:
  29089. break;
  29090. }
  29091. return String::empty;
  29092. }
  29093. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  29094. {
  29095. return type == audioInputNode || type == audioOutputNode;
  29096. }
  29097. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  29098. {
  29099. return isInputChannelStereoPair (index);
  29100. }
  29101. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  29102. {
  29103. return type == audioInputNode || type == midiInputNode;
  29104. }
  29105. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29106. {
  29107. return type == audioOutputNode || type == midiOutputNode;
  29108. }
  29109. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29110. {
  29111. return 0;
  29112. }
  29113. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29114. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29115. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29116. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29117. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29118. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29119. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29120. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29121. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29122. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29123. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29124. {
  29125. }
  29126. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29127. {
  29128. }
  29129. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29130. {
  29131. graph = newGraph;
  29132. if (graph != 0)
  29133. {
  29134. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29135. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29136. getSampleRate(),
  29137. getBlockSize());
  29138. updateHostDisplay();
  29139. }
  29140. }
  29141. END_JUCE_NAMESPACE
  29142. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  29143. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29144. BEGIN_JUCE_NAMESPACE
  29145. AudioProcessorPlayer::AudioProcessorPlayer()
  29146. : processor (0),
  29147. sampleRate (0),
  29148. blockSize (0),
  29149. isPrepared (false),
  29150. numInputChans (0),
  29151. numOutputChans (0),
  29152. tempBuffer (1, 1)
  29153. {
  29154. }
  29155. AudioProcessorPlayer::~AudioProcessorPlayer()
  29156. {
  29157. setProcessor (0);
  29158. }
  29159. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29160. {
  29161. if (processor != processorToPlay)
  29162. {
  29163. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29164. {
  29165. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29166. sampleRate, blockSize);
  29167. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29168. }
  29169. AudioProcessor* oldOne;
  29170. {
  29171. const ScopedLock sl (lock);
  29172. oldOne = isPrepared ? processor : 0;
  29173. processor = processorToPlay;
  29174. isPrepared = true;
  29175. }
  29176. if (oldOne != 0)
  29177. oldOne->releaseResources();
  29178. }
  29179. }
  29180. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29181. int numInputChannels,
  29182. float** outputChannelData,
  29183. int numOutputChannels,
  29184. int numSamples)
  29185. {
  29186. // these should have been prepared by audioDeviceAboutToStart()...
  29187. jassert (sampleRate > 0 && blockSize > 0);
  29188. incomingMidi.clear();
  29189. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29190. int i, totalNumChans = 0;
  29191. if (numInputChannels > numOutputChannels)
  29192. {
  29193. // if there aren't enough output channels for the number of
  29194. // inputs, we need to create some temporary extra ones (can't
  29195. // use the input data in case it gets written to)
  29196. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29197. false, false, true);
  29198. for (i = 0; i < numOutputChannels; ++i)
  29199. {
  29200. channels[totalNumChans] = outputChannelData[i];
  29201. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29202. ++totalNumChans;
  29203. }
  29204. for (i = numOutputChannels; i < numInputChannels; ++i)
  29205. {
  29206. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29207. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29208. ++totalNumChans;
  29209. }
  29210. }
  29211. else
  29212. {
  29213. for (i = 0; i < numInputChannels; ++i)
  29214. {
  29215. channels[totalNumChans] = outputChannelData[i];
  29216. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29217. ++totalNumChans;
  29218. }
  29219. for (i = numInputChannels; i < numOutputChannels; ++i)
  29220. {
  29221. channels[totalNumChans] = outputChannelData[i];
  29222. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29223. ++totalNumChans;
  29224. }
  29225. }
  29226. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29227. const ScopedLock sl (lock);
  29228. if (processor != 0)
  29229. processor->processBlock (buffer, incomingMidi);
  29230. }
  29231. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29232. {
  29233. const ScopedLock sl (lock);
  29234. sampleRate = device->getCurrentSampleRate();
  29235. blockSize = device->getCurrentBufferSizeSamples();
  29236. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29237. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29238. messageCollector.reset (sampleRate);
  29239. zeromem (channels, sizeof (channels));
  29240. if (processor != 0)
  29241. {
  29242. if (isPrepared)
  29243. processor->releaseResources();
  29244. AudioProcessor* const oldProcessor = processor;
  29245. setProcessor (0);
  29246. setProcessor (oldProcessor);
  29247. }
  29248. }
  29249. void AudioProcessorPlayer::audioDeviceStopped()
  29250. {
  29251. const ScopedLock sl (lock);
  29252. if (processor != 0 && isPrepared)
  29253. processor->releaseResources();
  29254. sampleRate = 0.0;
  29255. blockSize = 0;
  29256. isPrepared = false;
  29257. tempBuffer.setSize (1, 1);
  29258. }
  29259. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29260. {
  29261. messageCollector.addMessageToQueue (message);
  29262. }
  29263. END_JUCE_NAMESPACE
  29264. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29265. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29266. BEGIN_JUCE_NAMESPACE
  29267. class ProcessorParameterPropertyComp : public PropertyComponent,
  29268. public AudioProcessorListener,
  29269. public AsyncUpdater
  29270. {
  29271. public:
  29272. ProcessorParameterPropertyComp (const String& name,
  29273. AudioProcessor* const owner_,
  29274. const int index_)
  29275. : PropertyComponent (name),
  29276. owner (owner_),
  29277. index (index_)
  29278. {
  29279. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29280. owner_->addListener (this);
  29281. }
  29282. ~ProcessorParameterPropertyComp()
  29283. {
  29284. owner->removeListener (this);
  29285. deleteAllChildren();
  29286. }
  29287. void refresh()
  29288. {
  29289. slider->setValue (owner->getParameter (index), false);
  29290. }
  29291. void audioProcessorChanged (AudioProcessor*) {}
  29292. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29293. {
  29294. if (parameterIndex == index)
  29295. triggerAsyncUpdate();
  29296. }
  29297. void handleAsyncUpdate()
  29298. {
  29299. refresh();
  29300. }
  29301. juce_UseDebuggingNewOperator
  29302. private:
  29303. AudioProcessor* const owner;
  29304. const int index;
  29305. Slider* slider;
  29306. class ParamSlider : public Slider
  29307. {
  29308. public:
  29309. ParamSlider (AudioProcessor* const owner_, const int index_)
  29310. : Slider (String::empty),
  29311. owner (owner_),
  29312. index (index_)
  29313. {
  29314. setRange (0.0, 1.0, 0.0);
  29315. setSliderStyle (Slider::LinearBar);
  29316. setTextBoxIsEditable (false);
  29317. setScrollWheelEnabled (false);
  29318. }
  29319. ~ParamSlider()
  29320. {
  29321. }
  29322. void valueChanged()
  29323. {
  29324. const float newVal = (float) getValue();
  29325. if (owner->getParameter (index) != newVal)
  29326. owner->setParameter (index, newVal);
  29327. }
  29328. const String getTextFromValue (double /*value*/)
  29329. {
  29330. return owner->getParameterText (index);
  29331. }
  29332. juce_UseDebuggingNewOperator
  29333. private:
  29334. AudioProcessor* const owner;
  29335. const int index;
  29336. ParamSlider (const ParamSlider&);
  29337. ParamSlider& operator= (const ParamSlider&);
  29338. };
  29339. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29340. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29341. };
  29342. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29343. : AudioProcessorEditor (owner_)
  29344. {
  29345. setOpaque (true);
  29346. addAndMakeVisible (panel = new PropertyPanel());
  29347. Array <PropertyComponent*> params;
  29348. const int numParams = owner_->getNumParameters();
  29349. int totalHeight = 0;
  29350. for (int i = 0; i < numParams; ++i)
  29351. {
  29352. String name (owner_->getParameterName (i));
  29353. if (name.trim().isEmpty())
  29354. name = "Unnamed";
  29355. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29356. params.add (pc);
  29357. totalHeight += pc->getPreferredHeight();
  29358. }
  29359. panel->addProperties (params);
  29360. setSize (400, jlimit (25, 400, totalHeight));
  29361. }
  29362. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29363. {
  29364. deleteAllChildren();
  29365. }
  29366. void GenericAudioProcessorEditor::paint (Graphics& g)
  29367. {
  29368. g.fillAll (Colours::white);
  29369. }
  29370. void GenericAudioProcessorEditor::resized()
  29371. {
  29372. panel->setSize (getWidth(), getHeight());
  29373. }
  29374. END_JUCE_NAMESPACE
  29375. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29376. /*** Start of inlined file: juce_Sampler.cpp ***/
  29377. BEGIN_JUCE_NAMESPACE
  29378. SamplerSound::SamplerSound (const String& name_,
  29379. AudioFormatReader& source,
  29380. const BitArray& midiNotes_,
  29381. const int midiNoteForNormalPitch,
  29382. const double attackTimeSecs,
  29383. const double releaseTimeSecs,
  29384. const double maxSampleLengthSeconds)
  29385. : name (name_),
  29386. midiNotes (midiNotes_),
  29387. midiRootNote (midiNoteForNormalPitch)
  29388. {
  29389. sourceSampleRate = source.sampleRate;
  29390. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29391. {
  29392. length = 0;
  29393. attackSamples = 0;
  29394. releaseSamples = 0;
  29395. }
  29396. else
  29397. {
  29398. length = jmin ((int) source.lengthInSamples,
  29399. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29400. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29401. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29402. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29403. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29404. }
  29405. }
  29406. SamplerSound::~SamplerSound()
  29407. {
  29408. }
  29409. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29410. {
  29411. return midiNotes [midiNoteNumber];
  29412. }
  29413. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29414. {
  29415. return true;
  29416. }
  29417. SamplerVoice::SamplerVoice()
  29418. : pitchRatio (0.0),
  29419. sourceSamplePosition (0.0),
  29420. lgain (0.0f),
  29421. rgain (0.0f),
  29422. isInAttack (false),
  29423. isInRelease (false)
  29424. {
  29425. }
  29426. SamplerVoice::~SamplerVoice()
  29427. {
  29428. }
  29429. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29430. {
  29431. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29432. }
  29433. void SamplerVoice::startNote (const int midiNoteNumber,
  29434. const float velocity,
  29435. SynthesiserSound* s,
  29436. const int /*currentPitchWheelPosition*/)
  29437. {
  29438. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29439. jassert (sound != 0); // this object can only play SamplerSounds!
  29440. if (sound != 0)
  29441. {
  29442. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29443. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29444. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29445. sourceSamplePosition = 0.0;
  29446. lgain = velocity;
  29447. rgain = velocity;
  29448. isInAttack = (sound->attackSamples > 0);
  29449. isInRelease = false;
  29450. if (isInAttack)
  29451. {
  29452. attackReleaseLevel = 0.0f;
  29453. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29454. }
  29455. else
  29456. {
  29457. attackReleaseLevel = 1.0f;
  29458. attackDelta = 0.0f;
  29459. }
  29460. if (sound->releaseSamples > 0)
  29461. {
  29462. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29463. }
  29464. else
  29465. {
  29466. releaseDelta = 0.0f;
  29467. }
  29468. }
  29469. }
  29470. void SamplerVoice::stopNote (const bool allowTailOff)
  29471. {
  29472. if (allowTailOff)
  29473. {
  29474. isInAttack = false;
  29475. isInRelease = true;
  29476. }
  29477. else
  29478. {
  29479. clearCurrentNote();
  29480. }
  29481. }
  29482. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29483. {
  29484. }
  29485. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29486. const int /*newValue*/)
  29487. {
  29488. }
  29489. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29490. {
  29491. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29492. if (playingSound != 0)
  29493. {
  29494. const float* const inL = playingSound->data->getSampleData (0, 0);
  29495. const float* const inR = playingSound->data->getNumChannels() > 1
  29496. ? playingSound->data->getSampleData (1, 0) : 0;
  29497. float* outL = outputBuffer.getSampleData (0, startSample);
  29498. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29499. while (--numSamples >= 0)
  29500. {
  29501. const int pos = (int) sourceSamplePosition;
  29502. const float alpha = (float) (sourceSamplePosition - pos);
  29503. const float invAlpha = 1.0f - alpha;
  29504. // just using a very simple linear interpolation here..
  29505. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29506. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29507. : l;
  29508. l *= lgain;
  29509. r *= rgain;
  29510. if (isInAttack)
  29511. {
  29512. l *= attackReleaseLevel;
  29513. r *= attackReleaseLevel;
  29514. attackReleaseLevel += attackDelta;
  29515. if (attackReleaseLevel >= 1.0f)
  29516. {
  29517. attackReleaseLevel = 1.0f;
  29518. isInAttack = false;
  29519. }
  29520. }
  29521. else if (isInRelease)
  29522. {
  29523. l *= attackReleaseLevel;
  29524. r *= attackReleaseLevel;
  29525. attackReleaseLevel += releaseDelta;
  29526. if (attackReleaseLevel <= 0.0f)
  29527. {
  29528. stopNote (false);
  29529. break;
  29530. }
  29531. }
  29532. if (outR != 0)
  29533. {
  29534. *outL++ += l;
  29535. *outR++ += r;
  29536. }
  29537. else
  29538. {
  29539. *outL++ += (l + r) * 0.5f;
  29540. }
  29541. sourceSamplePosition += pitchRatio;
  29542. if (sourceSamplePosition > playingSound->length)
  29543. {
  29544. stopNote (false);
  29545. break;
  29546. }
  29547. }
  29548. }
  29549. }
  29550. END_JUCE_NAMESPACE
  29551. /*** End of inlined file: juce_Sampler.cpp ***/
  29552. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29553. BEGIN_JUCE_NAMESPACE
  29554. SynthesiserSound::SynthesiserSound()
  29555. {
  29556. }
  29557. SynthesiserSound::~SynthesiserSound()
  29558. {
  29559. }
  29560. SynthesiserVoice::SynthesiserVoice()
  29561. : currentSampleRate (44100.0),
  29562. currentlyPlayingNote (-1),
  29563. noteOnTime (0),
  29564. currentlyPlayingSound (0)
  29565. {
  29566. }
  29567. SynthesiserVoice::~SynthesiserVoice()
  29568. {
  29569. }
  29570. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29571. {
  29572. return currentlyPlayingSound != 0
  29573. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29574. }
  29575. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29576. {
  29577. currentSampleRate = newRate;
  29578. }
  29579. void SynthesiserVoice::clearCurrentNote()
  29580. {
  29581. currentlyPlayingNote = -1;
  29582. currentlyPlayingSound = 0;
  29583. }
  29584. Synthesiser::Synthesiser()
  29585. : sampleRate (0),
  29586. lastNoteOnCounter (0),
  29587. shouldStealNotes (true)
  29588. {
  29589. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29590. lastPitchWheelValues[i] = 0x2000;
  29591. }
  29592. Synthesiser::~Synthesiser()
  29593. {
  29594. }
  29595. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29596. {
  29597. const ScopedLock sl (lock);
  29598. return voices [index];
  29599. }
  29600. void Synthesiser::clearVoices()
  29601. {
  29602. const ScopedLock sl (lock);
  29603. voices.clear();
  29604. }
  29605. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29606. {
  29607. const ScopedLock sl (lock);
  29608. voices.add (newVoice);
  29609. }
  29610. void Synthesiser::removeVoice (const int index)
  29611. {
  29612. const ScopedLock sl (lock);
  29613. voices.remove (index);
  29614. }
  29615. void Synthesiser::clearSounds()
  29616. {
  29617. const ScopedLock sl (lock);
  29618. sounds.clear();
  29619. }
  29620. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29621. {
  29622. const ScopedLock sl (lock);
  29623. sounds.add (newSound);
  29624. }
  29625. void Synthesiser::removeSound (const int index)
  29626. {
  29627. const ScopedLock sl (lock);
  29628. sounds.remove (index);
  29629. }
  29630. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29631. {
  29632. shouldStealNotes = shouldStealNotes_;
  29633. }
  29634. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29635. {
  29636. if (sampleRate != newRate)
  29637. {
  29638. const ScopedLock sl (lock);
  29639. allNotesOff (0, false);
  29640. sampleRate = newRate;
  29641. for (int i = voices.size(); --i >= 0;)
  29642. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29643. }
  29644. }
  29645. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29646. const MidiBuffer& midiData,
  29647. int startSample,
  29648. int numSamples)
  29649. {
  29650. // must set the sample rate before using this!
  29651. jassert (sampleRate != 0);
  29652. const ScopedLock sl (lock);
  29653. MidiBuffer::Iterator midiIterator (midiData);
  29654. midiIterator.setNextSamplePosition (startSample);
  29655. MidiMessage m (0xf4, 0.0);
  29656. while (numSamples > 0)
  29657. {
  29658. int midiEventPos;
  29659. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29660. && midiEventPos < startSample + numSamples;
  29661. const int numThisTime = useEvent ? midiEventPos - startSample
  29662. : numSamples;
  29663. if (numThisTime > 0)
  29664. {
  29665. for (int i = voices.size(); --i >= 0;)
  29666. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29667. }
  29668. if (useEvent)
  29669. {
  29670. if (m.isNoteOn())
  29671. {
  29672. const int channel = m.getChannel();
  29673. noteOn (channel,
  29674. m.getNoteNumber(),
  29675. m.getFloatVelocity());
  29676. }
  29677. else if (m.isNoteOff())
  29678. {
  29679. noteOff (m.getChannel(),
  29680. m.getNoteNumber(),
  29681. true);
  29682. }
  29683. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29684. {
  29685. allNotesOff (m.getChannel(), true);
  29686. }
  29687. else if (m.isPitchWheel())
  29688. {
  29689. const int channel = m.getChannel();
  29690. const int wheelPos = m.getPitchWheelValue();
  29691. lastPitchWheelValues [channel - 1] = wheelPos;
  29692. handlePitchWheel (channel, wheelPos);
  29693. }
  29694. else if (m.isController())
  29695. {
  29696. handleController (m.getChannel(),
  29697. m.getControllerNumber(),
  29698. m.getControllerValue());
  29699. }
  29700. }
  29701. startSample += numThisTime;
  29702. numSamples -= numThisTime;
  29703. }
  29704. }
  29705. void Synthesiser::noteOn (const int midiChannel,
  29706. const int midiNoteNumber,
  29707. const float velocity)
  29708. {
  29709. const ScopedLock sl (lock);
  29710. for (int i = sounds.size(); --i >= 0;)
  29711. {
  29712. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29713. if (sound->appliesToNote (midiNoteNumber)
  29714. && sound->appliesToChannel (midiChannel))
  29715. {
  29716. startVoice (findFreeVoice (sound, shouldStealNotes),
  29717. sound, midiChannel, midiNoteNumber, velocity);
  29718. }
  29719. }
  29720. }
  29721. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29722. SynthesiserSound* const sound,
  29723. const int midiChannel,
  29724. const int midiNoteNumber,
  29725. const float velocity)
  29726. {
  29727. if (voice != 0 && sound != 0)
  29728. {
  29729. if (voice->currentlyPlayingSound != 0)
  29730. voice->stopNote (false);
  29731. voice->startNote (midiNoteNumber,
  29732. velocity,
  29733. sound,
  29734. lastPitchWheelValues [midiChannel - 1]);
  29735. voice->currentlyPlayingNote = midiNoteNumber;
  29736. voice->noteOnTime = ++lastNoteOnCounter;
  29737. voice->currentlyPlayingSound = sound;
  29738. }
  29739. }
  29740. void Synthesiser::noteOff (const int midiChannel,
  29741. const int midiNoteNumber,
  29742. const bool allowTailOff)
  29743. {
  29744. const ScopedLock sl (lock);
  29745. for (int i = voices.size(); --i >= 0;)
  29746. {
  29747. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29748. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29749. {
  29750. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29751. if (sound != 0
  29752. && sound->appliesToNote (midiNoteNumber)
  29753. && sound->appliesToChannel (midiChannel))
  29754. {
  29755. voice->stopNote (allowTailOff);
  29756. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29757. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29758. }
  29759. }
  29760. }
  29761. }
  29762. void Synthesiser::allNotesOff (const int midiChannel,
  29763. const bool allowTailOff)
  29764. {
  29765. const ScopedLock sl (lock);
  29766. for (int i = voices.size(); --i >= 0;)
  29767. {
  29768. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29769. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29770. voice->stopNote (allowTailOff);
  29771. }
  29772. }
  29773. void Synthesiser::handlePitchWheel (const int midiChannel,
  29774. const int wheelValue)
  29775. {
  29776. const ScopedLock sl (lock);
  29777. for (int i = voices.size(); --i >= 0;)
  29778. {
  29779. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29780. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29781. {
  29782. voice->pitchWheelMoved (wheelValue);
  29783. }
  29784. }
  29785. }
  29786. void Synthesiser::handleController (const int midiChannel,
  29787. const int controllerNumber,
  29788. const int controllerValue)
  29789. {
  29790. const ScopedLock sl (lock);
  29791. for (int i = voices.size(); --i >= 0;)
  29792. {
  29793. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29794. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29795. voice->controllerMoved (controllerNumber, controllerValue);
  29796. }
  29797. }
  29798. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29799. const bool stealIfNoneAvailable) const
  29800. {
  29801. const ScopedLock sl (lock);
  29802. for (int i = voices.size(); --i >= 0;)
  29803. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29804. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29805. return voices.getUnchecked (i);
  29806. if (stealIfNoneAvailable)
  29807. {
  29808. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29809. SynthesiserVoice* oldest = 0;
  29810. for (int i = voices.size(); --i >= 0;)
  29811. {
  29812. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29813. if (voice->canPlaySound (soundToPlay)
  29814. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29815. oldest = voice;
  29816. }
  29817. jassert (oldest != 0);
  29818. return oldest;
  29819. }
  29820. return 0;
  29821. }
  29822. END_JUCE_NAMESPACE
  29823. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29824. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29825. BEGIN_JUCE_NAMESPACE
  29826. ActionBroadcaster::ActionBroadcaster() throw()
  29827. {
  29828. // are you trying to create this object before or after juce has been intialised??
  29829. jassert (MessageManager::instance != 0);
  29830. }
  29831. ActionBroadcaster::~ActionBroadcaster()
  29832. {
  29833. // all event-based objects must be deleted BEFORE juce is shut down!
  29834. jassert (MessageManager::instance != 0);
  29835. }
  29836. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29837. {
  29838. actionListenerList.addActionListener (listener);
  29839. }
  29840. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29841. {
  29842. jassert (actionListenerList.isValidMessageListener());
  29843. if (actionListenerList.isValidMessageListener())
  29844. actionListenerList.removeActionListener (listener);
  29845. }
  29846. void ActionBroadcaster::removeAllActionListeners()
  29847. {
  29848. actionListenerList.removeAllActionListeners();
  29849. }
  29850. void ActionBroadcaster::sendActionMessage (const String& message) const
  29851. {
  29852. actionListenerList.sendActionMessage (message);
  29853. }
  29854. END_JUCE_NAMESPACE
  29855. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29856. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29857. BEGIN_JUCE_NAMESPACE
  29858. // special message of our own with a string in it
  29859. class ActionMessage : public Message
  29860. {
  29861. public:
  29862. const String message;
  29863. ActionMessage (const String& messageText,
  29864. void* const listener_) throw()
  29865. : message (messageText)
  29866. {
  29867. pointerParameter = listener_;
  29868. }
  29869. ~ActionMessage() throw()
  29870. {
  29871. }
  29872. private:
  29873. ActionMessage (const ActionMessage&);
  29874. ActionMessage& operator= (const ActionMessage&);
  29875. };
  29876. ActionListenerList::ActionListenerList() throw()
  29877. {
  29878. }
  29879. ActionListenerList::~ActionListenerList() throw()
  29880. {
  29881. }
  29882. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29883. {
  29884. const ScopedLock sl (actionListenerLock_);
  29885. jassert (listener != 0);
  29886. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29887. if (listener != 0)
  29888. actionListeners_.add (listener);
  29889. }
  29890. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29891. {
  29892. const ScopedLock sl (actionListenerLock_);
  29893. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29894. actionListeners_.removeValue (listener);
  29895. }
  29896. void ActionListenerList::removeAllActionListeners() throw()
  29897. {
  29898. const ScopedLock sl (actionListenerLock_);
  29899. actionListeners_.clear();
  29900. }
  29901. void ActionListenerList::sendActionMessage (const String& message) const
  29902. {
  29903. const ScopedLock sl (actionListenerLock_);
  29904. for (int i = actionListeners_.size(); --i >= 0;)
  29905. {
  29906. postMessage (new ActionMessage (message,
  29907. (ActionListener*) actionListeners_.getUnchecked(i)));
  29908. }
  29909. }
  29910. void ActionListenerList::handleMessage (const Message& message)
  29911. {
  29912. const ActionMessage& am = (const ActionMessage&) message;
  29913. if (actionListeners_.contains (am.pointerParameter))
  29914. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29915. }
  29916. END_JUCE_NAMESPACE
  29917. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29918. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29919. BEGIN_JUCE_NAMESPACE
  29920. AsyncUpdater::AsyncUpdater() throw()
  29921. : asyncMessagePending (false)
  29922. {
  29923. internalAsyncHandler.owner = this;
  29924. }
  29925. AsyncUpdater::~AsyncUpdater()
  29926. {
  29927. }
  29928. void AsyncUpdater::triggerAsyncUpdate() throw()
  29929. {
  29930. if (! asyncMessagePending)
  29931. {
  29932. asyncMessagePending = true;
  29933. internalAsyncHandler.postMessage (new Message());
  29934. }
  29935. }
  29936. void AsyncUpdater::cancelPendingUpdate() throw()
  29937. {
  29938. asyncMessagePending = false;
  29939. }
  29940. void AsyncUpdater::handleUpdateNowIfNeeded()
  29941. {
  29942. if (asyncMessagePending)
  29943. {
  29944. asyncMessagePending = false;
  29945. handleAsyncUpdate();
  29946. }
  29947. }
  29948. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29949. {
  29950. owner->handleUpdateNowIfNeeded();
  29951. }
  29952. END_JUCE_NAMESPACE
  29953. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29954. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29955. BEGIN_JUCE_NAMESPACE
  29956. ChangeBroadcaster::ChangeBroadcaster() throw()
  29957. {
  29958. // are you trying to create this object before or after juce has been intialised??
  29959. jassert (MessageManager::instance != 0);
  29960. }
  29961. ChangeBroadcaster::~ChangeBroadcaster()
  29962. {
  29963. // all event-based objects must be deleted BEFORE juce is shut down!
  29964. jassert (MessageManager::instance != 0);
  29965. }
  29966. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29967. {
  29968. changeListenerList.addChangeListener (listener);
  29969. }
  29970. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29971. {
  29972. jassert (changeListenerList.isValidMessageListener());
  29973. if (changeListenerList.isValidMessageListener())
  29974. changeListenerList.removeChangeListener (listener);
  29975. }
  29976. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29977. {
  29978. changeListenerList.removeAllChangeListeners();
  29979. }
  29980. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29981. {
  29982. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29983. }
  29984. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29985. {
  29986. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29987. }
  29988. void ChangeBroadcaster::dispatchPendingMessages()
  29989. {
  29990. changeListenerList.dispatchPendingMessages();
  29991. }
  29992. END_JUCE_NAMESPACE
  29993. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29994. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29995. BEGIN_JUCE_NAMESPACE
  29996. ChangeListenerList::ChangeListenerList() throw()
  29997. : lastChangedObject (0),
  29998. messagePending (false)
  29999. {
  30000. }
  30001. ChangeListenerList::~ChangeListenerList() throw()
  30002. {
  30003. }
  30004. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  30005. {
  30006. const ScopedLock sl (lock);
  30007. jassert (listener != 0);
  30008. if (listener != 0)
  30009. listeners.add (listener);
  30010. }
  30011. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  30012. {
  30013. const ScopedLock sl (lock);
  30014. listeners.removeValue (listener);
  30015. }
  30016. void ChangeListenerList::removeAllChangeListeners() throw()
  30017. {
  30018. const ScopedLock sl (lock);
  30019. listeners.clear();
  30020. }
  30021. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  30022. {
  30023. const ScopedLock sl (lock);
  30024. if ((! messagePending) && (listeners.size() > 0))
  30025. {
  30026. lastChangedObject = objectThatHasChanged;
  30027. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  30028. messagePending = true;
  30029. }
  30030. }
  30031. void ChangeListenerList::handleMessage (const Message& message)
  30032. {
  30033. sendSynchronousChangeMessage (message.pointerParameter);
  30034. }
  30035. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  30036. {
  30037. const ScopedLock sl (lock);
  30038. messagePending = false;
  30039. for (int i = listeners.size(); --i >= 0;)
  30040. {
  30041. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  30042. {
  30043. const ScopedUnlock tempUnlocker (lock);
  30044. l->changeListenerCallback (objectThatHasChanged);
  30045. }
  30046. i = jmin (i, listeners.size());
  30047. }
  30048. }
  30049. void ChangeListenerList::dispatchPendingMessages()
  30050. {
  30051. if (messagePending)
  30052. sendSynchronousChangeMessage (lastChangedObject);
  30053. }
  30054. END_JUCE_NAMESPACE
  30055. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  30056. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  30057. BEGIN_JUCE_NAMESPACE
  30058. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  30059. const uint32 magicMessageHeaderNumber)
  30060. : Thread ("Juce IPC connection"),
  30061. callbackConnectionState (false),
  30062. useMessageThread (callbacksOnMessageThread),
  30063. magicMessageHeader (magicMessageHeaderNumber),
  30064. pipeReceiveMessageTimeout (-1)
  30065. {
  30066. }
  30067. InterprocessConnection::~InterprocessConnection()
  30068. {
  30069. callbackConnectionState = false;
  30070. disconnect();
  30071. }
  30072. bool InterprocessConnection::connectToSocket (const String& hostName,
  30073. const int portNumber,
  30074. const int timeOutMillisecs)
  30075. {
  30076. disconnect();
  30077. const ScopedLock sl (pipeAndSocketLock);
  30078. socket = new StreamingSocket();
  30079. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  30080. {
  30081. connectionMadeInt();
  30082. startThread();
  30083. return true;
  30084. }
  30085. else
  30086. {
  30087. socket = 0;
  30088. return false;
  30089. }
  30090. }
  30091. bool InterprocessConnection::connectToPipe (const String& pipeName,
  30092. const int pipeReceiveMessageTimeoutMs)
  30093. {
  30094. disconnect();
  30095. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30096. if (newPipe->openExisting (pipeName))
  30097. {
  30098. const ScopedLock sl (pipeAndSocketLock);
  30099. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30100. initialiseWithPipe (newPipe.release());
  30101. return true;
  30102. }
  30103. return false;
  30104. }
  30105. bool InterprocessConnection::createPipe (const String& pipeName,
  30106. const int pipeReceiveMessageTimeoutMs)
  30107. {
  30108. disconnect();
  30109. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30110. if (newPipe->createNewPipe (pipeName))
  30111. {
  30112. const ScopedLock sl (pipeAndSocketLock);
  30113. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30114. initialiseWithPipe (newPipe.release());
  30115. return true;
  30116. }
  30117. return false;
  30118. }
  30119. void InterprocessConnection::disconnect()
  30120. {
  30121. if (socket != 0)
  30122. socket->close();
  30123. if (pipe != 0)
  30124. {
  30125. pipe->cancelPendingReads();
  30126. pipe->close();
  30127. }
  30128. stopThread (4000);
  30129. {
  30130. const ScopedLock sl (pipeAndSocketLock);
  30131. socket = 0;
  30132. pipe = 0;
  30133. }
  30134. connectionLostInt();
  30135. }
  30136. bool InterprocessConnection::isConnected() const
  30137. {
  30138. const ScopedLock sl (pipeAndSocketLock);
  30139. return ((socket != 0 && socket->isConnected())
  30140. || (pipe != 0 && pipe->isOpen()))
  30141. && isThreadRunning();
  30142. }
  30143. const String InterprocessConnection::getConnectedHostName() const
  30144. {
  30145. if (pipe != 0)
  30146. {
  30147. return "localhost";
  30148. }
  30149. else if (socket != 0)
  30150. {
  30151. if (! socket->isLocal())
  30152. return socket->getHostName();
  30153. return "localhost";
  30154. }
  30155. return String::empty;
  30156. }
  30157. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30158. {
  30159. uint32 messageHeader[2];
  30160. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30161. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30162. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30163. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30164. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30165. size_t bytesWritten = 0;
  30166. const ScopedLock sl (pipeAndSocketLock);
  30167. if (socket != 0)
  30168. {
  30169. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30170. }
  30171. else if (pipe != 0)
  30172. {
  30173. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30174. }
  30175. if (bytesWritten < 0)
  30176. {
  30177. // error..
  30178. return false;
  30179. }
  30180. return (bytesWritten == messageData.getSize());
  30181. }
  30182. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30183. {
  30184. jassert (socket == 0);
  30185. socket = socket_;
  30186. connectionMadeInt();
  30187. startThread();
  30188. }
  30189. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30190. {
  30191. jassert (pipe == 0);
  30192. pipe = pipe_;
  30193. connectionMadeInt();
  30194. startThread();
  30195. }
  30196. const int messageMagicNumber = 0xb734128b;
  30197. void InterprocessConnection::handleMessage (const Message& message)
  30198. {
  30199. if (message.intParameter1 == messageMagicNumber)
  30200. {
  30201. switch (message.intParameter2)
  30202. {
  30203. case 0:
  30204. {
  30205. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30206. messageReceived (*data);
  30207. break;
  30208. }
  30209. case 1:
  30210. connectionMade();
  30211. break;
  30212. case 2:
  30213. connectionLost();
  30214. break;
  30215. }
  30216. }
  30217. }
  30218. void InterprocessConnection::connectionMadeInt()
  30219. {
  30220. if (! callbackConnectionState)
  30221. {
  30222. callbackConnectionState = true;
  30223. if (useMessageThread)
  30224. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30225. else
  30226. connectionMade();
  30227. }
  30228. }
  30229. void InterprocessConnection::connectionLostInt()
  30230. {
  30231. if (callbackConnectionState)
  30232. {
  30233. callbackConnectionState = false;
  30234. if (useMessageThread)
  30235. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30236. else
  30237. connectionLost();
  30238. }
  30239. }
  30240. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30241. {
  30242. jassert (callbackConnectionState);
  30243. if (useMessageThread)
  30244. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30245. else
  30246. messageReceived (data);
  30247. }
  30248. bool InterprocessConnection::readNextMessageInt()
  30249. {
  30250. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30251. uint32 messageHeader[2];
  30252. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30253. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30254. if (bytes == sizeof (messageHeader)
  30255. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30256. {
  30257. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30258. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30259. {
  30260. MemoryBlock messageData (bytesInMessage, true);
  30261. int bytesRead = 0;
  30262. while (bytesRead < bytesInMessage)
  30263. {
  30264. if (threadShouldExit())
  30265. return false;
  30266. const int numThisTime = jmin (bytesInMessage, 65536);
  30267. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30268. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30269. pipeReceiveMessageTimeout);
  30270. if (bytesIn <= 0)
  30271. break;
  30272. bytesRead += bytesIn;
  30273. }
  30274. if (bytesRead >= 0)
  30275. deliverDataInt (messageData);
  30276. }
  30277. }
  30278. else if (bytes < 0)
  30279. {
  30280. {
  30281. const ScopedLock sl (pipeAndSocketLock);
  30282. socket = 0;
  30283. }
  30284. connectionLostInt();
  30285. return false;
  30286. }
  30287. return true;
  30288. }
  30289. void InterprocessConnection::run()
  30290. {
  30291. while (! threadShouldExit())
  30292. {
  30293. if (socket != 0)
  30294. {
  30295. const int ready = socket->waitUntilReady (true, 0);
  30296. if (ready < 0)
  30297. {
  30298. {
  30299. const ScopedLock sl (pipeAndSocketLock);
  30300. socket = 0;
  30301. }
  30302. connectionLostInt();
  30303. break;
  30304. }
  30305. else if (ready > 0)
  30306. {
  30307. if (! readNextMessageInt())
  30308. break;
  30309. }
  30310. else
  30311. {
  30312. Thread::sleep (2);
  30313. }
  30314. }
  30315. else if (pipe != 0)
  30316. {
  30317. if (! pipe->isOpen())
  30318. {
  30319. {
  30320. const ScopedLock sl (pipeAndSocketLock);
  30321. pipe = 0;
  30322. }
  30323. connectionLostInt();
  30324. break;
  30325. }
  30326. else
  30327. {
  30328. if (! readNextMessageInt())
  30329. break;
  30330. }
  30331. }
  30332. else
  30333. {
  30334. break;
  30335. }
  30336. }
  30337. }
  30338. END_JUCE_NAMESPACE
  30339. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30340. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30341. BEGIN_JUCE_NAMESPACE
  30342. InterprocessConnectionServer::InterprocessConnectionServer()
  30343. : Thread ("Juce IPC server")
  30344. {
  30345. }
  30346. InterprocessConnectionServer::~InterprocessConnectionServer()
  30347. {
  30348. stop();
  30349. }
  30350. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30351. {
  30352. stop();
  30353. socket = new StreamingSocket();
  30354. if (socket->createListener (portNumber))
  30355. {
  30356. startThread();
  30357. return true;
  30358. }
  30359. socket = 0;
  30360. return false;
  30361. }
  30362. void InterprocessConnectionServer::stop()
  30363. {
  30364. signalThreadShouldExit();
  30365. if (socket != 0)
  30366. socket->close();
  30367. stopThread (4000);
  30368. socket = 0;
  30369. }
  30370. void InterprocessConnectionServer::run()
  30371. {
  30372. while ((! threadShouldExit()) && socket != 0)
  30373. {
  30374. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30375. if (clientSocket != 0)
  30376. {
  30377. InterprocessConnection* newConnection = createConnectionObject();
  30378. if (newConnection != 0)
  30379. newConnection->initialiseWithSocket (clientSocket.release());
  30380. }
  30381. }
  30382. }
  30383. END_JUCE_NAMESPACE
  30384. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30385. /*** Start of inlined file: juce_Message.cpp ***/
  30386. BEGIN_JUCE_NAMESPACE
  30387. Message::Message() throw()
  30388. {
  30389. }
  30390. Message::~Message() throw()
  30391. {
  30392. }
  30393. Message::Message (const int intParameter1_,
  30394. const int intParameter2_,
  30395. const int intParameter3_,
  30396. void* const pointerParameter_) throw()
  30397. : intParameter1 (intParameter1_),
  30398. intParameter2 (intParameter2_),
  30399. intParameter3 (intParameter3_),
  30400. pointerParameter (pointerParameter_)
  30401. {
  30402. }
  30403. END_JUCE_NAMESPACE
  30404. /*** End of inlined file: juce_Message.cpp ***/
  30405. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30406. BEGIN_JUCE_NAMESPACE
  30407. MessageListener::MessageListener() throw()
  30408. {
  30409. // are you trying to create a messagelistener before or after juce has been intialised??
  30410. jassert (MessageManager::instance != 0);
  30411. if (MessageManager::instance != 0)
  30412. MessageManager::instance->messageListeners.add (this);
  30413. }
  30414. MessageListener::~MessageListener()
  30415. {
  30416. if (MessageManager::instance != 0)
  30417. MessageManager::instance->messageListeners.removeValue (this);
  30418. }
  30419. void MessageListener::postMessage (Message* const message) const throw()
  30420. {
  30421. message->messageRecipient = const_cast <MessageListener*> (this);
  30422. if (MessageManager::instance == 0)
  30423. MessageManager::getInstance();
  30424. MessageManager::instance->postMessageToQueue (message);
  30425. }
  30426. bool MessageListener::isValidMessageListener() const throw()
  30427. {
  30428. return (MessageManager::instance != 0)
  30429. && MessageManager::instance->messageListeners.contains (this);
  30430. }
  30431. END_JUCE_NAMESPACE
  30432. /*** End of inlined file: juce_MessageListener.cpp ***/
  30433. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30434. BEGIN_JUCE_NAMESPACE
  30435. // platform-specific functions..
  30436. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30437. bool juce_postMessageToSystemQueue (void* message);
  30438. MessageManager* MessageManager::instance = 0;
  30439. static const int quitMessageId = 0xfffff321;
  30440. MessageManager::MessageManager() throw()
  30441. : quitMessagePosted (false),
  30442. quitMessageReceived (false),
  30443. threadWithLock (0)
  30444. {
  30445. messageThreadId = Thread::getCurrentThreadId();
  30446. }
  30447. MessageManager::~MessageManager() throw()
  30448. {
  30449. broadcastListeners = 0;
  30450. doPlatformSpecificShutdown();
  30451. jassert (instance == this);
  30452. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30453. }
  30454. MessageManager* MessageManager::getInstance() throw()
  30455. {
  30456. if (instance == 0)
  30457. {
  30458. instance = new MessageManager();
  30459. doPlatformSpecificInitialisation();
  30460. }
  30461. return instance;
  30462. }
  30463. void MessageManager::postMessageToQueue (Message* const message)
  30464. {
  30465. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30466. delete message;
  30467. }
  30468. CallbackMessage::CallbackMessage() throw() {}
  30469. CallbackMessage::~CallbackMessage() throw() {}
  30470. void CallbackMessage::post()
  30471. {
  30472. if (MessageManager::instance != 0)
  30473. MessageManager::instance->postCallbackMessage (this);
  30474. }
  30475. void MessageManager::postCallbackMessage (Message* const message)
  30476. {
  30477. message->messageRecipient = 0;
  30478. postMessageToQueue (message);
  30479. }
  30480. // not for public use..
  30481. void MessageManager::deliverMessage (void* message)
  30482. {
  30483. const ScopedPointer <Message> m ((Message*) message);
  30484. MessageListener* const recipient = m->messageRecipient;
  30485. JUCE_TRY
  30486. {
  30487. if (messageListeners.contains (recipient))
  30488. {
  30489. recipient->handleMessage (*m);
  30490. }
  30491. else if (recipient == 0)
  30492. {
  30493. if (m->intParameter1 == quitMessageId)
  30494. {
  30495. quitMessageReceived = true;
  30496. }
  30497. else
  30498. {
  30499. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30500. if (cm != 0)
  30501. cm->messageCallback();
  30502. }
  30503. }
  30504. }
  30505. JUCE_CATCH_EXCEPTION
  30506. }
  30507. #if ! (JUCE_MAC || JUCE_IPHONE)
  30508. void MessageManager::runDispatchLoop()
  30509. {
  30510. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30511. runDispatchLoopUntil (-1);
  30512. }
  30513. void MessageManager::stopDispatchLoop()
  30514. {
  30515. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30516. m->messageRecipient = 0;
  30517. postMessageToQueue (m);
  30518. quitMessagePosted = true;
  30519. }
  30520. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30521. {
  30522. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30523. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30524. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30525. && ! quitMessageReceived)
  30526. {
  30527. JUCE_TRY
  30528. {
  30529. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30530. {
  30531. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30532. if (msToWait > 0)
  30533. Thread::sleep (jmin (5, msToWait));
  30534. }
  30535. }
  30536. JUCE_CATCH_EXCEPTION
  30537. }
  30538. return ! quitMessageReceived;
  30539. }
  30540. #endif
  30541. void MessageManager::deliverBroadcastMessage (const String& value)
  30542. {
  30543. if (broadcastListeners != 0)
  30544. broadcastListeners->sendActionMessage (value);
  30545. }
  30546. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30547. {
  30548. if (broadcastListeners == 0)
  30549. broadcastListeners = new ActionListenerList();
  30550. broadcastListeners->addActionListener (listener);
  30551. }
  30552. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30553. {
  30554. if (broadcastListeners != 0)
  30555. broadcastListeners->removeActionListener (listener);
  30556. }
  30557. bool MessageManager::isThisTheMessageThread() const throw()
  30558. {
  30559. return Thread::getCurrentThreadId() == messageThreadId;
  30560. }
  30561. void MessageManager::setCurrentThreadAsMessageThread()
  30562. {
  30563. if (messageThreadId != Thread::getCurrentThreadId())
  30564. {
  30565. messageThreadId = Thread::getCurrentThreadId();
  30566. // This is needed on windows to make sure the message window is created by this thread
  30567. doPlatformSpecificShutdown();
  30568. doPlatformSpecificInitialisation();
  30569. }
  30570. }
  30571. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30572. {
  30573. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30574. return thisThread == messageThreadId || thisThread == threadWithLock;
  30575. }
  30576. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30577. {
  30578. public:
  30579. SharedEvents() {}
  30580. ~SharedEvents() {}
  30581. WaitableEvent lockedEvent, releaseEvent;
  30582. private:
  30583. SharedEvents (const SharedEvents&);
  30584. SharedEvents& operator= (const SharedEvents&);
  30585. };
  30586. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30587. {
  30588. public:
  30589. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30590. ~BlockingMessage() throw() {}
  30591. void messageCallback()
  30592. {
  30593. events->lockedEvent.signal();
  30594. events->releaseEvent.wait();
  30595. }
  30596. juce_UseDebuggingNewOperator
  30597. private:
  30598. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30599. BlockingMessage (const BlockingMessage&);
  30600. BlockingMessage& operator= (const BlockingMessage&);
  30601. };
  30602. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30603. : sharedEvents (0),
  30604. locked (false)
  30605. {
  30606. init (threadToCheck, 0);
  30607. }
  30608. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30609. : sharedEvents (0),
  30610. locked (false)
  30611. {
  30612. init (0, jobToCheckForExitSignal);
  30613. }
  30614. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30615. {
  30616. if (MessageManager::instance != 0)
  30617. {
  30618. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30619. {
  30620. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30621. }
  30622. else
  30623. {
  30624. if (threadToCheck == 0 && job == 0)
  30625. {
  30626. MessageManager::instance->lockingLock.enter();
  30627. }
  30628. else
  30629. {
  30630. while (! MessageManager::instance->lockingLock.tryEnter())
  30631. {
  30632. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30633. || (job != 0 && job->shouldExit()))
  30634. return;
  30635. Thread::sleep (1);
  30636. }
  30637. }
  30638. sharedEvents = new SharedEvents();
  30639. sharedEvents->incReferenceCount();
  30640. (new BlockingMessage (sharedEvents))->post();
  30641. while (! sharedEvents->lockedEvent.wait (50))
  30642. {
  30643. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30644. || (job != 0 && job->shouldExit()))
  30645. {
  30646. sharedEvents->releaseEvent.signal();
  30647. sharedEvents->decReferenceCount();
  30648. sharedEvents = 0;
  30649. MessageManager::instance->lockingLock.exit();
  30650. return;
  30651. }
  30652. }
  30653. jassert (MessageManager::instance->threadWithLock == 0);
  30654. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30655. locked = true;
  30656. }
  30657. }
  30658. }
  30659. MessageManagerLock::~MessageManagerLock() throw()
  30660. {
  30661. if (sharedEvents != 0)
  30662. {
  30663. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30664. sharedEvents->releaseEvent.signal();
  30665. sharedEvents->decReferenceCount();
  30666. if (MessageManager::instance != 0)
  30667. {
  30668. MessageManager::instance->threadWithLock = 0;
  30669. MessageManager::instance->lockingLock.exit();
  30670. }
  30671. }
  30672. }
  30673. END_JUCE_NAMESPACE
  30674. /*** End of inlined file: juce_MessageManager.cpp ***/
  30675. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30676. BEGIN_JUCE_NAMESPACE
  30677. class MultiTimer::MultiTimerCallback : public Timer
  30678. {
  30679. public:
  30680. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30681. : timerId (timerId_),
  30682. owner (owner_)
  30683. {
  30684. }
  30685. ~MultiTimerCallback()
  30686. {
  30687. }
  30688. void timerCallback()
  30689. {
  30690. owner.timerCallback (timerId);
  30691. }
  30692. const int timerId;
  30693. private:
  30694. MultiTimer& owner;
  30695. };
  30696. MultiTimer::MultiTimer() throw()
  30697. {
  30698. }
  30699. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30700. {
  30701. }
  30702. MultiTimer::~MultiTimer()
  30703. {
  30704. const ScopedLock sl (timerListLock);
  30705. timers.clear();
  30706. }
  30707. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30708. {
  30709. const ScopedLock sl (timerListLock);
  30710. for (int i = timers.size(); --i >= 0;)
  30711. {
  30712. MultiTimerCallback* const t = timers.getUnchecked(i);
  30713. if (t->timerId == timerId)
  30714. {
  30715. t->startTimer (intervalInMilliseconds);
  30716. return;
  30717. }
  30718. }
  30719. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30720. timers.add (newTimer);
  30721. newTimer->startTimer (intervalInMilliseconds);
  30722. }
  30723. void MultiTimer::stopTimer (const int timerId) throw()
  30724. {
  30725. const ScopedLock sl (timerListLock);
  30726. for (int i = timers.size(); --i >= 0;)
  30727. {
  30728. MultiTimerCallback* const t = timers.getUnchecked(i);
  30729. if (t->timerId == timerId)
  30730. t->stopTimer();
  30731. }
  30732. }
  30733. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30734. {
  30735. const ScopedLock sl (timerListLock);
  30736. for (int i = timers.size(); --i >= 0;)
  30737. {
  30738. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30739. if (t->timerId == timerId)
  30740. return t->isTimerRunning();
  30741. }
  30742. return false;
  30743. }
  30744. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30745. {
  30746. const ScopedLock sl (timerListLock);
  30747. for (int i = timers.size(); --i >= 0;)
  30748. {
  30749. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30750. if (t->timerId == timerId)
  30751. return t->getTimerInterval();
  30752. }
  30753. return 0;
  30754. }
  30755. END_JUCE_NAMESPACE
  30756. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30757. /*** Start of inlined file: juce_Timer.cpp ***/
  30758. BEGIN_JUCE_NAMESPACE
  30759. class InternalTimerThread : private Thread,
  30760. private MessageListener,
  30761. private DeletedAtShutdown,
  30762. private AsyncUpdater
  30763. {
  30764. public:
  30765. InternalTimerThread()
  30766. : Thread ("Juce Timer"),
  30767. firstTimer (0),
  30768. callbackNeeded (false)
  30769. {
  30770. triggerAsyncUpdate();
  30771. }
  30772. ~InternalTimerThread() throw()
  30773. {
  30774. stopThread (4000);
  30775. jassert (instance == this || instance == 0);
  30776. if (instance == this)
  30777. instance = 0;
  30778. }
  30779. void run()
  30780. {
  30781. uint32 lastTime = Time::getMillisecondCounter();
  30782. while (! threadShouldExit())
  30783. {
  30784. const uint32 now = Time::getMillisecondCounter();
  30785. if (now <= lastTime)
  30786. {
  30787. wait (2);
  30788. continue;
  30789. }
  30790. const int elapsed = now - lastTime;
  30791. lastTime = now;
  30792. int timeUntilFirstTimer = 1000;
  30793. {
  30794. const ScopedLock sl (lock);
  30795. decrementAllCounters (elapsed);
  30796. if (firstTimer != 0)
  30797. timeUntilFirstTimer = firstTimer->countdownMs;
  30798. }
  30799. if (timeUntilFirstTimer <= 0)
  30800. {
  30801. if (callbackNeeded.set (true))
  30802. {
  30803. postMessage (new Message());
  30804. const uint32 messageDeliveryTimeout = now + 2000;
  30805. while (callbackNeeded.get())
  30806. {
  30807. wait (4);
  30808. if (threadShouldExit())
  30809. return;
  30810. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30811. break;
  30812. }
  30813. }
  30814. }
  30815. else
  30816. {
  30817. // don't wait for too long because running this loop also helps keep the
  30818. // Time::getApproximateMillisecondTimer value stay up-to-date
  30819. wait (jlimit (1, 50, timeUntilFirstTimer));
  30820. }
  30821. }
  30822. }
  30823. void callTimers()
  30824. {
  30825. const ScopedLock sl (lock);
  30826. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30827. {
  30828. Timer* const t = firstTimer;
  30829. t->countdownMs = t->periodMs;
  30830. removeTimer (t);
  30831. addTimer (t);
  30832. const ScopedUnlock ul (lock);
  30833. JUCE_TRY
  30834. {
  30835. t->timerCallback();
  30836. }
  30837. JUCE_CATCH_EXCEPTION
  30838. }
  30839. callbackNeeded.set (false);
  30840. }
  30841. void handleMessage (const Message&)
  30842. {
  30843. callTimers();
  30844. }
  30845. void callTimersSynchronously()
  30846. {
  30847. if (! isThreadRunning())
  30848. {
  30849. // (This is relied on by some plugins in cases where the MM has
  30850. // had to restart and the async callback never started)
  30851. cancelPendingUpdate();
  30852. triggerAsyncUpdate();
  30853. }
  30854. callTimers();
  30855. }
  30856. static void callAnyTimersSynchronously()
  30857. {
  30858. if (InternalTimerThread::instance != 0)
  30859. InternalTimerThread::instance->callTimersSynchronously();
  30860. }
  30861. static inline void add (Timer* const tim) throw()
  30862. {
  30863. if (instance == 0)
  30864. instance = new InternalTimerThread();
  30865. const ScopedLock sl (instance->lock);
  30866. instance->addTimer (tim);
  30867. }
  30868. static inline void remove (Timer* const tim) throw()
  30869. {
  30870. if (instance != 0)
  30871. {
  30872. const ScopedLock sl (instance->lock);
  30873. instance->removeTimer (tim);
  30874. }
  30875. }
  30876. static inline void resetCounter (Timer* const tim,
  30877. const int newCounter) throw()
  30878. {
  30879. if (instance != 0)
  30880. {
  30881. tim->countdownMs = newCounter;
  30882. tim->periodMs = newCounter;
  30883. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30884. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30885. {
  30886. const ScopedLock sl (instance->lock);
  30887. instance->removeTimer (tim);
  30888. instance->addTimer (tim);
  30889. }
  30890. }
  30891. }
  30892. private:
  30893. friend class Timer;
  30894. static InternalTimerThread* instance;
  30895. static CriticalSection lock;
  30896. Timer* volatile firstTimer;
  30897. class AtomicBool
  30898. {
  30899. public:
  30900. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30901. ~AtomicBool() throw() {}
  30902. bool get() const throw() { return value != 0; }
  30903. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30904. private:
  30905. int32 value;
  30906. AtomicBool (const AtomicBool&);
  30907. AtomicBool& operator= (const AtomicBool&);
  30908. };
  30909. AtomicBool callbackNeeded;
  30910. void addTimer (Timer* const t) throw()
  30911. {
  30912. #ifdef JUCE_DEBUG
  30913. Timer* tt = firstTimer;
  30914. while (tt != 0)
  30915. {
  30916. // trying to add a timer that's already here - shouldn't get to this point,
  30917. // so if you get this assertion, let me know!
  30918. jassert (tt != t);
  30919. tt = tt->next;
  30920. }
  30921. jassert (t->previous == 0 && t->next == 0);
  30922. #endif
  30923. Timer* i = firstTimer;
  30924. if (i == 0 || i->countdownMs > t->countdownMs)
  30925. {
  30926. t->next = firstTimer;
  30927. firstTimer = t;
  30928. }
  30929. else
  30930. {
  30931. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30932. i = i->next;
  30933. jassert (i != 0);
  30934. t->next = i->next;
  30935. t->previous = i;
  30936. i->next = t;
  30937. }
  30938. if (t->next != 0)
  30939. t->next->previous = t;
  30940. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30941. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30942. notify();
  30943. }
  30944. void removeTimer (Timer* const t) throw()
  30945. {
  30946. #ifdef JUCE_DEBUG
  30947. Timer* tt = firstTimer;
  30948. bool found = false;
  30949. while (tt != 0)
  30950. {
  30951. if (tt == t)
  30952. {
  30953. found = true;
  30954. break;
  30955. }
  30956. tt = tt->next;
  30957. }
  30958. // trying to remove a timer that's not here - shouldn't get to this point,
  30959. // so if you get this assertion, let me know!
  30960. jassert (found);
  30961. #endif
  30962. if (t->previous != 0)
  30963. {
  30964. jassert (firstTimer != t);
  30965. t->previous->next = t->next;
  30966. }
  30967. else
  30968. {
  30969. jassert (firstTimer == t);
  30970. firstTimer = t->next;
  30971. }
  30972. if (t->next != 0)
  30973. t->next->previous = t->previous;
  30974. t->next = 0;
  30975. t->previous = 0;
  30976. }
  30977. void decrementAllCounters (const int numMillisecs) const
  30978. {
  30979. Timer* t = firstTimer;
  30980. while (t != 0)
  30981. {
  30982. t->countdownMs -= numMillisecs;
  30983. t = t->next;
  30984. }
  30985. }
  30986. void handleAsyncUpdate()
  30987. {
  30988. startThread (7);
  30989. }
  30990. InternalTimerThread (const InternalTimerThread&);
  30991. InternalTimerThread& operator= (const InternalTimerThread&);
  30992. };
  30993. InternalTimerThread* InternalTimerThread::instance = 0;
  30994. CriticalSection InternalTimerThread::lock;
  30995. void juce_callAnyTimersSynchronously()
  30996. {
  30997. InternalTimerThread::callAnyTimersSynchronously();
  30998. }
  30999. #ifdef JUCE_DEBUG
  31000. static SortedSet <Timer*> activeTimers;
  31001. #endif
  31002. Timer::Timer() throw()
  31003. : countdownMs (0),
  31004. periodMs (0),
  31005. previous (0),
  31006. next (0)
  31007. {
  31008. #ifdef JUCE_DEBUG
  31009. activeTimers.add (this);
  31010. #endif
  31011. }
  31012. Timer::Timer (const Timer&) throw()
  31013. : countdownMs (0),
  31014. periodMs (0),
  31015. previous (0),
  31016. next (0)
  31017. {
  31018. #ifdef JUCE_DEBUG
  31019. activeTimers.add (this);
  31020. #endif
  31021. }
  31022. Timer::~Timer()
  31023. {
  31024. stopTimer();
  31025. #ifdef JUCE_DEBUG
  31026. activeTimers.removeValue (this);
  31027. #endif
  31028. }
  31029. void Timer::startTimer (const int interval) throw()
  31030. {
  31031. const ScopedLock sl (InternalTimerThread::lock);
  31032. #ifdef JUCE_DEBUG
  31033. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31034. jassert (activeTimers.contains (this));
  31035. #endif
  31036. if (periodMs == 0)
  31037. {
  31038. countdownMs = interval;
  31039. periodMs = jmax (1, interval);
  31040. InternalTimerThread::add (this);
  31041. }
  31042. else
  31043. {
  31044. InternalTimerThread::resetCounter (this, interval);
  31045. }
  31046. }
  31047. void Timer::stopTimer() throw()
  31048. {
  31049. const ScopedLock sl (InternalTimerThread::lock);
  31050. #ifdef JUCE_DEBUG
  31051. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31052. jassert (activeTimers.contains (this));
  31053. #endif
  31054. if (periodMs > 0)
  31055. {
  31056. InternalTimerThread::remove (this);
  31057. periodMs = 0;
  31058. }
  31059. }
  31060. END_JUCE_NAMESPACE
  31061. /*** End of inlined file: juce_Timer.cpp ***/
  31062. #endif
  31063. #if JUCE_BUILD_GUI
  31064. /*** Start of inlined file: juce_Component.cpp ***/
  31065. BEGIN_JUCE_NAMESPACE
  31066. Component* Component::componentUnderMouse = 0;
  31067. Component* Component::currentlyFocusedComponent = 0;
  31068. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  31069. static Array <int> modalReturnValues;
  31070. static const int customCommandMessage = 0x7fff0001;
  31071. static const int exitModalStateMessage = 0x7fff0002;
  31072. static Point<int> unboundedMouseOffset;
  31073. static bool isUnboundedMouseModeOn = false;
  31074. static bool isCursorVisibleUntilOffscreen;
  31075. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31076. static uint32 nextComponentUID = 0;
  31077. Component::Component() throw()
  31078. : parentComponent_ (0),
  31079. componentUID (++nextComponentUID),
  31080. numDeepMouseListeners (0),
  31081. lookAndFeel_ (0),
  31082. effect_ (0),
  31083. bufferedImage_ (0),
  31084. mouseListeners_ (0),
  31085. keyListeners_ (0),
  31086. componentListeners_ (0),
  31087. componentFlags_ (0)
  31088. {
  31089. }
  31090. Component::Component (const String& name) throw()
  31091. : componentName_ (name),
  31092. parentComponent_ (0),
  31093. componentUID (++nextComponentUID),
  31094. numDeepMouseListeners (0),
  31095. lookAndFeel_ (0),
  31096. effect_ (0),
  31097. bufferedImage_ (0),
  31098. mouseListeners_ (0),
  31099. keyListeners_ (0),
  31100. componentListeners_ (0),
  31101. componentFlags_ (0)
  31102. {
  31103. }
  31104. Component::~Component()
  31105. {
  31106. if (parentComponent_ != 0)
  31107. {
  31108. parentComponent_->removeChildComponent (this);
  31109. }
  31110. else if ((currentlyFocusedComponent == this)
  31111. || isParentOf (currentlyFocusedComponent))
  31112. {
  31113. giveAwayFocus();
  31114. }
  31115. if (componentUnderMouse == this)
  31116. componentUnderMouse = 0;
  31117. if (flags.hasHeavyweightPeerFlag)
  31118. removeFromDesktop();
  31119. modalComponentStack.removeValue (this);
  31120. for (int i = childComponentList_.size(); --i >= 0;)
  31121. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31122. delete bufferedImage_;
  31123. delete mouseListeners_;
  31124. delete keyListeners_;
  31125. delete componentListeners_;
  31126. }
  31127. void Component::setName (const String& name)
  31128. {
  31129. // if component methods are being called from threads other than the message
  31130. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31131. checkMessageManagerIsLocked
  31132. if (componentName_ != name)
  31133. {
  31134. componentName_ = name;
  31135. if (flags.hasHeavyweightPeerFlag)
  31136. {
  31137. ComponentPeer* const peer = getPeer();
  31138. jassert (peer != 0);
  31139. if (peer != 0)
  31140. peer->setTitle (name);
  31141. }
  31142. if (componentListeners_ != 0)
  31143. {
  31144. const ComponentDeletionWatcher deletionChecker (this);
  31145. for (int i = componentListeners_->size(); --i >= 0;)
  31146. {
  31147. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31148. ->componentNameChanged (*this);
  31149. if (deletionChecker.hasBeenDeleted())
  31150. return;
  31151. i = jmin (i, componentListeners_->size());
  31152. }
  31153. }
  31154. }
  31155. }
  31156. void Component::setVisible (bool shouldBeVisible)
  31157. {
  31158. if (flags.visibleFlag != shouldBeVisible)
  31159. {
  31160. // if component methods are being called from threads other than the message
  31161. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31162. checkMessageManagerIsLocked
  31163. const ComponentDeletionWatcher deletionChecker (this);
  31164. flags.visibleFlag = shouldBeVisible;
  31165. internalRepaint (0, 0, getWidth(), getHeight());
  31166. sendFakeMouseMove();
  31167. if (! shouldBeVisible)
  31168. {
  31169. if (currentlyFocusedComponent == this
  31170. || isParentOf (currentlyFocusedComponent))
  31171. {
  31172. if (parentComponent_ != 0)
  31173. parentComponent_->grabKeyboardFocus();
  31174. else
  31175. giveAwayFocus();
  31176. }
  31177. }
  31178. sendVisibilityChangeMessage();
  31179. if ((! deletionChecker.hasBeenDeleted()) && flags.hasHeavyweightPeerFlag)
  31180. {
  31181. ComponentPeer* const peer = getPeer();
  31182. jassert (peer != 0);
  31183. if (peer != 0)
  31184. {
  31185. peer->setVisible (shouldBeVisible);
  31186. internalHierarchyChanged();
  31187. }
  31188. }
  31189. }
  31190. }
  31191. void Component::visibilityChanged()
  31192. {
  31193. }
  31194. void Component::sendVisibilityChangeMessage()
  31195. {
  31196. const ComponentDeletionWatcher deletionChecker (this);
  31197. visibilityChanged();
  31198. if ((! deletionChecker.hasBeenDeleted()) && componentListeners_ != 0)
  31199. {
  31200. for (int i = componentListeners_->size(); --i >= 0;)
  31201. {
  31202. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31203. ->componentVisibilityChanged (*this);
  31204. if (deletionChecker.hasBeenDeleted())
  31205. return;
  31206. i = jmin (i, componentListeners_->size());
  31207. }
  31208. }
  31209. }
  31210. bool Component::isShowing() const throw()
  31211. {
  31212. if (flags.visibleFlag)
  31213. {
  31214. if (parentComponent_ != 0)
  31215. {
  31216. return parentComponent_->isShowing();
  31217. }
  31218. else
  31219. {
  31220. const ComponentPeer* const peer = getPeer();
  31221. return peer != 0 && ! peer->isMinimised();
  31222. }
  31223. }
  31224. return false;
  31225. }
  31226. class FadeOutProxyComponent : public Component,
  31227. public Timer
  31228. {
  31229. public:
  31230. FadeOutProxyComponent (Component* comp,
  31231. const int fadeLengthMs,
  31232. const int deltaXToMove,
  31233. const int deltaYToMove,
  31234. const float scaleFactorAtEnd)
  31235. : lastTime (0),
  31236. alpha (1.0f),
  31237. scale (1.0f)
  31238. {
  31239. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31240. setBounds (comp->getBounds());
  31241. comp->getParentComponent()->addAndMakeVisible (this);
  31242. toBehind (comp);
  31243. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31244. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31245. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31246. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31247. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31248. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31249. setInterceptsMouseClicks (false, false);
  31250. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31251. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31252. }
  31253. ~FadeOutProxyComponent()
  31254. {
  31255. delete image;
  31256. }
  31257. void paint (Graphics& g)
  31258. {
  31259. g.setOpacity (alpha);
  31260. g.drawImage (image,
  31261. 0, 0, getWidth(), getHeight(),
  31262. 0, 0, image->getWidth(), image->getHeight());
  31263. }
  31264. void timerCallback()
  31265. {
  31266. const uint32 now = Time::getMillisecondCounter();
  31267. if (lastTime == 0)
  31268. lastTime = now;
  31269. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31270. lastTime = now;
  31271. alpha += alphaChangePerMs * msPassed;
  31272. if (alpha > 0)
  31273. {
  31274. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31275. {
  31276. centreX += xChangePerMs * msPassed;
  31277. centreY += yChangePerMs * msPassed;
  31278. scale += scaleChangePerMs * msPassed;
  31279. const int w = roundToInt (image->getWidth() * scale);
  31280. const int h = roundToInt (image->getHeight() * scale);
  31281. setBounds (roundToInt (centreX) - w / 2,
  31282. roundToInt (centreY) - h / 2,
  31283. w, h);
  31284. }
  31285. repaint();
  31286. }
  31287. else
  31288. {
  31289. delete this;
  31290. }
  31291. }
  31292. juce_UseDebuggingNewOperator
  31293. private:
  31294. Image* image;
  31295. uint32 lastTime;
  31296. float alpha, alphaChangePerMs;
  31297. float centreX, xChangePerMs;
  31298. float centreY, yChangePerMs;
  31299. float scale, scaleChangePerMs;
  31300. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31301. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31302. };
  31303. void Component::fadeOutComponent (const int millisecondsToFade,
  31304. const int deltaXToMove,
  31305. const int deltaYToMove,
  31306. const float scaleFactorAtEnd)
  31307. {
  31308. //xxx won't work for comps without parents
  31309. if (isShowing() && millisecondsToFade > 0)
  31310. new FadeOutProxyComponent (this, millisecondsToFade,
  31311. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31312. setVisible (false);
  31313. }
  31314. bool Component::isValidComponent() const throw()
  31315. {
  31316. return (this != 0) && isValidMessageListener();
  31317. }
  31318. void* Component::getWindowHandle() const throw()
  31319. {
  31320. const ComponentPeer* const peer = getPeer();
  31321. if (peer != 0)
  31322. return peer->getNativeHandle();
  31323. return 0;
  31324. }
  31325. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31326. {
  31327. // if component methods are being called from threads other than the message
  31328. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31329. checkMessageManagerIsLocked
  31330. if (isOpaque())
  31331. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31332. else
  31333. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31334. int currentStyleFlags = 0;
  31335. // don't use getPeer(), so that we only get the peer that's specifically
  31336. // for this comp, and not for one of its parents.
  31337. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31338. if (peer != 0)
  31339. currentStyleFlags = peer->getStyleFlags();
  31340. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31341. {
  31342. const ComponentDeletionWatcher deletionChecker (this);
  31343. #if JUCE_LINUX
  31344. // it's wise to give the component a non-zero size before
  31345. // putting it on the desktop, as X windows get confused by this, and
  31346. // a (1, 1) minimum size is enforced here.
  31347. setSize (jmax (1, getWidth()),
  31348. jmax (1, getHeight()));
  31349. #endif
  31350. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31351. bool wasFullscreen = false;
  31352. bool wasMinimised = false;
  31353. ComponentBoundsConstrainer* currentConstainer = 0;
  31354. Rectangle<int> oldNonFullScreenBounds;
  31355. if (peer != 0)
  31356. {
  31357. wasFullscreen = peer->isFullScreen();
  31358. wasMinimised = peer->isMinimised();
  31359. currentConstainer = peer->getConstrainer();
  31360. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31361. removeFromDesktop();
  31362. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31363. }
  31364. if (parentComponent_ != 0)
  31365. parentComponent_->removeChildComponent (this);
  31366. if (! deletionChecker.hasBeenDeleted())
  31367. {
  31368. flags.hasHeavyweightPeerFlag = true;
  31369. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31370. Desktop::getInstance().addDesktopComponent (this);
  31371. bounds_.setPosition (topLeft);
  31372. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31373. peer->setVisible (isVisible());
  31374. if (wasFullscreen)
  31375. {
  31376. peer->setFullScreen (true);
  31377. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31378. }
  31379. if (wasMinimised)
  31380. peer->setMinimised (true);
  31381. if (isAlwaysOnTop())
  31382. peer->setAlwaysOnTop (true);
  31383. peer->setConstrainer (currentConstainer);
  31384. repaint();
  31385. }
  31386. internalHierarchyChanged();
  31387. }
  31388. }
  31389. void Component::removeFromDesktop()
  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 (flags.hasHeavyweightPeerFlag)
  31395. {
  31396. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31397. flags.hasHeavyweightPeerFlag = false;
  31398. jassert (peer != 0);
  31399. delete peer;
  31400. Desktop::getInstance().removeDesktopComponent (this);
  31401. }
  31402. }
  31403. bool Component::isOnDesktop() const throw()
  31404. {
  31405. return flags.hasHeavyweightPeerFlag;
  31406. }
  31407. void Component::userTriedToCloseWindow()
  31408. {
  31409. /* This means that the user's trying to get rid of your window with the 'close window' system
  31410. menu option (on windows) or possibly the task manager - you should really handle this
  31411. and delete or hide your component in an appropriate way.
  31412. If you want to ignore the event and don't want to trigger this assertion, just override
  31413. this method and do nothing.
  31414. */
  31415. jassertfalse
  31416. }
  31417. void Component::minimisationStateChanged (bool)
  31418. {
  31419. }
  31420. void Component::setOpaque (const bool shouldBeOpaque) throw()
  31421. {
  31422. if (shouldBeOpaque != flags.opaqueFlag)
  31423. {
  31424. flags.opaqueFlag = shouldBeOpaque;
  31425. if (flags.hasHeavyweightPeerFlag)
  31426. {
  31427. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31428. if (peer != 0)
  31429. {
  31430. // to make it recreate the heavyweight window
  31431. addToDesktop (peer->getStyleFlags());
  31432. }
  31433. }
  31434. repaint();
  31435. }
  31436. }
  31437. bool Component::isOpaque() const throw()
  31438. {
  31439. return flags.opaqueFlag;
  31440. }
  31441. void Component::setBufferedToImage (const bool shouldBeBuffered) throw()
  31442. {
  31443. if (shouldBeBuffered != flags.bufferToImageFlag)
  31444. {
  31445. deleteAndZero (bufferedImage_);
  31446. flags.bufferToImageFlag = shouldBeBuffered;
  31447. }
  31448. }
  31449. void Component::toFront (const bool setAsForeground)
  31450. {
  31451. // if component methods are being called from threads other than the message
  31452. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31453. checkMessageManagerIsLocked
  31454. if (flags.hasHeavyweightPeerFlag)
  31455. {
  31456. ComponentPeer* const peer = getPeer();
  31457. if (peer != 0)
  31458. {
  31459. peer->toFront (setAsForeground);
  31460. if (setAsForeground && ! hasKeyboardFocus (true))
  31461. grabKeyboardFocus();
  31462. }
  31463. }
  31464. else if (parentComponent_ != 0)
  31465. {
  31466. if (parentComponent_->childComponentList_.getLast() != this)
  31467. {
  31468. const int index = parentComponent_->childComponentList_.indexOf (this);
  31469. if (index >= 0)
  31470. {
  31471. int insertIndex = -1;
  31472. if (! flags.alwaysOnTopFlag)
  31473. {
  31474. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31475. while (insertIndex > 0
  31476. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31477. {
  31478. --insertIndex;
  31479. }
  31480. }
  31481. if (index != insertIndex)
  31482. {
  31483. parentComponent_->childComponentList_.move (index, insertIndex);
  31484. sendFakeMouseMove();
  31485. repaintParent();
  31486. }
  31487. }
  31488. }
  31489. if (setAsForeground)
  31490. {
  31491. internalBroughtToFront();
  31492. grabKeyboardFocus();
  31493. }
  31494. }
  31495. }
  31496. void Component::toBehind (Component* const other)
  31497. {
  31498. if (other != 0)
  31499. {
  31500. // the two components must belong to the same parent..
  31501. jassert (parentComponent_ == other->parentComponent_);
  31502. if (parentComponent_ != 0)
  31503. {
  31504. const int index = parentComponent_->childComponentList_.indexOf (this);
  31505. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31506. if (index >= 0
  31507. && otherIndex >= 0
  31508. && index != otherIndex - 1
  31509. && other != this)
  31510. {
  31511. if (index < otherIndex)
  31512. --otherIndex;
  31513. parentComponent_->childComponentList_.move (index, otherIndex);
  31514. sendFakeMouseMove();
  31515. repaintParent();
  31516. }
  31517. }
  31518. else if (isOnDesktop())
  31519. {
  31520. jassert (other->isOnDesktop());
  31521. if (other->isOnDesktop())
  31522. {
  31523. ComponentPeer* const us = getPeer();
  31524. ComponentPeer* const them = other->getPeer();
  31525. jassert (us != 0 && them != 0);
  31526. if (us != 0 && them != 0)
  31527. us->toBehind (them);
  31528. }
  31529. }
  31530. }
  31531. }
  31532. void Component::toBack()
  31533. {
  31534. if (isOnDesktop())
  31535. {
  31536. jassertfalse //xxx need to add this to native window
  31537. }
  31538. else if (parentComponent_ != 0
  31539. && parentComponent_->childComponentList_.getFirst() != this)
  31540. {
  31541. const int index = parentComponent_->childComponentList_.indexOf (this);
  31542. if (index > 0)
  31543. {
  31544. int insertIndex = 0;
  31545. if (flags.alwaysOnTopFlag)
  31546. {
  31547. while (insertIndex < parentComponent_->childComponentList_.size()
  31548. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31549. {
  31550. ++insertIndex;
  31551. }
  31552. }
  31553. if (index != insertIndex)
  31554. {
  31555. parentComponent_->childComponentList_.move (index, insertIndex);
  31556. sendFakeMouseMove();
  31557. repaintParent();
  31558. }
  31559. }
  31560. }
  31561. }
  31562. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31563. {
  31564. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31565. {
  31566. flags.alwaysOnTopFlag = shouldStayOnTop;
  31567. if (isOnDesktop())
  31568. {
  31569. ComponentPeer* const peer = getPeer();
  31570. jassert (peer != 0);
  31571. if (peer != 0)
  31572. {
  31573. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31574. {
  31575. // some kinds of peer can't change their always-on-top status, so
  31576. // for these, we'll need to create a new window
  31577. const int oldFlags = peer->getStyleFlags();
  31578. removeFromDesktop();
  31579. addToDesktop (oldFlags);
  31580. }
  31581. }
  31582. }
  31583. if (shouldStayOnTop)
  31584. toFront (false);
  31585. internalHierarchyChanged();
  31586. }
  31587. }
  31588. bool Component::isAlwaysOnTop() const throw()
  31589. {
  31590. return flags.alwaysOnTopFlag;
  31591. }
  31592. int Component::proportionOfWidth (const float proportion) const throw()
  31593. {
  31594. return roundToInt (proportion * bounds_.getWidth());
  31595. }
  31596. int Component::proportionOfHeight (const float proportion) const throw()
  31597. {
  31598. return roundToInt (proportion * bounds_.getHeight());
  31599. }
  31600. int Component::getParentWidth() const throw()
  31601. {
  31602. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31603. : getParentMonitorArea().getWidth();
  31604. }
  31605. int Component::getParentHeight() const throw()
  31606. {
  31607. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31608. : getParentMonitorArea().getHeight();
  31609. }
  31610. int Component::getScreenX() const
  31611. {
  31612. return getScreenPosition().getX();
  31613. }
  31614. int Component::getScreenY() const
  31615. {
  31616. return getScreenPosition().getY();
  31617. }
  31618. const Point<int> Component::getScreenPosition() const
  31619. {
  31620. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31621. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31622. : getPosition());
  31623. }
  31624. const Rectangle<int> Component::getScreenBounds() const
  31625. {
  31626. return bounds_.withPosition (getScreenPosition());
  31627. }
  31628. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31629. {
  31630. const Component* c = this;
  31631. Point<int> p (relativePosition);
  31632. do
  31633. {
  31634. if (c->flags.hasHeavyweightPeerFlag)
  31635. return c->getPeer()->relativePositionToGlobal (p);
  31636. p += c->getPosition();
  31637. c = c->parentComponent_;
  31638. }
  31639. while (c != 0);
  31640. return p;
  31641. }
  31642. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31643. {
  31644. if (flags.hasHeavyweightPeerFlag)
  31645. {
  31646. return getPeer()->globalPositionToRelative (screenPosition);
  31647. }
  31648. else
  31649. {
  31650. if (parentComponent_ != 0)
  31651. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31652. return screenPosition - getPosition();
  31653. }
  31654. }
  31655. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31656. {
  31657. Point<int> p (positionRelativeToThis);
  31658. if (targetComponent != 0)
  31659. {
  31660. const Component* c = this;
  31661. do
  31662. {
  31663. if (c == targetComponent)
  31664. return p;
  31665. if (c->flags.hasHeavyweightPeerFlag)
  31666. {
  31667. p = c->getPeer()->relativePositionToGlobal (p);
  31668. break;
  31669. }
  31670. p += c->getPosition();
  31671. c = c->parentComponent_;
  31672. }
  31673. while (c != 0);
  31674. p = targetComponent->globalPositionToRelative (p);
  31675. }
  31676. return p;
  31677. }
  31678. void Component::setBounds (int x, int y, int w, int h)
  31679. {
  31680. // if component methods are being called from threads other than the message
  31681. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31682. checkMessageManagerIsLocked
  31683. if (w < 0) w = 0;
  31684. if (h < 0) h = 0;
  31685. const bool wasResized = (getWidth() != w || getHeight() != h);
  31686. const bool wasMoved = (getX() != x || getY() != y);
  31687. #ifdef JUCE_DEBUG
  31688. // It's a very bad idea to try to resize a window during its paint() method!
  31689. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31690. #endif
  31691. if (wasMoved || wasResized)
  31692. {
  31693. if (flags.visibleFlag)
  31694. {
  31695. // send a fake mouse move to trigger enter/exit messages if needed..
  31696. sendFakeMouseMove();
  31697. if (! flags.hasHeavyweightPeerFlag)
  31698. repaintParent();
  31699. }
  31700. bounds_.setBounds (x, y, w, h);
  31701. if (wasResized)
  31702. repaint();
  31703. else if (! flags.hasHeavyweightPeerFlag)
  31704. repaintParent();
  31705. if (flags.hasHeavyweightPeerFlag)
  31706. {
  31707. ComponentPeer* const peer = getPeer();
  31708. if (peer != 0)
  31709. {
  31710. if (wasMoved && wasResized)
  31711. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31712. else if (wasMoved)
  31713. peer->setPosition (getX(), getY());
  31714. else if (wasResized)
  31715. peer->setSize (getWidth(), getHeight());
  31716. }
  31717. }
  31718. sendMovedResizedMessages (wasMoved, wasResized);
  31719. }
  31720. }
  31721. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31722. {
  31723. JUCE_TRY
  31724. {
  31725. if (wasMoved)
  31726. moved();
  31727. if (wasResized)
  31728. {
  31729. resized();
  31730. for (int i = childComponentList_.size(); --i >= 0;)
  31731. {
  31732. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31733. i = jmin (i, childComponentList_.size());
  31734. }
  31735. }
  31736. if (parentComponent_ != 0)
  31737. parentComponent_->childBoundsChanged (this);
  31738. if (componentListeners_ != 0)
  31739. {
  31740. const ComponentDeletionWatcher deletionChecker (this);
  31741. for (int i = componentListeners_->size(); --i >= 0;)
  31742. {
  31743. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31744. ->componentMovedOrResized (*this, wasMoved, wasResized);
  31745. if (deletionChecker.hasBeenDeleted())
  31746. return;
  31747. i = jmin (i, componentListeners_->size());
  31748. }
  31749. }
  31750. }
  31751. JUCE_CATCH_EXCEPTION
  31752. }
  31753. void Component::setSize (const int w, const int h)
  31754. {
  31755. setBounds (getX(), getY(), w, h);
  31756. }
  31757. void Component::setTopLeftPosition (const int x, const int y)
  31758. {
  31759. setBounds (x, y, getWidth(), getHeight());
  31760. }
  31761. void Component::setTopRightPosition (const int x, const int y)
  31762. {
  31763. setTopLeftPosition (x - getWidth(), y);
  31764. }
  31765. void Component::setBounds (const Rectangle<int>& r)
  31766. {
  31767. setBounds (r.getX(),
  31768. r.getY(),
  31769. r.getWidth(),
  31770. r.getHeight());
  31771. }
  31772. void Component::setBoundsRelative (const float x, const float y,
  31773. const float w, const float h)
  31774. {
  31775. const int pw = getParentWidth();
  31776. const int ph = getParentHeight();
  31777. setBounds (roundToInt (x * pw),
  31778. roundToInt (y * ph),
  31779. roundToInt (w * pw),
  31780. roundToInt (h * ph));
  31781. }
  31782. void Component::setCentrePosition (const int x, const int y)
  31783. {
  31784. setTopLeftPosition (x - getWidth() / 2,
  31785. y - getHeight() / 2);
  31786. }
  31787. void Component::setCentreRelative (const float x, const float y)
  31788. {
  31789. setCentrePosition (roundToInt (getParentWidth() * x),
  31790. roundToInt (getParentHeight() * y));
  31791. }
  31792. void Component::centreWithSize (const int width, const int height)
  31793. {
  31794. setBounds ((getParentWidth() - width) / 2,
  31795. (getParentHeight() - height) / 2,
  31796. width,
  31797. height);
  31798. }
  31799. void Component::setBoundsInset (const BorderSize& borders)
  31800. {
  31801. setBounds (borders.getLeft(),
  31802. borders.getTop(),
  31803. getParentWidth() - (borders.getLeftAndRight()),
  31804. getParentHeight() - (borders.getTopAndBottom()));
  31805. }
  31806. void Component::setBoundsToFit (int x, int y, int width, int height,
  31807. const Justification& justification,
  31808. const bool onlyReduceInSize)
  31809. {
  31810. // it's no good calling this method unless both the component and
  31811. // target rectangle have a finite size.
  31812. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31813. if (getWidth() > 0 && getHeight() > 0
  31814. && width > 0 && height > 0)
  31815. {
  31816. int newW, newH;
  31817. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31818. {
  31819. newW = getWidth();
  31820. newH = getHeight();
  31821. }
  31822. else
  31823. {
  31824. const double imageRatio = getHeight() / (double) getWidth();
  31825. const double targetRatio = height / (double) width;
  31826. if (imageRatio <= targetRatio)
  31827. {
  31828. newW = width;
  31829. newH = jmin (height, roundToInt (newW * imageRatio));
  31830. }
  31831. else
  31832. {
  31833. newH = height;
  31834. newW = jmin (width, roundToInt (newH / imageRatio));
  31835. }
  31836. }
  31837. if (newW > 0 && newH > 0)
  31838. {
  31839. int newX, newY;
  31840. justification.applyToRectangle (newX, newY, newW, newH,
  31841. x, y, width, height);
  31842. setBounds (newX, newY, newW, newH);
  31843. }
  31844. }
  31845. }
  31846. bool Component::hitTest (int x, int y)
  31847. {
  31848. if (! flags.ignoresMouseClicksFlag)
  31849. return true;
  31850. if (flags.allowChildMouseClicksFlag)
  31851. {
  31852. for (int i = getNumChildComponents(); --i >= 0;)
  31853. {
  31854. Component* const c = getChildComponent (i);
  31855. if (c->isVisible()
  31856. && c->bounds_.contains (x, y)
  31857. && c->hitTest (x - c->getX(),
  31858. y - c->getY()))
  31859. {
  31860. return true;
  31861. }
  31862. }
  31863. }
  31864. return false;
  31865. }
  31866. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31867. const bool allowClicksOnChildComponents) throw()
  31868. {
  31869. flags.ignoresMouseClicksFlag = ! allowClicks;
  31870. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31871. }
  31872. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31873. bool& allowsClicksOnChildComponents) const throw()
  31874. {
  31875. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31876. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31877. }
  31878. bool Component::contains (const int x, const int y)
  31879. {
  31880. if (((unsigned int) x) < (unsigned int) getWidth()
  31881. && ((unsigned int) y) < (unsigned int) getHeight()
  31882. && hitTest (x, y))
  31883. {
  31884. if (parentComponent_ != 0)
  31885. {
  31886. return parentComponent_->contains (x + getX(),
  31887. y + getY());
  31888. }
  31889. else if (flags.hasHeavyweightPeerFlag)
  31890. {
  31891. const ComponentPeer* const peer = getPeer();
  31892. if (peer != 0)
  31893. return peer->contains (Point<int> (x, y), true);
  31894. }
  31895. }
  31896. return false;
  31897. }
  31898. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31899. {
  31900. if (! contains (x, y))
  31901. return false;
  31902. Component* p = this;
  31903. while (p->parentComponent_ != 0)
  31904. {
  31905. x += p->getX();
  31906. y += p->getY();
  31907. p = p->parentComponent_;
  31908. }
  31909. const Component* const c = p->getComponentAt (x, y);
  31910. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31911. }
  31912. Component* Component::getComponentAt (const Point<int>& position)
  31913. {
  31914. return getComponentAt (position.getX(), position.getY());
  31915. }
  31916. Component* Component::getComponentAt (const int x, const int y)
  31917. {
  31918. if (flags.visibleFlag
  31919. && ((unsigned int) x) < (unsigned int) getWidth()
  31920. && ((unsigned int) y) < (unsigned int) getHeight()
  31921. && hitTest (x, y))
  31922. {
  31923. for (int i = childComponentList_.size(); --i >= 0;)
  31924. {
  31925. Component* const child = childComponentList_.getUnchecked(i);
  31926. Component* const c = child->getComponentAt (x - child->getX(),
  31927. y - child->getY());
  31928. if (c != 0)
  31929. return c;
  31930. }
  31931. return this;
  31932. }
  31933. return 0;
  31934. }
  31935. void Component::addChildComponent (Component* const child, int zOrder)
  31936. {
  31937. // if component methods are being called from threads other than the message
  31938. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31939. checkMessageManagerIsLocked
  31940. if (child != 0 && child->parentComponent_ != this)
  31941. {
  31942. if (child->parentComponent_ != 0)
  31943. child->parentComponent_->removeChildComponent (child);
  31944. else
  31945. child->removeFromDesktop();
  31946. child->parentComponent_ = this;
  31947. if (child->isVisible())
  31948. child->repaintParent();
  31949. if (! child->isAlwaysOnTop())
  31950. {
  31951. if (zOrder < 0 || zOrder > childComponentList_.size())
  31952. zOrder = childComponentList_.size();
  31953. while (zOrder > 0)
  31954. {
  31955. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31956. break;
  31957. --zOrder;
  31958. }
  31959. }
  31960. childComponentList_.insert (zOrder, child);
  31961. child->internalHierarchyChanged();
  31962. internalChildrenChanged();
  31963. }
  31964. }
  31965. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31966. {
  31967. if (child != 0)
  31968. {
  31969. child->setVisible (true);
  31970. addChildComponent (child, zOrder);
  31971. }
  31972. }
  31973. void Component::removeChildComponent (Component* const child)
  31974. {
  31975. removeChildComponent (childComponentList_.indexOf (child));
  31976. }
  31977. Component* Component::removeChildComponent (const int index)
  31978. {
  31979. // if component methods are being called from threads other than the message
  31980. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31981. checkMessageManagerIsLocked
  31982. Component* const child = childComponentList_ [index];
  31983. if (child != 0)
  31984. {
  31985. sendFakeMouseMove();
  31986. child->repaintParent();
  31987. childComponentList_.remove (index);
  31988. child->parentComponent_ = 0;
  31989. JUCE_TRY
  31990. {
  31991. if ((currentlyFocusedComponent == child)
  31992. || child->isParentOf (currentlyFocusedComponent))
  31993. {
  31994. // get rid first to force the grabKeyboardFocus to change to us.
  31995. giveAwayFocus();
  31996. grabKeyboardFocus();
  31997. }
  31998. }
  31999. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32000. catch (const std::exception& e)
  32001. {
  32002. currentlyFocusedComponent = 0;
  32003. Desktop::getInstance().triggerFocusCallback();
  32004. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32005. }
  32006. catch (...)
  32007. {
  32008. currentlyFocusedComponent = 0;
  32009. Desktop::getInstance().triggerFocusCallback();
  32010. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32011. }
  32012. #endif
  32013. child->internalHierarchyChanged();
  32014. internalChildrenChanged();
  32015. }
  32016. return child;
  32017. }
  32018. void Component::removeAllChildren()
  32019. {
  32020. for (int i = childComponentList_.size(); --i >= 0;)
  32021. removeChildComponent (i);
  32022. }
  32023. void Component::deleteAllChildren()
  32024. {
  32025. for (int i = childComponentList_.size(); --i >= 0;)
  32026. delete (removeChildComponent (i));
  32027. }
  32028. int Component::getNumChildComponents() const throw()
  32029. {
  32030. return childComponentList_.size();
  32031. }
  32032. Component* Component::getChildComponent (const int index) const throw()
  32033. {
  32034. return childComponentList_ [index];
  32035. }
  32036. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  32037. {
  32038. return childComponentList_.indexOf (const_cast <Component*> (child));
  32039. }
  32040. Component* Component::getTopLevelComponent() const throw()
  32041. {
  32042. const Component* comp = this;
  32043. while (comp->parentComponent_ != 0)
  32044. comp = comp->parentComponent_;
  32045. return (Component*) comp;
  32046. }
  32047. bool Component::isParentOf (const Component* possibleChild) const throw()
  32048. {
  32049. while (possibleChild->isValidComponent())
  32050. {
  32051. possibleChild = possibleChild->parentComponent_;
  32052. if (possibleChild == this)
  32053. return true;
  32054. }
  32055. return false;
  32056. }
  32057. void Component::parentHierarchyChanged()
  32058. {
  32059. }
  32060. void Component::childrenChanged()
  32061. {
  32062. }
  32063. void Component::internalChildrenChanged()
  32064. {
  32065. const ComponentDeletionWatcher deletionChecker (this);
  32066. const bool hasListeners = componentListeners_ != 0;
  32067. childrenChanged();
  32068. if (hasListeners)
  32069. {
  32070. if (deletionChecker.hasBeenDeleted())
  32071. return;
  32072. for (int i = componentListeners_->size(); --i >= 0;)
  32073. {
  32074. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32075. ->componentChildrenChanged (*this);
  32076. if (deletionChecker.hasBeenDeleted())
  32077. return;
  32078. i = jmin (i, componentListeners_->size());
  32079. }
  32080. }
  32081. }
  32082. void Component::internalHierarchyChanged()
  32083. {
  32084. parentHierarchyChanged();
  32085. const ComponentDeletionWatcher deletionChecker (this);
  32086. if (componentListeners_ != 0)
  32087. {
  32088. for (int i = componentListeners_->size(); --i >= 0;)
  32089. {
  32090. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32091. ->componentParentHierarchyChanged (*this);
  32092. if (deletionChecker.hasBeenDeleted())
  32093. return;
  32094. i = jmin (i, componentListeners_->size());
  32095. }
  32096. }
  32097. for (int i = childComponentList_.size(); --i >= 0;)
  32098. {
  32099. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  32100. // you really shouldn't delete the parent component during a callback telling you
  32101. // that it's changed..
  32102. jassert (! deletionChecker.hasBeenDeleted());
  32103. if (deletionChecker.hasBeenDeleted())
  32104. return;
  32105. i = jmin (i, childComponentList_.size());
  32106. }
  32107. }
  32108. void* Component::runModalLoopCallback (void* userData)
  32109. {
  32110. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  32111. }
  32112. int Component::runModalLoop()
  32113. {
  32114. if (! MessageManager::getInstance()->isThisTheMessageThread())
  32115. {
  32116. // use a callback so this can be called from non-gui threads
  32117. return (int) (pointer_sized_int)
  32118. MessageManager::getInstance()
  32119. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  32120. }
  32121. Component* const prevFocused = getCurrentlyFocusedComponent();
  32122. ScopedPointer <ComponentDeletionWatcher> deletionChecker;
  32123. if (prevFocused != 0)
  32124. deletionChecker = new ComponentDeletionWatcher (prevFocused);
  32125. if (! isCurrentlyModal())
  32126. enterModalState();
  32127. JUCE_TRY
  32128. {
  32129. while (flags.currentlyModalFlag && flags.visibleFlag)
  32130. {
  32131. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  32132. break;
  32133. // check whether this component was deleted during the last message
  32134. if (! isValidMessageListener())
  32135. break;
  32136. }
  32137. }
  32138. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32139. catch (const std::exception& e)
  32140. {
  32141. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32142. return 0;
  32143. }
  32144. catch (...)
  32145. {
  32146. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32147. return 0;
  32148. }
  32149. #endif
  32150. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32151. int returnValue = 0;
  32152. if (modalIndex >= 0)
  32153. {
  32154. modalComponentReturnValueKeys.remove (modalIndex);
  32155. returnValue = modalReturnValues.remove (modalIndex);
  32156. }
  32157. modalComponentStack.removeValue (this);
  32158. if (deletionChecker != 0 && ! deletionChecker->hasBeenDeleted())
  32159. prevFocused->grabKeyboardFocus();
  32160. return returnValue;
  32161. }
  32162. void Component::enterModalState (const bool takeKeyboardFocus_)
  32163. {
  32164. // if component methods are being called from threads other than the message
  32165. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32166. checkMessageManagerIsLocked
  32167. // Check for an attempt to make a component modal when it already is!
  32168. // This can cause nasty problems..
  32169. jassert (! flags.currentlyModalFlag);
  32170. if (! isCurrentlyModal())
  32171. {
  32172. modalComponentStack.add (this);
  32173. modalComponentReturnValueKeys.add (this);
  32174. modalReturnValues.add (0);
  32175. flags.currentlyModalFlag = true;
  32176. setVisible (true);
  32177. if (takeKeyboardFocus_)
  32178. grabKeyboardFocus();
  32179. }
  32180. }
  32181. void Component::exitModalState (const int returnValue)
  32182. {
  32183. if (isCurrentlyModal())
  32184. {
  32185. if (MessageManager::getInstance()->isThisTheMessageThread())
  32186. {
  32187. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32188. if (modalIndex >= 0)
  32189. {
  32190. modalReturnValues.set (modalIndex, returnValue);
  32191. }
  32192. else
  32193. {
  32194. modalComponentReturnValueKeys.add (this);
  32195. modalReturnValues.add (returnValue);
  32196. }
  32197. modalComponentStack.removeValue (this);
  32198. flags.currentlyModalFlag = false;
  32199. bringModalComponentToFront();
  32200. }
  32201. else
  32202. {
  32203. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32204. }
  32205. }
  32206. }
  32207. bool Component::isCurrentlyModal() const throw()
  32208. {
  32209. return flags.currentlyModalFlag
  32210. && getCurrentlyModalComponent() == this;
  32211. }
  32212. bool Component::isCurrentlyBlockedByAnotherModalComponent() const throw()
  32213. {
  32214. Component* const mc = getCurrentlyModalComponent();
  32215. return mc != 0
  32216. && mc != this
  32217. && (! mc->isParentOf (this))
  32218. && ! mc->canModalEventBeSentToComponent (this);
  32219. }
  32220. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32221. {
  32222. return modalComponentStack.size();
  32223. }
  32224. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32225. {
  32226. Component* const c = (Component*) (modalComponentStack [modalComponentStack.size() - index - 1]);
  32227. return c->isValidComponent() ? c : 0;
  32228. }
  32229. void Component::bringModalComponentToFront()
  32230. {
  32231. ComponentPeer* lastOne = 0;
  32232. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32233. {
  32234. Component* const c = getCurrentlyModalComponent (i);
  32235. if (c == 0)
  32236. break;
  32237. ComponentPeer* peer = c->getPeer();
  32238. if (peer != 0 && peer != lastOne)
  32239. {
  32240. if (lastOne == 0)
  32241. {
  32242. peer->toFront (true);
  32243. peer->grabFocus();
  32244. }
  32245. else
  32246. peer->toBehind (lastOne);
  32247. lastOne = peer;
  32248. }
  32249. }
  32250. }
  32251. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32252. {
  32253. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32254. }
  32255. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32256. {
  32257. return flags.bringToFrontOnClickFlag;
  32258. }
  32259. void Component::setMouseCursor (const MouseCursor& cursor) throw()
  32260. {
  32261. cursor_ = cursor;
  32262. if (flags.visibleFlag)
  32263. {
  32264. const Point<int> mousePos (getMouseXYRelative());
  32265. if (flags.draggingFlag || reallyContains (mousePos.getX(), mousePos.getY(), false))
  32266. {
  32267. internalUpdateMouseCursor (false);
  32268. }
  32269. }
  32270. }
  32271. const MouseCursor Component::getMouseCursor()
  32272. {
  32273. return cursor_;
  32274. }
  32275. void Component::updateMouseCursor() const throw()
  32276. {
  32277. sendFakeMouseMove();
  32278. }
  32279. void Component::internalUpdateMouseCursor (bool forcedUpdate) throw()
  32280. {
  32281. ComponentPeer* const peer = getPeer();
  32282. if (peer != 0)
  32283. {
  32284. MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this));
  32285. if (isUnboundedMouseModeOn
  32286. && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  32287. {
  32288. mc = MouseCursor::NoCursor;
  32289. forcedUpdate = true;
  32290. }
  32291. static void* currentCursorHandle = 0;
  32292. if (forcedUpdate || mc.getHandle() != currentCursorHandle)
  32293. {
  32294. currentCursorHandle = mc.getHandle();
  32295. mc.showInWindow (peer);
  32296. }
  32297. }
  32298. }
  32299. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32300. {
  32301. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32302. }
  32303. void Component::repaintParent() throw()
  32304. {
  32305. if (flags.visibleFlag)
  32306. internalRepaint (0, 0, getWidth(), getHeight());
  32307. }
  32308. void Component::repaint() throw()
  32309. {
  32310. repaint (0, 0, getWidth(), getHeight());
  32311. }
  32312. void Component::repaint (const int x, const int y,
  32313. const int w, const int h) throw()
  32314. {
  32315. deleteAndZero (bufferedImage_);
  32316. if (flags.visibleFlag)
  32317. internalRepaint (x, y, w, h);
  32318. }
  32319. void Component::internalRepaint (int x, int y, int w, int h)
  32320. {
  32321. // if component methods are being called from threads other than the message
  32322. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32323. checkMessageManagerIsLocked
  32324. if (x < 0)
  32325. {
  32326. w += x;
  32327. x = 0;
  32328. }
  32329. if (x + w > getWidth())
  32330. w = getWidth() - x;
  32331. if (w > 0)
  32332. {
  32333. if (y < 0)
  32334. {
  32335. h += y;
  32336. y = 0;
  32337. }
  32338. if (y + h > getHeight())
  32339. h = getHeight() - y;
  32340. if (h > 0)
  32341. {
  32342. if (parentComponent_ != 0)
  32343. {
  32344. x += getX();
  32345. y += getY();
  32346. if (parentComponent_->flags.visibleFlag)
  32347. parentComponent_->internalRepaint (x, y, w, h);
  32348. }
  32349. else if (flags.hasHeavyweightPeerFlag)
  32350. {
  32351. ComponentPeer* const peer = getPeer();
  32352. if (peer != 0)
  32353. peer->repaint (x, y, w, h);
  32354. }
  32355. }
  32356. }
  32357. }
  32358. void Component::paintEntireComponent (Graphics& originalContext)
  32359. {
  32360. jassert (! originalContext.isClipEmpty());
  32361. #ifdef JUCE_DEBUG
  32362. flags.isInsidePaintCall = true;
  32363. #endif
  32364. Graphics* g = &originalContext;
  32365. Image* effectImage = 0;
  32366. if (effect_ != 0)
  32367. {
  32368. effectImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32369. getWidth(), getHeight(),
  32370. ! flags.opaqueFlag);
  32371. g = new Graphics (*effectImage);
  32372. }
  32373. g->saveState();
  32374. clipObscuredRegions (*g, g->getClipBounds(), 0, 0);
  32375. if (! g->isClipEmpty())
  32376. {
  32377. if (bufferedImage_ != 0)
  32378. {
  32379. g->setColour (Colours::black);
  32380. g->drawImageAt (bufferedImage_, 0, 0);
  32381. }
  32382. else
  32383. {
  32384. if (flags.bufferToImageFlag)
  32385. {
  32386. if (bufferedImage_ == 0)
  32387. {
  32388. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32389. getWidth(), getHeight(), ! flags.opaqueFlag);
  32390. Graphics imG (*bufferedImage_);
  32391. paint (imG);
  32392. }
  32393. g->setColour (Colours::black);
  32394. g->drawImageAt (bufferedImage_, 0, 0);
  32395. }
  32396. else
  32397. {
  32398. paint (*g);
  32399. g->resetToDefaultState();
  32400. }
  32401. }
  32402. }
  32403. g->restoreState();
  32404. for (int i = 0; i < childComponentList_.size(); ++i)
  32405. {
  32406. Component* const child = childComponentList_.getUnchecked (i);
  32407. if (child->isVisible())
  32408. {
  32409. g->saveState();
  32410. if (g->reduceClipRegion (child->getX(), child->getY(),
  32411. child->getWidth(), child->getHeight()))
  32412. {
  32413. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32414. {
  32415. const Component* const sibling = childComponentList_.getUnchecked (j);
  32416. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32417. g->excludeClipRegion (sibling->getX(), sibling->getY(),
  32418. sibling->getWidth(), sibling->getHeight());
  32419. }
  32420. if (! g->isClipEmpty())
  32421. {
  32422. g->setOrigin (child->getX(), child->getY());
  32423. child->paintEntireComponent (*g);
  32424. }
  32425. }
  32426. g->restoreState();
  32427. }
  32428. }
  32429. JUCE_TRY
  32430. {
  32431. g->saveState();
  32432. paintOverChildren (*g);
  32433. g->restoreState();
  32434. }
  32435. JUCE_CATCH_EXCEPTION
  32436. if (effect_ != 0)
  32437. {
  32438. delete g;
  32439. effect_->applyEffect (*effectImage, originalContext);
  32440. delete effectImage;
  32441. }
  32442. #ifdef JUCE_DEBUG
  32443. flags.isInsidePaintCall = false;
  32444. #endif
  32445. }
  32446. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32447. const bool clipImageToComponentBounds)
  32448. {
  32449. Rectangle<int> r (areaToGrab);
  32450. if (clipImageToComponentBounds)
  32451. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32452. Image* const componentImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32453. jmax (1, r.getWidth()),
  32454. jmax (1, r.getHeight()),
  32455. true);
  32456. Graphics imageContext (*componentImage);
  32457. imageContext.setOrigin (-r.getX(),
  32458. -r.getY());
  32459. paintEntireComponent (imageContext);
  32460. return componentImage;
  32461. }
  32462. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32463. {
  32464. if (effect_ != effect)
  32465. {
  32466. effect_ = effect;
  32467. repaint();
  32468. }
  32469. }
  32470. LookAndFeel& Component::getLookAndFeel() const throw()
  32471. {
  32472. const Component* c = this;
  32473. do
  32474. {
  32475. if (c->lookAndFeel_ != 0)
  32476. return *(c->lookAndFeel_);
  32477. c = c->parentComponent_;
  32478. }
  32479. while (c != 0);
  32480. return LookAndFeel::getDefaultLookAndFeel();
  32481. }
  32482. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32483. {
  32484. if (lookAndFeel_ != newLookAndFeel)
  32485. {
  32486. lookAndFeel_ = newLookAndFeel;
  32487. sendLookAndFeelChange();
  32488. }
  32489. }
  32490. void Component::lookAndFeelChanged()
  32491. {
  32492. }
  32493. void Component::sendLookAndFeelChange()
  32494. {
  32495. repaint();
  32496. lookAndFeelChanged();
  32497. // (it's not a great idea to do anything that would delete this component
  32498. // during the lookAndFeelChanged() callback)
  32499. jassert (isValidComponent());
  32500. const ComponentDeletionWatcher deletionChecker (this);
  32501. for (int i = childComponentList_.size(); --i >= 0;)
  32502. {
  32503. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32504. if (deletionChecker.hasBeenDeleted())
  32505. return;
  32506. i = jmin (i, childComponentList_.size());
  32507. }
  32508. }
  32509. static const var::identifier getColourPropertyId (const int colourId)
  32510. {
  32511. String s;
  32512. s.preallocateStorage (18);
  32513. s << T("jcclr_") << colourId;
  32514. return s;
  32515. }
  32516. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const throw()
  32517. {
  32518. var* v = properties.getItem (getColourPropertyId (colourId));
  32519. if (v != 0)
  32520. return Colour ((int) *v);
  32521. if (inheritFromParent && parentComponent_ != 0)
  32522. return parentComponent_->findColour (colourId, true);
  32523. return getLookAndFeel().findColour (colourId);
  32524. }
  32525. bool Component::isColourSpecified (const int colourId) const throw()
  32526. {
  32527. return properties.contains (getColourPropertyId (colourId));
  32528. }
  32529. void Component::removeColour (const int colourId)
  32530. {
  32531. if (properties.remove (getColourPropertyId (colourId)))
  32532. colourChanged();
  32533. }
  32534. void Component::setColour (const int colourId, const Colour& colour)
  32535. {
  32536. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32537. colourChanged();
  32538. }
  32539. void Component::copyAllExplicitColoursTo (Component& target) const throw()
  32540. {
  32541. bool changed = false;
  32542. for (int i = properties.size(); --i >= 0;)
  32543. {
  32544. const var::identifier name (properties.getName(i));
  32545. if (name.name.startsWith (T("jcclr_")))
  32546. if (target.properties.set (name, properties [name]))
  32547. changed = true;
  32548. }
  32549. if (changed)
  32550. target.colourChanged();
  32551. }
  32552. void Component::colourChanged()
  32553. {
  32554. }
  32555. const Rectangle<int> Component::getUnclippedArea() const
  32556. {
  32557. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32558. Component* p = parentComponent_;
  32559. int px = getX();
  32560. int py = getY();
  32561. while (p != 0)
  32562. {
  32563. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32564. return Rectangle<int>();
  32565. px += p->getX();
  32566. py += p->getY();
  32567. p = p->parentComponent_;
  32568. }
  32569. return Rectangle<int> (x, y, w, h);
  32570. }
  32571. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32572. const int deltaX, const int deltaY) const throw()
  32573. {
  32574. for (int i = childComponentList_.size(); --i >= 0;)
  32575. {
  32576. const Component* const c = childComponentList_.getUnchecked(i);
  32577. if (c->isVisible())
  32578. {
  32579. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32580. if (! newClip.isEmpty())
  32581. {
  32582. if (c->isOpaque())
  32583. {
  32584. g.excludeClipRegion (deltaX + newClip.getX(),
  32585. deltaY + newClip.getY(),
  32586. newClip.getWidth(),
  32587. newClip.getHeight());
  32588. }
  32589. else
  32590. {
  32591. newClip.translate (-c->getX(), -c->getY());
  32592. c->clipObscuredRegions (g, newClip,
  32593. c->getX() + deltaX,
  32594. c->getY() + deltaY);
  32595. }
  32596. }
  32597. }
  32598. }
  32599. }
  32600. void Component::getVisibleArea (RectangleList& result,
  32601. const bool includeSiblings) const
  32602. {
  32603. result.clear();
  32604. const Rectangle<int> unclipped (getUnclippedArea());
  32605. if (! unclipped.isEmpty())
  32606. {
  32607. result.add (unclipped);
  32608. if (includeSiblings)
  32609. {
  32610. const Component* const c = getTopLevelComponent();
  32611. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32612. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32613. this);
  32614. }
  32615. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32616. result.consolidate();
  32617. }
  32618. }
  32619. void Component::subtractObscuredRegions (RectangleList& result,
  32620. const Point<int>& delta,
  32621. const Rectangle<int>& clipRect,
  32622. const Component* const compToAvoid) const throw()
  32623. {
  32624. for (int i = childComponentList_.size(); --i >= 0;)
  32625. {
  32626. const Component* const c = childComponentList_.getUnchecked(i);
  32627. if (c != compToAvoid && c->isVisible())
  32628. {
  32629. if (c->isOpaque())
  32630. {
  32631. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32632. childBounds.translate (delta.getX(), delta.getY());
  32633. result.subtract (childBounds);
  32634. }
  32635. else
  32636. {
  32637. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32638. newClip.translate (-c->getX(), -c->getY());
  32639. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32640. newClip, compToAvoid);
  32641. }
  32642. }
  32643. }
  32644. }
  32645. void Component::mouseEnter (const MouseEvent&)
  32646. {
  32647. // base class does nothing
  32648. }
  32649. void Component::mouseExit (const MouseEvent&)
  32650. {
  32651. // base class does nothing
  32652. }
  32653. void Component::mouseDown (const MouseEvent&)
  32654. {
  32655. // base class does nothing
  32656. }
  32657. void Component::mouseUp (const MouseEvent&)
  32658. {
  32659. // base class does nothing
  32660. }
  32661. void Component::mouseDrag (const MouseEvent&)
  32662. {
  32663. // base class does nothing
  32664. }
  32665. void Component::mouseMove (const MouseEvent&)
  32666. {
  32667. // base class does nothing
  32668. }
  32669. void Component::mouseDoubleClick (const MouseEvent&)
  32670. {
  32671. // base class does nothing
  32672. }
  32673. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32674. {
  32675. // the base class just passes this event up to its parent..
  32676. if (parentComponent_ != 0)
  32677. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32678. wheelIncrementX, wheelIncrementY);
  32679. }
  32680. void Component::resized()
  32681. {
  32682. // base class does nothing
  32683. }
  32684. void Component::moved()
  32685. {
  32686. // base class does nothing
  32687. }
  32688. void Component::childBoundsChanged (Component*)
  32689. {
  32690. // base class does nothing
  32691. }
  32692. void Component::parentSizeChanged()
  32693. {
  32694. // base class does nothing
  32695. }
  32696. void Component::addComponentListener (ComponentListener* const newListener) throw()
  32697. {
  32698. if (componentListeners_ == 0)
  32699. componentListeners_ = new VoidArray();
  32700. componentListeners_->addIfNotAlreadyThere (newListener);
  32701. }
  32702. void Component::removeComponentListener (ComponentListener* const listenerToRemove) throw()
  32703. {
  32704. jassert (isValidComponent());
  32705. if (componentListeners_ != 0)
  32706. componentListeners_->removeValue (listenerToRemove);
  32707. }
  32708. void Component::inputAttemptWhenModal()
  32709. {
  32710. bringModalComponentToFront();
  32711. getLookAndFeel().playAlertSound();
  32712. }
  32713. bool Component::canModalEventBeSentToComponent (const Component*)
  32714. {
  32715. return false;
  32716. }
  32717. void Component::internalModalInputAttempt()
  32718. {
  32719. Component* const current = getCurrentlyModalComponent();
  32720. if (current != 0)
  32721. current->inputAttemptWhenModal();
  32722. }
  32723. void Component::paint (Graphics&)
  32724. {
  32725. // all painting is done in the subclasses
  32726. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32727. }
  32728. void Component::paintOverChildren (Graphics&)
  32729. {
  32730. // all painting is done in the subclasses
  32731. }
  32732. void Component::handleMessage (const Message& message)
  32733. {
  32734. if (message.intParameter1 == exitModalStateMessage)
  32735. {
  32736. exitModalState (message.intParameter2);
  32737. }
  32738. else if (message.intParameter1 == customCommandMessage)
  32739. {
  32740. handleCommandMessage (message.intParameter2);
  32741. }
  32742. }
  32743. void Component::postCommandMessage (const int commandId) throw()
  32744. {
  32745. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32746. }
  32747. void Component::handleCommandMessage (int)
  32748. {
  32749. // used by subclasses
  32750. }
  32751. void Component::addMouseListener (MouseListener* const newListener,
  32752. const bool wantsEventsForAllNestedChildComponents) throw()
  32753. {
  32754. // if component methods are being called from threads other than the message
  32755. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32756. checkMessageManagerIsLocked
  32757. if (mouseListeners_ == 0)
  32758. mouseListeners_ = new VoidArray();
  32759. if (! mouseListeners_->contains (newListener))
  32760. {
  32761. if (wantsEventsForAllNestedChildComponents)
  32762. {
  32763. mouseListeners_->insert (0, newListener);
  32764. ++numDeepMouseListeners;
  32765. }
  32766. else
  32767. {
  32768. mouseListeners_->add (newListener);
  32769. }
  32770. }
  32771. }
  32772. void Component::removeMouseListener (MouseListener* const listenerToRemove) throw()
  32773. {
  32774. // if component methods are being called from threads other than the message
  32775. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32776. checkMessageManagerIsLocked
  32777. if (mouseListeners_ != 0)
  32778. {
  32779. const int index = mouseListeners_->indexOf (listenerToRemove);
  32780. if (index >= 0)
  32781. {
  32782. if (index < numDeepMouseListeners)
  32783. --numDeepMouseListeners;
  32784. mouseListeners_->remove (index);
  32785. }
  32786. }
  32787. }
  32788. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32789. {
  32790. if (isCurrentlyBlockedByAnotherModalComponent())
  32791. {
  32792. // if something else is modal, always just show a normal mouse cursor
  32793. if (componentUnderMouse == this)
  32794. {
  32795. ComponentPeer* const peer = getPeer();
  32796. if (peer != 0)
  32797. {
  32798. MouseCursor mc (MouseCursor::NormalCursor);
  32799. mc.showInWindow (peer);
  32800. }
  32801. }
  32802. return;
  32803. }
  32804. if (isValidComponent() && ! flags.mouseInsideFlag)
  32805. {
  32806. flags.mouseInsideFlag = true;
  32807. flags.mouseOverFlag = true;
  32808. flags.draggingFlag = false;
  32809. const ComponentDeletionWatcher deletionChecker (this);
  32810. if (flags.repaintOnMouseActivityFlag)
  32811. repaint();
  32812. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32813. this, time, relativePos,
  32814. time, 0, false);
  32815. mouseEnter (me);
  32816. if (deletionChecker.hasBeenDeleted())
  32817. return;
  32818. Desktop::getInstance().resetTimer();
  32819. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32820. {
  32821. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me);
  32822. if (deletionChecker.hasBeenDeleted())
  32823. return;
  32824. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32825. }
  32826. if (mouseListeners_ != 0)
  32827. {
  32828. for (int i = mouseListeners_->size(); --i >= 0;)
  32829. {
  32830. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32831. if (deletionChecker.hasBeenDeleted())
  32832. return;
  32833. i = jmin (i, mouseListeners_->size());
  32834. }
  32835. }
  32836. const Component* p = parentComponent_;
  32837. while (p != 0)
  32838. {
  32839. const ComponentDeletionWatcher parentDeletionChecker (p);
  32840. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32841. {
  32842. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32843. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32844. return;
  32845. i = jmin (i, p->numDeepMouseListeners);
  32846. }
  32847. p = p->parentComponent_;
  32848. }
  32849. }
  32850. if (componentUnderMouse == this)
  32851. internalUpdateMouseCursor (true);
  32852. }
  32853. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32854. {
  32855. const ComponentDeletionWatcher deletionChecker (this);
  32856. if (flags.draggingFlag)
  32857. {
  32858. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32859. if (deletionChecker.hasBeenDeleted())
  32860. return;
  32861. }
  32862. enableUnboundedMouseMovement (false);
  32863. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32864. {
  32865. flags.mouseInsideFlag = false;
  32866. flags.mouseOverFlag = false;
  32867. flags.draggingFlag = false;
  32868. if (flags.repaintOnMouseActivityFlag)
  32869. repaint();
  32870. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32871. this, time, relativePos,
  32872. time, 0, false);
  32873. mouseExit (me);
  32874. if (deletionChecker.hasBeenDeleted())
  32875. return;
  32876. Desktop::getInstance().resetTimer();
  32877. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32878. {
  32879. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me);
  32880. if (deletionChecker.hasBeenDeleted())
  32881. return;
  32882. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32883. }
  32884. if (mouseListeners_ != 0)
  32885. {
  32886. for (int i = mouseListeners_->size(); --i >= 0;)
  32887. {
  32888. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32889. if (deletionChecker.hasBeenDeleted())
  32890. return;
  32891. i = jmin (i, mouseListeners_->size());
  32892. }
  32893. }
  32894. const Component* p = parentComponent_;
  32895. while (p != 0)
  32896. {
  32897. const ComponentDeletionWatcher parentDeletionChecker (p);
  32898. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32899. {
  32900. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32901. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32902. return;
  32903. i = jmin (i, p->numDeepMouseListeners);
  32904. }
  32905. p = p->parentComponent_;
  32906. }
  32907. }
  32908. }
  32909. class InternalDragRepeater : public Timer
  32910. {
  32911. public:
  32912. InternalDragRepeater()
  32913. {}
  32914. ~InternalDragRepeater()
  32915. {
  32916. clearSingletonInstance();
  32917. }
  32918. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32919. void timerCallback()
  32920. {
  32921. Desktop& desktop = Desktop::getInstance();
  32922. int numMiceDown = 0;
  32923. for (int i = desktop.getNumMouseInputSources(); --i >= 0;)
  32924. {
  32925. MouseInputSource* const source = desktop.getMouseSource(i);
  32926. if (source->isDragging())
  32927. {
  32928. source->triggerFakeMove();
  32929. ++numMiceDown;
  32930. }
  32931. }
  32932. if (numMiceDown == 0)
  32933. deleteInstance();
  32934. }
  32935. juce_UseDebuggingNewOperator
  32936. private:
  32937. InternalDragRepeater (const InternalDragRepeater&);
  32938. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32939. };
  32940. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32941. void Component::beginDragAutoRepeat (const int interval)
  32942. {
  32943. if (interval > 0)
  32944. {
  32945. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32946. InternalDragRepeater::getInstance()->startTimer (interval);
  32947. }
  32948. else
  32949. {
  32950. InternalDragRepeater::deleteInstance();
  32951. }
  32952. }
  32953. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32954. {
  32955. Desktop& desktop = Desktop::getInstance();
  32956. const ComponentDeletionWatcher deletionChecker (this);
  32957. if (isCurrentlyBlockedByAnotherModalComponent())
  32958. {
  32959. internalModalInputAttempt();
  32960. if (deletionChecker.hasBeenDeleted())
  32961. return;
  32962. // If processing the input attempt has exited the modal loop, we'll allow the event
  32963. // to be delivered..
  32964. if (isCurrentlyBlockedByAnotherModalComponent())
  32965. {
  32966. // allow blocked mouse-events to go to global listeners..
  32967. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32968. this, time, relativePos, time,
  32969. source.getNumberOfMultipleClicks(), false);
  32970. desktop.resetTimer();
  32971. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  32972. {
  32973. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  32974. if (deletionChecker.hasBeenDeleted())
  32975. return;
  32976. i = jmin (i, desktop.mouseListeners.size());
  32977. }
  32978. return;
  32979. }
  32980. }
  32981. {
  32982. Component* c = this;
  32983. while (c != 0)
  32984. {
  32985. if (c->isBroughtToFrontOnMouseClick())
  32986. {
  32987. c->toFront (true);
  32988. if (deletionChecker.hasBeenDeleted())
  32989. return;
  32990. }
  32991. c = c->parentComponent_;
  32992. }
  32993. }
  32994. if (! flags.dontFocusOnMouseClickFlag)
  32995. grabFocusInternal (focusChangedByMouseClick);
  32996. if (! deletionChecker.hasBeenDeleted())
  32997. {
  32998. flags.draggingFlag = true;
  32999. flags.mouseOverFlag = true;
  33000. if (flags.repaintOnMouseActivityFlag)
  33001. repaint();
  33002. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  33003. this, time, relativePos, time,
  33004. source.getNumberOfMultipleClicks(), false);
  33005. mouseDown (me);
  33006. if (deletionChecker.hasBeenDeleted())
  33007. return;
  33008. desktop.resetTimer();
  33009. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33010. {
  33011. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  33012. if (deletionChecker.hasBeenDeleted())
  33013. return;
  33014. i = jmin (i, desktop.mouseListeners.size());
  33015. }
  33016. if (mouseListeners_ != 0)
  33017. {
  33018. for (int i = mouseListeners_->size(); --i >= 0;)
  33019. {
  33020. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  33021. if (deletionChecker.hasBeenDeleted())
  33022. return;
  33023. i = jmin (i, mouseListeners_->size());
  33024. }
  33025. }
  33026. const Component* p = parentComponent_;
  33027. while (p != 0)
  33028. {
  33029. const ComponentDeletionWatcher parentDeletionChecker (p);
  33030. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33031. {
  33032. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  33033. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33034. return;
  33035. i = jmin (i, p->numDeepMouseListeners);
  33036. }
  33037. p = p->parentComponent_;
  33038. }
  33039. }
  33040. }
  33041. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  33042. {
  33043. if (isValidComponent() && flags.draggingFlag)
  33044. {
  33045. Desktop& desktop = Desktop::getInstance();
  33046. flags.draggingFlag = false;
  33047. const ComponentDeletionWatcher deletionChecker (this);
  33048. if (flags.repaintOnMouseActivityFlag)
  33049. repaint();
  33050. const MouseEvent me (source, relativePos + unboundedMouseOffset,
  33051. oldModifiers, this, time,
  33052. globalPositionToRelative (source.getLastMouseDownPosition()),
  33053. source.getLastMouseDownTime(),
  33054. source.getNumberOfMultipleClicks(),
  33055. source.hasMouseMovedSignificantlySincePressed());
  33056. mouseUp (me);
  33057. if (deletionChecker.hasBeenDeleted())
  33058. return;
  33059. desktop.resetTimer();
  33060. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33061. {
  33062. ((MouseListener*) desktop.mouseListeners[i])->mouseUp (me);
  33063. if (deletionChecker.hasBeenDeleted())
  33064. return;
  33065. i = jmin (i, desktop.mouseListeners.size());
  33066. }
  33067. if (mouseListeners_ != 0)
  33068. {
  33069. for (int i = mouseListeners_->size(); --i >= 0;)
  33070. {
  33071. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  33072. if (deletionChecker.hasBeenDeleted())
  33073. return;
  33074. i = jmin (i, mouseListeners_->size());
  33075. }
  33076. }
  33077. {
  33078. const Component* p = parentComponent_;
  33079. while (p != 0)
  33080. {
  33081. const ComponentDeletionWatcher parentDeletionChecker (p);
  33082. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33083. {
  33084. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  33085. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33086. return;
  33087. i = jmin (i, p->numDeepMouseListeners);
  33088. }
  33089. p = p->parentComponent_;
  33090. }
  33091. }
  33092. // check for double-click
  33093. if (me.getNumberOfClicks() >= 2)
  33094. {
  33095. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  33096. mouseDoubleClick (me);
  33097. int i;
  33098. for (i = desktop.mouseListeners.size(); --i >= 0;)
  33099. {
  33100. ((MouseListener*) desktop.mouseListeners[i])->mouseDoubleClick (me);
  33101. if (deletionChecker.hasBeenDeleted())
  33102. return;
  33103. i = jmin (i, desktop.mouseListeners.size());
  33104. }
  33105. for (i = numListeners; --i >= 0;)
  33106. {
  33107. if (deletionChecker.hasBeenDeleted() || mouseListeners_ == 0)
  33108. return;
  33109. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  33110. if (ml != 0)
  33111. ml->mouseDoubleClick (me);
  33112. }
  33113. if (deletionChecker.hasBeenDeleted())
  33114. return;
  33115. const Component* p = parentComponent_;
  33116. while (p != 0)
  33117. {
  33118. const ComponentDeletionWatcher parentDeletionChecker (p);
  33119. for (i = p->numDeepMouseListeners; --i >= 0;)
  33120. {
  33121. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  33122. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33123. return;
  33124. i = jmin (i, p->numDeepMouseListeners);
  33125. }
  33126. p = p->parentComponent_;
  33127. }
  33128. }
  33129. }
  33130. enableUnboundedMouseMovement (false);
  33131. }
  33132. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  33133. {
  33134. if (isValidComponent() && flags.draggingFlag)
  33135. {
  33136. Desktop& desktop = Desktop::getInstance();
  33137. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  33138. const ComponentDeletionWatcher deletionChecker (this);
  33139. const MouseEvent me (source, relativePos + unboundedMouseOffset,
  33140. source.getCurrentModifiers(), this, time,
  33141. globalPositionToRelative (source.getLastMouseDownPosition()),
  33142. source.getLastMouseDownTime(),
  33143. source.getNumberOfMultipleClicks(),
  33144. source.hasMouseMovedSignificantlySincePressed());
  33145. mouseDrag (me);
  33146. if (deletionChecker.hasBeenDeleted())
  33147. return;
  33148. desktop.resetTimer();
  33149. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33150. {
  33151. ((MouseListener*) desktop.mouseListeners[i])->mouseDrag (me);
  33152. if (deletionChecker.hasBeenDeleted())
  33153. return;
  33154. i = jmin (i, desktop.mouseListeners.size());
  33155. }
  33156. if (mouseListeners_ != 0)
  33157. {
  33158. for (int i = mouseListeners_->size(); --i >= 0;)
  33159. {
  33160. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  33161. if (deletionChecker.hasBeenDeleted())
  33162. return;
  33163. i = jmin (i, mouseListeners_->size());
  33164. }
  33165. }
  33166. const Component* p = parentComponent_;
  33167. while (p != 0)
  33168. {
  33169. const ComponentDeletionWatcher parentDeletionChecker (p);
  33170. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33171. {
  33172. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  33173. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33174. return;
  33175. i = jmin (i, p->numDeepMouseListeners);
  33176. }
  33177. p = p->parentComponent_;
  33178. }
  33179. if (this == componentUnderMouse)
  33180. {
  33181. if (isUnboundedMouseModeOn)
  33182. {
  33183. const Rectangle<int> screenArea (getParentMonitorArea().expanded (-2, -2));
  33184. Point<int> mousePos (source.getScreenPosition());
  33185. if (! screenArea.contains (mousePos))
  33186. {
  33187. int deltaX = 0, deltaY = 0;
  33188. if (mousePos.getX() <= screenArea.getX() || mousePos.getX() >= screenArea.getRight())
  33189. deltaX = getScreenX() + getWidth() / 2 - mousePos.getX();
  33190. if (mousePos.getY() <= screenArea.getY() || mousePos.getY() >= screenArea.getBottom())
  33191. deltaY = getScreenY() + getHeight() / 2 - mousePos.getY();
  33192. unboundedMouseOffset -= Point<int> (deltaX, deltaY);
  33193. Desktop::setMousePosition (mousePos + Point<int> (deltaX, deltaY));
  33194. }
  33195. else if (isCursorVisibleUntilOffscreen
  33196. && (! unboundedMouseOffset.isOrigin())
  33197. && screenArea.contains (mousePos + unboundedMouseOffset))
  33198. {
  33199. mousePos += unboundedMouseOffset;
  33200. unboundedMouseOffset = Point<int>();
  33201. Desktop::setMousePosition (mousePos);
  33202. }
  33203. }
  33204. internalUpdateMouseCursor (false);
  33205. }
  33206. }
  33207. }
  33208. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  33209. {
  33210. const ComponentDeletionWatcher deletionChecker (this);
  33211. if (isValidComponent())
  33212. {
  33213. Desktop& desktop = Desktop::getInstance();
  33214. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  33215. this, time, relativePos,
  33216. time, 0, false);
  33217. if (isCurrentlyBlockedByAnotherModalComponent())
  33218. {
  33219. // allow blocked mouse-events to go to global listeners..
  33220. desktop.sendMouseMove();
  33221. }
  33222. else
  33223. {
  33224. if (this == componentUnderMouse)
  33225. internalUpdateMouseCursor (false);
  33226. flags.mouseOverFlag = true;
  33227. mouseMove (me);
  33228. if (deletionChecker.hasBeenDeleted())
  33229. return;
  33230. desktop.resetTimer();
  33231. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33232. {
  33233. ((MouseListener*) desktop.mouseListeners[i])->mouseMove (me);
  33234. if (deletionChecker.hasBeenDeleted())
  33235. return;
  33236. i = jmin (i, desktop.mouseListeners.size());
  33237. }
  33238. if (mouseListeners_ != 0)
  33239. {
  33240. for (int i = mouseListeners_->size(); --i >= 0;)
  33241. {
  33242. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33243. if (deletionChecker.hasBeenDeleted())
  33244. return;
  33245. i = jmin (i, mouseListeners_->size());
  33246. }
  33247. }
  33248. const Component* p = parentComponent_;
  33249. while (p != 0)
  33250. {
  33251. const ComponentDeletionWatcher parentDeletionChecker (p);
  33252. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33253. {
  33254. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33255. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33256. return;
  33257. i = jmin (i, p->numDeepMouseListeners);
  33258. }
  33259. p = p->parentComponent_;
  33260. }
  33261. }
  33262. }
  33263. }
  33264. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  33265. const Time& time, const float amountX, const float amountY)
  33266. {
  33267. Desktop& desktop = Desktop::getInstance();
  33268. const ComponentDeletionWatcher deletionChecker (this);
  33269. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  33270. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  33271. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  33272. this, time, relativePos, time, 0, false);
  33273. if (isCurrentlyBlockedByAnotherModalComponent())
  33274. {
  33275. // allow blocked mouse-events to go to global listeners..
  33276. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33277. {
  33278. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33279. if (deletionChecker.hasBeenDeleted())
  33280. return;
  33281. i = jmin (i, desktop.mouseListeners.size());
  33282. }
  33283. }
  33284. else
  33285. {
  33286. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33287. if (deletionChecker.hasBeenDeleted())
  33288. return;
  33289. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33290. {
  33291. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33292. if (deletionChecker.hasBeenDeleted())
  33293. return;
  33294. i = jmin (i, desktop.mouseListeners.size());
  33295. }
  33296. if (mouseListeners_ != 0)
  33297. {
  33298. for (int i = mouseListeners_->size(); --i >= 0;)
  33299. {
  33300. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33301. if (deletionChecker.hasBeenDeleted())
  33302. return;
  33303. i = jmin (i, mouseListeners_->size());
  33304. }
  33305. }
  33306. const Component* p = parentComponent_;
  33307. while (p != 0)
  33308. {
  33309. const ComponentDeletionWatcher parentDeletionChecker (p);
  33310. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33311. {
  33312. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33313. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33314. return;
  33315. i = jmin (i, p->numDeepMouseListeners);
  33316. }
  33317. p = p->parentComponent_;
  33318. }
  33319. }
  33320. }
  33321. void Component::sendFakeMouseMove() const
  33322. {
  33323. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  33324. }
  33325. void Component::broughtToFront()
  33326. {
  33327. }
  33328. void Component::internalBroughtToFront()
  33329. {
  33330. if (isValidComponent())
  33331. {
  33332. if (flags.hasHeavyweightPeerFlag)
  33333. Desktop::getInstance().componentBroughtToFront (this);
  33334. const ComponentDeletionWatcher deletionChecker (this);
  33335. broughtToFront();
  33336. if (deletionChecker.hasBeenDeleted())
  33337. return;
  33338. if (componentListeners_ != 0)
  33339. {
  33340. for (int i = componentListeners_->size(); --i >= 0;)
  33341. {
  33342. ((ComponentListener*) componentListeners_->getUnchecked (i))
  33343. ->componentBroughtToFront (*this);
  33344. if (deletionChecker.hasBeenDeleted())
  33345. return;
  33346. i = jmin (i, componentListeners_->size());
  33347. }
  33348. }
  33349. // when brought to the front and there's a modal component blocking this one,
  33350. // we need to bring the modal one to the front instead..
  33351. Component* const cm = getCurrentlyModalComponent();
  33352. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33353. bringModalComponentToFront();
  33354. }
  33355. }
  33356. void Component::focusGained (FocusChangeType)
  33357. {
  33358. // base class does nothing
  33359. }
  33360. void Component::internalFocusGain (const FocusChangeType cause)
  33361. {
  33362. const ComponentDeletionWatcher deletionChecker (this);
  33363. focusGained (cause);
  33364. if (! deletionChecker.hasBeenDeleted())
  33365. internalChildFocusChange (cause);
  33366. }
  33367. void Component::focusLost (FocusChangeType)
  33368. {
  33369. // base class does nothing
  33370. }
  33371. void Component::internalFocusLoss (const FocusChangeType cause)
  33372. {
  33373. const ComponentDeletionWatcher deletionChecker (this);
  33374. focusLost (focusChangedDirectly);
  33375. if (! deletionChecker.hasBeenDeleted())
  33376. internalChildFocusChange (cause);
  33377. }
  33378. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33379. {
  33380. // base class does nothing
  33381. }
  33382. void Component::internalChildFocusChange (FocusChangeType cause)
  33383. {
  33384. const bool childIsNowFocused = hasKeyboardFocus (true);
  33385. if (flags.childCompFocusedFlag != childIsNowFocused)
  33386. {
  33387. flags.childCompFocusedFlag = childIsNowFocused;
  33388. const ComponentDeletionWatcher deletionChecker (this);
  33389. focusOfChildComponentChanged (cause);
  33390. if (deletionChecker.hasBeenDeleted())
  33391. return;
  33392. }
  33393. if (parentComponent_ != 0)
  33394. parentComponent_->internalChildFocusChange (cause);
  33395. }
  33396. bool Component::isEnabled() const throw()
  33397. {
  33398. return (! flags.isDisabledFlag)
  33399. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33400. }
  33401. void Component::setEnabled (const bool shouldBeEnabled)
  33402. {
  33403. if (flags.isDisabledFlag == shouldBeEnabled)
  33404. {
  33405. flags.isDisabledFlag = ! shouldBeEnabled;
  33406. // if any parent components are disabled, setting our flag won't make a difference,
  33407. // so no need to send a change message
  33408. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33409. sendEnablementChangeMessage();
  33410. }
  33411. }
  33412. void Component::sendEnablementChangeMessage()
  33413. {
  33414. const ComponentDeletionWatcher deletionChecker (this);
  33415. enablementChanged();
  33416. if (deletionChecker.hasBeenDeleted())
  33417. return;
  33418. for (int i = getNumChildComponents(); --i >= 0;)
  33419. {
  33420. Component* const c = getChildComponent (i);
  33421. if (c != 0)
  33422. {
  33423. c->sendEnablementChangeMessage();
  33424. if (deletionChecker.hasBeenDeleted())
  33425. return;
  33426. }
  33427. }
  33428. }
  33429. void Component::enablementChanged()
  33430. {
  33431. }
  33432. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33433. {
  33434. flags.wantsFocusFlag = wantsFocus;
  33435. }
  33436. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33437. {
  33438. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33439. }
  33440. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33441. {
  33442. return ! flags.dontFocusOnMouseClickFlag;
  33443. }
  33444. bool Component::getWantsKeyboardFocus() const throw()
  33445. {
  33446. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33447. }
  33448. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33449. {
  33450. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33451. }
  33452. bool Component::isFocusContainer() const throw()
  33453. {
  33454. return flags.isFocusContainerFlag;
  33455. }
  33456. int Component::getExplicitFocusOrder() const throw()
  33457. {
  33458. return properties ["_jexfo"];
  33459. }
  33460. void Component::setExplicitFocusOrder (const int newFocusOrderIndex) throw()
  33461. {
  33462. properties.set ("_jexfo", newFocusOrderIndex);
  33463. }
  33464. KeyboardFocusTraverser* Component::createFocusTraverser()
  33465. {
  33466. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33467. return new KeyboardFocusTraverser();
  33468. return parentComponent_->createFocusTraverser();
  33469. }
  33470. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33471. {
  33472. // give the focus to this component
  33473. if (currentlyFocusedComponent != this)
  33474. {
  33475. JUCE_TRY
  33476. {
  33477. // get the focus onto our desktop window
  33478. ComponentPeer* const peer = getPeer();
  33479. if (peer != 0)
  33480. {
  33481. const ComponentDeletionWatcher deletionChecker (this);
  33482. peer->grabFocus();
  33483. if (peer->isFocused() && currentlyFocusedComponent != this)
  33484. {
  33485. Component* const componentLosingFocus = currentlyFocusedComponent;
  33486. currentlyFocusedComponent = this;
  33487. Desktop::getInstance().triggerFocusCallback();
  33488. // call this after setting currentlyFocusedComponent so that the one that's
  33489. // losing it has a chance to see where focus is going
  33490. if (componentLosingFocus->isValidComponent())
  33491. componentLosingFocus->internalFocusLoss (cause);
  33492. if (currentlyFocusedComponent == this)
  33493. {
  33494. focusGained (cause);
  33495. if (! deletionChecker.hasBeenDeleted())
  33496. internalChildFocusChange (cause);
  33497. }
  33498. }
  33499. }
  33500. }
  33501. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33502. catch (const std::exception& e)
  33503. {
  33504. currentlyFocusedComponent = 0;
  33505. Desktop::getInstance().triggerFocusCallback();
  33506. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33507. }
  33508. catch (...)
  33509. {
  33510. currentlyFocusedComponent = 0;
  33511. Desktop::getInstance().triggerFocusCallback();
  33512. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33513. }
  33514. #endif
  33515. }
  33516. }
  33517. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33518. {
  33519. if (isShowing())
  33520. {
  33521. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33522. {
  33523. takeKeyboardFocus (cause);
  33524. }
  33525. else
  33526. {
  33527. if (isParentOf (currentlyFocusedComponent)
  33528. && currentlyFocusedComponent->isShowing())
  33529. {
  33530. // do nothing if the focused component is actually a child of ours..
  33531. }
  33532. else
  33533. {
  33534. // find the default child component..
  33535. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33536. if (traverser != 0)
  33537. {
  33538. Component* const defaultComp = traverser->getDefaultComponent (this);
  33539. traverser = 0;
  33540. if (defaultComp != 0)
  33541. {
  33542. defaultComp->grabFocusInternal (cause, false);
  33543. return;
  33544. }
  33545. }
  33546. if (canTryParent && parentComponent_ != 0)
  33547. {
  33548. // if no children want it and we're allowed to try our parent comp,
  33549. // then pass up to parent, which will try our siblings.
  33550. parentComponent_->grabFocusInternal (cause, true);
  33551. }
  33552. }
  33553. }
  33554. }
  33555. }
  33556. void Component::grabKeyboardFocus()
  33557. {
  33558. // if component methods are being called from threads other than the message
  33559. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33560. checkMessageManagerIsLocked
  33561. grabFocusInternal (focusChangedDirectly);
  33562. }
  33563. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33564. {
  33565. // if component methods are being called from threads other than the message
  33566. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33567. checkMessageManagerIsLocked
  33568. if (parentComponent_ != 0)
  33569. {
  33570. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33571. if (traverser != 0)
  33572. {
  33573. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33574. : traverser->getPreviousComponent (this);
  33575. traverser = 0;
  33576. if (nextComp != 0)
  33577. {
  33578. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33579. {
  33580. const ComponentDeletionWatcher deletionChecker (nextComp);
  33581. internalModalInputAttempt();
  33582. if (deletionChecker.hasBeenDeleted()
  33583. || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33584. return;
  33585. }
  33586. nextComp->grabFocusInternal (focusChangedByTabKey);
  33587. return;
  33588. }
  33589. }
  33590. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33591. }
  33592. }
  33593. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const throw()
  33594. {
  33595. return (currentlyFocusedComponent == this)
  33596. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33597. }
  33598. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33599. {
  33600. return currentlyFocusedComponent;
  33601. }
  33602. void Component::giveAwayFocus()
  33603. {
  33604. // use a copy so we can clear the value before the call
  33605. Component* const componentLosingFocus = currentlyFocusedComponent;
  33606. currentlyFocusedComponent = 0;
  33607. Desktop::getInstance().triggerFocusCallback();
  33608. if (componentLosingFocus->isValidComponent())
  33609. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33610. }
  33611. bool Component::isMouseOver() const throw()
  33612. {
  33613. return flags.mouseOverFlag;
  33614. }
  33615. bool Component::isMouseButtonDown() const throw()
  33616. {
  33617. return flags.draggingFlag;
  33618. }
  33619. bool Component::isMouseOverOrDragging() const throw()
  33620. {
  33621. return flags.mouseOverFlag || flags.draggingFlag;
  33622. }
  33623. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33624. {
  33625. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33626. }
  33627. const Point<int> Component::getMouseXYRelative() const
  33628. {
  33629. return globalPositionToRelative (Desktop::getMousePosition()) + unboundedMouseOffset;
  33630. }
  33631. void Component::enableUnboundedMouseMovement (bool enable,
  33632. bool keepCursorVisibleUntilOffscreen) throw()
  33633. {
  33634. enable = enable && isMouseButtonDown();
  33635. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  33636. if (enable != isUnboundedMouseModeOn)
  33637. {
  33638. if ((! enable) && ((! isCursorVisibleUntilOffscreen)
  33639. || ! unboundedMouseOffset.isOrigin()))
  33640. {
  33641. // when released, return the mouse to within the component's bounds
  33642. Desktop::setMousePosition (relativePositionToGlobal (Rectangle<int> (0, 0, getWidth(), getHeight())
  33643. .getConstrainedPoint (getMouseXYRelative())));
  33644. }
  33645. isUnboundedMouseModeOn = enable;
  33646. unboundedMouseOffset = Point<int>();
  33647. internalUpdateMouseCursor (true);
  33648. }
  33649. }
  33650. Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw()
  33651. {
  33652. return componentUnderMouse;
  33653. }
  33654. const Rectangle<int> Component::getParentMonitorArea() const throw()
  33655. {
  33656. return Desktop::getInstance()
  33657. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33658. getHeight() / 2)));
  33659. }
  33660. void Component::addKeyListener (KeyListener* const newListener) throw()
  33661. {
  33662. if (keyListeners_ == 0)
  33663. keyListeners_ = new VoidArray();
  33664. keyListeners_->addIfNotAlreadyThere (newListener);
  33665. }
  33666. void Component::removeKeyListener (KeyListener* const listenerToRemove) throw()
  33667. {
  33668. if (keyListeners_ != 0)
  33669. keyListeners_->removeValue (listenerToRemove);
  33670. }
  33671. bool Component::keyPressed (const KeyPress&)
  33672. {
  33673. return false;
  33674. }
  33675. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33676. {
  33677. return false;
  33678. }
  33679. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33680. {
  33681. if (parentComponent_ != 0)
  33682. parentComponent_->modifierKeysChanged (modifiers);
  33683. }
  33684. void Component::internalModifierKeysChanged()
  33685. {
  33686. sendFakeMouseMove();
  33687. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33688. }
  33689. ComponentPeer* Component::getPeer() const throw()
  33690. {
  33691. if (flags.hasHeavyweightPeerFlag)
  33692. return ComponentPeer::getPeerFor (this);
  33693. else if (parentComponent_ != 0)
  33694. return parentComponent_->getPeer();
  33695. else
  33696. return 0;
  33697. }
  33698. ComponentDeletionWatcher::ComponentDeletionWatcher (const Component* const componentToWatch_) throw()
  33699. : componentToWatch (componentToWatch_),
  33700. componentUID (componentToWatch_->getComponentUID())
  33701. {
  33702. // not possible to check on an already-deleted object..
  33703. jassert (componentToWatch_->isValidComponent());
  33704. }
  33705. ComponentDeletionWatcher::~ComponentDeletionWatcher() throw() {}
  33706. bool ComponentDeletionWatcher::hasBeenDeleted() const throw()
  33707. {
  33708. return ! (componentToWatch->isValidComponent()
  33709. && componentToWatch->getComponentUID() == componentUID);
  33710. }
  33711. const Component* ComponentDeletionWatcher::getComponent() const throw()
  33712. {
  33713. return hasBeenDeleted() ? 0 : componentToWatch;
  33714. }
  33715. END_JUCE_NAMESPACE
  33716. /*** End of inlined file: juce_Component.cpp ***/
  33717. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33718. BEGIN_JUCE_NAMESPACE
  33719. void ComponentListener::componentMovedOrResized (Component&, bool, bool)
  33720. {
  33721. }
  33722. void ComponentListener::componentBroughtToFront (Component&)
  33723. {
  33724. }
  33725. void ComponentListener::componentVisibilityChanged (Component&)
  33726. {
  33727. }
  33728. void ComponentListener::componentChildrenChanged (Component&)
  33729. {
  33730. }
  33731. void ComponentListener::componentParentHierarchyChanged (Component&)
  33732. {
  33733. }
  33734. void ComponentListener::componentNameChanged (Component&)
  33735. {
  33736. }
  33737. END_JUCE_NAMESPACE
  33738. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33739. /*** Start of inlined file: juce_Desktop.cpp ***/
  33740. BEGIN_JUCE_NAMESPACE
  33741. Desktop::Desktop() throw()
  33742. : mouseClickCounter (0),
  33743. kioskModeComponent (0)
  33744. {
  33745. const int maxNumMice = 1;
  33746. for (int i = maxNumMice; --i >= 0;)
  33747. mouseSources.add (new MouseInputSource (i, true));
  33748. refreshMonitorSizes();
  33749. }
  33750. Desktop::~Desktop() throw()
  33751. {
  33752. jassert (instance == this);
  33753. instance = 0;
  33754. // doh! If you don't delete all your windows before exiting, you're going to
  33755. // be leaking memory!
  33756. jassert (desktopComponents.size() == 0);
  33757. }
  33758. Desktop& JUCE_CALLTYPE Desktop::getInstance() throw()
  33759. {
  33760. if (instance == 0)
  33761. instance = new Desktop();
  33762. return *instance;
  33763. }
  33764. Desktop* Desktop::instance = 0;
  33765. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33766. const bool clipToWorkArea);
  33767. void Desktop::refreshMonitorSizes() throw()
  33768. {
  33769. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33770. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33771. monitorCoordsClipped.clear();
  33772. monitorCoordsUnclipped.clear();
  33773. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33774. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33775. jassert (monitorCoordsClipped.size() > 0
  33776. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33777. if (oldClipped != monitorCoordsClipped
  33778. || oldUnclipped != monitorCoordsUnclipped)
  33779. {
  33780. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33781. {
  33782. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33783. if (p != 0)
  33784. p->handleScreenSizeChange();
  33785. }
  33786. }
  33787. }
  33788. int Desktop::getNumDisplayMonitors() const throw()
  33789. {
  33790. return monitorCoordsClipped.size();
  33791. }
  33792. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33793. {
  33794. return clippedToWorkArea ? monitorCoordsClipped [index]
  33795. : monitorCoordsUnclipped [index];
  33796. }
  33797. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33798. {
  33799. RectangleList rl;
  33800. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33801. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33802. return rl;
  33803. }
  33804. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33805. {
  33806. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33807. }
  33808. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const throw()
  33809. {
  33810. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33811. double bestDistance = 1.0e10;
  33812. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33813. {
  33814. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33815. if (rect.contains (position))
  33816. return rect;
  33817. const double distance = rect.getCentre().getDistanceFrom (position);
  33818. if (distance < bestDistance)
  33819. {
  33820. bestDistance = distance;
  33821. best = rect;
  33822. }
  33823. }
  33824. return best;
  33825. }
  33826. int Desktop::getNumComponents() const throw()
  33827. {
  33828. return desktopComponents.size();
  33829. }
  33830. Component* Desktop::getComponent (const int index) const throw()
  33831. {
  33832. return desktopComponents [index];
  33833. }
  33834. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33835. {
  33836. for (int i = desktopComponents.size(); --i >= 0;)
  33837. {
  33838. Component* const c = desktopComponents.getUnchecked(i);
  33839. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33840. if (c->contains (relative.getX(), relative.getY()))
  33841. return c->getComponentAt (relative.getX(), relative.getY());
  33842. }
  33843. return 0;
  33844. }
  33845. void Desktop::addDesktopComponent (Component* const c) throw()
  33846. {
  33847. jassert (c != 0);
  33848. jassert (! desktopComponents.contains (c));
  33849. desktopComponents.addIfNotAlreadyThere (c);
  33850. }
  33851. void Desktop::removeDesktopComponent (Component* const c) throw()
  33852. {
  33853. desktopComponents.removeValue (c);
  33854. }
  33855. void Desktop::componentBroughtToFront (Component* const c) throw()
  33856. {
  33857. const int index = desktopComponents.indexOf (c);
  33858. jassert (index >= 0);
  33859. if (index >= 0)
  33860. {
  33861. int newIndex = -1;
  33862. if (! c->isAlwaysOnTop())
  33863. {
  33864. newIndex = desktopComponents.size();
  33865. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33866. --newIndex;
  33867. --newIndex;
  33868. }
  33869. desktopComponents.move (index, newIndex);
  33870. }
  33871. }
  33872. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33873. {
  33874. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33875. }
  33876. int Desktop::getMouseButtonClickCounter() throw()
  33877. {
  33878. return getInstance().mouseClickCounter;
  33879. }
  33880. void Desktop::incrementMouseClickCounter() throw()
  33881. {
  33882. ++mouseClickCounter;
  33883. }
  33884. void Desktop::addGlobalMouseListener (MouseListener* const listener) throw()
  33885. {
  33886. jassert (listener != 0);
  33887. if (listener != 0)
  33888. {
  33889. mouseListeners.add (listener);
  33890. resetTimer();
  33891. }
  33892. }
  33893. void Desktop::removeGlobalMouseListener (MouseListener* const listener) throw()
  33894. {
  33895. mouseListeners.removeValue (listener);
  33896. resetTimer();
  33897. }
  33898. void Desktop::addFocusChangeListener (FocusChangeListener* const listener) throw()
  33899. {
  33900. jassert (listener != 0);
  33901. if (listener != 0)
  33902. focusListeners.add (listener);
  33903. }
  33904. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) throw()
  33905. {
  33906. focusListeners.removeValue (listener);
  33907. }
  33908. void Desktop::triggerFocusCallback() throw()
  33909. {
  33910. triggerAsyncUpdate();
  33911. }
  33912. void Desktop::handleAsyncUpdate()
  33913. {
  33914. for (int i = focusListeners.size(); --i >= 0;)
  33915. {
  33916. ((FocusChangeListener*) focusListeners.getUnchecked (i))->globalFocusChanged (Component::getCurrentlyFocusedComponent());
  33917. i = jmin (i, focusListeners.size());
  33918. }
  33919. }
  33920. void Desktop::timerCallback()
  33921. {
  33922. if (lastFakeMouseMove != getMousePosition())
  33923. sendMouseMove();
  33924. }
  33925. void Desktop::sendMouseMove()
  33926. {
  33927. if (mouseListeners.size() > 0)
  33928. {
  33929. startTimer (20);
  33930. lastFakeMouseMove = getMousePosition();
  33931. Component* const target = findComponentAt (lastFakeMouseMove);
  33932. if (target != 0)
  33933. {
  33934. ComponentDeletionWatcher deletionChecker (target);
  33935. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33936. const Time now (Time::getCurrentTime());
  33937. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33938. target, now, pos, now, 0, false);
  33939. for (int i = mouseListeners.size(); --i >= 0;)
  33940. {
  33941. if (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  33942. ((MouseListener*) mouseListeners[i])->mouseDrag (me);
  33943. else
  33944. ((MouseListener*) mouseListeners[i])->mouseMove (me);
  33945. if (deletionChecker.hasBeenDeleted())
  33946. return;
  33947. i = jmin (i, mouseListeners.size());
  33948. }
  33949. }
  33950. }
  33951. }
  33952. void Desktop::resetTimer() throw()
  33953. {
  33954. if (mouseListeners.size() == 0)
  33955. stopTimer();
  33956. else
  33957. startTimer (100);
  33958. lastFakeMouseMove = getMousePosition();
  33959. }
  33960. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33961. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33962. {
  33963. if (kioskModeComponent != componentToUse)
  33964. {
  33965. // agh! Don't delete a component without first stopping it being the kiosk comp
  33966. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33967. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33968. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33969. if (kioskModeComponent->isValidComponent())
  33970. {
  33971. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33972. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33973. }
  33974. kioskModeComponent = componentToUse;
  33975. if (kioskModeComponent != 0)
  33976. {
  33977. jassert (kioskModeComponent->isValidComponent());
  33978. // Only components that are already on the desktop can be put into kiosk mode!
  33979. jassert (kioskModeComponent->isOnDesktop());
  33980. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33981. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33982. }
  33983. }
  33984. }
  33985. END_JUCE_NAMESPACE
  33986. /*** End of inlined file: juce_Desktop.cpp ***/
  33987. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33988. BEGIN_JUCE_NAMESPACE
  33989. ArrowButton::ArrowButton (const String& name,
  33990. float arrowDirectionInRadians,
  33991. const Colour& arrowColour)
  33992. : Button (name),
  33993. colour (arrowColour)
  33994. {
  33995. path.lineTo (0.0f, 1.0f);
  33996. path.lineTo (1.0f, 0.5f);
  33997. path.closeSubPath();
  33998. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33999. 0.5f, 0.5f));
  34000. setComponentEffect (&shadow);
  34001. buttonStateChanged();
  34002. }
  34003. ArrowButton::~ArrowButton()
  34004. {
  34005. }
  34006. void ArrowButton::paintButton (Graphics& g,
  34007. bool /*isMouseOverButton*/,
  34008. bool /*isButtonDown*/)
  34009. {
  34010. g.setColour (colour);
  34011. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  34012. (float) offset,
  34013. (float) (getWidth() - 3),
  34014. (float) (getHeight() - 3),
  34015. false));
  34016. }
  34017. void ArrowButton::buttonStateChanged()
  34018. {
  34019. offset = (isDown()) ? 1 : 0;
  34020. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  34021. 0.3f, -1, 0);
  34022. }
  34023. END_JUCE_NAMESPACE
  34024. /*** End of inlined file: juce_ArrowButton.cpp ***/
  34025. /*** Start of inlined file: juce_Button.cpp ***/
  34026. BEGIN_JUCE_NAMESPACE
  34027. class Button::RepeatTimer : public Timer
  34028. {
  34029. public:
  34030. RepeatTimer (Button& owner_) : owner (owner_) {}
  34031. void timerCallback() { owner.repeatTimerCallback(); }
  34032. juce_UseDebuggingNewOperator
  34033. private:
  34034. Button& owner;
  34035. RepeatTimer (const RepeatTimer&);
  34036. RepeatTimer& operator= (const RepeatTimer&);
  34037. };
  34038. Button::Button (const String& name)
  34039. : Component (name),
  34040. keySource (0),
  34041. text (name),
  34042. buttonPressTime (0),
  34043. lastTimeCallbackTime (0),
  34044. commandManagerToUse (0),
  34045. autoRepeatDelay (-1),
  34046. autoRepeatSpeed (0),
  34047. autoRepeatMinimumDelay (-1),
  34048. radioGroupId (0),
  34049. commandID (0),
  34050. connectedEdgeFlags (0),
  34051. buttonState (buttonNormal),
  34052. lastToggleState (false),
  34053. clickTogglesState (false),
  34054. needsToRelease (false),
  34055. needsRepainting (false),
  34056. isKeyDown (false),
  34057. triggerOnMouseDown (false),
  34058. generateTooltip (false)
  34059. {
  34060. setWantsKeyboardFocus (true);
  34061. isOn.addListener (this);
  34062. }
  34063. Button::~Button()
  34064. {
  34065. isOn.removeListener (this);
  34066. if (commandManagerToUse != 0)
  34067. commandManagerToUse->removeListener (this);
  34068. repeatTimer = 0;
  34069. clearShortcuts();
  34070. }
  34071. void Button::setButtonText (const String& newText)
  34072. {
  34073. if (text != newText)
  34074. {
  34075. text = newText;
  34076. repaint();
  34077. }
  34078. }
  34079. void Button::setTooltip (const String& newTooltip)
  34080. {
  34081. SettableTooltipClient::setTooltip (newTooltip);
  34082. generateTooltip = false;
  34083. }
  34084. const String Button::getTooltip()
  34085. {
  34086. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  34087. {
  34088. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  34089. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  34090. for (int i = 0; i < keyPresses.size(); ++i)
  34091. {
  34092. const String key (keyPresses.getReference(i).getTextDescription());
  34093. tt << " [";
  34094. if (key.length() == 1)
  34095. tt << TRANS("shortcut") << ": '" << key << "']";
  34096. else
  34097. tt << key << ']';
  34098. }
  34099. return tt;
  34100. }
  34101. return SettableTooltipClient::getTooltip();
  34102. }
  34103. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  34104. {
  34105. if (connectedEdgeFlags != connectedEdgeFlags_)
  34106. {
  34107. connectedEdgeFlags = connectedEdgeFlags_;
  34108. repaint();
  34109. }
  34110. }
  34111. void Button::setToggleState (const bool shouldBeOn,
  34112. const bool sendChangeNotification)
  34113. {
  34114. if (shouldBeOn != lastToggleState)
  34115. {
  34116. const ComponentDeletionWatcher deletionWatcher (this);
  34117. isOn = shouldBeOn;
  34118. lastToggleState = shouldBeOn;
  34119. repaint();
  34120. if (sendChangeNotification)
  34121. sendClickMessage (ModifierKeys());
  34122. if ((! deletionWatcher.hasBeenDeleted()) && lastToggleState)
  34123. turnOffOtherButtonsInGroup (sendChangeNotification);
  34124. }
  34125. }
  34126. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  34127. {
  34128. clickTogglesState = shouldToggle;
  34129. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34130. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34131. // it is that this button represents, and the button will update its state to reflect this
  34132. // in the applicationCommandListChanged() method.
  34133. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34134. }
  34135. bool Button::getClickingTogglesState() const throw()
  34136. {
  34137. return clickTogglesState;
  34138. }
  34139. void Button::valueChanged (Value& value)
  34140. {
  34141. if (value.refersToSameSourceAs (isOn))
  34142. setToggleState (isOn.getValue(), true);
  34143. }
  34144. void Button::setRadioGroupId (const int newGroupId)
  34145. {
  34146. if (radioGroupId != newGroupId)
  34147. {
  34148. radioGroupId = newGroupId;
  34149. if (lastToggleState)
  34150. turnOffOtherButtonsInGroup (true);
  34151. }
  34152. }
  34153. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  34154. {
  34155. Component* const p = getParentComponent();
  34156. if (p != 0 && radioGroupId != 0)
  34157. {
  34158. const ComponentDeletionWatcher deletionWatcher (this);
  34159. for (int i = p->getNumChildComponents(); --i >= 0;)
  34160. {
  34161. Component* const c = p->getChildComponent (i);
  34162. if (c != this)
  34163. {
  34164. Button* const b = dynamic_cast <Button*> (c);
  34165. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  34166. {
  34167. b->setToggleState (false, sendChangeNotification);
  34168. if (deletionWatcher.hasBeenDeleted())
  34169. return;
  34170. }
  34171. }
  34172. }
  34173. }
  34174. }
  34175. void Button::enablementChanged()
  34176. {
  34177. updateState (0);
  34178. repaint();
  34179. }
  34180. Button::ButtonState Button::updateState (const MouseEvent* const e)
  34181. {
  34182. ButtonState state = buttonNormal;
  34183. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  34184. {
  34185. Point<int> mousePos;
  34186. if (e == 0)
  34187. mousePos = getMouseXYRelative();
  34188. else
  34189. mousePos = e->getEventRelativeTo (this).getPosition();
  34190. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  34191. const bool down = isMouseButtonDown();
  34192. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  34193. state = buttonDown;
  34194. else if (over)
  34195. state = buttonOver;
  34196. }
  34197. setState (state);
  34198. return state;
  34199. }
  34200. void Button::setState (const ButtonState newState)
  34201. {
  34202. if (buttonState != newState)
  34203. {
  34204. buttonState = newState;
  34205. repaint();
  34206. if (buttonState == buttonDown)
  34207. {
  34208. buttonPressTime = Time::getApproximateMillisecondCounter();
  34209. lastTimeCallbackTime = buttonPressTime;
  34210. }
  34211. sendStateMessage();
  34212. }
  34213. }
  34214. bool Button::isDown() const throw()
  34215. {
  34216. return buttonState == buttonDown;
  34217. }
  34218. bool Button::isOver() const throw()
  34219. {
  34220. return buttonState != buttonNormal;
  34221. }
  34222. void Button::buttonStateChanged()
  34223. {
  34224. }
  34225. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  34226. {
  34227. const uint32 now = Time::getApproximateMillisecondCounter();
  34228. return now > buttonPressTime ? now - buttonPressTime : 0;
  34229. }
  34230. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  34231. {
  34232. triggerOnMouseDown = isTriggeredOnMouseDown;
  34233. }
  34234. void Button::clicked()
  34235. {
  34236. }
  34237. void Button::clicked (const ModifierKeys& /*modifiers*/)
  34238. {
  34239. clicked();
  34240. }
  34241. static const int clickMessageId = 0x2f3f4f99;
  34242. void Button::triggerClick()
  34243. {
  34244. postCommandMessage (clickMessageId);
  34245. }
  34246. void Button::internalClickCallback (const ModifierKeys& modifiers)
  34247. {
  34248. if (clickTogglesState)
  34249. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  34250. sendClickMessage (modifiers);
  34251. }
  34252. void Button::flashButtonState()
  34253. {
  34254. if (isEnabled())
  34255. {
  34256. needsToRelease = true;
  34257. setState (buttonDown);
  34258. getRepeatTimer().startTimer (100);
  34259. }
  34260. }
  34261. void Button::handleCommandMessage (int commandId)
  34262. {
  34263. if (commandId == clickMessageId)
  34264. {
  34265. if (isEnabled())
  34266. {
  34267. flashButtonState();
  34268. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34269. }
  34270. }
  34271. else
  34272. {
  34273. Component::handleCommandMessage (commandId);
  34274. }
  34275. }
  34276. void Button::addButtonListener (ButtonListener* const newListener)
  34277. {
  34278. jassert (newListener != 0);
  34279. jassert (! buttonListeners.contains (newListener)); // trying to add a listener to the list twice!
  34280. if (newListener != 0)
  34281. buttonListeners.add (newListener);
  34282. }
  34283. void Button::removeButtonListener (ButtonListener* const listener)
  34284. {
  34285. jassert (buttonListeners.contains (listener)); // trying to remove a listener that isn't on the list!
  34286. buttonListeners.removeValue (listener);
  34287. }
  34288. void Button::sendClickMessage (const ModifierKeys& modifiers)
  34289. {
  34290. const ComponentDeletionWatcher cdw (this);
  34291. if (commandManagerToUse != 0 && commandID != 0)
  34292. {
  34293. ApplicationCommandTarget::InvocationInfo info (commandID);
  34294. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34295. info.originatingComponent = this;
  34296. commandManagerToUse->invoke (info, true);
  34297. }
  34298. clicked (modifiers);
  34299. if (! cdw.hasBeenDeleted())
  34300. {
  34301. for (int i = buttonListeners.size(); --i >= 0;)
  34302. {
  34303. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34304. if (bl != 0)
  34305. {
  34306. bl->buttonClicked (this);
  34307. if (cdw.hasBeenDeleted())
  34308. return;
  34309. }
  34310. }
  34311. }
  34312. }
  34313. void Button::sendStateMessage()
  34314. {
  34315. const ComponentDeletionWatcher cdw (this);
  34316. buttonStateChanged();
  34317. if (cdw.hasBeenDeleted())
  34318. return;
  34319. for (int i = buttonListeners.size(); --i >= 0;)
  34320. {
  34321. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34322. if (bl != 0)
  34323. {
  34324. bl->buttonStateChanged (this);
  34325. if (cdw.hasBeenDeleted())
  34326. return;
  34327. }
  34328. }
  34329. }
  34330. void Button::paint (Graphics& g)
  34331. {
  34332. if (needsToRelease && isEnabled())
  34333. {
  34334. needsToRelease = false;
  34335. needsRepainting = true;
  34336. }
  34337. paintButton (g, isOver(), isDown());
  34338. }
  34339. void Button::mouseEnter (const MouseEvent& e)
  34340. {
  34341. updateState (&e);
  34342. }
  34343. void Button::mouseExit (const MouseEvent& e)
  34344. {
  34345. updateState (&e);
  34346. }
  34347. void Button::mouseDown (const MouseEvent& e)
  34348. {
  34349. updateState (&e);
  34350. if (isDown())
  34351. {
  34352. if (autoRepeatDelay >= 0)
  34353. getRepeatTimer().startTimer (autoRepeatDelay);
  34354. if (triggerOnMouseDown)
  34355. internalClickCallback (e.mods);
  34356. }
  34357. }
  34358. void Button::mouseUp (const MouseEvent& e)
  34359. {
  34360. const bool wasDown = isDown();
  34361. updateState (&e);
  34362. if (wasDown && isOver() && ! triggerOnMouseDown)
  34363. internalClickCallback (e.mods);
  34364. }
  34365. void Button::mouseDrag (const MouseEvent& e)
  34366. {
  34367. const ButtonState oldState = buttonState;
  34368. updateState (&e);
  34369. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34370. getRepeatTimer().startTimer (autoRepeatSpeed);
  34371. }
  34372. void Button::focusGained (FocusChangeType)
  34373. {
  34374. updateState (0);
  34375. repaint();
  34376. }
  34377. void Button::focusLost (FocusChangeType)
  34378. {
  34379. updateState (0);
  34380. repaint();
  34381. }
  34382. void Button::setVisible (bool shouldBeVisible)
  34383. {
  34384. if (shouldBeVisible != isVisible())
  34385. {
  34386. Component::setVisible (shouldBeVisible);
  34387. if (! shouldBeVisible)
  34388. needsToRelease = false;
  34389. updateState (0);
  34390. }
  34391. else
  34392. {
  34393. Component::setVisible (shouldBeVisible);
  34394. }
  34395. }
  34396. void Button::parentHierarchyChanged()
  34397. {
  34398. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34399. if (newKeySource != keySource)
  34400. {
  34401. if (keySource->isValidComponent())
  34402. keySource->removeKeyListener (this);
  34403. keySource = newKeySource;
  34404. if (keySource->isValidComponent())
  34405. keySource->addKeyListener (this);
  34406. }
  34407. }
  34408. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34409. const int commandID_,
  34410. const bool generateTooltip_)
  34411. {
  34412. commandID = commandID_;
  34413. generateTooltip = generateTooltip_;
  34414. if (commandManagerToUse != commandManagerToUse_)
  34415. {
  34416. if (commandManagerToUse != 0)
  34417. commandManagerToUse->removeListener (this);
  34418. commandManagerToUse = commandManagerToUse_;
  34419. if (commandManagerToUse != 0)
  34420. commandManagerToUse->addListener (this);
  34421. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34422. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34423. // it is that this button represents, and the button will update its state to reflect this
  34424. // in the applicationCommandListChanged() method.
  34425. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34426. }
  34427. if (commandManagerToUse != 0)
  34428. applicationCommandListChanged();
  34429. else
  34430. setEnabled (true);
  34431. }
  34432. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34433. {
  34434. if (info.commandID == commandID
  34435. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34436. {
  34437. flashButtonState();
  34438. }
  34439. }
  34440. void Button::applicationCommandListChanged()
  34441. {
  34442. if (commandManagerToUse != 0)
  34443. {
  34444. ApplicationCommandInfo info (0);
  34445. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34446. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34447. if (target != 0)
  34448. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34449. }
  34450. }
  34451. void Button::addShortcut (const KeyPress& key)
  34452. {
  34453. if (key.isValid())
  34454. {
  34455. jassert (! isRegisteredForShortcut (key)); // already registered!
  34456. shortcuts.add (key);
  34457. parentHierarchyChanged();
  34458. }
  34459. }
  34460. void Button::clearShortcuts()
  34461. {
  34462. shortcuts.clear();
  34463. parentHierarchyChanged();
  34464. }
  34465. bool Button::isShortcutPressed() const
  34466. {
  34467. if (! isCurrentlyBlockedByAnotherModalComponent())
  34468. {
  34469. for (int i = shortcuts.size(); --i >= 0;)
  34470. if (shortcuts.getReference(i).isCurrentlyDown())
  34471. return true;
  34472. }
  34473. return false;
  34474. }
  34475. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34476. {
  34477. for (int i = shortcuts.size(); --i >= 0;)
  34478. if (key == shortcuts.getReference(i))
  34479. return true;
  34480. return false;
  34481. }
  34482. bool Button::keyStateChanged (const bool, Component*)
  34483. {
  34484. if (! isEnabled())
  34485. return false;
  34486. const bool wasDown = isKeyDown;
  34487. isKeyDown = isShortcutPressed();
  34488. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34489. getRepeatTimer().startTimer (autoRepeatDelay);
  34490. updateState (0);
  34491. if (isEnabled() && wasDown && ! isKeyDown)
  34492. {
  34493. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34494. // (return immediately - this button may now have been deleted)
  34495. return true;
  34496. }
  34497. return wasDown || isKeyDown;
  34498. }
  34499. bool Button::keyPressed (const KeyPress&, Component*)
  34500. {
  34501. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34502. return isShortcutPressed();
  34503. }
  34504. bool Button::keyPressed (const KeyPress& key)
  34505. {
  34506. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34507. {
  34508. triggerClick();
  34509. return true;
  34510. }
  34511. return false;
  34512. }
  34513. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34514. const int repeatMillisecs,
  34515. const int minimumDelayInMillisecs) throw()
  34516. {
  34517. autoRepeatDelay = initialDelayMillisecs;
  34518. autoRepeatSpeed = repeatMillisecs;
  34519. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34520. }
  34521. void Button::repeatTimerCallback()
  34522. {
  34523. if (needsRepainting)
  34524. {
  34525. getRepeatTimer().stopTimer();
  34526. updateState (0);
  34527. needsRepainting = false;
  34528. }
  34529. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34530. {
  34531. int repeatSpeed = autoRepeatSpeed;
  34532. if (autoRepeatMinimumDelay >= 0)
  34533. {
  34534. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34535. timeHeldDown *= timeHeldDown;
  34536. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34537. }
  34538. repeatSpeed = jmax (1, repeatSpeed);
  34539. getRepeatTimer().startTimer (repeatSpeed);
  34540. const uint32 now = Time::getApproximateMillisecondCounter();
  34541. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34542. lastTimeCallbackTime = now;
  34543. const ComponentDeletionWatcher cdw (this);
  34544. for (int i = numTimesToCallback; --i >= 0;)
  34545. {
  34546. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34547. if (cdw.hasBeenDeleted() || ! isDown())
  34548. return;
  34549. }
  34550. }
  34551. else if (! needsToRelease)
  34552. {
  34553. getRepeatTimer().stopTimer();
  34554. }
  34555. }
  34556. Button::RepeatTimer& Button::getRepeatTimer()
  34557. {
  34558. if (repeatTimer == 0)
  34559. repeatTimer = new RepeatTimer (*this);
  34560. return *repeatTimer;
  34561. }
  34562. END_JUCE_NAMESPACE
  34563. /*** End of inlined file: juce_Button.cpp ***/
  34564. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34565. BEGIN_JUCE_NAMESPACE
  34566. DrawableButton::DrawableButton (const String& name,
  34567. const DrawableButton::ButtonStyle buttonStyle)
  34568. : Button (name),
  34569. style (buttonStyle),
  34570. edgeIndent (3)
  34571. {
  34572. if (buttonStyle == ImageOnButtonBackground)
  34573. {
  34574. backgroundOff = Colour (0xffbbbbff);
  34575. backgroundOn = Colour (0xff3333ff);
  34576. }
  34577. else
  34578. {
  34579. backgroundOff = Colours::transparentBlack;
  34580. backgroundOn = Colour (0xaabbbbff);
  34581. }
  34582. }
  34583. DrawableButton::~DrawableButton()
  34584. {
  34585. deleteImages();
  34586. }
  34587. void DrawableButton::deleteImages()
  34588. {
  34589. }
  34590. void DrawableButton::setImages (const Drawable* normal,
  34591. const Drawable* over,
  34592. const Drawable* down,
  34593. const Drawable* disabled,
  34594. const Drawable* normalOn,
  34595. const Drawable* overOn,
  34596. const Drawable* downOn,
  34597. const Drawable* disabledOn)
  34598. {
  34599. deleteImages();
  34600. jassert (normal != 0); // you really need to give it at least a normal image..
  34601. if (normal != 0)
  34602. normalImage = normal->createCopy();
  34603. if (over != 0)
  34604. overImage = over->createCopy();
  34605. if (down != 0)
  34606. downImage = down->createCopy();
  34607. if (disabled != 0)
  34608. disabledImage = disabled->createCopy();
  34609. if (normalOn != 0)
  34610. normalImageOn = normalOn->createCopy();
  34611. if (overOn != 0)
  34612. overImageOn = overOn->createCopy();
  34613. if (downOn != 0)
  34614. downImageOn = downOn->createCopy();
  34615. if (disabledOn != 0)
  34616. disabledImageOn = disabledOn->createCopy();
  34617. repaint();
  34618. }
  34619. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34620. {
  34621. if (style != newStyle)
  34622. {
  34623. style = newStyle;
  34624. repaint();
  34625. }
  34626. }
  34627. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34628. const Colour& toggledOnColour)
  34629. {
  34630. if (backgroundOff != toggledOffColour
  34631. || backgroundOn != toggledOnColour)
  34632. {
  34633. backgroundOff = toggledOffColour;
  34634. backgroundOn = toggledOnColour;
  34635. repaint();
  34636. }
  34637. }
  34638. const Colour& DrawableButton::getBackgroundColour() const throw()
  34639. {
  34640. return getToggleState() ? backgroundOn
  34641. : backgroundOff;
  34642. }
  34643. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34644. {
  34645. edgeIndent = numPixelsIndent;
  34646. repaint();
  34647. }
  34648. void DrawableButton::paintButton (Graphics& g,
  34649. bool isMouseOverButton,
  34650. bool isButtonDown)
  34651. {
  34652. Rectangle<int> imageSpace;
  34653. if (style == ImageOnButtonBackground)
  34654. {
  34655. const int insetX = getWidth() / 4;
  34656. const int insetY = getHeight() / 4;
  34657. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34658. getLookAndFeel().drawButtonBackground (g, *this,
  34659. getBackgroundColour(),
  34660. isMouseOverButton,
  34661. isButtonDown);
  34662. }
  34663. else
  34664. {
  34665. g.fillAll (getBackgroundColour());
  34666. const int textH = (style == ImageAboveTextLabel)
  34667. ? jmin (16, proportionOfHeight (0.25f))
  34668. : 0;
  34669. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34670. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34671. imageSpace.setBounds (indentX, indentY,
  34672. getWidth() - indentX * 2,
  34673. getHeight() - indentY * 2 - textH);
  34674. if (textH > 0)
  34675. {
  34676. g.setFont ((float) textH);
  34677. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34678. g.drawFittedText (getButtonText(),
  34679. 2, getHeight() - textH - 1,
  34680. getWidth() - 4, textH,
  34681. Justification::centred, 1);
  34682. }
  34683. }
  34684. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34685. g.setOpacity (1.0f);
  34686. const Drawable* imageToDraw = 0;
  34687. if (isEnabled())
  34688. {
  34689. imageToDraw = getCurrentImage();
  34690. }
  34691. else
  34692. {
  34693. imageToDraw = getToggleState() ? disabledImageOn
  34694. : disabledImage;
  34695. if (imageToDraw == 0)
  34696. {
  34697. g.setOpacity (0.4f);
  34698. imageToDraw = getNormalImage();
  34699. }
  34700. }
  34701. if (imageToDraw != 0)
  34702. {
  34703. if (style == ImageRaw)
  34704. {
  34705. imageToDraw->draw (g, 1.0f);
  34706. }
  34707. else
  34708. {
  34709. imageToDraw->drawWithin (g,
  34710. imageSpace.getX(),
  34711. imageSpace.getY(),
  34712. imageSpace.getWidth(),
  34713. imageSpace.getHeight(),
  34714. RectanglePlacement::centred,
  34715. 1.0f);
  34716. }
  34717. }
  34718. }
  34719. const Drawable* DrawableButton::getCurrentImage() const throw()
  34720. {
  34721. if (isDown())
  34722. return getDownImage();
  34723. if (isOver())
  34724. return getOverImage();
  34725. return getNormalImage();
  34726. }
  34727. const Drawable* DrawableButton::getNormalImage() const throw()
  34728. {
  34729. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34730. : normalImage;
  34731. }
  34732. const Drawable* DrawableButton::getOverImage() const throw()
  34733. {
  34734. const Drawable* d = normalImage;
  34735. if (getToggleState())
  34736. {
  34737. if (overImageOn != 0)
  34738. d = overImageOn;
  34739. else if (normalImageOn != 0)
  34740. d = normalImageOn;
  34741. else if (overImage != 0)
  34742. d = overImage;
  34743. }
  34744. else
  34745. {
  34746. if (overImage != 0)
  34747. d = overImage;
  34748. }
  34749. return d;
  34750. }
  34751. const Drawable* DrawableButton::getDownImage() const throw()
  34752. {
  34753. const Drawable* d = normalImage;
  34754. if (getToggleState())
  34755. {
  34756. if (downImageOn != 0)
  34757. d = downImageOn;
  34758. else if (overImageOn != 0)
  34759. d = overImageOn;
  34760. else if (normalImageOn != 0)
  34761. d = normalImageOn;
  34762. else if (downImage != 0)
  34763. d = downImage;
  34764. else
  34765. d = getOverImage();
  34766. }
  34767. else
  34768. {
  34769. if (downImage != 0)
  34770. d = downImage;
  34771. else
  34772. d = getOverImage();
  34773. }
  34774. return d;
  34775. }
  34776. END_JUCE_NAMESPACE
  34777. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34778. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34779. BEGIN_JUCE_NAMESPACE
  34780. HyperlinkButton::HyperlinkButton (const String& linkText,
  34781. const URL& linkURL)
  34782. : Button (linkText),
  34783. url (linkURL),
  34784. font (14.0f, Font::underlined),
  34785. resizeFont (true),
  34786. justification (Justification::centred)
  34787. {
  34788. setMouseCursor (MouseCursor::PointingHandCursor);
  34789. setTooltip (linkURL.toString (false));
  34790. }
  34791. HyperlinkButton::~HyperlinkButton()
  34792. {
  34793. }
  34794. void HyperlinkButton::setFont (const Font& newFont,
  34795. const bool resizeToMatchComponentHeight,
  34796. const Justification& justificationType)
  34797. {
  34798. font = newFont;
  34799. resizeFont = resizeToMatchComponentHeight;
  34800. justification = justificationType;
  34801. repaint();
  34802. }
  34803. void HyperlinkButton::setURL (const URL& newURL) throw()
  34804. {
  34805. url = newURL;
  34806. setTooltip (newURL.toString (false));
  34807. }
  34808. const Font HyperlinkButton::getFontToUse() const
  34809. {
  34810. Font f (font);
  34811. if (resizeFont)
  34812. f.setHeight (getHeight() * 0.7f);
  34813. return f;
  34814. }
  34815. void HyperlinkButton::changeWidthToFitText()
  34816. {
  34817. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34818. }
  34819. void HyperlinkButton::colourChanged()
  34820. {
  34821. repaint();
  34822. }
  34823. void HyperlinkButton::clicked()
  34824. {
  34825. if (url.isWellFormed())
  34826. url.launchInDefaultBrowser();
  34827. }
  34828. void HyperlinkButton::paintButton (Graphics& g,
  34829. bool isMouseOverButton,
  34830. bool isButtonDown)
  34831. {
  34832. const Colour textColour (findColour (textColourId));
  34833. if (isEnabled())
  34834. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34835. : textColour);
  34836. else
  34837. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34838. g.setFont (getFontToUse());
  34839. g.drawText (getButtonText(),
  34840. 2, 0, getWidth() - 2, getHeight(),
  34841. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34842. true);
  34843. }
  34844. END_JUCE_NAMESPACE
  34845. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34846. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34847. BEGIN_JUCE_NAMESPACE
  34848. ImageButton::ImageButton (const String& text_)
  34849. : Button (text_),
  34850. scaleImageToFit (true),
  34851. preserveProportions (true),
  34852. alphaThreshold (0),
  34853. imageX (0),
  34854. imageY (0),
  34855. imageW (0),
  34856. imageH (0),
  34857. normalImage (0),
  34858. overImage (0),
  34859. downImage (0)
  34860. {
  34861. }
  34862. ImageButton::~ImageButton()
  34863. {
  34864. deleteImages();
  34865. }
  34866. void ImageButton::deleteImages()
  34867. {
  34868. ImageCache::releaseOrDelete (normalImage);
  34869. ImageCache::releaseOrDelete (overImage);
  34870. ImageCache::releaseOrDelete (downImage);
  34871. }
  34872. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34873. const bool rescaleImagesWhenButtonSizeChanges,
  34874. const bool preserveImageProportions,
  34875. Image* const normalImage_,
  34876. const float imageOpacityWhenNormal,
  34877. const Colour& overlayColourWhenNormal,
  34878. Image* const overImage_,
  34879. const float imageOpacityWhenOver,
  34880. const Colour& overlayColourWhenOver,
  34881. Image* const downImage_,
  34882. const float imageOpacityWhenDown,
  34883. const Colour& overlayColourWhenDown,
  34884. const float hitTestAlphaThreshold)
  34885. {
  34886. deleteImages();
  34887. normalImage = normalImage_;
  34888. overImage = overImage_;
  34889. downImage = downImage_;
  34890. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34891. {
  34892. imageW = normalImage->getWidth();
  34893. imageH = normalImage->getHeight();
  34894. setSize (imageW, imageH);
  34895. }
  34896. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34897. preserveProportions = preserveImageProportions;
  34898. normalOpacity = imageOpacityWhenNormal;
  34899. normalOverlay = overlayColourWhenNormal;
  34900. overOpacity = imageOpacityWhenOver;
  34901. overOverlay = overlayColourWhenOver;
  34902. downOpacity = imageOpacityWhenDown;
  34903. downOverlay = overlayColourWhenDown;
  34904. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34905. repaint();
  34906. }
  34907. Image* ImageButton::getCurrentImage() const
  34908. {
  34909. if (isDown() || getToggleState())
  34910. return getDownImage();
  34911. if (isOver())
  34912. return getOverImage();
  34913. return getNormalImage();
  34914. }
  34915. Image* ImageButton::getNormalImage() const throw()
  34916. {
  34917. return normalImage;
  34918. }
  34919. Image* ImageButton::getOverImage() const throw()
  34920. {
  34921. return (overImage != 0) ? overImage
  34922. : normalImage;
  34923. }
  34924. Image* ImageButton::getDownImage() const throw()
  34925. {
  34926. return (downImage != 0) ? downImage
  34927. : getOverImage();
  34928. }
  34929. void ImageButton::paintButton (Graphics& g,
  34930. bool isMouseOverButton,
  34931. bool isButtonDown)
  34932. {
  34933. if (! isEnabled())
  34934. {
  34935. isMouseOverButton = false;
  34936. isButtonDown = false;
  34937. }
  34938. Image* const im = getCurrentImage();
  34939. if (im != 0)
  34940. {
  34941. const int iw = im->getWidth();
  34942. const int ih = im->getHeight();
  34943. imageW = getWidth();
  34944. imageH = getHeight();
  34945. imageX = (imageW - iw) >> 1;
  34946. imageY = (imageH - ih) >> 1;
  34947. if (scaleImageToFit)
  34948. {
  34949. if (preserveProportions)
  34950. {
  34951. int newW, newH;
  34952. const float imRatio = ih / (float)iw;
  34953. const float destRatio = imageH / (float)imageW;
  34954. if (imRatio > destRatio)
  34955. {
  34956. newW = roundToInt (imageH / imRatio);
  34957. newH = imageH;
  34958. }
  34959. else
  34960. {
  34961. newW = imageW;
  34962. newH = roundToInt (imageW * imRatio);
  34963. }
  34964. imageX = (imageW - newW) / 2;
  34965. imageY = (imageH - newH) / 2;
  34966. imageW = newW;
  34967. imageH = newH;
  34968. }
  34969. else
  34970. {
  34971. imageX = 0;
  34972. imageY = 0;
  34973. }
  34974. }
  34975. if (! scaleImageToFit)
  34976. {
  34977. imageW = iw;
  34978. imageH = ih;
  34979. }
  34980. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34981. isButtonDown ? downOverlay
  34982. : (isMouseOverButton ? overOverlay
  34983. : normalOverlay),
  34984. isButtonDown ? downOpacity
  34985. : (isMouseOverButton ? overOpacity
  34986. : normalOpacity),
  34987. *this);
  34988. }
  34989. }
  34990. bool ImageButton::hitTest (int x, int y)
  34991. {
  34992. if (alphaThreshold == 0)
  34993. return true;
  34994. Image* const im = getCurrentImage();
  34995. return im == 0
  34996. || (imageW > 0 && imageH > 0
  34997. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34998. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34999. }
  35000. END_JUCE_NAMESPACE
  35001. /*** End of inlined file: juce_ImageButton.cpp ***/
  35002. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  35003. BEGIN_JUCE_NAMESPACE
  35004. ShapeButton::ShapeButton (const String& text_,
  35005. const Colour& normalColour_,
  35006. const Colour& overColour_,
  35007. const Colour& downColour_)
  35008. : Button (text_),
  35009. normalColour (normalColour_),
  35010. overColour (overColour_),
  35011. downColour (downColour_),
  35012. maintainShapeProportions (false),
  35013. outlineWidth (0.0f)
  35014. {
  35015. }
  35016. ShapeButton::~ShapeButton()
  35017. {
  35018. }
  35019. void ShapeButton::setColours (const Colour& newNormalColour,
  35020. const Colour& newOverColour,
  35021. const Colour& newDownColour)
  35022. {
  35023. normalColour = newNormalColour;
  35024. overColour = newOverColour;
  35025. downColour = newDownColour;
  35026. }
  35027. void ShapeButton::setOutline (const Colour& newOutlineColour,
  35028. const float newOutlineWidth)
  35029. {
  35030. outlineColour = newOutlineColour;
  35031. outlineWidth = newOutlineWidth;
  35032. }
  35033. void ShapeButton::setShape (const Path& newShape,
  35034. const bool resizeNowToFitThisShape,
  35035. const bool maintainShapeProportions_,
  35036. const bool hasShadow)
  35037. {
  35038. shape = newShape;
  35039. maintainShapeProportions = maintainShapeProportions_;
  35040. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  35041. setComponentEffect ((hasShadow) ? &shadow : 0);
  35042. if (resizeNowToFitThisShape)
  35043. {
  35044. Rectangle<float> bounds (shape.getBounds());
  35045. if (hasShadow)
  35046. bounds.expand (4.0f, 4.0f);
  35047. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  35048. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  35049. 1 + (int) (bounds.getHeight() + outlineWidth));
  35050. }
  35051. }
  35052. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  35053. {
  35054. if (! isEnabled())
  35055. {
  35056. isMouseOverButton = false;
  35057. isButtonDown = false;
  35058. }
  35059. g.setColour ((isButtonDown) ? downColour
  35060. : (isMouseOverButton) ? overColour
  35061. : normalColour);
  35062. int w = getWidth();
  35063. int h = getHeight();
  35064. if (getComponentEffect() != 0)
  35065. {
  35066. w -= 4;
  35067. h -= 4;
  35068. }
  35069. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  35070. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  35071. w - offset - outlineWidth,
  35072. h - offset - outlineWidth,
  35073. maintainShapeProportions));
  35074. g.fillPath (shape, trans);
  35075. if (outlineWidth > 0.0f)
  35076. {
  35077. g.setColour (outlineColour);
  35078. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  35079. }
  35080. }
  35081. END_JUCE_NAMESPACE
  35082. /*** End of inlined file: juce_ShapeButton.cpp ***/
  35083. /*** Start of inlined file: juce_TextButton.cpp ***/
  35084. BEGIN_JUCE_NAMESPACE
  35085. TextButton::TextButton (const String& name,
  35086. const String& toolTip)
  35087. : Button (name)
  35088. {
  35089. setTooltip (toolTip);
  35090. }
  35091. TextButton::~TextButton()
  35092. {
  35093. }
  35094. void TextButton::paintButton (Graphics& g,
  35095. bool isMouseOverButton,
  35096. bool isButtonDown)
  35097. {
  35098. getLookAndFeel().drawButtonBackground (g, *this,
  35099. findColour (getToggleState() ? buttonOnColourId
  35100. : buttonColourId),
  35101. isMouseOverButton,
  35102. isButtonDown);
  35103. getLookAndFeel().drawButtonText (g, *this,
  35104. isMouseOverButton,
  35105. isButtonDown);
  35106. }
  35107. void TextButton::colourChanged()
  35108. {
  35109. repaint();
  35110. }
  35111. const Font TextButton::getFont()
  35112. {
  35113. return Font (jmin (15.0f, getHeight() * 0.6f));
  35114. }
  35115. void TextButton::changeWidthToFitText (const int newHeight)
  35116. {
  35117. if (newHeight >= 0)
  35118. setSize (jmax (1, getWidth()), newHeight);
  35119. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  35120. getHeight());
  35121. }
  35122. END_JUCE_NAMESPACE
  35123. /*** End of inlined file: juce_TextButton.cpp ***/
  35124. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  35125. BEGIN_JUCE_NAMESPACE
  35126. ToggleButton::ToggleButton (const String& buttonText)
  35127. : Button (buttonText)
  35128. {
  35129. setClickingTogglesState (true);
  35130. }
  35131. ToggleButton::~ToggleButton()
  35132. {
  35133. }
  35134. void ToggleButton::paintButton (Graphics& g,
  35135. bool isMouseOverButton,
  35136. bool isButtonDown)
  35137. {
  35138. getLookAndFeel().drawToggleButton (g, *this,
  35139. isMouseOverButton,
  35140. isButtonDown);
  35141. }
  35142. void ToggleButton::changeWidthToFitText()
  35143. {
  35144. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  35145. }
  35146. void ToggleButton::colourChanged()
  35147. {
  35148. repaint();
  35149. }
  35150. END_JUCE_NAMESPACE
  35151. /*** End of inlined file: juce_ToggleButton.cpp ***/
  35152. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  35153. BEGIN_JUCE_NAMESPACE
  35154. ToolbarButton::ToolbarButton (const int itemId_,
  35155. const String& buttonText,
  35156. Drawable* const normalImage_,
  35157. Drawable* const toggledOnImage_)
  35158. : ToolbarItemComponent (itemId_, buttonText, true),
  35159. normalImage (normalImage_),
  35160. toggledOnImage (toggledOnImage_)
  35161. {
  35162. }
  35163. ToolbarButton::~ToolbarButton()
  35164. {
  35165. }
  35166. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  35167. bool /*isToolbarVertical*/,
  35168. int& preferredSize,
  35169. int& minSize, int& maxSize)
  35170. {
  35171. preferredSize = minSize = maxSize = toolbarDepth;
  35172. return true;
  35173. }
  35174. void ToolbarButton::paintButtonArea (Graphics& g,
  35175. int width, int height,
  35176. bool /*isMouseOver*/,
  35177. bool /*isMouseDown*/)
  35178. {
  35179. Drawable* d = normalImage;
  35180. if (getToggleState() && toggledOnImage != 0)
  35181. d = toggledOnImage;
  35182. if (! isEnabled())
  35183. {
  35184. Image im (Image::ARGB, width, height, true);
  35185. Graphics g2 (im);
  35186. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35187. im.desaturate();
  35188. g.drawImageAt (&im, 0, 0);
  35189. }
  35190. else
  35191. {
  35192. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35193. }
  35194. }
  35195. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  35196. {
  35197. }
  35198. END_JUCE_NAMESPACE
  35199. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  35200. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  35201. BEGIN_JUCE_NAMESPACE
  35202. class CodeDocumentLine
  35203. {
  35204. public:
  35205. CodeDocumentLine (const tchar* const line_,
  35206. const int lineLength_,
  35207. const int numNewLineChars,
  35208. const int lineStartInFile_)
  35209. : line (line_, lineLength_),
  35210. lineStartInFile (lineStartInFile_),
  35211. lineLength (lineLength_),
  35212. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  35213. {
  35214. }
  35215. ~CodeDocumentLine()
  35216. {
  35217. }
  35218. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  35219. {
  35220. const tchar* const t = (const tchar*) text;
  35221. int pos = 0;
  35222. while (t [pos] != 0)
  35223. {
  35224. const int startOfLine = pos;
  35225. int numNewLineChars = 0;
  35226. while (t[pos] != 0)
  35227. {
  35228. if (t[pos] == T('\r'))
  35229. {
  35230. ++numNewLineChars;
  35231. ++pos;
  35232. if (t[pos] == T('\n'))
  35233. {
  35234. ++numNewLineChars;
  35235. ++pos;
  35236. }
  35237. break;
  35238. }
  35239. if (t[pos] == T('\n'))
  35240. {
  35241. ++numNewLineChars;
  35242. ++pos;
  35243. break;
  35244. }
  35245. ++pos;
  35246. }
  35247. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  35248. numNewLineChars, startOfLine));
  35249. }
  35250. jassert (pos == text.length());
  35251. }
  35252. bool endsWithLineBreak() const throw()
  35253. {
  35254. return lineLengthWithoutNewLines != lineLength;
  35255. }
  35256. void updateLength() throw()
  35257. {
  35258. lineLengthWithoutNewLines = lineLength = line.length();
  35259. while (lineLengthWithoutNewLines > 0
  35260. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35261. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35262. {
  35263. --lineLengthWithoutNewLines;
  35264. }
  35265. }
  35266. String line;
  35267. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  35268. };
  35269. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  35270. : document (document_),
  35271. currentLine (document_->lines[0]),
  35272. line (0),
  35273. position (0)
  35274. {
  35275. }
  35276. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  35277. : document (other.document),
  35278. currentLine (other.currentLine),
  35279. line (other.line),
  35280. position (other.position)
  35281. {
  35282. }
  35283. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  35284. {
  35285. document = other.document;
  35286. currentLine = other.currentLine;
  35287. line = other.line;
  35288. position = other.position;
  35289. return *this;
  35290. }
  35291. CodeDocument::Iterator::~Iterator() throw()
  35292. {
  35293. }
  35294. juce_wchar CodeDocument::Iterator::nextChar()
  35295. {
  35296. if (currentLine == 0)
  35297. return 0;
  35298. jassert (currentLine == document->lines.getUnchecked (line));
  35299. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  35300. skip();
  35301. return result;
  35302. }
  35303. void CodeDocument::Iterator::skip()
  35304. {
  35305. if (currentLine != 0)
  35306. {
  35307. jassert (currentLine == document->lines.getUnchecked (line));
  35308. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35309. {
  35310. ++line;
  35311. currentLine = document->lines [line];
  35312. }
  35313. }
  35314. }
  35315. void CodeDocument::Iterator::skipToEndOfLine()
  35316. {
  35317. if (currentLine != 0)
  35318. {
  35319. jassert (currentLine == document->lines.getUnchecked (line));
  35320. ++line;
  35321. currentLine = document->lines [line];
  35322. if (currentLine != 0)
  35323. position = currentLine->lineStartInFile;
  35324. else
  35325. position = document->getNumCharacters();
  35326. }
  35327. }
  35328. juce_wchar CodeDocument::Iterator::peekNextChar() const
  35329. {
  35330. if (currentLine == 0)
  35331. return 0;
  35332. jassert (currentLine == document->lines.getUnchecked (line));
  35333. return currentLine->line [position - currentLine->lineStartInFile];
  35334. }
  35335. void CodeDocument::Iterator::skipWhitespace()
  35336. {
  35337. while (CharacterFunctions::isWhitespace (peekNextChar()))
  35338. skip();
  35339. }
  35340. bool CodeDocument::Iterator::isEOF() const throw()
  35341. {
  35342. return currentLine == 0;
  35343. }
  35344. CodeDocument::Position::Position() throw()
  35345. : owner (0), characterPos (0), line (0),
  35346. indexInLine (0), positionMaintained (false)
  35347. {
  35348. }
  35349. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35350. const int line_, const int indexInLine_) throw()
  35351. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35352. characterPos (0), line (line_),
  35353. indexInLine (indexInLine_), positionMaintained (false)
  35354. {
  35355. setLineAndIndex (line_, indexInLine_);
  35356. }
  35357. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35358. const int characterPos_) throw()
  35359. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35360. positionMaintained (false)
  35361. {
  35362. setPosition (characterPos_);
  35363. }
  35364. CodeDocument::Position::Position (const Position& other) throw()
  35365. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35366. indexInLine (other.indexInLine), positionMaintained (false)
  35367. {
  35368. jassert (*this == other);
  35369. }
  35370. CodeDocument::Position::~Position() throw()
  35371. {
  35372. setPositionMaintained (false);
  35373. }
  35374. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35375. {
  35376. if (this != &other)
  35377. {
  35378. const bool wasPositionMaintained = positionMaintained;
  35379. if (owner != other.owner)
  35380. setPositionMaintained (false);
  35381. owner = other.owner;
  35382. line = other.line;
  35383. indexInLine = other.indexInLine;
  35384. characterPos = other.characterPos;
  35385. setPositionMaintained (wasPositionMaintained);
  35386. jassert (*this == other);
  35387. }
  35388. return *this;
  35389. }
  35390. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35391. {
  35392. jassert ((characterPos == other.characterPos)
  35393. == (line == other.line && indexInLine == other.indexInLine));
  35394. return characterPos == other.characterPos
  35395. && line == other.line
  35396. && indexInLine == other.indexInLine
  35397. && owner == other.owner;
  35398. }
  35399. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35400. {
  35401. return ! operator== (other);
  35402. }
  35403. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35404. {
  35405. jassert (owner != 0);
  35406. if (owner->lines.size() == 0)
  35407. {
  35408. line = 0;
  35409. indexInLine = 0;
  35410. characterPos = 0;
  35411. }
  35412. else
  35413. {
  35414. if (newLine >= owner->lines.size())
  35415. {
  35416. line = owner->lines.size() - 1;
  35417. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35418. jassert (l != 0);
  35419. indexInLine = l->lineLengthWithoutNewLines;
  35420. characterPos = l->lineStartInFile + indexInLine;
  35421. }
  35422. else
  35423. {
  35424. line = jmax (0, newLine);
  35425. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35426. jassert (l != 0);
  35427. if (l->lineLengthWithoutNewLines > 0)
  35428. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35429. else
  35430. indexInLine = 0;
  35431. characterPos = l->lineStartInFile + indexInLine;
  35432. }
  35433. }
  35434. }
  35435. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35436. {
  35437. jassert (owner != 0);
  35438. line = 0;
  35439. indexInLine = 0;
  35440. characterPos = 0;
  35441. if (newPosition > 0)
  35442. {
  35443. int lineStart = 0;
  35444. int lineEnd = owner->lines.size();
  35445. for (;;)
  35446. {
  35447. if (lineEnd - lineStart < 4)
  35448. {
  35449. for (int i = lineStart; i < lineEnd; ++i)
  35450. {
  35451. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35452. int index = newPosition - l->lineStartInFile;
  35453. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35454. {
  35455. line = i;
  35456. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35457. characterPos = l->lineStartInFile + indexInLine;
  35458. }
  35459. }
  35460. break;
  35461. }
  35462. else
  35463. {
  35464. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35465. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35466. if (newPosition >= mid->lineStartInFile)
  35467. lineStart = midIndex;
  35468. else
  35469. lineEnd = midIndex;
  35470. }
  35471. }
  35472. }
  35473. }
  35474. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35475. {
  35476. jassert (owner != 0);
  35477. if (characterDelta == 1)
  35478. {
  35479. setPosition (getPosition());
  35480. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35481. if (line < owner->lines.size())
  35482. {
  35483. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35484. if (indexInLine + characterDelta < l->lineLength
  35485. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35486. ++characterDelta;
  35487. }
  35488. }
  35489. setPosition (characterPos + characterDelta);
  35490. }
  35491. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35492. {
  35493. CodeDocument::Position p (*this);
  35494. p.moveBy (characterDelta);
  35495. return p;
  35496. }
  35497. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35498. {
  35499. CodeDocument::Position p (*this);
  35500. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35501. return p;
  35502. }
  35503. const tchar CodeDocument::Position::getCharacter() const throw()
  35504. {
  35505. const CodeDocumentLine* const l = owner->lines [line];
  35506. return l == 0 ? 0 : l->line [getIndexInLine()];
  35507. }
  35508. const String CodeDocument::Position::getLineText() const throw()
  35509. {
  35510. const CodeDocumentLine* const l = owner->lines [line];
  35511. return l == 0 ? String::empty : l->line;
  35512. }
  35513. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35514. {
  35515. if (isMaintained != positionMaintained)
  35516. {
  35517. positionMaintained = isMaintained;
  35518. if (owner != 0)
  35519. {
  35520. if (isMaintained)
  35521. {
  35522. jassert (! owner->positionsToMaintain.contains (this));
  35523. owner->positionsToMaintain.add (this);
  35524. }
  35525. else
  35526. {
  35527. jassert (owner->positionsToMaintain.contains (this));
  35528. owner->positionsToMaintain.removeValue (this);
  35529. }
  35530. }
  35531. }
  35532. }
  35533. CodeDocument::CodeDocument()
  35534. : undoManager (std::numeric_limits<int>::max(), 10000),
  35535. currentActionIndex (0),
  35536. indexOfSavedState (-1),
  35537. maximumLineLength (-1),
  35538. newLineChars ("\r\n")
  35539. {
  35540. }
  35541. CodeDocument::~CodeDocument()
  35542. {
  35543. }
  35544. const String CodeDocument::getAllContent() const throw()
  35545. {
  35546. return getTextBetween (Position (this, 0),
  35547. Position (this, lines.size(), 0));
  35548. }
  35549. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35550. {
  35551. if (end.getPosition() <= start.getPosition())
  35552. return String::empty;
  35553. const int startLine = start.getLineNumber();
  35554. const int endLine = end.getLineNumber();
  35555. if (startLine == endLine)
  35556. {
  35557. CodeDocumentLine* const line = lines [startLine];
  35558. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35559. }
  35560. String result;
  35561. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35562. String::Concatenator concatenator (result);
  35563. const int maxLine = jmin (lines.size() - 1, endLine);
  35564. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35565. {
  35566. const CodeDocumentLine* line = lines.getUnchecked(i);
  35567. int len = line->lineLength;
  35568. if (i == startLine)
  35569. {
  35570. const int index = start.getIndexInLine();
  35571. concatenator.append (line->line.substring (index, len));
  35572. }
  35573. else if (i == endLine)
  35574. {
  35575. len = end.getIndexInLine();
  35576. concatenator.append (line->line.substring (0, len));
  35577. }
  35578. else
  35579. {
  35580. concatenator.append (line->line);
  35581. }
  35582. }
  35583. return result;
  35584. }
  35585. int CodeDocument::getNumCharacters() const throw()
  35586. {
  35587. const CodeDocumentLine* const lastLine = lines.getLast();
  35588. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35589. }
  35590. const String CodeDocument::getLine (const int lineIndex) const throw()
  35591. {
  35592. const CodeDocumentLine* const line = lines [lineIndex];
  35593. return (line == 0) ? String::empty : line->line;
  35594. }
  35595. int CodeDocument::getMaximumLineLength() throw()
  35596. {
  35597. if (maximumLineLength < 0)
  35598. {
  35599. maximumLineLength = 0;
  35600. for (int i = lines.size(); --i >= 0;)
  35601. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35602. }
  35603. return maximumLineLength;
  35604. }
  35605. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35606. {
  35607. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35608. }
  35609. void CodeDocument::insertText (const Position& position, const String& text)
  35610. {
  35611. insert (text, position.getPosition(), true);
  35612. }
  35613. void CodeDocument::replaceAllContent (const String& newContent)
  35614. {
  35615. remove (0, getNumCharacters(), true);
  35616. insert (newContent, 0, true);
  35617. }
  35618. bool CodeDocument::loadFromStream (InputStream& stream)
  35619. {
  35620. replaceAllContent (stream.readEntireStreamAsString());
  35621. setSavePoint();
  35622. clearUndoHistory();
  35623. return true;
  35624. }
  35625. bool CodeDocument::writeToStream (OutputStream& stream)
  35626. {
  35627. for (int i = 0; i < lines.size(); ++i)
  35628. {
  35629. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35630. const char* utf8 = temp.toUTF8();
  35631. if (! stream.write (utf8, (int) strlen (utf8)))
  35632. return false;
  35633. }
  35634. return true;
  35635. }
  35636. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35637. {
  35638. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35639. newLineChars = newLine;
  35640. }
  35641. void CodeDocument::newTransaction()
  35642. {
  35643. undoManager.beginNewTransaction (String::empty);
  35644. }
  35645. void CodeDocument::undo()
  35646. {
  35647. newTransaction();
  35648. undoManager.undo();
  35649. }
  35650. void CodeDocument::redo()
  35651. {
  35652. undoManager.redo();
  35653. }
  35654. void CodeDocument::clearUndoHistory()
  35655. {
  35656. undoManager.clearUndoHistory();
  35657. }
  35658. void CodeDocument::setSavePoint() throw()
  35659. {
  35660. indexOfSavedState = currentActionIndex;
  35661. }
  35662. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35663. {
  35664. return currentActionIndex != indexOfSavedState;
  35665. }
  35666. static int getCodeCharacterCategory (const tchar character) throw()
  35667. {
  35668. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35669. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35670. }
  35671. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35672. {
  35673. Position p (position);
  35674. const int maxDistance = 256;
  35675. int i = 0;
  35676. while (i < maxDistance
  35677. && CharacterFunctions::isWhitespace (p.getCharacter())
  35678. && (i == 0 || (p.getCharacter() != T('\n')
  35679. && p.getCharacter() != T('\r'))))
  35680. {
  35681. ++i;
  35682. p.moveBy (1);
  35683. }
  35684. if (i == 0)
  35685. {
  35686. const int type = getCodeCharacterCategory (p.getCharacter());
  35687. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35688. {
  35689. ++i;
  35690. p.moveBy (1);
  35691. }
  35692. while (i < maxDistance
  35693. && CharacterFunctions::isWhitespace (p.getCharacter())
  35694. && (i == 0 || (p.getCharacter() != T('\n')
  35695. && p.getCharacter() != T('\r'))))
  35696. {
  35697. ++i;
  35698. p.moveBy (1);
  35699. }
  35700. }
  35701. return p;
  35702. }
  35703. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35704. {
  35705. Position p (position);
  35706. const int maxDistance = 256;
  35707. int i = 0;
  35708. bool stoppedAtLineStart = false;
  35709. while (i < maxDistance)
  35710. {
  35711. const tchar c = p.movedBy (-1).getCharacter();
  35712. if (c == T('\r') || c == T('\n'))
  35713. {
  35714. stoppedAtLineStart = true;
  35715. if (i > 0)
  35716. break;
  35717. }
  35718. if (! CharacterFunctions::isWhitespace (c))
  35719. break;
  35720. p.moveBy (-1);
  35721. ++i;
  35722. }
  35723. if (i < maxDistance && ! stoppedAtLineStart)
  35724. {
  35725. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35726. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35727. {
  35728. p.moveBy (-1);
  35729. ++i;
  35730. }
  35731. }
  35732. return p;
  35733. }
  35734. void CodeDocument::checkLastLineStatus()
  35735. {
  35736. while (lines.size() > 0
  35737. && lines.getLast()->lineLength == 0
  35738. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35739. {
  35740. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35741. lines.removeLast();
  35742. }
  35743. const CodeDocumentLine* const lastLine = lines.getLast();
  35744. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35745. {
  35746. // check that there's an empty line at the end if the preceding one ends in a newline..
  35747. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35748. }
  35749. }
  35750. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35751. {
  35752. listeners.addIfNotAlreadyThere (listener);
  35753. }
  35754. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35755. {
  35756. listeners.removeValue (listener);
  35757. }
  35758. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35759. {
  35760. const Position startPos (this, startLine, 0);
  35761. const Position endPos (this, endLine, 0);
  35762. for (int i = listeners.size(); --i >= 0;)
  35763. {
  35764. Listener* const l = (Listener*) listeners[i];
  35765. if (l != 0)
  35766. l->codeDocumentChanged (startPos, endPos);
  35767. }
  35768. }
  35769. class CodeDocumentInsertAction : public UndoableAction
  35770. {
  35771. CodeDocument& owner;
  35772. const String text;
  35773. int insertPos;
  35774. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35775. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35776. public:
  35777. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35778. : owner (owner_),
  35779. text (text_),
  35780. insertPos (insertPos_)
  35781. {
  35782. }
  35783. ~CodeDocumentInsertAction() {}
  35784. bool perform()
  35785. {
  35786. owner.currentActionIndex++;
  35787. owner.insert (text, insertPos, false);
  35788. return true;
  35789. }
  35790. bool undo()
  35791. {
  35792. owner.currentActionIndex--;
  35793. owner.remove (insertPos, insertPos + text.length(), false);
  35794. return true;
  35795. }
  35796. int getSizeInUnits() { return text.length() + 32; }
  35797. };
  35798. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35799. {
  35800. if (text.isEmpty())
  35801. return;
  35802. if (undoable)
  35803. {
  35804. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35805. }
  35806. else
  35807. {
  35808. Position pos (this, insertPos);
  35809. const int firstAffectedLine = pos.getLineNumber();
  35810. int lastAffectedLine = firstAffectedLine + 1;
  35811. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35812. String textInsideOriginalLine (text);
  35813. if (firstLine != 0)
  35814. {
  35815. const int index = pos.getIndexInLine();
  35816. textInsideOriginalLine = firstLine->line.substring (0, index)
  35817. + textInsideOriginalLine
  35818. + firstLine->line.substring (index);
  35819. }
  35820. maximumLineLength = -1;
  35821. Array <CodeDocumentLine*> newLines;
  35822. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35823. jassert (newLines.size() > 0);
  35824. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35825. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35826. lines.set (firstAffectedLine, newFirstLine);
  35827. if (newLines.size() > 1)
  35828. {
  35829. for (int i = 1; i < newLines.size(); ++i)
  35830. {
  35831. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35832. lines.insert (firstAffectedLine + i, l);
  35833. }
  35834. lastAffectedLine = lines.size();
  35835. }
  35836. int i, lineStart = newFirstLine->lineStartInFile;
  35837. for (i = firstAffectedLine; i < lines.size(); ++i)
  35838. {
  35839. CodeDocumentLine* const l = lines.getUnchecked (i);
  35840. l->lineStartInFile = lineStart;
  35841. lineStart += l->lineLength;
  35842. }
  35843. checkLastLineStatus();
  35844. const int newTextLength = text.length();
  35845. for (i = 0; i < positionsToMaintain.size(); ++i)
  35846. {
  35847. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35848. if (p->getPosition() >= insertPos)
  35849. p->setPosition (p->getPosition() + newTextLength);
  35850. }
  35851. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35852. }
  35853. }
  35854. class CodeDocumentDeleteAction : public UndoableAction
  35855. {
  35856. CodeDocument& owner;
  35857. int startPos, endPos;
  35858. String removedText;
  35859. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35860. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35861. public:
  35862. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35863. : owner (owner_),
  35864. startPos (startPos_),
  35865. endPos (endPos_)
  35866. {
  35867. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35868. CodeDocument::Position (&owner, endPos));
  35869. }
  35870. ~CodeDocumentDeleteAction() {}
  35871. bool perform()
  35872. {
  35873. owner.currentActionIndex++;
  35874. owner.remove (startPos, endPos, false);
  35875. return true;
  35876. }
  35877. bool undo()
  35878. {
  35879. owner.currentActionIndex--;
  35880. owner.insert (removedText, startPos, false);
  35881. return true;
  35882. }
  35883. int getSizeInUnits() { return removedText.length() + 32; }
  35884. };
  35885. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35886. {
  35887. if (endPos <= startPos)
  35888. return;
  35889. if (undoable)
  35890. {
  35891. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35892. }
  35893. else
  35894. {
  35895. Position startPosition (this, startPos);
  35896. Position endPosition (this, endPos);
  35897. maximumLineLength = -1;
  35898. const int firstAffectedLine = startPosition.getLineNumber();
  35899. const int endLine = endPosition.getLineNumber();
  35900. int lastAffectedLine = firstAffectedLine + 1;
  35901. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35902. if (firstAffectedLine == endLine)
  35903. {
  35904. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35905. + firstLine->line.substring (endPosition.getIndexInLine());
  35906. firstLine->updateLength();
  35907. }
  35908. else
  35909. {
  35910. lastAffectedLine = lines.size();
  35911. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35912. jassert (lastLine != 0);
  35913. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35914. + lastLine->line.substring (endPosition.getIndexInLine());
  35915. firstLine->updateLength();
  35916. int numLinesToRemove = endLine - firstAffectedLine;
  35917. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35918. }
  35919. int i;
  35920. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35921. {
  35922. CodeDocumentLine* const l = lines.getUnchecked (i);
  35923. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35924. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35925. }
  35926. checkLastLineStatus();
  35927. const int totalChars = getNumCharacters();
  35928. for (i = 0; i < positionsToMaintain.size(); ++i)
  35929. {
  35930. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35931. if (p->getPosition() > startPosition.getPosition())
  35932. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35933. if (p->getPosition() > totalChars)
  35934. p->setPosition (totalChars);
  35935. }
  35936. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35937. }
  35938. }
  35939. END_JUCE_NAMESPACE
  35940. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35941. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35942. BEGIN_JUCE_NAMESPACE
  35943. class CaretComponent : public Component,
  35944. public Timer
  35945. {
  35946. public:
  35947. CaretComponent()
  35948. {
  35949. setAlwaysOnTop (true);
  35950. setInterceptsMouseClicks (false, false);
  35951. }
  35952. ~CaretComponent()
  35953. {
  35954. }
  35955. void paint (Graphics& g)
  35956. {
  35957. if (getParentComponent()->hasKeyboardFocus (true))
  35958. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35959. }
  35960. void timerCallback()
  35961. {
  35962. setVisible (! isVisible());
  35963. }
  35964. void updatePosition (CodeEditorComponent& owner)
  35965. {
  35966. startTimer (400);
  35967. setVisible (true);
  35968. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35969. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35970. }
  35971. };
  35972. class CodeEditorComponent::CodeEditorLine
  35973. {
  35974. public:
  35975. CodeEditorLine() throw()
  35976. {
  35977. }
  35978. ~CodeEditorLine() throw()
  35979. {
  35980. }
  35981. bool update (CodeDocument& document, int lineNum,
  35982. CodeDocument::Iterator& source,
  35983. CodeTokeniser* analyser, const int spacesPerTab,
  35984. const CodeDocument::Position& selectionStart,
  35985. const CodeDocument::Position& selectionEnd)
  35986. {
  35987. Array <SyntaxToken> newTokens;
  35988. newTokens.ensureStorageAllocated (8);
  35989. if (analyser == 0)
  35990. {
  35991. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35992. }
  35993. else if (lineNum < document.getNumLines())
  35994. {
  35995. const CodeDocument::Position pos (&document, lineNum, 0);
  35996. createTokens (pos.getPosition(), pos.getLineText(),
  35997. source, analyser, newTokens);
  35998. }
  35999. replaceTabsWithSpaces (newTokens, spacesPerTab);
  36000. int newHighlightStart = 0;
  36001. int newHighlightEnd = 0;
  36002. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  36003. {
  36004. const String line (document.getLine (lineNum));
  36005. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  36006. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  36007. line, spacesPerTab);
  36008. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  36009. line, spacesPerTab);
  36010. }
  36011. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  36012. {
  36013. highlightColumnStart = newHighlightStart;
  36014. highlightColumnEnd = newHighlightEnd;
  36015. }
  36016. else
  36017. {
  36018. if (tokens.size() == newTokens.size())
  36019. {
  36020. bool allTheSame = true;
  36021. for (int i = newTokens.size(); --i >= 0;)
  36022. {
  36023. if (tokens.getReference(i) != newTokens.getReference(i))
  36024. {
  36025. allTheSame = false;
  36026. break;
  36027. }
  36028. }
  36029. if (allTheSame)
  36030. return false;
  36031. }
  36032. }
  36033. tokens.swapWithArray (newTokens);
  36034. return true;
  36035. }
  36036. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  36037. float x, const int y, const int baselineOffset, const int lineHeight,
  36038. const Colour& highlightColour) const throw()
  36039. {
  36040. if (highlightColumnStart < highlightColumnEnd)
  36041. {
  36042. g.setColour (highlightColour);
  36043. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  36044. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  36045. }
  36046. int lastType = std::numeric_limits<int>::min();
  36047. for (int i = 0; i < tokens.size(); ++i)
  36048. {
  36049. SyntaxToken& token = tokens.getReference(i);
  36050. if (lastType != token.tokenType)
  36051. {
  36052. lastType = token.tokenType;
  36053. g.setColour (owner.getColourForTokenType (lastType));
  36054. }
  36055. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  36056. if (i < tokens.size() - 1)
  36057. {
  36058. if (token.width < 0)
  36059. token.width = font.getStringWidthFloat (token.text);
  36060. x += token.width;
  36061. }
  36062. }
  36063. }
  36064. private:
  36065. struct SyntaxToken
  36066. {
  36067. String text;
  36068. int tokenType;
  36069. float width;
  36070. SyntaxToken (const String& text_, const int type) throw()
  36071. : text (text_), tokenType (type), width (-1.0f)
  36072. {
  36073. }
  36074. bool operator!= (const SyntaxToken& other) const throw()
  36075. {
  36076. return text != other.text || tokenType != other.tokenType;
  36077. }
  36078. };
  36079. Array <SyntaxToken> tokens;
  36080. int highlightColumnStart, highlightColumnEnd;
  36081. static void createTokens (int startPosition, const String& lineText,
  36082. CodeDocument::Iterator& source,
  36083. CodeTokeniser* analyser,
  36084. Array <SyntaxToken>& newTokens)
  36085. {
  36086. CodeDocument::Iterator lastIterator (source);
  36087. const int lineLength = lineText.length();
  36088. for (;;)
  36089. {
  36090. int tokenType = analyser->readNextToken (source);
  36091. int tokenStart = lastIterator.getPosition();
  36092. int tokenEnd = source.getPosition();
  36093. if (tokenEnd <= tokenStart)
  36094. break;
  36095. tokenEnd -= startPosition;
  36096. if (tokenEnd > 0)
  36097. {
  36098. tokenStart -= startPosition;
  36099. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  36100. tokenType));
  36101. if (tokenEnd >= lineLength)
  36102. break;
  36103. }
  36104. lastIterator = source;
  36105. }
  36106. source = lastIterator;
  36107. }
  36108. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  36109. {
  36110. int x = 0;
  36111. for (int i = 0; i < tokens.size(); ++i)
  36112. {
  36113. SyntaxToken& t = tokens.getReference(i);
  36114. for (;;)
  36115. {
  36116. int tabPos = t.text.indexOfChar (T('\t'));
  36117. if (tabPos < 0)
  36118. break;
  36119. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  36120. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  36121. }
  36122. x += t.text.length();
  36123. }
  36124. }
  36125. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  36126. {
  36127. jassert (index <= line.length());
  36128. int col = 0;
  36129. for (int i = 0; i < index; ++i)
  36130. {
  36131. if (line[i] != T('\t'))
  36132. ++col;
  36133. else
  36134. col += spacesPerTab - (col % spacesPerTab);
  36135. }
  36136. return col;
  36137. }
  36138. };
  36139. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  36140. CodeTokeniser* const codeTokeniser_)
  36141. : document (document_),
  36142. firstLineOnScreen (0),
  36143. gutter (5),
  36144. spacesPerTab (4),
  36145. lineHeight (0),
  36146. linesOnScreen (0),
  36147. columnsOnScreen (0),
  36148. scrollbarThickness (16),
  36149. columnToTryToMaintain (-1),
  36150. useSpacesForTabs (false),
  36151. xOffset (0),
  36152. codeTokeniser (codeTokeniser_)
  36153. {
  36154. caretPos = CodeDocument::Position (&document_, 0, 0);
  36155. caretPos.setPositionMaintained (true);
  36156. selectionStart = CodeDocument::Position (&document_, 0, 0);
  36157. selectionStart.setPositionMaintained (true);
  36158. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  36159. selectionEnd.setPositionMaintained (true);
  36160. setOpaque (true);
  36161. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  36162. setWantsKeyboardFocus (true);
  36163. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  36164. verticalScrollBar->setSingleStepSize (1.0);
  36165. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  36166. horizontalScrollBar->setSingleStepSize (1.0);
  36167. addAndMakeVisible (caret = new CaretComponent());
  36168. Font f (12.0f);
  36169. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  36170. setFont (f);
  36171. resetToDefaultColours();
  36172. verticalScrollBar->addListener (this);
  36173. horizontalScrollBar->addListener (this);
  36174. document.addListener (this);
  36175. }
  36176. CodeEditorComponent::~CodeEditorComponent()
  36177. {
  36178. document.removeListener (this);
  36179. deleteAllChildren();
  36180. }
  36181. void CodeEditorComponent::loadContent (const String& newContent)
  36182. {
  36183. clearCachedIterators (0);
  36184. document.replaceAllContent (newContent);
  36185. document.clearUndoHistory();
  36186. document.setSavePoint();
  36187. caretPos.setPosition (0);
  36188. selectionStart.setPosition (0);
  36189. selectionEnd.setPosition (0);
  36190. scrollToLine (0);
  36191. }
  36192. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  36193. const CodeDocument::Position& affectedTextEnd)
  36194. {
  36195. clearCachedIterators (affectedTextStart.getLineNumber());
  36196. triggerAsyncUpdate();
  36197. ((CaretComponent*) caret)->updatePosition (*this);
  36198. columnToTryToMaintain = -1;
  36199. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  36200. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  36201. deselectAll();
  36202. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  36203. || caretPos.getPosition() < affectedTextStart.getPosition())
  36204. moveCaretTo (affectedTextStart, false);
  36205. updateScrollBars();
  36206. }
  36207. void CodeEditorComponent::resized()
  36208. {
  36209. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  36210. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  36211. lines.clear();
  36212. rebuildLineTokens();
  36213. ((CaretComponent*) caret)->updatePosition (*this);
  36214. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  36215. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  36216. updateScrollBars();
  36217. }
  36218. void CodeEditorComponent::paint (Graphics& g)
  36219. {
  36220. handleUpdateNowIfNeeded();
  36221. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  36222. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  36223. g.setFont (font);
  36224. const int baselineOffset = (int) font.getAscent();
  36225. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  36226. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  36227. const Rectangle<int> clip (g.getClipBounds());
  36228. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  36229. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  36230. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  36231. {
  36232. lines.getUnchecked(j)->draw (*this, g, font,
  36233. (float) (gutter - xOffset * charWidth),
  36234. lineHeight * j, baselineOffset, lineHeight,
  36235. highlightColour);
  36236. }
  36237. }
  36238. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  36239. {
  36240. if (scrollbarThickness != thickness)
  36241. {
  36242. scrollbarThickness = thickness;
  36243. resized();
  36244. }
  36245. }
  36246. void CodeEditorComponent::handleAsyncUpdate()
  36247. {
  36248. rebuildLineTokens();
  36249. }
  36250. void CodeEditorComponent::rebuildLineTokens()
  36251. {
  36252. cancelPendingUpdate();
  36253. const int numNeeded = linesOnScreen + 1;
  36254. int minLineToRepaint = numNeeded;
  36255. int maxLineToRepaint = 0;
  36256. if (numNeeded != lines.size())
  36257. {
  36258. lines.clear();
  36259. for (int i = numNeeded; --i >= 0;)
  36260. lines.add (new CodeEditorLine());
  36261. minLineToRepaint = 0;
  36262. maxLineToRepaint = numNeeded;
  36263. }
  36264. jassert (numNeeded == lines.size());
  36265. CodeDocument::Iterator source (&document);
  36266. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  36267. for (int i = 0; i < numNeeded; ++i)
  36268. {
  36269. CodeEditorLine* const line = lines.getUnchecked(i);
  36270. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  36271. selectionStart, selectionEnd))
  36272. {
  36273. minLineToRepaint = jmin (minLineToRepaint, i);
  36274. maxLineToRepaint = jmax (maxLineToRepaint, i);
  36275. }
  36276. }
  36277. if (minLineToRepaint <= maxLineToRepaint)
  36278. {
  36279. repaint (gutter, lineHeight * minLineToRepaint - 1,
  36280. verticalScrollBar->getX() - gutter,
  36281. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  36282. }
  36283. }
  36284. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  36285. {
  36286. caretPos = newPos;
  36287. columnToTryToMaintain = -1;
  36288. if (highlighting)
  36289. {
  36290. if (dragType == notDragging)
  36291. {
  36292. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  36293. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  36294. dragType = draggingSelectionStart;
  36295. else
  36296. dragType = draggingSelectionEnd;
  36297. }
  36298. if (dragType == draggingSelectionStart)
  36299. {
  36300. selectionStart = caretPos;
  36301. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36302. {
  36303. const CodeDocument::Position temp (selectionStart);
  36304. selectionStart = selectionEnd;
  36305. selectionEnd = temp;
  36306. dragType = draggingSelectionEnd;
  36307. }
  36308. }
  36309. else
  36310. {
  36311. selectionEnd = caretPos;
  36312. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36313. {
  36314. const CodeDocument::Position temp (selectionStart);
  36315. selectionStart = selectionEnd;
  36316. selectionEnd = temp;
  36317. dragType = draggingSelectionStart;
  36318. }
  36319. }
  36320. triggerAsyncUpdate();
  36321. }
  36322. else
  36323. {
  36324. deselectAll();
  36325. }
  36326. ((CaretComponent*) caret)->updatePosition (*this);
  36327. scrollToKeepCaretOnScreen();
  36328. updateScrollBars();
  36329. }
  36330. void CodeEditorComponent::deselectAll()
  36331. {
  36332. if (selectionStart != selectionEnd)
  36333. triggerAsyncUpdate();
  36334. selectionStart = caretPos;
  36335. selectionEnd = caretPos;
  36336. }
  36337. void CodeEditorComponent::updateScrollBars()
  36338. {
  36339. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36340. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36341. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36342. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36343. }
  36344. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36345. {
  36346. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36347. newFirstLineOnScreen);
  36348. if (newFirstLineOnScreen != firstLineOnScreen)
  36349. {
  36350. firstLineOnScreen = newFirstLineOnScreen;
  36351. ((CaretComponent*) caret)->updatePosition (*this);
  36352. updateCachedIterators (firstLineOnScreen);
  36353. triggerAsyncUpdate();
  36354. }
  36355. }
  36356. void CodeEditorComponent::scrollToColumnInternal (double column)
  36357. {
  36358. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36359. if (xOffset != newOffset)
  36360. {
  36361. xOffset = newOffset;
  36362. ((CaretComponent*) caret)->updatePosition (*this);
  36363. repaint();
  36364. }
  36365. }
  36366. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36367. {
  36368. scrollToLineInternal (newFirstLineOnScreen);
  36369. updateScrollBars();
  36370. }
  36371. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36372. {
  36373. scrollToColumnInternal (newFirstColumnOnScreen);
  36374. updateScrollBars();
  36375. }
  36376. void CodeEditorComponent::scrollBy (int deltaLines)
  36377. {
  36378. scrollToLine (firstLineOnScreen + deltaLines);
  36379. }
  36380. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36381. {
  36382. if (caretPos.getLineNumber() < firstLineOnScreen)
  36383. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36384. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36385. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36386. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36387. if (column >= xOffset + columnsOnScreen - 1)
  36388. scrollToColumn (column + 1 - columnsOnScreen);
  36389. else if (column < xOffset)
  36390. scrollToColumn (column);
  36391. }
  36392. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36393. {
  36394. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36395. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36396. roundToInt (charWidth),
  36397. lineHeight);
  36398. }
  36399. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36400. {
  36401. const int line = y / lineHeight + firstLineOnScreen;
  36402. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36403. const int index = columnToIndex (line, column);
  36404. return CodeDocument::Position (&document, line, index);
  36405. }
  36406. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36407. {
  36408. document.deleteSection (selectionStart, selectionEnd);
  36409. if (newText.isNotEmpty())
  36410. document.insertText (caretPos, newText);
  36411. scrollToKeepCaretOnScreen();
  36412. }
  36413. void CodeEditorComponent::insertTabAtCaret()
  36414. {
  36415. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36416. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36417. {
  36418. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36419. }
  36420. if (useSpacesForTabs)
  36421. {
  36422. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36423. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36424. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36425. }
  36426. else
  36427. {
  36428. insertTextAtCaret (T("\t"));
  36429. }
  36430. }
  36431. void CodeEditorComponent::cut()
  36432. {
  36433. insertTextAtCaret (String::empty);
  36434. }
  36435. void CodeEditorComponent::copy()
  36436. {
  36437. newTransaction();
  36438. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36439. if (selection.isNotEmpty())
  36440. SystemClipboard::copyTextToClipboard (selection);
  36441. }
  36442. void CodeEditorComponent::copyThenCut()
  36443. {
  36444. copy();
  36445. cut();
  36446. newTransaction();
  36447. }
  36448. void CodeEditorComponent::paste()
  36449. {
  36450. newTransaction();
  36451. const String clip (SystemClipboard::getTextFromClipboard());
  36452. if (clip.isNotEmpty())
  36453. insertTextAtCaret (clip);
  36454. newTransaction();
  36455. }
  36456. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36457. {
  36458. newTransaction();
  36459. if (moveInWholeWordSteps)
  36460. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36461. else
  36462. moveCaretTo (caretPos.movedBy (-1), selecting);
  36463. }
  36464. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36465. {
  36466. newTransaction();
  36467. if (moveInWholeWordSteps)
  36468. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36469. else
  36470. moveCaretTo (caretPos.movedBy (1), selecting);
  36471. }
  36472. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36473. {
  36474. CodeDocument::Position pos (caretPos);
  36475. const int newLineNum = pos.getLineNumber() + delta;
  36476. if (columnToTryToMaintain < 0)
  36477. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36478. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36479. const int colToMaintain = columnToTryToMaintain;
  36480. moveCaretTo (pos, selecting);
  36481. columnToTryToMaintain = colToMaintain;
  36482. }
  36483. void CodeEditorComponent::cursorDown (const bool selecting)
  36484. {
  36485. newTransaction();
  36486. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36487. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36488. else
  36489. moveLineDelta (1, selecting);
  36490. }
  36491. void CodeEditorComponent::cursorUp (const bool selecting)
  36492. {
  36493. newTransaction();
  36494. if (caretPos.getLineNumber() == 0)
  36495. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36496. else
  36497. moveLineDelta (-1, selecting);
  36498. }
  36499. void CodeEditorComponent::pageDown (const bool selecting)
  36500. {
  36501. newTransaction();
  36502. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36503. moveLineDelta (linesOnScreen, selecting);
  36504. }
  36505. void CodeEditorComponent::pageUp (const bool selecting)
  36506. {
  36507. newTransaction();
  36508. scrollBy (-linesOnScreen);
  36509. moveLineDelta (-linesOnScreen, selecting);
  36510. }
  36511. void CodeEditorComponent::scrollUp()
  36512. {
  36513. newTransaction();
  36514. scrollBy (1);
  36515. if (caretPos.getLineNumber() < firstLineOnScreen)
  36516. moveLineDelta (1, false);
  36517. }
  36518. void CodeEditorComponent::scrollDown()
  36519. {
  36520. newTransaction();
  36521. scrollBy (-1);
  36522. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36523. moveLineDelta (-1, false);
  36524. }
  36525. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36526. {
  36527. newTransaction();
  36528. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36529. }
  36530. static int findFirstNonWhitespaceChar (const String& line) throw()
  36531. {
  36532. const int len = line.length();
  36533. for (int i = 0; i < len; ++i)
  36534. if (! CharacterFunctions::isWhitespace (line [i]))
  36535. return i;
  36536. return 0;
  36537. }
  36538. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36539. {
  36540. newTransaction();
  36541. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36542. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36543. index = 0;
  36544. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36545. }
  36546. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36547. {
  36548. newTransaction();
  36549. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36550. }
  36551. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36552. {
  36553. newTransaction();
  36554. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36555. }
  36556. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36557. {
  36558. if (moveInWholeWordSteps)
  36559. {
  36560. cut(); // in case something is already highlighted
  36561. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36562. }
  36563. else
  36564. {
  36565. if (selectionStart == selectionEnd)
  36566. selectionStart.moveBy (-1);
  36567. }
  36568. cut();
  36569. }
  36570. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36571. {
  36572. if (moveInWholeWordSteps)
  36573. {
  36574. cut(); // in case something is already highlighted
  36575. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36576. }
  36577. else
  36578. {
  36579. if (selectionStart == selectionEnd)
  36580. selectionEnd.moveBy (1);
  36581. else
  36582. newTransaction();
  36583. }
  36584. cut();
  36585. }
  36586. void CodeEditorComponent::selectAll()
  36587. {
  36588. newTransaction();
  36589. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36590. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36591. }
  36592. void CodeEditorComponent::undo()
  36593. {
  36594. document.undo();
  36595. scrollToKeepCaretOnScreen();
  36596. }
  36597. void CodeEditorComponent::redo()
  36598. {
  36599. document.redo();
  36600. scrollToKeepCaretOnScreen();
  36601. }
  36602. void CodeEditorComponent::newTransaction()
  36603. {
  36604. document.newTransaction();
  36605. startTimer (600);
  36606. }
  36607. void CodeEditorComponent::timerCallback()
  36608. {
  36609. newTransaction();
  36610. }
  36611. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36612. {
  36613. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36614. }
  36615. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36616. {
  36617. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36618. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36619. }
  36620. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36621. {
  36622. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36623. CodeDocument::Position (&document, range.getEnd()));
  36624. }
  36625. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36626. {
  36627. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36628. const bool shiftDown = key.getModifiers().isShiftDown();
  36629. if (key.isKeyCode (KeyPress::leftKey))
  36630. {
  36631. cursorLeft (moveInWholeWordSteps, shiftDown);
  36632. }
  36633. else if (key.isKeyCode (KeyPress::rightKey))
  36634. {
  36635. cursorRight (moveInWholeWordSteps, shiftDown);
  36636. }
  36637. else if (key.isKeyCode (KeyPress::upKey))
  36638. {
  36639. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36640. scrollDown();
  36641. #if JUCE_MAC
  36642. else if (key.getModifiers().isCommandDown())
  36643. goToStartOfDocument (shiftDown);
  36644. #endif
  36645. else
  36646. cursorUp (shiftDown);
  36647. }
  36648. else if (key.isKeyCode (KeyPress::downKey))
  36649. {
  36650. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36651. scrollUp();
  36652. #if JUCE_MAC
  36653. else if (key.getModifiers().isCommandDown())
  36654. goToEndOfDocument (shiftDown);
  36655. #endif
  36656. else
  36657. cursorDown (shiftDown);
  36658. }
  36659. else if (key.isKeyCode (KeyPress::pageDownKey))
  36660. {
  36661. pageDown (shiftDown);
  36662. }
  36663. else if (key.isKeyCode (KeyPress::pageUpKey))
  36664. {
  36665. pageUp (shiftDown);
  36666. }
  36667. else if (key.isKeyCode (KeyPress::homeKey))
  36668. {
  36669. if (moveInWholeWordSteps)
  36670. goToStartOfDocument (shiftDown);
  36671. else
  36672. goToStartOfLine (shiftDown);
  36673. }
  36674. else if (key.isKeyCode (KeyPress::endKey))
  36675. {
  36676. if (moveInWholeWordSteps)
  36677. goToEndOfDocument (shiftDown);
  36678. else
  36679. goToEndOfLine (shiftDown);
  36680. }
  36681. else if (key.isKeyCode (KeyPress::backspaceKey))
  36682. {
  36683. backspace (moveInWholeWordSteps);
  36684. }
  36685. else if (key.isKeyCode (KeyPress::deleteKey))
  36686. {
  36687. deleteForward (moveInWholeWordSteps);
  36688. }
  36689. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36690. {
  36691. copy();
  36692. }
  36693. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36694. {
  36695. copyThenCut();
  36696. }
  36697. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36698. {
  36699. paste();
  36700. }
  36701. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36702. {
  36703. undo();
  36704. }
  36705. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36706. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36707. {
  36708. redo();
  36709. }
  36710. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36711. {
  36712. selectAll();
  36713. }
  36714. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36715. {
  36716. insertTabAtCaret();
  36717. }
  36718. else if (key == KeyPress::returnKey)
  36719. {
  36720. newTransaction();
  36721. insertTextAtCaret (document.getNewLineCharacters());
  36722. }
  36723. else if (key.isKeyCode (KeyPress::escapeKey))
  36724. {
  36725. newTransaction();
  36726. }
  36727. else if (key.getTextCharacter() >= ' ')
  36728. {
  36729. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36730. }
  36731. else
  36732. {
  36733. return false;
  36734. }
  36735. return true;
  36736. }
  36737. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36738. {
  36739. newTransaction();
  36740. dragType = notDragging;
  36741. if (! e.mods.isPopupMenu())
  36742. {
  36743. beginDragAutoRepeat (100);
  36744. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36745. }
  36746. else
  36747. {
  36748. }
  36749. }
  36750. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36751. {
  36752. if (! e.mods.isPopupMenu())
  36753. moveCaretTo (getPositionAt (e.x, e.y), true);
  36754. }
  36755. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36756. {
  36757. newTransaction();
  36758. beginDragAutoRepeat (0);
  36759. dragType = notDragging;
  36760. }
  36761. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36762. {
  36763. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36764. CodeDocument::Position tokenEnd (tokenStart);
  36765. if (e.getNumberOfClicks() > 2)
  36766. {
  36767. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36768. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36769. }
  36770. else
  36771. {
  36772. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36773. tokenEnd.moveBy (1);
  36774. tokenStart = tokenEnd;
  36775. while (tokenStart.getIndexInLine() > 0
  36776. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36777. tokenStart.moveBy (-1);
  36778. }
  36779. moveCaretTo (tokenEnd, false);
  36780. moveCaretTo (tokenStart, true);
  36781. }
  36782. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36783. {
  36784. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36785. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36786. }
  36787. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  36788. {
  36789. if (scrollBarThatHasMoved == verticalScrollBar)
  36790. scrollToLineInternal ((int) newRangeStart);
  36791. else
  36792. scrollToColumnInternal (newRangeStart);
  36793. }
  36794. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36795. {
  36796. useSpacesForTabs = insertSpaces;
  36797. if (spacesPerTab != numSpaces)
  36798. {
  36799. spacesPerTab = numSpaces;
  36800. triggerAsyncUpdate();
  36801. }
  36802. }
  36803. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36804. {
  36805. const String line (document.getLine (lineNum));
  36806. jassert (index <= line.length());
  36807. int col = 0;
  36808. for (int i = 0; i < index; ++i)
  36809. {
  36810. if (line[i] != T('\t'))
  36811. ++col;
  36812. else
  36813. col += getTabSize() - (col % getTabSize());
  36814. }
  36815. return col;
  36816. }
  36817. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36818. {
  36819. const String line (document.getLine (lineNum));
  36820. const int lineLength = line.length();
  36821. int i, col = 0;
  36822. for (i = 0; i < lineLength; ++i)
  36823. {
  36824. if (line[i] != T('\t'))
  36825. ++col;
  36826. else
  36827. col += getTabSize() - (col % getTabSize());
  36828. if (col > column)
  36829. break;
  36830. }
  36831. return i;
  36832. }
  36833. void CodeEditorComponent::setFont (const Font& newFont)
  36834. {
  36835. font = newFont;
  36836. charWidth = font.getStringWidthFloat (T("0"));
  36837. lineHeight = roundToInt (font.getHeight());
  36838. resized();
  36839. }
  36840. void CodeEditorComponent::resetToDefaultColours()
  36841. {
  36842. coloursForTokenCategories.clear();
  36843. if (codeTokeniser != 0)
  36844. {
  36845. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36846. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36847. }
  36848. }
  36849. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36850. {
  36851. jassert (tokenType < 256);
  36852. while (coloursForTokenCategories.size() < tokenType)
  36853. coloursForTokenCategories.add (Colours::black);
  36854. coloursForTokenCategories.set (tokenType, colour);
  36855. repaint();
  36856. }
  36857. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36858. {
  36859. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36860. return findColour (CodeEditorComponent::defaultTextColourId);
  36861. return coloursForTokenCategories.getReference (tokenType);
  36862. }
  36863. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36864. {
  36865. int i;
  36866. for (i = cachedIterators.size(); --i >= 0;)
  36867. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36868. break;
  36869. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36870. }
  36871. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36872. {
  36873. const int maxNumCachedPositions = 5000;
  36874. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36875. if (cachedIterators.size() == 0)
  36876. cachedIterators.add (new CodeDocument::Iterator (&document));
  36877. if (codeTokeniser == 0)
  36878. return;
  36879. for (;;)
  36880. {
  36881. CodeDocument::Iterator* last = cachedIterators.getLast();
  36882. if (last->getLine() >= maxLineNum)
  36883. break;
  36884. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36885. cachedIterators.add (t);
  36886. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36887. for (;;)
  36888. {
  36889. codeTokeniser->readNextToken (*t);
  36890. if (t->getLine() >= targetLine)
  36891. break;
  36892. if (t->isEOF())
  36893. return;
  36894. }
  36895. }
  36896. }
  36897. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36898. {
  36899. if (codeTokeniser == 0)
  36900. return;
  36901. for (int i = cachedIterators.size(); --i >= 0;)
  36902. {
  36903. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36904. if (t->getPosition() <= position)
  36905. {
  36906. source = *t;
  36907. break;
  36908. }
  36909. }
  36910. while (source.getPosition() < position)
  36911. {
  36912. const CodeDocument::Iterator original (source);
  36913. codeTokeniser->readNextToken (source);
  36914. if (source.getPosition() > position || source.isEOF())
  36915. {
  36916. source = original;
  36917. break;
  36918. }
  36919. }
  36920. }
  36921. END_JUCE_NAMESPACE
  36922. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36923. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36924. BEGIN_JUCE_NAMESPACE
  36925. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36926. {
  36927. }
  36928. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36929. {
  36930. }
  36931. namespace CppTokeniser
  36932. {
  36933. static bool isIdentifierStart (const tchar c) throw()
  36934. {
  36935. return CharacterFunctions::isLetter (c)
  36936. || c == T('_') || c == T('@');
  36937. }
  36938. static bool isIdentifierBody (const tchar c) throw()
  36939. {
  36940. return CharacterFunctions::isLetter (c)
  36941. || CharacterFunctions::isDigit (c)
  36942. || c == T('_') || c == T('@');
  36943. }
  36944. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36945. {
  36946. static const tchar* keywords2Char[] =
  36947. { T("if"), T("do"), T("or"), 0 };
  36948. static const tchar* keywords3Char[] =
  36949. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36950. static const tchar* keywords4Char[] =
  36951. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36952. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36953. static const tchar* keywords5Char[] =
  36954. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36955. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36956. static const tchar* keywords6Char[] =
  36957. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36958. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36959. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36960. static const tchar* keywordsOther[] =
  36961. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36962. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36963. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36964. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36965. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36966. int tokenLength = 0;
  36967. tchar possibleIdentifier [19];
  36968. while (isIdentifierBody (source.peekNextChar()))
  36969. {
  36970. const tchar c = source.nextChar();
  36971. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36972. possibleIdentifier [tokenLength] = c;
  36973. ++tokenLength;
  36974. }
  36975. if (tokenLength > 1 && tokenLength <= 16)
  36976. {
  36977. possibleIdentifier [tokenLength] = 0;
  36978. const tchar** k;
  36979. switch (tokenLength)
  36980. {
  36981. case 2: k = keywords2Char; break;
  36982. case 3: k = keywords3Char; break;
  36983. case 4: k = keywords4Char; break;
  36984. case 5: k = keywords5Char; break;
  36985. case 6: k = keywords6Char; break;
  36986. default: k = keywordsOther; break;
  36987. }
  36988. int i = 0;
  36989. while (k[i] != 0)
  36990. {
  36991. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36992. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36993. ++i;
  36994. }
  36995. }
  36996. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36997. }
  36998. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36999. {
  37000. const juce_wchar c = source.peekNextChar();
  37001. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  37002. source.skip();
  37003. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  37004. return false;
  37005. return true;
  37006. }
  37007. static bool isHexDigit (const juce_wchar c) throw()
  37008. {
  37009. return (c >= '0' && c <= '9')
  37010. || (c >= 'a' && c <= 'f')
  37011. || (c >= 'A' && c <= 'F');
  37012. }
  37013. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  37014. {
  37015. if (source.nextChar() != '0')
  37016. return false;
  37017. juce_wchar c = source.nextChar();
  37018. if (c != 'x' && c != 'X')
  37019. return false;
  37020. int numDigits = 0;
  37021. while (isHexDigit (source.peekNextChar()))
  37022. {
  37023. ++numDigits;
  37024. source.skip();
  37025. }
  37026. if (numDigits == 0)
  37027. return false;
  37028. return skipNumberSuffix (source);
  37029. }
  37030. static bool isOctalDigit (const juce_wchar c) throw()
  37031. {
  37032. return c >= '0' && c <= '7';
  37033. }
  37034. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  37035. {
  37036. if (source.nextChar() != '0')
  37037. return false;
  37038. if (! isOctalDigit (source.nextChar()))
  37039. return false;
  37040. while (isOctalDigit (source.peekNextChar()))
  37041. source.skip();
  37042. return skipNumberSuffix (source);
  37043. }
  37044. static bool isDecimalDigit (const juce_wchar c) throw()
  37045. {
  37046. return c >= '0' && c <= '9';
  37047. }
  37048. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  37049. {
  37050. int numChars = 0;
  37051. while (isDecimalDigit (source.peekNextChar()))
  37052. {
  37053. ++numChars;
  37054. source.skip();
  37055. }
  37056. if (numChars == 0)
  37057. return false;
  37058. return skipNumberSuffix (source);
  37059. }
  37060. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  37061. {
  37062. int numDigits = 0;
  37063. while (isDecimalDigit (source.peekNextChar()))
  37064. {
  37065. source.skip();
  37066. ++numDigits;
  37067. }
  37068. const bool hasPoint = (source.peekNextChar() == '.');
  37069. if (hasPoint)
  37070. {
  37071. source.skip();
  37072. while (isDecimalDigit (source.peekNextChar()))
  37073. {
  37074. source.skip();
  37075. ++numDigits;
  37076. }
  37077. }
  37078. if (numDigits == 0)
  37079. return false;
  37080. juce_wchar c = source.peekNextChar();
  37081. const bool hasExponent = (c == 'e' || c == 'E');
  37082. if (hasExponent)
  37083. {
  37084. source.skip();
  37085. c = source.peekNextChar();
  37086. if (c == '+' || c == '-')
  37087. source.skip();
  37088. int numExpDigits = 0;
  37089. while (isDecimalDigit (source.peekNextChar()))
  37090. {
  37091. source.skip();
  37092. ++numExpDigits;
  37093. }
  37094. if (numExpDigits == 0)
  37095. return false;
  37096. }
  37097. c = source.peekNextChar();
  37098. if (c == 'f' || c == 'F')
  37099. source.skip();
  37100. else if (! (hasExponent || hasPoint))
  37101. return false;
  37102. return true;
  37103. }
  37104. static int parseNumber (CodeDocument::Iterator& source)
  37105. {
  37106. const CodeDocument::Iterator original (source);
  37107. if (parseFloatLiteral (source))
  37108. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  37109. source = original;
  37110. if (parseHexLiteral (source))
  37111. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37112. source = original;
  37113. if (parseOctalLiteral (source))
  37114. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37115. source = original;
  37116. if (parseDecimalLiteral (source))
  37117. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37118. source = original;
  37119. source.skip();
  37120. return CPlusPlusCodeTokeniser::tokenType_error;
  37121. }
  37122. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  37123. {
  37124. const juce_wchar quote = source.nextChar();
  37125. for (;;)
  37126. {
  37127. const juce_wchar c = source.nextChar();
  37128. if (c == quote || c == 0)
  37129. break;
  37130. if (c == '\\')
  37131. source.skip();
  37132. }
  37133. }
  37134. static void skipComment (CodeDocument::Iterator& source) throw()
  37135. {
  37136. bool lastWasStar = false;
  37137. for (;;)
  37138. {
  37139. const juce_wchar c = source.nextChar();
  37140. if (c == 0 || (c == T('/') && lastWasStar))
  37141. break;
  37142. lastWasStar = (c == '*');
  37143. }
  37144. }
  37145. }
  37146. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  37147. {
  37148. int result = tokenType_error;
  37149. source.skipWhitespace();
  37150. tchar firstChar = source.peekNextChar();
  37151. switch (firstChar)
  37152. {
  37153. case 0:
  37154. source.skip();
  37155. break;
  37156. case T('0'):
  37157. case T('1'):
  37158. case T('2'):
  37159. case T('3'):
  37160. case T('4'):
  37161. case T('5'):
  37162. case T('6'):
  37163. case T('7'):
  37164. case T('8'):
  37165. case T('9'):
  37166. result = CppTokeniser::parseNumber (source);
  37167. break;
  37168. case T('.'):
  37169. result = CppTokeniser::parseNumber (source);
  37170. if (result == tokenType_error)
  37171. result = tokenType_punctuation;
  37172. break;
  37173. case T(','):
  37174. case T(';'):
  37175. case T(':'):
  37176. source.skip();
  37177. result = tokenType_punctuation;
  37178. break;
  37179. case T('('):
  37180. case T(')'):
  37181. case T('{'):
  37182. case T('}'):
  37183. case T('['):
  37184. case T(']'):
  37185. source.skip();
  37186. result = tokenType_bracket;
  37187. break;
  37188. case T('"'):
  37189. case T('\''):
  37190. CppTokeniser::skipQuotedString (source);
  37191. result = tokenType_stringLiteral;
  37192. break;
  37193. case T('+'):
  37194. result = tokenType_operator;
  37195. source.skip();
  37196. if (source.peekNextChar() == T('+'))
  37197. source.skip();
  37198. else if (source.peekNextChar() == T('='))
  37199. source.skip();
  37200. break;
  37201. case T('-'):
  37202. source.skip();
  37203. result = CppTokeniser::parseNumber (source);
  37204. if (result == tokenType_error)
  37205. {
  37206. result = tokenType_operator;
  37207. if (source.peekNextChar() == T('-'))
  37208. source.skip();
  37209. else if (source.peekNextChar() == T('='))
  37210. source.skip();
  37211. }
  37212. break;
  37213. case T('*'):
  37214. case T('%'):
  37215. case T('='):
  37216. case T('!'):
  37217. result = tokenType_operator;
  37218. source.skip();
  37219. if (source.peekNextChar() == T('='))
  37220. source.skip();
  37221. break;
  37222. case T('/'):
  37223. result = tokenType_operator;
  37224. source.skip();
  37225. if (source.peekNextChar() == T('='))
  37226. {
  37227. source.skip();
  37228. }
  37229. else if (source.peekNextChar() == T('/'))
  37230. {
  37231. result = tokenType_comment;
  37232. source.skipToEndOfLine();
  37233. }
  37234. else if (source.peekNextChar() == T('*'))
  37235. {
  37236. source.skip();
  37237. result = tokenType_comment;
  37238. CppTokeniser::skipComment (source);
  37239. }
  37240. break;
  37241. case T('?'):
  37242. case T('~'):
  37243. source.skip();
  37244. result = tokenType_operator;
  37245. break;
  37246. case T('<'):
  37247. source.skip();
  37248. result = tokenType_operator;
  37249. if (source.peekNextChar() == T('='))
  37250. {
  37251. source.skip();
  37252. }
  37253. else if (source.peekNextChar() == T('<'))
  37254. {
  37255. source.skip();
  37256. if (source.peekNextChar() == T('='))
  37257. source.skip();
  37258. }
  37259. break;
  37260. case T('>'):
  37261. source.skip();
  37262. result = tokenType_operator;
  37263. if (source.peekNextChar() == T('='))
  37264. {
  37265. source.skip();
  37266. }
  37267. else if (source.peekNextChar() == T('<'))
  37268. {
  37269. source.skip();
  37270. if (source.peekNextChar() == T('='))
  37271. source.skip();
  37272. }
  37273. break;
  37274. case T('|'):
  37275. source.skip();
  37276. result = tokenType_operator;
  37277. if (source.peekNextChar() == T('='))
  37278. {
  37279. source.skip();
  37280. }
  37281. else if (source.peekNextChar() == T('|'))
  37282. {
  37283. source.skip();
  37284. if (source.peekNextChar() == T('='))
  37285. source.skip();
  37286. }
  37287. break;
  37288. case T('&'):
  37289. source.skip();
  37290. result = tokenType_operator;
  37291. if (source.peekNextChar() == T('='))
  37292. {
  37293. source.skip();
  37294. }
  37295. else if (source.peekNextChar() == T('&'))
  37296. {
  37297. source.skip();
  37298. if (source.peekNextChar() == T('='))
  37299. source.skip();
  37300. }
  37301. break;
  37302. case T('^'):
  37303. source.skip();
  37304. result = tokenType_operator;
  37305. if (source.peekNextChar() == T('='))
  37306. {
  37307. source.skip();
  37308. }
  37309. else if (source.peekNextChar() == T('^'))
  37310. {
  37311. source.skip();
  37312. if (source.peekNextChar() == T('='))
  37313. source.skip();
  37314. }
  37315. break;
  37316. case T('#'):
  37317. result = tokenType_preprocessor;
  37318. source.skipToEndOfLine();
  37319. break;
  37320. default:
  37321. if (CppTokeniser::isIdentifierStart (firstChar))
  37322. result = CppTokeniser::parseIdentifier (source);
  37323. else
  37324. source.skip();
  37325. break;
  37326. }
  37327. //jassert (result != tokenType_unknown);
  37328. return result;
  37329. }
  37330. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37331. {
  37332. StringArray s;
  37333. s.add ("Error");
  37334. s.add ("Comment");
  37335. s.add ("C++ keyword");
  37336. s.add ("Identifier");
  37337. s.add ("Integer literal");
  37338. s.add ("Float literal");
  37339. s.add ("String literal");
  37340. s.add ("Operator");
  37341. s.add ("Bracket");
  37342. s.add ("Punctuation");
  37343. s.add ("Preprocessor line");
  37344. return s;
  37345. }
  37346. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37347. {
  37348. const uint32 colours[] =
  37349. {
  37350. 0xffcc0000, // error
  37351. 0xff00aa00, // comment
  37352. 0xff0000cc, // keyword
  37353. 0xff000000, // identifier
  37354. 0xff880000, // int literal
  37355. 0xff885500, // float literal
  37356. 0xff990099, // string literal
  37357. 0xff225500, // operator
  37358. 0xff000055, // bracket
  37359. 0xff004400, // punctuation
  37360. 0xff660000 // preprocessor
  37361. };
  37362. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37363. return Colour (colours [tokenType]);
  37364. return Colours::black;
  37365. }
  37366. END_JUCE_NAMESPACE
  37367. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37368. /*** Start of inlined file: juce_ComboBox.cpp ***/
  37369. BEGIN_JUCE_NAMESPACE
  37370. ComboBox::ComboBox (const String& name)
  37371. : Component (name),
  37372. lastCurrentId (0),
  37373. isButtonDown (false),
  37374. separatorPending (false),
  37375. menuActive (false),
  37376. label (0)
  37377. {
  37378. noChoicesMessage = TRANS("(no choices)");
  37379. setRepaintsOnMouseActivity (true);
  37380. lookAndFeelChanged();
  37381. currentId.addListener (this);
  37382. }
  37383. ComboBox::~ComboBox()
  37384. {
  37385. currentId.removeListener (this);
  37386. if (menuActive)
  37387. PopupMenu::dismissAllActiveMenus();
  37388. label = 0;
  37389. deleteAllChildren();
  37390. }
  37391. void ComboBox::setEditableText (const bool isEditable)
  37392. {
  37393. label->setEditable (isEditable, isEditable, false);
  37394. setWantsKeyboardFocus (! isEditable);
  37395. resized();
  37396. }
  37397. bool ComboBox::isTextEditable() const throw()
  37398. {
  37399. return label->isEditable();
  37400. }
  37401. void ComboBox::setJustificationType (const Justification& justification) throw()
  37402. {
  37403. label->setJustificationType (justification);
  37404. }
  37405. const Justification ComboBox::getJustificationType() const throw()
  37406. {
  37407. return label->getJustificationType();
  37408. }
  37409. void ComboBox::setTooltip (const String& newTooltip)
  37410. {
  37411. SettableTooltipClient::setTooltip (newTooltip);
  37412. label->setTooltip (newTooltip);
  37413. }
  37414. void ComboBox::addItem (const String& newItemText,
  37415. const int newItemId) throw()
  37416. {
  37417. // you can't add empty strings to the list..
  37418. jassert (newItemText.isNotEmpty());
  37419. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37420. jassert (newItemId != 0);
  37421. // you shouldn't use duplicate item IDs!
  37422. jassert (getItemForId (newItemId) == 0);
  37423. if (newItemText.isNotEmpty() && newItemId != 0)
  37424. {
  37425. if (separatorPending)
  37426. {
  37427. separatorPending = false;
  37428. ItemInfo* const item = new ItemInfo();
  37429. item->itemId = 0;
  37430. item->isEnabled = false;
  37431. item->isHeading = false;
  37432. items.add (item);
  37433. }
  37434. ItemInfo* const item = new ItemInfo();
  37435. item->name = newItemText;
  37436. item->itemId = newItemId;
  37437. item->isEnabled = true;
  37438. item->isHeading = false;
  37439. items.add (item);
  37440. }
  37441. }
  37442. void ComboBox::addSeparator() throw()
  37443. {
  37444. separatorPending = (items.size() > 0);
  37445. }
  37446. void ComboBox::addSectionHeading (const String& headingName) throw()
  37447. {
  37448. // you can't add empty strings to the list..
  37449. jassert (headingName.isNotEmpty());
  37450. if (headingName.isNotEmpty())
  37451. {
  37452. if (separatorPending)
  37453. {
  37454. separatorPending = false;
  37455. ItemInfo* const item = new ItemInfo();
  37456. item->itemId = 0;
  37457. item->isEnabled = false;
  37458. item->isHeading = false;
  37459. items.add (item);
  37460. }
  37461. ItemInfo* const item = new ItemInfo();
  37462. item->name = headingName;
  37463. item->itemId = 0;
  37464. item->isEnabled = true;
  37465. item->isHeading = true;
  37466. items.add (item);
  37467. }
  37468. }
  37469. void ComboBox::setItemEnabled (const int itemId,
  37470. const bool shouldBeEnabled) throw()
  37471. {
  37472. ItemInfo* const item = getItemForId (itemId);
  37473. if (item != 0)
  37474. item->isEnabled = shouldBeEnabled;
  37475. }
  37476. void ComboBox::changeItemText (const int itemId,
  37477. const String& newText) throw()
  37478. {
  37479. ItemInfo* const item = getItemForId (itemId);
  37480. jassert (item != 0);
  37481. if (item != 0)
  37482. item->name = newText;
  37483. }
  37484. void ComboBox::clear (const bool dontSendChangeMessage)
  37485. {
  37486. items.clear();
  37487. separatorPending = false;
  37488. if (! label->isEditable())
  37489. setSelectedItemIndex (-1, dontSendChangeMessage);
  37490. }
  37491. bool ComboBox::ItemInfo::isSeparator() const throw()
  37492. {
  37493. return name.isEmpty();
  37494. }
  37495. bool ComboBox::ItemInfo::isRealItem() const throw()
  37496. {
  37497. return ! (isHeading || name.isEmpty());
  37498. }
  37499. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37500. {
  37501. if (itemId != 0)
  37502. {
  37503. for (int i = items.size(); --i >= 0;)
  37504. if (items.getUnchecked(i)->itemId == itemId)
  37505. return items.getUnchecked(i);
  37506. }
  37507. return 0;
  37508. }
  37509. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37510. {
  37511. int n = 0;
  37512. for (int i = 0; i < items.size(); ++i)
  37513. {
  37514. ItemInfo* const item = items.getUnchecked(i);
  37515. if (item->isRealItem())
  37516. if (n++ == index)
  37517. return item;
  37518. }
  37519. return 0;
  37520. }
  37521. int ComboBox::getNumItems() const throw()
  37522. {
  37523. int n = 0;
  37524. for (int i = items.size(); --i >= 0;)
  37525. if (items.getUnchecked(i)->isRealItem())
  37526. ++n;
  37527. return n;
  37528. }
  37529. const String ComboBox::getItemText (const int index) const throw()
  37530. {
  37531. const ItemInfo* const item = getItemForIndex (index);
  37532. if (item != 0)
  37533. return item->name;
  37534. return String::empty;
  37535. }
  37536. int ComboBox::getItemId (const int index) const throw()
  37537. {
  37538. const ItemInfo* const item = getItemForIndex (index);
  37539. return (item != 0) ? item->itemId : 0;
  37540. }
  37541. int ComboBox::indexOfItemId (const int itemId) const throw()
  37542. {
  37543. int n = 0;
  37544. for (int i = 0; i < items.size(); ++i)
  37545. {
  37546. const ItemInfo* const item = items.getUnchecked(i);
  37547. if (item->isRealItem())
  37548. {
  37549. if (item->itemId == itemId)
  37550. return n;
  37551. ++n;
  37552. }
  37553. }
  37554. return -1;
  37555. }
  37556. int ComboBox::getSelectedItemIndex() const throw()
  37557. {
  37558. int index = indexOfItemId (currentId.getValue());
  37559. if (getText() != getItemText (index))
  37560. index = -1;
  37561. return index;
  37562. }
  37563. void ComboBox::setSelectedItemIndex (const int index,
  37564. const bool dontSendChangeMessage) throw()
  37565. {
  37566. setSelectedId (getItemId (index), dontSendChangeMessage);
  37567. }
  37568. int ComboBox::getSelectedId() const throw()
  37569. {
  37570. const ItemInfo* const item = getItemForId (currentId.getValue());
  37571. return (item != 0 && getText() == item->name)
  37572. ? item->itemId
  37573. : 0;
  37574. }
  37575. void ComboBox::setSelectedId (const int newItemId,
  37576. const bool dontSendChangeMessage) throw()
  37577. {
  37578. const ItemInfo* const item = getItemForId (newItemId);
  37579. const String newItemText (item != 0 ? item->name : String::empty);
  37580. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37581. {
  37582. if (! dontSendChangeMessage)
  37583. triggerAsyncUpdate();
  37584. label->setText (newItemText, false);
  37585. lastCurrentId = newItemId;
  37586. currentId = newItemId;
  37587. repaint(); // for the benefit of the 'none selected' text
  37588. }
  37589. }
  37590. void ComboBox::valueChanged (Value&)
  37591. {
  37592. if (lastCurrentId != (int) currentId.getValue())
  37593. setSelectedId (currentId.getValue(), false);
  37594. }
  37595. const String ComboBox::getText() const throw()
  37596. {
  37597. return label->getText();
  37598. }
  37599. void ComboBox::setText (const String& newText,
  37600. const bool dontSendChangeMessage) throw()
  37601. {
  37602. for (int i = items.size(); --i >= 0;)
  37603. {
  37604. const ItemInfo* const item = items.getUnchecked(i);
  37605. if (item->isRealItem()
  37606. && item->name == newText)
  37607. {
  37608. setSelectedId (item->itemId, dontSendChangeMessage);
  37609. return;
  37610. }
  37611. }
  37612. lastCurrentId = 0;
  37613. currentId = 0;
  37614. if (label->getText() != newText)
  37615. {
  37616. label->setText (newText, false);
  37617. if (! dontSendChangeMessage)
  37618. triggerAsyncUpdate();
  37619. }
  37620. repaint();
  37621. }
  37622. void ComboBox::showEditor()
  37623. {
  37624. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37625. label->showEditor();
  37626. }
  37627. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37628. {
  37629. textWhenNothingSelected = newMessage;
  37630. repaint();
  37631. }
  37632. const String ComboBox::getTextWhenNothingSelected() const throw()
  37633. {
  37634. return textWhenNothingSelected;
  37635. }
  37636. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37637. {
  37638. noChoicesMessage = newMessage;
  37639. }
  37640. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37641. {
  37642. return noChoicesMessage;
  37643. }
  37644. void ComboBox::paint (Graphics& g)
  37645. {
  37646. getLookAndFeel().drawComboBox (g,
  37647. getWidth(),
  37648. getHeight(),
  37649. isButtonDown,
  37650. label->getRight(),
  37651. 0,
  37652. getWidth() - label->getRight(),
  37653. getHeight(),
  37654. *this);
  37655. if (textWhenNothingSelected.isNotEmpty()
  37656. && label->getText().isEmpty()
  37657. && ! label->isBeingEdited())
  37658. {
  37659. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37660. g.setFont (label->getFont());
  37661. g.drawFittedText (textWhenNothingSelected,
  37662. label->getX() + 2, label->getY() + 1,
  37663. label->getWidth() - 4, label->getHeight() - 2,
  37664. label->getJustificationType(),
  37665. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37666. }
  37667. }
  37668. void ComboBox::resized()
  37669. {
  37670. if (getHeight() > 0 && getWidth() > 0)
  37671. getLookAndFeel().positionComboBoxText (*this, *label);
  37672. }
  37673. void ComboBox::enablementChanged()
  37674. {
  37675. repaint();
  37676. }
  37677. void ComboBox::lookAndFeelChanged()
  37678. {
  37679. repaint();
  37680. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37681. if (label != 0)
  37682. {
  37683. newLabel->setEditable (label->isEditable());
  37684. newLabel->setJustificationType (label->getJustificationType());
  37685. newLabel->setTooltip (label->getTooltip());
  37686. newLabel->setText (label->getText(), false);
  37687. }
  37688. label = newLabel;
  37689. addAndMakeVisible (newLabel);
  37690. newLabel->addListener (this);
  37691. newLabel->addMouseListener (this, false);
  37692. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37693. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37694. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37695. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37696. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37697. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37698. resized();
  37699. }
  37700. void ComboBox::colourChanged()
  37701. {
  37702. lookAndFeelChanged();
  37703. }
  37704. bool ComboBox::keyPressed (const KeyPress& key)
  37705. {
  37706. bool used = false;
  37707. if (key.isKeyCode (KeyPress::upKey)
  37708. || key.isKeyCode (KeyPress::leftKey))
  37709. {
  37710. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37711. used = true;
  37712. }
  37713. else if (key.isKeyCode (KeyPress::downKey)
  37714. || key.isKeyCode (KeyPress::rightKey))
  37715. {
  37716. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37717. used = true;
  37718. }
  37719. else if (key.isKeyCode (KeyPress::returnKey))
  37720. {
  37721. showPopup();
  37722. used = true;
  37723. }
  37724. return used;
  37725. }
  37726. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37727. {
  37728. // only forward key events that aren't used by this component
  37729. return isKeyDown
  37730. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37731. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37732. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37733. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37734. }
  37735. void ComboBox::focusGained (FocusChangeType)
  37736. {
  37737. repaint();
  37738. }
  37739. void ComboBox::focusLost (FocusChangeType)
  37740. {
  37741. repaint();
  37742. }
  37743. void ComboBox::labelTextChanged (Label*)
  37744. {
  37745. triggerAsyncUpdate();
  37746. }
  37747. void ComboBox::showPopup()
  37748. {
  37749. if (! menuActive)
  37750. {
  37751. const int selectedId = getSelectedId();
  37752. ComponentDeletionWatcher deletionWatcher (this);
  37753. PopupMenu menu;
  37754. menu.setLookAndFeel (&getLookAndFeel());
  37755. for (int i = 0; i < items.size(); ++i)
  37756. {
  37757. const ItemInfo* const item = items.getUnchecked(i);
  37758. if (item->isSeparator())
  37759. menu.addSeparator();
  37760. else if (item->isHeading)
  37761. menu.addSectionHeader (item->name);
  37762. else
  37763. menu.addItem (item->itemId, item->name,
  37764. item->isEnabled, item->itemId == selectedId);
  37765. }
  37766. if (items.size() == 0)
  37767. menu.addItem (1, noChoicesMessage, false);
  37768. const int itemHeight = jlimit (12, 24, getHeight());
  37769. menuActive = true;
  37770. const int resultId = menu.showAt (this, selectedId,
  37771. getWidth(), 1, itemHeight);
  37772. if (deletionWatcher.hasBeenDeleted())
  37773. return;
  37774. menuActive = false;
  37775. if (resultId != 0)
  37776. setSelectedId (resultId);
  37777. }
  37778. }
  37779. void ComboBox::mouseDown (const MouseEvent& e)
  37780. {
  37781. beginDragAutoRepeat (300);
  37782. isButtonDown = isEnabled();
  37783. if (isButtonDown
  37784. && (e.eventComponent == this || ! label->isEditable()))
  37785. {
  37786. showPopup();
  37787. }
  37788. }
  37789. void ComboBox::mouseDrag (const MouseEvent& e)
  37790. {
  37791. beginDragAutoRepeat (50);
  37792. if (isButtonDown && ! e.mouseWasClicked())
  37793. showPopup();
  37794. }
  37795. void ComboBox::mouseUp (const MouseEvent& e2)
  37796. {
  37797. if (isButtonDown)
  37798. {
  37799. isButtonDown = false;
  37800. repaint();
  37801. const MouseEvent e (e2.getEventRelativeTo (this));
  37802. if (reallyContains (e.x, e.y, true)
  37803. && (e2.eventComponent == this || ! label->isEditable()))
  37804. {
  37805. showPopup();
  37806. }
  37807. }
  37808. }
  37809. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37810. {
  37811. jassert (listener != 0);
  37812. if (listener != 0)
  37813. listeners.add (listener);
  37814. }
  37815. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37816. {
  37817. listeners.removeValue (listener);
  37818. }
  37819. void ComboBox::handleAsyncUpdate()
  37820. {
  37821. for (int i = listeners.size(); --i >= 0;)
  37822. {
  37823. ((ComboBoxListener*) listeners.getUnchecked (i))->comboBoxChanged (this);
  37824. i = jmin (i, listeners.size());
  37825. }
  37826. }
  37827. END_JUCE_NAMESPACE
  37828. /*** End of inlined file: juce_ComboBox.cpp ***/
  37829. /*** Start of inlined file: juce_Label.cpp ***/
  37830. BEGIN_JUCE_NAMESPACE
  37831. Label::Label (const String& componentName,
  37832. const String& labelText)
  37833. : Component (componentName),
  37834. textValue (labelText),
  37835. lastTextValue (labelText),
  37836. font (15.0f),
  37837. justification (Justification::centredLeft),
  37838. ownerComponent (0),
  37839. horizontalBorderSize (5),
  37840. verticalBorderSize (1),
  37841. minimumHorizontalScale (0.7f),
  37842. editSingleClick (false),
  37843. editDoubleClick (false),
  37844. lossOfFocusDiscardsChanges (false)
  37845. {
  37846. setColour (TextEditor::textColourId, Colours::black);
  37847. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37848. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37849. textValue.addListener (this);
  37850. }
  37851. Label::~Label()
  37852. {
  37853. textValue.removeListener (this);
  37854. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37855. ownerComponent->removeComponentListener (this);
  37856. editor = 0;
  37857. }
  37858. void Label::setText (const String& newText,
  37859. const bool broadcastChangeMessage)
  37860. {
  37861. hideEditor (true);
  37862. if (lastTextValue != newText)
  37863. {
  37864. lastTextValue = newText;
  37865. textValue = newText;
  37866. repaint();
  37867. textWasChanged();
  37868. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37869. componentMovedOrResized (*ownerComponent, true, true);
  37870. if (broadcastChangeMessage)
  37871. callChangeListeners();
  37872. }
  37873. }
  37874. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37875. {
  37876. return (returnActiveEditorContents && isBeingEdited())
  37877. ? editor->getText()
  37878. : textValue.toString();
  37879. }
  37880. void Label::valueChanged (Value&)
  37881. {
  37882. if (lastTextValue != textValue.toString())
  37883. setText (textValue.toString(), true);
  37884. }
  37885. void Label::setFont (const Font& newFont) throw()
  37886. {
  37887. font = newFont;
  37888. repaint();
  37889. }
  37890. const Font& Label::getFont() const throw()
  37891. {
  37892. return font;
  37893. }
  37894. void Label::setEditable (const bool editOnSingleClick,
  37895. const bool editOnDoubleClick,
  37896. const bool lossOfFocusDiscardsChanges_) throw()
  37897. {
  37898. editSingleClick = editOnSingleClick;
  37899. editDoubleClick = editOnDoubleClick;
  37900. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37901. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37902. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37903. }
  37904. void Label::setJustificationType (const Justification& justification_) throw()
  37905. {
  37906. justification = justification_;
  37907. repaint();
  37908. }
  37909. void Label::setBorderSize (int h, int v)
  37910. {
  37911. horizontalBorderSize = h;
  37912. verticalBorderSize = v;
  37913. repaint();
  37914. }
  37915. void Label::attachToComponent (Component* owner,
  37916. const bool onLeft)
  37917. {
  37918. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37919. ownerComponent->removeComponentListener (this);
  37920. deletionWatcher = 0;
  37921. ownerComponent = owner;
  37922. leftOfOwnerComp = onLeft;
  37923. if (ownerComponent != 0)
  37924. {
  37925. deletionWatcher = new ComponentDeletionWatcher (owner);
  37926. setVisible (owner->isVisible());
  37927. ownerComponent->addComponentListener (this);
  37928. componentParentHierarchyChanged (*ownerComponent);
  37929. componentMovedOrResized (*ownerComponent, true, true);
  37930. }
  37931. }
  37932. void Label::componentMovedOrResized (Component& component,
  37933. bool /*wasMoved*/,
  37934. bool /*wasResized*/)
  37935. {
  37936. if (leftOfOwnerComp)
  37937. {
  37938. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37939. component.getHeight());
  37940. setTopRightPosition (component.getX(), component.getY());
  37941. }
  37942. else
  37943. {
  37944. setSize (component.getWidth(),
  37945. 8 + roundToInt (getFont().getHeight()));
  37946. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37947. }
  37948. }
  37949. void Label::componentParentHierarchyChanged (Component& component)
  37950. {
  37951. if (component.getParentComponent() != 0)
  37952. component.getParentComponent()->addChildComponent (this);
  37953. }
  37954. void Label::componentVisibilityChanged (Component& component)
  37955. {
  37956. setVisible (component.isVisible());
  37957. }
  37958. void Label::textWasEdited()
  37959. {
  37960. }
  37961. void Label::textWasChanged()
  37962. {
  37963. }
  37964. void Label::showEditor()
  37965. {
  37966. if (editor == 0)
  37967. {
  37968. addAndMakeVisible (editor = createEditorComponent());
  37969. editor->setText (getText(), false);
  37970. editor->addListener (this);
  37971. editor->grabKeyboardFocus();
  37972. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37973. editor->addListener (this);
  37974. resized();
  37975. repaint();
  37976. editorShown (editor);
  37977. enterModalState();
  37978. editor->grabKeyboardFocus();
  37979. }
  37980. }
  37981. void Label::editorShown (TextEditor* /*editorComponent*/)
  37982. {
  37983. }
  37984. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37985. {
  37986. }
  37987. bool Label::updateFromTextEditorContents()
  37988. {
  37989. jassert (editor != 0);
  37990. const String newText (editor->getText());
  37991. if (textValue.toString() != newText)
  37992. {
  37993. lastTextValue = newText;
  37994. textValue = newText;
  37995. repaint();
  37996. textWasChanged();
  37997. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37998. componentMovedOrResized (*ownerComponent, true, true);
  37999. return true;
  38000. }
  38001. return false;
  38002. }
  38003. void Label::hideEditor (const bool discardCurrentEditorContents)
  38004. {
  38005. if (editor != 0)
  38006. {
  38007. editorAboutToBeHidden (editor);
  38008. const bool changed = (! discardCurrentEditorContents)
  38009. && updateFromTextEditorContents();
  38010. editor = 0;
  38011. repaint();
  38012. if (changed)
  38013. textWasEdited();
  38014. exitModalState (0);
  38015. if (changed && isValidComponent())
  38016. callChangeListeners();
  38017. }
  38018. }
  38019. void Label::inputAttemptWhenModal()
  38020. {
  38021. if (editor != 0)
  38022. {
  38023. if (lossOfFocusDiscardsChanges)
  38024. textEditorEscapeKeyPressed (*editor);
  38025. else
  38026. textEditorReturnKeyPressed (*editor);
  38027. }
  38028. }
  38029. bool Label::isBeingEdited() const throw()
  38030. {
  38031. return editor != 0;
  38032. }
  38033. TextEditor* Label::createEditorComponent()
  38034. {
  38035. TextEditor* const ed = new TextEditor (getName());
  38036. ed->setFont (font);
  38037. // copy these colours from our own settings..
  38038. const int cols[] = { TextEditor::backgroundColourId,
  38039. TextEditor::textColourId,
  38040. TextEditor::highlightColourId,
  38041. TextEditor::highlightedTextColourId,
  38042. TextEditor::caretColourId,
  38043. TextEditor::outlineColourId,
  38044. TextEditor::focusedOutlineColourId,
  38045. TextEditor::shadowColourId };
  38046. for (int i = 0; i < numElementsInArray (cols); ++i)
  38047. ed->setColour (cols[i], findColour (cols[i]));
  38048. return ed;
  38049. }
  38050. void Label::paint (Graphics& g)
  38051. {
  38052. getLookAndFeel().drawLabel (g, *this);
  38053. }
  38054. void Label::mouseUp (const MouseEvent& e)
  38055. {
  38056. if (editSingleClick
  38057. && e.mouseWasClicked()
  38058. && contains (e.x, e.y)
  38059. && ! e.mods.isPopupMenu())
  38060. {
  38061. showEditor();
  38062. }
  38063. }
  38064. void Label::mouseDoubleClick (const MouseEvent& e)
  38065. {
  38066. if (editDoubleClick && ! e.mods.isPopupMenu())
  38067. showEditor();
  38068. }
  38069. void Label::resized()
  38070. {
  38071. if (editor != 0)
  38072. editor->setBoundsInset (BorderSize (0));
  38073. }
  38074. void Label::focusGained (FocusChangeType cause)
  38075. {
  38076. if (editSingleClick && cause == focusChangedByTabKey)
  38077. showEditor();
  38078. }
  38079. void Label::enablementChanged()
  38080. {
  38081. repaint();
  38082. }
  38083. void Label::colourChanged()
  38084. {
  38085. repaint();
  38086. }
  38087. void Label::setMinimumHorizontalScale (const float newScale)
  38088. {
  38089. if (minimumHorizontalScale != newScale)
  38090. {
  38091. minimumHorizontalScale = newScale;
  38092. repaint();
  38093. }
  38094. }
  38095. // We'll use a custom focus traverser here to make sure focus goes from the
  38096. // text editor to another component rather than back to the label itself.
  38097. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  38098. {
  38099. public:
  38100. LabelKeyboardFocusTraverser() {}
  38101. Component* getNextComponent (Component* current)
  38102. {
  38103. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  38104. ? current->getParentComponent() : current);
  38105. }
  38106. Component* getPreviousComponent (Component* current)
  38107. {
  38108. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  38109. ? current->getParentComponent() : current);
  38110. }
  38111. };
  38112. KeyboardFocusTraverser* Label::createFocusTraverser()
  38113. {
  38114. return new LabelKeyboardFocusTraverser();
  38115. }
  38116. void Label::addListener (LabelListener* const listener) throw()
  38117. {
  38118. jassert (listener != 0);
  38119. if (listener != 0)
  38120. listeners.add (listener);
  38121. }
  38122. void Label::removeListener (LabelListener* const listener) throw()
  38123. {
  38124. listeners.removeValue (listener);
  38125. }
  38126. void Label::callChangeListeners()
  38127. {
  38128. for (int i = listeners.size(); --i >= 0;)
  38129. {
  38130. ((LabelListener*) listeners.getUnchecked (i))->labelTextChanged (this);
  38131. i = jmin (i, listeners.size());
  38132. }
  38133. }
  38134. void Label::textEditorTextChanged (TextEditor& ed)
  38135. {
  38136. if (editor != 0)
  38137. {
  38138. jassert (&ed == editor);
  38139. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  38140. {
  38141. if (lossOfFocusDiscardsChanges)
  38142. textEditorEscapeKeyPressed (ed);
  38143. else
  38144. textEditorReturnKeyPressed (ed);
  38145. }
  38146. }
  38147. }
  38148. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  38149. {
  38150. if (editor != 0)
  38151. {
  38152. jassert (&ed == editor);
  38153. (void) ed;
  38154. const bool changed = updateFromTextEditorContents();
  38155. hideEditor (true);
  38156. if (changed)
  38157. {
  38158. textWasEdited();
  38159. if (isValidComponent())
  38160. callChangeListeners();
  38161. }
  38162. }
  38163. }
  38164. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  38165. {
  38166. if (editor != 0)
  38167. {
  38168. jassert (&ed == editor);
  38169. (void) ed;
  38170. editor->setText (textValue.toString(), false);
  38171. hideEditor (true);
  38172. }
  38173. }
  38174. void Label::textEditorFocusLost (TextEditor& ed)
  38175. {
  38176. textEditorTextChanged (ed);
  38177. }
  38178. END_JUCE_NAMESPACE
  38179. /*** End of inlined file: juce_Label.cpp ***/
  38180. /*** Start of inlined file: juce_ListBox.cpp ***/
  38181. BEGIN_JUCE_NAMESPACE
  38182. class ListBoxRowComponent : public Component,
  38183. public TooltipClient
  38184. {
  38185. public:
  38186. ListBoxRowComponent (ListBox& owner_)
  38187. : owner (owner_),
  38188. row (-1),
  38189. selected (false),
  38190. isDragging (false)
  38191. {
  38192. }
  38193. ~ListBoxRowComponent()
  38194. {
  38195. deleteAllChildren();
  38196. }
  38197. void paint (Graphics& g)
  38198. {
  38199. if (owner.getModel() != 0)
  38200. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  38201. }
  38202. void update (const int row_, const bool selected_)
  38203. {
  38204. if (row != row_ || selected != selected_)
  38205. {
  38206. repaint();
  38207. row = row_;
  38208. selected = selected_;
  38209. }
  38210. if (owner.getModel() != 0)
  38211. {
  38212. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  38213. if (customComp != 0)
  38214. {
  38215. addAndMakeVisible (customComp);
  38216. customComp->setBounds (0, 0, getWidth(), getHeight());
  38217. for (int i = getNumChildComponents(); --i >= 0;)
  38218. if (getChildComponent (i) != customComp)
  38219. delete getChildComponent (i);
  38220. }
  38221. else
  38222. {
  38223. deleteAllChildren();
  38224. }
  38225. }
  38226. }
  38227. void mouseDown (const MouseEvent& e)
  38228. {
  38229. isDragging = false;
  38230. selectRowOnMouseUp = false;
  38231. if (isEnabled())
  38232. {
  38233. if (! selected)
  38234. {
  38235. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38236. if (owner.getModel() != 0)
  38237. owner.getModel()->listBoxItemClicked (row, e);
  38238. }
  38239. else
  38240. {
  38241. selectRowOnMouseUp = true;
  38242. }
  38243. }
  38244. }
  38245. void mouseUp (const MouseEvent& e)
  38246. {
  38247. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  38248. {
  38249. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38250. if (owner.getModel() != 0)
  38251. owner.getModel()->listBoxItemClicked (row, e);
  38252. }
  38253. }
  38254. void mouseDoubleClick (const MouseEvent& e)
  38255. {
  38256. if (owner.getModel() != 0 && isEnabled())
  38257. owner.getModel()->listBoxItemDoubleClicked (row, e);
  38258. }
  38259. void mouseDrag (const MouseEvent& e)
  38260. {
  38261. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  38262. {
  38263. const SparseSet <int> selectedRows (owner.getSelectedRows());
  38264. if (selectedRows.size() > 0)
  38265. {
  38266. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  38267. if (dragDescription.isNotEmpty())
  38268. {
  38269. isDragging = true;
  38270. owner.startDragAndDrop (e, dragDescription);
  38271. }
  38272. }
  38273. }
  38274. }
  38275. void resized()
  38276. {
  38277. if (getNumChildComponents() > 0)
  38278. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  38279. }
  38280. const String getTooltip()
  38281. {
  38282. if (owner.getModel() != 0)
  38283. return owner.getModel()->getTooltipForRow (row);
  38284. return String::empty;
  38285. }
  38286. juce_UseDebuggingNewOperator
  38287. bool neededFlag;
  38288. private:
  38289. ListBox& owner;
  38290. int row;
  38291. bool selected, isDragging, selectRowOnMouseUp;
  38292. ListBoxRowComponent (const ListBoxRowComponent&);
  38293. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  38294. };
  38295. class ListViewport : public Viewport
  38296. {
  38297. public:
  38298. int firstIndex, firstWholeIndex, lastWholeIndex;
  38299. bool hasUpdated;
  38300. ListViewport (ListBox& owner_)
  38301. : owner (owner_)
  38302. {
  38303. setWantsKeyboardFocus (false);
  38304. setViewedComponent (new Component());
  38305. getViewedComponent()->addMouseListener (this, false);
  38306. getViewedComponent()->setWantsKeyboardFocus (false);
  38307. }
  38308. ~ListViewport()
  38309. {
  38310. getViewedComponent()->removeMouseListener (this);
  38311. getViewedComponent()->deleteAllChildren();
  38312. }
  38313. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38314. {
  38315. return (ListBoxRowComponent*) getViewedComponent()
  38316. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38317. }
  38318. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38319. {
  38320. const int index = getIndexOfChildComponent (rowComponent);
  38321. const int num = getViewedComponent()->getNumChildComponents();
  38322. for (int i = num; --i >= 0;)
  38323. if (((firstIndex + i) % jmax (1, num)) == index)
  38324. return firstIndex + i;
  38325. return -1;
  38326. }
  38327. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38328. {
  38329. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38330. ? getComponentForRow (row) : 0;
  38331. }
  38332. void visibleAreaChanged (int, int, int, int)
  38333. {
  38334. updateVisibleArea (true);
  38335. if (owner.getModel() != 0)
  38336. owner.getModel()->listWasScrolled();
  38337. }
  38338. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38339. {
  38340. hasUpdated = false;
  38341. const int newX = getViewedComponent()->getX();
  38342. int newY = getViewedComponent()->getY();
  38343. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38344. const int newH = owner.totalItems * owner.getRowHeight();
  38345. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38346. newY = getMaximumVisibleHeight() - newH;
  38347. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38348. if (makeSureItUpdatesContent && ! hasUpdated)
  38349. updateContents();
  38350. }
  38351. void updateContents()
  38352. {
  38353. hasUpdated = true;
  38354. const int rowHeight = owner.getRowHeight();
  38355. if (rowHeight > 0)
  38356. {
  38357. const int y = getViewPositionY();
  38358. const int w = getViewedComponent()->getWidth();
  38359. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38360. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38361. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38362. jassert (numNeeded >= 0);
  38363. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38364. {
  38365. Component* const rowToRemove
  38366. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38367. delete rowToRemove;
  38368. }
  38369. firstIndex = y / rowHeight;
  38370. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38371. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38372. for (int i = 0; i < numNeeded; ++i)
  38373. {
  38374. const int row = i + firstIndex;
  38375. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38376. if (rowComp != 0)
  38377. {
  38378. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38379. rowComp->update (row, owner.isRowSelected (row));
  38380. }
  38381. }
  38382. }
  38383. if (owner.headerComponent != 0)
  38384. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38385. owner.outlineThickness,
  38386. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38387. getViewedComponent()->getWidth()),
  38388. owner.headerComponent->getHeight());
  38389. }
  38390. void paint (Graphics& g)
  38391. {
  38392. if (isOpaque())
  38393. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38394. }
  38395. bool keyPressed (const KeyPress& key)
  38396. {
  38397. if (key.isKeyCode (KeyPress::upKey)
  38398. || key.isKeyCode (KeyPress::downKey)
  38399. || key.isKeyCode (KeyPress::pageUpKey)
  38400. || key.isKeyCode (KeyPress::pageDownKey)
  38401. || key.isKeyCode (KeyPress::homeKey)
  38402. || key.isKeyCode (KeyPress::endKey))
  38403. {
  38404. // we want to avoid these keypresses going to the viewport, and instead allow
  38405. // them to pass up to our listbox..
  38406. return false;
  38407. }
  38408. return Viewport::keyPressed (key);
  38409. }
  38410. juce_UseDebuggingNewOperator
  38411. private:
  38412. ListBox& owner;
  38413. ListViewport (const ListViewport&);
  38414. ListViewport& operator= (const ListViewport&);
  38415. };
  38416. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38417. : Component (name),
  38418. model (model_),
  38419. headerComponent (0),
  38420. totalItems (0),
  38421. rowHeight (22),
  38422. minimumRowWidth (0),
  38423. outlineThickness (0),
  38424. lastRowSelected (-1),
  38425. mouseMoveSelects (false),
  38426. multipleSelection (false),
  38427. hasDoneInitialUpdate (false)
  38428. {
  38429. addAndMakeVisible (viewport = new ListViewport (*this));
  38430. setWantsKeyboardFocus (true);
  38431. colourChanged();
  38432. }
  38433. ListBox::~ListBox()
  38434. {
  38435. deleteAllChildren();
  38436. }
  38437. void ListBox::setModel (ListBoxModel* const newModel)
  38438. {
  38439. if (model != newModel)
  38440. {
  38441. model = newModel;
  38442. updateContent();
  38443. }
  38444. }
  38445. void ListBox::setMultipleSelectionEnabled (bool b)
  38446. {
  38447. multipleSelection = b;
  38448. }
  38449. void ListBox::setMouseMoveSelectsRows (bool b)
  38450. {
  38451. mouseMoveSelects = b;
  38452. if (b)
  38453. addMouseListener (this, true);
  38454. }
  38455. void ListBox::paint (Graphics& g)
  38456. {
  38457. if (! hasDoneInitialUpdate)
  38458. updateContent();
  38459. g.fillAll (findColour (backgroundColourId));
  38460. }
  38461. void ListBox::paintOverChildren (Graphics& g)
  38462. {
  38463. if (outlineThickness > 0)
  38464. {
  38465. g.setColour (findColour (outlineColourId));
  38466. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38467. }
  38468. }
  38469. void ListBox::resized()
  38470. {
  38471. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38472. outlineThickness,
  38473. outlineThickness,
  38474. outlineThickness));
  38475. viewport->setSingleStepSizes (20, getRowHeight());
  38476. viewport->updateVisibleArea (false);
  38477. }
  38478. void ListBox::visibilityChanged()
  38479. {
  38480. viewport->updateVisibleArea (true);
  38481. }
  38482. Viewport* ListBox::getViewport() const throw()
  38483. {
  38484. return viewport;
  38485. }
  38486. void ListBox::updateContent()
  38487. {
  38488. hasDoneInitialUpdate = true;
  38489. totalItems = (model != 0) ? model->getNumRows() : 0;
  38490. bool selectionChanged = false;
  38491. if (selected [selected.size() - 1] >= totalItems)
  38492. {
  38493. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38494. lastRowSelected = getSelectedRow (0);
  38495. selectionChanged = true;
  38496. }
  38497. viewport->updateVisibleArea (isVisible());
  38498. viewport->resized();
  38499. if (selectionChanged && model != 0)
  38500. model->selectedRowsChanged (lastRowSelected);
  38501. }
  38502. void ListBox::selectRow (const int row,
  38503. bool dontScroll,
  38504. bool deselectOthersFirst)
  38505. {
  38506. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38507. }
  38508. void ListBox::selectRowInternal (const int row,
  38509. bool dontScroll,
  38510. bool deselectOthersFirst,
  38511. bool isMouseClick)
  38512. {
  38513. if (! multipleSelection)
  38514. deselectOthersFirst = true;
  38515. if ((! isRowSelected (row))
  38516. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38517. {
  38518. if (((unsigned int) row) < (unsigned int) totalItems)
  38519. {
  38520. if (deselectOthersFirst)
  38521. selected.clear();
  38522. selected.addRange (row, 1);
  38523. if (getHeight() == 0 || getWidth() == 0)
  38524. dontScroll = true;
  38525. viewport->hasUpdated = false;
  38526. if (row < viewport->firstWholeIndex && ! dontScroll)
  38527. {
  38528. viewport->setViewPosition (viewport->getViewPositionX(),
  38529. row * getRowHeight());
  38530. }
  38531. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38532. {
  38533. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38534. if (row >= lastRowSelected + rowsOnScreen
  38535. && rowsOnScreen < totalItems - 1
  38536. && ! isMouseClick)
  38537. {
  38538. viewport->setViewPosition (viewport->getViewPositionX(),
  38539. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38540. * getRowHeight());
  38541. }
  38542. else
  38543. {
  38544. viewport->setViewPosition (viewport->getViewPositionX(),
  38545. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38546. }
  38547. }
  38548. if (! viewport->hasUpdated)
  38549. viewport->updateContents();
  38550. lastRowSelected = row;
  38551. model->selectedRowsChanged (row);
  38552. }
  38553. else
  38554. {
  38555. if (deselectOthersFirst)
  38556. deselectAllRows();
  38557. }
  38558. }
  38559. }
  38560. void ListBox::deselectRow (const int row)
  38561. {
  38562. if (selected.contains (row))
  38563. {
  38564. selected.removeRange (row, 1);
  38565. if (row == lastRowSelected)
  38566. lastRowSelected = getSelectedRow (0);
  38567. viewport->updateContents();
  38568. model->selectedRowsChanged (lastRowSelected);
  38569. }
  38570. }
  38571. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38572. const bool sendNotificationEventToModel)
  38573. {
  38574. selected = setOfRowsToBeSelected;
  38575. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38576. if (! isRowSelected (lastRowSelected))
  38577. lastRowSelected = getSelectedRow (0);
  38578. viewport->updateContents();
  38579. if ((model != 0) && sendNotificationEventToModel)
  38580. model->selectedRowsChanged (lastRowSelected);
  38581. }
  38582. const SparseSet<int> ListBox::getSelectedRows() const
  38583. {
  38584. return selected;
  38585. }
  38586. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38587. {
  38588. if (multipleSelection && (firstRow != lastRow))
  38589. {
  38590. const int numRows = totalItems - 1;
  38591. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38592. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38593. selected.addRange (jmin (firstRow, lastRow),
  38594. abs (firstRow - lastRow) + 1);
  38595. selected.removeRange (lastRow, 1);
  38596. }
  38597. selectRowInternal (lastRow, false, false, true);
  38598. }
  38599. void ListBox::flipRowSelection (const int row)
  38600. {
  38601. if (isRowSelected (row))
  38602. deselectRow (row);
  38603. else
  38604. selectRowInternal (row, false, false, true);
  38605. }
  38606. void ListBox::deselectAllRows()
  38607. {
  38608. if (! selected.isEmpty())
  38609. {
  38610. selected.clear();
  38611. lastRowSelected = -1;
  38612. viewport->updateContents();
  38613. if (model != 0)
  38614. model->selectedRowsChanged (lastRowSelected);
  38615. }
  38616. }
  38617. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38618. const ModifierKeys& mods)
  38619. {
  38620. if (multipleSelection && mods.isCommandDown())
  38621. {
  38622. flipRowSelection (row);
  38623. }
  38624. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38625. {
  38626. selectRangeOfRows (lastRowSelected, row);
  38627. }
  38628. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38629. {
  38630. selectRowInternal (row, false, true, true);
  38631. }
  38632. }
  38633. int ListBox::getNumSelectedRows() const
  38634. {
  38635. return selected.size();
  38636. }
  38637. int ListBox::getSelectedRow (const int index) const
  38638. {
  38639. return (((unsigned int) index) < (unsigned int) selected.size())
  38640. ? selected [index] : -1;
  38641. }
  38642. bool ListBox::isRowSelected (const int row) const
  38643. {
  38644. return selected.contains (row);
  38645. }
  38646. int ListBox::getLastRowSelected() const
  38647. {
  38648. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38649. }
  38650. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38651. {
  38652. if (((unsigned int) x) < (unsigned int) getWidth())
  38653. {
  38654. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38655. if (((unsigned int) row) < (unsigned int) totalItems)
  38656. return row;
  38657. }
  38658. return -1;
  38659. }
  38660. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38661. {
  38662. if (((unsigned int) x) < (unsigned int) getWidth())
  38663. {
  38664. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38665. return jlimit (0, totalItems, row);
  38666. }
  38667. return -1;
  38668. }
  38669. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38670. {
  38671. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38672. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38673. }
  38674. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38675. {
  38676. return viewport->getRowNumberOfComponent (rowComponent);
  38677. }
  38678. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38679. const bool relativeToComponentTopLeft) const throw()
  38680. {
  38681. const int rowHeight = getRowHeight();
  38682. int y = viewport->getY() + rowHeight * rowNumber;
  38683. if (relativeToComponentTopLeft)
  38684. y -= viewport->getViewPositionY();
  38685. return Rectangle<int> (viewport->getX(), y,
  38686. viewport->getViewedComponent()->getWidth(), rowHeight);
  38687. }
  38688. void ListBox::setVerticalPosition (const double proportion)
  38689. {
  38690. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38691. viewport->setViewPosition (viewport->getViewPositionX(),
  38692. jmax (0, roundToInt (proportion * offscreen)));
  38693. }
  38694. double ListBox::getVerticalPosition() const
  38695. {
  38696. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38697. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38698. : 0;
  38699. }
  38700. int ListBox::getVisibleRowWidth() const throw()
  38701. {
  38702. return viewport->getViewWidth();
  38703. }
  38704. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38705. {
  38706. if (row < viewport->firstWholeIndex)
  38707. {
  38708. viewport->setViewPosition (viewport->getViewPositionX(),
  38709. row * getRowHeight());
  38710. }
  38711. else if (row >= viewport->lastWholeIndex)
  38712. {
  38713. viewport->setViewPosition (viewport->getViewPositionX(),
  38714. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38715. }
  38716. }
  38717. bool ListBox::keyPressed (const KeyPress& key)
  38718. {
  38719. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38720. const bool multiple = multipleSelection
  38721. && (lastRowSelected >= 0)
  38722. && (key.getModifiers().isShiftDown()
  38723. || key.getModifiers().isCtrlDown()
  38724. || key.getModifiers().isCommandDown());
  38725. if (key.isKeyCode (KeyPress::upKey))
  38726. {
  38727. if (multiple)
  38728. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38729. else
  38730. selectRow (jmax (0, lastRowSelected - 1));
  38731. }
  38732. else if (key.isKeyCode (KeyPress::returnKey)
  38733. && isRowSelected (lastRowSelected))
  38734. {
  38735. if (model != 0)
  38736. model->returnKeyPressed (lastRowSelected);
  38737. }
  38738. else if (key.isKeyCode (KeyPress::pageUpKey))
  38739. {
  38740. if (multiple)
  38741. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38742. else
  38743. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38744. }
  38745. else if (key.isKeyCode (KeyPress::pageDownKey))
  38746. {
  38747. if (multiple)
  38748. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38749. else
  38750. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38751. }
  38752. else if (key.isKeyCode (KeyPress::homeKey))
  38753. {
  38754. if (multiple && key.getModifiers().isShiftDown())
  38755. selectRangeOfRows (lastRowSelected, 0);
  38756. else
  38757. selectRow (0);
  38758. }
  38759. else if (key.isKeyCode (KeyPress::endKey))
  38760. {
  38761. if (multiple && key.getModifiers().isShiftDown())
  38762. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38763. else
  38764. selectRow (totalItems - 1);
  38765. }
  38766. else if (key.isKeyCode (KeyPress::downKey))
  38767. {
  38768. if (multiple)
  38769. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38770. else
  38771. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38772. }
  38773. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38774. && isRowSelected (lastRowSelected))
  38775. {
  38776. if (model != 0)
  38777. model->deleteKeyPressed (lastRowSelected);
  38778. }
  38779. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38780. {
  38781. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38782. }
  38783. else
  38784. {
  38785. return false;
  38786. }
  38787. return true;
  38788. }
  38789. bool ListBox::keyStateChanged (const bool isKeyDown)
  38790. {
  38791. return isKeyDown
  38792. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38793. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38794. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38795. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38796. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38797. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38798. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38799. }
  38800. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38801. {
  38802. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38803. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38804. }
  38805. void ListBox::mouseMove (const MouseEvent& e)
  38806. {
  38807. if (mouseMoveSelects)
  38808. {
  38809. const MouseEvent e2 (e.getEventRelativeTo (this));
  38810. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38811. }
  38812. }
  38813. void ListBox::mouseExit (const MouseEvent& e)
  38814. {
  38815. mouseMove (e);
  38816. }
  38817. void ListBox::mouseUp (const MouseEvent& e)
  38818. {
  38819. if (e.mouseWasClicked() && model != 0)
  38820. model->backgroundClicked();
  38821. }
  38822. void ListBox::setRowHeight (const int newHeight)
  38823. {
  38824. rowHeight = jmax (1, newHeight);
  38825. viewport->setSingleStepSizes (20, rowHeight);
  38826. updateContent();
  38827. }
  38828. int ListBox::getNumRowsOnScreen() const throw()
  38829. {
  38830. return viewport->getMaximumVisibleHeight() / rowHeight;
  38831. }
  38832. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38833. {
  38834. minimumRowWidth = newMinimumWidth;
  38835. updateContent();
  38836. }
  38837. int ListBox::getVisibleContentWidth() const throw()
  38838. {
  38839. return viewport->getMaximumVisibleWidth();
  38840. }
  38841. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38842. {
  38843. return viewport->getVerticalScrollBar();
  38844. }
  38845. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38846. {
  38847. return viewport->getHorizontalScrollBar();
  38848. }
  38849. void ListBox::colourChanged()
  38850. {
  38851. setOpaque (findColour (backgroundColourId).isOpaque());
  38852. viewport->setOpaque (isOpaque());
  38853. repaint();
  38854. }
  38855. void ListBox::setOutlineThickness (const int outlineThickness_)
  38856. {
  38857. outlineThickness = outlineThickness_;
  38858. resized();
  38859. }
  38860. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38861. {
  38862. if (headerComponent != newHeaderComponent)
  38863. {
  38864. delete headerComponent;
  38865. headerComponent = newHeaderComponent;
  38866. addAndMakeVisible (newHeaderComponent);
  38867. ListBox::resized();
  38868. }
  38869. }
  38870. void ListBox::repaintRow (const int rowNumber) throw()
  38871. {
  38872. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38873. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38874. }
  38875. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38876. {
  38877. Rectangle<int> imageArea;
  38878. const int firstRow = getRowContainingPosition (0, 0);
  38879. int i;
  38880. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38881. {
  38882. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38883. if (rowComp != 0 && isRowSelected (firstRow + i))
  38884. {
  38885. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38886. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38887. if (imageArea.isEmpty())
  38888. imageArea = rowRect;
  38889. else
  38890. imageArea = imageArea.getUnion (rowRect);
  38891. }
  38892. }
  38893. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38894. imageX = imageArea.getX();
  38895. imageY = imageArea.getY();
  38896. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38897. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38898. {
  38899. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38900. if (rowComp != 0 && isRowSelected (firstRow + i))
  38901. {
  38902. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38903. Graphics g (*snapshot);
  38904. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38905. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38906. rowComp->paintEntireComponent (g);
  38907. }
  38908. }
  38909. return snapshot;
  38910. }
  38911. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38912. {
  38913. DragAndDropContainer* const dragContainer
  38914. = DragAndDropContainer::findParentDragContainerFor (this);
  38915. if (dragContainer != 0)
  38916. {
  38917. int x, y;
  38918. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38919. dragImage->multiplyAllAlphas (0.6f);
  38920. MouseEvent e2 (e.getEventRelativeTo (this));
  38921. const Point<int> p (x - e2.x, y - e2.y);
  38922. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38923. }
  38924. else
  38925. {
  38926. // to be able to do a drag-and-drop operation, the listbox needs to
  38927. // be inside a component which is also a DragAndDropContainer.
  38928. jassertfalse
  38929. }
  38930. }
  38931. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38932. {
  38933. (void) existingComponentToUpdate;
  38934. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38935. return 0;
  38936. }
  38937. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38938. {
  38939. }
  38940. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38941. {
  38942. }
  38943. void ListBoxModel::backgroundClicked()
  38944. {
  38945. }
  38946. void ListBoxModel::selectedRowsChanged (int)
  38947. {
  38948. }
  38949. void ListBoxModel::deleteKeyPressed (int)
  38950. {
  38951. }
  38952. void ListBoxModel::returnKeyPressed (int)
  38953. {
  38954. }
  38955. void ListBoxModel::listWasScrolled()
  38956. {
  38957. }
  38958. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38959. {
  38960. return String::empty;
  38961. }
  38962. const String ListBoxModel::getTooltipForRow (int)
  38963. {
  38964. return String::empty;
  38965. }
  38966. END_JUCE_NAMESPACE
  38967. /*** End of inlined file: juce_ListBox.cpp ***/
  38968. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38969. BEGIN_JUCE_NAMESPACE
  38970. ProgressBar::ProgressBar (double& progress_)
  38971. : progress (progress_),
  38972. displayPercentage (true),
  38973. lastCallbackTime (0)
  38974. {
  38975. currentValue = jlimit (0.0, 1.0, progress);
  38976. }
  38977. ProgressBar::~ProgressBar()
  38978. {
  38979. }
  38980. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38981. {
  38982. displayPercentage = shouldDisplayPercentage;
  38983. repaint();
  38984. }
  38985. void ProgressBar::setTextToDisplay (const String& text)
  38986. {
  38987. displayPercentage = false;
  38988. displayedMessage = text;
  38989. }
  38990. void ProgressBar::lookAndFeelChanged()
  38991. {
  38992. setOpaque (findColour (backgroundColourId).isOpaque());
  38993. }
  38994. void ProgressBar::colourChanged()
  38995. {
  38996. lookAndFeelChanged();
  38997. }
  38998. void ProgressBar::paint (Graphics& g)
  38999. {
  39000. String text;
  39001. if (displayPercentage)
  39002. {
  39003. if (currentValue >= 0 && currentValue <= 1.0)
  39004. text << roundToInt (currentValue * 100.0) << T("%");
  39005. }
  39006. else
  39007. {
  39008. text = displayedMessage;
  39009. }
  39010. getLookAndFeel().drawProgressBar (g, *this,
  39011. getWidth(), getHeight(),
  39012. currentValue, text);
  39013. }
  39014. void ProgressBar::visibilityChanged()
  39015. {
  39016. if (isVisible())
  39017. startTimer (30);
  39018. else
  39019. stopTimer();
  39020. }
  39021. void ProgressBar::timerCallback()
  39022. {
  39023. double newProgress = progress;
  39024. const uint32 now = Time::getMillisecondCounter();
  39025. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  39026. lastCallbackTime = now;
  39027. if (currentValue != newProgress
  39028. || newProgress < 0 || newProgress >= 1.0
  39029. || currentMessage != displayedMessage)
  39030. {
  39031. if (currentValue < newProgress
  39032. && newProgress >= 0 && newProgress < 1.0
  39033. && currentValue >= 0 && currentValue < 1.0)
  39034. {
  39035. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  39036. newProgress);
  39037. }
  39038. currentValue = newProgress;
  39039. currentMessage = displayedMessage;
  39040. repaint();
  39041. }
  39042. }
  39043. END_JUCE_NAMESPACE
  39044. /*** End of inlined file: juce_ProgressBar.cpp ***/
  39045. /*** Start of inlined file: juce_Slider.cpp ***/
  39046. BEGIN_JUCE_NAMESPACE
  39047. class SliderPopupDisplayComponent : public BubbleComponent
  39048. {
  39049. public:
  39050. SliderPopupDisplayComponent (Slider* const owner_)
  39051. : owner (owner_),
  39052. font (15.0f, Font::bold)
  39053. {
  39054. setAlwaysOnTop (true);
  39055. }
  39056. ~SliderPopupDisplayComponent()
  39057. {
  39058. }
  39059. void paintContent (Graphics& g, int w, int h)
  39060. {
  39061. g.setFont (font);
  39062. g.setColour (Colours::black);
  39063. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  39064. }
  39065. void getContentSize (int& w, int& h)
  39066. {
  39067. w = font.getStringWidth (text) + 18;
  39068. h = (int) (font.getHeight() * 1.6f);
  39069. }
  39070. void updatePosition (const String& newText)
  39071. {
  39072. if (text != newText)
  39073. {
  39074. text = newText;
  39075. repaint();
  39076. }
  39077. BubbleComponent::setPosition (owner);
  39078. }
  39079. juce_UseDebuggingNewOperator
  39080. private:
  39081. Slider* owner;
  39082. Font font;
  39083. String text;
  39084. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  39085. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  39086. };
  39087. Slider::Slider (const String& name)
  39088. : Component (name),
  39089. lastCurrentValue (0),
  39090. lastValueMin (0),
  39091. lastValueMax (0),
  39092. minimum (0),
  39093. maximum (10),
  39094. interval (0),
  39095. skewFactor (1.0),
  39096. velocityModeSensitivity (1.0),
  39097. velocityModeOffset (0.0),
  39098. velocityModeThreshold (1),
  39099. rotaryStart (float_Pi * 1.2f),
  39100. rotaryEnd (float_Pi * 2.8f),
  39101. numDecimalPlaces (7),
  39102. sliderRegionStart (0),
  39103. sliderRegionSize (1),
  39104. sliderBeingDragged (-1),
  39105. pixelsForFullDragExtent (250),
  39106. style (LinearHorizontal),
  39107. textBoxPos (TextBoxLeft),
  39108. textBoxWidth (80),
  39109. textBoxHeight (20),
  39110. incDecButtonMode (incDecButtonsNotDraggable),
  39111. editableText (true),
  39112. doubleClickToValue (false),
  39113. isVelocityBased (false),
  39114. userKeyOverridesVelocity (true),
  39115. rotaryStop (true),
  39116. incDecButtonsSideBySide (false),
  39117. sendChangeOnlyOnRelease (false),
  39118. popupDisplayEnabled (false),
  39119. menuEnabled (false),
  39120. menuShown (false),
  39121. scrollWheelEnabled (true),
  39122. snapsToMousePos (true),
  39123. valueBox (0),
  39124. incButton (0),
  39125. decButton (0),
  39126. popupDisplay (0),
  39127. parentForPopupDisplay (0)
  39128. {
  39129. setWantsKeyboardFocus (false);
  39130. setRepaintsOnMouseActivity (true);
  39131. lookAndFeelChanged();
  39132. updateText();
  39133. currentValue.addListener (this);
  39134. valueMin.addListener (this);
  39135. valueMax.addListener (this);
  39136. }
  39137. Slider::~Slider()
  39138. {
  39139. currentValue.removeListener (this);
  39140. valueMin.removeListener (this);
  39141. valueMax.removeListener (this);
  39142. popupDisplay = 0;
  39143. deleteAllChildren();
  39144. }
  39145. void Slider::handleAsyncUpdate()
  39146. {
  39147. cancelPendingUpdate();
  39148. for (int i = listeners.size(); --i >= 0;)
  39149. {
  39150. ((SliderListener*) listeners.getUnchecked (i))->sliderValueChanged (this);
  39151. i = jmin (i, listeners.size());
  39152. }
  39153. }
  39154. void Slider::sendDragStart()
  39155. {
  39156. startedDragging();
  39157. for (int i = listeners.size(); --i >= 0;)
  39158. {
  39159. ((SliderListener*) listeners.getUnchecked (i))->sliderDragStarted (this);
  39160. i = jmin (i, listeners.size());
  39161. }
  39162. }
  39163. void Slider::sendDragEnd()
  39164. {
  39165. stoppedDragging();
  39166. sliderBeingDragged = -1;
  39167. for (int i = listeners.size(); --i >= 0;)
  39168. {
  39169. ((SliderListener*) listeners.getUnchecked (i))->sliderDragEnded (this);
  39170. i = jmin (i, listeners.size());
  39171. }
  39172. }
  39173. void Slider::addListener (SliderListener* const listener)
  39174. {
  39175. jassert (listener != 0);
  39176. if (listener != 0)
  39177. listeners.add (listener);
  39178. }
  39179. void Slider::removeListener (SliderListener* const listener)
  39180. {
  39181. listeners.removeValue (listener);
  39182. }
  39183. void Slider::setSliderStyle (const SliderStyle newStyle)
  39184. {
  39185. if (style != newStyle)
  39186. {
  39187. style = newStyle;
  39188. repaint();
  39189. lookAndFeelChanged();
  39190. }
  39191. }
  39192. void Slider::setRotaryParameters (const float startAngleRadians,
  39193. const float endAngleRadians,
  39194. const bool stopAtEnd)
  39195. {
  39196. // make sure the values are sensible..
  39197. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  39198. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  39199. jassert (rotaryStart < rotaryEnd);
  39200. rotaryStart = startAngleRadians;
  39201. rotaryEnd = endAngleRadians;
  39202. rotaryStop = stopAtEnd;
  39203. }
  39204. void Slider::setVelocityBasedMode (const bool velBased)
  39205. {
  39206. isVelocityBased = velBased;
  39207. }
  39208. void Slider::setVelocityModeParameters (const double sensitivity,
  39209. const int threshold,
  39210. const double offset,
  39211. const bool userCanPressKeyToSwapMode)
  39212. {
  39213. jassert (threshold >= 0);
  39214. jassert (sensitivity > 0);
  39215. jassert (offset >= 0);
  39216. velocityModeSensitivity = sensitivity;
  39217. velocityModeOffset = offset;
  39218. velocityModeThreshold = threshold;
  39219. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  39220. }
  39221. void Slider::setSkewFactor (const double factor)
  39222. {
  39223. skewFactor = factor;
  39224. }
  39225. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  39226. {
  39227. if (maximum > minimum)
  39228. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  39229. / (maximum - minimum));
  39230. }
  39231. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  39232. {
  39233. jassert (distanceForFullScaleDrag > 0);
  39234. pixelsForFullDragExtent = distanceForFullScaleDrag;
  39235. }
  39236. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  39237. {
  39238. if (incDecButtonMode != mode)
  39239. {
  39240. incDecButtonMode = mode;
  39241. lookAndFeelChanged();
  39242. }
  39243. }
  39244. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  39245. const bool isReadOnly,
  39246. const int textEntryBoxWidth,
  39247. const int textEntryBoxHeight)
  39248. {
  39249. textBoxPos = newPosition;
  39250. editableText = ! isReadOnly;
  39251. textBoxWidth = textEntryBoxWidth;
  39252. textBoxHeight = textEntryBoxHeight;
  39253. repaint();
  39254. lookAndFeelChanged();
  39255. }
  39256. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  39257. {
  39258. editableText = shouldBeEditable;
  39259. if (valueBox != 0)
  39260. valueBox->setEditable (shouldBeEditable && isEnabled());
  39261. }
  39262. void Slider::showTextBox()
  39263. {
  39264. jassert (editableText); // this should probably be avoided in read-only sliders.
  39265. if (valueBox != 0)
  39266. valueBox->showEditor();
  39267. }
  39268. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  39269. {
  39270. if (valueBox != 0)
  39271. {
  39272. valueBox->hideEditor (discardCurrentEditorContents);
  39273. if (discardCurrentEditorContents)
  39274. updateText();
  39275. }
  39276. }
  39277. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  39278. {
  39279. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  39280. }
  39281. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  39282. {
  39283. snapsToMousePos = shouldSnapToMouse;
  39284. }
  39285. void Slider::setPopupDisplayEnabled (const bool enabled,
  39286. Component* const parentComponentToUse)
  39287. {
  39288. popupDisplayEnabled = enabled;
  39289. parentForPopupDisplay = parentComponentToUse;
  39290. }
  39291. void Slider::colourChanged()
  39292. {
  39293. lookAndFeelChanged();
  39294. }
  39295. void Slider::lookAndFeelChanged()
  39296. {
  39297. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  39298. : getTextFromValue (currentValue.getValue()));
  39299. deleteAllChildren();
  39300. valueBox = 0;
  39301. LookAndFeel& lf = getLookAndFeel();
  39302. if (textBoxPos != NoTextBox)
  39303. {
  39304. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  39305. valueBox->setWantsKeyboardFocus (false);
  39306. valueBox->setText (previousTextBoxContent, false);
  39307. valueBox->setEditable (editableText && isEnabled());
  39308. valueBox->addListener (this);
  39309. if (style == LinearBar)
  39310. valueBox->addMouseListener (this, false);
  39311. valueBox->setTooltip (getTooltip());
  39312. }
  39313. if (style == IncDecButtons)
  39314. {
  39315. addAndMakeVisible (incButton = lf.createSliderButton (true));
  39316. incButton->addButtonListener (this);
  39317. addAndMakeVisible (decButton = lf.createSliderButton (false));
  39318. decButton->addButtonListener (this);
  39319. if (incDecButtonMode != incDecButtonsNotDraggable)
  39320. {
  39321. incButton->addMouseListener (this, false);
  39322. decButton->addMouseListener (this, false);
  39323. }
  39324. else
  39325. {
  39326. incButton->setRepeatSpeed (300, 100, 20);
  39327. incButton->addMouseListener (decButton, false);
  39328. decButton->setRepeatSpeed (300, 100, 20);
  39329. decButton->addMouseListener (incButton, false);
  39330. }
  39331. incButton->setTooltip (getTooltip());
  39332. decButton->setTooltip (getTooltip());
  39333. }
  39334. setComponentEffect (lf.getSliderEffect());
  39335. resized();
  39336. repaint();
  39337. }
  39338. void Slider::setRange (const double newMin,
  39339. const double newMax,
  39340. const double newInt)
  39341. {
  39342. if (minimum != newMin
  39343. || maximum != newMax
  39344. || interval != newInt)
  39345. {
  39346. minimum = newMin;
  39347. maximum = newMax;
  39348. interval = newInt;
  39349. // figure out the number of DPs needed to display all values at this
  39350. // interval setting.
  39351. numDecimalPlaces = 7;
  39352. if (newInt != 0)
  39353. {
  39354. int v = abs ((int) (newInt * 10000000));
  39355. while ((v % 10) == 0)
  39356. {
  39357. --numDecimalPlaces;
  39358. v /= 10;
  39359. }
  39360. }
  39361. // keep the current values inside the new range..
  39362. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39363. {
  39364. setValue (getValue(), false, false);
  39365. }
  39366. else
  39367. {
  39368. setMinValue (getMinValue(), false, false);
  39369. setMaxValue (getMaxValue(), false, false);
  39370. }
  39371. updateText();
  39372. }
  39373. }
  39374. void Slider::triggerChangeMessage (const bool synchronous)
  39375. {
  39376. if (synchronous)
  39377. handleAsyncUpdate();
  39378. else
  39379. triggerAsyncUpdate();
  39380. valueChanged();
  39381. }
  39382. void Slider::valueChanged (Value& value)
  39383. {
  39384. if (value.refersToSameSourceAs (currentValue))
  39385. {
  39386. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39387. setValue (currentValue.getValue(), false, false);
  39388. }
  39389. else if (value.refersToSameSourceAs (valueMin))
  39390. setMinValue (valueMin.getValue(), false, false, true);
  39391. else if (value.refersToSameSourceAs (valueMax))
  39392. setMaxValue (valueMax.getValue(), false, false, true);
  39393. }
  39394. double Slider::getValue() const
  39395. {
  39396. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39397. // methods to get the two values.
  39398. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39399. return currentValue.getValue();
  39400. }
  39401. void Slider::setValue (double newValue,
  39402. const bool sendUpdateMessage,
  39403. const bool sendMessageSynchronously)
  39404. {
  39405. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39406. // methods to set the two values.
  39407. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39408. newValue = constrainedValue (newValue);
  39409. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39410. {
  39411. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39412. newValue = jlimit ((double) valueMin.getValue(),
  39413. (double) valueMax.getValue(),
  39414. newValue);
  39415. }
  39416. if (newValue != lastCurrentValue)
  39417. {
  39418. if (valueBox != 0)
  39419. valueBox->hideEditor (true);
  39420. lastCurrentValue = newValue;
  39421. currentValue = newValue;
  39422. updateText();
  39423. repaint();
  39424. if (popupDisplay != 0)
  39425. {
  39426. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39427. popupDisplay->repaint();
  39428. }
  39429. if (sendUpdateMessage)
  39430. triggerChangeMessage (sendMessageSynchronously);
  39431. }
  39432. }
  39433. double Slider::getMinValue() const
  39434. {
  39435. // The minimum value only applies to sliders that are in two- or three-value mode.
  39436. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39437. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39438. return valueMin.getValue();
  39439. }
  39440. double Slider::getMaxValue() const
  39441. {
  39442. // The maximum value only applies to sliders that are in two- or three-value mode.
  39443. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39444. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39445. return valueMax.getValue();
  39446. }
  39447. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39448. {
  39449. // The minimum value only applies to sliders that are in two- or three-value mode.
  39450. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39451. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39452. newValue = constrainedValue (newValue);
  39453. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39454. {
  39455. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39456. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39457. newValue = jmin ((double) valueMax.getValue(), newValue);
  39458. }
  39459. else
  39460. {
  39461. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39462. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39463. newValue = jmin (lastCurrentValue, newValue);
  39464. }
  39465. if (lastValueMin != newValue)
  39466. {
  39467. lastValueMin = newValue;
  39468. valueMin = newValue;
  39469. repaint();
  39470. if (popupDisplay != 0)
  39471. {
  39472. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39473. popupDisplay->repaint();
  39474. }
  39475. if (sendUpdateMessage)
  39476. triggerChangeMessage (sendMessageSynchronously);
  39477. }
  39478. }
  39479. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39480. {
  39481. // The maximum value only applies to sliders that are in two- or three-value mode.
  39482. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39483. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39484. newValue = constrainedValue (newValue);
  39485. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39486. {
  39487. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39488. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39489. newValue = jmax ((double) valueMin.getValue(), newValue);
  39490. }
  39491. else
  39492. {
  39493. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39494. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39495. newValue = jmax (lastCurrentValue, newValue);
  39496. }
  39497. if (lastValueMax != newValue)
  39498. {
  39499. lastValueMax = newValue;
  39500. valueMax = newValue;
  39501. repaint();
  39502. if (popupDisplay != 0)
  39503. {
  39504. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (valueMax.getValue()));
  39505. popupDisplay->repaint();
  39506. }
  39507. if (sendUpdateMessage)
  39508. triggerChangeMessage (sendMessageSynchronously);
  39509. }
  39510. }
  39511. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39512. const double valueToSetOnDoubleClick)
  39513. {
  39514. doubleClickToValue = isDoubleClickEnabled;
  39515. doubleClickReturnValue = valueToSetOnDoubleClick;
  39516. }
  39517. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39518. {
  39519. isEnabled_ = doubleClickToValue;
  39520. return doubleClickReturnValue;
  39521. }
  39522. void Slider::updateText()
  39523. {
  39524. if (valueBox != 0)
  39525. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39526. }
  39527. void Slider::setTextValueSuffix (const String& suffix)
  39528. {
  39529. if (textSuffix != suffix)
  39530. {
  39531. textSuffix = suffix;
  39532. updateText();
  39533. }
  39534. }
  39535. const String Slider::getTextFromValue (double v)
  39536. {
  39537. if (numDecimalPlaces > 0)
  39538. return String (v, numDecimalPlaces) + textSuffix;
  39539. else
  39540. return String (roundToInt (v)) + textSuffix;
  39541. }
  39542. double Slider::getValueFromText (const String& text)
  39543. {
  39544. String t (text.trimStart());
  39545. if (t.endsWith (textSuffix))
  39546. t = t.substring (0, t.length() - textSuffix.length());
  39547. while (t.startsWithChar (T('+')))
  39548. t = t.substring (1).trimStart();
  39549. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39550. .getDoubleValue();
  39551. }
  39552. double Slider::proportionOfLengthToValue (double proportion)
  39553. {
  39554. if (skewFactor != 1.0 && proportion > 0.0)
  39555. proportion = exp (log (proportion) / skewFactor);
  39556. return minimum + (maximum - minimum) * proportion;
  39557. }
  39558. double Slider::valueToProportionOfLength (double value)
  39559. {
  39560. const double n = (value - minimum) / (maximum - minimum);
  39561. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39562. }
  39563. double Slider::snapValue (double attemptedValue, const bool)
  39564. {
  39565. return attemptedValue;
  39566. }
  39567. void Slider::startedDragging()
  39568. {
  39569. }
  39570. void Slider::stoppedDragging()
  39571. {
  39572. }
  39573. void Slider::valueChanged()
  39574. {
  39575. }
  39576. void Slider::enablementChanged()
  39577. {
  39578. repaint();
  39579. }
  39580. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39581. {
  39582. menuEnabled = menuEnabled_;
  39583. }
  39584. void Slider::setScrollWheelEnabled (const bool enabled)
  39585. {
  39586. scrollWheelEnabled = enabled;
  39587. }
  39588. void Slider::labelTextChanged (Label* label)
  39589. {
  39590. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39591. if (newValue != (double) currentValue.getValue())
  39592. {
  39593. sendDragStart();
  39594. setValue (newValue, true, true);
  39595. sendDragEnd();
  39596. }
  39597. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39598. }
  39599. void Slider::buttonClicked (Button* button)
  39600. {
  39601. if (style == IncDecButtons)
  39602. {
  39603. sendDragStart();
  39604. if (button == incButton)
  39605. setValue (snapValue (getValue() + interval, false), true, true);
  39606. else if (button == decButton)
  39607. setValue (snapValue (getValue() - interval, false), true, true);
  39608. sendDragEnd();
  39609. }
  39610. }
  39611. double Slider::constrainedValue (double value) const
  39612. {
  39613. if (interval > 0)
  39614. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39615. if (value <= minimum || maximum <= minimum)
  39616. value = minimum;
  39617. else if (value >= maximum)
  39618. value = maximum;
  39619. return value;
  39620. }
  39621. float Slider::getLinearSliderPos (const double value)
  39622. {
  39623. double sliderPosProportional;
  39624. if (maximum > minimum)
  39625. {
  39626. if (value < minimum)
  39627. {
  39628. sliderPosProportional = 0.0;
  39629. }
  39630. else if (value > maximum)
  39631. {
  39632. sliderPosProportional = 1.0;
  39633. }
  39634. else
  39635. {
  39636. sliderPosProportional = valueToProportionOfLength (value);
  39637. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39638. }
  39639. }
  39640. else
  39641. {
  39642. sliderPosProportional = 0.5;
  39643. }
  39644. if (isVertical() || style == IncDecButtons)
  39645. sliderPosProportional = 1.0 - sliderPosProportional;
  39646. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39647. }
  39648. bool Slider::isHorizontal() const
  39649. {
  39650. return style == LinearHorizontal
  39651. || style == LinearBar
  39652. || style == TwoValueHorizontal
  39653. || style == ThreeValueHorizontal;
  39654. }
  39655. bool Slider::isVertical() const
  39656. {
  39657. return style == LinearVertical
  39658. || style == TwoValueVertical
  39659. || style == ThreeValueVertical;
  39660. }
  39661. bool Slider::incDecDragDirectionIsHorizontal() const
  39662. {
  39663. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39664. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39665. }
  39666. float Slider::getPositionOfValue (const double value)
  39667. {
  39668. if (isHorizontal() || isVertical())
  39669. {
  39670. return getLinearSliderPos (value);
  39671. }
  39672. else
  39673. {
  39674. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39675. return 0.0f;
  39676. }
  39677. }
  39678. void Slider::paint (Graphics& g)
  39679. {
  39680. if (style != IncDecButtons)
  39681. {
  39682. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39683. {
  39684. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39685. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39686. getLookAndFeel().drawRotarySlider (g,
  39687. sliderRect.getX(),
  39688. sliderRect.getY(),
  39689. sliderRect.getWidth(),
  39690. sliderRect.getHeight(),
  39691. sliderPos,
  39692. rotaryStart, rotaryEnd,
  39693. *this);
  39694. }
  39695. else
  39696. {
  39697. getLookAndFeel().drawLinearSlider (g,
  39698. sliderRect.getX(),
  39699. sliderRect.getY(),
  39700. sliderRect.getWidth(),
  39701. sliderRect.getHeight(),
  39702. getLinearSliderPos (lastCurrentValue),
  39703. getLinearSliderPos (lastValueMin),
  39704. getLinearSliderPos (lastValueMax),
  39705. style,
  39706. *this);
  39707. }
  39708. if (style == LinearBar && valueBox == 0)
  39709. {
  39710. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39711. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39712. }
  39713. }
  39714. }
  39715. void Slider::resized()
  39716. {
  39717. int minXSpace = 0;
  39718. int minYSpace = 0;
  39719. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39720. minXSpace = 30;
  39721. else
  39722. minYSpace = 15;
  39723. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39724. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39725. if (style == LinearBar)
  39726. {
  39727. if (valueBox != 0)
  39728. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39729. }
  39730. else
  39731. {
  39732. if (textBoxPos == NoTextBox)
  39733. {
  39734. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39735. }
  39736. else if (textBoxPos == TextBoxLeft)
  39737. {
  39738. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39739. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39740. }
  39741. else if (textBoxPos == TextBoxRight)
  39742. {
  39743. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39744. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39745. }
  39746. else if (textBoxPos == TextBoxAbove)
  39747. {
  39748. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39749. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39750. }
  39751. else if (textBoxPos == TextBoxBelow)
  39752. {
  39753. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39754. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39755. }
  39756. }
  39757. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39758. if (style == LinearBar)
  39759. {
  39760. const int barIndent = 1;
  39761. sliderRegionStart = barIndent;
  39762. sliderRegionSize = getWidth() - barIndent * 2;
  39763. sliderRect.setBounds (sliderRegionStart, barIndent,
  39764. sliderRegionSize, getHeight() - barIndent * 2);
  39765. }
  39766. else if (isHorizontal())
  39767. {
  39768. sliderRegionStart = sliderRect.getX() + indent;
  39769. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39770. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39771. sliderRegionSize, sliderRect.getHeight());
  39772. }
  39773. else if (isVertical())
  39774. {
  39775. sliderRegionStart = sliderRect.getY() + indent;
  39776. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39777. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39778. sliderRect.getWidth(), sliderRegionSize);
  39779. }
  39780. else
  39781. {
  39782. sliderRegionStart = 0;
  39783. sliderRegionSize = 100;
  39784. }
  39785. if (style == IncDecButtons)
  39786. {
  39787. Rectangle<int> buttonRect (sliderRect);
  39788. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39789. buttonRect.expand (-2, 0);
  39790. else
  39791. buttonRect.expand (0, -2);
  39792. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39793. if (incDecButtonsSideBySide)
  39794. {
  39795. decButton->setBounds (buttonRect.getX(),
  39796. buttonRect.getY(),
  39797. buttonRect.getWidth() / 2,
  39798. buttonRect.getHeight());
  39799. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39800. incButton->setBounds (buttonRect.getCentreX(),
  39801. buttonRect.getY(),
  39802. buttonRect.getWidth() / 2,
  39803. buttonRect.getHeight());
  39804. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39805. }
  39806. else
  39807. {
  39808. incButton->setBounds (buttonRect.getX(),
  39809. buttonRect.getY(),
  39810. buttonRect.getWidth(),
  39811. buttonRect.getHeight() / 2);
  39812. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39813. decButton->setBounds (buttonRect.getX(),
  39814. buttonRect.getCentreY(),
  39815. buttonRect.getWidth(),
  39816. buttonRect.getHeight() / 2);
  39817. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39818. }
  39819. }
  39820. }
  39821. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39822. {
  39823. repaint();
  39824. }
  39825. void Slider::mouseDown (const MouseEvent& e)
  39826. {
  39827. mouseWasHidden = false;
  39828. incDecDragged = false;
  39829. mouseXWhenLastDragged = e.x;
  39830. mouseYWhenLastDragged = e.y;
  39831. mouseDragStartX = e.getMouseDownX();
  39832. mouseDragStartY = e.getMouseDownY();
  39833. if (isEnabled())
  39834. {
  39835. if (e.mods.isPopupMenu() && menuEnabled)
  39836. {
  39837. menuShown = true;
  39838. PopupMenu m;
  39839. m.setLookAndFeel (&getLookAndFeel());
  39840. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39841. m.addSeparator();
  39842. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39843. {
  39844. PopupMenu rotaryMenu;
  39845. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39846. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39847. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39848. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39849. }
  39850. const int r = m.show();
  39851. if (r == 1)
  39852. {
  39853. setVelocityBasedMode (! isVelocityBased);
  39854. }
  39855. else if (r == 2)
  39856. {
  39857. setSliderStyle (Rotary);
  39858. }
  39859. else if (r == 3)
  39860. {
  39861. setSliderStyle (RotaryHorizontalDrag);
  39862. }
  39863. else if (r == 4)
  39864. {
  39865. setSliderStyle (RotaryVerticalDrag);
  39866. }
  39867. }
  39868. else if (maximum > minimum)
  39869. {
  39870. menuShown = false;
  39871. if (valueBox != 0)
  39872. valueBox->hideEditor (true);
  39873. sliderBeingDragged = 0;
  39874. if (style == TwoValueHorizontal
  39875. || style == TwoValueVertical
  39876. || style == ThreeValueHorizontal
  39877. || style == ThreeValueVertical)
  39878. {
  39879. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39880. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39881. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39882. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39883. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39884. {
  39885. if (maxPosDistance <= minPosDistance)
  39886. sliderBeingDragged = 2;
  39887. else
  39888. sliderBeingDragged = 1;
  39889. }
  39890. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39891. {
  39892. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39893. sliderBeingDragged = 1;
  39894. else if (normalPosDistance >= maxPosDistance)
  39895. sliderBeingDragged = 2;
  39896. }
  39897. }
  39898. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39899. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39900. * valueToProportionOfLength (currentValue.getValue());
  39901. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39902. : ((sliderBeingDragged == 1) ? valueMin
  39903. : currentValue)).getValue();
  39904. valueOnMouseDown = valueWhenLastDragged;
  39905. if (popupDisplayEnabled)
  39906. {
  39907. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39908. popupDisplay = popup;
  39909. if (parentForPopupDisplay != 0)
  39910. {
  39911. parentForPopupDisplay->addChildComponent (popup);
  39912. }
  39913. else
  39914. {
  39915. popup->addToDesktop (0);
  39916. }
  39917. popup->setVisible (true);
  39918. }
  39919. sendDragStart();
  39920. mouseDrag (e);
  39921. }
  39922. }
  39923. }
  39924. void Slider::mouseUp (const MouseEvent&)
  39925. {
  39926. if (isEnabled()
  39927. && (! menuShown)
  39928. && (maximum > minimum)
  39929. && (style != IncDecButtons || incDecDragged))
  39930. {
  39931. restoreMouseIfHidden();
  39932. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39933. triggerChangeMessage (false);
  39934. sendDragEnd();
  39935. popupDisplay = 0;
  39936. if (style == IncDecButtons)
  39937. {
  39938. incButton->setState (Button::buttonNormal);
  39939. decButton->setState (Button::buttonNormal);
  39940. }
  39941. }
  39942. }
  39943. void Slider::restoreMouseIfHidden()
  39944. {
  39945. if (mouseWasHidden)
  39946. {
  39947. mouseWasHidden = false;
  39948. Component* c = Component::getComponentUnderMouse();
  39949. if (c == 0)
  39950. c = this;
  39951. c->enableUnboundedMouseMovement (false);
  39952. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39953. : ((sliderBeingDragged == 1) ? getMinValue()
  39954. : (double) currentValue.getValue());
  39955. Point<int> mousePos;
  39956. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39957. {
  39958. mousePos = Desktop::getLastMouseDownPosition();
  39959. if (style == RotaryHorizontalDrag)
  39960. {
  39961. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39962. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39963. }
  39964. else
  39965. {
  39966. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39967. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39968. }
  39969. }
  39970. else
  39971. {
  39972. const int pixelPos = (int) getLinearSliderPos (pos);
  39973. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39974. isVertical() ? pixelPos : (getHeight() / 2)));
  39975. }
  39976. Desktop::setMousePosition (mousePos);
  39977. }
  39978. }
  39979. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39980. {
  39981. if (isEnabled()
  39982. && style != IncDecButtons
  39983. && style != Rotary
  39984. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39985. {
  39986. restoreMouseIfHidden();
  39987. }
  39988. }
  39989. static double smallestAngleBetween (double a1, double a2)
  39990. {
  39991. return jmin (fabs (a1 - a2),
  39992. fabs (a1 + double_Pi * 2.0 - a2),
  39993. fabs (a2 + double_Pi * 2.0 - a1));
  39994. }
  39995. void Slider::mouseDrag (const MouseEvent& e)
  39996. {
  39997. if (isEnabled()
  39998. && (! menuShown)
  39999. && (maximum > minimum))
  40000. {
  40001. if (style == Rotary)
  40002. {
  40003. int dx = e.x - sliderRect.getCentreX();
  40004. int dy = e.y - sliderRect.getCentreY();
  40005. if (dx * dx + dy * dy > 25)
  40006. {
  40007. double angle = atan2 ((double) dx, (double) -dy);
  40008. while (angle < 0.0)
  40009. angle += double_Pi * 2.0;
  40010. if (rotaryStop && ! e.mouseWasClicked())
  40011. {
  40012. if (fabs (angle - lastAngle) > double_Pi)
  40013. {
  40014. if (angle >= lastAngle)
  40015. angle -= double_Pi * 2.0;
  40016. else
  40017. angle += double_Pi * 2.0;
  40018. }
  40019. if (angle >= lastAngle)
  40020. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  40021. else
  40022. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  40023. }
  40024. else
  40025. {
  40026. while (angle < rotaryStart)
  40027. angle += double_Pi * 2.0;
  40028. if (angle > rotaryEnd)
  40029. {
  40030. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  40031. angle = rotaryStart;
  40032. else
  40033. angle = rotaryEnd;
  40034. }
  40035. }
  40036. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  40037. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  40038. lastAngle = angle;
  40039. }
  40040. }
  40041. else
  40042. {
  40043. if (style == LinearBar && e.mouseWasClicked()
  40044. && valueBox != 0 && valueBox->isEditable())
  40045. return;
  40046. if (style == IncDecButtons && ! incDecDragged)
  40047. {
  40048. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  40049. return;
  40050. incDecDragged = true;
  40051. mouseDragStartX = e.x;
  40052. mouseDragStartY = e.y;
  40053. }
  40054. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  40055. : false))
  40056. || ((maximum - minimum) / sliderRegionSize < interval))
  40057. {
  40058. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  40059. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  40060. if (style == RotaryHorizontalDrag
  40061. || style == RotaryVerticalDrag
  40062. || style == IncDecButtons
  40063. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  40064. && ! snapsToMousePos))
  40065. {
  40066. const int mouseDiff = (style == RotaryHorizontalDrag
  40067. || style == LinearHorizontal
  40068. || style == LinearBar
  40069. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40070. ? e.x - mouseDragStartX
  40071. : mouseDragStartY - e.y;
  40072. double newPos = valueToProportionOfLength (valueOnMouseDown)
  40073. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  40074. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  40075. if (style == IncDecButtons)
  40076. {
  40077. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  40078. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  40079. }
  40080. }
  40081. else
  40082. {
  40083. if (isVertical())
  40084. scaledMousePos = 1.0 - scaledMousePos;
  40085. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  40086. }
  40087. }
  40088. else
  40089. {
  40090. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  40091. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40092. ? e.x - mouseXWhenLastDragged
  40093. : e.y - mouseYWhenLastDragged;
  40094. const double maxSpeed = jmax (200, sliderRegionSize);
  40095. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  40096. if (speed != 0)
  40097. {
  40098. speed = 0.2 * velocityModeSensitivity
  40099. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  40100. + jmax (0.0, (double) (speed - velocityModeThreshold))
  40101. / maxSpeed))));
  40102. if (mouseDiff < 0)
  40103. speed = -speed;
  40104. if (isVertical() || style == RotaryVerticalDrag
  40105. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  40106. speed = -speed;
  40107. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  40108. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  40109. e.originalComponent->enableUnboundedMouseMovement (true, false);
  40110. mouseWasHidden = true;
  40111. }
  40112. }
  40113. }
  40114. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  40115. if (sliderBeingDragged == 0)
  40116. {
  40117. setValue (snapValue (valueWhenLastDragged, true),
  40118. ! sendChangeOnlyOnRelease, true);
  40119. }
  40120. else if (sliderBeingDragged == 1)
  40121. {
  40122. setMinValue (snapValue (valueWhenLastDragged, true),
  40123. ! sendChangeOnlyOnRelease, false, true);
  40124. if (e.mods.isShiftDown())
  40125. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  40126. else
  40127. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40128. }
  40129. else
  40130. {
  40131. jassert (sliderBeingDragged == 2);
  40132. setMaxValue (snapValue (valueWhenLastDragged, true),
  40133. ! sendChangeOnlyOnRelease, false, true);
  40134. if (e.mods.isShiftDown())
  40135. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  40136. else
  40137. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40138. }
  40139. mouseXWhenLastDragged = e.x;
  40140. mouseYWhenLastDragged = e.y;
  40141. }
  40142. }
  40143. void Slider::mouseDoubleClick (const MouseEvent&)
  40144. {
  40145. if (doubleClickToValue
  40146. && isEnabled()
  40147. && style != IncDecButtons
  40148. && minimum <= doubleClickReturnValue
  40149. && maximum >= doubleClickReturnValue)
  40150. {
  40151. sendDragStart();
  40152. setValue (doubleClickReturnValue, true, true);
  40153. sendDragEnd();
  40154. }
  40155. }
  40156. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  40157. {
  40158. if (scrollWheelEnabled && isEnabled()
  40159. && style != TwoValueHorizontal
  40160. && style != TwoValueVertical)
  40161. {
  40162. if (maximum > minimum && ! isMouseButtonDownAnywhere())
  40163. {
  40164. if (valueBox != 0)
  40165. valueBox->hideEditor (false);
  40166. const double value = (double) currentValue.getValue();
  40167. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  40168. const double currentPos = valueToProportionOfLength (value);
  40169. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  40170. double delta = (newValue != value)
  40171. ? jmax (fabs (newValue - value), interval) : 0;
  40172. if (value > newValue)
  40173. delta = -delta;
  40174. sendDragStart();
  40175. setValue (snapValue (value + delta, false), true, true);
  40176. sendDragEnd();
  40177. }
  40178. }
  40179. else
  40180. {
  40181. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  40182. }
  40183. }
  40184. void SliderListener::sliderDragStarted (Slider*)
  40185. {
  40186. }
  40187. void SliderListener::sliderDragEnded (Slider*)
  40188. {
  40189. }
  40190. END_JUCE_NAMESPACE
  40191. /*** End of inlined file: juce_Slider.cpp ***/
  40192. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  40193. BEGIN_JUCE_NAMESPACE
  40194. class DragOverlayComp : public Component
  40195. {
  40196. public:
  40197. DragOverlayComp (Image* const image_)
  40198. : image (image_)
  40199. {
  40200. image->multiplyAllAlphas (0.8f);
  40201. setAlwaysOnTop (true);
  40202. }
  40203. ~DragOverlayComp()
  40204. {
  40205. }
  40206. void paint (Graphics& g)
  40207. {
  40208. g.drawImageAt (image, 0, 0);
  40209. }
  40210. private:
  40211. ScopedPointer <Image> image;
  40212. DragOverlayComp (const DragOverlayComp&);
  40213. DragOverlayComp& operator= (const DragOverlayComp&);
  40214. };
  40215. TableHeaderComponent::TableHeaderComponent()
  40216. : columnsChanged (false),
  40217. columnsResized (false),
  40218. sortChanged (false),
  40219. menuActive (true),
  40220. stretchToFit (false),
  40221. columnIdBeingResized (0),
  40222. columnIdBeingDragged (0),
  40223. columnIdUnderMouse (0),
  40224. lastDeliberateWidth (0)
  40225. {
  40226. }
  40227. TableHeaderComponent::~TableHeaderComponent()
  40228. {
  40229. dragOverlayComp = 0;
  40230. }
  40231. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  40232. {
  40233. menuActive = hasMenu;
  40234. }
  40235. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  40236. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  40237. {
  40238. if (onlyCountVisibleColumns)
  40239. {
  40240. int num = 0;
  40241. for (int i = columns.size(); --i >= 0;)
  40242. if (columns.getUnchecked(i)->isVisible())
  40243. ++num;
  40244. return num;
  40245. }
  40246. else
  40247. {
  40248. return columns.size();
  40249. }
  40250. }
  40251. const String TableHeaderComponent::getColumnName (const int columnId) const
  40252. {
  40253. const ColumnInfo* const ci = getInfoForId (columnId);
  40254. return ci != 0 ? ci->name : String::empty;
  40255. }
  40256. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  40257. {
  40258. ColumnInfo* const ci = getInfoForId (columnId);
  40259. if (ci != 0 && ci->name != newName)
  40260. {
  40261. ci->name = newName;
  40262. sendColumnsChanged();
  40263. }
  40264. }
  40265. void TableHeaderComponent::addColumn (const String& columnName,
  40266. const int columnId,
  40267. const int width,
  40268. const int minimumWidth,
  40269. const int maximumWidth,
  40270. const int propertyFlags,
  40271. const int insertIndex)
  40272. {
  40273. // can't have a duplicate or null ID!
  40274. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  40275. jassert (width > 0);
  40276. ColumnInfo* const ci = new ColumnInfo();
  40277. ci->name = columnName;
  40278. ci->id = columnId;
  40279. ci->width = width;
  40280. ci->lastDeliberateWidth = width;
  40281. ci->minimumWidth = minimumWidth;
  40282. ci->maximumWidth = maximumWidth;
  40283. if (ci->maximumWidth < 0)
  40284. ci->maximumWidth = std::numeric_limits<int>::max();
  40285. jassert (ci->maximumWidth >= ci->minimumWidth);
  40286. ci->propertyFlags = propertyFlags;
  40287. columns.insert (insertIndex, ci);
  40288. sendColumnsChanged();
  40289. }
  40290. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  40291. {
  40292. const int index = getIndexOfColumnId (columnIdToRemove, false);
  40293. if (index >= 0)
  40294. {
  40295. columns.remove (index);
  40296. sortChanged = true;
  40297. sendColumnsChanged();
  40298. }
  40299. }
  40300. void TableHeaderComponent::removeAllColumns()
  40301. {
  40302. if (columns.size() > 0)
  40303. {
  40304. columns.clear();
  40305. sendColumnsChanged();
  40306. }
  40307. }
  40308. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  40309. {
  40310. const int currentIndex = getIndexOfColumnId (columnId, false);
  40311. newIndex = visibleIndexToTotalIndex (newIndex);
  40312. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  40313. {
  40314. columns.move (currentIndex, newIndex);
  40315. sendColumnsChanged();
  40316. }
  40317. }
  40318. int TableHeaderComponent::getColumnWidth (const int columnId) const
  40319. {
  40320. const ColumnInfo* const ci = getInfoForId (columnId);
  40321. return ci != 0 ? ci->width : 0;
  40322. }
  40323. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40324. {
  40325. ColumnInfo* const ci = getInfoForId (columnId);
  40326. if (ci != 0 && ci->width != newWidth)
  40327. {
  40328. const int numColumns = getNumColumns (true);
  40329. ci->lastDeliberateWidth = ci->width
  40330. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40331. if (stretchToFit)
  40332. {
  40333. const int index = getIndexOfColumnId (columnId, true) + 1;
  40334. if (((unsigned int) index) < (unsigned int) numColumns)
  40335. {
  40336. const int x = getColumnPosition (index).getX();
  40337. if (lastDeliberateWidth == 0)
  40338. lastDeliberateWidth = getTotalWidth();
  40339. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40340. }
  40341. }
  40342. repaint();
  40343. columnsResized = true;
  40344. triggerAsyncUpdate();
  40345. }
  40346. }
  40347. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40348. {
  40349. int n = 0;
  40350. for (int i = 0; i < columns.size(); ++i)
  40351. {
  40352. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40353. {
  40354. if (columns.getUnchecked(i)->id == columnId)
  40355. return n;
  40356. ++n;
  40357. }
  40358. }
  40359. return -1;
  40360. }
  40361. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40362. {
  40363. if (onlyCountVisibleColumns)
  40364. index = visibleIndexToTotalIndex (index);
  40365. const ColumnInfo* const ci = columns [index];
  40366. return (ci != 0) ? ci->id : 0;
  40367. }
  40368. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  40369. {
  40370. int x = 0, width = 0, n = 0;
  40371. for (int i = 0; i < columns.size(); ++i)
  40372. {
  40373. x += width;
  40374. if (columns.getUnchecked(i)->isVisible())
  40375. {
  40376. width = columns.getUnchecked(i)->width;
  40377. if (n++ == index)
  40378. break;
  40379. }
  40380. else
  40381. {
  40382. width = 0;
  40383. }
  40384. }
  40385. return Rectangle<int> (x, 0, width, getHeight());
  40386. }
  40387. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40388. {
  40389. if (xToFind >= 0)
  40390. {
  40391. int x = 0;
  40392. for (int i = 0; i < columns.size(); ++i)
  40393. {
  40394. const ColumnInfo* const ci = columns.getUnchecked(i);
  40395. if (ci->isVisible())
  40396. {
  40397. x += ci->width;
  40398. if (xToFind < x)
  40399. return ci->id;
  40400. }
  40401. }
  40402. }
  40403. return 0;
  40404. }
  40405. int TableHeaderComponent::getTotalWidth() const
  40406. {
  40407. int w = 0;
  40408. for (int i = columns.size(); --i >= 0;)
  40409. if (columns.getUnchecked(i)->isVisible())
  40410. w += columns.getUnchecked(i)->width;
  40411. return w;
  40412. }
  40413. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40414. {
  40415. stretchToFit = shouldStretchToFit;
  40416. lastDeliberateWidth = getTotalWidth();
  40417. resized();
  40418. }
  40419. bool TableHeaderComponent::isStretchToFitActive() const
  40420. {
  40421. return stretchToFit;
  40422. }
  40423. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40424. {
  40425. if (stretchToFit && getWidth() > 0
  40426. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40427. {
  40428. lastDeliberateWidth = targetTotalWidth;
  40429. resizeColumnsToFit (0, targetTotalWidth);
  40430. }
  40431. }
  40432. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40433. {
  40434. targetTotalWidth = jmax (targetTotalWidth, 0);
  40435. StretchableObjectResizer sor;
  40436. int i;
  40437. for (i = firstColumnIndex; i < columns.size(); ++i)
  40438. {
  40439. ColumnInfo* const ci = columns.getUnchecked(i);
  40440. if (ci->isVisible())
  40441. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40442. }
  40443. sor.resizeToFit (targetTotalWidth);
  40444. int visIndex = 0;
  40445. for (i = firstColumnIndex; i < columns.size(); ++i)
  40446. {
  40447. ColumnInfo* const ci = columns.getUnchecked(i);
  40448. if (ci->isVisible())
  40449. {
  40450. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40451. (int) floor (sor.getItemSize (visIndex++)));
  40452. if (newWidth != ci->width)
  40453. {
  40454. ci->width = newWidth;
  40455. repaint();
  40456. columnsResized = true;
  40457. triggerAsyncUpdate();
  40458. }
  40459. }
  40460. }
  40461. }
  40462. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40463. {
  40464. ColumnInfo* const ci = getInfoForId (columnId);
  40465. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40466. {
  40467. if (shouldBeVisible)
  40468. ci->propertyFlags |= visible;
  40469. else
  40470. ci->propertyFlags &= ~visible;
  40471. sendColumnsChanged();
  40472. resized();
  40473. }
  40474. }
  40475. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40476. {
  40477. const ColumnInfo* const ci = getInfoForId (columnId);
  40478. return ci != 0 && ci->isVisible();
  40479. }
  40480. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40481. {
  40482. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40483. {
  40484. for (int i = columns.size(); --i >= 0;)
  40485. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40486. ColumnInfo* const ci = getInfoForId (columnId);
  40487. if (ci != 0)
  40488. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40489. reSortTable();
  40490. }
  40491. }
  40492. int TableHeaderComponent::getSortColumnId() const
  40493. {
  40494. for (int i = columns.size(); --i >= 0;)
  40495. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40496. return columns.getUnchecked(i)->id;
  40497. return 0;
  40498. }
  40499. bool TableHeaderComponent::isSortedForwards() const
  40500. {
  40501. for (int i = columns.size(); --i >= 0;)
  40502. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40503. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40504. return true;
  40505. }
  40506. void TableHeaderComponent::reSortTable()
  40507. {
  40508. sortChanged = true;
  40509. repaint();
  40510. triggerAsyncUpdate();
  40511. }
  40512. const String TableHeaderComponent::toString() const
  40513. {
  40514. String s;
  40515. XmlElement doc ("TABLELAYOUT");
  40516. doc.setAttribute ("sortedCol", getSortColumnId());
  40517. doc.setAttribute ("sortForwards", isSortedForwards());
  40518. for (int i = 0; i < columns.size(); ++i)
  40519. {
  40520. const ColumnInfo* const ci = columns.getUnchecked (i);
  40521. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40522. e->setAttribute ("id", ci->id);
  40523. e->setAttribute ("visible", ci->isVisible());
  40524. e->setAttribute ("width", ci->width);
  40525. }
  40526. return doc.createDocument (String::empty, true, false);
  40527. }
  40528. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40529. {
  40530. XmlDocument doc (storedVersion);
  40531. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40532. int index = 0;
  40533. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40534. {
  40535. forEachXmlChildElement (*storedXml, col)
  40536. {
  40537. const int tabId = col->getIntAttribute ("id");
  40538. ColumnInfo* const ci = getInfoForId (tabId);
  40539. if (ci != 0)
  40540. {
  40541. columns.move (columns.indexOf (ci), index);
  40542. ci->width = col->getIntAttribute ("width");
  40543. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40544. }
  40545. ++index;
  40546. }
  40547. columnsResized = true;
  40548. sendColumnsChanged();
  40549. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40550. storedXml->getBoolAttribute ("sortForwards", true));
  40551. }
  40552. }
  40553. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40554. {
  40555. listeners.addIfNotAlreadyThere (newListener);
  40556. }
  40557. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40558. {
  40559. listeners.removeValue (listenerToRemove);
  40560. }
  40561. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40562. {
  40563. const ColumnInfo* const ci = getInfoForId (columnId);
  40564. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40565. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40566. }
  40567. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40568. {
  40569. for (int i = 0; i < columns.size(); ++i)
  40570. {
  40571. const ColumnInfo* const ci = columns.getUnchecked(i);
  40572. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40573. menu.addItem (ci->id, ci->name,
  40574. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40575. isColumnVisible (ci->id));
  40576. }
  40577. }
  40578. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40579. {
  40580. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40581. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40582. }
  40583. void TableHeaderComponent::paint (Graphics& g)
  40584. {
  40585. LookAndFeel& lf = getLookAndFeel();
  40586. lf.drawTableHeaderBackground (g, *this);
  40587. const Rectangle<int> clip (g.getClipBounds());
  40588. int x = 0;
  40589. for (int i = 0; i < columns.size(); ++i)
  40590. {
  40591. const ColumnInfo* const ci = columns.getUnchecked(i);
  40592. if (ci->isVisible())
  40593. {
  40594. if (x + ci->width > clip.getX()
  40595. && (ci->id != columnIdBeingDragged
  40596. || dragOverlayComp == 0
  40597. || ! dragOverlayComp->isVisible()))
  40598. {
  40599. g.saveState();
  40600. g.setOrigin (x, 0);
  40601. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40602. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40603. ci->id == columnIdUnderMouse,
  40604. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40605. ci->propertyFlags);
  40606. g.restoreState();
  40607. }
  40608. x += ci->width;
  40609. if (x >= clip.getRight())
  40610. break;
  40611. }
  40612. }
  40613. }
  40614. void TableHeaderComponent::resized()
  40615. {
  40616. }
  40617. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40618. {
  40619. updateColumnUnderMouse (e.x, e.y);
  40620. }
  40621. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40622. {
  40623. updateColumnUnderMouse (e.x, e.y);
  40624. }
  40625. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40626. {
  40627. updateColumnUnderMouse (e.x, e.y);
  40628. }
  40629. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40630. {
  40631. repaint();
  40632. columnIdBeingResized = 0;
  40633. columnIdBeingDragged = 0;
  40634. if (columnIdUnderMouse != 0)
  40635. {
  40636. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40637. if (e.mods.isPopupMenu())
  40638. columnClicked (columnIdUnderMouse, e.mods);
  40639. }
  40640. if (menuActive && e.mods.isPopupMenu())
  40641. showColumnChooserMenu (columnIdUnderMouse);
  40642. }
  40643. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40644. {
  40645. if (columnIdBeingResized == 0
  40646. && columnIdBeingDragged == 0
  40647. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40648. {
  40649. dragOverlayComp = 0;
  40650. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40651. if (columnIdBeingResized != 0)
  40652. {
  40653. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40654. initialColumnWidth = ci->width;
  40655. }
  40656. else
  40657. {
  40658. beginDrag (e);
  40659. }
  40660. }
  40661. if (columnIdBeingResized != 0)
  40662. {
  40663. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40664. if (ci != 0)
  40665. {
  40666. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40667. initialColumnWidth + e.getDistanceFromDragStartX());
  40668. if (stretchToFit)
  40669. {
  40670. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40671. int minWidthOnRight = 0;
  40672. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40673. if (columns.getUnchecked (i)->isVisible())
  40674. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40675. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40676. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40677. }
  40678. setColumnWidth (columnIdBeingResized, w);
  40679. }
  40680. }
  40681. else if (columnIdBeingDragged != 0)
  40682. {
  40683. if (e.y >= -50 && e.y < getHeight() + 50)
  40684. {
  40685. if (dragOverlayComp != 0)
  40686. {
  40687. dragOverlayComp->setVisible (true);
  40688. dragOverlayComp->setBounds (jlimit (0,
  40689. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40690. e.x - draggingColumnOffset),
  40691. 0,
  40692. dragOverlayComp->getWidth(),
  40693. getHeight());
  40694. for (int i = columns.size(); --i >= 0;)
  40695. {
  40696. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40697. int newIndex = currentIndex;
  40698. if (newIndex > 0)
  40699. {
  40700. // if the previous column isn't draggable, we can't move our column
  40701. // past it, because that'd change the undraggable column's position..
  40702. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40703. if ((previous->propertyFlags & draggable) != 0)
  40704. {
  40705. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40706. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40707. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40708. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40709. {
  40710. --newIndex;
  40711. }
  40712. }
  40713. }
  40714. if (newIndex < columns.size() - 1)
  40715. {
  40716. // if the next column isn't draggable, we can't move our column
  40717. // past it, because that'd change the undraggable column's position..
  40718. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40719. if ((nextCol->propertyFlags & draggable) != 0)
  40720. {
  40721. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40722. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40723. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40724. > abs (dragOverlayComp->getRight() - rightOfNext))
  40725. {
  40726. ++newIndex;
  40727. }
  40728. }
  40729. }
  40730. if (newIndex != currentIndex)
  40731. moveColumn (columnIdBeingDragged, newIndex);
  40732. else
  40733. break;
  40734. }
  40735. }
  40736. }
  40737. else
  40738. {
  40739. endDrag (draggingColumnOriginalIndex);
  40740. }
  40741. }
  40742. }
  40743. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40744. {
  40745. if (columnIdBeingDragged == 0)
  40746. {
  40747. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40748. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40749. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40750. {
  40751. columnIdBeingDragged = 0;
  40752. }
  40753. else
  40754. {
  40755. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40756. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40757. const int temp = columnIdBeingDragged;
  40758. columnIdBeingDragged = 0;
  40759. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40760. columnIdBeingDragged = temp;
  40761. dragOverlayComp->setBounds (columnRect);
  40762. for (int i = listeners.size(); --i >= 0;)
  40763. {
  40764. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40765. i = jmin (i, listeners.size() - 1);
  40766. }
  40767. }
  40768. }
  40769. }
  40770. void TableHeaderComponent::endDrag (const int finalIndex)
  40771. {
  40772. if (columnIdBeingDragged != 0)
  40773. {
  40774. moveColumn (columnIdBeingDragged, finalIndex);
  40775. columnIdBeingDragged = 0;
  40776. repaint();
  40777. for (int i = listeners.size(); --i >= 0;)
  40778. {
  40779. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40780. i = jmin (i, listeners.size() - 1);
  40781. }
  40782. }
  40783. }
  40784. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40785. {
  40786. mouseDrag (e);
  40787. for (int i = columns.size(); --i >= 0;)
  40788. if (columns.getUnchecked (i)->isVisible())
  40789. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40790. columnIdBeingResized = 0;
  40791. repaint();
  40792. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40793. updateColumnUnderMouse (e.x, e.y);
  40794. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40795. columnClicked (columnIdUnderMouse, e.mods);
  40796. dragOverlayComp = 0;
  40797. }
  40798. const MouseCursor TableHeaderComponent::getMouseCursor()
  40799. {
  40800. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40801. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40802. return Component::getMouseCursor();
  40803. }
  40804. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40805. {
  40806. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40807. }
  40808. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40809. {
  40810. for (int i = columns.size(); --i >= 0;)
  40811. if (columns.getUnchecked(i)->id == id)
  40812. return columns.getUnchecked(i);
  40813. return 0;
  40814. }
  40815. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40816. {
  40817. int n = 0;
  40818. for (int i = 0; i < columns.size(); ++i)
  40819. {
  40820. if (columns.getUnchecked(i)->isVisible())
  40821. {
  40822. if (n == visibleIndex)
  40823. return i;
  40824. ++n;
  40825. }
  40826. }
  40827. return -1;
  40828. }
  40829. void TableHeaderComponent::sendColumnsChanged()
  40830. {
  40831. if (stretchToFit && lastDeliberateWidth > 0)
  40832. resizeAllColumnsToFit (lastDeliberateWidth);
  40833. repaint();
  40834. columnsChanged = true;
  40835. triggerAsyncUpdate();
  40836. }
  40837. void TableHeaderComponent::handleAsyncUpdate()
  40838. {
  40839. const bool changed = columnsChanged || sortChanged;
  40840. const bool sized = columnsResized || changed;
  40841. const bool sorted = sortChanged;
  40842. columnsChanged = false;
  40843. columnsResized = false;
  40844. sortChanged = false;
  40845. if (sorted)
  40846. {
  40847. for (int i = listeners.size(); --i >= 0;)
  40848. {
  40849. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40850. i = jmin (i, listeners.size() - 1);
  40851. }
  40852. }
  40853. if (changed)
  40854. {
  40855. for (int i = listeners.size(); --i >= 0;)
  40856. {
  40857. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40858. i = jmin (i, listeners.size() - 1);
  40859. }
  40860. }
  40861. if (sized)
  40862. {
  40863. for (int i = listeners.size(); --i >= 0;)
  40864. {
  40865. listeners.getUnchecked(i)->tableColumnsResized (this);
  40866. i = jmin (i, listeners.size() - 1);
  40867. }
  40868. }
  40869. }
  40870. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40871. {
  40872. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40873. {
  40874. const int draggableDistance = 3;
  40875. int x = 0;
  40876. for (int i = 0; i < columns.size(); ++i)
  40877. {
  40878. const ColumnInfo* const ci = columns.getUnchecked(i);
  40879. if (ci->isVisible())
  40880. {
  40881. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40882. && (ci->propertyFlags & resizable) != 0)
  40883. return ci->id;
  40884. x += ci->width;
  40885. }
  40886. }
  40887. }
  40888. return 0;
  40889. }
  40890. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40891. {
  40892. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40893. ? getColumnIdAtX (x) : 0;
  40894. if (newCol != columnIdUnderMouse)
  40895. {
  40896. columnIdUnderMouse = newCol;
  40897. repaint();
  40898. }
  40899. }
  40900. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40901. {
  40902. PopupMenu m;
  40903. addMenuItems (m, columnIdClicked);
  40904. if (m.getNumItems() > 0)
  40905. {
  40906. m.setLookAndFeel (&getLookAndFeel());
  40907. const int result = m.show();
  40908. if (result != 0)
  40909. reactToMenuItem (result, columnIdClicked);
  40910. }
  40911. }
  40912. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40913. {
  40914. }
  40915. END_JUCE_NAMESPACE
  40916. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40917. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40918. BEGIN_JUCE_NAMESPACE
  40919. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40920. class TableListRowComp : public Component,
  40921. public TooltipClient
  40922. {
  40923. public:
  40924. TableListRowComp (TableListBox& owner_)
  40925. : owner (owner_),
  40926. row (-1),
  40927. isSelected (false)
  40928. {
  40929. }
  40930. ~TableListRowComp()
  40931. {
  40932. deleteAllChildren();
  40933. }
  40934. void paint (Graphics& g)
  40935. {
  40936. TableListBoxModel* const model = owner.getModel();
  40937. if (model != 0)
  40938. {
  40939. const TableHeaderComponent* const header = owner.getHeader();
  40940. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40941. const int numColumns = header->getNumColumns (true);
  40942. for (int i = 0; i < numColumns; ++i)
  40943. {
  40944. if (! columnsWithComponents [i])
  40945. {
  40946. const int columnId = header->getColumnIdOfIndex (i, true);
  40947. Rectangle<int> columnRect (header->getColumnPosition (i));
  40948. columnRect.setSize (columnRect.getWidth(), getHeight());
  40949. g.saveState();
  40950. g.reduceClipRegion (columnRect);
  40951. g.setOrigin (columnRect.getX(), 0);
  40952. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40953. g.restoreState();
  40954. }
  40955. }
  40956. }
  40957. }
  40958. void update (const int newRow, const bool isNowSelected)
  40959. {
  40960. if (newRow != row || isNowSelected != isSelected)
  40961. {
  40962. row = newRow;
  40963. isSelected = isNowSelected;
  40964. repaint();
  40965. }
  40966. if (row < owner.getNumRows())
  40967. {
  40968. jassert (row >= 0);
  40969. const var::identifier tagPropertyName ("_tableLastUseNum");
  40970. const int newTag = Random::getSystemRandom().nextInt();
  40971. const TableHeaderComponent* const header = owner.getHeader();
  40972. const int numColumns = header->getNumColumns (true);
  40973. int i;
  40974. columnsWithComponents.clear();
  40975. if (owner.getModel() != 0)
  40976. {
  40977. for (i = 0; i < numColumns; ++i)
  40978. {
  40979. const int columnId = header->getColumnIdOfIndex (i, true);
  40980. Component* const newComp
  40981. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40982. findChildComponentForColumn (columnId));
  40983. if (newComp != 0)
  40984. {
  40985. addAndMakeVisible (newComp);
  40986. newComp->getProperties().set (tagPropertyName, newTag);
  40987. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40988. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40989. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40990. columnsWithComponents.setBit (i);
  40991. }
  40992. }
  40993. }
  40994. for (i = getNumChildComponents(); --i >= 0;)
  40995. {
  40996. Component* const c = getChildComponent (i);
  40997. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40998. delete c;
  40999. }
  41000. }
  41001. else
  41002. {
  41003. columnsWithComponents.clear();
  41004. deleteAllChildren();
  41005. }
  41006. }
  41007. void resized()
  41008. {
  41009. for (int i = getNumChildComponents(); --i >= 0;)
  41010. {
  41011. Component* const c = getChildComponent (i);
  41012. const int columnId = c->getProperties() [tableColumnPropertyTag];
  41013. if (columnId != 0)
  41014. {
  41015. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  41016. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41017. }
  41018. }
  41019. }
  41020. void mouseDown (const MouseEvent& e)
  41021. {
  41022. isDragging = false;
  41023. selectRowOnMouseUp = false;
  41024. if (isEnabled())
  41025. {
  41026. if (! isSelected)
  41027. {
  41028. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41029. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41030. if (columnId != 0 && owner.getModel() != 0)
  41031. owner.getModel()->cellClicked (row, columnId, e);
  41032. }
  41033. else
  41034. {
  41035. selectRowOnMouseUp = true;
  41036. }
  41037. }
  41038. }
  41039. void mouseDrag (const MouseEvent& e)
  41040. {
  41041. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  41042. {
  41043. const SparseSet <int> selectedRows (owner.getSelectedRows());
  41044. if (selectedRows.size() > 0)
  41045. {
  41046. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  41047. if (dragDescription.isNotEmpty())
  41048. {
  41049. isDragging = true;
  41050. owner.startDragAndDrop (e, dragDescription);
  41051. }
  41052. }
  41053. }
  41054. }
  41055. void mouseUp (const MouseEvent& e)
  41056. {
  41057. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  41058. {
  41059. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41060. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41061. if (columnId != 0 && owner.getModel() != 0)
  41062. owner.getModel()->cellClicked (row, columnId, e);
  41063. }
  41064. }
  41065. void mouseDoubleClick (const MouseEvent& e)
  41066. {
  41067. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41068. if (columnId != 0 && owner.getModel() != 0)
  41069. owner.getModel()->cellDoubleClicked (row, columnId, e);
  41070. }
  41071. const String getTooltip()
  41072. {
  41073. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  41074. if (columnId != 0 && owner.getModel() != 0)
  41075. return owner.getModel()->getCellTooltip (row, columnId);
  41076. return String::empty;
  41077. }
  41078. juce_UseDebuggingNewOperator
  41079. private:
  41080. TableListBox& owner;
  41081. int row;
  41082. bool isSelected, isDragging, selectRowOnMouseUp;
  41083. BitArray columnsWithComponents;
  41084. Component* findChildComponentForColumn (const int columnId) const
  41085. {
  41086. for (int i = getNumChildComponents(); --i >= 0;)
  41087. {
  41088. Component* const c = getChildComponent (i);
  41089. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  41090. return c;
  41091. }
  41092. return 0;
  41093. }
  41094. TableListRowComp (const TableListRowComp&);
  41095. TableListRowComp& operator= (const TableListRowComp&);
  41096. };
  41097. class TableListBoxHeader : public TableHeaderComponent
  41098. {
  41099. public:
  41100. TableListBoxHeader (TableListBox& owner_)
  41101. : owner (owner_)
  41102. {
  41103. }
  41104. ~TableListBoxHeader()
  41105. {
  41106. }
  41107. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  41108. {
  41109. if (owner.isAutoSizeMenuOptionShown())
  41110. {
  41111. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  41112. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  41113. menu.addSeparator();
  41114. }
  41115. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  41116. }
  41117. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  41118. {
  41119. if (menuReturnId == 0xf836743)
  41120. {
  41121. owner.autoSizeColumn (columnIdClicked);
  41122. }
  41123. else if (menuReturnId == 0xf836744)
  41124. {
  41125. owner.autoSizeAllColumns();
  41126. }
  41127. else
  41128. {
  41129. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  41130. }
  41131. }
  41132. juce_UseDebuggingNewOperator
  41133. private:
  41134. TableListBox& owner;
  41135. TableListBoxHeader (const TableListBoxHeader&);
  41136. TableListBoxHeader& operator= (const TableListBoxHeader&);
  41137. };
  41138. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  41139. : ListBox (name, 0),
  41140. model (model_),
  41141. autoSizeOptionsShown (true)
  41142. {
  41143. ListBox::model = this;
  41144. header = new TableListBoxHeader (*this);
  41145. header->setSize (100, 28);
  41146. header->addListener (this);
  41147. setHeaderComponent (header);
  41148. }
  41149. TableListBox::~TableListBox()
  41150. {
  41151. deleteAllChildren();
  41152. }
  41153. void TableListBox::setModel (TableListBoxModel* const newModel)
  41154. {
  41155. if (model != newModel)
  41156. {
  41157. model = newModel;
  41158. updateContent();
  41159. }
  41160. }
  41161. int TableListBox::getHeaderHeight() const
  41162. {
  41163. return header->getHeight();
  41164. }
  41165. void TableListBox::setHeaderHeight (const int newHeight)
  41166. {
  41167. header->setSize (header->getWidth(), newHeight);
  41168. resized();
  41169. }
  41170. void TableListBox::autoSizeColumn (const int columnId)
  41171. {
  41172. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  41173. if (width > 0)
  41174. header->setColumnWidth (columnId, width);
  41175. }
  41176. void TableListBox::autoSizeAllColumns()
  41177. {
  41178. for (int i = 0; i < header->getNumColumns (true); ++i)
  41179. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  41180. }
  41181. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  41182. {
  41183. autoSizeOptionsShown = shouldBeShown;
  41184. }
  41185. bool TableListBox::isAutoSizeMenuOptionShown() const
  41186. {
  41187. return autoSizeOptionsShown;
  41188. }
  41189. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  41190. const int rowNumber,
  41191. const bool relativeToComponentTopLeft) const
  41192. {
  41193. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41194. if (relativeToComponentTopLeft)
  41195. headerCell.translate (header->getX(), 0);
  41196. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  41197. return Rectangle<int> (headerCell.getX(), row.getY(),
  41198. headerCell.getWidth(), row.getHeight());
  41199. }
  41200. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  41201. {
  41202. ScrollBar* const scrollbar = getHorizontalScrollBar();
  41203. if (scrollbar != 0)
  41204. {
  41205. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41206. double x = scrollbar->getCurrentRangeStart();
  41207. const double w = scrollbar->getCurrentRangeSize();
  41208. if (pos.getX() < x)
  41209. x = pos.getX();
  41210. else if (pos.getRight() > x + w)
  41211. x += jmax (0.0, pos.getRight() - (x + w));
  41212. scrollbar->setCurrentRangeStart (x);
  41213. }
  41214. }
  41215. int TableListBox::getNumRows()
  41216. {
  41217. return model != 0 ? model->getNumRows() : 0;
  41218. }
  41219. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  41220. {
  41221. }
  41222. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  41223. {
  41224. if (existingComponentToUpdate == 0)
  41225. existingComponentToUpdate = new TableListRowComp (*this);
  41226. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  41227. return existingComponentToUpdate;
  41228. }
  41229. void TableListBox::selectedRowsChanged (int row)
  41230. {
  41231. if (model != 0)
  41232. model->selectedRowsChanged (row);
  41233. }
  41234. void TableListBox::deleteKeyPressed (int row)
  41235. {
  41236. if (model != 0)
  41237. model->deleteKeyPressed (row);
  41238. }
  41239. void TableListBox::returnKeyPressed (int row)
  41240. {
  41241. if (model != 0)
  41242. model->returnKeyPressed (row);
  41243. }
  41244. void TableListBox::backgroundClicked()
  41245. {
  41246. if (model != 0)
  41247. model->backgroundClicked();
  41248. }
  41249. void TableListBox::listWasScrolled()
  41250. {
  41251. if (model != 0)
  41252. model->listWasScrolled();
  41253. }
  41254. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  41255. {
  41256. setMinimumContentWidth (header->getTotalWidth());
  41257. repaint();
  41258. updateColumnComponents();
  41259. }
  41260. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  41261. {
  41262. setMinimumContentWidth (header->getTotalWidth());
  41263. repaint();
  41264. updateColumnComponents();
  41265. }
  41266. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  41267. {
  41268. if (model != 0)
  41269. model->sortOrderChanged (header->getSortColumnId(),
  41270. header->isSortedForwards());
  41271. }
  41272. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  41273. {
  41274. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  41275. repaint();
  41276. }
  41277. void TableListBox::resized()
  41278. {
  41279. ListBox::resized();
  41280. header->resizeAllColumnsToFit (getVisibleContentWidth());
  41281. setMinimumContentWidth (header->getTotalWidth());
  41282. }
  41283. void TableListBox::updateColumnComponents() const
  41284. {
  41285. const int firstRow = getRowContainingPosition (0, 0);
  41286. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  41287. {
  41288. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  41289. if (rowComp != 0)
  41290. rowComp->resized();
  41291. }
  41292. }
  41293. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  41294. {
  41295. }
  41296. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  41297. {
  41298. }
  41299. void TableListBoxModel::backgroundClicked()
  41300. {
  41301. }
  41302. void TableListBoxModel::sortOrderChanged (int, const bool)
  41303. {
  41304. }
  41305. int TableListBoxModel::getColumnAutoSizeWidth (int)
  41306. {
  41307. return 0;
  41308. }
  41309. void TableListBoxModel::selectedRowsChanged (int)
  41310. {
  41311. }
  41312. void TableListBoxModel::deleteKeyPressed (int)
  41313. {
  41314. }
  41315. void TableListBoxModel::returnKeyPressed (int)
  41316. {
  41317. }
  41318. void TableListBoxModel::listWasScrolled()
  41319. {
  41320. }
  41321. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  41322. {
  41323. return String::empty;
  41324. }
  41325. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41326. {
  41327. return String::empty;
  41328. }
  41329. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41330. {
  41331. (void) existingComponentToUpdate;
  41332. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41333. return 0;
  41334. }
  41335. END_JUCE_NAMESPACE
  41336. /*** End of inlined file: juce_TableListBox.cpp ***/
  41337. /*** Start of inlined file: juce_TextEditor.cpp ***/
  41338. BEGIN_JUCE_NAMESPACE
  41339. // a word or space that can't be broken down any further
  41340. struct TextAtom
  41341. {
  41342. String atomText;
  41343. float width;
  41344. uint16 numChars;
  41345. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41346. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41347. const String getText (const tchar passwordCharacter) const
  41348. {
  41349. if (passwordCharacter == 0)
  41350. return atomText;
  41351. else
  41352. return String::repeatedString (String::charToString (passwordCharacter),
  41353. atomText.length());
  41354. }
  41355. const String getTrimmedText (const tchar passwordCharacter) const
  41356. {
  41357. if (passwordCharacter == 0)
  41358. return atomText.substring (0, numChars);
  41359. else if (isNewLine())
  41360. return String::empty;
  41361. else
  41362. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41363. }
  41364. };
  41365. // a run of text with a single font and colour
  41366. class UniformTextSection
  41367. {
  41368. public:
  41369. UniformTextSection (const String& text,
  41370. const Font& font_,
  41371. const Colour& colour_,
  41372. const tchar passwordCharacter)
  41373. : font (font_),
  41374. colour (colour_)
  41375. {
  41376. initialiseAtoms (text, passwordCharacter);
  41377. }
  41378. UniformTextSection (const UniformTextSection& other)
  41379. : font (other.font),
  41380. colour (other.colour)
  41381. {
  41382. atoms.ensureStorageAllocated (other.atoms.size());
  41383. for (int i = 0; i < other.atoms.size(); ++i)
  41384. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41385. }
  41386. ~UniformTextSection()
  41387. {
  41388. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41389. }
  41390. void clear()
  41391. {
  41392. for (int i = atoms.size(); --i >= 0;)
  41393. delete getAtom(i);
  41394. atoms.clear();
  41395. }
  41396. int getNumAtoms() const
  41397. {
  41398. return atoms.size();
  41399. }
  41400. TextAtom* getAtom (const int index) const
  41401. {
  41402. return (TextAtom*) atoms.getUnchecked (index);
  41403. }
  41404. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41405. {
  41406. if (other.atoms.size() > 0)
  41407. {
  41408. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41409. int i = 0;
  41410. if (lastAtom != 0)
  41411. {
  41412. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41413. {
  41414. TextAtom* const first = other.getAtom(0);
  41415. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41416. {
  41417. lastAtom->atomText += first->atomText;
  41418. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41419. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41420. delete first;
  41421. ++i;
  41422. }
  41423. }
  41424. }
  41425. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41426. while (i < other.atoms.size())
  41427. {
  41428. atoms.add (other.getAtom(i));
  41429. ++i;
  41430. }
  41431. }
  41432. }
  41433. UniformTextSection* split (const int indexToBreakAt,
  41434. const tchar passwordCharacter)
  41435. {
  41436. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41437. font, colour,
  41438. passwordCharacter);
  41439. int index = 0;
  41440. for (int i = 0; i < atoms.size(); ++i)
  41441. {
  41442. TextAtom* const atom = getAtom(i);
  41443. const int nextIndex = index + atom->numChars;
  41444. if (index == indexToBreakAt)
  41445. {
  41446. int j;
  41447. for (j = i; j < atoms.size(); ++j)
  41448. section2->atoms.add (getAtom (j));
  41449. for (j = atoms.size(); --j >= i;)
  41450. atoms.remove (j);
  41451. break;
  41452. }
  41453. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41454. {
  41455. TextAtom* const secondAtom = new TextAtom();
  41456. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41457. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41458. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41459. section2->atoms.add (secondAtom);
  41460. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41461. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41462. atom->numChars = (uint16) (indexToBreakAt - index);
  41463. int j;
  41464. for (j = i + 1; j < atoms.size(); ++j)
  41465. section2->atoms.add (getAtom (j));
  41466. for (j = atoms.size(); --j > i;)
  41467. atoms.remove (j);
  41468. break;
  41469. }
  41470. index = nextIndex;
  41471. }
  41472. return section2;
  41473. }
  41474. void appendAllText (String::Concatenator& concatenator) const
  41475. {
  41476. for (int i = 0; i < atoms.size(); ++i)
  41477. concatenator.append (getAtom(i)->atomText);
  41478. }
  41479. void appendSubstring (String::Concatenator& concatenator,
  41480. const Range<int>& range) const
  41481. {
  41482. int index = 0;
  41483. for (int i = 0; i < atoms.size(); ++i)
  41484. {
  41485. const TextAtom* const atom = getAtom (i);
  41486. const int nextIndex = index + atom->numChars;
  41487. if (range.getStart() < nextIndex)
  41488. {
  41489. if (range.getEnd() <= index)
  41490. break;
  41491. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41492. if (! r.isEmpty())
  41493. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41494. }
  41495. index = nextIndex;
  41496. }
  41497. }
  41498. int getTotalLength() const
  41499. {
  41500. int total = 0;
  41501. for (int i = atoms.size(); --i >= 0;)
  41502. total += getAtom(i)->numChars;
  41503. return total;
  41504. }
  41505. void setFont (const Font& newFont,
  41506. const tchar passwordCharacter)
  41507. {
  41508. if (font != newFont)
  41509. {
  41510. font = newFont;
  41511. for (int i = atoms.size(); --i >= 0;)
  41512. {
  41513. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41514. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41515. }
  41516. }
  41517. }
  41518. juce_UseDebuggingNewOperator
  41519. Font font;
  41520. Colour colour;
  41521. private:
  41522. VoidArray atoms;
  41523. void initialiseAtoms (const String& textToParse,
  41524. const tchar passwordCharacter)
  41525. {
  41526. int i = 0;
  41527. const int len = textToParse.length();
  41528. const tchar* const text = (const tchar*) textToParse;
  41529. while (i < len)
  41530. {
  41531. int start = i;
  41532. // create a whitespace atom unless it starts with non-ws
  41533. if (CharacterFunctions::isWhitespace (text[i])
  41534. && text[i] != T('\r')
  41535. && text[i] != T('\n'))
  41536. {
  41537. while (i < len
  41538. && CharacterFunctions::isWhitespace (text[i])
  41539. && text[i] != T('\r')
  41540. && text[i] != T('\n'))
  41541. {
  41542. ++i;
  41543. }
  41544. }
  41545. else
  41546. {
  41547. if (text[i] == T('\r'))
  41548. {
  41549. ++i;
  41550. if ((i < len) && (text[i] == T('\n')))
  41551. {
  41552. ++start;
  41553. ++i;
  41554. }
  41555. }
  41556. else if (text[i] == T('\n'))
  41557. {
  41558. ++i;
  41559. }
  41560. else
  41561. {
  41562. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41563. ++i;
  41564. }
  41565. }
  41566. TextAtom* const atom = new TextAtom();
  41567. atom->atomText = String (text + start, i - start);
  41568. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41569. atom->numChars = (uint16) (i - start);
  41570. atoms.add (atom);
  41571. }
  41572. }
  41573. UniformTextSection& operator= (const UniformTextSection& other);
  41574. };
  41575. class TextEditorIterator
  41576. {
  41577. public:
  41578. TextEditorIterator (const VoidArray& sections_,
  41579. const float wordWrapWidth_,
  41580. const tchar passwordCharacter_)
  41581. : indexInText (0),
  41582. lineY (0),
  41583. lineHeight (0),
  41584. maxDescent (0),
  41585. atomX (0),
  41586. atomRight (0),
  41587. atom (0),
  41588. currentSection (0),
  41589. sections (sections_),
  41590. sectionIndex (0),
  41591. atomIndex (0),
  41592. wordWrapWidth (wordWrapWidth_),
  41593. passwordCharacter (passwordCharacter_)
  41594. {
  41595. jassert (wordWrapWidth_ > 0);
  41596. if (sections.size() > 0)
  41597. {
  41598. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41599. if (currentSection != 0)
  41600. beginNewLine();
  41601. }
  41602. }
  41603. TextEditorIterator (const TextEditorIterator& other)
  41604. : indexInText (other.indexInText),
  41605. lineY (other.lineY),
  41606. lineHeight (other.lineHeight),
  41607. maxDescent (other.maxDescent),
  41608. atomX (other.atomX),
  41609. atomRight (other.atomRight),
  41610. atom (other.atom),
  41611. currentSection (other.currentSection),
  41612. sections (other.sections),
  41613. sectionIndex (other.sectionIndex),
  41614. atomIndex (other.atomIndex),
  41615. wordWrapWidth (other.wordWrapWidth),
  41616. passwordCharacter (other.passwordCharacter),
  41617. tempAtom (other.tempAtom)
  41618. {
  41619. }
  41620. ~TextEditorIterator()
  41621. {
  41622. }
  41623. bool next()
  41624. {
  41625. if (atom == &tempAtom)
  41626. {
  41627. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41628. if (numRemaining > 0)
  41629. {
  41630. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41631. atomX = 0;
  41632. if (tempAtom.numChars > 0)
  41633. lineY += lineHeight;
  41634. indexInText += tempAtom.numChars;
  41635. GlyphArrangement g;
  41636. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41637. int split;
  41638. for (split = 0; split < g.getNumGlyphs(); ++split)
  41639. if (shouldWrap (g.getGlyph (split).getRight()))
  41640. break;
  41641. if (split > 0 && split <= numRemaining)
  41642. {
  41643. tempAtom.numChars = (uint16) split;
  41644. tempAtom.width = g.getGlyph (split - 1).getRight();
  41645. atomRight = atomX + tempAtom.width;
  41646. return true;
  41647. }
  41648. }
  41649. }
  41650. bool forceNewLine = false;
  41651. if (sectionIndex >= sections.size())
  41652. {
  41653. moveToEndOfLastAtom();
  41654. return false;
  41655. }
  41656. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41657. {
  41658. if (atomIndex >= currentSection->getNumAtoms())
  41659. {
  41660. if (++sectionIndex >= sections.size())
  41661. {
  41662. moveToEndOfLastAtom();
  41663. return false;
  41664. }
  41665. atomIndex = 0;
  41666. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41667. }
  41668. else
  41669. {
  41670. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41671. if (! lastAtom->isWhitespace())
  41672. {
  41673. // handle the case where the last atom in a section is actually part of the same
  41674. // word as the first atom of the next section...
  41675. float right = atomRight + lastAtom->width;
  41676. float lineHeight2 = lineHeight;
  41677. float maxDescent2 = maxDescent;
  41678. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41679. {
  41680. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41681. if (s->getNumAtoms() == 0)
  41682. break;
  41683. const TextAtom* const nextAtom = s->getAtom (0);
  41684. if (nextAtom->isWhitespace())
  41685. break;
  41686. right += nextAtom->width;
  41687. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41688. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41689. if (shouldWrap (right))
  41690. {
  41691. lineHeight = lineHeight2;
  41692. maxDescent = maxDescent2;
  41693. forceNewLine = true;
  41694. break;
  41695. }
  41696. if (s->getNumAtoms() > 1)
  41697. break;
  41698. }
  41699. }
  41700. }
  41701. }
  41702. if (atom != 0)
  41703. {
  41704. atomX = atomRight;
  41705. indexInText += atom->numChars;
  41706. if (atom->isNewLine())
  41707. beginNewLine();
  41708. }
  41709. atom = currentSection->getAtom (atomIndex);
  41710. atomRight = atomX + atom->width;
  41711. ++atomIndex;
  41712. if (shouldWrap (atomRight) || forceNewLine)
  41713. {
  41714. if (atom->isWhitespace())
  41715. {
  41716. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41717. atomRight = jmin (atomRight, wordWrapWidth);
  41718. }
  41719. else
  41720. {
  41721. atomRight = atom->width;
  41722. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41723. {
  41724. tempAtom = *atom;
  41725. tempAtom.width = 0;
  41726. tempAtom.numChars = 0;
  41727. atom = &tempAtom;
  41728. if (atomX > 0)
  41729. beginNewLine();
  41730. return next();
  41731. }
  41732. beginNewLine();
  41733. return true;
  41734. }
  41735. }
  41736. return true;
  41737. }
  41738. void beginNewLine()
  41739. {
  41740. atomX = 0;
  41741. lineY += lineHeight;
  41742. int tempSectionIndex = sectionIndex;
  41743. int tempAtomIndex = atomIndex;
  41744. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41745. lineHeight = section->font.getHeight();
  41746. maxDescent = section->font.getDescent();
  41747. float x = (atom != 0) ? atom->width : 0;
  41748. while (! shouldWrap (x))
  41749. {
  41750. if (tempSectionIndex >= sections.size())
  41751. break;
  41752. bool checkSize = false;
  41753. if (tempAtomIndex >= section->getNumAtoms())
  41754. {
  41755. if (++tempSectionIndex >= sections.size())
  41756. break;
  41757. tempAtomIndex = 0;
  41758. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41759. checkSize = true;
  41760. }
  41761. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41762. if (nextAtom == 0)
  41763. break;
  41764. x += nextAtom->width;
  41765. if (shouldWrap (x) || nextAtom->isNewLine())
  41766. break;
  41767. if (checkSize)
  41768. {
  41769. lineHeight = jmax (lineHeight, section->font.getHeight());
  41770. maxDescent = jmax (maxDescent, section->font.getDescent());
  41771. }
  41772. ++tempAtomIndex;
  41773. }
  41774. }
  41775. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41776. {
  41777. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41778. {
  41779. if (lastSection != currentSection)
  41780. {
  41781. lastSection = currentSection;
  41782. g.setColour (currentSection->colour);
  41783. g.setFont (currentSection->font);
  41784. }
  41785. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41786. GlyphArrangement ga;
  41787. ga.addLineOfText (currentSection->font,
  41788. atom->getTrimmedText (passwordCharacter),
  41789. atomX,
  41790. (float) roundToInt (lineY + lineHeight - maxDescent));
  41791. ga.draw (g);
  41792. }
  41793. }
  41794. void drawSelection (Graphics& g,
  41795. const Range<int>& selection) const
  41796. {
  41797. const int startX = roundToInt (indexToX (selection.getStart()));
  41798. const int endX = roundToInt (indexToX (selection.getEnd()));
  41799. const int y = roundToInt (lineY);
  41800. const int nextY = roundToInt (lineY + lineHeight);
  41801. g.fillRect (startX, y, endX - startX, nextY - y);
  41802. }
  41803. void drawSelectedText (Graphics& g,
  41804. const Range<int>& selection,
  41805. const Colour& selectedTextColour) const
  41806. {
  41807. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41808. {
  41809. GlyphArrangement ga;
  41810. ga.addLineOfText (currentSection->font,
  41811. atom->getTrimmedText (passwordCharacter),
  41812. atomX,
  41813. (float) roundToInt (lineY + lineHeight - maxDescent));
  41814. if (selection.getEnd() < indexInText + atom->numChars)
  41815. {
  41816. GlyphArrangement ga2 (ga);
  41817. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41818. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41819. g.setColour (currentSection->colour);
  41820. ga2.draw (g);
  41821. }
  41822. if (selection.getStart() > indexInText)
  41823. {
  41824. GlyphArrangement ga2 (ga);
  41825. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41826. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41827. g.setColour (currentSection->colour);
  41828. ga2.draw (g);
  41829. }
  41830. g.setColour (selectedTextColour);
  41831. ga.draw (g);
  41832. }
  41833. }
  41834. float indexToX (const int indexToFind) const
  41835. {
  41836. if (indexToFind <= indexInText)
  41837. return atomX;
  41838. if (indexToFind >= indexInText + atom->numChars)
  41839. return atomRight;
  41840. GlyphArrangement g;
  41841. g.addLineOfText (currentSection->font,
  41842. atom->getText (passwordCharacter),
  41843. atomX, 0.0f);
  41844. if (indexToFind - indexInText >= g.getNumGlyphs())
  41845. return atomRight;
  41846. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41847. }
  41848. int xToIndex (const float xToFind) const
  41849. {
  41850. if (xToFind <= atomX || atom->isNewLine())
  41851. return indexInText;
  41852. if (xToFind >= atomRight)
  41853. return indexInText + atom->numChars;
  41854. GlyphArrangement g;
  41855. g.addLineOfText (currentSection->font,
  41856. atom->getText (passwordCharacter),
  41857. atomX, 0.0f);
  41858. int j;
  41859. for (j = 0; j < g.getNumGlyphs(); ++j)
  41860. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41861. break;
  41862. return indexInText + j;
  41863. }
  41864. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41865. {
  41866. while (next())
  41867. {
  41868. if (indexInText + atom->numChars > index)
  41869. {
  41870. cx = indexToX (index);
  41871. cy = lineY;
  41872. lineHeight_ = lineHeight;
  41873. return true;
  41874. }
  41875. }
  41876. cx = atomX;
  41877. cy = lineY;
  41878. lineHeight_ = lineHeight;
  41879. return false;
  41880. }
  41881. juce_UseDebuggingNewOperator
  41882. int indexInText;
  41883. float lineY, lineHeight, maxDescent;
  41884. float atomX, atomRight;
  41885. const TextAtom* atom;
  41886. const UniformTextSection* currentSection;
  41887. private:
  41888. const VoidArray& sections;
  41889. int sectionIndex, atomIndex;
  41890. const float wordWrapWidth;
  41891. const tchar passwordCharacter;
  41892. TextAtom tempAtom;
  41893. TextEditorIterator& operator= (const TextEditorIterator&);
  41894. void moveToEndOfLastAtom()
  41895. {
  41896. if (atom != 0)
  41897. {
  41898. atomX = atomRight;
  41899. if (atom->isNewLine())
  41900. {
  41901. atomX = 0.0f;
  41902. lineY += lineHeight;
  41903. }
  41904. }
  41905. }
  41906. bool shouldWrap (const float x) const
  41907. {
  41908. return (x - 0.0001f) >= wordWrapWidth;
  41909. }
  41910. };
  41911. class TextEditorInsertAction : public UndoableAction
  41912. {
  41913. TextEditor& owner;
  41914. const String text;
  41915. const int insertIndex, oldCaretPos, newCaretPos;
  41916. const Font font;
  41917. const Colour colour;
  41918. TextEditorInsertAction (const TextEditorInsertAction&);
  41919. TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41920. public:
  41921. TextEditorInsertAction (TextEditor& owner_,
  41922. const String& text_,
  41923. const int insertIndex_,
  41924. const Font& font_,
  41925. const Colour& colour_,
  41926. const int oldCaretPos_,
  41927. const int newCaretPos_)
  41928. : owner (owner_),
  41929. text (text_),
  41930. insertIndex (insertIndex_),
  41931. oldCaretPos (oldCaretPos_),
  41932. newCaretPos (newCaretPos_),
  41933. font (font_),
  41934. colour (colour_)
  41935. {
  41936. }
  41937. ~TextEditorInsertAction()
  41938. {
  41939. }
  41940. bool perform()
  41941. {
  41942. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41943. return true;
  41944. }
  41945. bool undo()
  41946. {
  41947. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41948. return true;
  41949. }
  41950. int getSizeInUnits()
  41951. {
  41952. return text.length() + 16;
  41953. }
  41954. };
  41955. class TextEditorRemoveAction : public UndoableAction
  41956. {
  41957. TextEditor& owner;
  41958. const Range<int> range;
  41959. const int oldCaretPos, newCaretPos;
  41960. VoidArray removedSections;
  41961. TextEditorRemoveAction (const TextEditorRemoveAction&);
  41962. TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  41963. public:
  41964. TextEditorRemoveAction (TextEditor& owner_,
  41965. const Range<int> range_,
  41966. const int oldCaretPos_,
  41967. const int newCaretPos_,
  41968. const VoidArray& removedSections_)
  41969. : owner (owner_),
  41970. range (range_),
  41971. oldCaretPos (oldCaretPos_),
  41972. newCaretPos (newCaretPos_),
  41973. removedSections (removedSections_)
  41974. {
  41975. }
  41976. ~TextEditorRemoveAction()
  41977. {
  41978. for (int i = removedSections.size(); --i >= 0;)
  41979. {
  41980. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41981. section->clear();
  41982. delete section;
  41983. }
  41984. }
  41985. bool perform()
  41986. {
  41987. owner.remove (range, 0, newCaretPos);
  41988. return true;
  41989. }
  41990. bool undo()
  41991. {
  41992. owner.reinsert (range.getStart(), removedSections);
  41993. owner.moveCursorTo (oldCaretPos, false);
  41994. return true;
  41995. }
  41996. int getSizeInUnits()
  41997. {
  41998. int n = 0;
  41999. for (int i = removedSections.size(); --i >= 0;)
  42000. {
  42001. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42002. n += section->getTotalLength();
  42003. }
  42004. return n + 16;
  42005. }
  42006. };
  42007. class TextHolderComponent : public Component,
  42008. public Timer,
  42009. public Value::Listener
  42010. {
  42011. TextEditor& owner;
  42012. TextHolderComponent (const TextHolderComponent&);
  42013. TextHolderComponent& operator= (const TextHolderComponent&);
  42014. public:
  42015. TextHolderComponent (TextEditor& owner_)
  42016. : owner (owner_)
  42017. {
  42018. setWantsKeyboardFocus (false);
  42019. setInterceptsMouseClicks (false, true);
  42020. owner.getTextValue().addListener (this);
  42021. }
  42022. ~TextHolderComponent()
  42023. {
  42024. owner.getTextValue().removeListener (this);
  42025. }
  42026. void paint (Graphics& g)
  42027. {
  42028. owner.drawContent (g);
  42029. }
  42030. void timerCallback()
  42031. {
  42032. owner.timerCallbackInt();
  42033. }
  42034. const MouseCursor getMouseCursor()
  42035. {
  42036. return owner.getMouseCursor();
  42037. }
  42038. void valueChanged (Value&)
  42039. {
  42040. owner.textWasChangedByValue();
  42041. }
  42042. };
  42043. class TextEditorViewport : public Viewport
  42044. {
  42045. TextEditor* const owner;
  42046. float lastWordWrapWidth;
  42047. TextEditorViewport (const TextEditorViewport&);
  42048. TextEditorViewport& operator= (const TextEditorViewport&);
  42049. public:
  42050. TextEditorViewport (TextEditor* const owner_)
  42051. : owner (owner_),
  42052. lastWordWrapWidth (0)
  42053. {
  42054. }
  42055. ~TextEditorViewport()
  42056. {
  42057. }
  42058. void visibleAreaChanged (int, int, int, int)
  42059. {
  42060. const float wordWrapWidth = owner->getWordWrapWidth();
  42061. if (wordWrapWidth != lastWordWrapWidth)
  42062. {
  42063. lastWordWrapWidth = wordWrapWidth;
  42064. owner->updateTextHolderSize();
  42065. }
  42066. }
  42067. };
  42068. namespace TextEditorDefs
  42069. {
  42070. const int flashSpeedIntervalMs = 380;
  42071. const int textChangeMessageId = 0x10003001;
  42072. const int returnKeyMessageId = 0x10003002;
  42073. const int escapeKeyMessageId = 0x10003003;
  42074. const int focusLossMessageId = 0x10003004;
  42075. const int maxActionsPerTransaction = 100;
  42076. }
  42077. TextEditor::TextEditor (const String& name,
  42078. const tchar passwordCharacter_)
  42079. : Component (name),
  42080. borderSize (1, 1, 1, 3),
  42081. readOnly (false),
  42082. multiline (false),
  42083. wordWrap (false),
  42084. returnKeyStartsNewLine (false),
  42085. caretVisible (true),
  42086. popupMenuEnabled (true),
  42087. selectAllTextWhenFocused (false),
  42088. scrollbarVisible (true),
  42089. wasFocused (false),
  42090. caretFlashState (true),
  42091. keepCursorOnScreen (true),
  42092. tabKeyUsed (false),
  42093. menuActive (false),
  42094. valueTextNeedsUpdating (false),
  42095. cursorX (0),
  42096. cursorY (0),
  42097. cursorHeight (0),
  42098. maxTextLength (0),
  42099. leftIndent (4),
  42100. topIndent (4),
  42101. lastTransactionTime (0),
  42102. currentFont (14.0f),
  42103. totalNumChars (0),
  42104. caretPosition (0),
  42105. passwordCharacter (passwordCharacter_),
  42106. dragType (notDragging)
  42107. {
  42108. setOpaque (true);
  42109. addAndMakeVisible (viewport = new TextEditorViewport (this));
  42110. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  42111. viewport->setWantsKeyboardFocus (false);
  42112. viewport->setScrollBarsShown (false, false);
  42113. setMouseCursor (MouseCursor::IBeamCursor);
  42114. setWantsKeyboardFocus (true);
  42115. }
  42116. TextEditor::~TextEditor()
  42117. {
  42118. textValue.referTo (Value());
  42119. clearInternal (0);
  42120. viewport = 0;
  42121. textHolder = 0;
  42122. }
  42123. void TextEditor::newTransaction()
  42124. {
  42125. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42126. undoManager.beginNewTransaction();
  42127. }
  42128. void TextEditor::doUndoRedo (const bool isRedo)
  42129. {
  42130. if (! isReadOnly())
  42131. {
  42132. if ((isRedo) ? undoManager.redo()
  42133. : undoManager.undo())
  42134. {
  42135. scrollToMakeSureCursorIsVisible();
  42136. repaint();
  42137. textChanged();
  42138. }
  42139. }
  42140. }
  42141. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  42142. const bool shouldWordWrap)
  42143. {
  42144. multiline = shouldBeMultiLine;
  42145. wordWrap = shouldWordWrap && shouldBeMultiLine;
  42146. setScrollbarsShown (scrollbarVisible);
  42147. viewport->setViewPosition (0, 0);
  42148. resized();
  42149. scrollToMakeSureCursorIsVisible();
  42150. }
  42151. bool TextEditor::isMultiLine() const
  42152. {
  42153. return multiline;
  42154. }
  42155. void TextEditor::setScrollbarsShown (bool enabled)
  42156. {
  42157. scrollbarVisible = enabled;
  42158. enabled = enabled && isMultiLine();
  42159. viewport->setScrollBarsShown (enabled, enabled);
  42160. }
  42161. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  42162. {
  42163. readOnly = shouldBeReadOnly;
  42164. enablementChanged();
  42165. }
  42166. bool TextEditor::isReadOnly() const
  42167. {
  42168. return readOnly || ! isEnabled();
  42169. }
  42170. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  42171. {
  42172. returnKeyStartsNewLine = shouldStartNewLine;
  42173. }
  42174. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  42175. {
  42176. tabKeyUsed = shouldTabKeyBeUsed;
  42177. }
  42178. void TextEditor::setPopupMenuEnabled (const bool b)
  42179. {
  42180. popupMenuEnabled = b;
  42181. }
  42182. void TextEditor::setSelectAllWhenFocused (const bool b)
  42183. {
  42184. selectAllTextWhenFocused = b;
  42185. }
  42186. const Font TextEditor::getFont() const
  42187. {
  42188. return currentFont;
  42189. }
  42190. void TextEditor::setFont (const Font& newFont)
  42191. {
  42192. currentFont = newFont;
  42193. scrollToMakeSureCursorIsVisible();
  42194. }
  42195. void TextEditor::applyFontToAllText (const Font& newFont)
  42196. {
  42197. currentFont = newFont;
  42198. const Colour overallColour (findColour (textColourId));
  42199. for (int i = sections.size(); --i >= 0;)
  42200. {
  42201. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  42202. uts->setFont (newFont, passwordCharacter);
  42203. uts->colour = overallColour;
  42204. }
  42205. coalesceSimilarSections();
  42206. updateTextHolderSize();
  42207. scrollToMakeSureCursorIsVisible();
  42208. repaint();
  42209. }
  42210. void TextEditor::colourChanged()
  42211. {
  42212. setOpaque (findColour (backgroundColourId).isOpaque());
  42213. repaint();
  42214. }
  42215. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  42216. {
  42217. caretVisible = shouldCaretBeVisible;
  42218. if (shouldCaretBeVisible)
  42219. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42220. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  42221. : MouseCursor::NormalCursor);
  42222. }
  42223. void TextEditor::setInputRestrictions (const int maxLen,
  42224. const String& chars)
  42225. {
  42226. maxTextLength = jmax (0, maxLen);
  42227. allowedCharacters = chars;
  42228. }
  42229. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  42230. {
  42231. textToShowWhenEmpty = text;
  42232. colourForTextWhenEmpty = colourToUse;
  42233. }
  42234. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  42235. {
  42236. if (passwordCharacter != newPasswordCharacter)
  42237. {
  42238. passwordCharacter = newPasswordCharacter;
  42239. resized();
  42240. repaint();
  42241. }
  42242. }
  42243. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  42244. {
  42245. viewport->setScrollBarThickness (newThicknessPixels);
  42246. }
  42247. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  42248. {
  42249. viewport->setScrollBarButtonVisibility (buttonsVisible);
  42250. }
  42251. void TextEditor::clear()
  42252. {
  42253. clearInternal (0);
  42254. updateTextHolderSize();
  42255. undoManager.clearUndoHistory();
  42256. }
  42257. void TextEditor::setText (const String& newText,
  42258. const bool sendTextChangeMessage)
  42259. {
  42260. const int newLength = newText.length();
  42261. if (newLength != getTotalNumChars() || getText() != newText)
  42262. {
  42263. const int oldCursorPos = caretPosition;
  42264. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  42265. clearInternal (0);
  42266. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  42267. // if you're adding text with line-feeds to a single-line text editor, it
  42268. // ain't gonna look right!
  42269. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  42270. if (cursorWasAtEnd && ! isMultiLine())
  42271. moveCursorTo (getTotalNumChars(), false);
  42272. else
  42273. moveCursorTo (oldCursorPos, false);
  42274. if (sendTextChangeMessage)
  42275. textChanged();
  42276. repaint();
  42277. }
  42278. updateTextHolderSize();
  42279. scrollToMakeSureCursorIsVisible();
  42280. undoManager.clearUndoHistory();
  42281. }
  42282. Value& TextEditor::getTextValue()
  42283. {
  42284. if (valueTextNeedsUpdating)
  42285. {
  42286. valueTextNeedsUpdating = false;
  42287. textValue = getText();
  42288. }
  42289. return textValue;
  42290. }
  42291. void TextEditor::textWasChangedByValue()
  42292. {
  42293. if (textValue.getValueSource().getReferenceCount() > 1)
  42294. setText (textValue.getValue());
  42295. }
  42296. void TextEditor::textChanged()
  42297. {
  42298. updateTextHolderSize();
  42299. postCommandMessage (TextEditorDefs::textChangeMessageId);
  42300. if (textValue.getValueSource().getReferenceCount() > 1)
  42301. {
  42302. valueTextNeedsUpdating = false;
  42303. textValue = getText();
  42304. }
  42305. }
  42306. void TextEditor::returnPressed()
  42307. {
  42308. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  42309. }
  42310. void TextEditor::escapePressed()
  42311. {
  42312. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  42313. }
  42314. void TextEditor::addListener (TextEditorListener* const newListener)
  42315. {
  42316. jassert (newListener != 0)
  42317. if (newListener != 0)
  42318. listeners.add (newListener);
  42319. }
  42320. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  42321. {
  42322. listeners.removeValue (listenerToRemove);
  42323. }
  42324. void TextEditor::timerCallbackInt()
  42325. {
  42326. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42327. if (caretFlashState != newState)
  42328. {
  42329. caretFlashState = newState;
  42330. if (caretFlashState)
  42331. wasFocused = true;
  42332. if (caretVisible
  42333. && hasKeyboardFocus (false)
  42334. && ! isReadOnly())
  42335. {
  42336. repaintCaret();
  42337. }
  42338. }
  42339. const unsigned int now = Time::getApproximateMillisecondCounter();
  42340. if (now > lastTransactionTime + 200)
  42341. newTransaction();
  42342. }
  42343. void TextEditor::repaintCaret()
  42344. {
  42345. if (! findColour (caretColourId).isTransparent())
  42346. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42347. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42348. 4,
  42349. roundToInt (cursorHeight) + 2);
  42350. }
  42351. void TextEditor::repaintText (const Range<int>& range)
  42352. {
  42353. if (! range.isEmpty())
  42354. {
  42355. float x = 0, y = 0, lh = currentFont.getHeight();
  42356. const float wordWrapWidth = getWordWrapWidth();
  42357. if (wordWrapWidth > 0)
  42358. {
  42359. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42360. i.getCharPosition (range.getStart(), x, y, lh);
  42361. const int y1 = (int) y;
  42362. int y2;
  42363. if (range.getEnd() >= getTotalNumChars())
  42364. {
  42365. y2 = textHolder->getHeight();
  42366. }
  42367. else
  42368. {
  42369. i.getCharPosition (range.getEnd(), x, y, lh);
  42370. y2 = (int) (y + lh * 2.0f);
  42371. }
  42372. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42373. }
  42374. }
  42375. }
  42376. void TextEditor::moveCaret (int newCaretPos)
  42377. {
  42378. if (newCaretPos < 0)
  42379. newCaretPos = 0;
  42380. else if (newCaretPos > getTotalNumChars())
  42381. newCaretPos = getTotalNumChars();
  42382. if (newCaretPos != getCaretPosition())
  42383. {
  42384. repaintCaret();
  42385. caretFlashState = true;
  42386. caretPosition = newCaretPos;
  42387. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42388. scrollToMakeSureCursorIsVisible();
  42389. repaintCaret();
  42390. }
  42391. }
  42392. void TextEditor::setCaretPosition (const int newIndex)
  42393. {
  42394. moveCursorTo (newIndex, false);
  42395. }
  42396. int TextEditor::getCaretPosition() const
  42397. {
  42398. return caretPosition;
  42399. }
  42400. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42401. const int desiredCaretY)
  42402. {
  42403. updateCaretPosition();
  42404. int vx = roundToInt (cursorX) - desiredCaretX;
  42405. int vy = roundToInt (cursorY) - desiredCaretY;
  42406. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42407. {
  42408. vx += desiredCaretX - proportionOfWidth (0.2f);
  42409. }
  42410. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42411. {
  42412. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42413. }
  42414. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42415. if (! isMultiLine())
  42416. {
  42417. vy = viewport->getViewPositionY();
  42418. }
  42419. else
  42420. {
  42421. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42422. const int curH = roundToInt (cursorHeight);
  42423. if (desiredCaretY < 0)
  42424. {
  42425. vy = jmax (0, desiredCaretY + vy);
  42426. }
  42427. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42428. {
  42429. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42430. }
  42431. }
  42432. viewport->setViewPosition (vx, vy);
  42433. }
  42434. const Rectangle<int> TextEditor::getCaretRectangle()
  42435. {
  42436. updateCaretPosition();
  42437. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42438. roundToInt (cursorY) - viewport->getY(),
  42439. 1, roundToInt (cursorHeight));
  42440. }
  42441. float TextEditor::getWordWrapWidth() const
  42442. {
  42443. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42444. : 1.0e10f;
  42445. }
  42446. void TextEditor::updateTextHolderSize()
  42447. {
  42448. const float wordWrapWidth = getWordWrapWidth();
  42449. if (wordWrapWidth > 0)
  42450. {
  42451. float maxWidth = 0.0f;
  42452. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42453. while (i.next())
  42454. maxWidth = jmax (maxWidth, i.atomRight);
  42455. const int w = leftIndent + roundToInt (maxWidth);
  42456. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42457. currentFont.getHeight()));
  42458. textHolder->setSize (w + 1, h + 1);
  42459. }
  42460. }
  42461. int TextEditor::getTextWidth() const
  42462. {
  42463. return textHolder->getWidth();
  42464. }
  42465. int TextEditor::getTextHeight() const
  42466. {
  42467. return textHolder->getHeight();
  42468. }
  42469. void TextEditor::setIndents (const int newLeftIndent,
  42470. const int newTopIndent)
  42471. {
  42472. leftIndent = newLeftIndent;
  42473. topIndent = newTopIndent;
  42474. }
  42475. void TextEditor::setBorder (const BorderSize& border)
  42476. {
  42477. borderSize = border;
  42478. resized();
  42479. }
  42480. const BorderSize TextEditor::getBorder() const
  42481. {
  42482. return borderSize;
  42483. }
  42484. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42485. {
  42486. keepCursorOnScreen = shouldScrollToShowCursor;
  42487. }
  42488. void TextEditor::updateCaretPosition()
  42489. {
  42490. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42491. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42492. }
  42493. void TextEditor::scrollToMakeSureCursorIsVisible()
  42494. {
  42495. updateCaretPosition();
  42496. if (keepCursorOnScreen)
  42497. {
  42498. int x = viewport->getViewPositionX();
  42499. int y = viewport->getViewPositionY();
  42500. const int relativeCursorX = roundToInt (cursorX) - x;
  42501. const int relativeCursorY = roundToInt (cursorY) - y;
  42502. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42503. {
  42504. x += relativeCursorX - proportionOfWidth (0.2f);
  42505. }
  42506. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42507. {
  42508. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42509. }
  42510. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42511. if (! isMultiLine())
  42512. {
  42513. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42514. }
  42515. else
  42516. {
  42517. const int curH = roundToInt (cursorHeight);
  42518. if (relativeCursorY < 0)
  42519. {
  42520. y = jmax (0, relativeCursorY + y);
  42521. }
  42522. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42523. {
  42524. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42525. }
  42526. }
  42527. viewport->setViewPosition (x, y);
  42528. }
  42529. }
  42530. void TextEditor::moveCursorTo (const int newPosition,
  42531. const bool isSelecting)
  42532. {
  42533. if (isSelecting)
  42534. {
  42535. moveCaret (newPosition);
  42536. const Range<int> oldSelection (selection);
  42537. if (dragType == notDragging)
  42538. {
  42539. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42540. dragType = draggingSelectionStart;
  42541. else
  42542. dragType = draggingSelectionEnd;
  42543. }
  42544. if (dragType == draggingSelectionStart)
  42545. {
  42546. if (getCaretPosition() >= selection.getEnd())
  42547. dragType = draggingSelectionEnd;
  42548. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42549. }
  42550. else
  42551. {
  42552. if (getCaretPosition() < selection.getStart())
  42553. dragType = draggingSelectionStart;
  42554. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42555. }
  42556. repaintText (selection.getUnionWith (oldSelection));
  42557. }
  42558. else
  42559. {
  42560. dragType = notDragging;
  42561. repaintText (selection);
  42562. moveCaret (newPosition);
  42563. selection = Range<int>::emptyRange (getCaretPosition());
  42564. }
  42565. }
  42566. int TextEditor::getTextIndexAt (const int x,
  42567. const int y)
  42568. {
  42569. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42570. (float) (y + viewport->getViewPositionY() - topIndent));
  42571. }
  42572. void TextEditor::insertTextAtCaret (const String& newText_)
  42573. {
  42574. String newText (newText_);
  42575. if (allowedCharacters.isNotEmpty())
  42576. newText = newText.retainCharacters (allowedCharacters);
  42577. if (! isMultiLine())
  42578. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42579. else
  42580. newText = newText.replace (T("\r\n"), T("\n"));
  42581. const int newCaretPos = selection.getStart() + newText.length();
  42582. const int insertIndex = selection.getStart();
  42583. remove (selection, &undoManager,
  42584. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42585. if (maxTextLength > 0)
  42586. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42587. if (newText.isNotEmpty())
  42588. insert (newText,
  42589. insertIndex,
  42590. currentFont,
  42591. findColour (textColourId),
  42592. &undoManager,
  42593. newCaretPos);
  42594. textChanged();
  42595. }
  42596. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42597. {
  42598. moveCursorTo (newSelection.getStart(), false);
  42599. moveCursorTo (newSelection.getEnd(), true);
  42600. }
  42601. void TextEditor::copy()
  42602. {
  42603. if (passwordCharacter == 0)
  42604. {
  42605. const String selection (getHighlightedText());
  42606. if (selection.isNotEmpty())
  42607. SystemClipboard::copyTextToClipboard (selection);
  42608. }
  42609. }
  42610. void TextEditor::paste()
  42611. {
  42612. if (! isReadOnly())
  42613. {
  42614. const String clip (SystemClipboard::getTextFromClipboard());
  42615. if (clip.isNotEmpty())
  42616. insertTextAtCaret (clip);
  42617. }
  42618. }
  42619. void TextEditor::cut()
  42620. {
  42621. if (! isReadOnly())
  42622. {
  42623. moveCaret (selection.getEnd());
  42624. insertTextAtCaret (String::empty);
  42625. }
  42626. }
  42627. void TextEditor::drawContent (Graphics& g)
  42628. {
  42629. const float wordWrapWidth = getWordWrapWidth();
  42630. if (wordWrapWidth > 0)
  42631. {
  42632. g.setOrigin (leftIndent, topIndent);
  42633. const Rectangle<int> clip (g.getClipBounds());
  42634. Colour selectedTextColour;
  42635. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42636. while (i.lineY + 200.0 < clip.getY() && i.next())
  42637. {}
  42638. if (! selection.isEmpty())
  42639. {
  42640. g.setColour (findColour (highlightColourId)
  42641. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42642. selectedTextColour = findColour (highlightedTextColourId);
  42643. TextEditorIterator i2 (i);
  42644. while (i2.next() && i2.lineY < clip.getBottom())
  42645. {
  42646. if (i2.lineY + i2.lineHeight >= clip.getY()
  42647. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42648. {
  42649. i2.drawSelection (g, selection);
  42650. }
  42651. }
  42652. }
  42653. const UniformTextSection* lastSection = 0;
  42654. while (i.next() && i.lineY < clip.getBottom())
  42655. {
  42656. if (i.lineY + i.lineHeight >= clip.getY())
  42657. {
  42658. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42659. {
  42660. i.drawSelectedText (g, selection, selectedTextColour);
  42661. lastSection = 0;
  42662. }
  42663. else
  42664. {
  42665. i.draw (g, lastSection);
  42666. }
  42667. }
  42668. }
  42669. }
  42670. }
  42671. void TextEditor::paint (Graphics& g)
  42672. {
  42673. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42674. }
  42675. void TextEditor::paintOverChildren (Graphics& g)
  42676. {
  42677. if (caretFlashState
  42678. && hasKeyboardFocus (false)
  42679. && caretVisible
  42680. && ! isReadOnly())
  42681. {
  42682. g.setColour (findColour (caretColourId));
  42683. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42684. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42685. 2.0f, cursorHeight);
  42686. }
  42687. if (textToShowWhenEmpty.isNotEmpty()
  42688. && (! hasKeyboardFocus (false))
  42689. && getTotalNumChars() == 0)
  42690. {
  42691. g.setColour (colourForTextWhenEmpty);
  42692. g.setFont (getFont());
  42693. if (isMultiLine())
  42694. {
  42695. g.drawText (textToShowWhenEmpty,
  42696. 0, 0, getWidth(), getHeight(),
  42697. Justification::centred, true);
  42698. }
  42699. else
  42700. {
  42701. g.drawText (textToShowWhenEmpty,
  42702. leftIndent, topIndent,
  42703. viewport->getWidth() - leftIndent,
  42704. viewport->getHeight() - topIndent,
  42705. Justification::centredLeft, true);
  42706. }
  42707. }
  42708. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42709. }
  42710. void TextEditor::mouseDown (const MouseEvent& e)
  42711. {
  42712. beginDragAutoRepeat (100);
  42713. newTransaction();
  42714. if (wasFocused || ! selectAllTextWhenFocused)
  42715. {
  42716. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42717. {
  42718. moveCursorTo (getTextIndexAt (e.x, e.y),
  42719. e.mods.isShiftDown());
  42720. }
  42721. else
  42722. {
  42723. PopupMenu m;
  42724. m.setLookAndFeel (&getLookAndFeel());
  42725. addPopupMenuItems (m, &e);
  42726. menuActive = true;
  42727. const int result = m.show();
  42728. menuActive = false;
  42729. if (result != 0)
  42730. performPopupMenuAction (result);
  42731. }
  42732. }
  42733. }
  42734. void TextEditor::mouseDrag (const MouseEvent& e)
  42735. {
  42736. if (wasFocused || ! selectAllTextWhenFocused)
  42737. {
  42738. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42739. {
  42740. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42741. }
  42742. }
  42743. }
  42744. void TextEditor::mouseUp (const MouseEvent& e)
  42745. {
  42746. newTransaction();
  42747. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42748. if (wasFocused || ! selectAllTextWhenFocused)
  42749. {
  42750. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42751. {
  42752. moveCaret (getTextIndexAt (e.x, e.y));
  42753. }
  42754. }
  42755. wasFocused = true;
  42756. }
  42757. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42758. {
  42759. int tokenEnd = getTextIndexAt (e.x, e.y);
  42760. int tokenStart = tokenEnd;
  42761. if (e.getNumberOfClicks() > 3)
  42762. {
  42763. tokenStart = 0;
  42764. tokenEnd = getTotalNumChars();
  42765. }
  42766. else
  42767. {
  42768. const String t (getText());
  42769. const int totalLength = getTotalNumChars();
  42770. while (tokenEnd < totalLength)
  42771. {
  42772. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42773. ++tokenEnd;
  42774. else
  42775. break;
  42776. }
  42777. tokenStart = tokenEnd;
  42778. while (tokenStart > 0)
  42779. {
  42780. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42781. --tokenStart;
  42782. else
  42783. break;
  42784. }
  42785. if (e.getNumberOfClicks() > 2)
  42786. {
  42787. while (tokenEnd < totalLength)
  42788. {
  42789. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42790. ++tokenEnd;
  42791. else
  42792. break;
  42793. }
  42794. while (tokenStart > 0)
  42795. {
  42796. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42797. --tokenStart;
  42798. else
  42799. break;
  42800. }
  42801. }
  42802. }
  42803. moveCursorTo (tokenEnd, false);
  42804. moveCursorTo (tokenStart, true);
  42805. }
  42806. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42807. {
  42808. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42809. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42810. }
  42811. bool TextEditor::keyPressed (const KeyPress& key)
  42812. {
  42813. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42814. return false;
  42815. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42816. if (key.isKeyCode (KeyPress::leftKey)
  42817. || key.isKeyCode (KeyPress::upKey))
  42818. {
  42819. newTransaction();
  42820. int newPos;
  42821. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42822. newPos = indexAtPosition (cursorX, cursorY - 1);
  42823. else if (moveInWholeWordSteps)
  42824. newPos = findWordBreakBefore (getCaretPosition());
  42825. else
  42826. newPos = getCaretPosition() - 1;
  42827. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42828. }
  42829. else if (key.isKeyCode (KeyPress::rightKey)
  42830. || key.isKeyCode (KeyPress::downKey))
  42831. {
  42832. newTransaction();
  42833. int newPos;
  42834. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42835. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42836. else if (moveInWholeWordSteps)
  42837. newPos = findWordBreakAfter (getCaretPosition());
  42838. else
  42839. newPos = getCaretPosition() + 1;
  42840. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42841. }
  42842. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42843. {
  42844. newTransaction();
  42845. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42846. key.getModifiers().isShiftDown());
  42847. }
  42848. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42849. {
  42850. newTransaction();
  42851. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42852. key.getModifiers().isShiftDown());
  42853. }
  42854. else if (key.isKeyCode (KeyPress::homeKey))
  42855. {
  42856. newTransaction();
  42857. if (isMultiLine() && ! moveInWholeWordSteps)
  42858. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42859. key.getModifiers().isShiftDown());
  42860. else
  42861. moveCursorTo (0, key.getModifiers().isShiftDown());
  42862. }
  42863. else if (key.isKeyCode (KeyPress::endKey))
  42864. {
  42865. newTransaction();
  42866. if (isMultiLine() && ! moveInWholeWordSteps)
  42867. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42868. key.getModifiers().isShiftDown());
  42869. else
  42870. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42871. }
  42872. else if (key.isKeyCode (KeyPress::backspaceKey))
  42873. {
  42874. if (moveInWholeWordSteps)
  42875. {
  42876. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42877. }
  42878. else
  42879. {
  42880. if (selection.isEmpty() && selection.getStart() > 0)
  42881. selection.setStart (selection.getEnd() - 1);
  42882. }
  42883. cut();
  42884. }
  42885. else if (key.isKeyCode (KeyPress::deleteKey))
  42886. {
  42887. if (key.getModifiers().isShiftDown())
  42888. copy();
  42889. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42890. selection.setEnd (selection.getStart() + 1);
  42891. cut();
  42892. }
  42893. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  42894. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42895. {
  42896. newTransaction();
  42897. copy();
  42898. }
  42899. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  42900. {
  42901. newTransaction();
  42902. copy();
  42903. cut();
  42904. }
  42905. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  42906. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42907. {
  42908. newTransaction();
  42909. paste();
  42910. }
  42911. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  42912. {
  42913. newTransaction();
  42914. doUndoRedo (false);
  42915. }
  42916. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  42917. {
  42918. newTransaction();
  42919. doUndoRedo (true);
  42920. }
  42921. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  42922. {
  42923. newTransaction();
  42924. moveCursorTo (getTotalNumChars(), false);
  42925. moveCursorTo (0, true);
  42926. }
  42927. else if (key == KeyPress::returnKey)
  42928. {
  42929. newTransaction();
  42930. if (returnKeyStartsNewLine)
  42931. insertTextAtCaret (T("\n"));
  42932. else
  42933. returnPressed();
  42934. }
  42935. else if (key.isKeyCode (KeyPress::escapeKey))
  42936. {
  42937. newTransaction();
  42938. moveCursorTo (getCaretPosition(), false);
  42939. escapePressed();
  42940. }
  42941. else if (key.getTextCharacter() >= ' '
  42942. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42943. {
  42944. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42945. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42946. }
  42947. else
  42948. {
  42949. return false;
  42950. }
  42951. return true;
  42952. }
  42953. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42954. {
  42955. if (! isKeyDown)
  42956. return false;
  42957. #if JUCE_WIN32
  42958. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42959. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42960. #endif
  42961. // (overridden to avoid forwarding key events to the parent)
  42962. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42963. }
  42964. const int baseMenuItemID = 0x7fff0000;
  42965. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42966. {
  42967. const bool writable = ! isReadOnly();
  42968. if (passwordCharacter == 0)
  42969. {
  42970. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42971. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42972. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42973. }
  42974. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42975. m.addSeparator();
  42976. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42977. m.addSeparator();
  42978. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42979. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42980. }
  42981. void TextEditor::performPopupMenuAction (const int menuItemID)
  42982. {
  42983. switch (menuItemID)
  42984. {
  42985. case baseMenuItemID + 1:
  42986. copy();
  42987. cut();
  42988. break;
  42989. case baseMenuItemID + 2:
  42990. copy();
  42991. break;
  42992. case baseMenuItemID + 3:
  42993. paste();
  42994. break;
  42995. case baseMenuItemID + 4:
  42996. cut();
  42997. break;
  42998. case baseMenuItemID + 5:
  42999. moveCursorTo (getTotalNumChars(), false);
  43000. moveCursorTo (0, true);
  43001. break;
  43002. case baseMenuItemID + 6:
  43003. doUndoRedo (false);
  43004. break;
  43005. case baseMenuItemID + 7:
  43006. doUndoRedo (true);
  43007. break;
  43008. default:
  43009. break;
  43010. }
  43011. }
  43012. void TextEditor::focusGained (FocusChangeType)
  43013. {
  43014. newTransaction();
  43015. caretFlashState = true;
  43016. if (selectAllTextWhenFocused)
  43017. {
  43018. moveCursorTo (0, false);
  43019. moveCursorTo (getTotalNumChars(), true);
  43020. }
  43021. repaint();
  43022. if (caretVisible)
  43023. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  43024. ComponentPeer* const peer = getPeer();
  43025. if (peer != 0 && ! isReadOnly())
  43026. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  43027. }
  43028. void TextEditor::focusLost (FocusChangeType)
  43029. {
  43030. newTransaction();
  43031. wasFocused = false;
  43032. textHolder->stopTimer();
  43033. caretFlashState = false;
  43034. postCommandMessage (TextEditorDefs::focusLossMessageId);
  43035. repaint();
  43036. }
  43037. void TextEditor::resized()
  43038. {
  43039. viewport->setBoundsInset (borderSize);
  43040. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  43041. updateTextHolderSize();
  43042. if (! isMultiLine())
  43043. {
  43044. scrollToMakeSureCursorIsVisible();
  43045. }
  43046. else
  43047. {
  43048. updateCaretPosition();
  43049. }
  43050. }
  43051. void TextEditor::handleCommandMessage (const int commandId)
  43052. {
  43053. const ComponentDeletionWatcher deletionChecker (this);
  43054. for (int i = listeners.size(); --i >= 0;)
  43055. {
  43056. TextEditorListener* const tl = (TextEditorListener*) listeners [i];
  43057. if (tl != 0)
  43058. {
  43059. switch (commandId)
  43060. {
  43061. case TextEditorDefs::textChangeMessageId:
  43062. tl->textEditorTextChanged (*this);
  43063. break;
  43064. case TextEditorDefs::returnKeyMessageId:
  43065. tl->textEditorReturnKeyPressed (*this);
  43066. break;
  43067. case TextEditorDefs::escapeKeyMessageId:
  43068. tl->textEditorEscapeKeyPressed (*this);
  43069. break;
  43070. case TextEditorDefs::focusLossMessageId:
  43071. tl->textEditorFocusLost (*this);
  43072. break;
  43073. default:
  43074. jassertfalse
  43075. break;
  43076. }
  43077. if (i > 0 && deletionChecker.hasBeenDeleted())
  43078. return;
  43079. }
  43080. }
  43081. }
  43082. void TextEditor::enablementChanged()
  43083. {
  43084. setMouseCursor (MouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  43085. : MouseCursor::IBeamCursor));
  43086. repaint();
  43087. }
  43088. void TextEditor::clearInternal (UndoManager* const um)
  43089. {
  43090. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  43091. }
  43092. void TextEditor::insert (const String& text,
  43093. const int insertIndex,
  43094. const Font& font,
  43095. const Colour& colour,
  43096. UndoManager* const um,
  43097. const int caretPositionToMoveTo)
  43098. {
  43099. if (text.isNotEmpty())
  43100. {
  43101. if (um != 0)
  43102. {
  43103. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43104. newTransaction();
  43105. um->perform (new TextEditorInsertAction (*this,
  43106. text,
  43107. insertIndex,
  43108. font,
  43109. colour,
  43110. caretPosition,
  43111. caretPositionToMoveTo));
  43112. }
  43113. else
  43114. {
  43115. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  43116. // a line gets moved due to word wrap
  43117. int index = 0;
  43118. int nextIndex = 0;
  43119. for (int i = 0; i < sections.size(); ++i)
  43120. {
  43121. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43122. if (insertIndex == index)
  43123. {
  43124. sections.insert (i, new UniformTextSection (text,
  43125. font, colour,
  43126. passwordCharacter));
  43127. break;
  43128. }
  43129. else if (insertIndex > index && insertIndex < nextIndex)
  43130. {
  43131. splitSection (i, insertIndex - index);
  43132. sections.insert (i + 1, new UniformTextSection (text,
  43133. font, colour,
  43134. passwordCharacter));
  43135. break;
  43136. }
  43137. index = nextIndex;
  43138. }
  43139. if (nextIndex == insertIndex)
  43140. sections.add (new UniformTextSection (text,
  43141. font, colour,
  43142. passwordCharacter));
  43143. coalesceSimilarSections();
  43144. totalNumChars = -1;
  43145. valueTextNeedsUpdating = true;
  43146. moveCursorTo (caretPositionToMoveTo, false);
  43147. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  43148. }
  43149. }
  43150. }
  43151. void TextEditor::reinsert (const int insertIndex,
  43152. const VoidArray& sectionsToInsert)
  43153. {
  43154. int index = 0;
  43155. int nextIndex = 0;
  43156. for (int i = 0; i < sections.size(); ++i)
  43157. {
  43158. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43159. if (insertIndex == index)
  43160. {
  43161. for (int j = sectionsToInsert.size(); --j >= 0;)
  43162. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43163. break;
  43164. }
  43165. else if (insertIndex > index && insertIndex < nextIndex)
  43166. {
  43167. splitSection (i, insertIndex - index);
  43168. for (int j = sectionsToInsert.size(); --j >= 0;)
  43169. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43170. break;
  43171. }
  43172. index = nextIndex;
  43173. }
  43174. if (nextIndex == insertIndex)
  43175. {
  43176. for (int j = 0; j < sectionsToInsert.size(); ++j)
  43177. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43178. }
  43179. coalesceSimilarSections();
  43180. totalNumChars = -1;
  43181. valueTextNeedsUpdating = true;
  43182. }
  43183. void TextEditor::remove (const Range<int>& range,
  43184. UndoManager* const um,
  43185. const int caretPositionToMoveTo)
  43186. {
  43187. if (! range.isEmpty())
  43188. {
  43189. int index = 0;
  43190. for (int i = 0; i < sections.size(); ++i)
  43191. {
  43192. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  43193. if (range.getStart() > index && range.getStart() < nextIndex)
  43194. {
  43195. splitSection (i, range.getStart() - index);
  43196. --i;
  43197. }
  43198. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  43199. {
  43200. splitSection (i, range.getEnd() - index);
  43201. --i;
  43202. }
  43203. else
  43204. {
  43205. index = nextIndex;
  43206. if (index > range.getEnd())
  43207. break;
  43208. }
  43209. }
  43210. index = 0;
  43211. if (um != 0)
  43212. {
  43213. VoidArray removedSections;
  43214. for (int i = 0; i < sections.size(); ++i)
  43215. {
  43216. if (range.getEnd() <= range.getStart())
  43217. break;
  43218. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43219. const int nextIndex = index + section->getTotalLength();
  43220. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  43221. removedSections.add (new UniformTextSection (*section));
  43222. index = nextIndex;
  43223. }
  43224. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43225. newTransaction();
  43226. um->perform (new TextEditorRemoveAction (*this,
  43227. range,
  43228. caretPosition,
  43229. caretPositionToMoveTo,
  43230. removedSections));
  43231. }
  43232. else
  43233. {
  43234. Range<int> remainingRange (range);
  43235. for (int i = 0; i < sections.size(); ++i)
  43236. {
  43237. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43238. const int nextIndex = index + section->getTotalLength();
  43239. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  43240. {
  43241. sections.remove(i);
  43242. section->clear();
  43243. delete section;
  43244. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  43245. if (remainingRange.isEmpty())
  43246. break;
  43247. --i;
  43248. }
  43249. else
  43250. {
  43251. index = nextIndex;
  43252. }
  43253. }
  43254. coalesceSimilarSections();
  43255. totalNumChars = -1;
  43256. valueTextNeedsUpdating = true;
  43257. moveCursorTo (caretPositionToMoveTo, false);
  43258. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  43259. }
  43260. }
  43261. }
  43262. const String TextEditor::getText() const
  43263. {
  43264. String t;
  43265. t.preallocateStorage (getTotalNumChars());
  43266. String::Concatenator concatenator (t);
  43267. for (int i = 0; i < sections.size(); ++i)
  43268. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  43269. return t;
  43270. }
  43271. const String TextEditor::getTextInRange (const Range<int>& range) const
  43272. {
  43273. String t;
  43274. if (! range.isEmpty())
  43275. {
  43276. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  43277. String::Concatenator concatenator (t);
  43278. int index = 0;
  43279. for (int i = 0; i < sections.size(); ++i)
  43280. {
  43281. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  43282. const int nextIndex = index + s->getTotalLength();
  43283. if (range.getStart() < nextIndex)
  43284. {
  43285. if (range.getEnd() <= index)
  43286. break;
  43287. s->appendSubstring (concatenator, range - index);
  43288. }
  43289. index = nextIndex;
  43290. }
  43291. }
  43292. return t;
  43293. }
  43294. const String TextEditor::getHighlightedText() const
  43295. {
  43296. return getTextInRange (selection);
  43297. }
  43298. int TextEditor::getTotalNumChars() const
  43299. {
  43300. if (totalNumChars < 0)
  43301. {
  43302. totalNumChars = 0;
  43303. for (int i = sections.size(); --i >= 0;)
  43304. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43305. }
  43306. return totalNumChars;
  43307. }
  43308. bool TextEditor::isEmpty() const
  43309. {
  43310. return getTotalNumChars() == 0;
  43311. }
  43312. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  43313. {
  43314. const float wordWrapWidth = getWordWrapWidth();
  43315. if (wordWrapWidth > 0 && sections.size() > 0)
  43316. {
  43317. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43318. i.getCharPosition (index, cx, cy, lineHeight);
  43319. }
  43320. else
  43321. {
  43322. cx = cy = 0;
  43323. lineHeight = currentFont.getHeight();
  43324. }
  43325. }
  43326. int TextEditor::indexAtPosition (const float x, const float y)
  43327. {
  43328. const float wordWrapWidth = getWordWrapWidth();
  43329. if (wordWrapWidth > 0)
  43330. {
  43331. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43332. while (i.next())
  43333. {
  43334. if (i.lineY + i.lineHeight > y)
  43335. {
  43336. if (i.lineY > y)
  43337. return jmax (0, i.indexInText - 1);
  43338. if (i.atomX >= x)
  43339. return i.indexInText;
  43340. if (x < i.atomRight)
  43341. return i.xToIndex (x);
  43342. }
  43343. }
  43344. }
  43345. return getTotalNumChars();
  43346. }
  43347. static int getCharacterCategory (const tchar character)
  43348. {
  43349. return CharacterFunctions::isLetterOrDigit (character)
  43350. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43351. }
  43352. int TextEditor::findWordBreakAfter (const int position) const
  43353. {
  43354. const String t (getTextInRange (Range<int> (position, position + 512)));
  43355. const int totalLength = t.length();
  43356. int i = 0;
  43357. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43358. ++i;
  43359. const int type = getCharacterCategory (t[i]);
  43360. while (i < totalLength && type == getCharacterCategory (t[i]))
  43361. ++i;
  43362. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43363. ++i;
  43364. return position + i;
  43365. }
  43366. int TextEditor::findWordBreakBefore (const int position) const
  43367. {
  43368. if (position <= 0)
  43369. return 0;
  43370. const int startOfBuffer = jmax (0, position - 512);
  43371. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  43372. int i = position - startOfBuffer;
  43373. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43374. --i;
  43375. if (i > 0)
  43376. {
  43377. const int type = getCharacterCategory (t [i - 1]);
  43378. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43379. --i;
  43380. }
  43381. jassert (startOfBuffer + i >= 0);
  43382. return startOfBuffer + i;
  43383. }
  43384. void TextEditor::splitSection (const int sectionIndex,
  43385. const int charToSplitAt)
  43386. {
  43387. jassert (sections[sectionIndex] != 0);
  43388. sections.insert (sectionIndex + 1,
  43389. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43390. ->split (charToSplitAt, passwordCharacter));
  43391. }
  43392. void TextEditor::coalesceSimilarSections()
  43393. {
  43394. for (int i = 0; i < sections.size() - 1; ++i)
  43395. {
  43396. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43397. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43398. if (s1->font == s2->font
  43399. && s1->colour == s2->colour)
  43400. {
  43401. s1->append (*s2, passwordCharacter);
  43402. sections.remove (i + 1);
  43403. delete s2;
  43404. --i;
  43405. }
  43406. }
  43407. }
  43408. END_JUCE_NAMESPACE
  43409. /*** End of inlined file: juce_TextEditor.cpp ***/
  43410. /*** Start of inlined file: juce_Toolbar.cpp ***/
  43411. BEGIN_JUCE_NAMESPACE
  43412. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43413. class ToolbarSpacerComp : public ToolbarItemComponent
  43414. {
  43415. public:
  43416. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43417. : ToolbarItemComponent (itemId_, String::empty, false),
  43418. fixedSize (fixedSize_),
  43419. drawBar (drawBar_)
  43420. {
  43421. }
  43422. ~ToolbarSpacerComp()
  43423. {
  43424. }
  43425. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43426. int& preferredSize, int& minSize, int& maxSize)
  43427. {
  43428. if (fixedSize <= 0)
  43429. {
  43430. preferredSize = toolbarThickness * 2;
  43431. minSize = 4;
  43432. maxSize = 32768;
  43433. }
  43434. else
  43435. {
  43436. maxSize = roundToInt (toolbarThickness * fixedSize);
  43437. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43438. preferredSize = maxSize;
  43439. if (getEditingMode() == editableOnPalette)
  43440. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43441. }
  43442. return true;
  43443. }
  43444. void paintButtonArea (Graphics&, int, int, bool, bool)
  43445. {
  43446. }
  43447. void contentAreaChanged (const Rectangle<int>&)
  43448. {
  43449. }
  43450. int getResizeOrder() const throw()
  43451. {
  43452. return fixedSize <= 0 ? 0 : 1;
  43453. }
  43454. void paint (Graphics& g)
  43455. {
  43456. const int w = getWidth();
  43457. const int h = getHeight();
  43458. if (drawBar)
  43459. {
  43460. g.setColour (findColour (Toolbar::separatorColourId, true));
  43461. const float thickness = 0.2f;
  43462. if (isToolbarVertical())
  43463. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43464. else
  43465. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43466. }
  43467. if (getEditingMode() != normalMode && ! drawBar)
  43468. {
  43469. g.setColour (findColour (Toolbar::separatorColourId, true));
  43470. const int indentX = jmin (2, (w - 3) / 2);
  43471. const int indentY = jmin (2, (h - 3) / 2);
  43472. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43473. if (fixedSize <= 0)
  43474. {
  43475. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43476. if (isToolbarVertical())
  43477. {
  43478. x1 = w * 0.5f;
  43479. y1 = h * 0.4f;
  43480. x2 = x1;
  43481. y2 = indentX * 2.0f;
  43482. x3 = x1;
  43483. y3 = h * 0.6f;
  43484. x4 = x1;
  43485. y4 = h - y2;
  43486. hw = w * 0.15f;
  43487. hl = w * 0.2f;
  43488. }
  43489. else
  43490. {
  43491. x1 = w * 0.4f;
  43492. y1 = h * 0.5f;
  43493. x2 = indentX * 2.0f;
  43494. y2 = y1;
  43495. x3 = w * 0.6f;
  43496. y3 = y1;
  43497. x4 = w - x2;
  43498. y4 = y1;
  43499. hw = h * 0.15f;
  43500. hl = h * 0.2f;
  43501. }
  43502. Path p;
  43503. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43504. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43505. g.fillPath (p);
  43506. }
  43507. }
  43508. }
  43509. juce_UseDebuggingNewOperator
  43510. private:
  43511. const float fixedSize;
  43512. const bool drawBar;
  43513. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43514. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43515. };
  43516. class MissingItemsComponent : public PopupMenuCustomComponent
  43517. {
  43518. public:
  43519. MissingItemsComponent (Toolbar& owner_, const int height_)
  43520. : PopupMenuCustomComponent (true),
  43521. owner (owner_),
  43522. height (height_)
  43523. {
  43524. for (int i = owner_.items.size(); --i >= 0;)
  43525. {
  43526. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43527. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43528. {
  43529. oldIndexes.insert (0, i);
  43530. addAndMakeVisible (tc, 0);
  43531. }
  43532. }
  43533. layout (400);
  43534. }
  43535. ~MissingItemsComponent()
  43536. {
  43537. // deleting the toolbar while its menu it open??
  43538. jassert (owner.isValidComponent());
  43539. for (int i = 0; i < getNumChildComponents(); ++i)
  43540. {
  43541. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43542. if (tc != 0)
  43543. {
  43544. tc->setVisible (false);
  43545. const int index = oldIndexes.remove (i);
  43546. owner.addChildComponent (tc, index);
  43547. --i;
  43548. }
  43549. }
  43550. owner.resized();
  43551. }
  43552. void layout (const int preferredWidth)
  43553. {
  43554. const int indent = 8;
  43555. int x = indent;
  43556. int y = indent;
  43557. int maxX = 0;
  43558. for (int i = 0; i < getNumChildComponents(); ++i)
  43559. {
  43560. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43561. if (tc != 0)
  43562. {
  43563. int preferredSize = 1, minSize = 1, maxSize = 1;
  43564. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43565. {
  43566. if (x + preferredSize > preferredWidth && x > indent)
  43567. {
  43568. x = indent;
  43569. y += height;
  43570. }
  43571. tc->setBounds (x, y, preferredSize, height);
  43572. x += preferredSize;
  43573. maxX = jmax (maxX, x);
  43574. }
  43575. }
  43576. }
  43577. setSize (maxX + 8, y + height + 8);
  43578. }
  43579. void getIdealSize (int& idealWidth, int& idealHeight)
  43580. {
  43581. idealWidth = getWidth();
  43582. idealHeight = getHeight();
  43583. }
  43584. juce_UseDebuggingNewOperator
  43585. private:
  43586. Toolbar& owner;
  43587. const int height;
  43588. Array <int> oldIndexes;
  43589. MissingItemsComponent (const MissingItemsComponent&);
  43590. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43591. };
  43592. Toolbar::Toolbar()
  43593. : vertical (false),
  43594. isEditingActive (false),
  43595. toolbarStyle (Toolbar::iconsOnly)
  43596. {
  43597. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43598. missingItemsButton->setAlwaysOnTop (true);
  43599. missingItemsButton->addButtonListener (this);
  43600. }
  43601. Toolbar::~Toolbar()
  43602. {
  43603. animator.cancelAllAnimations (true);
  43604. deleteAllChildren();
  43605. }
  43606. void Toolbar::setVertical (const bool shouldBeVertical)
  43607. {
  43608. if (vertical != shouldBeVertical)
  43609. {
  43610. vertical = shouldBeVertical;
  43611. resized();
  43612. }
  43613. }
  43614. void Toolbar::clear()
  43615. {
  43616. for (int i = items.size(); --i >= 0;)
  43617. {
  43618. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43619. items.remove (i);
  43620. delete tc;
  43621. }
  43622. resized();
  43623. }
  43624. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43625. {
  43626. if (itemId == ToolbarItemFactory::separatorBarId)
  43627. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43628. else if (itemId == ToolbarItemFactory::spacerId)
  43629. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43630. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43631. return new ToolbarSpacerComp (itemId, 0, false);
  43632. return factory.createItem (itemId);
  43633. }
  43634. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43635. const int itemId,
  43636. const int insertIndex)
  43637. {
  43638. // An ID can't be zero - this might indicate a mistake somewhere?
  43639. jassert (itemId != 0);
  43640. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43641. if (tc != 0)
  43642. {
  43643. #ifdef JUCE_DEBUG
  43644. Array <int> allowedIds;
  43645. factory.getAllToolbarItemIds (allowedIds);
  43646. // If your factory can create an item for a given ID, it must also return
  43647. // that ID from its getAllToolbarItemIds() method!
  43648. jassert (allowedIds.contains (itemId));
  43649. #endif
  43650. items.insert (insertIndex, tc);
  43651. addAndMakeVisible (tc, insertIndex);
  43652. }
  43653. }
  43654. void Toolbar::addItem (ToolbarItemFactory& factory,
  43655. const int itemId,
  43656. const int insertIndex)
  43657. {
  43658. addItemInternal (factory, itemId, insertIndex);
  43659. resized();
  43660. }
  43661. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43662. {
  43663. Array <int> ids;
  43664. factoryToUse.getDefaultItemSet (ids);
  43665. clear();
  43666. for (int i = 0; i < ids.size(); ++i)
  43667. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43668. resized();
  43669. }
  43670. void Toolbar::removeToolbarItem (const int itemIndex)
  43671. {
  43672. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43673. if (tc != 0)
  43674. {
  43675. items.removeValue (tc);
  43676. delete tc;
  43677. resized();
  43678. }
  43679. }
  43680. int Toolbar::getNumItems() const throw()
  43681. {
  43682. return items.size();
  43683. }
  43684. int Toolbar::getItemId (const int itemIndex) const throw()
  43685. {
  43686. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43687. return tc != 0 ? tc->getItemId() : 0;
  43688. }
  43689. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43690. {
  43691. return items [itemIndex];
  43692. }
  43693. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43694. {
  43695. for (;;)
  43696. {
  43697. index += delta;
  43698. ToolbarItemComponent* const tc = getItemComponent (index);
  43699. if (tc == 0)
  43700. break;
  43701. if (tc->isActive)
  43702. return tc;
  43703. }
  43704. return 0;
  43705. }
  43706. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43707. {
  43708. if (toolbarStyle != newStyle)
  43709. {
  43710. toolbarStyle = newStyle;
  43711. updateAllItemPositions (false);
  43712. }
  43713. }
  43714. const String Toolbar::toString() const
  43715. {
  43716. String s (T("TB:"));
  43717. for (int i = 0; i < getNumItems(); ++i)
  43718. s << getItemId(i) << T(' ');
  43719. return s.trimEnd();
  43720. }
  43721. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43722. const String& savedVersion)
  43723. {
  43724. if (! savedVersion.startsWith (T("TB:")))
  43725. return false;
  43726. StringArray tokens;
  43727. tokens.addTokens (savedVersion.substring (3), false);
  43728. clear();
  43729. for (int i = 0; i < tokens.size(); ++i)
  43730. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43731. resized();
  43732. return true;
  43733. }
  43734. void Toolbar::paint (Graphics& g)
  43735. {
  43736. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43737. }
  43738. int Toolbar::getThickness() const throw()
  43739. {
  43740. return vertical ? getWidth() : getHeight();
  43741. }
  43742. int Toolbar::getLength() const throw()
  43743. {
  43744. return vertical ? getHeight() : getWidth();
  43745. }
  43746. void Toolbar::setEditingActive (const bool active)
  43747. {
  43748. if (isEditingActive != active)
  43749. {
  43750. isEditingActive = active;
  43751. updateAllItemPositions (false);
  43752. }
  43753. }
  43754. void Toolbar::resized()
  43755. {
  43756. updateAllItemPositions (false);
  43757. }
  43758. void Toolbar::updateAllItemPositions (const bool animate)
  43759. {
  43760. if (getWidth() > 0 && getHeight() > 0)
  43761. {
  43762. StretchableObjectResizer resizer;
  43763. int i;
  43764. for (i = 0; i < items.size(); ++i)
  43765. {
  43766. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43767. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43768. : ToolbarItemComponent::normalMode);
  43769. tc->setStyle (toolbarStyle);
  43770. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43771. int preferredSize = 1, minSize = 1, maxSize = 1;
  43772. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43773. preferredSize, minSize, maxSize))
  43774. {
  43775. tc->isActive = true;
  43776. resizer.addItem (preferredSize, minSize, maxSize,
  43777. spacer != 0 ? spacer->getResizeOrder() : 2);
  43778. }
  43779. else
  43780. {
  43781. tc->isActive = false;
  43782. tc->setVisible (false);
  43783. }
  43784. }
  43785. resizer.resizeToFit (getLength());
  43786. int totalLength = 0;
  43787. for (i = 0; i < resizer.getNumItems(); ++i)
  43788. totalLength += (int) resizer.getItemSize (i);
  43789. const bool itemsOffTheEnd = totalLength > getLength();
  43790. const int extrasButtonSize = getThickness() / 2;
  43791. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43792. missingItemsButton->setVisible (itemsOffTheEnd);
  43793. missingItemsButton->setEnabled (! isEditingActive);
  43794. if (vertical)
  43795. missingItemsButton->setCentrePosition (getWidth() / 2,
  43796. getHeight() - 4 - extrasButtonSize / 2);
  43797. else
  43798. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43799. getHeight() / 2);
  43800. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43801. : missingItemsButton->getX()) - 4
  43802. : getLength();
  43803. int pos = 0, activeIndex = 0;
  43804. for (i = 0; i < items.size(); ++i)
  43805. {
  43806. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43807. if (tc->isActive)
  43808. {
  43809. const int size = (int) resizer.getItemSize (activeIndex++);
  43810. Rectangle<int> newBounds;
  43811. if (vertical)
  43812. newBounds.setBounds (0, pos, getWidth(), size);
  43813. else
  43814. newBounds.setBounds (pos, 0, size, getHeight());
  43815. if (animate)
  43816. {
  43817. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43818. }
  43819. else
  43820. {
  43821. animator.cancelAnimation (tc, false);
  43822. tc->setBounds (newBounds);
  43823. }
  43824. pos += size;
  43825. tc->setVisible (pos <= maxLength
  43826. && ((! tc->isBeingDragged)
  43827. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43828. }
  43829. }
  43830. }
  43831. }
  43832. void Toolbar::buttonClicked (Button*)
  43833. {
  43834. jassert (missingItemsButton->isShowing());
  43835. if (missingItemsButton->isShowing())
  43836. {
  43837. PopupMenu m;
  43838. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43839. m.showAt (missingItemsButton);
  43840. }
  43841. }
  43842. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43843. Component* /*sourceComponent*/)
  43844. {
  43845. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43846. }
  43847. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43848. {
  43849. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43850. if (tc != 0)
  43851. {
  43852. if (getNumItems() == 0)
  43853. {
  43854. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43855. {
  43856. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43857. if (palette != 0)
  43858. palette->replaceComponent (tc);
  43859. }
  43860. else
  43861. {
  43862. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43863. }
  43864. items.add (tc);
  43865. addChildComponent (tc);
  43866. updateAllItemPositions (false);
  43867. }
  43868. else
  43869. {
  43870. for (int i = getNumItems(); --i >= 0;)
  43871. {
  43872. int currentIndex = getIndexOfChildComponent (tc);
  43873. if (currentIndex < 0)
  43874. {
  43875. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43876. {
  43877. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43878. if (palette != 0)
  43879. palette->replaceComponent (tc);
  43880. }
  43881. else
  43882. {
  43883. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43884. }
  43885. items.add (tc);
  43886. addChildComponent (tc);
  43887. currentIndex = getIndexOfChildComponent (tc);
  43888. updateAllItemPositions (true);
  43889. }
  43890. int newIndex = currentIndex;
  43891. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43892. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43893. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43894. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43895. if (prev != 0)
  43896. {
  43897. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43898. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43899. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43900. {
  43901. newIndex = getIndexOfChildComponent (prev);
  43902. }
  43903. }
  43904. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43905. if (next != 0)
  43906. {
  43907. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43908. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43909. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43910. {
  43911. newIndex = getIndexOfChildComponent (next) + 1;
  43912. }
  43913. }
  43914. if (newIndex != currentIndex)
  43915. {
  43916. items.removeValue (tc);
  43917. removeChildComponent (tc);
  43918. addChildComponent (tc, newIndex);
  43919. items.insert (newIndex, tc);
  43920. updateAllItemPositions (true);
  43921. }
  43922. else
  43923. {
  43924. break;
  43925. }
  43926. }
  43927. }
  43928. }
  43929. }
  43930. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43931. {
  43932. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43933. if (tc != 0)
  43934. {
  43935. if (isParentOf (tc))
  43936. {
  43937. items.removeValue (tc);
  43938. removeChildComponent (tc);
  43939. updateAllItemPositions (true);
  43940. }
  43941. }
  43942. }
  43943. void Toolbar::itemDropped (const String&, Component*, int, int)
  43944. {
  43945. }
  43946. void Toolbar::mouseDown (const MouseEvent& e)
  43947. {
  43948. if (e.mods.isPopupMenu())
  43949. {
  43950. }
  43951. }
  43952. class ToolbarCustomisationDialog : public DialogWindow
  43953. {
  43954. public:
  43955. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43956. Toolbar* const toolbar_,
  43957. const int optionFlags)
  43958. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43959. toolbar (toolbar_)
  43960. {
  43961. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43962. setResizable (true, true);
  43963. setResizeLimits (400, 300, 1500, 1000);
  43964. positionNearBar();
  43965. }
  43966. ~ToolbarCustomisationDialog()
  43967. {
  43968. setContentComponent (0, true);
  43969. }
  43970. void closeButtonPressed()
  43971. {
  43972. setVisible (false);
  43973. }
  43974. bool canModalEventBeSentToComponent (const Component* comp)
  43975. {
  43976. return toolbar->isParentOf (comp);
  43977. }
  43978. void positionNearBar()
  43979. {
  43980. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43981. const int tbx = toolbar->getScreenX();
  43982. const int tby = toolbar->getScreenY();
  43983. const int gap = 8;
  43984. int x, y;
  43985. if (toolbar->isVertical())
  43986. {
  43987. y = tby;
  43988. if (tbx > screenSize.getCentreX())
  43989. x = tbx - getWidth() - gap;
  43990. else
  43991. x = tbx + toolbar->getWidth() + gap;
  43992. }
  43993. else
  43994. {
  43995. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43996. if (tby > screenSize.getCentreY())
  43997. y = tby - getHeight() - gap;
  43998. else
  43999. y = tby + toolbar->getHeight() + gap;
  44000. }
  44001. setTopLeftPosition (x, y);
  44002. }
  44003. private:
  44004. Toolbar* const toolbar;
  44005. class CustomiserPanel : public Component,
  44006. private ComboBoxListener,
  44007. private ButtonListener
  44008. {
  44009. public:
  44010. CustomiserPanel (ToolbarItemFactory& factory_,
  44011. Toolbar* const toolbar_,
  44012. const int optionFlags)
  44013. : factory (factory_),
  44014. toolbar (toolbar_),
  44015. styleBox (0),
  44016. defaultButton (0)
  44017. {
  44018. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  44019. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  44020. | Toolbar::allowIconsWithTextChoice
  44021. | Toolbar::allowTextOnlyChoice)) != 0)
  44022. {
  44023. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  44024. styleBox->setEditableText (false);
  44025. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  44026. styleBox->addItem (TRANS("Show icons only"), 1);
  44027. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  44028. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  44029. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  44030. styleBox->addItem (TRANS("Show descriptions only"), 3);
  44031. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  44032. styleBox->setSelectedId (1);
  44033. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  44034. styleBox->setSelectedId (2);
  44035. else if (toolbar_->getStyle() == Toolbar::textOnly)
  44036. styleBox->setSelectedId (3);
  44037. styleBox->addListener (this);
  44038. }
  44039. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  44040. {
  44041. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  44042. defaultButton->addButtonListener (this);
  44043. }
  44044. addAndMakeVisible (instructions = new Label (String::empty,
  44045. 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.")));
  44046. instructions->setFont (Font (13.0f));
  44047. setSize (500, 300);
  44048. }
  44049. ~CustomiserPanel()
  44050. {
  44051. deleteAllChildren();
  44052. }
  44053. void comboBoxChanged (ComboBox*)
  44054. {
  44055. if (styleBox->getSelectedId() == 1)
  44056. toolbar->setStyle (Toolbar::iconsOnly);
  44057. else if (styleBox->getSelectedId() == 2)
  44058. toolbar->setStyle (Toolbar::iconsWithText);
  44059. else if (styleBox->getSelectedId() == 3)
  44060. toolbar->setStyle (Toolbar::textOnly);
  44061. palette->resized(); // to make it update the styles
  44062. }
  44063. void buttonClicked (Button*)
  44064. {
  44065. toolbar->addDefaultItems (factory);
  44066. }
  44067. void paint (Graphics& g)
  44068. {
  44069. Colour background;
  44070. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  44071. if (dw != 0)
  44072. background = dw->getBackgroundColour();
  44073. g.setColour (background.contrasting().withAlpha (0.3f));
  44074. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  44075. }
  44076. void resized()
  44077. {
  44078. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  44079. if (styleBox != 0)
  44080. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  44081. if (defaultButton != 0)
  44082. {
  44083. defaultButton->changeWidthToFitText (22);
  44084. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  44085. }
  44086. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  44087. }
  44088. private:
  44089. ToolbarItemFactory& factory;
  44090. Toolbar* const toolbar;
  44091. Label* instructions;
  44092. ToolbarItemPalette* palette;
  44093. ComboBox* styleBox;
  44094. TextButton* defaultButton;
  44095. };
  44096. };
  44097. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  44098. {
  44099. setEditingActive (true);
  44100. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  44101. dw.runModalLoop();
  44102. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  44103. setEditingActive (false);
  44104. }
  44105. END_JUCE_NAMESPACE
  44106. /*** End of inlined file: juce_Toolbar.cpp ***/
  44107. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  44108. BEGIN_JUCE_NAMESPACE
  44109. ToolbarItemFactory::ToolbarItemFactory()
  44110. {
  44111. }
  44112. ToolbarItemFactory::~ToolbarItemFactory()
  44113. {
  44114. }
  44115. class ItemDragAndDropOverlayComponent : public Component
  44116. {
  44117. public:
  44118. ItemDragAndDropOverlayComponent()
  44119. : isDragging (false)
  44120. {
  44121. setAlwaysOnTop (true);
  44122. setRepaintsOnMouseActivity (true);
  44123. setMouseCursor (MouseCursor::DraggingHandCursor);
  44124. }
  44125. ~ItemDragAndDropOverlayComponent()
  44126. {
  44127. }
  44128. void paint (Graphics& g)
  44129. {
  44130. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44131. if (isMouseOverOrDragging()
  44132. && tc != 0
  44133. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44134. {
  44135. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  44136. g.drawRect (0, 0, getWidth(), getHeight(),
  44137. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  44138. }
  44139. }
  44140. void mouseDown (const MouseEvent& e)
  44141. {
  44142. isDragging = false;
  44143. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44144. if (tc != 0)
  44145. {
  44146. tc->dragOffsetX = e.x;
  44147. tc->dragOffsetY = e.y;
  44148. }
  44149. }
  44150. void mouseDrag (const MouseEvent& e)
  44151. {
  44152. if (! (isDragging || e.mouseWasClicked()))
  44153. {
  44154. isDragging = true;
  44155. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  44156. if (dnd != 0)
  44157. {
  44158. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  44159. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44160. if (tc != 0)
  44161. {
  44162. tc->isBeingDragged = true;
  44163. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44164. tc->setVisible (false);
  44165. }
  44166. }
  44167. }
  44168. }
  44169. void mouseUp (const MouseEvent&)
  44170. {
  44171. isDragging = false;
  44172. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44173. if (tc != 0)
  44174. {
  44175. tc->isBeingDragged = false;
  44176. Toolbar* const tb = tc->getToolbar();
  44177. if (tb != 0)
  44178. tb->updateAllItemPositions (true);
  44179. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44180. delete tc;
  44181. }
  44182. }
  44183. void parentSizeChanged()
  44184. {
  44185. setBounds (0, 0, getParentWidth(), getParentHeight());
  44186. }
  44187. juce_UseDebuggingNewOperator
  44188. private:
  44189. bool isDragging;
  44190. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  44191. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  44192. };
  44193. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  44194. const String& labelText,
  44195. const bool isBeingUsedAsAButton_)
  44196. : Button (labelText),
  44197. itemId (itemId_),
  44198. mode (normalMode),
  44199. toolbarStyle (Toolbar::iconsOnly),
  44200. dragOffsetX (0),
  44201. dragOffsetY (0),
  44202. isActive (true),
  44203. isBeingDragged (false),
  44204. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  44205. {
  44206. // Your item ID can't be 0!
  44207. jassert (itemId_ != 0);
  44208. }
  44209. ToolbarItemComponent::~ToolbarItemComponent()
  44210. {
  44211. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44212. overlayComp = 0;
  44213. }
  44214. Toolbar* ToolbarItemComponent::getToolbar() const
  44215. {
  44216. return dynamic_cast <Toolbar*> (getParentComponent());
  44217. }
  44218. bool ToolbarItemComponent::isToolbarVertical() const
  44219. {
  44220. const Toolbar* const t = getToolbar();
  44221. return t != 0 && t->isVertical();
  44222. }
  44223. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  44224. {
  44225. if (toolbarStyle != newStyle)
  44226. {
  44227. toolbarStyle = newStyle;
  44228. repaint();
  44229. resized();
  44230. }
  44231. }
  44232. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  44233. {
  44234. if (isBeingUsedAsAButton)
  44235. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  44236. isMouseOver, isMouseDown, *this);
  44237. if (toolbarStyle != Toolbar::iconsOnly)
  44238. {
  44239. const int indent = contentArea.getX();
  44240. int y = indent;
  44241. int h = getHeight() - indent * 2;
  44242. if (toolbarStyle == Toolbar::iconsWithText)
  44243. {
  44244. y = contentArea.getBottom() + indent / 2;
  44245. h -= contentArea.getHeight();
  44246. }
  44247. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  44248. getButtonText(), *this);
  44249. }
  44250. if (! contentArea.isEmpty())
  44251. {
  44252. g.saveState();
  44253. g.setOrigin (contentArea.getX(), contentArea.getY());
  44254. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  44255. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  44256. g.restoreState();
  44257. }
  44258. }
  44259. void ToolbarItemComponent::resized()
  44260. {
  44261. if (toolbarStyle != Toolbar::textOnly)
  44262. {
  44263. const int indent = jmin (proportionOfWidth (0.08f),
  44264. proportionOfHeight (0.08f));
  44265. contentArea = Rectangle<int> (indent, indent,
  44266. getWidth() - indent * 2,
  44267. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  44268. : (getHeight() - indent * 2));
  44269. }
  44270. else
  44271. {
  44272. contentArea = Rectangle<int>();
  44273. }
  44274. contentAreaChanged (contentArea);
  44275. }
  44276. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  44277. {
  44278. if (mode != newMode)
  44279. {
  44280. mode = newMode;
  44281. repaint();
  44282. if (mode == normalMode)
  44283. {
  44284. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44285. overlayComp = 0;
  44286. }
  44287. else if (overlayComp == 0)
  44288. {
  44289. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  44290. overlayComp->parentSizeChanged();
  44291. }
  44292. resized();
  44293. }
  44294. }
  44295. END_JUCE_NAMESPACE
  44296. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  44297. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  44298. BEGIN_JUCE_NAMESPACE
  44299. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  44300. Toolbar* const toolbar_)
  44301. : factory (factory_),
  44302. toolbar (toolbar_)
  44303. {
  44304. Component* const itemHolder = new Component();
  44305. Array <int> allIds;
  44306. factory_.getAllToolbarItemIds (allIds);
  44307. for (int i = 0; i < allIds.size(); ++i)
  44308. {
  44309. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  44310. jassert (tc != 0);
  44311. if (tc != 0)
  44312. {
  44313. itemHolder->addAndMakeVisible (tc);
  44314. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  44315. }
  44316. }
  44317. viewport = new Viewport();
  44318. viewport->setViewedComponent (itemHolder);
  44319. addAndMakeVisible (viewport);
  44320. }
  44321. ToolbarItemPalette::~ToolbarItemPalette()
  44322. {
  44323. viewport->getViewedComponent()->deleteAllChildren();
  44324. deleteAllChildren();
  44325. }
  44326. void ToolbarItemPalette::resized()
  44327. {
  44328. viewport->setBoundsInset (BorderSize (1));
  44329. Component* const itemHolder = viewport->getViewedComponent();
  44330. const int indent = 8;
  44331. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44332. const int height = toolbar->getThickness();
  44333. int x = indent;
  44334. int y = indent;
  44335. int maxX = 0;
  44336. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44337. {
  44338. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44339. if (tc != 0)
  44340. {
  44341. tc->setStyle (toolbar->getStyle());
  44342. int preferredSize = 1, minSize = 1, maxSize = 1;
  44343. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44344. {
  44345. if (x + preferredSize > preferredWidth && x > indent)
  44346. {
  44347. x = indent;
  44348. y += height;
  44349. }
  44350. tc->setBounds (x, y, preferredSize, height);
  44351. x += preferredSize + 8;
  44352. maxX = jmax (maxX, x);
  44353. }
  44354. }
  44355. }
  44356. itemHolder->setSize (maxX, y + height + 8);
  44357. }
  44358. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44359. {
  44360. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44361. jassert (tc != 0);
  44362. if (tc != 0)
  44363. {
  44364. tc->setBounds (comp->getBounds());
  44365. tc->setStyle (toolbar->getStyle());
  44366. tc->setEditingMode (comp->getEditingMode());
  44367. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44368. }
  44369. }
  44370. END_JUCE_NAMESPACE
  44371. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  44372. /*** Start of inlined file: juce_TreeView.cpp ***/
  44373. BEGIN_JUCE_NAMESPACE
  44374. class TreeViewContentComponent : public Component,
  44375. public TooltipClient
  44376. {
  44377. public:
  44378. TreeViewContentComponent (TreeView* const owner_)
  44379. : owner (owner_),
  44380. buttonUnderMouse (0),
  44381. isDragging (false)
  44382. {
  44383. }
  44384. ~TreeViewContentComponent()
  44385. {
  44386. deleteAllChildren();
  44387. }
  44388. void mouseDown (const MouseEvent& e)
  44389. {
  44390. updateButtonUnderMouse (e);
  44391. isDragging = false;
  44392. needSelectionOnMouseUp = false;
  44393. Rectangle<int> pos;
  44394. TreeViewItem* const item = findItemAt (e.y, pos);
  44395. if (item == 0)
  44396. return;
  44397. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44398. // as selection clicks)
  44399. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44400. {
  44401. if (e.x >= pos.getX() - owner->getIndentSize())
  44402. item->setOpen (! item->isOpen());
  44403. // (clicks to the left of an open/close button are ignored)
  44404. }
  44405. else
  44406. {
  44407. // mouse-down inside the body of the item..
  44408. if (! owner->isMultiSelectEnabled())
  44409. item->setSelected (true, true);
  44410. else if (item->isSelected())
  44411. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44412. else
  44413. selectBasedOnModifiers (item, e.mods);
  44414. if (e.x >= pos.getX())
  44415. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  44416. }
  44417. }
  44418. void mouseUp (const MouseEvent& e)
  44419. {
  44420. updateButtonUnderMouse (e);
  44421. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44422. {
  44423. Rectangle<int> pos;
  44424. TreeViewItem* const item = findItemAt (e.y, pos);
  44425. if (item != 0)
  44426. selectBasedOnModifiers (item, e.mods);
  44427. }
  44428. }
  44429. void mouseDoubleClick (const MouseEvent& e)
  44430. {
  44431. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44432. {
  44433. Rectangle<int> pos;
  44434. TreeViewItem* const item = findItemAt (e.y, pos);
  44435. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44436. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  44437. }
  44438. }
  44439. void mouseDrag (const MouseEvent& e)
  44440. {
  44441. if (isEnabled()
  44442. && ! (isDragging || e.mouseWasClicked()
  44443. || e.getDistanceFromDragStart() < 5
  44444. || e.mods.isPopupMenu()))
  44445. {
  44446. isDragging = true;
  44447. Rectangle<int> pos;
  44448. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44449. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44450. {
  44451. const String dragDescription (item->getDragSourceDescription());
  44452. if (dragDescription.isNotEmpty())
  44453. {
  44454. DragAndDropContainer* const dragContainer
  44455. = DragAndDropContainer::findParentDragContainerFor (this);
  44456. if (dragContainer != 0)
  44457. {
  44458. pos.setSize (pos.getWidth(), item->itemHeight);
  44459. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44460. dragImage->multiplyAllAlphas (0.6f);
  44461. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44462. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44463. }
  44464. else
  44465. {
  44466. // to be able to do a drag-and-drop operation, the treeview needs to
  44467. // be inside a component which is also a DragAndDropContainer.
  44468. jassertfalse
  44469. }
  44470. }
  44471. }
  44472. }
  44473. }
  44474. void mouseMove (const MouseEvent& e)
  44475. {
  44476. updateButtonUnderMouse (e);
  44477. }
  44478. void mouseExit (const MouseEvent& e)
  44479. {
  44480. updateButtonUnderMouse (e);
  44481. }
  44482. void paint (Graphics& g);
  44483. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44484. void updateComponents()
  44485. {
  44486. const int visibleTop = -getY();
  44487. const int visibleBottom = visibleTop + getParentHeight();
  44488. BitArray itemsToKeep;
  44489. TreeViewItem* item = owner->rootItem;
  44490. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44491. while (item != 0 && y < visibleBottom)
  44492. {
  44493. y += item->itemHeight;
  44494. if (y >= visibleTop)
  44495. {
  44496. const int index = rowComponentIds.indexOf (item->uid);
  44497. if (index < 0)
  44498. {
  44499. Component* const comp = item->createItemComponent();
  44500. if (comp != 0)
  44501. {
  44502. addAndMakeVisible (comp);
  44503. itemsToKeep.setBit (rowComponentItems.size());
  44504. rowComponentItems.add (item);
  44505. rowComponentIds.add (item->uid);
  44506. rowComponents.add (comp);
  44507. }
  44508. }
  44509. else
  44510. {
  44511. itemsToKeep.setBit (index);
  44512. }
  44513. }
  44514. item = item->getNextVisibleItem (true);
  44515. }
  44516. for (int i = rowComponentItems.size(); --i >= 0;)
  44517. {
  44518. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44519. bool keep = false;
  44520. if (isParentOf (comp))
  44521. {
  44522. if (itemsToKeep[i])
  44523. {
  44524. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44525. Rectangle<int> pos (item->getItemPosition (false));
  44526. pos.setSize (pos.getWidth(), item->itemHeight);
  44527. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44528. {
  44529. keep = true;
  44530. comp->setBounds (pos);
  44531. }
  44532. }
  44533. if ((! keep)
  44534. && Component::isMouseButtonDownAnywhere()
  44535. && (comp == Component::getComponentUnderMouse()
  44536. || comp->isParentOf (Component::getComponentUnderMouse())))
  44537. {
  44538. keep = true;
  44539. comp->setSize (0, 0);
  44540. }
  44541. }
  44542. if (! keep)
  44543. {
  44544. delete comp;
  44545. rowComponents.remove (i);
  44546. rowComponentIds.remove (i);
  44547. rowComponentItems.remove (i);
  44548. }
  44549. }
  44550. }
  44551. void updateButtonUnderMouse (const MouseEvent& e)
  44552. {
  44553. TreeViewItem* newItem = 0;
  44554. if (owner->openCloseButtonsVisible)
  44555. {
  44556. Rectangle<int> pos;
  44557. TreeViewItem* item = findItemAt (e.y, pos);
  44558. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44559. {
  44560. newItem = item;
  44561. if (! newItem->mightContainSubItems())
  44562. newItem = 0;
  44563. }
  44564. }
  44565. if (buttonUnderMouse != newItem)
  44566. {
  44567. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44568. {
  44569. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44570. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44571. }
  44572. buttonUnderMouse = newItem;
  44573. if (buttonUnderMouse != 0)
  44574. {
  44575. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44576. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44577. }
  44578. }
  44579. }
  44580. bool isMouseOverButton (TreeViewItem* item) const throw()
  44581. {
  44582. return item == buttonUnderMouse;
  44583. }
  44584. void resized()
  44585. {
  44586. owner->itemsChanged();
  44587. }
  44588. const String getTooltip()
  44589. {
  44590. Rectangle<int> pos;
  44591. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44592. if (item != 0)
  44593. return item->getTooltip();
  44594. return owner->getTooltip();
  44595. }
  44596. juce_UseDebuggingNewOperator
  44597. private:
  44598. TreeView* const owner;
  44599. VoidArray rowComponentItems;
  44600. Array <int> rowComponentIds;
  44601. VoidArray rowComponents;
  44602. TreeViewItem* buttonUnderMouse;
  44603. bool isDragging, needSelectionOnMouseUp;
  44604. TreeViewContentComponent (const TreeViewContentComponent&);
  44605. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44606. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44607. {
  44608. TreeViewItem* firstSelected = 0;
  44609. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44610. {
  44611. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44612. jassert (lastSelected != 0);
  44613. int rowStart = firstSelected->getRowNumberInTree();
  44614. int rowEnd = lastSelected->getRowNumberInTree();
  44615. if (rowStart > rowEnd)
  44616. swapVariables (rowStart, rowEnd);
  44617. int ourRow = item->getRowNumberInTree();
  44618. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44619. if (ourRow > otherEnd)
  44620. swapVariables (ourRow, otherEnd);
  44621. for (int i = ourRow; i <= otherEnd; ++i)
  44622. owner->getItemOnRow (i)->setSelected (true, false);
  44623. }
  44624. else
  44625. {
  44626. const bool cmd = modifiers.isCommandDown();
  44627. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44628. }
  44629. }
  44630. bool containsItem (TreeViewItem* const item) const
  44631. {
  44632. for (int i = rowComponentItems.size(); --i >= 0;)
  44633. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44634. return true;
  44635. return false;
  44636. }
  44637. };
  44638. class TreeViewport : public Viewport
  44639. {
  44640. public:
  44641. TreeViewport() throw() {}
  44642. ~TreeViewport() throw() {}
  44643. void updateComponents()
  44644. {
  44645. if (getViewedComponent() != 0)
  44646. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44647. repaint();
  44648. }
  44649. void visibleAreaChanged (int, int, int, int)
  44650. {
  44651. updateComponents();
  44652. }
  44653. juce_UseDebuggingNewOperator
  44654. private:
  44655. TreeViewport (const TreeViewport&);
  44656. TreeViewport& operator= (const TreeViewport&);
  44657. };
  44658. TreeView::TreeView (const String& componentName)
  44659. : Component (componentName),
  44660. rootItem (0),
  44661. dragInsertPointHighlight (0),
  44662. dragTargetGroupHighlight (0),
  44663. indentSize (24),
  44664. defaultOpenness (false),
  44665. needsRecalculating (true),
  44666. rootItemVisible (true),
  44667. multiSelectEnabled (false),
  44668. openCloseButtonsVisible (true)
  44669. {
  44670. addAndMakeVisible (viewport = new TreeViewport());
  44671. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44672. viewport->setWantsKeyboardFocus (false);
  44673. setWantsKeyboardFocus (true);
  44674. }
  44675. TreeView::~TreeView()
  44676. {
  44677. if (rootItem != 0)
  44678. rootItem->setOwnerView (0);
  44679. deleteAllChildren();
  44680. }
  44681. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44682. {
  44683. if (rootItem != newRootItem)
  44684. {
  44685. if (newRootItem != 0)
  44686. {
  44687. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44688. if (newRootItem->ownerView != 0)
  44689. newRootItem->ownerView->setRootItem (0);
  44690. }
  44691. if (rootItem != 0)
  44692. rootItem->setOwnerView (0);
  44693. rootItem = newRootItem;
  44694. if (newRootItem != 0)
  44695. newRootItem->setOwnerView (this);
  44696. needsRecalculating = true;
  44697. handleAsyncUpdate();
  44698. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44699. {
  44700. rootItem->setOpen (false); // force a re-open
  44701. rootItem->setOpen (true);
  44702. }
  44703. }
  44704. }
  44705. void TreeView::deleteRootItem()
  44706. {
  44707. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44708. setRootItem (0);
  44709. }
  44710. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44711. {
  44712. rootItemVisible = shouldBeVisible;
  44713. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44714. {
  44715. rootItem->setOpen (false); // force a re-open
  44716. rootItem->setOpen (true);
  44717. }
  44718. itemsChanged();
  44719. }
  44720. void TreeView::colourChanged()
  44721. {
  44722. setOpaque (findColour (backgroundColourId).isOpaque());
  44723. repaint();
  44724. }
  44725. void TreeView::setIndentSize (const int newIndentSize)
  44726. {
  44727. if (indentSize != newIndentSize)
  44728. {
  44729. indentSize = newIndentSize;
  44730. resized();
  44731. }
  44732. }
  44733. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44734. {
  44735. if (defaultOpenness != isOpenByDefault)
  44736. {
  44737. defaultOpenness = isOpenByDefault;
  44738. itemsChanged();
  44739. }
  44740. }
  44741. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44742. {
  44743. multiSelectEnabled = canMultiSelect;
  44744. }
  44745. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44746. {
  44747. if (openCloseButtonsVisible != shouldBeVisible)
  44748. {
  44749. openCloseButtonsVisible = shouldBeVisible;
  44750. itemsChanged();
  44751. }
  44752. }
  44753. void TreeView::clearSelectedItems()
  44754. {
  44755. if (rootItem != 0)
  44756. rootItem->deselectAllRecursively();
  44757. }
  44758. int TreeView::getNumSelectedItems() const throw()
  44759. {
  44760. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44761. }
  44762. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44763. {
  44764. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44765. }
  44766. int TreeView::getNumRowsInTree() const
  44767. {
  44768. if (rootItem != 0)
  44769. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44770. return 0;
  44771. }
  44772. TreeViewItem* TreeView::getItemOnRow (int index) const
  44773. {
  44774. if (! rootItemVisible)
  44775. ++index;
  44776. if (rootItem != 0 && index >= 0)
  44777. return rootItem->getItemOnRow (index);
  44778. return 0;
  44779. }
  44780. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44781. {
  44782. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44783. Rectangle<int> pos;
  44784. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44785. }
  44786. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44787. {
  44788. if (rootItem == 0)
  44789. return 0;
  44790. return rootItem->findItemFromIdentifierString (identifierString);
  44791. }
  44792. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44793. {
  44794. XmlElement* e = 0;
  44795. if (rootItem != 0)
  44796. {
  44797. e = rootItem->getOpennessState();
  44798. if (e != 0 && alsoIncludeScrollPosition)
  44799. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44800. }
  44801. return e;
  44802. }
  44803. void TreeView::restoreOpennessState (const XmlElement& newState)
  44804. {
  44805. if (rootItem != 0)
  44806. {
  44807. rootItem->restoreOpennessState (newState);
  44808. if (newState.hasAttribute (T("scrollPos")))
  44809. viewport->setViewPosition (viewport->getViewPositionX(),
  44810. newState.getIntAttribute (T("scrollPos")));
  44811. }
  44812. }
  44813. void TreeView::paint (Graphics& g)
  44814. {
  44815. g.fillAll (findColour (backgroundColourId));
  44816. }
  44817. void TreeView::resized()
  44818. {
  44819. viewport->setBounds (0, 0, getWidth(), getHeight());
  44820. itemsChanged();
  44821. handleAsyncUpdate();
  44822. }
  44823. void TreeView::enablementChanged()
  44824. {
  44825. repaint();
  44826. }
  44827. void TreeView::moveSelectedRow (int delta)
  44828. {
  44829. if (delta == 0)
  44830. return;
  44831. int rowSelected = 0;
  44832. TreeViewItem* const firstSelected = getSelectedItem (0);
  44833. if (firstSelected != 0)
  44834. rowSelected = firstSelected->getRowNumberInTree();
  44835. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44836. for (;;)
  44837. {
  44838. TreeViewItem* item = getItemOnRow (rowSelected);
  44839. if (item != 0)
  44840. {
  44841. if (! item->canBeSelected())
  44842. {
  44843. // if the row we want to highlight doesn't allow it, try skipping
  44844. // to the next item..
  44845. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44846. rowSelected + (delta < 0 ? -1 : 1));
  44847. if (rowSelected != nextRowToTry)
  44848. {
  44849. rowSelected = nextRowToTry;
  44850. continue;
  44851. }
  44852. else
  44853. {
  44854. break;
  44855. }
  44856. }
  44857. item->setSelected (true, true);
  44858. scrollToKeepItemVisible (item);
  44859. }
  44860. break;
  44861. }
  44862. }
  44863. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44864. {
  44865. if (item != 0 && item->ownerView == this)
  44866. {
  44867. handleAsyncUpdate();
  44868. item = item->getDeepestOpenParentItem();
  44869. int y = item->y;
  44870. int viewTop = viewport->getViewPositionY();
  44871. if (y < viewTop)
  44872. {
  44873. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44874. }
  44875. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44876. {
  44877. viewport->setViewPosition (viewport->getViewPositionX(),
  44878. (y + item->itemHeight) - viewport->getViewHeight());
  44879. }
  44880. }
  44881. }
  44882. bool TreeView::keyPressed (const KeyPress& key)
  44883. {
  44884. if (key.isKeyCode (KeyPress::upKey))
  44885. {
  44886. moveSelectedRow (-1);
  44887. }
  44888. else if (key.isKeyCode (KeyPress::downKey))
  44889. {
  44890. moveSelectedRow (1);
  44891. }
  44892. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44893. {
  44894. if (rootItem != 0)
  44895. {
  44896. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44897. if (key.isKeyCode (KeyPress::pageUpKey))
  44898. rowsOnScreen = -rowsOnScreen;
  44899. moveSelectedRow (rowsOnScreen);
  44900. }
  44901. }
  44902. else if (key.isKeyCode (KeyPress::homeKey))
  44903. {
  44904. moveSelectedRow (-0x3fffffff);
  44905. }
  44906. else if (key.isKeyCode (KeyPress::endKey))
  44907. {
  44908. moveSelectedRow (0x3fffffff);
  44909. }
  44910. else if (key.isKeyCode (KeyPress::returnKey))
  44911. {
  44912. TreeViewItem* const firstSelected = getSelectedItem (0);
  44913. if (firstSelected != 0)
  44914. firstSelected->setOpen (! firstSelected->isOpen());
  44915. }
  44916. else if (key.isKeyCode (KeyPress::leftKey))
  44917. {
  44918. TreeViewItem* const firstSelected = getSelectedItem (0);
  44919. if (firstSelected != 0)
  44920. {
  44921. if (firstSelected->isOpen())
  44922. {
  44923. firstSelected->setOpen (false);
  44924. }
  44925. else
  44926. {
  44927. TreeViewItem* parent = firstSelected->parentItem;
  44928. if ((! rootItemVisible) && parent == rootItem)
  44929. parent = 0;
  44930. if (parent != 0)
  44931. {
  44932. parent->setSelected (true, true);
  44933. scrollToKeepItemVisible (parent);
  44934. }
  44935. }
  44936. }
  44937. }
  44938. else if (key.isKeyCode (KeyPress::rightKey))
  44939. {
  44940. TreeViewItem* const firstSelected = getSelectedItem (0);
  44941. if (firstSelected != 0)
  44942. {
  44943. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44944. moveSelectedRow (1);
  44945. else
  44946. firstSelected->setOpen (true);
  44947. }
  44948. }
  44949. else
  44950. {
  44951. return false;
  44952. }
  44953. return true;
  44954. }
  44955. void TreeView::itemsChanged() throw()
  44956. {
  44957. needsRecalculating = true;
  44958. repaint();
  44959. triggerAsyncUpdate();
  44960. }
  44961. void TreeView::handleAsyncUpdate()
  44962. {
  44963. if (needsRecalculating)
  44964. {
  44965. needsRecalculating = false;
  44966. const ScopedLock sl (nodeAlterationLock);
  44967. if (rootItem != 0)
  44968. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44969. ((TreeViewport*) viewport)->updateComponents();
  44970. if (rootItem != 0)
  44971. {
  44972. viewport->getViewedComponent()
  44973. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44974. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44975. }
  44976. else
  44977. {
  44978. viewport->getViewedComponent()->setSize (0, 0);
  44979. }
  44980. }
  44981. }
  44982. class TreeViewDragInsertPointHighlight : public Component
  44983. {
  44984. public:
  44985. TreeViewDragInsertPointHighlight()
  44986. : lastItem (0)
  44987. {
  44988. setSize (100, 12);
  44989. setAlwaysOnTop (true);
  44990. setInterceptsMouseClicks (false, false);
  44991. }
  44992. ~TreeViewDragInsertPointHighlight() {}
  44993. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44994. {
  44995. lastItem = item;
  44996. lastIndex = insertIndex;
  44997. const int offset = getHeight() / 2;
  44998. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44999. }
  45000. void paint (Graphics& g)
  45001. {
  45002. Path p;
  45003. const float h = (float) getHeight();
  45004. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  45005. p.startNewSubPath (h - 2.0f, h / 2.0f);
  45006. p.lineTo ((float) getWidth(), h / 2.0f);
  45007. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45008. g.strokePath (p, PathStrokeType (2.0f));
  45009. }
  45010. TreeViewItem* lastItem;
  45011. int lastIndex;
  45012. };
  45013. class TreeViewDragTargetGroupHighlight : public Component
  45014. {
  45015. public:
  45016. TreeViewDragTargetGroupHighlight()
  45017. {
  45018. setAlwaysOnTop (true);
  45019. setInterceptsMouseClicks (false, false);
  45020. }
  45021. ~TreeViewDragTargetGroupHighlight() {}
  45022. void setTargetPosition (TreeViewItem* const item) throw()
  45023. {
  45024. Rectangle<int> r (item->getItemPosition (true));
  45025. r.setHeight (item->getItemHeight());
  45026. setBounds (r);
  45027. }
  45028. void paint (Graphics& g)
  45029. {
  45030. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45031. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  45032. }
  45033. };
  45034. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  45035. {
  45036. beginDragAutoRepeat (1000 / 30);
  45037. if (dragInsertPointHighlight == 0)
  45038. {
  45039. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  45040. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  45041. }
  45042. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  45043. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  45044. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  45045. ->setTargetPosition (item);
  45046. }
  45047. void TreeView::hideDragHighlight() throw()
  45048. {
  45049. deleteAndZero (dragInsertPointHighlight);
  45050. deleteAndZero (dragTargetGroupHighlight);
  45051. }
  45052. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  45053. const StringArray& files, const String& sourceDescription,
  45054. Component* sourceComponent) const throw()
  45055. {
  45056. insertIndex = 0;
  45057. TreeViewItem* item = getItemAt (y);
  45058. if (item == 0)
  45059. return 0;
  45060. Rectangle<int> itemPos (item->getItemPosition (true));
  45061. insertIndex = item->getIndexInParent();
  45062. const int oldY = y;
  45063. y = itemPos.getY();
  45064. if (item->getNumSubItems() == 0 || ! item->isOpen())
  45065. {
  45066. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45067. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45068. {
  45069. // Check if we're trying to drag into an empty group item..
  45070. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  45071. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  45072. {
  45073. insertIndex = 0;
  45074. x = itemPos.getX() + getIndentSize();
  45075. y = itemPos.getBottom();
  45076. return item;
  45077. }
  45078. }
  45079. }
  45080. if (oldY > itemPos.getCentreY())
  45081. {
  45082. y += item->getItemHeight();
  45083. while (item->isLastOfSiblings() && item->parentItem != 0
  45084. && item->parentItem->parentItem != 0)
  45085. {
  45086. if (x > itemPos.getX())
  45087. break;
  45088. item = item->parentItem;
  45089. itemPos = item->getItemPosition (true);
  45090. insertIndex = item->getIndexInParent();
  45091. }
  45092. ++insertIndex;
  45093. }
  45094. x = itemPos.getX();
  45095. return item->parentItem;
  45096. }
  45097. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45098. {
  45099. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  45100. int insertIndex;
  45101. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45102. if (item != 0)
  45103. {
  45104. if (scrolled || dragInsertPointHighlight == 0
  45105. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  45106. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  45107. {
  45108. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45109. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45110. showDragHighlight (item, insertIndex, x, y);
  45111. else
  45112. hideDragHighlight();
  45113. }
  45114. }
  45115. else
  45116. {
  45117. hideDragHighlight();
  45118. }
  45119. }
  45120. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45121. {
  45122. hideDragHighlight();
  45123. int insertIndex;
  45124. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45125. if (item != 0)
  45126. {
  45127. if (files.size() > 0)
  45128. {
  45129. if (item->isInterestedInFileDrag (files))
  45130. item->filesDropped (files, insertIndex);
  45131. }
  45132. else
  45133. {
  45134. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45135. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  45136. }
  45137. }
  45138. }
  45139. bool TreeView::isInterestedInFileDrag (const StringArray&)
  45140. {
  45141. return true;
  45142. }
  45143. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  45144. {
  45145. fileDragMove (files, x, y);
  45146. }
  45147. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  45148. {
  45149. handleDrag (files, String::empty, 0, x, y);
  45150. }
  45151. void TreeView::fileDragExit (const StringArray&)
  45152. {
  45153. hideDragHighlight();
  45154. }
  45155. void TreeView::filesDropped (const StringArray& files, int x, int y)
  45156. {
  45157. handleDrop (files, String::empty, 0, x, y);
  45158. }
  45159. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45160. {
  45161. return true;
  45162. }
  45163. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45164. {
  45165. itemDragMove (sourceDescription, sourceComponent, x, y);
  45166. }
  45167. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45168. {
  45169. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  45170. }
  45171. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45172. {
  45173. hideDragHighlight();
  45174. }
  45175. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45176. {
  45177. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  45178. }
  45179. void TreeViewContentComponent::paint (Graphics& g)
  45180. {
  45181. if (owner->rootItem != 0)
  45182. {
  45183. owner->handleAsyncUpdate();
  45184. if (! owner->rootItemVisible)
  45185. g.setOrigin (0, -owner->rootItem->itemHeight);
  45186. owner->rootItem->paintRecursively (g, getWidth());
  45187. }
  45188. }
  45189. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  45190. {
  45191. if (owner->rootItem != 0)
  45192. {
  45193. owner->handleAsyncUpdate();
  45194. if (! owner->rootItemVisible)
  45195. y += owner->rootItem->itemHeight;
  45196. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  45197. if (ti != 0)
  45198. itemPosition = ti->getItemPosition (false);
  45199. return ti;
  45200. }
  45201. return 0;
  45202. }
  45203. enum TreeViewOpenness
  45204. {
  45205. opennessDefault = 0,
  45206. opennessClosed = 1,
  45207. opennessOpen = 2
  45208. };
  45209. TreeViewItem::TreeViewItem()
  45210. : ownerView (0),
  45211. parentItem (0),
  45212. y (0),
  45213. itemHeight (0),
  45214. totalHeight (0),
  45215. selected (false),
  45216. redrawNeeded (true),
  45217. drawLinesInside (true),
  45218. drawsInLeftMargin (false),
  45219. openness (opennessDefault)
  45220. {
  45221. static int nextUID = 0;
  45222. uid = nextUID++;
  45223. }
  45224. TreeViewItem::~TreeViewItem()
  45225. {
  45226. }
  45227. const String TreeViewItem::getUniqueName() const
  45228. {
  45229. return String::empty;
  45230. }
  45231. void TreeViewItem::itemOpennessChanged (bool)
  45232. {
  45233. }
  45234. int TreeViewItem::getNumSubItems() const throw()
  45235. {
  45236. return subItems.size();
  45237. }
  45238. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  45239. {
  45240. return subItems [index];
  45241. }
  45242. void TreeViewItem::clearSubItems()
  45243. {
  45244. if (subItems.size() > 0)
  45245. {
  45246. if (ownerView != 0)
  45247. {
  45248. const ScopedLock sl (ownerView->nodeAlterationLock);
  45249. subItems.clear();
  45250. treeHasChanged();
  45251. }
  45252. else
  45253. {
  45254. subItems.clear();
  45255. }
  45256. }
  45257. }
  45258. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  45259. {
  45260. if (newItem != 0)
  45261. {
  45262. newItem->parentItem = this;
  45263. newItem->setOwnerView (ownerView);
  45264. newItem->y = 0;
  45265. newItem->itemHeight = newItem->getItemHeight();
  45266. newItem->totalHeight = 0;
  45267. newItem->itemWidth = newItem->getItemWidth();
  45268. newItem->totalWidth = 0;
  45269. if (ownerView != 0)
  45270. {
  45271. const ScopedLock sl (ownerView->nodeAlterationLock);
  45272. subItems.insert (insertPosition, newItem);
  45273. treeHasChanged();
  45274. if (newItem->isOpen())
  45275. newItem->itemOpennessChanged (true);
  45276. }
  45277. else
  45278. {
  45279. subItems.insert (insertPosition, newItem);
  45280. if (newItem->isOpen())
  45281. newItem->itemOpennessChanged (true);
  45282. }
  45283. }
  45284. }
  45285. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  45286. {
  45287. if (ownerView != 0)
  45288. {
  45289. const ScopedLock sl (ownerView->nodeAlterationLock);
  45290. if (((unsigned int) index) < (unsigned int) subItems.size())
  45291. {
  45292. subItems.remove (index, deleteItem);
  45293. treeHasChanged();
  45294. }
  45295. }
  45296. else
  45297. {
  45298. subItems.remove (index, deleteItem);
  45299. }
  45300. }
  45301. bool TreeViewItem::isOpen() const throw()
  45302. {
  45303. if (openness == opennessDefault)
  45304. return ownerView != 0 && ownerView->defaultOpenness;
  45305. else
  45306. return openness == opennessOpen;
  45307. }
  45308. void TreeViewItem::setOpen (const bool shouldBeOpen)
  45309. {
  45310. if (isOpen() != shouldBeOpen)
  45311. {
  45312. openness = shouldBeOpen ? opennessOpen
  45313. : opennessClosed;
  45314. treeHasChanged();
  45315. itemOpennessChanged (isOpen());
  45316. }
  45317. }
  45318. bool TreeViewItem::isSelected() const throw()
  45319. {
  45320. return selected;
  45321. }
  45322. void TreeViewItem::deselectAllRecursively()
  45323. {
  45324. setSelected (false, false);
  45325. for (int i = 0; i < subItems.size(); ++i)
  45326. subItems.getUnchecked(i)->deselectAllRecursively();
  45327. }
  45328. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45329. const bool deselectOtherItemsFirst)
  45330. {
  45331. if (shouldBeSelected && ! canBeSelected())
  45332. return;
  45333. if (deselectOtherItemsFirst)
  45334. getTopLevelItem()->deselectAllRecursively();
  45335. if (shouldBeSelected != selected)
  45336. {
  45337. selected = shouldBeSelected;
  45338. if (ownerView != 0)
  45339. ownerView->repaint();
  45340. itemSelectionChanged (shouldBeSelected);
  45341. }
  45342. }
  45343. void TreeViewItem::paintItem (Graphics&, int, int)
  45344. {
  45345. }
  45346. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45347. {
  45348. ownerView->getLookAndFeel()
  45349. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45350. }
  45351. void TreeViewItem::itemClicked (const MouseEvent&)
  45352. {
  45353. }
  45354. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45355. {
  45356. if (mightContainSubItems())
  45357. setOpen (! isOpen());
  45358. }
  45359. void TreeViewItem::itemSelectionChanged (bool)
  45360. {
  45361. }
  45362. const String TreeViewItem::getTooltip()
  45363. {
  45364. return String::empty;
  45365. }
  45366. const String TreeViewItem::getDragSourceDescription()
  45367. {
  45368. return String::empty;
  45369. }
  45370. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45371. {
  45372. return false;
  45373. }
  45374. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45375. {
  45376. }
  45377. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45378. {
  45379. return false;
  45380. }
  45381. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45382. {
  45383. }
  45384. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45385. {
  45386. const int indentX = getIndentX();
  45387. int width = itemWidth;
  45388. if (ownerView != 0 && width < 0)
  45389. width = ownerView->viewport->getViewWidth() - indentX;
  45390. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  45391. if (relativeToTreeViewTopLeft)
  45392. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45393. r.getY() - ownerView->viewport->getViewPositionY());
  45394. return r;
  45395. }
  45396. void TreeViewItem::treeHasChanged() const throw()
  45397. {
  45398. if (ownerView != 0)
  45399. ownerView->itemsChanged();
  45400. }
  45401. void TreeViewItem::repaintItem() const
  45402. {
  45403. if (ownerView != 0 && areAllParentsOpen())
  45404. {
  45405. const Rectangle<int> r (getItemPosition (true));
  45406. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45407. }
  45408. }
  45409. bool TreeViewItem::areAllParentsOpen() const throw()
  45410. {
  45411. return parentItem == 0
  45412. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45413. }
  45414. void TreeViewItem::updatePositions (int newY)
  45415. {
  45416. y = newY;
  45417. itemHeight = getItemHeight();
  45418. totalHeight = itemHeight;
  45419. itemWidth = getItemWidth();
  45420. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45421. if (isOpen())
  45422. {
  45423. newY += totalHeight;
  45424. for (int i = 0; i < subItems.size(); ++i)
  45425. {
  45426. TreeViewItem* const ti = subItems.getUnchecked(i);
  45427. ti->updatePositions (newY);
  45428. newY += ti->totalHeight;
  45429. totalHeight += ti->totalHeight;
  45430. totalWidth = jmax (totalWidth, ti->totalWidth);
  45431. }
  45432. }
  45433. }
  45434. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45435. {
  45436. TreeViewItem* result = this;
  45437. TreeViewItem* item = this;
  45438. while (item->parentItem != 0)
  45439. {
  45440. item = item->parentItem;
  45441. if (! item->isOpen())
  45442. result = item;
  45443. }
  45444. return result;
  45445. }
  45446. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45447. {
  45448. ownerView = newOwner;
  45449. for (int i = subItems.size(); --i >= 0;)
  45450. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45451. }
  45452. int TreeViewItem::getIndentX() const throw()
  45453. {
  45454. const int indentWidth = ownerView->getIndentSize();
  45455. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45456. if (! ownerView->openCloseButtonsVisible)
  45457. x -= indentWidth;
  45458. TreeViewItem* p = parentItem;
  45459. while (p != 0)
  45460. {
  45461. x += indentWidth;
  45462. p = p->parentItem;
  45463. }
  45464. return x;
  45465. }
  45466. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45467. {
  45468. drawsInLeftMargin = canDrawInLeftMargin;
  45469. }
  45470. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45471. {
  45472. jassert (ownerView != 0);
  45473. if (ownerView == 0)
  45474. return;
  45475. const int indent = getIndentX();
  45476. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45477. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45478. const float halfH = itemHeight * 0.5f;
  45479. int depth = 0;
  45480. TreeViewItem* p = parentItem;
  45481. while (p != 0)
  45482. {
  45483. ++depth;
  45484. p = p->parentItem;
  45485. }
  45486. if (! ownerView->rootItemVisible)
  45487. --depth;
  45488. const int indentWidth = ownerView->getIndentSize();
  45489. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45490. {
  45491. float x = (depth + 0.5f) * indentWidth;
  45492. if (depth >= 0)
  45493. {
  45494. if (parentItem != 0 && parentItem->drawLinesInside)
  45495. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45496. if ((parentItem != 0 && parentItem->drawLinesInside)
  45497. || (parentItem == 0 && drawLinesInside))
  45498. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45499. }
  45500. p = parentItem;
  45501. int d = depth;
  45502. while (p != 0 && --d >= 0)
  45503. {
  45504. x -= (float) indentWidth;
  45505. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45506. && ! p->isLastOfSiblings())
  45507. {
  45508. g.drawLine (x, 0, x, (float) itemHeight);
  45509. }
  45510. p = p->parentItem;
  45511. }
  45512. if (mightContainSubItems())
  45513. {
  45514. g.saveState();
  45515. g.setOrigin (depth * indentWidth, 0);
  45516. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45517. paintOpenCloseButton (g, indentWidth, itemHeight,
  45518. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45519. ->isMouseOverButton (this));
  45520. g.restoreState();
  45521. }
  45522. }
  45523. {
  45524. g.saveState();
  45525. g.setOrigin (indent, 0);
  45526. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45527. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45528. paintItem (g, itemW, itemHeight);
  45529. g.restoreState();
  45530. }
  45531. if (isOpen())
  45532. {
  45533. const Rectangle<int> clip (g.getClipBounds());
  45534. for (int i = 0; i < subItems.size(); ++i)
  45535. {
  45536. TreeViewItem* const ti = subItems.getUnchecked(i);
  45537. const int relY = ti->y - y;
  45538. if (relY >= clip.getBottom())
  45539. break;
  45540. if (relY + ti->totalHeight >= clip.getY())
  45541. {
  45542. g.saveState();
  45543. g.setOrigin (0, relY);
  45544. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45545. ti->paintRecursively (g, width);
  45546. g.restoreState();
  45547. }
  45548. }
  45549. }
  45550. }
  45551. bool TreeViewItem::isLastOfSiblings() const throw()
  45552. {
  45553. return parentItem == 0
  45554. || parentItem->subItems.getLast() == this;
  45555. }
  45556. int TreeViewItem::getIndexInParent() const throw()
  45557. {
  45558. if (parentItem == 0)
  45559. return 0;
  45560. return parentItem->subItems.indexOf (this);
  45561. }
  45562. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45563. {
  45564. return (parentItem == 0) ? this
  45565. : parentItem->getTopLevelItem();
  45566. }
  45567. int TreeViewItem::getNumRows() const throw()
  45568. {
  45569. int num = 1;
  45570. if (isOpen())
  45571. {
  45572. for (int i = subItems.size(); --i >= 0;)
  45573. num += subItems.getUnchecked(i)->getNumRows();
  45574. }
  45575. return num;
  45576. }
  45577. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45578. {
  45579. if (index == 0)
  45580. return this;
  45581. if (index > 0 && isOpen())
  45582. {
  45583. --index;
  45584. for (int i = 0; i < subItems.size(); ++i)
  45585. {
  45586. TreeViewItem* const item = subItems.getUnchecked(i);
  45587. if (index == 0)
  45588. return item;
  45589. const int numRows = item->getNumRows();
  45590. if (numRows > index)
  45591. return item->getItemOnRow (index);
  45592. index -= numRows;
  45593. }
  45594. }
  45595. return 0;
  45596. }
  45597. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45598. {
  45599. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45600. {
  45601. const int h = itemHeight;
  45602. if (targetY < h)
  45603. return this;
  45604. if (isOpen())
  45605. {
  45606. targetY -= h;
  45607. for (int i = 0; i < subItems.size(); ++i)
  45608. {
  45609. TreeViewItem* const ti = subItems.getUnchecked(i);
  45610. if (targetY < ti->totalHeight)
  45611. return ti->findItemRecursively (targetY);
  45612. targetY -= ti->totalHeight;
  45613. }
  45614. }
  45615. }
  45616. return 0;
  45617. }
  45618. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45619. {
  45620. int total = 0;
  45621. if (isSelected())
  45622. ++total;
  45623. for (int i = subItems.size(); --i >= 0;)
  45624. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45625. return total;
  45626. }
  45627. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45628. {
  45629. if (isSelected())
  45630. {
  45631. if (index == 0)
  45632. return this;
  45633. --index;
  45634. }
  45635. if (index >= 0)
  45636. {
  45637. for (int i = 0; i < subItems.size(); ++i)
  45638. {
  45639. TreeViewItem* const item = subItems.getUnchecked(i);
  45640. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45641. if (found != 0)
  45642. return found;
  45643. index -= item->countSelectedItemsRecursively();
  45644. }
  45645. }
  45646. return 0;
  45647. }
  45648. int TreeViewItem::getRowNumberInTree() const throw()
  45649. {
  45650. if (parentItem != 0 && ownerView != 0)
  45651. {
  45652. int n = 1 + parentItem->getRowNumberInTree();
  45653. int ourIndex = parentItem->subItems.indexOf (this);
  45654. jassert (ourIndex >= 0);
  45655. while (--ourIndex >= 0)
  45656. n += parentItem->subItems [ourIndex]->getNumRows();
  45657. if (parentItem->parentItem == 0
  45658. && ! ownerView->rootItemVisible)
  45659. --n;
  45660. return n;
  45661. }
  45662. else
  45663. {
  45664. return 0;
  45665. }
  45666. }
  45667. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45668. {
  45669. drawLinesInside = drawLines;
  45670. }
  45671. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45672. {
  45673. if (recurse && isOpen() && subItems.size() > 0)
  45674. return subItems [0];
  45675. if (parentItem != 0)
  45676. {
  45677. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45678. if (nextIndex >= parentItem->subItems.size())
  45679. return parentItem->getNextVisibleItem (false);
  45680. return parentItem->subItems [nextIndex];
  45681. }
  45682. return 0;
  45683. }
  45684. const String TreeViewItem::getItemIdentifierString() const
  45685. {
  45686. String s;
  45687. if (parentItem != 0)
  45688. s = parentItem->getItemIdentifierString();
  45689. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45690. }
  45691. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45692. {
  45693. const String uid (getUniqueName());
  45694. if (uid == identifierString)
  45695. return this;
  45696. if (identifierString.startsWith (uid + T("/")))
  45697. {
  45698. const String remainingPath (identifierString.substring (uid.length() + 1));
  45699. bool wasOpen = isOpen();
  45700. setOpen (true);
  45701. for (int i = subItems.size(); --i >= 0;)
  45702. {
  45703. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45704. if (item != 0)
  45705. return item;
  45706. }
  45707. setOpen (wasOpen);
  45708. }
  45709. return 0;
  45710. }
  45711. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45712. {
  45713. if (e.hasTagName (T("CLOSED")))
  45714. {
  45715. setOpen (false);
  45716. }
  45717. else if (e.hasTagName (T("OPEN")))
  45718. {
  45719. setOpen (true);
  45720. forEachXmlChildElement (e, n)
  45721. {
  45722. const String id (n->getStringAttribute (T("id")));
  45723. for (int i = 0; i < subItems.size(); ++i)
  45724. {
  45725. TreeViewItem* const ti = subItems.getUnchecked(i);
  45726. if (ti->getUniqueName() == id)
  45727. {
  45728. ti->restoreOpennessState (*n);
  45729. break;
  45730. }
  45731. }
  45732. }
  45733. }
  45734. }
  45735. XmlElement* TreeViewItem::getOpennessState() const throw()
  45736. {
  45737. const String name (getUniqueName());
  45738. if (name.isNotEmpty())
  45739. {
  45740. XmlElement* e;
  45741. if (isOpen())
  45742. {
  45743. e = new XmlElement (T("OPEN"));
  45744. for (int i = 0; i < subItems.size(); ++i)
  45745. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45746. }
  45747. else
  45748. {
  45749. e = new XmlElement (T("CLOSED"));
  45750. }
  45751. e->setAttribute (T("id"), name);
  45752. return e;
  45753. }
  45754. else
  45755. {
  45756. // trying to save the openness for an element that has no name - this won't
  45757. // work because it needs the names to identify what to open.
  45758. jassertfalse
  45759. }
  45760. return 0;
  45761. }
  45762. END_JUCE_NAMESPACE
  45763. /*** End of inlined file: juce_TreeView.cpp ***/
  45764. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45765. BEGIN_JUCE_NAMESPACE
  45766. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45767. : fileList (listToShow)
  45768. {
  45769. }
  45770. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45771. {
  45772. }
  45773. FileBrowserListener::~FileBrowserListener()
  45774. {
  45775. }
  45776. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45777. {
  45778. jassert (listener != 0);
  45779. if (listener != 0)
  45780. listeners.add (listener);
  45781. }
  45782. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45783. {
  45784. listeners.removeValue (listener);
  45785. }
  45786. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45787. {
  45788. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45789. for (int i = listeners.size(); --i >= 0;)
  45790. {
  45791. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  45792. if (deletionWatcher.hasBeenDeleted())
  45793. return;
  45794. i = jmin (i, listeners.size() - 1);
  45795. }
  45796. }
  45797. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45798. {
  45799. if (fileList.getDirectory().exists())
  45800. {
  45801. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45802. for (int i = listeners.size(); --i >= 0;)
  45803. {
  45804. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e);
  45805. if (deletionWatcher.hasBeenDeleted())
  45806. return;
  45807. i = jmin (i, listeners.size() - 1);
  45808. }
  45809. }
  45810. }
  45811. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45812. {
  45813. if (fileList.getDirectory().exists())
  45814. {
  45815. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45816. for (int i = listeners.size(); --i >= 0;)
  45817. {
  45818. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file);
  45819. if (deletionWatcher.hasBeenDeleted())
  45820. return;
  45821. i = jmin (i, listeners.size() - 1);
  45822. }
  45823. }
  45824. }
  45825. END_JUCE_NAMESPACE
  45826. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45827. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45828. BEGIN_JUCE_NAMESPACE
  45829. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45830. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45831. Time* creationTime, bool* isReadOnly);
  45832. bool juce_findFileNext (void* handle, String& resultFile,
  45833. bool* isDirectory, bool* isHidden, int64* fileSize,
  45834. Time* modTime, Time* creationTime, bool* isReadOnly);
  45835. void juce_findFileClose (void* handle);
  45836. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45837. TimeSliceThread& thread_)
  45838. : fileFilter (fileFilter_),
  45839. thread (thread_),
  45840. includeDirectories (false),
  45841. includeFiles (false),
  45842. ignoreHiddenFiles (true),
  45843. fileFindHandle (0),
  45844. shouldStop (true)
  45845. {
  45846. }
  45847. DirectoryContentsList::~DirectoryContentsList()
  45848. {
  45849. clear();
  45850. }
  45851. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45852. {
  45853. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45854. }
  45855. const File& DirectoryContentsList::getDirectory() const
  45856. {
  45857. return root;
  45858. }
  45859. void DirectoryContentsList::setDirectory (const File& directory,
  45860. const bool includeDirectories_,
  45861. const bool includeFiles_)
  45862. {
  45863. if (directory != root
  45864. || includeDirectories != includeDirectories_
  45865. || includeFiles != includeFiles_)
  45866. {
  45867. clear();
  45868. root = directory;
  45869. includeDirectories = includeDirectories_;
  45870. includeFiles = includeFiles_;
  45871. refresh();
  45872. }
  45873. }
  45874. void DirectoryContentsList::clear()
  45875. {
  45876. shouldStop = true;
  45877. thread.removeTimeSliceClient (this);
  45878. if (fileFindHandle != 0)
  45879. {
  45880. juce_findFileClose (fileFindHandle);
  45881. fileFindHandle = 0;
  45882. }
  45883. if (files.size() > 0)
  45884. {
  45885. files.clear();
  45886. changed();
  45887. }
  45888. }
  45889. void DirectoryContentsList::refresh()
  45890. {
  45891. clear();
  45892. if (root.isDirectory())
  45893. {
  45894. String fileFound;
  45895. bool fileFoundIsDir, isHidden, isReadOnly;
  45896. int64 fileSize;
  45897. Time modTime, creationTime;
  45898. String path (root.getFullPathName());
  45899. if (! path.endsWithChar (File::separator))
  45900. path += File::separator;
  45901. jassert (fileFindHandle == 0);
  45902. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  45903. &fileFoundIsDir,
  45904. &isHidden,
  45905. &fileSize,
  45906. &modTime,
  45907. &creationTime,
  45908. &isReadOnly);
  45909. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45910. {
  45911. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45912. fileSize, modTime, creationTime, isReadOnly))
  45913. {
  45914. changed();
  45915. }
  45916. }
  45917. shouldStop = false;
  45918. thread.addTimeSliceClient (this);
  45919. }
  45920. }
  45921. int DirectoryContentsList::getNumFiles() const
  45922. {
  45923. return files.size();
  45924. }
  45925. bool DirectoryContentsList::getFileInfo (const int index,
  45926. FileInfo& result) const
  45927. {
  45928. const ScopedLock sl (fileListLock);
  45929. const FileInfo* const info = files [index];
  45930. if (info != 0)
  45931. {
  45932. result = *info;
  45933. return true;
  45934. }
  45935. return false;
  45936. }
  45937. const File DirectoryContentsList::getFile (const int index) const
  45938. {
  45939. const ScopedLock sl (fileListLock);
  45940. const FileInfo* const info = files [index];
  45941. if (info != 0)
  45942. return root.getChildFile (info->filename);
  45943. return File::nonexistent;
  45944. }
  45945. bool DirectoryContentsList::isStillLoading() const
  45946. {
  45947. return fileFindHandle != 0;
  45948. }
  45949. void DirectoryContentsList::changed()
  45950. {
  45951. sendChangeMessage (this);
  45952. }
  45953. bool DirectoryContentsList::useTimeSlice()
  45954. {
  45955. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45956. bool hasChanged = false;
  45957. for (int i = 100; --i >= 0;)
  45958. {
  45959. if (! checkNextFile (hasChanged))
  45960. {
  45961. if (hasChanged)
  45962. changed();
  45963. return false;
  45964. }
  45965. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45966. break;
  45967. }
  45968. if (hasChanged)
  45969. changed();
  45970. return true;
  45971. }
  45972. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45973. {
  45974. if (fileFindHandle != 0)
  45975. {
  45976. String fileFound;
  45977. bool fileFoundIsDir, isHidden, isReadOnly;
  45978. int64 fileSize;
  45979. Time modTime, creationTime;
  45980. if (juce_findFileNext (fileFindHandle, fileFound,
  45981. &fileFoundIsDir, &isHidden,
  45982. &fileSize,
  45983. &modTime,
  45984. &creationTime,
  45985. &isReadOnly))
  45986. {
  45987. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45988. modTime, creationTime, isReadOnly))
  45989. {
  45990. hasChanged = true;
  45991. }
  45992. return true;
  45993. }
  45994. else
  45995. {
  45996. juce_findFileClose (fileFindHandle);
  45997. fileFindHandle = 0;
  45998. }
  45999. }
  46000. return false;
  46001. }
  46002. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  46003. const DirectoryContentsList::FileInfo* const second)
  46004. {
  46005. #if JUCE_WINDOWS
  46006. if (first->isDirectory != second->isDirectory)
  46007. return first->isDirectory ? -1 : 1;
  46008. #endif
  46009. return first->filename.compareIgnoreCase (second->filename);
  46010. }
  46011. bool DirectoryContentsList::addFile (const String& filename,
  46012. const bool isDir,
  46013. const bool isHidden,
  46014. const int64 fileSize,
  46015. const Time& modTime,
  46016. const Time& creationTime,
  46017. const bool isReadOnly)
  46018. {
  46019. if (filename == T("..")
  46020. || filename == T(".")
  46021. || (ignoreHiddenFiles && isHidden))
  46022. return false;
  46023. const File file (root.getChildFile (filename));
  46024. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  46025. && (fileFilter == 0
  46026. || ((! isDir) && fileFilter->isFileSuitable (file))
  46027. || (isDir && fileFilter->isDirectorySuitable (file))))
  46028. {
  46029. ScopedPointer <FileInfo> info (new FileInfo());
  46030. info->filename = filename;
  46031. info->fileSize = fileSize;
  46032. info->modificationTime = modTime;
  46033. info->creationTime = creationTime;
  46034. info->isDirectory = isDir;
  46035. info->isReadOnly = isReadOnly;
  46036. const ScopedLock sl (fileListLock);
  46037. for (int i = files.size(); --i >= 0;)
  46038. if (files.getUnchecked(i)->filename == info->filename)
  46039. return false;
  46040. files.addSorted (*this, info.release());
  46041. return true;
  46042. }
  46043. return false;
  46044. }
  46045. END_JUCE_NAMESPACE
  46046. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  46047. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  46048. BEGIN_JUCE_NAMESPACE
  46049. FileBrowserComponent::FileBrowserComponent (int flags_,
  46050. const File& initialFileOrDirectory,
  46051. const FileFilter* fileFilter_,
  46052. FilePreviewComponent* previewComp_)
  46053. : FileFilter (String::empty),
  46054. fileFilter (fileFilter_),
  46055. flags (flags_),
  46056. previewComp (previewComp_),
  46057. thread ("Juce FileBrowser")
  46058. {
  46059. // You need to specify one or other of the open/save flags..
  46060. jassert ((flags & (saveMode | openMode)) != 0);
  46061. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  46062. // You need to specify at least one of these flags..
  46063. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  46064. String filename;
  46065. if (initialFileOrDirectory == File::nonexistent)
  46066. {
  46067. currentRoot = File::getCurrentWorkingDirectory();
  46068. }
  46069. else if (initialFileOrDirectory.isDirectory())
  46070. {
  46071. currentRoot = initialFileOrDirectory;
  46072. }
  46073. else
  46074. {
  46075. chosenFiles.add (initialFileOrDirectory);
  46076. currentRoot = initialFileOrDirectory.getParentDirectory();
  46077. filename = initialFileOrDirectory.getFileName();
  46078. }
  46079. fileList = new DirectoryContentsList (this, thread);
  46080. if ((flags & useTreeView) != 0)
  46081. {
  46082. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  46083. if ((flags & canSelectMultipleItems) != 0)
  46084. tree->setMultiSelectEnabled (true);
  46085. addAndMakeVisible (tree);
  46086. fileListComponent = tree;
  46087. }
  46088. else
  46089. {
  46090. FileListComponent* const list = new FileListComponent (*fileList);
  46091. list->setOutlineThickness (1);
  46092. if ((flags & canSelectMultipleItems) != 0)
  46093. list->setMultipleSelectionEnabled (true);
  46094. addAndMakeVisible (list);
  46095. fileListComponent = list;
  46096. }
  46097. fileListComponent->addListener (this);
  46098. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  46099. currentPathBox->setEditableText (true);
  46100. StringArray rootNames, rootPaths;
  46101. const BitArray separators (getRoots (rootNames, rootPaths));
  46102. for (int i = 0; i < rootNames.size(); ++i)
  46103. {
  46104. if (separators [i])
  46105. currentPathBox->addSeparator();
  46106. currentPathBox->addItem (rootNames[i], i + 1);
  46107. }
  46108. currentPathBox->addSeparator();
  46109. currentPathBox->addListener (this);
  46110. addAndMakeVisible (filenameBox = new TextEditor());
  46111. filenameBox->setMultiLine (false);
  46112. filenameBox->setSelectAllWhenFocused (true);
  46113. filenameBox->setText (filename, false);
  46114. filenameBox->addListener (this);
  46115. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  46116. Label* label = new Label ("f", TRANS("file:"));
  46117. addAndMakeVisible (label);
  46118. label->attachToComponent (filenameBox, true);
  46119. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  46120. goUpButton->addButtonListener (this);
  46121. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  46122. if (previewComp != 0)
  46123. addAndMakeVisible (previewComp);
  46124. setRoot (currentRoot);
  46125. thread.startThread (4);
  46126. }
  46127. FileBrowserComponent::~FileBrowserComponent()
  46128. {
  46129. if (previewComp != 0)
  46130. removeChildComponent (previewComp);
  46131. deleteAllChildren();
  46132. fileList = 0;
  46133. thread.stopThread (10000);
  46134. }
  46135. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  46136. {
  46137. jassert (newListener != 0)
  46138. if (newListener != 0)
  46139. listeners.add (newListener);
  46140. }
  46141. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  46142. {
  46143. listeners.removeValue (listener);
  46144. }
  46145. bool FileBrowserComponent::isSaveMode() const throw()
  46146. {
  46147. return (flags & saveMode) != 0;
  46148. }
  46149. int FileBrowserComponent::getNumSelectedFiles() const throw()
  46150. {
  46151. if (chosenFiles.size() == 0 && currentFileIsValid())
  46152. return 1;
  46153. return chosenFiles.size();
  46154. }
  46155. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  46156. {
  46157. if (! filenameBox->isReadOnly())
  46158. return currentRoot.getChildFile (filenameBox->getText());
  46159. else
  46160. return chosenFiles[index];
  46161. }
  46162. bool FileBrowserComponent::currentFileIsValid() const
  46163. {
  46164. if (isSaveMode())
  46165. return ! getSelectedFile (0).isDirectory();
  46166. else
  46167. return getSelectedFile (0).exists();
  46168. }
  46169. const File FileBrowserComponent::getHighlightedFile() const throw()
  46170. {
  46171. return fileListComponent->getSelectedFile (0);
  46172. }
  46173. bool FileBrowserComponent::isFileSuitable (const File& file) const
  46174. {
  46175. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  46176. : false;
  46177. }
  46178. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  46179. {
  46180. return true;
  46181. }
  46182. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  46183. {
  46184. if (f.isDirectory())
  46185. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  46186. return (flags & canSelectFiles) != 0 && f.exists()
  46187. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  46188. }
  46189. const File FileBrowserComponent::getRoot() const
  46190. {
  46191. return currentRoot;
  46192. }
  46193. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  46194. {
  46195. if (currentRoot != newRootDirectory)
  46196. {
  46197. fileListComponent->scrollToTop();
  46198. String path (newRootDirectory.getFullPathName());
  46199. if (path.isEmpty())
  46200. path += File::separator;
  46201. StringArray rootNames, rootPaths;
  46202. getRoots (rootNames, rootPaths);
  46203. if (! rootPaths.contains (path, true))
  46204. {
  46205. bool alreadyListed = false;
  46206. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  46207. {
  46208. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  46209. {
  46210. alreadyListed = true;
  46211. break;
  46212. }
  46213. }
  46214. if (! alreadyListed)
  46215. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  46216. }
  46217. }
  46218. currentRoot = newRootDirectory;
  46219. fileList->setDirectory (currentRoot, true, true);
  46220. String currentRootName (currentRoot.getFullPathName());
  46221. if (currentRootName.isEmpty())
  46222. currentRootName += File::separator;
  46223. currentPathBox->setText (currentRootName, true);
  46224. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  46225. && currentRoot.getParentDirectory() != currentRoot);
  46226. }
  46227. void FileBrowserComponent::goUp()
  46228. {
  46229. setRoot (getRoot().getParentDirectory());
  46230. }
  46231. void FileBrowserComponent::refresh()
  46232. {
  46233. fileList->refresh();
  46234. }
  46235. const String FileBrowserComponent::getActionVerb() const
  46236. {
  46237. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  46238. }
  46239. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  46240. {
  46241. return previewComp;
  46242. }
  46243. void FileBrowserComponent::resized()
  46244. {
  46245. getLookAndFeel()
  46246. .layoutFileBrowserComponent (*this, fileListComponent,
  46247. previewComp, currentPathBox,
  46248. filenameBox, goUpButton);
  46249. }
  46250. void FileBrowserComponent::sendListenerChangeMessage()
  46251. {
  46252. ComponentDeletionWatcher deletionWatcher (this);
  46253. if (previewComp != 0)
  46254. previewComp->selectedFileChanged (getSelectedFile (0));
  46255. jassert (! deletionWatcher.hasBeenDeleted());
  46256. for (int i = listeners.size(); --i >= 0;)
  46257. {
  46258. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  46259. if (deletionWatcher.hasBeenDeleted())
  46260. return;
  46261. i = jmin (i, listeners.size() - 1);
  46262. }
  46263. }
  46264. void FileBrowserComponent::selectionChanged()
  46265. {
  46266. StringArray newFilenames;
  46267. bool resetChosenFiles = true;
  46268. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  46269. {
  46270. const File f (fileListComponent->getSelectedFile (i));
  46271. if (isFileOrDirSuitable (f))
  46272. {
  46273. if (resetChosenFiles)
  46274. {
  46275. chosenFiles.clear();
  46276. resetChosenFiles = false;
  46277. }
  46278. chosenFiles.add (f);
  46279. newFilenames.add (f.getRelativePathFrom (getRoot()));
  46280. }
  46281. }
  46282. if (newFilenames.size() > 0)
  46283. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  46284. sendListenerChangeMessage();
  46285. }
  46286. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  46287. {
  46288. ComponentDeletionWatcher deletionWatcher (this);
  46289. for (int i = listeners.size(); --i >= 0;)
  46290. {
  46291. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e);
  46292. if (deletionWatcher.hasBeenDeleted())
  46293. return;
  46294. i = jmin (i, listeners.size() - 1);
  46295. }
  46296. }
  46297. void FileBrowserComponent::fileDoubleClicked (const File& f)
  46298. {
  46299. if (f.isDirectory())
  46300. {
  46301. setRoot (f);
  46302. }
  46303. else
  46304. {
  46305. ComponentDeletionWatcher deletionWatcher (this);
  46306. for (int i = listeners.size(); --i >= 0;)
  46307. {
  46308. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f);
  46309. if (deletionWatcher.hasBeenDeleted())
  46310. return;
  46311. i = jmin (i, listeners.size() - 1);
  46312. }
  46313. }
  46314. }
  46315. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  46316. {
  46317. #if JUCE_LINUX || JUCE_WINDOWS
  46318. if (key.getModifiers().isCommandDown()
  46319. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  46320. {
  46321. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  46322. fileList->refresh();
  46323. return true;
  46324. }
  46325. #endif
  46326. return false;
  46327. }
  46328. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  46329. {
  46330. sendListenerChangeMessage();
  46331. }
  46332. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  46333. {
  46334. if (filenameBox->getText().containsChar (File::separator))
  46335. {
  46336. const File f (currentRoot.getChildFile (filenameBox->getText()));
  46337. if (f.isDirectory())
  46338. {
  46339. setRoot (f);
  46340. chosenFiles.clear();
  46341. filenameBox->setText (String::empty);
  46342. }
  46343. else
  46344. {
  46345. setRoot (f.getParentDirectory());
  46346. chosenFiles.clear();
  46347. chosenFiles.add (f);
  46348. filenameBox->setText (f.getFileName());
  46349. }
  46350. }
  46351. else
  46352. {
  46353. fileDoubleClicked (getSelectedFile (0));
  46354. }
  46355. }
  46356. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46357. {
  46358. }
  46359. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46360. {
  46361. if (! isSaveMode())
  46362. selectionChanged();
  46363. }
  46364. void FileBrowserComponent::buttonClicked (Button*)
  46365. {
  46366. goUp();
  46367. }
  46368. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46369. {
  46370. const String newText (currentPathBox->getText().trim().unquoted());
  46371. if (newText.isNotEmpty())
  46372. {
  46373. const int index = currentPathBox->getSelectedId() - 1;
  46374. StringArray rootNames, rootPaths;
  46375. getRoots (rootNames, rootPaths);
  46376. if (rootPaths [index].isNotEmpty())
  46377. {
  46378. setRoot (File (rootPaths [index]));
  46379. }
  46380. else
  46381. {
  46382. File f (newText);
  46383. for (;;)
  46384. {
  46385. if (f.isDirectory())
  46386. {
  46387. setRoot (f);
  46388. break;
  46389. }
  46390. if (f.getParentDirectory() == f)
  46391. break;
  46392. f = f.getParentDirectory();
  46393. }
  46394. }
  46395. }
  46396. }
  46397. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46398. {
  46399. BitArray separators;
  46400. #if JUCE_WINDOWS
  46401. Array<File> roots;
  46402. File::findFileSystemRoots (roots);
  46403. rootPaths.clear();
  46404. for (int i = 0; i < roots.size(); ++i)
  46405. {
  46406. const File& drive = roots.getReference(i);
  46407. String name (drive.getFullPathName());
  46408. rootPaths.add (name);
  46409. if (drive.isOnHardDisk())
  46410. {
  46411. String volume (drive.getVolumeLabel());
  46412. if (volume.isEmpty())
  46413. volume = TRANS("Hard Drive");
  46414. name << " [" << drive.getVolumeLabel() << ']';
  46415. }
  46416. else if (drive.isOnCDRomDrive())
  46417. {
  46418. name << TRANS(" [CD/DVD drive]");
  46419. }
  46420. rootNames.add (name);
  46421. }
  46422. separators.setBit (rootPaths.size());
  46423. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46424. rootNames.add ("Documents");
  46425. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46426. rootNames.add ("Desktop");
  46427. #endif
  46428. #if JUCE_MAC
  46429. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46430. rootNames.add ("Home folder");
  46431. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46432. rootNames.add ("Documents");
  46433. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46434. rootNames.add ("Desktop");
  46435. separators.setBit (rootPaths.size());
  46436. Array <File> volumes;
  46437. File vol ("/Volumes");
  46438. vol.findChildFiles (volumes, File::findDirectories, false);
  46439. for (int i = 0; i < volumes.size(); ++i)
  46440. {
  46441. const File& volume = volumes.getReference(i);
  46442. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46443. {
  46444. rootPaths.add (volume.getFullPathName());
  46445. rootNames.add (volume.getFileName());
  46446. }
  46447. }
  46448. #endif
  46449. #if JUCE_LINUX
  46450. rootPaths.add ("/");
  46451. rootNames.add ("/");
  46452. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46453. rootNames.add ("Home folder");
  46454. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46455. rootNames.add ("Desktop");
  46456. #endif
  46457. return separators;
  46458. }
  46459. END_JUCE_NAMESPACE
  46460. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46461. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46462. BEGIN_JUCE_NAMESPACE
  46463. FileChooser::FileChooser (const String& chooserBoxTitle,
  46464. const File& currentFileOrDirectory,
  46465. const String& fileFilters,
  46466. const bool useNativeDialogBox_)
  46467. : title (chooserBoxTitle),
  46468. filters (fileFilters),
  46469. startingFile (currentFileOrDirectory),
  46470. useNativeDialogBox (useNativeDialogBox_)
  46471. {
  46472. #if JUCE_LINUX
  46473. useNativeDialogBox = false;
  46474. #endif
  46475. if (! fileFilters.containsNonWhitespaceChars())
  46476. filters = T("*");
  46477. }
  46478. FileChooser::~FileChooser()
  46479. {
  46480. }
  46481. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46482. {
  46483. return showDialog (false, true, false, false, false, previewComponent);
  46484. }
  46485. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46486. {
  46487. return showDialog (false, true, false, false, true, previewComponent);
  46488. }
  46489. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46490. {
  46491. return showDialog (true, true, false, false, true, previewComponent);
  46492. }
  46493. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46494. {
  46495. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46496. }
  46497. bool FileChooser::browseForDirectory()
  46498. {
  46499. return showDialog (true, false, false, false, false, 0);
  46500. }
  46501. const File FileChooser::getResult() const
  46502. {
  46503. // if you've used a multiple-file select, you should use the getResults() method
  46504. // to retrieve all the files that were chosen.
  46505. jassert (results.size() <= 1);
  46506. return results.getFirst();
  46507. }
  46508. const Array<File>& FileChooser::getResults() const
  46509. {
  46510. return results;
  46511. }
  46512. bool FileChooser::showDialog (const bool selectsDirectories,
  46513. const bool selectsFiles,
  46514. const bool isSave,
  46515. const bool warnAboutOverwritingExistingFiles,
  46516. const bool selectMultipleFiles,
  46517. FilePreviewComponent* const previewComponent)
  46518. {
  46519. ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
  46520. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  46521. if (currentlyFocused != 0)
  46522. currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);
  46523. results.clear();
  46524. // the preview component needs to be the right size before you pass it in here..
  46525. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46526. && previewComponent->getHeight() > 10));
  46527. #if JUCE_WINDOWS
  46528. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46529. #elif JUCE_MAC
  46530. if (useNativeDialogBox && (previewComponent == 0))
  46531. #else
  46532. if (false)
  46533. #endif
  46534. {
  46535. showPlatformDialog (results, title, startingFile, filters,
  46536. selectsDirectories, selectsFiles, isSave,
  46537. warnAboutOverwritingExistingFiles,
  46538. selectMultipleFiles,
  46539. previewComponent);
  46540. }
  46541. else
  46542. {
  46543. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46544. selectsDirectories ? "*" : String::empty,
  46545. String::empty);
  46546. int flags = isSave ? FileBrowserComponent::saveMode
  46547. : FileBrowserComponent::openMode;
  46548. if (selectsFiles)
  46549. flags |= FileBrowserComponent::canSelectFiles;
  46550. if (selectsDirectories)
  46551. flags |= FileBrowserComponent::canSelectDirectories;
  46552. if (selectMultipleFiles)
  46553. flags |= FileBrowserComponent::canSelectMultipleItems;
  46554. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46555. FileChooserDialogBox box (title, String::empty,
  46556. browserComponent,
  46557. warnAboutOverwritingExistingFiles,
  46558. browserComponent.findColour (AlertWindow::backgroundColourId));
  46559. if (box.show())
  46560. {
  46561. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46562. results.add (browserComponent.getSelectedFile (i));
  46563. }
  46564. }
  46565. if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
  46566. currentlyFocused->grabKeyboardFocus();
  46567. return results.size() > 0;
  46568. }
  46569. FilePreviewComponent::FilePreviewComponent()
  46570. {
  46571. }
  46572. FilePreviewComponent::~FilePreviewComponent()
  46573. {
  46574. }
  46575. END_JUCE_NAMESPACE
  46576. /*** End of inlined file: juce_FileChooser.cpp ***/
  46577. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46578. BEGIN_JUCE_NAMESPACE
  46579. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46580. const String& instructions,
  46581. FileBrowserComponent& chooserComponent,
  46582. const bool warnAboutOverwritingExistingFiles_,
  46583. const Colour& backgroundColour)
  46584. : ResizableWindow (name, backgroundColour, true),
  46585. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46586. {
  46587. content = new ContentComponent();
  46588. content->setName (name);
  46589. content->instructions = instructions;
  46590. content->chooserComponent = &chooserComponent;
  46591. content->addAndMakeVisible (&chooserComponent);
  46592. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46593. content->addAndMakeVisible (content->okButton);
  46594. content->okButton->addButtonListener (this);
  46595. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46596. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46597. content->cancelButton = new TextButton (TRANS("Cancel"));
  46598. content->addAndMakeVisible (content->cancelButton);
  46599. content->cancelButton->addButtonListener (this);
  46600. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46601. setContentComponent (content);
  46602. setResizable (true, true);
  46603. setResizeLimits (300, 300, 1200, 1000);
  46604. content->chooserComponent->addListener (this);
  46605. }
  46606. FileChooserDialogBox::~FileChooserDialogBox()
  46607. {
  46608. content->chooserComponent->removeListener (this);
  46609. }
  46610. bool FileChooserDialogBox::show (int w, int h)
  46611. {
  46612. if (w <= 0)
  46613. {
  46614. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46615. if (previewComp != 0)
  46616. w = 400 + previewComp->getWidth();
  46617. else
  46618. w = 600;
  46619. }
  46620. if (h <= 0)
  46621. h = 500;
  46622. centreWithSize (w, h);
  46623. const bool ok = (runModalLoop() != 0);
  46624. setVisible (false);
  46625. return ok;
  46626. }
  46627. void FileChooserDialogBox::buttonClicked (Button* button)
  46628. {
  46629. if (button == content->okButton)
  46630. {
  46631. if (warnAboutOverwritingExistingFiles
  46632. && content->chooserComponent->isSaveMode()
  46633. && content->chooserComponent->getSelectedFile(0).exists())
  46634. {
  46635. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46636. TRANS("File already exists"),
  46637. TRANS("There's already a file called:\n\n")
  46638. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46639. + T("\n\nAre you sure you want to overwrite it?"),
  46640. TRANS("overwrite"),
  46641. TRANS("cancel")))
  46642. {
  46643. return;
  46644. }
  46645. }
  46646. exitModalState (1);
  46647. }
  46648. else if (button == content->cancelButton)
  46649. closeButtonPressed();
  46650. }
  46651. void FileChooserDialogBox::closeButtonPressed()
  46652. {
  46653. setVisible (false);
  46654. }
  46655. void FileChooserDialogBox::selectionChanged()
  46656. {
  46657. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46658. }
  46659. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46660. {
  46661. }
  46662. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46663. {
  46664. selectionChanged();
  46665. content->okButton->triggerClick();
  46666. }
  46667. FileChooserDialogBox::ContentComponent::ContentComponent()
  46668. {
  46669. setInterceptsMouseClicks (false, true);
  46670. }
  46671. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46672. {
  46673. delete okButton;
  46674. delete cancelButton;
  46675. }
  46676. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46677. {
  46678. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46679. text.draw (g);
  46680. }
  46681. void FileChooserDialogBox::ContentComponent::resized()
  46682. {
  46683. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46684. float left, top, right, bottom;
  46685. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46686. const int y = roundToInt (bottom) + 10;
  46687. const int buttonHeight = 26;
  46688. const int buttonY = getHeight() - buttonHeight - 8;
  46689. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46690. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46691. proportionOfWidth (0.2f), buttonHeight);
  46692. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46693. proportionOfWidth (0.2f), buttonHeight);
  46694. }
  46695. END_JUCE_NAMESPACE
  46696. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46697. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46698. BEGIN_JUCE_NAMESPACE
  46699. FileFilter::FileFilter (const String& filterDescription)
  46700. : description (filterDescription)
  46701. {
  46702. }
  46703. FileFilter::~FileFilter()
  46704. {
  46705. }
  46706. const String& FileFilter::getDescription() const throw()
  46707. {
  46708. return description;
  46709. }
  46710. END_JUCE_NAMESPACE
  46711. /*** End of inlined file: juce_FileFilter.cpp ***/
  46712. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46713. BEGIN_JUCE_NAMESPACE
  46714. Image* juce_createIconForFile (const File& file);
  46715. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46716. : ListBox (String::empty, 0),
  46717. DirectoryContentsDisplayComponent (listToShow)
  46718. {
  46719. setModel (this);
  46720. fileList.addChangeListener (this);
  46721. }
  46722. FileListComponent::~FileListComponent()
  46723. {
  46724. fileList.removeChangeListener (this);
  46725. deleteAllChildren();
  46726. }
  46727. int FileListComponent::getNumSelectedFiles() const
  46728. {
  46729. return getNumSelectedRows();
  46730. }
  46731. const File FileListComponent::getSelectedFile (int index) const
  46732. {
  46733. return fileList.getFile (getSelectedRow (index));
  46734. }
  46735. void FileListComponent::scrollToTop()
  46736. {
  46737. getVerticalScrollBar()->setCurrentRangeStart (0);
  46738. }
  46739. void FileListComponent::changeListenerCallback (void*)
  46740. {
  46741. updateContent();
  46742. if (lastDirectory != fileList.getDirectory())
  46743. {
  46744. lastDirectory = fileList.getDirectory();
  46745. deselectAllRows();
  46746. }
  46747. }
  46748. class FileListItemComponent : public Component,
  46749. public TimeSliceClient,
  46750. public AsyncUpdater
  46751. {
  46752. public:
  46753. FileListItemComponent (FileListComponent& owner_,
  46754. TimeSliceThread& thread_) throw()
  46755. : owner (owner_),
  46756. thread (thread_),
  46757. icon (0)
  46758. {
  46759. }
  46760. ~FileListItemComponent() throw()
  46761. {
  46762. thread.removeTimeSliceClient (this);
  46763. clearIcon();
  46764. }
  46765. void paint (Graphics& g)
  46766. {
  46767. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46768. file.getFileName(),
  46769. icon,
  46770. fileSize, modTime,
  46771. isDirectory, highlighted,
  46772. index);
  46773. }
  46774. void mouseDown (const MouseEvent& e)
  46775. {
  46776. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46777. owner.sendMouseClickMessage (file, e);
  46778. }
  46779. void mouseDoubleClick (const MouseEvent&)
  46780. {
  46781. owner.sendDoubleClickMessage (file);
  46782. }
  46783. void update (const File& root,
  46784. const DirectoryContentsList::FileInfo* const fileInfo,
  46785. const int index_,
  46786. const bool highlighted_) throw()
  46787. {
  46788. thread.removeTimeSliceClient (this);
  46789. if (highlighted_ != highlighted
  46790. || index_ != index)
  46791. {
  46792. index = index_;
  46793. highlighted = highlighted_;
  46794. repaint();
  46795. }
  46796. File newFile;
  46797. String newFileSize;
  46798. String newModTime;
  46799. if (fileInfo != 0)
  46800. {
  46801. newFile = root.getChildFile (fileInfo->filename);
  46802. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46803. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46804. }
  46805. if (newFile != file
  46806. || fileSize != newFileSize
  46807. || modTime != newModTime)
  46808. {
  46809. file = newFile;
  46810. fileSize = newFileSize;
  46811. modTime = newModTime;
  46812. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46813. repaint();
  46814. clearIcon();
  46815. }
  46816. if (file != File::nonexistent
  46817. && icon == 0 && ! isDirectory)
  46818. {
  46819. updateIcon (true);
  46820. if (icon == 0)
  46821. thread.addTimeSliceClient (this);
  46822. }
  46823. }
  46824. bool useTimeSlice()
  46825. {
  46826. updateIcon (false);
  46827. return false;
  46828. }
  46829. void handleAsyncUpdate()
  46830. {
  46831. repaint();
  46832. }
  46833. juce_UseDebuggingNewOperator
  46834. private:
  46835. FileListComponent& owner;
  46836. TimeSliceThread& thread;
  46837. bool highlighted;
  46838. int index;
  46839. File file;
  46840. String fileSize;
  46841. String modTime;
  46842. Image* icon;
  46843. bool isDirectory;
  46844. void clearIcon() throw()
  46845. {
  46846. ImageCache::release (icon);
  46847. icon = 0;
  46848. }
  46849. void updateIcon (const bool onlyUpdateIfCached) throw()
  46850. {
  46851. if (icon == 0)
  46852. {
  46853. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46854. Image* im = ImageCache::getFromHashCode (hashCode);
  46855. if (im == 0 && ! onlyUpdateIfCached)
  46856. {
  46857. im = juce_createIconForFile (file);
  46858. if (im != 0)
  46859. ImageCache::addImageToCache (im, hashCode);
  46860. }
  46861. if (im != 0)
  46862. {
  46863. icon = im;
  46864. triggerAsyncUpdate();
  46865. }
  46866. }
  46867. }
  46868. };
  46869. int FileListComponent::getNumRows()
  46870. {
  46871. return fileList.getNumFiles();
  46872. }
  46873. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46874. {
  46875. }
  46876. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46877. {
  46878. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46879. if (comp == 0)
  46880. {
  46881. delete existingComponentToUpdate;
  46882. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46883. }
  46884. DirectoryContentsList::FileInfo fileInfo;
  46885. if (fileList.getFileInfo (row, fileInfo))
  46886. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46887. else
  46888. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46889. return comp;
  46890. }
  46891. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46892. {
  46893. sendSelectionChangeMessage();
  46894. }
  46895. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46896. {
  46897. }
  46898. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46899. {
  46900. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46901. }
  46902. END_JUCE_NAMESPACE
  46903. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46904. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46905. BEGIN_JUCE_NAMESPACE
  46906. FilenameComponent::FilenameComponent (const String& name,
  46907. const File& currentFile,
  46908. const bool canEditFilename,
  46909. const bool isDirectory,
  46910. const bool isForSaving,
  46911. const String& fileBrowserWildcard,
  46912. const String& enforcedSuffix_,
  46913. const String& textWhenNothingSelected)
  46914. : Component (name),
  46915. maxRecentFiles (30),
  46916. isDir (isDirectory),
  46917. isSaving (isForSaving),
  46918. isFileDragOver (false),
  46919. wildcard (fileBrowserWildcard),
  46920. enforcedSuffix (enforcedSuffix_)
  46921. {
  46922. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  46923. filenameBox->setEditableText (canEditFilename);
  46924. filenameBox->addListener (this);
  46925. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46926. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46927. browseButton = 0;
  46928. setBrowseButtonText (T("..."));
  46929. setCurrentFile (currentFile, true);
  46930. }
  46931. FilenameComponent::~FilenameComponent()
  46932. {
  46933. deleteAllChildren();
  46934. }
  46935. void FilenameComponent::paintOverChildren (Graphics& g)
  46936. {
  46937. if (isFileDragOver)
  46938. {
  46939. g.setColour (Colours::red.withAlpha (0.2f));
  46940. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46941. }
  46942. }
  46943. void FilenameComponent::resized()
  46944. {
  46945. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46946. }
  46947. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46948. {
  46949. browseButtonText = newBrowseButtonText;
  46950. lookAndFeelChanged();
  46951. }
  46952. void FilenameComponent::lookAndFeelChanged()
  46953. {
  46954. deleteAndZero (browseButton);
  46955. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46956. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46957. resized();
  46958. browseButton->addButtonListener (this);
  46959. }
  46960. void FilenameComponent::setTooltip (const String& newTooltip)
  46961. {
  46962. SettableTooltipClient::setTooltip (newTooltip);
  46963. filenameBox->setTooltip (newTooltip);
  46964. }
  46965. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46966. {
  46967. defaultBrowseFile = newDefaultDirectory;
  46968. }
  46969. void FilenameComponent::buttonClicked (Button*)
  46970. {
  46971. FileChooser fc (TRANS("Choose a new file"),
  46972. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46973. : getCurrentFile(),
  46974. wildcard);
  46975. if (isDir ? fc.browseForDirectory()
  46976. : (isSaving ? fc.browseForFileToSave (false)
  46977. : fc.browseForFileToOpen()))
  46978. {
  46979. setCurrentFile (fc.getResult(), true);
  46980. }
  46981. }
  46982. void FilenameComponent::comboBoxChanged (ComboBox*)
  46983. {
  46984. setCurrentFile (getCurrentFile(), true);
  46985. }
  46986. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46987. {
  46988. return true;
  46989. }
  46990. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46991. {
  46992. isFileDragOver = false;
  46993. repaint();
  46994. const File f (filenames[0]);
  46995. if (f.exists() && (f.isDirectory() == isDir))
  46996. setCurrentFile (f, true);
  46997. }
  46998. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46999. {
  47000. isFileDragOver = true;
  47001. repaint();
  47002. }
  47003. void FilenameComponent::fileDragExit (const StringArray&)
  47004. {
  47005. isFileDragOver = false;
  47006. repaint();
  47007. }
  47008. const File FilenameComponent::getCurrentFile() const
  47009. {
  47010. File f (filenameBox->getText());
  47011. if (enforcedSuffix.isNotEmpty())
  47012. f = f.withFileExtension (enforcedSuffix);
  47013. return f;
  47014. }
  47015. void FilenameComponent::setCurrentFile (File newFile,
  47016. const bool addToRecentlyUsedList,
  47017. const bool sendChangeNotification)
  47018. {
  47019. if (enforcedSuffix.isNotEmpty())
  47020. newFile = newFile.withFileExtension (enforcedSuffix);
  47021. if (newFile.getFullPathName() != lastFilename)
  47022. {
  47023. lastFilename = newFile.getFullPathName();
  47024. if (addToRecentlyUsedList)
  47025. addRecentlyUsedFile (newFile);
  47026. filenameBox->setText (lastFilename, true);
  47027. if (sendChangeNotification)
  47028. triggerAsyncUpdate();
  47029. }
  47030. }
  47031. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  47032. {
  47033. filenameBox->setEditableText (shouldBeEditable);
  47034. }
  47035. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  47036. {
  47037. StringArray names;
  47038. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  47039. names.add (filenameBox->getItemText (i));
  47040. return names;
  47041. }
  47042. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  47043. {
  47044. if (filenames != getRecentlyUsedFilenames())
  47045. {
  47046. filenameBox->clear();
  47047. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  47048. filenameBox->addItem (filenames[i], i + 1);
  47049. }
  47050. }
  47051. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  47052. {
  47053. maxRecentFiles = jmax (1, newMaximum);
  47054. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  47055. }
  47056. void FilenameComponent::addRecentlyUsedFile (const File& file)
  47057. {
  47058. StringArray files (getRecentlyUsedFilenames());
  47059. if (file.getFullPathName().isNotEmpty())
  47060. {
  47061. files.removeString (file.getFullPathName(), true);
  47062. files.insert (0, file.getFullPathName());
  47063. setRecentlyUsedFilenames (files);
  47064. }
  47065. }
  47066. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  47067. {
  47068. jassert (listener != 0);
  47069. if (listener != 0)
  47070. listeners.add (listener);
  47071. }
  47072. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  47073. {
  47074. listeners.removeValue (listener);
  47075. }
  47076. void FilenameComponent::handleAsyncUpdate()
  47077. {
  47078. for (int i = listeners.size(); --i >= 0;)
  47079. {
  47080. ((FilenameComponentListener*) listeners.getUnchecked (i))->filenameComponentChanged (this);
  47081. i = jmin (i, listeners.size());
  47082. }
  47083. }
  47084. END_JUCE_NAMESPACE
  47085. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  47086. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47087. BEGIN_JUCE_NAMESPACE
  47088. FileSearchPathListComponent::FileSearchPathListComponent()
  47089. {
  47090. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  47091. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  47092. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  47093. listBox->setOutlineThickness (1);
  47094. addAndMakeVisible (addButton = new TextButton ("+"));
  47095. addButton->addButtonListener (this);
  47096. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47097. addAndMakeVisible (removeButton = new TextButton ("-"));
  47098. removeButton->addButtonListener (this);
  47099. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47100. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  47101. changeButton->addButtonListener (this);
  47102. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47103. upButton->addButtonListener (this);
  47104. {
  47105. Path arrowPath;
  47106. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  47107. DrawablePath arrowImage;
  47108. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47109. arrowImage.setPath (arrowPath);
  47110. ((DrawableButton*) upButton)->setImages (&arrowImage);
  47111. }
  47112. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47113. downButton->addButtonListener (this);
  47114. {
  47115. Path arrowPath;
  47116. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  47117. DrawablePath arrowImage;
  47118. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47119. arrowImage.setPath (arrowPath);
  47120. ((DrawableButton*) downButton)->setImages (&arrowImage);
  47121. }
  47122. updateButtons();
  47123. }
  47124. FileSearchPathListComponent::~FileSearchPathListComponent()
  47125. {
  47126. deleteAllChildren();
  47127. }
  47128. void FileSearchPathListComponent::updateButtons() throw()
  47129. {
  47130. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  47131. removeButton->setEnabled (anythingSelected);
  47132. changeButton->setEnabled (anythingSelected);
  47133. upButton->setEnabled (anythingSelected);
  47134. downButton->setEnabled (anythingSelected);
  47135. }
  47136. void FileSearchPathListComponent::changed() throw()
  47137. {
  47138. listBox->updateContent();
  47139. listBox->repaint();
  47140. updateButtons();
  47141. }
  47142. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  47143. {
  47144. if (newPath.toString() != path.toString())
  47145. {
  47146. path = newPath;
  47147. changed();
  47148. }
  47149. }
  47150. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47151. {
  47152. defaultBrowseTarget = newDefaultDirectory;
  47153. }
  47154. int FileSearchPathListComponent::getNumRows()
  47155. {
  47156. return path.getNumPaths();
  47157. }
  47158. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  47159. {
  47160. if (rowIsSelected)
  47161. g.fillAll (findColour (TextEditor::highlightColourId));
  47162. g.setColour (findColour (ListBox::textColourId));
  47163. Font f (height * 0.7f);
  47164. f.setHorizontalScale (0.9f);
  47165. g.setFont (f);
  47166. g.drawText (path [rowNumber].getFullPathName(),
  47167. 4, 0, width - 6, height,
  47168. Justification::centredLeft, true);
  47169. }
  47170. void FileSearchPathListComponent::deleteKeyPressed (int row)
  47171. {
  47172. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  47173. {
  47174. path.remove (row);
  47175. changed();
  47176. }
  47177. }
  47178. void FileSearchPathListComponent::returnKeyPressed (int row)
  47179. {
  47180. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  47181. if (chooser.browseForDirectory())
  47182. {
  47183. path.remove (row);
  47184. path.add (chooser.getResult(), row);
  47185. changed();
  47186. }
  47187. }
  47188. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  47189. {
  47190. returnKeyPressed (row);
  47191. }
  47192. void FileSearchPathListComponent::selectedRowsChanged (int)
  47193. {
  47194. updateButtons();
  47195. }
  47196. void FileSearchPathListComponent::paint (Graphics& g)
  47197. {
  47198. g.fillAll (findColour (backgroundColourId));
  47199. }
  47200. void FileSearchPathListComponent::resized()
  47201. {
  47202. const int buttonH = 22;
  47203. const int buttonY = getHeight() - buttonH - 4;
  47204. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  47205. addButton->setBounds (2, buttonY, buttonH, buttonH);
  47206. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  47207. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  47208. downButton->setSize (buttonH * 2, buttonH);
  47209. upButton->setSize (buttonH * 2, buttonH);
  47210. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  47211. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  47212. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  47213. }
  47214. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  47215. {
  47216. return true;
  47217. }
  47218. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  47219. {
  47220. for (int i = filenames.size(); --i >= 0;)
  47221. {
  47222. const File f (filenames[i]);
  47223. if (f.isDirectory())
  47224. {
  47225. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  47226. path.add (f, row);
  47227. changed();
  47228. }
  47229. }
  47230. }
  47231. void FileSearchPathListComponent::buttonClicked (Button* button)
  47232. {
  47233. const int currentRow = listBox->getSelectedRow();
  47234. if (button == removeButton)
  47235. {
  47236. deleteKeyPressed (currentRow);
  47237. }
  47238. else if (button == addButton)
  47239. {
  47240. File start (defaultBrowseTarget);
  47241. if (start == File::nonexistent)
  47242. start = path [0];
  47243. if (start == File::nonexistent)
  47244. start = File::getCurrentWorkingDirectory();
  47245. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  47246. if (chooser.browseForDirectory())
  47247. {
  47248. path.add (chooser.getResult(), currentRow);
  47249. }
  47250. }
  47251. else if (button == changeButton)
  47252. {
  47253. returnKeyPressed (currentRow);
  47254. }
  47255. else if (button == upButton)
  47256. {
  47257. if (currentRow > 0 && currentRow < path.getNumPaths())
  47258. {
  47259. const File f (path[currentRow]);
  47260. path.remove (currentRow);
  47261. path.add (f, currentRow - 1);
  47262. listBox->selectRow (currentRow - 1);
  47263. }
  47264. }
  47265. else if (button == downButton)
  47266. {
  47267. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  47268. {
  47269. const File f (path[currentRow]);
  47270. path.remove (currentRow);
  47271. path.add (f, currentRow + 1);
  47272. listBox->selectRow (currentRow + 1);
  47273. }
  47274. }
  47275. changed();
  47276. }
  47277. END_JUCE_NAMESPACE
  47278. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47279. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  47280. BEGIN_JUCE_NAMESPACE
  47281. Image* juce_createIconForFile (const File& file);
  47282. class FileListTreeItem : public TreeViewItem,
  47283. public TimeSliceClient,
  47284. public AsyncUpdater,
  47285. public ChangeListener
  47286. {
  47287. public:
  47288. FileListTreeItem (FileTreeComponent& owner_,
  47289. DirectoryContentsList* const parentContentsList_,
  47290. const int indexInContentsList_,
  47291. const File& file_,
  47292. TimeSliceThread& thread_) throw()
  47293. : file (file_),
  47294. owner (owner_),
  47295. parentContentsList (parentContentsList_),
  47296. indexInContentsList (indexInContentsList_),
  47297. subContentsList (0),
  47298. canDeleteSubContentsList (false),
  47299. thread (thread_),
  47300. icon (0)
  47301. {
  47302. DirectoryContentsList::FileInfo fileInfo;
  47303. if (parentContentsList_ != 0
  47304. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  47305. {
  47306. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  47307. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  47308. isDirectory = fileInfo.isDirectory;
  47309. }
  47310. else
  47311. {
  47312. isDirectory = true;
  47313. }
  47314. }
  47315. ~FileListTreeItem() throw()
  47316. {
  47317. thread.removeTimeSliceClient (this);
  47318. clearSubItems();
  47319. ImageCache::release (icon);
  47320. if (canDeleteSubContentsList)
  47321. delete subContentsList;
  47322. }
  47323. bool mightContainSubItems() { return isDirectory; }
  47324. const String getUniqueName() const { return file.getFullPathName(); }
  47325. int getItemHeight() const { return 22; }
  47326. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  47327. void itemOpennessChanged (bool isNowOpen)
  47328. {
  47329. if (isNowOpen)
  47330. {
  47331. clearSubItems();
  47332. isDirectory = file.isDirectory();
  47333. if (isDirectory)
  47334. {
  47335. if (subContentsList == 0)
  47336. {
  47337. jassert (parentContentsList != 0);
  47338. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  47339. l->setDirectory (file, true, true);
  47340. setSubContentsList (l);
  47341. canDeleteSubContentsList = true;
  47342. }
  47343. changeListenerCallback (0);
  47344. }
  47345. }
  47346. }
  47347. void setSubContentsList (DirectoryContentsList* newList) throw()
  47348. {
  47349. jassert (subContentsList == 0);
  47350. subContentsList = newList;
  47351. newList->addChangeListener (this);
  47352. }
  47353. void changeListenerCallback (void*)
  47354. {
  47355. clearSubItems();
  47356. if (isOpen() && subContentsList != 0)
  47357. {
  47358. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  47359. {
  47360. FileListTreeItem* const item
  47361. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  47362. addSubItem (item);
  47363. }
  47364. }
  47365. }
  47366. void paintItem (Graphics& g, int width, int height)
  47367. {
  47368. if (file != File::nonexistent)
  47369. {
  47370. updateIcon (true);
  47371. if (icon == 0)
  47372. thread.addTimeSliceClient (this);
  47373. }
  47374. owner.getLookAndFeel()
  47375. .drawFileBrowserRow (g, width, height,
  47376. file.getFileName(),
  47377. icon,
  47378. fileSize, modTime,
  47379. isDirectory, isSelected(),
  47380. indexInContentsList);
  47381. }
  47382. void itemClicked (const MouseEvent& e)
  47383. {
  47384. owner.sendMouseClickMessage (file, e);
  47385. }
  47386. void itemDoubleClicked (const MouseEvent& e)
  47387. {
  47388. TreeViewItem::itemDoubleClicked (e);
  47389. owner.sendDoubleClickMessage (file);
  47390. }
  47391. void itemSelectionChanged (bool)
  47392. {
  47393. owner.sendSelectionChangeMessage();
  47394. }
  47395. bool useTimeSlice()
  47396. {
  47397. updateIcon (false);
  47398. thread.removeTimeSliceClient (this);
  47399. return false;
  47400. }
  47401. void handleAsyncUpdate()
  47402. {
  47403. owner.repaint();
  47404. }
  47405. const File file;
  47406. juce_UseDebuggingNewOperator
  47407. private:
  47408. FileTreeComponent& owner;
  47409. DirectoryContentsList* parentContentsList;
  47410. int indexInContentsList;
  47411. DirectoryContentsList* subContentsList;
  47412. bool isDirectory, canDeleteSubContentsList;
  47413. TimeSliceThread& thread;
  47414. Image* icon;
  47415. String fileSize;
  47416. String modTime;
  47417. void updateIcon (const bool onlyUpdateIfCached) throw()
  47418. {
  47419. if (icon == 0)
  47420. {
  47421. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47422. Image* im = ImageCache::getFromHashCode (hashCode);
  47423. if (im == 0 && ! onlyUpdateIfCached)
  47424. {
  47425. im = juce_createIconForFile (file);
  47426. if (im != 0)
  47427. ImageCache::addImageToCache (im, hashCode);
  47428. }
  47429. if (im != 0)
  47430. {
  47431. icon = im;
  47432. triggerAsyncUpdate();
  47433. }
  47434. }
  47435. }
  47436. };
  47437. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47438. : DirectoryContentsDisplayComponent (listToShow)
  47439. {
  47440. FileListTreeItem* const root
  47441. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47442. listToShow.getTimeSliceThread());
  47443. root->setSubContentsList (&listToShow);
  47444. setRootItemVisible (false);
  47445. setRootItem (root);
  47446. }
  47447. FileTreeComponent::~FileTreeComponent()
  47448. {
  47449. deleteRootItem();
  47450. }
  47451. const File FileTreeComponent::getSelectedFile (const int index) const
  47452. {
  47453. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47454. if (item != 0)
  47455. return item->file;
  47456. return File::nonexistent;
  47457. }
  47458. void FileTreeComponent::scrollToTop()
  47459. {
  47460. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47461. }
  47462. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47463. {
  47464. dragAndDropDescription = description;
  47465. }
  47466. END_JUCE_NAMESPACE
  47467. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47468. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47469. BEGIN_JUCE_NAMESPACE
  47470. ImagePreviewComponent::ImagePreviewComponent()
  47471. {
  47472. }
  47473. ImagePreviewComponent::~ImagePreviewComponent()
  47474. {
  47475. }
  47476. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47477. {
  47478. const int availableW = proportionOfWidth (0.97f);
  47479. const int availableH = getHeight() - 13 * 4;
  47480. const double scale = jmin (1.0,
  47481. availableW / (double) w,
  47482. availableH / (double) h);
  47483. w = roundToInt (scale * w);
  47484. h = roundToInt (scale * h);
  47485. }
  47486. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47487. {
  47488. if (fileToLoad != file)
  47489. {
  47490. fileToLoad = file;
  47491. startTimer (100);
  47492. }
  47493. }
  47494. void ImagePreviewComponent::timerCallback()
  47495. {
  47496. stopTimer();
  47497. currentThumbnail = 0;
  47498. currentDetails = String::empty;
  47499. repaint();
  47500. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47501. if (in != 0)
  47502. {
  47503. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47504. if (format != 0)
  47505. {
  47506. currentThumbnail = format->decodeImage (*in);
  47507. if (currentThumbnail != 0)
  47508. {
  47509. int w = currentThumbnail->getWidth();
  47510. int h = currentThumbnail->getHeight();
  47511. currentDetails
  47512. << fileToLoad.getFileName() << "\n"
  47513. << format->getFormatName() << "\n"
  47514. << w << " x " << h << " pixels\n"
  47515. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47516. getThumbSize (w, h);
  47517. currentThumbnail = currentThumbnail->createCopy (w, h);
  47518. }
  47519. }
  47520. }
  47521. }
  47522. void ImagePreviewComponent::paint (Graphics& g)
  47523. {
  47524. if (currentThumbnail != 0)
  47525. {
  47526. g.setFont (13.0f);
  47527. int w = currentThumbnail->getWidth();
  47528. int h = currentThumbnail->getHeight();
  47529. getThumbSize (w, h);
  47530. const int numLines = 4;
  47531. const int totalH = 13 * numLines + h + 4;
  47532. const int y = (getHeight() - totalH) / 2;
  47533. g.drawImageWithin (currentThumbnail,
  47534. (getWidth() - w) / 2, y, w, h,
  47535. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47536. false);
  47537. g.drawFittedText (currentDetails,
  47538. 0, y + h + 4, getWidth(), 100,
  47539. Justification::centredTop, numLines);
  47540. }
  47541. }
  47542. END_JUCE_NAMESPACE
  47543. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47544. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47545. BEGIN_JUCE_NAMESPACE
  47546. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47547. const String& directoryWildcardPatterns,
  47548. const String& description_)
  47549. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47550. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47551. {
  47552. parse (fileWildcardPatterns, fileWildcards);
  47553. parse (directoryWildcardPatterns, directoryWildcards);
  47554. }
  47555. WildcardFileFilter::~WildcardFileFilter()
  47556. {
  47557. }
  47558. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47559. {
  47560. return match (file, fileWildcards);
  47561. }
  47562. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47563. {
  47564. return match (file, directoryWildcards);
  47565. }
  47566. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47567. {
  47568. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47569. result.trim();
  47570. result.removeEmptyStrings();
  47571. // special case for *.*, because people use it to mean "any file", but it
  47572. // would actually ignore files with no extension.
  47573. for (int i = result.size(); --i >= 0;)
  47574. if (result[i] == T("*.*"))
  47575. result.set (i, T("*"));
  47576. }
  47577. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47578. {
  47579. const String filename (file.getFileName());
  47580. for (int i = wildcards.size(); --i >= 0;)
  47581. if (filename.matchesWildcard (wildcards[i], true))
  47582. return true;
  47583. return false;
  47584. }
  47585. END_JUCE_NAMESPACE
  47586. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47587. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47588. BEGIN_JUCE_NAMESPACE
  47589. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47590. {
  47591. }
  47592. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47593. {
  47594. }
  47595. namespace KeyboardFocusHelpers
  47596. {
  47597. // This will sort a set of components, so that they are ordered in terms of
  47598. // left-to-right and then top-to-bottom.
  47599. class ScreenPositionComparator
  47600. {
  47601. public:
  47602. ScreenPositionComparator() {}
  47603. static int compareElements (const Component* const first, const Component* const second) throw()
  47604. {
  47605. int explicitOrder1 = first->getExplicitFocusOrder();
  47606. if (explicitOrder1 <= 0)
  47607. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47608. int explicitOrder2 = second->getExplicitFocusOrder();
  47609. if (explicitOrder2 <= 0)
  47610. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47611. if (explicitOrder1 != explicitOrder2)
  47612. return explicitOrder1 - explicitOrder2;
  47613. const int diff = first->getY() - second->getY();
  47614. return (diff == 0) ? first->getX() - second->getX()
  47615. : diff;
  47616. }
  47617. };
  47618. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47619. {
  47620. if (parent->getNumChildComponents() > 0)
  47621. {
  47622. Array <Component*> localComps;
  47623. ScreenPositionComparator comparator;
  47624. int i;
  47625. for (i = parent->getNumChildComponents(); --i >= 0;)
  47626. {
  47627. Component* const c = parent->getChildComponent (i);
  47628. if (c->isVisible() && c->isEnabled())
  47629. localComps.addSorted (comparator, c);
  47630. }
  47631. for (i = 0; i < localComps.size(); ++i)
  47632. {
  47633. Component* const c = localComps.getUnchecked (i);
  47634. if (c->getWantsKeyboardFocus())
  47635. comps.add (c);
  47636. if (! c->isFocusContainer())
  47637. findAllFocusableComponents (c, comps);
  47638. }
  47639. }
  47640. }
  47641. }
  47642. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47643. {
  47644. Component* focusContainer = current->getParentComponent();
  47645. if (focusContainer != 0)
  47646. {
  47647. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47648. focusContainer = focusContainer->getParentComponent();
  47649. if (focusContainer != 0)
  47650. {
  47651. Array <Component*> comps;
  47652. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47653. if (comps.size() > 0)
  47654. {
  47655. const int index = comps.indexOf (current);
  47656. return comps [(index + comps.size() + delta) % comps.size()];
  47657. }
  47658. }
  47659. }
  47660. return 0;
  47661. }
  47662. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47663. {
  47664. return getIncrementedComponent (current, 1);
  47665. }
  47666. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47667. {
  47668. return getIncrementedComponent (current, -1);
  47669. }
  47670. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47671. {
  47672. Array <Component*> comps;
  47673. if (parentComponent != 0)
  47674. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47675. return comps.getFirst();
  47676. }
  47677. END_JUCE_NAMESPACE
  47678. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47679. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47680. BEGIN_JUCE_NAMESPACE
  47681. bool KeyListener::keyStateChanged (const bool, Component*)
  47682. {
  47683. return false;
  47684. }
  47685. END_JUCE_NAMESPACE
  47686. /*** End of inlined file: juce_KeyListener.cpp ***/
  47687. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47688. BEGIN_JUCE_NAMESPACE
  47689. // N.B. these two includes are put here deliberately to avoid problems with
  47690. // old GCCs failing on long include paths
  47691. const int maxKeys = 3;
  47692. class KeyMappingChangeButton : public Button
  47693. {
  47694. public:
  47695. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47696. const CommandID commandID_,
  47697. const String& keyName,
  47698. const int keyNum_)
  47699. : Button (keyName),
  47700. owner (owner_),
  47701. commandID (commandID_),
  47702. keyNum (keyNum_)
  47703. {
  47704. setWantsKeyboardFocus (false);
  47705. setTriggeredOnMouseDown (keyNum >= 0);
  47706. if (keyNum_ < 0)
  47707. setTooltip (TRANS("adds a new key-mapping"));
  47708. else
  47709. setTooltip (TRANS("click to change this key-mapping"));
  47710. }
  47711. ~KeyMappingChangeButton()
  47712. {
  47713. }
  47714. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47715. {
  47716. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47717. keyNum >= 0 ? getName() : String::empty);
  47718. }
  47719. void clicked()
  47720. {
  47721. if (keyNum >= 0)
  47722. {
  47723. // existing key clicked..
  47724. PopupMenu m;
  47725. m.addItem (1, TRANS("change this key-mapping"));
  47726. m.addSeparator();
  47727. m.addItem (2, TRANS("remove this key-mapping"));
  47728. const int res = m.show();
  47729. if (res == 1)
  47730. {
  47731. owner->assignNewKey (commandID, keyNum);
  47732. }
  47733. else if (res == 2)
  47734. {
  47735. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47736. }
  47737. }
  47738. else
  47739. {
  47740. // + button pressed..
  47741. owner->assignNewKey (commandID, -1);
  47742. }
  47743. }
  47744. void fitToContent (const int h) throw()
  47745. {
  47746. if (keyNum < 0)
  47747. {
  47748. setSize (h, h);
  47749. }
  47750. else
  47751. {
  47752. Font f (h * 0.6f);
  47753. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47754. }
  47755. }
  47756. juce_UseDebuggingNewOperator
  47757. private:
  47758. KeyMappingEditorComponent* const owner;
  47759. const CommandID commandID;
  47760. const int keyNum;
  47761. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47762. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47763. };
  47764. class KeyMappingItemComponent : public Component
  47765. {
  47766. public:
  47767. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47768. const CommandID commandID_)
  47769. : owner (owner_),
  47770. commandID (commandID_)
  47771. {
  47772. setInterceptsMouseClicks (false, true);
  47773. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47774. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47775. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47776. {
  47777. KeyMappingChangeButton* const kb
  47778. = new KeyMappingChangeButton (owner_, commandID,
  47779. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47780. kb->setEnabled (! isReadOnly);
  47781. addAndMakeVisible (kb);
  47782. }
  47783. KeyMappingChangeButton* const kb
  47784. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47785. addChildComponent (kb);
  47786. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47787. }
  47788. ~KeyMappingItemComponent()
  47789. {
  47790. deleteAllChildren();
  47791. }
  47792. void paint (Graphics& g)
  47793. {
  47794. g.setFont (getHeight() * 0.7f);
  47795. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47796. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47797. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47798. Justification::centredLeft, true);
  47799. }
  47800. void resized()
  47801. {
  47802. int x = getWidth() - 4;
  47803. for (int i = getNumChildComponents(); --i >= 0;)
  47804. {
  47805. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47806. kb->fitToContent (getHeight() - 2);
  47807. kb->setTopRightPosition (x, 1);
  47808. x -= kb->getWidth() + 5;
  47809. }
  47810. }
  47811. juce_UseDebuggingNewOperator
  47812. private:
  47813. KeyMappingEditorComponent* const owner;
  47814. const CommandID commandID;
  47815. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47816. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47817. };
  47818. class KeyMappingTreeViewItem : public TreeViewItem
  47819. {
  47820. public:
  47821. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47822. const CommandID commandID_)
  47823. : owner (owner_),
  47824. commandID (commandID_)
  47825. {
  47826. }
  47827. ~KeyMappingTreeViewItem()
  47828. {
  47829. }
  47830. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47831. bool mightContainSubItems() { return false; }
  47832. int getItemHeight() const { return 20; }
  47833. Component* createItemComponent()
  47834. {
  47835. return new KeyMappingItemComponent (owner, commandID);
  47836. }
  47837. juce_UseDebuggingNewOperator
  47838. private:
  47839. KeyMappingEditorComponent* const owner;
  47840. const CommandID commandID;
  47841. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47842. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47843. };
  47844. class KeyCategoryTreeViewItem : public TreeViewItem
  47845. {
  47846. public:
  47847. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47848. const String& name)
  47849. : owner (owner_),
  47850. categoryName (name)
  47851. {
  47852. }
  47853. ~KeyCategoryTreeViewItem()
  47854. {
  47855. }
  47856. const String getUniqueName() const { return categoryName + "_cat"; }
  47857. bool mightContainSubItems() { return true; }
  47858. int getItemHeight() const { return 28; }
  47859. void paintItem (Graphics& g, int width, int height)
  47860. {
  47861. g.setFont (height * 0.6f, Font::bold);
  47862. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47863. g.drawText (categoryName,
  47864. 2, 0, width - 2, height,
  47865. Justification::centredLeft, true);
  47866. }
  47867. void itemOpennessChanged (bool isNowOpen)
  47868. {
  47869. if (isNowOpen)
  47870. {
  47871. if (getNumSubItems() == 0)
  47872. {
  47873. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47874. for (int i = 0; i < commands.size(); ++i)
  47875. {
  47876. if (owner->shouldCommandBeIncluded (commands[i]))
  47877. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47878. }
  47879. }
  47880. }
  47881. else
  47882. {
  47883. clearSubItems();
  47884. }
  47885. }
  47886. juce_UseDebuggingNewOperator
  47887. private:
  47888. KeyMappingEditorComponent* owner;
  47889. String categoryName;
  47890. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47891. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47892. };
  47893. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47894. const bool showResetToDefaultButton)
  47895. : mappings (mappingManager)
  47896. {
  47897. jassert (mappingManager != 0); // can't be null!
  47898. mappingManager->addChangeListener (this);
  47899. setLinesDrawnForSubItems (false);
  47900. resetButton = 0;
  47901. if (showResetToDefaultButton)
  47902. {
  47903. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47904. resetButton->addButtonListener (this);
  47905. }
  47906. addAndMakeVisible (tree = new TreeView());
  47907. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47908. tree->setRootItemVisible (false);
  47909. tree->setDefaultOpenness (true);
  47910. tree->setRootItem (this);
  47911. }
  47912. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47913. {
  47914. mappings->removeChangeListener (this);
  47915. deleteAllChildren();
  47916. }
  47917. bool KeyMappingEditorComponent::mightContainSubItems()
  47918. {
  47919. return true;
  47920. }
  47921. const String KeyMappingEditorComponent::getUniqueName() const
  47922. {
  47923. return T("keys");
  47924. }
  47925. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47926. const Colour& textColour)
  47927. {
  47928. setColour (backgroundColourId, mainBackground);
  47929. setColour (textColourId, textColour);
  47930. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47931. }
  47932. void KeyMappingEditorComponent::parentHierarchyChanged()
  47933. {
  47934. changeListenerCallback (0);
  47935. }
  47936. void KeyMappingEditorComponent::resized()
  47937. {
  47938. int h = getHeight();
  47939. if (resetButton != 0)
  47940. {
  47941. const int buttonHeight = 20;
  47942. h -= buttonHeight + 8;
  47943. int x = getWidth() - 8;
  47944. const int y = h + 6;
  47945. resetButton->changeWidthToFitText (buttonHeight);
  47946. resetButton->setTopRightPosition (x, y);
  47947. }
  47948. tree->setBounds (0, 0, getWidth(), h);
  47949. }
  47950. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47951. {
  47952. if (button == resetButton)
  47953. {
  47954. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47955. TRANS("Reset to defaults"),
  47956. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47957. TRANS("Reset")))
  47958. {
  47959. mappings->resetToDefaultMappings();
  47960. }
  47961. }
  47962. }
  47963. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47964. {
  47965. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47966. clearSubItems();
  47967. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47968. for (int i = 0; i < categories.size(); ++i)
  47969. {
  47970. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47971. int count = 0;
  47972. for (int j = 0; j < commands.size(); ++j)
  47973. if (shouldCommandBeIncluded (commands[j]))
  47974. ++count;
  47975. if (count > 0)
  47976. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47977. }
  47978. if (openness != 0)
  47979. tree->restoreOpennessState (*openness);
  47980. }
  47981. class KeyEntryWindow : public AlertWindow
  47982. {
  47983. public:
  47984. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47985. : AlertWindow (TRANS("New key-mapping"),
  47986. TRANS("Please press a key combination now..."),
  47987. AlertWindow::NoIcon),
  47988. owner (owner_)
  47989. {
  47990. addButton (TRANS("ok"), 1);
  47991. addButton (TRANS("cancel"), 0);
  47992. // (avoid return + escape keys getting processed by the buttons..)
  47993. for (int i = getNumChildComponents(); --i >= 0;)
  47994. getChildComponent (i)->setWantsKeyboardFocus (false);
  47995. setWantsKeyboardFocus (true);
  47996. grabKeyboardFocus();
  47997. }
  47998. ~KeyEntryWindow()
  47999. {
  48000. }
  48001. bool keyPressed (const KeyPress& key)
  48002. {
  48003. lastPress = key;
  48004. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  48005. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  48006. if (previousCommand != 0)
  48007. {
  48008. message << "\n\n"
  48009. << TRANS("(Currently assigned to \"")
  48010. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  48011. << "\")";
  48012. }
  48013. setMessage (message);
  48014. return true;
  48015. }
  48016. bool keyStateChanged (const bool)
  48017. {
  48018. return true;
  48019. }
  48020. KeyPress lastPress;
  48021. juce_UseDebuggingNewOperator
  48022. private:
  48023. KeyMappingEditorComponent* owner;
  48024. KeyEntryWindow (const KeyEntryWindow&);
  48025. KeyEntryWindow& operator= (const KeyEntryWindow&);
  48026. };
  48027. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  48028. {
  48029. KeyEntryWindow entryWindow (this);
  48030. if (entryWindow.runModalLoop() != 0)
  48031. {
  48032. entryWindow.setVisible (false);
  48033. if (entryWindow.lastPress.isValid())
  48034. {
  48035. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  48036. if (previousCommand != 0)
  48037. {
  48038. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  48039. TRANS("Change key-mapping"),
  48040. TRANS("This key is already assigned to the command \"")
  48041. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  48042. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  48043. TRANS("re-assign"),
  48044. TRANS("cancel")))
  48045. {
  48046. return;
  48047. }
  48048. }
  48049. mappings->removeKeyPress (entryWindow.lastPress);
  48050. if (index >= 0)
  48051. mappings->removeKeyPress (commandID, index);
  48052. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  48053. }
  48054. }
  48055. }
  48056. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  48057. {
  48058. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48059. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  48060. }
  48061. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  48062. {
  48063. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48064. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  48065. }
  48066. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  48067. {
  48068. return key.getTextDescription();
  48069. }
  48070. END_JUCE_NAMESPACE
  48071. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  48072. /*** Start of inlined file: juce_KeyPress.cpp ***/
  48073. BEGIN_JUCE_NAMESPACE
  48074. KeyPress::KeyPress() throw()
  48075. : keyCode (0),
  48076. mods (0),
  48077. textCharacter (0)
  48078. {
  48079. }
  48080. KeyPress::KeyPress (const int keyCode_,
  48081. const ModifierKeys& mods_,
  48082. const juce_wchar textCharacter_) throw()
  48083. : keyCode (keyCode_),
  48084. mods (mods_),
  48085. textCharacter (textCharacter_)
  48086. {
  48087. }
  48088. KeyPress::KeyPress (const int keyCode_) throw()
  48089. : keyCode (keyCode_),
  48090. textCharacter (0)
  48091. {
  48092. }
  48093. KeyPress::KeyPress (const KeyPress& other) throw()
  48094. : keyCode (other.keyCode),
  48095. mods (other.mods),
  48096. textCharacter (other.textCharacter)
  48097. {
  48098. }
  48099. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  48100. {
  48101. keyCode = other.keyCode;
  48102. mods = other.mods;
  48103. textCharacter = other.textCharacter;
  48104. return *this;
  48105. }
  48106. bool KeyPress::operator== (const KeyPress& other) const throw()
  48107. {
  48108. return mods.getRawFlags() == other.mods.getRawFlags()
  48109. && (textCharacter == other.textCharacter
  48110. || textCharacter == 0
  48111. || other.textCharacter == 0)
  48112. && (keyCode == other.keyCode
  48113. || (keyCode < 256
  48114. && other.keyCode < 256
  48115. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  48116. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  48117. }
  48118. bool KeyPress::operator!= (const KeyPress& other) const throw()
  48119. {
  48120. return ! operator== (other);
  48121. }
  48122. bool KeyPress::isCurrentlyDown() const throw()
  48123. {
  48124. return isKeyCurrentlyDown (keyCode)
  48125. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  48126. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  48127. }
  48128. struct KeyNameAndCode
  48129. {
  48130. const char* name;
  48131. int code;
  48132. };
  48133. static const KeyNameAndCode keyNameTranslations[] =
  48134. {
  48135. { "spacebar", KeyPress::spaceKey },
  48136. { "return", KeyPress::returnKey },
  48137. { "escape", KeyPress::escapeKey },
  48138. { "backspace", KeyPress::backspaceKey },
  48139. { "cursor left", KeyPress::leftKey },
  48140. { "cursor right", KeyPress::rightKey },
  48141. { "cursor up", KeyPress::upKey },
  48142. { "cursor down", KeyPress::downKey },
  48143. { "page up", KeyPress::pageUpKey },
  48144. { "page down", KeyPress::pageDownKey },
  48145. { "home", KeyPress::homeKey },
  48146. { "end", KeyPress::endKey },
  48147. { "delete", KeyPress::deleteKey },
  48148. { "insert", KeyPress::insertKey },
  48149. { "tab", KeyPress::tabKey },
  48150. { "play", KeyPress::playKey },
  48151. { "stop", KeyPress::stopKey },
  48152. { "fast forward", KeyPress::fastForwardKey },
  48153. { "rewind", KeyPress::rewindKey }
  48154. };
  48155. static const tchar* const numberPadPrefix = T("numpad ");
  48156. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  48157. {
  48158. int modifiers = 0;
  48159. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  48160. || desc.containsWholeWordIgnoreCase (T("control"))
  48161. || desc.containsWholeWordIgnoreCase (T("ctl")))
  48162. modifiers |= ModifierKeys::ctrlModifier;
  48163. if (desc.containsWholeWordIgnoreCase (T("shift"))
  48164. || desc.containsWholeWordIgnoreCase (T("shft")))
  48165. modifiers |= ModifierKeys::shiftModifier;
  48166. if (desc.containsWholeWordIgnoreCase (T("alt"))
  48167. || desc.containsWholeWordIgnoreCase (T("option")))
  48168. modifiers |= ModifierKeys::altModifier;
  48169. if (desc.containsWholeWordIgnoreCase (T("command"))
  48170. || desc.containsWholeWordIgnoreCase (T("cmd")))
  48171. modifiers |= ModifierKeys::commandModifier;
  48172. int key = 0;
  48173. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48174. {
  48175. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  48176. {
  48177. key = keyNameTranslations[i].code;
  48178. break;
  48179. }
  48180. }
  48181. if (key == 0)
  48182. {
  48183. // see if it's a numpad key..
  48184. if (desc.containsIgnoreCase (numberPadPrefix))
  48185. {
  48186. const tchar lastChar = desc.trimEnd().getLastCharacter();
  48187. if (lastChar >= T('0') && lastChar <= T('9'))
  48188. key = numberPad0 + lastChar - T('0');
  48189. else if (lastChar == T('+'))
  48190. key = numberPadAdd;
  48191. else if (lastChar == T('-'))
  48192. key = numberPadSubtract;
  48193. else if (lastChar == T('*'))
  48194. key = numberPadMultiply;
  48195. else if (lastChar == T('/'))
  48196. key = numberPadDivide;
  48197. else if (lastChar == T('.'))
  48198. key = numberPadDecimalPoint;
  48199. else if (lastChar == T('='))
  48200. key = numberPadEquals;
  48201. else if (desc.endsWith (T("separator")))
  48202. key = numberPadSeparator;
  48203. else if (desc.endsWith (T("delete")))
  48204. key = numberPadDelete;
  48205. }
  48206. if (key == 0)
  48207. {
  48208. // see if it's a function key..
  48209. for (int i = 1; i <= 12; ++i)
  48210. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  48211. key = F1Key + i - 1;
  48212. if (key == 0)
  48213. {
  48214. // give up and use the hex code..
  48215. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  48216. .toLowerCase()
  48217. .retainCharacters (T("0123456789abcdef"))
  48218. .getHexValue32();
  48219. if (hexCode > 0)
  48220. key = hexCode;
  48221. else
  48222. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  48223. }
  48224. }
  48225. }
  48226. return KeyPress (key, ModifierKeys (modifiers), 0);
  48227. }
  48228. const String KeyPress::getTextDescription() const throw()
  48229. {
  48230. String desc;
  48231. if (keyCode > 0)
  48232. {
  48233. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  48234. // want to store it as being a slash, not shift+whatever.
  48235. if (textCharacter == T('/'))
  48236. return "/";
  48237. if (mods.isCtrlDown())
  48238. desc << "ctrl + ";
  48239. if (mods.isShiftDown())
  48240. desc << "shift + ";
  48241. #if JUCE_MAC
  48242. // only do this on the mac, because on Windows ctrl and command are the same,
  48243. // and this would get confusing
  48244. if (mods.isCommandDown())
  48245. desc << "command + ";
  48246. if (mods.isAltDown())
  48247. desc << "option + ";
  48248. #else
  48249. if (mods.isAltDown())
  48250. desc << "alt + ";
  48251. #endif
  48252. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48253. if (keyCode == keyNameTranslations[i].code)
  48254. return desc + keyNameTranslations[i].name;
  48255. if (keyCode >= F1Key && keyCode <= F16Key)
  48256. desc << 'F' << (1 + keyCode - F1Key);
  48257. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  48258. desc << numberPadPrefix << (keyCode - numberPad0);
  48259. else if (keyCode >= 33 && keyCode < 176)
  48260. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  48261. else if (keyCode == numberPadAdd)
  48262. desc << numberPadPrefix << '+';
  48263. else if (keyCode == numberPadSubtract)
  48264. desc << numberPadPrefix << '-';
  48265. else if (keyCode == numberPadMultiply)
  48266. desc << numberPadPrefix << '*';
  48267. else if (keyCode == numberPadDivide)
  48268. desc << numberPadPrefix << '/';
  48269. else if (keyCode == numberPadSeparator)
  48270. desc << numberPadPrefix << "separator";
  48271. else if (keyCode == numberPadDecimalPoint)
  48272. desc << numberPadPrefix << '.';
  48273. else if (keyCode == numberPadDelete)
  48274. desc << numberPadPrefix << "delete";
  48275. else
  48276. desc << '#' << String::toHexString (keyCode);
  48277. }
  48278. return desc;
  48279. }
  48280. END_JUCE_NAMESPACE
  48281. /*** End of inlined file: juce_KeyPress.cpp ***/
  48282. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  48283. BEGIN_JUCE_NAMESPACE
  48284. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  48285. : commandManager (commandManager_)
  48286. {
  48287. // A manager is needed to get the descriptions of commands, and will be called when
  48288. // a command is invoked. So you can't leave this null..
  48289. jassert (commandManager_ != 0);
  48290. Desktop::getInstance().addFocusChangeListener (this);
  48291. }
  48292. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  48293. : commandManager (other.commandManager)
  48294. {
  48295. Desktop::getInstance().addFocusChangeListener (this);
  48296. }
  48297. KeyPressMappingSet::~KeyPressMappingSet()
  48298. {
  48299. Desktop::getInstance().removeFocusChangeListener (this);
  48300. }
  48301. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  48302. {
  48303. for (int i = 0; i < mappings.size(); ++i)
  48304. if (mappings.getUnchecked(i)->commandID == commandID)
  48305. return mappings.getUnchecked (i)->keypresses;
  48306. return Array <KeyPress> ();
  48307. }
  48308. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  48309. const KeyPress& newKeyPress,
  48310. int insertIndex) throw()
  48311. {
  48312. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  48313. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  48314. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  48315. && ! newKeyPress.getModifiers().isShiftDown()));
  48316. if (findCommandForKeyPress (newKeyPress) != commandID)
  48317. {
  48318. removeKeyPress (newKeyPress);
  48319. if (newKeyPress.isValid())
  48320. {
  48321. for (int i = mappings.size(); --i >= 0;)
  48322. {
  48323. if (mappings.getUnchecked(i)->commandID == commandID)
  48324. {
  48325. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  48326. sendChangeMessage (this);
  48327. return;
  48328. }
  48329. }
  48330. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48331. if (ci != 0)
  48332. {
  48333. CommandMapping* const cm = new CommandMapping();
  48334. cm->commandID = commandID;
  48335. cm->keypresses.add (newKeyPress);
  48336. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  48337. mappings.add (cm);
  48338. sendChangeMessage (this);
  48339. }
  48340. }
  48341. }
  48342. }
  48343. void KeyPressMappingSet::resetToDefaultMappings() throw()
  48344. {
  48345. mappings.clear();
  48346. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  48347. {
  48348. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  48349. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48350. {
  48351. addKeyPress (ci->commandID,
  48352. ci->defaultKeypresses.getReference (j));
  48353. }
  48354. }
  48355. sendChangeMessage (this);
  48356. }
  48357. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  48358. {
  48359. clearAllKeyPresses (commandID);
  48360. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48361. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48362. {
  48363. addKeyPress (ci->commandID,
  48364. ci->defaultKeypresses.getReference (j));
  48365. }
  48366. }
  48367. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48368. {
  48369. if (mappings.size() > 0)
  48370. {
  48371. sendChangeMessage (this);
  48372. mappings.clear();
  48373. }
  48374. }
  48375. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48376. {
  48377. for (int i = mappings.size(); --i >= 0;)
  48378. {
  48379. if (mappings.getUnchecked(i)->commandID == commandID)
  48380. {
  48381. mappings.remove (i);
  48382. sendChangeMessage (this);
  48383. }
  48384. }
  48385. }
  48386. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48387. {
  48388. if (keypress.isValid())
  48389. {
  48390. for (int i = mappings.size(); --i >= 0;)
  48391. {
  48392. CommandMapping* const cm = mappings.getUnchecked(i);
  48393. for (int j = cm->keypresses.size(); --j >= 0;)
  48394. {
  48395. if (keypress == cm->keypresses [j])
  48396. {
  48397. cm->keypresses.remove (j);
  48398. sendChangeMessage (this);
  48399. }
  48400. }
  48401. }
  48402. }
  48403. }
  48404. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48405. const int keyPressIndex) throw()
  48406. {
  48407. for (int i = mappings.size(); --i >= 0;)
  48408. {
  48409. if (mappings.getUnchecked(i)->commandID == commandID)
  48410. {
  48411. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48412. sendChangeMessage (this);
  48413. break;
  48414. }
  48415. }
  48416. }
  48417. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48418. {
  48419. for (int i = 0; i < mappings.size(); ++i)
  48420. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48421. return mappings.getUnchecked(i)->commandID;
  48422. return 0;
  48423. }
  48424. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48425. const KeyPress& keyPress) const throw()
  48426. {
  48427. for (int i = mappings.size(); --i >= 0;)
  48428. if (mappings.getUnchecked(i)->commandID == commandID)
  48429. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48430. return false;
  48431. }
  48432. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48433. const KeyPress& key,
  48434. const bool isKeyDown,
  48435. const int millisecsSinceKeyPressed,
  48436. Component* const originatingComponent) const
  48437. {
  48438. ApplicationCommandTarget::InvocationInfo info (commandID);
  48439. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48440. info.isKeyDown = isKeyDown;
  48441. info.keyPress = key;
  48442. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48443. info.originatingComponent = originatingComponent;
  48444. commandManager->invoke (info, false);
  48445. }
  48446. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48447. {
  48448. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48449. {
  48450. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48451. {
  48452. // if the XML was created as a set of differences from the default mappings,
  48453. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48454. resetToDefaultMappings();
  48455. }
  48456. else
  48457. {
  48458. // if the XML was created calling createXml (false), then we need to clear all
  48459. // the keys and treat the xml as describing the entire set of mappings.
  48460. clearAllKeyPresses();
  48461. }
  48462. forEachXmlChildElement (xmlVersion, map)
  48463. {
  48464. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48465. if (commandId != 0)
  48466. {
  48467. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48468. if (map->hasTagName (T("MAPPING")))
  48469. {
  48470. addKeyPress (commandId, key);
  48471. }
  48472. else if (map->hasTagName (T("UNMAPPING")))
  48473. {
  48474. if (containsMapping (commandId, key))
  48475. removeKeyPress (key);
  48476. }
  48477. }
  48478. }
  48479. return true;
  48480. }
  48481. return false;
  48482. }
  48483. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48484. {
  48485. ScopedPointer <KeyPressMappingSet> defaultSet;
  48486. if (saveDifferencesFromDefaultSet)
  48487. {
  48488. defaultSet = new KeyPressMappingSet (commandManager);
  48489. defaultSet->resetToDefaultMappings();
  48490. }
  48491. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48492. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48493. int i;
  48494. for (i = 0; i < mappings.size(); ++i)
  48495. {
  48496. const CommandMapping* const cm = mappings.getUnchecked(i);
  48497. for (int j = 0; j < cm->keypresses.size(); ++j)
  48498. {
  48499. if (defaultSet == 0
  48500. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48501. {
  48502. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48503. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48504. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48505. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48506. }
  48507. }
  48508. }
  48509. if (defaultSet != 0)
  48510. {
  48511. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48512. {
  48513. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48514. for (int j = 0; j < cm->keypresses.size(); ++j)
  48515. {
  48516. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48517. {
  48518. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48519. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48520. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48521. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48522. }
  48523. }
  48524. }
  48525. }
  48526. return doc;
  48527. }
  48528. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48529. Component* originatingComponent)
  48530. {
  48531. bool used = false;
  48532. const CommandID commandID = findCommandForKeyPress (key);
  48533. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48534. if (ci != 0
  48535. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48536. {
  48537. ApplicationCommandInfo info (0);
  48538. if (commandManager->getTargetForCommand (commandID, info) != 0
  48539. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48540. {
  48541. invokeCommand (commandID, key, true, 0, originatingComponent);
  48542. used = true;
  48543. }
  48544. else
  48545. {
  48546. if (originatingComponent != 0)
  48547. originatingComponent->getLookAndFeel().playAlertSound();
  48548. }
  48549. }
  48550. return used;
  48551. }
  48552. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48553. {
  48554. bool used = false;
  48555. const uint32 now = Time::getMillisecondCounter();
  48556. for (int i = mappings.size(); --i >= 0;)
  48557. {
  48558. CommandMapping* const cm = mappings.getUnchecked(i);
  48559. if (cm->wantsKeyUpDownCallbacks)
  48560. {
  48561. for (int j = cm->keypresses.size(); --j >= 0;)
  48562. {
  48563. const KeyPress key (cm->keypresses.getReference (j));
  48564. const bool isDown = key.isCurrentlyDown();
  48565. int keyPressEntryIndex = 0;
  48566. bool wasDown = false;
  48567. for (int k = keysDown.size(); --k >= 0;)
  48568. {
  48569. if (key == keysDown.getUnchecked(k)->key)
  48570. {
  48571. keyPressEntryIndex = k;
  48572. wasDown = true;
  48573. used = true;
  48574. break;
  48575. }
  48576. }
  48577. if (isDown != wasDown)
  48578. {
  48579. int millisecs = 0;
  48580. if (isDown)
  48581. {
  48582. KeyPressTime* const k = new KeyPressTime();
  48583. k->key = key;
  48584. k->timeWhenPressed = now;
  48585. keysDown.add (k);
  48586. }
  48587. else
  48588. {
  48589. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48590. if (now > pressTime)
  48591. millisecs = now - pressTime;
  48592. keysDown.remove (keyPressEntryIndex);
  48593. }
  48594. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48595. used = true;
  48596. }
  48597. }
  48598. }
  48599. }
  48600. return used;
  48601. }
  48602. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48603. {
  48604. if (focusedComponent != 0)
  48605. focusedComponent->keyStateChanged (false);
  48606. }
  48607. END_JUCE_NAMESPACE
  48608. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48609. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48610. BEGIN_JUCE_NAMESPACE
  48611. ModifierKeys::ModifierKeys (const int flags_) throw()
  48612. : flags (flags_)
  48613. {
  48614. }
  48615. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48616. : flags (other.flags)
  48617. {
  48618. }
  48619. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48620. {
  48621. flags = other.flags;
  48622. return *this;
  48623. }
  48624. ModifierKeys ModifierKeys::currentModifiers;
  48625. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48626. {
  48627. return currentModifiers;
  48628. }
  48629. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48630. {
  48631. int num = 0;
  48632. if (isLeftButtonDown()) ++num;
  48633. if (isRightButtonDown()) ++num;
  48634. if (isMiddleButtonDown()) ++num;
  48635. return num;
  48636. }
  48637. END_JUCE_NAMESPACE
  48638. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48639. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48640. BEGIN_JUCE_NAMESPACE
  48641. struct AnimationTask
  48642. {
  48643. AnimationTask (Component* const comp)
  48644. : component (comp),
  48645. watcher (comp)
  48646. {
  48647. }
  48648. Component* component;
  48649. ComponentDeletionWatcher watcher;
  48650. Rectangle<int> destination;
  48651. int msElapsed, msTotal;
  48652. double startSpeed, midSpeed, endSpeed, lastProgress;
  48653. double left, top, right, bottom;
  48654. bool useTimeslice (const int elapsed)
  48655. {
  48656. if (watcher.hasBeenDeleted())
  48657. return false;
  48658. msElapsed += elapsed;
  48659. double newProgress = msElapsed / (double) msTotal;
  48660. if (newProgress >= 0 && newProgress < 1.0)
  48661. {
  48662. newProgress = timeToDistance (newProgress);
  48663. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48664. jassert (newProgress >= lastProgress);
  48665. lastProgress = newProgress;
  48666. left += (destination.getX() - left) * delta;
  48667. top += (destination.getY() - top) * delta;
  48668. right += (destination.getRight() - right) * delta;
  48669. bottom += (destination.getBottom() - bottom) * delta;
  48670. if (delta < 1.0)
  48671. {
  48672. const Rectangle<int> newBounds (roundToInt (left),
  48673. roundToInt (top),
  48674. roundToInt (right - left),
  48675. roundToInt (bottom - top));
  48676. if (newBounds != destination)
  48677. {
  48678. component->setBounds (newBounds);
  48679. return true;
  48680. }
  48681. }
  48682. }
  48683. component->setBounds (destination);
  48684. return false;
  48685. }
  48686. void moveToFinalDestination()
  48687. {
  48688. if (! watcher.hasBeenDeleted())
  48689. component->setBounds (destination);
  48690. }
  48691. private:
  48692. inline double timeToDistance (const double time) const
  48693. {
  48694. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48695. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48696. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48697. }
  48698. };
  48699. ComponentAnimator::ComponentAnimator()
  48700. : lastTime (0)
  48701. {
  48702. }
  48703. ComponentAnimator::~ComponentAnimator()
  48704. {
  48705. cancelAllAnimations (false);
  48706. jassert (tasks.size() == 0);
  48707. }
  48708. void* ComponentAnimator::findTaskFor (Component* const component) const
  48709. {
  48710. for (int i = tasks.size(); --i >= 0;)
  48711. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component)
  48712. return tasks.getUnchecked(i);
  48713. return 0;
  48714. }
  48715. void ComponentAnimator::animateComponent (Component* const component,
  48716. const Rectangle<int>& finalPosition,
  48717. const int millisecondsToSpendMoving,
  48718. const double startSpeed,
  48719. const double endSpeed)
  48720. {
  48721. if (component != 0)
  48722. {
  48723. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48724. if (at == 0)
  48725. {
  48726. at = new AnimationTask (component);
  48727. tasks.add (at);
  48728. sendChangeMessage (this);
  48729. }
  48730. at->msElapsed = 0;
  48731. at->lastProgress = 0;
  48732. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48733. at->destination = finalPosition;
  48734. // the speeds must be 0 or greater!
  48735. jassert (startSpeed >= 0 && endSpeed >= 0)
  48736. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48737. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48738. at->midSpeed = invTotalDistance;
  48739. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48740. at->left = component->getX();
  48741. at->top = component->getY();
  48742. at->right = component->getRight();
  48743. at->bottom = component->getBottom();
  48744. if (! isTimerRunning())
  48745. {
  48746. lastTime = Time::getMillisecondCounter();
  48747. startTimer (1000 / 50);
  48748. }
  48749. }
  48750. }
  48751. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48752. {
  48753. for (int i = tasks.size(); --i >= 0;)
  48754. {
  48755. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48756. if (moveComponentsToTheirFinalPositions)
  48757. at->moveToFinalDestination();
  48758. delete at;
  48759. tasks.remove (i);
  48760. sendChangeMessage (this);
  48761. }
  48762. }
  48763. void ComponentAnimator::cancelAnimation (Component* const component,
  48764. const bool moveComponentToItsFinalPosition)
  48765. {
  48766. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48767. if (at != 0)
  48768. {
  48769. if (moveComponentToItsFinalPosition)
  48770. at->moveToFinalDestination();
  48771. tasks.removeValue (at);
  48772. delete at;
  48773. sendChangeMessage (this);
  48774. }
  48775. }
  48776. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48777. {
  48778. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48779. if (at != 0)
  48780. return at->destination;
  48781. else if (component != 0)
  48782. return component->getBounds();
  48783. return Rectangle<int>();
  48784. }
  48785. bool ComponentAnimator::isAnimating (Component* component) const
  48786. {
  48787. return findTaskFor (component) != 0;
  48788. }
  48789. void ComponentAnimator::timerCallback()
  48790. {
  48791. const uint32 timeNow = Time::getMillisecondCounter();
  48792. if (lastTime == 0 || lastTime == timeNow)
  48793. lastTime = timeNow;
  48794. const int elapsed = timeNow - lastTime;
  48795. for (int i = tasks.size(); --i >= 0;)
  48796. {
  48797. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48798. if (! at->useTimeslice (elapsed))
  48799. {
  48800. tasks.remove (i);
  48801. delete at;
  48802. sendChangeMessage (this);
  48803. }
  48804. }
  48805. lastTime = timeNow;
  48806. if (tasks.size() == 0)
  48807. stopTimer();
  48808. }
  48809. END_JUCE_NAMESPACE
  48810. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48811. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48812. BEGIN_JUCE_NAMESPACE
  48813. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48814. : minW (0),
  48815. maxW (0x3fffffff),
  48816. minH (0),
  48817. maxH (0x3fffffff),
  48818. minOffTop (0),
  48819. minOffLeft (0),
  48820. minOffBottom (0),
  48821. minOffRight (0),
  48822. aspectRatio (0.0)
  48823. {
  48824. }
  48825. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48826. {
  48827. }
  48828. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48829. {
  48830. minW = minimumWidth;
  48831. }
  48832. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48833. {
  48834. maxW = maximumWidth;
  48835. }
  48836. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48837. {
  48838. minH = minimumHeight;
  48839. }
  48840. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48841. {
  48842. maxH = maximumHeight;
  48843. }
  48844. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48845. {
  48846. jassert (maxW >= minimumWidth);
  48847. jassert (maxH >= minimumHeight);
  48848. jassert (minimumWidth > 0 && minimumHeight > 0);
  48849. minW = minimumWidth;
  48850. minH = minimumHeight;
  48851. if (minW > maxW)
  48852. maxW = minW;
  48853. if (minH > maxH)
  48854. maxH = minH;
  48855. }
  48856. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48857. {
  48858. jassert (maximumWidth >= minW);
  48859. jassert (maximumHeight >= minH);
  48860. jassert (maximumWidth > 0 && maximumHeight > 0);
  48861. maxW = jmax (minW, maximumWidth);
  48862. maxH = jmax (minH, maximumHeight);
  48863. }
  48864. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48865. const int minimumHeight,
  48866. const int maximumWidth,
  48867. const int maximumHeight) throw()
  48868. {
  48869. jassert (maximumWidth >= minimumWidth);
  48870. jassert (maximumHeight >= minimumHeight);
  48871. jassert (maximumWidth > 0 && maximumHeight > 0);
  48872. jassert (minimumWidth > 0 && minimumHeight > 0);
  48873. minW = jmax (0, minimumWidth);
  48874. minH = jmax (0, minimumHeight);
  48875. maxW = jmax (minW, maximumWidth);
  48876. maxH = jmax (minH, maximumHeight);
  48877. }
  48878. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48879. const int minimumWhenOffTheLeft,
  48880. const int minimumWhenOffTheBottom,
  48881. const int minimumWhenOffTheRight) throw()
  48882. {
  48883. minOffTop = minimumWhenOffTheTop;
  48884. minOffLeft = minimumWhenOffTheLeft;
  48885. minOffBottom = minimumWhenOffTheBottom;
  48886. minOffRight = minimumWhenOffTheRight;
  48887. }
  48888. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48889. {
  48890. aspectRatio = jmax (0.0, widthOverHeight);
  48891. }
  48892. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48893. {
  48894. return aspectRatio;
  48895. }
  48896. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48897. const Rectangle<int>& targetBounds,
  48898. const bool isStretchingTop,
  48899. const bool isStretchingLeft,
  48900. const bool isStretchingBottom,
  48901. const bool isStretchingRight)
  48902. {
  48903. jassert (component != 0);
  48904. Rectangle<int> limits, bounds (targetBounds);
  48905. BorderSize border;
  48906. Component* const parent = component->getParentComponent();
  48907. if (parent == 0)
  48908. {
  48909. ComponentPeer* peer = component->getPeer();
  48910. if (peer != 0)
  48911. border = peer->getFrameSize();
  48912. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48913. }
  48914. else
  48915. {
  48916. limits.setSize (parent->getWidth(), parent->getHeight());
  48917. }
  48918. border.addTo (bounds);
  48919. checkBounds (bounds,
  48920. border.addedTo (component->getBounds()), limits,
  48921. isStretchingTop, isStretchingLeft,
  48922. isStretchingBottom, isStretchingRight);
  48923. border.subtractFrom (bounds);
  48924. applyBoundsToComponent (component, bounds);
  48925. }
  48926. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48927. {
  48928. setBoundsForComponent (component, component->getBounds(),
  48929. false, false, false, false);
  48930. }
  48931. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48932. const Rectangle<int>& bounds)
  48933. {
  48934. component->setBounds (bounds);
  48935. }
  48936. void ComponentBoundsConstrainer::resizeStart()
  48937. {
  48938. }
  48939. void ComponentBoundsConstrainer::resizeEnd()
  48940. {
  48941. }
  48942. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48943. const Rectangle<int>& old,
  48944. const Rectangle<int>& limits,
  48945. const bool isStretchingTop,
  48946. const bool isStretchingLeft,
  48947. const bool isStretchingBottom,
  48948. const bool isStretchingRight)
  48949. {
  48950. int x = bounds.getX();
  48951. int y = bounds.getY();
  48952. int w = bounds.getWidth();
  48953. int h = bounds.getHeight();
  48954. // constrain the size if it's being stretched..
  48955. if (isStretchingLeft)
  48956. {
  48957. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48958. w = old.getRight() - x;
  48959. }
  48960. if (isStretchingRight)
  48961. {
  48962. w = jlimit (minW, maxW, w);
  48963. }
  48964. if (isStretchingTop)
  48965. {
  48966. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48967. h = old.getBottom() - y;
  48968. }
  48969. if (isStretchingBottom)
  48970. {
  48971. h = jlimit (minH, maxH, h);
  48972. }
  48973. // constrain the aspect ratio if one has been specified..
  48974. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48975. {
  48976. bool adjustWidth;
  48977. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48978. {
  48979. adjustWidth = true;
  48980. }
  48981. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48982. {
  48983. adjustWidth = false;
  48984. }
  48985. else
  48986. {
  48987. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48988. const double newRatio = fabs (w / (double) h);
  48989. adjustWidth = (oldRatio > newRatio);
  48990. }
  48991. if (adjustWidth)
  48992. {
  48993. w = roundToInt (h * aspectRatio);
  48994. if (w > maxW || w < minW)
  48995. {
  48996. w = jlimit (minW, maxW, w);
  48997. h = roundToInt (w / aspectRatio);
  48998. }
  48999. }
  49000. else
  49001. {
  49002. h = roundToInt (w / aspectRatio);
  49003. if (h > maxH || h < minH)
  49004. {
  49005. h = jlimit (minH, maxH, h);
  49006. w = roundToInt (h * aspectRatio);
  49007. }
  49008. }
  49009. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49010. {
  49011. x = old.getX() + (old.getWidth() - w) / 2;
  49012. }
  49013. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49014. {
  49015. y = old.getY() + (old.getHeight() - h) / 2;
  49016. }
  49017. else
  49018. {
  49019. if (isStretchingLeft)
  49020. x = old.getRight() - w;
  49021. if (isStretchingTop)
  49022. y = old.getBottom() - h;
  49023. }
  49024. }
  49025. // ...and constrain the position if limits have been set for that.
  49026. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  49027. {
  49028. if (minOffTop > 0)
  49029. {
  49030. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  49031. if (y < limit)
  49032. {
  49033. if (isStretchingTop)
  49034. h -= (limit - y);
  49035. y = limit;
  49036. }
  49037. }
  49038. if (minOffLeft > 0)
  49039. {
  49040. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  49041. if (x < limit)
  49042. {
  49043. if (isStretchingLeft)
  49044. w -= (limit - x);
  49045. x = limit;
  49046. }
  49047. }
  49048. if (minOffBottom > 0)
  49049. {
  49050. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  49051. if (y > limit)
  49052. {
  49053. if (isStretchingBottom)
  49054. h += (limit - y);
  49055. else
  49056. y = limit;
  49057. }
  49058. }
  49059. if (minOffRight > 0)
  49060. {
  49061. const int limit = limits.getRight() - jmin (minOffRight, w);
  49062. if (x > limit)
  49063. {
  49064. if (isStretchingRight)
  49065. w += (limit - x);
  49066. else
  49067. x = limit;
  49068. }
  49069. }
  49070. }
  49071. jassert (w >= 0 && h >= 0);
  49072. bounds = Rectangle<int> (x, y, w, h);
  49073. }
  49074. END_JUCE_NAMESPACE
  49075. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  49076. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49077. BEGIN_JUCE_NAMESPACE
  49078. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  49079. : component (component_),
  49080. lastPeer (0),
  49081. reentrant (false)
  49082. {
  49083. jassert (component != 0); // can't use this with a null pointer..
  49084. #ifdef JUCE_DEBUG
  49085. deletionWatcher = new ComponentDeletionWatcher (component_);
  49086. #endif
  49087. component->addComponentListener (this);
  49088. registerWithParentComps();
  49089. }
  49090. ComponentMovementWatcher::~ComponentMovementWatcher()
  49091. {
  49092. component->removeComponentListener (this);
  49093. unregister();
  49094. }
  49095. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  49096. {
  49097. #ifdef JUCE_DEBUG
  49098. // agh! don't delete the target component without deleting this object first!
  49099. jassert (! deletionWatcher->hasBeenDeleted());
  49100. #endif
  49101. if (! reentrant)
  49102. {
  49103. reentrant = true;
  49104. ComponentPeer* const peer = component->getPeer();
  49105. if (peer != lastPeer)
  49106. {
  49107. ComponentDeletionWatcher watcher (component);
  49108. componentPeerChanged();
  49109. if (watcher.hasBeenDeleted())
  49110. return;
  49111. lastPeer = peer;
  49112. }
  49113. unregister();
  49114. registerWithParentComps();
  49115. reentrant = false;
  49116. componentMovedOrResized (*component, true, true);
  49117. }
  49118. }
  49119. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  49120. {
  49121. #ifdef JUCE_DEBUG
  49122. // agh! don't delete the target component without deleting this object first!
  49123. jassert (! deletionWatcher->hasBeenDeleted());
  49124. #endif
  49125. if (wasMoved)
  49126. {
  49127. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  49128. wasMoved = lastBounds.getPosition() != pos;
  49129. lastBounds.setPosition (pos);
  49130. }
  49131. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  49132. lastBounds.setSize (component->getWidth(), component->getHeight());
  49133. if (wasMoved || wasResized)
  49134. componentMovedOrResized (wasMoved, wasResized);
  49135. }
  49136. void ComponentMovementWatcher::registerWithParentComps() throw()
  49137. {
  49138. Component* p = component->getParentComponent();
  49139. while (p != 0)
  49140. {
  49141. p->addComponentListener (this);
  49142. registeredParentComps.add (p);
  49143. p = p->getParentComponent();
  49144. }
  49145. }
  49146. void ComponentMovementWatcher::unregister() throw()
  49147. {
  49148. for (int i = registeredParentComps.size(); --i >= 0;)
  49149. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  49150. registeredParentComps.clear();
  49151. }
  49152. END_JUCE_NAMESPACE
  49153. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49154. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  49155. BEGIN_JUCE_NAMESPACE
  49156. GroupComponent::GroupComponent (const String& componentName,
  49157. const String& labelText)
  49158. : Component (componentName),
  49159. text (labelText),
  49160. justification (Justification::left)
  49161. {
  49162. setInterceptsMouseClicks (false, true);
  49163. }
  49164. GroupComponent::~GroupComponent()
  49165. {
  49166. }
  49167. void GroupComponent::setText (const String& newText) throw()
  49168. {
  49169. if (text != newText)
  49170. {
  49171. text = newText;
  49172. repaint();
  49173. }
  49174. }
  49175. const String GroupComponent::getText() const throw()
  49176. {
  49177. return text;
  49178. }
  49179. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  49180. {
  49181. if (justification.getFlags() != newJustification.getFlags())
  49182. {
  49183. justification = newJustification;
  49184. repaint();
  49185. }
  49186. }
  49187. void GroupComponent::paint (Graphics& g)
  49188. {
  49189. getLookAndFeel()
  49190. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  49191. text, justification,
  49192. *this);
  49193. }
  49194. void GroupComponent::enablementChanged()
  49195. {
  49196. repaint();
  49197. }
  49198. void GroupComponent::colourChanged()
  49199. {
  49200. repaint();
  49201. }
  49202. END_JUCE_NAMESPACE
  49203. /*** End of inlined file: juce_GroupComponent.cpp ***/
  49204. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  49205. BEGIN_JUCE_NAMESPACE
  49206. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  49207. : DocumentWindow (String::empty, backgroundColour,
  49208. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  49209. {
  49210. }
  49211. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  49212. {
  49213. }
  49214. void MultiDocumentPanelWindow::maximiseButtonPressed()
  49215. {
  49216. MultiDocumentPanel* const owner = getOwner();
  49217. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49218. if (owner != 0)
  49219. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  49220. }
  49221. void MultiDocumentPanelWindow::closeButtonPressed()
  49222. {
  49223. MultiDocumentPanel* const owner = getOwner();
  49224. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49225. if (owner != 0)
  49226. owner->closeDocument (getContentComponent(), true);
  49227. }
  49228. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  49229. {
  49230. DocumentWindow::activeWindowStatusChanged();
  49231. updateOrder();
  49232. }
  49233. void MultiDocumentPanelWindow::broughtToFront()
  49234. {
  49235. DocumentWindow::broughtToFront();
  49236. updateOrder();
  49237. }
  49238. void MultiDocumentPanelWindow::updateOrder()
  49239. {
  49240. MultiDocumentPanel* const owner = getOwner();
  49241. if (owner != 0)
  49242. owner->updateOrder();
  49243. }
  49244. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  49245. {
  49246. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49247. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49248. }
  49249. class MDITabbedComponentInternal : public TabbedComponent
  49250. {
  49251. public:
  49252. MDITabbedComponentInternal()
  49253. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  49254. {
  49255. }
  49256. ~MDITabbedComponentInternal()
  49257. {
  49258. }
  49259. void currentTabChanged (const int, const String&)
  49260. {
  49261. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49262. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49263. if (owner != 0)
  49264. owner->updateOrder();
  49265. }
  49266. };
  49267. MultiDocumentPanel::MultiDocumentPanel()
  49268. : mode (MaximisedWindowsWithTabs),
  49269. tabComponent (0),
  49270. backgroundColour (Colours::lightblue),
  49271. maximumNumDocuments (0),
  49272. numDocsBeforeTabsUsed (0)
  49273. {
  49274. setOpaque (true);
  49275. }
  49276. MultiDocumentPanel::~MultiDocumentPanel()
  49277. {
  49278. closeAllDocuments (false);
  49279. }
  49280. static bool shouldDeleteComp (Component* const c)
  49281. {
  49282. return c->getProperties() ["mdiDocumentDelete_"];
  49283. }
  49284. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  49285. {
  49286. while (components.size() > 0)
  49287. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  49288. return false;
  49289. return true;
  49290. }
  49291. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  49292. {
  49293. return new MultiDocumentPanelWindow (backgroundColour);
  49294. }
  49295. void MultiDocumentPanel::addWindow (Component* component)
  49296. {
  49297. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  49298. dw->setResizable (true, false);
  49299. dw->setContentComponent (component, false, true);
  49300. dw->setName (component->getName());
  49301. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  49302. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  49303. int x = 4;
  49304. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  49305. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  49306. x += 16;
  49307. dw->setTopLeftPosition (x, x);
  49308. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  49309. if (pos.toString().isNotEmpty())
  49310. dw->restoreWindowStateFromString (pos.toString());
  49311. addAndMakeVisible (dw);
  49312. dw->toFront (true);
  49313. }
  49314. bool MultiDocumentPanel::addDocument (Component* const component,
  49315. const Colour& docColour,
  49316. const bool deleteWhenRemoved)
  49317. {
  49318. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  49319. // with a frame-within-a-frame! Just pass in the bare content component.
  49320. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  49321. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  49322. return false;
  49323. components.add (component);
  49324. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  49325. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  49326. component->addComponentListener (this);
  49327. if (mode == FloatingWindows)
  49328. {
  49329. if (isFullscreenWhenOneDocument())
  49330. {
  49331. if (components.size() == 1)
  49332. {
  49333. addAndMakeVisible (component);
  49334. }
  49335. else
  49336. {
  49337. if (components.size() == 2)
  49338. addWindow (components.getFirst());
  49339. addWindow (component);
  49340. }
  49341. }
  49342. else
  49343. {
  49344. addWindow (component);
  49345. }
  49346. }
  49347. else
  49348. {
  49349. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  49350. {
  49351. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  49352. Array <Component*> temp (components);
  49353. for (int i = 0; i < temp.size(); ++i)
  49354. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  49355. resized();
  49356. }
  49357. else
  49358. {
  49359. if (tabComponent != 0)
  49360. tabComponent->addTab (component->getName(), docColour, component, false);
  49361. else
  49362. addAndMakeVisible (component);
  49363. }
  49364. setActiveDocument (component);
  49365. }
  49366. resized();
  49367. activeDocumentChanged();
  49368. return true;
  49369. }
  49370. bool MultiDocumentPanel::closeDocument (Component* component,
  49371. const bool checkItsOkToCloseFirst)
  49372. {
  49373. if (components.contains (component))
  49374. {
  49375. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49376. return false;
  49377. component->removeComponentListener (this);
  49378. const bool shouldDelete = shouldDeleteComp (component);
  49379. component->getProperties().remove ("mdiDocumentDelete_");
  49380. component->getProperties().remove ("mdiDocumentBkg_");
  49381. if (mode == FloatingWindows)
  49382. {
  49383. for (int i = getNumChildComponents(); --i >= 0;)
  49384. {
  49385. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49386. if (dw != 0 && dw->getContentComponent() == component)
  49387. {
  49388. dw->setContentComponent (0, false);
  49389. delete dw;
  49390. break;
  49391. }
  49392. }
  49393. if (shouldDelete)
  49394. delete component;
  49395. components.removeValue (component);
  49396. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49397. {
  49398. for (int i = getNumChildComponents(); --i >= 0;)
  49399. {
  49400. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49401. if (dw != 0)
  49402. {
  49403. dw->setContentComponent (0, false);
  49404. delete dw;
  49405. }
  49406. }
  49407. addAndMakeVisible (components.getFirst());
  49408. }
  49409. }
  49410. else
  49411. {
  49412. jassert (components.indexOf (component) >= 0);
  49413. if (tabComponent != 0)
  49414. {
  49415. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49416. if (tabComponent->getTabContentComponent (i) == component)
  49417. tabComponent->removeTab (i);
  49418. }
  49419. else
  49420. {
  49421. removeChildComponent (component);
  49422. }
  49423. if (shouldDelete)
  49424. delete component;
  49425. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49426. deleteAndZero (tabComponent);
  49427. components.removeValue (component);
  49428. if (components.size() > 0 && tabComponent == 0)
  49429. addAndMakeVisible (components.getFirst());
  49430. }
  49431. resized();
  49432. activeDocumentChanged();
  49433. }
  49434. else
  49435. {
  49436. jassertfalse
  49437. }
  49438. return true;
  49439. }
  49440. int MultiDocumentPanel::getNumDocuments() const throw()
  49441. {
  49442. return components.size();
  49443. }
  49444. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49445. {
  49446. return components [index];
  49447. }
  49448. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49449. {
  49450. if (mode == FloatingWindows)
  49451. {
  49452. for (int i = getNumChildComponents(); --i >= 0;)
  49453. {
  49454. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49455. if (dw != 0 && dw->isActiveWindow())
  49456. return dw->getContentComponent();
  49457. }
  49458. }
  49459. return components.getLast();
  49460. }
  49461. void MultiDocumentPanel::setActiveDocument (Component* component)
  49462. {
  49463. if (mode == FloatingWindows)
  49464. {
  49465. component = getContainerComp (component);
  49466. if (component != 0)
  49467. component->toFront (true);
  49468. }
  49469. else if (tabComponent != 0)
  49470. {
  49471. jassert (components.indexOf (component) >= 0);
  49472. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49473. {
  49474. if (tabComponent->getTabContentComponent (i) == component)
  49475. {
  49476. tabComponent->setCurrentTabIndex (i);
  49477. break;
  49478. }
  49479. }
  49480. }
  49481. else
  49482. {
  49483. component->grabKeyboardFocus();
  49484. }
  49485. }
  49486. void MultiDocumentPanel::activeDocumentChanged()
  49487. {
  49488. }
  49489. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49490. {
  49491. maximumNumDocuments = newNumber;
  49492. }
  49493. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49494. {
  49495. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49496. }
  49497. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49498. {
  49499. return numDocsBeforeTabsUsed != 0;
  49500. }
  49501. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49502. {
  49503. if (mode != newLayoutMode)
  49504. {
  49505. mode = newLayoutMode;
  49506. if (mode == FloatingWindows)
  49507. {
  49508. deleteAndZero (tabComponent);
  49509. }
  49510. else
  49511. {
  49512. for (int i = getNumChildComponents(); --i >= 0;)
  49513. {
  49514. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49515. if (dw != 0)
  49516. {
  49517. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49518. dw->setContentComponent (0, false);
  49519. delete dw;
  49520. }
  49521. }
  49522. }
  49523. resized();
  49524. const Array <Component*> tempComps (components);
  49525. components.clear();
  49526. for (int i = 0; i < tempComps.size(); ++i)
  49527. {
  49528. Component* const c = tempComps.getUnchecked(i);
  49529. addDocument (c,
  49530. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49531. shouldDeleteComp (c));
  49532. }
  49533. }
  49534. }
  49535. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49536. {
  49537. if (backgroundColour != newBackgroundColour)
  49538. {
  49539. backgroundColour = newBackgroundColour;
  49540. setOpaque (newBackgroundColour.isOpaque());
  49541. repaint();
  49542. }
  49543. }
  49544. void MultiDocumentPanel::paint (Graphics& g)
  49545. {
  49546. g.fillAll (backgroundColour);
  49547. }
  49548. void MultiDocumentPanel::resized()
  49549. {
  49550. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49551. {
  49552. for (int i = getNumChildComponents(); --i >= 0;)
  49553. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49554. }
  49555. setWantsKeyboardFocus (components.size() == 0);
  49556. }
  49557. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49558. {
  49559. if (mode == FloatingWindows)
  49560. {
  49561. for (int i = 0; i < getNumChildComponents(); ++i)
  49562. {
  49563. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49564. if (dw != 0 && dw->getContentComponent() == c)
  49565. {
  49566. c = dw;
  49567. break;
  49568. }
  49569. }
  49570. }
  49571. return c;
  49572. }
  49573. void MultiDocumentPanel::componentNameChanged (Component&)
  49574. {
  49575. if (mode == FloatingWindows)
  49576. {
  49577. for (int i = 0; i < getNumChildComponents(); ++i)
  49578. {
  49579. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49580. if (dw != 0)
  49581. dw->setName (dw->getContentComponent()->getName());
  49582. }
  49583. }
  49584. else if (tabComponent != 0)
  49585. {
  49586. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49587. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49588. }
  49589. }
  49590. void MultiDocumentPanel::updateOrder()
  49591. {
  49592. const Array <Component*> oldList (components);
  49593. if (mode == FloatingWindows)
  49594. {
  49595. components.clear();
  49596. for (int i = 0; i < getNumChildComponents(); ++i)
  49597. {
  49598. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49599. if (dw != 0)
  49600. components.add (dw->getContentComponent());
  49601. }
  49602. }
  49603. else
  49604. {
  49605. if (tabComponent != 0)
  49606. {
  49607. Component* const current = tabComponent->getCurrentContentComponent();
  49608. if (current != 0)
  49609. {
  49610. components.removeValue (current);
  49611. components.add (current);
  49612. }
  49613. }
  49614. }
  49615. if (components != oldList)
  49616. activeDocumentChanged();
  49617. }
  49618. END_JUCE_NAMESPACE
  49619. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49620. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49621. BEGIN_JUCE_NAMESPACE
  49622. const int zoneL = 1;
  49623. const int zoneR = 2;
  49624. const int zoneT = 4;
  49625. const int zoneB = 8;
  49626. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49627. ComponentBoundsConstrainer* const constrainer_)
  49628. : component (componentToResize),
  49629. constrainer (constrainer_),
  49630. borderSize (5),
  49631. mouseZone (0)
  49632. {
  49633. }
  49634. ResizableBorderComponent::~ResizableBorderComponent()
  49635. {
  49636. }
  49637. void ResizableBorderComponent::paint (Graphics& g)
  49638. {
  49639. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49640. }
  49641. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49642. {
  49643. updateMouseZone (e);
  49644. }
  49645. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49646. {
  49647. updateMouseZone (e);
  49648. }
  49649. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49650. {
  49651. if (component->isValidComponent())
  49652. {
  49653. updateMouseZone (e);
  49654. originalX = component->getX();
  49655. originalY = component->getY();
  49656. originalW = component->getWidth();
  49657. originalH = component->getHeight();
  49658. if (constrainer != 0)
  49659. constrainer->resizeStart();
  49660. }
  49661. else
  49662. {
  49663. jassertfalse
  49664. }
  49665. }
  49666. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49667. {
  49668. if (! component->isValidComponent())
  49669. {
  49670. jassertfalse
  49671. return;
  49672. }
  49673. int x = originalX;
  49674. int y = originalY;
  49675. int w = originalW;
  49676. int h = originalH;
  49677. const int dx = e.getDistanceFromDragStartX();
  49678. const int dy = e.getDistanceFromDragStartY();
  49679. if ((mouseZone & zoneL) != 0)
  49680. {
  49681. x += dx;
  49682. w -= dx;
  49683. }
  49684. if ((mouseZone & zoneT) != 0)
  49685. {
  49686. y += dy;
  49687. h -= dy;
  49688. }
  49689. if ((mouseZone & zoneR) != 0)
  49690. w += dx;
  49691. if ((mouseZone & zoneB) != 0)
  49692. h += dy;
  49693. if (constrainer != 0)
  49694. constrainer->setBoundsForComponent (component,
  49695. Rectangle<int> (x, y, w, h),
  49696. (mouseZone & zoneT) != 0,
  49697. (mouseZone & zoneL) != 0,
  49698. (mouseZone & zoneB) != 0,
  49699. (mouseZone & zoneR) != 0);
  49700. else
  49701. component->setBounds (x, y, w, h);
  49702. }
  49703. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49704. {
  49705. if (constrainer != 0)
  49706. constrainer->resizeEnd();
  49707. }
  49708. bool ResizableBorderComponent::hitTest (int x, int y)
  49709. {
  49710. return x < borderSize.getLeft()
  49711. || x >= getWidth() - borderSize.getRight()
  49712. || y < borderSize.getTop()
  49713. || y >= getHeight() - borderSize.getBottom();
  49714. }
  49715. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw()
  49716. {
  49717. if (borderSize != newBorderSize)
  49718. {
  49719. borderSize = newBorderSize;
  49720. repaint();
  49721. }
  49722. }
  49723. const BorderSize ResizableBorderComponent::getBorderThickness() const throw()
  49724. {
  49725. return borderSize;
  49726. }
  49727. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw()
  49728. {
  49729. int newZone = 0;
  49730. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49731. {
  49732. if (e.x < jmax (borderSize.getLeft(),
  49733. proportionOfWidth (0.1f),
  49734. jmin (10, proportionOfWidth (0.33f))))
  49735. newZone |= zoneL;
  49736. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49737. proportionOfWidth (0.9f),
  49738. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49739. newZone |= zoneR;
  49740. if (e.y < jmax (borderSize.getTop(),
  49741. proportionOfHeight (0.1f),
  49742. jmin (10, proportionOfHeight (0.33f))))
  49743. newZone |= zoneT;
  49744. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49745. proportionOfHeight (0.9f),
  49746. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49747. newZone |= zoneB;
  49748. }
  49749. if (mouseZone != newZone)
  49750. {
  49751. mouseZone = newZone;
  49752. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49753. switch (newZone)
  49754. {
  49755. case (zoneL | zoneT):
  49756. mc = MouseCursor::TopLeftCornerResizeCursor;
  49757. break;
  49758. case zoneT:
  49759. mc = MouseCursor::TopEdgeResizeCursor;
  49760. break;
  49761. case (zoneR | zoneT):
  49762. mc = MouseCursor::TopRightCornerResizeCursor;
  49763. break;
  49764. case zoneL:
  49765. mc = MouseCursor::LeftEdgeResizeCursor;
  49766. break;
  49767. case zoneR:
  49768. mc = MouseCursor::RightEdgeResizeCursor;
  49769. break;
  49770. case (zoneL | zoneB):
  49771. mc = MouseCursor::BottomLeftCornerResizeCursor;
  49772. break;
  49773. case zoneB:
  49774. mc = MouseCursor::BottomEdgeResizeCursor;
  49775. break;
  49776. case (zoneR | zoneB):
  49777. mc = MouseCursor::BottomRightCornerResizeCursor;
  49778. break;
  49779. default:
  49780. break;
  49781. }
  49782. setMouseCursor (mc);
  49783. }
  49784. }
  49785. END_JUCE_NAMESPACE
  49786. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49787. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49788. BEGIN_JUCE_NAMESPACE
  49789. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49790. ComponentBoundsConstrainer* const constrainer_)
  49791. : component (componentToResize),
  49792. constrainer (constrainer_)
  49793. {
  49794. setRepaintsOnMouseActivity (true);
  49795. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49796. }
  49797. ResizableCornerComponent::~ResizableCornerComponent()
  49798. {
  49799. }
  49800. void ResizableCornerComponent::paint (Graphics& g)
  49801. {
  49802. getLookAndFeel()
  49803. .drawCornerResizer (g, getWidth(), getHeight(),
  49804. isMouseOverOrDragging(),
  49805. isMouseButtonDown());
  49806. }
  49807. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49808. {
  49809. if (component->isValidComponent())
  49810. {
  49811. originalX = component->getX();
  49812. originalY = component->getY();
  49813. originalW = component->getWidth();
  49814. originalH = component->getHeight();
  49815. if (constrainer != 0)
  49816. constrainer->resizeStart();
  49817. }
  49818. else
  49819. {
  49820. jassertfalse
  49821. }
  49822. }
  49823. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49824. {
  49825. if (! component->isValidComponent())
  49826. {
  49827. jassertfalse
  49828. return;
  49829. }
  49830. int x = originalX;
  49831. int y = originalY;
  49832. int w = originalW + e.getDistanceFromDragStartX();
  49833. int h = originalH + e.getDistanceFromDragStartY();
  49834. if (constrainer != 0)
  49835. constrainer->setBoundsForComponent (component, Rectangle<int> (x, y, w, h),
  49836. false, false, true, true);
  49837. else
  49838. component->setBounds (x, y, w, h);
  49839. }
  49840. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49841. {
  49842. if (constrainer != 0)
  49843. constrainer->resizeStart();
  49844. }
  49845. bool ResizableCornerComponent::hitTest (int x, int y)
  49846. {
  49847. if (getWidth() <= 0)
  49848. return false;
  49849. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49850. return y >= yAtX - getHeight() / 4;
  49851. }
  49852. END_JUCE_NAMESPACE
  49853. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49854. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49855. BEGIN_JUCE_NAMESPACE
  49856. class ScrollbarButton : public Button
  49857. {
  49858. public:
  49859. int direction;
  49860. ScrollbarButton (const int direction_,
  49861. ScrollBar& owner_) throw()
  49862. : Button (String::empty),
  49863. direction (direction_),
  49864. owner (owner_)
  49865. {
  49866. setWantsKeyboardFocus (false);
  49867. }
  49868. ~ScrollbarButton()
  49869. {
  49870. }
  49871. void paintButton (Graphics& g,
  49872. bool isMouseOver,
  49873. bool isMouseDown)
  49874. {
  49875. getLookAndFeel()
  49876. .drawScrollbarButton (g, owner,
  49877. getWidth(), getHeight(),
  49878. direction,
  49879. owner.isVertical(),
  49880. isMouseOver, isMouseDown);
  49881. }
  49882. void clicked()
  49883. {
  49884. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49885. }
  49886. juce_UseDebuggingNewOperator
  49887. private:
  49888. ScrollBar& owner;
  49889. ScrollbarButton (const ScrollbarButton&);
  49890. ScrollbarButton& operator= (const ScrollbarButton&);
  49891. };
  49892. ScrollBar::ScrollBar (const bool vertical_,
  49893. const bool buttonsAreVisible)
  49894. : minimum (0.0),
  49895. maximum (1.0),
  49896. rangeStart (0.0),
  49897. rangeSize (0.1),
  49898. singleStepSize (0.1),
  49899. thumbAreaStart (0),
  49900. thumbAreaSize (0),
  49901. thumbStart (0),
  49902. thumbSize (0),
  49903. initialDelayInMillisecs (100),
  49904. repeatDelayInMillisecs (50),
  49905. minimumDelayInMillisecs (10),
  49906. vertical (vertical_),
  49907. isDraggingThumb (false),
  49908. alwaysVisible (false),
  49909. upButton (0),
  49910. downButton (0)
  49911. {
  49912. setButtonVisibility (buttonsAreVisible);
  49913. setRepaintsOnMouseActivity (true);
  49914. setFocusContainer (true);
  49915. }
  49916. ScrollBar::~ScrollBar()
  49917. {
  49918. deleteAllChildren();
  49919. }
  49920. void ScrollBar::setRangeLimits (const double newMinimum,
  49921. const double newMaximum) throw()
  49922. {
  49923. minimum = newMinimum;
  49924. maximum = newMaximum;
  49925. jassert (maximum >= minimum); // these can't be the wrong way round!
  49926. setCurrentRangeStart (rangeStart);
  49927. updateThumbPosition();
  49928. }
  49929. void ScrollBar::setCurrentRange (double newStart,
  49930. double newSize) throw()
  49931. {
  49932. newSize = jlimit (0.0, maximum - minimum, newSize);
  49933. newStart = jlimit (minimum, maximum - newSize, newStart);
  49934. if (rangeStart != newStart
  49935. || rangeSize != newSize)
  49936. {
  49937. rangeStart = newStart;
  49938. rangeSize = newSize;
  49939. updateThumbPosition();
  49940. triggerAsyncUpdate();
  49941. }
  49942. }
  49943. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  49944. {
  49945. setCurrentRange (newStart, rangeSize);
  49946. }
  49947. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  49948. {
  49949. singleStepSize = newSingleStepSize;
  49950. }
  49951. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  49952. {
  49953. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  49954. }
  49955. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  49956. {
  49957. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  49958. }
  49959. void ScrollBar::scrollToTop() throw()
  49960. {
  49961. setCurrentRangeStart (minimum);
  49962. }
  49963. void ScrollBar::scrollToBottom() throw()
  49964. {
  49965. setCurrentRangeStart (maximum - rangeSize);
  49966. }
  49967. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49968. const int repeatDelayInMillisecs_,
  49969. const int minimumDelayInMillisecs_) throw()
  49970. {
  49971. initialDelayInMillisecs = initialDelayInMillisecs_;
  49972. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49973. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49974. if (upButton != 0)
  49975. {
  49976. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49977. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49978. }
  49979. }
  49980. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  49981. {
  49982. jassert (listener != 0);
  49983. if (listener != 0)
  49984. listeners.add (listener);
  49985. }
  49986. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  49987. {
  49988. listeners.removeValue (listener);
  49989. }
  49990. void ScrollBar::handleAsyncUpdate()
  49991. {
  49992. const double value = getCurrentRangeStart();
  49993. for (int i = listeners.size(); --i >= 0;)
  49994. {
  49995. ((ScrollBarListener*) listeners.getUnchecked (i))->scrollBarMoved (this, value);
  49996. i = jmin (i, listeners.size());
  49997. }
  49998. }
  49999. void ScrollBar::updateThumbPosition() throw()
  50000. {
  50001. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  50002. : thumbAreaSize);
  50003. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50004. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  50005. if (newThumbSize > thumbAreaSize)
  50006. newThumbSize = thumbAreaSize;
  50007. int newThumbStart = thumbAreaStart;
  50008. if (maximum - minimum > rangeSize)
  50009. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  50010. / ((maximum - minimum) - rangeSize));
  50011. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  50012. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  50013. {
  50014. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  50015. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  50016. if (vertical)
  50017. repaint (0, repaintStart, getWidth(), repaintSize);
  50018. else
  50019. repaint (repaintStart, 0, repaintSize, getHeight());
  50020. thumbStart = newThumbStart;
  50021. thumbSize = newThumbSize;
  50022. }
  50023. }
  50024. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  50025. {
  50026. if (vertical != shouldBeVertical)
  50027. {
  50028. vertical = shouldBeVertical;
  50029. if (upButton != 0)
  50030. {
  50031. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  50032. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  50033. }
  50034. updateThumbPosition();
  50035. }
  50036. }
  50037. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  50038. {
  50039. deleteAndZero (upButton);
  50040. deleteAndZero (downButton);
  50041. if (buttonsAreVisible)
  50042. {
  50043. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  50044. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  50045. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50046. }
  50047. updateThumbPosition();
  50048. }
  50049. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  50050. {
  50051. alwaysVisible = ! shouldHideWhenFullRange;
  50052. updateThumbPosition();
  50053. }
  50054. void ScrollBar::paint (Graphics& g)
  50055. {
  50056. if (thumbAreaSize > 0)
  50057. {
  50058. LookAndFeel& lf = getLookAndFeel();
  50059. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  50060. ? thumbSize : 0;
  50061. if (vertical)
  50062. {
  50063. lf.drawScrollbar (g, *this,
  50064. 0, thumbAreaStart,
  50065. getWidth(), thumbAreaSize,
  50066. vertical,
  50067. thumbStart, thumb,
  50068. isMouseOver(), isMouseButtonDown());
  50069. }
  50070. else
  50071. {
  50072. lf.drawScrollbar (g, *this,
  50073. thumbAreaStart, 0,
  50074. thumbAreaSize, getHeight(),
  50075. vertical,
  50076. thumbStart, thumb,
  50077. isMouseOver(), isMouseButtonDown());
  50078. }
  50079. }
  50080. }
  50081. void ScrollBar::lookAndFeelChanged()
  50082. {
  50083. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  50084. }
  50085. void ScrollBar::resized()
  50086. {
  50087. const int length = ((vertical) ? getHeight() : getWidth());
  50088. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  50089. : 0;
  50090. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50091. {
  50092. thumbAreaStart = length >> 1;
  50093. thumbAreaSize = 0;
  50094. }
  50095. else
  50096. {
  50097. thumbAreaStart = buttonSize;
  50098. thumbAreaSize = length - (buttonSize << 1);
  50099. }
  50100. if (upButton != 0)
  50101. {
  50102. if (vertical)
  50103. {
  50104. upButton->setBounds (0, 0, getWidth(), buttonSize);
  50105. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  50106. }
  50107. else
  50108. {
  50109. upButton->setBounds (0, 0, buttonSize, getHeight());
  50110. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  50111. }
  50112. }
  50113. updateThumbPosition();
  50114. }
  50115. void ScrollBar::mouseDown (const MouseEvent& e)
  50116. {
  50117. isDraggingThumb = false;
  50118. lastMousePos = vertical ? e.y : e.x;
  50119. dragStartMousePos = lastMousePos;
  50120. dragStartRange = rangeStart;
  50121. if (dragStartMousePos < thumbStart)
  50122. {
  50123. moveScrollbarInPages (-1);
  50124. startTimer (400);
  50125. }
  50126. else if (dragStartMousePos >= thumbStart + thumbSize)
  50127. {
  50128. moveScrollbarInPages (1);
  50129. startTimer (400);
  50130. }
  50131. else
  50132. {
  50133. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50134. && (thumbAreaSize > thumbSize);
  50135. }
  50136. }
  50137. void ScrollBar::mouseDrag (const MouseEvent& e)
  50138. {
  50139. if (isDraggingThumb)
  50140. {
  50141. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  50142. setCurrentRangeStart (dragStartRange
  50143. + deltaPixels * ((maximum - minimum) - rangeSize)
  50144. / (thumbAreaSize - thumbSize));
  50145. }
  50146. else
  50147. {
  50148. lastMousePos = (vertical) ? e.y : e.x;
  50149. }
  50150. }
  50151. void ScrollBar::mouseUp (const MouseEvent&)
  50152. {
  50153. isDraggingThumb = false;
  50154. stopTimer();
  50155. repaint();
  50156. }
  50157. void ScrollBar::mouseWheelMove (const MouseEvent&,
  50158. float wheelIncrementX,
  50159. float wheelIncrementY)
  50160. {
  50161. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  50162. if (increment < 0)
  50163. increment = jmin (increment * 10.0f, -1.0f);
  50164. else if (increment > 0)
  50165. increment = jmax (increment * 10.0f, 1.0f);
  50166. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  50167. }
  50168. void ScrollBar::timerCallback()
  50169. {
  50170. if (isMouseButtonDown())
  50171. {
  50172. startTimer (40);
  50173. if (lastMousePos < thumbStart)
  50174. setCurrentRangeStart (rangeStart - rangeSize);
  50175. else if (lastMousePos > thumbStart + thumbSize)
  50176. setCurrentRangeStart (rangeStart + rangeSize);
  50177. }
  50178. else
  50179. {
  50180. stopTimer();
  50181. }
  50182. }
  50183. bool ScrollBar::keyPressed (const KeyPress& key)
  50184. {
  50185. if (! isVisible())
  50186. return false;
  50187. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  50188. moveScrollbarInSteps (-1);
  50189. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  50190. moveScrollbarInSteps (1);
  50191. else if (key.isKeyCode (KeyPress::pageUpKey))
  50192. moveScrollbarInPages (-1);
  50193. else if (key.isKeyCode (KeyPress::pageDownKey))
  50194. moveScrollbarInPages (1);
  50195. else if (key.isKeyCode (KeyPress::homeKey))
  50196. scrollToTop();
  50197. else if (key.isKeyCode (KeyPress::endKey))
  50198. scrollToBottom();
  50199. else
  50200. return false;
  50201. return true;
  50202. }
  50203. END_JUCE_NAMESPACE
  50204. /*** End of inlined file: juce_ScrollBar.cpp ***/
  50205. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  50206. BEGIN_JUCE_NAMESPACE
  50207. StretchableLayoutManager::StretchableLayoutManager()
  50208. : totalSize (0)
  50209. {
  50210. }
  50211. StretchableLayoutManager::~StretchableLayoutManager()
  50212. {
  50213. }
  50214. void StretchableLayoutManager::clearAllItems()
  50215. {
  50216. items.clear();
  50217. totalSize = 0;
  50218. }
  50219. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  50220. const double minimumSize,
  50221. const double maximumSize,
  50222. const double preferredSize)
  50223. {
  50224. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  50225. if (layout == 0)
  50226. {
  50227. layout = new ItemLayoutProperties();
  50228. layout->itemIndex = itemIndex;
  50229. int i;
  50230. for (i = 0; i < items.size(); ++i)
  50231. if (items.getUnchecked (i)->itemIndex > itemIndex)
  50232. break;
  50233. items.insert (i, layout);
  50234. }
  50235. layout->minSize = minimumSize;
  50236. layout->maxSize = maximumSize;
  50237. layout->preferredSize = preferredSize;
  50238. layout->currentSize = 0;
  50239. }
  50240. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  50241. double& minimumSize,
  50242. double& maximumSize,
  50243. double& preferredSize) const
  50244. {
  50245. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50246. if (layout != 0)
  50247. {
  50248. minimumSize = layout->minSize;
  50249. maximumSize = layout->maxSize;
  50250. preferredSize = layout->preferredSize;
  50251. return true;
  50252. }
  50253. return false;
  50254. }
  50255. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  50256. {
  50257. totalSize = newTotalSize;
  50258. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  50259. }
  50260. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  50261. {
  50262. int pos = 0;
  50263. for (int i = 0; i < itemIndex; ++i)
  50264. {
  50265. const ItemLayoutProperties* const layout = getInfoFor (i);
  50266. if (layout != 0)
  50267. pos += layout->currentSize;
  50268. }
  50269. return pos;
  50270. }
  50271. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  50272. {
  50273. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50274. if (layout != 0)
  50275. return layout->currentSize;
  50276. return 0;
  50277. }
  50278. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  50279. {
  50280. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50281. if (layout != 0)
  50282. return -layout->currentSize / (double) totalSize;
  50283. return 0;
  50284. }
  50285. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  50286. int newPosition)
  50287. {
  50288. for (int i = items.size(); --i >= 0;)
  50289. {
  50290. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  50291. if (layout->itemIndex == itemIndex)
  50292. {
  50293. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  50294. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  50295. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  50296. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  50297. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  50298. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  50299. endPos += layout->currentSize;
  50300. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  50301. updatePrefSizesToMatchCurrentPositions();
  50302. break;
  50303. }
  50304. }
  50305. }
  50306. void StretchableLayoutManager::layOutComponents (Component** const components,
  50307. int numComponents,
  50308. int x, int y, int w, int h,
  50309. const bool vertically,
  50310. const bool resizeOtherDimension)
  50311. {
  50312. setTotalSize (vertically ? h : w);
  50313. int pos = vertically ? y : x;
  50314. for (int i = 0; i < numComponents; ++i)
  50315. {
  50316. const ItemLayoutProperties* const layout = getInfoFor (i);
  50317. if (layout != 0)
  50318. {
  50319. Component* const c = components[i];
  50320. if (c != 0)
  50321. {
  50322. if (i == numComponents - 1)
  50323. {
  50324. // if it's the last item, crop it to exactly fit the available space..
  50325. if (resizeOtherDimension)
  50326. {
  50327. if (vertically)
  50328. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  50329. else
  50330. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  50331. }
  50332. else
  50333. {
  50334. if (vertically)
  50335. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  50336. else
  50337. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  50338. }
  50339. }
  50340. else
  50341. {
  50342. if (resizeOtherDimension)
  50343. {
  50344. if (vertically)
  50345. c->setBounds (x, pos, w, layout->currentSize);
  50346. else
  50347. c->setBounds (pos, y, layout->currentSize, h);
  50348. }
  50349. else
  50350. {
  50351. if (vertically)
  50352. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  50353. else
  50354. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  50355. }
  50356. }
  50357. }
  50358. pos += layout->currentSize;
  50359. }
  50360. }
  50361. }
  50362. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  50363. {
  50364. for (int i = items.size(); --i >= 0;)
  50365. if (items.getUnchecked(i)->itemIndex == itemIndex)
  50366. return items.getUnchecked(i);
  50367. return 0;
  50368. }
  50369. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  50370. const int endIndex,
  50371. const int availableSpace,
  50372. int startPos)
  50373. {
  50374. // calculate the total sizes
  50375. int i;
  50376. double totalIdealSize = 0.0;
  50377. int totalMinimums = 0;
  50378. for (i = startIndex; i < endIndex; ++i)
  50379. {
  50380. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50381. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  50382. totalMinimums += layout->currentSize;
  50383. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  50384. }
  50385. if (totalIdealSize <= 0)
  50386. totalIdealSize = 1.0;
  50387. // now calc the best sizes..
  50388. int extraSpace = availableSpace - totalMinimums;
  50389. while (extraSpace > 0)
  50390. {
  50391. int numWantingMoreSpace = 0;
  50392. int numHavingTakenExtraSpace = 0;
  50393. // first figure out how many comps want a slice of the extra space..
  50394. for (i = startIndex; i < endIndex; ++i)
  50395. {
  50396. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50397. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50398. const int bestSize = jlimit (layout->currentSize,
  50399. jmax (layout->currentSize,
  50400. sizeToRealSize (layout->maxSize, totalSize)),
  50401. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50402. if (bestSize > layout->currentSize)
  50403. ++numWantingMoreSpace;
  50404. }
  50405. // ..share out the extra space..
  50406. for (i = startIndex; i < endIndex; ++i)
  50407. {
  50408. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50409. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50410. int bestSize = jlimit (layout->currentSize,
  50411. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  50412. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50413. const int extraWanted = bestSize - layout->currentSize;
  50414. if (extraWanted > 0)
  50415. {
  50416. const int extraAllowed = jmin (extraWanted,
  50417. extraSpace / jmax (1, numWantingMoreSpace));
  50418. if (extraAllowed > 0)
  50419. {
  50420. ++numHavingTakenExtraSpace;
  50421. --numWantingMoreSpace;
  50422. layout->currentSize += extraAllowed;
  50423. extraSpace -= extraAllowed;
  50424. }
  50425. }
  50426. }
  50427. if (numHavingTakenExtraSpace <= 0)
  50428. break;
  50429. }
  50430. // ..and calculate the end position
  50431. for (i = startIndex; i < endIndex; ++i)
  50432. {
  50433. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50434. startPos += layout->currentSize;
  50435. }
  50436. return startPos;
  50437. }
  50438. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50439. const int endIndex) const
  50440. {
  50441. int totalMinimums = 0;
  50442. for (int i = startIndex; i < endIndex; ++i)
  50443. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50444. return totalMinimums;
  50445. }
  50446. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50447. {
  50448. int totalMaximums = 0;
  50449. for (int i = startIndex; i < endIndex; ++i)
  50450. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50451. return totalMaximums;
  50452. }
  50453. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50454. {
  50455. for (int i = 0; i < items.size(); ++i)
  50456. {
  50457. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50458. layout->preferredSize
  50459. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50460. : getItemCurrentAbsoluteSize (i);
  50461. }
  50462. }
  50463. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50464. {
  50465. if (size < 0)
  50466. size *= -totalSpace;
  50467. return roundToInt (size);
  50468. }
  50469. END_JUCE_NAMESPACE
  50470. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  50471. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50472. BEGIN_JUCE_NAMESPACE
  50473. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50474. const int itemIndex_,
  50475. const bool isVertical_)
  50476. : layout (layout_),
  50477. itemIndex (itemIndex_),
  50478. isVertical (isVertical_)
  50479. {
  50480. setRepaintsOnMouseActivity (true);
  50481. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50482. : MouseCursor::UpDownResizeCursor));
  50483. }
  50484. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50485. {
  50486. }
  50487. void StretchableLayoutResizerBar::paint (Graphics& g)
  50488. {
  50489. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50490. getWidth(), getHeight(),
  50491. isVertical,
  50492. isMouseOver(),
  50493. isMouseButtonDown());
  50494. }
  50495. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50496. {
  50497. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50498. }
  50499. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50500. {
  50501. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50502. : e.getDistanceFromDragStartY());
  50503. layout->setItemPosition (itemIndex, desiredPos);
  50504. hasBeenMoved();
  50505. }
  50506. void StretchableLayoutResizerBar::hasBeenMoved()
  50507. {
  50508. if (getParentComponent() != 0)
  50509. getParentComponent()->resized();
  50510. }
  50511. END_JUCE_NAMESPACE
  50512. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50513. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50514. BEGIN_JUCE_NAMESPACE
  50515. StretchableObjectResizer::StretchableObjectResizer()
  50516. {
  50517. }
  50518. StretchableObjectResizer::~StretchableObjectResizer()
  50519. {
  50520. }
  50521. void StretchableObjectResizer::addItem (const double size,
  50522. const double minSize, const double maxSize,
  50523. const int order)
  50524. {
  50525. // the order must be >= 0 but less than the maximum integer value.
  50526. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50527. Item* const item = new Item();
  50528. item->size = size;
  50529. item->minSize = minSize;
  50530. item->maxSize = maxSize;
  50531. item->order = order;
  50532. items.add (item);
  50533. }
  50534. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50535. {
  50536. const Item* const it = items [index];
  50537. return it != 0 ? it->size : 0;
  50538. }
  50539. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50540. {
  50541. int order = 0;
  50542. for (;;)
  50543. {
  50544. double currentSize = 0;
  50545. double minSize = 0;
  50546. double maxSize = 0;
  50547. int nextHighestOrder = std::numeric_limits<int>::max();
  50548. for (int i = 0; i < items.size(); ++i)
  50549. {
  50550. const Item* const it = items.getUnchecked(i);
  50551. currentSize += it->size;
  50552. if (it->order <= order)
  50553. {
  50554. minSize += it->minSize;
  50555. maxSize += it->maxSize;
  50556. }
  50557. else
  50558. {
  50559. minSize += it->size;
  50560. maxSize += it->size;
  50561. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50562. }
  50563. }
  50564. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50565. if (thisIterationTarget >= currentSize)
  50566. {
  50567. const double availableExtraSpace = maxSize - currentSize;
  50568. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50569. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50570. for (int i = 0; i < items.size(); ++i)
  50571. {
  50572. Item* const it = items.getUnchecked(i);
  50573. if (it->order <= order)
  50574. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50575. }
  50576. }
  50577. else
  50578. {
  50579. const double amountOfSlack = currentSize - minSize;
  50580. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50581. const double scale = targetAmountOfSlack / amountOfSlack;
  50582. for (int i = 0; i < items.size(); ++i)
  50583. {
  50584. Item* const it = items.getUnchecked(i);
  50585. if (it->order <= order)
  50586. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50587. }
  50588. }
  50589. if (nextHighestOrder < std::numeric_limits<int>::max())
  50590. order = nextHighestOrder;
  50591. else
  50592. break;
  50593. }
  50594. }
  50595. END_JUCE_NAMESPACE
  50596. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50597. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50598. BEGIN_JUCE_NAMESPACE
  50599. TabBarButton::TabBarButton (const String& name,
  50600. TabbedButtonBar* const owner_,
  50601. const int index)
  50602. : Button (name),
  50603. owner (owner_),
  50604. tabIndex (index),
  50605. overlapPixels (0)
  50606. {
  50607. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50608. setComponentEffect (&shadow);
  50609. setWantsKeyboardFocus (false);
  50610. }
  50611. TabBarButton::~TabBarButton()
  50612. {
  50613. }
  50614. void TabBarButton::paintButton (Graphics& g,
  50615. bool isMouseOverButton,
  50616. bool isButtonDown)
  50617. {
  50618. int x, y, w, h;
  50619. getActiveArea (x, y, w, h);
  50620. g.setOrigin (x, y);
  50621. getLookAndFeel()
  50622. .drawTabButton (g, w, h,
  50623. owner->getTabBackgroundColour (tabIndex),
  50624. tabIndex, getButtonText(), *this,
  50625. owner->getOrientation(),
  50626. isMouseOverButton, isButtonDown,
  50627. getToggleState());
  50628. }
  50629. void TabBarButton::clicked (const ModifierKeys& mods)
  50630. {
  50631. if (mods.isPopupMenu())
  50632. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50633. else
  50634. owner->setCurrentTabIndex (tabIndex);
  50635. }
  50636. bool TabBarButton::hitTest (int mx, int my)
  50637. {
  50638. int x, y, w, h;
  50639. getActiveArea (x, y, w, h);
  50640. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50641. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50642. {
  50643. if (((unsigned int) mx) < (unsigned int) getWidth()
  50644. && my >= y + overlapPixels
  50645. && my < y + h - overlapPixels)
  50646. return true;
  50647. }
  50648. else
  50649. {
  50650. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50651. && ((unsigned int) my) < (unsigned int) getHeight())
  50652. return true;
  50653. }
  50654. Path p;
  50655. getLookAndFeel()
  50656. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50657. owner->getOrientation(),
  50658. false, false, getToggleState());
  50659. return p.contains ((float) (mx - x),
  50660. (float) (my - y));
  50661. }
  50662. int TabBarButton::getBestTabLength (const int depth)
  50663. {
  50664. return jlimit (depth * 2,
  50665. depth * 7,
  50666. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50667. }
  50668. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50669. {
  50670. x = 0;
  50671. y = 0;
  50672. int r = getWidth();
  50673. int b = getHeight();
  50674. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50675. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50676. r -= spaceAroundImage;
  50677. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50678. x += spaceAroundImage;
  50679. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50680. y += spaceAroundImage;
  50681. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50682. b -= spaceAroundImage;
  50683. w = r - x;
  50684. h = b - y;
  50685. }
  50686. class TabAreaBehindFrontButtonComponent : public Component
  50687. {
  50688. public:
  50689. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50690. : owner (owner_)
  50691. {
  50692. setInterceptsMouseClicks (false, false);
  50693. }
  50694. ~TabAreaBehindFrontButtonComponent()
  50695. {
  50696. }
  50697. void paint (Graphics& g)
  50698. {
  50699. getLookAndFeel()
  50700. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50701. *owner, owner->getOrientation());
  50702. }
  50703. void enablementChanged()
  50704. {
  50705. repaint();
  50706. }
  50707. private:
  50708. TabbedButtonBar* const owner;
  50709. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50710. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50711. };
  50712. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50713. : orientation (orientation_),
  50714. currentTabIndex (-1),
  50715. extraTabsButton (0)
  50716. {
  50717. setInterceptsMouseClicks (false, true);
  50718. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50719. setFocusContainer (true);
  50720. }
  50721. TabbedButtonBar::~TabbedButtonBar()
  50722. {
  50723. deleteAllChildren();
  50724. }
  50725. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50726. {
  50727. orientation = newOrientation;
  50728. for (int i = getNumChildComponents(); --i >= 0;)
  50729. getChildComponent (i)->resized();
  50730. resized();
  50731. }
  50732. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50733. {
  50734. return new TabBarButton (name, this, index);
  50735. }
  50736. void TabbedButtonBar::clearTabs()
  50737. {
  50738. tabs.clear();
  50739. tabColours.clear();
  50740. currentTabIndex = -1;
  50741. deleteAndZero (extraTabsButton);
  50742. removeChildComponent (behindFrontTab);
  50743. deleteAllChildren();
  50744. addChildComponent (behindFrontTab);
  50745. setCurrentTabIndex (-1);
  50746. }
  50747. void TabbedButtonBar::addTab (const String& tabName,
  50748. const Colour& tabBackgroundColour,
  50749. int insertIndex)
  50750. {
  50751. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50752. if (tabName.isNotEmpty())
  50753. {
  50754. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50755. insertIndex = tabs.size();
  50756. for (int i = tabs.size(); --i >= insertIndex;)
  50757. {
  50758. TabBarButton* const tb = getTabButton (i);
  50759. if (tb != 0)
  50760. tb->tabIndex++;
  50761. }
  50762. tabs.insert (insertIndex, tabName);
  50763. tabColours.insert (insertIndex, tabBackgroundColour);
  50764. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50765. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50766. addAndMakeVisible (tb, insertIndex);
  50767. resized();
  50768. if (currentTabIndex < 0)
  50769. setCurrentTabIndex (0);
  50770. }
  50771. }
  50772. void TabbedButtonBar::setTabName (const int tabIndex,
  50773. const String& newName)
  50774. {
  50775. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50776. && tabs[tabIndex] != newName)
  50777. {
  50778. tabs.set (tabIndex, newName);
  50779. TabBarButton* const tb = getTabButton (tabIndex);
  50780. if (tb != 0)
  50781. tb->setButtonText (newName);
  50782. resized();
  50783. }
  50784. }
  50785. void TabbedButtonBar::removeTab (const int tabIndex)
  50786. {
  50787. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50788. {
  50789. const int oldTabIndex = currentTabIndex;
  50790. if (currentTabIndex == tabIndex)
  50791. currentTabIndex = -1;
  50792. tabs.remove (tabIndex);
  50793. tabColours.remove (tabIndex);
  50794. delete getTabButton (tabIndex);
  50795. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50796. {
  50797. TabBarButton* const tb = getTabButton (i);
  50798. if (tb != 0)
  50799. tb->tabIndex--;
  50800. }
  50801. resized();
  50802. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50803. }
  50804. }
  50805. void TabbedButtonBar::moveTab (const int currentIndex,
  50806. const int newIndex)
  50807. {
  50808. tabs.move (currentIndex, newIndex);
  50809. tabColours.move (currentIndex, newIndex);
  50810. resized();
  50811. }
  50812. int TabbedButtonBar::getNumTabs() const
  50813. {
  50814. return tabs.size();
  50815. }
  50816. const StringArray TabbedButtonBar::getTabNames() const
  50817. {
  50818. return tabs;
  50819. }
  50820. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50821. {
  50822. if (currentTabIndex != newIndex)
  50823. {
  50824. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50825. newIndex = -1;
  50826. currentTabIndex = newIndex;
  50827. for (int i = 0; i < getNumChildComponents(); ++i)
  50828. {
  50829. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50830. if (tb != 0)
  50831. tb->setToggleState (tb->tabIndex == newIndex, false);
  50832. }
  50833. resized();
  50834. if (sendChangeMessage_)
  50835. sendChangeMessage (this);
  50836. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50837. }
  50838. }
  50839. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50840. {
  50841. for (int i = getNumChildComponents(); --i >= 0;)
  50842. {
  50843. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50844. if (tb != 0 && tb->tabIndex == index)
  50845. return tb;
  50846. }
  50847. return 0;
  50848. }
  50849. void TabbedButtonBar::lookAndFeelChanged()
  50850. {
  50851. deleteAndZero (extraTabsButton);
  50852. resized();
  50853. }
  50854. void TabbedButtonBar::resized()
  50855. {
  50856. const double minimumScale = 0.7;
  50857. int depth = getWidth();
  50858. int length = getHeight();
  50859. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50860. swapVariables (depth, length);
  50861. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50862. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50863. int i, totalLength = overlap;
  50864. int numVisibleButtons = tabs.size();
  50865. for (i = 0; i < getNumChildComponents(); ++i)
  50866. {
  50867. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50868. if (tb != 0)
  50869. {
  50870. totalLength += tb->getBestTabLength (depth) - overlap;
  50871. tb->overlapPixels = overlap / 2;
  50872. }
  50873. }
  50874. double scale = 1.0;
  50875. if (totalLength > length)
  50876. scale = jmax (minimumScale, length / (double) totalLength);
  50877. const bool isTooBig = totalLength * scale > length;
  50878. int tabsButtonPos = 0;
  50879. if (isTooBig)
  50880. {
  50881. if (extraTabsButton == 0)
  50882. {
  50883. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50884. extraTabsButton->addButtonListener (this);
  50885. extraTabsButton->setAlwaysOnTop (true);
  50886. extraTabsButton->setTriggeredOnMouseDown (true);
  50887. }
  50888. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50889. extraTabsButton->setSize (buttonSize, buttonSize);
  50890. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50891. {
  50892. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50893. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50894. }
  50895. else
  50896. {
  50897. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50898. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50899. }
  50900. totalLength = 0;
  50901. for (i = 0; i < tabs.size(); ++i)
  50902. {
  50903. TabBarButton* const tb = getTabButton (i);
  50904. if (tb != 0)
  50905. {
  50906. const int newLength = totalLength + tb->getBestTabLength (depth);
  50907. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50908. {
  50909. totalLength += overlap;
  50910. break;
  50911. }
  50912. numVisibleButtons = i + 1;
  50913. totalLength = newLength - overlap;
  50914. }
  50915. }
  50916. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50917. }
  50918. else
  50919. {
  50920. deleteAndZero (extraTabsButton);
  50921. }
  50922. int pos = 0;
  50923. TabBarButton* frontTab = 0;
  50924. for (i = 0; i < tabs.size(); ++i)
  50925. {
  50926. TabBarButton* const tb = getTabButton (i);
  50927. if (tb != 0)
  50928. {
  50929. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50930. if (i < numVisibleButtons)
  50931. {
  50932. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50933. tb->setBounds (pos, 0, bestLength, getHeight());
  50934. else
  50935. tb->setBounds (0, pos, getWidth(), bestLength);
  50936. tb->toBack();
  50937. if (tb->tabIndex == currentTabIndex)
  50938. frontTab = tb;
  50939. tb->setVisible (true);
  50940. }
  50941. else
  50942. {
  50943. tb->setVisible (false);
  50944. }
  50945. pos += bestLength - overlap;
  50946. }
  50947. }
  50948. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50949. if (frontTab != 0)
  50950. {
  50951. frontTab->toFront (false);
  50952. behindFrontTab->toBehind (frontTab);
  50953. }
  50954. }
  50955. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50956. {
  50957. return tabColours [tabIndex];
  50958. }
  50959. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50960. {
  50961. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50962. && tabColours [tabIndex] != newColour)
  50963. {
  50964. tabColours.set (tabIndex, newColour);
  50965. repaint();
  50966. }
  50967. }
  50968. void TabbedButtonBar::buttonClicked (Button* button)
  50969. {
  50970. if (extraTabsButton == button)
  50971. {
  50972. PopupMenu m;
  50973. for (int i = 0; i < tabs.size(); ++i)
  50974. {
  50975. TabBarButton* const tb = getTabButton (i);
  50976. if (tb != 0 && ! tb->isVisible())
  50977. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50978. }
  50979. const int res = m.showAt (extraTabsButton);
  50980. if (res != 0)
  50981. setCurrentTabIndex (res - 1);
  50982. }
  50983. }
  50984. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50985. {
  50986. }
  50987. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50988. {
  50989. }
  50990. END_JUCE_NAMESPACE
  50991. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50992. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50993. BEGIN_JUCE_NAMESPACE
  50994. class TabCompButtonBar : public TabbedButtonBar
  50995. {
  50996. public:
  50997. TabCompButtonBar (TabbedComponent* const owner_,
  50998. const TabbedButtonBar::Orientation orientation)
  50999. : TabbedButtonBar (orientation),
  51000. owner (owner_)
  51001. {
  51002. }
  51003. ~TabCompButtonBar()
  51004. {
  51005. }
  51006. void currentTabChanged (const int newCurrentTabIndex,
  51007. const String& newTabName)
  51008. {
  51009. owner->changeCallback (newCurrentTabIndex, newTabName);
  51010. }
  51011. void popupMenuClickOnTab (const int tabIndex,
  51012. const String& tabName)
  51013. {
  51014. owner->popupMenuClickOnTab (tabIndex, tabName);
  51015. }
  51016. const Colour getTabBackgroundColour (const int tabIndex)
  51017. {
  51018. return owner->tabs->getTabBackgroundColour (tabIndex);
  51019. }
  51020. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  51021. {
  51022. return owner->createTabButton (tabName, tabIndex);
  51023. }
  51024. juce_UseDebuggingNewOperator
  51025. private:
  51026. TabbedComponent* const owner;
  51027. TabCompButtonBar (const TabCompButtonBar&);
  51028. TabCompButtonBar& operator= (const TabCompButtonBar&);
  51029. };
  51030. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  51031. : panelComponent (0),
  51032. tabDepth (30),
  51033. outlineThickness (1),
  51034. edgeIndent (0)
  51035. {
  51036. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  51037. }
  51038. TabbedComponent::~TabbedComponent()
  51039. {
  51040. clearTabs();
  51041. delete tabs;
  51042. }
  51043. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  51044. {
  51045. tabs->setOrientation (orientation);
  51046. resized();
  51047. }
  51048. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  51049. {
  51050. return tabs->getOrientation();
  51051. }
  51052. void TabbedComponent::setTabBarDepth (const int newDepth)
  51053. {
  51054. if (tabDepth != newDepth)
  51055. {
  51056. tabDepth = newDepth;
  51057. resized();
  51058. }
  51059. }
  51060. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  51061. {
  51062. return new TabBarButton (tabName, tabs, tabIndex);
  51063. }
  51064. void TabbedComponent::clearTabs()
  51065. {
  51066. if (panelComponent != 0)
  51067. {
  51068. panelComponent->setVisible (false);
  51069. removeChildComponent (panelComponent);
  51070. panelComponent = 0;
  51071. }
  51072. tabs->clearTabs();
  51073. for (int i = contentComponents.size(); --i >= 0;)
  51074. {
  51075. Component* const c = contentComponents.getUnchecked(i);
  51076. // be careful not to delete these components until they've been removed from the tab component
  51077. jassert (c == 0 || c->isValidComponent());
  51078. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51079. delete c;
  51080. }
  51081. contentComponents.clear();
  51082. }
  51083. void TabbedComponent::addTab (const String& tabName,
  51084. const Colour& tabBackgroundColour,
  51085. Component* const contentComponent,
  51086. const bool deleteComponentWhenNotNeeded,
  51087. const int insertIndex)
  51088. {
  51089. contentComponents.insert (insertIndex, contentComponent);
  51090. if (contentComponent != 0)
  51091. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  51092. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  51093. }
  51094. void TabbedComponent::setTabName (const int tabIndex,
  51095. const String& newName)
  51096. {
  51097. tabs->setTabName (tabIndex, newName);
  51098. }
  51099. void TabbedComponent::removeTab (const int tabIndex)
  51100. {
  51101. Component* const c = contentComponents [tabIndex];
  51102. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51103. {
  51104. if (c == panelComponent)
  51105. panelComponent = 0;
  51106. delete c;
  51107. }
  51108. contentComponents.remove (tabIndex);
  51109. tabs->removeTab (tabIndex);
  51110. }
  51111. int TabbedComponent::getNumTabs() const
  51112. {
  51113. return tabs->getNumTabs();
  51114. }
  51115. const StringArray TabbedComponent::getTabNames() const
  51116. {
  51117. return tabs->getTabNames();
  51118. }
  51119. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  51120. {
  51121. return contentComponents [tabIndex];
  51122. }
  51123. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  51124. {
  51125. return tabs->getTabBackgroundColour (tabIndex);
  51126. }
  51127. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51128. {
  51129. tabs->setTabBackgroundColour (tabIndex, newColour);
  51130. if (getCurrentTabIndex() == tabIndex)
  51131. repaint();
  51132. }
  51133. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  51134. {
  51135. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  51136. }
  51137. int TabbedComponent::getCurrentTabIndex() const
  51138. {
  51139. return tabs->getCurrentTabIndex();
  51140. }
  51141. const String& TabbedComponent::getCurrentTabName() const
  51142. {
  51143. return tabs->getCurrentTabName();
  51144. }
  51145. void TabbedComponent::setOutline (int thickness)
  51146. {
  51147. outlineThickness = thickness;
  51148. repaint();
  51149. }
  51150. void TabbedComponent::setIndent (const int indentThickness)
  51151. {
  51152. edgeIndent = indentThickness;
  51153. }
  51154. void TabbedComponent::paint (Graphics& g)
  51155. {
  51156. g.fillAll (findColour (backgroundColourId));
  51157. const TabbedButtonBar::Orientation o = getOrientation();
  51158. int x = 0;
  51159. int y = 0;
  51160. int r = getWidth();
  51161. int b = getHeight();
  51162. if (o == TabbedButtonBar::TabsAtTop)
  51163. y += tabDepth;
  51164. else if (o == TabbedButtonBar::TabsAtBottom)
  51165. b -= tabDepth;
  51166. else if (o == TabbedButtonBar::TabsAtLeft)
  51167. x += tabDepth;
  51168. else if (o == TabbedButtonBar::TabsAtRight)
  51169. r -= tabDepth;
  51170. g.reduceClipRegion (x, y, r - x, b - y);
  51171. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  51172. if (outlineThickness > 0)
  51173. {
  51174. if (o == TabbedButtonBar::TabsAtTop)
  51175. --y;
  51176. else if (o == TabbedButtonBar::TabsAtBottom)
  51177. ++b;
  51178. else if (o == TabbedButtonBar::TabsAtLeft)
  51179. --x;
  51180. else if (o == TabbedButtonBar::TabsAtRight)
  51181. ++r;
  51182. g.setColour (findColour (outlineColourId));
  51183. g.drawRect (x, y, r - x, b - y, outlineThickness);
  51184. }
  51185. }
  51186. void TabbedComponent::resized()
  51187. {
  51188. const TabbedButtonBar::Orientation o = getOrientation();
  51189. const int indent = edgeIndent + outlineThickness;
  51190. BorderSize indents (indent);
  51191. if (o == TabbedButtonBar::TabsAtTop)
  51192. {
  51193. tabs->setBounds (0, 0, getWidth(), tabDepth);
  51194. indents.setTop (tabDepth + edgeIndent);
  51195. }
  51196. else if (o == TabbedButtonBar::TabsAtBottom)
  51197. {
  51198. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  51199. indents.setBottom (tabDepth + edgeIndent);
  51200. }
  51201. else if (o == TabbedButtonBar::TabsAtLeft)
  51202. {
  51203. tabs->setBounds (0, 0, tabDepth, getHeight());
  51204. indents.setLeft (tabDepth + edgeIndent);
  51205. }
  51206. else if (o == TabbedButtonBar::TabsAtRight)
  51207. {
  51208. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  51209. indents.setRight (tabDepth + edgeIndent);
  51210. }
  51211. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  51212. for (int i = contentComponents.size(); --i >= 0;)
  51213. if (contentComponents.getUnchecked (i) != 0)
  51214. contentComponents.getUnchecked (i)->setBounds (bounds);
  51215. }
  51216. void TabbedComponent::lookAndFeelChanged()
  51217. {
  51218. for (int i = contentComponents.size(); --i >= 0;)
  51219. if (contentComponents.getUnchecked (i) != 0)
  51220. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  51221. }
  51222. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  51223. const String& newTabName)
  51224. {
  51225. if (panelComponent != 0)
  51226. {
  51227. panelComponent->setVisible (false);
  51228. removeChildComponent (panelComponent);
  51229. panelComponent = 0;
  51230. }
  51231. if (getCurrentTabIndex() >= 0)
  51232. {
  51233. panelComponent = contentComponents [getCurrentTabIndex()];
  51234. if (panelComponent != 0)
  51235. {
  51236. // do these ops as two stages instead of addAndMakeVisible() so that the
  51237. // component has always got a parent when it gets the visibilityChanged() callback
  51238. addChildComponent (panelComponent);
  51239. panelComponent->setVisible (true);
  51240. panelComponent->toFront (true);
  51241. }
  51242. repaint();
  51243. }
  51244. resized();
  51245. currentTabChanged (newCurrentTabIndex, newTabName);
  51246. }
  51247. void TabbedComponent::currentTabChanged (const int, const String&)
  51248. {
  51249. }
  51250. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  51251. {
  51252. }
  51253. END_JUCE_NAMESPACE
  51254. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  51255. /*** Start of inlined file: juce_Viewport.cpp ***/
  51256. BEGIN_JUCE_NAMESPACE
  51257. Viewport::Viewport (const String& componentName)
  51258. : Component (componentName),
  51259. contentComp (0),
  51260. lastVX (0),
  51261. lastVY (0),
  51262. lastVW (0),
  51263. lastVH (0),
  51264. scrollBarThickness (0),
  51265. singleStepX (16),
  51266. singleStepY (16),
  51267. showHScrollbar (true),
  51268. showVScrollbar (true)
  51269. {
  51270. // content holder is used to clip the contents so they don't overlap the scrollbars
  51271. addAndMakeVisible (contentHolder = new Component());
  51272. contentHolder->setInterceptsMouseClicks (false, true);
  51273. verticalScrollBar = new ScrollBar (true);
  51274. horizontalScrollBar = new ScrollBar (false);
  51275. addChildComponent (verticalScrollBar);
  51276. addChildComponent (horizontalScrollBar);
  51277. verticalScrollBar->addListener (this);
  51278. horizontalScrollBar->addListener (this);
  51279. setInterceptsMouseClicks (false, true);
  51280. setWantsKeyboardFocus (true);
  51281. }
  51282. Viewport::~Viewport()
  51283. {
  51284. contentHolder->deleteAllChildren();
  51285. deleteAllChildren();
  51286. }
  51287. void Viewport::visibleAreaChanged (int, int, int, int)
  51288. {
  51289. }
  51290. void Viewport::setViewedComponent (Component* const newViewedComponent)
  51291. {
  51292. if (contentComp != newViewedComponent)
  51293. {
  51294. if (contentComp->isValidComponent())
  51295. {
  51296. Component* const oldComp = contentComp;
  51297. contentComp = 0;
  51298. delete oldComp;
  51299. }
  51300. contentComp = newViewedComponent;
  51301. if (contentComp != 0)
  51302. {
  51303. contentComp->setTopLeftPosition (0, 0);
  51304. contentHolder->addAndMakeVisible (contentComp);
  51305. contentComp->addComponentListener (this);
  51306. }
  51307. updateVisibleRegion();
  51308. }
  51309. }
  51310. int Viewport::getMaximumVisibleWidth() const throw()
  51311. {
  51312. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51313. }
  51314. int Viewport::getMaximumVisibleHeight() const throw()
  51315. {
  51316. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51317. }
  51318. void Viewport::setViewPosition (const int xPixelsOffset,
  51319. const int yPixelsOffset)
  51320. {
  51321. if (contentComp != 0)
  51322. contentComp->setTopLeftPosition (-xPixelsOffset,
  51323. -yPixelsOffset);
  51324. }
  51325. void Viewport::setViewPositionProportionately (const double x,
  51326. const double y)
  51327. {
  51328. if (contentComp != 0)
  51329. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  51330. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  51331. }
  51332. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  51333. {
  51334. if (contentComp != 0)
  51335. {
  51336. int dx = 0, dy = 0;
  51337. if (mouseX < activeBorderThickness)
  51338. dx = activeBorderThickness - mouseX;
  51339. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  51340. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  51341. if (dx < 0)
  51342. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  51343. else
  51344. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  51345. if (mouseY < activeBorderThickness)
  51346. dy = activeBorderThickness - mouseY;
  51347. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  51348. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  51349. if (dy < 0)
  51350. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  51351. else
  51352. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  51353. if (dx != 0 || dy != 0)
  51354. {
  51355. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  51356. contentComp->getY() + dy);
  51357. return true;
  51358. }
  51359. }
  51360. return false;
  51361. }
  51362. void Viewport::componentMovedOrResized (Component&, bool, bool)
  51363. {
  51364. updateVisibleRegion();
  51365. }
  51366. void Viewport::resized()
  51367. {
  51368. updateVisibleRegion();
  51369. }
  51370. void Viewport::updateVisibleRegion()
  51371. {
  51372. if (contentComp != 0)
  51373. {
  51374. const int newVX = -contentComp->getX();
  51375. const int newVY = -contentComp->getY();
  51376. if (newVX == 0 && newVY == 0
  51377. && contentComp->getWidth() <= getWidth()
  51378. && contentComp->getHeight() <= getHeight())
  51379. {
  51380. horizontalScrollBar->setVisible (false);
  51381. verticalScrollBar->setVisible (false);
  51382. }
  51383. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  51384. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51385. horizontalScrollBar->setSingleStepSize (singleStepX);
  51386. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  51387. horizontalScrollBar->setVisible (false);
  51388. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  51389. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51390. verticalScrollBar->setSingleStepSize (singleStepY);
  51391. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  51392. verticalScrollBar->setVisible (false);
  51393. if (verticalScrollBar->isVisible())
  51394. {
  51395. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51396. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51397. verticalScrollBar
  51398. ->setBounds (getMaximumVisibleWidth(), 0,
  51399. getScrollBarThickness(), getMaximumVisibleHeight());
  51400. }
  51401. if (horizontalScrollBar->isVisible())
  51402. {
  51403. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51404. horizontalScrollBar
  51405. ->setBounds (0, getMaximumVisibleHeight(),
  51406. getMaximumVisibleWidth(), getScrollBarThickness());
  51407. }
  51408. contentHolder->setSize (getMaximumVisibleWidth(),
  51409. getMaximumVisibleHeight());
  51410. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  51411. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  51412. if (newVX != lastVX
  51413. || newVY != lastVY
  51414. || newVW != lastVW
  51415. || newVH != lastVH)
  51416. {
  51417. lastVX = newVX;
  51418. lastVY = newVY;
  51419. lastVW = newVW;
  51420. lastVH = newVH;
  51421. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51422. }
  51423. horizontalScrollBar->handleUpdateNowIfNeeded();
  51424. verticalScrollBar->handleUpdateNowIfNeeded();
  51425. }
  51426. else
  51427. {
  51428. horizontalScrollBar->setVisible (false);
  51429. verticalScrollBar->setVisible (false);
  51430. }
  51431. }
  51432. void Viewport::setSingleStepSizes (const int stepX,
  51433. const int stepY)
  51434. {
  51435. singleStepX = stepX;
  51436. singleStepY = stepY;
  51437. updateVisibleRegion();
  51438. }
  51439. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51440. const bool showHorizontalScrollbarIfNeeded)
  51441. {
  51442. showVScrollbar = showVerticalScrollbarIfNeeded;
  51443. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51444. updateVisibleRegion();
  51445. }
  51446. void Viewport::setScrollBarThickness (const int thickness)
  51447. {
  51448. scrollBarThickness = thickness;
  51449. updateVisibleRegion();
  51450. }
  51451. int Viewport::getScrollBarThickness() const throw()
  51452. {
  51453. return (scrollBarThickness > 0) ? scrollBarThickness
  51454. : getLookAndFeel().getDefaultScrollbarWidth();
  51455. }
  51456. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51457. {
  51458. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51459. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51460. }
  51461. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  51462. {
  51463. if (scrollBarThatHasMoved == horizontalScrollBar)
  51464. {
  51465. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51466. }
  51467. else if (scrollBarThatHasMoved == verticalScrollBar)
  51468. {
  51469. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51470. }
  51471. }
  51472. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51473. {
  51474. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51475. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51476. }
  51477. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51478. {
  51479. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51480. {
  51481. const bool hasVertBar = verticalScrollBar->isVisible();
  51482. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51483. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51484. {
  51485. if (wheelIncrementX == 0 && ! hasVertBar)
  51486. wheelIncrementX = wheelIncrementY;
  51487. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51488. wheelIncrementX, wheelIncrementY);
  51489. return true;
  51490. }
  51491. else if (hasVertBar && wheelIncrementY != 0)
  51492. {
  51493. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51494. wheelIncrementX, wheelIncrementY);
  51495. return true;
  51496. }
  51497. }
  51498. return false;
  51499. }
  51500. bool Viewport::keyPressed (const KeyPress& key)
  51501. {
  51502. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51503. || key.isKeyCode (KeyPress::downKey)
  51504. || key.isKeyCode (KeyPress::pageUpKey)
  51505. || key.isKeyCode (KeyPress::pageDownKey)
  51506. || key.isKeyCode (KeyPress::homeKey)
  51507. || key.isKeyCode (KeyPress::endKey);
  51508. if (verticalScrollBar->isVisible() && isUpDownKey)
  51509. return verticalScrollBar->keyPressed (key);
  51510. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51511. || key.isKeyCode (KeyPress::rightKey);
  51512. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51513. return horizontalScrollBar->keyPressed (key);
  51514. return false;
  51515. }
  51516. END_JUCE_NAMESPACE
  51517. /*** End of inlined file: juce_Viewport.cpp ***/
  51518. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51519. BEGIN_JUCE_NAMESPACE
  51520. static const Colour createBaseColour (const Colour& buttonColour,
  51521. const bool hasKeyboardFocus,
  51522. const bool isMouseOverButton,
  51523. const bool isButtonDown) throw()
  51524. {
  51525. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51526. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51527. if (isButtonDown)
  51528. return baseColour.contrasting (0.2f);
  51529. else if (isMouseOverButton)
  51530. return baseColour.contrasting (0.1f);
  51531. return baseColour;
  51532. }
  51533. static String defaultSansName, defaultSerifName, defaultFixedName;
  51534. void clearUpDefaultFontNames() throw()
  51535. {
  51536. defaultSansName = String::empty;
  51537. defaultSerifName = String::empty;
  51538. defaultFixedName = String::empty;
  51539. }
  51540. LookAndFeel::LookAndFeel()
  51541. {
  51542. /* if this fails it means you're trying to create a LookAndFeel object before
  51543. the static Colours have been initialised. That ain't gonna work. It probably
  51544. means that you're using a static LookAndFeel object and that your compiler has
  51545. decided to intialise it before the Colours class.
  51546. */
  51547. jassert (Colours::white == Colour (0xffffffff));
  51548. // set up the standard set of colours..
  51549. const int textButtonColour = 0xffbbbbff;
  51550. const int textHighlightColour = 0x401111ee;
  51551. const int standardOutlineColour = 0xb2808080;
  51552. static const int standardColours[] =
  51553. {
  51554. TextButton::buttonColourId, textButtonColour,
  51555. TextButton::buttonOnColourId, 0xff4444ff,
  51556. TextButton::textColourOnId, 0xff000000,
  51557. TextButton::textColourOffId, 0xff000000,
  51558. ComboBox::buttonColourId, 0xffbbbbff,
  51559. ComboBox::outlineColourId, standardOutlineColour,
  51560. ToggleButton::textColourId, 0xff000000,
  51561. TextEditor::backgroundColourId, 0xffffffff,
  51562. TextEditor::textColourId, 0xff000000,
  51563. TextEditor::highlightColourId, textHighlightColour,
  51564. TextEditor::highlightedTextColourId, 0xff000000,
  51565. TextEditor::caretColourId, 0xff000000,
  51566. TextEditor::outlineColourId, 0x00000000,
  51567. TextEditor::focusedOutlineColourId, textButtonColour,
  51568. TextEditor::shadowColourId, 0x38000000,
  51569. Label::backgroundColourId, 0x00000000,
  51570. Label::textColourId, 0xff000000,
  51571. Label::outlineColourId, 0x00000000,
  51572. ScrollBar::backgroundColourId, 0x00000000,
  51573. ScrollBar::thumbColourId, 0xffffffff,
  51574. ScrollBar::trackColourId, 0xffffffff,
  51575. TreeView::linesColourId, 0x4c000000,
  51576. TreeView::backgroundColourId, 0x00000000,
  51577. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51578. PopupMenu::backgroundColourId, 0xffffffff,
  51579. PopupMenu::textColourId, 0xff000000,
  51580. PopupMenu::headerTextColourId, 0xff000000,
  51581. PopupMenu::highlightedTextColourId, 0xffffffff,
  51582. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51583. ComboBox::textColourId, 0xff000000,
  51584. ComboBox::backgroundColourId, 0xffffffff,
  51585. ComboBox::arrowColourId, 0x99000000,
  51586. ListBox::backgroundColourId, 0xffffffff,
  51587. ListBox::outlineColourId, standardOutlineColour,
  51588. ListBox::textColourId, 0xff000000,
  51589. Slider::backgroundColourId, 0x00000000,
  51590. Slider::thumbColourId, textButtonColour,
  51591. Slider::trackColourId, 0x7fffffff,
  51592. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51593. Slider::rotarySliderOutlineColourId, 0x66000000,
  51594. Slider::textBoxTextColourId, 0xff000000,
  51595. Slider::textBoxBackgroundColourId, 0xffffffff,
  51596. Slider::textBoxHighlightColourId, textHighlightColour,
  51597. Slider::textBoxOutlineColourId, standardOutlineColour,
  51598. ResizableWindow::backgroundColourId, 0xff777777,
  51599. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51600. AlertWindow::backgroundColourId, 0xffededed,
  51601. AlertWindow::textColourId, 0xff000000,
  51602. AlertWindow::outlineColourId, 0xff666666,
  51603. ProgressBar::backgroundColourId, 0xffeeeeee,
  51604. ProgressBar::foregroundColourId, 0xffaaaaee,
  51605. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51606. TooltipWindow::textColourId, 0xff000000,
  51607. TooltipWindow::outlineColourId, 0x4c000000,
  51608. TabbedComponent::backgroundColourId, 0x00000000,
  51609. TabbedComponent::outlineColourId, 0xff777777,
  51610. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51611. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51612. Toolbar::backgroundColourId, 0xfff6f8f9,
  51613. Toolbar::separatorColourId, 0x4c000000,
  51614. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51615. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51616. Toolbar::labelTextColourId, 0xff000000,
  51617. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51618. HyperlinkButton::textColourId, 0xcc1111ee,
  51619. GroupComponent::outlineColourId, 0x66000000,
  51620. GroupComponent::textColourId, 0xff000000,
  51621. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51622. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51623. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51624. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51625. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51626. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51627. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51628. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51629. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51630. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51631. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51632. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51633. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51634. CodeEditorComponent::caretColourId, 0xff000000,
  51635. CodeEditorComponent::highlightColourId, textHighlightColour,
  51636. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51637. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51638. ColourSelector::labelTextColourId, 0xff000000,
  51639. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51640. KeyMappingEditorComponent::textColourId, 0xff000000,
  51641. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51642. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51643. };
  51644. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51645. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51646. if (defaultSansName.isEmpty())
  51647. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51648. defaultSans = defaultSansName;
  51649. defaultSerif = defaultSerifName;
  51650. defaultFixed = defaultFixedName;
  51651. }
  51652. LookAndFeel::~LookAndFeel()
  51653. {
  51654. }
  51655. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51656. {
  51657. const int index = colourIds.indexOf (colourId);
  51658. if (index >= 0)
  51659. return colours [index];
  51660. jassertfalse
  51661. return Colours::black;
  51662. }
  51663. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51664. {
  51665. const int index = colourIds.indexOf (colourId);
  51666. if (index >= 0)
  51667. colours.set (index, colour);
  51668. colourIds.add (colourId);
  51669. colours.add (colour);
  51670. }
  51671. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51672. {
  51673. return colourIds.contains (colourId);
  51674. }
  51675. static LookAndFeel* defaultLF = 0;
  51676. static LookAndFeel* currentDefaultLF = 0;
  51677. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51678. {
  51679. // if this happens, your app hasn't initialised itself properly.. if you're
  51680. // trying to hack your own main() function, have a look at
  51681. // JUCEApplication::initialiseForGUI()
  51682. jassert (currentDefaultLF != 0);
  51683. return *currentDefaultLF;
  51684. }
  51685. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51686. {
  51687. if (newDefaultLookAndFeel == 0)
  51688. {
  51689. if (defaultLF == 0)
  51690. defaultLF = new LookAndFeel();
  51691. newDefaultLookAndFeel = defaultLF;
  51692. }
  51693. currentDefaultLF = newDefaultLookAndFeel;
  51694. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51695. {
  51696. Component* const c = Desktop::getInstance().getComponent (i);
  51697. if (c != 0)
  51698. c->sendLookAndFeelChange();
  51699. }
  51700. }
  51701. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51702. {
  51703. if (currentDefaultLF == defaultLF)
  51704. currentDefaultLF = 0;
  51705. deleteAndZero (defaultLF);
  51706. }
  51707. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51708. {
  51709. String faceName (font.getTypefaceName());
  51710. if (faceName == Font::getDefaultSansSerifFontName())
  51711. faceName = defaultSans;
  51712. else if (faceName == Font::getDefaultSerifFontName())
  51713. faceName = defaultSerif;
  51714. else if (faceName == Font::getDefaultMonospacedFontName())
  51715. faceName = defaultFixed;
  51716. Font f (font);
  51717. f.setTypefaceName (faceName);
  51718. return Typeface::createSystemTypefaceFor (f);
  51719. }
  51720. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51721. {
  51722. defaultSans = newName;
  51723. }
  51724. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51725. {
  51726. return component.getMouseCursor();
  51727. }
  51728. void LookAndFeel::drawButtonBackground (Graphics& g,
  51729. Button& button,
  51730. const Colour& backgroundColour,
  51731. bool isMouseOverButton,
  51732. bool isButtonDown)
  51733. {
  51734. const int width = button.getWidth();
  51735. const int height = button.getHeight();
  51736. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51737. const float halfThickness = outlineThickness * 0.5f;
  51738. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51739. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51740. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51741. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51742. const Colour baseColour (createBaseColour (backgroundColour,
  51743. button.hasKeyboardFocus (true),
  51744. isMouseOverButton, isButtonDown)
  51745. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51746. drawGlassLozenge (g,
  51747. indentL,
  51748. indentT,
  51749. width - indentL - indentR,
  51750. height - indentT - indentB,
  51751. baseColour, outlineThickness, -1.0f,
  51752. button.isConnectedOnLeft(),
  51753. button.isConnectedOnRight(),
  51754. button.isConnectedOnTop(),
  51755. button.isConnectedOnBottom());
  51756. }
  51757. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51758. {
  51759. return button.getFont();
  51760. }
  51761. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51762. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51763. {
  51764. Font font (getFontForTextButton (button));
  51765. g.setFont (font);
  51766. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51767. : TextButton::textColourOffId)
  51768. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51769. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51770. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51771. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51772. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51773. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51774. g.drawFittedText (button.getButtonText(),
  51775. leftIndent,
  51776. yIndent,
  51777. button.getWidth() - leftIndent - rightIndent,
  51778. button.getHeight() - yIndent * 2,
  51779. Justification::centred, 2);
  51780. }
  51781. void LookAndFeel::drawTickBox (Graphics& g,
  51782. Component& component,
  51783. float x, float y, float w, float h,
  51784. const bool ticked,
  51785. const bool isEnabled,
  51786. const bool isMouseOverButton,
  51787. const bool isButtonDown)
  51788. {
  51789. const float boxSize = w * 0.7f;
  51790. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51791. createBaseColour (component.findColour (TextButton::buttonColourId)
  51792. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51793. true,
  51794. isMouseOverButton,
  51795. isButtonDown),
  51796. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51797. if (ticked)
  51798. {
  51799. Path tick;
  51800. tick.startNewSubPath (1.5f, 3.0f);
  51801. tick.lineTo (3.0f, 6.0f);
  51802. tick.lineTo (6.0f, 0.0f);
  51803. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51804. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51805. .translated (x, y));
  51806. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51807. }
  51808. }
  51809. void LookAndFeel::drawToggleButton (Graphics& g,
  51810. ToggleButton& button,
  51811. bool isMouseOverButton,
  51812. bool isButtonDown)
  51813. {
  51814. if (button.hasKeyboardFocus (true))
  51815. {
  51816. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51817. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51818. }
  51819. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51820. const float tickWidth = fontSize * 1.1f;
  51821. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51822. tickWidth, tickWidth,
  51823. button.getToggleState(),
  51824. button.isEnabled(),
  51825. isMouseOverButton,
  51826. isButtonDown);
  51827. g.setColour (button.findColour (ToggleButton::textColourId));
  51828. g.setFont (fontSize);
  51829. if (! button.isEnabled())
  51830. g.setOpacity (0.5f);
  51831. const int textX = (int) tickWidth + 5;
  51832. g.drawFittedText (button.getButtonText(),
  51833. textX, 0,
  51834. button.getWidth() - textX - 2, button.getHeight(),
  51835. Justification::centredLeft, 10);
  51836. }
  51837. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51838. {
  51839. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51840. const int tickWidth = jmin (24, button.getHeight());
  51841. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51842. button.getHeight());
  51843. }
  51844. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51845. const String& message,
  51846. const String& button1,
  51847. const String& button2,
  51848. const String& button3,
  51849. AlertWindow::AlertIconType iconType,
  51850. int numButtons,
  51851. Component* associatedComponent)
  51852. {
  51853. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51854. if (numButtons == 1)
  51855. {
  51856. aw->addButton (button1, 0,
  51857. KeyPress (KeyPress::escapeKey, 0, 0),
  51858. KeyPress (KeyPress::returnKey, 0, 0));
  51859. }
  51860. else
  51861. {
  51862. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51863. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51864. if (button1ShortCut == button2ShortCut)
  51865. button2ShortCut = KeyPress();
  51866. if (numButtons == 2)
  51867. {
  51868. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51869. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51870. }
  51871. else if (numButtons == 3)
  51872. {
  51873. aw->addButton (button1, 1, button1ShortCut);
  51874. aw->addButton (button2, 2, button2ShortCut);
  51875. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51876. }
  51877. }
  51878. return aw;
  51879. }
  51880. void LookAndFeel::drawAlertBox (Graphics& g,
  51881. AlertWindow& alert,
  51882. const Rectangle<int>& textArea,
  51883. TextLayout& textLayout)
  51884. {
  51885. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51886. int iconSpaceUsed = 0;
  51887. Justification alignment (Justification::horizontallyCentred);
  51888. const int iconWidth = 80;
  51889. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51890. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51891. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51892. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51893. iconSize, iconSize);
  51894. if (alert.getAlertType() != AlertWindow::NoIcon)
  51895. {
  51896. Path icon;
  51897. uint32 colour;
  51898. char character;
  51899. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51900. {
  51901. colour = 0x55ff5555;
  51902. character = '!';
  51903. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51904. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51905. (float) iconRect.getX(), (float) iconRect.getBottom());
  51906. icon = icon.createPathWithRoundedCorners (5.0f);
  51907. }
  51908. else
  51909. {
  51910. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51911. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51912. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51913. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51914. }
  51915. GlyphArrangement ga;
  51916. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51917. String::charToString (character),
  51918. (float) iconRect.getX(), (float) iconRect.getY(),
  51919. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51920. Justification::centred, false);
  51921. ga.createPath (icon);
  51922. icon.setUsingNonZeroWinding (false);
  51923. g.setColour (Colour (colour));
  51924. g.fillPath (icon);
  51925. iconSpaceUsed = iconWidth;
  51926. alignment = Justification::left;
  51927. }
  51928. g.setColour (alert.findColour (AlertWindow::textColourId));
  51929. textLayout.drawWithin (g,
  51930. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51931. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51932. alignment.getFlags() | Justification::top);
  51933. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51934. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51935. }
  51936. int LookAndFeel::getAlertBoxWindowFlags()
  51937. {
  51938. return ComponentPeer::windowAppearsOnTaskbar
  51939. | ComponentPeer::windowHasDropShadow;
  51940. }
  51941. int LookAndFeel::getAlertWindowButtonHeight()
  51942. {
  51943. return 28;
  51944. }
  51945. const Font LookAndFeel::getAlertWindowFont()
  51946. {
  51947. return Font (12.0f);
  51948. }
  51949. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51950. int width, int height,
  51951. double progress, const String& textToShow)
  51952. {
  51953. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51954. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51955. g.fillAll (background);
  51956. if (progress >= 0.0f && progress < 1.0f)
  51957. {
  51958. drawGlassLozenge (g, 1.0f, 1.0f,
  51959. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51960. (float) (height - 2),
  51961. foreground,
  51962. 0.5f, 0.0f,
  51963. true, true, true, true);
  51964. }
  51965. else
  51966. {
  51967. // spinning bar..
  51968. g.setColour (foreground);
  51969. const int stripeWidth = height * 2;
  51970. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51971. Path p;
  51972. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51973. p.addQuadrilateral (x, 0.0f,
  51974. x + stripeWidth * 0.5f, 0.0f,
  51975. x, (float) height,
  51976. x - stripeWidth * 0.5f, (float) height);
  51977. Image im (Image::ARGB, width, height, true);
  51978. {
  51979. Graphics g2 (im);
  51980. drawGlassLozenge (g2, 1.0f, 1.0f,
  51981. (float) (width - 2),
  51982. (float) (height - 2),
  51983. foreground,
  51984. 0.5f, 0.0f,
  51985. true, true, true, true);
  51986. }
  51987. g.setTiledImageFill (im, 0, 0, 0.85f);
  51988. g.fillPath (p);
  51989. }
  51990. if (textToShow.isNotEmpty())
  51991. {
  51992. g.setColour (Colour::contrasting (background, foreground));
  51993. g.setFont (height * 0.6f);
  51994. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51995. }
  51996. }
  51997. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51998. {
  51999. const float radius = jmin (w, h) * 0.4f;
  52000. const float thickness = radius * 0.15f;
  52001. Path p;
  52002. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  52003. radius * 0.6f, thickness,
  52004. thickness * 0.5f);
  52005. const float cx = x + w * 0.5f;
  52006. const float cy = y + h * 0.5f;
  52007. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  52008. for (int i = 0; i < 12; ++i)
  52009. {
  52010. const int n = (i + 12 - animationIndex) % 12;
  52011. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  52012. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  52013. .translated (cx, cy));
  52014. }
  52015. }
  52016. void LookAndFeel::drawScrollbarButton (Graphics& g,
  52017. ScrollBar& scrollbar,
  52018. int width, int height,
  52019. int buttonDirection,
  52020. bool /*isScrollbarVertical*/,
  52021. bool /*isMouseOverButton*/,
  52022. bool isButtonDown)
  52023. {
  52024. Path p;
  52025. if (buttonDirection == 0)
  52026. p.addTriangle (width * 0.5f, height * 0.2f,
  52027. width * 0.1f, height * 0.7f,
  52028. width * 0.9f, height * 0.7f);
  52029. else if (buttonDirection == 1)
  52030. p.addTriangle (width * 0.8f, height * 0.5f,
  52031. width * 0.3f, height * 0.1f,
  52032. width * 0.3f, height * 0.9f);
  52033. else if (buttonDirection == 2)
  52034. p.addTriangle (width * 0.5f, height * 0.8f,
  52035. width * 0.1f, height * 0.3f,
  52036. width * 0.9f, height * 0.3f);
  52037. else if (buttonDirection == 3)
  52038. p.addTriangle (width * 0.2f, height * 0.5f,
  52039. width * 0.7f, height * 0.1f,
  52040. width * 0.7f, height * 0.9f);
  52041. if (isButtonDown)
  52042. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  52043. else
  52044. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52045. g.fillPath (p);
  52046. g.setColour (Colour (0x80000000));
  52047. g.strokePath (p, PathStrokeType (0.5f));
  52048. }
  52049. void LookAndFeel::drawScrollbar (Graphics& g,
  52050. ScrollBar& scrollbar,
  52051. int x, int y,
  52052. int width, int height,
  52053. bool isScrollbarVertical,
  52054. int thumbStartPosition,
  52055. int thumbSize,
  52056. bool /*isMouseOver*/,
  52057. bool /*isMouseDown*/)
  52058. {
  52059. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  52060. Path slotPath, thumbPath;
  52061. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  52062. const float slotIndentx2 = slotIndent * 2.0f;
  52063. const float thumbIndent = slotIndent + 1.0f;
  52064. const float thumbIndentx2 = thumbIndent * 2.0f;
  52065. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  52066. if (isScrollbarVertical)
  52067. {
  52068. slotPath.addRoundedRectangle (x + slotIndent,
  52069. y + slotIndent,
  52070. width - slotIndentx2,
  52071. height - slotIndentx2,
  52072. (width - slotIndentx2) * 0.5f);
  52073. if (thumbSize > 0)
  52074. thumbPath.addRoundedRectangle (x + thumbIndent,
  52075. thumbStartPosition + thumbIndent,
  52076. width - thumbIndentx2,
  52077. thumbSize - thumbIndentx2,
  52078. (width - thumbIndentx2) * 0.5f);
  52079. gx1 = (float) x;
  52080. gx2 = x + width * 0.7f;
  52081. }
  52082. else
  52083. {
  52084. slotPath.addRoundedRectangle (x + slotIndent,
  52085. y + slotIndent,
  52086. width - slotIndentx2,
  52087. height - slotIndentx2,
  52088. (height - slotIndentx2) * 0.5f);
  52089. if (thumbSize > 0)
  52090. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  52091. y + thumbIndent,
  52092. thumbSize - thumbIndentx2,
  52093. height - thumbIndentx2,
  52094. (height - thumbIndentx2) * 0.5f);
  52095. gy1 = (float) y;
  52096. gy2 = y + height * 0.7f;
  52097. }
  52098. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52099. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  52100. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  52101. g.fillPath (slotPath);
  52102. if (isScrollbarVertical)
  52103. {
  52104. gx1 = x + width * 0.6f;
  52105. gx2 = (float) x + width;
  52106. }
  52107. else
  52108. {
  52109. gy1 = y + height * 0.6f;
  52110. gy2 = (float) y + height;
  52111. }
  52112. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  52113. Colour (0x19000000), gx2, gy2, false));
  52114. g.fillPath (slotPath);
  52115. g.setColour (thumbColour);
  52116. g.fillPath (thumbPath);
  52117. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  52118. Colours::transparentBlack, gx2, gy2, false));
  52119. g.saveState();
  52120. if (isScrollbarVertical)
  52121. g.reduceClipRegion (x + width / 2, y, width, height);
  52122. else
  52123. g.reduceClipRegion (x, y + height / 2, width, height);
  52124. g.fillPath (thumbPath);
  52125. g.restoreState();
  52126. g.setColour (Colour (0x4c000000));
  52127. g.strokePath (thumbPath, PathStrokeType (0.4f));
  52128. }
  52129. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  52130. {
  52131. return 0;
  52132. }
  52133. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  52134. {
  52135. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  52136. }
  52137. int LookAndFeel::getDefaultScrollbarWidth()
  52138. {
  52139. return 18;
  52140. }
  52141. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  52142. {
  52143. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  52144. : scrollbar.getHeight());
  52145. }
  52146. const Path LookAndFeel::getTickShape (const float height)
  52147. {
  52148. static const unsigned char tickShapeData[] =
  52149. {
  52150. 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,
  52151. 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,
  52152. 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,
  52153. 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,
  52154. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  52155. };
  52156. Path p;
  52157. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  52158. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52159. return p;
  52160. }
  52161. const Path LookAndFeel::getCrossShape (const float height)
  52162. {
  52163. static const unsigned char crossShapeData[] =
  52164. {
  52165. 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,
  52166. 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,
  52167. 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,
  52168. 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,
  52169. 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,
  52170. 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,
  52171. 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
  52172. };
  52173. Path p;
  52174. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  52175. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52176. return p;
  52177. }
  52178. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  52179. {
  52180. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  52181. x += (w - boxSize) >> 1;
  52182. y += (h - boxSize) >> 1;
  52183. w = boxSize;
  52184. h = boxSize;
  52185. g.setColour (Colour (0xe5ffffff));
  52186. g.fillRect (x, y, w, h);
  52187. g.setColour (Colour (0x80000000));
  52188. g.drawRect (x, y, w, h);
  52189. const float size = boxSize / 2 + 1.0f;
  52190. const float centre = (float) (boxSize / 2);
  52191. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  52192. if (isPlus)
  52193. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  52194. }
  52195. void LookAndFeel::drawBubble (Graphics& g,
  52196. float tipX, float tipY,
  52197. float boxX, float boxY,
  52198. float boxW, float boxH)
  52199. {
  52200. int side = 0;
  52201. if (tipX < boxX)
  52202. side = 1;
  52203. else if (tipX > boxX + boxW)
  52204. side = 3;
  52205. else if (tipY > boxY + boxH)
  52206. side = 2;
  52207. const float indent = 2.0f;
  52208. Path p;
  52209. p.addBubble (boxX + indent,
  52210. boxY + indent,
  52211. boxW - indent * 2.0f,
  52212. boxH - indent * 2.0f,
  52213. 5.0f,
  52214. tipX, tipY,
  52215. side,
  52216. 0.5f,
  52217. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  52218. //xxx need to take comp as param for colour
  52219. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  52220. g.fillPath (p);
  52221. //xxx as above
  52222. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  52223. g.strokePath (p, PathStrokeType (1.33f));
  52224. }
  52225. const Font LookAndFeel::getPopupMenuFont()
  52226. {
  52227. return Font (17.0f);
  52228. }
  52229. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  52230. const bool isSeparator,
  52231. int standardMenuItemHeight,
  52232. int& idealWidth,
  52233. int& idealHeight)
  52234. {
  52235. if (isSeparator)
  52236. {
  52237. idealWidth = 50;
  52238. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  52239. }
  52240. else
  52241. {
  52242. Font font (getPopupMenuFont());
  52243. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  52244. font.setHeight (standardMenuItemHeight / 1.3f);
  52245. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  52246. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  52247. }
  52248. }
  52249. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  52250. {
  52251. const Colour background (findColour (PopupMenu::backgroundColourId));
  52252. g.fillAll (background);
  52253. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  52254. for (int i = 0; i < height; i += 3)
  52255. g.fillRect (0, i, width, 1);
  52256. #if ! JUCE_MAC
  52257. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  52258. g.drawRect (0, 0, width, height);
  52259. #endif
  52260. }
  52261. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  52262. int width, int height,
  52263. bool isScrollUpArrow)
  52264. {
  52265. const Colour background (findColour (PopupMenu::backgroundColourId));
  52266. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  52267. background.withAlpha (0.0f),
  52268. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  52269. false));
  52270. g.fillRect (1, 1, width - 2, height - 2);
  52271. const float hw = width * 0.5f;
  52272. const float arrowW = height * 0.3f;
  52273. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  52274. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  52275. Path p;
  52276. p.addTriangle (hw - arrowW, y1,
  52277. hw + arrowW, y1,
  52278. hw, y2);
  52279. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  52280. g.fillPath (p);
  52281. }
  52282. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  52283. int width, int height,
  52284. const bool isSeparator,
  52285. const bool isActive,
  52286. const bool isHighlighted,
  52287. const bool isTicked,
  52288. const bool hasSubMenu,
  52289. const String& text,
  52290. const String& shortcutKeyText,
  52291. Image* image,
  52292. const Colour* const textColourToUse)
  52293. {
  52294. const float halfH = height * 0.5f;
  52295. if (isSeparator)
  52296. {
  52297. const float separatorIndent = 5.5f;
  52298. g.setColour (Colour (0x33000000));
  52299. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  52300. g.setColour (Colour (0x66ffffff));
  52301. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  52302. }
  52303. else
  52304. {
  52305. Colour textColour (findColour (PopupMenu::textColourId));
  52306. if (textColourToUse != 0)
  52307. textColour = *textColourToUse;
  52308. if (isHighlighted)
  52309. {
  52310. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  52311. g.fillRect (1, 1, width - 2, height - 2);
  52312. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  52313. }
  52314. else
  52315. {
  52316. g.setColour (textColour);
  52317. }
  52318. if (! isActive)
  52319. g.setOpacity (0.3f);
  52320. Font font (getPopupMenuFont());
  52321. if (font.getHeight() > height / 1.3f)
  52322. font.setHeight (height / 1.3f);
  52323. g.setFont (font);
  52324. const int leftBorder = (height * 5) / 4;
  52325. const int rightBorder = 4;
  52326. if (image != 0)
  52327. {
  52328. g.drawImageWithin (image,
  52329. 2, 1, leftBorder - 4, height - 2,
  52330. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  52331. }
  52332. else if (isTicked)
  52333. {
  52334. const Path tick (getTickShape (1.0f));
  52335. const float th = font.getAscent();
  52336. const float ty = halfH - th * 0.5f;
  52337. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  52338. th, true));
  52339. }
  52340. g.drawFittedText (text,
  52341. leftBorder, 0,
  52342. width - (leftBorder + rightBorder), height,
  52343. Justification::centredLeft, 1);
  52344. if (shortcutKeyText.isNotEmpty())
  52345. {
  52346. Font f2 (font);
  52347. f2.setHeight (f2.getHeight() * 0.75f);
  52348. f2.setHorizontalScale (0.95f);
  52349. g.setFont (f2);
  52350. g.drawText (shortcutKeyText,
  52351. leftBorder,
  52352. 0,
  52353. width - (leftBorder + rightBorder + 4),
  52354. height,
  52355. Justification::centredRight,
  52356. true);
  52357. }
  52358. if (hasSubMenu)
  52359. {
  52360. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  52361. const float x = width - height * 0.6f;
  52362. Path p;
  52363. p.addTriangle (x, halfH - arrowH * 0.5f,
  52364. x, halfH + arrowH * 0.5f,
  52365. x + arrowH * 0.6f, halfH);
  52366. g.fillPath (p);
  52367. }
  52368. }
  52369. }
  52370. int LookAndFeel::getMenuWindowFlags()
  52371. {
  52372. return ComponentPeer::windowHasDropShadow;
  52373. }
  52374. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  52375. bool, MenuBarComponent& menuBar)
  52376. {
  52377. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  52378. if (menuBar.isEnabled())
  52379. {
  52380. drawShinyButtonShape (g,
  52381. -4.0f, 0.0f,
  52382. width + 8.0f, (float) height,
  52383. 0.0f,
  52384. baseColour,
  52385. 0.4f,
  52386. true, true, true, true);
  52387. }
  52388. else
  52389. {
  52390. g.fillAll (baseColour);
  52391. }
  52392. }
  52393. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  52394. {
  52395. return Font (menuBar.getHeight() * 0.7f);
  52396. }
  52397. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  52398. {
  52399. return getMenuBarFont (menuBar, itemIndex, itemText)
  52400. .getStringWidth (itemText) + menuBar.getHeight();
  52401. }
  52402. void LookAndFeel::drawMenuBarItem (Graphics& g,
  52403. int width, int height,
  52404. int itemIndex,
  52405. const String& itemText,
  52406. bool isMouseOverItem,
  52407. bool isMenuOpen,
  52408. bool /*isMouseOverBar*/,
  52409. MenuBarComponent& menuBar)
  52410. {
  52411. if (! menuBar.isEnabled())
  52412. {
  52413. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  52414. .withMultipliedAlpha (0.5f));
  52415. }
  52416. else if (isMenuOpen || isMouseOverItem)
  52417. {
  52418. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  52419. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  52420. }
  52421. else
  52422. {
  52423. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52424. }
  52425. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52426. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52427. }
  52428. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52429. TextEditor& textEditor)
  52430. {
  52431. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52432. }
  52433. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52434. {
  52435. if (textEditor.isEnabled())
  52436. {
  52437. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52438. {
  52439. const int border = 2;
  52440. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52441. g.drawRect (0, 0, width, height, border);
  52442. g.setOpacity (1.0f);
  52443. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52444. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52445. }
  52446. else
  52447. {
  52448. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52449. g.drawRect (0, 0, width, height);
  52450. g.setOpacity (1.0f);
  52451. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52452. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52453. }
  52454. }
  52455. }
  52456. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52457. const bool isButtonDown,
  52458. int buttonX, int buttonY,
  52459. int buttonW, int buttonH,
  52460. ComboBox& box)
  52461. {
  52462. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52463. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52464. {
  52465. g.setColour (box.findColour (TextButton::buttonColourId));
  52466. g.drawRect (0, 0, width, height, 2);
  52467. }
  52468. else
  52469. {
  52470. g.setColour (box.findColour (ComboBox::outlineColourId));
  52471. g.drawRect (0, 0, width, height);
  52472. }
  52473. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52474. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52475. box.hasKeyboardFocus (true),
  52476. false, isButtonDown)
  52477. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52478. drawGlassLozenge (g,
  52479. buttonX + outlineThickness, buttonY + outlineThickness,
  52480. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52481. baseColour, outlineThickness, -1.0f,
  52482. true, true, true, true);
  52483. if (box.isEnabled())
  52484. {
  52485. const float arrowX = 0.3f;
  52486. const float arrowH = 0.2f;
  52487. Path p;
  52488. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52489. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52490. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52491. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52492. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52493. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52494. g.setColour (box.findColour (ComboBox::arrowColourId));
  52495. g.fillPath (p);
  52496. }
  52497. }
  52498. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52499. {
  52500. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52501. }
  52502. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52503. {
  52504. return new Label (String::empty, String::empty);
  52505. }
  52506. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52507. {
  52508. label.setBounds (1, 1,
  52509. box.getWidth() + 3 - box.getHeight(),
  52510. box.getHeight() - 2);
  52511. label.setFont (getComboBoxFont (box));
  52512. }
  52513. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52514. {
  52515. g.fillAll (label.findColour (Label::backgroundColourId));
  52516. if (! label.isBeingEdited())
  52517. {
  52518. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52519. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52520. g.setFont (label.getFont());
  52521. g.drawFittedText (label.getText(),
  52522. label.getHorizontalBorderSize(),
  52523. label.getVerticalBorderSize(),
  52524. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52525. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52526. label.getJustificationType(),
  52527. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52528. label.getMinimumHorizontalScale());
  52529. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52530. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52531. }
  52532. else if (label.isEnabled())
  52533. {
  52534. g.setColour (label.findColour (Label::outlineColourId));
  52535. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52536. }
  52537. }
  52538. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52539. int x, int y,
  52540. int width, int height,
  52541. float /*sliderPos*/,
  52542. float /*minSliderPos*/,
  52543. float /*maxSliderPos*/,
  52544. const Slider::SliderStyle /*style*/,
  52545. Slider& slider)
  52546. {
  52547. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52548. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52549. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52550. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52551. Path indent;
  52552. if (slider.isHorizontal())
  52553. {
  52554. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52555. const float ih = sliderRadius;
  52556. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52557. gradCol2, 0.0f, iy + ih, false));
  52558. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52559. width + sliderRadius, ih,
  52560. 5.0f);
  52561. g.fillPath (indent);
  52562. }
  52563. else
  52564. {
  52565. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52566. const float iw = sliderRadius;
  52567. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52568. gradCol2, ix + iw, 0.0f, false));
  52569. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52570. iw, height + sliderRadius,
  52571. 5.0f);
  52572. g.fillPath (indent);
  52573. }
  52574. g.setColour (Colour (0x4c000000));
  52575. g.strokePath (indent, PathStrokeType (0.5f));
  52576. }
  52577. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52578. int x, int y,
  52579. int width, int height,
  52580. float sliderPos,
  52581. float minSliderPos,
  52582. float maxSliderPos,
  52583. const Slider::SliderStyle style,
  52584. Slider& slider)
  52585. {
  52586. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52587. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52588. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52589. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52590. slider.isMouseButtonDown() && slider.isEnabled()));
  52591. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52592. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52593. {
  52594. float kx, ky;
  52595. if (style == Slider::LinearVertical)
  52596. {
  52597. kx = x + width * 0.5f;
  52598. ky = sliderPos;
  52599. }
  52600. else
  52601. {
  52602. kx = sliderPos;
  52603. ky = y + height * 0.5f;
  52604. }
  52605. drawGlassSphere (g,
  52606. kx - sliderRadius,
  52607. ky - sliderRadius,
  52608. sliderRadius * 2.0f,
  52609. knobColour, outlineThickness);
  52610. }
  52611. else
  52612. {
  52613. if (style == Slider::ThreeValueVertical)
  52614. {
  52615. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52616. sliderPos - sliderRadius,
  52617. sliderRadius * 2.0f,
  52618. knobColour, outlineThickness);
  52619. }
  52620. else if (style == Slider::ThreeValueHorizontal)
  52621. {
  52622. drawGlassSphere (g,sliderPos - sliderRadius,
  52623. y + height * 0.5f - sliderRadius,
  52624. sliderRadius * 2.0f,
  52625. knobColour, outlineThickness);
  52626. }
  52627. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52628. {
  52629. const float sr = jmin (sliderRadius, width * 0.4f);
  52630. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52631. minSliderPos - sliderRadius,
  52632. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52633. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52634. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52635. }
  52636. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52637. {
  52638. const float sr = jmin (sliderRadius, height * 0.4f);
  52639. drawGlassPointer (g, minSliderPos - sr,
  52640. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52641. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52642. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52643. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52644. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52645. }
  52646. }
  52647. }
  52648. void LookAndFeel::drawLinearSlider (Graphics& g,
  52649. int x, int y,
  52650. int width, int height,
  52651. float sliderPos,
  52652. float minSliderPos,
  52653. float maxSliderPos,
  52654. const Slider::SliderStyle style,
  52655. Slider& slider)
  52656. {
  52657. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52658. if (style == Slider::LinearBar)
  52659. {
  52660. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52661. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52662. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52663. false,
  52664. isMouseOver,
  52665. isMouseOver || slider.isMouseButtonDown()));
  52666. drawShinyButtonShape (g,
  52667. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52668. baseColour,
  52669. slider.isEnabled() ? 0.9f : 0.3f,
  52670. true, true, true, true);
  52671. }
  52672. else
  52673. {
  52674. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52675. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52676. }
  52677. }
  52678. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52679. {
  52680. return jmin (7,
  52681. slider.getHeight() / 2,
  52682. slider.getWidth() / 2) + 2;
  52683. }
  52684. void LookAndFeel::drawRotarySlider (Graphics& g,
  52685. int x, int y,
  52686. int width, int height,
  52687. float sliderPos,
  52688. const float rotaryStartAngle,
  52689. const float rotaryEndAngle,
  52690. Slider& slider)
  52691. {
  52692. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52693. const float centreX = x + width * 0.5f;
  52694. const float centreY = y + height * 0.5f;
  52695. const float rx = centreX - radius;
  52696. const float ry = centreY - radius;
  52697. const float rw = radius * 2.0f;
  52698. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52699. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52700. if (radius > 12.0f)
  52701. {
  52702. if (slider.isEnabled())
  52703. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52704. else
  52705. g.setColour (Colour (0x80808080));
  52706. const float thickness = 0.7f;
  52707. {
  52708. Path filledArc;
  52709. filledArc.addPieSegment (rx, ry, rw, rw,
  52710. rotaryStartAngle,
  52711. angle,
  52712. thickness);
  52713. g.fillPath (filledArc);
  52714. }
  52715. if (thickness > 0)
  52716. {
  52717. const float innerRadius = radius * 0.2f;
  52718. Path p;
  52719. p.addTriangle (-innerRadius, 0.0f,
  52720. 0.0f, -radius * thickness * 1.1f,
  52721. innerRadius, 0.0f);
  52722. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52723. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52724. }
  52725. if (slider.isEnabled())
  52726. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52727. else
  52728. g.setColour (Colour (0x80808080));
  52729. Path outlineArc;
  52730. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52731. outlineArc.closeSubPath();
  52732. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52733. }
  52734. else
  52735. {
  52736. if (slider.isEnabled())
  52737. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52738. else
  52739. g.setColour (Colour (0x80808080));
  52740. Path p;
  52741. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52742. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52743. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52744. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52745. }
  52746. }
  52747. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52748. {
  52749. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52750. }
  52751. class SliderLabelComp : public Label
  52752. {
  52753. public:
  52754. SliderLabelComp() : Label (String::empty, String::empty) {}
  52755. ~SliderLabelComp() {}
  52756. void mouseWheelMove (const MouseEvent&, float, float) {}
  52757. };
  52758. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52759. {
  52760. Label* const l = new SliderLabelComp();
  52761. l->setJustificationType (Justification::centred);
  52762. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52763. l->setColour (Label::backgroundColourId,
  52764. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52765. : slider.findColour (Slider::textBoxBackgroundColourId));
  52766. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52767. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52768. l->setColour (TextEditor::backgroundColourId,
  52769. slider.findColour (Slider::textBoxBackgroundColourId)
  52770. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52771. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52772. return l;
  52773. }
  52774. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52775. {
  52776. return 0;
  52777. }
  52778. static const TextLayout layoutTooltipText (const String& text) throw()
  52779. {
  52780. const float tooltipFontSize = 12.0f;
  52781. const int maxToolTipWidth = 400;
  52782. const Font f (tooltipFontSize, Font::bold);
  52783. TextLayout tl (text, f);
  52784. tl.layout (maxToolTipWidth, Justification::left, true);
  52785. return tl;
  52786. }
  52787. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52788. {
  52789. const TextLayout tl (layoutTooltipText (tipText));
  52790. width = tl.getWidth() + 14;
  52791. height = tl.getHeight() + 6;
  52792. }
  52793. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52794. {
  52795. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52796. const Colour textCol (findColour (TooltipWindow::textColourId));
  52797. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52798. g.setColour (findColour (TooltipWindow::outlineColourId));
  52799. g.drawRect (0, 0, width, height, 1);
  52800. #endif
  52801. const TextLayout tl (layoutTooltipText (text));
  52802. g.setColour (findColour (TooltipWindow::textColourId));
  52803. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52804. }
  52805. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52806. {
  52807. return new TextButton (text, TRANS("click to browse for a different file"));
  52808. }
  52809. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52810. ComboBox* filenameBox,
  52811. Button* browseButton)
  52812. {
  52813. browseButton->setSize (80, filenameComp.getHeight());
  52814. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52815. if (tb != 0)
  52816. tb->changeWidthToFitText();
  52817. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52818. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52819. }
  52820. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52821. int imageX, int imageY, int imageW, int imageH,
  52822. const Colour& overlayColour,
  52823. float imageOpacity,
  52824. ImageButton& button)
  52825. {
  52826. if (! button.isEnabled())
  52827. imageOpacity *= 0.3f;
  52828. if (! overlayColour.isOpaque())
  52829. {
  52830. g.setOpacity (imageOpacity);
  52831. g.drawImage (image, imageX, imageY, imageW, imageH,
  52832. 0, 0, image->getWidth(), image->getHeight(), false);
  52833. }
  52834. if (! overlayColour.isTransparent())
  52835. {
  52836. g.setColour (overlayColour);
  52837. g.drawImage (image, imageX, imageY, imageW, imageH,
  52838. 0, 0, image->getWidth(), image->getHeight(), true);
  52839. }
  52840. }
  52841. void LookAndFeel::drawCornerResizer (Graphics& g,
  52842. int w, int h,
  52843. bool /*isMouseOver*/,
  52844. bool /*isMouseDragging*/)
  52845. {
  52846. const float lineThickness = jmin (w, h) * 0.075f;
  52847. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52848. {
  52849. g.setColour (Colours::lightgrey);
  52850. g.drawLine (w * i,
  52851. h + 1.0f,
  52852. w + 1.0f,
  52853. h * i,
  52854. lineThickness);
  52855. g.setColour (Colours::darkgrey);
  52856. g.drawLine (w * i + lineThickness,
  52857. h + 1.0f,
  52858. w + 1.0f,
  52859. h * i + lineThickness,
  52860. lineThickness);
  52861. }
  52862. }
  52863. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52864. const BorderSize& /*borders*/)
  52865. {
  52866. }
  52867. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52868. const BorderSize& /*border*/, ResizableWindow& window)
  52869. {
  52870. g.fillAll (window.getBackgroundColour());
  52871. }
  52872. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52873. const BorderSize& border, ResizableWindow&)
  52874. {
  52875. g.setColour (Colour (0x80000000));
  52876. g.drawRect (0, 0, w, h);
  52877. g.setColour (Colour (0x19000000));
  52878. g.drawRect (border.getLeft() - 1,
  52879. border.getTop() - 1,
  52880. w + 2 - border.getLeftAndRight(),
  52881. h + 2 - border.getTopAndBottom());
  52882. }
  52883. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52884. Graphics& g, int w, int h,
  52885. int titleSpaceX, int titleSpaceW,
  52886. const Image* icon,
  52887. bool drawTitleTextOnLeft)
  52888. {
  52889. const bool isActive = window.isActiveWindow();
  52890. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52891. 0.0f, 0.0f,
  52892. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52893. 0.0f, (float) h, false));
  52894. g.fillAll();
  52895. Font font (h * 0.65f, Font::bold);
  52896. g.setFont (font);
  52897. int textW = font.getStringWidth (window.getName());
  52898. int iconW = 0;
  52899. int iconH = 0;
  52900. if (icon != 0)
  52901. {
  52902. iconH = (int) font.getHeight();
  52903. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52904. }
  52905. textW = jmin (titleSpaceW, textW + iconW);
  52906. int textX = drawTitleTextOnLeft ? titleSpaceX
  52907. : jmax (titleSpaceX, (w - textW) / 2);
  52908. if (textX + textW > titleSpaceX + titleSpaceW)
  52909. textX = titleSpaceX + titleSpaceW - textW;
  52910. if (icon != 0)
  52911. {
  52912. g.setOpacity (isActive ? 1.0f : 0.6f);
  52913. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52914. RectanglePlacement::centred, false);
  52915. textX += iconW;
  52916. textW -= iconW;
  52917. }
  52918. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52919. g.setColour (findColour (DocumentWindow::textColourId));
  52920. else
  52921. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52922. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52923. }
  52924. class GlassWindowButton : public Button
  52925. {
  52926. public:
  52927. GlassWindowButton (const String& name, const Colour& col,
  52928. const Path& normalShape_,
  52929. const Path& toggledShape_) throw()
  52930. : Button (name),
  52931. colour (col),
  52932. normalShape (normalShape_),
  52933. toggledShape (toggledShape_)
  52934. {
  52935. }
  52936. ~GlassWindowButton()
  52937. {
  52938. }
  52939. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52940. {
  52941. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52942. if (! isEnabled())
  52943. alpha *= 0.5f;
  52944. float x = 0, y = 0, diam;
  52945. if (getWidth() < getHeight())
  52946. {
  52947. diam = (float) getWidth();
  52948. y = (getHeight() - getWidth()) * 0.5f;
  52949. }
  52950. else
  52951. {
  52952. diam = (float) getHeight();
  52953. y = (getWidth() - getHeight()) * 0.5f;
  52954. }
  52955. x += diam * 0.05f;
  52956. y += diam * 0.05f;
  52957. diam *= 0.9f;
  52958. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52959. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52960. g.fillEllipse (x, y, diam, diam);
  52961. x += 2.0f;
  52962. y += 2.0f;
  52963. diam -= 4.0f;
  52964. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52965. Path& p = getToggleState() ? toggledShape : normalShape;
  52966. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52967. diam * 0.4f, diam * 0.4f, true));
  52968. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52969. g.fillPath (p, t);
  52970. }
  52971. juce_UseDebuggingNewOperator
  52972. private:
  52973. Colour colour;
  52974. Path normalShape, toggledShape;
  52975. GlassWindowButton (const GlassWindowButton&);
  52976. GlassWindowButton& operator= (const GlassWindowButton&);
  52977. };
  52978. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52979. {
  52980. Path shape;
  52981. const float crossThickness = 0.25f;
  52982. if (buttonType == DocumentWindow::closeButton)
  52983. {
  52984. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52985. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52986. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52987. }
  52988. else if (buttonType == DocumentWindow::minimiseButton)
  52989. {
  52990. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52991. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52992. }
  52993. else if (buttonType == DocumentWindow::maximiseButton)
  52994. {
  52995. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52996. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52997. Path fullscreenShape;
  52998. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52999. fullscreenShape.lineTo (0.0f, 100.0f);
  53000. fullscreenShape.lineTo (0.0f, 0.0f);
  53001. fullscreenShape.lineTo (100.0f, 0.0f);
  53002. fullscreenShape.lineTo (100.0f, 45.0f);
  53003. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  53004. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  53005. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  53006. }
  53007. jassertfalse
  53008. return 0;
  53009. }
  53010. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53011. int titleBarX,
  53012. int titleBarY,
  53013. int titleBarW,
  53014. int titleBarH,
  53015. Button* minimiseButton,
  53016. Button* maximiseButton,
  53017. Button* closeButton,
  53018. bool positionTitleBarButtonsOnLeft)
  53019. {
  53020. const int buttonW = titleBarH - titleBarH / 8;
  53021. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53022. : titleBarX + titleBarW - buttonW - buttonW / 4;
  53023. if (closeButton != 0)
  53024. {
  53025. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53026. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  53027. }
  53028. if (positionTitleBarButtonsOnLeft)
  53029. swapVariables (minimiseButton, maximiseButton);
  53030. if (maximiseButton != 0)
  53031. {
  53032. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53033. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53034. }
  53035. if (minimiseButton != 0)
  53036. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53037. }
  53038. int LookAndFeel::getDefaultMenuBarHeight()
  53039. {
  53040. return 24;
  53041. }
  53042. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  53043. {
  53044. return new DropShadower (0.4f, 1, 5, 10);
  53045. }
  53046. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  53047. int w, int h,
  53048. bool /*isVerticalBar*/,
  53049. bool isMouseOver,
  53050. bool isMouseDragging)
  53051. {
  53052. float alpha = 0.5f;
  53053. if (isMouseOver || isMouseDragging)
  53054. {
  53055. g.fillAll (Colour (0x190000ff));
  53056. alpha = 1.0f;
  53057. }
  53058. const float cx = w * 0.5f;
  53059. const float cy = h * 0.5f;
  53060. const float cr = jmin (w, h) * 0.4f;
  53061. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  53062. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  53063. true));
  53064. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  53065. }
  53066. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  53067. const String& text,
  53068. const Justification& position,
  53069. GroupComponent& group)
  53070. {
  53071. const float textH = 15.0f;
  53072. const float indent = 3.0f;
  53073. const float textEdgeGap = 4.0f;
  53074. float cs = 5.0f;
  53075. Font f (textH);
  53076. Path p;
  53077. float x = indent;
  53078. float y = f.getAscent() - 3.0f;
  53079. float w = jmax (0.0f, width - x * 2.0f);
  53080. float h = jmax (0.0f, height - y - indent);
  53081. cs = jmin (cs, w * 0.5f, h * 0.5f);
  53082. const float cs2 = 2.0f * cs;
  53083. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  53084. float textX = cs + textEdgeGap;
  53085. if (position.testFlags (Justification::horizontallyCentred))
  53086. textX = cs + (w - cs2 - textW) * 0.5f;
  53087. else if (position.testFlags (Justification::right))
  53088. textX = w - cs - textW - textEdgeGap;
  53089. p.startNewSubPath (x + textX + textW, y);
  53090. p.lineTo (x + w - cs, y);
  53091. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  53092. p.lineTo (x + w, y + h - cs);
  53093. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53094. p.lineTo (x + cs, y + h);
  53095. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53096. p.lineTo (x, y + cs);
  53097. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53098. p.lineTo (x + textX, y);
  53099. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  53100. g.setColour (group.findColour (GroupComponent::outlineColourId)
  53101. .withMultipliedAlpha (alpha));
  53102. g.strokePath (p, PathStrokeType (2.0f));
  53103. g.setColour (group.findColour (GroupComponent::textColourId)
  53104. .withMultipliedAlpha (alpha));
  53105. g.setFont (f);
  53106. g.drawText (text,
  53107. roundToInt (x + textX), 0,
  53108. roundToInt (textW),
  53109. roundToInt (textH),
  53110. Justification::centred, true);
  53111. }
  53112. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  53113. {
  53114. return 1 + tabDepth / 3;
  53115. }
  53116. int LookAndFeel::getTabButtonSpaceAroundImage()
  53117. {
  53118. return 4;
  53119. }
  53120. void LookAndFeel::createTabButtonShape (Path& p,
  53121. int width, int height,
  53122. int /*tabIndex*/,
  53123. const String& /*text*/,
  53124. Button& /*button*/,
  53125. TabbedButtonBar::Orientation orientation,
  53126. const bool /*isMouseOver*/,
  53127. const bool /*isMouseDown*/,
  53128. const bool /*isFrontTab*/)
  53129. {
  53130. const float w = (float) width;
  53131. const float h = (float) height;
  53132. float length = w;
  53133. float depth = h;
  53134. if (orientation == TabbedButtonBar::TabsAtLeft
  53135. || orientation == TabbedButtonBar::TabsAtRight)
  53136. {
  53137. swapVariables (length, depth);
  53138. }
  53139. const float indent = (float) getTabButtonOverlap ((int) depth);
  53140. const float overhang = 4.0f;
  53141. if (orientation == TabbedButtonBar::TabsAtLeft)
  53142. {
  53143. p.startNewSubPath (w, 0.0f);
  53144. p.lineTo (0.0f, indent);
  53145. p.lineTo (0.0f, h - indent);
  53146. p.lineTo (w, h);
  53147. p.lineTo (w + overhang, h + overhang);
  53148. p.lineTo (w + overhang, -overhang);
  53149. }
  53150. else if (orientation == TabbedButtonBar::TabsAtRight)
  53151. {
  53152. p.startNewSubPath (0.0f, 0.0f);
  53153. p.lineTo (w, indent);
  53154. p.lineTo (w, h - indent);
  53155. p.lineTo (0.0f, h);
  53156. p.lineTo (-overhang, h + overhang);
  53157. p.lineTo (-overhang, -overhang);
  53158. }
  53159. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53160. {
  53161. p.startNewSubPath (0.0f, 0.0f);
  53162. p.lineTo (indent, h);
  53163. p.lineTo (w - indent, h);
  53164. p.lineTo (w, 0.0f);
  53165. p.lineTo (w + overhang, -overhang);
  53166. p.lineTo (-overhang, -overhang);
  53167. }
  53168. else
  53169. {
  53170. p.startNewSubPath (0.0f, h);
  53171. p.lineTo (indent, 0.0f);
  53172. p.lineTo (w - indent, 0.0f);
  53173. p.lineTo (w, h);
  53174. p.lineTo (w + overhang, h + overhang);
  53175. p.lineTo (-overhang, h + overhang);
  53176. }
  53177. p.closeSubPath();
  53178. p = p.createPathWithRoundedCorners (3.0f);
  53179. }
  53180. void LookAndFeel::fillTabButtonShape (Graphics& g,
  53181. const Path& path,
  53182. const Colour& preferredColour,
  53183. int /*tabIndex*/,
  53184. const String& /*text*/,
  53185. Button& button,
  53186. TabbedButtonBar::Orientation /*orientation*/,
  53187. const bool /*isMouseOver*/,
  53188. const bool /*isMouseDown*/,
  53189. const bool isFrontTab)
  53190. {
  53191. g.setColour (isFrontTab ? preferredColour
  53192. : preferredColour.withMultipliedAlpha (0.9f));
  53193. g.fillPath (path);
  53194. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  53195. : TabbedButtonBar::tabOutlineColourId, false)
  53196. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  53197. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  53198. }
  53199. void LookAndFeel::drawTabButtonText (Graphics& g,
  53200. int x, int y, int w, int h,
  53201. const Colour& preferredBackgroundColour,
  53202. int /*tabIndex*/,
  53203. const String& text,
  53204. Button& button,
  53205. TabbedButtonBar::Orientation orientation,
  53206. const bool isMouseOver,
  53207. const bool isMouseDown,
  53208. const bool isFrontTab)
  53209. {
  53210. int length = w;
  53211. int depth = h;
  53212. if (orientation == TabbedButtonBar::TabsAtLeft
  53213. || orientation == TabbedButtonBar::TabsAtRight)
  53214. {
  53215. swapVariables (length, depth);
  53216. }
  53217. Font font (depth * 0.6f);
  53218. font.setUnderline (button.hasKeyboardFocus (false));
  53219. GlyphArrangement textLayout;
  53220. textLayout.addFittedText (font, text.trim(),
  53221. 0.0f, 0.0f, (float) length, (float) depth,
  53222. Justification::centred,
  53223. jmax (1, depth / 12));
  53224. AffineTransform transform;
  53225. if (orientation == TabbedButtonBar::TabsAtLeft)
  53226. {
  53227. transform = transform.rotated (float_Pi * -0.5f)
  53228. .translated ((float) x, (float) (y + h));
  53229. }
  53230. else if (orientation == TabbedButtonBar::TabsAtRight)
  53231. {
  53232. transform = transform.rotated (float_Pi * 0.5f)
  53233. .translated ((float) (x + w), (float) y);
  53234. }
  53235. else
  53236. {
  53237. transform = transform.translated ((float) x, (float) y);
  53238. }
  53239. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  53240. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  53241. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  53242. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  53243. else
  53244. g.setColour (preferredBackgroundColour.contrasting());
  53245. if (! (isMouseOver || isMouseDown))
  53246. g.setOpacity (0.8f);
  53247. if (! button.isEnabled())
  53248. g.setOpacity (0.3f);
  53249. textLayout.draw (g, transform);
  53250. }
  53251. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  53252. const String& text,
  53253. int tabDepth,
  53254. Button&)
  53255. {
  53256. Font f (tabDepth * 0.6f);
  53257. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  53258. }
  53259. void LookAndFeel::drawTabButton (Graphics& g,
  53260. int w, int h,
  53261. const Colour& preferredColour,
  53262. int tabIndex,
  53263. const String& text,
  53264. Button& button,
  53265. TabbedButtonBar::Orientation orientation,
  53266. const bool isMouseOver,
  53267. const bool isMouseDown,
  53268. const bool isFrontTab)
  53269. {
  53270. int length = w;
  53271. int depth = h;
  53272. if (orientation == TabbedButtonBar::TabsAtLeft
  53273. || orientation == TabbedButtonBar::TabsAtRight)
  53274. {
  53275. swapVariables (length, depth);
  53276. }
  53277. Path tabShape;
  53278. createTabButtonShape (tabShape, w, h,
  53279. tabIndex, text, button, orientation,
  53280. isMouseOver, isMouseDown, isFrontTab);
  53281. fillTabButtonShape (g, tabShape, preferredColour,
  53282. tabIndex, text, button, orientation,
  53283. isMouseOver, isMouseDown, isFrontTab);
  53284. const int indent = getTabButtonOverlap (depth);
  53285. int x = 0, y = 0;
  53286. if (orientation == TabbedButtonBar::TabsAtLeft
  53287. || orientation == TabbedButtonBar::TabsAtRight)
  53288. {
  53289. y += indent;
  53290. h -= indent * 2;
  53291. }
  53292. else
  53293. {
  53294. x += indent;
  53295. w -= indent * 2;
  53296. }
  53297. drawTabButtonText (g, x, y, w, h, preferredColour,
  53298. tabIndex, text, button, orientation,
  53299. isMouseOver, isMouseDown, isFrontTab);
  53300. }
  53301. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  53302. int w, int h,
  53303. TabbedButtonBar& tabBar,
  53304. TabbedButtonBar::Orientation orientation)
  53305. {
  53306. const float shadowSize = 0.2f;
  53307. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  53308. Rectangle<int> shadowRect;
  53309. if (orientation == TabbedButtonBar::TabsAtLeft)
  53310. {
  53311. x1 = (float) w;
  53312. x2 = w * (1.0f - shadowSize);
  53313. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  53314. }
  53315. else if (orientation == TabbedButtonBar::TabsAtRight)
  53316. {
  53317. x2 = w * shadowSize;
  53318. shadowRect.setBounds (0, 0, (int) x2, h);
  53319. }
  53320. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53321. {
  53322. y2 = h * shadowSize;
  53323. shadowRect.setBounds (0, 0, w, (int) y2);
  53324. }
  53325. else
  53326. {
  53327. y1 = (float) h;
  53328. y2 = h * (1.0f - shadowSize);
  53329. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  53330. }
  53331. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  53332. Colours::transparentBlack, x2, y2, false));
  53333. shadowRect.expand (2, 2);
  53334. g.fillRect (shadowRect);
  53335. g.setColour (Colour (0x80000000));
  53336. if (orientation == TabbedButtonBar::TabsAtLeft)
  53337. {
  53338. g.fillRect (w - 1, 0, 1, h);
  53339. }
  53340. else if (orientation == TabbedButtonBar::TabsAtRight)
  53341. {
  53342. g.fillRect (0, 0, 1, h);
  53343. }
  53344. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53345. {
  53346. g.fillRect (0, 0, w, 1);
  53347. }
  53348. else
  53349. {
  53350. g.fillRect (0, h - 1, w, 1);
  53351. }
  53352. }
  53353. Button* LookAndFeel::createTabBarExtrasButton()
  53354. {
  53355. const float thickness = 7.0f;
  53356. const float indent = 22.0f;
  53357. Path p;
  53358. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  53359. DrawablePath ellipse;
  53360. ellipse.setPath (p);
  53361. ellipse.setFill (Colour (0x99ffffff));
  53362. p.clear();
  53363. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53364. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53365. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53366. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53367. p.setUsingNonZeroWinding (false);
  53368. DrawablePath dp;
  53369. dp.setPath (p);
  53370. dp.setFill (Colour (0x59000000));
  53371. DrawableComposite normalImage;
  53372. normalImage.insertDrawable (ellipse);
  53373. normalImage.insertDrawable (dp);
  53374. dp.setFill (Colour (0xcc000000));
  53375. DrawableComposite overImage;
  53376. overImage.insertDrawable (ellipse);
  53377. overImage.insertDrawable (dp);
  53378. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  53379. db->setImages (&normalImage, &overImage, 0);
  53380. return db;
  53381. }
  53382. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  53383. {
  53384. g.fillAll (Colours::white);
  53385. const int w = header.getWidth();
  53386. const int h = header.getHeight();
  53387. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  53388. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  53389. false));
  53390. g.fillRect (0, h / 2, w, h);
  53391. g.setColour (Colour (0x33000000));
  53392. g.fillRect (0, h - 1, w, 1);
  53393. for (int i = header.getNumColumns (true); --i >= 0;)
  53394. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  53395. }
  53396. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  53397. int width, int height,
  53398. bool isMouseOver, bool isMouseDown,
  53399. int columnFlags)
  53400. {
  53401. if (isMouseDown)
  53402. g.fillAll (Colour (0x8899aadd));
  53403. else if (isMouseOver)
  53404. g.fillAll (Colour (0x5599aadd));
  53405. int rightOfText = width - 4;
  53406. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  53407. {
  53408. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  53409. const float bottom = height - top;
  53410. const float w = height * 0.5f;
  53411. const float x = rightOfText - (w * 1.25f);
  53412. rightOfText = (int) x;
  53413. Path sortArrow;
  53414. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  53415. g.setColour (Colour (0x99000000));
  53416. g.fillPath (sortArrow);
  53417. }
  53418. g.setColour (Colours::black);
  53419. g.setFont (height * 0.5f, Font::bold);
  53420. const int textX = 4;
  53421. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53422. }
  53423. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53424. {
  53425. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53426. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53427. background.darker (0.1f),
  53428. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53429. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53430. false));
  53431. g.fillAll();
  53432. }
  53433. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53434. {
  53435. return createTabBarExtrasButton();
  53436. }
  53437. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53438. bool isMouseOver, bool isMouseDown,
  53439. ToolbarItemComponent& component)
  53440. {
  53441. if (isMouseDown)
  53442. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53443. else if (isMouseOver)
  53444. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53445. }
  53446. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53447. const String& text, ToolbarItemComponent& component)
  53448. {
  53449. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53450. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53451. const float fontHeight = jmin (14.0f, height * 0.85f);
  53452. g.setFont (fontHeight);
  53453. g.drawFittedText (text,
  53454. x, y, width, height,
  53455. Justification::centred,
  53456. jmax (1, height / (int) fontHeight));
  53457. }
  53458. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53459. bool isOpen, int width, int height)
  53460. {
  53461. const int buttonSize = (height * 3) / 4;
  53462. const int buttonIndent = (height - buttonSize) / 2;
  53463. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53464. const int textX = buttonIndent * 2 + buttonSize + 2;
  53465. g.setColour (Colours::black);
  53466. g.setFont (height * 0.7f, Font::bold);
  53467. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53468. }
  53469. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53470. PropertyComponent&)
  53471. {
  53472. g.setColour (Colour (0x66ffffff));
  53473. g.fillRect (0, 0, width, height - 1);
  53474. }
  53475. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53476. PropertyComponent& component)
  53477. {
  53478. g.setColour (Colours::black);
  53479. if (! component.isEnabled())
  53480. g.setOpacity (0.6f);
  53481. g.setFont (jmin (height, 24) * 0.65f);
  53482. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  53483. g.drawFittedText (component.getName(),
  53484. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53485. Justification::centredLeft, 2);
  53486. }
  53487. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53488. {
  53489. return Rectangle<int> (component.getWidth() / 3, 1,
  53490. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53491. }
  53492. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53493. const String& instructions,
  53494. GlyphArrangement& text,
  53495. int width)
  53496. {
  53497. text.clear();
  53498. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53499. 8.0f, 22.0f, width - 16.0f,
  53500. Justification::centred);
  53501. text.addJustifiedText (Font (14.0f), instructions,
  53502. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53503. Justification::centred);
  53504. }
  53505. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53506. const String& filename, Image* icon,
  53507. const String& fileSizeDescription,
  53508. const String& fileTimeDescription,
  53509. const bool isDirectory,
  53510. const bool isItemSelected,
  53511. const int /*itemIndex*/)
  53512. {
  53513. if (isItemSelected)
  53514. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53515. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53516. g.setFont (height * 0.7f);
  53517. Image* im = icon;
  53518. Image* toRelease = 0;
  53519. if (im == 0)
  53520. {
  53521. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53522. : getDefaultDocumentFileImage());
  53523. }
  53524. const int x = 32;
  53525. if (im != 0)
  53526. {
  53527. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53528. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53529. false);
  53530. ImageCache::release (toRelease);
  53531. }
  53532. if (width > 450 && ! isDirectory)
  53533. {
  53534. const int sizeX = roundToInt (width * 0.7f);
  53535. const int dateX = roundToInt (width * 0.8f);
  53536. g.drawFittedText (filename,
  53537. x, 0, sizeX - x, height,
  53538. Justification::centredLeft, 1);
  53539. g.setFont (height * 0.5f);
  53540. g.setColour (Colours::darkgrey);
  53541. if (! isDirectory)
  53542. {
  53543. g.drawFittedText (fileSizeDescription,
  53544. sizeX, 0, dateX - sizeX - 8, height,
  53545. Justification::centredRight, 1);
  53546. g.drawFittedText (fileTimeDescription,
  53547. dateX, 0, width - 8 - dateX, height,
  53548. Justification::centredRight, 1);
  53549. }
  53550. }
  53551. else
  53552. {
  53553. g.drawFittedText (filename,
  53554. x, 0, width - x, height,
  53555. Justification::centredLeft, 1);
  53556. }
  53557. }
  53558. Button* LookAndFeel::createFileBrowserGoUpButton()
  53559. {
  53560. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53561. Path arrowPath;
  53562. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53563. DrawablePath arrowImage;
  53564. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53565. arrowImage.setPath (arrowPath);
  53566. goUpButton->setImages (&arrowImage);
  53567. return goUpButton;
  53568. }
  53569. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53570. DirectoryContentsDisplayComponent* fileListComponent,
  53571. FilePreviewComponent* previewComp,
  53572. ComboBox* currentPathBox,
  53573. TextEditor* filenameBox,
  53574. Button* goUpButton)
  53575. {
  53576. const int x = 8;
  53577. int w = browserComp.getWidth() - x - x;
  53578. if (previewComp != 0)
  53579. {
  53580. const int previewWidth = w / 3;
  53581. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53582. w -= previewWidth + 4;
  53583. }
  53584. int y = 4;
  53585. const int controlsHeight = 22;
  53586. const int bottomSectionHeight = controlsHeight + 8;
  53587. const int upButtonWidth = 50;
  53588. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53589. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53590. y += controlsHeight + 4;
  53591. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53592. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53593. y = listAsComp->getBottom() + 4;
  53594. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53595. }
  53596. Image* LookAndFeel::getDefaultFolderImage()
  53597. {
  53598. 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,
  53599. 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,
  53600. 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,
  53601. 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,
  53602. 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,
  53603. 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,
  53604. 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,
  53605. 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,
  53606. 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,
  53607. 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,
  53608. 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,
  53609. 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,
  53610. 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,
  53611. 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,
  53612. 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,
  53613. 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,
  53614. 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,
  53615. 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,
  53616. 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,
  53617. 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,
  53618. 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,
  53619. 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,
  53620. 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,
  53621. 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,
  53622. 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,
  53623. 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,
  53624. 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,
  53625. 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,
  53626. 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,
  53627. 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,
  53628. 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,
  53629. 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,
  53630. 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,
  53631. 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,
  53632. 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,
  53633. 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,
  53634. 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,
  53635. 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,
  53636. 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,
  53637. 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,
  53638. 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,
  53639. 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,
  53640. 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,
  53641. 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};
  53642. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53643. }
  53644. Image* LookAndFeel::getDefaultDocumentFileImage()
  53645. {
  53646. 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,
  53647. 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,
  53648. 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,
  53649. 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,
  53650. 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,
  53651. 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,
  53652. 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,
  53653. 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,
  53654. 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,
  53655. 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,
  53656. 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,
  53657. 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,
  53658. 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,
  53659. 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,
  53660. 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,
  53661. 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,
  53662. 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,
  53663. 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,
  53664. 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,
  53665. 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,
  53666. 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,
  53667. 174,66,96,130,0,0};
  53668. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53669. }
  53670. void LookAndFeel::playAlertSound()
  53671. {
  53672. PlatformUtilities::beep();
  53673. }
  53674. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53675. {
  53676. g.setColour (Colours::white.withAlpha (0.7f));
  53677. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53678. g.setColour (Colours::black.withAlpha (0.2f));
  53679. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53680. const int totalBlocks = 7;
  53681. const int numBlocks = roundToInt (totalBlocks * level);
  53682. const float w = (width - 6.0f) / (float) totalBlocks;
  53683. for (int i = 0; i < totalBlocks; ++i)
  53684. {
  53685. if (i >= numBlocks)
  53686. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53687. else
  53688. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53689. : Colours::red);
  53690. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53691. }
  53692. }
  53693. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53694. {
  53695. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53696. if (keyDescription.isNotEmpty())
  53697. {
  53698. if (button.isEnabled())
  53699. {
  53700. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53701. g.fillAll (textColour.withAlpha (alpha));
  53702. g.setOpacity (0.3f);
  53703. g.drawBevel (0, 0, width, height, 2);
  53704. }
  53705. g.setColour (textColour);
  53706. g.setFont (height * 0.6f);
  53707. g.drawFittedText (keyDescription,
  53708. 3, 0, width - 6, height,
  53709. Justification::centred, 1);
  53710. }
  53711. else
  53712. {
  53713. const float thickness = 7.0f;
  53714. const float indent = 22.0f;
  53715. Path p;
  53716. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53717. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53718. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53719. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53720. p.setUsingNonZeroWinding (false);
  53721. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53722. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53723. }
  53724. if (button.hasKeyboardFocus (false))
  53725. {
  53726. g.setColour (textColour.withAlpha (0.4f));
  53727. g.drawRect (0, 0, width, height);
  53728. }
  53729. }
  53730. static void createRoundedPath (Path& p,
  53731. const float x, const float y,
  53732. const float w, const float h,
  53733. const float cs,
  53734. const bool curveTopLeft, const bool curveTopRight,
  53735. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53736. {
  53737. const float cs2 = 2.0f * cs;
  53738. if (curveTopLeft)
  53739. {
  53740. p.startNewSubPath (x, y + cs);
  53741. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53742. }
  53743. else
  53744. {
  53745. p.startNewSubPath (x, y);
  53746. }
  53747. if (curveTopRight)
  53748. {
  53749. p.lineTo (x + w - cs, y);
  53750. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53751. }
  53752. else
  53753. {
  53754. p.lineTo (x + w, y);
  53755. }
  53756. if (curveBottomRight)
  53757. {
  53758. p.lineTo (x + w, y + h - cs);
  53759. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53760. }
  53761. else
  53762. {
  53763. p.lineTo (x + w, y + h);
  53764. }
  53765. if (curveBottomLeft)
  53766. {
  53767. p.lineTo (x + cs, y + h);
  53768. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53769. }
  53770. else
  53771. {
  53772. p.lineTo (x, y + h);
  53773. }
  53774. p.closeSubPath();
  53775. }
  53776. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53777. float x, float y, float w, float h,
  53778. float maxCornerSize,
  53779. const Colour& baseColour,
  53780. const float strokeWidth,
  53781. const bool flatOnLeft,
  53782. const bool flatOnRight,
  53783. const bool flatOnTop,
  53784. const bool flatOnBottom) throw()
  53785. {
  53786. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53787. return;
  53788. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53789. Path outline;
  53790. createRoundedPath (outline, x, y, w, h, cs,
  53791. ! (flatOnLeft || flatOnTop),
  53792. ! (flatOnRight || flatOnTop),
  53793. ! (flatOnLeft || flatOnBottom),
  53794. ! (flatOnRight || flatOnBottom));
  53795. ColourGradient cg (baseColour, 0.0f, y,
  53796. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53797. false);
  53798. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53799. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53800. g.setGradientFill (cg);
  53801. g.fillPath (outline);
  53802. g.setColour (Colour (0x80000000));
  53803. g.strokePath (outline, PathStrokeType (strokeWidth));
  53804. }
  53805. void LookAndFeel::drawGlassSphere (Graphics& g,
  53806. const float x, const float y,
  53807. const float diameter,
  53808. const Colour& colour,
  53809. const float outlineThickness) throw()
  53810. {
  53811. if (diameter <= outlineThickness)
  53812. return;
  53813. Path p;
  53814. p.addEllipse (x, y, diameter, diameter);
  53815. {
  53816. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53817. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53818. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53819. g.setGradientFill (cg);
  53820. g.fillPath (p);
  53821. }
  53822. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53823. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53824. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53825. ColourGradient cg (Colours::transparentBlack,
  53826. x + diameter * 0.5f, y + diameter * 0.5f,
  53827. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53828. x, y + diameter * 0.5f, true);
  53829. cg.addColour (0.7, Colours::transparentBlack);
  53830. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53831. g.setGradientFill (cg);
  53832. g.fillPath (p);
  53833. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53834. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53835. }
  53836. void LookAndFeel::drawGlassPointer (Graphics& g,
  53837. const float x, const float y,
  53838. const float diameter,
  53839. const Colour& colour, const float outlineThickness,
  53840. const int direction) throw()
  53841. {
  53842. if (diameter <= outlineThickness)
  53843. return;
  53844. Path p;
  53845. p.startNewSubPath (x + diameter * 0.5f, y);
  53846. p.lineTo (x + diameter, y + diameter * 0.6f);
  53847. p.lineTo (x + diameter, y + diameter);
  53848. p.lineTo (x, y + diameter);
  53849. p.lineTo (x, y + diameter * 0.6f);
  53850. p.closeSubPath();
  53851. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53852. {
  53853. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53854. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53855. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53856. g.setGradientFill (cg);
  53857. g.fillPath (p);
  53858. }
  53859. ColourGradient cg (Colours::transparentBlack,
  53860. x + diameter * 0.5f, y + diameter * 0.5f,
  53861. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53862. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53863. cg.addColour (0.5, Colours::transparentBlack);
  53864. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53865. g.setGradientFill (cg);
  53866. g.fillPath (p);
  53867. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53868. g.strokePath (p, PathStrokeType (outlineThickness));
  53869. }
  53870. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53871. const float x, const float y,
  53872. const float width, const float height,
  53873. const Colour& colour,
  53874. const float outlineThickness,
  53875. const float cornerSize,
  53876. const bool flatOnLeft,
  53877. const bool flatOnRight,
  53878. const bool flatOnTop,
  53879. const bool flatOnBottom) throw()
  53880. {
  53881. if (width <= outlineThickness || height <= outlineThickness)
  53882. return;
  53883. const int intX = (int) x;
  53884. const int intY = (int) y;
  53885. const int intW = (int) width;
  53886. const int intH = (int) height;
  53887. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53888. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53889. const int intEdge = (int) edgeBlurRadius;
  53890. Path outline;
  53891. createRoundedPath (outline, x, y, width, height, cs,
  53892. ! (flatOnLeft || flatOnTop),
  53893. ! (flatOnRight || flatOnTop),
  53894. ! (flatOnLeft || flatOnBottom),
  53895. ! (flatOnRight || flatOnBottom));
  53896. {
  53897. ColourGradient cg (colour.darker (0.2f), 0, y,
  53898. colour.darker (0.2f), 0, y + height, false);
  53899. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53900. cg.addColour (0.4, colour);
  53901. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53902. g.setGradientFill (cg);
  53903. g.fillPath (outline);
  53904. }
  53905. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53906. colour.darker (0.2f), x, y + height * 0.5f, true);
  53907. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53908. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53909. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53910. {
  53911. g.saveState();
  53912. g.setGradientFill (cg);
  53913. g.reduceClipRegion (intX, intY, intEdge, intH);
  53914. g.fillPath (outline);
  53915. g.restoreState();
  53916. }
  53917. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53918. {
  53919. cg.x1 = x + width - edgeBlurRadius;
  53920. cg.x2 = x + width;
  53921. g.saveState();
  53922. g.setGradientFill (cg);
  53923. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53924. g.fillPath (outline);
  53925. g.restoreState();
  53926. }
  53927. {
  53928. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53929. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53930. Path highlight;
  53931. createRoundedPath (highlight,
  53932. x + leftIndent,
  53933. y + cs * 0.1f,
  53934. width - (leftIndent + rightIndent),
  53935. height * 0.4f, cs * 0.4f,
  53936. ! (flatOnLeft || flatOnTop),
  53937. ! (flatOnRight || flatOnTop),
  53938. ! (flatOnLeft || flatOnBottom),
  53939. ! (flatOnRight || flatOnBottom));
  53940. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53941. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53942. g.fillPath (highlight);
  53943. }
  53944. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53945. g.strokePath (outline, PathStrokeType (outlineThickness));
  53946. }
  53947. END_JUCE_NAMESPACE
  53948. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53949. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53950. BEGIN_JUCE_NAMESPACE
  53951. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53952. {
  53953. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53954. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53955. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53956. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53957. setColour (Slider::thumbColourId, Colours::white);
  53958. setColour (Slider::trackColourId, Colour (0x7f000000));
  53959. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53960. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53961. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53962. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53963. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53964. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53965. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53966. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53967. }
  53968. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53969. {
  53970. }
  53971. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53972. Button& button,
  53973. const Colour& backgroundColour,
  53974. bool isMouseOverButton,
  53975. bool isButtonDown)
  53976. {
  53977. const int width = button.getWidth();
  53978. const int height = button.getHeight();
  53979. const float indent = 2.0f;
  53980. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53981. roundToInt (height * 0.4f));
  53982. Path p;
  53983. p.addRoundedRectangle (indent, indent,
  53984. width - indent * 2.0f,
  53985. height - indent * 2.0f,
  53986. (float) cornerSize);
  53987. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53988. if (isMouseOverButton)
  53989. {
  53990. if (isButtonDown)
  53991. bc = bc.brighter();
  53992. else if (bc.getBrightness() > 0.5f)
  53993. bc = bc.darker (0.1f);
  53994. else
  53995. bc = bc.brighter (0.1f);
  53996. }
  53997. g.setColour (bc);
  53998. g.fillPath (p);
  53999. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  54000. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  54001. }
  54002. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  54003. Component& /*component*/,
  54004. float x, float y, float w, float h,
  54005. const bool ticked,
  54006. const bool isEnabled,
  54007. const bool /*isMouseOverButton*/,
  54008. const bool isButtonDown)
  54009. {
  54010. Path box;
  54011. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  54012. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  54013. : Colours::lightgrey.withAlpha (0.1f));
  54014. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  54015. g.fillPath (box, trans);
  54016. g.setColour (Colours::black.withAlpha (0.6f));
  54017. g.strokePath (box, PathStrokeType (0.9f), trans);
  54018. if (ticked)
  54019. {
  54020. Path tick;
  54021. tick.startNewSubPath (1.5f, 3.0f);
  54022. tick.lineTo (3.0f, 6.0f);
  54023. tick.lineTo (6.0f, 0.0f);
  54024. g.setColour (isEnabled ? Colours::black : Colours::grey);
  54025. g.strokePath (tick, PathStrokeType (2.5f), trans);
  54026. }
  54027. }
  54028. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  54029. ToggleButton& button,
  54030. bool isMouseOverButton,
  54031. bool isButtonDown)
  54032. {
  54033. if (button.hasKeyboardFocus (true))
  54034. {
  54035. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  54036. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  54037. }
  54038. const int tickWidth = jmin (20, button.getHeight() - 4);
  54039. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  54040. (float) tickWidth, (float) tickWidth,
  54041. button.getToggleState(),
  54042. button.isEnabled(),
  54043. isMouseOverButton,
  54044. isButtonDown);
  54045. g.setColour (button.findColour (ToggleButton::textColourId));
  54046. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  54047. if (! button.isEnabled())
  54048. g.setOpacity (0.5f);
  54049. const int textX = tickWidth + 5;
  54050. g.drawFittedText (button.getButtonText(),
  54051. textX, 4,
  54052. button.getWidth() - textX - 2, button.getHeight() - 8,
  54053. Justification::centredLeft, 10);
  54054. }
  54055. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  54056. int width, int height,
  54057. double progress, const String& textToShow)
  54058. {
  54059. if (progress < 0 || progress >= 1.0)
  54060. {
  54061. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  54062. }
  54063. else
  54064. {
  54065. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  54066. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  54067. g.fillAll (background);
  54068. g.setColour (foreground);
  54069. g.fillRect (1, 1,
  54070. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  54071. height - 2);
  54072. if (textToShow.isNotEmpty())
  54073. {
  54074. g.setColour (Colour::contrasting (background, foreground));
  54075. g.setFont (height * 0.6f);
  54076. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  54077. }
  54078. }
  54079. }
  54080. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  54081. ScrollBar& bar,
  54082. int width, int height,
  54083. int buttonDirection,
  54084. bool isScrollbarVertical,
  54085. bool isMouseOverButton,
  54086. bool isButtonDown)
  54087. {
  54088. if (isScrollbarVertical)
  54089. width -= 2;
  54090. else
  54091. height -= 2;
  54092. Path p;
  54093. if (buttonDirection == 0)
  54094. p.addTriangle (width * 0.5f, height * 0.2f,
  54095. width * 0.1f, height * 0.7f,
  54096. width * 0.9f, height * 0.7f);
  54097. else if (buttonDirection == 1)
  54098. p.addTriangle (width * 0.8f, height * 0.5f,
  54099. width * 0.3f, height * 0.1f,
  54100. width * 0.3f, height * 0.9f);
  54101. else if (buttonDirection == 2)
  54102. p.addTriangle (width * 0.5f, height * 0.8f,
  54103. width * 0.1f, height * 0.3f,
  54104. width * 0.9f, height * 0.3f);
  54105. else if (buttonDirection == 3)
  54106. p.addTriangle (width * 0.2f, height * 0.5f,
  54107. width * 0.7f, height * 0.1f,
  54108. width * 0.7f, height * 0.9f);
  54109. if (isButtonDown)
  54110. g.setColour (Colours::white);
  54111. else if (isMouseOverButton)
  54112. g.setColour (Colours::white.withAlpha (0.7f));
  54113. else
  54114. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  54115. g.fillPath (p);
  54116. g.setColour (Colours::black.withAlpha (0.5f));
  54117. g.strokePath (p, PathStrokeType (0.5f));
  54118. }
  54119. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  54120. ScrollBar& bar,
  54121. int x, int y,
  54122. int width, int height,
  54123. bool isScrollbarVertical,
  54124. int thumbStartPosition,
  54125. int thumbSize,
  54126. bool isMouseOver,
  54127. bool isMouseDown)
  54128. {
  54129. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  54130. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54131. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  54132. if (thumbSize > 0.0f)
  54133. {
  54134. Rectangle<int> thumb;
  54135. if (isScrollbarVertical)
  54136. {
  54137. width -= 2;
  54138. g.fillRect (x + roundToInt (width * 0.35f), y,
  54139. roundToInt (width * 0.3f), height);
  54140. thumb.setBounds (x + 1, thumbStartPosition,
  54141. width - 2, thumbSize);
  54142. }
  54143. else
  54144. {
  54145. height -= 2;
  54146. g.fillRect (x, y + roundToInt (height * 0.35f),
  54147. width, roundToInt (height * 0.3f));
  54148. thumb.setBounds (thumbStartPosition, y + 1,
  54149. thumbSize, height - 2);
  54150. }
  54151. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54152. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  54153. g.fillRect (thumb);
  54154. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  54155. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  54156. if (thumbSize > 16)
  54157. {
  54158. for (int i = 3; --i >= 0;)
  54159. {
  54160. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  54161. g.setColour (Colours::black.withAlpha (0.15f));
  54162. if (isScrollbarVertical)
  54163. {
  54164. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  54165. g.setColour (Colours::white.withAlpha (0.15f));
  54166. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  54167. }
  54168. else
  54169. {
  54170. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  54171. g.setColour (Colours::white.withAlpha (0.15f));
  54172. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  54173. }
  54174. }
  54175. }
  54176. }
  54177. }
  54178. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  54179. {
  54180. return &scrollbarShadow;
  54181. }
  54182. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  54183. {
  54184. g.fillAll (findColour (PopupMenu::backgroundColourId));
  54185. g.setColour (Colours::black.withAlpha (0.6f));
  54186. g.drawRect (0, 0, width, height);
  54187. }
  54188. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  54189. bool, MenuBarComponent& menuBar)
  54190. {
  54191. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  54192. }
  54193. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  54194. {
  54195. if (textEditor.isEnabled())
  54196. {
  54197. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  54198. g.drawRect (0, 0, width, height);
  54199. }
  54200. }
  54201. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  54202. const bool isButtonDown,
  54203. int buttonX, int buttonY,
  54204. int buttonW, int buttonH,
  54205. ComboBox& box)
  54206. {
  54207. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  54208. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  54209. : ComboBox::backgroundColourId));
  54210. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  54211. g.setColour (box.findColour (ComboBox::outlineColourId));
  54212. g.drawRect (0, 0, width, height);
  54213. const float arrowX = 0.2f;
  54214. const float arrowH = 0.3f;
  54215. if (box.isEnabled())
  54216. {
  54217. Path p;
  54218. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  54219. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  54220. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  54221. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  54222. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  54223. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  54224. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  54225. : ComboBox::buttonColourId));
  54226. g.fillPath (p);
  54227. }
  54228. }
  54229. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  54230. {
  54231. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  54232. f.setHorizontalScale (0.9f);
  54233. return f;
  54234. }
  54235. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  54236. {
  54237. Path p;
  54238. p.addTriangle (x1, y1, x2, y2, x3, y3);
  54239. g.setColour (fill);
  54240. g.fillPath (p);
  54241. g.setColour (outline);
  54242. g.strokePath (p, PathStrokeType (0.3f));
  54243. }
  54244. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  54245. int x, int y,
  54246. int w, int h,
  54247. float sliderPos,
  54248. float minSliderPos,
  54249. float maxSliderPos,
  54250. const Slider::SliderStyle style,
  54251. Slider& slider)
  54252. {
  54253. g.fillAll (slider.findColour (Slider::backgroundColourId));
  54254. if (style == Slider::LinearBar)
  54255. {
  54256. g.setColour (slider.findColour (Slider::thumbColourId));
  54257. g.fillRect (x, y, (int) sliderPos - x, h);
  54258. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  54259. g.drawRect (x, y, (int) sliderPos - x, h);
  54260. }
  54261. else
  54262. {
  54263. g.setColour (slider.findColour (Slider::trackColourId)
  54264. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  54265. if (slider.isHorizontal())
  54266. {
  54267. g.fillRect (x, y + roundToInt (h * 0.6f),
  54268. w, roundToInt (h * 0.2f));
  54269. }
  54270. else
  54271. {
  54272. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  54273. jmin (4, roundToInt (w * 0.2f)), h);
  54274. }
  54275. float alpha = 0.35f;
  54276. if (slider.isEnabled())
  54277. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  54278. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  54279. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  54280. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  54281. {
  54282. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  54283. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  54284. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  54285. fill, outline);
  54286. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  54287. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  54288. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  54289. fill, outline);
  54290. }
  54291. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  54292. {
  54293. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54294. minSliderPos - 7.0f, y + h * 0.9f ,
  54295. minSliderPos, y + h * 0.9f,
  54296. fill, outline);
  54297. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54298. maxSliderPos, y + h * 0.9f,
  54299. maxSliderPos + 7.0f, y + h * 0.9f,
  54300. fill, outline);
  54301. }
  54302. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  54303. {
  54304. drawTriangle (g, sliderPos, y + h * 0.9f,
  54305. sliderPos - 7.0f, y + h * 0.2f,
  54306. sliderPos + 7.0f, y + h * 0.2f,
  54307. fill, outline);
  54308. }
  54309. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  54310. {
  54311. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  54312. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  54313. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  54314. fill, outline);
  54315. }
  54316. }
  54317. }
  54318. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  54319. {
  54320. if (isIncrement)
  54321. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  54322. else
  54323. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  54324. }
  54325. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  54326. {
  54327. return &scrollbarShadow;
  54328. }
  54329. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  54330. {
  54331. return 8;
  54332. }
  54333. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  54334. int w, int h,
  54335. bool isMouseOver,
  54336. bool isMouseDragging)
  54337. {
  54338. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  54339. : Colours::darkgrey);
  54340. const float lineThickness = jmin (w, h) * 0.1f;
  54341. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  54342. {
  54343. g.drawLine (w * i,
  54344. h + 1.0f,
  54345. w + 1.0f,
  54346. h * i,
  54347. lineThickness);
  54348. }
  54349. }
  54350. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  54351. {
  54352. Path shape;
  54353. if (buttonType == DocumentWindow::closeButton)
  54354. {
  54355. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  54356. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  54357. ShapeButton* const b = new ShapeButton ("close",
  54358. Colour (0x7fff3333),
  54359. Colour (0xd7ff3333),
  54360. Colour (0xf7ff3333));
  54361. b->setShape (shape, true, true, true);
  54362. return b;
  54363. }
  54364. else if (buttonType == DocumentWindow::minimiseButton)
  54365. {
  54366. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54367. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  54368. DrawablePath dp;
  54369. dp.setPath (shape);
  54370. dp.setFill (Colours::black.withAlpha (0.3f));
  54371. b->setImages (&dp);
  54372. return b;
  54373. }
  54374. else if (buttonType == DocumentWindow::maximiseButton)
  54375. {
  54376. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  54377. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54378. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  54379. DrawablePath dp;
  54380. dp.setPath (shape);
  54381. dp.setFill (Colours::black.withAlpha (0.3f));
  54382. b->setImages (&dp);
  54383. return b;
  54384. }
  54385. jassertfalse
  54386. return 0;
  54387. }
  54388. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  54389. int titleBarX,
  54390. int titleBarY,
  54391. int titleBarW,
  54392. int titleBarH,
  54393. Button* minimiseButton,
  54394. Button* maximiseButton,
  54395. Button* closeButton,
  54396. bool positionTitleBarButtonsOnLeft)
  54397. {
  54398. titleBarY += titleBarH / 8;
  54399. titleBarH -= titleBarH / 4;
  54400. const int buttonW = titleBarH;
  54401. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  54402. : titleBarX + titleBarW - buttonW - 4;
  54403. if (closeButton != 0)
  54404. {
  54405. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  54406. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  54407. : -(buttonW + buttonW / 5);
  54408. }
  54409. if (positionTitleBarButtonsOnLeft)
  54410. swapVariables (minimiseButton, maximiseButton);
  54411. if (maximiseButton != 0)
  54412. {
  54413. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54414. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  54415. }
  54416. if (minimiseButton != 0)
  54417. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54418. }
  54419. END_JUCE_NAMESPACE
  54420. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54421. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  54422. BEGIN_JUCE_NAMESPACE
  54423. class DummyMenuComponent : public Component
  54424. {
  54425. DummyMenuComponent (const DummyMenuComponent&);
  54426. DummyMenuComponent& operator= (const DummyMenuComponent&);
  54427. public:
  54428. DummyMenuComponent() {}
  54429. ~DummyMenuComponent() {}
  54430. void inputAttemptWhenModal()
  54431. {
  54432. exitModalState (0);
  54433. }
  54434. };
  54435. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54436. : model (0),
  54437. itemUnderMouse (-1),
  54438. currentPopupIndex (-1),
  54439. indexToShowAgain (-1),
  54440. lastMouseX (0),
  54441. lastMouseY (0),
  54442. inModalState (false)
  54443. {
  54444. setRepaintsOnMouseActivity (true);
  54445. setWantsKeyboardFocus (false);
  54446. setMouseClickGrabsKeyboardFocus (false);
  54447. setModel (model_);
  54448. }
  54449. MenuBarComponent::~MenuBarComponent()
  54450. {
  54451. setModel (0);
  54452. Desktop::getInstance().removeGlobalMouseListener (this);
  54453. currentPopup = 0;
  54454. }
  54455. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54456. {
  54457. if (model != newModel)
  54458. {
  54459. if (model != 0)
  54460. model->removeListener (this);
  54461. model = newModel;
  54462. if (model != 0)
  54463. model->addListener (this);
  54464. repaint();
  54465. menuBarItemsChanged (0);
  54466. }
  54467. }
  54468. void MenuBarComponent::paint (Graphics& g)
  54469. {
  54470. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54471. getLookAndFeel().drawMenuBarBackground (g,
  54472. getWidth(),
  54473. getHeight(),
  54474. isMouseOverBar,
  54475. *this);
  54476. if (model != 0)
  54477. {
  54478. for (int i = 0; i < menuNames.size(); ++i)
  54479. {
  54480. g.saveState();
  54481. g.setOrigin (xPositions [i], 0);
  54482. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54483. getLookAndFeel().drawMenuBarItem (g,
  54484. xPositions[i + 1] - xPositions[i],
  54485. getHeight(),
  54486. i,
  54487. menuNames[i],
  54488. i == itemUnderMouse,
  54489. i == currentPopupIndex,
  54490. isMouseOverBar,
  54491. *this);
  54492. g.restoreState();
  54493. }
  54494. }
  54495. }
  54496. void MenuBarComponent::resized()
  54497. {
  54498. xPositions.clear();
  54499. int x = 2;
  54500. xPositions.add (x);
  54501. for (int i = 0; i < menuNames.size(); ++i)
  54502. {
  54503. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54504. xPositions.add (x);
  54505. }
  54506. }
  54507. int MenuBarComponent::getItemAt (const int x, const int y)
  54508. {
  54509. for (int i = 0; i < xPositions.size(); ++i)
  54510. if (x >= xPositions[i] && x < xPositions[i + 1])
  54511. return reallyContains (x, y, true) ? i : -1;
  54512. return -1;
  54513. }
  54514. void MenuBarComponent::repaintMenuItem (int index)
  54515. {
  54516. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54517. {
  54518. const int x1 = xPositions [index];
  54519. const int x2 = xPositions [index + 1];
  54520. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54521. }
  54522. }
  54523. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54524. {
  54525. const int newItem = getItemAt (x, y);
  54526. if (itemUnderMouse != newItem)
  54527. {
  54528. repaintMenuItem (itemUnderMouse);
  54529. itemUnderMouse = newItem;
  54530. repaintMenuItem (itemUnderMouse);
  54531. }
  54532. }
  54533. void MenuBarComponent::hideCurrentMenu()
  54534. {
  54535. currentPopup = 0;
  54536. repaint();
  54537. }
  54538. void MenuBarComponent::showMenu (int index)
  54539. {
  54540. if (index != currentPopupIndex)
  54541. {
  54542. if (inModalState)
  54543. {
  54544. hideCurrentMenu();
  54545. indexToShowAgain = index;
  54546. return;
  54547. }
  54548. indexToShowAgain = -1;
  54549. currentPopupIndex = -1;
  54550. itemUnderMouse = index;
  54551. currentPopup = 0;
  54552. menuBarItemsChanged (0);
  54553. Component* const prevFocused = getCurrentlyFocusedComponent();
  54554. ScopedPointer <ComponentDeletionWatcher> prevCompDeletionChecker;
  54555. if (prevFocused != 0)
  54556. prevCompDeletionChecker = new ComponentDeletionWatcher (prevFocused);
  54557. ComponentDeletionWatcher deletionChecker (this);
  54558. enterModalState (false);
  54559. inModalState = true;
  54560. int result = 0;
  54561. ApplicationCommandManager* managerOfChosenCommand = 0;
  54562. Desktop::getInstance().addGlobalMouseListener (this);
  54563. for (;;)
  54564. {
  54565. const int x = getScreenX() + xPositions [itemUnderMouse];
  54566. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54567. currentPopupIndex = itemUnderMouse;
  54568. indexToShowAgain = -1;
  54569. repaint();
  54570. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54571. {
  54572. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54573. menuNames [itemUnderMouse]));
  54574. if (m.lookAndFeel == 0)
  54575. m.setLookAndFeel (&getLookAndFeel());
  54576. currentPopup = m.createMenuComponent (x, getScreenY(),
  54577. w, getHeight(),
  54578. 0, w, 0, 0,
  54579. true, this,
  54580. &managerOfChosenCommand,
  54581. this);
  54582. }
  54583. if (currentPopup == 0)
  54584. {
  54585. currentPopup = new DummyMenuComponent();
  54586. addAndMakeVisible (currentPopup);
  54587. }
  54588. currentPopup->enterModalState (false);
  54589. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54590. // be stuck behind other comps that are already modal..
  54591. result = currentPopup->runModalLoop();
  54592. if (deletionChecker.hasBeenDeleted())
  54593. return;
  54594. const int lastPopupIndex = currentPopupIndex;
  54595. currentPopup = 0;
  54596. currentPopupIndex = -1;
  54597. if (result != 0)
  54598. {
  54599. topLevelIndexClicked = lastPopupIndex;
  54600. break;
  54601. }
  54602. else if (indexToShowAgain >= 0)
  54603. {
  54604. menuBarItemsChanged (0);
  54605. repaint();
  54606. itemUnderMouse = indexToShowAgain;
  54607. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54608. break;
  54609. }
  54610. else
  54611. {
  54612. break;
  54613. }
  54614. }
  54615. Desktop::getInstance().removeGlobalMouseListener (this);
  54616. inModalState = false;
  54617. exitModalState (0);
  54618. if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted())
  54619. prevFocused->grabKeyboardFocus();
  54620. const Point<int> mousePos (getMouseXYRelative());
  54621. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54622. repaint();
  54623. if (result != 0)
  54624. {
  54625. if (managerOfChosenCommand != 0)
  54626. {
  54627. ApplicationCommandTarget::InvocationInfo info (result);
  54628. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54629. managerOfChosenCommand->invoke (info, true);
  54630. }
  54631. postCommandMessage (result);
  54632. }
  54633. }
  54634. }
  54635. void MenuBarComponent::handleCommandMessage (int commandId)
  54636. {
  54637. if (model != 0)
  54638. model->menuItemSelected (commandId, topLevelIndexClicked);
  54639. }
  54640. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54641. {
  54642. if (e.eventComponent == this)
  54643. updateItemUnderMouse (e.x, e.y);
  54644. }
  54645. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54646. {
  54647. if (e.eventComponent == this)
  54648. updateItemUnderMouse (e.x, e.y);
  54649. }
  54650. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54651. {
  54652. if (currentPopupIndex < 0)
  54653. {
  54654. const MouseEvent e2 (e.getEventRelativeTo (this));
  54655. updateItemUnderMouse (e2.x, e2.y);
  54656. currentPopupIndex = -2;
  54657. showMenu (itemUnderMouse);
  54658. }
  54659. }
  54660. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54661. {
  54662. const MouseEvent e2 (e.getEventRelativeTo (this));
  54663. const int item = getItemAt (e2.x, e2.y);
  54664. if (item >= 0)
  54665. showMenu (item);
  54666. }
  54667. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54668. {
  54669. const MouseEvent e2 (e.getEventRelativeTo (this));
  54670. updateItemUnderMouse (e2.x, e2.y);
  54671. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54672. hideCurrentMenu();
  54673. }
  54674. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54675. {
  54676. const MouseEvent e2 (e.getEventRelativeTo (this));
  54677. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54678. {
  54679. if (currentPopupIndex >= 0)
  54680. {
  54681. const int item = getItemAt (e2.x, e2.y);
  54682. if (item >= 0)
  54683. showMenu (item);
  54684. }
  54685. else
  54686. {
  54687. updateItemUnderMouse (e2.x, e2.y);
  54688. }
  54689. lastMouseX = e2.x;
  54690. lastMouseY = e2.y;
  54691. }
  54692. }
  54693. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54694. {
  54695. bool used = false;
  54696. const int numMenus = menuNames.size();
  54697. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54698. if (key.isKeyCode (KeyPress::leftKey))
  54699. {
  54700. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54701. used = true;
  54702. }
  54703. else if (key.isKeyCode (KeyPress::rightKey))
  54704. {
  54705. showMenu ((currentIndex + 1) % numMenus);
  54706. used = true;
  54707. }
  54708. return used;
  54709. }
  54710. void MenuBarComponent::inputAttemptWhenModal()
  54711. {
  54712. hideCurrentMenu();
  54713. }
  54714. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54715. {
  54716. StringArray newNames;
  54717. if (model != 0)
  54718. newNames = model->getMenuBarNames();
  54719. if (newNames != menuNames)
  54720. {
  54721. menuNames = newNames;
  54722. repaint();
  54723. resized();
  54724. }
  54725. }
  54726. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54727. const ApplicationCommandTarget::InvocationInfo& info)
  54728. {
  54729. if (model == 0
  54730. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54731. return;
  54732. for (int i = 0; i < menuNames.size(); ++i)
  54733. {
  54734. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54735. if (menu.containsCommandItem (info.commandID))
  54736. {
  54737. itemUnderMouse = i;
  54738. repaintMenuItem (i);
  54739. startTimer (200);
  54740. break;
  54741. }
  54742. }
  54743. }
  54744. void MenuBarComponent::timerCallback()
  54745. {
  54746. stopTimer();
  54747. const Point<int> mousePos (getMouseXYRelative());
  54748. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54749. }
  54750. END_JUCE_NAMESPACE
  54751. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54752. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54753. BEGIN_JUCE_NAMESPACE
  54754. MenuBarModel::MenuBarModel() throw()
  54755. : manager (0)
  54756. {
  54757. }
  54758. MenuBarModel::~MenuBarModel()
  54759. {
  54760. setApplicationCommandManagerToWatch (0);
  54761. }
  54762. void MenuBarModel::menuItemsChanged()
  54763. {
  54764. triggerAsyncUpdate();
  54765. }
  54766. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54767. {
  54768. if (manager != newManager)
  54769. {
  54770. if (manager != 0)
  54771. manager->removeListener (this);
  54772. manager = newManager;
  54773. if (manager != 0)
  54774. manager->addListener (this);
  54775. }
  54776. }
  54777. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54778. {
  54779. jassert (newListener != 0);
  54780. jassert (! listeners.contains (newListener)); // trying to add a listener to the list twice!
  54781. if (newListener != 0)
  54782. listeners.add (newListener);
  54783. }
  54784. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54785. {
  54786. // Trying to remove a listener that isn't on the list!
  54787. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54788. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54789. jassert (listeners.contains (listenerToRemove));
  54790. listeners.removeValue (listenerToRemove);
  54791. }
  54792. void MenuBarModel::handleAsyncUpdate()
  54793. {
  54794. for (int i = listeners.size(); --i >= 0;)
  54795. {
  54796. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuBarItemsChanged (this);
  54797. i = jmin (i, listeners.size());
  54798. }
  54799. }
  54800. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54801. {
  54802. for (int i = listeners.size(); --i >= 0;)
  54803. {
  54804. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuCommandInvoked (this, info);
  54805. i = jmin (i, listeners.size());
  54806. }
  54807. }
  54808. void MenuBarModel::applicationCommandListChanged()
  54809. {
  54810. menuItemsChanged();
  54811. }
  54812. END_JUCE_NAMESPACE
  54813. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54814. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54815. BEGIN_JUCE_NAMESPACE
  54816. class PopupMenu::Item
  54817. {
  54818. public:
  54819. Item()
  54820. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54821. usesColour (false), customComp (0), commandManager (0)
  54822. {
  54823. }
  54824. Item (const int itemId_,
  54825. const String& text_,
  54826. const bool active_,
  54827. const bool isTicked_,
  54828. const Image* im,
  54829. const Colour& textColour_,
  54830. const bool usesColour_,
  54831. PopupMenuCustomComponent* const customComp_,
  54832. const PopupMenu* const subMenu_,
  54833. ApplicationCommandManager* const commandManager_)
  54834. : itemId (itemId_), text (text_), textColour (textColour_),
  54835. active (active_), isSeparator (false), isTicked (isTicked_),
  54836. usesColour (usesColour_), customComp (customComp_),
  54837. commandManager (commandManager_)
  54838. {
  54839. if (subMenu_ != 0)
  54840. subMenu = new PopupMenu (*subMenu_);
  54841. if (im != 0)
  54842. image = im->createCopy();
  54843. if (commandManager_ != 0 && itemId_ != 0)
  54844. {
  54845. String shortcutKey;
  54846. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54847. ->getKeyPressesAssignedToCommand (itemId_));
  54848. for (int i = 0; i < keyPresses.size(); ++i)
  54849. {
  54850. const String key (keyPresses.getReference(i).getTextDescription());
  54851. if (shortcutKey.isNotEmpty())
  54852. shortcutKey << ", ";
  54853. if (key.length() == 1)
  54854. shortcutKey << "shortcut: '" << key << '\'';
  54855. else
  54856. shortcutKey << key;
  54857. }
  54858. shortcutKey = shortcutKey.trim();
  54859. if (shortcutKey.isNotEmpty())
  54860. text << "<end>" << shortcutKey;
  54861. }
  54862. }
  54863. Item (const Item& other)
  54864. : itemId (other.itemId),
  54865. text (other.text),
  54866. textColour (other.textColour),
  54867. active (other.active),
  54868. isSeparator (other.isSeparator),
  54869. isTicked (other.isTicked),
  54870. usesColour (other.usesColour),
  54871. customComp (other.customComp),
  54872. commandManager (other.commandManager)
  54873. {
  54874. if (other.subMenu != 0)
  54875. subMenu = new PopupMenu (*(other.subMenu));
  54876. if (other.image != 0)
  54877. image = other.image->createCopy();
  54878. }
  54879. ~Item()
  54880. {
  54881. customComp = 0;
  54882. }
  54883. bool canBeTriggered() const throw()
  54884. {
  54885. return active && ! (isSeparator || (subMenu != 0));
  54886. }
  54887. bool hasActiveSubMenu() const throw()
  54888. {
  54889. return active && (subMenu != 0);
  54890. }
  54891. const int itemId;
  54892. String text;
  54893. const Colour textColour;
  54894. const bool active, isSeparator, isTicked, usesColour;
  54895. ScopedPointer <Image> image;
  54896. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54897. ScopedPointer <PopupMenu> subMenu;
  54898. ApplicationCommandManager* const commandManager;
  54899. juce_UseDebuggingNewOperator
  54900. private:
  54901. Item& operator= (const Item&);
  54902. };
  54903. class PopupMenu::ItemComponent : public Component
  54904. {
  54905. public:
  54906. ItemComponent (const PopupMenu::Item& itemInfo_)
  54907. : itemInfo (itemInfo_),
  54908. isHighlighted (false)
  54909. {
  54910. if (itemInfo.customComp != 0)
  54911. addAndMakeVisible (itemInfo.customComp);
  54912. }
  54913. ~ItemComponent()
  54914. {
  54915. if (itemInfo.customComp != 0)
  54916. removeChildComponent (itemInfo.customComp);
  54917. }
  54918. void getIdealSize (int& idealWidth,
  54919. int& idealHeight,
  54920. const int standardItemHeight)
  54921. {
  54922. if (itemInfo.customComp != 0)
  54923. {
  54924. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54925. }
  54926. else
  54927. {
  54928. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54929. itemInfo.isSeparator,
  54930. standardItemHeight,
  54931. idealWidth,
  54932. idealHeight);
  54933. }
  54934. }
  54935. void paint (Graphics& g)
  54936. {
  54937. if (itemInfo.customComp == 0)
  54938. {
  54939. String mainText (itemInfo.text);
  54940. String endText;
  54941. const int endIndex = mainText.indexOf (T("<end>"));
  54942. if (endIndex >= 0)
  54943. {
  54944. endText = mainText.substring (endIndex + 5).trim();
  54945. mainText = mainText.substring (0, endIndex);
  54946. }
  54947. getLookAndFeel()
  54948. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54949. itemInfo.isSeparator,
  54950. itemInfo.active,
  54951. isHighlighted,
  54952. itemInfo.isTicked,
  54953. itemInfo.subMenu != 0,
  54954. mainText, endText,
  54955. itemInfo.image,
  54956. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54957. }
  54958. }
  54959. void resized()
  54960. {
  54961. if (getNumChildComponents() > 0)
  54962. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54963. }
  54964. void setHighlighted (bool shouldBeHighlighted)
  54965. {
  54966. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54967. if (isHighlighted != shouldBeHighlighted)
  54968. {
  54969. isHighlighted = shouldBeHighlighted;
  54970. if (itemInfo.customComp != 0)
  54971. {
  54972. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54973. itemInfo.customComp->repaint();
  54974. }
  54975. repaint();
  54976. }
  54977. }
  54978. PopupMenu::Item itemInfo;
  54979. juce_UseDebuggingNewOperator
  54980. private:
  54981. bool isHighlighted;
  54982. ItemComponent (const ItemComponent&);
  54983. ItemComponent& operator= (const ItemComponent&);
  54984. };
  54985. namespace PopupMenuSettings
  54986. {
  54987. static const int scrollZone = 24;
  54988. static const int borderSize = 2;
  54989. static const int timerInterval = 50;
  54990. static const int dismissCommandId = 0x6287345f;
  54991. }
  54992. class PopupMenu::Window : public Component,
  54993. private Timer
  54994. {
  54995. public:
  54996. Window()
  54997. : Component (T("menu")),
  54998. owner (0),
  54999. currentChild (0),
  55000. activeSubMenu (0),
  55001. menuBarComponent (0),
  55002. managerOfChosenCommand (0),
  55003. componentAttachedTo (0),
  55004. minimumWidth (0),
  55005. maximumNumColumns (7),
  55006. standardItemHeight (0),
  55007. isOver (false),
  55008. hasBeenOver (false),
  55009. isDown (false),
  55010. needsToScroll (false),
  55011. hideOnExit (false),
  55012. disableMouseMoves (false),
  55013. hasAnyJuceCompHadFocus (false),
  55014. numColumns (0),
  55015. contentHeight (0),
  55016. childYOffset (0),
  55017. timeEnteredCurrentChildComp (0),
  55018. scrollAcceleration (1.0)
  55019. {
  55020. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  55021. setWantsKeyboardFocus (true);
  55022. setMouseClickGrabsKeyboardFocus (false);
  55023. setOpaque (true);
  55024. setAlwaysOnTop (true);
  55025. Desktop::getInstance().addGlobalMouseListener (this);
  55026. getActiveWindows().add (this);
  55027. }
  55028. ~Window()
  55029. {
  55030. getActiveWindows().removeValue (this);
  55031. Desktop::getInstance().removeGlobalMouseListener (this);
  55032. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55033. activeSubMenu = 0;
  55034. deleteAllChildren();
  55035. attachedCompWatcher = 0;
  55036. }
  55037. static Window* create (const PopupMenu& menu,
  55038. const bool dismissOnMouseUp,
  55039. Window* const owner_,
  55040. const int minX, const int maxX,
  55041. const int minY, const int maxY,
  55042. const int minimumWidth,
  55043. const int maximumNumColumns,
  55044. const int standardItemHeight,
  55045. const bool alignToRectangle,
  55046. const int itemIdThatMustBeVisible,
  55047. Component* const menuBarComponent,
  55048. ApplicationCommandManager** managerOfChosenCommand,
  55049. Component* const componentAttachedTo)
  55050. {
  55051. if (menu.items.size() > 0)
  55052. {
  55053. int totalItems = 0;
  55054. ScopedPointer <Window> mw (new Window());
  55055. mw->setLookAndFeel (menu.lookAndFeel);
  55056. mw->setWantsKeyboardFocus (false);
  55057. mw->minimumWidth = minimumWidth;
  55058. mw->maximumNumColumns = maximumNumColumns;
  55059. mw->standardItemHeight = standardItemHeight;
  55060. mw->dismissOnMouseUp = dismissOnMouseUp;
  55061. for (int i = 0; i < menu.items.size(); ++i)
  55062. {
  55063. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  55064. mw->addItem (*item);
  55065. ++totalItems;
  55066. }
  55067. if (totalItems > 0)
  55068. {
  55069. mw->owner = owner_;
  55070. mw->menuBarComponent = menuBarComponent;
  55071. mw->managerOfChosenCommand = managerOfChosenCommand;
  55072. mw->componentAttachedTo = componentAttachedTo;
  55073. mw->attachedCompWatcher = componentAttachedTo != 0 ? new ComponentDeletionWatcher (componentAttachedTo) : 0;
  55074. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  55075. mw->setTopLeftPosition (mw->windowPos.getX(),
  55076. mw->windowPos.getY());
  55077. mw->updateYPositions();
  55078. if (itemIdThatMustBeVisible != 0)
  55079. {
  55080. const int y = minY - mw->windowPos.getY();
  55081. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  55082. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  55083. }
  55084. mw->resizeToBestWindowPos();
  55085. mw->addToDesktop (ComponentPeer::windowIsTemporary
  55086. | mw->getLookAndFeel().getMenuWindowFlags());
  55087. return mw.release();
  55088. }
  55089. }
  55090. return 0;
  55091. }
  55092. void paint (Graphics& g)
  55093. {
  55094. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  55095. }
  55096. void paintOverChildren (Graphics& g)
  55097. {
  55098. if (isScrolling())
  55099. {
  55100. LookAndFeel& lf = getLookAndFeel();
  55101. if (isScrollZoneActive (false))
  55102. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  55103. if (isScrollZoneActive (true))
  55104. {
  55105. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  55106. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  55107. }
  55108. }
  55109. }
  55110. bool isScrollZoneActive (bool bottomOne) const
  55111. {
  55112. return isScrolling()
  55113. && (bottomOne
  55114. ? childYOffset < contentHeight - windowPos.getHeight()
  55115. : childYOffset > 0);
  55116. }
  55117. void addItem (const PopupMenu::Item& item)
  55118. {
  55119. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  55120. addAndMakeVisible (mic);
  55121. int itemW = 80;
  55122. int itemH = 16;
  55123. mic->getIdealSize (itemW, itemH, standardItemHeight);
  55124. mic->setSize (itemW, jlimit (2, 600, itemH));
  55125. mic->addMouseListener (this, false);
  55126. }
  55127. // hide this and all sub-comps
  55128. void hide (const PopupMenu::Item* const item)
  55129. {
  55130. if (isVisible())
  55131. {
  55132. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55133. activeSubMenu = 0;
  55134. currentChild = 0;
  55135. exitModalState (item != 0 ? item->itemId : 0);
  55136. setVisible (false);
  55137. if (item != 0
  55138. && item->commandManager != 0
  55139. && item->itemId != 0)
  55140. {
  55141. *managerOfChosenCommand = item->commandManager;
  55142. }
  55143. }
  55144. }
  55145. void dismissMenu (const PopupMenu::Item* const item)
  55146. {
  55147. if (owner != 0)
  55148. {
  55149. owner->dismissMenu (item);
  55150. }
  55151. else
  55152. {
  55153. if (item != 0)
  55154. {
  55155. // need a copy of this on the stack as the one passed in will get deleted during this call
  55156. const PopupMenu::Item mi (*item);
  55157. hide (&mi);
  55158. }
  55159. else
  55160. {
  55161. hide (0);
  55162. }
  55163. }
  55164. }
  55165. void mouseMove (const MouseEvent&)
  55166. {
  55167. timerCallback();
  55168. }
  55169. void mouseDown (const MouseEvent&)
  55170. {
  55171. timerCallback();
  55172. }
  55173. void mouseDrag (const MouseEvent&)
  55174. {
  55175. timerCallback();
  55176. }
  55177. void mouseUp (const MouseEvent&)
  55178. {
  55179. timerCallback();
  55180. }
  55181. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  55182. {
  55183. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  55184. lastMouse = Point<int> (-1, -1);
  55185. }
  55186. bool keyPressed (const KeyPress& key)
  55187. {
  55188. if (key.isKeyCode (KeyPress::downKey))
  55189. {
  55190. selectNextItem (1);
  55191. }
  55192. else if (key.isKeyCode (KeyPress::upKey))
  55193. {
  55194. selectNextItem (-1);
  55195. }
  55196. else if (key.isKeyCode (KeyPress::leftKey))
  55197. {
  55198. Window* parentWindow = owner;
  55199. if (parentWindow != 0)
  55200. {
  55201. PopupMenu::ItemComponent* currentChildOfParent
  55202. = (parentWindow != 0) ? parentWindow->currentChild : 0;
  55203. hide (0);
  55204. if (parentWindow->isValidComponent())
  55205. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  55206. disableTimerUntilMouseMoves();
  55207. }
  55208. else if (menuBarComponent != 0)
  55209. {
  55210. menuBarComponent->keyPressed (key);
  55211. }
  55212. }
  55213. else if (key.isKeyCode (KeyPress::rightKey))
  55214. {
  55215. disableTimerUntilMouseMoves();
  55216. if (showSubMenuFor (currentChild))
  55217. {
  55218. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55219. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  55220. activeSubMenu->selectNextItem (1);
  55221. }
  55222. else if (menuBarComponent != 0)
  55223. {
  55224. menuBarComponent->keyPressed (key);
  55225. }
  55226. }
  55227. else if (key.isKeyCode (KeyPress::returnKey))
  55228. {
  55229. triggerCurrentlyHighlightedItem();
  55230. }
  55231. else if (key.isKeyCode (KeyPress::escapeKey))
  55232. {
  55233. dismissMenu (0);
  55234. }
  55235. else
  55236. {
  55237. return false;
  55238. }
  55239. return true;
  55240. }
  55241. void inputAttemptWhenModal()
  55242. {
  55243. timerCallback();
  55244. if (! isOverAnyMenu())
  55245. {
  55246. if (componentAttachedTo != 0 && ! attachedCompWatcher->hasBeenDeleted())
  55247. {
  55248. // we want to dismiss the menu, but if we do it synchronously, then
  55249. // the mouse-click will be allowed to pass through. That's good, except
  55250. // when the user clicks on the button that orginally popped the menu up,
  55251. // as they'll expect the menu to go away, and in fact it'll just
  55252. // come back. So only dismiss synchronously if they're not on the original
  55253. // comp that we're attached to.
  55254. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  55255. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  55256. {
  55257. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  55258. return;
  55259. }
  55260. }
  55261. dismissMenu (0);
  55262. }
  55263. }
  55264. void handleCommandMessage (int commandId)
  55265. {
  55266. Component::handleCommandMessage (commandId);
  55267. if (commandId == PopupMenuSettings::dismissCommandId)
  55268. dismissMenu (0);
  55269. }
  55270. void timerCallback()
  55271. {
  55272. if (! isVisible())
  55273. return;
  55274. if (attachedCompWatcher != 0 && attachedCompWatcher->hasBeenDeleted())
  55275. {
  55276. dismissMenu (0);
  55277. return;
  55278. }
  55279. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  55280. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  55281. return;
  55282. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  55283. // move rather than a real timer callback
  55284. const Point<int> globalMousePos (Desktop::getMousePosition());
  55285. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  55286. const uint32 now = Time::getMillisecondCounter();
  55287. if (now > timeEnteredCurrentChildComp + 100
  55288. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  55289. && currentChild->isValidComponent()
  55290. && (! disableMouseMoves)
  55291. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  55292. {
  55293. showSubMenuFor (currentChild);
  55294. }
  55295. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  55296. {
  55297. highlightItemUnderMouse (globalMousePos, localMousePos);
  55298. }
  55299. bool overScrollArea = false;
  55300. if (isScrolling()
  55301. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  55302. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  55303. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  55304. {
  55305. if (now > lastScroll + 20)
  55306. {
  55307. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  55308. int amount = 0;
  55309. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  55310. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  55311. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  55312. lastScroll = now;
  55313. }
  55314. overScrollArea = true;
  55315. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  55316. }
  55317. else
  55318. {
  55319. scrollAcceleration = 1.0;
  55320. }
  55321. const bool wasDown = isDown;
  55322. bool isOverAny = isOverAnyMenu();
  55323. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  55324. {
  55325. activeSubMenu->updateMouseOverStatus (globalMousePos);
  55326. isOverAny = isOverAnyMenu();
  55327. }
  55328. if (hideOnExit && hasBeenOver && ! isOverAny)
  55329. {
  55330. hide (0);
  55331. }
  55332. else
  55333. {
  55334. isDown = hasBeenOver
  55335. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  55336. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  55337. bool anyFocused = Process::isForegroundProcess();
  55338. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  55339. {
  55340. // because no component at all may have focus, our test here will
  55341. // only be triggered when something has focus and then loses it.
  55342. anyFocused = ! hasAnyJuceCompHadFocus;
  55343. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  55344. {
  55345. if (ComponentPeer::getPeer (i)->isFocused())
  55346. {
  55347. anyFocused = true;
  55348. hasAnyJuceCompHadFocus = true;
  55349. break;
  55350. }
  55351. }
  55352. }
  55353. if (! anyFocused)
  55354. {
  55355. if (now > lastFocused + 10)
  55356. {
  55357. wasHiddenBecauseOfAppChange() = true;
  55358. dismissMenu (0);
  55359. return; // may have been deleted by the previous call..
  55360. }
  55361. }
  55362. else if (wasDown && now > menuCreationTime + 250
  55363. && ! (isDown || overScrollArea))
  55364. {
  55365. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55366. if (isOver)
  55367. {
  55368. triggerCurrentlyHighlightedItem();
  55369. }
  55370. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  55371. {
  55372. dismissMenu (0);
  55373. }
  55374. return; // may have been deleted by the previous calls..
  55375. }
  55376. else
  55377. {
  55378. lastFocused = now;
  55379. }
  55380. }
  55381. }
  55382. static Array<Window*>& getActiveWindows()
  55383. {
  55384. static Array<Window*> activeMenuWindows;
  55385. return activeMenuWindows;
  55386. }
  55387. static bool& wasHiddenBecauseOfAppChange() throw()
  55388. {
  55389. static bool b = false;
  55390. return b;
  55391. }
  55392. juce_UseDebuggingNewOperator
  55393. private:
  55394. Window* owner;
  55395. PopupMenu::ItemComponent* currentChild;
  55396. ScopedPointer <Window> activeSubMenu;
  55397. Component* menuBarComponent;
  55398. ApplicationCommandManager** managerOfChosenCommand;
  55399. Component* componentAttachedTo;
  55400. ScopedPointer <ComponentDeletionWatcher> attachedCompWatcher;
  55401. Rectangle<int> windowPos;
  55402. Point<int> lastMouse;
  55403. int minimumWidth, maximumNumColumns, standardItemHeight;
  55404. bool isOver, hasBeenOver, isDown, needsToScroll;
  55405. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  55406. int numColumns, contentHeight, childYOffset;
  55407. Array <int> columnWidths;
  55408. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  55409. double scrollAcceleration;
  55410. bool overlaps (const Rectangle<int>& r) const
  55411. {
  55412. return r.intersects (getBounds())
  55413. || (owner != 0 && owner->overlaps (r));
  55414. }
  55415. bool isOverAnyMenu() const
  55416. {
  55417. return (owner != 0) ? owner->isOverAnyMenu()
  55418. : isOverChildren();
  55419. }
  55420. bool isOverChildren() const
  55421. {
  55422. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55423. return isVisible()
  55424. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  55425. }
  55426. void updateMouseOverStatus (const Point<int>& globalMousePos)
  55427. {
  55428. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  55429. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  55430. if (activeSubMenu != 0)
  55431. activeSubMenu->updateMouseOverStatus (globalMousePos);
  55432. }
  55433. bool treeContains (const Window* const window) const throw()
  55434. {
  55435. const Window* mw = this;
  55436. while (mw->owner != 0)
  55437. mw = mw->owner;
  55438. while (mw != 0)
  55439. {
  55440. if (mw == window)
  55441. return true;
  55442. mw = mw->activeSubMenu;
  55443. }
  55444. return false;
  55445. }
  55446. void calculateWindowPos (const int minX, const int maxX,
  55447. const int minY, const int maxY,
  55448. const bool alignToRectangle)
  55449. {
  55450. const Rectangle<int> mon (Desktop::getInstance()
  55451. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  55452. (minY + maxY) / 2),
  55453. #if JUCE_MAC
  55454. true));
  55455. #else
  55456. false)); // on windows, don't stop the menu overlapping the taskbar
  55457. #endif
  55458. int x, y, widthToUse, heightToUse;
  55459. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55460. if (alignToRectangle)
  55461. {
  55462. x = minX;
  55463. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55464. const int spaceOver = minY - mon.getY();
  55465. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55466. y = maxY;
  55467. else
  55468. y = minY - heightToUse;
  55469. }
  55470. else
  55471. {
  55472. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55473. if (owner != 0)
  55474. {
  55475. if (owner->owner != 0)
  55476. {
  55477. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55478. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55479. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55480. tendTowardsRight = true;
  55481. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55482. tendTowardsRight = false;
  55483. }
  55484. else if (maxX + widthToUse < mon.getRight() - 32)
  55485. {
  55486. tendTowardsRight = true;
  55487. }
  55488. }
  55489. const int biggestSpace = jmax (mon.getRight() - maxX,
  55490. minX - mon.getX()) - 32;
  55491. if (biggestSpace < widthToUse)
  55492. {
  55493. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55494. if (numColumns > 1)
  55495. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55496. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55497. }
  55498. if (tendTowardsRight)
  55499. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55500. else
  55501. x = jmax (mon.getX() + 4, minX - widthToUse);
  55502. y = minY;
  55503. if ((minY + maxY) / 2 > mon.getCentreY())
  55504. y = jmax (mon.getY(), maxY - heightToUse);
  55505. }
  55506. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55507. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55508. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55509. // sets this flag if it's big enough to obscure any of its parent menus
  55510. hideOnExit = (owner != 0)
  55511. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55512. }
  55513. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55514. {
  55515. numColumns = 0;
  55516. contentHeight = 0;
  55517. const int maxMenuH = getParentHeight() - 24;
  55518. int totalW;
  55519. do
  55520. {
  55521. ++numColumns;
  55522. totalW = workOutBestSize (maxMenuW);
  55523. if (totalW > maxMenuW)
  55524. {
  55525. numColumns = jmax (1, numColumns - 1);
  55526. totalW = workOutBestSize (maxMenuW); // to update col widths
  55527. break;
  55528. }
  55529. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55530. {
  55531. break;
  55532. }
  55533. } while (numColumns < maximumNumColumns);
  55534. const int actualH = jmin (contentHeight, maxMenuH);
  55535. needsToScroll = contentHeight > actualH;
  55536. width = updateYPositions();
  55537. height = actualH + PopupMenuSettings::borderSize * 2;
  55538. }
  55539. int workOutBestSize (const int maxMenuW)
  55540. {
  55541. int totalW = 0;
  55542. contentHeight = 0;
  55543. int childNum = 0;
  55544. for (int col = 0; col < numColumns; ++col)
  55545. {
  55546. int i, colW = 50, colH = 0;
  55547. const int numChildren = jmin (getNumChildComponents() - childNum,
  55548. (getNumChildComponents() + numColumns - 1) / numColumns);
  55549. for (i = numChildren; --i >= 0;)
  55550. {
  55551. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55552. colH += getChildComponent (childNum + i)->getHeight();
  55553. }
  55554. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55555. columnWidths.set (col, colW);
  55556. totalW += colW;
  55557. contentHeight = jmax (contentHeight, colH);
  55558. childNum += numChildren;
  55559. }
  55560. if (totalW < minimumWidth)
  55561. {
  55562. totalW = minimumWidth;
  55563. for (int col = 0; col < numColumns; ++col)
  55564. columnWidths.set (0, totalW / numColumns);
  55565. }
  55566. return totalW;
  55567. }
  55568. void ensureItemIsVisible (const int itemId, int wantedY)
  55569. {
  55570. jassert (itemId != 0)
  55571. for (int i = getNumChildComponents(); --i >= 0;)
  55572. {
  55573. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55574. if (m != 0
  55575. && m->itemInfo.itemId == itemId
  55576. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55577. {
  55578. const int currentY = m->getY();
  55579. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55580. {
  55581. if (wantedY < 0)
  55582. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55583. jmax (PopupMenuSettings::scrollZone,
  55584. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55585. currentY);
  55586. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55587. int deltaY = wantedY - currentY;
  55588. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55589. jmin (windowPos.getHeight(), mon.getHeight()));
  55590. const int newY = jlimit (mon.getY(),
  55591. mon.getBottom() - windowPos.getHeight(),
  55592. windowPos.getY() + deltaY);
  55593. deltaY -= newY - windowPos.getY();
  55594. childYOffset -= deltaY;
  55595. windowPos.setPosition (windowPos.getX(), newY);
  55596. updateYPositions();
  55597. }
  55598. break;
  55599. }
  55600. }
  55601. }
  55602. void resizeToBestWindowPos()
  55603. {
  55604. Rectangle<int> r (windowPos);
  55605. if (childYOffset < 0)
  55606. {
  55607. r.setBounds (r.getX(), r.getY() - childYOffset,
  55608. r.getWidth(), r.getHeight() + childYOffset);
  55609. }
  55610. else if (childYOffset > 0)
  55611. {
  55612. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55613. if (spaceAtBottom > 0)
  55614. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55615. }
  55616. setBounds (r);
  55617. updateYPositions();
  55618. }
  55619. void alterChildYPos (const int delta)
  55620. {
  55621. if (isScrolling())
  55622. {
  55623. childYOffset += delta;
  55624. if (delta < 0)
  55625. {
  55626. childYOffset = jmax (childYOffset, 0);
  55627. }
  55628. else if (delta > 0)
  55629. {
  55630. childYOffset = jmin (childYOffset,
  55631. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55632. }
  55633. updateYPositions();
  55634. }
  55635. else
  55636. {
  55637. childYOffset = 0;
  55638. }
  55639. resizeToBestWindowPos();
  55640. repaint();
  55641. }
  55642. int updateYPositions()
  55643. {
  55644. int x = 0;
  55645. int childNum = 0;
  55646. for (int col = 0; col < numColumns; ++col)
  55647. {
  55648. const int numChildren = jmin (getNumChildComponents() - childNum,
  55649. (getNumChildComponents() + numColumns - 1) / numColumns);
  55650. const int colW = columnWidths [col];
  55651. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55652. for (int i = 0; i < numChildren; ++i)
  55653. {
  55654. Component* const c = getChildComponent (childNum + i);
  55655. c->setBounds (x, y, colW, c->getHeight());
  55656. y += c->getHeight();
  55657. }
  55658. x += colW;
  55659. childNum += numChildren;
  55660. }
  55661. return x;
  55662. }
  55663. bool isScrolling() const throw()
  55664. {
  55665. return childYOffset != 0 || needsToScroll;
  55666. }
  55667. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55668. {
  55669. if (currentChild->isValidComponent())
  55670. currentChild->setHighlighted (false);
  55671. currentChild = child;
  55672. if (currentChild != 0)
  55673. {
  55674. currentChild->setHighlighted (true);
  55675. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55676. }
  55677. }
  55678. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55679. {
  55680. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55681. activeSubMenu = 0;
  55682. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55683. {
  55684. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55685. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55686. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55687. dismissOnMouseUp,
  55688. this,
  55689. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55690. 0, maximumNumColumns,
  55691. standardItemHeight,
  55692. false, 0, menuBarComponent,
  55693. managerOfChosenCommand,
  55694. componentAttachedTo);
  55695. if (activeSubMenu != 0)
  55696. {
  55697. activeSubMenu->setVisible (true);
  55698. activeSubMenu->enterModalState (false);
  55699. activeSubMenu->toFront (false);
  55700. return true;
  55701. }
  55702. }
  55703. return false;
  55704. }
  55705. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55706. {
  55707. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55708. if (isOver)
  55709. hasBeenOver = true;
  55710. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55711. {
  55712. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55713. if (disableMouseMoves && isOver)
  55714. disableMouseMoves = false;
  55715. }
  55716. if (disableMouseMoves)
  55717. return;
  55718. bool isMovingTowardsMenu = false;
  55719. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55720. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55721. {
  55722. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55723. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55724. // extends from the last mouse pos to the submenu's rectangle..
  55725. float subX = (float) activeSubMenu->getScreenX();
  55726. if (activeSubMenu->getX() > getX())
  55727. {
  55728. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55729. }
  55730. else
  55731. {
  55732. lastMouse += Point<int> (2, 0);
  55733. subX += activeSubMenu->getWidth();
  55734. }
  55735. Path areaTowardsSubMenu;
  55736. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55737. (float) lastMouse.getY(),
  55738. subX,
  55739. (float) activeSubMenu->getScreenY(),
  55740. subX,
  55741. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55742. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55743. }
  55744. lastMouse = globalMousePos;
  55745. if (! isMovingTowardsMenu)
  55746. {
  55747. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55748. if (c == this)
  55749. c = 0;
  55750. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55751. if (mic == 0 && c != 0)
  55752. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55753. if (mic != currentChild
  55754. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55755. {
  55756. if (isOver && (c != 0) && (activeSubMenu != 0))
  55757. {
  55758. activeSubMenu->hide (0);
  55759. }
  55760. if (! isOver)
  55761. mic = 0;
  55762. setCurrentlyHighlightedChild (mic);
  55763. }
  55764. }
  55765. }
  55766. void triggerCurrentlyHighlightedItem()
  55767. {
  55768. if (currentChild->isValidComponent()
  55769. && currentChild->itemInfo.canBeTriggered()
  55770. && (currentChild->itemInfo.customComp == 0
  55771. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55772. {
  55773. dismissMenu (&currentChild->itemInfo);
  55774. }
  55775. }
  55776. void selectNextItem (const int delta)
  55777. {
  55778. disableTimerUntilMouseMoves();
  55779. PopupMenu::ItemComponent* mic = 0;
  55780. bool wasLastOne = (currentChild == 0);
  55781. const int numItems = getNumChildComponents();
  55782. for (int i = 0; i < numItems + 1; ++i)
  55783. {
  55784. int index = (delta > 0) ? i : (numItems - 1 - i);
  55785. index = (index + numItems) % numItems;
  55786. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55787. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55788. && wasLastOne)
  55789. break;
  55790. if (mic == currentChild)
  55791. wasLastOne = true;
  55792. }
  55793. setCurrentlyHighlightedChild (mic);
  55794. }
  55795. void disableTimerUntilMouseMoves()
  55796. {
  55797. disableMouseMoves = true;
  55798. if (owner != 0)
  55799. owner->disableTimerUntilMouseMoves();
  55800. }
  55801. Window (const Window&);
  55802. Window& operator= (const Window&);
  55803. };
  55804. PopupMenu::PopupMenu()
  55805. : lookAndFeel (0),
  55806. separatorPending (false)
  55807. {
  55808. }
  55809. PopupMenu::PopupMenu (const PopupMenu& other)
  55810. : lookAndFeel (other.lookAndFeel),
  55811. separatorPending (false)
  55812. {
  55813. items.ensureStorageAllocated (other.items.size());
  55814. for (int i = 0; i < other.items.size(); ++i)
  55815. items.add (new Item (*other.items.getUnchecked(i)));
  55816. }
  55817. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55818. {
  55819. if (this != &other)
  55820. {
  55821. lookAndFeel = other.lookAndFeel;
  55822. clear();
  55823. items.ensureStorageAllocated (other.items.size());
  55824. for (int i = 0; i < other.items.size(); ++i)
  55825. items.add (new Item (*other.items.getUnchecked(i)));
  55826. }
  55827. return *this;
  55828. }
  55829. PopupMenu::~PopupMenu()
  55830. {
  55831. clear();
  55832. }
  55833. void PopupMenu::clear()
  55834. {
  55835. items.clear();
  55836. separatorPending = false;
  55837. }
  55838. void PopupMenu::addSeparatorIfPending()
  55839. {
  55840. if (separatorPending)
  55841. {
  55842. separatorPending = false;
  55843. if (items.size() > 0)
  55844. items.add (new Item());
  55845. }
  55846. }
  55847. void PopupMenu::addItem (const int itemResultId,
  55848. const String& itemText,
  55849. const bool isActive,
  55850. const bool isTicked,
  55851. const Image* const iconToUse)
  55852. {
  55853. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55854. // didn't pick anything, so you shouldn't use it as the id
  55855. // for an item..
  55856. addSeparatorIfPending();
  55857. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55858. iconToUse, Colours::black, false, 0, 0, 0));
  55859. }
  55860. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55861. const int commandID,
  55862. const String& displayName)
  55863. {
  55864. jassert (commandManager != 0 && commandID != 0);
  55865. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55866. if (registeredInfo != 0)
  55867. {
  55868. ApplicationCommandInfo info (*registeredInfo);
  55869. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55870. addSeparatorIfPending();
  55871. items.add (new Item (commandID,
  55872. displayName.isNotEmpty() ? displayName
  55873. : info.shortName,
  55874. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55875. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55876. 0,
  55877. Colours::black,
  55878. false,
  55879. 0, 0,
  55880. commandManager));
  55881. }
  55882. }
  55883. void PopupMenu::addColouredItem (const int itemResultId,
  55884. const String& itemText,
  55885. const Colour& itemTextColour,
  55886. const bool isActive,
  55887. const bool isTicked,
  55888. const Image* const iconToUse)
  55889. {
  55890. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55891. // didn't pick anything, so you shouldn't use it as the id
  55892. // for an item..
  55893. addSeparatorIfPending();
  55894. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55895. iconToUse, itemTextColour, true, 0, 0, 0));
  55896. }
  55897. void PopupMenu::addCustomItem (const int itemResultId,
  55898. PopupMenuCustomComponent* const customComponent)
  55899. {
  55900. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55901. // didn't pick anything, so you shouldn't use it as the id
  55902. // for an item..
  55903. addSeparatorIfPending();
  55904. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55905. Colours::black, false, customComponent, 0, 0));
  55906. }
  55907. class NormalComponentWrapper : public PopupMenuCustomComponent
  55908. {
  55909. public:
  55910. NormalComponentWrapper (Component* const comp,
  55911. const int w, const int h,
  55912. const bool triggerMenuItemAutomaticallyWhenClicked)
  55913. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55914. width (w),
  55915. height (h)
  55916. {
  55917. addAndMakeVisible (comp);
  55918. }
  55919. ~NormalComponentWrapper() {}
  55920. void getIdealSize (int& idealWidth, int& idealHeight)
  55921. {
  55922. idealWidth = width;
  55923. idealHeight = height;
  55924. }
  55925. void resized()
  55926. {
  55927. if (getChildComponent(0) != 0)
  55928. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55929. }
  55930. juce_UseDebuggingNewOperator
  55931. private:
  55932. const int width, height;
  55933. NormalComponentWrapper (const NormalComponentWrapper&);
  55934. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55935. };
  55936. void PopupMenu::addCustomItem (const int itemResultId,
  55937. Component* customComponent,
  55938. int idealWidth, int idealHeight,
  55939. const bool triggerMenuItemAutomaticallyWhenClicked)
  55940. {
  55941. addCustomItem (itemResultId,
  55942. new NormalComponentWrapper (customComponent,
  55943. idealWidth, idealHeight,
  55944. triggerMenuItemAutomaticallyWhenClicked));
  55945. }
  55946. void PopupMenu::addSubMenu (const String& subMenuName,
  55947. const PopupMenu& subMenu,
  55948. const bool isActive,
  55949. Image* const iconToUse,
  55950. const bool isTicked)
  55951. {
  55952. addSeparatorIfPending();
  55953. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55954. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55955. }
  55956. void PopupMenu::addSeparator()
  55957. {
  55958. separatorPending = true;
  55959. }
  55960. class HeaderItemComponent : public PopupMenuCustomComponent
  55961. {
  55962. public:
  55963. HeaderItemComponent (const String& name)
  55964. : PopupMenuCustomComponent (false)
  55965. {
  55966. setName (name);
  55967. }
  55968. ~HeaderItemComponent()
  55969. {
  55970. }
  55971. void paint (Graphics& g)
  55972. {
  55973. Font f (getLookAndFeel().getPopupMenuFont());
  55974. f.setBold (true);
  55975. g.setFont (f);
  55976. g.setColour (findColour (PopupMenu::headerTextColourId));
  55977. g.drawFittedText (getName(),
  55978. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55979. Justification::bottomLeft, 1);
  55980. }
  55981. void getIdealSize (int& idealWidth,
  55982. int& idealHeight)
  55983. {
  55984. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55985. idealHeight += idealHeight / 2;
  55986. idealWidth += idealWidth / 4;
  55987. }
  55988. juce_UseDebuggingNewOperator
  55989. };
  55990. void PopupMenu::addSectionHeader (const String& title)
  55991. {
  55992. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55993. }
  55994. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55995. const int itemIdThatMustBeVisible,
  55996. const int minimumWidth,
  55997. const int maximumNumColumns,
  55998. const int standardItemHeight,
  55999. const bool alignToRectangle,
  56000. Component* menuBarComponent,
  56001. ApplicationCommandManager** managerOfChosenCommand,
  56002. Component* const componentAttachedTo)
  56003. {
  56004. Window* const pw
  56005. = Window::create (*this,
  56006. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  56007. 0,
  56008. x, x + w,
  56009. y, y + h,
  56010. minimumWidth,
  56011. maximumNumColumns,
  56012. standardItemHeight,
  56013. alignToRectangle,
  56014. itemIdThatMustBeVisible,
  56015. menuBarComponent,
  56016. managerOfChosenCommand,
  56017. componentAttachedTo);
  56018. if (pw != 0)
  56019. pw->setVisible (true);
  56020. return pw;
  56021. }
  56022. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  56023. const int itemIdThatMustBeVisible,
  56024. const int minimumWidth,
  56025. const int maximumNumColumns,
  56026. const int standardItemHeight,
  56027. const bool alignToRectangle,
  56028. Component* const componentAttachedTo)
  56029. {
  56030. Component* const prevFocused = Component::getCurrentlyFocusedComponent();
  56031. ScopedPointer <ComponentDeletionWatcher> deletionChecker[2];
  56032. if (prevFocused != 0)
  56033. deletionChecker[0] = new ComponentDeletionWatcher (prevFocused);
  56034. Component* const prevTopLevel = (prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0;
  56035. if (prevTopLevel != 0)
  56036. deletionChecker[1] = new ComponentDeletionWatcher (prevTopLevel);
  56037. Window::wasHiddenBecauseOfAppChange() = false;
  56038. int result = 0;
  56039. ApplicationCommandManager* managerOfChosenCommand = 0;
  56040. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  56041. itemIdThatMustBeVisible,
  56042. minimumWidth,
  56043. maximumNumColumns > 0 ? maximumNumColumns : 7,
  56044. standardItemHeight,
  56045. alignToRectangle, 0,
  56046. &managerOfChosenCommand,
  56047. componentAttachedTo));
  56048. if (popupComp != 0)
  56049. {
  56050. popupComp->enterModalState (false);
  56051. popupComp->toFront (false); // need to do this after making it modal, or it could
  56052. // be stuck behind other comps that are already modal..
  56053. result = popupComp->runModalLoop();
  56054. popupComp = 0;
  56055. if (! Window::wasHiddenBecauseOfAppChange())
  56056. {
  56057. if (deletionChecker[1] != 0 && ! deletionChecker[1]->hasBeenDeleted())
  56058. prevTopLevel->toFront (true);
  56059. if (deletionChecker[0] != 0 && ! deletionChecker[0]->hasBeenDeleted())
  56060. prevFocused->grabKeyboardFocus();
  56061. }
  56062. }
  56063. if (managerOfChosenCommand != 0 && result != 0)
  56064. {
  56065. ApplicationCommandTarget::InvocationInfo info (result);
  56066. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  56067. managerOfChosenCommand->invoke (info, true);
  56068. }
  56069. return result;
  56070. }
  56071. int PopupMenu::show (const int itemIdThatMustBeVisible,
  56072. const int minimumWidth,
  56073. const int maximumNumColumns,
  56074. const int standardItemHeight)
  56075. {
  56076. const Point<int> mousePos (Desktop::getMousePosition());
  56077. return showAt (mousePos.getX(), mousePos.getY(),
  56078. itemIdThatMustBeVisible,
  56079. minimumWidth,
  56080. maximumNumColumns,
  56081. standardItemHeight);
  56082. }
  56083. int PopupMenu::showAt (const int screenX,
  56084. const int screenY,
  56085. const int itemIdThatMustBeVisible,
  56086. const int minimumWidth,
  56087. const int maximumNumColumns,
  56088. const int standardItemHeight)
  56089. {
  56090. return showMenu (screenX, screenY, 1, 1,
  56091. itemIdThatMustBeVisible,
  56092. minimumWidth, maximumNumColumns,
  56093. standardItemHeight,
  56094. false, 0);
  56095. }
  56096. int PopupMenu::showAt (Component* componentToAttachTo,
  56097. const int itemIdThatMustBeVisible,
  56098. const int minimumWidth,
  56099. const int maximumNumColumns,
  56100. const int standardItemHeight)
  56101. {
  56102. if (componentToAttachTo != 0)
  56103. {
  56104. return showMenu (componentToAttachTo->getScreenX(),
  56105. componentToAttachTo->getScreenY(),
  56106. componentToAttachTo->getWidth(),
  56107. componentToAttachTo->getHeight(),
  56108. itemIdThatMustBeVisible,
  56109. minimumWidth,
  56110. maximumNumColumns,
  56111. standardItemHeight,
  56112. true, componentToAttachTo);
  56113. }
  56114. else
  56115. {
  56116. return show (itemIdThatMustBeVisible,
  56117. minimumWidth,
  56118. maximumNumColumns,
  56119. standardItemHeight);
  56120. }
  56121. }
  56122. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  56123. {
  56124. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  56125. {
  56126. Window* const pmw = Window::getActiveWindows()[i];
  56127. if (pmw != 0)
  56128. pmw->dismissMenu (0);
  56129. }
  56130. }
  56131. int PopupMenu::getNumItems() const throw()
  56132. {
  56133. int num = 0;
  56134. for (int i = items.size(); --i >= 0;)
  56135. if (! (items.getUnchecked(i))->isSeparator)
  56136. ++num;
  56137. return num;
  56138. }
  56139. bool PopupMenu::containsCommandItem (const int commandID) const
  56140. {
  56141. for (int i = items.size(); --i >= 0;)
  56142. {
  56143. const Item* mi = items.getUnchecked (i);
  56144. if ((mi->itemId == commandID && mi->commandManager != 0)
  56145. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  56146. {
  56147. return true;
  56148. }
  56149. }
  56150. return false;
  56151. }
  56152. bool PopupMenu::containsAnyActiveItems() const throw()
  56153. {
  56154. for (int i = items.size(); --i >= 0;)
  56155. {
  56156. const Item* const mi = items.getUnchecked (i);
  56157. if (mi->subMenu != 0)
  56158. {
  56159. if (mi->subMenu->containsAnyActiveItems())
  56160. return true;
  56161. }
  56162. else if (mi->active)
  56163. {
  56164. return true;
  56165. }
  56166. }
  56167. return false;
  56168. }
  56169. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  56170. {
  56171. lookAndFeel = newLookAndFeel;
  56172. }
  56173. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  56174. : isHighlighted (false),
  56175. isTriggeredAutomatically (isTriggeredAutomatically_)
  56176. {
  56177. }
  56178. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  56179. {
  56180. }
  56181. void PopupMenuCustomComponent::triggerMenuItem()
  56182. {
  56183. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  56184. if (mic != 0)
  56185. {
  56186. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  56187. if (pmw != 0)
  56188. {
  56189. pmw->dismissMenu (&mic->itemInfo);
  56190. }
  56191. else
  56192. {
  56193. // something must have gone wrong with the component hierarchy if this happens..
  56194. jassertfalse
  56195. }
  56196. }
  56197. else
  56198. {
  56199. // why isn't this component inside a menu? Not much point triggering the item if
  56200. // there's no menu.
  56201. jassertfalse
  56202. }
  56203. }
  56204. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  56205. : subMenu (0),
  56206. itemId (0),
  56207. isSeparator (false),
  56208. isTicked (false),
  56209. isEnabled (false),
  56210. isCustomComponent (false),
  56211. isSectionHeader (false),
  56212. customColour (0),
  56213. customImage (0),
  56214. menu (menu_),
  56215. index (0)
  56216. {
  56217. }
  56218. PopupMenu::MenuItemIterator::~MenuItemIterator()
  56219. {
  56220. }
  56221. bool PopupMenu::MenuItemIterator::next()
  56222. {
  56223. if (index >= menu.items.size())
  56224. return false;
  56225. const Item* const item = menu.items.getUnchecked (index);
  56226. ++index;
  56227. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  56228. subMenu = item->subMenu;
  56229. itemId = item->itemId;
  56230. isSeparator = item->isSeparator;
  56231. isTicked = item->isTicked;
  56232. isEnabled = item->active;
  56233. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  56234. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  56235. customColour = item->usesColour ? &(item->textColour) : 0;
  56236. customImage = item->image;
  56237. commandManager = item->commandManager;
  56238. return true;
  56239. }
  56240. END_JUCE_NAMESPACE
  56241. /*** End of inlined file: juce_PopupMenu.cpp ***/
  56242. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  56243. BEGIN_JUCE_NAMESPACE
  56244. ComponentDragger::ComponentDragger()
  56245. : constrainer (0)
  56246. {
  56247. }
  56248. ComponentDragger::~ComponentDragger()
  56249. {
  56250. }
  56251. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  56252. ComponentBoundsConstrainer* const constrainer_)
  56253. {
  56254. jassert (componentToDrag->isValidComponent());
  56255. if (componentToDrag->isValidComponent())
  56256. {
  56257. constrainer = constrainer_;
  56258. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  56259. }
  56260. }
  56261. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  56262. {
  56263. jassert (componentToDrag->isValidComponent());
  56264. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  56265. if (componentToDrag->isValidComponent())
  56266. {
  56267. Point<int> pos (originalPos);
  56268. int w = componentToDrag->getWidth();
  56269. int h = componentToDrag->getHeight();
  56270. const Component* const parentComp = componentToDrag->getParentComponent();
  56271. if (parentComp != 0)
  56272. pos = parentComp->globalPositionToRelative (pos);
  56273. pos += Point<int> (e.getDistanceFromDragStartX(),
  56274. e.getDistanceFromDragStartY());
  56275. if (constrainer != 0)
  56276. constrainer->setBoundsForComponent (componentToDrag, Rectangle<int> (pos.getX(), pos.getY(), w, h),
  56277. false, false, false, false);
  56278. else
  56279. componentToDrag->setBounds (pos.getX(), pos.getY(), w, h);
  56280. }
  56281. }
  56282. END_JUCE_NAMESPACE
  56283. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  56284. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  56285. BEGIN_JUCE_NAMESPACE
  56286. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  56287. bool juce_performDragDropText (const String& text, bool& shouldStop);
  56288. class DragImageComponent : public Component,
  56289. public Timer
  56290. {
  56291. public:
  56292. DragImageComponent (Image* const im,
  56293. const String& desc,
  56294. Component* const s,
  56295. DragAndDropContainer* const o,
  56296. const Point<int>& imageOffset_)
  56297. : image (im),
  56298. source (s),
  56299. owner (o),
  56300. currentlyOver (0),
  56301. dragDesc (desc),
  56302. imageOffset (imageOffset_),
  56303. hasCheckedForExternalDrag (false),
  56304. drawImage (true)
  56305. {
  56306. setSize (im->getWidth(), im->getHeight());
  56307. sourceWatcher = new ComponentDeletionWatcher (source);
  56308. mouseDragSource = Component::getComponentUnderMouse();
  56309. if (mouseDragSource == 0)
  56310. mouseDragSource = source;
  56311. mouseDragSourceWatcher = new ComponentDeletionWatcher (mouseDragSource);
  56312. mouseDragSource->addMouseListener (this, false);
  56313. startTimer (200);
  56314. setInterceptsMouseClicks (false, false);
  56315. setAlwaysOnTop (true);
  56316. }
  56317. ~DragImageComponent()
  56318. {
  56319. if ((DragImageComponent*) owner->dragImageComponent == this)
  56320. owner->dragImageComponent.release();
  56321. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56322. {
  56323. mouseDragSource->removeMouseListener (this);
  56324. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56325. if (currentlyOver->isInterestedInDragSource (dragDesc, source))
  56326. currentlyOver->itemDragExit (dragDesc, source);
  56327. }
  56328. }
  56329. void paint (Graphics& g)
  56330. {
  56331. if (isOpaque())
  56332. g.fillAll (Colours::white);
  56333. if (drawImage)
  56334. {
  56335. g.setOpacity (1.0f);
  56336. g.drawImageAt (image, 0, 0);
  56337. }
  56338. }
  56339. DragAndDropTarget* findTarget (const Point<int>& screenPos,
  56340. Point<int>& relativePos) const
  56341. {
  56342. Component* hit = getParentComponent();
  56343. if (hit == 0)
  56344. {
  56345. hit = Desktop::getInstance().findComponentAt (screenPos);
  56346. }
  56347. else
  56348. {
  56349. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  56350. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  56351. }
  56352. // (note: use a local copy of the dragDesc member in case the callback runs
  56353. // a modal loop and deletes this object before the method completes)
  56354. const String dragDescLocal (dragDesc);
  56355. while (hit != 0)
  56356. {
  56357. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  56358. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  56359. {
  56360. relativePos = hit->globalPositionToRelative (screenPos);
  56361. return ddt;
  56362. }
  56363. hit = hit->getParentComponent();
  56364. }
  56365. return 0;
  56366. }
  56367. void mouseUp (const MouseEvent& e)
  56368. {
  56369. if (e.originalComponent != this)
  56370. {
  56371. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56372. mouseDragSource->removeMouseListener (this);
  56373. bool dropAccepted = false;
  56374. DragAndDropTarget* ddt = 0;
  56375. Point<int> relPos;
  56376. if (isVisible())
  56377. {
  56378. setVisible (false);
  56379. ddt = findTarget (e.getScreenPosition(), relPos);
  56380. // fade this component and remove it - it'll be deleted later by the timer callback
  56381. dropAccepted = ddt != 0;
  56382. setVisible (true);
  56383. if (dropAccepted || sourceWatcher->hasBeenDeleted())
  56384. {
  56385. fadeOutComponent (120);
  56386. }
  56387. else
  56388. {
  56389. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  56390. source->getHeight() / 2)));
  56391. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  56392. getHeight() / 2)));
  56393. fadeOutComponent (120,
  56394. target.getX() - ourCentre.getX(),
  56395. target.getY() - ourCentre.getY());
  56396. }
  56397. }
  56398. if (getParentComponent() != 0)
  56399. getParentComponent()->removeChildComponent (this);
  56400. if (dropAccepted && ddt != 0)
  56401. {
  56402. // (note: use a local copy of the dragDesc member in case the callback runs
  56403. // a modal loop and deletes this object before the method completes)
  56404. const String dragDescLocal (dragDesc);
  56405. currentlyOverWatcher = 0;
  56406. currentlyOver = 0;
  56407. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  56408. }
  56409. // careful - this object could now be deleted..
  56410. }
  56411. }
  56412. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  56413. {
  56414. // (note: use a local copy of the dragDesc member in case the callback runs
  56415. // a modal loop and deletes this object before it returns)
  56416. const String dragDescLocal (dragDesc);
  56417. Point<int> newPos (screenPos + imageOffset);
  56418. if (getParentComponent() != 0)
  56419. newPos = getParentComponent()->globalPositionToRelative (newPos);
  56420. //if (newX != getX() || newY != getY())
  56421. {
  56422. setTopLeftPosition (newPos.getX(), newPos.getY());
  56423. Point<int> relPos;
  56424. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  56425. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  56426. if (ddt != currentlyOver)
  56427. {
  56428. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56429. {
  56430. Component* const over = dynamic_cast <Component*> (currentlyOver);
  56431. if (over != 0
  56432. && over->isValidComponent()
  56433. && ! (sourceWatcher->hasBeenDeleted())
  56434. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56435. {
  56436. currentlyOver->itemDragExit (dragDescLocal, source);
  56437. }
  56438. }
  56439. currentlyOver = ddt;
  56440. currentlyOverWatcher = 0;
  56441. if (ddt != 0)
  56442. {
  56443. currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast <Component*> (ddt));
  56444. if (currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56445. currentlyOver->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  56446. }
  56447. }
  56448. else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
  56449. {
  56450. currentlyOver = 0;
  56451. currentlyOverWatcher = 0;
  56452. }
  56453. if (currentlyOver != 0
  56454. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56455. currentlyOver->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  56456. if (currentlyOver == 0
  56457. && canDoExternalDrag
  56458. && ! hasCheckedForExternalDrag)
  56459. {
  56460. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  56461. {
  56462. hasCheckedForExternalDrag = true;
  56463. StringArray files;
  56464. bool canMoveFiles = false;
  56465. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  56466. && files.size() > 0)
  56467. {
  56468. ComponentDeletionWatcher cdw (this);
  56469. setVisible (false);
  56470. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56471. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56472. if (! cdw.hasBeenDeleted())
  56473. delete this;
  56474. return;
  56475. }
  56476. }
  56477. }
  56478. }
  56479. }
  56480. void mouseDrag (const MouseEvent& e)
  56481. {
  56482. if (e.originalComponent != this)
  56483. updateLocation (true, e.getScreenPosition());
  56484. }
  56485. void timerCallback()
  56486. {
  56487. if (sourceWatcher->hasBeenDeleted())
  56488. {
  56489. delete this;
  56490. }
  56491. else if (! isMouseButtonDownAnywhere())
  56492. {
  56493. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56494. mouseDragSource->removeMouseListener (this);
  56495. delete this;
  56496. }
  56497. }
  56498. private:
  56499. ScopedPointer<Image> image;
  56500. Component* const source;
  56501. DragAndDropContainer* const owner;
  56502. ScopedPointer<ComponentDeletionWatcher> sourceWatcher, mouseDragSourceWatcher, currentlyOverWatcher;
  56503. Component* mouseDragSource;
  56504. DragAndDropTarget* currentlyOver;
  56505. String dragDesc;
  56506. const Point<int> imageOffset;
  56507. bool hasCheckedForExternalDrag, drawImage;
  56508. DragImageComponent (const DragImageComponent&);
  56509. DragImageComponent& operator= (const DragImageComponent&);
  56510. };
  56511. DragAndDropContainer::DragAndDropContainer()
  56512. {
  56513. }
  56514. DragAndDropContainer::~DragAndDropContainer()
  56515. {
  56516. dragImageComponent = 0;
  56517. }
  56518. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56519. Component* sourceComponent,
  56520. Image* dragImage_,
  56521. const bool allowDraggingToExternalWindows,
  56522. const Point<int>* imageOffsetFromMouse)
  56523. {
  56524. ScopedPointer <Image> dragImage (dragImage_);
  56525. if (dragImageComponent == 0)
  56526. {
  56527. Component* const thisComp = dynamic_cast <Component*> (this);
  56528. if (thisComp != 0)
  56529. {
  56530. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  56531. Point<int> imageOffset;
  56532. if (dragImage == 0)
  56533. {
  56534. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56535. if (dragImage->getFormat() != Image::ARGB)
  56536. {
  56537. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56538. Graphics g2 (*newIm);
  56539. g2.drawImageAt (dragImage, 0, 0);
  56540. dragImage = newIm;
  56541. }
  56542. dragImage->multiplyAllAlphas (0.6f);
  56543. const int lo = 150;
  56544. const int hi = 400;
  56545. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  56546. Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
  56547. .getConstrainedPoint (relPos));
  56548. for (int y = dragImage->getHeight(); --y >= 0;)
  56549. {
  56550. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  56551. for (int x = dragImage->getWidth(); --x >= 0;)
  56552. {
  56553. const int dx = x - clipped.getX();
  56554. const int distance = roundToInt (sqrt (dx * dx + dy));
  56555. if (distance > lo)
  56556. {
  56557. const float alpha = (distance > hi) ? 0
  56558. : (hi - distance) / (float) (hi - lo)
  56559. + Random::getSystemRandom().nextFloat() * 0.008f;
  56560. dragImage->multiplyAlphaAt (x, y, alpha);
  56561. }
  56562. }
  56563. }
  56564. imageOffset = -clipped;
  56565. }
  56566. else
  56567. {
  56568. if (imageOffsetFromMouse == 0)
  56569. imageOffset = Point<int> (dragImage->getWidth() / -2,
  56570. dragImage->getHeight() / -2);
  56571. else
  56572. imageOffset = *imageOffsetFromMouse;
  56573. }
  56574. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56575. this, imageOffset);
  56576. currentDragDesc = sourceDescription;
  56577. if (allowDraggingToExternalWindows)
  56578. {
  56579. if (! Desktop::canUseSemiTransparentWindows())
  56580. dragImageComponent->setOpaque (true);
  56581. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56582. | ComponentPeer::windowIsTemporary
  56583. | ComponentPeer::windowIgnoresKeyPresses);
  56584. }
  56585. else
  56586. thisComp->addChildComponent (dragImageComponent);
  56587. ((DragImageComponent*) dragImageComponent)->updateLocation (false, lastMouseDown);
  56588. dragImageComponent->setVisible (true);
  56589. }
  56590. else
  56591. {
  56592. // this class must only be implemented by an object that
  56593. // is also a Component.
  56594. jassertfalse
  56595. }
  56596. }
  56597. }
  56598. bool DragAndDropContainer::isDragAndDropActive() const
  56599. {
  56600. return dragImageComponent != 0;
  56601. }
  56602. const String DragAndDropContainer::getCurrentDragDescription() const
  56603. {
  56604. return (dragImageComponent != 0) ? currentDragDesc
  56605. : String::empty;
  56606. }
  56607. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56608. {
  56609. if (c == 0)
  56610. return 0;
  56611. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56612. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56613. }
  56614. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56615. {
  56616. return false;
  56617. }
  56618. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56619. {
  56620. }
  56621. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56622. {
  56623. }
  56624. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56625. {
  56626. }
  56627. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56628. {
  56629. return true;
  56630. }
  56631. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56632. {
  56633. }
  56634. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56635. {
  56636. }
  56637. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56638. {
  56639. }
  56640. END_JUCE_NAMESPACE
  56641. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56642. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56643. BEGIN_JUCE_NAMESPACE
  56644. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56645. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56646. // isStandard set depending on which interface was used to create the cursor
  56647. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56648. static CriticalSection activeCursorListLock;
  56649. static VoidArray activeCursors;
  56650. class SharedMouseCursorInternal : public ReferenceCountedObject
  56651. {
  56652. public:
  56653. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56654. : standardType (type),
  56655. isStandard (true)
  56656. {
  56657. handle = juce_createStandardMouseCursor (standardType);
  56658. activeCursors.add (this);
  56659. }
  56660. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56661. : standardType (MouseCursor::NormalCursor),
  56662. isStandard (false)
  56663. {
  56664. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56665. }
  56666. ~SharedMouseCursorInternal() throw()
  56667. {
  56668. juce_deleteMouseCursor (handle, isStandard);
  56669. activeCursors.removeValue (this);
  56670. }
  56671. void* getHandle() const throw()
  56672. {
  56673. return handle;
  56674. }
  56675. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56676. {
  56677. for (int i = activeCursors.size(); --i >= 0;)
  56678. {
  56679. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56680. if (r->standardType == type)
  56681. return r;
  56682. }
  56683. return new SharedMouseCursorInternal (type);
  56684. }
  56685. juce_UseDebuggingNewOperator
  56686. private:
  56687. void* handle;
  56688. const MouseCursor::StandardCursorType standardType;
  56689. const bool isStandard;
  56690. SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56691. };
  56692. MouseCursor::MouseCursor() throw()
  56693. {
  56694. const ScopedLock sl (activeCursorListLock);
  56695. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56696. }
  56697. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56698. {
  56699. const ScopedLock sl (activeCursorListLock);
  56700. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56701. }
  56702. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56703. {
  56704. const ScopedLock sl (activeCursorListLock);
  56705. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56706. }
  56707. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56708. : cursorHandle (other.cursorHandle)
  56709. {
  56710. }
  56711. MouseCursor::~MouseCursor() throw()
  56712. {
  56713. }
  56714. MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56715. {
  56716. cursorHandle = other.cursorHandle;
  56717. return *this;
  56718. }
  56719. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56720. {
  56721. return cursorHandle == other.cursorHandle;
  56722. }
  56723. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56724. {
  56725. return cursorHandle != other.cursorHandle;
  56726. }
  56727. void* MouseCursor::getHandle() const throw()
  56728. {
  56729. return cursorHandle->getHandle();
  56730. }
  56731. void MouseCursor::showWaitCursor() throw()
  56732. {
  56733. const MouseCursor mc (MouseCursor::WaitCursor);
  56734. mc.showInAllWindows();
  56735. }
  56736. void MouseCursor::hideWaitCursor() throw()
  56737. {
  56738. Component* const c = Component::getComponentUnderMouse();
  56739. MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c)
  56740. : MouseCursor::NormalCursor);
  56741. mc.showInAllWindows();
  56742. }
  56743. END_JUCE_NAMESPACE
  56744. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56745. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56746. BEGIN_JUCE_NAMESPACE
  56747. MouseEvent::MouseEvent (MouseInputSource& source_,
  56748. const Point<int>& position,
  56749. const ModifierKeys& mods_,
  56750. Component* const originator,
  56751. const Time& eventTime_,
  56752. const Point<int> mouseDownPos_,
  56753. const Time& mouseDownTime_,
  56754. const int numberOfClicks_,
  56755. const bool mouseWasDragged) throw()
  56756. : x (position.getX()),
  56757. y (position.getY()),
  56758. mods (mods_),
  56759. eventComponent (originator),
  56760. originalComponent (originator),
  56761. eventTime (eventTime_),
  56762. source (source_),
  56763. mouseDownPos (mouseDownPos_),
  56764. mouseDownTime (mouseDownTime_),
  56765. numberOfClicks (numberOfClicks_),
  56766. wasMovedSinceMouseDown (mouseWasDragged)
  56767. {
  56768. }
  56769. MouseEvent::~MouseEvent() throw()
  56770. {
  56771. }
  56772. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56773. {
  56774. if (otherComponent == 0)
  56775. {
  56776. jassertfalse
  56777. return *this;
  56778. }
  56779. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56780. mods, originalComponent, eventTime,
  56781. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56782. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56783. }
  56784. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56785. {
  56786. return MouseEvent (source, newPosition, mods, originalComponent,
  56787. eventTime, mouseDownPos, mouseDownTime,
  56788. numberOfClicks, wasMovedSinceMouseDown);
  56789. }
  56790. bool MouseEvent::mouseWasClicked() const throw()
  56791. {
  56792. return ! wasMovedSinceMouseDown;
  56793. }
  56794. int MouseEvent::getMouseDownX() const throw()
  56795. {
  56796. return mouseDownPos.getX();
  56797. }
  56798. int MouseEvent::getMouseDownY() const throw()
  56799. {
  56800. return mouseDownPos.getY();
  56801. }
  56802. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56803. {
  56804. return mouseDownPos;
  56805. }
  56806. int MouseEvent::getDistanceFromDragStartX() const throw()
  56807. {
  56808. return x - mouseDownPos.getX();
  56809. }
  56810. int MouseEvent::getDistanceFromDragStartY() const throw()
  56811. {
  56812. return y - mouseDownPos.getY();
  56813. }
  56814. int MouseEvent::getDistanceFromDragStart() const throw()
  56815. {
  56816. return mouseDownPos.getDistanceFrom (getPosition());
  56817. }
  56818. int MouseEvent::getLengthOfMousePress() const throw()
  56819. {
  56820. if (mouseDownTime.toMilliseconds() > 0)
  56821. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56822. return 0;
  56823. }
  56824. const Point<int> MouseEvent::getPosition() const throw()
  56825. {
  56826. return Point<int> (x, y);
  56827. }
  56828. int MouseEvent::getScreenX() const
  56829. {
  56830. return getScreenPosition().getX();
  56831. }
  56832. int MouseEvent::getScreenY() const
  56833. {
  56834. return getScreenPosition().getY();
  56835. }
  56836. const Point<int> MouseEvent::getScreenPosition() const
  56837. {
  56838. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56839. }
  56840. int MouseEvent::getMouseDownScreenX() const
  56841. {
  56842. return getMouseDownScreenPosition().getX();
  56843. }
  56844. int MouseEvent::getMouseDownScreenY() const
  56845. {
  56846. return getMouseDownScreenPosition().getY();
  56847. }
  56848. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56849. {
  56850. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56851. }
  56852. static int doubleClickTimeOutMs = 400;
  56853. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56854. {
  56855. doubleClickTimeOutMs = newTime;
  56856. }
  56857. int MouseEvent::getDoubleClickTimeout() throw()
  56858. {
  56859. return doubleClickTimeOutMs;
  56860. }
  56861. END_JUCE_NAMESPACE
  56862. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56863. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56864. BEGIN_JUCE_NAMESPACE
  56865. class MouseInputSourceInternal : public AsyncUpdater
  56866. {
  56867. public:
  56868. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56869. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0)
  56870. {
  56871. zerostruct (mouseDowns);
  56872. }
  56873. ~MouseInputSourceInternal()
  56874. {
  56875. }
  56876. bool isDragging() const throw()
  56877. {
  56878. return buttonState.isAnyMouseButtonDown();
  56879. }
  56880. Component* getComponentUnderMouse() const
  56881. {
  56882. return componentUnderMouse != 0 ? const_cast<Component*> (componentUnderMouse->getComponent()) : 0;
  56883. }
  56884. const ModifierKeys getCurrentModifiers() const
  56885. {
  56886. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56887. }
  56888. ComponentPeer* getPeer()
  56889. {
  56890. if (! ComponentPeer::isValidPeer (lastPeer))
  56891. lastPeer = 0;
  56892. return lastPeer;
  56893. }
  56894. Component* findComponentAt (const Point<int>& screenPos)
  56895. {
  56896. ComponentPeer* const peer = getPeer();
  56897. if (peer != 0)
  56898. {
  56899. Component* const comp = peer->getComponent();
  56900. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56901. // (the contains() call is needed to test for overlapping desktop windows)
  56902. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56903. return comp->getComponentAt (relativePos);
  56904. }
  56905. return 0;
  56906. }
  56907. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56908. {
  56909. if (buttonState != newButtonState)
  56910. {
  56911. // (ignore secondary clicks when there's already a button down)
  56912. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56913. {
  56914. buttonState = newButtonState;
  56915. return;
  56916. }
  56917. if (buttonState.isAnyMouseButtonDown())
  56918. {
  56919. Component* const current = getComponentUnderMouse();
  56920. if (current != 0)
  56921. current->internalMouseUp (source, current->globalPositionToRelative (screenPos),
  56922. time, getCurrentModifiers());
  56923. }
  56924. buttonState = newButtonState;
  56925. if (buttonState.isAnyMouseButtonDown())
  56926. {
  56927. Desktop::getInstance().incrementMouseClickCounter();
  56928. Component* const current = getComponentUnderMouse();
  56929. if (current != 0)
  56930. {
  56931. registerMouseDown (screenPos, time, current);
  56932. current->internalMouseDown (source, current->globalPositionToRelative (screenPos), time);
  56933. }
  56934. }
  56935. }
  56936. }
  56937. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56938. {
  56939. Component* current = getComponentUnderMouse();
  56940. if (newComponent != current)
  56941. {
  56942. ScopedPointer<ComponentDeletionWatcher> newCompWatcher (newComponent != 0 ? new ComponentDeletionWatcher (newComponent) : 0);
  56943. const ModifierKeys originalButtonState (buttonState);
  56944. if (current != 0)
  56945. {
  56946. setButtons (screenPos, time, ModifierKeys());
  56947. current->internalMouseExit (source, current->globalPositionToRelative (screenPos), time);
  56948. buttonState = originalButtonState;
  56949. }
  56950. componentUnderMouse = newCompWatcher;
  56951. current = getComponentUnderMouse();
  56952. Component::componentUnderMouse = current;
  56953. if (current != 0)
  56954. current->internalMouseEnter (source, current->globalPositionToRelative (screenPos), time);
  56955. setButtons (screenPos, time, originalButtonState);
  56956. }
  56957. }
  56958. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56959. {
  56960. ModifierKeys::updateCurrentModifiers();
  56961. if (newPeer != lastPeer)
  56962. {
  56963. setComponentUnderMouse (0, screenPos, time);
  56964. lastPeer = newPeer;
  56965. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56966. }
  56967. }
  56968. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56969. {
  56970. if (! isDragging())
  56971. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56972. if (newScreenPos != lastScreenPos || forceUpdate)
  56973. {
  56974. cancelPendingUpdate();
  56975. lastScreenPos = newScreenPos;
  56976. Component* const current = getComponentUnderMouse();
  56977. if (current != 0)
  56978. {
  56979. const Point<int> pos (current->globalPositionToRelative (lastScreenPos));
  56980. if (isDragging())
  56981. {
  56982. registerMouseDrag (newScreenPos);
  56983. current->internalMouseDrag (source, pos, time);
  56984. }
  56985. else
  56986. {
  56987. current->internalMouseMove (source, pos, time);
  56988. }
  56989. }
  56990. }
  56991. }
  56992. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56993. {
  56994. jassert (newPeer != 0);
  56995. lastTime = time;
  56996. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56997. if (isDragging() && newMods.isAnyMouseButtonDown())
  56998. {
  56999. setScreenPos (screenPos, time, false);
  57000. }
  57001. else
  57002. {
  57003. setPeer (newPeer, screenPos, time);
  57004. ComponentPeer* peer = getPeer();
  57005. if (peer != 0)
  57006. {
  57007. setButtons (screenPos, time, newMods);
  57008. peer = getPeer();
  57009. if (peer != 0)
  57010. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  57011. }
  57012. }
  57013. }
  57014. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  57015. {
  57016. jassert (peer != 0);
  57017. lastTime = time;
  57018. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  57019. setPeer (peer, screenPos, time);
  57020. setScreenPos (screenPos, time, false);
  57021. triggerFakeMove();
  57022. if (! isDragging())
  57023. {
  57024. Component* current = getComponentUnderMouse();
  57025. if (current != 0)
  57026. current->internalMouseWheel (source, current->globalPositionToRelative (screenPos), time, x, y);
  57027. }
  57028. }
  57029. const Time getLastMouseDownTime() const throw()
  57030. {
  57031. return Time (mouseDowns[0].time);
  57032. }
  57033. const Point<int> getLastMouseDownPosition() const throw()
  57034. {
  57035. return mouseDowns[0].position;
  57036. }
  57037. int getNumberOfMultipleClicks() const throw()
  57038. {
  57039. int numClicks = 0;
  57040. if (mouseDowns[0].time != 0)
  57041. {
  57042. if (! mouseMovedSignificantlySincePressed)
  57043. ++numClicks;
  57044. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  57045. {
  57046. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  57047. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  57048. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  57049. && mouseDowns[0].component == mouseDowns[i].component)
  57050. {
  57051. ++numClicks;
  57052. }
  57053. else
  57054. {
  57055. break;
  57056. }
  57057. }
  57058. }
  57059. return numClicks;
  57060. }
  57061. bool hasMouseMovedSignificantlySincePressed() const throw()
  57062. {
  57063. return mouseMovedSignificantlySincePressed
  57064. || lastTime > mouseDowns[0].time + 300;
  57065. }
  57066. void triggerFakeMove()
  57067. {
  57068. triggerAsyncUpdate();
  57069. }
  57070. void handleAsyncUpdate()
  57071. {
  57072. setScreenPos (Desktop::getMousePosition(), Time::currentTimeMillis(), true);
  57073. }
  57074. int index;
  57075. bool isMouseDevice;
  57076. Point<int> lastScreenPos;
  57077. ModifierKeys buttonState;
  57078. private:
  57079. MouseInputSource& source;
  57080. ScopedPointer<ComponentDeletionWatcher> componentUnderMouse;
  57081. ComponentPeer* lastPeer;
  57082. struct RecentMouseDown
  57083. {
  57084. Point<int> position;
  57085. int64 time;
  57086. Component* component;
  57087. };
  57088. RecentMouseDown mouseDowns[4];
  57089. bool mouseMovedSignificantlySincePressed;
  57090. int64 lastTime;
  57091. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  57092. {
  57093. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  57094. mouseDowns[i] = mouseDowns[i - 1];
  57095. mouseDowns[0].position = screenPos;
  57096. mouseDowns[0].time = time;
  57097. mouseDowns[0].component = component;
  57098. mouseMovedSignificantlySincePressed = false;
  57099. }
  57100. void registerMouseDrag (const Point<int>& screenPos) throw()
  57101. {
  57102. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  57103. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  57104. }
  57105. };
  57106. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  57107. {
  57108. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  57109. }
  57110. MouseInputSource::~MouseInputSource()
  57111. {
  57112. }
  57113. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  57114. bool MouseInputSource::isTouch() const { return ! pimpl->isMouseDevice; }
  57115. bool MouseInputSource::canHover() const { return pimpl->isMouseDevice; }
  57116. bool MouseInputSource::hasMouseWheel() const { return pimpl->isMouseDevice; }
  57117. int MouseInputSource::getIndex() const { return pimpl->index; }
  57118. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  57119. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->lastScreenPos; }
  57120. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  57121. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  57122. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  57123. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  57124. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  57125. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  57126. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  57127. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  57128. {
  57129. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  57130. }
  57131. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  57132. {
  57133. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  57134. }
  57135. END_JUCE_NAMESPACE
  57136. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  57137. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  57138. BEGIN_JUCE_NAMESPACE
  57139. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  57140. : source (0),
  57141. hoverTimeMillisecs (hoverTimeMillisecs_),
  57142. hasJustHovered (false)
  57143. {
  57144. internalTimer.owner = this;
  57145. }
  57146. MouseHoverDetector::~MouseHoverDetector()
  57147. {
  57148. setHoverComponent (0);
  57149. }
  57150. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  57151. {
  57152. hoverTimeMillisecs = newTimeInMillisecs;
  57153. }
  57154. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  57155. {
  57156. if (source != newSourceComponent)
  57157. {
  57158. internalTimer.stopTimer();
  57159. hasJustHovered = false;
  57160. if (source != 0)
  57161. {
  57162. // ! you need to delete the hover detector before deleting its component
  57163. jassert (source->isValidComponent());
  57164. source->removeMouseListener (&internalTimer);
  57165. }
  57166. source = newSourceComponent;
  57167. if (newSourceComponent != 0)
  57168. newSourceComponent->addMouseListener (&internalTimer, false);
  57169. }
  57170. }
  57171. void MouseHoverDetector::hoverTimerCallback()
  57172. {
  57173. internalTimer.stopTimer();
  57174. if (source != 0)
  57175. {
  57176. const Point<int> pos (source->getMouseXYRelative());
  57177. if (source->reallyContains (pos.getX(), pos.getY(), false))
  57178. {
  57179. hasJustHovered = true;
  57180. mouseHovered (pos.getX(), pos.getY());
  57181. }
  57182. }
  57183. }
  57184. void MouseHoverDetector::checkJustHoveredCallback()
  57185. {
  57186. if (hasJustHovered)
  57187. {
  57188. hasJustHovered = false;
  57189. mouseMovedAfterHover();
  57190. }
  57191. }
  57192. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  57193. {
  57194. owner->hoverTimerCallback();
  57195. }
  57196. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  57197. {
  57198. stopTimer();
  57199. owner->checkJustHoveredCallback();
  57200. }
  57201. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  57202. {
  57203. stopTimer();
  57204. owner->checkJustHoveredCallback();
  57205. }
  57206. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  57207. {
  57208. stopTimer();
  57209. owner->checkJustHoveredCallback();
  57210. }
  57211. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  57212. {
  57213. stopTimer();
  57214. owner->checkJustHoveredCallback();
  57215. }
  57216. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  57217. {
  57218. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  57219. {
  57220. lastX = e.x;
  57221. lastY = e.y;
  57222. if (owner->source != 0)
  57223. startTimer (owner->hoverTimeMillisecs);
  57224. owner->checkJustHoveredCallback();
  57225. }
  57226. }
  57227. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  57228. {
  57229. stopTimer();
  57230. owner->checkJustHoveredCallback();
  57231. }
  57232. END_JUCE_NAMESPACE
  57233. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  57234. /*** Start of inlined file: juce_MouseListener.cpp ***/
  57235. BEGIN_JUCE_NAMESPACE
  57236. void MouseListener::mouseEnter (const MouseEvent&)
  57237. {
  57238. }
  57239. void MouseListener::mouseExit (const MouseEvent&)
  57240. {
  57241. }
  57242. void MouseListener::mouseDown (const MouseEvent&)
  57243. {
  57244. }
  57245. void MouseListener::mouseUp (const MouseEvent&)
  57246. {
  57247. }
  57248. void MouseListener::mouseDrag (const MouseEvent&)
  57249. {
  57250. }
  57251. void MouseListener::mouseMove (const MouseEvent&)
  57252. {
  57253. }
  57254. void MouseListener::mouseDoubleClick (const MouseEvent&)
  57255. {
  57256. }
  57257. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  57258. {
  57259. }
  57260. END_JUCE_NAMESPACE
  57261. /*** End of inlined file: juce_MouseListener.cpp ***/
  57262. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57263. BEGIN_JUCE_NAMESPACE
  57264. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  57265. const String& buttonTextWhenTrue,
  57266. const String& buttonTextWhenFalse)
  57267. : PropertyComponent (name),
  57268. onText (buttonTextWhenTrue),
  57269. offText (buttonTextWhenFalse)
  57270. {
  57271. createButton();
  57272. button->addButtonListener (this);
  57273. }
  57274. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  57275. const String& name,
  57276. const String& buttonText)
  57277. : PropertyComponent (name),
  57278. onText (buttonText),
  57279. offText (buttonText)
  57280. {
  57281. createButton();
  57282. button->setButtonText (buttonText);
  57283. button->getToggleStateValue().referTo (valueToControl);
  57284. button->setClickingTogglesState (true);
  57285. }
  57286. BooleanPropertyComponent::~BooleanPropertyComponent()
  57287. {
  57288. deleteAllChildren();
  57289. }
  57290. void BooleanPropertyComponent::createButton()
  57291. {
  57292. addAndMakeVisible (button = new ToggleButton (String::empty));
  57293. button->setClickingTogglesState (false);
  57294. }
  57295. void BooleanPropertyComponent::setState (const bool newState)
  57296. {
  57297. button->setToggleState (newState, true);
  57298. }
  57299. bool BooleanPropertyComponent::getState() const
  57300. {
  57301. return button->getToggleState();
  57302. }
  57303. void BooleanPropertyComponent::paint (Graphics& g)
  57304. {
  57305. PropertyComponent::paint (g);
  57306. const Rectangle<int> r (button->getBounds());
  57307. g.setColour (Colours::white);
  57308. g.fillRect (r);
  57309. g.setColour (findColour (ComboBox::outlineColourId));
  57310. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  57311. }
  57312. void BooleanPropertyComponent::refresh()
  57313. {
  57314. button->setToggleState (getState(), false);
  57315. button->setButtonText (button->getToggleState() ? onText : offText);
  57316. }
  57317. void BooleanPropertyComponent::buttonClicked (Button*)
  57318. {
  57319. setState (! getState());
  57320. }
  57321. END_JUCE_NAMESPACE
  57322. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57323. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57324. BEGIN_JUCE_NAMESPACE
  57325. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  57326. const bool triggerOnMouseDown)
  57327. : PropertyComponent (name)
  57328. {
  57329. addAndMakeVisible (button = new TextButton (String::empty));
  57330. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  57331. button->addButtonListener (this);
  57332. }
  57333. ButtonPropertyComponent::~ButtonPropertyComponent()
  57334. {
  57335. deleteAllChildren();
  57336. }
  57337. void ButtonPropertyComponent::refresh()
  57338. {
  57339. button->setButtonText (getButtonText());
  57340. }
  57341. void ButtonPropertyComponent::buttonClicked (Button*)
  57342. {
  57343. buttonClicked();
  57344. }
  57345. END_JUCE_NAMESPACE
  57346. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57347. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57348. BEGIN_JUCE_NAMESPACE
  57349. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57350. : PropertyComponent (name),
  57351. comboBox (0)
  57352. {
  57353. }
  57354. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57355. const String& name,
  57356. const StringArray& choices_,
  57357. const Array <int>* choiceIDs)
  57358. : PropertyComponent (name),
  57359. choices (choices_),
  57360. comboBox (0)
  57361. {
  57362. createComboBox (choiceIDs);
  57363. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57364. }
  57365. ChoicePropertyComponent::~ChoicePropertyComponent()
  57366. {
  57367. deleteAllChildren();
  57368. }
  57369. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57370. {
  57371. // The array of IDs must contain the same number of values as the choices list!
  57372. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57373. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57374. for (int i = 0; i < choices.size(); ++i)
  57375. {
  57376. if (choices[i].isNotEmpty())
  57377. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57378. : ((*choiceIDs)[i]));
  57379. else
  57380. comboBox->addSeparator();
  57381. }
  57382. comboBox->setEditableText (false);
  57383. }
  57384. void ChoicePropertyComponent::setIndex (const int newIndex)
  57385. {
  57386. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57387. }
  57388. int ChoicePropertyComponent::getIndex() const
  57389. {
  57390. return comboBox->getSelectedItemIndex();
  57391. }
  57392. const StringArray& ChoicePropertyComponent::getChoices() const
  57393. {
  57394. return choices;
  57395. }
  57396. void ChoicePropertyComponent::refresh()
  57397. {
  57398. if (comboBox == 0)
  57399. {
  57400. createComboBox (0);
  57401. comboBox->addListener (this);
  57402. }
  57403. comboBox->setSelectedId (getIndex() + 1, true);
  57404. }
  57405. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57406. {
  57407. const int newIndex = comboBox->getSelectedId() - 1;
  57408. if (newIndex != getIndex())
  57409. setIndex (newIndex);
  57410. }
  57411. END_JUCE_NAMESPACE
  57412. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57413. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57414. BEGIN_JUCE_NAMESPACE
  57415. PropertyComponent::PropertyComponent (const String& name,
  57416. const int preferredHeight_)
  57417. : Component (name),
  57418. preferredHeight (preferredHeight_)
  57419. {
  57420. jassert (name.isNotEmpty());
  57421. }
  57422. PropertyComponent::~PropertyComponent()
  57423. {
  57424. }
  57425. void PropertyComponent::paint (Graphics& g)
  57426. {
  57427. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57428. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57429. }
  57430. void PropertyComponent::resized()
  57431. {
  57432. if (getNumChildComponents() > 0)
  57433. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57434. }
  57435. void PropertyComponent::enablementChanged()
  57436. {
  57437. repaint();
  57438. }
  57439. END_JUCE_NAMESPACE
  57440. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57441. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57442. BEGIN_JUCE_NAMESPACE
  57443. class PropertyHolderComponent : public Component
  57444. {
  57445. public:
  57446. PropertyHolderComponent()
  57447. {
  57448. }
  57449. ~PropertyHolderComponent()
  57450. {
  57451. deleteAllChildren();
  57452. }
  57453. void paint (Graphics&)
  57454. {
  57455. }
  57456. void updateLayout (const int width);
  57457. void refreshAll() const;
  57458. };
  57459. class PropertySectionComponent : public Component
  57460. {
  57461. public:
  57462. PropertySectionComponent (const String& sectionTitle,
  57463. const Array <PropertyComponent*>& newProperties,
  57464. const bool open)
  57465. : Component (sectionTitle),
  57466. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57467. isOpen_ (open)
  57468. {
  57469. for (int i = newProperties.size(); --i >= 0;)
  57470. {
  57471. addAndMakeVisible (newProperties.getUnchecked(i));
  57472. newProperties.getUnchecked(i)->refresh();
  57473. }
  57474. }
  57475. ~PropertySectionComponent()
  57476. {
  57477. deleteAllChildren();
  57478. }
  57479. void paint (Graphics& g)
  57480. {
  57481. if (titleHeight > 0)
  57482. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57483. }
  57484. void resized()
  57485. {
  57486. int y = titleHeight;
  57487. for (int i = getNumChildComponents(); --i >= 0;)
  57488. {
  57489. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57490. if (pec != 0)
  57491. {
  57492. const int prefH = pec->getPreferredHeight();
  57493. pec->setBounds (1, y, getWidth() - 2, prefH);
  57494. y += prefH;
  57495. }
  57496. }
  57497. }
  57498. int getPreferredHeight() const
  57499. {
  57500. int y = titleHeight;
  57501. if (isOpen())
  57502. {
  57503. for (int i = 0; i < getNumChildComponents(); ++i)
  57504. {
  57505. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57506. if (pec != 0)
  57507. y += pec->getPreferredHeight();
  57508. }
  57509. }
  57510. return y;
  57511. }
  57512. void setOpen (const bool open)
  57513. {
  57514. if (isOpen_ != open)
  57515. {
  57516. isOpen_ = open;
  57517. for (int i = 0; i < getNumChildComponents(); ++i)
  57518. {
  57519. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57520. if (pec != 0)
  57521. pec->setVisible (open);
  57522. }
  57523. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57524. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57525. if (pp != 0)
  57526. pp->resized();
  57527. }
  57528. }
  57529. bool isOpen() const
  57530. {
  57531. return isOpen_;
  57532. }
  57533. void refreshAll() const
  57534. {
  57535. for (int i = 0; i < getNumChildComponents(); ++i)
  57536. {
  57537. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57538. if (pec != 0)
  57539. pec->refresh();
  57540. }
  57541. }
  57542. void mouseDown (const MouseEvent&)
  57543. {
  57544. }
  57545. void mouseUp (const MouseEvent& e)
  57546. {
  57547. if (e.getMouseDownX() < titleHeight
  57548. && e.x < titleHeight
  57549. && e.y < titleHeight
  57550. && e.getNumberOfClicks() != 2)
  57551. {
  57552. setOpen (! isOpen());
  57553. }
  57554. }
  57555. void mouseDoubleClick (const MouseEvent& e)
  57556. {
  57557. if (e.y < titleHeight)
  57558. setOpen (! isOpen());
  57559. }
  57560. private:
  57561. int titleHeight;
  57562. bool isOpen_;
  57563. };
  57564. void PropertyHolderComponent::updateLayout (const int width)
  57565. {
  57566. int y = 0;
  57567. for (int i = getNumChildComponents(); --i >= 0;)
  57568. {
  57569. PropertySectionComponent* const section
  57570. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57571. if (section != 0)
  57572. {
  57573. const int prefH = section->getPreferredHeight();
  57574. section->setBounds (0, y, width, prefH);
  57575. y += prefH;
  57576. }
  57577. }
  57578. setSize (width, y);
  57579. repaint();
  57580. }
  57581. void PropertyHolderComponent::refreshAll() const
  57582. {
  57583. for (int i = getNumChildComponents(); --i >= 0;)
  57584. {
  57585. PropertySectionComponent* const section
  57586. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57587. if (section != 0)
  57588. section->refreshAll();
  57589. }
  57590. }
  57591. PropertyPanel::PropertyPanel()
  57592. {
  57593. messageWhenEmpty = TRANS("(nothing selected)");
  57594. addAndMakeVisible (viewport = new Viewport());
  57595. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57596. viewport->setFocusContainer (true);
  57597. }
  57598. PropertyPanel::~PropertyPanel()
  57599. {
  57600. clear();
  57601. deleteAllChildren();
  57602. }
  57603. void PropertyPanel::paint (Graphics& g)
  57604. {
  57605. if (propertyHolderComponent->getNumChildComponents() == 0)
  57606. {
  57607. g.setColour (Colours::black.withAlpha (0.5f));
  57608. g.setFont (14.0f);
  57609. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57610. Justification::centred, true);
  57611. }
  57612. }
  57613. void PropertyPanel::resized()
  57614. {
  57615. viewport->setBounds (0, 0, getWidth(), getHeight());
  57616. updatePropHolderLayout();
  57617. }
  57618. void PropertyPanel::clear()
  57619. {
  57620. if (propertyHolderComponent->getNumChildComponents() > 0)
  57621. {
  57622. propertyHolderComponent->deleteAllChildren();
  57623. repaint();
  57624. }
  57625. }
  57626. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57627. {
  57628. if (propertyHolderComponent->getNumChildComponents() == 0)
  57629. repaint();
  57630. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57631. newProperties,
  57632. true), 0);
  57633. updatePropHolderLayout();
  57634. }
  57635. void PropertyPanel::addSection (const String& sectionTitle,
  57636. const Array <PropertyComponent*>& newProperties,
  57637. const bool shouldBeOpen)
  57638. {
  57639. jassert (sectionTitle.isNotEmpty());
  57640. if (propertyHolderComponent->getNumChildComponents() == 0)
  57641. repaint();
  57642. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57643. newProperties,
  57644. shouldBeOpen), 0);
  57645. updatePropHolderLayout();
  57646. }
  57647. void PropertyPanel::updatePropHolderLayout() const
  57648. {
  57649. const int maxWidth = viewport->getMaximumVisibleWidth();
  57650. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57651. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57652. if (maxWidth != newMaxWidth)
  57653. {
  57654. // need to do this twice because of scrollbars changing the size, etc.
  57655. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57656. }
  57657. }
  57658. void PropertyPanel::refreshAll() const
  57659. {
  57660. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57661. }
  57662. const StringArray PropertyPanel::getSectionNames() const
  57663. {
  57664. StringArray s;
  57665. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57666. {
  57667. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57668. if (section != 0 && section->getName().isNotEmpty())
  57669. s.add (section->getName());
  57670. }
  57671. return s;
  57672. }
  57673. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57674. {
  57675. int index = 0;
  57676. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57677. {
  57678. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57679. if (section != 0 && section->getName().isNotEmpty())
  57680. {
  57681. if (index == sectionIndex)
  57682. return section->isOpen();
  57683. ++index;
  57684. }
  57685. }
  57686. return false;
  57687. }
  57688. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57689. {
  57690. int index = 0;
  57691. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57692. {
  57693. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57694. if (section != 0 && section->getName().isNotEmpty())
  57695. {
  57696. if (index == sectionIndex)
  57697. {
  57698. section->setOpen (shouldBeOpen);
  57699. break;
  57700. }
  57701. ++index;
  57702. }
  57703. }
  57704. }
  57705. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57706. {
  57707. int index = 0;
  57708. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57709. {
  57710. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57711. if (section != 0 && section->getName().isNotEmpty())
  57712. {
  57713. if (index == sectionIndex)
  57714. {
  57715. section->setEnabled (shouldBeEnabled);
  57716. break;
  57717. }
  57718. ++index;
  57719. }
  57720. }
  57721. }
  57722. XmlElement* PropertyPanel::getOpennessState() const
  57723. {
  57724. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57725. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57726. const StringArray sections (getSectionNames());
  57727. for (int i = 0; i < sections.size(); ++i)
  57728. {
  57729. if (sections[i].isNotEmpty())
  57730. {
  57731. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57732. e->setAttribute ("name", sections[i]);
  57733. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57734. }
  57735. }
  57736. return xml;
  57737. }
  57738. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57739. {
  57740. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57741. {
  57742. const StringArray sections (getSectionNames());
  57743. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57744. {
  57745. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57746. e->getBoolAttribute (T("open")));
  57747. }
  57748. viewport->setViewPosition (viewport->getViewPositionX(),
  57749. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57750. }
  57751. }
  57752. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57753. {
  57754. if (messageWhenEmpty != newMessage)
  57755. {
  57756. messageWhenEmpty = newMessage;
  57757. repaint();
  57758. }
  57759. }
  57760. const String& PropertyPanel::getMessageWhenEmpty() const
  57761. {
  57762. return messageWhenEmpty;
  57763. }
  57764. END_JUCE_NAMESPACE
  57765. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57766. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57767. BEGIN_JUCE_NAMESPACE
  57768. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57769. const double rangeMin,
  57770. const double rangeMax,
  57771. const double interval,
  57772. const double skewFactor)
  57773. : PropertyComponent (name)
  57774. {
  57775. addAndMakeVisible (slider = new Slider (name));
  57776. slider->setRange (rangeMin, rangeMax, interval);
  57777. slider->setSkewFactor (skewFactor);
  57778. slider->setSliderStyle (Slider::LinearBar);
  57779. slider->addListener (this);
  57780. }
  57781. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57782. const String& name,
  57783. const double rangeMin,
  57784. const double rangeMax,
  57785. const double interval,
  57786. const double skewFactor)
  57787. : PropertyComponent (name)
  57788. {
  57789. addAndMakeVisible (slider = new Slider (name));
  57790. slider->setRange (rangeMin, rangeMax, interval);
  57791. slider->setSkewFactor (skewFactor);
  57792. slider->setSliderStyle (Slider::LinearBar);
  57793. slider->getValueObject().referTo (valueToControl);
  57794. }
  57795. SliderPropertyComponent::~SliderPropertyComponent()
  57796. {
  57797. deleteAllChildren();
  57798. }
  57799. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57800. {
  57801. }
  57802. const double SliderPropertyComponent::getValue() const
  57803. {
  57804. return slider->getValue();
  57805. }
  57806. void SliderPropertyComponent::refresh()
  57807. {
  57808. slider->setValue (getValue(), false);
  57809. }
  57810. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57811. {
  57812. if (getValue() != slider->getValue())
  57813. setValue (slider->getValue());
  57814. }
  57815. END_JUCE_NAMESPACE
  57816. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57817. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57818. BEGIN_JUCE_NAMESPACE
  57819. class TextPropLabel : public Label
  57820. {
  57821. TextPropertyComponent& owner;
  57822. int maxChars;
  57823. bool isMultiline;
  57824. public:
  57825. TextPropLabel (TextPropertyComponent& owner_,
  57826. const int maxChars_, const bool isMultiline_)
  57827. : Label (String::empty, String::empty),
  57828. owner (owner_),
  57829. maxChars (maxChars_),
  57830. isMultiline (isMultiline_)
  57831. {
  57832. setEditable (true, true, false);
  57833. setColour (backgroundColourId, Colours::white);
  57834. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57835. }
  57836. ~TextPropLabel()
  57837. {
  57838. }
  57839. TextEditor* createEditorComponent()
  57840. {
  57841. TextEditor* const textEditor = Label::createEditorComponent();
  57842. textEditor->setInputRestrictions (maxChars);
  57843. if (isMultiline)
  57844. {
  57845. textEditor->setMultiLine (true, true);
  57846. textEditor->setReturnKeyStartsNewLine (true);
  57847. }
  57848. return textEditor;
  57849. }
  57850. void textWasEdited()
  57851. {
  57852. owner.textWasEdited();
  57853. }
  57854. };
  57855. TextPropertyComponent::TextPropertyComponent (const String& name,
  57856. const int maxNumChars,
  57857. const bool isMultiLine)
  57858. : PropertyComponent (name)
  57859. {
  57860. createEditor (maxNumChars, isMultiLine);
  57861. }
  57862. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57863. const String& name,
  57864. const int maxNumChars,
  57865. const bool isMultiLine)
  57866. : PropertyComponent (name)
  57867. {
  57868. createEditor (maxNumChars, isMultiLine);
  57869. textEditor->getTextValue().referTo (valueToControl);
  57870. }
  57871. TextPropertyComponent::~TextPropertyComponent()
  57872. {
  57873. deleteAllChildren();
  57874. }
  57875. void TextPropertyComponent::setText (const String& newText)
  57876. {
  57877. textEditor->setText (newText, true);
  57878. }
  57879. const String TextPropertyComponent::getText() const
  57880. {
  57881. return textEditor->getText();
  57882. }
  57883. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57884. {
  57885. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57886. if (isMultiLine)
  57887. {
  57888. textEditor->setJustificationType (Justification::topLeft);
  57889. preferredHeight = 120;
  57890. }
  57891. }
  57892. void TextPropertyComponent::refresh()
  57893. {
  57894. textEditor->setText (getText(), false);
  57895. }
  57896. void TextPropertyComponent::textWasEdited()
  57897. {
  57898. const String newText (textEditor->getText());
  57899. if (getText() != newText)
  57900. setText (newText);
  57901. }
  57902. END_JUCE_NAMESPACE
  57903. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57904. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57905. BEGIN_JUCE_NAMESPACE
  57906. class SimpleDeviceManagerInputLevelMeter : public Component,
  57907. public Timer
  57908. {
  57909. public:
  57910. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57911. : manager (manager_),
  57912. level (0)
  57913. {
  57914. startTimer (50);
  57915. manager->enableInputLevelMeasurement (true);
  57916. }
  57917. ~SimpleDeviceManagerInputLevelMeter()
  57918. {
  57919. manager->enableInputLevelMeasurement (false);
  57920. }
  57921. void timerCallback()
  57922. {
  57923. const float newLevel = (float) manager->getCurrentInputLevel();
  57924. if (fabsf (level - newLevel) > 0.005f)
  57925. {
  57926. level = newLevel;
  57927. repaint();
  57928. }
  57929. }
  57930. void paint (Graphics& g)
  57931. {
  57932. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57933. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57934. }
  57935. private:
  57936. AudioDeviceManager* const manager;
  57937. float level;
  57938. };
  57939. class MidiInputSelectorComponentListBox : public ListBox,
  57940. public ListBoxModel
  57941. {
  57942. public:
  57943. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57944. const String& noItemsMessage_,
  57945. const int minNumber_,
  57946. const int maxNumber_)
  57947. : ListBox (String::empty, 0),
  57948. deviceManager (deviceManager_),
  57949. noItemsMessage (noItemsMessage_),
  57950. minNumber (minNumber_),
  57951. maxNumber (maxNumber_)
  57952. {
  57953. items = MidiInput::getDevices();
  57954. setModel (this);
  57955. setOutlineThickness (1);
  57956. }
  57957. ~MidiInputSelectorComponentListBox()
  57958. {
  57959. }
  57960. int getNumRows()
  57961. {
  57962. return items.size();
  57963. }
  57964. void paintListBoxItem (int row,
  57965. Graphics& g,
  57966. int width, int height,
  57967. bool rowIsSelected)
  57968. {
  57969. if (((unsigned int) row) < (unsigned int) items.size())
  57970. {
  57971. if (rowIsSelected)
  57972. g.fillAll (findColour (TextEditor::highlightColourId)
  57973. .withMultipliedAlpha (0.3f));
  57974. const String item (items [row]);
  57975. bool enabled = deviceManager.isMidiInputEnabled (item);
  57976. const int x = getTickX();
  57977. const float tickW = height * 0.75f;
  57978. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57979. enabled, true, true, false);
  57980. g.setFont (height * 0.6f);
  57981. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57982. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57983. }
  57984. }
  57985. void listBoxItemClicked (int row, const MouseEvent& e)
  57986. {
  57987. selectRow (row);
  57988. if (e.x < getTickX())
  57989. flipEnablement (row);
  57990. }
  57991. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57992. {
  57993. flipEnablement (row);
  57994. }
  57995. void returnKeyPressed (int row)
  57996. {
  57997. flipEnablement (row);
  57998. }
  57999. void paint (Graphics& g)
  58000. {
  58001. ListBox::paint (g);
  58002. if (items.size() == 0)
  58003. {
  58004. g.setColour (Colours::grey);
  58005. g.setFont (13.0f);
  58006. g.drawText (noItemsMessage,
  58007. 0, 0, getWidth(), getHeight() / 2,
  58008. Justification::centred, true);
  58009. }
  58010. }
  58011. int getBestHeight (const int preferredHeight)
  58012. {
  58013. const int extra = getOutlineThickness() * 2;
  58014. return jmax (getRowHeight() * 2 + extra,
  58015. jmin (getRowHeight() * getNumRows() + extra,
  58016. preferredHeight));
  58017. }
  58018. juce_UseDebuggingNewOperator
  58019. private:
  58020. AudioDeviceManager& deviceManager;
  58021. const String noItemsMessage;
  58022. StringArray items;
  58023. int minNumber, maxNumber;
  58024. void flipEnablement (const int row)
  58025. {
  58026. if (((unsigned int) row) < (unsigned int) items.size())
  58027. {
  58028. const String item (items [row]);
  58029. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  58030. }
  58031. }
  58032. int getTickX() const
  58033. {
  58034. return getRowHeight() + 5;
  58035. }
  58036. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  58037. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  58038. };
  58039. class AudioDeviceSettingsPanel : public Component,
  58040. public ComboBoxListener,
  58041. public ChangeListener,
  58042. public ButtonListener
  58043. {
  58044. public:
  58045. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  58046. AudioIODeviceType::DeviceSetupDetails& setup_,
  58047. const bool hideAdvancedOptionsWithButton)
  58048. : type (type_),
  58049. setup (setup_)
  58050. {
  58051. sampleRateDropDown = 0;
  58052. sampleRateLabel = 0;
  58053. bufferSizeDropDown = 0;
  58054. bufferSizeLabel = 0;
  58055. outputDeviceDropDown = 0;
  58056. outputDeviceLabel = 0;
  58057. inputDeviceDropDown = 0;
  58058. inputDeviceLabel = 0;
  58059. testButton = 0;
  58060. inputLevelMeter = 0;
  58061. showUIButton = 0;
  58062. inputChanList = 0;
  58063. outputChanList = 0;
  58064. inputChanLabel = 0;
  58065. outputChanLabel = 0;
  58066. showAdvancedSettingsButton = 0;
  58067. if (hideAdvancedOptionsWithButton)
  58068. {
  58069. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  58070. showAdvancedSettingsButton->addButtonListener (this);
  58071. }
  58072. type->scanForDevices();
  58073. setup.manager->addChangeListener (this);
  58074. changeListenerCallback (0);
  58075. }
  58076. ~AudioDeviceSettingsPanel()
  58077. {
  58078. setup.manager->removeChangeListener (this);
  58079. deleteAndZero (outputDeviceLabel);
  58080. deleteAndZero (inputDeviceLabel);
  58081. deleteAndZero (sampleRateLabel);
  58082. deleteAndZero (bufferSizeLabel);
  58083. deleteAndZero (showUIButton);
  58084. deleteAndZero (inputChanLabel);
  58085. deleteAndZero (outputChanLabel);
  58086. deleteAndZero (showAdvancedSettingsButton);
  58087. deleteAllChildren();
  58088. }
  58089. void resized()
  58090. {
  58091. const int lx = proportionOfWidth (0.35f);
  58092. const int w = proportionOfWidth (0.4f);
  58093. const int h = 24;
  58094. const int space = 6;
  58095. const int dh = h + space;
  58096. int y = 0;
  58097. if (outputDeviceDropDown != 0)
  58098. {
  58099. outputDeviceDropDown->setBounds (lx, y, w, h);
  58100. if (testButton != 0)
  58101. testButton->setBounds (proportionOfWidth (0.77f),
  58102. outputDeviceDropDown->getY(),
  58103. proportionOfWidth (0.18f),
  58104. h);
  58105. y += dh;
  58106. }
  58107. if (inputDeviceDropDown != 0)
  58108. {
  58109. inputDeviceDropDown->setBounds (lx, y, w, h);
  58110. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  58111. inputDeviceDropDown->getY(),
  58112. proportionOfWidth (0.18f),
  58113. h);
  58114. y += dh;
  58115. }
  58116. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  58117. if (outputChanList != 0)
  58118. {
  58119. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  58120. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58121. y += bh + space;
  58122. }
  58123. if (inputChanList != 0)
  58124. {
  58125. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  58126. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58127. y += bh + space;
  58128. }
  58129. y += space * 2;
  58130. if (showAdvancedSettingsButton != 0)
  58131. {
  58132. showAdvancedSettingsButton->changeWidthToFitText (h);
  58133. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  58134. }
  58135. if (sampleRateDropDown != 0)
  58136. {
  58137. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  58138. || ! showAdvancedSettingsButton->isVisible());
  58139. sampleRateDropDown->setBounds (lx, y, w, h);
  58140. y += dh;
  58141. }
  58142. if (bufferSizeDropDown != 0)
  58143. {
  58144. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  58145. || ! showAdvancedSettingsButton->isVisible());
  58146. bufferSizeDropDown->setBounds (lx, y, w, h);
  58147. y += dh;
  58148. }
  58149. if (showUIButton != 0)
  58150. {
  58151. showUIButton->setVisible (showAdvancedSettingsButton == 0
  58152. || ! showAdvancedSettingsButton->isVisible());
  58153. showUIButton->changeWidthToFitText (h);
  58154. showUIButton->setTopLeftPosition (lx, y);
  58155. }
  58156. }
  58157. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58158. {
  58159. if (comboBoxThatHasChanged == 0)
  58160. return;
  58161. AudioDeviceManager::AudioDeviceSetup config;
  58162. setup.manager->getAudioDeviceSetup (config);
  58163. String error;
  58164. if (comboBoxThatHasChanged == outputDeviceDropDown
  58165. || comboBoxThatHasChanged == inputDeviceDropDown)
  58166. {
  58167. if (outputDeviceDropDown != 0)
  58168. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58169. : outputDeviceDropDown->getText();
  58170. if (inputDeviceDropDown != 0)
  58171. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58172. : inputDeviceDropDown->getText();
  58173. if (! type->hasSeparateInputsAndOutputs())
  58174. config.inputDeviceName = config.outputDeviceName;
  58175. if (comboBoxThatHasChanged == inputDeviceDropDown)
  58176. config.useDefaultInputChannels = true;
  58177. else
  58178. config.useDefaultOutputChannels = true;
  58179. error = setup.manager->setAudioDeviceSetup (config, true);
  58180. showCorrectDeviceName (inputDeviceDropDown, true);
  58181. showCorrectDeviceName (outputDeviceDropDown, false);
  58182. updateControlPanelButton();
  58183. resized();
  58184. }
  58185. else if (comboBoxThatHasChanged == sampleRateDropDown)
  58186. {
  58187. if (sampleRateDropDown->getSelectedId() > 0)
  58188. {
  58189. config.sampleRate = sampleRateDropDown->getSelectedId();
  58190. error = setup.manager->setAudioDeviceSetup (config, true);
  58191. }
  58192. }
  58193. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  58194. {
  58195. if (bufferSizeDropDown->getSelectedId() > 0)
  58196. {
  58197. config.bufferSize = bufferSizeDropDown->getSelectedId();
  58198. error = setup.manager->setAudioDeviceSetup (config, true);
  58199. }
  58200. }
  58201. if (error.isNotEmpty())
  58202. {
  58203. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  58204. T("Error when trying to open audio device!"),
  58205. error);
  58206. }
  58207. }
  58208. void buttonClicked (Button* button)
  58209. {
  58210. if (button == showAdvancedSettingsButton)
  58211. {
  58212. showAdvancedSettingsButton->setVisible (false);
  58213. resized();
  58214. }
  58215. else if (button == showUIButton)
  58216. {
  58217. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  58218. if (device != 0 && device->showControlPanel())
  58219. {
  58220. setup.manager->closeAudioDevice();
  58221. setup.manager->restartLastAudioDevice();
  58222. getTopLevelComponent()->toFront (true);
  58223. }
  58224. }
  58225. else if (button == testButton && testButton != 0)
  58226. {
  58227. setup.manager->playTestSound();
  58228. }
  58229. }
  58230. void updateControlPanelButton()
  58231. {
  58232. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58233. deleteAndZero (showUIButton);
  58234. if (currentDevice != 0 && currentDevice->hasControlPanel())
  58235. {
  58236. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  58237. TRANS ("opens the device's own control panel")));
  58238. showUIButton->addButtonListener (this);
  58239. }
  58240. resized();
  58241. }
  58242. void changeListenerCallback (void*)
  58243. {
  58244. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58245. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  58246. {
  58247. if (outputDeviceDropDown == 0)
  58248. {
  58249. outputDeviceDropDown = new ComboBox (String::empty);
  58250. outputDeviceDropDown->addListener (this);
  58251. addAndMakeVisible (outputDeviceDropDown);
  58252. outputDeviceLabel = new Label (String::empty,
  58253. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  58254. : TRANS ("device:"));
  58255. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  58256. if (setup.maxNumOutputChannels > 0)
  58257. {
  58258. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  58259. testButton->addButtonListener (this);
  58260. }
  58261. }
  58262. addNamesToDeviceBox (*outputDeviceDropDown, false);
  58263. }
  58264. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  58265. {
  58266. if (inputDeviceDropDown == 0)
  58267. {
  58268. inputDeviceDropDown = new ComboBox (String::empty);
  58269. inputDeviceDropDown->addListener (this);
  58270. addAndMakeVisible (inputDeviceDropDown);
  58271. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  58272. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  58273. addAndMakeVisible (inputLevelMeter
  58274. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  58275. }
  58276. addNamesToDeviceBox (*inputDeviceDropDown, true);
  58277. }
  58278. updateControlPanelButton();
  58279. showCorrectDeviceName (inputDeviceDropDown, true);
  58280. showCorrectDeviceName (outputDeviceDropDown, false);
  58281. if (currentDevice != 0)
  58282. {
  58283. if (setup.maxNumOutputChannels > 0
  58284. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  58285. {
  58286. if (outputChanList == 0)
  58287. {
  58288. addAndMakeVisible (outputChanList
  58289. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  58290. TRANS ("(no audio output channels found)")));
  58291. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  58292. outputChanLabel->attachToComponent (outputChanList, true);
  58293. }
  58294. outputChanList->refresh();
  58295. }
  58296. else
  58297. {
  58298. deleteAndZero (outputChanLabel);
  58299. deleteAndZero (outputChanList);
  58300. }
  58301. if (setup.maxNumInputChannels > 0
  58302. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  58303. {
  58304. if (inputChanList == 0)
  58305. {
  58306. addAndMakeVisible (inputChanList
  58307. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  58308. TRANS ("(no audio input channels found)")));
  58309. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  58310. inputChanLabel->attachToComponent (inputChanList, true);
  58311. }
  58312. inputChanList->refresh();
  58313. }
  58314. else
  58315. {
  58316. deleteAndZero (inputChanLabel);
  58317. deleteAndZero (inputChanList);
  58318. }
  58319. // sample rate..
  58320. {
  58321. if (sampleRateDropDown == 0)
  58322. {
  58323. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  58324. sampleRateDropDown->addListener (this);
  58325. delete sampleRateLabel;
  58326. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  58327. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  58328. }
  58329. else
  58330. {
  58331. sampleRateDropDown->clear();
  58332. sampleRateDropDown->removeListener (this);
  58333. }
  58334. const int numRates = currentDevice->getNumSampleRates();
  58335. for (int i = 0; i < numRates; ++i)
  58336. {
  58337. const int rate = roundToInt (currentDevice->getSampleRate (i));
  58338. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  58339. }
  58340. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58341. sampleRateDropDown->addListener (this);
  58342. }
  58343. // buffer size
  58344. {
  58345. if (bufferSizeDropDown == 0)
  58346. {
  58347. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58348. bufferSizeDropDown->addListener (this);
  58349. delete bufferSizeLabel;
  58350. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58351. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58352. }
  58353. else
  58354. {
  58355. bufferSizeDropDown->clear();
  58356. }
  58357. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58358. double currentRate = currentDevice->getCurrentSampleRate();
  58359. if (currentRate == 0)
  58360. currentRate = 48000.0;
  58361. for (int i = 0; i < numBufferSizes; ++i)
  58362. {
  58363. const int bs = currentDevice->getBufferSizeSamples (i);
  58364. bufferSizeDropDown->addItem (String (bs)
  58365. + T(" samples (")
  58366. + String (bs * 1000.0 / currentRate, 1)
  58367. + T(" ms)"),
  58368. bs);
  58369. }
  58370. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58371. }
  58372. }
  58373. else
  58374. {
  58375. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58376. deleteAndZero (sampleRateLabel);
  58377. deleteAndZero (bufferSizeLabel);
  58378. deleteAndZero (sampleRateDropDown);
  58379. deleteAndZero (bufferSizeDropDown);
  58380. if (outputDeviceDropDown != 0)
  58381. outputDeviceDropDown->setSelectedId (-1, true);
  58382. if (inputDeviceDropDown != 0)
  58383. inputDeviceDropDown->setSelectedId (-1, true);
  58384. }
  58385. resized();
  58386. setSize (getWidth(), getLowestY() + 4);
  58387. }
  58388. private:
  58389. AudioIODeviceType* const type;
  58390. const AudioIODeviceType::DeviceSetupDetails setup;
  58391. ComboBox* outputDeviceDropDown;
  58392. ComboBox* inputDeviceDropDown;
  58393. ComboBox* sampleRateDropDown;
  58394. ComboBox* bufferSizeDropDown;
  58395. Label* outputDeviceLabel;
  58396. Label* inputDeviceLabel;
  58397. Label* sampleRateLabel;
  58398. Label* bufferSizeLabel;
  58399. Label* inputChanLabel;
  58400. Label* outputChanLabel;
  58401. TextButton* testButton;
  58402. Component* inputLevelMeter;
  58403. TextButton* showUIButton;
  58404. TextButton* showAdvancedSettingsButton;
  58405. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58406. {
  58407. if (box != 0)
  58408. {
  58409. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58410. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58411. box->setSelectedId (index + 1, true);
  58412. if (testButton != 0 && ! isInput)
  58413. testButton->setEnabled (index >= 0);
  58414. }
  58415. }
  58416. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58417. {
  58418. const StringArray devs (type->getDeviceNames (isInputs));
  58419. combo.clear (true);
  58420. for (int i = 0; i < devs.size(); ++i)
  58421. combo.addItem (devs[i], i + 1);
  58422. combo.addItem (TRANS("<< none >>"), -1);
  58423. combo.setSelectedId (-1, true);
  58424. }
  58425. int getLowestY() const
  58426. {
  58427. int y = 0;
  58428. for (int i = getNumChildComponents(); --i >= 0;)
  58429. y = jmax (y, getChildComponent (i)->getBottom());
  58430. return y;
  58431. }
  58432. public:
  58433. class ChannelSelectorListBox : public ListBox,
  58434. public ListBoxModel
  58435. {
  58436. public:
  58437. enum BoxType
  58438. {
  58439. audioInputType,
  58440. audioOutputType
  58441. };
  58442. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58443. const BoxType type_,
  58444. const String& noItemsMessage_)
  58445. : ListBox (String::empty, 0),
  58446. setup (setup_),
  58447. type (type_),
  58448. noItemsMessage (noItemsMessage_)
  58449. {
  58450. refresh();
  58451. setModel (this);
  58452. setOutlineThickness (1);
  58453. }
  58454. ~ChannelSelectorListBox()
  58455. {
  58456. }
  58457. void refresh()
  58458. {
  58459. items.clear();
  58460. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58461. if (currentDevice != 0)
  58462. {
  58463. if (type == audioInputType)
  58464. items = currentDevice->getInputChannelNames();
  58465. else if (type == audioOutputType)
  58466. items = currentDevice->getOutputChannelNames();
  58467. if (setup.useStereoPairs)
  58468. {
  58469. StringArray pairs;
  58470. for (int i = 0; i < items.size(); i += 2)
  58471. {
  58472. String name (items[i]);
  58473. String name2 (items[i + 1]);
  58474. String commonBit;
  58475. for (int j = 0; j < name.length(); ++j)
  58476. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58477. commonBit = name.substring (0, j);
  58478. pairs.add (name.trim()
  58479. + " + "
  58480. + name2.substring (commonBit.length()).trim());
  58481. }
  58482. items = pairs;
  58483. }
  58484. }
  58485. updateContent();
  58486. repaint();
  58487. }
  58488. int getNumRows()
  58489. {
  58490. return items.size();
  58491. }
  58492. void paintListBoxItem (int row,
  58493. Graphics& g,
  58494. int width, int height,
  58495. bool rowIsSelected)
  58496. {
  58497. if (((unsigned int) row) < (unsigned int) items.size())
  58498. {
  58499. if (rowIsSelected)
  58500. g.fillAll (findColour (TextEditor::highlightColourId)
  58501. .withMultipliedAlpha (0.3f));
  58502. const String item (items [row]);
  58503. bool enabled = false;
  58504. AudioDeviceManager::AudioDeviceSetup config;
  58505. setup.manager->getAudioDeviceSetup (config);
  58506. if (setup.useStereoPairs)
  58507. {
  58508. if (type == audioInputType)
  58509. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58510. else if (type == audioOutputType)
  58511. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58512. }
  58513. else
  58514. {
  58515. if (type == audioInputType)
  58516. enabled = config.inputChannels [row];
  58517. else if (type == audioOutputType)
  58518. enabled = config.outputChannels [row];
  58519. }
  58520. const int x = getTickX();
  58521. const float tickW = height * 0.75f;
  58522. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58523. enabled, true, true, false);
  58524. g.setFont (height * 0.6f);
  58525. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58526. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58527. }
  58528. }
  58529. void listBoxItemClicked (int row, const MouseEvent& e)
  58530. {
  58531. selectRow (row);
  58532. if (e.x < getTickX())
  58533. flipEnablement (row);
  58534. }
  58535. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58536. {
  58537. flipEnablement (row);
  58538. }
  58539. void returnKeyPressed (int row)
  58540. {
  58541. flipEnablement (row);
  58542. }
  58543. void paint (Graphics& g)
  58544. {
  58545. ListBox::paint (g);
  58546. if (items.size() == 0)
  58547. {
  58548. g.setColour (Colours::grey);
  58549. g.setFont (13.0f);
  58550. g.drawText (noItemsMessage,
  58551. 0, 0, getWidth(), getHeight() / 2,
  58552. Justification::centred, true);
  58553. }
  58554. }
  58555. int getBestHeight (int maxHeight)
  58556. {
  58557. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58558. getNumRows())
  58559. + getOutlineThickness() * 2;
  58560. }
  58561. juce_UseDebuggingNewOperator
  58562. private:
  58563. const AudioIODeviceType::DeviceSetupDetails setup;
  58564. const BoxType type;
  58565. const String noItemsMessage;
  58566. StringArray items;
  58567. void flipEnablement (const int row)
  58568. {
  58569. jassert (type == audioInputType || type == audioOutputType);
  58570. if (((unsigned int) row) < (unsigned int) items.size())
  58571. {
  58572. AudioDeviceManager::AudioDeviceSetup config;
  58573. setup.manager->getAudioDeviceSetup (config);
  58574. if (setup.useStereoPairs)
  58575. {
  58576. BitArray bits;
  58577. BitArray& original = (type == audioInputType ? config.inputChannels
  58578. : config.outputChannels);
  58579. int i;
  58580. for (i = 0; i < 256; i += 2)
  58581. bits.setBit (i / 2, original [i] || original [i + 1]);
  58582. if (type == audioInputType)
  58583. {
  58584. config.useDefaultInputChannels = false;
  58585. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58586. }
  58587. else
  58588. {
  58589. config.useDefaultOutputChannels = false;
  58590. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58591. }
  58592. for (i = 0; i < 256; ++i)
  58593. original.setBit (i, bits [i / 2]);
  58594. }
  58595. else
  58596. {
  58597. if (type == audioInputType)
  58598. {
  58599. config.useDefaultInputChannels = false;
  58600. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58601. }
  58602. else
  58603. {
  58604. config.useDefaultOutputChannels = false;
  58605. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58606. }
  58607. }
  58608. String error (setup.manager->setAudioDeviceSetup (config, true));
  58609. if (! error.isEmpty())
  58610. {
  58611. //xxx
  58612. }
  58613. }
  58614. }
  58615. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58616. {
  58617. const int numActive = chans.countNumberOfSetBits();
  58618. if (chans [index])
  58619. {
  58620. if (numActive > minNumber)
  58621. chans.setBit (index, false);
  58622. }
  58623. else
  58624. {
  58625. if (numActive >= maxNumber)
  58626. {
  58627. const int firstActiveChan = chans.findNextSetBit();
  58628. chans.setBit (index > firstActiveChan
  58629. ? firstActiveChan : chans.getHighestBit(),
  58630. false);
  58631. }
  58632. chans.setBit (index, true);
  58633. }
  58634. }
  58635. int getTickX() const
  58636. {
  58637. return getRowHeight() + 5;
  58638. }
  58639. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58640. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58641. };
  58642. private:
  58643. ChannelSelectorListBox* inputChanList;
  58644. ChannelSelectorListBox* outputChanList;
  58645. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58646. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58647. };
  58648. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58649. const int minInputChannels_,
  58650. const int maxInputChannels_,
  58651. const int minOutputChannels_,
  58652. const int maxOutputChannels_,
  58653. const bool showMidiInputOptions,
  58654. const bool showMidiOutputSelector,
  58655. const bool showChannelsAsStereoPairs_,
  58656. const bool hideAdvancedOptionsWithButton_)
  58657. : deviceManager (deviceManager_),
  58658. deviceTypeDropDown (0),
  58659. deviceTypeDropDownLabel (0),
  58660. audioDeviceSettingsComp (0),
  58661. minOutputChannels (minOutputChannels_),
  58662. maxOutputChannels (maxOutputChannels_),
  58663. minInputChannels (minInputChannels_),
  58664. maxInputChannels (maxInputChannels_),
  58665. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58666. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58667. {
  58668. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58669. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58670. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58671. {
  58672. deviceTypeDropDown = new ComboBox (String::empty);
  58673. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58674. {
  58675. deviceTypeDropDown
  58676. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58677. i + 1);
  58678. }
  58679. addAndMakeVisible (deviceTypeDropDown);
  58680. deviceTypeDropDown->addListener (this);
  58681. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58682. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58683. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58684. }
  58685. if (showMidiInputOptions)
  58686. {
  58687. addAndMakeVisible (midiInputsList
  58688. = new MidiInputSelectorComponentListBox (deviceManager,
  58689. TRANS("(no midi inputs available)"),
  58690. 0, 0));
  58691. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58692. midiInputsLabel->setJustificationType (Justification::topRight);
  58693. midiInputsLabel->attachToComponent (midiInputsList, true);
  58694. }
  58695. else
  58696. {
  58697. midiInputsList = 0;
  58698. midiInputsLabel = 0;
  58699. }
  58700. if (showMidiOutputSelector)
  58701. {
  58702. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58703. midiOutputSelector->addListener (this);
  58704. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58705. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58706. }
  58707. else
  58708. {
  58709. midiOutputSelector = 0;
  58710. midiOutputLabel = 0;
  58711. }
  58712. deviceManager_.addChangeListener (this);
  58713. changeListenerCallback (0);
  58714. }
  58715. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58716. {
  58717. deviceManager.removeChangeListener (this);
  58718. deleteAllChildren();
  58719. }
  58720. void AudioDeviceSelectorComponent::resized()
  58721. {
  58722. const int lx = proportionOfWidth (0.35f);
  58723. const int w = proportionOfWidth (0.4f);
  58724. const int h = 24;
  58725. const int space = 6;
  58726. const int dh = h + space;
  58727. int y = 15;
  58728. if (deviceTypeDropDown != 0)
  58729. {
  58730. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58731. y += dh + space * 2;
  58732. }
  58733. if (audioDeviceSettingsComp != 0)
  58734. {
  58735. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58736. y += audioDeviceSettingsComp->getHeight() + space;
  58737. }
  58738. if (midiInputsList != 0)
  58739. {
  58740. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58741. midiInputsList->setBounds (lx, y, w, bh);
  58742. y += bh + space;
  58743. }
  58744. if (midiOutputSelector != 0)
  58745. midiOutputSelector->setBounds (lx, y, w, h);
  58746. }
  58747. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58748. {
  58749. if (child == audioDeviceSettingsComp)
  58750. resized();
  58751. }
  58752. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58753. {
  58754. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58755. if (device != 0 && device->hasControlPanel())
  58756. {
  58757. if (device->showControlPanel())
  58758. deviceManager.restartLastAudioDevice();
  58759. getTopLevelComponent()->toFront (true);
  58760. }
  58761. }
  58762. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58763. {
  58764. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58765. {
  58766. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58767. if (type != 0)
  58768. {
  58769. deleteAndZero (audioDeviceSettingsComp);
  58770. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58771. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58772. }
  58773. }
  58774. else if (comboBoxThatHasChanged == midiOutputSelector)
  58775. {
  58776. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58777. }
  58778. }
  58779. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58780. {
  58781. if (deviceTypeDropDown != 0)
  58782. {
  58783. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58784. }
  58785. if (audioDeviceSettingsComp == 0
  58786. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58787. {
  58788. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58789. deleteAndZero (audioDeviceSettingsComp);
  58790. AudioIODeviceType* const type
  58791. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58792. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58793. if (type != 0)
  58794. {
  58795. AudioIODeviceType::DeviceSetupDetails details;
  58796. details.manager = &deviceManager;
  58797. details.minNumInputChannels = minInputChannels;
  58798. details.maxNumInputChannels = maxInputChannels;
  58799. details.minNumOutputChannels = minOutputChannels;
  58800. details.maxNumOutputChannels = maxOutputChannels;
  58801. details.useStereoPairs = showChannelsAsStereoPairs;
  58802. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58803. if (audioDeviceSettingsComp != 0)
  58804. {
  58805. addAndMakeVisible (audioDeviceSettingsComp);
  58806. audioDeviceSettingsComp->resized();
  58807. }
  58808. }
  58809. }
  58810. if (midiInputsList != 0)
  58811. {
  58812. midiInputsList->updateContent();
  58813. midiInputsList->repaint();
  58814. }
  58815. if (midiOutputSelector != 0)
  58816. {
  58817. midiOutputSelector->clear();
  58818. const StringArray midiOuts (MidiOutput::getDevices());
  58819. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58820. midiOutputSelector->addSeparator();
  58821. for (int i = 0; i < midiOuts.size(); ++i)
  58822. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58823. int current = -1;
  58824. if (deviceManager.getDefaultMidiOutput() != 0)
  58825. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58826. midiOutputSelector->setSelectedId (current, true);
  58827. }
  58828. resized();
  58829. }
  58830. END_JUCE_NAMESPACE
  58831. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58832. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58833. BEGIN_JUCE_NAMESPACE
  58834. BubbleComponent::BubbleComponent()
  58835. : side (0),
  58836. allowablePlacements (above | below | left | right),
  58837. arrowTipX (0.0f),
  58838. arrowTipY (0.0f)
  58839. {
  58840. setInterceptsMouseClicks (false, false);
  58841. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58842. setComponentEffect (&shadow);
  58843. }
  58844. BubbleComponent::~BubbleComponent()
  58845. {
  58846. }
  58847. void BubbleComponent::paint (Graphics& g)
  58848. {
  58849. int x = content.getX();
  58850. int y = content.getY();
  58851. int w = content.getWidth();
  58852. int h = content.getHeight();
  58853. int cw, ch;
  58854. getContentSize (cw, ch);
  58855. if (side == 3)
  58856. x += w - cw;
  58857. else if (side != 1)
  58858. x += (w - cw) / 2;
  58859. w = cw;
  58860. if (side == 2)
  58861. y += h - ch;
  58862. else if (side != 0)
  58863. y += (h - ch) / 2;
  58864. h = ch;
  58865. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58866. (float) x, (float) y,
  58867. (float) w, (float) h);
  58868. const int cx = x + (w - cw) / 2;
  58869. const int cy = y + (h - ch) / 2;
  58870. const int indent = 3;
  58871. g.setOrigin (cx + indent, cy + indent);
  58872. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58873. paintContent (g, cw - indent * 2, ch - indent * 2);
  58874. }
  58875. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58876. {
  58877. allowablePlacements = newPlacement;
  58878. }
  58879. void BubbleComponent::setPosition (Component* componentToPointTo)
  58880. {
  58881. jassert (componentToPointTo->isValidComponent());
  58882. Point<int> pos;
  58883. if (getParentComponent() != 0)
  58884. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58885. else
  58886. pos = componentToPointTo->relativePositionToGlobal (pos);
  58887. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58888. }
  58889. void BubbleComponent::setPosition (const int arrowTipX_,
  58890. const int arrowTipY_)
  58891. {
  58892. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58893. }
  58894. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58895. {
  58896. Rectangle<int> availableSpace;
  58897. if (getParentComponent() != 0)
  58898. {
  58899. availableSpace.setSize (getParentComponent()->getWidth(),
  58900. getParentComponent()->getHeight());
  58901. }
  58902. else
  58903. {
  58904. availableSpace = getParentMonitorArea();
  58905. }
  58906. int x = 0;
  58907. int y = 0;
  58908. int w = 150;
  58909. int h = 30;
  58910. getContentSize (w, h);
  58911. w += 30;
  58912. h += 30;
  58913. const float edgeIndent = 2.0f;
  58914. const int arrowLength = jmin (10, h / 3, w / 3);
  58915. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58916. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58917. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58918. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58919. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58920. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58921. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58922. {
  58923. spaceLeft = spaceRight = 0;
  58924. }
  58925. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58926. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58927. {
  58928. spaceAbove = spaceBelow = 0;
  58929. }
  58930. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58931. {
  58932. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58933. arrowTipX = w * 0.5f;
  58934. content.setSize (w, h - arrowLength);
  58935. if (spaceAbove >= spaceBelow)
  58936. {
  58937. // above
  58938. y = rectangleToPointTo.getY() - h;
  58939. content.setPosition (0, 0);
  58940. arrowTipY = h - edgeIndent;
  58941. side = 2;
  58942. }
  58943. else
  58944. {
  58945. // below
  58946. y = rectangleToPointTo.getBottom();
  58947. content.setPosition (0, arrowLength);
  58948. arrowTipY = edgeIndent;
  58949. side = 0;
  58950. }
  58951. }
  58952. else
  58953. {
  58954. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58955. arrowTipY = h * 0.5f;
  58956. content.setSize (w - arrowLength, h);
  58957. if (spaceLeft > spaceRight)
  58958. {
  58959. // on the left
  58960. x = rectangleToPointTo.getX() - w;
  58961. content.setPosition (0, 0);
  58962. arrowTipX = w - edgeIndent;
  58963. side = 3;
  58964. }
  58965. else
  58966. {
  58967. // on the right
  58968. x = rectangleToPointTo.getRight();
  58969. content.setPosition (arrowLength, 0);
  58970. arrowTipX = edgeIndent;
  58971. side = 1;
  58972. }
  58973. }
  58974. setBounds (x, y, w, h);
  58975. }
  58976. END_JUCE_NAMESPACE
  58977. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58978. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58979. BEGIN_JUCE_NAMESPACE
  58980. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58981. : fadeOutLength (fadeOutLengthMs),
  58982. deleteAfterUse (false)
  58983. {
  58984. }
  58985. BubbleMessageComponent::~BubbleMessageComponent()
  58986. {
  58987. fadeOutComponent (fadeOutLength);
  58988. }
  58989. void BubbleMessageComponent::showAt (int x, int y,
  58990. const String& text,
  58991. const int numMillisecondsBeforeRemoving,
  58992. const bool removeWhenMouseClicked,
  58993. const bool deleteSelfAfterUse)
  58994. {
  58995. textLayout.clear();
  58996. textLayout.setText (text, Font (14.0f));
  58997. textLayout.layout (256, Justification::centredLeft, true);
  58998. setPosition (x, y);
  58999. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  59000. }
  59001. void BubbleMessageComponent::showAt (Component* const component,
  59002. const String& text,
  59003. const int numMillisecondsBeforeRemoving,
  59004. const bool removeWhenMouseClicked,
  59005. const bool deleteSelfAfterUse)
  59006. {
  59007. textLayout.clear();
  59008. textLayout.setText (text, Font (14.0f));
  59009. textLayout.layout (256, Justification::centredLeft, true);
  59010. setPosition (component);
  59011. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  59012. }
  59013. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  59014. const bool removeWhenMouseClicked,
  59015. const bool deleteSelfAfterUse)
  59016. {
  59017. setVisible (true);
  59018. deleteAfterUse = deleteSelfAfterUse;
  59019. if (numMillisecondsBeforeRemoving > 0)
  59020. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  59021. else
  59022. expiryTime = 0;
  59023. startTimer (77);
  59024. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  59025. if (! (removeWhenMouseClicked && isShowing()))
  59026. mouseClickCounter += 0xfffff;
  59027. repaint();
  59028. }
  59029. void BubbleMessageComponent::getContentSize (int& w, int& h)
  59030. {
  59031. w = textLayout.getWidth() + 16;
  59032. h = textLayout.getHeight() + 16;
  59033. }
  59034. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  59035. {
  59036. g.setColour (findColour (TooltipWindow::textColourId));
  59037. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  59038. }
  59039. void BubbleMessageComponent::timerCallback()
  59040. {
  59041. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  59042. {
  59043. stopTimer();
  59044. setVisible (false);
  59045. if (deleteAfterUse)
  59046. delete this;
  59047. }
  59048. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  59049. {
  59050. stopTimer();
  59051. fadeOutComponent (fadeOutLength);
  59052. if (deleteAfterUse)
  59053. delete this;
  59054. }
  59055. }
  59056. END_JUCE_NAMESPACE
  59057. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  59058. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  59059. BEGIN_JUCE_NAMESPACE
  59060. static const int swatchesPerRow = 8;
  59061. static const int swatchHeight = 22;
  59062. class ColourComponentSlider : public Slider
  59063. {
  59064. public:
  59065. ColourComponentSlider (const String& name)
  59066. : Slider (name)
  59067. {
  59068. setRange (0.0, 255.0, 1.0);
  59069. }
  59070. ~ColourComponentSlider()
  59071. {
  59072. }
  59073. const String getTextFromValue (double value)
  59074. {
  59075. return String::formatted (T("%02X"), (int) value);
  59076. }
  59077. double getValueFromText (const String& text)
  59078. {
  59079. return (double) text.getHexValue32();
  59080. }
  59081. private:
  59082. ColourComponentSlider (const ColourComponentSlider&);
  59083. ColourComponentSlider& operator= (const ColourComponentSlider&);
  59084. };
  59085. class ColourSpaceMarker : public Component
  59086. {
  59087. public:
  59088. ColourSpaceMarker()
  59089. {
  59090. setInterceptsMouseClicks (false, false);
  59091. }
  59092. ~ColourSpaceMarker()
  59093. {
  59094. }
  59095. void paint (Graphics& g)
  59096. {
  59097. g.setColour (Colour::greyLevel (0.1f));
  59098. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  59099. g.setColour (Colour::greyLevel (0.9f));
  59100. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  59101. }
  59102. private:
  59103. ColourSpaceMarker (const ColourSpaceMarker&);
  59104. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  59105. };
  59106. class ColourSpaceView : public Component
  59107. {
  59108. ColourSelector* const owner;
  59109. float& h;
  59110. float& s;
  59111. float& v;
  59112. float lastHue;
  59113. ColourSpaceMarker* marker;
  59114. const int edge;
  59115. public:
  59116. ColourSpaceView (ColourSelector* owner_,
  59117. float& h_, float& s_, float& v_,
  59118. const int edgeSize)
  59119. : owner (owner_),
  59120. h (h_), s (s_), v (v_),
  59121. lastHue (0.0f),
  59122. edge (edgeSize)
  59123. {
  59124. addAndMakeVisible (marker = new ColourSpaceMarker());
  59125. setMouseCursor (MouseCursor::CrosshairCursor);
  59126. }
  59127. ~ColourSpaceView()
  59128. {
  59129. deleteAllChildren();
  59130. }
  59131. void paint (Graphics& g)
  59132. {
  59133. if (colours == 0)
  59134. {
  59135. const int width = getWidth() / 2;
  59136. const int height = getHeight() / 2;
  59137. colours = new Image (Image::RGB, width, height, false);
  59138. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  59139. for (int y = 0; y < height; ++y)
  59140. {
  59141. const float v = 1.0f - y / (float) height;
  59142. for (int x = 0; x < width; ++x)
  59143. {
  59144. const float s = x / (float) width;
  59145. const Colour col (h, s, v, 1.0f);
  59146. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  59147. pix->set (col.getPixelARGB());
  59148. }
  59149. }
  59150. }
  59151. g.setOpacity (1.0f);
  59152. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  59153. 0, 0, colours->getWidth(), colours->getHeight());
  59154. }
  59155. void mouseDown (const MouseEvent& e)
  59156. {
  59157. mouseDrag (e);
  59158. }
  59159. void mouseDrag (const MouseEvent& e)
  59160. {
  59161. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  59162. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  59163. owner->setSV (s, v);
  59164. }
  59165. void updateIfNeeded()
  59166. {
  59167. if (lastHue != h)
  59168. {
  59169. lastHue = h;
  59170. colours = 0;
  59171. repaint();
  59172. }
  59173. updateMarker();
  59174. }
  59175. void resized()
  59176. {
  59177. colours = 0;
  59178. updateMarker();
  59179. }
  59180. private:
  59181. ScopedPointer <Image> colours;
  59182. void updateMarker() const throw()
  59183. {
  59184. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  59185. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  59186. edge * 2, edge * 2);
  59187. }
  59188. ColourSpaceView (const ColourSpaceView&);
  59189. ColourSpaceView& operator= (const ColourSpaceView&);
  59190. };
  59191. class HueSelectorMarker : public Component
  59192. {
  59193. public:
  59194. HueSelectorMarker()
  59195. {
  59196. setInterceptsMouseClicks (false, false);
  59197. }
  59198. ~HueSelectorMarker()
  59199. {
  59200. }
  59201. void paint (Graphics& g)
  59202. {
  59203. Path p;
  59204. p.addTriangle (1.0f, 1.0f,
  59205. getWidth() * 0.3f, getHeight() * 0.5f,
  59206. 1.0f, getHeight() - 1.0f);
  59207. p.addTriangle (getWidth() - 1.0f, 1.0f,
  59208. getWidth() * 0.7f, getHeight() * 0.5f,
  59209. getWidth() - 1.0f, getHeight() - 1.0f);
  59210. g.setColour (Colours::white.withAlpha (0.75f));
  59211. g.fillPath (p);
  59212. g.setColour (Colours::black.withAlpha (0.75f));
  59213. g.strokePath (p, PathStrokeType (1.2f));
  59214. }
  59215. private:
  59216. HueSelectorMarker (const HueSelectorMarker&);
  59217. HueSelectorMarker& operator= (const HueSelectorMarker&);
  59218. };
  59219. class HueSelectorComp : public Component
  59220. {
  59221. public:
  59222. HueSelectorComp (ColourSelector* owner_,
  59223. float& h_, float& s_, float& v_,
  59224. const int edgeSize)
  59225. : owner (owner_),
  59226. h (h_), s (s_), v (v_),
  59227. lastHue (0.0f),
  59228. edge (edgeSize)
  59229. {
  59230. addAndMakeVisible (marker = new HueSelectorMarker());
  59231. }
  59232. ~HueSelectorComp()
  59233. {
  59234. deleteAllChildren();
  59235. }
  59236. void paint (Graphics& g)
  59237. {
  59238. const float yScale = 1.0f / (getHeight() - edge * 2);
  59239. const Rectangle<int> clip (g.getClipBounds());
  59240. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  59241. {
  59242. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  59243. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  59244. }
  59245. }
  59246. void resized()
  59247. {
  59248. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  59249. getWidth(), edge * 2);
  59250. }
  59251. void mouseDown (const MouseEvent& e)
  59252. {
  59253. mouseDrag (e);
  59254. }
  59255. void mouseDrag (const MouseEvent& e)
  59256. {
  59257. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  59258. owner->setHue (hue);
  59259. }
  59260. void updateIfNeeded()
  59261. {
  59262. resized();
  59263. }
  59264. private:
  59265. ColourSelector* const owner;
  59266. float& h;
  59267. float& s;
  59268. float& v;
  59269. float lastHue;
  59270. HueSelectorMarker* marker;
  59271. const int edge;
  59272. HueSelectorComp (const HueSelectorComp&);
  59273. HueSelectorComp& operator= (const HueSelectorComp&);
  59274. };
  59275. class ColourSelector::SwatchComponent : public Component
  59276. {
  59277. public:
  59278. SwatchComponent (ColourSelector* owner_, int index_)
  59279. : owner (owner_),
  59280. index (index_)
  59281. {
  59282. }
  59283. ~SwatchComponent()
  59284. {
  59285. }
  59286. void paint (Graphics& g)
  59287. {
  59288. const Colour colour (owner->getSwatchColour (index));
  59289. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  59290. 6, 6,
  59291. Colour (0xffdddddd).overlaidWith (colour),
  59292. Colour (0xffffffff).overlaidWith (colour));
  59293. }
  59294. void mouseDown (const MouseEvent&)
  59295. {
  59296. PopupMenu m;
  59297. m.addItem (1, TRANS("Use this swatch as the current colour"));
  59298. m.addSeparator();
  59299. m.addItem (2, TRANS("Set this swatch to the current colour"));
  59300. const int r = m.showAt (this);
  59301. if (r == 1)
  59302. {
  59303. owner->setCurrentColour (owner->getSwatchColour (index));
  59304. }
  59305. else if (r == 2)
  59306. {
  59307. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  59308. {
  59309. owner->setSwatchColour (index, owner->getCurrentColour());
  59310. repaint();
  59311. }
  59312. }
  59313. }
  59314. private:
  59315. ColourSelector* const owner;
  59316. const int index;
  59317. SwatchComponent (const SwatchComponent&);
  59318. SwatchComponent& operator= (const SwatchComponent&);
  59319. };
  59320. ColourSelector::ColourSelector (const int flags_,
  59321. const int edgeGap_,
  59322. const int gapAroundColourSpaceComponent)
  59323. : colour (Colours::white),
  59324. flags (flags_),
  59325. topSpace (0),
  59326. edgeGap (edgeGap_)
  59327. {
  59328. // not much point having a selector with no components in it!
  59329. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  59330. updateHSV();
  59331. if ((flags & showSliders) != 0)
  59332. {
  59333. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  59334. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  59335. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  59336. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  59337. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  59338. for (int i = 4; --i >= 0;)
  59339. sliders[i]->addListener (this);
  59340. }
  59341. else
  59342. {
  59343. zeromem (sliders, sizeof (sliders));
  59344. }
  59345. if ((flags & showColourspace) != 0)
  59346. {
  59347. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59348. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59349. }
  59350. else
  59351. {
  59352. colourSpace = 0;
  59353. hueSelector = 0;
  59354. }
  59355. update();
  59356. }
  59357. ColourSelector::~ColourSelector()
  59358. {
  59359. dispatchPendingMessages();
  59360. swatchComponents.clear();
  59361. deleteAllChildren();
  59362. }
  59363. const Colour ColourSelector::getCurrentColour() const
  59364. {
  59365. return ((flags & showAlphaChannel) != 0) ? colour
  59366. : colour.withAlpha ((uint8) 0xff);
  59367. }
  59368. void ColourSelector::setCurrentColour (const Colour& c)
  59369. {
  59370. if (c != colour)
  59371. {
  59372. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59373. updateHSV();
  59374. update();
  59375. }
  59376. }
  59377. void ColourSelector::setHue (float newH)
  59378. {
  59379. newH = jlimit (0.0f, 1.0f, newH);
  59380. if (h != newH)
  59381. {
  59382. h = newH;
  59383. colour = Colour (h, s, v, colour.getFloatAlpha());
  59384. update();
  59385. }
  59386. }
  59387. void ColourSelector::setSV (float newS, float newV)
  59388. {
  59389. newS = jlimit (0.0f, 1.0f, newS);
  59390. newV = jlimit (0.0f, 1.0f, newV);
  59391. if (s != newS || v != newV)
  59392. {
  59393. s = newS;
  59394. v = newV;
  59395. colour = Colour (h, s, v, colour.getFloatAlpha());
  59396. update();
  59397. }
  59398. }
  59399. void ColourSelector::updateHSV()
  59400. {
  59401. colour.getHSB (h, s, v);
  59402. }
  59403. void ColourSelector::update()
  59404. {
  59405. if (sliders[0] != 0)
  59406. {
  59407. sliders[0]->setValue ((int) colour.getRed());
  59408. sliders[1]->setValue ((int) colour.getGreen());
  59409. sliders[2]->setValue ((int) colour.getBlue());
  59410. sliders[3]->setValue ((int) colour.getAlpha());
  59411. }
  59412. if (colourSpace != 0)
  59413. {
  59414. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59415. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59416. }
  59417. if ((flags & showColourAtTop) != 0)
  59418. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59419. sendChangeMessage (this);
  59420. }
  59421. void ColourSelector::paint (Graphics& g)
  59422. {
  59423. g.fillAll (findColour (backgroundColourId));
  59424. if ((flags & showColourAtTop) != 0)
  59425. {
  59426. const Colour colour (getCurrentColour());
  59427. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59428. 10, 10,
  59429. Colour (0xffdddddd).overlaidWith (colour),
  59430. Colour (0xffffffff).overlaidWith (colour));
  59431. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59432. g.setFont (14.0f, true);
  59433. g.drawText (((flags & showAlphaChannel) != 0)
  59434. ? String::formatted (T("#%02X%02X%02X%02X"),
  59435. (int) colour.getAlpha(),
  59436. (int) colour.getRed(),
  59437. (int) colour.getGreen(),
  59438. (int) colour.getBlue())
  59439. : String::formatted (T("#%02X%02X%02X"),
  59440. (int) colour.getRed(),
  59441. (int) colour.getGreen(),
  59442. (int) colour.getBlue()),
  59443. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59444. Justification::centred, false);
  59445. }
  59446. if ((flags & showSliders) != 0)
  59447. {
  59448. g.setColour (findColour (labelTextColourId));
  59449. g.setFont (11.0f);
  59450. for (int i = 4; --i >= 0;)
  59451. {
  59452. if (sliders[i]->isVisible())
  59453. g.drawText (sliders[i]->getName() + T(":"),
  59454. 0, sliders[i]->getY(),
  59455. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59456. Justification::centredRight, false);
  59457. }
  59458. }
  59459. }
  59460. void ColourSelector::resized()
  59461. {
  59462. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59463. const int numSwatches = getNumSwatches();
  59464. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59465. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59466. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59467. int y = topSpace;
  59468. if ((flags & showColourspace) != 0)
  59469. {
  59470. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59471. colourSpace->setBounds (edgeGap, y,
  59472. getWidth() - hueWidth - edgeGap - 4,
  59473. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59474. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59475. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59476. colourSpace->getHeight());
  59477. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59478. }
  59479. if ((flags & showSliders) != 0)
  59480. {
  59481. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59482. for (int i = 0; i < numSliders; ++i)
  59483. {
  59484. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59485. proportionOfWidth (0.72f), sliderHeight - 2);
  59486. y += sliderHeight;
  59487. }
  59488. }
  59489. if (numSwatches > 0)
  59490. {
  59491. const int startX = 8;
  59492. const int xGap = 4;
  59493. const int yGap = 4;
  59494. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59495. y += edgeGap;
  59496. if (swatchComponents.size() != numSwatches)
  59497. {
  59498. swatchComponents.clear();
  59499. for (int i = 0; i < numSwatches; ++i)
  59500. {
  59501. SwatchComponent* const sc = new SwatchComponent (this, i);
  59502. swatchComponents.add (sc);
  59503. addAndMakeVisible (sc);
  59504. }
  59505. }
  59506. int x = startX;
  59507. for (int i = 0; i < swatchComponents.size(); ++i)
  59508. {
  59509. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59510. sc->setBounds (x + xGap / 2,
  59511. y + yGap / 2,
  59512. swatchWidth - xGap,
  59513. swatchHeight - yGap);
  59514. if (((i + 1) % swatchesPerRow) == 0)
  59515. {
  59516. x = startX;
  59517. y += swatchHeight;
  59518. }
  59519. else
  59520. {
  59521. x += swatchWidth;
  59522. }
  59523. }
  59524. }
  59525. }
  59526. void ColourSelector::sliderValueChanged (Slider*)
  59527. {
  59528. if (sliders[0] != 0)
  59529. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59530. (uint8) sliders[1]->getValue(),
  59531. (uint8) sliders[2]->getValue(),
  59532. (uint8) sliders[3]->getValue()));
  59533. }
  59534. int ColourSelector::getNumSwatches() const
  59535. {
  59536. return 0;
  59537. }
  59538. const Colour ColourSelector::getSwatchColour (const int) const
  59539. {
  59540. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59541. return Colours::black;
  59542. }
  59543. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59544. {
  59545. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59546. }
  59547. END_JUCE_NAMESPACE
  59548. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59549. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59550. BEGIN_JUCE_NAMESPACE
  59551. class ShadowWindow : public Component
  59552. {
  59553. Component* owner;
  59554. Image** shadowImageSections;
  59555. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59556. public:
  59557. ShadowWindow (Component* const owner_,
  59558. const int type_,
  59559. Image** const shadowImageSections_)
  59560. : owner (owner_),
  59561. shadowImageSections (shadowImageSections_),
  59562. type (type_)
  59563. {
  59564. setInterceptsMouseClicks (false, false);
  59565. if (owner_->isOnDesktop())
  59566. {
  59567. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59568. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59569. | ComponentPeer::windowIsTemporary
  59570. | ComponentPeer::windowIgnoresKeyPresses);
  59571. }
  59572. else if (owner_->getParentComponent() != 0)
  59573. {
  59574. owner_->getParentComponent()->addChildComponent (this);
  59575. }
  59576. }
  59577. ~ShadowWindow()
  59578. {
  59579. }
  59580. void paint (Graphics& g)
  59581. {
  59582. Image* const topLeft = shadowImageSections [type * 3];
  59583. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59584. Image* const filler = shadowImageSections [type * 3 + 2];
  59585. g.setOpacity (1.0f);
  59586. if (type < 2)
  59587. {
  59588. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59589. g.drawImage (topLeft,
  59590. 0, 0, topLeft->getWidth(), imH,
  59591. 0, 0, topLeft->getWidth(), imH);
  59592. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59593. g.drawImage (bottomRight,
  59594. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59595. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59596. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59597. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59598. }
  59599. else
  59600. {
  59601. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59602. g.drawImage (topLeft,
  59603. 0, 0, imW, topLeft->getHeight(),
  59604. 0, 0, imW, topLeft->getHeight());
  59605. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59606. g.drawImage (bottomRight,
  59607. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59608. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59609. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59610. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59611. }
  59612. }
  59613. void resized()
  59614. {
  59615. repaint(); // (needed for correct repainting)
  59616. }
  59617. private:
  59618. ShadowWindow (const ShadowWindow&);
  59619. ShadowWindow& operator= (const ShadowWindow&);
  59620. };
  59621. DropShadower::DropShadower (const float alpha_,
  59622. const int xOffset_,
  59623. const int yOffset_,
  59624. const float blurRadius_)
  59625. : owner (0),
  59626. numShadows (0),
  59627. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59628. xOffset (xOffset_),
  59629. yOffset (yOffset_),
  59630. alpha (alpha_),
  59631. blurRadius (blurRadius_),
  59632. inDestructor (false),
  59633. reentrant (false)
  59634. {
  59635. }
  59636. DropShadower::~DropShadower()
  59637. {
  59638. if (owner != 0)
  59639. owner->removeComponentListener (this);
  59640. inDestructor = true;
  59641. deleteShadowWindows();
  59642. }
  59643. void DropShadower::deleteShadowWindows()
  59644. {
  59645. if (numShadows > 0)
  59646. {
  59647. int i;
  59648. for (i = numShadows; --i >= 0;)
  59649. delete shadowWindows[i];
  59650. for (i = 12; --i >= 0;)
  59651. delete shadowImageSections[i];
  59652. numShadows = 0;
  59653. }
  59654. }
  59655. void DropShadower::setOwner (Component* componentToFollow)
  59656. {
  59657. if (componentToFollow != owner)
  59658. {
  59659. if (owner != 0)
  59660. owner->removeComponentListener (this);
  59661. // (the component can't be null)
  59662. jassert (componentToFollow != 0);
  59663. owner = componentToFollow;
  59664. jassert (owner != 0);
  59665. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59666. owner->addComponentListener (this);
  59667. updateShadows();
  59668. }
  59669. }
  59670. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59671. {
  59672. updateShadows();
  59673. }
  59674. void DropShadower::componentBroughtToFront (Component&)
  59675. {
  59676. bringShadowWindowsToFront();
  59677. }
  59678. void DropShadower::componentChildrenChanged (Component&)
  59679. {
  59680. }
  59681. void DropShadower::componentParentHierarchyChanged (Component&)
  59682. {
  59683. deleteShadowWindows();
  59684. updateShadows();
  59685. }
  59686. void DropShadower::componentVisibilityChanged (Component&)
  59687. {
  59688. updateShadows();
  59689. }
  59690. void DropShadower::updateShadows()
  59691. {
  59692. if (reentrant || inDestructor || (owner == 0))
  59693. return;
  59694. reentrant = true;
  59695. ComponentPeer* const nw = owner->getPeer();
  59696. const bool isOwnerVisible = owner->isVisible()
  59697. && (nw == 0 || ! nw->isMinimised());
  59698. const bool createShadowWindows = numShadows == 0
  59699. && owner->getWidth() > 0
  59700. && owner->getHeight() > 0
  59701. && isOwnerVisible
  59702. && (Desktop::canUseSemiTransparentWindows()
  59703. || owner->getParentComponent() != 0);
  59704. if (createShadowWindows)
  59705. {
  59706. // keep a cached version of the image to save doing the gaussian too often
  59707. String imageId;
  59708. imageId << shadowEdge << T(',')
  59709. << xOffset << T(',')
  59710. << yOffset << T(',')
  59711. << alpha;
  59712. const int hash = imageId.hashCode();
  59713. Image* bigIm = ImageCache::getFromHashCode (hash);
  59714. if (bigIm == 0)
  59715. {
  59716. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59717. Graphics bigG (*bigIm);
  59718. bigG.setColour (Colours::black.withAlpha (alpha));
  59719. bigG.fillRect (shadowEdge + xOffset,
  59720. shadowEdge + yOffset,
  59721. bigIm->getWidth() - (shadowEdge * 2),
  59722. bigIm->getHeight() - (shadowEdge * 2));
  59723. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59724. blurKernel.createGaussianBlur (blurRadius);
  59725. blurKernel.applyToImage (*bigIm, 0,
  59726. xOffset,
  59727. yOffset,
  59728. bigIm->getWidth(),
  59729. bigIm->getHeight());
  59730. ImageCache::addImageToCache (bigIm, hash);
  59731. }
  59732. const int iw = bigIm->getWidth();
  59733. const int ih = bigIm->getHeight();
  59734. const int shadowEdge2 = shadowEdge * 2;
  59735. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59736. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59737. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59738. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59739. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59740. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59741. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59742. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59743. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59744. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59745. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59746. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59747. ImageCache::release (bigIm);
  59748. for (int i = 0; i < 4; ++i)
  59749. {
  59750. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59751. ++numShadows;
  59752. }
  59753. }
  59754. if (numShadows > 0)
  59755. {
  59756. for (int i = numShadows; --i >= 0;)
  59757. {
  59758. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59759. shadowWindows[i]->setVisible (isOwnerVisible);
  59760. }
  59761. const int x = owner->getX();
  59762. const int y = owner->getY() - shadowEdge;
  59763. const int w = owner->getWidth();
  59764. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59765. shadowWindows[0]->setBounds (x - shadowEdge,
  59766. y,
  59767. shadowEdge,
  59768. h);
  59769. shadowWindows[1]->setBounds (x + w,
  59770. y,
  59771. shadowEdge,
  59772. h);
  59773. shadowWindows[2]->setBounds (x,
  59774. y,
  59775. w,
  59776. shadowEdge);
  59777. shadowWindows[3]->setBounds (x,
  59778. owner->getBottom(),
  59779. w,
  59780. shadowEdge);
  59781. }
  59782. reentrant = false;
  59783. if (createShadowWindows)
  59784. bringShadowWindowsToFront();
  59785. }
  59786. void DropShadower::setShadowImage (Image* const src,
  59787. const int num,
  59788. const int w,
  59789. const int h,
  59790. const int sx,
  59791. const int sy)
  59792. {
  59793. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59794. Graphics g (*shadowImageSections[num]);
  59795. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59796. }
  59797. void DropShadower::bringShadowWindowsToFront()
  59798. {
  59799. if (! (inDestructor || reentrant))
  59800. {
  59801. updateShadows();
  59802. reentrant = true;
  59803. for (int i = numShadows; --i >= 0;)
  59804. shadowWindows[i]->toBehind (owner);
  59805. reentrant = false;
  59806. }
  59807. }
  59808. END_JUCE_NAMESPACE
  59809. /*** End of inlined file: juce_DropShadower.cpp ***/
  59810. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59811. BEGIN_JUCE_NAMESPACE
  59812. class MagnifyingPeer : public ComponentPeer
  59813. {
  59814. public:
  59815. MagnifyingPeer (Component* const component_,
  59816. MagnifierComponent* const magnifierComp_)
  59817. : ComponentPeer (component_, 0),
  59818. magnifierComp (magnifierComp_)
  59819. {
  59820. }
  59821. ~MagnifyingPeer()
  59822. {
  59823. }
  59824. void* getNativeHandle() const { return 0; }
  59825. void setVisible (bool) {}
  59826. void setTitle (const String&) {}
  59827. void setPosition (int, int) {}
  59828. void setSize (int, int) {}
  59829. void setBounds (int, int, int, int, const bool) {}
  59830. void setMinimised (bool) {}
  59831. bool isMinimised() const { return false; }
  59832. void setFullScreen (bool) {}
  59833. bool isFullScreen() const { return false; }
  59834. const BorderSize getFrameSize() const { return BorderSize (0); }
  59835. bool setAlwaysOnTop (bool) { return true; }
  59836. void toFront (bool) {}
  59837. void toBehind (ComponentPeer*) {}
  59838. void setIcon (const Image&) {}
  59839. bool isFocused() const
  59840. {
  59841. return magnifierComp->hasKeyboardFocus (true);
  59842. }
  59843. void grabFocus()
  59844. {
  59845. ComponentPeer* peer = magnifierComp->getPeer();
  59846. if (peer != 0)
  59847. peer->grabFocus();
  59848. }
  59849. void textInputRequired (const Point<int>& position)
  59850. {
  59851. ComponentPeer* peer = magnifierComp->getPeer();
  59852. if (peer != 0)
  59853. peer->textInputRequired (position);
  59854. }
  59855. const Rectangle<int> getBounds() const
  59856. {
  59857. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59858. component->getWidth(), component->getHeight());
  59859. }
  59860. const Point<int> getScreenPosition() const
  59861. {
  59862. return magnifierComp->getScreenPosition();
  59863. }
  59864. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59865. {
  59866. const double zoom = magnifierComp->getScaleFactor();
  59867. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59868. roundToInt (relativePosition.getY() * zoom)));
  59869. }
  59870. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59871. {
  59872. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59873. const double zoom = magnifierComp->getScaleFactor();
  59874. return Point<int> (roundToInt (p.getX() / zoom),
  59875. roundToInt (p.getY() / zoom));
  59876. }
  59877. bool contains (const Point<int>& position, bool) const
  59878. {
  59879. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59880. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59881. }
  59882. void repaint (int x, int y, int w, int h)
  59883. {
  59884. const double zoom = magnifierComp->getScaleFactor();
  59885. magnifierComp->repaint ((int) (x * zoom),
  59886. (int) (y * zoom),
  59887. roundToInt (w * zoom) + 1,
  59888. roundToInt (h * zoom) + 1);
  59889. }
  59890. void performAnyPendingRepaintsNow()
  59891. {
  59892. }
  59893. juce_UseDebuggingNewOperator
  59894. private:
  59895. MagnifierComponent* const magnifierComp;
  59896. MagnifyingPeer (const MagnifyingPeer&);
  59897. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59898. };
  59899. class PeerHolderComp : public Component
  59900. {
  59901. public:
  59902. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59903. : magnifierComp (magnifierComp_)
  59904. {
  59905. setVisible (true);
  59906. }
  59907. ~PeerHolderComp()
  59908. {
  59909. }
  59910. ComponentPeer* createNewPeer (int, void*)
  59911. {
  59912. return new MagnifyingPeer (this, magnifierComp);
  59913. }
  59914. void childBoundsChanged (Component* c)
  59915. {
  59916. if (c != 0)
  59917. {
  59918. setSize (c->getWidth(), c->getHeight());
  59919. magnifierComp->childBoundsChanged (this);
  59920. }
  59921. }
  59922. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59923. {
  59924. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59925. Component* const p = magnifierComp->getParentComponent();
  59926. if (p != 0)
  59927. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59928. }
  59929. private:
  59930. MagnifierComponent* const magnifierComp;
  59931. PeerHolderComp (const PeerHolderComp&);
  59932. PeerHolderComp& operator= (const PeerHolderComp&);
  59933. };
  59934. MagnifierComponent::MagnifierComponent (Component* const content_,
  59935. const bool deleteContentCompWhenNoLongerNeeded)
  59936. : content (content_),
  59937. scaleFactor (0.0),
  59938. peer (0),
  59939. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59940. quality (Graphics::lowResamplingQuality),
  59941. mouseSource (0, true)
  59942. {
  59943. holderComp = new PeerHolderComp (this);
  59944. setScaleFactor (1.0);
  59945. }
  59946. MagnifierComponent::~MagnifierComponent()
  59947. {
  59948. delete holderComp;
  59949. if (deleteContent)
  59950. delete content;
  59951. }
  59952. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59953. {
  59954. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59955. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59956. if (scaleFactor != newScaleFactor)
  59957. {
  59958. scaleFactor = newScaleFactor;
  59959. if (scaleFactor == 1.0)
  59960. {
  59961. holderComp->removeFromDesktop();
  59962. peer = 0;
  59963. addChildComponent (content);
  59964. childBoundsChanged (content);
  59965. }
  59966. else
  59967. {
  59968. holderComp->addAndMakeVisible (content);
  59969. holderComp->childBoundsChanged (content);
  59970. childBoundsChanged (holderComp);
  59971. holderComp->addToDesktop (0);
  59972. peer = holderComp->getPeer();
  59973. }
  59974. repaint();
  59975. }
  59976. }
  59977. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59978. {
  59979. quality = newQuality;
  59980. }
  59981. void MagnifierComponent::paint (Graphics& g)
  59982. {
  59983. const int w = holderComp->getWidth();
  59984. const int h = holderComp->getHeight();
  59985. if (w == 0 || h == 0)
  59986. return;
  59987. const Rectangle<int> r (g.getClipBounds());
  59988. const int srcX = (int) (r.getX() / scaleFactor);
  59989. const int srcY = (int) (r.getY() / scaleFactor);
  59990. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59991. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59992. if (scaleFactor >= 1.0)
  59993. {
  59994. ++srcW;
  59995. ++srcH;
  59996. }
  59997. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59998. temp.clear (srcX, srcY, srcW, srcH);
  59999. {
  60000. Graphics g2 (temp);
  60001. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  60002. holderComp->paintEntireComponent (g2);
  60003. }
  60004. g.setImageResamplingQuality (quality);
  60005. g.drawImageTransformed (&temp, temp.getBounds(),
  60006. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  60007. false);
  60008. }
  60009. void MagnifierComponent::childBoundsChanged (Component* c)
  60010. {
  60011. if (c != 0)
  60012. setSize (roundToInt (c->getWidth() * scaleFactor),
  60013. roundToInt (c->getHeight() * scaleFactor));
  60014. }
  60015. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  60016. {
  60017. if (peer != 0)
  60018. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  60019. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  60020. }
  60021. void MagnifierComponent::mouseDown (const MouseEvent& e)
  60022. {
  60023. passOnMouseEventToPeer (e);
  60024. }
  60025. void MagnifierComponent::mouseUp (const MouseEvent& e)
  60026. {
  60027. passOnMouseEventToPeer (e);
  60028. }
  60029. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  60030. {
  60031. passOnMouseEventToPeer (e);
  60032. }
  60033. void MagnifierComponent::mouseMove (const MouseEvent& e)
  60034. {
  60035. passOnMouseEventToPeer (e);
  60036. }
  60037. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  60038. {
  60039. passOnMouseEventToPeer (e);
  60040. }
  60041. void MagnifierComponent::mouseExit (const MouseEvent& e)
  60042. {
  60043. passOnMouseEventToPeer (e);
  60044. }
  60045. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  60046. {
  60047. if (peer != 0)
  60048. peer->handleMouseWheel (Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  60049. ix * 256.0f, iy * 256.0f);
  60050. else
  60051. Component::mouseWheelMove (e, ix, iy);
  60052. }
  60053. int MagnifierComponent::scaleInt (const int n) const
  60054. {
  60055. return roundToInt (n / scaleFactor);
  60056. }
  60057. END_JUCE_NAMESPACE
  60058. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  60059. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60060. BEGIN_JUCE_NAMESPACE
  60061. class MidiKeyboardUpDownButton : public Button
  60062. {
  60063. public:
  60064. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  60065. const int delta_)
  60066. : Button (String::empty),
  60067. owner (owner_),
  60068. delta (delta_)
  60069. {
  60070. setOpaque (true);
  60071. }
  60072. ~MidiKeyboardUpDownButton()
  60073. {
  60074. }
  60075. void clicked()
  60076. {
  60077. int note = owner->getLowestVisibleKey();
  60078. if (delta < 0)
  60079. note = (note - 1) / 12;
  60080. else
  60081. note = note / 12 + 1;
  60082. owner->setLowestVisibleKey (note * 12);
  60083. }
  60084. void paintButton (Graphics& g,
  60085. bool isMouseOverButton,
  60086. bool isButtonDown)
  60087. {
  60088. owner->drawUpDownButton (g, getWidth(), getHeight(),
  60089. isMouseOverButton, isButtonDown,
  60090. delta > 0);
  60091. }
  60092. private:
  60093. MidiKeyboardComponent* const owner;
  60094. const int delta;
  60095. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  60096. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  60097. };
  60098. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  60099. const Orientation orientation_)
  60100. : state (state_),
  60101. xOffset (0),
  60102. blackNoteLength (1),
  60103. keyWidth (16.0f),
  60104. orientation (orientation_),
  60105. midiChannel (1),
  60106. midiInChannelMask (0xffff),
  60107. velocity (1.0f),
  60108. noteUnderMouse (-1),
  60109. mouseDownNote (-1),
  60110. rangeStart (0),
  60111. rangeEnd (127),
  60112. firstKey (12 * 4),
  60113. canScroll (true),
  60114. mouseDragging (false),
  60115. useMousePositionForVelocity (true),
  60116. keyMappingOctave (6),
  60117. octaveNumForMiddleC (3)
  60118. {
  60119. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  60120. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  60121. // initialise with a default set of querty key-mappings..
  60122. const char* const keymap = "awsedftgyhujkolp;";
  60123. for (int i = String (keymap).length(); --i >= 0;)
  60124. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  60125. setOpaque (true);
  60126. setWantsKeyboardFocus (true);
  60127. state.addListener (this);
  60128. }
  60129. MidiKeyboardComponent::~MidiKeyboardComponent()
  60130. {
  60131. state.removeListener (this);
  60132. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  60133. deleteAllChildren();
  60134. }
  60135. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  60136. {
  60137. keyWidth = widthInPixels;
  60138. resized();
  60139. }
  60140. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  60141. {
  60142. if (orientation != newOrientation)
  60143. {
  60144. orientation = newOrientation;
  60145. resized();
  60146. }
  60147. }
  60148. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  60149. const int highestNote)
  60150. {
  60151. jassert (lowestNote >= 0 && lowestNote <= 127);
  60152. jassert (highestNote >= 0 && highestNote <= 127);
  60153. jassert (lowestNote <= highestNote);
  60154. if (rangeStart != lowestNote || rangeEnd != highestNote)
  60155. {
  60156. rangeStart = jlimit (0, 127, lowestNote);
  60157. rangeEnd = jlimit (0, 127, highestNote);
  60158. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  60159. resized();
  60160. }
  60161. }
  60162. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  60163. {
  60164. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  60165. if (noteNumber != firstKey)
  60166. {
  60167. firstKey = noteNumber;
  60168. sendChangeMessage (this);
  60169. resized();
  60170. }
  60171. }
  60172. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  60173. {
  60174. if (canScroll != canScroll_)
  60175. {
  60176. canScroll = canScroll_;
  60177. resized();
  60178. }
  60179. }
  60180. void MidiKeyboardComponent::colourChanged()
  60181. {
  60182. repaint();
  60183. }
  60184. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  60185. {
  60186. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  60187. if (midiChannel != midiChannelNumber)
  60188. {
  60189. resetAnyKeysInUse();
  60190. midiChannel = jlimit (1, 16, midiChannelNumber);
  60191. }
  60192. }
  60193. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  60194. {
  60195. midiInChannelMask = midiChannelMask;
  60196. triggerAsyncUpdate();
  60197. }
  60198. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  60199. {
  60200. velocity = jlimit (0.0f, 1.0f, velocity_);
  60201. useMousePositionForVelocity = useMousePositionForVelocity_;
  60202. }
  60203. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  60204. {
  60205. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  60206. static const float blackNoteWidth = 0.7f;
  60207. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  60208. 1.0f, 2 - blackNoteWidth * 0.4f,
  60209. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  60210. 4.0f, 5 - blackNoteWidth * 0.5f,
  60211. 5.0f, 6 - blackNoteWidth * 0.3f,
  60212. 6.0f };
  60213. static const float widths[] = { 1.0f, blackNoteWidth,
  60214. 1.0f, blackNoteWidth,
  60215. 1.0f, 1.0f, blackNoteWidth,
  60216. 1.0f, blackNoteWidth,
  60217. 1.0f, blackNoteWidth,
  60218. 1.0f };
  60219. const int octave = midiNoteNumber / 12;
  60220. const int note = midiNoteNumber % 12;
  60221. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  60222. w = roundToInt (widths [note] * keyWidth);
  60223. }
  60224. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  60225. {
  60226. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  60227. int rx, rw;
  60228. getKeyPosition (rangeStart, keyWidth, rx, rw);
  60229. x -= xOffset + rx;
  60230. }
  60231. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  60232. {
  60233. int x, y;
  60234. getKeyPos (midiNoteNumber, x, y);
  60235. return x;
  60236. }
  60237. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  60238. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  60239. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  60240. {
  60241. if (! reallyContains (pos.getX(), pos.getY(), false))
  60242. return -1;
  60243. Point<int> p (pos);
  60244. if (orientation != horizontalKeyboard)
  60245. {
  60246. p = Point<int> (p.getY(), p.getX());
  60247. if (orientation == verticalKeyboardFacingLeft)
  60248. p = Point<int> (p.getX(), getWidth() - p.getY());
  60249. else
  60250. p = Point<int> (getHeight() - p.getX(), p.getY());
  60251. }
  60252. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  60253. }
  60254. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  60255. {
  60256. if (pos.getY() < blackNoteLength)
  60257. {
  60258. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60259. {
  60260. for (int i = 0; i < 5; ++i)
  60261. {
  60262. const int note = octaveStart + blackNotes [i];
  60263. if (note >= rangeStart && note <= rangeEnd)
  60264. {
  60265. int kx, kw;
  60266. getKeyPos (note, kx, kw);
  60267. kx += xOffset;
  60268. if (pos.getX() >= kx && pos.getX() < kx + kw)
  60269. {
  60270. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  60271. return note;
  60272. }
  60273. }
  60274. }
  60275. }
  60276. }
  60277. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60278. {
  60279. for (int i = 0; i < 7; ++i)
  60280. {
  60281. const int note = octaveStart + whiteNotes [i];
  60282. if (note >= rangeStart && note <= rangeEnd)
  60283. {
  60284. int kx, kw;
  60285. getKeyPos (note, kx, kw);
  60286. kx += xOffset;
  60287. if (pos.getX() >= kx && pos.getX() < kx + kw)
  60288. {
  60289. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  60290. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  60291. return note;
  60292. }
  60293. }
  60294. }
  60295. }
  60296. mousePositionVelocity = 0;
  60297. return -1;
  60298. }
  60299. void MidiKeyboardComponent::repaintNote (const int noteNum)
  60300. {
  60301. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60302. {
  60303. int x, w;
  60304. getKeyPos (noteNum, x, w);
  60305. if (orientation == horizontalKeyboard)
  60306. repaint (x, 0, w, getHeight());
  60307. else if (orientation == verticalKeyboardFacingLeft)
  60308. repaint (0, x, getWidth(), w);
  60309. else if (orientation == verticalKeyboardFacingRight)
  60310. repaint (0, getHeight() - x - w, getWidth(), w);
  60311. }
  60312. }
  60313. void MidiKeyboardComponent::paint (Graphics& g)
  60314. {
  60315. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  60316. const Colour lineColour (findColour (keySeparatorLineColourId));
  60317. const Colour textColour (findColour (textLabelColourId));
  60318. int x, w, octave;
  60319. for (octave = 0; octave < 128; octave += 12)
  60320. {
  60321. for (int white = 0; white < 7; ++white)
  60322. {
  60323. const int noteNum = octave + whiteNotes [white];
  60324. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60325. {
  60326. getKeyPos (noteNum, x, w);
  60327. if (orientation == horizontalKeyboard)
  60328. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  60329. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60330. noteUnderMouse == noteNum,
  60331. lineColour, textColour);
  60332. else if (orientation == verticalKeyboardFacingLeft)
  60333. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  60334. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60335. noteUnderMouse == noteNum,
  60336. lineColour, textColour);
  60337. else if (orientation == verticalKeyboardFacingRight)
  60338. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  60339. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60340. noteUnderMouse == noteNum,
  60341. lineColour, textColour);
  60342. }
  60343. }
  60344. }
  60345. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  60346. if (orientation == verticalKeyboardFacingLeft)
  60347. {
  60348. x1 = getWidth() - 1.0f;
  60349. x2 = getWidth() - 5.0f;
  60350. }
  60351. else if (orientation == verticalKeyboardFacingRight)
  60352. x2 = 5.0f;
  60353. else
  60354. y2 = 5.0f;
  60355. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60356. Colours::transparentBlack, x2, y2, false));
  60357. getKeyPos (rangeEnd, x, w);
  60358. x += w;
  60359. if (orientation == verticalKeyboardFacingLeft)
  60360. g.fillRect (getWidth() - 5, 0, 5, x);
  60361. else if (orientation == verticalKeyboardFacingRight)
  60362. g.fillRect (0, 0, 5, x);
  60363. else
  60364. g.fillRect (0, 0, x, 5);
  60365. g.setColour (lineColour);
  60366. if (orientation == verticalKeyboardFacingLeft)
  60367. g.fillRect (0, 0, 1, x);
  60368. else if (orientation == verticalKeyboardFacingRight)
  60369. g.fillRect (getWidth() - 1, 0, 1, x);
  60370. else
  60371. g.fillRect (0, getHeight() - 1, x, 1);
  60372. const Colour blackNoteColour (findColour (blackNoteColourId));
  60373. for (octave = 0; octave < 128; octave += 12)
  60374. {
  60375. for (int black = 0; black < 5; ++black)
  60376. {
  60377. const int noteNum = octave + blackNotes [black];
  60378. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60379. {
  60380. getKeyPos (noteNum, x, w);
  60381. if (orientation == horizontalKeyboard)
  60382. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60383. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60384. noteUnderMouse == noteNum,
  60385. blackNoteColour);
  60386. else if (orientation == verticalKeyboardFacingLeft)
  60387. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60388. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60389. noteUnderMouse == noteNum,
  60390. blackNoteColour);
  60391. else if (orientation == verticalKeyboardFacingRight)
  60392. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60393. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60394. noteUnderMouse == noteNum,
  60395. blackNoteColour);
  60396. }
  60397. }
  60398. }
  60399. }
  60400. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60401. Graphics& g, int x, int y, int w, int h,
  60402. bool isDown, bool isOver,
  60403. const Colour& lineColour,
  60404. const Colour& textColour)
  60405. {
  60406. Colour c (Colours::transparentWhite);
  60407. if (isDown)
  60408. c = findColour (keyDownOverlayColourId);
  60409. if (isOver)
  60410. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60411. g.setColour (c);
  60412. g.fillRect (x, y, w, h);
  60413. const String text (getWhiteNoteText (midiNoteNumber));
  60414. if (! text.isEmpty())
  60415. {
  60416. g.setColour (textColour);
  60417. Font f (jmin (12.0f, keyWidth * 0.9f));
  60418. f.setHorizontalScale (0.8f);
  60419. g.setFont (f);
  60420. Justification justification (Justification::centredBottom);
  60421. if (orientation == verticalKeyboardFacingLeft)
  60422. justification = Justification::centredLeft;
  60423. else if (orientation == verticalKeyboardFacingRight)
  60424. justification = Justification::centredRight;
  60425. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60426. }
  60427. g.setColour (lineColour);
  60428. if (orientation == horizontalKeyboard)
  60429. g.fillRect (x, y, 1, h);
  60430. else if (orientation == verticalKeyboardFacingLeft)
  60431. g.fillRect (x, y, w, 1);
  60432. else if (orientation == verticalKeyboardFacingRight)
  60433. g.fillRect (x, y + h - 1, w, 1);
  60434. if (midiNoteNumber == rangeEnd)
  60435. {
  60436. if (orientation == horizontalKeyboard)
  60437. g.fillRect (x + w, y, 1, h);
  60438. else if (orientation == verticalKeyboardFacingLeft)
  60439. g.fillRect (x, y + h, w, 1);
  60440. else if (orientation == verticalKeyboardFacingRight)
  60441. g.fillRect (x, y - 1, w, 1);
  60442. }
  60443. }
  60444. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60445. Graphics& g, int x, int y, int w, int h,
  60446. bool isDown, bool isOver,
  60447. const Colour& noteFillColour)
  60448. {
  60449. Colour c (noteFillColour);
  60450. if (isDown)
  60451. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60452. if (isOver)
  60453. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60454. g.setColour (c);
  60455. g.fillRect (x, y, w, h);
  60456. if (isDown)
  60457. {
  60458. g.setColour (noteFillColour);
  60459. g.drawRect (x, y, w, h);
  60460. }
  60461. else
  60462. {
  60463. const int xIndent = jmax (1, jmin (w, h) / 8);
  60464. g.setColour (c.brighter());
  60465. if (orientation == horizontalKeyboard)
  60466. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60467. else if (orientation == verticalKeyboardFacingLeft)
  60468. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60469. else if (orientation == verticalKeyboardFacingRight)
  60470. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60471. }
  60472. }
  60473. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60474. {
  60475. octaveNumForMiddleC = octaveNumForMiddleC_;
  60476. repaint();
  60477. }
  60478. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60479. {
  60480. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60481. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60482. return String::empty;
  60483. }
  60484. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60485. const bool isMouseOver,
  60486. const bool isButtonDown,
  60487. const bool movesOctavesUp)
  60488. {
  60489. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60490. float angle;
  60491. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60492. angle = movesOctavesUp ? 0.0f : 0.5f;
  60493. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60494. angle = movesOctavesUp ? 0.25f : 0.75f;
  60495. else
  60496. angle = movesOctavesUp ? 0.75f : 0.25f;
  60497. Path path;
  60498. path.lineTo (0.0f, 1.0f);
  60499. path.lineTo (1.0f, 0.5f);
  60500. path.closeSubPath();
  60501. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60502. g.setColour (findColour (upDownButtonArrowColourId)
  60503. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60504. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60505. w - 2.0f,
  60506. h - 2.0f,
  60507. true));
  60508. }
  60509. void MidiKeyboardComponent::resized()
  60510. {
  60511. int w = getWidth();
  60512. int h = getHeight();
  60513. if (w > 0 && h > 0)
  60514. {
  60515. if (orientation != horizontalKeyboard)
  60516. swapVariables (w, h);
  60517. blackNoteLength = roundToInt (h * 0.7f);
  60518. int kx2, kw2;
  60519. getKeyPos (rangeEnd, kx2, kw2);
  60520. kx2 += kw2;
  60521. if (firstKey != rangeStart)
  60522. {
  60523. int kx1, kw1;
  60524. getKeyPos (rangeStart, kx1, kw1);
  60525. if (kx2 - kx1 <= w)
  60526. {
  60527. firstKey = rangeStart;
  60528. sendChangeMessage (this);
  60529. repaint();
  60530. }
  60531. }
  60532. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60533. scrollDown->setVisible (showScrollButtons);
  60534. scrollUp->setVisible (showScrollButtons);
  60535. xOffset = 0;
  60536. if (showScrollButtons)
  60537. {
  60538. const int scrollButtonW = jmin (12, w / 2);
  60539. if (orientation == horizontalKeyboard)
  60540. {
  60541. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60542. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60543. }
  60544. else if (orientation == verticalKeyboardFacingLeft)
  60545. {
  60546. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60547. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60548. }
  60549. else if (orientation == verticalKeyboardFacingRight)
  60550. {
  60551. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60552. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60553. }
  60554. int endOfLastKey, kw;
  60555. getKeyPos (rangeEnd, endOfLastKey, kw);
  60556. endOfLastKey += kw;
  60557. float mousePositionVelocity;
  60558. const int spaceAvailable = w - scrollButtonW * 2;
  60559. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60560. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60561. {
  60562. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60563. sendChangeMessage (this);
  60564. }
  60565. int newOffset = 0;
  60566. getKeyPos (firstKey, newOffset, kw);
  60567. xOffset = newOffset - scrollButtonW;
  60568. }
  60569. else
  60570. {
  60571. firstKey = rangeStart;
  60572. }
  60573. timerCallback();
  60574. repaint();
  60575. }
  60576. }
  60577. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60578. {
  60579. triggerAsyncUpdate();
  60580. }
  60581. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60582. {
  60583. triggerAsyncUpdate();
  60584. }
  60585. void MidiKeyboardComponent::handleAsyncUpdate()
  60586. {
  60587. for (int i = rangeStart; i <= rangeEnd; ++i)
  60588. {
  60589. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60590. {
  60591. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60592. repaintNote (i);
  60593. }
  60594. }
  60595. }
  60596. void MidiKeyboardComponent::resetAnyKeysInUse()
  60597. {
  60598. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60599. {
  60600. state.allNotesOff (midiChannel);
  60601. keysPressed.clear();
  60602. mouseDownNote = -1;
  60603. }
  60604. }
  60605. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60606. {
  60607. float mousePositionVelocity = 0.0f;
  60608. const int newNote = (mouseDragging || isMouseOver())
  60609. ? xyToNote (pos, mousePositionVelocity) : -1;
  60610. if (noteUnderMouse != newNote)
  60611. {
  60612. if (mouseDownNote >= 0)
  60613. {
  60614. state.noteOff (midiChannel, mouseDownNote);
  60615. mouseDownNote = -1;
  60616. }
  60617. if (mouseDragging && newNote >= 0)
  60618. {
  60619. if (! useMousePositionForVelocity)
  60620. mousePositionVelocity = 1.0f;
  60621. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60622. mouseDownNote = newNote;
  60623. }
  60624. repaintNote (noteUnderMouse);
  60625. noteUnderMouse = newNote;
  60626. repaintNote (noteUnderMouse);
  60627. }
  60628. else if (mouseDownNote >= 0 && ! mouseDragging)
  60629. {
  60630. state.noteOff (midiChannel, mouseDownNote);
  60631. mouseDownNote = -1;
  60632. }
  60633. }
  60634. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60635. {
  60636. updateNoteUnderMouse (e.getPosition());
  60637. stopTimer();
  60638. }
  60639. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60640. {
  60641. float mousePositionVelocity;
  60642. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60643. if (newNote >= 0)
  60644. mouseDraggedToKey (newNote, e);
  60645. updateNoteUnderMouse (e.getPosition());
  60646. }
  60647. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60648. {
  60649. return true;
  60650. }
  60651. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60652. {
  60653. }
  60654. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60655. {
  60656. float mousePositionVelocity;
  60657. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60658. mouseDragging = false;
  60659. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60660. {
  60661. repaintNote (noteUnderMouse);
  60662. noteUnderMouse = -1;
  60663. mouseDragging = true;
  60664. updateNoteUnderMouse (e.getPosition());
  60665. startTimer (500);
  60666. }
  60667. }
  60668. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60669. {
  60670. mouseDragging = false;
  60671. updateNoteUnderMouse (e.getPosition());
  60672. stopTimer();
  60673. }
  60674. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60675. {
  60676. updateNoteUnderMouse (e.getPosition());
  60677. }
  60678. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60679. {
  60680. updateNoteUnderMouse (e.getPosition());
  60681. }
  60682. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60683. {
  60684. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60685. }
  60686. void MidiKeyboardComponent::timerCallback()
  60687. {
  60688. updateNoteUnderMouse (getMouseXYRelative());
  60689. }
  60690. void MidiKeyboardComponent::clearKeyMappings()
  60691. {
  60692. resetAnyKeysInUse();
  60693. keyPressNotes.clear();
  60694. keyPresses.clear();
  60695. }
  60696. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60697. const int midiNoteOffsetFromC)
  60698. {
  60699. removeKeyPressForNote (midiNoteOffsetFromC);
  60700. keyPressNotes.add (midiNoteOffsetFromC);
  60701. keyPresses.add (key);
  60702. }
  60703. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60704. {
  60705. for (int i = keyPressNotes.size(); --i >= 0;)
  60706. {
  60707. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60708. {
  60709. keyPressNotes.remove (i);
  60710. keyPresses.remove (i);
  60711. }
  60712. }
  60713. }
  60714. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60715. {
  60716. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60717. keyMappingOctave = newOctaveNumber;
  60718. }
  60719. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60720. {
  60721. bool keyPressUsed = false;
  60722. for (int i = keyPresses.size(); --i >= 0;)
  60723. {
  60724. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60725. if (keyPresses.getReference(i).isCurrentlyDown())
  60726. {
  60727. if (! keysPressed [note])
  60728. {
  60729. keysPressed.setBit (note);
  60730. state.noteOn (midiChannel, note, velocity);
  60731. keyPressUsed = true;
  60732. }
  60733. }
  60734. else
  60735. {
  60736. if (keysPressed [note])
  60737. {
  60738. keysPressed.clearBit (note);
  60739. state.noteOff (midiChannel, note);
  60740. keyPressUsed = true;
  60741. }
  60742. }
  60743. }
  60744. return keyPressUsed;
  60745. }
  60746. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60747. {
  60748. resetAnyKeysInUse();
  60749. }
  60750. END_JUCE_NAMESPACE
  60751. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60752. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60753. #if JUCE_OPENGL
  60754. BEGIN_JUCE_NAMESPACE
  60755. extern void juce_glViewport (const int w, const int h);
  60756. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60757. const int alphaBits_,
  60758. const int depthBufferBits_,
  60759. const int stencilBufferBits_) throw()
  60760. : redBits (bitsPerRGBComponent),
  60761. greenBits (bitsPerRGBComponent),
  60762. blueBits (bitsPerRGBComponent),
  60763. alphaBits (alphaBits_),
  60764. depthBufferBits (depthBufferBits_),
  60765. stencilBufferBits (stencilBufferBits_),
  60766. accumulationBufferRedBits (0),
  60767. accumulationBufferGreenBits (0),
  60768. accumulationBufferBlueBits (0),
  60769. accumulationBufferAlphaBits (0),
  60770. fullSceneAntiAliasingNumSamples (0)
  60771. {
  60772. }
  60773. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60774. {
  60775. return memcmp (this, &other, sizeof (other)) == 0;
  60776. }
  60777. static VoidArray knownContexts;
  60778. OpenGLContext::OpenGLContext() throw()
  60779. {
  60780. knownContexts.add (this);
  60781. }
  60782. OpenGLContext::~OpenGLContext()
  60783. {
  60784. knownContexts.removeValue (this);
  60785. }
  60786. OpenGLContext* OpenGLContext::getCurrentContext()
  60787. {
  60788. for (int i = knownContexts.size(); --i >= 0;)
  60789. {
  60790. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60791. if (oglc->isActive())
  60792. return oglc;
  60793. }
  60794. return 0;
  60795. }
  60796. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60797. {
  60798. public:
  60799. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60800. : ComponentMovementWatcher (owner_),
  60801. owner (owner_),
  60802. wasShowing (false)
  60803. {
  60804. }
  60805. ~OpenGLComponentWatcher() {}
  60806. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60807. {
  60808. owner->updateContextPosition();
  60809. }
  60810. void componentPeerChanged()
  60811. {
  60812. const ScopedLock sl (owner->getContextLock());
  60813. owner->deleteContext();
  60814. }
  60815. void componentVisibilityChanged (Component&)
  60816. {
  60817. const bool isShowingNow = owner->isShowing();
  60818. if (wasShowing != isShowingNow)
  60819. {
  60820. wasShowing = isShowingNow;
  60821. owner->updateContextPosition();
  60822. }
  60823. }
  60824. juce_UseDebuggingNewOperator
  60825. private:
  60826. OpenGLComponent* const owner;
  60827. bool wasShowing;
  60828. };
  60829. OpenGLComponent::OpenGLComponent()
  60830. : context (0),
  60831. contextToShareListsWith (0),
  60832. needToUpdateViewport (true)
  60833. {
  60834. setOpaque (true);
  60835. componentWatcher = new OpenGLComponentWatcher (this);
  60836. }
  60837. OpenGLComponent::~OpenGLComponent()
  60838. {
  60839. deleteContext();
  60840. componentWatcher = 0;
  60841. }
  60842. void OpenGLComponent::deleteContext()
  60843. {
  60844. const ScopedLock sl (contextLock);
  60845. deleteAndZero (context);
  60846. }
  60847. void OpenGLComponent::updateContextPosition()
  60848. {
  60849. needToUpdateViewport = true;
  60850. if (getWidth() > 0 && getHeight() > 0)
  60851. {
  60852. Component* const topComp = getTopLevelComponent();
  60853. if (topComp->getPeer() != 0)
  60854. {
  60855. const ScopedLock sl (contextLock);
  60856. if (context != 0)
  60857. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60858. getScreenY() - topComp->getScreenY(),
  60859. getWidth(),
  60860. getHeight(),
  60861. topComp->getHeight());
  60862. }
  60863. }
  60864. }
  60865. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60866. {
  60867. OpenGLPixelFormat pf;
  60868. const ScopedLock sl (contextLock);
  60869. if (context != 0)
  60870. pf = context->getPixelFormat();
  60871. return pf;
  60872. }
  60873. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60874. {
  60875. if (! (preferredPixelFormat == formatToUse))
  60876. {
  60877. const ScopedLock sl (contextLock);
  60878. deleteContext();
  60879. preferredPixelFormat = formatToUse;
  60880. }
  60881. }
  60882. void OpenGLComponent::shareWith (OpenGLContext* c)
  60883. {
  60884. if (contextToShareListsWith != c)
  60885. {
  60886. const ScopedLock sl (contextLock);
  60887. deleteContext();
  60888. contextToShareListsWith = c;
  60889. }
  60890. }
  60891. bool OpenGLComponent::makeCurrentContextActive()
  60892. {
  60893. if (context == 0)
  60894. {
  60895. const ScopedLock sl (contextLock);
  60896. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60897. {
  60898. context = OpenGLContext::createContextForWindow (this,
  60899. preferredPixelFormat,
  60900. contextToShareListsWith);
  60901. if (context != 0)
  60902. {
  60903. updateContextPosition();
  60904. if (context->makeActive())
  60905. newOpenGLContextCreated();
  60906. }
  60907. }
  60908. }
  60909. return context != 0 && context->makeActive();
  60910. }
  60911. void OpenGLComponent::makeCurrentContextInactive()
  60912. {
  60913. if (context != 0)
  60914. context->makeInactive();
  60915. }
  60916. bool OpenGLComponent::isActiveContext() const throw()
  60917. {
  60918. return context != 0 && context->isActive();
  60919. }
  60920. void OpenGLComponent::swapBuffers()
  60921. {
  60922. if (context != 0)
  60923. context->swapBuffers();
  60924. }
  60925. void OpenGLComponent::paint (Graphics&)
  60926. {
  60927. if (renderAndSwapBuffers())
  60928. {
  60929. ComponentPeer* const peer = getPeer();
  60930. if (peer != 0)
  60931. {
  60932. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60933. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60934. }
  60935. }
  60936. }
  60937. bool OpenGLComponent::renderAndSwapBuffers()
  60938. {
  60939. const ScopedLock sl (contextLock);
  60940. if (! makeCurrentContextActive())
  60941. return false;
  60942. if (needToUpdateViewport)
  60943. {
  60944. needToUpdateViewport = false;
  60945. juce_glViewport (getWidth(), getHeight());
  60946. }
  60947. renderOpenGL();
  60948. swapBuffers();
  60949. return true;
  60950. }
  60951. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60952. {
  60953. Component::internalRepaint (x, y, w, h);
  60954. if (context != 0)
  60955. context->repaint();
  60956. }
  60957. END_JUCE_NAMESPACE
  60958. #endif
  60959. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60960. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60961. BEGIN_JUCE_NAMESPACE
  60962. PreferencesPanel::PreferencesPanel()
  60963. : buttonSize (70)
  60964. {
  60965. }
  60966. PreferencesPanel::~PreferencesPanel()
  60967. {
  60968. currentPage = 0;
  60969. deleteAllChildren();
  60970. }
  60971. void PreferencesPanel::addSettingsPage (const String& title,
  60972. const Drawable* icon,
  60973. const Drawable* overIcon,
  60974. const Drawable* downIcon)
  60975. {
  60976. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60977. button->setImages (icon, overIcon, downIcon);
  60978. button->setRadioGroupId (1);
  60979. button->addButtonListener (this);
  60980. button->setClickingTogglesState (true);
  60981. button->setWantsKeyboardFocus (false);
  60982. addAndMakeVisible (button);
  60983. resized();
  60984. if (currentPage == 0)
  60985. setCurrentPage (title);
  60986. }
  60987. void PreferencesPanel::addSettingsPage (const String& title,
  60988. const char* imageData,
  60989. const int imageDataSize)
  60990. {
  60991. DrawableImage icon, iconOver, iconDown;
  60992. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60993. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60994. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60995. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60996. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60997. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60998. }
  60999. class PrefsDialogWindow : public DialogWindow
  61000. {
  61001. public:
  61002. PrefsDialogWindow (const String& dialogtitle,
  61003. const Colour& backgroundColour)
  61004. : DialogWindow (dialogtitle, backgroundColour, true)
  61005. {
  61006. }
  61007. ~PrefsDialogWindow()
  61008. {
  61009. }
  61010. void closeButtonPressed()
  61011. {
  61012. exitModalState (0);
  61013. }
  61014. private:
  61015. PrefsDialogWindow (const PrefsDialogWindow&);
  61016. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  61017. };
  61018. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  61019. int dialogWidth,
  61020. int dialogHeight,
  61021. const Colour& backgroundColour)
  61022. {
  61023. setSize (dialogWidth, dialogHeight);
  61024. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  61025. dw.setContentComponent (this, true, true);
  61026. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  61027. dw.runModalLoop();
  61028. dw.setContentComponent (0, false, false);
  61029. }
  61030. void PreferencesPanel::resized()
  61031. {
  61032. int x = 0;
  61033. for (int i = 0; i < getNumChildComponents(); ++i)
  61034. {
  61035. Component* c = getChildComponent (i);
  61036. if (dynamic_cast <DrawableButton*> (c) == 0)
  61037. {
  61038. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  61039. }
  61040. else
  61041. {
  61042. c->setBounds (x, 0, buttonSize, buttonSize);
  61043. x += buttonSize;
  61044. }
  61045. }
  61046. }
  61047. void PreferencesPanel::paint (Graphics& g)
  61048. {
  61049. g.setColour (Colours::grey);
  61050. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  61051. }
  61052. void PreferencesPanel::setCurrentPage (const String& pageName)
  61053. {
  61054. if (currentPageName != pageName)
  61055. {
  61056. currentPageName = pageName;
  61057. currentPage = 0;
  61058. currentPage = createComponentForPage (pageName);
  61059. if (currentPage != 0)
  61060. {
  61061. addAndMakeVisible (currentPage);
  61062. currentPage->toBack();
  61063. resized();
  61064. }
  61065. for (int i = 0; i < getNumChildComponents(); ++i)
  61066. {
  61067. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  61068. if (db != 0 && db->getName() == pageName)
  61069. {
  61070. db->setToggleState (true, false);
  61071. break;
  61072. }
  61073. }
  61074. }
  61075. }
  61076. void PreferencesPanel::buttonClicked (Button*)
  61077. {
  61078. for (int i = 0; i < getNumChildComponents(); ++i)
  61079. {
  61080. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  61081. if (db != 0 && db->getToggleState())
  61082. {
  61083. setCurrentPage (db->getName());
  61084. break;
  61085. }
  61086. }
  61087. }
  61088. END_JUCE_NAMESPACE
  61089. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  61090. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  61091. #if JUCE_WINDOWS || JUCE_LINUX
  61092. BEGIN_JUCE_NAMESPACE
  61093. SystemTrayIconComponent::SystemTrayIconComponent()
  61094. {
  61095. addToDesktop (0);
  61096. }
  61097. SystemTrayIconComponent::~SystemTrayIconComponent()
  61098. {
  61099. }
  61100. END_JUCE_NAMESPACE
  61101. #endif
  61102. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  61103. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  61104. BEGIN_JUCE_NAMESPACE
  61105. static const int titleH = 24;
  61106. static const int iconWidth = 80;
  61107. class AlertWindowTextEditor : public TextEditor
  61108. {
  61109. public:
  61110. static const tchar passwordChar;
  61111. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  61112. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  61113. {
  61114. setSelectAllWhenFocused (true);
  61115. }
  61116. ~AlertWindowTextEditor()
  61117. {
  61118. }
  61119. void returnPressed()
  61120. {
  61121. // pass these up the component hierarchy to be trigger the buttons
  61122. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  61123. }
  61124. void escapePressed()
  61125. {
  61126. // pass these up the component hierarchy to be trigger the buttons
  61127. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  61128. }
  61129. private:
  61130. AlertWindowTextEditor (const AlertWindowTextEditor&);
  61131. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  61132. };
  61133. #if JUCE_LINUX
  61134. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  61135. #else
  61136. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  61137. #endif
  61138. AlertWindow::AlertWindow (const String& title,
  61139. const String& message,
  61140. AlertIconType iconType,
  61141. Component* associatedComponent_)
  61142. : TopLevelWindow (title, true),
  61143. alertIconType (iconType),
  61144. associatedComponent (associatedComponent_)
  61145. {
  61146. if (message.isEmpty())
  61147. text = T(" "); // to force an update if the message is empty
  61148. setMessage (message);
  61149. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  61150. {
  61151. Component* const c = Desktop::getInstance().getComponent (i);
  61152. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  61153. {
  61154. setAlwaysOnTop (true);
  61155. break;
  61156. }
  61157. }
  61158. if (JUCEApplication::getInstance() == 0)
  61159. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  61160. lookAndFeelChanged();
  61161. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  61162. }
  61163. AlertWindow::~AlertWindow()
  61164. {
  61165. for (int i = customComps.size(); --i >= 0;)
  61166. removeChildComponent ((Component*) customComps[i]);
  61167. deleteAllChildren();
  61168. }
  61169. void AlertWindow::userTriedToCloseWindow()
  61170. {
  61171. exitModalState (0);
  61172. }
  61173. void AlertWindow::setMessage (const String& message)
  61174. {
  61175. const String newMessage (message.substring (0, 2048));
  61176. if (text != newMessage)
  61177. {
  61178. text = newMessage;
  61179. font.setHeight (15.0f);
  61180. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  61181. textLayout.setText (getName() + T("\n\n"), titleFont);
  61182. textLayout.appendText (text, font);
  61183. updateLayout (true);
  61184. repaint();
  61185. }
  61186. }
  61187. void AlertWindow::buttonClicked (Button* button)
  61188. {
  61189. for (int i = 0; i < buttons.size(); i++)
  61190. {
  61191. TextButton* const c = (TextButton*) buttons[i];
  61192. if (button->getName() == c->getName())
  61193. {
  61194. if (c->getParentComponent() != 0)
  61195. c->getParentComponent()->exitModalState (c->getCommandID());
  61196. break;
  61197. }
  61198. }
  61199. }
  61200. void AlertWindow::addButton (const String& name,
  61201. const int returnValue,
  61202. const KeyPress& shortcutKey1,
  61203. const KeyPress& shortcutKey2)
  61204. {
  61205. TextButton* const b = new TextButton (name, String::empty);
  61206. b->setWantsKeyboardFocus (true);
  61207. b->setMouseClickGrabsKeyboardFocus (false);
  61208. b->setCommandToTrigger (0, returnValue, false);
  61209. b->addShortcut (shortcutKey1);
  61210. b->addShortcut (shortcutKey2);
  61211. b->addButtonListener (this);
  61212. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  61213. addAndMakeVisible (b, 0);
  61214. buttons.add (b);
  61215. updateLayout (false);
  61216. }
  61217. int AlertWindow::getNumButtons() const
  61218. {
  61219. return buttons.size();
  61220. }
  61221. void AlertWindow::addTextEditor (const String& name,
  61222. const String& initialContents,
  61223. const String& onScreenLabel,
  61224. const bool isPasswordBox)
  61225. {
  61226. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  61227. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  61228. tc->setFont (font);
  61229. tc->setText (initialContents);
  61230. tc->setCaretPosition (initialContents.length());
  61231. addAndMakeVisible (tc);
  61232. textBoxes.add (tc);
  61233. allComps.add (tc);
  61234. textboxNames.add (onScreenLabel);
  61235. updateLayout (false);
  61236. }
  61237. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  61238. {
  61239. for (int i = textBoxes.size(); --i >= 0;)
  61240. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  61241. return ((TextEditor*)textBoxes[i])->getText();
  61242. return String::empty;
  61243. }
  61244. void AlertWindow::addComboBox (const String& name,
  61245. const StringArray& items,
  61246. const String& onScreenLabel)
  61247. {
  61248. ComboBox* const cb = new ComboBox (name);
  61249. for (int i = 0; i < items.size(); ++i)
  61250. cb->addItem (items[i], i + 1);
  61251. addAndMakeVisible (cb);
  61252. cb->setSelectedItemIndex (0);
  61253. comboBoxes.add (cb);
  61254. allComps.add (cb);
  61255. comboBoxNames.add (onScreenLabel);
  61256. updateLayout (false);
  61257. }
  61258. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  61259. {
  61260. for (int i = comboBoxes.size(); --i >= 0;)
  61261. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  61262. return (ComboBox*) comboBoxes[i];
  61263. return 0;
  61264. }
  61265. class AlertTextComp : public TextEditor
  61266. {
  61267. public:
  61268. AlertTextComp (const String& message,
  61269. const Font& font)
  61270. {
  61271. setReadOnly (true);
  61272. setMultiLine (true, true);
  61273. setCaretVisible (false);
  61274. setScrollbarsShown (true);
  61275. lookAndFeelChanged();
  61276. setWantsKeyboardFocus (false);
  61277. setFont (font);
  61278. setText (message, false);
  61279. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  61280. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  61281. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  61282. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  61283. }
  61284. ~AlertTextComp()
  61285. {
  61286. }
  61287. int getPreferredWidth() const throw() { return bestWidth; }
  61288. void updateLayout (const int width)
  61289. {
  61290. TextLayout text;
  61291. text.appendText (getText(), getFont());
  61292. text.layout (width - 8, Justification::topLeft, true);
  61293. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  61294. }
  61295. private:
  61296. int bestWidth;
  61297. AlertTextComp (const AlertTextComp&);
  61298. AlertTextComp& operator= (const AlertTextComp&);
  61299. };
  61300. void AlertWindow::addTextBlock (const String& text)
  61301. {
  61302. AlertTextComp* const c = new AlertTextComp (text, font);
  61303. textBlocks.add (c);
  61304. allComps.add (c);
  61305. addAndMakeVisible (c);
  61306. updateLayout (false);
  61307. }
  61308. void AlertWindow::addProgressBarComponent (double& progressValue)
  61309. {
  61310. ProgressBar* const pb = new ProgressBar (progressValue);
  61311. progressBars.add (pb);
  61312. allComps.add (pb);
  61313. addAndMakeVisible (pb);
  61314. updateLayout (false);
  61315. }
  61316. void AlertWindow::addCustomComponent (Component* const component)
  61317. {
  61318. customComps.add (component);
  61319. allComps.add (component);
  61320. addAndMakeVisible (component);
  61321. updateLayout (false);
  61322. }
  61323. int AlertWindow::getNumCustomComponents() const
  61324. {
  61325. return customComps.size();
  61326. }
  61327. Component* AlertWindow::getCustomComponent (const int index) const
  61328. {
  61329. return (Component*) customComps [index];
  61330. }
  61331. Component* AlertWindow::removeCustomComponent (const int index)
  61332. {
  61333. Component* const c = getCustomComponent (index);
  61334. if (c != 0)
  61335. {
  61336. customComps.removeValue (c);
  61337. allComps.removeValue (c);
  61338. removeChildComponent (c);
  61339. updateLayout (false);
  61340. }
  61341. return c;
  61342. }
  61343. void AlertWindow::paint (Graphics& g)
  61344. {
  61345. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  61346. g.setColour (findColour (textColourId));
  61347. g.setFont (getLookAndFeel().getAlertWindowFont());
  61348. int i;
  61349. for (i = textBoxes.size(); --i >= 0;)
  61350. {
  61351. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61352. g.drawFittedText (textboxNames[i],
  61353. te->getX(), te->getY() - 14,
  61354. te->getWidth(), 14,
  61355. Justification::centredLeft, 1);
  61356. }
  61357. for (i = comboBoxNames.size(); --i >= 0;)
  61358. {
  61359. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61360. g.drawFittedText (comboBoxNames[i],
  61361. cb->getX(), cb->getY() - 14,
  61362. cb->getWidth(), 14,
  61363. Justification::centredLeft, 1);
  61364. }
  61365. for (i = customComps.size(); --i >= 0;)
  61366. {
  61367. const Component* const c = (Component*) customComps[i];
  61368. g.drawFittedText (c->getName(),
  61369. c->getX(), c->getY() - 14,
  61370. c->getWidth(), 14,
  61371. Justification::centredLeft, 1);
  61372. }
  61373. }
  61374. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61375. {
  61376. const int wid = jmax (font.getStringWidth (text),
  61377. font.getStringWidth (getName()));
  61378. const int sw = (int) sqrt (font.getHeight() * wid);
  61379. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61380. const int edgeGap = 10;
  61381. const int labelHeight = 18;
  61382. int iconSpace;
  61383. if (alertIconType == NoIcon)
  61384. {
  61385. textLayout.layout (w, Justification::horizontallyCentred, true);
  61386. iconSpace = 0;
  61387. }
  61388. else
  61389. {
  61390. textLayout.layout (w, Justification::left, true);
  61391. iconSpace = iconWidth;
  61392. }
  61393. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61394. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61395. const int textLayoutH = textLayout.getHeight();
  61396. const int textBottom = 16 + titleH + textLayoutH;
  61397. int h = textBottom;
  61398. int buttonW = 40;
  61399. int i;
  61400. for (i = 0; i < buttons.size(); ++i)
  61401. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61402. w = jmax (buttonW, w);
  61403. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61404. if (buttons.size() > 0)
  61405. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61406. for (i = customComps.size(); --i >= 0;)
  61407. {
  61408. Component* c = (Component*) customComps[i];
  61409. w = jmax (w, (c->getWidth() * 100) / 80);
  61410. h += 10 + c->getHeight();
  61411. if (c->getName().isNotEmpty())
  61412. h += labelHeight;
  61413. }
  61414. for (i = textBlocks.size(); --i >= 0;)
  61415. {
  61416. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61417. w = jmax (w, ac->getPreferredWidth());
  61418. }
  61419. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61420. for (i = textBlocks.size(); --i >= 0;)
  61421. {
  61422. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61423. ac->updateLayout ((int) (w * 0.8f));
  61424. h += ac->getHeight() + 10;
  61425. }
  61426. h = jmin (getParentHeight() - 50, h);
  61427. if (onlyIncreaseSize)
  61428. {
  61429. w = jmax (w, getWidth());
  61430. h = jmax (h, getHeight());
  61431. }
  61432. if (! isVisible())
  61433. {
  61434. centreAroundComponent (associatedComponent, w, h);
  61435. }
  61436. else
  61437. {
  61438. const int cx = getX() + getWidth() / 2;
  61439. const int cy = getY() + getHeight() / 2;
  61440. setBounds (cx - w / 2,
  61441. cy - h / 2,
  61442. w, h);
  61443. }
  61444. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61445. const int spacer = 16;
  61446. int totalWidth = -spacer;
  61447. for (i = buttons.size(); --i >= 0;)
  61448. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61449. int x = (w - totalWidth) / 2;
  61450. int y = (int) (getHeight() * 0.95f);
  61451. for (i = 0; i < buttons.size(); ++i)
  61452. {
  61453. TextButton* const c = (TextButton*) buttons[i];
  61454. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61455. c->setTopLeftPosition (x, ny);
  61456. if (ny < y)
  61457. y = ny;
  61458. x += c->getWidth() + spacer;
  61459. c->toFront (false);
  61460. }
  61461. y = textBottom;
  61462. for (i = 0; i < allComps.size(); ++i)
  61463. {
  61464. Component* const c = (Component*) allComps[i];
  61465. int h = 22;
  61466. const int comboIndex = comboBoxes.indexOf (c);
  61467. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61468. y += labelHeight;
  61469. const int tbIndex = textBoxes.indexOf (c);
  61470. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61471. y += labelHeight;
  61472. if (customComps.contains (c))
  61473. {
  61474. if (c->getName().isNotEmpty())
  61475. y += labelHeight;
  61476. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61477. h = c->getHeight();
  61478. }
  61479. else if (textBlocks.contains (c))
  61480. {
  61481. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61482. h = c->getHeight();
  61483. }
  61484. else
  61485. {
  61486. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61487. }
  61488. y += h + 10;
  61489. }
  61490. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61491. }
  61492. bool AlertWindow::containsAnyExtraComponents() const
  61493. {
  61494. return textBoxes.size()
  61495. + comboBoxes.size()
  61496. + progressBars.size()
  61497. + customComps.size() > 0;
  61498. }
  61499. void AlertWindow::mouseDown (const MouseEvent&)
  61500. {
  61501. dragger.startDraggingComponent (this, &constrainer);
  61502. }
  61503. void AlertWindow::mouseDrag (const MouseEvent& e)
  61504. {
  61505. dragger.dragComponent (this, e);
  61506. }
  61507. bool AlertWindow::keyPressed (const KeyPress& key)
  61508. {
  61509. for (int i = buttons.size(); --i >= 0;)
  61510. {
  61511. TextButton* const b = (TextButton*) buttons[i];
  61512. if (b->isRegisteredForShortcut (key))
  61513. {
  61514. b->triggerClick();
  61515. return true;
  61516. }
  61517. }
  61518. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61519. {
  61520. exitModalState (0);
  61521. return true;
  61522. }
  61523. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61524. {
  61525. ((TextButton*) buttons.getFirst())->triggerClick();
  61526. return true;
  61527. }
  61528. return false;
  61529. }
  61530. void AlertWindow::lookAndFeelChanged()
  61531. {
  61532. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61533. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61534. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61535. }
  61536. int AlertWindow::getDesktopWindowStyleFlags() const
  61537. {
  61538. return getLookAndFeel().getAlertBoxWindowFlags();
  61539. }
  61540. struct AlertWindowInfo
  61541. {
  61542. String title, message, button1, button2, button3;
  61543. AlertWindow::AlertIconType iconType;
  61544. int numButtons;
  61545. Component* associatedComponent;
  61546. int run() const
  61547. {
  61548. return (int) (pointer_sized_int)
  61549. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61550. }
  61551. private:
  61552. int show() const
  61553. {
  61554. jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted?
  61555. LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel()
  61556. : LookAndFeel::getDefaultLookAndFeel();
  61557. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61558. iconType, numButtons, associatedComponent));
  61559. jassert (alertBox != 0); // you have to return one of these!
  61560. return alertBox->runModalLoop();
  61561. }
  61562. static void* showCallback (void* userData)
  61563. {
  61564. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61565. }
  61566. };
  61567. void AlertWindow::showMessageBox (AlertIconType iconType,
  61568. const String& title,
  61569. const String& message,
  61570. const String& buttonText,
  61571. Component* associatedComponent)
  61572. {
  61573. AlertWindowInfo info;
  61574. info.title = title;
  61575. info.message = message;
  61576. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61577. info.iconType = iconType;
  61578. info.numButtons = 1;
  61579. info.associatedComponent = associatedComponent;
  61580. info.run();
  61581. }
  61582. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61583. const String& title,
  61584. const String& message,
  61585. const String& button1Text,
  61586. const String& button2Text,
  61587. Component* associatedComponent)
  61588. {
  61589. AlertWindowInfo info;
  61590. info.title = title;
  61591. info.message = message;
  61592. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61593. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61594. info.iconType = iconType;
  61595. info.numButtons = 2;
  61596. info.associatedComponent = associatedComponent;
  61597. return info.run() != 0;
  61598. }
  61599. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61600. const String& title,
  61601. const String& message,
  61602. const String& button1Text,
  61603. const String& button2Text,
  61604. const String& button3Text,
  61605. Component* associatedComponent)
  61606. {
  61607. AlertWindowInfo info;
  61608. info.title = title;
  61609. info.message = message;
  61610. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61611. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61612. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61613. info.iconType = iconType;
  61614. info.numButtons = 3;
  61615. info.associatedComponent = associatedComponent;
  61616. return info.run();
  61617. }
  61618. END_JUCE_NAMESPACE
  61619. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61620. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61621. BEGIN_JUCE_NAMESPACE
  61622. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61623. static VoidArray heavyweightPeers;
  61624. ComponentPeer::ComponentPeer (Component* const component_,
  61625. const int styleFlags_) throw()
  61626. : component (component_),
  61627. styleFlags (styleFlags_),
  61628. lastPaintTime (0),
  61629. constrainer (0),
  61630. lastFocusedComponent (0),
  61631. lastDragAndDropCompUnderMouse (0),
  61632. fakeMouseMessageSent (false),
  61633. isWindowMinimised (false)
  61634. {
  61635. heavyweightPeers.add (this);
  61636. }
  61637. ComponentPeer::~ComponentPeer()
  61638. {
  61639. heavyweightPeers.removeValue (this);
  61640. Desktop::getInstance().triggerFocusCallback();
  61641. }
  61642. int ComponentPeer::getNumPeers() throw()
  61643. {
  61644. return heavyweightPeers.size();
  61645. }
  61646. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61647. {
  61648. return (ComponentPeer*) heavyweightPeers [index];
  61649. }
  61650. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61651. {
  61652. for (int i = heavyweightPeers.size(); --i >= 0;)
  61653. {
  61654. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61655. if (peer->getComponent() == component)
  61656. return peer;
  61657. }
  61658. return 0;
  61659. }
  61660. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61661. {
  61662. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61663. }
  61664. void ComponentPeer::updateCurrentModifiers() throw()
  61665. {
  61666. ModifierKeys::updateCurrentModifiers();
  61667. }
  61668. void ComponentPeer::handleMouseEvent (const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61669. {
  61670. Desktop::getInstance().getMainMouseSource().handleEvent (this, positionWithinPeer, time, newMods);
  61671. }
  61672. void ComponentPeer::handleMouseWheel (const Point<int>& positionWithinPeer, const int64 time, float x, float y)
  61673. {
  61674. Desktop::getInstance().getMainMouseSource().handleWheel (this, positionWithinPeer, time, x, y);
  61675. }
  61676. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61677. {
  61678. Graphics g (&contextToPaintTo);
  61679. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61680. g.saveState();
  61681. #endif
  61682. JUCE_TRY
  61683. {
  61684. component->paintEntireComponent (g);
  61685. }
  61686. JUCE_CATCH_EXCEPTION
  61687. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61688. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61689. // clearly when things are being repainted.
  61690. {
  61691. g.restoreState();
  61692. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61693. (uint8) Random::getSystemRandom().nextInt (255),
  61694. (uint8) Random::getSystemRandom().nextInt (255),
  61695. (uint8) 0x50));
  61696. }
  61697. #endif
  61698. }
  61699. bool ComponentPeer::handleKeyPress (const int keyCode,
  61700. const juce_wchar textCharacter)
  61701. {
  61702. updateCurrentModifiers();
  61703. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61704. ? Component::currentlyFocusedComponent
  61705. : component;
  61706. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61707. {
  61708. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61709. if (currentModalComp != 0)
  61710. target = currentModalComp;
  61711. }
  61712. const KeyPress keyInfo (keyCode,
  61713. ModifierKeys::getCurrentModifiers().getRawFlags()
  61714. & ModifierKeys::allKeyboardModifiers,
  61715. textCharacter);
  61716. bool keyWasUsed = false;
  61717. while (target != 0)
  61718. {
  61719. const ComponentDeletionWatcher deletionChecker (target);
  61720. if (target->keyListeners_ != 0)
  61721. {
  61722. for (int i = target->keyListeners_->size(); --i >= 0;)
  61723. {
  61724. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61725. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61726. return keyWasUsed;
  61727. i = jmin (i, target->keyListeners_->size());
  61728. }
  61729. }
  61730. keyWasUsed = target->keyPressed (keyInfo);
  61731. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61732. break;
  61733. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61734. {
  61735. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61736. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61737. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61738. break;
  61739. }
  61740. target = target->parentComponent_;
  61741. }
  61742. return keyWasUsed;
  61743. }
  61744. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61745. {
  61746. updateCurrentModifiers();
  61747. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61748. ? Component::currentlyFocusedComponent
  61749. : component;
  61750. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61751. {
  61752. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61753. if (currentModalComp != 0)
  61754. target = currentModalComp;
  61755. }
  61756. bool keyWasUsed = false;
  61757. while (target != 0)
  61758. {
  61759. const ComponentDeletionWatcher deletionChecker (target);
  61760. keyWasUsed = target->keyStateChanged (isKeyDown);
  61761. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61762. break;
  61763. if (target->keyListeners_ != 0)
  61764. {
  61765. for (int i = target->keyListeners_->size(); --i >= 0;)
  61766. {
  61767. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61768. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61769. return keyWasUsed;
  61770. i = jmin (i, target->keyListeners_->size());
  61771. }
  61772. }
  61773. target = target->parentComponent_;
  61774. }
  61775. return keyWasUsed;
  61776. }
  61777. void ComponentPeer::handleModifierKeysChange()
  61778. {
  61779. updateCurrentModifiers();
  61780. Component* target = Component::getComponentUnderMouse();
  61781. if (target == 0)
  61782. target = Component::getCurrentlyFocusedComponent();
  61783. if (target == 0)
  61784. target = component;
  61785. if (target->isValidComponent())
  61786. target->internalModifierKeysChanged();
  61787. }
  61788. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61789. {
  61790. Component* const c = Component::getCurrentlyFocusedComponent();
  61791. if (component->isParentOf (c))
  61792. return dynamic_cast <TextInputTarget*> (c);
  61793. return 0;
  61794. }
  61795. void ComponentPeer::handleBroughtToFront()
  61796. {
  61797. updateCurrentModifiers();
  61798. if (component != 0)
  61799. component->internalBroughtToFront();
  61800. }
  61801. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61802. {
  61803. constrainer = newConstrainer;
  61804. }
  61805. void ComponentPeer::handleMovedOrResized()
  61806. {
  61807. jassert (component->isValidComponent());
  61808. updateCurrentModifiers();
  61809. const bool nowMinimised = isMinimised();
  61810. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61811. {
  61812. const ComponentDeletionWatcher deletionChecker (component);
  61813. const Rectangle<int> newBounds (getBounds());
  61814. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61815. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61816. if (wasMoved || wasResized)
  61817. {
  61818. component->bounds_ = newBounds;
  61819. if (wasResized)
  61820. component->repaint();
  61821. component->sendMovedResizedMessages (wasMoved, wasResized);
  61822. if (deletionChecker.hasBeenDeleted())
  61823. return;
  61824. }
  61825. }
  61826. if (isWindowMinimised != nowMinimised)
  61827. {
  61828. isWindowMinimised = nowMinimised;
  61829. component->minimisationStateChanged (nowMinimised);
  61830. component->sendVisibilityChangeMessage();
  61831. }
  61832. if (! isFullScreen())
  61833. lastNonFullscreenBounds = component->getBounds();
  61834. }
  61835. void ComponentPeer::handleFocusGain()
  61836. {
  61837. updateCurrentModifiers();
  61838. if (component->isParentOf (lastFocusedComponent))
  61839. {
  61840. Component::currentlyFocusedComponent = lastFocusedComponent;
  61841. Desktop::getInstance().triggerFocusCallback();
  61842. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61843. }
  61844. else
  61845. {
  61846. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61847. component->grabKeyboardFocus();
  61848. else
  61849. Component::bringModalComponentToFront();
  61850. }
  61851. }
  61852. void ComponentPeer::handleFocusLoss()
  61853. {
  61854. updateCurrentModifiers();
  61855. if (component->hasKeyboardFocus (true))
  61856. {
  61857. lastFocusedComponent = Component::currentlyFocusedComponent;
  61858. if (lastFocusedComponent != 0)
  61859. {
  61860. Component::currentlyFocusedComponent = 0;
  61861. Desktop::getInstance().triggerFocusCallback();
  61862. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61863. }
  61864. }
  61865. }
  61866. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61867. {
  61868. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61869. ? lastFocusedComponent
  61870. : component;
  61871. }
  61872. void ComponentPeer::handleScreenSizeChange()
  61873. {
  61874. updateCurrentModifiers();
  61875. component->parentSizeChanged();
  61876. handleMovedOrResized();
  61877. }
  61878. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61879. {
  61880. lastNonFullscreenBounds = newBounds;
  61881. }
  61882. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61883. {
  61884. return lastNonFullscreenBounds;
  61885. }
  61886. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61887. const StringArray& files,
  61888. FileDragAndDropTarget* const lastOne)
  61889. {
  61890. while (c != 0)
  61891. {
  61892. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61893. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61894. return t;
  61895. c = c->getParentComponent();
  61896. }
  61897. return 0;
  61898. }
  61899. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61900. {
  61901. updateCurrentModifiers();
  61902. FileDragAndDropTarget* lastTarget = 0;
  61903. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61904. lastTarget = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61905. FileDragAndDropTarget* newTarget = 0;
  61906. Component* const compUnderMouse = component->getComponentAt (position);
  61907. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61908. {
  61909. lastDragAndDropCompUnderMouse = compUnderMouse;
  61910. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61911. if (newTarget != lastTarget)
  61912. {
  61913. if (lastTarget != 0)
  61914. lastTarget->fileDragExit (files);
  61915. dragAndDropTargetComponent = 0;
  61916. if (newTarget != 0)
  61917. {
  61918. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61919. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61920. dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast <Component*> (newTarget));
  61921. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61922. }
  61923. }
  61924. }
  61925. else
  61926. {
  61927. newTarget = lastTarget;
  61928. }
  61929. if (newTarget != 0)
  61930. {
  61931. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61932. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61933. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61934. }
  61935. }
  61936. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61937. {
  61938. handleFileDragMove (files, Point<int> (-1, -1));
  61939. jassert (dragAndDropTargetComponent == 0);
  61940. lastDragAndDropCompUnderMouse = 0;
  61941. }
  61942. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61943. {
  61944. handleFileDragMove (files, position);
  61945. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61946. {
  61947. FileDragAndDropTarget* const target = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61948. dragAndDropTargetComponent = 0;
  61949. lastDragAndDropCompUnderMouse = 0;
  61950. if (target != 0)
  61951. {
  61952. Component* const targetComp = dynamic_cast <Component*> (target);
  61953. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61954. {
  61955. targetComp->internalModalInputAttempt();
  61956. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61957. return;
  61958. }
  61959. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61960. target->filesDropped (files, pos.getX(), pos.getY());
  61961. }
  61962. }
  61963. }
  61964. void ComponentPeer::handleUserClosingWindow()
  61965. {
  61966. updateCurrentModifiers();
  61967. component->userTriedToCloseWindow();
  61968. }
  61969. void ComponentPeer::bringModalComponentToFront()
  61970. {
  61971. Component::bringModalComponentToFront();
  61972. }
  61973. void ComponentPeer::clearMaskedRegion() throw()
  61974. {
  61975. maskedRegion.clear();
  61976. }
  61977. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61978. {
  61979. maskedRegion.add (x, y, w, h);
  61980. }
  61981. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61982. {
  61983. StringArray s;
  61984. s.add ("Software Renderer");
  61985. return s;
  61986. }
  61987. int ComponentPeer::getCurrentRenderingEngine() throw()
  61988. {
  61989. return 0;
  61990. }
  61991. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61992. {
  61993. }
  61994. END_JUCE_NAMESPACE
  61995. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61996. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61997. BEGIN_JUCE_NAMESPACE
  61998. DialogWindow::DialogWindow (const String& name,
  61999. const Colour& backgroundColour_,
  62000. const bool escapeKeyTriggersCloseButton_,
  62001. const bool addToDesktop_)
  62002. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  62003. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  62004. {
  62005. }
  62006. DialogWindow::~DialogWindow()
  62007. {
  62008. }
  62009. void DialogWindow::resized()
  62010. {
  62011. DocumentWindow::resized();
  62012. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  62013. if (escapeKeyTriggersCloseButton
  62014. && getCloseButton() != 0
  62015. && ! getCloseButton()->isRegisteredForShortcut (esc))
  62016. {
  62017. getCloseButton()->addShortcut (esc);
  62018. }
  62019. }
  62020. class TempDialogWindow : public DialogWindow
  62021. {
  62022. public:
  62023. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  62024. : DialogWindow (title, colour, escapeCloses, true)
  62025. {
  62026. }
  62027. ~TempDialogWindow()
  62028. {
  62029. }
  62030. void closeButtonPressed()
  62031. {
  62032. setVisible (false);
  62033. }
  62034. private:
  62035. TempDialogWindow (const TempDialogWindow&);
  62036. TempDialogWindow& operator= (const TempDialogWindow&);
  62037. };
  62038. int DialogWindow::showModalDialog (const String& dialogTitle,
  62039. Component* contentComponent,
  62040. Component* componentToCentreAround,
  62041. const Colour& colour,
  62042. const bool escapeKeyTriggersCloseButton,
  62043. const bool shouldBeResizable,
  62044. const bool useBottomRightCornerResizer)
  62045. {
  62046. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  62047. dw.setContentComponent (contentComponent, true, true);
  62048. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  62049. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62050. const int result = dw.runModalLoop();
  62051. dw.setContentComponent (0, false);
  62052. return result;
  62053. }
  62054. END_JUCE_NAMESPACE
  62055. /*** End of inlined file: juce_DialogWindow.cpp ***/
  62056. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  62057. BEGIN_JUCE_NAMESPACE
  62058. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  62059. {
  62060. public:
  62061. ButtonListenerProxy (DocumentWindow& owner_)
  62062. : owner (owner_)
  62063. {
  62064. }
  62065. void buttonClicked (Button* button)
  62066. {
  62067. if (button == owner.getMinimiseButton())
  62068. owner.minimiseButtonPressed();
  62069. else if (button == owner.getMaximiseButton())
  62070. owner.maximiseButtonPressed();
  62071. else if (button == owner.getCloseButton())
  62072. owner.closeButtonPressed();
  62073. }
  62074. juce_UseDebuggingNewOperator
  62075. private:
  62076. DocumentWindow& owner;
  62077. ButtonListenerProxy (const ButtonListenerProxy&);
  62078. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  62079. };
  62080. DocumentWindow::DocumentWindow (const String& title,
  62081. const Colour& backgroundColour,
  62082. const int requiredButtons_,
  62083. const bool addToDesktop_)
  62084. : ResizableWindow (title, backgroundColour, addToDesktop_),
  62085. titleBarHeight (26),
  62086. menuBarHeight (24),
  62087. requiredButtons (requiredButtons_),
  62088. #if JUCE_MAC
  62089. positionTitleBarButtonsOnLeft (true),
  62090. #else
  62091. positionTitleBarButtonsOnLeft (false),
  62092. #endif
  62093. drawTitleTextCentred (true),
  62094. menuBarModel (0)
  62095. {
  62096. setResizeLimits (128, 128, 32768, 32768);
  62097. lookAndFeelChanged();
  62098. }
  62099. DocumentWindow::~DocumentWindow()
  62100. {
  62101. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62102. titleBarButtons[i] = 0;
  62103. menuBar = 0;
  62104. }
  62105. void DocumentWindow::repaintTitleBar()
  62106. {
  62107. const Rectangle<int> titleBarArea (getTitleBarArea());
  62108. repaint (titleBarArea.getX(), titleBarArea.getY(),
  62109. titleBarArea.getWidth(), titleBarArea.getHeight());
  62110. }
  62111. void DocumentWindow::setName (const String& newName)
  62112. {
  62113. if (newName != getName())
  62114. {
  62115. Component::setName (newName);
  62116. repaintTitleBar();
  62117. }
  62118. }
  62119. void DocumentWindow::setIcon (const Image* imageToUse)
  62120. {
  62121. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  62122. repaintTitleBar();
  62123. }
  62124. void DocumentWindow::setTitleBarHeight (const int newHeight)
  62125. {
  62126. titleBarHeight = newHeight;
  62127. resized();
  62128. repaintTitleBar();
  62129. }
  62130. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  62131. const bool positionTitleBarButtonsOnLeft_)
  62132. {
  62133. requiredButtons = requiredButtons_;
  62134. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  62135. lookAndFeelChanged();
  62136. }
  62137. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  62138. {
  62139. drawTitleTextCentred = textShouldBeCentred;
  62140. repaintTitleBar();
  62141. }
  62142. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  62143. const int menuBarHeight_)
  62144. {
  62145. if (menuBarModel != menuBarModel_)
  62146. {
  62147. menuBar = 0;
  62148. menuBarModel = menuBarModel_;
  62149. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  62150. : getLookAndFeel().getDefaultMenuBarHeight();
  62151. if (menuBarModel != 0)
  62152. {
  62153. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62154. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  62155. menuBar->setEnabled (isActiveWindow());
  62156. }
  62157. resized();
  62158. }
  62159. }
  62160. void DocumentWindow::closeButtonPressed()
  62161. {
  62162. /* If you've got a close button, you have to override this method to get
  62163. rid of your window!
  62164. If the window is just a pop-up, you should override this method and make
  62165. it delete the window in whatever way is appropriate for your app. E.g. you
  62166. might just want to call "delete this".
  62167. If your app is centred around this window such that the whole app should quit when
  62168. the window is closed, then you will probably want to use this method as an opportunity
  62169. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  62170. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  62171. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  62172. or closing it via the taskbar icon on Windows).
  62173. */
  62174. jassertfalse
  62175. }
  62176. void DocumentWindow::minimiseButtonPressed()
  62177. {
  62178. setMinimised (true);
  62179. }
  62180. void DocumentWindow::maximiseButtonPressed()
  62181. {
  62182. setFullScreen (! isFullScreen());
  62183. }
  62184. void DocumentWindow::paint (Graphics& g)
  62185. {
  62186. ResizableWindow::paint (g);
  62187. if (resizableBorder == 0)
  62188. {
  62189. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  62190. const BorderSize border (getBorderThickness());
  62191. g.fillRect (0, 0, getWidth(), border.getTop());
  62192. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  62193. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  62194. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  62195. }
  62196. const Rectangle<int> titleBarArea (getTitleBarArea());
  62197. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  62198. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  62199. int titleSpaceX1 = 6;
  62200. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  62201. for (int i = 0; i < 3; ++i)
  62202. {
  62203. if (titleBarButtons[i] != 0)
  62204. {
  62205. if (positionTitleBarButtonsOnLeft)
  62206. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  62207. else
  62208. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  62209. }
  62210. }
  62211. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  62212. titleBarArea.getWidth(),
  62213. titleBarArea.getHeight(),
  62214. titleSpaceX1,
  62215. jmax (1, titleSpaceX2 - titleSpaceX1),
  62216. titleBarIcon,
  62217. ! drawTitleTextCentred);
  62218. }
  62219. void DocumentWindow::resized()
  62220. {
  62221. ResizableWindow::resized();
  62222. if (titleBarButtons[1] != 0)
  62223. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  62224. const Rectangle<int> titleBarArea (getTitleBarArea());
  62225. getLookAndFeel()
  62226. .positionDocumentWindowButtons (*this,
  62227. titleBarArea.getX(), titleBarArea.getY(),
  62228. titleBarArea.getWidth(), titleBarArea.getHeight(),
  62229. titleBarButtons[0],
  62230. titleBarButtons[1],
  62231. titleBarButtons[2],
  62232. positionTitleBarButtonsOnLeft);
  62233. if (menuBar != 0)
  62234. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  62235. titleBarArea.getWidth(), menuBarHeight);
  62236. }
  62237. const BorderSize DocumentWindow::getBorderThickness()
  62238. {
  62239. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  62240. ? 0 : (resizableBorder != 0 ? 4 : 1));
  62241. }
  62242. const BorderSize DocumentWindow::getContentComponentBorder()
  62243. {
  62244. BorderSize border (getBorderThickness());
  62245. border.setTop (border.getTop()
  62246. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  62247. + (menuBar != 0 ? menuBarHeight : 0));
  62248. return border;
  62249. }
  62250. int DocumentWindow::getTitleBarHeight() const
  62251. {
  62252. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  62253. }
  62254. const Rectangle<int> DocumentWindow::getTitleBarArea()
  62255. {
  62256. const BorderSize border (getBorderThickness());
  62257. return Rectangle<int> (border.getLeft(), border.getTop(),
  62258. getWidth() - border.getLeftAndRight(),
  62259. getTitleBarHeight());
  62260. }
  62261. Button* DocumentWindow::getCloseButton() const throw()
  62262. {
  62263. return titleBarButtons[2];
  62264. }
  62265. Button* DocumentWindow::getMinimiseButton() const throw()
  62266. {
  62267. return titleBarButtons[0];
  62268. }
  62269. Button* DocumentWindow::getMaximiseButton() const throw()
  62270. {
  62271. return titleBarButtons[1];
  62272. }
  62273. int DocumentWindow::getDesktopWindowStyleFlags() const
  62274. {
  62275. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  62276. if ((requiredButtons & minimiseButton) != 0)
  62277. flags |= ComponentPeer::windowHasMinimiseButton;
  62278. if ((requiredButtons & maximiseButton) != 0)
  62279. flags |= ComponentPeer::windowHasMaximiseButton;
  62280. if ((requiredButtons & closeButton) != 0)
  62281. flags |= ComponentPeer::windowHasCloseButton;
  62282. return flags;
  62283. }
  62284. void DocumentWindow::lookAndFeelChanged()
  62285. {
  62286. int i;
  62287. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  62288. titleBarButtons[i] = 0;
  62289. if (! isUsingNativeTitleBar())
  62290. {
  62291. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  62292. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  62293. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  62294. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  62295. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  62296. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  62297. for (i = 0; i < 3; ++i)
  62298. {
  62299. if (titleBarButtons[i] != 0)
  62300. {
  62301. if (buttonListener == 0)
  62302. buttonListener = new ButtonListenerProxy (*this);
  62303. titleBarButtons[i]->addButtonListener (buttonListener);
  62304. titleBarButtons[i]->setWantsKeyboardFocus (false);
  62305. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62306. Component::addAndMakeVisible (titleBarButtons[i]);
  62307. }
  62308. }
  62309. if (getCloseButton() != 0)
  62310. {
  62311. #if JUCE_MAC
  62312. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  62313. #else
  62314. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  62315. #endif
  62316. }
  62317. }
  62318. activeWindowStatusChanged();
  62319. ResizableWindow::lookAndFeelChanged();
  62320. }
  62321. void DocumentWindow::parentHierarchyChanged()
  62322. {
  62323. lookAndFeelChanged();
  62324. }
  62325. void DocumentWindow::activeWindowStatusChanged()
  62326. {
  62327. ResizableWindow::activeWindowStatusChanged();
  62328. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62329. if (titleBarButtons[i] != 0)
  62330. titleBarButtons[i]->setEnabled (isActiveWindow());
  62331. if (menuBar != 0)
  62332. menuBar->setEnabled (isActiveWindow());
  62333. }
  62334. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  62335. {
  62336. if (getTitleBarArea().contains (e.x, e.y)
  62337. && getMaximiseButton() != 0)
  62338. {
  62339. getMaximiseButton()->triggerClick();
  62340. }
  62341. }
  62342. void DocumentWindow::userTriedToCloseWindow()
  62343. {
  62344. closeButtonPressed();
  62345. }
  62346. END_JUCE_NAMESPACE
  62347. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  62348. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  62349. BEGIN_JUCE_NAMESPACE
  62350. ResizableWindow::ResizableWindow (const String& name,
  62351. const bool addToDesktop_)
  62352. : TopLevelWindow (name, addToDesktop_),
  62353. resizeToFitContent (false),
  62354. fullscreen (false),
  62355. lastNonFullScreenPos (50, 50, 256, 256),
  62356. constrainer (0)
  62357. #ifdef JUCE_DEBUG
  62358. , hasBeenResized (false)
  62359. #endif
  62360. {
  62361. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62362. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62363. if (addToDesktop_)
  62364. Component::addToDesktop (getDesktopWindowStyleFlags());
  62365. }
  62366. ResizableWindow::ResizableWindow (const String& name,
  62367. const Colour& backgroundColour_,
  62368. const bool addToDesktop_)
  62369. : TopLevelWindow (name, addToDesktop_),
  62370. resizeToFitContent (false),
  62371. fullscreen (false),
  62372. lastNonFullScreenPos (50, 50, 256, 256),
  62373. constrainer (0)
  62374. #ifdef JUCE_DEBUG
  62375. , hasBeenResized (false)
  62376. #endif
  62377. {
  62378. setBackgroundColour (backgroundColour_);
  62379. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62380. if (addToDesktop_)
  62381. Component::addToDesktop (getDesktopWindowStyleFlags());
  62382. }
  62383. ResizableWindow::~ResizableWindow()
  62384. {
  62385. resizableCorner = 0;
  62386. resizableBorder = 0;
  62387. contentComponent = 0;
  62388. // have you been adding your own components directly to this window..? tut tut tut.
  62389. // Read the instructions for using a ResizableWindow!
  62390. jassert (getNumChildComponents() == 0);
  62391. }
  62392. int ResizableWindow::getDesktopWindowStyleFlags() const
  62393. {
  62394. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62395. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62396. flags |= ComponentPeer::windowIsResizable;
  62397. return flags;
  62398. }
  62399. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62400. const bool deleteOldOne,
  62401. const bool resizeToFit)
  62402. {
  62403. resizeToFitContent = resizeToFit;
  62404. if (newContentComponent != (Component*) contentComponent)
  62405. {
  62406. if (! deleteOldOne)
  62407. removeChildComponent (contentComponent.release());
  62408. contentComponent = newContentComponent;
  62409. Component::addAndMakeVisible (contentComponent);
  62410. }
  62411. if (resizeToFit)
  62412. childBoundsChanged (contentComponent);
  62413. resized(); // must always be called to position the new content comp
  62414. }
  62415. void ResizableWindow::setContentComponentSize (int width, int height)
  62416. {
  62417. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62418. const BorderSize border (getContentComponentBorder());
  62419. setSize (width + border.getLeftAndRight(),
  62420. height + border.getTopAndBottom());
  62421. }
  62422. const BorderSize ResizableWindow::getBorderThickness()
  62423. {
  62424. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62425. }
  62426. const BorderSize ResizableWindow::getContentComponentBorder()
  62427. {
  62428. return getBorderThickness();
  62429. }
  62430. void ResizableWindow::moved()
  62431. {
  62432. updateLastPos();
  62433. }
  62434. void ResizableWindow::visibilityChanged()
  62435. {
  62436. TopLevelWindow::visibilityChanged();
  62437. updateLastPos();
  62438. }
  62439. void ResizableWindow::resized()
  62440. {
  62441. if (resizableBorder != 0)
  62442. {
  62443. resizableBorder->setVisible (! isFullScreen());
  62444. resizableBorder->setBorderThickness (getBorderThickness());
  62445. resizableBorder->setSize (getWidth(), getHeight());
  62446. resizableBorder->toBack();
  62447. }
  62448. if (resizableCorner != 0)
  62449. {
  62450. resizableCorner->setVisible (! isFullScreen());
  62451. const int resizerSize = 18;
  62452. resizableCorner->setBounds (getWidth() - resizerSize,
  62453. getHeight() - resizerSize,
  62454. resizerSize, resizerSize);
  62455. }
  62456. if (contentComponent != 0)
  62457. contentComponent->setBoundsInset (getContentComponentBorder());
  62458. updateLastPos();
  62459. #ifdef JUCE_DEBUG
  62460. hasBeenResized = true;
  62461. #endif
  62462. }
  62463. void ResizableWindow::childBoundsChanged (Component* child)
  62464. {
  62465. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62466. {
  62467. // not going to look very good if this component has a zero size..
  62468. jassert (child->getWidth() > 0);
  62469. jassert (child->getHeight() > 0);
  62470. const BorderSize borders (getContentComponentBorder());
  62471. setSize (child->getWidth() + borders.getLeftAndRight(),
  62472. child->getHeight() + borders.getTopAndBottom());
  62473. }
  62474. }
  62475. void ResizableWindow::activeWindowStatusChanged()
  62476. {
  62477. const BorderSize borders (getContentComponentBorder());
  62478. repaint (0, 0, getWidth(), borders.getTop());
  62479. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62480. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62481. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62482. }
  62483. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62484. const bool useBottomRightCornerResizer)
  62485. {
  62486. if (shouldBeResizable)
  62487. {
  62488. if (useBottomRightCornerResizer)
  62489. {
  62490. resizableBorder = 0;
  62491. if (resizableCorner == 0)
  62492. {
  62493. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62494. resizableCorner->setAlwaysOnTop (true);
  62495. }
  62496. }
  62497. else
  62498. {
  62499. resizableCorner = 0;
  62500. if (resizableBorder == 0)
  62501. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62502. }
  62503. }
  62504. else
  62505. {
  62506. resizableCorner = 0;
  62507. resizableBorder = 0;
  62508. }
  62509. if (isUsingNativeTitleBar())
  62510. recreateDesktopWindow();
  62511. childBoundsChanged (contentComponent);
  62512. resized();
  62513. }
  62514. bool ResizableWindow::isResizable() const throw()
  62515. {
  62516. return resizableCorner != 0
  62517. || resizableBorder != 0;
  62518. }
  62519. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62520. const int newMinimumHeight,
  62521. const int newMaximumWidth,
  62522. const int newMaximumHeight) throw()
  62523. {
  62524. // if you've set up a custom constrainer then these settings won't have any effect..
  62525. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62526. if (constrainer == 0)
  62527. setConstrainer (&defaultConstrainer);
  62528. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62529. newMaximumWidth, newMaximumHeight);
  62530. setBoundsConstrained (getBounds());
  62531. }
  62532. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62533. {
  62534. if (constrainer != newConstrainer)
  62535. {
  62536. constrainer = newConstrainer;
  62537. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62538. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62539. resizableCorner = 0;
  62540. resizableBorder = 0;
  62541. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62542. ComponentPeer* const peer = getPeer();
  62543. if (peer != 0)
  62544. peer->setConstrainer (newConstrainer);
  62545. }
  62546. }
  62547. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62548. {
  62549. if (constrainer != 0)
  62550. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62551. else
  62552. setBounds (bounds);
  62553. }
  62554. void ResizableWindow::paint (Graphics& g)
  62555. {
  62556. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62557. getBorderThickness(), *this);
  62558. if (! isFullScreen())
  62559. {
  62560. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62561. getBorderThickness(), *this);
  62562. }
  62563. #ifdef JUCE_DEBUG
  62564. /* If this fails, then you've probably written a subclass with a resized()
  62565. callback but forgotten to make it call its parent class's resized() method.
  62566. It's important when you override methods like resized(), moved(),
  62567. etc., that you make sure the base class methods also get called.
  62568. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62569. because your content should all be inside the content component - and it's the
  62570. content component's resized() method that you should be using to do your
  62571. layout.
  62572. */
  62573. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62574. #endif
  62575. }
  62576. void ResizableWindow::lookAndFeelChanged()
  62577. {
  62578. resized();
  62579. if (isOnDesktop())
  62580. {
  62581. Component::addToDesktop (getDesktopWindowStyleFlags());
  62582. ComponentPeer* const peer = getPeer();
  62583. if (peer != 0)
  62584. peer->setConstrainer (constrainer);
  62585. }
  62586. }
  62587. const Colour ResizableWindow::getBackgroundColour() const throw()
  62588. {
  62589. return findColour (backgroundColourId, false);
  62590. }
  62591. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62592. {
  62593. Colour backgroundColour (newColour);
  62594. if (! Desktop::canUseSemiTransparentWindows())
  62595. backgroundColour = newColour.withAlpha (1.0f);
  62596. setColour (backgroundColourId, backgroundColour);
  62597. setOpaque (backgroundColour.isOpaque());
  62598. repaint();
  62599. }
  62600. bool ResizableWindow::isFullScreen() const
  62601. {
  62602. if (isOnDesktop())
  62603. {
  62604. ComponentPeer* const peer = getPeer();
  62605. return peer != 0 && peer->isFullScreen();
  62606. }
  62607. return fullscreen;
  62608. }
  62609. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62610. {
  62611. if (shouldBeFullScreen != isFullScreen())
  62612. {
  62613. updateLastPos();
  62614. fullscreen = shouldBeFullScreen;
  62615. if (isOnDesktop())
  62616. {
  62617. ComponentPeer* const peer = getPeer();
  62618. if (peer != 0)
  62619. {
  62620. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62621. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62622. peer->setFullScreen (shouldBeFullScreen);
  62623. if (! shouldBeFullScreen)
  62624. setBounds (lastPos);
  62625. }
  62626. else
  62627. {
  62628. jassertfalse
  62629. }
  62630. }
  62631. else
  62632. {
  62633. if (shouldBeFullScreen)
  62634. setBounds (0, 0, getParentWidth(), getParentHeight());
  62635. else
  62636. setBounds (lastNonFullScreenPos);
  62637. }
  62638. resized();
  62639. }
  62640. }
  62641. bool ResizableWindow::isMinimised() const
  62642. {
  62643. ComponentPeer* const peer = getPeer();
  62644. return (peer != 0) && peer->isMinimised();
  62645. }
  62646. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62647. {
  62648. if (shouldMinimise != isMinimised())
  62649. {
  62650. ComponentPeer* const peer = getPeer();
  62651. if (peer != 0)
  62652. {
  62653. updateLastPos();
  62654. peer->setMinimised (shouldMinimise);
  62655. }
  62656. else
  62657. {
  62658. jassertfalse
  62659. }
  62660. }
  62661. }
  62662. void ResizableWindow::updateLastPos()
  62663. {
  62664. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62665. {
  62666. lastNonFullScreenPos = getBounds();
  62667. }
  62668. }
  62669. void ResizableWindow::parentSizeChanged()
  62670. {
  62671. if (isFullScreen() && getParentComponent() != 0)
  62672. {
  62673. setBounds (0, 0, getParentWidth(), getParentHeight());
  62674. }
  62675. }
  62676. const String ResizableWindow::getWindowStateAsString()
  62677. {
  62678. updateLastPos();
  62679. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62680. }
  62681. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62682. {
  62683. StringArray tokens;
  62684. tokens.addTokens (s, false);
  62685. tokens.removeEmptyStrings();
  62686. tokens.trim();
  62687. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62688. const int firstCoord = fs ? 1 : 0;
  62689. if (tokens.size() != firstCoord + 4)
  62690. return false;
  62691. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62692. tokens[firstCoord + 1].getIntValue(),
  62693. tokens[firstCoord + 2].getIntValue(),
  62694. tokens[firstCoord + 3].getIntValue());
  62695. if (newPos.isEmpty())
  62696. return false;
  62697. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62698. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62699. if (peer != 0)
  62700. peer->getFrameSize().addTo (newPos);
  62701. if (! screen.contains (newPos))
  62702. {
  62703. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62704. jmin (newPos.getHeight(), screen.getHeight()));
  62705. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62706. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62707. }
  62708. if (peer != 0)
  62709. {
  62710. peer->getFrameSize().subtractFrom (newPos);
  62711. peer->setNonFullScreenBounds (newPos);
  62712. }
  62713. lastNonFullScreenPos = newPos;
  62714. setFullScreen (fs);
  62715. if (! fs)
  62716. setBoundsConstrained (newPos);
  62717. return true;
  62718. }
  62719. void ResizableWindow::mouseDown (const MouseEvent&)
  62720. {
  62721. if (! isFullScreen())
  62722. dragger.startDraggingComponent (this, constrainer);
  62723. }
  62724. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62725. {
  62726. if (! isFullScreen())
  62727. dragger.dragComponent (this, e);
  62728. }
  62729. #ifdef JUCE_DEBUG
  62730. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62731. {
  62732. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62733. manages its child components automatically, and if you add your own it'll cause
  62734. trouble. Instead, use setContentComponent() to give it a component which
  62735. will be automatically resized and kept in the right place - then you can add
  62736. subcomponents to the content comp. See the notes for the ResizableWindow class
  62737. for more info.
  62738. If you really know what you're doing and want to avoid this assertion, just call
  62739. Component::addChildComponent directly.
  62740. */
  62741. jassertfalse
  62742. Component::addChildComponent (child, zOrder);
  62743. }
  62744. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62745. {
  62746. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62747. manages its child components automatically, and if you add your own it'll cause
  62748. trouble. Instead, use setContentComponent() to give it a component which
  62749. will be automatically resized and kept in the right place - then you can add
  62750. subcomponents to the content comp. See the notes for the ResizableWindow class
  62751. for more info.
  62752. If you really know what you're doing and want to avoid this assertion, just call
  62753. Component::addAndMakeVisible directly.
  62754. */
  62755. jassertfalse
  62756. Component::addAndMakeVisible (child, zOrder);
  62757. }
  62758. #endif
  62759. END_JUCE_NAMESPACE
  62760. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62761. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62762. BEGIN_JUCE_NAMESPACE
  62763. SplashScreen::SplashScreen()
  62764. : backgroundImage (0)
  62765. {
  62766. setOpaque (true);
  62767. }
  62768. SplashScreen::~SplashScreen()
  62769. {
  62770. ImageCache::releaseOrDelete (backgroundImage);
  62771. }
  62772. void SplashScreen::show (const String& title,
  62773. Image* const backgroundImage_,
  62774. const int minimumTimeToDisplayFor,
  62775. const bool useDropShadow,
  62776. const bool removeOnMouseClick)
  62777. {
  62778. backgroundImage = backgroundImage_;
  62779. jassert (backgroundImage_ != 0);
  62780. if (backgroundImage_ != 0)
  62781. {
  62782. setOpaque (! backgroundImage_->hasAlphaChannel());
  62783. show (title,
  62784. backgroundImage_->getWidth(),
  62785. backgroundImage_->getHeight(),
  62786. minimumTimeToDisplayFor,
  62787. useDropShadow,
  62788. removeOnMouseClick);
  62789. }
  62790. }
  62791. void SplashScreen::show (const String& title,
  62792. const int width,
  62793. const int height,
  62794. const int minimumTimeToDisplayFor,
  62795. const bool useDropShadow,
  62796. const bool removeOnMouseClick)
  62797. {
  62798. setName (title);
  62799. setAlwaysOnTop (true);
  62800. setVisible (true);
  62801. centreWithSize (width, height);
  62802. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62803. toFront (false);
  62804. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62805. repaint();
  62806. originalClickCounter = removeOnMouseClick
  62807. ? Desktop::getMouseButtonClickCounter()
  62808. : std::numeric_limits<int>::max();
  62809. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62810. startTimer (50);
  62811. }
  62812. void SplashScreen::paint (Graphics& g)
  62813. {
  62814. if (backgroundImage != 0)
  62815. {
  62816. g.setOpacity (1.0f);
  62817. g.drawImage (backgroundImage,
  62818. 0, 0, getWidth(), getHeight(),
  62819. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62820. }
  62821. }
  62822. void SplashScreen::timerCallback()
  62823. {
  62824. if (Time::getCurrentTime() > earliestTimeToDelete
  62825. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62826. {
  62827. delete this;
  62828. }
  62829. }
  62830. END_JUCE_NAMESPACE
  62831. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62832. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62833. BEGIN_JUCE_NAMESPACE
  62834. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62835. const bool hasProgressBar,
  62836. const bool hasCancelButton,
  62837. const int timeOutMsWhenCancelling_,
  62838. const String& cancelButtonText)
  62839. : Thread ("Juce Progress Window"),
  62840. progress (0.0),
  62841. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62842. {
  62843. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62844. .createAlertWindow (title, String::empty, cancelButtonText,
  62845. String::empty, String::empty,
  62846. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62847. if (hasProgressBar)
  62848. alertWindow->addProgressBarComponent (progress);
  62849. }
  62850. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62851. {
  62852. stopThread (timeOutMsWhenCancelling);
  62853. }
  62854. bool ThreadWithProgressWindow::runThread (const int priority)
  62855. {
  62856. startThread (priority);
  62857. startTimer (100);
  62858. {
  62859. const ScopedLock sl (messageLock);
  62860. alertWindow->setMessage (message);
  62861. }
  62862. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62863. stopThread (timeOutMsWhenCancelling);
  62864. alertWindow->setVisible (false);
  62865. return finishedNaturally;
  62866. }
  62867. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62868. {
  62869. progress = newProgress;
  62870. }
  62871. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62872. {
  62873. const ScopedLock sl (messageLock);
  62874. message = newStatusMessage;
  62875. }
  62876. void ThreadWithProgressWindow::timerCallback()
  62877. {
  62878. if (! isThreadRunning())
  62879. {
  62880. // thread has finished normally..
  62881. alertWindow->exitModalState (1);
  62882. alertWindow->setVisible (false);
  62883. }
  62884. else
  62885. {
  62886. const ScopedLock sl (messageLock);
  62887. alertWindow->setMessage (message);
  62888. }
  62889. }
  62890. END_JUCE_NAMESPACE
  62891. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62892. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62893. BEGIN_JUCE_NAMESPACE
  62894. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62895. const int millisecondsBeforeTipAppears_)
  62896. : Component ("tooltip"),
  62897. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62898. lastHideTime (0),
  62899. lastComponentUnderMouse (0),
  62900. changedCompsSinceShown (true)
  62901. {
  62902. startTimer (123);
  62903. setAlwaysOnTop (true);
  62904. setOpaque (true);
  62905. if (parentComponent != 0)
  62906. parentComponent->addChildComponent (this);
  62907. }
  62908. TooltipWindow::~TooltipWindow()
  62909. {
  62910. hide();
  62911. }
  62912. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62913. {
  62914. millisecondsBeforeTipAppears = newTimeMs;
  62915. }
  62916. void TooltipWindow::paint (Graphics& g)
  62917. {
  62918. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62919. }
  62920. void TooltipWindow::mouseEnter (const MouseEvent&)
  62921. {
  62922. hide();
  62923. }
  62924. void TooltipWindow::showFor (const String& tip)
  62925. {
  62926. jassert (tip.isNotEmpty());
  62927. tipShowing = tip;
  62928. Point<int> mousePos (Desktop::getMousePosition());
  62929. if (getParentComponent() != 0)
  62930. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62931. int x, y, w, h;
  62932. getLookAndFeel().getTooltipSize (tip, w, h);
  62933. if (mousePos.getX() > getParentWidth() / 2)
  62934. x = mousePos.getX() - (w + 12);
  62935. else
  62936. x = mousePos.getX() + 24;
  62937. if (mousePos.getY() > getParentHeight() / 2)
  62938. y = mousePos.getY() - (h + 6);
  62939. else
  62940. y = mousePos.getY() + 6;
  62941. setBounds (x, y, w, h);
  62942. setVisible (true);
  62943. if (getParentComponent() == 0)
  62944. {
  62945. addToDesktop (ComponentPeer::windowHasDropShadow
  62946. | ComponentPeer::windowIsTemporary
  62947. | ComponentPeer::windowIgnoresKeyPresses);
  62948. }
  62949. toFront (false);
  62950. }
  62951. const String TooltipWindow::getTipFor (Component* const c)
  62952. {
  62953. if (c->isValidComponent()
  62954. && Process::isForegroundProcess()
  62955. && ! Component::isMouseButtonDownAnywhere())
  62956. {
  62957. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62958. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62959. return ttc->getTooltip();
  62960. }
  62961. return String::empty;
  62962. }
  62963. void TooltipWindow::hide()
  62964. {
  62965. tipShowing = String::empty;
  62966. removeFromDesktop();
  62967. setVisible (false);
  62968. }
  62969. void TooltipWindow::timerCallback()
  62970. {
  62971. const unsigned int now = Time::getApproximateMillisecondCounter();
  62972. Component* const newComp = Component::getComponentUnderMouse();
  62973. const String newTip (getTipFor (newComp));
  62974. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62975. lastComponentUnderMouse = newComp;
  62976. lastTipUnderMouse = newTip;
  62977. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62978. const bool mouseWasClicked = clickCount > mouseClicks;
  62979. mouseClicks = clickCount;
  62980. const Point<int> mousePos (Desktop::getMousePosition());
  62981. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62982. lastMousePos = mousePos;
  62983. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62984. lastCompChangeTime = now;
  62985. if (isVisible() || now < lastHideTime + 500)
  62986. {
  62987. // if a tip is currently visible (or has just disappeared), update to a new one
  62988. // immediately if needed..
  62989. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62990. {
  62991. if (isVisible())
  62992. {
  62993. lastHideTime = now;
  62994. hide();
  62995. }
  62996. }
  62997. else if (tipChanged)
  62998. {
  62999. showFor (newTip);
  63000. }
  63001. }
  63002. else
  63003. {
  63004. // if there isn't currently a tip, but one is needed, only let it
  63005. // appear after a timeout..
  63006. if (newTip.isNotEmpty()
  63007. && newTip != tipShowing
  63008. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  63009. {
  63010. showFor (newTip);
  63011. }
  63012. }
  63013. }
  63014. END_JUCE_NAMESPACE
  63015. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  63016. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  63017. BEGIN_JUCE_NAMESPACE
  63018. class TopLevelWindowManager : public Timer,
  63019. public DeletedAtShutdown
  63020. {
  63021. public:
  63022. TopLevelWindowManager()
  63023. : currentActive (0)
  63024. {
  63025. }
  63026. ~TopLevelWindowManager()
  63027. {
  63028. clearSingletonInstance();
  63029. }
  63030. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  63031. void timerCallback()
  63032. {
  63033. startTimer (jmin (1731, getTimerInterval() * 2));
  63034. TopLevelWindow* active = 0;
  63035. if (Process::isForegroundProcess())
  63036. {
  63037. active = currentActive;
  63038. Component* const c = Component::getCurrentlyFocusedComponent();
  63039. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  63040. if (tlw == 0 && c != 0)
  63041. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  63042. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  63043. if (tlw != 0)
  63044. active = tlw;
  63045. }
  63046. if (active != currentActive)
  63047. {
  63048. currentActive = active;
  63049. for (int i = windows.size(); --i >= 0;)
  63050. {
  63051. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  63052. tlw->setWindowActive (isWindowActive (tlw));
  63053. i = jmin (i, windows.size() - 1);
  63054. }
  63055. Desktop::getInstance().triggerFocusCallback();
  63056. }
  63057. }
  63058. bool addWindow (TopLevelWindow* const w) throw()
  63059. {
  63060. windows.add (w);
  63061. startTimer (10);
  63062. return isWindowActive (w);
  63063. }
  63064. void removeWindow (TopLevelWindow* const w) throw()
  63065. {
  63066. startTimer (10);
  63067. if (currentActive == w)
  63068. currentActive = 0;
  63069. windows.removeValue (w);
  63070. if (windows.size() == 0)
  63071. deleteInstance();
  63072. }
  63073. VoidArray windows;
  63074. private:
  63075. TopLevelWindow* currentActive;
  63076. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  63077. {
  63078. return (tlw == currentActive
  63079. || tlw->isParentOf (currentActive)
  63080. || tlw->hasKeyboardFocus (true))
  63081. && tlw->isShowing();
  63082. }
  63083. TopLevelWindowManager (const TopLevelWindowManager&);
  63084. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  63085. };
  63086. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  63087. void juce_CheckCurrentlyFocusedTopLevelWindow()
  63088. {
  63089. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  63090. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  63091. }
  63092. TopLevelWindow::TopLevelWindow (const String& name,
  63093. const bool addToDesktop_)
  63094. : Component (name),
  63095. useDropShadow (true),
  63096. useNativeTitleBar (false),
  63097. windowIsActive_ (false)
  63098. {
  63099. setOpaque (true);
  63100. if (addToDesktop_)
  63101. Component::addToDesktop (getDesktopWindowStyleFlags());
  63102. else
  63103. setDropShadowEnabled (true);
  63104. setWantsKeyboardFocus (true);
  63105. setBroughtToFrontOnMouseClick (true);
  63106. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  63107. }
  63108. TopLevelWindow::~TopLevelWindow()
  63109. {
  63110. shadower = 0;
  63111. TopLevelWindowManager::getInstance()->removeWindow (this);
  63112. }
  63113. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  63114. {
  63115. if (hasKeyboardFocus (true))
  63116. TopLevelWindowManager::getInstance()->timerCallback();
  63117. else
  63118. TopLevelWindowManager::getInstance()->startTimer (10);
  63119. }
  63120. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  63121. {
  63122. if (windowIsActive_ != isNowActive)
  63123. {
  63124. windowIsActive_ = isNowActive;
  63125. activeWindowStatusChanged();
  63126. }
  63127. }
  63128. void TopLevelWindow::activeWindowStatusChanged()
  63129. {
  63130. }
  63131. void TopLevelWindow::parentHierarchyChanged()
  63132. {
  63133. setDropShadowEnabled (useDropShadow);
  63134. }
  63135. void TopLevelWindow::visibilityChanged()
  63136. {
  63137. if (isShowing())
  63138. toFront (true);
  63139. }
  63140. int TopLevelWindow::getDesktopWindowStyleFlags() const
  63141. {
  63142. int flags = ComponentPeer::windowAppearsOnTaskbar;
  63143. if (useDropShadow)
  63144. flags |= ComponentPeer::windowHasDropShadow;
  63145. if (useNativeTitleBar)
  63146. flags |= ComponentPeer::windowHasTitleBar;
  63147. return flags;
  63148. }
  63149. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  63150. {
  63151. useDropShadow = useShadow;
  63152. if (isOnDesktop())
  63153. {
  63154. shadower = 0;
  63155. Component::addToDesktop (getDesktopWindowStyleFlags());
  63156. }
  63157. else
  63158. {
  63159. if (useShadow && isOpaque())
  63160. {
  63161. if (shadower == 0)
  63162. {
  63163. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  63164. if (shadower != 0)
  63165. shadower->setOwner (this);
  63166. }
  63167. }
  63168. else
  63169. {
  63170. shadower = 0;
  63171. }
  63172. }
  63173. }
  63174. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  63175. {
  63176. if (useNativeTitleBar != useNativeTitleBar_)
  63177. {
  63178. useNativeTitleBar = useNativeTitleBar_;
  63179. recreateDesktopWindow();
  63180. sendLookAndFeelChange();
  63181. }
  63182. }
  63183. void TopLevelWindow::recreateDesktopWindow()
  63184. {
  63185. if (isOnDesktop())
  63186. {
  63187. Component::addToDesktop (getDesktopWindowStyleFlags());
  63188. toFront (true);
  63189. }
  63190. }
  63191. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  63192. {
  63193. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  63194. because this class needs to make sure its layout corresponds with settings like whether
  63195. it's got a native title bar or not.
  63196. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  63197. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  63198. method, then add or remove whatever flags are necessary from this value before returning it.
  63199. */
  63200. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  63201. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  63202. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  63203. if (windowStyleFlags != getDesktopWindowStyleFlags())
  63204. sendLookAndFeelChange();
  63205. }
  63206. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  63207. {
  63208. if (c == 0)
  63209. c = TopLevelWindow::getActiveTopLevelWindow();
  63210. if (c == 0)
  63211. {
  63212. centreWithSize (width, height);
  63213. }
  63214. else
  63215. {
  63216. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  63217. (c->getHeight() - height) / 2)));
  63218. Rectangle<int> parentArea (c->getParentMonitorArea());
  63219. if (getParentComponent() != 0)
  63220. {
  63221. p = getParentComponent()->globalPositionToRelative (p);
  63222. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  63223. }
  63224. parentArea.reduce (12, 12);
  63225. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  63226. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  63227. width, height);
  63228. }
  63229. }
  63230. int TopLevelWindow::getNumTopLevelWindows() throw()
  63231. {
  63232. return TopLevelWindowManager::getInstance()->windows.size();
  63233. }
  63234. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  63235. {
  63236. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  63237. }
  63238. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  63239. {
  63240. TopLevelWindow* best = 0;
  63241. int bestNumTWLParents = -1;
  63242. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  63243. {
  63244. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  63245. if (tlw->isActiveWindow())
  63246. {
  63247. int numTWLParents = 0;
  63248. const Component* c = tlw->getParentComponent();
  63249. while (c != 0)
  63250. {
  63251. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  63252. ++numTWLParents;
  63253. c = c->getParentComponent();
  63254. }
  63255. if (bestNumTWLParents < numTWLParents)
  63256. {
  63257. best = tlw;
  63258. bestNumTWLParents = numTWLParents;
  63259. }
  63260. }
  63261. }
  63262. return best;
  63263. }
  63264. END_JUCE_NAMESPACE
  63265. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  63266. /*** Start of inlined file: juce_Colour.cpp ***/
  63267. BEGIN_JUCE_NAMESPACE
  63268. static uint8 floatAlphaToInt (const float alpha)
  63269. {
  63270. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  63271. }
  63272. static const float oneOver255 = 1.0f / 255.0f;
  63273. Colour::Colour() throw()
  63274. : argb (0)
  63275. {
  63276. }
  63277. Colour::Colour (const Colour& other) throw()
  63278. : argb (other.argb)
  63279. {
  63280. }
  63281. Colour& Colour::operator= (const Colour& other) throw()
  63282. {
  63283. argb = other.argb;
  63284. return *this;
  63285. }
  63286. bool Colour::operator== (const Colour& other) const throw()
  63287. {
  63288. return argb.getARGB() == other.argb.getARGB();
  63289. }
  63290. bool Colour::operator!= (const Colour& other) const throw()
  63291. {
  63292. return argb.getARGB() != other.argb.getARGB();
  63293. }
  63294. Colour::Colour (const uint32 argb_) throw()
  63295. : argb (argb_)
  63296. {
  63297. }
  63298. Colour::Colour (const uint8 red,
  63299. const uint8 green,
  63300. const uint8 blue) throw()
  63301. {
  63302. argb.setARGB (0xff, red, green, blue);
  63303. }
  63304. const Colour Colour::fromRGB (const uint8 red,
  63305. const uint8 green,
  63306. const uint8 blue) throw()
  63307. {
  63308. return Colour (red, green, blue);
  63309. }
  63310. Colour::Colour (const uint8 red,
  63311. const uint8 green,
  63312. const uint8 blue,
  63313. const uint8 alpha) throw()
  63314. {
  63315. argb.setARGB (alpha, red, green, blue);
  63316. }
  63317. const Colour Colour::fromRGBA (const uint8 red,
  63318. const uint8 green,
  63319. const uint8 blue,
  63320. const uint8 alpha) throw()
  63321. {
  63322. return Colour (red, green, blue, alpha);
  63323. }
  63324. Colour::Colour (const uint8 red,
  63325. const uint8 green,
  63326. const uint8 blue,
  63327. const float alpha) throw()
  63328. {
  63329. argb.setARGB (floatAlphaToInt (alpha), red, green, blue);
  63330. }
  63331. const Colour Colour::fromRGBAFloat (const uint8 red,
  63332. const uint8 green,
  63333. const uint8 blue,
  63334. const float alpha) throw()
  63335. {
  63336. return Colour (red, green, blue, alpha);
  63337. }
  63338. static void convertHSBtoRGB (float h, float s, float v,
  63339. uint8& r, uint8& g, uint8& b) throw()
  63340. {
  63341. v = jlimit (0.0f, 1.0f, v);
  63342. v *= 255.0f;
  63343. const uint8 intV = (uint8) roundToInt (v);
  63344. if (s <= 0)
  63345. {
  63346. r = intV;
  63347. g = intV;
  63348. b = intV;
  63349. }
  63350. else
  63351. {
  63352. s = jmin (1.0f, s);
  63353. h = jlimit (0.0f, 1.0f, h);
  63354. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  63355. const float f = h - floorf (h);
  63356. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  63357. const float y = v * (1.0f - s * f);
  63358. const float z = v * (1.0f - (s * (1.0f - f)));
  63359. if (h < 1.0f)
  63360. {
  63361. r = intV;
  63362. g = (uint8) roundToInt (z);
  63363. b = x;
  63364. }
  63365. else if (h < 2.0f)
  63366. {
  63367. r = (uint8) roundToInt (y);
  63368. g = intV;
  63369. b = x;
  63370. }
  63371. else if (h < 3.0f)
  63372. {
  63373. r = x;
  63374. g = intV;
  63375. b = (uint8) roundToInt (z);
  63376. }
  63377. else if (h < 4.0f)
  63378. {
  63379. r = x;
  63380. g = (uint8) roundToInt (y);
  63381. b = intV;
  63382. }
  63383. else if (h < 5.0f)
  63384. {
  63385. r = (uint8) roundToInt (z);
  63386. g = x;
  63387. b = intV;
  63388. }
  63389. else if (h < 6.0f)
  63390. {
  63391. r = intV;
  63392. g = x;
  63393. b = (uint8) roundToInt (y);
  63394. }
  63395. else
  63396. {
  63397. r = 0;
  63398. g = 0;
  63399. b = 0;
  63400. }
  63401. }
  63402. }
  63403. Colour::Colour (const float hue,
  63404. const float saturation,
  63405. const float brightness,
  63406. const float alpha) throw()
  63407. {
  63408. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63409. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63410. argb.setARGB (floatAlphaToInt (alpha), r, g, b);
  63411. }
  63412. const Colour Colour::fromHSV (const float hue,
  63413. const float saturation,
  63414. const float brightness,
  63415. const float alpha) throw()
  63416. {
  63417. return Colour (hue, saturation, brightness, alpha);
  63418. }
  63419. Colour::Colour (const float hue,
  63420. const float saturation,
  63421. const float brightness,
  63422. const uint8 alpha) throw()
  63423. {
  63424. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63425. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63426. argb.setARGB (alpha, r, g, b);
  63427. }
  63428. Colour::~Colour() throw()
  63429. {
  63430. }
  63431. const PixelARGB Colour::getPixelARGB() const throw()
  63432. {
  63433. PixelARGB p (argb);
  63434. p.premultiply();
  63435. return p;
  63436. }
  63437. uint32 Colour::getARGB() const throw()
  63438. {
  63439. return argb.getARGB();
  63440. }
  63441. bool Colour::isTransparent() const throw()
  63442. {
  63443. return getAlpha() == 0;
  63444. }
  63445. bool Colour::isOpaque() const throw()
  63446. {
  63447. return getAlpha() == 0xff;
  63448. }
  63449. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63450. {
  63451. PixelARGB newCol (argb);
  63452. newCol.setAlpha (newAlpha);
  63453. return Colour (newCol.getARGB());
  63454. }
  63455. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63456. {
  63457. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63458. PixelARGB newCol (argb);
  63459. newCol.setAlpha (floatAlphaToInt (newAlpha));
  63460. return Colour (newCol.getARGB());
  63461. }
  63462. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63463. {
  63464. jassert (alphaMultiplier >= 0);
  63465. PixelARGB newCol (argb);
  63466. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63467. return Colour (newCol.getARGB());
  63468. }
  63469. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63470. {
  63471. const int destAlpha = getAlpha();
  63472. if (destAlpha > 0)
  63473. {
  63474. const int invA = 0xff - (int) src.getAlpha();
  63475. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63476. if (resA > 0)
  63477. {
  63478. const int da = (invA * destAlpha) / resA;
  63479. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63480. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63481. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63482. (uint8) resA);
  63483. }
  63484. return *this;
  63485. }
  63486. else
  63487. {
  63488. return src;
  63489. }
  63490. }
  63491. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63492. {
  63493. if (proportionOfOther <= 0)
  63494. return *this;
  63495. if (proportionOfOther >= 1.0f)
  63496. return other;
  63497. PixelARGB c1 (getPixelARGB());
  63498. const PixelARGB c2 (other.getPixelARGB());
  63499. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63500. c1.unpremultiply();
  63501. return Colour (c1.getARGB());
  63502. }
  63503. float Colour::getFloatRed() const throw()
  63504. {
  63505. return getRed() * oneOver255;
  63506. }
  63507. float Colour::getFloatGreen() const throw()
  63508. {
  63509. return getGreen() * oneOver255;
  63510. }
  63511. float Colour::getFloatBlue() const throw()
  63512. {
  63513. return getBlue() * oneOver255;
  63514. }
  63515. float Colour::getFloatAlpha() const throw()
  63516. {
  63517. return getAlpha() * oneOver255;
  63518. }
  63519. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63520. {
  63521. const int r = getRed();
  63522. const int g = getGreen();
  63523. const int b = getBlue();
  63524. const int hi = jmax (r, g, b);
  63525. const int lo = jmin (r, g, b);
  63526. if (hi != 0)
  63527. {
  63528. s = (hi - lo) / (float) hi;
  63529. if (s != 0)
  63530. {
  63531. const float invDiff = 1.0f / (hi - lo);
  63532. const float red = (hi - r) * invDiff;
  63533. const float green = (hi - g) * invDiff;
  63534. const float blue = (hi - b) * invDiff;
  63535. if (r == hi)
  63536. h = blue - green;
  63537. else if (g == hi)
  63538. h = 2.0f + red - blue;
  63539. else
  63540. h = 4.0f + green - red;
  63541. h *= 1.0f / 6.0f;
  63542. if (h < 0)
  63543. ++h;
  63544. }
  63545. else
  63546. {
  63547. h = 0;
  63548. }
  63549. }
  63550. else
  63551. {
  63552. s = 0;
  63553. h = 0;
  63554. }
  63555. v = hi * oneOver255;
  63556. }
  63557. float Colour::getHue() const throw()
  63558. {
  63559. float h, s, b;
  63560. getHSB (h, s, b);
  63561. return h;
  63562. }
  63563. const Colour Colour::withHue (const float hue) const throw()
  63564. {
  63565. float h, s, b;
  63566. getHSB (h, s, b);
  63567. return Colour (hue, s, b, getAlpha());
  63568. }
  63569. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63570. {
  63571. float h, s, b;
  63572. getHSB (h, s, b);
  63573. h += amountToRotate;
  63574. h -= floorf (h);
  63575. return Colour (h, s, b, getAlpha());
  63576. }
  63577. float Colour::getSaturation() const throw()
  63578. {
  63579. float h, s, b;
  63580. getHSB (h, s, b);
  63581. return s;
  63582. }
  63583. const Colour Colour::withSaturation (const float saturation) const throw()
  63584. {
  63585. float h, s, b;
  63586. getHSB (h, s, b);
  63587. return Colour (h, saturation, b, getAlpha());
  63588. }
  63589. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63590. {
  63591. float h, s, b;
  63592. getHSB (h, s, b);
  63593. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63594. }
  63595. float Colour::getBrightness() const throw()
  63596. {
  63597. float h, s, b;
  63598. getHSB (h, s, b);
  63599. return b;
  63600. }
  63601. const Colour Colour::withBrightness (const float brightness) const throw()
  63602. {
  63603. float h, s, b;
  63604. getHSB (h, s, b);
  63605. return Colour (h, s, brightness, getAlpha());
  63606. }
  63607. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63608. {
  63609. float h, s, b;
  63610. getHSB (h, s, b);
  63611. b *= amount;
  63612. if (b > 1.0f)
  63613. b = 1.0f;
  63614. return Colour (h, s, b, getAlpha());
  63615. }
  63616. const Colour Colour::brighter (float amount) const throw()
  63617. {
  63618. amount = 1.0f / (1.0f + amount);
  63619. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63620. (uint8) (255 - (amount * (255 - getGreen()))),
  63621. (uint8) (255 - (amount * (255 - getBlue()))),
  63622. getAlpha());
  63623. }
  63624. const Colour Colour::darker (float amount) const throw()
  63625. {
  63626. amount = 1.0f / (1.0f + amount);
  63627. return Colour ((uint8) (amount * getRed()),
  63628. (uint8) (amount * getGreen()),
  63629. (uint8) (amount * getBlue()),
  63630. getAlpha());
  63631. }
  63632. const Colour Colour::greyLevel (const float brightness) throw()
  63633. {
  63634. const uint8 level
  63635. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63636. return Colour (level, level, level);
  63637. }
  63638. const Colour Colour::contrasting (const float amount) const throw()
  63639. {
  63640. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63641. ? Colours::black
  63642. : Colours::white).withAlpha (amount));
  63643. }
  63644. const Colour Colour::contrasting (const Colour& colour1,
  63645. const Colour& colour2) throw()
  63646. {
  63647. const float b1 = colour1.getBrightness();
  63648. const float b2 = colour2.getBrightness();
  63649. float best = 0.0f;
  63650. float bestDist = 0.0f;
  63651. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63652. {
  63653. const float d1 = fabsf (i - b1);
  63654. const float d2 = fabsf (i - b2);
  63655. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63656. if (dist > bestDist)
  63657. {
  63658. best = i;
  63659. bestDist = dist;
  63660. }
  63661. }
  63662. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63663. .withBrightness (best);
  63664. }
  63665. const String Colour::toString() const throw()
  63666. {
  63667. return String::toHexString ((int) argb.getARGB());
  63668. }
  63669. const Colour Colour::fromString (const String& encodedColourString)
  63670. {
  63671. return Colour ((uint32) encodedColourString.getHexValue32());
  63672. }
  63673. END_JUCE_NAMESPACE
  63674. /*** End of inlined file: juce_Colour.cpp ***/
  63675. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63676. BEGIN_JUCE_NAMESPACE
  63677. ColourGradient::ColourGradient() throw()
  63678. {
  63679. #ifdef JUCE_DEBUG
  63680. x1 = 987654.0f;
  63681. #endif
  63682. }
  63683. ColourGradient::ColourGradient (const Colour& colour1,
  63684. const float x1_,
  63685. const float y1_,
  63686. const Colour& colour2,
  63687. const float x2_,
  63688. const float y2_,
  63689. const bool isRadial_) throw()
  63690. : x1 (x1_),
  63691. y1 (y1_),
  63692. x2 (x2_),
  63693. y2 (y2_),
  63694. isRadial (isRadial_)
  63695. {
  63696. colours.add (0);
  63697. colours.add (colour1.getARGB());
  63698. colours.add (1 << 16);
  63699. colours.add (colour2.getARGB());
  63700. }
  63701. ColourGradient::~ColourGradient() throw()
  63702. {
  63703. }
  63704. void ColourGradient::clearColours() throw()
  63705. {
  63706. colours.clear();
  63707. }
  63708. void ColourGradient::addColour (const double proportionAlongGradient,
  63709. const Colour& colour) throw()
  63710. {
  63711. // must be within the two end-points
  63712. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63713. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63714. int i;
  63715. for (i = 0; i < colours.size(); i += 2)
  63716. if (colours.getUnchecked(i) > pos)
  63717. break;
  63718. colours.insert (i, pos);
  63719. colours.insert (i + 1, colour.getARGB());
  63720. }
  63721. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63722. {
  63723. for (int i = 1; i < colours.size(); i += 2)
  63724. {
  63725. const Colour c (colours.getUnchecked(i));
  63726. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63727. }
  63728. }
  63729. int ColourGradient::getNumColours() const throw()
  63730. {
  63731. return colours.size() >> 1;
  63732. }
  63733. double ColourGradient::getColourPosition (const int index) const throw()
  63734. {
  63735. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63736. }
  63737. const Colour ColourGradient::getColour (const int index) const throw()
  63738. {
  63739. return Colour (colours [(index << 1) + 1]);
  63740. }
  63741. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63742. {
  63743. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63744. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63745. if (integerPos <= 0 || colours.size() <= 2)
  63746. return getColour (0);
  63747. int i = colours.size() - 2;
  63748. while (integerPos < (int) colours.getUnchecked(i))
  63749. i -= 2;
  63750. if (i >= colours.size() - 2)
  63751. return Colour (colours.getUnchecked(i));
  63752. const int pos1 = colours.getUnchecked (i);
  63753. const Colour col1 (colours.getUnchecked (i + 1));
  63754. const int pos2 = colours.getUnchecked (i + 2);
  63755. const Colour col2 (colours.getUnchecked (i + 3));
  63756. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63757. }
  63758. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63759. {
  63760. #ifdef JUCE_DEBUG
  63761. // trying to use the object without setting its co-ordinates? Have a careful read of
  63762. // the comments for the constructors.
  63763. jassert (x1 != 987654.0f);
  63764. #endif
  63765. const int numColours = colours.size() >> 1;
  63766. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63767. transform.transformPoint (tx1, ty1);
  63768. transform.transformPoint (tx2, ty2);
  63769. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63770. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63771. lookupTable.malloc (numEntries);
  63772. if (numColours >= 2)
  63773. {
  63774. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63775. PixelARGB pix1 (colours.getUnchecked (1));
  63776. pix1.premultiply();
  63777. int index = 0;
  63778. for (int j = 2; j < colours.size(); j += 2)
  63779. {
  63780. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63781. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63782. pix2.premultiply();
  63783. for (int i = 0; i < numToDo; ++i)
  63784. {
  63785. jassert (index >= 0 && index < numEntries);
  63786. lookupTable[index] = pix1;
  63787. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63788. ++index;
  63789. }
  63790. pix1 = pix2;
  63791. }
  63792. while (index < numEntries)
  63793. lookupTable [index++] = pix1;
  63794. }
  63795. else
  63796. {
  63797. jassertfalse // no colours specified!
  63798. }
  63799. return numEntries;
  63800. }
  63801. bool ColourGradient::isOpaque() const throw()
  63802. {
  63803. for (int i = 1; i < colours.size(); i += 2)
  63804. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63805. return false;
  63806. return true;
  63807. }
  63808. bool ColourGradient::isInvisible() const throw()
  63809. {
  63810. for (int i = 1; i < colours.size(); i += 2)
  63811. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63812. return false;
  63813. return true;
  63814. }
  63815. END_JUCE_NAMESPACE
  63816. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63817. /*** Start of inlined file: juce_Colours.cpp ***/
  63818. BEGIN_JUCE_NAMESPACE
  63819. const Colour Colours::transparentBlack (0);
  63820. const Colour Colours::transparentWhite (0x00ffffff);
  63821. const Colour Colours::aliceblue (0xfff0f8ff);
  63822. const Colour Colours::antiquewhite (0xfffaebd7);
  63823. const Colour Colours::aqua (0xff00ffff);
  63824. const Colour Colours::aquamarine (0xff7fffd4);
  63825. const Colour Colours::azure (0xfff0ffff);
  63826. const Colour Colours::beige (0xfff5f5dc);
  63827. const Colour Colours::bisque (0xffffe4c4);
  63828. const Colour Colours::black (0xff000000);
  63829. const Colour Colours::blanchedalmond (0xffffebcd);
  63830. const Colour Colours::blue (0xff0000ff);
  63831. const Colour Colours::blueviolet (0xff8a2be2);
  63832. const Colour Colours::brown (0xffa52a2a);
  63833. const Colour Colours::burlywood (0xffdeb887);
  63834. const Colour Colours::cadetblue (0xff5f9ea0);
  63835. const Colour Colours::chartreuse (0xff7fff00);
  63836. const Colour Colours::chocolate (0xffd2691e);
  63837. const Colour Colours::coral (0xffff7f50);
  63838. const Colour Colours::cornflowerblue (0xff6495ed);
  63839. const Colour Colours::cornsilk (0xfffff8dc);
  63840. const Colour Colours::crimson (0xffdc143c);
  63841. const Colour Colours::cyan (0xff00ffff);
  63842. const Colour Colours::darkblue (0xff00008b);
  63843. const Colour Colours::darkcyan (0xff008b8b);
  63844. const Colour Colours::darkgoldenrod (0xffb8860b);
  63845. const Colour Colours::darkgrey (0xff555555);
  63846. const Colour Colours::darkgreen (0xff006400);
  63847. const Colour Colours::darkkhaki (0xffbdb76b);
  63848. const Colour Colours::darkmagenta (0xff8b008b);
  63849. const Colour Colours::darkolivegreen (0xff556b2f);
  63850. const Colour Colours::darkorange (0xffff8c00);
  63851. const Colour Colours::darkorchid (0xff9932cc);
  63852. const Colour Colours::darkred (0xff8b0000);
  63853. const Colour Colours::darksalmon (0xffe9967a);
  63854. const Colour Colours::darkseagreen (0xff8fbc8f);
  63855. const Colour Colours::darkslateblue (0xff483d8b);
  63856. const Colour Colours::darkslategrey (0xff2f4f4f);
  63857. const Colour Colours::darkturquoise (0xff00ced1);
  63858. const Colour Colours::darkviolet (0xff9400d3);
  63859. const Colour Colours::deeppink (0xffff1493);
  63860. const Colour Colours::deepskyblue (0xff00bfff);
  63861. const Colour Colours::dimgrey (0xff696969);
  63862. const Colour Colours::dodgerblue (0xff1e90ff);
  63863. const Colour Colours::firebrick (0xffb22222);
  63864. const Colour Colours::floralwhite (0xfffffaf0);
  63865. const Colour Colours::forestgreen (0xff228b22);
  63866. const Colour Colours::fuchsia (0xffff00ff);
  63867. const Colour Colours::gainsboro (0xffdcdcdc);
  63868. const Colour Colours::gold (0xffffd700);
  63869. const Colour Colours::goldenrod (0xffdaa520);
  63870. const Colour Colours::grey (0xff808080);
  63871. const Colour Colours::green (0xff008000);
  63872. const Colour Colours::greenyellow (0xffadff2f);
  63873. const Colour Colours::honeydew (0xfff0fff0);
  63874. const Colour Colours::hotpink (0xffff69b4);
  63875. const Colour Colours::indianred (0xffcd5c5c);
  63876. const Colour Colours::indigo (0xff4b0082);
  63877. const Colour Colours::ivory (0xfffffff0);
  63878. const Colour Colours::khaki (0xfff0e68c);
  63879. const Colour Colours::lavender (0xffe6e6fa);
  63880. const Colour Colours::lavenderblush (0xfffff0f5);
  63881. const Colour Colours::lemonchiffon (0xfffffacd);
  63882. const Colour Colours::lightblue (0xffadd8e6);
  63883. const Colour Colours::lightcoral (0xfff08080);
  63884. const Colour Colours::lightcyan (0xffe0ffff);
  63885. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63886. const Colour Colours::lightgreen (0xff90ee90);
  63887. const Colour Colours::lightgrey (0xffd3d3d3);
  63888. const Colour Colours::lightpink (0xffffb6c1);
  63889. const Colour Colours::lightsalmon (0xffffa07a);
  63890. const Colour Colours::lightseagreen (0xff20b2aa);
  63891. const Colour Colours::lightskyblue (0xff87cefa);
  63892. const Colour Colours::lightslategrey (0xff778899);
  63893. const Colour Colours::lightsteelblue (0xffb0c4de);
  63894. const Colour Colours::lightyellow (0xffffffe0);
  63895. const Colour Colours::lime (0xff00ff00);
  63896. const Colour Colours::limegreen (0xff32cd32);
  63897. const Colour Colours::linen (0xfffaf0e6);
  63898. const Colour Colours::magenta (0xffff00ff);
  63899. const Colour Colours::maroon (0xff800000);
  63900. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63901. const Colour Colours::mediumblue (0xff0000cd);
  63902. const Colour Colours::mediumorchid (0xffba55d3);
  63903. const Colour Colours::mediumpurple (0xff9370db);
  63904. const Colour Colours::mediumseagreen (0xff3cb371);
  63905. const Colour Colours::mediumslateblue (0xff7b68ee);
  63906. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63907. const Colour Colours::mediumturquoise (0xff48d1cc);
  63908. const Colour Colours::mediumvioletred (0xffc71585);
  63909. const Colour Colours::midnightblue (0xff191970);
  63910. const Colour Colours::mintcream (0xfff5fffa);
  63911. const Colour Colours::mistyrose (0xffffe4e1);
  63912. const Colour Colours::navajowhite (0xffffdead);
  63913. const Colour Colours::navy (0xff000080);
  63914. const Colour Colours::oldlace (0xfffdf5e6);
  63915. const Colour Colours::olive (0xff808000);
  63916. const Colour Colours::olivedrab (0xff6b8e23);
  63917. const Colour Colours::orange (0xffffa500);
  63918. const Colour Colours::orangered (0xffff4500);
  63919. const Colour Colours::orchid (0xffda70d6);
  63920. const Colour Colours::palegoldenrod (0xffeee8aa);
  63921. const Colour Colours::palegreen (0xff98fb98);
  63922. const Colour Colours::paleturquoise (0xffafeeee);
  63923. const Colour Colours::palevioletred (0xffdb7093);
  63924. const Colour Colours::papayawhip (0xffffefd5);
  63925. const Colour Colours::peachpuff (0xffffdab9);
  63926. const Colour Colours::peru (0xffcd853f);
  63927. const Colour Colours::pink (0xffffc0cb);
  63928. const Colour Colours::plum (0xffdda0dd);
  63929. const Colour Colours::powderblue (0xffb0e0e6);
  63930. const Colour Colours::purple (0xff800080);
  63931. const Colour Colours::red (0xffff0000);
  63932. const Colour Colours::rosybrown (0xffbc8f8f);
  63933. const Colour Colours::royalblue (0xff4169e1);
  63934. const Colour Colours::saddlebrown (0xff8b4513);
  63935. const Colour Colours::salmon (0xfffa8072);
  63936. const Colour Colours::sandybrown (0xfff4a460);
  63937. const Colour Colours::seagreen (0xff2e8b57);
  63938. const Colour Colours::seashell (0xfffff5ee);
  63939. const Colour Colours::sienna (0xffa0522d);
  63940. const Colour Colours::silver (0xffc0c0c0);
  63941. const Colour Colours::skyblue (0xff87ceeb);
  63942. const Colour Colours::slateblue (0xff6a5acd);
  63943. const Colour Colours::slategrey (0xff708090);
  63944. const Colour Colours::snow (0xfffffafa);
  63945. const Colour Colours::springgreen (0xff00ff7f);
  63946. const Colour Colours::steelblue (0xff4682b4);
  63947. const Colour Colours::tan (0xffd2b48c);
  63948. const Colour Colours::teal (0xff008080);
  63949. const Colour Colours::thistle (0xffd8bfd8);
  63950. const Colour Colours::tomato (0xffff6347);
  63951. const Colour Colours::turquoise (0xff40e0d0);
  63952. const Colour Colours::violet (0xffee82ee);
  63953. const Colour Colours::wheat (0xfff5deb3);
  63954. const Colour Colours::white (0xffffffff);
  63955. const Colour Colours::whitesmoke (0xfff5f5f5);
  63956. const Colour Colours::yellow (0xffffff00);
  63957. const Colour Colours::yellowgreen (0xff9acd32);
  63958. const Colour Colours::findColourForName (const String& colourName,
  63959. const Colour& defaultColour)
  63960. {
  63961. static const int presets[] =
  63962. {
  63963. // (first value is the string's hashcode, second is ARGB)
  63964. 0x05978fff, 0xff000000, /* black */
  63965. 0x06bdcc29, 0xffffffff, /* white */
  63966. 0x002e305a, 0xff0000ff, /* blue */
  63967. 0x00308adf, 0xff808080, /* grey */
  63968. 0x05e0cf03, 0xff008000, /* green */
  63969. 0x0001b891, 0xffff0000, /* red */
  63970. 0xd43c6474, 0xffffff00, /* yellow */
  63971. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63972. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63973. 0x002dcebc, 0xff00ffff, /* aqua */
  63974. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63975. 0x0590228f, 0xfff0ffff, /* azure */
  63976. 0x05947fe4, 0xfff5f5dc, /* beige */
  63977. 0xad388e35, 0xffffe4c4, /* bisque */
  63978. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63979. 0x39129959, 0xff8a2be2, /* blueviolet */
  63980. 0x059a8136, 0xffa52a2a, /* brown */
  63981. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63982. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63983. 0x6b748956, 0xff7fff00, /* chartreuse */
  63984. 0x2903623c, 0xffd2691e, /* chocolate */
  63985. 0x05a74431, 0xffff7f50, /* coral */
  63986. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63987. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63988. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63989. 0x002ed323, 0xff00ffff, /* cyan */
  63990. 0x67cc74d0, 0xff00008b, /* darkblue */
  63991. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63992. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63993. 0x67cecf55, 0xff555555, /* darkgrey */
  63994. 0x920b194d, 0xff006400, /* darkgreen */
  63995. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63996. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63997. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63998. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63999. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  64000. 0x55ee0d5b, 0xff8b0000, /* darkred */
  64001. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  64002. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  64003. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  64004. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  64005. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  64006. 0xc8769375, 0xff9400d3, /* darkviolet */
  64007. 0x25832862, 0xffff1493, /* deeppink */
  64008. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  64009. 0x634c8b67, 0xff696969, /* dimgrey */
  64010. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  64011. 0xef19e3cb, 0xffb22222, /* firebrick */
  64012. 0xb852b195, 0xfffffaf0, /* floralwhite */
  64013. 0xd086fd06, 0xff228b22, /* forestgreen */
  64014. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  64015. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  64016. 0x00308060, 0xffffd700, /* gold */
  64017. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  64018. 0xbab8a537, 0xffadff2f, /* greenyellow */
  64019. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  64020. 0x41892743, 0xffff69b4, /* hotpink */
  64021. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  64022. 0xb969fed2, 0xff4b0082, /* indigo */
  64023. 0x05fef6a9, 0xfffffff0, /* ivory */
  64024. 0x06149302, 0xfff0e68c, /* khaki */
  64025. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  64026. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  64027. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  64028. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  64029. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  64030. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  64031. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  64032. 0xf40157ad, 0xff90ee90, /* lightgreen */
  64033. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  64034. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  64035. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  64036. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  64037. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  64038. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  64039. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  64040. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  64041. 0x0032afd5, 0xff00ff00, /* lime */
  64042. 0x607bbc4e, 0xff32cd32, /* limegreen */
  64043. 0x06234efa, 0xfffaf0e6, /* linen */
  64044. 0x316858a9, 0xffff00ff, /* magenta */
  64045. 0xbf8ca470, 0xff800000, /* maroon */
  64046. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  64047. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  64048. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  64049. 0x07556b71, 0xff9370db, /* mediumpurple */
  64050. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  64051. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  64052. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  64053. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  64054. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  64055. 0x168eb32a, 0xff191970, /* midnightblue */
  64056. 0x4306b960, 0xfff5fffa, /* mintcream */
  64057. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  64058. 0xe97218a6, 0xffffdead, /* navajowhite */
  64059. 0x00337bb6, 0xff000080, /* navy */
  64060. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  64061. 0x064ee1db, 0xff808000, /* olive */
  64062. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  64063. 0xc3de262e, 0xffffa500, /* orange */
  64064. 0x58bebba3, 0xffff4500, /* orangered */
  64065. 0xc3def8a3, 0xffda70d6, /* orchid */
  64066. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  64067. 0x3d9dd619, 0xff98fb98, /* palegreen */
  64068. 0x74022737, 0xffafeeee, /* paleturquoise */
  64069. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  64070. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  64071. 0x93e1b776, 0xffffdab9, /* peachpuff */
  64072. 0x003472f8, 0xffcd853f, /* peru */
  64073. 0x00348176, 0xffffc0cb, /* pink */
  64074. 0x00348d94, 0xffdda0dd, /* plum */
  64075. 0xd036be93, 0xffb0e0e6, /* powderblue */
  64076. 0xc5c507bc, 0xff800080, /* purple */
  64077. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  64078. 0xbd9413e1, 0xff4169e1, /* royalblue */
  64079. 0xf456044f, 0xff8b4513, /* saddlebrown */
  64080. 0xc9c6f66e, 0xfffa8072, /* salmon */
  64081. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  64082. 0x34636c14, 0xff2e8b57, /* seagreen */
  64083. 0x3507fb41, 0xfffff5ee, /* seashell */
  64084. 0xca348772, 0xffa0522d, /* sienna */
  64085. 0xca37d30d, 0xffc0c0c0, /* silver */
  64086. 0x80da74fb, 0xff87ceeb, /* skyblue */
  64087. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  64088. 0x44ab37f8, 0xff708090, /* slategrey */
  64089. 0x0035f183, 0xfffffafa, /* snow */
  64090. 0xd5440d16, 0xff00ff7f, /* springgreen */
  64091. 0x3e1524a5, 0xff4682b4, /* steelblue */
  64092. 0x0001bfa1, 0xffd2b48c, /* tan */
  64093. 0x0036425c, 0xff008080, /* teal */
  64094. 0xafc8858f, 0xffd8bfd8, /* thistle */
  64095. 0xcc41600a, 0xffff6347, /* tomato */
  64096. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  64097. 0xcf57947f, 0xffee82ee, /* violet */
  64098. 0x06bdbae7, 0xfff5deb3, /* wheat */
  64099. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  64100. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  64101. };
  64102. const int hash = colourName.trim().toLowerCase().hashCode();
  64103. for (int i = 0; i < numElementsInArray (presets); i += 2)
  64104. if (presets [i] == hash)
  64105. return Colour (presets [i + 1]);
  64106. return defaultColour;
  64107. }
  64108. END_JUCE_NAMESPACE
  64109. /*** End of inlined file: juce_Colours.cpp ***/
  64110. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  64111. BEGIN_JUCE_NAMESPACE
  64112. const int juce_edgeTableDefaultEdgesPerLine = 32;
  64113. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  64114. const Path& path, const AffineTransform& transform) throw()
  64115. : bounds (bounds_),
  64116. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64117. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64118. needToCheckEmptinesss (true)
  64119. {
  64120. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  64121. int* t = table;
  64122. for (int i = bounds.getHeight(); --i >= 0;)
  64123. {
  64124. *t = 0;
  64125. t += lineStrideElements;
  64126. }
  64127. const int topLimit = bounds.getY() << 8;
  64128. const int heightLimit = bounds.getHeight() << 8;
  64129. const int leftLimit = bounds.getX() << 8;
  64130. const int rightLimit = bounds.getRight() << 8;
  64131. PathFlatteningIterator iter (path, transform);
  64132. while (iter.next())
  64133. {
  64134. int y1 = roundToInt (iter.y1 * 256.0f);
  64135. int y2 = roundToInt (iter.y2 * 256.0f);
  64136. if (y1 != y2)
  64137. {
  64138. y1 -= topLimit;
  64139. y2 -= topLimit;
  64140. const int startY = y1;
  64141. int direction = -1;
  64142. if (y1 > y2)
  64143. {
  64144. swapVariables (y1, y2);
  64145. direction = 1;
  64146. }
  64147. if (y1 < 0)
  64148. y1 = 0;
  64149. if (y2 > heightLimit)
  64150. y2 = heightLimit;
  64151. if (y1 < y2)
  64152. {
  64153. const double startX = 256.0f * iter.x1;
  64154. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  64155. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  64156. do
  64157. {
  64158. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  64159. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  64160. if (x < leftLimit)
  64161. x = leftLimit;
  64162. else if (x >= rightLimit)
  64163. x = rightLimit - 1;
  64164. addEdgePoint (x, y1 >> 8, direction * step);
  64165. y1 += step;
  64166. }
  64167. while (y1 < y2);
  64168. }
  64169. }
  64170. }
  64171. sanitiseLevels (path.isUsingNonZeroWinding());
  64172. }
  64173. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd) throw()
  64174. : bounds (rectangleToAdd),
  64175. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64176. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64177. needToCheckEmptinesss (true)
  64178. {
  64179. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64180. table[0] = 0;
  64181. const int x1 = rectangleToAdd.getX() << 8;
  64182. const int x2 = rectangleToAdd.getRight() << 8;
  64183. int* t = table;
  64184. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  64185. {
  64186. t[0] = 2;
  64187. t[1] = x1;
  64188. t[2] = 255;
  64189. t[3] = x2;
  64190. t[4] = 0;
  64191. t += lineStrideElements;
  64192. }
  64193. }
  64194. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) throw()
  64195. : bounds (rectanglesToAdd.getBounds()),
  64196. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64197. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64198. needToCheckEmptinesss (true)
  64199. {
  64200. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64201. int* t = table;
  64202. for (int i = bounds.getHeight(); --i >= 0;)
  64203. {
  64204. *t = 0;
  64205. t += lineStrideElements;
  64206. }
  64207. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  64208. {
  64209. const Rectangle<int>* const r = iter.getRectangle();
  64210. const int x1 = r->getX() << 8;
  64211. const int x2 = r->getRight() << 8;
  64212. int y = r->getY() - bounds.getY();
  64213. for (int j = r->getHeight(); --j >= 0;)
  64214. {
  64215. addEdgePoint (x1, y, 255);
  64216. addEdgePoint (x2, y, -255);
  64217. ++y;
  64218. }
  64219. }
  64220. sanitiseLevels (true);
  64221. }
  64222. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h) throw()
  64223. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  64224. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64225. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64226. needToCheckEmptinesss (true)
  64227. {
  64228. jassert (w > 0 && h > 0);
  64229. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64230. table[0] = 0;
  64231. const int x1 = roundToInt (x * 256.0f);
  64232. const int x2 = roundToInt ((x + w) * 256.0f);
  64233. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  64234. jassert (y1 < 256);
  64235. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  64236. if (x2 <= x1 || y2 <= y1)
  64237. {
  64238. bounds.setHeight (0);
  64239. return;
  64240. }
  64241. int lineY = 0;
  64242. int* t = table;
  64243. if ((y1 >> 8) == (y2 >> 8))
  64244. {
  64245. t[0] = 2;
  64246. t[1] = x1;
  64247. t[2] = y2 - y1;
  64248. t[3] = x2;
  64249. t[4] = 0;
  64250. ++lineY;
  64251. t += lineStrideElements;
  64252. }
  64253. else
  64254. {
  64255. t[0] = 2;
  64256. t[1] = x1;
  64257. t[2] = 255 - (y1 & 255);
  64258. t[3] = x2;
  64259. t[4] = 0;
  64260. ++lineY;
  64261. t += lineStrideElements;
  64262. while (lineY < (y2 >> 8))
  64263. {
  64264. t[0] = 2;
  64265. t[1] = x1;
  64266. t[2] = 255;
  64267. t[3] = x2;
  64268. t[4] = 0;
  64269. ++lineY;
  64270. t += lineStrideElements;
  64271. }
  64272. jassert (lineY < bounds.getHeight());
  64273. t[0] = 2;
  64274. t[1] = x1;
  64275. t[2] = y2 & 255;
  64276. t[3] = x2;
  64277. t[4] = 0;
  64278. ++lineY;
  64279. t += lineStrideElements;
  64280. }
  64281. while (lineY < bounds.getHeight())
  64282. {
  64283. t[0] = 0;
  64284. t += lineStrideElements;
  64285. ++lineY;
  64286. }
  64287. }
  64288. EdgeTable::EdgeTable (const EdgeTable& other) throw()
  64289. : table (0)
  64290. {
  64291. operator= (other);
  64292. }
  64293. EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw()
  64294. {
  64295. bounds = other.bounds;
  64296. maxEdgesPerLine = other.maxEdgesPerLine;
  64297. lineStrideElements = other.lineStrideElements;
  64298. needToCheckEmptinesss = other.needToCheckEmptinesss;
  64299. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64300. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  64301. return *this;
  64302. }
  64303. EdgeTable::~EdgeTable() throw()
  64304. {
  64305. }
  64306. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  64307. {
  64308. while (--numLines >= 0)
  64309. {
  64310. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  64311. src += srcLineStride;
  64312. dest += destLineStride;
  64313. }
  64314. }
  64315. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  64316. {
  64317. // Convert the table from relative windings to absolute levels..
  64318. int* lineStart = table;
  64319. for (int i = bounds.getHeight(); --i >= 0;)
  64320. {
  64321. int* line = lineStart;
  64322. lineStart += lineStrideElements;
  64323. int num = *line;
  64324. if (num == 0)
  64325. continue;
  64326. int level = 0;
  64327. if (useNonZeroWinding)
  64328. {
  64329. while (--num > 0)
  64330. {
  64331. line += 2;
  64332. level += *line;
  64333. int corrected = abs (level);
  64334. if (corrected >> 8)
  64335. corrected = 255;
  64336. *line = corrected;
  64337. }
  64338. }
  64339. else
  64340. {
  64341. while (--num > 0)
  64342. {
  64343. line += 2;
  64344. level += *line;
  64345. int corrected = abs (level);
  64346. if (corrected >> 8)
  64347. {
  64348. corrected &= 511;
  64349. if (corrected >> 8)
  64350. corrected = 511 - corrected;
  64351. }
  64352. *line = corrected;
  64353. }
  64354. }
  64355. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64356. }
  64357. }
  64358. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64359. {
  64360. if (newNumEdgesPerLine != maxEdgesPerLine)
  64361. {
  64362. maxEdgesPerLine = newNumEdgesPerLine;
  64363. jassert (bounds.getHeight() > 0);
  64364. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64365. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64366. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64367. table.swapWith (newTable);
  64368. lineStrideElements = newLineStrideElements;
  64369. }
  64370. }
  64371. void EdgeTable::optimiseTable() throw()
  64372. {
  64373. int maxLineElements = 0;
  64374. for (int i = bounds.getHeight(); --i >= 0;)
  64375. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64376. remapTableForNumEdges (maxLineElements);
  64377. }
  64378. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64379. {
  64380. jassert (y >= 0 && y < bounds.getHeight());
  64381. int* line = table + lineStrideElements * y;
  64382. const int numPoints = line[0];
  64383. int n = numPoints << 1;
  64384. if (n > 0)
  64385. {
  64386. while (n > 0)
  64387. {
  64388. const int cx = line [n - 1];
  64389. if (cx <= x)
  64390. {
  64391. if (cx == x)
  64392. {
  64393. line [n] += winding;
  64394. return;
  64395. }
  64396. break;
  64397. }
  64398. n -= 2;
  64399. }
  64400. if (numPoints >= maxEdgesPerLine)
  64401. {
  64402. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64403. jassert (numPoints < maxEdgesPerLine);
  64404. line = table + lineStrideElements * y;
  64405. }
  64406. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64407. }
  64408. line [n + 1] = x;
  64409. line [n + 2] = winding;
  64410. line[0]++;
  64411. }
  64412. void EdgeTable::translate (float dx, int dy) throw()
  64413. {
  64414. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64415. int* lineStart = table;
  64416. const int intDx = (int) (dx * 256.0f);
  64417. for (int i = bounds.getHeight(); --i >= 0;)
  64418. {
  64419. int* line = lineStart;
  64420. lineStart += lineStrideElements;
  64421. int num = *line++;
  64422. while (--num >= 0)
  64423. {
  64424. *line += intDx;
  64425. line += 2;
  64426. }
  64427. }
  64428. }
  64429. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64430. {
  64431. jassert (y >= 0 && y < bounds.getHeight());
  64432. int* dest = table + lineStrideElements * y;
  64433. if (dest[0] == 0)
  64434. return;
  64435. int otherNumPoints = *otherLine;
  64436. if (otherNumPoints == 0)
  64437. {
  64438. *dest = 0;
  64439. return;
  64440. }
  64441. const int right = bounds.getRight() << 8;
  64442. // optimise for the common case where our line lies entirely within a
  64443. // single pair of points, as happens when clipping to a simple rect.
  64444. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64445. {
  64446. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64447. return;
  64448. }
  64449. ++otherLine;
  64450. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64451. int* temp = (int*) alloca (lineSizeBytes);
  64452. memcpy (temp, dest, lineSizeBytes);
  64453. const int* src1 = temp;
  64454. int srcNum1 = *src1++;
  64455. int x1 = *src1++;
  64456. const int* src2 = otherLine;
  64457. int srcNum2 = otherNumPoints;
  64458. int x2 = *src2++;
  64459. int destIndex = 0, destTotal = 0;
  64460. int level1 = 0, level2 = 0;
  64461. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64462. while (srcNum1 > 0 && srcNum2 > 0)
  64463. {
  64464. int nextX;
  64465. if (x1 < x2)
  64466. {
  64467. nextX = x1;
  64468. level1 = *src1++;
  64469. x1 = *src1++;
  64470. --srcNum1;
  64471. }
  64472. else if (x1 == x2)
  64473. {
  64474. nextX = x1;
  64475. level1 = *src1++;
  64476. level2 = *src2++;
  64477. x1 = *src1++;
  64478. x2 = *src2++;
  64479. --srcNum1;
  64480. --srcNum2;
  64481. }
  64482. else
  64483. {
  64484. nextX = x2;
  64485. level2 = *src2++;
  64486. x2 = *src2++;
  64487. --srcNum2;
  64488. }
  64489. if (nextX > lastX)
  64490. {
  64491. if (nextX >= right)
  64492. break;
  64493. lastX = nextX;
  64494. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64495. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64496. if (nextLevel != lastLevel)
  64497. {
  64498. if (destTotal >= maxEdgesPerLine)
  64499. {
  64500. dest[0] = destTotal;
  64501. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64502. dest = table + lineStrideElements * y;
  64503. }
  64504. ++destTotal;
  64505. lastLevel = nextLevel;
  64506. dest[++destIndex] = nextX;
  64507. dest[++destIndex] = nextLevel;
  64508. }
  64509. }
  64510. }
  64511. if (lastLevel > 0)
  64512. {
  64513. if (destTotal >= maxEdgesPerLine)
  64514. {
  64515. dest[0] = destTotal;
  64516. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64517. dest = table + lineStrideElements * y;
  64518. }
  64519. ++destTotal;
  64520. dest[++destIndex] = right;
  64521. dest[++destIndex] = 0;
  64522. }
  64523. dest[0] = destTotal;
  64524. #if JUCE_DEBUG
  64525. int last = std::numeric_limits<int>::min();
  64526. for (int i = 0; i < dest[0]; ++i)
  64527. {
  64528. jassert (dest[i * 2 + 1] > last);
  64529. last = dest[i * 2 + 1];
  64530. }
  64531. jassert (dest [dest[0] * 2] == 0);
  64532. #endif
  64533. }
  64534. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64535. {
  64536. int* lastItem = dest + (dest[0] * 2 - 1);
  64537. if (x2 < lastItem[0])
  64538. {
  64539. if (x2 <= dest[1])
  64540. {
  64541. dest[0] = 0;
  64542. return;
  64543. }
  64544. while (x2 < lastItem[-2])
  64545. {
  64546. --(dest[0]);
  64547. lastItem -= 2;
  64548. }
  64549. lastItem[0] = x2;
  64550. lastItem[1] = 0;
  64551. }
  64552. if (x1 > dest[1])
  64553. {
  64554. while (lastItem[0] > x1)
  64555. lastItem -= 2;
  64556. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64557. if (itemsRemoved > 0)
  64558. {
  64559. dest[0] -= itemsRemoved;
  64560. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64561. }
  64562. dest[1] = x1;
  64563. }
  64564. }
  64565. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64566. {
  64567. const Rectangle<int> clipped (r.getIntersection (bounds));
  64568. if (clipped.isEmpty())
  64569. {
  64570. needToCheckEmptinesss = false;
  64571. bounds.setHeight (0);
  64572. }
  64573. else
  64574. {
  64575. const int top = clipped.getY() - bounds.getY();
  64576. const int bottom = clipped.getBottom() - bounds.getY();
  64577. if (bottom < bounds.getHeight())
  64578. bounds.setHeight (bottom);
  64579. if (clipped.getRight() < bounds.getRight())
  64580. bounds.setRight (clipped.getRight());
  64581. for (int i = top; --i >= 0;)
  64582. table [lineStrideElements * i] = 0;
  64583. if (clipped.getX() > bounds.getX())
  64584. {
  64585. const int x1 = clipped.getX() << 8;
  64586. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64587. int* line = table + lineStrideElements * top;
  64588. for (int i = bottom - top; --i >= 0;)
  64589. {
  64590. if (line[0] != 0)
  64591. clipEdgeTableLineToRange (line, x1, x2);
  64592. line += lineStrideElements;
  64593. }
  64594. }
  64595. needToCheckEmptinesss = true;
  64596. }
  64597. }
  64598. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64599. {
  64600. const Rectangle<int> clipped (r.getIntersection (bounds));
  64601. if (! clipped.isEmpty())
  64602. {
  64603. const int top = clipped.getY() - bounds.getY();
  64604. const int bottom = clipped.getBottom() - bounds.getY();
  64605. //XXX optimise here by shortening the table if it fills top or bottom
  64606. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64607. clipped.getX() << 8, 0,
  64608. clipped.getRight() << 8, 255,
  64609. std::numeric_limits<int>::max(), 0 };
  64610. for (int i = top; i < bottom; ++i)
  64611. intersectWithEdgeTableLine (i, rectLine);
  64612. needToCheckEmptinesss = true;
  64613. }
  64614. }
  64615. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64616. {
  64617. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64618. if (clipped.isEmpty())
  64619. {
  64620. needToCheckEmptinesss = false;
  64621. bounds.setHeight (0);
  64622. }
  64623. else
  64624. {
  64625. const int top = clipped.getY() - bounds.getY();
  64626. const int bottom = clipped.getBottom() - bounds.getY();
  64627. if (bottom < bounds.getHeight())
  64628. bounds.setHeight (bottom);
  64629. if (clipped.getRight() < bounds.getRight())
  64630. bounds.setRight (clipped.getRight());
  64631. int i = 0;
  64632. for (i = top; --i >= 0;)
  64633. table [lineStrideElements * i] = 0;
  64634. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64635. for (i = top; i < bottom; ++i)
  64636. {
  64637. intersectWithEdgeTableLine (i, otherLine);
  64638. otherLine += other.lineStrideElements;
  64639. }
  64640. needToCheckEmptinesss = true;
  64641. }
  64642. }
  64643. void EdgeTable::clipLineToMask (int x, int y, uint8* mask, int maskStride, int numPixels) throw()
  64644. {
  64645. y -= bounds.getY();
  64646. if (y < 0 || y >= bounds.getHeight())
  64647. return;
  64648. needToCheckEmptinesss = true;
  64649. if (numPixels <= 0)
  64650. {
  64651. table [lineStrideElements * y] = 0;
  64652. return;
  64653. }
  64654. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64655. int destIndex = 0, lastLevel = 0;
  64656. while (--numPixels >= 0)
  64657. {
  64658. const int alpha = *mask;
  64659. mask += maskStride;
  64660. if (alpha != lastLevel)
  64661. {
  64662. tempLine[++destIndex] = (x << 8);
  64663. tempLine[++destIndex] = alpha;
  64664. lastLevel = alpha;
  64665. }
  64666. ++x;
  64667. }
  64668. if (lastLevel > 0)
  64669. {
  64670. tempLine[++destIndex] = (x << 8);
  64671. tempLine[++destIndex] = 0;
  64672. }
  64673. tempLine[0] = destIndex >> 1;
  64674. intersectWithEdgeTableLine (y, tempLine);
  64675. }
  64676. bool EdgeTable::isEmpty() throw()
  64677. {
  64678. if (needToCheckEmptinesss)
  64679. {
  64680. needToCheckEmptinesss = false;
  64681. int* t = table;
  64682. for (int i = bounds.getHeight(); --i >= 0;)
  64683. {
  64684. if (t[0] > 1)
  64685. return false;
  64686. t += lineStrideElements;
  64687. }
  64688. bounds.setHeight (0);
  64689. }
  64690. return bounds.getHeight() == 0;
  64691. }
  64692. END_JUCE_NAMESPACE
  64693. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64694. /*** Start of inlined file: juce_FillType.cpp ***/
  64695. BEGIN_JUCE_NAMESPACE
  64696. FillType::FillType() throw()
  64697. : colour (0xff000000), image (0)
  64698. {
  64699. }
  64700. FillType::FillType (const Colour& colour_) throw()
  64701. : colour (colour_), image (0)
  64702. {
  64703. }
  64704. FillType::FillType (const ColourGradient& gradient_) throw()
  64705. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64706. {
  64707. }
  64708. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64709. : colour (0xff000000), image (&image_), transform (transform_)
  64710. {
  64711. }
  64712. FillType::FillType (const FillType& other) throw()
  64713. : colour (other.colour),
  64714. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64715. image (other.image), transform (other.transform)
  64716. {
  64717. }
  64718. FillType& FillType::operator= (const FillType& other) throw()
  64719. {
  64720. if (this != &other)
  64721. {
  64722. colour = other.colour;
  64723. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64724. image = other.image;
  64725. transform = other.transform;
  64726. }
  64727. return *this;
  64728. }
  64729. FillType::~FillType() throw()
  64730. {
  64731. }
  64732. void FillType::setColour (const Colour& newColour) throw()
  64733. {
  64734. gradient = 0;
  64735. image = 0;
  64736. colour = newColour;
  64737. }
  64738. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64739. {
  64740. if (gradient != 0)
  64741. {
  64742. *gradient = newGradient;
  64743. }
  64744. else
  64745. {
  64746. image = 0;
  64747. gradient = new ColourGradient (newGradient);
  64748. colour = Colours::black;
  64749. }
  64750. }
  64751. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64752. {
  64753. gradient = 0;
  64754. image = &image_;
  64755. transform = transform_;
  64756. colour = Colours::black;
  64757. }
  64758. void FillType::setOpacity (const float newOpacity) throw()
  64759. {
  64760. colour = colour.withAlpha (newOpacity);
  64761. }
  64762. END_JUCE_NAMESPACE
  64763. /*** End of inlined file: juce_FillType.cpp ***/
  64764. /*** Start of inlined file: juce_Graphics.cpp ***/
  64765. BEGIN_JUCE_NAMESPACE
  64766. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64767. template <typename Type>
  64768. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64769. {
  64770. const int maxVal = 0x3fffffff;
  64771. return (int) x >= -maxVal && (int) x <= maxVal
  64772. && (int) y >= -maxVal && (int) y <= maxVal
  64773. && (int) w >= -maxVal && (int) w <= maxVal
  64774. && (int) h >= -maxVal && (int) h <= maxVal;
  64775. }
  64776. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64777. {
  64778. }
  64779. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64780. {
  64781. }
  64782. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64783. : context (imageToDrawOnto.createLowLevelContext()),
  64784. contextToDelete (context),
  64785. saveStatePending (false)
  64786. {
  64787. resetToDefaultState();
  64788. }
  64789. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64790. : context (internalContext),
  64791. saveStatePending (false)
  64792. {
  64793. resetToDefaultState();
  64794. }
  64795. Graphics::~Graphics() throw()
  64796. {
  64797. }
  64798. void Graphics::resetToDefaultState() throw()
  64799. {
  64800. saveStateIfPending();
  64801. context->setFill (FillType());
  64802. context->setFont (Font());
  64803. context->setInterpolationQuality (defaultQuality);
  64804. }
  64805. bool Graphics::isVectorDevice() const throw()
  64806. {
  64807. return context->isVectorDevice();
  64808. }
  64809. bool Graphics::reduceClipRegion (const int x, const int y,
  64810. const int w, const int h) throw()
  64811. {
  64812. saveStateIfPending();
  64813. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64814. }
  64815. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64816. {
  64817. saveStateIfPending();
  64818. return context->clipToRectangleList (clipRegion);
  64819. }
  64820. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64821. {
  64822. saveStateIfPending();
  64823. context->clipToPath (path, transform);
  64824. return ! context->isClipEmpty();
  64825. }
  64826. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64827. {
  64828. saveStateIfPending();
  64829. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64830. return ! context->isClipEmpty();
  64831. }
  64832. void Graphics::excludeClipRegion (const int x, const int y,
  64833. const int w, const int h) throw()
  64834. {
  64835. saveStateIfPending();
  64836. context->excludeClipRectangle (Rectangle<int> (x, y, w, h));
  64837. }
  64838. bool Graphics::isClipEmpty() const throw()
  64839. {
  64840. return context->isClipEmpty();
  64841. }
  64842. const Rectangle<int> Graphics::getClipBounds() const throw()
  64843. {
  64844. return context->getClipBounds();
  64845. }
  64846. void Graphics::saveState() throw()
  64847. {
  64848. saveStateIfPending();
  64849. saveStatePending = true;
  64850. }
  64851. void Graphics::restoreState() throw()
  64852. {
  64853. if (saveStatePending)
  64854. saveStatePending = false;
  64855. else
  64856. context->restoreState();
  64857. }
  64858. void Graphics::saveStateIfPending() throw()
  64859. {
  64860. if (saveStatePending)
  64861. {
  64862. saveStatePending = false;
  64863. context->saveState();
  64864. }
  64865. }
  64866. void Graphics::setOrigin (const int newOriginX,
  64867. const int newOriginY) throw()
  64868. {
  64869. saveStateIfPending();
  64870. context->setOrigin (newOriginX, newOriginY);
  64871. }
  64872. bool Graphics::clipRegionIntersects (const int x, const int y,
  64873. const int w, const int h) const throw()
  64874. {
  64875. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64876. }
  64877. void Graphics::setColour (const Colour& newColour) throw()
  64878. {
  64879. saveStateIfPending();
  64880. context->setFill (FillType (newColour));
  64881. }
  64882. void Graphics::setOpacity (const float newOpacity) throw()
  64883. {
  64884. saveStateIfPending();
  64885. context->setOpacity (newOpacity);
  64886. }
  64887. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64888. {
  64889. saveStateIfPending();
  64890. context->setFill (FillType (gradient));
  64891. }
  64892. void Graphics::setTiledImageFill (const Image& imageToUse,
  64893. const int anchorX,
  64894. const int anchorY,
  64895. const float opacity) throw()
  64896. {
  64897. saveStateIfPending();
  64898. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64899. context->setOpacity (opacity);
  64900. }
  64901. void Graphics::setFillType (const FillType& newFill) throw()
  64902. {
  64903. saveStateIfPending();
  64904. context->setFill (newFill);
  64905. }
  64906. void Graphics::setFont (const Font& newFont) throw()
  64907. {
  64908. saveStateIfPending();
  64909. context->setFont (newFont);
  64910. }
  64911. void Graphics::setFont (const float newFontHeight,
  64912. const int newFontStyleFlags) throw()
  64913. {
  64914. saveStateIfPending();
  64915. Font f (context->getFont());
  64916. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64917. context->setFont (f);
  64918. }
  64919. void Graphics::drawSingleLineText (const String& text,
  64920. const int startX,
  64921. const int baselineY) const throw()
  64922. {
  64923. if (text.isNotEmpty()
  64924. && startX < context->getClipBounds().getRight())
  64925. {
  64926. GlyphArrangement arr;
  64927. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64928. arr.draw (*this);
  64929. }
  64930. }
  64931. void Graphics::drawTextAsPath (const String& text,
  64932. const AffineTransform& transform) const throw()
  64933. {
  64934. if (text.isNotEmpty())
  64935. {
  64936. GlyphArrangement arr;
  64937. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64938. arr.draw (*this, transform);
  64939. }
  64940. }
  64941. void Graphics::drawMultiLineText (const String& text,
  64942. const int startX,
  64943. const int baselineY,
  64944. const int maximumLineWidth) const throw()
  64945. {
  64946. if (text.isNotEmpty()
  64947. && startX < context->getClipBounds().getRight())
  64948. {
  64949. GlyphArrangement arr;
  64950. arr.addJustifiedText (context->getFont(), text,
  64951. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64952. Justification::left);
  64953. arr.draw (*this);
  64954. }
  64955. }
  64956. void Graphics::drawText (const String& text,
  64957. const int x,
  64958. const int y,
  64959. const int width,
  64960. const int height,
  64961. const Justification& justificationType,
  64962. const bool useEllipsesIfTooBig) const throw()
  64963. {
  64964. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64965. {
  64966. GlyphArrangement arr;
  64967. arr.addCurtailedLineOfText (context->getFont(), text,
  64968. 0.0f, 0.0f, (float)width,
  64969. useEllipsesIfTooBig);
  64970. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64971. (float) x, (float) y,
  64972. (float) width, (float) height,
  64973. justificationType);
  64974. arr.draw (*this);
  64975. }
  64976. }
  64977. void Graphics::drawFittedText (const String& text,
  64978. const int x,
  64979. const int y,
  64980. const int width,
  64981. const int height,
  64982. const Justification& justification,
  64983. const int maximumNumberOfLines,
  64984. const float minimumHorizontalScale) const throw()
  64985. {
  64986. if (text.isNotEmpty()
  64987. && width > 0 && height > 0
  64988. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64989. {
  64990. GlyphArrangement arr;
  64991. arr.addFittedText (context->getFont(), text,
  64992. (float) x, (float) y,
  64993. (float) width, (float) height,
  64994. justification,
  64995. maximumNumberOfLines,
  64996. minimumHorizontalScale);
  64997. arr.draw (*this);
  64998. }
  64999. }
  65000. void Graphics::fillRect (int x,
  65001. int y,
  65002. int width,
  65003. int height) const throw()
  65004. {
  65005. // passing in a silly number can cause maths problems in rendering!
  65006. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65007. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65008. }
  65009. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  65010. {
  65011. context->fillRect (r, false);
  65012. }
  65013. void Graphics::fillRect (const float x,
  65014. const float y,
  65015. const float width,
  65016. const float height) const throw()
  65017. {
  65018. // passing in a silly number can cause maths problems in rendering!
  65019. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65020. Path p;
  65021. p.addRectangle (x, y, width, height);
  65022. fillPath (p);
  65023. }
  65024. void Graphics::setPixel (int x, int y) const throw()
  65025. {
  65026. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  65027. }
  65028. void Graphics::fillAll() const throw()
  65029. {
  65030. fillRect (context->getClipBounds());
  65031. }
  65032. void Graphics::fillAll (const Colour& colourToUse) const throw()
  65033. {
  65034. if (! colourToUse.isTransparent())
  65035. {
  65036. const Rectangle<int> clip (context->getClipBounds());
  65037. context->saveState();
  65038. context->setFill (FillType (colourToUse));
  65039. context->fillRect (clip, false);
  65040. context->restoreState();
  65041. }
  65042. }
  65043. void Graphics::fillPath (const Path& path,
  65044. const AffineTransform& transform) const throw()
  65045. {
  65046. if ((! context->isClipEmpty()) && ! path.isEmpty())
  65047. context->fillPath (path, transform);
  65048. }
  65049. void Graphics::strokePath (const Path& path,
  65050. const PathStrokeType& strokeType,
  65051. const AffineTransform& transform) const throw()
  65052. {
  65053. Path stroke;
  65054. strokeType.createStrokedPath (stroke, path, transform);
  65055. fillPath (stroke);
  65056. }
  65057. void Graphics::drawRect (const int x,
  65058. const int y,
  65059. const int width,
  65060. const int height,
  65061. const int lineThickness) const throw()
  65062. {
  65063. // passing in a silly number can cause maths problems in rendering!
  65064. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65065. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  65066. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65067. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65068. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  65069. }
  65070. void Graphics::drawRect (const float x,
  65071. const float y,
  65072. const float width,
  65073. const float height,
  65074. const float lineThickness) const throw()
  65075. {
  65076. // passing in a silly number can cause maths problems in rendering!
  65077. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65078. Path p;
  65079. p.addRectangle (x, y, width, lineThickness);
  65080. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65081. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65082. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  65083. fillPath (p);
  65084. }
  65085. void Graphics::drawRect (const Rectangle<int>& r,
  65086. const int lineThickness) const throw()
  65087. {
  65088. drawRect (r.getX(), r.getY(),
  65089. r.getWidth(), r.getHeight(),
  65090. lineThickness);
  65091. }
  65092. void Graphics::drawBevel (const int x,
  65093. const int y,
  65094. const int width,
  65095. const int height,
  65096. const int bevelThickness,
  65097. const Colour& topLeftColour,
  65098. const Colour& bottomRightColour,
  65099. const bool useGradient,
  65100. const bool sharpEdgeOnOutside) const throw()
  65101. {
  65102. // passing in a silly number can cause maths problems in rendering!
  65103. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65104. if (clipRegionIntersects (x, y, width, height))
  65105. {
  65106. context->saveState();
  65107. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  65108. const float ramp = oldOpacity / bevelThickness;
  65109. for (int i = bevelThickness; --i >= 0;)
  65110. {
  65111. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  65112. : oldOpacity;
  65113. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  65114. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  65115. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  65116. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  65117. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  65118. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  65119. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  65120. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  65121. }
  65122. context->restoreState();
  65123. }
  65124. }
  65125. void Graphics::fillEllipse (const float x,
  65126. const float y,
  65127. const float width,
  65128. const float height) const throw()
  65129. {
  65130. // passing in a silly number can cause maths problems in rendering!
  65131. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65132. Path p;
  65133. p.addEllipse (x, y, width, height);
  65134. fillPath (p);
  65135. }
  65136. void Graphics::drawEllipse (const float x,
  65137. const float y,
  65138. const float width,
  65139. const float height,
  65140. const float lineThickness) const throw()
  65141. {
  65142. // passing in a silly number can cause maths problems in rendering!
  65143. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65144. Path p;
  65145. p.addEllipse (x, y, width, height);
  65146. strokePath (p, PathStrokeType (lineThickness));
  65147. }
  65148. void Graphics::fillRoundedRectangle (const float x,
  65149. const float y,
  65150. const float width,
  65151. const float height,
  65152. const float cornerSize) const throw()
  65153. {
  65154. // passing in a silly number can cause maths problems in rendering!
  65155. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65156. Path p;
  65157. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65158. fillPath (p);
  65159. }
  65160. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  65161. const float cornerSize) const throw()
  65162. {
  65163. fillRoundedRectangle ((float) r.getX(),
  65164. (float) r.getY(),
  65165. (float) r.getWidth(),
  65166. (float) r.getHeight(),
  65167. cornerSize);
  65168. }
  65169. void Graphics::drawRoundedRectangle (const float x,
  65170. const float y,
  65171. const float width,
  65172. const float height,
  65173. const float cornerSize,
  65174. const float lineThickness) const throw()
  65175. {
  65176. // passing in a silly number can cause maths problems in rendering!
  65177. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65178. Path p;
  65179. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65180. strokePath (p, PathStrokeType (lineThickness));
  65181. }
  65182. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  65183. const float cornerSize,
  65184. const float lineThickness) const throw()
  65185. {
  65186. drawRoundedRectangle ((float) r.getX(),
  65187. (float) r.getY(),
  65188. (float) r.getWidth(),
  65189. (float) r.getHeight(),
  65190. cornerSize, lineThickness);
  65191. }
  65192. void Graphics::drawArrow (const float startX,
  65193. const float startY,
  65194. const float endX,
  65195. const float endY,
  65196. const float lineThickness,
  65197. const float arrowheadWidth,
  65198. const float arrowheadLength) const throw()
  65199. {
  65200. Path p;
  65201. p.addArrow (startX, startY, endX, endY,
  65202. lineThickness, arrowheadWidth, arrowheadLength);
  65203. fillPath (p);
  65204. }
  65205. void Graphics::fillCheckerBoard (int x, int y,
  65206. int width, int height,
  65207. const int checkWidth,
  65208. const int checkHeight,
  65209. const Colour& colour1,
  65210. const Colour& colour2) const throw()
  65211. {
  65212. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  65213. if (checkWidth > 0 && checkHeight > 0)
  65214. {
  65215. context->saveState();
  65216. if (colour1 == colour2)
  65217. {
  65218. context->setFill (FillType (colour1));
  65219. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65220. }
  65221. else
  65222. {
  65223. const Rectangle<int> clip (context->getClipBounds());
  65224. const int right = jmin (x + width, clip.getRight());
  65225. const int bottom = jmin (y + height, clip.getBottom());
  65226. int cy = 0;
  65227. while (y < bottom)
  65228. {
  65229. int cx = cy;
  65230. for (int xx = x; xx < right; xx += checkWidth)
  65231. {
  65232. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  65233. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  65234. false);
  65235. }
  65236. ++cy;
  65237. y += checkHeight;
  65238. }
  65239. }
  65240. context->restoreState();
  65241. }
  65242. }
  65243. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  65244. {
  65245. context->drawVerticalLine (x, top, bottom);
  65246. }
  65247. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  65248. {
  65249. context->drawHorizontalLine (y, left, right);
  65250. }
  65251. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  65252. {
  65253. context->drawLine (x1, y1, x2, y2);
  65254. }
  65255. void Graphics::drawLine (const float startX,
  65256. const float startY,
  65257. const float endX,
  65258. const float endY,
  65259. const float lineThickness) const throw()
  65260. {
  65261. Path p;
  65262. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  65263. fillPath (p);
  65264. }
  65265. void Graphics::drawLine (const Line& line) const throw()
  65266. {
  65267. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  65268. }
  65269. void Graphics::drawLine (const Line& line,
  65270. const float lineThickness) const throw()
  65271. {
  65272. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  65273. }
  65274. void Graphics::drawDashedLine (const float startX,
  65275. const float startY,
  65276. const float endX,
  65277. const float endY,
  65278. const float* const dashLengths,
  65279. const int numDashLengths,
  65280. const float lineThickness) const throw()
  65281. {
  65282. const double dx = endX - startX;
  65283. const double dy = endY - startY;
  65284. const double totalLen = juce_hypot (dx, dy);
  65285. if (totalLen >= 0.5)
  65286. {
  65287. const double onePixAlpha = 1.0 / totalLen;
  65288. double alpha = 0.0;
  65289. float x = startX;
  65290. float y = startY;
  65291. int n = 0;
  65292. while (alpha < 1.0f)
  65293. {
  65294. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  65295. n = n % numDashLengths;
  65296. const float oldX = x;
  65297. const float oldY = y;
  65298. x = (float) (startX + dx * alpha);
  65299. y = (float) (startY + dy * alpha);
  65300. if ((n & 1) != 0)
  65301. {
  65302. if (lineThickness != 1.0f)
  65303. drawLine (oldX, oldY, x, y, lineThickness);
  65304. else
  65305. drawLine (oldX, oldY, x, y);
  65306. }
  65307. }
  65308. }
  65309. }
  65310. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  65311. {
  65312. saveStateIfPending();
  65313. context->setInterpolationQuality (newQuality);
  65314. }
  65315. void Graphics::drawImageAt (const Image* const imageToDraw,
  65316. const int topLeftX,
  65317. const int topLeftY,
  65318. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65319. {
  65320. if (imageToDraw != 0)
  65321. {
  65322. const int imageW = imageToDraw->getWidth();
  65323. const int imageH = imageToDraw->getHeight();
  65324. drawImage (imageToDraw,
  65325. topLeftX, topLeftY, imageW, imageH,
  65326. 0, 0, imageW, imageH,
  65327. fillAlphaChannelWithCurrentBrush);
  65328. }
  65329. }
  65330. void Graphics::drawImageWithin (const Image* const imageToDraw,
  65331. const int destX,
  65332. const int destY,
  65333. const int destW,
  65334. const int destH,
  65335. const RectanglePlacement& placementWithinTarget,
  65336. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65337. {
  65338. // passing in a silly number can cause maths problems in rendering!
  65339. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  65340. if (imageToDraw != 0)
  65341. {
  65342. const int imageW = imageToDraw->getWidth();
  65343. const int imageH = imageToDraw->getHeight();
  65344. if (imageW > 0 && imageH > 0)
  65345. {
  65346. double newX = 0.0, newY = 0.0;
  65347. double newW = imageW;
  65348. double newH = imageH;
  65349. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65350. destX, destY, destW, destH);
  65351. if (newW > 0 && newH > 0)
  65352. {
  65353. drawImage (imageToDraw,
  65354. roundToInt (newX), roundToInt (newY),
  65355. roundToInt (newW), roundToInt (newH),
  65356. 0, 0, imageW, imageH,
  65357. fillAlphaChannelWithCurrentBrush);
  65358. }
  65359. }
  65360. }
  65361. }
  65362. void Graphics::drawImage (const Image* const imageToDraw,
  65363. int dx, int dy, int dw, int dh,
  65364. int sx, int sy, int sw, int sh,
  65365. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65366. {
  65367. // passing in a silly number can cause maths problems in rendering!
  65368. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65369. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65370. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  65371. {
  65372. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  65373. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65374. .translated ((float) dx, (float) dy),
  65375. fillAlphaChannelWithCurrentBrush);
  65376. }
  65377. }
  65378. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65379. const Rectangle<int>& imageSubRegion,
  65380. const AffineTransform& transform,
  65381. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65382. {
  65383. if (imageToDraw != 0 && ! context->isClipEmpty())
  65384. {
  65385. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65386. if (fillAlphaChannelWithCurrentBrush)
  65387. {
  65388. context->saveState();
  65389. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65390. fillAll();
  65391. context->restoreState();
  65392. }
  65393. else
  65394. {
  65395. context->drawImage (*imageToDraw, srcClip, transform, false);
  65396. }
  65397. }
  65398. }
  65399. END_JUCE_NAMESPACE
  65400. /*** End of inlined file: juce_Graphics.cpp ***/
  65401. /*** Start of inlined file: juce_Justification.cpp ***/
  65402. BEGIN_JUCE_NAMESPACE
  65403. Justification::Justification (const Justification& other) throw()
  65404. : flags (other.flags)
  65405. {
  65406. }
  65407. Justification& Justification::operator= (const Justification& other) throw()
  65408. {
  65409. flags = other.flags;
  65410. return *this;
  65411. }
  65412. int Justification::getOnlyVerticalFlags() const throw()
  65413. {
  65414. return flags & (top | bottom | verticallyCentred);
  65415. }
  65416. int Justification::getOnlyHorizontalFlags() const throw()
  65417. {
  65418. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65419. }
  65420. void Justification::applyToRectangle (int& x, int& y,
  65421. const int w, const int h,
  65422. const int spaceX, const int spaceY,
  65423. const int spaceW, const int spaceH) const throw()
  65424. {
  65425. if ((flags & horizontallyCentred) != 0)
  65426. {
  65427. x = spaceX + ((spaceW - w) >> 1);
  65428. }
  65429. else if ((flags & right) != 0)
  65430. {
  65431. x = spaceX + spaceW - w;
  65432. }
  65433. else
  65434. {
  65435. x = spaceX;
  65436. }
  65437. if ((flags & verticallyCentred) != 0)
  65438. {
  65439. y = spaceY + ((spaceH - h) >> 1);
  65440. }
  65441. else if ((flags & bottom) != 0)
  65442. {
  65443. y = spaceY + spaceH - h;
  65444. }
  65445. else
  65446. {
  65447. y = spaceY;
  65448. }
  65449. }
  65450. END_JUCE_NAMESPACE
  65451. /*** End of inlined file: juce_Justification.cpp ***/
  65452. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65453. BEGIN_JUCE_NAMESPACE
  65454. // this will throw an assertion if you try to draw something that's not
  65455. // possible in postscript
  65456. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65457. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65458. #define notPossibleInPostscriptAssert jassertfalse
  65459. #else
  65460. #define notPossibleInPostscriptAssert
  65461. #endif
  65462. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65463. const String& documentTitle,
  65464. const int totalWidth_,
  65465. const int totalHeight_)
  65466. : out (resultingPostScript),
  65467. totalWidth (totalWidth_),
  65468. totalHeight (totalHeight_),
  65469. needToClip (true)
  65470. {
  65471. stateStack.add (new SavedState());
  65472. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65473. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65474. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65475. "\n%%BoundingBox: 0 0 600 824"
  65476. "\n%%Pages: 0"
  65477. "\n%%Creator: Raw Material Software JUCE"
  65478. "\n%%Title: " << documentTitle <<
  65479. "\n%%CreationDate: none"
  65480. "\n%%LanguageLevel: 2"
  65481. "\n%%EndComments"
  65482. "\n%%BeginProlog"
  65483. "\n%%BeginResource: JRes"
  65484. "\n/bd {bind def} bind def"
  65485. "\n/c {setrgbcolor} bd"
  65486. "\n/m {moveto} bd"
  65487. "\n/l {lineto} bd"
  65488. "\n/rl {rlineto} bd"
  65489. "\n/ct {curveto} bd"
  65490. "\n/cp {closepath} bd"
  65491. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65492. "\n/doclip {initclip newpath} bd"
  65493. "\n/endclip {clip newpath} bd"
  65494. "\n%%EndResource"
  65495. "\n%%EndProlog"
  65496. "\n%%BeginSetup"
  65497. "\n%%EndSetup"
  65498. "\n%%Page: 1 1"
  65499. "\n%%BeginPageSetup"
  65500. "\n%%EndPageSetup\n\n"
  65501. << "40 800 translate\n"
  65502. << scale << ' ' << scale << " scale\n\n";
  65503. }
  65504. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65505. {
  65506. }
  65507. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65508. {
  65509. return true;
  65510. }
  65511. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65512. {
  65513. if (x != 0 || y != 0)
  65514. {
  65515. stateStack.getLast()->xOffset += x;
  65516. stateStack.getLast()->yOffset += y;
  65517. needToClip = true;
  65518. }
  65519. }
  65520. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65521. {
  65522. needToClip = true;
  65523. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65524. }
  65525. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65526. {
  65527. needToClip = true;
  65528. return stateStack.getLast()->clip.clipTo (clipRegion);
  65529. }
  65530. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65531. {
  65532. needToClip = true;
  65533. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65534. }
  65535. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65536. {
  65537. writeClip();
  65538. Path p (path);
  65539. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65540. writePath (p);
  65541. out << "clip\n";
  65542. }
  65543. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65544. {
  65545. needToClip = true;
  65546. jassertfalse // xxx
  65547. }
  65548. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65549. {
  65550. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65551. }
  65552. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65553. {
  65554. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65555. -stateStack.getLast()->yOffset);
  65556. }
  65557. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65558. {
  65559. return stateStack.getLast()->clip.isEmpty();
  65560. }
  65561. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65562. : xOffset (0),
  65563. yOffset (0)
  65564. {
  65565. }
  65566. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65567. {
  65568. }
  65569. void LowLevelGraphicsPostScriptRenderer::saveState()
  65570. {
  65571. stateStack.add (new SavedState (*stateStack.getLast()));
  65572. }
  65573. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65574. {
  65575. jassert (stateStack.size() > 0);
  65576. if (stateStack.size() > 0)
  65577. stateStack.removeLast();
  65578. }
  65579. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65580. {
  65581. if (needToClip)
  65582. {
  65583. needToClip = false;
  65584. out << "doclip ";
  65585. int itemsOnLine = 0;
  65586. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65587. {
  65588. if (++itemsOnLine == 6)
  65589. {
  65590. itemsOnLine = 0;
  65591. out << '\n';
  65592. }
  65593. const Rectangle<int>& r = *i.getRectangle();
  65594. out << r.getX() << ' ' << -r.getY() << ' '
  65595. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65596. }
  65597. out << "endclip\n";
  65598. }
  65599. }
  65600. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65601. {
  65602. Colour c (Colours::white.overlaidWith (colour));
  65603. if (lastColour != c)
  65604. {
  65605. lastColour = c;
  65606. out << String (c.getFloatRed(), 3) << ' '
  65607. << String (c.getFloatGreen(), 3) << ' '
  65608. << String (c.getFloatBlue(), 3) << " c\n";
  65609. }
  65610. }
  65611. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65612. {
  65613. out << String (x, 2) << ' '
  65614. << String (-y, 2) << ' ';
  65615. }
  65616. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65617. {
  65618. out << "newpath ";
  65619. float lastX = 0.0f;
  65620. float lastY = 0.0f;
  65621. int itemsOnLine = 0;
  65622. Path::Iterator i (path);
  65623. while (i.next())
  65624. {
  65625. if (++itemsOnLine == 4)
  65626. {
  65627. itemsOnLine = 0;
  65628. out << '\n';
  65629. }
  65630. switch (i.elementType)
  65631. {
  65632. case Path::Iterator::startNewSubPath:
  65633. writeXY (i.x1, i.y1);
  65634. lastX = i.x1;
  65635. lastY = i.y1;
  65636. out << "m ";
  65637. break;
  65638. case Path::Iterator::lineTo:
  65639. writeXY (i.x1, i.y1);
  65640. lastX = i.x1;
  65641. lastY = i.y1;
  65642. out << "l ";
  65643. break;
  65644. case Path::Iterator::quadraticTo:
  65645. {
  65646. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65647. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65648. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65649. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65650. writeXY (cp1x, cp1y);
  65651. writeXY (cp2x, cp2y);
  65652. writeXY (i.x2, i.y2);
  65653. out << "ct ";
  65654. lastX = i.x2;
  65655. lastY = i.y2;
  65656. }
  65657. break;
  65658. case Path::Iterator::cubicTo:
  65659. writeXY (i.x1, i.y1);
  65660. writeXY (i.x2, i.y2);
  65661. writeXY (i.x3, i.y3);
  65662. out << "ct ";
  65663. lastX = i.x3;
  65664. lastY = i.y3;
  65665. break;
  65666. case Path::Iterator::closePath:
  65667. out << "cp ";
  65668. break;
  65669. default:
  65670. jassertfalse
  65671. break;
  65672. }
  65673. }
  65674. out << '\n';
  65675. }
  65676. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65677. {
  65678. out << "[ "
  65679. << trans.mat00 << ' '
  65680. << trans.mat10 << ' '
  65681. << trans.mat01 << ' '
  65682. << trans.mat11 << ' '
  65683. << trans.mat02 << ' '
  65684. << trans.mat12 << " ] concat ";
  65685. }
  65686. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65687. {
  65688. stateStack.getLast()->fillType = fillType;
  65689. }
  65690. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65691. {
  65692. }
  65693. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65694. {
  65695. }
  65696. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65697. {
  65698. if (stateStack.getLast()->fillType.isColour())
  65699. {
  65700. writeClip();
  65701. writeColour (stateStack.getLast()->fillType.colour);
  65702. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65703. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65704. }
  65705. else
  65706. {
  65707. Path p;
  65708. p.addRectangle (r);
  65709. fillPath (p, AffineTransform::identity);
  65710. }
  65711. }
  65712. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65713. {
  65714. if (stateStack.getLast()->fillType.isColour())
  65715. {
  65716. writeClip();
  65717. Path p (path);
  65718. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65719. (float) stateStack.getLast()->yOffset));
  65720. writePath (p);
  65721. writeColour (stateStack.getLast()->fillType.colour);
  65722. out << "fill\n";
  65723. }
  65724. else if (stateStack.getLast()->fillType.isGradient())
  65725. {
  65726. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65727. // postscript can't do semi-transparent ones.
  65728. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65729. writeClip();
  65730. out << "gsave ";
  65731. {
  65732. Path p (path);
  65733. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65734. writePath (p);
  65735. out << "clip\n";
  65736. }
  65737. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65738. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65739. // time-being, this just fills it with the average colour..
  65740. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65741. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65742. out << "grestore\n";
  65743. }
  65744. }
  65745. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65746. const int sx, const int sy,
  65747. const int maxW, const int maxH) const
  65748. {
  65749. out << "{<\n";
  65750. const int w = jmin (maxW, im.getWidth());
  65751. const int h = jmin (maxH, im.getHeight());
  65752. int charsOnLine = 0;
  65753. const Image::BitmapData srcData (im, 0, 0, w, h);
  65754. Colour pixel;
  65755. for (int y = h; --y >= 0;)
  65756. {
  65757. for (int x = 0; x < w; ++x)
  65758. {
  65759. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65760. if (x >= sx && y >= sy)
  65761. {
  65762. if (im.isARGB())
  65763. {
  65764. PixelARGB p (*(const PixelARGB*) pixelData);
  65765. p.unpremultiply();
  65766. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65767. }
  65768. else if (im.isRGB())
  65769. {
  65770. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65771. }
  65772. else
  65773. {
  65774. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65775. }
  65776. }
  65777. else
  65778. {
  65779. pixel = Colours::transparentWhite;
  65780. }
  65781. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65782. out << String::toHexString (pixelValues, 3, 0);
  65783. charsOnLine += 3;
  65784. if (charsOnLine > 100)
  65785. {
  65786. out << '\n';
  65787. charsOnLine = 0;
  65788. }
  65789. }
  65790. }
  65791. out << "\n>}\n";
  65792. }
  65793. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65794. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65795. {
  65796. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65797. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65798. writeClip();
  65799. out << "gsave ";
  65800. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65801. .scaled (1.0f, -1.0f));
  65802. RectangleList imageClip;
  65803. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65804. imageClip.clipTo (srcClip);
  65805. out << "newpath ";
  65806. int itemsOnLine = 0;
  65807. for (RectangleList::Iterator i (imageClip); i.next();)
  65808. {
  65809. if (++itemsOnLine == 6)
  65810. {
  65811. out << '\n';
  65812. itemsOnLine = 0;
  65813. }
  65814. const Rectangle<int>& r = *i.getRectangle();
  65815. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65816. }
  65817. out << " clip newpath\n";
  65818. out << w << ' ' << h << " scale\n";
  65819. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65820. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65821. out << "false 3 colorimage grestore\n";
  65822. needToClip = true;
  65823. }
  65824. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65825. {
  65826. Path p;
  65827. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65828. fillPath (p, AffineTransform::identity);
  65829. }
  65830. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65831. {
  65832. drawLine (x, top, x, bottom);
  65833. }
  65834. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65835. {
  65836. drawLine (left, y, right, y);
  65837. }
  65838. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65839. {
  65840. stateStack.getLast()->font = newFont;
  65841. }
  65842. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65843. {
  65844. return stateStack.getLast()->font;
  65845. }
  65846. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65847. {
  65848. Path p;
  65849. Font& font = stateStack.getLast()->font;
  65850. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65851. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65852. }
  65853. END_JUCE_NAMESPACE
  65854. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65855. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65856. BEGIN_JUCE_NAMESPACE
  65857. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65858. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65859. #endif
  65860. #if JUCE_MSVC && JUCE_DEBUG
  65861. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65862. #endif
  65863. #if JUCE_MSVC
  65864. #pragma warning (push)
  65865. #pragma warning (disable: 4127) // "expression is constant" warning
  65866. #endif
  65867. template <class PixelType, bool replaceExisting = false>
  65868. class SolidColourEdgeTableRenderer
  65869. {
  65870. public:
  65871. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65872. : data (data_),
  65873. sourceColour (colour)
  65874. {
  65875. if (sizeof (PixelType) == 3)
  65876. {
  65877. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65878. && sourceColour.getGreen() == sourceColour.getBlue();
  65879. filler[0].set (sourceColour);
  65880. filler[1].set (sourceColour);
  65881. filler[2].set (sourceColour);
  65882. filler[3].set (sourceColour);
  65883. }
  65884. }
  65885. forcedinline void setEdgeTableYPos (const int y) throw()
  65886. {
  65887. linePixels = (PixelType*) data.getLinePointer (y);
  65888. }
  65889. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65890. {
  65891. if (replaceExisting)
  65892. linePixels[x].set (sourceColour);
  65893. else
  65894. linePixels[x].blend (sourceColour, alphaLevel);
  65895. }
  65896. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65897. {
  65898. PixelARGB p (sourceColour);
  65899. p.multiplyAlpha (alphaLevel);
  65900. PixelType* dest = linePixels + x;
  65901. if (replaceExisting || p.getAlpha() >= 0xff)
  65902. replaceLine (dest, p, width);
  65903. else
  65904. blendLine (dest, p, width);
  65905. }
  65906. private:
  65907. const Image::BitmapData& data;
  65908. PixelType* linePixels;
  65909. PixelARGB sourceColour;
  65910. PixelRGB filler [4];
  65911. bool areRGBComponentsEqual;
  65912. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const
  65913. {
  65914. do
  65915. {
  65916. dest->blend (colour);
  65917. ++dest;
  65918. } while (--width > 0);
  65919. }
  65920. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65921. {
  65922. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65923. {
  65924. memset (dest, colour.getRed(), width * 3);
  65925. }
  65926. else
  65927. {
  65928. if (width >> 5)
  65929. {
  65930. const int* const intFiller = (const int*) filler;
  65931. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65932. {
  65933. dest->set (colour);
  65934. ++dest;
  65935. --width;
  65936. }
  65937. while (width > 4)
  65938. {
  65939. ((int*) dest) [0] = intFiller[0];
  65940. ((int*) dest) [1] = intFiller[1];
  65941. ((int*) dest) [2] = intFiller[2];
  65942. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65943. width -= 4;
  65944. }
  65945. }
  65946. while (--width >= 0)
  65947. {
  65948. dest->set (colour);
  65949. ++dest;
  65950. }
  65951. }
  65952. }
  65953. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65954. {
  65955. memset (dest, colour.getAlpha(), width);
  65956. }
  65957. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65958. {
  65959. do
  65960. {
  65961. dest->set (colour);
  65962. ++dest;
  65963. } while (--width > 0);
  65964. }
  65965. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65966. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65967. };
  65968. class LinearGradientPixelGenerator
  65969. {
  65970. public:
  65971. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65972. : lookupTable (lookupTable_), numEntries (numEntries_)
  65973. {
  65974. jassert (numEntries_ >= 0);
  65975. float x1 = gradient.x1;
  65976. float y1 = gradient.y1;
  65977. float x2 = gradient.x2;
  65978. float y2 = gradient.y2;
  65979. if (! transform.isIdentity())
  65980. {
  65981. const Line l (x2, y2, x1, y1);
  65982. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65983. float x3 = p3.getX();
  65984. float y3 = p3.getY();
  65985. transform.transformPoint (x1, y1);
  65986. transform.transformPoint (x2, y2);
  65987. transform.transformPoint (x3, y3);
  65988. const Line l2 (x2, y2, x3, y3);
  65989. const float prop = l2.findNearestPointTo (x1, y1);
  65990. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65991. x2 = newP2.getX();
  65992. y2 = newP2.getY();
  65993. }
  65994. vertical = fabs (x1 - x2) < 0.001f;
  65995. horizontal = fabs (y1 - y2) < 0.001f;
  65996. if (vertical)
  65997. {
  65998. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65999. start = roundToInt (y1 * scale);
  66000. }
  66001. else if (horizontal)
  66002. {
  66003. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  66004. start = roundToInt (x1 * scale);
  66005. }
  66006. else
  66007. {
  66008. grad = (y2 - y1) / (double) (x1 - x2);
  66009. yTerm = y1 - x1 / grad;
  66010. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  66011. grad *= scale;
  66012. }
  66013. }
  66014. forcedinline void setY (const int y) throw()
  66015. {
  66016. if (vertical)
  66017. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  66018. else if (! horizontal)
  66019. start = roundToInt ((y - yTerm) * grad);
  66020. }
  66021. inline const PixelARGB getPixel (const int x) const throw()
  66022. {
  66023. return vertical ? linePix
  66024. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  66025. }
  66026. private:
  66027. const PixelARGB* const lookupTable;
  66028. const int numEntries;
  66029. PixelARGB linePix;
  66030. int start, scale;
  66031. double grad, yTerm;
  66032. bool vertical, horizontal;
  66033. enum { numScaleBits = 12 };
  66034. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  66035. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  66036. };
  66037. class RadialGradientPixelGenerator
  66038. {
  66039. public:
  66040. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  66041. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66042. : lookupTable (lookupTable_),
  66043. numEntries (numEntries_),
  66044. gx1 (gradient.x1),
  66045. gy1 (gradient.y1)
  66046. {
  66047. jassert (numEntries_ >= 0);
  66048. const float gdx = gradient.x1 - gradient.x2;
  66049. const float gdy = gradient.y1 - gradient.y2;
  66050. maxDist = gdx * gdx + gdy * gdy;
  66051. invScale = numEntries / sqrt (maxDist);
  66052. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  66053. }
  66054. forcedinline void setY (const int y) throw()
  66055. {
  66056. dy = y - gy1;
  66057. dy *= dy;
  66058. }
  66059. inline const PixelARGB getPixel (const int px) const throw()
  66060. {
  66061. double x = px - gx1;
  66062. x *= x;
  66063. x += dy;
  66064. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  66065. }
  66066. protected:
  66067. const PixelARGB* const lookupTable;
  66068. const int numEntries;
  66069. const double gx1, gy1;
  66070. double maxDist, invScale, dy;
  66071. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  66072. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  66073. };
  66074. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  66075. {
  66076. public:
  66077. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  66078. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66079. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  66080. inverseTransform (transform.inverted())
  66081. {
  66082. tM10 = inverseTransform.mat10;
  66083. tM00 = inverseTransform.mat00;
  66084. }
  66085. forcedinline void setY (const int y) throw()
  66086. {
  66087. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  66088. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  66089. }
  66090. inline const PixelARGB getPixel (const int px) const throw()
  66091. {
  66092. double x = px;
  66093. const double y = tM10 * x + lineYM11;
  66094. x = tM00 * x + lineYM01;
  66095. x *= x;
  66096. x += y * y;
  66097. if (x >= maxDist)
  66098. return lookupTable [numEntries];
  66099. else
  66100. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  66101. }
  66102. private:
  66103. double tM10, tM00, lineYM01, lineYM11;
  66104. const AffineTransform inverseTransform;
  66105. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  66106. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  66107. };
  66108. template <class PixelType, class GradientType>
  66109. class GradientEdgeTableRenderer : public GradientType
  66110. {
  66111. public:
  66112. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  66113. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66114. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  66115. destData (destData_)
  66116. {
  66117. }
  66118. forcedinline void setEdgeTableYPos (const int y) throw()
  66119. {
  66120. linePixels = (PixelType*) destData.getLinePointer (y);
  66121. GradientType::setY (y);
  66122. }
  66123. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  66124. {
  66125. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  66126. }
  66127. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  66128. {
  66129. PixelType* dest = linePixels + x;
  66130. if (alphaLevel < 0xff)
  66131. {
  66132. do
  66133. {
  66134. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  66135. } while (--width > 0);
  66136. }
  66137. else
  66138. {
  66139. do
  66140. {
  66141. (dest++)->blend (GradientType::getPixel (x++));
  66142. } while (--width > 0);
  66143. }
  66144. }
  66145. private:
  66146. const Image::BitmapData& destData;
  66147. PixelType* linePixels;
  66148. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  66149. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  66150. };
  66151. static forcedinline int safeModulo (int n, const int divisor) throw()
  66152. {
  66153. jassert (divisor > 0);
  66154. n %= divisor;
  66155. return (n < 0) ? (n + divisor) : n;
  66156. }
  66157. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66158. class ImageFillEdgeTableRenderer
  66159. {
  66160. public:
  66161. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66162. const Image::BitmapData& srcData_,
  66163. const int extraAlpha_,
  66164. const int x, const int y) throw()
  66165. : destData (destData_),
  66166. srcData (srcData_),
  66167. extraAlpha (extraAlpha_ + 1),
  66168. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  66169. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  66170. {
  66171. }
  66172. forcedinline void setEdgeTableYPos (int y) throw()
  66173. {
  66174. linePixels = (DestPixelType*) destData.getLinePointer (y);
  66175. y -= yOffset;
  66176. if (repeatPattern)
  66177. {
  66178. jassert (y >= 0);
  66179. y %= srcData.height;
  66180. }
  66181. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  66182. }
  66183. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  66184. {
  66185. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66186. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  66187. }
  66188. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  66189. {
  66190. DestPixelType* dest = linePixels + x;
  66191. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66192. x -= xOffset;
  66193. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  66194. if (alphaLevel < 0xfe)
  66195. {
  66196. do
  66197. {
  66198. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  66199. } while (--width > 0);
  66200. }
  66201. else
  66202. {
  66203. if (repeatPattern)
  66204. {
  66205. do
  66206. {
  66207. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  66208. } while (--width > 0);
  66209. }
  66210. else
  66211. {
  66212. copyRow (dest, sourceLineStart + x, width);
  66213. }
  66214. }
  66215. }
  66216. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  66217. {
  66218. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  66219. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  66220. uint8* mask = (uint8*) (s + x - xOffset);
  66221. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66222. mask += PixelARGB::indexA;
  66223. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  66224. }
  66225. private:
  66226. const Image::BitmapData& destData;
  66227. const Image::BitmapData& srcData;
  66228. const int extraAlpha, xOffset, yOffset;
  66229. DestPixelType* linePixels;
  66230. SrcPixelType* sourceLineStart;
  66231. template <class PixelType1, class PixelType2>
  66232. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  66233. {
  66234. do
  66235. {
  66236. dest++ ->blend (*src++);
  66237. } while (--width > 0);
  66238. }
  66239. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  66240. {
  66241. memcpy (dest, src, width * sizeof (PixelRGB));
  66242. }
  66243. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  66244. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  66245. };
  66246. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66247. class TransformedImageFillEdgeTableRenderer
  66248. {
  66249. public:
  66250. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66251. const Image::BitmapData& srcData_,
  66252. const AffineTransform& transform,
  66253. const int extraAlpha_,
  66254. const bool betterQuality_) throw()
  66255. : interpolator (transform),
  66256. destData (destData_),
  66257. srcData (srcData_),
  66258. extraAlpha (extraAlpha_ + 1),
  66259. betterQuality (betterQuality_),
  66260. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  66261. pixelOffsetInt (betterQuality_ ? -128 : 0),
  66262. maxX (srcData_.width - 1),
  66263. maxY (srcData_.height - 1),
  66264. scratchSize (2048)
  66265. {
  66266. scratchBuffer.malloc (scratchSize);
  66267. }
  66268. ~TransformedImageFillEdgeTableRenderer() throw()
  66269. {
  66270. }
  66271. forcedinline void setEdgeTableYPos (const int newY) throw()
  66272. {
  66273. y = newY;
  66274. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  66275. }
  66276. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  66277. {
  66278. alphaLevel *= extraAlpha;
  66279. alphaLevel >>= 8;
  66280. SrcPixelType p;
  66281. generate (&p, x, 1);
  66282. linePixels[x].blend (p, alphaLevel);
  66283. }
  66284. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  66285. {
  66286. if (width > scratchSize)
  66287. {
  66288. scratchSize = width;
  66289. scratchBuffer.malloc (scratchSize);
  66290. }
  66291. SrcPixelType* span = scratchBuffer;
  66292. generate (span, x, width);
  66293. DestPixelType* dest = linePixels + x;
  66294. alphaLevel *= extraAlpha;
  66295. alphaLevel >>= 8;
  66296. if (alphaLevel < 0xfe)
  66297. {
  66298. do
  66299. {
  66300. dest++ ->blend (*span++, alphaLevel);
  66301. } while (--width > 0);
  66302. }
  66303. else
  66304. {
  66305. do
  66306. {
  66307. dest++ ->blend (*span++);
  66308. } while (--width > 0);
  66309. }
  66310. }
  66311. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  66312. {
  66313. if (width > scratchSize)
  66314. {
  66315. scratchSize = width;
  66316. scratchBuffer.malloc (scratchSize);
  66317. }
  66318. uint8* mask = (uint8*) scratchBuffer;
  66319. y = y_;
  66320. generate ((SrcPixelType*) mask, x, width);
  66321. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66322. mask += PixelARGB::indexA;
  66323. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  66324. }
  66325. private:
  66326. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  66327. {
  66328. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66329. do
  66330. {
  66331. int hiResX, hiResY;
  66332. this->interpolator.next (hiResX, hiResY);
  66333. hiResX += pixelOffsetInt;
  66334. hiResY += pixelOffsetInt;
  66335. int loResX = hiResX >> 8;
  66336. int loResY = hiResY >> 8;
  66337. if (repeatPattern)
  66338. {
  66339. loResX = safeModulo (loResX, srcData.width);
  66340. loResY = safeModulo (loResY, srcData.height);
  66341. }
  66342. if (betterQuality
  66343. && ((unsigned int) loResX) < (unsigned int) maxX
  66344. && ((unsigned int) loResY) < (unsigned int) maxY)
  66345. {
  66346. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66347. hiResX &= 255;
  66348. hiResY &= 255;
  66349. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66350. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66351. c[0] += weight * src[0];
  66352. c[1] += weight * src[1];
  66353. c[2] += weight * src[2];
  66354. c[3] += weight * src[3];
  66355. weight = hiResX * (256 - hiResY);
  66356. c[0] += weight * src[4];
  66357. c[1] += weight * src[5];
  66358. c[2] += weight * src[6];
  66359. c[3] += weight * src[7];
  66360. src += this->srcData.lineStride;
  66361. weight = (256 - hiResX) * hiResY;
  66362. c[0] += weight * src[0];
  66363. c[1] += weight * src[1];
  66364. c[2] += weight * src[2];
  66365. c[3] += weight * src[3];
  66366. weight = hiResX * hiResY;
  66367. c[0] += weight * src[4];
  66368. c[1] += weight * src[5];
  66369. c[2] += weight * src[6];
  66370. c[3] += weight * src[7];
  66371. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66372. (uint8) (c[PixelARGB::indexR] >> 16),
  66373. (uint8) (c[PixelARGB::indexG] >> 16),
  66374. (uint8) (c[PixelARGB::indexB] >> 16));
  66375. }
  66376. else
  66377. {
  66378. if (! repeatPattern)
  66379. {
  66380. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66381. if (loResX < 0) loResX = 0;
  66382. if (loResY < 0) loResY = 0;
  66383. if (loResX > maxX) loResX = maxX;
  66384. if (loResY > maxY) loResY = maxY;
  66385. }
  66386. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66387. }
  66388. ++dest;
  66389. } while (--numPixels > 0);
  66390. }
  66391. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66392. {
  66393. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66394. do
  66395. {
  66396. int hiResX, hiResY;
  66397. this->interpolator.next (hiResX, hiResY);
  66398. hiResX += pixelOffsetInt;
  66399. hiResY += pixelOffsetInt;
  66400. int loResX = hiResX >> 8;
  66401. int loResY = hiResY >> 8;
  66402. if (repeatPattern)
  66403. {
  66404. loResX = safeModulo (loResX, srcData.width);
  66405. loResY = safeModulo (loResY, srcData.height);
  66406. }
  66407. if (betterQuality
  66408. && ((unsigned int) loResX) < (unsigned int) maxX
  66409. && ((unsigned int) loResY) < (unsigned int) maxY)
  66410. {
  66411. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66412. hiResX &= 255;
  66413. hiResY &= 255;
  66414. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66415. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66416. c[0] += weight * src[0];
  66417. c[1] += weight * src[1];
  66418. c[2] += weight * src[2];
  66419. weight = hiResX * (256 - hiResY);
  66420. c[0] += weight * src[3];
  66421. c[1] += weight * src[4];
  66422. c[2] += weight * src[5];
  66423. src += this->srcData.lineStride;
  66424. weight = (256 - hiResX) * hiResY;
  66425. c[0] += weight * src[0];
  66426. c[1] += weight * src[1];
  66427. c[2] += weight * src[2];
  66428. weight = hiResX * hiResY;
  66429. c[0] += weight * src[3];
  66430. c[1] += weight * src[4];
  66431. c[2] += weight * src[5];
  66432. dest->setARGB ((uint8) 255,
  66433. (uint8) (c[PixelRGB::indexR] >> 16),
  66434. (uint8) (c[PixelRGB::indexG] >> 16),
  66435. (uint8) (c[PixelRGB::indexB] >> 16));
  66436. }
  66437. else
  66438. {
  66439. if (! repeatPattern)
  66440. {
  66441. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66442. if (loResX < 0) loResX = 0;
  66443. if (loResY < 0) loResY = 0;
  66444. if (loResX > maxX) loResX = maxX;
  66445. if (loResY > maxY) loResY = maxY;
  66446. }
  66447. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66448. }
  66449. ++dest;
  66450. } while (--numPixels > 0);
  66451. }
  66452. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66453. {
  66454. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66455. do
  66456. {
  66457. int hiResX, hiResY;
  66458. this->interpolator.next (hiResX, hiResY);
  66459. hiResX += pixelOffsetInt;
  66460. hiResY += pixelOffsetInt;
  66461. int loResX = hiResX >> 8;
  66462. int loResY = hiResY >> 8;
  66463. if (repeatPattern)
  66464. {
  66465. loResX = safeModulo (loResX, srcData.width);
  66466. loResY = safeModulo (loResY, srcData.height);
  66467. }
  66468. if (betterQuality
  66469. && ((unsigned int) loResX) < (unsigned int) maxX
  66470. && ((unsigned int) loResY) < (unsigned int) maxY)
  66471. {
  66472. hiResX &= 255;
  66473. hiResY &= 255;
  66474. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66475. uint32 c = 256 * 128;
  66476. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66477. c += src[1] * (hiResX * (256 - hiResY));
  66478. src += this->srcData.lineStride;
  66479. c += src[0] * ((256 - hiResX) * hiResY);
  66480. c += src[1] * (hiResX * hiResY);
  66481. *((uint8*) dest) = (uint8) c;
  66482. }
  66483. else
  66484. {
  66485. if (! repeatPattern)
  66486. {
  66487. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66488. if (loResX < 0) loResX = 0;
  66489. if (loResY < 0) loResY = 0;
  66490. if (loResX > maxX) loResX = maxX;
  66491. if (loResY > maxY) loResY = maxY;
  66492. }
  66493. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66494. }
  66495. ++dest;
  66496. } while (--numPixels > 0);
  66497. }
  66498. class TransformedImageSpanInterpolator
  66499. {
  66500. public:
  66501. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66502. : inverseTransform (transform.inverted())
  66503. {}
  66504. void setStartOfLine (float x, float y, const int numPixels) throw()
  66505. {
  66506. float x1 = x, y1 = y;
  66507. inverseTransform.transformPoint (x1, y1);
  66508. x += numPixels;
  66509. inverseTransform.transformPoint (x, y);
  66510. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66511. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66512. }
  66513. void next (int& x, int& y) throw()
  66514. {
  66515. x = xBresenham.n;
  66516. xBresenham.stepToNext();
  66517. y = yBresenham.n;
  66518. yBresenham.stepToNext();
  66519. }
  66520. private:
  66521. class BresenhamInterpolator
  66522. {
  66523. public:
  66524. BresenhamInterpolator() throw() {}
  66525. void set (const int n1, const int n2, const int numSteps_) throw()
  66526. {
  66527. numSteps = jmax (1, numSteps_);
  66528. step = (n2 - n1) / numSteps;
  66529. remainder = modulo = (n2 - n1) % numSteps;
  66530. n = n1;
  66531. if (modulo <= 0)
  66532. {
  66533. modulo += numSteps;
  66534. remainder += numSteps;
  66535. --step;
  66536. }
  66537. modulo -= numSteps;
  66538. }
  66539. forcedinline void stepToNext() throw()
  66540. {
  66541. modulo += remainder;
  66542. n += step;
  66543. if (modulo > 0)
  66544. {
  66545. modulo -= numSteps;
  66546. ++n;
  66547. }
  66548. }
  66549. int n;
  66550. private:
  66551. int numSteps, step, modulo, remainder;
  66552. };
  66553. const AffineTransform inverseTransform;
  66554. BresenhamInterpolator xBresenham, yBresenham;
  66555. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66556. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66557. };
  66558. TransformedImageSpanInterpolator interpolator;
  66559. const Image::BitmapData& destData;
  66560. const Image::BitmapData& srcData;
  66561. const int extraAlpha;
  66562. const bool betterQuality;
  66563. const float pixelOffset;
  66564. const int pixelOffsetInt, maxX, maxY;
  66565. int y;
  66566. DestPixelType* linePixels;
  66567. HeapBlock <SrcPixelType> scratchBuffer;
  66568. int scratchSize;
  66569. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66570. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66571. };
  66572. class LLGCSavedState
  66573. {
  66574. public:
  66575. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66576. const Font& font_, const FillType& fillType_,
  66577. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66578. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66579. xOffset (xOffset_), yOffset (yOffset_),
  66580. font (font_), fillType (fillType_),
  66581. interpolationQuality (interpolationQuality_)
  66582. {
  66583. }
  66584. LLGCSavedState (const LLGCSavedState& other) throw()
  66585. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66586. yOffset (other.yOffset), font (other.font),
  66587. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66588. {
  66589. }
  66590. ~LLGCSavedState() throw()
  66591. {
  66592. }
  66593. bool clipToRectangle (const Rectangle<int>& r) throw()
  66594. {
  66595. dupeEdgeTableIfMultiplyReferenced();
  66596. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66597. return ! edgeTable->edgeTable.isEmpty();
  66598. }
  66599. bool clipToRectangleList (const RectangleList& r) throw()
  66600. {
  66601. dupeEdgeTableIfMultiplyReferenced();
  66602. RectangleList offsetList (r);
  66603. offsetList.offsetAll (xOffset, yOffset);
  66604. EdgeTable e2 (offsetList);
  66605. edgeTable->edgeTable.clipToEdgeTable (e2);
  66606. return ! edgeTable->edgeTable.isEmpty();
  66607. }
  66608. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66609. {
  66610. dupeEdgeTableIfMultiplyReferenced();
  66611. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66612. return ! edgeTable->edgeTable.isEmpty();
  66613. }
  66614. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66615. {
  66616. dupeEdgeTableIfMultiplyReferenced();
  66617. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66618. edgeTable->edgeTable.clipToEdgeTable (et);
  66619. }
  66620. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66621. {
  66622. et.clipToEdgeTable (edgeTable->edgeTable);
  66623. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66624. if (fillType.isGradient())
  66625. {
  66626. jassert (! replaceContents); // that option is just for solid colours
  66627. ColourGradient g2 (*(fillType.gradient));
  66628. g2.multiplyOpacity (fillType.getOpacity());
  66629. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66630. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66631. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66632. const bool isIdentity = transform.isOnlyTranslation();
  66633. if (isIdentity)
  66634. {
  66635. // If our translation doesn't involve any distortion, we can speed it up..
  66636. transform.transformPoint (g2.x1, g2.y1);
  66637. transform.transformPoint (g2.x2, g2.y2);
  66638. transform = AffineTransform::identity;
  66639. }
  66640. HeapBlock <PixelARGB> lookupTable;
  66641. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66642. jassert (numLookupEntries > 0);
  66643. switch (image.getFormat())
  66644. {
  66645. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66646. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66647. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66648. }
  66649. }
  66650. else if (fillType.isTiledImage())
  66651. {
  66652. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66653. }
  66654. else
  66655. {
  66656. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66657. switch (image.getFormat())
  66658. {
  66659. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66660. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66661. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66662. }
  66663. }
  66664. }
  66665. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66666. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66667. {
  66668. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66669. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66670. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66671. const int alpha = fillType.colour.getAlpha();
  66672. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66673. if (transform.isOnlyTranslation())
  66674. {
  66675. // If our translation doesn't involve any distortion, just use a simple blit..
  66676. int tx = (int) (transform.getTranslationX() * 256.0f);
  66677. int ty = (int) (transform.getTranslationY() * 256.0f);
  66678. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66679. {
  66680. tx = ((tx + 128) >> 8);
  66681. ty = ((ty + 128) >> 8);
  66682. if (tiledFillClipRegion != 0)
  66683. {
  66684. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66685. }
  66686. else
  66687. {
  66688. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66689. et.clipToEdgeTable (edgeTable->edgeTable);
  66690. if (! et.isEmpty())
  66691. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66692. }
  66693. return;
  66694. }
  66695. }
  66696. if (transform.isSingularity())
  66697. return;
  66698. if (tiledFillClipRegion != 0)
  66699. {
  66700. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66701. }
  66702. else
  66703. {
  66704. Path p;
  66705. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66706. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66707. et.clipToEdgeTable (edgeTable->edgeTable);
  66708. if (! et.isEmpty())
  66709. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66710. }
  66711. }
  66712. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66713. {
  66714. if (! image.hasAlphaChannel())
  66715. {
  66716. Path p;
  66717. p.addRectangle (srcClip);
  66718. clipToPath (p, t);
  66719. return;
  66720. }
  66721. dupeEdgeTableIfMultiplyReferenced();
  66722. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66723. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66724. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66725. EdgeTable& et = edgeTable->edgeTable;
  66726. if (transform.isOnlyTranslation())
  66727. {
  66728. // If our translation doesn't involve any distortion, just use a simple blit..
  66729. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66730. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66731. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66732. {
  66733. const int imageX = ((tx + 128) >> 8);
  66734. const int imageY = ((ty + 128) >> 8);
  66735. if (image.getFormat() == Image::ARGB)
  66736. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66737. else
  66738. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66739. return;
  66740. }
  66741. }
  66742. if (transform.isSingularity())
  66743. {
  66744. et.clipToRectangle (Rectangle<int>());
  66745. return;
  66746. }
  66747. {
  66748. Path p;
  66749. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66750. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66751. et.clipToEdgeTable (et2);
  66752. }
  66753. if (! et.isEmpty())
  66754. {
  66755. if (image.getFormat() == Image::ARGB)
  66756. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66757. else
  66758. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66759. }
  66760. }
  66761. template <class SrcPixelType>
  66762. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66763. {
  66764. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66765. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66766. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66767. et.getMaximumBounds().getWidth());
  66768. }
  66769. template <class SrcPixelType>
  66770. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66771. {
  66772. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66773. et.clipToRectangle (r);
  66774. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66775. for (int y = 0; y < r.getHeight(); ++y)
  66776. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66777. }
  66778. class EdgeTableHolder : public ReferenceCountedObject
  66779. {
  66780. public:
  66781. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66782. EdgeTable edgeTable;
  66783. };
  66784. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66785. int xOffset, yOffset;
  66786. Font font;
  66787. FillType fillType;
  66788. Graphics::ResamplingQuality interpolationQuality;
  66789. private:
  66790. LLGCSavedState& operator= (const LLGCSavedState&);
  66791. void dupeEdgeTableIfMultiplyReferenced() throw()
  66792. {
  66793. if (edgeTable->getReferenceCount() > 1)
  66794. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66795. }
  66796. template <class DestPixelType>
  66797. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66798. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66799. {
  66800. jassert (destData.pixelStride == sizeof (DestPixelType));
  66801. if (g.isRadial)
  66802. {
  66803. if (isIdentity)
  66804. {
  66805. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66806. et.iterate (renderer);
  66807. }
  66808. else
  66809. {
  66810. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66811. et.iterate (renderer);
  66812. }
  66813. }
  66814. else
  66815. {
  66816. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66817. et.iterate (renderer);
  66818. }
  66819. }
  66820. template <class DestPixelType>
  66821. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66822. {
  66823. jassert (destData.pixelStride == sizeof (DestPixelType));
  66824. if (replaceContents)
  66825. {
  66826. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66827. et.iterate (r);
  66828. }
  66829. else
  66830. {
  66831. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66832. et.iterate (r);
  66833. }
  66834. }
  66835. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66836. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66837. {
  66838. switch (destImage.getFormat())
  66839. {
  66840. case Image::ARGB:
  66841. switch (srcImage.getFormat())
  66842. {
  66843. case Image::ARGB:
  66844. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66845. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66846. break;
  66847. case Image::RGB:
  66848. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66849. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66850. break;
  66851. default:
  66852. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66853. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66854. break;
  66855. }
  66856. break;
  66857. case Image::RGB:
  66858. switch (srcImage.getFormat())
  66859. {
  66860. case Image::ARGB:
  66861. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66862. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66863. break;
  66864. case Image::RGB:
  66865. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66866. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66867. break;
  66868. default:
  66869. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66870. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66871. break;
  66872. }
  66873. break;
  66874. default:
  66875. switch (srcImage.getFormat())
  66876. {
  66877. case Image::ARGB:
  66878. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66879. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66880. break;
  66881. case Image::RGB:
  66882. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66883. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66884. break;
  66885. default:
  66886. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66887. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66888. break;
  66889. }
  66890. break;
  66891. }
  66892. }
  66893. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66894. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66895. {
  66896. switch (destImage.getFormat())
  66897. {
  66898. case Image::ARGB:
  66899. switch (srcImage.getFormat())
  66900. {
  66901. case Image::ARGB:
  66902. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66903. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66904. break;
  66905. case Image::RGB:
  66906. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66907. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66908. break;
  66909. default:
  66910. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66911. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66912. break;
  66913. }
  66914. break;
  66915. case Image::RGB:
  66916. switch (srcImage.getFormat())
  66917. {
  66918. case Image::ARGB:
  66919. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66920. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66921. break;
  66922. case Image::RGB:
  66923. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66924. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66925. break;
  66926. default:
  66927. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66928. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66929. break;
  66930. }
  66931. break;
  66932. default:
  66933. switch (srcImage.getFormat())
  66934. {
  66935. case Image::ARGB:
  66936. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66937. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66938. break;
  66939. case Image::RGB:
  66940. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66941. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66942. break;
  66943. default:
  66944. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66945. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66946. break;
  66947. }
  66948. break;
  66949. }
  66950. }
  66951. };
  66952. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66953. : image (image_)
  66954. {
  66955. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66956. FillType(), Graphics::mediumResamplingQuality);
  66957. }
  66958. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66959. {
  66960. }
  66961. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66962. {
  66963. return false;
  66964. }
  66965. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66966. {
  66967. currentState->xOffset += x;
  66968. currentState->yOffset += y;
  66969. }
  66970. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66971. {
  66972. return currentState->clipToRectangle (r);
  66973. }
  66974. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66975. {
  66976. return currentState->clipToRectangleList (clipRegion);
  66977. }
  66978. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66979. {
  66980. currentState->excludeClipRectangle (r);
  66981. }
  66982. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66983. {
  66984. currentState->clipToPath (path, transform);
  66985. }
  66986. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66987. {
  66988. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66989. }
  66990. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66991. {
  66992. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66993. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66994. }
  66995. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66996. {
  66997. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66998. }
  66999. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  67000. {
  67001. return currentState->edgeTable->edgeTable.isEmpty();
  67002. }
  67003. void LowLevelGraphicsSoftwareRenderer::saveState()
  67004. {
  67005. stateStack.add (new LLGCSavedState (*currentState));
  67006. }
  67007. void LowLevelGraphicsSoftwareRenderer::restoreState()
  67008. {
  67009. LLGCSavedState* const top = stateStack.getLast();
  67010. if (top != 0)
  67011. {
  67012. currentState = top;
  67013. stateStack.removeLast (1, false);
  67014. }
  67015. else
  67016. {
  67017. jassertfalse // trying to pop with an empty stack!
  67018. }
  67019. }
  67020. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  67021. {
  67022. currentState->fillType = fillType;
  67023. }
  67024. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  67025. {
  67026. currentState->fillType.setOpacity (newOpacity);
  67027. }
  67028. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  67029. {
  67030. currentState->interpolationQuality = quality;
  67031. }
  67032. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  67033. {
  67034. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  67035. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  67036. if (! clipped.isEmpty())
  67037. {
  67038. EdgeTable et (clipped);
  67039. currentState->fillEdgeTable (image, et, replaceExistingContents);
  67040. }
  67041. }
  67042. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  67043. {
  67044. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  67045. path, transform.translated ((float) currentState->xOffset,
  67046. (float) currentState->yOffset));
  67047. currentState->fillEdgeTable (image, et);
  67048. }
  67049. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  67050. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  67051. {
  67052. jassert (sourceImage.getBounds().contains (srcClip));
  67053. currentState->renderImage (image, sourceImage, srcClip, transform,
  67054. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  67055. }
  67056. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  67057. {
  67058. Path p;
  67059. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  67060. fillPath (p, AffineTransform::identity);
  67061. }
  67062. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  67063. {
  67064. if (bottom > top)
  67065. {
  67066. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  67067. currentState->fillEdgeTable (image, et);
  67068. }
  67069. }
  67070. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  67071. {
  67072. if (right > left)
  67073. {
  67074. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  67075. (float) (right - left), 1.0f);
  67076. currentState->fillEdgeTable (image, et);
  67077. }
  67078. }
  67079. class GlyphCache : private DeletedAtShutdown
  67080. {
  67081. public:
  67082. GlyphCache() throw()
  67083. : accessCounter (0), hits (0), misses (0)
  67084. {
  67085. for (int i = 120; --i >= 0;)
  67086. glyphs.add (new CachedGlyph());
  67087. }
  67088. ~GlyphCache() throw()
  67089. {
  67090. clearSingletonInstance();
  67091. }
  67092. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  67093. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  67094. {
  67095. ++accessCounter;
  67096. int oldestCounter = std::numeric_limits<int>::max();
  67097. CachedGlyph* oldest = 0;
  67098. for (int i = glyphs.size(); --i >= 0;)
  67099. {
  67100. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  67101. if (glyph->glyph == glyphNumber && glyph->font == font)
  67102. {
  67103. ++hits;
  67104. glyph->lastAccessCount = accessCounter;
  67105. glyph->draw (state, image, x, y);
  67106. return;
  67107. }
  67108. if (glyph->lastAccessCount <= oldestCounter)
  67109. {
  67110. oldestCounter = glyph->lastAccessCount;
  67111. oldest = glyph;
  67112. }
  67113. }
  67114. if (hits + ++misses > (glyphs.size() << 4))
  67115. {
  67116. if (misses * 2 > hits)
  67117. {
  67118. for (int i = 32; --i >= 0;)
  67119. glyphs.add (new CachedGlyph());
  67120. }
  67121. hits = misses = 0;
  67122. oldest = glyphs.getLast();
  67123. }
  67124. jassert (oldest != 0);
  67125. oldest->lastAccessCount = accessCounter;
  67126. oldest->generate (font, glyphNumber);
  67127. oldest->draw (state, image, x, y);
  67128. }
  67129. class CachedGlyph
  67130. {
  67131. public:
  67132. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  67133. ~CachedGlyph() {}
  67134. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  67135. {
  67136. if (edgeTable != 0)
  67137. {
  67138. EdgeTable et (*edgeTable);
  67139. et.translate (x, roundToInt (y));
  67140. state.fillEdgeTable (image, et, false);
  67141. }
  67142. }
  67143. void generate (const Font& newFont, const int glyphNumber) throw()
  67144. {
  67145. font = newFont;
  67146. glyph = glyphNumber;
  67147. edgeTable = 0;
  67148. Path glyphPath;
  67149. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  67150. if (! glyphPath.isEmpty())
  67151. {
  67152. const float fontHeight = font.getHeight();
  67153. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  67154. .translated (0.0f, -0.5f));
  67155. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  67156. glyphPath, transform);
  67157. }
  67158. }
  67159. int glyph, lastAccessCount;
  67160. Font font;
  67161. juce_UseDebuggingNewOperator
  67162. private:
  67163. ScopedPointer <EdgeTable> edgeTable;
  67164. CachedGlyph (const CachedGlyph&);
  67165. CachedGlyph& operator= (const CachedGlyph&);
  67166. };
  67167. juce_UseDebuggingNewOperator
  67168. private:
  67169. OwnedArray <CachedGlyph> glyphs;
  67170. int accessCounter, hits, misses;
  67171. GlyphCache (const GlyphCache&);
  67172. GlyphCache& operator= (const GlyphCache&);
  67173. };
  67174. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  67175. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  67176. {
  67177. currentState->font = newFont;
  67178. }
  67179. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  67180. {
  67181. return currentState->font;
  67182. }
  67183. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  67184. {
  67185. Font& f = currentState->font;
  67186. if (transform.isOnlyTranslation())
  67187. {
  67188. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  67189. transform.getTranslationX() + (float) currentState->xOffset,
  67190. transform.getTranslationY() + (float) currentState->yOffset);
  67191. }
  67192. else
  67193. {
  67194. Path p;
  67195. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  67196. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  67197. }
  67198. }
  67199. #if JUCE_MSVC
  67200. #pragma warning (pop)
  67201. #endif
  67202. END_JUCE_NAMESPACE
  67203. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  67204. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  67205. BEGIN_JUCE_NAMESPACE
  67206. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  67207. : flags (other.flags)
  67208. {
  67209. }
  67210. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  67211. {
  67212. flags = other.flags;
  67213. return *this;
  67214. }
  67215. void RectanglePlacement::applyTo (double& x, double& y,
  67216. double& w, double& h,
  67217. const double dx, const double dy,
  67218. const double dw, const double dh) const throw()
  67219. {
  67220. if (w == 0 || h == 0)
  67221. return;
  67222. if ((flags & stretchToFit) != 0)
  67223. {
  67224. x = dx;
  67225. y = dy;
  67226. w = dw;
  67227. h = dh;
  67228. }
  67229. else
  67230. {
  67231. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  67232. : jmin (dw / w, dh / h);
  67233. if ((flags & onlyReduceInSize) != 0)
  67234. scale = jmin (scale, 1.0);
  67235. if ((flags & onlyIncreaseInSize) != 0)
  67236. scale = jmax (scale, 1.0);
  67237. w *= scale;
  67238. h *= scale;
  67239. if ((flags & xLeft) != 0)
  67240. x = dx;
  67241. else if ((flags & xRight) != 0)
  67242. x = dx + dw - w;
  67243. else
  67244. x = dx + (dw - w) * 0.5;
  67245. if ((flags & yTop) != 0)
  67246. y = dy;
  67247. else if ((flags & yBottom) != 0)
  67248. y = dy + dh - h;
  67249. else
  67250. y = dy + (dh - h) * 0.5;
  67251. }
  67252. }
  67253. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  67254. float w, float h,
  67255. const float dx, const float dy,
  67256. const float dw, const float dh) const throw()
  67257. {
  67258. if (w == 0 || h == 0)
  67259. return AffineTransform::identity;
  67260. const float scaleX = dw / w;
  67261. const float scaleY = dh / h;
  67262. if ((flags & stretchToFit) != 0)
  67263. return AffineTransform::translation (-x, -y)
  67264. .scaled (scaleX, scaleY)
  67265. .translated (dx, dy);
  67266. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  67267. : jmin (scaleX, scaleY);
  67268. if ((flags & onlyReduceInSize) != 0)
  67269. scale = jmin (scale, 1.0f);
  67270. if ((flags & onlyIncreaseInSize) != 0)
  67271. scale = jmax (scale, 1.0f);
  67272. w *= scale;
  67273. h *= scale;
  67274. float newX = dx;
  67275. if ((flags & xRight) != 0)
  67276. newX += dw - w; // right
  67277. else if ((flags & xLeft) == 0)
  67278. newX += (dw - w) / 2.0f; // centre
  67279. float newY = dy;
  67280. if ((flags & yBottom) != 0)
  67281. newY += dh - h; // bottom
  67282. else if ((flags & yTop) == 0)
  67283. newY += (dh - h) / 2.0f; // centre
  67284. return AffineTransform::translation (-x, -y)
  67285. .scaled (scale, scale)
  67286. .translated (newX, newY);
  67287. }
  67288. END_JUCE_NAMESPACE
  67289. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  67290. /*** Start of inlined file: juce_Drawable.cpp ***/
  67291. BEGIN_JUCE_NAMESPACE
  67292. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  67293. const AffineTransform& transform_,
  67294. const float opacity_) throw()
  67295. : g (g_),
  67296. transform (transform_),
  67297. opacity (opacity_)
  67298. {
  67299. }
  67300. Drawable::Drawable()
  67301. {
  67302. }
  67303. Drawable::~Drawable()
  67304. {
  67305. }
  67306. void Drawable::draw (Graphics& g, const float opacity,
  67307. const AffineTransform& transform) const
  67308. {
  67309. render (RenderingContext (g, transform, opacity));
  67310. }
  67311. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  67312. {
  67313. draw (g, opacity, AffineTransform::translation (x, y));
  67314. }
  67315. void Drawable::drawWithin (Graphics& g,
  67316. const int destX,
  67317. const int destY,
  67318. const int destW,
  67319. const int destH,
  67320. const RectanglePlacement& placement,
  67321. const float opacity) const
  67322. {
  67323. if (destW > 0 && destH > 0)
  67324. {
  67325. Rectangle<float> bounds (getBounds());
  67326. draw (g, opacity,
  67327. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  67328. (float) destX, (float) destY,
  67329. (float) destW, (float) destH));
  67330. }
  67331. }
  67332. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  67333. {
  67334. Drawable* result = 0;
  67335. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  67336. if (image != 0)
  67337. {
  67338. DrawableImage* const di = new DrawableImage();
  67339. di->setImage (image, true);
  67340. result = di;
  67341. }
  67342. else
  67343. {
  67344. const String asString (String::createStringFromData (data, (int) numBytes));
  67345. XmlDocument doc (asString);
  67346. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67347. if (outer != 0 && outer->hasTagName (T("svg")))
  67348. {
  67349. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67350. if (svg != 0)
  67351. result = Drawable::createFromSVG (*svg);
  67352. }
  67353. }
  67354. return result;
  67355. }
  67356. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67357. {
  67358. MemoryBlock mb;
  67359. dataSource.readIntoMemoryBlock (mb);
  67360. return createFromImageData (mb.getData(), mb.getSize());
  67361. }
  67362. Drawable* Drawable::createFromImageFile (const File& file)
  67363. {
  67364. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67365. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67366. }
  67367. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67368. {
  67369. Drawable* d = DrawablePath::createFromValueTree (tree);
  67370. if (d == 0)
  67371. {
  67372. d = DrawableComposite::createFromValueTree (tree);
  67373. if (d == 0)
  67374. {
  67375. d = DrawableImage::createFromValueTree (tree);
  67376. if (d == 0)
  67377. d = DrawableText::createFromValueTree (tree);
  67378. }
  67379. }
  67380. return d;
  67381. }
  67382. END_JUCE_NAMESPACE
  67383. /*** End of inlined file: juce_Drawable.cpp ***/
  67384. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  67385. BEGIN_JUCE_NAMESPACE
  67386. DrawableComposite::DrawableComposite()
  67387. {
  67388. }
  67389. DrawableComposite::~DrawableComposite()
  67390. {
  67391. }
  67392. void DrawableComposite::insertDrawable (Drawable* drawable,
  67393. const AffineTransform& transform,
  67394. const int index)
  67395. {
  67396. if (drawable != 0)
  67397. {
  67398. if (! drawables.contains (drawable))
  67399. {
  67400. drawables.insert (index, drawable);
  67401. if (transform.isIdentity())
  67402. transforms.insert (index, 0);
  67403. else
  67404. transforms.insert (index, new AffineTransform (transform));
  67405. }
  67406. else
  67407. {
  67408. jassertfalse // trying to add a drawable that's already in here!
  67409. }
  67410. }
  67411. }
  67412. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67413. const AffineTransform& transform,
  67414. const int index)
  67415. {
  67416. insertDrawable (drawable.createCopy(), transform, index);
  67417. }
  67418. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67419. {
  67420. drawables.remove (index, deleteDrawable);
  67421. transforms.remove (index);
  67422. }
  67423. void DrawableComposite::bringToFront (const int index)
  67424. {
  67425. if (index >= 0 && index < drawables.size() - 1)
  67426. {
  67427. drawables.move (index, -1);
  67428. transforms.move (index, -1);
  67429. }
  67430. }
  67431. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67432. {
  67433. if (drawables.size() > 0 && context.opacity > 0)
  67434. {
  67435. if (context.opacity >= 1.0f || drawables.size() == 1)
  67436. {
  67437. Drawable::RenderingContext contextCopy (context);
  67438. for (int i = 0; i < drawables.size(); ++i)
  67439. {
  67440. const AffineTransform* const t = transforms.getUnchecked(i);
  67441. contextCopy.transform = (t == 0) ? context.transform
  67442. : t->followedBy (context.transform);
  67443. drawables.getUnchecked(i)->render (contextCopy);
  67444. }
  67445. }
  67446. else
  67447. {
  67448. // To correctly render a whole composite layer with an overall transparency,
  67449. // we need to render everything opaquely into a temp buffer, then blend that
  67450. // with the target opacity...
  67451. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67452. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67453. {
  67454. Graphics tempG (tempImage);
  67455. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67456. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67457. render (tempContext);
  67458. }
  67459. context.g.setOpacity (context.opacity);
  67460. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67461. }
  67462. }
  67463. }
  67464. const Rectangle<float> DrawableComposite::getBounds() const
  67465. {
  67466. Rectangle<float> bounds;
  67467. for (int i = 0; i < drawables.size(); ++i)
  67468. {
  67469. const Drawable* const d = drawables.getUnchecked(i);
  67470. const AffineTransform* const t = transforms.getUnchecked(i);
  67471. bounds = bounds.getUnion (t == 0 ? d->getBounds()
  67472. : d->getBounds().transformed (*t));
  67473. }
  67474. return bounds;
  67475. }
  67476. bool DrawableComposite::hitTest (float x, float y) const
  67477. {
  67478. for (int i = 0; i < drawables.size(); ++i)
  67479. {
  67480. float tx = x;
  67481. float ty = y;
  67482. const AffineTransform* const t = transforms.getUnchecked(i);
  67483. if (t != 0)
  67484. t->inverted().transformPoint (tx, ty);
  67485. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67486. return true;
  67487. }
  67488. return false;
  67489. }
  67490. Drawable* DrawableComposite::createCopy() const
  67491. {
  67492. DrawableComposite* const dc = new DrawableComposite();
  67493. for (int i = 0; i < drawables.size(); ++i)
  67494. {
  67495. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67496. const AffineTransform* const t = transforms.getUnchecked(i);
  67497. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67498. }
  67499. return dc;
  67500. }
  67501. ValueTree DrawableComposite::createValueTree() const throw()
  67502. {
  67503. ValueTree v (T("Group"));
  67504. if (getName().isNotEmpty())
  67505. v.setProperty ("id", getName(), 0);
  67506. for (int i = 0; i < drawables.size(); ++i)
  67507. {
  67508. Drawable* const d = drawables.getUnchecked(i);
  67509. ValueTree child (d->createValueTree());
  67510. AffineTransform* transform = transforms.getUnchecked(i);
  67511. if (transform != 0)
  67512. {
  67513. String t;
  67514. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67515. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67516. child.setProperty ("transform", t, 0);
  67517. }
  67518. v.addChild (child, -1, 0);
  67519. }
  67520. return v;
  67521. }
  67522. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67523. {
  67524. if (! tree.hasType ("Group"))
  67525. return 0;
  67526. DrawableComposite* dc = new DrawableComposite();
  67527. dc->setName (tree ["id"]);
  67528. for (int i = 0; i < tree.getNumChildren(); ++i)
  67529. {
  67530. ValueTree childTree (tree.getChild (i));
  67531. Drawable* d = Drawable::createFromValueTree (childTree);
  67532. if (d != 0)
  67533. {
  67534. AffineTransform transform;
  67535. const String transformAtt (childTree ["transform"].toString());
  67536. if (transformAtt.isNotEmpty())
  67537. {
  67538. StringArray tokens;
  67539. tokens.addTokens (transformAtt.trim(), false);
  67540. tokens.removeEmptyStrings (true);
  67541. if (tokens.size() == 6)
  67542. {
  67543. float f[6];
  67544. for (int j = 0; j < 6; ++j)
  67545. f[j] = (float) tokens[j].getDoubleValue();
  67546. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67547. }
  67548. }
  67549. dc->insertDrawable (d, transform);
  67550. }
  67551. }
  67552. return dc;
  67553. }
  67554. END_JUCE_NAMESPACE
  67555. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67556. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67557. BEGIN_JUCE_NAMESPACE
  67558. DrawableImage::DrawableImage()
  67559. : image (0),
  67560. canDeleteImage (false),
  67561. opacity (1.0f),
  67562. overlayColour (0x00000000)
  67563. {
  67564. }
  67565. DrawableImage::~DrawableImage()
  67566. {
  67567. clearImage();
  67568. }
  67569. void DrawableImage::clearImage()
  67570. {
  67571. if (canDeleteImage && image != 0)
  67572. ImageCache::releaseOrDelete (image);
  67573. image = 0;
  67574. }
  67575. void DrawableImage::setImage (const Image& imageToCopy)
  67576. {
  67577. clearImage();
  67578. image = new Image (imageToCopy);
  67579. canDeleteImage = true;
  67580. }
  67581. void DrawableImage::setImage (Image* imageToUse,
  67582. const bool releaseWhenNotNeeded)
  67583. {
  67584. clearImage();
  67585. image = imageToUse;
  67586. canDeleteImage = releaseWhenNotNeeded;
  67587. }
  67588. void DrawableImage::setOpacity (const float newOpacity)
  67589. {
  67590. opacity = newOpacity;
  67591. }
  67592. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67593. {
  67594. overlayColour = newOverlayColour;
  67595. }
  67596. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67597. {
  67598. if (image != 0)
  67599. {
  67600. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67601. {
  67602. context.g.setOpacity (context.opacity * opacity);
  67603. context.g.drawImageTransformed (image, image->getBounds(),
  67604. context.transform, false);
  67605. }
  67606. if (! overlayColour.isTransparent())
  67607. {
  67608. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67609. context.g.drawImageTransformed (image, image->getBounds(),
  67610. context.transform, true);
  67611. }
  67612. }
  67613. }
  67614. const Rectangle<float> DrawableImage::getBounds() const
  67615. {
  67616. if (image == 0)
  67617. return Rectangle<float>();
  67618. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67619. }
  67620. bool DrawableImage::hitTest (float x, float y) const
  67621. {
  67622. return image != 0
  67623. && x >= 0.0f
  67624. && y >= 0.0f
  67625. && x < image->getWidth()
  67626. && y < image->getHeight()
  67627. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67628. }
  67629. Drawable* DrawableImage::createCopy() const
  67630. {
  67631. DrawableImage* const di = new DrawableImage();
  67632. di->opacity = opacity;
  67633. di->overlayColour = overlayColour;
  67634. if (image != 0)
  67635. {
  67636. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67637. {
  67638. di->setImage (*image);
  67639. }
  67640. else
  67641. {
  67642. ImageCache::incReferenceCount (image);
  67643. di->setImage (image, true);
  67644. }
  67645. }
  67646. return di;
  67647. }
  67648. ValueTree DrawableImage::createValueTree() const throw()
  67649. {
  67650. ValueTree v (T("Image"));
  67651. if (getName().isNotEmpty())
  67652. v.setProperty ("id", getName(), 0);
  67653. if (opacity < 1.0f)
  67654. v.setProperty ("opacity", (double) opacity, 0);
  67655. if (! overlayColour.isTransparent())
  67656. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67657. if (image != 0)
  67658. {
  67659. MemoryOutputStream imageData;
  67660. PNGImageFormat pngFormat;
  67661. if (pngFormat.writeImageToStream (*image, imageData))
  67662. {
  67663. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67664. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67665. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67666. v.setProperty ("data", base64, 0);
  67667. }
  67668. }
  67669. return v;
  67670. }
  67671. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67672. {
  67673. if (! tree.hasType ("Image"))
  67674. return 0;
  67675. DrawableImage* di = new DrawableImage();
  67676. di->setName (tree ["id"]);
  67677. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67678. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67679. MemoryBlock imageData;
  67680. if (imageData.fromBase64Encoding (tree ["data"]))
  67681. {
  67682. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67683. if (im == 0)
  67684. return false;
  67685. di->setImage (im, true);
  67686. }
  67687. return di;
  67688. }
  67689. END_JUCE_NAMESPACE
  67690. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67691. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67692. BEGIN_JUCE_NAMESPACE
  67693. DrawablePath::DrawablePath()
  67694. : mainFill (FillType (Colours::black)),
  67695. strokeFill (FillType (Colours::transparentBlack)),
  67696. strokeType (0.0f)
  67697. {
  67698. }
  67699. DrawablePath::~DrawablePath()
  67700. {
  67701. }
  67702. void DrawablePath::setPath (const Path& newPath) throw()
  67703. {
  67704. path = newPath;
  67705. updateOutline();
  67706. }
  67707. void DrawablePath::setFill (const FillType& newFill) throw()
  67708. {
  67709. mainFill = newFill;
  67710. }
  67711. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67712. {
  67713. strokeFill = newFill;
  67714. }
  67715. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67716. {
  67717. strokeType = newStrokeType;
  67718. updateOutline();
  67719. }
  67720. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67721. {
  67722. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67723. }
  67724. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67725. {
  67726. {
  67727. FillType f (mainFill);
  67728. if (f.isGradient())
  67729. f.gradient->multiplyOpacity (context.opacity);
  67730. f.transform = f.transform.followedBy (context.transform);
  67731. context.g.setFillType (f);
  67732. context.g.fillPath (path, context.transform);
  67733. }
  67734. if (strokeType.getStrokeThickness() > 0.0f)
  67735. {
  67736. FillType f (strokeFill);
  67737. if (f.isGradient())
  67738. f.gradient->multiplyOpacity (context.opacity);
  67739. f.transform = f.transform.followedBy (context.transform);
  67740. context.g.setFillType (f);
  67741. context.g.fillPath (stroke, context.transform);
  67742. }
  67743. }
  67744. void DrawablePath::updateOutline()
  67745. {
  67746. stroke.clear();
  67747. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67748. }
  67749. const Rectangle<float> DrawablePath::getBounds() const
  67750. {
  67751. if (strokeType.getStrokeThickness() > 0.0f)
  67752. return stroke.getBounds();
  67753. else
  67754. return path.getBounds();
  67755. }
  67756. bool DrawablePath::hitTest (float x, float y) const
  67757. {
  67758. return path.contains (x, y)
  67759. || stroke.contains (x, y);
  67760. }
  67761. Drawable* DrawablePath::createCopy() const
  67762. {
  67763. DrawablePath* const dp = new DrawablePath();
  67764. dp->path = path;
  67765. dp->stroke = stroke;
  67766. dp->mainFill = mainFill;
  67767. dp->strokeFill = strokeFill;
  67768. dp->strokeType = strokeType;
  67769. return dp;
  67770. }
  67771. static const FillType readFillTypeFromTree (const ValueTree& v)
  67772. {
  67773. const String type (v["type"].toString());
  67774. if (type.equalsIgnoreCase (T("solid")))
  67775. {
  67776. const String colour (v ["colour"].toString());
  67777. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67778. : (uint32) colour.getHexValue32()));
  67779. }
  67780. else if (type.equalsIgnoreCase ("gradient"))
  67781. {
  67782. ColourGradient g;
  67783. g.x1 = v["x1"];
  67784. g.y1 = v["y1"];
  67785. g.x2 = v["x2"];
  67786. g.y2 = v["y2"];
  67787. g.isRadial = v["radial"];
  67788. StringArray colours;
  67789. colours.addTokens (v["colours"].toString(), false);
  67790. for (int i = 0; i < colours.size() / 2; ++i)
  67791. g.addColour (colours[i * 2].getDoubleValue(),
  67792. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67793. return FillType (g);
  67794. }
  67795. jassertfalse
  67796. return FillType();
  67797. }
  67798. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67799. {
  67800. ValueTree v (tagName);
  67801. if (fillType.isColour())
  67802. {
  67803. v.setProperty ("type", T("solid"), 0);
  67804. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67805. }
  67806. else if (fillType.isGradient())
  67807. {
  67808. v.setProperty ("type", T("gradient"), 0);
  67809. v.setProperty ("x1", fillType.gradient->x1, 0);
  67810. v.setProperty ("y1", fillType.gradient->y1, 0);
  67811. v.setProperty ("x2", fillType.gradient->x2, 0);
  67812. v.setProperty ("y2", fillType.gradient->y2, 0);
  67813. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67814. String s;
  67815. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67816. s << " " << fillType.gradient->getColourPosition (i)
  67817. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67818. v.setProperty ("colours", s.trimStart(), 0);
  67819. }
  67820. else
  67821. {
  67822. jassertfalse //xxx
  67823. }
  67824. return v;
  67825. }
  67826. ValueTree DrawablePath::createValueTree() const throw()
  67827. {
  67828. ValueTree v (T("Path"));
  67829. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67830. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67831. if (getName().isNotEmpty())
  67832. v.setProperty ("id", getName(), 0);
  67833. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67834. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67835. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67836. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67837. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67838. v.setProperty ("path", path.toString(), 0);
  67839. return v;
  67840. }
  67841. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67842. {
  67843. if (! tree.hasType ("Path"))
  67844. return 0;
  67845. DrawablePath* p = new DrawablePath();
  67846. p->setName (tree ["id"]);
  67847. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67848. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67849. const String jointStyle (tree ["jointStyle"].toString());
  67850. const String endStyle (tree ["capStyle"].toString());
  67851. p->strokeType
  67852. = PathStrokeType (tree ["strokeWidth"],
  67853. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67854. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67855. : PathStrokeType::mitered),
  67856. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67857. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67858. : PathStrokeType::butt));
  67859. p->path.clear();
  67860. p->path.restoreFromString (tree ["path"]);
  67861. p->updateOutline();
  67862. return p;
  67863. }
  67864. END_JUCE_NAMESPACE
  67865. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67866. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67867. BEGIN_JUCE_NAMESPACE
  67868. DrawableText::DrawableText()
  67869. : colour (Colours::white)
  67870. {
  67871. }
  67872. DrawableText::~DrawableText()
  67873. {
  67874. }
  67875. void DrawableText::setText (const GlyphArrangement& newText)
  67876. {
  67877. text = newText;
  67878. }
  67879. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67880. {
  67881. text.clear();
  67882. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67883. }
  67884. void DrawableText::setColour (const Colour& newColour)
  67885. {
  67886. colour = newColour;
  67887. }
  67888. void DrawableText::render (const Drawable::RenderingContext& context) const
  67889. {
  67890. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67891. text.draw (context.g, context.transform);
  67892. }
  67893. const Rectangle<float> DrawableText::getBounds() const
  67894. {
  67895. float x, y, w, h;
  67896. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67897. w -= x;
  67898. h -= y;
  67899. return Rectangle<float> (x, y, w, h);
  67900. }
  67901. bool DrawableText::hitTest (float x, float y) const
  67902. {
  67903. return text.findGlyphIndexAt (x, y) >= 0;
  67904. }
  67905. Drawable* DrawableText::createCopy() const
  67906. {
  67907. DrawableText* const dt = new DrawableText();
  67908. dt->text = text;
  67909. dt->colour = colour;
  67910. return dt;
  67911. }
  67912. ValueTree DrawableText::createValueTree() const throw()
  67913. {
  67914. ValueTree v (T("Text"));
  67915. if (getName().isNotEmpty())
  67916. v.setProperty ("id", getName(), 0);
  67917. jassertfalse // xxx not finished!
  67918. return v;
  67919. }
  67920. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67921. {
  67922. if (! tree.hasType ("Text"))
  67923. return 0;
  67924. DrawableText* dt = new DrawableText();
  67925. dt->setName (tree ["id"]);
  67926. jassertfalse // xxx not finished!
  67927. return dt;
  67928. }
  67929. END_JUCE_NAMESPACE
  67930. /*** End of inlined file: juce_DrawableText.cpp ***/
  67931. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67932. BEGIN_JUCE_NAMESPACE
  67933. class SVGState
  67934. {
  67935. public:
  67936. SVGState (const XmlElement* const topLevel)
  67937. : topLevelXml (topLevel),
  67938. elementX (0), elementY (0),
  67939. width (512), height (512),
  67940. viewBoxW (0), viewBoxH (0)
  67941. {
  67942. }
  67943. ~SVGState()
  67944. {
  67945. }
  67946. Drawable* parseSVGElement (const XmlElement& xml)
  67947. {
  67948. if (! xml.hasTagName (T("svg")))
  67949. return 0;
  67950. DrawableComposite* const drawable = new DrawableComposite();
  67951. drawable->setName (xml.getStringAttribute (T("id")));
  67952. SVGState newState (*this);
  67953. if (xml.hasAttribute (T("transform")))
  67954. newState.addTransform (xml);
  67955. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  67956. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  67957. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  67958. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  67959. if (xml.hasAttribute (T("viewBox")))
  67960. {
  67961. const String viewParams (xml.getStringAttribute (T("viewBox")));
  67962. int i = 0;
  67963. float vx, vy, vw, vh;
  67964. if (parseCoords (viewParams, vx, vy, i, true)
  67965. && parseCoords (viewParams, vw, vh, i, true)
  67966. && vw > 0
  67967. && vh > 0)
  67968. {
  67969. newState.viewBoxW = vw;
  67970. newState.viewBoxH = vh;
  67971. int placementFlags = 0;
  67972. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  67973. if (aspect.containsIgnoreCase (T("none")))
  67974. {
  67975. placementFlags = RectanglePlacement::stretchToFit;
  67976. }
  67977. else
  67978. {
  67979. if (aspect.containsIgnoreCase (T("slice")))
  67980. placementFlags |= RectanglePlacement::fillDestination;
  67981. if (aspect.containsIgnoreCase (T("xMin")))
  67982. placementFlags |= RectanglePlacement::xLeft;
  67983. else if (aspect.containsIgnoreCase (T("xMax")))
  67984. placementFlags |= RectanglePlacement::xRight;
  67985. else
  67986. placementFlags |= RectanglePlacement::xMid;
  67987. if (aspect.containsIgnoreCase (T("yMin")))
  67988. placementFlags |= RectanglePlacement::yTop;
  67989. else if (aspect.containsIgnoreCase (T("yMax")))
  67990. placementFlags |= RectanglePlacement::yBottom;
  67991. else
  67992. placementFlags |= RectanglePlacement::yMid;
  67993. }
  67994. const RectanglePlacement placement (placementFlags);
  67995. newState.transform
  67996. = placement.getTransformToFit (vx, vy, vw, vh,
  67997. 0.0f, 0.0f, newState.width, newState.height)
  67998. .followedBy (newState.transform);
  67999. }
  68000. }
  68001. else
  68002. {
  68003. if (viewBoxW == 0)
  68004. newState.viewBoxW = newState.width;
  68005. if (viewBoxH == 0)
  68006. newState.viewBoxH = newState.height;
  68007. }
  68008. newState.parseSubElements (xml, drawable);
  68009. return drawable;
  68010. }
  68011. private:
  68012. const XmlElement* const topLevelXml;
  68013. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  68014. AffineTransform transform;
  68015. String cssStyleText;
  68016. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  68017. {
  68018. forEachXmlChildElement (xml, e)
  68019. {
  68020. Drawable* d = 0;
  68021. if (e->hasTagName (T("g")))
  68022. d = parseGroupElement (*e);
  68023. else if (e->hasTagName (T("svg")))
  68024. d = parseSVGElement (*e);
  68025. else if (e->hasTagName (T("path")))
  68026. d = parsePath (*e);
  68027. else if (e->hasTagName (T("rect")))
  68028. d = parseRect (*e);
  68029. else if (e->hasTagName (T("circle")))
  68030. d = parseCircle (*e);
  68031. else if (e->hasTagName (T("ellipse")))
  68032. d = parseEllipse (*e);
  68033. else if (e->hasTagName (T("line")))
  68034. d = parseLine (*e);
  68035. else if (e->hasTagName (T("polyline")))
  68036. d = parsePolygon (*e, true);
  68037. else if (e->hasTagName (T("polygon")))
  68038. d = parsePolygon (*e, false);
  68039. else if (e->hasTagName (T("text")))
  68040. d = parseText (*e);
  68041. else if (e->hasTagName (T("switch")))
  68042. d = parseSwitch (*e);
  68043. else if (e->hasTagName (T("style")))
  68044. parseCSSStyle (*e);
  68045. parentDrawable->insertDrawable (d);
  68046. }
  68047. }
  68048. DrawableComposite* parseSwitch (const XmlElement& xml)
  68049. {
  68050. const XmlElement* const group = xml.getChildByName (T("g"));
  68051. if (group != 0)
  68052. return parseGroupElement (*group);
  68053. return 0;
  68054. }
  68055. DrawableComposite* parseGroupElement (const XmlElement& xml)
  68056. {
  68057. DrawableComposite* const drawable = new DrawableComposite();
  68058. drawable->setName (xml.getStringAttribute (T("id")));
  68059. if (xml.hasAttribute (T("transform")))
  68060. {
  68061. SVGState newState (*this);
  68062. newState.addTransform (xml);
  68063. newState.parseSubElements (xml, drawable);
  68064. }
  68065. else
  68066. {
  68067. parseSubElements (xml, drawable);
  68068. }
  68069. return drawable;
  68070. }
  68071. Drawable* parsePath (const XmlElement& xml) const
  68072. {
  68073. const String d (xml.getStringAttribute (T("d")).trimStart());
  68074. Path path;
  68075. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  68076. path.setUsingNonZeroWinding (false);
  68077. int index = 0;
  68078. float lastX = 0, lastY = 0;
  68079. float lastX2 = 0, lastY2 = 0;
  68080. tchar lastCommandChar = 0;
  68081. bool isRelative = true;
  68082. bool carryOn = true;
  68083. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  68084. for (;;)
  68085. {
  68086. float x, y, x2, y2, x3, y3;
  68087. if (validCommandChars.containsChar (d[index]))
  68088. {
  68089. lastCommandChar = d [index++];
  68090. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  68091. }
  68092. switch (lastCommandChar)
  68093. {
  68094. case T('M'):
  68095. case T('m'):
  68096. case T('L'):
  68097. case T('l'):
  68098. if (parseCoords (d, x, y, index, false))
  68099. {
  68100. if (isRelative)
  68101. {
  68102. x += lastX;
  68103. y += lastY;
  68104. }
  68105. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  68106. path.startNewSubPath (x, y);
  68107. else
  68108. path.lineTo (x, y);
  68109. lastX2 = lastX;
  68110. lastY2 = lastY;
  68111. lastX = x;
  68112. lastY = y;
  68113. }
  68114. else
  68115. {
  68116. ++index;
  68117. }
  68118. break;
  68119. case T('H'):
  68120. case T('h'):
  68121. if (parseCoord (d, x, index, false, true))
  68122. {
  68123. if (isRelative)
  68124. x += lastX;
  68125. path.lineTo (x, lastY);
  68126. lastX2 = lastX;
  68127. lastX = x;
  68128. }
  68129. else
  68130. {
  68131. ++index;
  68132. }
  68133. break;
  68134. case T('V'):
  68135. case T('v'):
  68136. if (parseCoord (d, y, index, false, false))
  68137. {
  68138. if (isRelative)
  68139. y += lastY;
  68140. path.lineTo (lastX, y);
  68141. lastY2 = lastY;
  68142. lastY = y;
  68143. }
  68144. else
  68145. {
  68146. ++index;
  68147. }
  68148. break;
  68149. case T('C'):
  68150. case T('c'):
  68151. if (parseCoords (d, x, y, index, false)
  68152. && parseCoords (d, x2, y2, index, false)
  68153. && parseCoords (d, x3, y3, index, false))
  68154. {
  68155. if (isRelative)
  68156. {
  68157. x += lastX;
  68158. y += lastY;
  68159. x2 += lastX;
  68160. y2 += lastY;
  68161. x3 += lastX;
  68162. y3 += lastY;
  68163. }
  68164. path.cubicTo (x, y, x2, y2, x3, y3);
  68165. lastX2 = x2;
  68166. lastY2 = y2;
  68167. lastX = x3;
  68168. lastY = y3;
  68169. }
  68170. else
  68171. {
  68172. ++index;
  68173. }
  68174. break;
  68175. case T('S'):
  68176. case T('s'):
  68177. if (parseCoords (d, x, y, index, false)
  68178. && parseCoords (d, x3, y3, index, false))
  68179. {
  68180. if (isRelative)
  68181. {
  68182. x += lastX;
  68183. y += lastY;
  68184. x3 += lastX;
  68185. y3 += lastY;
  68186. }
  68187. x2 = lastX + (lastX - lastX2);
  68188. y2 = lastY + (lastY - lastY2);
  68189. path.cubicTo (x2, y2, x, y, x3, y3);
  68190. lastX2 = x;
  68191. lastY2 = y;
  68192. lastX = x3;
  68193. lastY = y3;
  68194. }
  68195. else
  68196. {
  68197. ++index;
  68198. }
  68199. break;
  68200. case T('Q'):
  68201. case T('q'):
  68202. if (parseCoords (d, x, y, index, false)
  68203. && parseCoords (d, x2, y2, index, false))
  68204. {
  68205. if (isRelative)
  68206. {
  68207. x += lastX;
  68208. y += lastY;
  68209. x2 += lastX;
  68210. y2 += lastY;
  68211. }
  68212. path.quadraticTo (x, y, x2, y2);
  68213. lastX2 = x;
  68214. lastY2 = y;
  68215. lastX = x2;
  68216. lastY = y2;
  68217. }
  68218. else
  68219. {
  68220. ++index;
  68221. }
  68222. break;
  68223. case T('T'):
  68224. case T('t'):
  68225. if (parseCoords (d, x, y, index, false))
  68226. {
  68227. if (isRelative)
  68228. {
  68229. x += lastX;
  68230. y += lastY;
  68231. }
  68232. x2 = lastX + (lastX - lastX2);
  68233. y2 = lastY + (lastY - lastY2);
  68234. path.quadraticTo (x2, y2, x, y);
  68235. lastX2 = x2;
  68236. lastY2 = y2;
  68237. lastX = x;
  68238. lastY = y;
  68239. }
  68240. else
  68241. {
  68242. ++index;
  68243. }
  68244. break;
  68245. case T('A'):
  68246. case T('a'):
  68247. if (parseCoords (d, x, y, index, false))
  68248. {
  68249. String num;
  68250. if (parseNextNumber (d, num, index, false))
  68251. {
  68252. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  68253. if (parseNextNumber (d, num, index, false))
  68254. {
  68255. const bool largeArc = num.getIntValue() != 0;
  68256. if (parseNextNumber (d, num, index, false))
  68257. {
  68258. const bool sweep = num.getIntValue() != 0;
  68259. if (parseCoords (d, x2, y2, index, false))
  68260. {
  68261. if (isRelative)
  68262. {
  68263. x2 += lastX;
  68264. y2 += lastY;
  68265. }
  68266. if (lastX != x2 || lastY != y2)
  68267. {
  68268. double centreX, centreY, startAngle, deltaAngle;
  68269. double rx = x, ry = y;
  68270. endpointToCentreParameters (lastX, lastY, x2, y2,
  68271. angle, largeArc, sweep,
  68272. rx, ry, centreX, centreY,
  68273. startAngle, deltaAngle);
  68274. path.addCentredArc ((float) centreX, (float) centreY,
  68275. (float) rx, (float) ry,
  68276. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  68277. false);
  68278. path.lineTo (x2, y2);
  68279. }
  68280. lastX2 = lastX;
  68281. lastY2 = lastY;
  68282. lastX = x2;
  68283. lastY = y2;
  68284. }
  68285. }
  68286. }
  68287. }
  68288. }
  68289. else
  68290. {
  68291. ++index;
  68292. }
  68293. break;
  68294. case T('Z'):
  68295. case T('z'):
  68296. path.closeSubPath();
  68297. while (CharacterFunctions::isWhitespace (d [index]))
  68298. ++index;
  68299. break;
  68300. default:
  68301. carryOn = false;
  68302. break;
  68303. }
  68304. if (! carryOn)
  68305. break;
  68306. }
  68307. return parseShape (xml, path);
  68308. }
  68309. Drawable* parseRect (const XmlElement& xml) const
  68310. {
  68311. Path rect;
  68312. const bool hasRX = xml.hasAttribute (T("rx"));
  68313. const bool hasRY = xml.hasAttribute (T("ry"));
  68314. if (hasRX || hasRY)
  68315. {
  68316. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68317. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68318. if (! hasRX)
  68319. rx = ry;
  68320. else if (! hasRY)
  68321. ry = rx;
  68322. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68323. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68324. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68325. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  68326. rx, ry);
  68327. }
  68328. else
  68329. {
  68330. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68331. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68332. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68333. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  68334. }
  68335. return parseShape (xml, rect);
  68336. }
  68337. Drawable* parseCircle (const XmlElement& xml) const
  68338. {
  68339. Path circle;
  68340. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68341. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68342. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68343. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68344. return parseShape (xml, circle);
  68345. }
  68346. Drawable* parseEllipse (const XmlElement& xml) const
  68347. {
  68348. Path ellipse;
  68349. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68350. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68351. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68352. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68353. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68354. return parseShape (xml, ellipse);
  68355. }
  68356. Drawable* parseLine (const XmlElement& xml) const
  68357. {
  68358. Path line;
  68359. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68360. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68361. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68362. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68363. line.startNewSubPath (x1, y1);
  68364. line.lineTo (x2, y2);
  68365. return parseShape (xml, line);
  68366. }
  68367. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68368. {
  68369. const String points (xml.getStringAttribute (T("points")));
  68370. Path path;
  68371. int index = 0;
  68372. float x, y;
  68373. if (parseCoords (points, x, y, index, true))
  68374. {
  68375. float firstX = x;
  68376. float firstY = y;
  68377. float lastX = 0, lastY = 0;
  68378. path.startNewSubPath (x, y);
  68379. while (parseCoords (points, x, y, index, true))
  68380. {
  68381. lastX = x;
  68382. lastY = y;
  68383. path.lineTo (x, y);
  68384. }
  68385. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68386. path.closeSubPath();
  68387. }
  68388. return parseShape (xml, path);
  68389. }
  68390. Drawable* parseShape (const XmlElement& xml, Path& path,
  68391. const bool shouldParseTransform = true) const
  68392. {
  68393. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68394. {
  68395. SVGState newState (*this);
  68396. newState.addTransform (xml);
  68397. return newState.parseShape (xml, path, false);
  68398. }
  68399. DrawablePath* dp = new DrawablePath();
  68400. dp->setName (xml.getStringAttribute (T("id")));
  68401. dp->setFill (FillType (Colours::transparentBlack));
  68402. path.applyTransform (transform);
  68403. dp->setPath (path);
  68404. Path::Iterator iter (path);
  68405. bool containsClosedSubPath = false;
  68406. while (iter.next())
  68407. {
  68408. if (iter.elementType == Path::Iterator::closePath)
  68409. {
  68410. containsClosedSubPath = true;
  68411. break;
  68412. }
  68413. }
  68414. dp->setFill (getPathFillType (path,
  68415. getStyleAttribute (&xml, T("fill")),
  68416. getStyleAttribute (&xml, T("fill-opacity")),
  68417. getStyleAttribute (&xml, T("opacity")),
  68418. containsClosedSubPath ? Colours::black
  68419. : Colours::transparentBlack));
  68420. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68421. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68422. {
  68423. dp->setStrokeFill (getPathFillType (path, strokeType,
  68424. getStyleAttribute (&xml, T("stroke-opacity")),
  68425. getStyleAttribute (&xml, T("opacity")),
  68426. Colours::transparentBlack));
  68427. dp->setStrokeType (getStrokeFor (&xml));
  68428. }
  68429. return dp;
  68430. }
  68431. const XmlElement* findLinkedElement (const XmlElement* e) const
  68432. {
  68433. const String id (e->getStringAttribute (T("xlink:href")));
  68434. if (! id.startsWithChar (T('#')))
  68435. return 0;
  68436. return findElementForId (topLevelXml, id.substring (1));
  68437. }
  68438. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68439. {
  68440. if (fillXml == 0)
  68441. return;
  68442. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68443. {
  68444. int index = 0;
  68445. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68446. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68447. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68448. double offset = e->getDoubleAttribute (T("offset"));
  68449. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68450. offset *= 0.01;
  68451. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68452. }
  68453. }
  68454. const FillType getPathFillType (const Path& path,
  68455. const String& fill,
  68456. const String& fillOpacity,
  68457. const String& overallOpacity,
  68458. const Colour& defaultColour) const
  68459. {
  68460. float opacity = 1.0f;
  68461. if (overallOpacity.isNotEmpty())
  68462. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68463. if (fillOpacity.isNotEmpty())
  68464. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68465. if (fill.startsWithIgnoreCase (T("url")))
  68466. {
  68467. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68468. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68469. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68470. if (fillXml != 0
  68471. && (fillXml->hasTagName (T("linearGradient"))
  68472. || fillXml->hasTagName (T("radialGradient"))))
  68473. {
  68474. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68475. ColourGradient gradient;
  68476. addGradientStopsIn (gradient, inheritedFrom);
  68477. addGradientStopsIn (gradient, fillXml);
  68478. if (gradient.getNumColours() > 0)
  68479. {
  68480. gradient.addColour (0.0, gradient.getColour (0));
  68481. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68482. }
  68483. else
  68484. {
  68485. gradient.addColour (0.0, Colours::black);
  68486. gradient.addColour (1.0, Colours::black);
  68487. }
  68488. if (overallOpacity.isNotEmpty())
  68489. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68490. jassert (gradient.getNumColours() > 0);
  68491. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68492. float width = viewBoxW;
  68493. float height = viewBoxH;
  68494. float dx = 0.0f;
  68495. float dy = 0.0f;
  68496. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68497. if (! userSpace)
  68498. {
  68499. const Rectangle<float> bounds (path.getBounds());
  68500. dx = bounds.getX();
  68501. dy = bounds.getY();
  68502. width = bounds.getWidth();
  68503. height = bounds.getHeight();
  68504. }
  68505. if (gradient.isRadial)
  68506. {
  68507. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68508. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68509. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68510. gradient.x2 = gradient.x1 + radius;
  68511. gradient.y2 = gradient.y1;
  68512. //xxx (the fx, fy focal point isn't handled properly here..)
  68513. }
  68514. else
  68515. {
  68516. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68517. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68518. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68519. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68520. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68521. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68522. }
  68523. FillType type (gradient);
  68524. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68525. .followedBy (transform);
  68526. return type;
  68527. }
  68528. }
  68529. if (fill.equalsIgnoreCase (T("none")))
  68530. return Colours::transparentBlack;
  68531. int i = 0;
  68532. const Colour colour (parseColour (fill, i, defaultColour));
  68533. return colour.withMultipliedAlpha (opacity);
  68534. }
  68535. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68536. {
  68537. const String width (getStyleAttribute (xml, T("stroke-width")));
  68538. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68539. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68540. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68541. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68542. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68543. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68544. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68545. if (join.equalsIgnoreCase (T("round")))
  68546. joinStyle = PathStrokeType::curved;
  68547. else if (join.equalsIgnoreCase (T("bevel")))
  68548. joinStyle = PathStrokeType::beveled;
  68549. if (cap.equalsIgnoreCase (T("round")))
  68550. capStyle = PathStrokeType::rounded;
  68551. else if (cap.equalsIgnoreCase (T("square")))
  68552. capStyle = PathStrokeType::square;
  68553. float ox = 0.0f, oy = 0.0f;
  68554. transform.transformPoint (ox, oy);
  68555. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68556. transform.transformPoint (x, y);
  68557. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68558. joinStyle, capStyle);
  68559. }
  68560. Drawable* parseText (const XmlElement& xml)
  68561. {
  68562. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68563. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68564. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68565. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68566. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68567. //xxx not done text yet!
  68568. forEachXmlChildElement (xml, e)
  68569. {
  68570. if (e->isTextElement())
  68571. {
  68572. const String text (e->getText());
  68573. Path path;
  68574. Drawable* s = parseShape (*e, path);
  68575. delete s;
  68576. }
  68577. else if (e->hasTagName (T("tspan")))
  68578. {
  68579. Drawable* s = parseText (*e);
  68580. delete s;
  68581. }
  68582. }
  68583. return 0;
  68584. }
  68585. void addTransform (const XmlElement& xml)
  68586. {
  68587. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68588. .followedBy (transform);
  68589. }
  68590. bool parseCoord (const String& s, float& value, int& index,
  68591. const bool allowUnits, const bool isX) const
  68592. {
  68593. String number;
  68594. if (! parseNextNumber (s, number, index, allowUnits))
  68595. {
  68596. value = 0;
  68597. return false;
  68598. }
  68599. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68600. return true;
  68601. }
  68602. bool parseCoords (const String& s, float& x, float& y,
  68603. int& index, const bool allowUnits) const
  68604. {
  68605. return parseCoord (s, x, index, allowUnits, true)
  68606. && parseCoord (s, y, index, allowUnits, false);
  68607. }
  68608. float getCoordLength (const String& s, const float sizeForProportions) const
  68609. {
  68610. float n = s.getFloatValue();
  68611. const int len = s.length();
  68612. if (len > 2)
  68613. {
  68614. const float dpi = 96.0f;
  68615. const tchar n1 = s [len - 2];
  68616. const tchar n2 = s [len - 1];
  68617. if (n1 == T('i') && n2 == T('n'))
  68618. n *= dpi;
  68619. else if (n1 == T('m') && n2 == T('m'))
  68620. n *= dpi / 25.4f;
  68621. else if (n1 == T('c') && n2 == T('m'))
  68622. n *= dpi / 2.54f;
  68623. else if (n1 == T('p') && n2 == T('c'))
  68624. n *= 15.0f;
  68625. else if (n2 == T('%'))
  68626. n *= 0.01f * sizeForProportions;
  68627. }
  68628. return n;
  68629. }
  68630. void getCoordList (Array <float>& coords, const String& list,
  68631. const bool allowUnits, const bool isX) const
  68632. {
  68633. int index = 0;
  68634. float value;
  68635. while (parseCoord (list, value, index, allowUnits, isX))
  68636. coords.add (value);
  68637. }
  68638. void parseCSSStyle (const XmlElement& xml)
  68639. {
  68640. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68641. }
  68642. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68643. const String& defaultValue = String::empty) const
  68644. {
  68645. if (xml->hasAttribute (attributeName))
  68646. return xml->getStringAttribute (attributeName, defaultValue);
  68647. const String styleAtt (xml->getStringAttribute (T("style")));
  68648. if (styleAtt.isNotEmpty())
  68649. {
  68650. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68651. if (value.isNotEmpty())
  68652. return value;
  68653. }
  68654. else if (xml->hasAttribute (T("class")))
  68655. {
  68656. const String className (T(".") + xml->getStringAttribute (T("class")));
  68657. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68658. if (index < 0)
  68659. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68660. if (index >= 0)
  68661. {
  68662. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68663. if (openBracket > index)
  68664. {
  68665. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68666. if (closeBracket > openBracket)
  68667. {
  68668. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68669. if (value.isNotEmpty())
  68670. return value;
  68671. }
  68672. }
  68673. }
  68674. }
  68675. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68676. if (xml != 0)
  68677. return getStyleAttribute (xml, attributeName, defaultValue);
  68678. return defaultValue;
  68679. }
  68680. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68681. {
  68682. if (xml->hasAttribute (attributeName))
  68683. return xml->getStringAttribute (attributeName);
  68684. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68685. if (xml != 0)
  68686. return getInheritedAttribute (xml, attributeName);
  68687. return String::empty;
  68688. }
  68689. static bool isIdentifierChar (const tchar c)
  68690. {
  68691. return CharacterFunctions::isLetter (c) || c == T('-');
  68692. }
  68693. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68694. {
  68695. int i = 0;
  68696. for (;;)
  68697. {
  68698. i = list.indexOf (i, attributeName);
  68699. if (i < 0)
  68700. break;
  68701. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68702. && ! isIdentifierChar (list [i + attributeName.length()]))
  68703. {
  68704. i = list.indexOfChar (i, T(':'));
  68705. if (i < 0)
  68706. break;
  68707. int end = list.indexOfChar (i, T(';'));
  68708. if (end < 0)
  68709. end = 0x7ffff;
  68710. return list.substring (i + 1, end).trim();
  68711. }
  68712. ++i;
  68713. }
  68714. return defaultValue;
  68715. }
  68716. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68717. {
  68718. const tchar* const s = (const tchar*) source;
  68719. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68720. ++index;
  68721. int start = index;
  68722. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68723. ++index;
  68724. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68725. ++index;
  68726. if ((s[index] == T('e') || s[index] == T('E'))
  68727. && (CharacterFunctions::isDigit (s[index + 1])
  68728. || s[index + 1] == T('-')
  68729. || s[index + 1] == T('+')))
  68730. {
  68731. index += 2;
  68732. while (CharacterFunctions::isDigit (s[index]))
  68733. ++index;
  68734. }
  68735. if (allowUnits)
  68736. {
  68737. while (CharacterFunctions::isLetter (s[index]))
  68738. ++index;
  68739. }
  68740. if (index == start)
  68741. return false;
  68742. value = String (s + start, index - start);
  68743. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68744. ++index;
  68745. return true;
  68746. }
  68747. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68748. {
  68749. if (s [index] == T('#'))
  68750. {
  68751. uint32 hex [6];
  68752. zeromem (hex, sizeof (hex));
  68753. int numChars = 0;
  68754. for (int i = 6; --i >= 0;)
  68755. {
  68756. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68757. if (hexValue >= 0)
  68758. hex [numChars++] = hexValue;
  68759. else
  68760. break;
  68761. }
  68762. if (numChars <= 3)
  68763. return Colour ((uint8) (hex [0] * 0x11),
  68764. (uint8) (hex [1] * 0x11),
  68765. (uint8) (hex [2] * 0x11));
  68766. else
  68767. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68768. (uint8) ((hex [2] << 4) + hex [3]),
  68769. (uint8) ((hex [4] << 4) + hex [5]));
  68770. }
  68771. else if (s [index] == T('r')
  68772. && s [index + 1] == T('g')
  68773. && s [index + 2] == T('b'))
  68774. {
  68775. const int openBracket = s.indexOfChar (index, T('('));
  68776. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68777. if (openBracket >= 3 && closeBracket > openBracket)
  68778. {
  68779. index = closeBracket;
  68780. StringArray tokens;
  68781. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68782. tokens.trim();
  68783. tokens.removeEmptyStrings();
  68784. if (tokens[0].containsChar (T('%')))
  68785. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68786. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68787. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68788. else
  68789. return Colour ((uint8) tokens[0].getIntValue(),
  68790. (uint8) tokens[1].getIntValue(),
  68791. (uint8) tokens[2].getIntValue());
  68792. }
  68793. }
  68794. return Colours::findColourForName (s, defaultColour);
  68795. }
  68796. static const AffineTransform parseTransform (String t)
  68797. {
  68798. AffineTransform result;
  68799. while (t.isNotEmpty())
  68800. {
  68801. StringArray tokens;
  68802. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68803. .upToFirstOccurrenceOf (T(")"), false, false),
  68804. T(", "), 0);
  68805. tokens.removeEmptyStrings (true);
  68806. float numbers [6];
  68807. for (int i = 0; i < 6; ++i)
  68808. numbers[i] = tokens[i].getFloatValue();
  68809. AffineTransform trans;
  68810. if (t.startsWithIgnoreCase (T("matrix")))
  68811. {
  68812. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68813. numbers[1], numbers[3], numbers[5]);
  68814. }
  68815. else if (t.startsWithIgnoreCase (T("translate")))
  68816. {
  68817. jassert (tokens.size() == 2);
  68818. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68819. }
  68820. else if (t.startsWithIgnoreCase (T("scale")))
  68821. {
  68822. if (tokens.size() == 1)
  68823. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68824. else
  68825. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68826. }
  68827. else if (t.startsWithIgnoreCase (T("rotate")))
  68828. {
  68829. if (tokens.size() != 3)
  68830. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68831. else
  68832. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68833. numbers[1], numbers[2]);
  68834. }
  68835. else if (t.startsWithIgnoreCase (T("skewX")))
  68836. {
  68837. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68838. 0.0f, 1.0f, 0.0f);
  68839. }
  68840. else if (t.startsWithIgnoreCase (T("skewY")))
  68841. {
  68842. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68843. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68844. }
  68845. result = trans.followedBy (result);
  68846. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68847. }
  68848. return result;
  68849. }
  68850. static void endpointToCentreParameters (const double x1, const double y1,
  68851. const double x2, const double y2,
  68852. const double angle,
  68853. const bool largeArc, const bool sweep,
  68854. double& rx, double& ry,
  68855. double& centreX, double& centreY,
  68856. double& startAngle, double& deltaAngle)
  68857. {
  68858. const double midX = (x1 - x2) * 0.5;
  68859. const double midY = (y1 - y2) * 0.5;
  68860. const double cosAngle = cos (angle);
  68861. const double sinAngle = sin (angle);
  68862. const double xp = cosAngle * midX + sinAngle * midY;
  68863. const double yp = cosAngle * midY - sinAngle * midX;
  68864. const double xp2 = xp * xp;
  68865. const double yp2 = yp * yp;
  68866. double rx2 = rx * rx;
  68867. double ry2 = ry * ry;
  68868. const double s = (xp2 / rx2) + (yp2 / ry2);
  68869. double c;
  68870. if (s <= 1.0)
  68871. {
  68872. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68873. / (( rx2 * yp2) + (ry2 * xp2))));
  68874. if (largeArc == sweep)
  68875. c = -c;
  68876. }
  68877. else
  68878. {
  68879. const double s2 = sqrt (s);
  68880. rx *= s2;
  68881. ry *= s2;
  68882. rx2 = rx * rx;
  68883. ry2 = ry * ry;
  68884. c = 0;
  68885. }
  68886. const double cpx = ((rx * yp) / ry) * c;
  68887. const double cpy = ((-ry * xp) / rx) * c;
  68888. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68889. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68890. const double ux = (xp - cpx) / rx;
  68891. const double uy = (yp - cpy) / ry;
  68892. const double vx = (-xp - cpx) / rx;
  68893. const double vy = (-yp - cpy) / ry;
  68894. const double length = juce_hypot (ux, uy);
  68895. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68896. if (uy < 0)
  68897. startAngle = -startAngle;
  68898. startAngle += double_Pi * 0.5;
  68899. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68900. / (length * juce_hypot (vx, vy))));
  68901. if ((ux * vy) - (uy * vx) < 0)
  68902. deltaAngle = -deltaAngle;
  68903. if (sweep)
  68904. {
  68905. if (deltaAngle < 0)
  68906. deltaAngle += double_Pi * 2.0;
  68907. }
  68908. else
  68909. {
  68910. if (deltaAngle > 0)
  68911. deltaAngle -= double_Pi * 2.0;
  68912. }
  68913. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68914. }
  68915. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68916. {
  68917. forEachXmlChildElement (*parent, e)
  68918. {
  68919. if (e->compareAttribute (T("id"), id))
  68920. return e;
  68921. const XmlElement* const found = findElementForId (e, id);
  68922. if (found != 0)
  68923. return found;
  68924. }
  68925. return 0;
  68926. }
  68927. SVGState& operator= (const SVGState&);
  68928. };
  68929. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68930. {
  68931. SVGState state (&svgDocument);
  68932. return state.parseSVGElement (svgDocument);
  68933. }
  68934. END_JUCE_NAMESPACE
  68935. /*** End of inlined file: juce_SVGParser.cpp ***/
  68936. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68937. BEGIN_JUCE_NAMESPACE
  68938. #if JUCE_MSVC
  68939. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68940. #endif
  68941. DropShadowEffect::DropShadowEffect()
  68942. : offsetX (0),
  68943. offsetY (0),
  68944. radius (4),
  68945. opacity (0.6f)
  68946. {
  68947. }
  68948. DropShadowEffect::~DropShadowEffect()
  68949. {
  68950. }
  68951. void DropShadowEffect::setShadowProperties (const float newRadius,
  68952. const float newOpacity,
  68953. const int newShadowOffsetX,
  68954. const int newShadowOffsetY)
  68955. {
  68956. radius = jmax (1.1f, newRadius);
  68957. offsetX = newShadowOffsetX;
  68958. offsetY = newShadowOffsetY;
  68959. opacity = newOpacity;
  68960. }
  68961. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68962. {
  68963. const int w = image.getWidth();
  68964. const int h = image.getHeight();
  68965. Image shadowImage (Image::SingleChannel, w, h, false);
  68966. const Image::BitmapData srcData (image, 0, 0, w, h);
  68967. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68968. const int filter = roundToInt (63.0f / radius);
  68969. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68970. for (int x = w; --x >= 0;)
  68971. {
  68972. int shadowAlpha = 0;
  68973. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68974. uint8* shadowPix = destData.data + x;
  68975. for (int y = h; --y >= 0;)
  68976. {
  68977. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68978. *shadowPix = (uint8) shadowAlpha;
  68979. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68980. shadowPix += destData.lineStride;
  68981. }
  68982. }
  68983. for (int y = h; --y >= 0;)
  68984. {
  68985. int shadowAlpha = 0;
  68986. uint8* shadowPix = destData.getLinePointer (y);
  68987. for (int x = w; --x >= 0;)
  68988. {
  68989. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68990. *shadowPix++ = (uint8) shadowAlpha;
  68991. }
  68992. }
  68993. g.setColour (Colours::black.withAlpha (opacity));
  68994. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68995. g.setOpacity (1.0f);
  68996. g.drawImageAt (&image, 0, 0);
  68997. }
  68998. END_JUCE_NAMESPACE
  68999. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  69000. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  69001. BEGIN_JUCE_NAMESPACE
  69002. GlowEffect::GlowEffect()
  69003. : radius (2.0f),
  69004. colour (Colours::white)
  69005. {
  69006. }
  69007. GlowEffect::~GlowEffect()
  69008. {
  69009. }
  69010. void GlowEffect::setGlowProperties (const float newRadius,
  69011. const Colour& newColour)
  69012. {
  69013. radius = newRadius;
  69014. colour = newColour;
  69015. }
  69016. void GlowEffect::applyEffect (Image& image, Graphics& g)
  69017. {
  69018. const int w = image.getWidth();
  69019. const int h = image.getHeight();
  69020. Image temp (image.getFormat(), w, h, true);
  69021. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  69022. blurKernel.createGaussianBlur (radius);
  69023. blurKernel.rescaleAllValues (radius);
  69024. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  69025. g.setColour (colour);
  69026. g.drawImageAt (&temp, 0, 0, true);
  69027. g.setOpacity (1.0f);
  69028. g.drawImageAt (&image, 0, 0, false);
  69029. }
  69030. END_JUCE_NAMESPACE
  69031. /*** End of inlined file: juce_GlowEffect.cpp ***/
  69032. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69033. BEGIN_JUCE_NAMESPACE
  69034. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  69035. : opacity (opacity_)
  69036. {
  69037. }
  69038. ReduceOpacityEffect::~ReduceOpacityEffect()
  69039. {
  69040. }
  69041. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  69042. {
  69043. opacity = jlimit (0.0f, 1.0f, newOpacity);
  69044. }
  69045. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  69046. {
  69047. g.setOpacity (opacity);
  69048. g.drawImageAt (&image, 0, 0);
  69049. }
  69050. END_JUCE_NAMESPACE
  69051. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69052. /*** Start of inlined file: juce_Font.cpp ***/
  69053. BEGIN_JUCE_NAMESPACE
  69054. static const float minFontHeight = 0.1f;
  69055. static const float maxFontHeight = 10000.0f;
  69056. static const float defaultFontHeight = 14.0f;
  69057. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  69058. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  69059. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  69060. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  69061. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  69062. const float kerning_, const float ascent_, const int styleFlags_,
  69063. Typeface* const typeface_) throw()
  69064. : typefaceName (typefaceName_),
  69065. height (height_),
  69066. horizontalScale (horizontalScale_),
  69067. kerning (kerning_),
  69068. ascent (ascent_),
  69069. styleFlags (styleFlags_),
  69070. typeface (typeface_)
  69071. {
  69072. }
  69073. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  69074. : typefaceName (other.typefaceName),
  69075. height (other.height),
  69076. horizontalScale (other.horizontalScale),
  69077. kerning (other.kerning),
  69078. ascent (other.ascent),
  69079. styleFlags (other.styleFlags),
  69080. typeface (other.typeface)
  69081. {
  69082. }
  69083. Font::Font() throw()
  69084. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  69085. 1.0f, 0, 0, Font::plain, 0))
  69086. {
  69087. }
  69088. Font::Font (const float fontHeight, const int styleFlags_) throw()
  69089. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69090. 1.0f, 0, 0, styleFlags_, 0))
  69091. {
  69092. }
  69093. Font::Font (const String& typefaceName_,
  69094. const float fontHeight,
  69095. const int styleFlags_) throw()
  69096. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69097. 1.0f, 0, 0, styleFlags_, 0))
  69098. {
  69099. }
  69100. Font::Font (const Font& other) throw()
  69101. : font (other.font)
  69102. {
  69103. }
  69104. Font& Font::operator= (const Font& other) throw()
  69105. {
  69106. font = other.font;
  69107. return *this;
  69108. }
  69109. Font::~Font() throw()
  69110. {
  69111. }
  69112. Font::Font (const Typeface::Ptr& typeface) throw()
  69113. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  69114. 1.0f, 0, 0, Font::plain, typeface))
  69115. {
  69116. }
  69117. bool Font::operator== (const Font& other) const throw()
  69118. {
  69119. return font == other.font
  69120. || (font->height == other.font->height
  69121. && font->styleFlags == other.font->styleFlags
  69122. && font->horizontalScale == other.font->horizontalScale
  69123. && font->kerning == other.font->kerning
  69124. && font->typefaceName == other.font->typefaceName);
  69125. }
  69126. bool Font::operator!= (const Font& other) const throw()
  69127. {
  69128. return ! operator== (other);
  69129. }
  69130. void Font::dupeInternalIfShared() throw()
  69131. {
  69132. if (font->getReferenceCount() > 1)
  69133. font = new SharedFontInternal (*font);
  69134. }
  69135. const String Font::getDefaultSansSerifFontName() throw()
  69136. {
  69137. return juce_defaultFontNameSans;
  69138. }
  69139. const String Font::getDefaultSerifFontName() throw()
  69140. {
  69141. return juce_defaultFontNameSerif;
  69142. }
  69143. const String Font::getDefaultMonospacedFontName() throw()
  69144. {
  69145. return juce_defaultFontNameMono;
  69146. }
  69147. void Font::setTypefaceName (const String& faceName) throw()
  69148. {
  69149. if (faceName != font->typefaceName)
  69150. {
  69151. dupeInternalIfShared();
  69152. font->typefaceName = faceName;
  69153. font->typeface = 0;
  69154. font->ascent = 0;
  69155. }
  69156. }
  69157. static String fallbackFont;
  69158. const String Font::getFallbackFontName() throw()
  69159. {
  69160. return fallbackFont;
  69161. }
  69162. void Font::setFallbackFontName (const String& name) throw()
  69163. {
  69164. fallbackFont = name;
  69165. }
  69166. void Font::setHeight (float newHeight) throw()
  69167. {
  69168. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69169. if (font->height != newHeight)
  69170. {
  69171. dupeInternalIfShared();
  69172. font->height = newHeight;
  69173. }
  69174. }
  69175. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  69176. {
  69177. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69178. if (font->height != newHeight)
  69179. {
  69180. dupeInternalIfShared();
  69181. font->horizontalScale *= (font->height / newHeight);
  69182. font->height = newHeight;
  69183. }
  69184. }
  69185. void Font::setStyleFlags (const int newFlags) throw()
  69186. {
  69187. if (font->styleFlags != newFlags)
  69188. {
  69189. dupeInternalIfShared();
  69190. font->styleFlags = newFlags;
  69191. font->typeface = 0;
  69192. font->ascent = 0;
  69193. }
  69194. }
  69195. void Font::setSizeAndStyle (float newHeight,
  69196. const int newStyleFlags,
  69197. const float newHorizontalScale,
  69198. const float newKerningAmount) throw()
  69199. {
  69200. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69201. if (font->height != newHeight
  69202. || font->horizontalScale != newHorizontalScale
  69203. || font->kerning != newKerningAmount)
  69204. {
  69205. dupeInternalIfShared();
  69206. font->height = newHeight;
  69207. font->horizontalScale = newHorizontalScale;
  69208. font->kerning = newKerningAmount;
  69209. }
  69210. setStyleFlags (newStyleFlags);
  69211. }
  69212. void Font::setHorizontalScale (const float scaleFactor) throw()
  69213. {
  69214. dupeInternalIfShared();
  69215. font->horizontalScale = scaleFactor;
  69216. }
  69217. void Font::setExtraKerningFactor (const float extraKerning) throw()
  69218. {
  69219. dupeInternalIfShared();
  69220. font->kerning = extraKerning;
  69221. }
  69222. void Font::setBold (const bool shouldBeBold) throw()
  69223. {
  69224. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  69225. : (font->styleFlags & ~bold));
  69226. }
  69227. bool Font::isBold() const throw()
  69228. {
  69229. return (font->styleFlags & bold) != 0;
  69230. }
  69231. void Font::setItalic (const bool shouldBeItalic) throw()
  69232. {
  69233. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  69234. : (font->styleFlags & ~italic));
  69235. }
  69236. bool Font::isItalic() const throw()
  69237. {
  69238. return (font->styleFlags & italic) != 0;
  69239. }
  69240. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  69241. {
  69242. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  69243. : (font->styleFlags & ~underlined));
  69244. }
  69245. bool Font::isUnderlined() const throw()
  69246. {
  69247. return (font->styleFlags & underlined) != 0;
  69248. }
  69249. float Font::getAscent() const throw()
  69250. {
  69251. if (font->ascent == 0)
  69252. font->ascent = getTypeface()->getAscent();
  69253. return font->height * font->ascent;
  69254. }
  69255. float Font::getDescent() const throw()
  69256. {
  69257. return font->height - getAscent();
  69258. }
  69259. int Font::getStringWidth (const String& text) const throw()
  69260. {
  69261. return roundToInt (getStringWidthFloat (text));
  69262. }
  69263. float Font::getStringWidthFloat (const String& text) const throw()
  69264. {
  69265. float w = getTypeface()->getStringWidth (text);
  69266. if (font->kerning != 0)
  69267. w += font->kerning * text.length();
  69268. return w * font->height * font->horizontalScale;
  69269. }
  69270. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  69271. {
  69272. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  69273. const float scale = font->height * font->horizontalScale;
  69274. const int num = xOffsets.size();
  69275. if (num > 0)
  69276. {
  69277. float* const x = &(xOffsets.getReference(0));
  69278. if (font->kerning != 0)
  69279. {
  69280. for (int i = 0; i < num; ++i)
  69281. x[i] = (x[i] + i * font->kerning) * scale;
  69282. }
  69283. else
  69284. {
  69285. for (int i = 0; i < num; ++i)
  69286. x[i] *= scale;
  69287. }
  69288. }
  69289. }
  69290. void Font::findFonts (Array<Font>& destArray) throw()
  69291. {
  69292. const StringArray names (findAllTypefaceNames());
  69293. for (int i = 0; i < names.size(); ++i)
  69294. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  69295. }
  69296. class TypefaceCache : public DeletedAtShutdown
  69297. {
  69298. public:
  69299. TypefaceCache (int numToCache = 10) throw()
  69300. : counter (1)
  69301. {
  69302. while (--numToCache >= 0)
  69303. faces.add (new CachedFace());
  69304. }
  69305. ~TypefaceCache()
  69306. {
  69307. clearUpDefaultFontNames();
  69308. clearSingletonInstance();
  69309. }
  69310. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  69311. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  69312. {
  69313. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  69314. const String faceName (font.getTypefaceName());
  69315. int i;
  69316. for (i = faces.size(); --i >= 0;)
  69317. {
  69318. CachedFace* const face = faces.getUnchecked(i);
  69319. if (face->flags == flags
  69320. && face->typefaceName == faceName)
  69321. {
  69322. face->lastUsageCount = ++counter;
  69323. return face->typeFace;
  69324. }
  69325. }
  69326. int replaceIndex = 0;
  69327. int bestLastUsageCount = std::numeric_limits<int>::max();
  69328. for (i = faces.size(); --i >= 0;)
  69329. {
  69330. const int lu = faces.getUnchecked(i)->lastUsageCount;
  69331. if (bestLastUsageCount > lu)
  69332. {
  69333. bestLastUsageCount = lu;
  69334. replaceIndex = i;
  69335. }
  69336. }
  69337. CachedFace* const face = faces.getUnchecked (replaceIndex);
  69338. face->typefaceName = faceName;
  69339. face->flags = flags;
  69340. face->lastUsageCount = ++counter;
  69341. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69342. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69343. return face->typeFace;
  69344. }
  69345. juce_UseDebuggingNewOperator
  69346. private:
  69347. struct CachedFace
  69348. {
  69349. CachedFace() throw()
  69350. : lastUsageCount (0), flags (-1)
  69351. {
  69352. }
  69353. String typefaceName;
  69354. int lastUsageCount;
  69355. int flags;
  69356. Typeface::Ptr typeFace;
  69357. };
  69358. int counter;
  69359. OwnedArray <CachedFace> faces;
  69360. TypefaceCache (const TypefaceCache&);
  69361. TypefaceCache& operator= (const TypefaceCache&);
  69362. };
  69363. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69364. Typeface* Font::getTypeface() const throw()
  69365. {
  69366. if (font->typeface == 0)
  69367. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69368. return font->typeface;
  69369. }
  69370. END_JUCE_NAMESPACE
  69371. /*** End of inlined file: juce_Font.cpp ***/
  69372. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  69373. BEGIN_JUCE_NAMESPACE
  69374. PositionedGlyph::PositionedGlyph()
  69375. {
  69376. }
  69377. void PositionedGlyph::draw (const Graphics& g) const
  69378. {
  69379. if (! isWhitespace())
  69380. {
  69381. g.getInternalContext()->setFont (font);
  69382. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69383. }
  69384. }
  69385. void PositionedGlyph::draw (const Graphics& g,
  69386. const AffineTransform& transform) const
  69387. {
  69388. if (! isWhitespace())
  69389. {
  69390. g.getInternalContext()->setFont (font);
  69391. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69392. .followedBy (transform));
  69393. }
  69394. }
  69395. void PositionedGlyph::createPath (Path& path) const
  69396. {
  69397. if (! isWhitespace())
  69398. {
  69399. Typeface* const t = font.getTypeface();
  69400. if (t != 0)
  69401. {
  69402. Path p;
  69403. t->getOutlineForGlyph (glyph, p);
  69404. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69405. .translated (x, y));
  69406. }
  69407. }
  69408. }
  69409. bool PositionedGlyph::hitTest (float px, float py) const
  69410. {
  69411. if (px >= getLeft() && px < getRight()
  69412. && py >= getTop() && py < getBottom()
  69413. && ! isWhitespace())
  69414. {
  69415. Typeface* const t = font.getTypeface();
  69416. if (t != 0)
  69417. {
  69418. Path p;
  69419. t->getOutlineForGlyph (glyph, p);
  69420. AffineTransform::translation (-x, -y)
  69421. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69422. .transformPoint (px, py);
  69423. return p.contains (px, py);
  69424. }
  69425. }
  69426. return false;
  69427. }
  69428. void PositionedGlyph::moveBy (const float deltaX,
  69429. const float deltaY)
  69430. {
  69431. x += deltaX;
  69432. y += deltaY;
  69433. }
  69434. GlyphArrangement::GlyphArrangement()
  69435. {
  69436. glyphs.ensureStorageAllocated (128);
  69437. }
  69438. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69439. {
  69440. addGlyphArrangement (other);
  69441. }
  69442. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69443. {
  69444. if (this != &other)
  69445. {
  69446. clear();
  69447. addGlyphArrangement (other);
  69448. }
  69449. return *this;
  69450. }
  69451. GlyphArrangement::~GlyphArrangement()
  69452. {
  69453. }
  69454. void GlyphArrangement::clear()
  69455. {
  69456. glyphs.clear();
  69457. }
  69458. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69459. {
  69460. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69461. return *glyphs [index];
  69462. }
  69463. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69464. {
  69465. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69466. for (int i = 0; i < other.glyphs.size(); ++i)
  69467. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69468. }
  69469. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69470. {
  69471. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69472. }
  69473. void GlyphArrangement::addLineOfText (const Font& font,
  69474. const String& text,
  69475. const float xOffset,
  69476. const float yOffset)
  69477. {
  69478. addCurtailedLineOfText (font, text,
  69479. xOffset, yOffset,
  69480. 1.0e10f, false);
  69481. }
  69482. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69483. const String& text,
  69484. float xOffset,
  69485. const float yOffset,
  69486. const float maxWidthPixels,
  69487. const bool useEllipsis)
  69488. {
  69489. int textLen = text.length();
  69490. if (textLen > 0)
  69491. {
  69492. Array <int> newGlyphs;
  69493. Array <float> xOffsets;
  69494. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69495. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69496. textLen = jmin (textLen, newGlyphs.size());
  69497. for (int i = 0; i < textLen; ++i)
  69498. {
  69499. const float thisX = xOffsets.getUnchecked (i);
  69500. const float nextX = xOffsets.getUnchecked (i + 1);
  69501. if (nextX > maxWidthPixels + 1.0f)
  69502. {
  69503. // curtail the string if it's too wide..
  69504. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69505. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69506. break;
  69507. }
  69508. else
  69509. {
  69510. PositionedGlyph* const pg = new PositionedGlyph();
  69511. pg->x = xOffset + thisX;
  69512. pg->y = yOffset;
  69513. pg->w = nextX - thisX;
  69514. pg->font = font;
  69515. pg->glyph = newGlyphs.getUnchecked(i);
  69516. pg->character = unicodeText[i];
  69517. glyphs.add (pg);
  69518. }
  69519. }
  69520. }
  69521. }
  69522. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69523. const int startIndex, int endIndex)
  69524. {
  69525. int numDeleted = 0;
  69526. if (glyphs.size() > 0)
  69527. {
  69528. Array<int> dotGlyphs;
  69529. Array<float> dotXs;
  69530. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69531. const float dx = dotXs[1];
  69532. float xOffset = 0.0f, yOffset = 0.0f;
  69533. while (endIndex > startIndex)
  69534. {
  69535. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69536. xOffset = pg->x;
  69537. yOffset = pg->y;
  69538. glyphs.remove (endIndex);
  69539. ++numDeleted;
  69540. if (xOffset + dx * 3 <= maxXPos)
  69541. break;
  69542. }
  69543. for (int i = 3; --i >= 0;)
  69544. {
  69545. PositionedGlyph* const pg = new PositionedGlyph();
  69546. pg->x = xOffset;
  69547. pg->y = yOffset;
  69548. pg->w = dx;
  69549. pg->font = font;
  69550. pg->character = '.';
  69551. pg->glyph = dotGlyphs.getFirst();
  69552. glyphs.insert (endIndex++, pg);
  69553. --numDeleted;
  69554. xOffset += dx;
  69555. if (xOffset > maxXPos)
  69556. break;
  69557. }
  69558. }
  69559. return numDeleted;
  69560. }
  69561. void GlyphArrangement::addJustifiedText (const Font& font,
  69562. const String& text,
  69563. float x, float y,
  69564. const float maxLineWidth,
  69565. const Justification& horizontalLayout)
  69566. {
  69567. int lineStartIndex = glyphs.size();
  69568. addLineOfText (font, text, x, y);
  69569. const float originalY = y;
  69570. while (lineStartIndex < glyphs.size())
  69571. {
  69572. int i = lineStartIndex;
  69573. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69574. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69575. ++i;
  69576. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69577. int lastWordBreakIndex = -1;
  69578. while (i < glyphs.size())
  69579. {
  69580. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69581. const juce_wchar c = pg->getCharacter();
  69582. if (c == T('\r') || c == T('\n'))
  69583. {
  69584. ++i;
  69585. if (c == T('\r') && i < glyphs.size()
  69586. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69587. ++i;
  69588. break;
  69589. }
  69590. else if (pg->isWhitespace())
  69591. {
  69592. lastWordBreakIndex = i + 1;
  69593. }
  69594. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69595. {
  69596. if (lastWordBreakIndex >= 0)
  69597. i = lastWordBreakIndex;
  69598. break;
  69599. }
  69600. ++i;
  69601. }
  69602. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69603. float currentLineEndX = currentLineStartX;
  69604. for (int j = i; --j >= lineStartIndex;)
  69605. {
  69606. if (! glyphs.getUnchecked (j)->isWhitespace())
  69607. {
  69608. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69609. break;
  69610. }
  69611. }
  69612. float deltaX = 0.0f;
  69613. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69614. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69615. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69616. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69617. else if (horizontalLayout.testFlags (Justification::right))
  69618. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69619. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69620. x + deltaX - currentLineStartX, y - originalY);
  69621. lineStartIndex = i;
  69622. y += font.getHeight();
  69623. }
  69624. }
  69625. void GlyphArrangement::addFittedText (const Font& f,
  69626. const String& text,
  69627. const float x, const float y,
  69628. const float width, const float height,
  69629. const Justification& layout,
  69630. int maximumLines,
  69631. const float minimumHorizontalScale)
  69632. {
  69633. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69634. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69635. if (text.containsAnyOf (T("\r\n")))
  69636. {
  69637. GlyphArrangement ga;
  69638. ga.addJustifiedText (f, text, x, y, width, layout);
  69639. float l, t, r, b;
  69640. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69641. float dy = y - t;
  69642. if (layout.testFlags (Justification::verticallyCentred))
  69643. dy += (height - (b - t)) * 0.5f;
  69644. else if (layout.testFlags (Justification::bottom))
  69645. dy += height - (b - t);
  69646. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69647. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69648. for (int i = 0; i < ga.glyphs.size(); ++i)
  69649. glyphs.add (ga.glyphs.getUnchecked (i));
  69650. ga.glyphs.clear (false);
  69651. return;
  69652. }
  69653. int startIndex = glyphs.size();
  69654. addLineOfText (f, text.trim(), x, y);
  69655. if (glyphs.size() > startIndex)
  69656. {
  69657. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69658. - glyphs.getUnchecked (startIndex)->getLeft();
  69659. if (lineWidth <= 0)
  69660. return;
  69661. if (lineWidth * minimumHorizontalScale < width)
  69662. {
  69663. if (lineWidth > width)
  69664. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69665. width / lineWidth);
  69666. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69667. x, y, width, height, layout);
  69668. }
  69669. else if (maximumLines <= 1)
  69670. {
  69671. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69672. x, y, width, height, f, layout, minimumHorizontalScale);
  69673. }
  69674. else
  69675. {
  69676. Font font (f);
  69677. String txt (text.trim());
  69678. const int length = txt.length();
  69679. const int originalStartIndex = startIndex;
  69680. int numLines = 1;
  69681. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69682. maximumLines = 1;
  69683. maximumLines = jmin (maximumLines, length);
  69684. while (numLines < maximumLines)
  69685. {
  69686. ++numLines;
  69687. const float newFontHeight = height / (float) numLines;
  69688. if (newFontHeight < font.getHeight())
  69689. {
  69690. font.setHeight (jmax (8.0f, newFontHeight));
  69691. removeRangeOfGlyphs (startIndex, -1);
  69692. addLineOfText (font, txt, x, y);
  69693. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69694. - glyphs.getUnchecked (startIndex)->getLeft();
  69695. }
  69696. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69697. break;
  69698. }
  69699. if (numLines < 1)
  69700. numLines = 1;
  69701. float lineY = y;
  69702. float widthPerLine = lineWidth / numLines;
  69703. int lastLineStartIndex = 0;
  69704. for (int line = 0; line < numLines; ++line)
  69705. {
  69706. int i = startIndex;
  69707. lastLineStartIndex = i;
  69708. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69709. if (line == numLines - 1)
  69710. {
  69711. widthPerLine = width;
  69712. i = glyphs.size();
  69713. }
  69714. else
  69715. {
  69716. while (i < glyphs.size())
  69717. {
  69718. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69719. if (lineWidth > widthPerLine)
  69720. {
  69721. // got to a point where the line's too long, so skip forward to find a
  69722. // good place to break it..
  69723. const int searchStartIndex = i;
  69724. while (i < glyphs.size())
  69725. {
  69726. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69727. {
  69728. if (glyphs.getUnchecked (i)->isWhitespace()
  69729. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69730. {
  69731. ++i;
  69732. break;
  69733. }
  69734. }
  69735. else
  69736. {
  69737. // can't find a suitable break, so try looking backwards..
  69738. i = searchStartIndex;
  69739. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69740. {
  69741. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69742. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69743. {
  69744. i -= back - 1;
  69745. break;
  69746. }
  69747. }
  69748. break;
  69749. }
  69750. ++i;
  69751. }
  69752. break;
  69753. }
  69754. ++i;
  69755. }
  69756. int wsStart = i;
  69757. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69758. --wsStart;
  69759. int wsEnd = i;
  69760. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69761. ++wsEnd;
  69762. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69763. i = jmax (wsStart, startIndex + 1);
  69764. }
  69765. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69766. x, lineY, width, font.getHeight(), font,
  69767. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69768. minimumHorizontalScale);
  69769. startIndex = i;
  69770. lineY += font.getHeight();
  69771. if (startIndex >= glyphs.size())
  69772. break;
  69773. }
  69774. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69775. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69776. }
  69777. }
  69778. }
  69779. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69780. const float dx, const float dy)
  69781. {
  69782. jassert (startIndex >= 0);
  69783. if (dx != 0.0f || dy != 0.0f)
  69784. {
  69785. if (num < 0 || startIndex + num > glyphs.size())
  69786. num = glyphs.size() - startIndex;
  69787. while (--num >= 0)
  69788. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69789. }
  69790. }
  69791. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69792. const Justification& justification, float minimumHorizontalScale)
  69793. {
  69794. int numDeleted = 0;
  69795. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69796. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69797. if (lineWidth > w)
  69798. {
  69799. if (minimumHorizontalScale < 1.0f)
  69800. {
  69801. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69802. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69803. }
  69804. if (lineWidth > w)
  69805. {
  69806. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69807. numGlyphs -= numDeleted;
  69808. }
  69809. }
  69810. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69811. return numDeleted;
  69812. }
  69813. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69814. const float horizontalScaleFactor)
  69815. {
  69816. jassert (startIndex >= 0);
  69817. if (num < 0 || startIndex + num > glyphs.size())
  69818. num = glyphs.size() - startIndex;
  69819. if (num > 0)
  69820. {
  69821. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69822. while (--num >= 0)
  69823. {
  69824. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69825. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69826. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69827. pg->w *= horizontalScaleFactor;
  69828. }
  69829. }
  69830. }
  69831. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69832. float& left,
  69833. float& top,
  69834. float& right,
  69835. float& bottom,
  69836. const bool includeWhitespace) const
  69837. {
  69838. jassert (startIndex >= 0);
  69839. if (num < 0 || startIndex + num > glyphs.size())
  69840. num = glyphs.size() - startIndex;
  69841. left = 0.0f;
  69842. top = 0.0f;
  69843. right = 0.0f;
  69844. bottom = 0.0f;
  69845. bool isFirst = true;
  69846. while (--num >= 0)
  69847. {
  69848. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69849. if (includeWhitespace || ! pg->isWhitespace())
  69850. {
  69851. if (isFirst)
  69852. {
  69853. isFirst = false;
  69854. left = pg->getLeft();
  69855. top = pg->getTop();
  69856. right = pg->getRight();
  69857. bottom = pg->getBottom();
  69858. }
  69859. else
  69860. {
  69861. left = jmin (left, pg->getLeft());
  69862. top = jmin (top, pg->getTop());
  69863. right = jmax (right, pg->getRight());
  69864. bottom = jmax (bottom, pg->getBottom());
  69865. }
  69866. }
  69867. }
  69868. }
  69869. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69870. const int num,
  69871. const float x, const float y,
  69872. const float width, const float height,
  69873. const Justification& justification)
  69874. {
  69875. jassert (num >= 0 && startIndex >= 0);
  69876. if (glyphs.size() > 0 && num > 0)
  69877. {
  69878. float left, top, right, bottom;
  69879. getBoundingBox (startIndex, num, left, top, right, bottom,
  69880. ! justification.testFlags (Justification::horizontallyJustified
  69881. | Justification::horizontallyCentred));
  69882. float deltaX = 0.0f;
  69883. if (justification.testFlags (Justification::horizontallyJustified))
  69884. deltaX = x - left;
  69885. else if (justification.testFlags (Justification::horizontallyCentred))
  69886. deltaX = x + (width - (right - left)) * 0.5f - left;
  69887. else if (justification.testFlags (Justification::right))
  69888. deltaX = (x + width) - right;
  69889. else
  69890. deltaX = x - left;
  69891. float deltaY = 0.0f;
  69892. if (justification.testFlags (Justification::top))
  69893. deltaY = y - top;
  69894. else if (justification.testFlags (Justification::bottom))
  69895. deltaY = (y + height) - bottom;
  69896. else
  69897. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69898. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69899. if (justification.testFlags (Justification::horizontallyJustified))
  69900. {
  69901. int lineStart = 0;
  69902. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69903. int i;
  69904. for (i = 0; i < num; ++i)
  69905. {
  69906. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69907. if (glyphY != baseY)
  69908. {
  69909. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69910. lineStart = i;
  69911. baseY = glyphY;
  69912. }
  69913. }
  69914. if (i > lineStart)
  69915. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69916. }
  69917. }
  69918. }
  69919. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69920. {
  69921. if (start + num < glyphs.size()
  69922. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  69923. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  69924. {
  69925. int numSpaces = 0;
  69926. int spacesAtEnd = 0;
  69927. for (int i = 0; i < num; ++i)
  69928. {
  69929. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69930. {
  69931. ++spacesAtEnd;
  69932. ++numSpaces;
  69933. }
  69934. else
  69935. {
  69936. spacesAtEnd = 0;
  69937. }
  69938. }
  69939. numSpaces -= spacesAtEnd;
  69940. if (numSpaces > 0)
  69941. {
  69942. const float startX = glyphs.getUnchecked (start)->getLeft();
  69943. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69944. const float extraPaddingBetweenWords
  69945. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69946. float deltaX = 0.0f;
  69947. for (int i = 0; i < num; ++i)
  69948. {
  69949. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69950. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69951. deltaX += extraPaddingBetweenWords;
  69952. }
  69953. }
  69954. }
  69955. }
  69956. void GlyphArrangement::draw (const Graphics& g) const
  69957. {
  69958. for (int i = 0; i < glyphs.size(); ++i)
  69959. {
  69960. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69961. if (pg->font.isUnderlined())
  69962. {
  69963. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69964. float nextX = pg->x + pg->w;
  69965. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69966. nextX = glyphs.getUnchecked (i + 1)->x;
  69967. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69968. nextX - pg->x, lineThickness);
  69969. }
  69970. pg->draw (g);
  69971. }
  69972. }
  69973. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69974. {
  69975. for (int i = 0; i < glyphs.size(); ++i)
  69976. {
  69977. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69978. if (pg->font.isUnderlined())
  69979. {
  69980. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69981. float nextX = pg->x + pg->w;
  69982. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69983. nextX = glyphs.getUnchecked (i + 1)->x;
  69984. Path p;
  69985. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69986. nextX, pg->y + lineThickness * 2.0f,
  69987. lineThickness);
  69988. g.fillPath (p, transform);
  69989. }
  69990. pg->draw (g, transform);
  69991. }
  69992. }
  69993. void GlyphArrangement::createPath (Path& path) const
  69994. {
  69995. for (int i = 0; i < glyphs.size(); ++i)
  69996. glyphs.getUnchecked (i)->createPath (path);
  69997. }
  69998. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69999. {
  70000. for (int i = 0; i < glyphs.size(); ++i)
  70001. if (glyphs.getUnchecked (i)->hitTest (x, y))
  70002. return i;
  70003. return -1;
  70004. }
  70005. END_JUCE_NAMESPACE
  70006. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  70007. /*** Start of inlined file: juce_TextLayout.cpp ***/
  70008. BEGIN_JUCE_NAMESPACE
  70009. class TextLayout::Token
  70010. {
  70011. public:
  70012. String text;
  70013. Font font;
  70014. int x, y, w, h;
  70015. int line, lineHeight;
  70016. bool isWhitespace, isNewLine;
  70017. Token (const String& t,
  70018. const Font& f,
  70019. const bool isWhitespace_) throw()
  70020. : text (t),
  70021. font (f),
  70022. x(0),
  70023. y(0),
  70024. isWhitespace (isWhitespace_)
  70025. {
  70026. w = font.getStringWidth (t);
  70027. h = roundToInt (f.getHeight());
  70028. isNewLine = t.containsAnyOf (T("\r\n"));
  70029. }
  70030. Token (const Token& other) throw()
  70031. : text (other.text),
  70032. font (other.font),
  70033. x (other.x),
  70034. y (other.y),
  70035. w (other.w),
  70036. h (other.h),
  70037. line (other.line),
  70038. lineHeight (other.lineHeight),
  70039. isWhitespace (other.isWhitespace),
  70040. isNewLine (other.isNewLine)
  70041. {
  70042. }
  70043. ~Token() throw()
  70044. {
  70045. }
  70046. void draw (Graphics& g,
  70047. const int xOffset,
  70048. const int yOffset) throw()
  70049. {
  70050. if (! isWhitespace)
  70051. {
  70052. g.setFont (font);
  70053. g.drawSingleLineText (text.trimEnd(),
  70054. xOffset + x,
  70055. yOffset + y + (lineHeight - h)
  70056. + roundToInt (font.getAscent()));
  70057. }
  70058. }
  70059. juce_UseDebuggingNewOperator
  70060. };
  70061. TextLayout::TextLayout() throw()
  70062. : totalLines (0)
  70063. {
  70064. tokens.ensureStorageAllocated (64);
  70065. }
  70066. TextLayout::TextLayout (const String& text,
  70067. const Font& font) throw()
  70068. : totalLines (0)
  70069. {
  70070. tokens.ensureStorageAllocated (64);
  70071. appendText (text, font);
  70072. }
  70073. TextLayout::TextLayout (const TextLayout& other) throw()
  70074. : totalLines (0)
  70075. {
  70076. *this = other;
  70077. }
  70078. TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  70079. {
  70080. if (this != &other)
  70081. {
  70082. clear();
  70083. totalLines = other.totalLines;
  70084. for (int i = 0; i < other.tokens.size(); ++i)
  70085. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  70086. }
  70087. return *this;
  70088. }
  70089. TextLayout::~TextLayout() throw()
  70090. {
  70091. clear();
  70092. }
  70093. void TextLayout::clear() throw()
  70094. {
  70095. tokens.clear();
  70096. totalLines = 0;
  70097. }
  70098. void TextLayout::appendText (const String& text,
  70099. const Font& font) throw()
  70100. {
  70101. const tchar* t = text;
  70102. String currentString;
  70103. int lastCharType = 0;
  70104. for (;;)
  70105. {
  70106. const tchar c = *t++;
  70107. if (c == 0)
  70108. break;
  70109. int charType;
  70110. if (c == T('\r') || c == T('\n'))
  70111. {
  70112. charType = 0;
  70113. }
  70114. else if (CharacterFunctions::isWhitespace (c))
  70115. {
  70116. charType = 2;
  70117. }
  70118. else
  70119. {
  70120. charType = 1;
  70121. }
  70122. if (charType == 0 || charType != lastCharType)
  70123. {
  70124. if (currentString.isNotEmpty())
  70125. {
  70126. tokens.add (new Token (currentString, font,
  70127. lastCharType == 2 || lastCharType == 0));
  70128. }
  70129. currentString = String::charToString (c);
  70130. if (c == T('\r') && *t == T('\n'))
  70131. currentString += *t++;
  70132. }
  70133. else
  70134. {
  70135. currentString += c;
  70136. }
  70137. lastCharType = charType;
  70138. }
  70139. if (currentString.isNotEmpty())
  70140. tokens.add (new Token (currentString, font, lastCharType == 2));
  70141. }
  70142. void TextLayout::setText (const String& text, const Font& font) throw()
  70143. {
  70144. clear();
  70145. appendText (text, font);
  70146. }
  70147. void TextLayout::layout (int maxWidth,
  70148. const Justification& justification,
  70149. const bool attemptToBalanceLineLengths) throw()
  70150. {
  70151. if (attemptToBalanceLineLengths)
  70152. {
  70153. const int originalW = maxWidth;
  70154. int bestWidth = maxWidth;
  70155. float bestLineProportion = 0.0f;
  70156. while (maxWidth > originalW / 2)
  70157. {
  70158. layout (maxWidth, justification, false);
  70159. if (getNumLines() <= 1)
  70160. return;
  70161. const int lastLineW = getLineWidth (getNumLines() - 1);
  70162. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  70163. const float prop = lastLineW / (float) lastButOneLineW;
  70164. if (prop > 0.9f)
  70165. return;
  70166. if (prop > bestLineProportion)
  70167. {
  70168. bestLineProportion = prop;
  70169. bestWidth = maxWidth;
  70170. }
  70171. maxWidth -= 10;
  70172. }
  70173. layout (bestWidth, justification, false);
  70174. }
  70175. else
  70176. {
  70177. int x = 0;
  70178. int y = 0;
  70179. int h = 0;
  70180. totalLines = 0;
  70181. int i;
  70182. for (i = 0; i < tokens.size(); ++i)
  70183. {
  70184. Token* const t = tokens.getUnchecked(i);
  70185. t->x = x;
  70186. t->y = y;
  70187. t->line = totalLines;
  70188. x += t->w;
  70189. h = jmax (h, t->h);
  70190. const Token* nextTok = tokens [i + 1];
  70191. if (nextTok == 0)
  70192. break;
  70193. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  70194. {
  70195. // finished a line, so go back and update the heights of the things on it
  70196. for (int j = i; j >= 0; --j)
  70197. {
  70198. Token* const tok = tokens.getUnchecked(j);
  70199. if (tok->line == totalLines)
  70200. tok->lineHeight = h;
  70201. else
  70202. break;
  70203. }
  70204. x = 0;
  70205. y += h;
  70206. h = 0;
  70207. ++totalLines;
  70208. }
  70209. }
  70210. // finished a line, so go back and update the heights of the things on it
  70211. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  70212. {
  70213. Token* const t = tokens.getUnchecked(j);
  70214. if (t->line == totalLines)
  70215. t->lineHeight = h;
  70216. else
  70217. break;
  70218. }
  70219. ++totalLines;
  70220. if (! justification.testFlags (Justification::left))
  70221. {
  70222. int totalW = getWidth();
  70223. for (i = totalLines; --i >= 0;)
  70224. {
  70225. const int lineW = getLineWidth (i);
  70226. int dx = 0;
  70227. if (justification.testFlags (Justification::horizontallyCentred))
  70228. dx = (totalW - lineW) / 2;
  70229. else if (justification.testFlags (Justification::right))
  70230. dx = totalW - lineW;
  70231. for (int j = tokens.size(); --j >= 0;)
  70232. {
  70233. Token* const t = tokens.getUnchecked(j);
  70234. if (t->line == i)
  70235. t->x += dx;
  70236. }
  70237. }
  70238. }
  70239. }
  70240. }
  70241. int TextLayout::getLineWidth (const int lineNumber) const throw()
  70242. {
  70243. int maxW = 0;
  70244. for (int i = tokens.size(); --i >= 0;)
  70245. {
  70246. const Token* const t = tokens.getUnchecked(i);
  70247. if (t->line == lineNumber && ! t->isWhitespace)
  70248. maxW = jmax (maxW, t->x + t->w);
  70249. }
  70250. return maxW;
  70251. }
  70252. int TextLayout::getWidth() const throw()
  70253. {
  70254. int maxW = 0;
  70255. for (int i = tokens.size(); --i >= 0;)
  70256. {
  70257. const Token* const t = tokens.getUnchecked(i);
  70258. if (! t->isWhitespace)
  70259. maxW = jmax (maxW, t->x + t->w);
  70260. }
  70261. return maxW;
  70262. }
  70263. int TextLayout::getHeight() const throw()
  70264. {
  70265. int maxH = 0;
  70266. for (int i = tokens.size(); --i >= 0;)
  70267. {
  70268. const Token* const t = tokens.getUnchecked(i);
  70269. if (! t->isWhitespace)
  70270. maxH = jmax (maxH, t->y + t->h);
  70271. }
  70272. return maxH;
  70273. }
  70274. void TextLayout::draw (Graphics& g,
  70275. const int xOffset,
  70276. const int yOffset) const throw()
  70277. {
  70278. for (int i = tokens.size(); --i >= 0;)
  70279. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  70280. }
  70281. void TextLayout::drawWithin (Graphics& g,
  70282. int x, int y, int w, int h,
  70283. const Justification& justification) const throw()
  70284. {
  70285. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  70286. x, y, w, h);
  70287. draw (g, x, y);
  70288. }
  70289. END_JUCE_NAMESPACE
  70290. /*** End of inlined file: juce_TextLayout.cpp ***/
  70291. /*** Start of inlined file: juce_Typeface.cpp ***/
  70292. BEGIN_JUCE_NAMESPACE
  70293. Typeface::Typeface (const String& name_) throw()
  70294. : name (name_)
  70295. {
  70296. }
  70297. Typeface::~Typeface()
  70298. {
  70299. }
  70300. class CustomTypeface::GlyphInfo
  70301. {
  70302. public:
  70303. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  70304. : character (character_), path (path_), width (width_)
  70305. {
  70306. }
  70307. ~GlyphInfo() throw()
  70308. {
  70309. }
  70310. struct KerningPair
  70311. {
  70312. juce_wchar character2;
  70313. float kerningAmount;
  70314. };
  70315. void addKerningPair (const juce_wchar subsequentCharacter,
  70316. const float extraKerningAmount) throw()
  70317. {
  70318. KerningPair kp;
  70319. kp.character2 = subsequentCharacter;
  70320. kp.kerningAmount = extraKerningAmount;
  70321. kerningPairs.add (kp);
  70322. }
  70323. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  70324. {
  70325. if (subsequentCharacter != 0)
  70326. {
  70327. for (int i = kerningPairs.size(); --i >= 0;)
  70328. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  70329. return width + kerningPairs.getReference(i).kerningAmount;
  70330. }
  70331. return width;
  70332. }
  70333. const juce_wchar character;
  70334. const Path path;
  70335. float width;
  70336. Array <KerningPair> kerningPairs;
  70337. juce_UseDebuggingNewOperator
  70338. private:
  70339. GlyphInfo (const GlyphInfo&);
  70340. GlyphInfo& operator= (const GlyphInfo&);
  70341. };
  70342. CustomTypeface::CustomTypeface()
  70343. : Typeface (String::empty)
  70344. {
  70345. clear();
  70346. }
  70347. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70348. : Typeface (String::empty)
  70349. {
  70350. clear();
  70351. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70352. BufferedInputStream in (&gzin, 32768, false);
  70353. name = in.readString();
  70354. isBold = in.readBool();
  70355. isItalic = in.readBool();
  70356. ascent = in.readFloat();
  70357. defaultCharacter = (juce_wchar) in.readShort();
  70358. int i, numChars = in.readInt();
  70359. for (i = 0; i < numChars; ++i)
  70360. {
  70361. const juce_wchar c = (juce_wchar) in.readShort();
  70362. const float width = in.readFloat();
  70363. Path p;
  70364. p.loadPathFromStream (in);
  70365. addGlyph (c, p, width);
  70366. }
  70367. const int numKerningPairs = in.readInt();
  70368. for (i = 0; i < numKerningPairs; ++i)
  70369. {
  70370. const juce_wchar char1 = (juce_wchar) in.readShort();
  70371. const juce_wchar char2 = (juce_wchar) in.readShort();
  70372. addKerningPair (char1, char2, in.readFloat());
  70373. }
  70374. }
  70375. CustomTypeface::~CustomTypeface()
  70376. {
  70377. }
  70378. void CustomTypeface::clear()
  70379. {
  70380. defaultCharacter = 0;
  70381. ascent = 1.0f;
  70382. isBold = isItalic = false;
  70383. zeromem (lookupTable, sizeof (lookupTable));
  70384. glyphs.clear();
  70385. }
  70386. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70387. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70388. {
  70389. name = name_;
  70390. defaultCharacter = defaultCharacter_;
  70391. ascent = ascent_;
  70392. isBold = isBold_;
  70393. isItalic = isItalic_;
  70394. }
  70395. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70396. {
  70397. // Check that you're not trying to add the same character twice..
  70398. jassert (findGlyph (character, false) == 0);
  70399. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70400. lookupTable [character] = (short) glyphs.size();
  70401. glyphs.add (new GlyphInfo (character, path, width));
  70402. }
  70403. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70404. {
  70405. if (extraAmount != 0)
  70406. {
  70407. GlyphInfo* const g = findGlyph (char1, true);
  70408. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70409. if (g != 0)
  70410. g->addKerningPair (char2, extraAmount);
  70411. }
  70412. }
  70413. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70414. {
  70415. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70416. return glyphs [(int) lookupTable [(int) character]];
  70417. for (int i = 0; i < glyphs.size(); ++i)
  70418. {
  70419. GlyphInfo* const g = glyphs.getUnchecked(i);
  70420. if (g->character == character)
  70421. return g;
  70422. }
  70423. if (loadIfNeeded && loadGlyphIfPossible (character))
  70424. return findGlyph (character, false);
  70425. return 0;
  70426. }
  70427. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70428. {
  70429. GlyphInfo* glyph = findGlyph (character, true);
  70430. if (glyph == 0)
  70431. {
  70432. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70433. glyph = findGlyph (L' ', true);
  70434. if (glyph == 0)
  70435. {
  70436. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70437. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70438. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70439. {
  70440. //xxx
  70441. }
  70442. if (glyph == 0)
  70443. glyph = findGlyph (defaultCharacter, true);
  70444. }
  70445. }
  70446. return glyph;
  70447. }
  70448. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70449. {
  70450. return false;
  70451. }
  70452. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70453. {
  70454. for (int i = 0; i < numCharacters; ++i)
  70455. {
  70456. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70457. Array <int> glyphIndexes;
  70458. Array <float> offsets;
  70459. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70460. const int glyphIndex = glyphIndexes.getFirst();
  70461. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70462. {
  70463. const float glyphWidth = offsets[1];
  70464. Path p;
  70465. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70466. addGlyph (c, p, glyphWidth);
  70467. for (int j = glyphs.size() - 1; --j >= 0;)
  70468. {
  70469. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70470. glyphIndexes.clearQuick();
  70471. offsets.clearQuick();
  70472. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70473. if (offsets.size() > 1)
  70474. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70475. }
  70476. }
  70477. }
  70478. }
  70479. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70480. {
  70481. GZIPCompressorOutputStream out (&outputStream);
  70482. out.writeString (name);
  70483. out.writeBool (isBold);
  70484. out.writeBool (isItalic);
  70485. out.writeFloat (ascent);
  70486. out.writeShort ((short) (unsigned short) defaultCharacter);
  70487. out.writeInt (glyphs.size());
  70488. int i, numKerningPairs = 0;
  70489. for (i = 0; i < glyphs.size(); ++i)
  70490. {
  70491. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70492. out.writeShort ((short) (unsigned short) g->character);
  70493. out.writeFloat (g->width);
  70494. g->path.writePathToStream (out);
  70495. numKerningPairs += g->kerningPairs.size();
  70496. }
  70497. out.writeInt (numKerningPairs);
  70498. for (i = 0; i < glyphs.size(); ++i)
  70499. {
  70500. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70501. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70502. {
  70503. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70504. out.writeShort ((short) (unsigned short) g->character);
  70505. out.writeShort ((short) (unsigned short) p.character2);
  70506. out.writeFloat (p.kerningAmount);
  70507. }
  70508. }
  70509. return true;
  70510. }
  70511. float CustomTypeface::getAscent() const
  70512. {
  70513. return ascent;
  70514. }
  70515. float CustomTypeface::getDescent() const
  70516. {
  70517. return 1.0f - ascent;
  70518. }
  70519. float CustomTypeface::getStringWidth (const String& text)
  70520. {
  70521. float x = 0;
  70522. const juce_wchar* t = (const juce_wchar*) text;
  70523. while (*t != 0)
  70524. {
  70525. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70526. if (glyph != 0)
  70527. x += glyph->getHorizontalSpacing (*t);
  70528. }
  70529. return x;
  70530. }
  70531. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70532. {
  70533. xOffsets.add (0);
  70534. float x = 0;
  70535. const juce_wchar* t = (const juce_wchar*) text;
  70536. while (*t != 0)
  70537. {
  70538. const juce_wchar c = *t++;
  70539. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70540. if (glyph != 0)
  70541. {
  70542. x += glyph->getHorizontalSpacing (*t);
  70543. resultGlyphs.add ((int) glyph->character);
  70544. xOffsets.add (x);
  70545. }
  70546. }
  70547. }
  70548. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70549. {
  70550. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70551. if (glyph != 0)
  70552. {
  70553. path = glyph->path;
  70554. return true;
  70555. }
  70556. return false;
  70557. }
  70558. END_JUCE_NAMESPACE
  70559. /*** End of inlined file: juce_Typeface.cpp ***/
  70560. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70561. BEGIN_JUCE_NAMESPACE
  70562. AffineTransform::AffineTransform() throw()
  70563. : mat00 (1.0f),
  70564. mat01 (0),
  70565. mat02 (0),
  70566. mat10 (0),
  70567. mat11 (1.0f),
  70568. mat12 (0)
  70569. {
  70570. }
  70571. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70572. : mat00 (other.mat00),
  70573. mat01 (other.mat01),
  70574. mat02 (other.mat02),
  70575. mat10 (other.mat10),
  70576. mat11 (other.mat11),
  70577. mat12 (other.mat12)
  70578. {
  70579. }
  70580. AffineTransform::AffineTransform (const float mat00_,
  70581. const float mat01_,
  70582. const float mat02_,
  70583. const float mat10_,
  70584. const float mat11_,
  70585. const float mat12_) throw()
  70586. : mat00 (mat00_),
  70587. mat01 (mat01_),
  70588. mat02 (mat02_),
  70589. mat10 (mat10_),
  70590. mat11 (mat11_),
  70591. mat12 (mat12_)
  70592. {
  70593. }
  70594. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70595. {
  70596. mat00 = other.mat00;
  70597. mat01 = other.mat01;
  70598. mat02 = other.mat02;
  70599. mat10 = other.mat10;
  70600. mat11 = other.mat11;
  70601. mat12 = other.mat12;
  70602. return *this;
  70603. }
  70604. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70605. {
  70606. return mat00 == other.mat00
  70607. && mat01 == other.mat01
  70608. && mat02 == other.mat02
  70609. && mat10 == other.mat10
  70610. && mat11 == other.mat11
  70611. && mat12 == other.mat12;
  70612. }
  70613. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70614. {
  70615. return ! operator== (other);
  70616. }
  70617. bool AffineTransform::isIdentity() const throw()
  70618. {
  70619. return (mat01 == 0)
  70620. && (mat02 == 0)
  70621. && (mat10 == 0)
  70622. && (mat12 == 0)
  70623. && (mat00 == 1.0f)
  70624. && (mat11 == 1.0f);
  70625. }
  70626. const AffineTransform AffineTransform::identity;
  70627. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70628. {
  70629. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70630. other.mat00 * mat01 + other.mat01 * mat11,
  70631. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70632. other.mat10 * mat00 + other.mat11 * mat10,
  70633. other.mat10 * mat01 + other.mat11 * mat11,
  70634. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70635. }
  70636. const AffineTransform AffineTransform::followedBy (const float omat00,
  70637. const float omat01,
  70638. const float omat02,
  70639. const float omat10,
  70640. const float omat11,
  70641. const float omat12) const throw()
  70642. {
  70643. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70644. omat00 * mat01 + omat01 * mat11,
  70645. omat00 * mat02 + omat01 * mat12 + omat02,
  70646. omat10 * mat00 + omat11 * mat10,
  70647. omat10 * mat01 + omat11 * mat11,
  70648. omat10 * mat02 + omat11 * mat12 + omat12);
  70649. }
  70650. const AffineTransform AffineTransform::translated (const float dx,
  70651. const float dy) const throw()
  70652. {
  70653. return AffineTransform (mat00, mat01, mat02 + dx,
  70654. mat10, mat11, mat12 + dy);
  70655. }
  70656. const AffineTransform AffineTransform::translation (const float dx,
  70657. const float dy) throw()
  70658. {
  70659. return AffineTransform (1.0f, 0, dx,
  70660. 0, 1.0f, dy);
  70661. }
  70662. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70663. {
  70664. const float cosRad = cosf (rad);
  70665. const float sinRad = sinf (rad);
  70666. return followedBy (cosRad, -sinRad, 0,
  70667. sinRad, cosRad, 0);
  70668. }
  70669. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70670. {
  70671. const float cosRad = cosf (rad);
  70672. const float sinRad = sinf (rad);
  70673. return AffineTransform (cosRad, -sinRad, 0,
  70674. sinRad, cosRad, 0);
  70675. }
  70676. const AffineTransform AffineTransform::rotated (const float angle,
  70677. const float pivotX,
  70678. const float pivotY) const throw()
  70679. {
  70680. return translated (-pivotX, -pivotY)
  70681. .rotated (angle)
  70682. .translated (pivotX, pivotY);
  70683. }
  70684. const AffineTransform AffineTransform::rotation (const float angle,
  70685. const float pivotX,
  70686. const float pivotY) throw()
  70687. {
  70688. return translation (-pivotX, -pivotY)
  70689. .rotated (angle)
  70690. .translated (pivotX, pivotY);
  70691. }
  70692. const AffineTransform AffineTransform::scaled (const float factorX,
  70693. const float factorY) const throw()
  70694. {
  70695. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70696. factorY * mat10, factorY * mat11, factorY * mat12);
  70697. }
  70698. const AffineTransform AffineTransform::scale (const float factorX,
  70699. const float factorY) throw()
  70700. {
  70701. return AffineTransform (factorX, 0, 0,
  70702. 0, factorY, 0);
  70703. }
  70704. const AffineTransform AffineTransform::sheared (const float shearX,
  70705. const float shearY) const throw()
  70706. {
  70707. return followedBy (1.0f, shearX, 0,
  70708. shearY, 1.0f, 0);
  70709. }
  70710. const AffineTransform AffineTransform::inverted() const throw()
  70711. {
  70712. double determinant = (mat00 * mat11 - mat10 * mat01);
  70713. if (determinant != 0.0)
  70714. {
  70715. determinant = 1.0 / determinant;
  70716. const float dst00 = (float) (mat11 * determinant);
  70717. const float dst10 = (float) (-mat10 * determinant);
  70718. const float dst01 = (float) (-mat01 * determinant);
  70719. const float dst11 = (float) (mat00 * determinant);
  70720. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70721. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70722. }
  70723. else
  70724. {
  70725. // singularity..
  70726. return *this;
  70727. }
  70728. }
  70729. bool AffineTransform::isSingularity() const throw()
  70730. {
  70731. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70732. }
  70733. bool AffineTransform::isOnlyTranslation() const throw()
  70734. {
  70735. return (mat01 == 0)
  70736. && (mat10 == 0)
  70737. && (mat00 == 1.0f)
  70738. && (mat11 == 1.0f);
  70739. }
  70740. void AffineTransform::transformPoint (float& x,
  70741. float& y) const throw()
  70742. {
  70743. const float oldX = x;
  70744. x = mat00 * oldX + mat01 * y + mat02;
  70745. y = mat10 * oldX + mat11 * y + mat12;
  70746. }
  70747. void AffineTransform::transformPoint (double& x,
  70748. double& y) const throw()
  70749. {
  70750. const double oldX = x;
  70751. x = mat00 * oldX + mat01 * y + mat02;
  70752. y = mat10 * oldX + mat11 * y + mat12;
  70753. }
  70754. END_JUCE_NAMESPACE
  70755. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70756. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70757. BEGIN_JUCE_NAMESPACE
  70758. BorderSize::BorderSize() throw()
  70759. : top (0),
  70760. left (0),
  70761. bottom (0),
  70762. right (0)
  70763. {
  70764. }
  70765. BorderSize::BorderSize (const BorderSize& other) throw()
  70766. : top (other.top),
  70767. left (other.left),
  70768. bottom (other.bottom),
  70769. right (other.right)
  70770. {
  70771. }
  70772. BorderSize::BorderSize (const int topGap,
  70773. const int leftGap,
  70774. const int bottomGap,
  70775. const int rightGap) throw()
  70776. : top (topGap),
  70777. left (leftGap),
  70778. bottom (bottomGap),
  70779. right (rightGap)
  70780. {
  70781. }
  70782. BorderSize::BorderSize (const int allGaps) throw()
  70783. : top (allGaps),
  70784. left (allGaps),
  70785. bottom (allGaps),
  70786. right (allGaps)
  70787. {
  70788. }
  70789. BorderSize::~BorderSize() throw()
  70790. {
  70791. }
  70792. void BorderSize::setTop (const int newTopGap) throw()
  70793. {
  70794. top = newTopGap;
  70795. }
  70796. void BorderSize::setLeft (const int newLeftGap) throw()
  70797. {
  70798. left = newLeftGap;
  70799. }
  70800. void BorderSize::setBottom (const int newBottomGap) throw()
  70801. {
  70802. bottom = newBottomGap;
  70803. }
  70804. void BorderSize::setRight (const int newRightGap) throw()
  70805. {
  70806. right = newRightGap;
  70807. }
  70808. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70809. {
  70810. return Rectangle<int> (r.getX() + left,
  70811. r.getY() + top,
  70812. r.getWidth() - (left + right),
  70813. r.getHeight() - (top + bottom));
  70814. }
  70815. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70816. {
  70817. r.setBounds (r.getX() + left,
  70818. r.getY() + top,
  70819. r.getWidth() - (left + right),
  70820. r.getHeight() - (top + bottom));
  70821. }
  70822. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70823. {
  70824. return Rectangle<int> (r.getX() - left,
  70825. r.getY() - top,
  70826. r.getWidth() + (left + right),
  70827. r.getHeight() + (top + bottom));
  70828. }
  70829. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70830. {
  70831. r.setBounds (r.getX() - left,
  70832. r.getY() - top,
  70833. r.getWidth() + (left + right),
  70834. r.getHeight() + (top + bottom));
  70835. }
  70836. bool BorderSize::operator== (const BorderSize& other) const throw()
  70837. {
  70838. return top == other.top
  70839. && left == other.left
  70840. && bottom == other.bottom
  70841. && right == other.right;
  70842. }
  70843. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70844. {
  70845. return ! operator== (other);
  70846. }
  70847. END_JUCE_NAMESPACE
  70848. /*** End of inlined file: juce_BorderSize.cpp ***/
  70849. /*** Start of inlined file: juce_Line.cpp ***/
  70850. BEGIN_JUCE_NAMESPACE
  70851. static bool juce_lineIntersection (const float x1, const float y1,
  70852. const float x2, const float y2,
  70853. const float x3, const float y3,
  70854. const float x4, const float y4,
  70855. float& intersectionX,
  70856. float& intersectionY) throw()
  70857. {
  70858. if (x2 != x3 || y2 != y3)
  70859. {
  70860. const float dx1 = x2 - x1;
  70861. const float dy1 = y2 - y1;
  70862. const float dx2 = x4 - x3;
  70863. const float dy2 = y4 - y3;
  70864. const float divisor = dx1 * dy2 - dx2 * dy1;
  70865. if (divisor == 0)
  70866. {
  70867. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70868. {
  70869. if (dy1 == 0 && dy2 != 0)
  70870. {
  70871. const float along = (y1 - y3) / dy2;
  70872. intersectionX = x3 + along * dx2;
  70873. intersectionY = y1;
  70874. return along >= 0 && along <= 1.0f;
  70875. }
  70876. else if (dy2 == 0 && dy1 != 0)
  70877. {
  70878. const float along = (y3 - y1) / dy1;
  70879. intersectionX = x1 + along * dx1;
  70880. intersectionY = y3;
  70881. return along >= 0 && along <= 1.0f;
  70882. }
  70883. else if (dx1 == 0 && dx2 != 0)
  70884. {
  70885. const float along = (x1 - x3) / dx2;
  70886. intersectionX = x1;
  70887. intersectionY = y3 + along * dy2;
  70888. return along >= 0 && along <= 1.0f;
  70889. }
  70890. else if (dx2 == 0 && dx1 != 0)
  70891. {
  70892. const float along = (x3 - x1) / dx1;
  70893. intersectionX = x3;
  70894. intersectionY = y1 + along * dy1;
  70895. return along >= 0 && along <= 1.0f;
  70896. }
  70897. }
  70898. intersectionX = 0.5f * (x2 + x3);
  70899. intersectionY = 0.5f * (y2 + y3);
  70900. return false;
  70901. }
  70902. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70903. intersectionX = x1 + along1 * dx1;
  70904. intersectionY = y1 + along1 * dy1;
  70905. if (along1 < 0 || along1 > 1.0f)
  70906. return false;
  70907. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70908. return along2 >= 0 && along2 <= 1.0f;
  70909. }
  70910. intersectionX = x2;
  70911. intersectionY = y2;
  70912. return true;
  70913. }
  70914. Line::Line() throw()
  70915. : startX (0.0f),
  70916. startY (0.0f),
  70917. endX (0.0f),
  70918. endY (0.0f)
  70919. {
  70920. }
  70921. Line::Line (const Line& other) throw()
  70922. : startX (other.startX),
  70923. startY (other.startY),
  70924. endX (other.endX),
  70925. endY (other.endY)
  70926. {
  70927. }
  70928. Line::Line (const float startX_, const float startY_,
  70929. const float endX_, const float endY_) throw()
  70930. : startX (startX_),
  70931. startY (startY_),
  70932. endX (endX_),
  70933. endY (endY_)
  70934. {
  70935. }
  70936. Line::Line (const Point<float>& start,
  70937. const Point<float>& end) throw()
  70938. : startX (start.getX()),
  70939. startY (start.getY()),
  70940. endX (end.getX()),
  70941. endY (end.getY())
  70942. {
  70943. }
  70944. Line& Line::operator= (const Line& other) throw()
  70945. {
  70946. startX = other.startX;
  70947. startY = other.startY;
  70948. endX = other.endX;
  70949. endY = other.endY;
  70950. return *this;
  70951. }
  70952. Line::~Line() throw()
  70953. {
  70954. }
  70955. const Point<float> Line::getStart() const throw()
  70956. {
  70957. return Point<float> (startX, startY);
  70958. }
  70959. const Point<float> Line::getEnd() const throw()
  70960. {
  70961. return Point<float> (endX, endY);
  70962. }
  70963. void Line::setStart (const float newStartX,
  70964. const float newStartY) throw()
  70965. {
  70966. startX = newStartX;
  70967. startY = newStartY;
  70968. }
  70969. void Line::setStart (const Point<float>& newStart) throw()
  70970. {
  70971. startX = newStart.getX();
  70972. startY = newStart.getY();
  70973. }
  70974. void Line::setEnd (const float newEndX,
  70975. const float newEndY) throw()
  70976. {
  70977. endX = newEndX;
  70978. endY = newEndY;
  70979. }
  70980. void Line::setEnd (const Point<float>& newEnd) throw()
  70981. {
  70982. endX = newEnd.getX();
  70983. endY = newEnd.getY();
  70984. }
  70985. bool Line::operator== (const Line& other) const throw()
  70986. {
  70987. return startX == other.startX
  70988. && startY == other.startY
  70989. && endX == other.endX
  70990. && endY == other.endY;
  70991. }
  70992. bool Line::operator!= (const Line& other) const throw()
  70993. {
  70994. return startX != other.startX
  70995. || startY != other.startY
  70996. || endX != other.endX
  70997. || endY != other.endY;
  70998. }
  70999. void Line::applyTransform (const AffineTransform& transform) throw()
  71000. {
  71001. transform.transformPoint (startX, startY);
  71002. transform.transformPoint (endX, endY);
  71003. }
  71004. float Line::getLength() const throw()
  71005. {
  71006. return (float) juce_hypot (startX - endX,
  71007. startY - endY);
  71008. }
  71009. float Line::getAngle() const throw()
  71010. {
  71011. return atan2f (endX - startX,
  71012. endY - startY);
  71013. }
  71014. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  71015. {
  71016. const float alpha = distanceFromStart / getLength();
  71017. return Point<float> (startX + (endX - startX) * alpha,
  71018. startY + (endY - startY) * alpha);
  71019. }
  71020. const Point<float> Line::getPointAlongLine (const float offsetX,
  71021. const float offsetY) const throw()
  71022. {
  71023. const float dx = endX - startX;
  71024. const float dy = endY - startY;
  71025. const double length = juce_hypot (dx, dy);
  71026. if (length == 0)
  71027. return Point<float> (startX, startY);
  71028. else
  71029. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  71030. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  71031. }
  71032. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  71033. {
  71034. return Point<float> (startX + (endX - startX) * alpha,
  71035. startY + (endY - startY) * alpha);
  71036. }
  71037. float Line::getDistanceFromLine (const float x,
  71038. const float y) const throw()
  71039. {
  71040. const double dx = endX - startX;
  71041. const double dy = endY - startY;
  71042. const double length = dx * dx + dy * dy;
  71043. if (length > 0)
  71044. {
  71045. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  71046. if (prop >= 0.0f && prop < 1.0f)
  71047. {
  71048. return (float) juce_hypot (x - (startX + prop * dx),
  71049. y - (startY + prop * dy));
  71050. }
  71051. }
  71052. return (float) jmin (juce_hypot (x - startX, y - startY),
  71053. juce_hypot (x - endX, y - endY));
  71054. }
  71055. float Line::findNearestPointTo (const float x,
  71056. const float y) const throw()
  71057. {
  71058. const double dx = endX - startX;
  71059. const double dy = endY - startY;
  71060. const double length = dx * dx + dy * dy;
  71061. if (length <= 0.0)
  71062. return 0.0f;
  71063. return jlimit (0.0f, 1.0f,
  71064. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  71065. }
  71066. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  71067. {
  71068. const float length = getLength();
  71069. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  71070. getEnd());
  71071. }
  71072. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  71073. {
  71074. const float length = getLength();
  71075. return Line (getStart(),
  71076. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  71077. }
  71078. bool Line::clipToPath (const Path& path,
  71079. const bool keepSectionOutsidePath) throw()
  71080. {
  71081. const bool startInside = path.contains (startX, startY);
  71082. const bool endInside = path.contains (endX, endY);
  71083. if (startInside == endInside)
  71084. {
  71085. if (keepSectionOutsidePath != startInside)
  71086. {
  71087. // entirely outside the path
  71088. return false;
  71089. }
  71090. else
  71091. {
  71092. // entirely inside the path
  71093. startX = 0.0f;
  71094. startY = 0.0f;
  71095. endX = 0.0f;
  71096. endY = 0.0f;
  71097. return true;
  71098. }
  71099. }
  71100. else
  71101. {
  71102. bool changed = false;
  71103. PathFlatteningIterator iter (path, AffineTransform::identity);
  71104. while (iter.next())
  71105. {
  71106. float ix, iy;
  71107. if (intersects (Line (iter.x1, iter.y1,
  71108. iter.x2, iter.y2),
  71109. ix, iy))
  71110. {
  71111. if ((startInside && keepSectionOutsidePath)
  71112. || (endInside && ! keepSectionOutsidePath))
  71113. {
  71114. setStart (ix, iy);
  71115. }
  71116. else
  71117. {
  71118. setEnd (ix, iy);
  71119. }
  71120. changed = true;
  71121. }
  71122. }
  71123. return changed;
  71124. }
  71125. }
  71126. bool Line::intersects (const Line& line,
  71127. float& intersectionX,
  71128. float& intersectionY) const throw()
  71129. {
  71130. return juce_lineIntersection (startX, startY,
  71131. endX, endY,
  71132. line.startX, line.startY,
  71133. line.endX, line.endY,
  71134. intersectionX,
  71135. intersectionY);
  71136. }
  71137. bool Line::isVertical() const throw()
  71138. {
  71139. return startX == endX;
  71140. }
  71141. bool Line::isHorizontal() const throw()
  71142. {
  71143. return startY == endY;
  71144. }
  71145. bool Line::isPointAbove (const float x, const float y) const throw()
  71146. {
  71147. return startX != endX
  71148. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  71149. }
  71150. END_JUCE_NAMESPACE
  71151. /*** End of inlined file: juce_Line.cpp ***/
  71152. /*** Start of inlined file: juce_Path.cpp ***/
  71153. BEGIN_JUCE_NAMESPACE
  71154. // tests that some co-ords aren't NaNs
  71155. #define CHECK_COORDS_ARE_VALID(x, y) \
  71156. jassert (x == x && y == y);
  71157. const float Path::lineMarker = 100001.0f;
  71158. const float Path::moveMarker = 100002.0f;
  71159. const float Path::quadMarker = 100003.0f;
  71160. const float Path::cubicMarker = 100004.0f;
  71161. const float Path::closeSubPathMarker = 100005.0f;
  71162. static const int defaultGranularity = 32;
  71163. Path::Path() throw()
  71164. : numElements (0),
  71165. pathXMin (0),
  71166. pathXMax (0),
  71167. pathYMin (0),
  71168. pathYMax (0),
  71169. useNonZeroWinding (true)
  71170. {
  71171. }
  71172. Path::~Path() throw()
  71173. {
  71174. }
  71175. Path::Path (const Path& other) throw()
  71176. : numElements (other.numElements),
  71177. pathXMin (other.pathXMin),
  71178. pathXMax (other.pathXMax),
  71179. pathYMin (other.pathYMin),
  71180. pathYMax (other.pathYMax),
  71181. useNonZeroWinding (other.useNonZeroWinding)
  71182. {
  71183. if (numElements > 0)
  71184. {
  71185. data.setAllocatedSize (numElements);
  71186. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71187. }
  71188. }
  71189. Path& Path::operator= (const Path& other) throw()
  71190. {
  71191. if (this != &other)
  71192. {
  71193. data.ensureAllocatedSize (other.numElements);
  71194. numElements = other.numElements;
  71195. pathXMin = other.pathXMin;
  71196. pathXMax = other.pathXMax;
  71197. pathYMin = other.pathYMin;
  71198. pathYMax = other.pathYMax;
  71199. useNonZeroWinding = other.useNonZeroWinding;
  71200. if (numElements > 0)
  71201. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71202. }
  71203. return *this;
  71204. }
  71205. void Path::clear() throw()
  71206. {
  71207. numElements = 0;
  71208. pathXMin = 0;
  71209. pathYMin = 0;
  71210. pathYMax = 0;
  71211. pathXMax = 0;
  71212. }
  71213. void Path::swapWithPath (Path& other)
  71214. {
  71215. data.swapWith (other.data);
  71216. swapVariables <int> (numElements, other.numElements);
  71217. swapVariables <float> (pathXMin, other.pathXMin);
  71218. swapVariables <float> (pathXMax, other.pathXMax);
  71219. swapVariables <float> (pathYMin, other.pathYMin);
  71220. swapVariables <float> (pathYMax, other.pathYMax);
  71221. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  71222. }
  71223. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  71224. {
  71225. useNonZeroWinding = isNonZero;
  71226. }
  71227. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  71228. const bool preserveProportions) throw()
  71229. {
  71230. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  71231. }
  71232. bool Path::isEmpty() const throw()
  71233. {
  71234. int i = 0;
  71235. while (i < numElements)
  71236. {
  71237. const float type = data.elements [i++];
  71238. if (type == moveMarker)
  71239. {
  71240. i += 2;
  71241. }
  71242. else if (type == lineMarker
  71243. || type == quadMarker
  71244. || type == cubicMarker)
  71245. {
  71246. return false;
  71247. }
  71248. }
  71249. return true;
  71250. }
  71251. const Rectangle<float> Path::getBounds () const throw()
  71252. {
  71253. return Rectangle<float> (pathXMin, pathYMin,
  71254. pathXMax - pathXMin,
  71255. pathYMax - pathYMin);
  71256. }
  71257. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  71258. {
  71259. return getBounds().transformed (transform);
  71260. }
  71261. void Path::startNewSubPath (const float x,
  71262. const float y) throw()
  71263. {
  71264. CHECK_COORDS_ARE_VALID (x, y);
  71265. if (numElements == 0)
  71266. {
  71267. pathXMin = pathXMax = x;
  71268. pathYMin = pathYMax = y;
  71269. }
  71270. else
  71271. {
  71272. pathXMin = jmin (pathXMin, x);
  71273. pathXMax = jmax (pathXMax, x);
  71274. pathYMin = jmin (pathYMin, y);
  71275. pathYMax = jmax (pathYMax, y);
  71276. }
  71277. data.ensureAllocatedSize (numElements + 3);
  71278. data.elements [numElements++] = moveMarker;
  71279. data.elements [numElements++] = x;
  71280. data.elements [numElements++] = y;
  71281. }
  71282. void Path::lineTo (const float x, const float y) throw()
  71283. {
  71284. CHECK_COORDS_ARE_VALID (x, y);
  71285. if (numElements == 0)
  71286. startNewSubPath (0, 0);
  71287. data.ensureAllocatedSize (numElements + 3);
  71288. data.elements [numElements++] = lineMarker;
  71289. data.elements [numElements++] = x;
  71290. data.elements [numElements++] = y;
  71291. pathXMin = jmin (pathXMin, x);
  71292. pathXMax = jmax (pathXMax, x);
  71293. pathYMin = jmin (pathYMin, y);
  71294. pathYMax = jmax (pathYMax, y);
  71295. }
  71296. void Path::quadraticTo (const float x1, const float y1,
  71297. const float x2, const float y2) throw()
  71298. {
  71299. CHECK_COORDS_ARE_VALID (x1, y1);
  71300. CHECK_COORDS_ARE_VALID (x2, y2);
  71301. if (numElements == 0)
  71302. startNewSubPath (0, 0);
  71303. data.ensureAllocatedSize (numElements + 5);
  71304. data.elements [numElements++] = quadMarker;
  71305. data.elements [numElements++] = x1;
  71306. data.elements [numElements++] = y1;
  71307. data.elements [numElements++] = x2;
  71308. data.elements [numElements++] = y2;
  71309. pathXMin = jmin (pathXMin, x1, x2);
  71310. pathXMax = jmax (pathXMax, x1, x2);
  71311. pathYMin = jmin (pathYMin, y1, y2);
  71312. pathYMax = jmax (pathYMax, y1, y2);
  71313. }
  71314. void Path::cubicTo (const float x1, const float y1,
  71315. const float x2, const float y2,
  71316. const float x3, const float y3) throw()
  71317. {
  71318. CHECK_COORDS_ARE_VALID (x1, y1);
  71319. CHECK_COORDS_ARE_VALID (x2, y2);
  71320. CHECK_COORDS_ARE_VALID (x3, y3);
  71321. if (numElements == 0)
  71322. startNewSubPath (0, 0);
  71323. data.ensureAllocatedSize (numElements + 7);
  71324. data.elements [numElements++] = cubicMarker;
  71325. data.elements [numElements++] = x1;
  71326. data.elements [numElements++] = y1;
  71327. data.elements [numElements++] = x2;
  71328. data.elements [numElements++] = y2;
  71329. data.elements [numElements++] = x3;
  71330. data.elements [numElements++] = y3;
  71331. pathXMin = jmin (pathXMin, x1, x2, x3);
  71332. pathXMax = jmax (pathXMax, x1, x2, x3);
  71333. pathYMin = jmin (pathYMin, y1, y2, y3);
  71334. pathYMax = jmax (pathYMax, y1, y2, y3);
  71335. }
  71336. void Path::closeSubPath() throw()
  71337. {
  71338. if (numElements > 0
  71339. && data.elements [numElements - 1] != closeSubPathMarker)
  71340. {
  71341. data.ensureAllocatedSize (numElements + 1);
  71342. data.elements [numElements++] = closeSubPathMarker;
  71343. }
  71344. }
  71345. const Point<float> Path::getCurrentPosition() const
  71346. {
  71347. int i = numElements - 1;
  71348. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71349. {
  71350. while (i >= 0)
  71351. {
  71352. if (data.elements[i] == moveMarker)
  71353. {
  71354. i += 2;
  71355. break;
  71356. }
  71357. --i;
  71358. }
  71359. }
  71360. if (i > 0)
  71361. return Point<float> (data.elements [i - 1], data.elements [i]);
  71362. return Point<float>();
  71363. }
  71364. void Path::addRectangle (const float x, const float y,
  71365. const float w, const float h) throw()
  71366. {
  71367. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71368. if (w < 0)
  71369. swapVariables (x1, x2);
  71370. if (h < 0)
  71371. swapVariables (y1, y2);
  71372. data.ensureAllocatedSize (numElements + 13);
  71373. if (numElements == 0)
  71374. {
  71375. pathXMin = x1;
  71376. pathXMax = x2;
  71377. pathYMin = y1;
  71378. pathYMax = y2;
  71379. }
  71380. else
  71381. {
  71382. pathXMin = jmin (pathXMin, x1);
  71383. pathXMax = jmax (pathXMax, x2);
  71384. pathYMin = jmin (pathYMin, y1);
  71385. pathYMax = jmax (pathYMax, y2);
  71386. }
  71387. data.elements [numElements++] = moveMarker;
  71388. data.elements [numElements++] = x1;
  71389. data.elements [numElements++] = y2;
  71390. data.elements [numElements++] = lineMarker;
  71391. data.elements [numElements++] = x1;
  71392. data.elements [numElements++] = y1;
  71393. data.elements [numElements++] = lineMarker;
  71394. data.elements [numElements++] = x2;
  71395. data.elements [numElements++] = y1;
  71396. data.elements [numElements++] = lineMarker;
  71397. data.elements [numElements++] = x2;
  71398. data.elements [numElements++] = y2;
  71399. data.elements [numElements++] = closeSubPathMarker;
  71400. }
  71401. void Path::addRectangle (const Rectangle<int>& rectangle) throw()
  71402. {
  71403. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71404. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71405. }
  71406. void Path::addRoundedRectangle (const float x, const float y,
  71407. const float w, const float h,
  71408. float csx,
  71409. float csy) throw()
  71410. {
  71411. csx = jmin (csx, w * 0.5f);
  71412. csy = jmin (csy, h * 0.5f);
  71413. const float cs45x = csx * 0.45f;
  71414. const float cs45y = csy * 0.45f;
  71415. const float x2 = x + w;
  71416. const float y2 = y + h;
  71417. startNewSubPath (x + csx, y);
  71418. lineTo (x2 - csx, y);
  71419. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71420. lineTo (x2, y2 - csy);
  71421. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71422. lineTo (x + csx, y2);
  71423. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71424. lineTo (x, y + csy);
  71425. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71426. closeSubPath();
  71427. }
  71428. void Path::addRoundedRectangle (const float x, const float y,
  71429. const float w, const float h,
  71430. float cs) throw()
  71431. {
  71432. addRoundedRectangle (x, y, w, h, cs, cs);
  71433. }
  71434. void Path::addTriangle (const float x1, const float y1,
  71435. const float x2, const float y2,
  71436. const float x3, const float y3) throw()
  71437. {
  71438. startNewSubPath (x1, y1);
  71439. lineTo (x2, y2);
  71440. lineTo (x3, y3);
  71441. closeSubPath();
  71442. }
  71443. void Path::addQuadrilateral (const float x1, const float y1,
  71444. const float x2, const float y2,
  71445. const float x3, const float y3,
  71446. const float x4, const float y4) throw()
  71447. {
  71448. startNewSubPath (x1, y1);
  71449. lineTo (x2, y2);
  71450. lineTo (x3, y3);
  71451. lineTo (x4, y4);
  71452. closeSubPath();
  71453. }
  71454. void Path::addEllipse (const float x, const float y,
  71455. const float w, const float h) throw()
  71456. {
  71457. const float hw = w * 0.5f;
  71458. const float hw55 = hw * 0.55f;
  71459. const float hh = h * 0.5f;
  71460. const float hh45 = hh * 0.55f;
  71461. const float cx = x + hw;
  71462. const float cy = y + hh;
  71463. startNewSubPath (cx, cy - hh);
  71464. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71465. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71466. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71467. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71468. closeSubPath();
  71469. }
  71470. void Path::addArc (const float x, const float y,
  71471. const float w, const float h,
  71472. const float fromRadians,
  71473. const float toRadians,
  71474. const bool startAsNewSubPath) throw()
  71475. {
  71476. const float radiusX = w / 2.0f;
  71477. const float radiusY = h / 2.0f;
  71478. addCentredArc (x + radiusX,
  71479. y + radiusY,
  71480. radiusX, radiusY,
  71481. 0.0f,
  71482. fromRadians, toRadians,
  71483. startAsNewSubPath);
  71484. }
  71485. static const float ellipseAngularIncrement = 0.05f;
  71486. void Path::addCentredArc (const float centreX, const float centreY,
  71487. const float radiusX, const float radiusY,
  71488. const float rotationOfEllipse,
  71489. const float fromRadians,
  71490. const float toRadians,
  71491. const bool startAsNewSubPath) throw()
  71492. {
  71493. if (radiusX > 0.0f && radiusY > 0.0f)
  71494. {
  71495. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71496. float angle = fromRadians;
  71497. if (startAsNewSubPath)
  71498. {
  71499. float x = centreX + radiusX * sinf (angle);
  71500. float y = centreY - radiusY * cosf (angle);
  71501. if (rotationOfEllipse != 0)
  71502. rotation.transformPoint (x, y);
  71503. startNewSubPath (x, y);
  71504. }
  71505. if (fromRadians < toRadians)
  71506. {
  71507. if (startAsNewSubPath)
  71508. angle += ellipseAngularIncrement;
  71509. while (angle < toRadians)
  71510. {
  71511. float x = centreX + radiusX * sinf (angle);
  71512. float y = centreY - radiusY * cosf (angle);
  71513. if (rotationOfEllipse != 0)
  71514. rotation.transformPoint (x, y);
  71515. lineTo (x, y);
  71516. angle += ellipseAngularIncrement;
  71517. }
  71518. }
  71519. else
  71520. {
  71521. if (startAsNewSubPath)
  71522. angle -= ellipseAngularIncrement;
  71523. while (angle > toRadians)
  71524. {
  71525. float x = centreX + radiusX * sinf (angle);
  71526. float y = centreY - radiusY * cosf (angle);
  71527. if (rotationOfEllipse != 0)
  71528. rotation.transformPoint (x, y);
  71529. lineTo (x, y);
  71530. angle -= ellipseAngularIncrement;
  71531. }
  71532. }
  71533. float x = centreX + radiusX * sinf (toRadians);
  71534. float y = centreY - radiusY * cosf (toRadians);
  71535. if (rotationOfEllipse != 0)
  71536. rotation.transformPoint (x, y);
  71537. lineTo (x, y);
  71538. }
  71539. }
  71540. void Path::addPieSegment (const float x, const float y,
  71541. const float width, const float height,
  71542. const float fromRadians,
  71543. const float toRadians,
  71544. const float innerCircleProportionalSize)
  71545. {
  71546. float hw = width * 0.5f;
  71547. float hh = height * 0.5f;
  71548. const float centreX = x + hw;
  71549. const float centreY = y + hh;
  71550. startNewSubPath (centreX + hw * sinf (fromRadians),
  71551. centreY - hh * cosf (fromRadians));
  71552. addArc (x, y, width, height, fromRadians, toRadians);
  71553. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71554. {
  71555. closeSubPath();
  71556. if (innerCircleProportionalSize > 0)
  71557. {
  71558. hw *= innerCircleProportionalSize;
  71559. hh *= innerCircleProportionalSize;
  71560. startNewSubPath (centreX + hw * sinf (toRadians),
  71561. centreY - hh * cosf (toRadians));
  71562. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71563. toRadians, fromRadians);
  71564. }
  71565. }
  71566. else
  71567. {
  71568. if (innerCircleProportionalSize > 0)
  71569. {
  71570. hw *= innerCircleProportionalSize;
  71571. hh *= innerCircleProportionalSize;
  71572. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71573. toRadians, fromRadians);
  71574. }
  71575. else
  71576. {
  71577. lineTo (centreX, centreY);
  71578. }
  71579. }
  71580. closeSubPath();
  71581. }
  71582. static void perpendicularOffset (const float x1, const float y1,
  71583. const float x2, const float y2,
  71584. const float offsetX, const float offsetY,
  71585. float& resultX, float& resultY) throw()
  71586. {
  71587. const float dx = x2 - x1;
  71588. const float dy = y2 - y1;
  71589. const float len = juce_hypotf (dx, dy);
  71590. if (len == 0)
  71591. {
  71592. resultX = x1;
  71593. resultY = y1;
  71594. }
  71595. else
  71596. {
  71597. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71598. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71599. }
  71600. }
  71601. void Path::addLineSegment (const float startX, const float startY,
  71602. const float endX, const float endY,
  71603. float lineThickness) throw()
  71604. {
  71605. lineThickness *= 0.5f;
  71606. float x, y;
  71607. perpendicularOffset (startX, startY, endX, endY,
  71608. 0, lineThickness, x, y);
  71609. startNewSubPath (x, y);
  71610. perpendicularOffset (startX, startY, endX, endY,
  71611. 0, -lineThickness, x, y);
  71612. lineTo (x, y);
  71613. perpendicularOffset (endX, endY, startX, startY,
  71614. 0, lineThickness, x, y);
  71615. lineTo (x, y);
  71616. perpendicularOffset (endX, endY, startX, startY,
  71617. 0, -lineThickness, x, y);
  71618. lineTo (x, y);
  71619. closeSubPath();
  71620. }
  71621. void Path::addArrow (const float startX, const float startY,
  71622. const float endX, const float endY,
  71623. float lineThickness,
  71624. float arrowheadWidth,
  71625. float arrowheadLength) throw()
  71626. {
  71627. lineThickness *= 0.5f;
  71628. arrowheadWidth *= 0.5f;
  71629. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71630. startY - endY));
  71631. float x, y;
  71632. perpendicularOffset (startX, startY, endX, endY,
  71633. 0, lineThickness, x, y);
  71634. startNewSubPath (x, y);
  71635. perpendicularOffset (startX, startY, endX, endY,
  71636. 0, -lineThickness, x, y);
  71637. lineTo (x, y);
  71638. perpendicularOffset (endX, endY, startX, startY,
  71639. arrowheadLength, lineThickness, x, y);
  71640. lineTo (x, y);
  71641. perpendicularOffset (endX, endY, startX, startY,
  71642. arrowheadLength, arrowheadWidth, x, y);
  71643. lineTo (x, y);
  71644. perpendicularOffset (endX, endY, startX, startY,
  71645. 0, 0, x, y);
  71646. lineTo (x, y);
  71647. perpendicularOffset (endX, endY, startX, startY,
  71648. arrowheadLength, -arrowheadWidth, x, y);
  71649. lineTo (x, y);
  71650. perpendicularOffset (endX, endY, startX, startY,
  71651. arrowheadLength, -lineThickness, x, y);
  71652. lineTo (x, y);
  71653. closeSubPath();
  71654. }
  71655. void Path::addStar (const float centreX,
  71656. const float centreY,
  71657. const int numberOfPoints,
  71658. const float innerRadius,
  71659. const float outerRadius,
  71660. const float startAngle)
  71661. {
  71662. jassert (numberOfPoints > 1); // this would be silly.
  71663. if (numberOfPoints > 1)
  71664. {
  71665. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71666. for (int i = 0; i < numberOfPoints; ++i)
  71667. {
  71668. float angle = startAngle + i * angleBetweenPoints;
  71669. const float x = centreX + outerRadius * sinf (angle);
  71670. const float y = centreY - outerRadius * cosf (angle);
  71671. if (i == 0)
  71672. startNewSubPath (x, y);
  71673. else
  71674. lineTo (x, y);
  71675. angle += angleBetweenPoints * 0.5f;
  71676. lineTo (centreX + innerRadius * sinf (angle),
  71677. centreY - innerRadius * cosf (angle));
  71678. }
  71679. closeSubPath();
  71680. }
  71681. }
  71682. void Path::addBubble (float x, float y,
  71683. float w, float h,
  71684. float cs,
  71685. float tipX,
  71686. float tipY,
  71687. int whichSide,
  71688. float arrowPos,
  71689. float arrowWidth)
  71690. {
  71691. if (w > 1.0f && h > 1.0f)
  71692. {
  71693. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71694. const float cs2 = 2.0f * cs;
  71695. startNewSubPath (x + cs, y);
  71696. if (whichSide == 0)
  71697. {
  71698. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71699. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71700. lineTo (arrowX1, y);
  71701. lineTo (tipX, tipY);
  71702. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71703. }
  71704. lineTo (x + w - cs, y);
  71705. if (cs > 0.0f)
  71706. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71707. if (whichSide == 3)
  71708. {
  71709. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71710. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71711. lineTo (x + w, arrowY1);
  71712. lineTo (tipX, tipY);
  71713. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71714. }
  71715. lineTo (x + w, y + h - cs);
  71716. if (cs > 0.0f)
  71717. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71718. if (whichSide == 2)
  71719. {
  71720. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71721. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71722. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71723. lineTo (tipX, tipY);
  71724. lineTo (arrowX1, y + h);
  71725. }
  71726. lineTo (x + cs, y + h);
  71727. if (cs > 0.0f)
  71728. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71729. if (whichSide == 1)
  71730. {
  71731. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71732. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71733. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71734. lineTo (tipX, tipY);
  71735. lineTo (x, arrowY1);
  71736. }
  71737. lineTo (x, y + cs);
  71738. if (cs > 0.0f)
  71739. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71740. closeSubPath();
  71741. }
  71742. }
  71743. void Path::addPath (const Path& other) throw()
  71744. {
  71745. int i = 0;
  71746. while (i < other.numElements)
  71747. {
  71748. const float type = other.data.elements [i++];
  71749. if (type == moveMarker)
  71750. {
  71751. startNewSubPath (other.data.elements [i],
  71752. other.data.elements [i + 1]);
  71753. i += 2;
  71754. }
  71755. else if (type == lineMarker)
  71756. {
  71757. lineTo (other.data.elements [i],
  71758. other.data.elements [i + 1]);
  71759. i += 2;
  71760. }
  71761. else if (type == quadMarker)
  71762. {
  71763. quadraticTo (other.data.elements [i],
  71764. other.data.elements [i + 1],
  71765. other.data.elements [i + 2],
  71766. other.data.elements [i + 3]);
  71767. i += 4;
  71768. }
  71769. else if (type == cubicMarker)
  71770. {
  71771. cubicTo (other.data.elements [i],
  71772. other.data.elements [i + 1],
  71773. other.data.elements [i + 2],
  71774. other.data.elements [i + 3],
  71775. other.data.elements [i + 4],
  71776. other.data.elements [i + 5]);
  71777. i += 6;
  71778. }
  71779. else if (type == closeSubPathMarker)
  71780. {
  71781. closeSubPath();
  71782. }
  71783. else
  71784. {
  71785. // something's gone wrong with the element list!
  71786. jassertfalse
  71787. }
  71788. }
  71789. }
  71790. void Path::addPath (const Path& other,
  71791. const AffineTransform& transformToApply) throw()
  71792. {
  71793. int i = 0;
  71794. while (i < other.numElements)
  71795. {
  71796. const float type = other.data.elements [i++];
  71797. if (type == closeSubPathMarker)
  71798. {
  71799. closeSubPath();
  71800. }
  71801. else
  71802. {
  71803. float x = other.data.elements [i++];
  71804. float y = other.data.elements [i++];
  71805. transformToApply.transformPoint (x, y);
  71806. if (type == moveMarker)
  71807. {
  71808. startNewSubPath (x, y);
  71809. }
  71810. else if (type == lineMarker)
  71811. {
  71812. lineTo (x, y);
  71813. }
  71814. else if (type == quadMarker)
  71815. {
  71816. float x2 = other.data.elements [i++];
  71817. float y2 = other.data.elements [i++];
  71818. transformToApply.transformPoint (x2, y2);
  71819. quadraticTo (x, y, x2, y2);
  71820. }
  71821. else if (type == cubicMarker)
  71822. {
  71823. float x2 = other.data.elements [i++];
  71824. float y2 = other.data.elements [i++];
  71825. float x3 = other.data.elements [i++];
  71826. float y3 = other.data.elements [i++];
  71827. transformToApply.transformPoint (x2, y2);
  71828. transformToApply.transformPoint (x3, y3);
  71829. cubicTo (x, y, x2, y2, x3, y3);
  71830. }
  71831. else
  71832. {
  71833. // something's gone wrong with the element list!
  71834. jassertfalse
  71835. }
  71836. }
  71837. }
  71838. }
  71839. void Path::applyTransform (const AffineTransform& transform) throw()
  71840. {
  71841. int i = 0;
  71842. pathYMin = pathXMin = 0;
  71843. pathYMax = pathXMax = 0;
  71844. bool setMaxMin = false;
  71845. while (i < numElements)
  71846. {
  71847. const float type = data.elements [i++];
  71848. if (type == moveMarker)
  71849. {
  71850. transform.transformPoint (data.elements [i],
  71851. data.elements [i + 1]);
  71852. if (setMaxMin)
  71853. {
  71854. pathXMin = jmin (pathXMin, data.elements [i]);
  71855. pathXMax = jmax (pathXMax, data.elements [i]);
  71856. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71857. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71858. }
  71859. else
  71860. {
  71861. pathXMin = pathXMax = data.elements [i];
  71862. pathYMin = pathYMax = data.elements [i + 1];
  71863. setMaxMin = true;
  71864. }
  71865. i += 2;
  71866. }
  71867. else if (type == lineMarker)
  71868. {
  71869. transform.transformPoint (data.elements [i],
  71870. data.elements [i + 1]);
  71871. pathXMin = jmin (pathXMin, data.elements [i]);
  71872. pathXMax = jmax (pathXMax, data.elements [i]);
  71873. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71874. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71875. i += 2;
  71876. }
  71877. else if (type == quadMarker)
  71878. {
  71879. transform.transformPoint (data.elements [i],
  71880. data.elements [i + 1]);
  71881. transform.transformPoint (data.elements [i + 2],
  71882. data.elements [i + 3]);
  71883. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71884. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71885. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71886. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71887. i += 4;
  71888. }
  71889. else if (type == cubicMarker)
  71890. {
  71891. transform.transformPoint (data.elements [i],
  71892. data.elements [i + 1]);
  71893. transform.transformPoint (data.elements [i + 2],
  71894. data.elements [i + 3]);
  71895. transform.transformPoint (data.elements [i + 4],
  71896. data.elements [i + 5]);
  71897. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71898. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71899. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71900. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71901. i += 6;
  71902. }
  71903. }
  71904. }
  71905. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71906. const float w, const float h,
  71907. const bool preserveProportions,
  71908. const Justification& justification) const throw()
  71909. {
  71910. Rectangle<float> bounds (getBounds());
  71911. if (preserveProportions)
  71912. {
  71913. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71914. return AffineTransform::identity;
  71915. float newW, newH;
  71916. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71917. if (srcRatio > h / w)
  71918. {
  71919. newW = h / srcRatio;
  71920. newH = h;
  71921. }
  71922. else
  71923. {
  71924. newW = w;
  71925. newH = w * srcRatio;
  71926. }
  71927. float newXCentre = x;
  71928. float newYCentre = y;
  71929. if (justification.testFlags (Justification::left))
  71930. newXCentre += newW * 0.5f;
  71931. else if (justification.testFlags (Justification::right))
  71932. newXCentre += w - newW * 0.5f;
  71933. else
  71934. newXCentre += w * 0.5f;
  71935. if (justification.testFlags (Justification::top))
  71936. newYCentre += newH * 0.5f;
  71937. else if (justification.testFlags (Justification::bottom))
  71938. newYCentre += h - newH * 0.5f;
  71939. else
  71940. newYCentre += h * 0.5f;
  71941. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71942. bounds.getHeight() * -0.5f - bounds.getY())
  71943. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71944. .translated (newXCentre, newYCentre);
  71945. }
  71946. else
  71947. {
  71948. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71949. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71950. .translated (x, y);
  71951. }
  71952. }
  71953. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  71954. {
  71955. if (x <= pathXMin || x >= pathXMax
  71956. || y <= pathYMin || y >= pathYMax)
  71957. return false;
  71958. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71959. int positiveCrossings = 0;
  71960. int negativeCrossings = 0;
  71961. while (i.next())
  71962. {
  71963. if ((i.y1 <= y && i.y2 > y)
  71964. || (i.y2 <= y && i.y1 > y))
  71965. {
  71966. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71967. if (intersectX <= x)
  71968. {
  71969. if (i.y1 < i.y2)
  71970. ++positiveCrossings;
  71971. else
  71972. ++negativeCrossings;
  71973. }
  71974. }
  71975. }
  71976. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71977. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71978. }
  71979. bool Path::intersectsLine (const float x1, const float y1,
  71980. const float x2, const float y2,
  71981. const float tolerence) throw()
  71982. {
  71983. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71984. const Line line1 (x1, y1, x2, y2);
  71985. while (i.next())
  71986. {
  71987. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71988. float ix, iy;
  71989. if (line1.intersects (line2, ix, iy))
  71990. return true;
  71991. }
  71992. return false;
  71993. }
  71994. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  71995. {
  71996. if (cornerRadius <= 0.01f)
  71997. return *this;
  71998. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71999. int n = 0;
  72000. bool lastWasLine = false, firstWasLine = false;
  72001. Path p;
  72002. while (n < numElements)
  72003. {
  72004. const float type = data.elements [n++];
  72005. if (type == moveMarker)
  72006. {
  72007. indexOfPathStart = p.numElements;
  72008. indexOfPathStartThis = n - 1;
  72009. const float x = data.elements [n++];
  72010. const float y = data.elements [n++];
  72011. p.startNewSubPath (x, y);
  72012. lastWasLine = false;
  72013. firstWasLine = (data.elements [n] == lineMarker);
  72014. }
  72015. else if (type == lineMarker || type == closeSubPathMarker)
  72016. {
  72017. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  72018. if (type == lineMarker)
  72019. {
  72020. endX = data.elements [n++];
  72021. endY = data.elements [n++];
  72022. if (n > 8)
  72023. {
  72024. startX = data.elements [n - 8];
  72025. startY = data.elements [n - 7];
  72026. joinX = data.elements [n - 5];
  72027. joinY = data.elements [n - 4];
  72028. }
  72029. }
  72030. else
  72031. {
  72032. endX = data.elements [indexOfPathStartThis + 1];
  72033. endY = data.elements [indexOfPathStartThis + 2];
  72034. if (n > 6)
  72035. {
  72036. startX = data.elements [n - 6];
  72037. startY = data.elements [n - 5];
  72038. joinX = data.elements [n - 3];
  72039. joinY = data.elements [n - 2];
  72040. }
  72041. }
  72042. if (lastWasLine)
  72043. {
  72044. const double len1 = juce_hypot (startX - joinX,
  72045. startY - joinY);
  72046. if (len1 > 0)
  72047. {
  72048. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72049. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72050. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72051. }
  72052. const double len2 = juce_hypot (endX - joinX,
  72053. endY - joinY);
  72054. if (len2 > 0)
  72055. {
  72056. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72057. p.quadraticTo (joinX, joinY,
  72058. (float) (joinX + (endX - joinX) * propNeeded),
  72059. (float) (joinY + (endY - joinY) * propNeeded));
  72060. }
  72061. p.lineTo (endX, endY);
  72062. }
  72063. else if (type == lineMarker)
  72064. {
  72065. p.lineTo (endX, endY);
  72066. lastWasLine = true;
  72067. }
  72068. if (type == closeSubPathMarker)
  72069. {
  72070. if (firstWasLine)
  72071. {
  72072. startX = data.elements [n - 3];
  72073. startY = data.elements [n - 2];
  72074. joinX = endX;
  72075. joinY = endY;
  72076. endX = data.elements [indexOfPathStartThis + 4];
  72077. endY = data.elements [indexOfPathStartThis + 5];
  72078. const double len1 = juce_hypot (startX - joinX,
  72079. startY - joinY);
  72080. if (len1 > 0)
  72081. {
  72082. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72083. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72084. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72085. }
  72086. const double len2 = juce_hypot (endX - joinX,
  72087. endY - joinY);
  72088. if (len2 > 0)
  72089. {
  72090. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72091. endX = (float) (joinX + (endX - joinX) * propNeeded);
  72092. endY = (float) (joinY + (endY - joinY) * propNeeded);
  72093. p.quadraticTo (joinX, joinY, endX, endY);
  72094. p.data.elements [indexOfPathStart + 1] = endX;
  72095. p.data.elements [indexOfPathStart + 2] = endY;
  72096. }
  72097. }
  72098. p.closeSubPath();
  72099. }
  72100. }
  72101. else if (type == quadMarker)
  72102. {
  72103. lastWasLine = false;
  72104. const float x1 = data.elements [n++];
  72105. const float y1 = data.elements [n++];
  72106. const float x2 = data.elements [n++];
  72107. const float y2 = data.elements [n++];
  72108. p.quadraticTo (x1, y1, x2, y2);
  72109. }
  72110. else if (type == cubicMarker)
  72111. {
  72112. lastWasLine = false;
  72113. const float x1 = data.elements [n++];
  72114. const float y1 = data.elements [n++];
  72115. const float x2 = data.elements [n++];
  72116. const float y2 = data.elements [n++];
  72117. const float x3 = data.elements [n++];
  72118. const float y3 = data.elements [n++];
  72119. p.cubicTo (x1, y1, x2, y2, x3, y3);
  72120. }
  72121. }
  72122. return p;
  72123. }
  72124. void Path::loadPathFromStream (InputStream& source)
  72125. {
  72126. while (! source.isExhausted())
  72127. {
  72128. switch (source.readByte())
  72129. {
  72130. case 'm':
  72131. {
  72132. const float x = source.readFloat();
  72133. const float y = source.readFloat();
  72134. startNewSubPath (x, y);
  72135. break;
  72136. }
  72137. case 'l':
  72138. {
  72139. const float x = source.readFloat();
  72140. const float y = source.readFloat();
  72141. lineTo (x, y);
  72142. break;
  72143. }
  72144. case 'q':
  72145. {
  72146. const float x1 = source.readFloat();
  72147. const float y1 = source.readFloat();
  72148. const float x2 = source.readFloat();
  72149. const float y2 = source.readFloat();
  72150. quadraticTo (x1, y1, x2, y2);
  72151. break;
  72152. }
  72153. case 'b':
  72154. {
  72155. const float x1 = source.readFloat();
  72156. const float y1 = source.readFloat();
  72157. const float x2 = source.readFloat();
  72158. const float y2 = source.readFloat();
  72159. const float x3 = source.readFloat();
  72160. const float y3 = source.readFloat();
  72161. cubicTo (x1, y1, x2, y2, x3, y3);
  72162. break;
  72163. }
  72164. case 'c':
  72165. closeSubPath();
  72166. break;
  72167. case 'n':
  72168. useNonZeroWinding = true;
  72169. break;
  72170. case 'z':
  72171. useNonZeroWinding = false;
  72172. break;
  72173. case 'e':
  72174. return; // end of path marker
  72175. default:
  72176. jassertfalse // illegal char in the stream
  72177. break;
  72178. }
  72179. }
  72180. }
  72181. void Path::loadPathFromData (const unsigned char* const data,
  72182. const int numberOfBytes) throw()
  72183. {
  72184. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  72185. loadPathFromStream (in);
  72186. }
  72187. void Path::writePathToStream (OutputStream& dest) const
  72188. {
  72189. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  72190. int i = 0;
  72191. while (i < numElements)
  72192. {
  72193. const float type = data.elements [i++];
  72194. if (type == moveMarker)
  72195. {
  72196. dest.writeByte ('m');
  72197. dest.writeFloat (data.elements [i++]);
  72198. dest.writeFloat (data.elements [i++]);
  72199. }
  72200. else if (type == lineMarker)
  72201. {
  72202. dest.writeByte ('l');
  72203. dest.writeFloat (data.elements [i++]);
  72204. dest.writeFloat (data.elements [i++]);
  72205. }
  72206. else if (type == quadMarker)
  72207. {
  72208. dest.writeByte ('q');
  72209. dest.writeFloat (data.elements [i++]);
  72210. dest.writeFloat (data.elements [i++]);
  72211. dest.writeFloat (data.elements [i++]);
  72212. dest.writeFloat (data.elements [i++]);
  72213. }
  72214. else if (type == cubicMarker)
  72215. {
  72216. dest.writeByte ('b');
  72217. dest.writeFloat (data.elements [i++]);
  72218. dest.writeFloat (data.elements [i++]);
  72219. dest.writeFloat (data.elements [i++]);
  72220. dest.writeFloat (data.elements [i++]);
  72221. dest.writeFloat (data.elements [i++]);
  72222. dest.writeFloat (data.elements [i++]);
  72223. }
  72224. else if (type == closeSubPathMarker)
  72225. {
  72226. dest.writeByte ('c');
  72227. }
  72228. }
  72229. dest.writeByte ('e'); // marks the end-of-path
  72230. }
  72231. const String Path::toString() const
  72232. {
  72233. MemoryOutputStream s (2048, 2048);
  72234. if (! useNonZeroWinding)
  72235. s << "a ";
  72236. int i = 0;
  72237. float lastMarker = 0.0f;
  72238. while (i < numElements)
  72239. {
  72240. const float marker = data.elements [i++];
  72241. char markerChar = 0;
  72242. int numCoords = 0;
  72243. if (marker == moveMarker)
  72244. {
  72245. markerChar = 'm';
  72246. numCoords = 2;
  72247. }
  72248. else if (marker == lineMarker)
  72249. {
  72250. markerChar = 'l';
  72251. numCoords = 2;
  72252. }
  72253. else if (marker == quadMarker)
  72254. {
  72255. markerChar = 'q';
  72256. numCoords = 4;
  72257. }
  72258. else if (marker == cubicMarker)
  72259. {
  72260. markerChar = 'c';
  72261. numCoords = 6;
  72262. }
  72263. else
  72264. {
  72265. jassert (marker == closeSubPathMarker);
  72266. markerChar = 'z';
  72267. }
  72268. if (marker != lastMarker)
  72269. {
  72270. s << markerChar << ' ';
  72271. lastMarker = marker;
  72272. }
  72273. while (--numCoords >= 0 && i < numElements)
  72274. {
  72275. String n (data.elements [i++], 3);
  72276. if (n.endsWithChar (T('0')))
  72277. {
  72278. do
  72279. {
  72280. n = n.dropLastCharacters (1);
  72281. } while (n.endsWithChar (T('0')));
  72282. if (n.endsWithChar (T('.')))
  72283. n = n.dropLastCharacters (1);
  72284. }
  72285. s << n << ' ';
  72286. }
  72287. }
  72288. const char* const result = (const char*) s.getData();
  72289. size_t len = s.getDataSize();
  72290. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  72291. --len;
  72292. return String (result, len);
  72293. }
  72294. static const String nextToken (const tchar*& t)
  72295. {
  72296. while (CharacterFunctions::isWhitespace (*t))
  72297. ++t;
  72298. const tchar* const start = t;
  72299. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  72300. ++t;
  72301. const int length = (int) (t - start);
  72302. while (CharacterFunctions::isWhitespace (*t))
  72303. ++t;
  72304. return String (start, length);
  72305. }
  72306. void Path::restoreFromString (const String& stringVersion)
  72307. {
  72308. clear();
  72309. setUsingNonZeroWinding (true);
  72310. const tchar* t = stringVersion;
  72311. tchar marker = T('m');
  72312. int numValues = 2;
  72313. float values [6];
  72314. while (*t != 0)
  72315. {
  72316. const String token (nextToken (t));
  72317. const tchar firstChar = token[0];
  72318. int startNum = 0;
  72319. if (firstChar == T('m') || firstChar == T('l'))
  72320. {
  72321. marker = firstChar;
  72322. numValues = 2;
  72323. }
  72324. else if (firstChar == T('q'))
  72325. {
  72326. marker = firstChar;
  72327. numValues = 4;
  72328. }
  72329. else if (firstChar == T('c'))
  72330. {
  72331. marker = firstChar;
  72332. numValues = 6;
  72333. }
  72334. else if (firstChar == T('z'))
  72335. {
  72336. marker = firstChar;
  72337. numValues = 0;
  72338. }
  72339. else if (firstChar == T('a'))
  72340. {
  72341. setUsingNonZeroWinding (false);
  72342. continue;
  72343. }
  72344. else
  72345. {
  72346. ++startNum;
  72347. values [0] = token.getFloatValue();
  72348. }
  72349. for (int i = startNum; i < numValues; ++i)
  72350. values [i] = nextToken (t).getFloatValue();
  72351. switch (marker)
  72352. {
  72353. case T('m'):
  72354. startNewSubPath (values[0], values[1]);
  72355. break;
  72356. case T('l'):
  72357. lineTo (values[0], values[1]);
  72358. break;
  72359. case T('q'):
  72360. quadraticTo (values[0], values[1],
  72361. values[2], values[3]);
  72362. break;
  72363. case T('c'):
  72364. cubicTo (values[0], values[1],
  72365. values[2], values[3],
  72366. values[4], values[5]);
  72367. break;
  72368. case T('z'):
  72369. closeSubPath();
  72370. break;
  72371. default:
  72372. jassertfalse // illegal string format?
  72373. break;
  72374. }
  72375. }
  72376. }
  72377. Path::Iterator::Iterator (const Path& path_)
  72378. : path (path_),
  72379. index (0)
  72380. {
  72381. }
  72382. Path::Iterator::~Iterator()
  72383. {
  72384. }
  72385. bool Path::Iterator::next()
  72386. {
  72387. const float* const elements = path.data.elements;
  72388. if (index < path.numElements)
  72389. {
  72390. const float type = elements [index++];
  72391. if (type == moveMarker)
  72392. {
  72393. elementType = startNewSubPath;
  72394. x1 = elements [index++];
  72395. y1 = elements [index++];
  72396. }
  72397. else if (type == lineMarker)
  72398. {
  72399. elementType = lineTo;
  72400. x1 = elements [index++];
  72401. y1 = elements [index++];
  72402. }
  72403. else if (type == quadMarker)
  72404. {
  72405. elementType = quadraticTo;
  72406. x1 = elements [index++];
  72407. y1 = elements [index++];
  72408. x2 = elements [index++];
  72409. y2 = elements [index++];
  72410. }
  72411. else if (type == cubicMarker)
  72412. {
  72413. elementType = cubicTo;
  72414. x1 = elements [index++];
  72415. y1 = elements [index++];
  72416. x2 = elements [index++];
  72417. y2 = elements [index++];
  72418. x3 = elements [index++];
  72419. y3 = elements [index++];
  72420. }
  72421. else if (type == closeSubPathMarker)
  72422. {
  72423. elementType = closePath;
  72424. }
  72425. return true;
  72426. }
  72427. return false;
  72428. }
  72429. END_JUCE_NAMESPACE
  72430. /*** End of inlined file: juce_Path.cpp ***/
  72431. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72432. BEGIN_JUCE_NAMESPACE
  72433. #if JUCE_MSVC
  72434. #pragma optimize ("t", on)
  72435. #endif
  72436. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72437. const AffineTransform& transform_,
  72438. float tolerence_) throw()
  72439. : x2 (0),
  72440. y2 (0),
  72441. closesSubPath (false),
  72442. subPathIndex (-1),
  72443. path (path_),
  72444. transform (transform_),
  72445. points (path_.data.elements),
  72446. tolerence (tolerence_ * tolerence_),
  72447. subPathCloseX (0),
  72448. subPathCloseY (0),
  72449. stackBase (32),
  72450. index (0),
  72451. stackSize (32)
  72452. {
  72453. isIdentityTransform = transform.isIdentity();
  72454. stackPos = stackBase;
  72455. }
  72456. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72457. {
  72458. }
  72459. bool PathFlatteningIterator::next() throw()
  72460. {
  72461. x1 = x2;
  72462. y1 = y2;
  72463. float x3 = 0;
  72464. float y3 = 0;
  72465. float x4 = 0;
  72466. float y4 = 0;
  72467. float type;
  72468. for (;;)
  72469. {
  72470. if (stackPos == stackBase)
  72471. {
  72472. if (index >= path.numElements)
  72473. {
  72474. return false;
  72475. }
  72476. else
  72477. {
  72478. type = points [index++];
  72479. if (type != Path::closeSubPathMarker)
  72480. {
  72481. x2 = points [index++];
  72482. y2 = points [index++];
  72483. if (! isIdentityTransform)
  72484. transform.transformPoint (x2, y2);
  72485. if (type == Path::quadMarker)
  72486. {
  72487. x3 = points [index++];
  72488. y3 = points [index++];
  72489. if (! isIdentityTransform)
  72490. transform.transformPoint (x3, y3);
  72491. }
  72492. else if (type == Path::cubicMarker)
  72493. {
  72494. x3 = points [index++];
  72495. y3 = points [index++];
  72496. x4 = points [index++];
  72497. y4 = points [index++];
  72498. if (! isIdentityTransform)
  72499. {
  72500. transform.transformPoint (x3, y3);
  72501. transform.transformPoint (x4, y4);
  72502. }
  72503. }
  72504. }
  72505. }
  72506. }
  72507. else
  72508. {
  72509. type = *--stackPos;
  72510. if (type != Path::closeSubPathMarker)
  72511. {
  72512. x2 = *--stackPos;
  72513. y2 = *--stackPos;
  72514. if (type == Path::quadMarker)
  72515. {
  72516. x3 = *--stackPos;
  72517. y3 = *--stackPos;
  72518. }
  72519. else if (type == Path::cubicMarker)
  72520. {
  72521. x3 = *--stackPos;
  72522. y3 = *--stackPos;
  72523. x4 = *--stackPos;
  72524. y4 = *--stackPos;
  72525. }
  72526. }
  72527. }
  72528. if (type == Path::lineMarker)
  72529. {
  72530. ++subPathIndex;
  72531. closesSubPath = (stackPos == stackBase)
  72532. && (index < path.numElements)
  72533. && (points [index] == Path::closeSubPathMarker)
  72534. && x2 == subPathCloseX
  72535. && y2 == subPathCloseY;
  72536. return true;
  72537. }
  72538. else if (type == Path::quadMarker)
  72539. {
  72540. const int offset = (int) (stackPos - stackBase);
  72541. if (offset >= stackSize - 10)
  72542. {
  72543. stackSize <<= 1;
  72544. stackBase.realloc (stackSize);
  72545. stackPos = stackBase + offset;
  72546. }
  72547. const float dx1 = x1 - x2;
  72548. const float dy1 = y1 - y2;
  72549. const float dx2 = x2 - x3;
  72550. const float dy2 = y2 - y3;
  72551. const float m1x = (x1 + x2) * 0.5f;
  72552. const float m1y = (y1 + y2) * 0.5f;
  72553. const float m2x = (x2 + x3) * 0.5f;
  72554. const float m2y = (y2 + y3) * 0.5f;
  72555. const float m3x = (m1x + m2x) * 0.5f;
  72556. const float m3y = (m1y + m2y) * 0.5f;
  72557. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72558. {
  72559. *stackPos++ = y3;
  72560. *stackPos++ = x3;
  72561. *stackPos++ = m2y;
  72562. *stackPos++ = m2x;
  72563. *stackPos++ = Path::quadMarker;
  72564. *stackPos++ = m3y;
  72565. *stackPos++ = m3x;
  72566. *stackPos++ = m1y;
  72567. *stackPos++ = m1x;
  72568. *stackPos++ = Path::quadMarker;
  72569. }
  72570. else
  72571. {
  72572. *stackPos++ = y3;
  72573. *stackPos++ = x3;
  72574. *stackPos++ = Path::lineMarker;
  72575. *stackPos++ = m3y;
  72576. *stackPos++ = m3x;
  72577. *stackPos++ = Path::lineMarker;
  72578. }
  72579. jassert (stackPos < stackBase + stackSize);
  72580. }
  72581. else if (type == Path::cubicMarker)
  72582. {
  72583. const int offset = (int) (stackPos - stackBase);
  72584. if (offset >= stackSize - 16)
  72585. {
  72586. stackSize <<= 1;
  72587. stackBase.realloc (stackSize);
  72588. stackPos = stackBase + offset;
  72589. }
  72590. const float dx1 = x1 - x2;
  72591. const float dy1 = y1 - y2;
  72592. const float dx2 = x2 - x3;
  72593. const float dy2 = y2 - y3;
  72594. const float dx3 = x3 - x4;
  72595. const float dy3 = y3 - y4;
  72596. const float m1x = (x1 + x2) * 0.5f;
  72597. const float m1y = (y1 + y2) * 0.5f;
  72598. const float m2x = (x3 + x2) * 0.5f;
  72599. const float m2y = (y3 + y2) * 0.5f;
  72600. const float m3x = (x3 + x4) * 0.5f;
  72601. const float m3y = (y3 + y4) * 0.5f;
  72602. const float m4x = (m1x + m2x) * 0.5f;
  72603. const float m4y = (m1y + m2y) * 0.5f;
  72604. const float m5x = (m3x + m2x) * 0.5f;
  72605. const float m5y = (m3y + m2y) * 0.5f;
  72606. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72607. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72608. {
  72609. *stackPos++ = y4;
  72610. *stackPos++ = x4;
  72611. *stackPos++ = m3y;
  72612. *stackPos++ = m3x;
  72613. *stackPos++ = m5y;
  72614. *stackPos++ = m5x;
  72615. *stackPos++ = Path::cubicMarker;
  72616. *stackPos++ = (m4y + m5y) * 0.5f;
  72617. *stackPos++ = (m4x + m5x) * 0.5f;
  72618. *stackPos++ = m4y;
  72619. *stackPos++ = m4x;
  72620. *stackPos++ = m1y;
  72621. *stackPos++ = m1x;
  72622. *stackPos++ = Path::cubicMarker;
  72623. }
  72624. else
  72625. {
  72626. *stackPos++ = y4;
  72627. *stackPos++ = x4;
  72628. *stackPos++ = Path::lineMarker;
  72629. *stackPos++ = m5y;
  72630. *stackPos++ = m5x;
  72631. *stackPos++ = Path::lineMarker;
  72632. *stackPos++ = m4y;
  72633. *stackPos++ = m4x;
  72634. *stackPos++ = Path::lineMarker;
  72635. }
  72636. }
  72637. else if (type == Path::closeSubPathMarker)
  72638. {
  72639. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72640. {
  72641. x1 = x2;
  72642. y1 = y2;
  72643. x2 = subPathCloseX;
  72644. y2 = subPathCloseY;
  72645. closesSubPath = true;
  72646. return true;
  72647. }
  72648. }
  72649. else
  72650. {
  72651. jassert (type == Path::moveMarker);
  72652. subPathIndex = -1;
  72653. subPathCloseX = x1 = x2;
  72654. subPathCloseY = y1 = y2;
  72655. }
  72656. }
  72657. }
  72658. END_JUCE_NAMESPACE
  72659. /*** End of inlined file: juce_PathIterator.cpp ***/
  72660. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72661. BEGIN_JUCE_NAMESPACE
  72662. PathStrokeType::PathStrokeType (const float strokeThickness,
  72663. const JointStyle jointStyle_,
  72664. const EndCapStyle endStyle_) throw()
  72665. : thickness (strokeThickness),
  72666. jointStyle (jointStyle_),
  72667. endStyle (endStyle_)
  72668. {
  72669. }
  72670. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72671. : thickness (other.thickness),
  72672. jointStyle (other.jointStyle),
  72673. endStyle (other.endStyle)
  72674. {
  72675. }
  72676. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72677. {
  72678. thickness = other.thickness;
  72679. jointStyle = other.jointStyle;
  72680. endStyle = other.endStyle;
  72681. return *this;
  72682. }
  72683. PathStrokeType::~PathStrokeType() throw()
  72684. {
  72685. }
  72686. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72687. {
  72688. return thickness == other.thickness
  72689. && jointStyle == other.jointStyle
  72690. && endStyle == other.endStyle;
  72691. }
  72692. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72693. {
  72694. return ! operator== (other);
  72695. }
  72696. static bool lineIntersection (const float x1, const float y1,
  72697. const float x2, const float y2,
  72698. const float x3, const float y3,
  72699. const float x4, const float y4,
  72700. float& intersectionX,
  72701. float& intersectionY,
  72702. float& distanceBeyondLine1EndSquared) throw()
  72703. {
  72704. if (x2 != x3 || y2 != y3)
  72705. {
  72706. const float dx1 = x2 - x1;
  72707. const float dy1 = y2 - y1;
  72708. const float dx2 = x4 - x3;
  72709. const float dy2 = y4 - y3;
  72710. const float divisor = dx1 * dy2 - dx2 * dy1;
  72711. if (divisor == 0)
  72712. {
  72713. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72714. {
  72715. if (dy1 == 0 && dy2 != 0)
  72716. {
  72717. const float along = (y1 - y3) / dy2;
  72718. intersectionX = x3 + along * dx2;
  72719. intersectionY = y1;
  72720. distanceBeyondLine1EndSquared = intersectionX - x2;
  72721. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72722. if ((x2 > x1) == (intersectionX < x2))
  72723. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72724. return along >= 0 && along <= 1.0f;
  72725. }
  72726. else if (dy2 == 0 && dy1 != 0)
  72727. {
  72728. const float along = (y3 - y1) / dy1;
  72729. intersectionX = x1 + along * dx1;
  72730. intersectionY = y3;
  72731. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72732. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72733. if (along < 1.0f)
  72734. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72735. return along >= 0 && along <= 1.0f;
  72736. }
  72737. else if (dx1 == 0 && dx2 != 0)
  72738. {
  72739. const float along = (x1 - x3) / dx2;
  72740. intersectionX = x1;
  72741. intersectionY = y3 + along * dy2;
  72742. distanceBeyondLine1EndSquared = intersectionY - y2;
  72743. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72744. if ((y2 > y1) == (intersectionY < y2))
  72745. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72746. return along >= 0 && along <= 1.0f;
  72747. }
  72748. else if (dx2 == 0 && dx1 != 0)
  72749. {
  72750. const float along = (x3 - x1) / dx1;
  72751. intersectionX = x3;
  72752. intersectionY = y1 + along * dy1;
  72753. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72754. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72755. if (along < 1.0f)
  72756. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72757. return along >= 0 && along <= 1.0f;
  72758. }
  72759. }
  72760. intersectionX = 0.5f * (x2 + x3);
  72761. intersectionY = 0.5f * (y2 + y3);
  72762. distanceBeyondLine1EndSquared = 0.0f;
  72763. return false;
  72764. }
  72765. else
  72766. {
  72767. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72768. intersectionX = x1 + along1 * dx1;
  72769. intersectionY = y1 + along1 * dy1;
  72770. if (along1 >= 0 && along1 <= 1.0f)
  72771. {
  72772. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72773. if (along2 >= 0 && along2 <= divisor)
  72774. {
  72775. distanceBeyondLine1EndSquared = 0.0f;
  72776. return true;
  72777. }
  72778. }
  72779. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72780. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72781. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72782. if (along1 < 1.0f)
  72783. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72784. return false;
  72785. }
  72786. }
  72787. intersectionX = x2;
  72788. intersectionY = y2;
  72789. distanceBeyondLine1EndSquared = 0.0f;
  72790. return true;
  72791. }
  72792. namespace PathFunctions
  72793. {
  72794. // part of stroke drawing stuff
  72795. static void addEdgeAndJoint (Path& destPath,
  72796. const PathStrokeType::JointStyle style,
  72797. const float maxMiterExtensionSquared, const float width,
  72798. const float x1, const float y1,
  72799. const float x2, const float y2,
  72800. const float x3, const float y3,
  72801. const float x4, const float y4,
  72802. const float midX, const float midY)
  72803. {
  72804. if (style == PathStrokeType::beveled
  72805. || (x3 == x4 && y3 == y4)
  72806. || (x1 == x2 && y1 == y2))
  72807. {
  72808. destPath.lineTo (x2, y2);
  72809. destPath.lineTo (x3, y3);
  72810. }
  72811. else
  72812. {
  72813. float jx, jy, distanceBeyondLine1EndSquared;
  72814. // if they intersect, use this point..
  72815. if (lineIntersection (x1, y1, x2, y2,
  72816. x3, y3, x4, y4,
  72817. jx, jy, distanceBeyondLine1EndSquared))
  72818. {
  72819. destPath.lineTo (jx, jy);
  72820. }
  72821. else
  72822. {
  72823. if (style == PathStrokeType::mitered)
  72824. {
  72825. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72826. && distanceBeyondLine1EndSquared > 0.0f)
  72827. {
  72828. destPath.lineTo (jx, jy);
  72829. }
  72830. else
  72831. {
  72832. // the end sticks out too far, so just use a blunt joint
  72833. destPath.lineTo (x2, y2);
  72834. destPath.lineTo (x3, y3);
  72835. }
  72836. }
  72837. else
  72838. {
  72839. // curved joints
  72840. float angle1 = atan2f (x2 - midX, y2 - midY);
  72841. float angle2 = atan2f (x3 - midX, y3 - midY);
  72842. const float angleIncrement = 0.1f;
  72843. destPath.lineTo (x2, y2);
  72844. if (fabs (angle1 - angle2) > angleIncrement)
  72845. {
  72846. if (angle2 > angle1 + float_Pi
  72847. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72848. {
  72849. if (angle2 > angle1)
  72850. angle2 -= float_Pi * 2.0f;
  72851. jassert (angle1 <= angle2 + float_Pi);
  72852. angle1 -= angleIncrement;
  72853. while (angle1 > angle2)
  72854. {
  72855. destPath.lineTo (midX + width * sinf (angle1),
  72856. midY + width * cosf (angle1));
  72857. angle1 -= angleIncrement;
  72858. }
  72859. }
  72860. else
  72861. {
  72862. if (angle1 > angle2)
  72863. angle1 -= float_Pi * 2.0f;
  72864. jassert (angle1 >= angle2 - float_Pi);
  72865. angle1 += angleIncrement;
  72866. while (angle1 < angle2)
  72867. {
  72868. destPath.lineTo (midX + width * sinf (angle1),
  72869. midY + width * cosf (angle1));
  72870. angle1 += angleIncrement;
  72871. }
  72872. }
  72873. }
  72874. destPath.lineTo (x3, y3);
  72875. }
  72876. }
  72877. }
  72878. }
  72879. static void addLineEnd (Path& destPath,
  72880. const PathStrokeType::EndCapStyle style,
  72881. const float x1, const float y1,
  72882. const float x2, const float y2,
  72883. const float width)
  72884. {
  72885. if (style == PathStrokeType::butt)
  72886. {
  72887. destPath.lineTo (x2, y2);
  72888. }
  72889. else
  72890. {
  72891. float offx1, offy1, offx2, offy2;
  72892. float dx = x2 - x1;
  72893. float dy = y2 - y1;
  72894. const float len = juce_hypotf (dx, dy);
  72895. if (len == 0)
  72896. {
  72897. offx1 = offx2 = x1;
  72898. offy1 = offy2 = y1;
  72899. }
  72900. else
  72901. {
  72902. const float offset = width / len;
  72903. dx *= offset;
  72904. dy *= offset;
  72905. offx1 = x1 + dy;
  72906. offy1 = y1 - dx;
  72907. offx2 = x2 + dy;
  72908. offy2 = y2 - dx;
  72909. }
  72910. if (style == PathStrokeType::square)
  72911. {
  72912. // sqaure ends
  72913. destPath.lineTo (offx1, offy1);
  72914. destPath.lineTo (offx2, offy2);
  72915. destPath.lineTo (x2, y2);
  72916. }
  72917. else
  72918. {
  72919. // rounded ends
  72920. const float midx = (offx1 + offx2) * 0.5f;
  72921. const float midy = (offy1 + offy2) * 0.5f;
  72922. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72923. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72924. midx, midy);
  72925. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72926. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72927. x2, y2);
  72928. }
  72929. }
  72930. }
  72931. struct LineSection
  72932. {
  72933. LineSection() {}
  72934. LineSection (int) {}
  72935. float x1, y1, x2, y2; // original line
  72936. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72937. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72938. };
  72939. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72940. const bool isClosed,
  72941. const float width, const float maxMiterExtensionSquared,
  72942. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72943. {
  72944. jassert (subPath.size() > 0);
  72945. const LineSection& firstLine = subPath.getReference (0);
  72946. float lastX1 = firstLine.lx1;
  72947. float lastY1 = firstLine.ly1;
  72948. float lastX2 = firstLine.lx2;
  72949. float lastY2 = firstLine.ly2;
  72950. if (isClosed)
  72951. {
  72952. destPath.startNewSubPath (lastX1, lastY1);
  72953. }
  72954. else
  72955. {
  72956. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72957. addLineEnd (destPath, endStyle,
  72958. firstLine.rx2, firstLine.ry2,
  72959. lastX1, lastY1,
  72960. width);
  72961. }
  72962. int i;
  72963. for (i = 1; i < subPath.size(); ++i)
  72964. {
  72965. const LineSection& l = subPath.getReference (i);
  72966. addEdgeAndJoint (destPath, jointStyle,
  72967. maxMiterExtensionSquared, width,
  72968. lastX1, lastY1, lastX2, lastY2,
  72969. l.lx1, l.ly1, l.lx2, l.ly2,
  72970. l.x1, l.y1);
  72971. lastX1 = l.lx1;
  72972. lastY1 = l.ly1;
  72973. lastX2 = l.lx2;
  72974. lastY2 = l.ly2;
  72975. }
  72976. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72977. if (isClosed)
  72978. {
  72979. const LineSection& l = subPath.getReference (0);
  72980. addEdgeAndJoint (destPath, jointStyle,
  72981. maxMiterExtensionSquared, width,
  72982. lastX1, lastY1, lastX2, lastY2,
  72983. l.lx1, l.ly1, l.lx2, l.ly2,
  72984. l.x1, l.y1);
  72985. destPath.closeSubPath();
  72986. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72987. }
  72988. else
  72989. {
  72990. destPath.lineTo (lastX2, lastY2);
  72991. addLineEnd (destPath, endStyle,
  72992. lastX2, lastY2,
  72993. lastLine.rx1, lastLine.ry1,
  72994. width);
  72995. }
  72996. lastX1 = lastLine.rx1;
  72997. lastY1 = lastLine.ry1;
  72998. lastX2 = lastLine.rx2;
  72999. lastY2 = lastLine.ry2;
  73000. for (i = subPath.size() - 1; --i >= 0;)
  73001. {
  73002. const LineSection& l = subPath.getReference (i);
  73003. addEdgeAndJoint (destPath, jointStyle,
  73004. maxMiterExtensionSquared, width,
  73005. lastX1, lastY1, lastX2, lastY2,
  73006. l.rx1, l.ry1, l.rx2, l.ry2,
  73007. l.x2, l.y2);
  73008. lastX1 = l.rx1;
  73009. lastY1 = l.ry1;
  73010. lastX2 = l.rx2;
  73011. lastY2 = l.ry2;
  73012. }
  73013. if (isClosed)
  73014. {
  73015. addEdgeAndJoint (destPath, jointStyle,
  73016. maxMiterExtensionSquared, width,
  73017. lastX1, lastY1, lastX2, lastY2,
  73018. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  73019. lastLine.x2, lastLine.y2);
  73020. }
  73021. else
  73022. {
  73023. // do the last line
  73024. destPath.lineTo (lastX2, lastY2);
  73025. }
  73026. destPath.closeSubPath();
  73027. }
  73028. }
  73029. void PathStrokeType::createStrokedPath (Path& destPath,
  73030. const Path& source,
  73031. const AffineTransform& transform,
  73032. const float extraAccuracy) const
  73033. {
  73034. if (thickness <= 0)
  73035. {
  73036. destPath.clear();
  73037. return;
  73038. }
  73039. const Path* sourcePath = &source;
  73040. Path temp;
  73041. if (sourcePath == &destPath)
  73042. {
  73043. destPath.swapWithPath (temp);
  73044. sourcePath = &temp;
  73045. }
  73046. else
  73047. {
  73048. destPath.clear();
  73049. }
  73050. destPath.setUsingNonZeroWinding (true);
  73051. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  73052. const float width = 0.5f * thickness;
  73053. // Iterate the path, creating a list of the
  73054. // left/right-hand lines along either side of it...
  73055. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  73056. using namespace PathFunctions;
  73057. Array <LineSection> subPath;
  73058. LineSection l;
  73059. l.x1 = 0;
  73060. l.y1 = 0;
  73061. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  73062. while (it.next())
  73063. {
  73064. if (it.subPathIndex == 0)
  73065. {
  73066. if (subPath.size() > 0)
  73067. {
  73068. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73069. subPath.clearQuick();
  73070. }
  73071. l.x1 = it.x1;
  73072. l.y1 = it.y1;
  73073. }
  73074. l.x2 = it.x2;
  73075. l.y2 = it.y2;
  73076. float dx = l.x2 - l.x1;
  73077. float dy = l.y2 - l.y1;
  73078. const float hypotSquared = dx*dx + dy*dy;
  73079. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  73080. {
  73081. const float len = sqrtf (hypotSquared);
  73082. if (len == 0)
  73083. {
  73084. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  73085. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  73086. }
  73087. else
  73088. {
  73089. const float offset = width / len;
  73090. dx *= offset;
  73091. dy *= offset;
  73092. l.rx2 = l.x1 - dy;
  73093. l.ry2 = l.y1 + dx;
  73094. l.lx1 = l.x1 + dy;
  73095. l.ly1 = l.y1 - dx;
  73096. l.lx2 = l.x2 + dy;
  73097. l.ly2 = l.y2 - dx;
  73098. l.rx1 = l.x2 - dy;
  73099. l.ry1 = l.y2 + dx;
  73100. }
  73101. subPath.add (l);
  73102. if (it.closesSubPath)
  73103. {
  73104. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73105. subPath.clearQuick();
  73106. }
  73107. else
  73108. {
  73109. l.x1 = it.x2;
  73110. l.y1 = it.y2;
  73111. }
  73112. }
  73113. }
  73114. if (subPath.size() > 0)
  73115. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73116. }
  73117. void PathStrokeType::createDashedStroke (Path& destPath,
  73118. const Path& sourcePath,
  73119. const float* dashLengths,
  73120. int numDashLengths,
  73121. const AffineTransform& transform,
  73122. const float extraAccuracy) const
  73123. {
  73124. if (thickness <= 0)
  73125. return;
  73126. // this should really be an even number..
  73127. jassert ((numDashLengths & 1) == 0);
  73128. Path newDestPath;
  73129. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  73130. bool first = true;
  73131. int dashNum = 0;
  73132. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  73133. float dx = 0.0f, dy = 0.0f;
  73134. for (;;)
  73135. {
  73136. const bool isSolid = ((dashNum & 1) == 0);
  73137. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  73138. jassert (dashLen > 0); // must be a positive increment!
  73139. if (dashLen <= 0)
  73140. break;
  73141. pos += dashLen;
  73142. while (pos > lineEndPos)
  73143. {
  73144. if (! it.next())
  73145. {
  73146. if (isSolid && ! first)
  73147. newDestPath.lineTo (it.x2, it.y2);
  73148. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  73149. return;
  73150. }
  73151. if (isSolid && ! first)
  73152. newDestPath.lineTo (it.x1, it.y1);
  73153. else
  73154. newDestPath.startNewSubPath (it.x1, it.y1);
  73155. dx = it.x2 - it.x1;
  73156. dy = it.y2 - it.y1;
  73157. lineLen = juce_hypotf (dx, dy);
  73158. lineEndPos += lineLen;
  73159. first = it.closesSubPath;
  73160. }
  73161. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  73162. if (isSolid)
  73163. newDestPath.lineTo (it.x1 + dx * alpha,
  73164. it.y1 + dy * alpha);
  73165. else
  73166. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  73167. it.y1 + dy * alpha);
  73168. }
  73169. }
  73170. END_JUCE_NAMESPACE
  73171. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  73172. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  73173. BEGIN_JUCE_NAMESPACE
  73174. PositionedRectangle::PositionedRectangle() throw()
  73175. : x (0.0),
  73176. y (0.0),
  73177. w (0.0),
  73178. h (0.0),
  73179. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73180. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73181. wMode (absoluteSize),
  73182. hMode (absoluteSize)
  73183. {
  73184. }
  73185. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  73186. : x (other.x),
  73187. y (other.y),
  73188. w (other.w),
  73189. h (other.h),
  73190. xMode (other.xMode),
  73191. yMode (other.yMode),
  73192. wMode (other.wMode),
  73193. hMode (other.hMode)
  73194. {
  73195. }
  73196. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  73197. {
  73198. x = other.x;
  73199. y = other.y;
  73200. w = other.w;
  73201. h = other.h;
  73202. xMode = other.xMode;
  73203. yMode = other.yMode;
  73204. wMode = other.wMode;
  73205. hMode = other.hMode;
  73206. return *this;
  73207. }
  73208. PositionedRectangle::~PositionedRectangle() throw()
  73209. {
  73210. }
  73211. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  73212. {
  73213. return x == other.x
  73214. && y == other.y
  73215. && w == other.w
  73216. && h == other.h
  73217. && xMode == other.xMode
  73218. && yMode == other.yMode
  73219. && wMode == other.wMode
  73220. && hMode == other.hMode;
  73221. }
  73222. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  73223. {
  73224. return ! operator== (other);
  73225. }
  73226. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  73227. {
  73228. StringArray tokens;
  73229. tokens.addTokens (stringVersion, false);
  73230. decodePosString (tokens [0], xMode, x);
  73231. decodePosString (tokens [1], yMode, y);
  73232. decodeSizeString (tokens [2], wMode, w);
  73233. decodeSizeString (tokens [3], hMode, h);
  73234. }
  73235. const String PositionedRectangle::toString() const throw()
  73236. {
  73237. String s;
  73238. s.preallocateStorage (12);
  73239. addPosDescription (s, xMode, x);
  73240. s << T(' ');
  73241. addPosDescription (s, yMode, y);
  73242. s << T(' ');
  73243. addSizeDescription (s, wMode, w);
  73244. s << T(' ');
  73245. addSizeDescription (s, hMode, h);
  73246. return s;
  73247. }
  73248. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  73249. {
  73250. jassert (! target.isEmpty());
  73251. double x_, y_, w_, h_;
  73252. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73253. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73254. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  73255. roundToInt (w_), roundToInt (h_));
  73256. }
  73257. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  73258. double& x_, double& y_,
  73259. double& w_, double& h_) const throw()
  73260. {
  73261. jassert (! target.isEmpty());
  73262. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73263. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73264. }
  73265. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  73266. {
  73267. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  73268. }
  73269. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  73270. const Rectangle<int>& target) throw()
  73271. {
  73272. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  73273. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  73274. }
  73275. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  73276. const double newW, const double newH,
  73277. const Rectangle<int>& target) throw()
  73278. {
  73279. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  73280. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  73281. }
  73282. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  73283. {
  73284. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  73285. updateFrom (comp.getBounds(), Rectangle<int>());
  73286. else
  73287. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  73288. }
  73289. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  73290. {
  73291. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73292. }
  73293. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  73294. {
  73295. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  73296. | absoluteFromParentBottomRight
  73297. | absoluteFromParentCentre
  73298. | proportionOfParentSize));
  73299. }
  73300. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  73301. {
  73302. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73303. }
  73304. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  73305. {
  73306. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  73307. | absoluteFromParentBottomRight
  73308. | absoluteFromParentCentre
  73309. | proportionOfParentSize));
  73310. }
  73311. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  73312. {
  73313. return (SizeMode) wMode;
  73314. }
  73315. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  73316. {
  73317. return (SizeMode) hMode;
  73318. }
  73319. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  73320. const PositionMode xMode_,
  73321. const AnchorPoint yAnchor,
  73322. const PositionMode yMode_,
  73323. const SizeMode widthMode,
  73324. const SizeMode heightMode,
  73325. const Rectangle<int>& target) throw()
  73326. {
  73327. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  73328. {
  73329. double tx, tw;
  73330. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  73331. xMode = (uint8) (xAnchor | xMode_);
  73332. wMode = (uint8) widthMode;
  73333. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  73334. }
  73335. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73336. {
  73337. double ty, th;
  73338. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73339. yMode = (uint8) (yAnchor | yMode_);
  73340. hMode = (uint8) heightMode;
  73341. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73342. }
  73343. }
  73344. bool PositionedRectangle::isPositionAbsolute() const throw()
  73345. {
  73346. return xMode == absoluteFromParentTopLeft
  73347. && yMode == absoluteFromParentTopLeft
  73348. && wMode == absoluteSize
  73349. && hMode == absoluteSize;
  73350. }
  73351. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73352. {
  73353. if ((mode & proportionOfParentSize) != 0)
  73354. {
  73355. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73356. }
  73357. else
  73358. {
  73359. s << (roundToInt (value * 100.0) / 100.0);
  73360. if ((mode & absoluteFromParentBottomRight) != 0)
  73361. s << T('R');
  73362. else if ((mode & absoluteFromParentCentre) != 0)
  73363. s << T('C');
  73364. }
  73365. if ((mode & anchorAtRightOrBottom) != 0)
  73366. s << T('r');
  73367. else if ((mode & anchorAtCentre) != 0)
  73368. s << T('c');
  73369. }
  73370. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73371. {
  73372. if (mode == proportionalSize)
  73373. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73374. else if (mode == parentSizeMinusAbsolute)
  73375. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73376. else
  73377. s << (roundToInt (value * 100.0) / 100.0);
  73378. }
  73379. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73380. {
  73381. if (s.containsChar (T('r')))
  73382. mode = anchorAtRightOrBottom;
  73383. else if (s.containsChar (T('c')))
  73384. mode = anchorAtCentre;
  73385. else
  73386. mode = anchorAtLeftOrTop;
  73387. if (s.containsChar (T('%')))
  73388. {
  73389. mode |= proportionOfParentSize;
  73390. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73391. }
  73392. else
  73393. {
  73394. if (s.containsChar (T('R')))
  73395. mode |= absoluteFromParentBottomRight;
  73396. else if (s.containsChar (T('C')))
  73397. mode |= absoluteFromParentCentre;
  73398. else
  73399. mode |= absoluteFromParentTopLeft;
  73400. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73401. }
  73402. }
  73403. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73404. {
  73405. if (s.containsChar (T('%')))
  73406. {
  73407. mode = proportionalSize;
  73408. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73409. }
  73410. else if (s.containsChar (T('M')))
  73411. {
  73412. mode = parentSizeMinusAbsolute;
  73413. value = s.getDoubleValue();
  73414. }
  73415. else
  73416. {
  73417. mode = absoluteSize;
  73418. value = s.getDoubleValue();
  73419. }
  73420. }
  73421. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73422. const double x_, const double w_,
  73423. const uint8 xMode_, const uint8 wMode_,
  73424. const int parentPos,
  73425. const int parentSize) const throw()
  73426. {
  73427. if (wMode_ == proportionalSize)
  73428. wOut = roundToInt (w_ * parentSize);
  73429. else if (wMode_ == parentSizeMinusAbsolute)
  73430. wOut = jmax (0, parentSize - roundToInt (w_));
  73431. else
  73432. wOut = roundToInt (w_);
  73433. if ((xMode_ & proportionOfParentSize) != 0)
  73434. xOut = parentPos + x_ * parentSize;
  73435. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73436. xOut = (parentPos + parentSize) - x_;
  73437. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73438. xOut = x_ + (parentPos + parentSize / 2);
  73439. else
  73440. xOut = x_ + parentPos;
  73441. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73442. xOut -= wOut;
  73443. else if ((xMode_ & anchorAtCentre) != 0)
  73444. xOut -= wOut / 2;
  73445. }
  73446. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73447. double x_, const double w_,
  73448. const uint8 xMode_, const uint8 wMode_,
  73449. const int parentPos,
  73450. const int parentSize) const throw()
  73451. {
  73452. if (wMode_ == proportionalSize)
  73453. {
  73454. if (parentSize > 0)
  73455. wOut = w_ / parentSize;
  73456. }
  73457. else if (wMode_ == parentSizeMinusAbsolute)
  73458. wOut = parentSize - w_;
  73459. else
  73460. wOut = w_;
  73461. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73462. x_ += w_;
  73463. else if ((xMode_ & anchorAtCentre) != 0)
  73464. x_ += w_ / 2;
  73465. if ((xMode_ & proportionOfParentSize) != 0)
  73466. {
  73467. if (parentSize > 0)
  73468. xOut = (x_ - parentPos) / parentSize;
  73469. }
  73470. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73471. xOut = (parentPos + parentSize) - x_;
  73472. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73473. xOut = x_ - (parentPos + parentSize / 2);
  73474. else
  73475. xOut = x_ - parentPos;
  73476. }
  73477. END_JUCE_NAMESPACE
  73478. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73479. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73480. BEGIN_JUCE_NAMESPACE
  73481. RectangleList::RectangleList() throw()
  73482. {
  73483. }
  73484. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73485. {
  73486. if (! rect.isEmpty())
  73487. rects.add (rect);
  73488. }
  73489. RectangleList::RectangleList (const RectangleList& other) throw()
  73490. : rects (other.rects)
  73491. {
  73492. }
  73493. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73494. {
  73495. rects = other.rects;
  73496. return *this;
  73497. }
  73498. RectangleList::~RectangleList() throw()
  73499. {
  73500. }
  73501. void RectangleList::clear() throw()
  73502. {
  73503. rects.clearQuick();
  73504. }
  73505. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73506. {
  73507. if (((unsigned int) index) < (unsigned int) rects.size())
  73508. return rects.getReference (index);
  73509. return Rectangle<int>();
  73510. }
  73511. bool RectangleList::isEmpty() const throw()
  73512. {
  73513. return rects.size() == 0;
  73514. }
  73515. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73516. : current (0),
  73517. owner (list),
  73518. index (list.rects.size())
  73519. {
  73520. }
  73521. RectangleList::Iterator::~Iterator() throw()
  73522. {
  73523. }
  73524. bool RectangleList::Iterator::next() throw()
  73525. {
  73526. if (--index >= 0)
  73527. {
  73528. current = & (owner.rects.getReference (index));
  73529. return true;
  73530. }
  73531. return false;
  73532. }
  73533. void RectangleList::add (const Rectangle<int>& rect) throw()
  73534. {
  73535. if (! rect.isEmpty())
  73536. {
  73537. if (rects.size() == 0)
  73538. {
  73539. rects.add (rect);
  73540. }
  73541. else
  73542. {
  73543. bool anyOverlaps = false;
  73544. int i;
  73545. for (i = rects.size(); --i >= 0;)
  73546. {
  73547. Rectangle<int>& ourRect = rects.getReference (i);
  73548. if (rect.intersects (ourRect))
  73549. {
  73550. if (rect.contains (ourRect))
  73551. rects.remove (i);
  73552. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73553. anyOverlaps = true;
  73554. }
  73555. }
  73556. if (anyOverlaps && rects.size() > 0)
  73557. {
  73558. RectangleList r (rect);
  73559. for (i = rects.size(); --i >= 0;)
  73560. {
  73561. const Rectangle<int>& ourRect = rects.getReference (i);
  73562. if (rect.intersects (ourRect))
  73563. {
  73564. r.subtract (ourRect);
  73565. if (r.rects.size() == 0)
  73566. return;
  73567. }
  73568. }
  73569. for (i = r.getNumRectangles(); --i >= 0;)
  73570. rects.add (r.rects.getReference (i));
  73571. }
  73572. else
  73573. {
  73574. rects.add (rect);
  73575. }
  73576. }
  73577. }
  73578. }
  73579. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73580. {
  73581. rects.add (rect);
  73582. }
  73583. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73584. {
  73585. if (rects.size() == 0)
  73586. {
  73587. if (w > 0 && h > 0)
  73588. rects.add (Rectangle<int> (x, y, w, h));
  73589. }
  73590. else
  73591. {
  73592. add (Rectangle<int> (x, y, w, h));
  73593. }
  73594. }
  73595. void RectangleList::add (const RectangleList& other) throw()
  73596. {
  73597. for (int i = 0; i < other.rects.size(); ++i)
  73598. add (other.rects.getReference (i));
  73599. }
  73600. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73601. {
  73602. const int originalNumRects = rects.size();
  73603. if (originalNumRects > 0)
  73604. {
  73605. const int x1 = rect.x;
  73606. const int y1 = rect.y;
  73607. const int x2 = x1 + rect.w;
  73608. const int y2 = y1 + rect.h;
  73609. for (int i = getNumRectangles(); --i >= 0;)
  73610. {
  73611. Rectangle<int>& r = rects.getReference (i);
  73612. const int rx1 = r.x;
  73613. const int ry1 = r.y;
  73614. const int rx2 = rx1 + r.w;
  73615. const int ry2 = ry1 + r.h;
  73616. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73617. {
  73618. if (x1 > rx1 && x1 < rx2)
  73619. {
  73620. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73621. {
  73622. r.w = x1 - rx1;
  73623. }
  73624. else
  73625. {
  73626. r.x = x1;
  73627. r.w = rx2 - x1;
  73628. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73629. i += 2;
  73630. }
  73631. }
  73632. else if (x2 > rx1 && x2 < rx2)
  73633. {
  73634. r.x = x2;
  73635. r.w = rx2 - x2;
  73636. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73637. {
  73638. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73639. i += 2;
  73640. }
  73641. }
  73642. else if (y1 > ry1 && y1 < ry2)
  73643. {
  73644. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73645. {
  73646. r.h = y1 - ry1;
  73647. }
  73648. else
  73649. {
  73650. r.y = y1;
  73651. r.h = ry2 - y1;
  73652. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73653. i += 2;
  73654. }
  73655. }
  73656. else if (y2 > ry1 && y2 < ry2)
  73657. {
  73658. r.y = y2;
  73659. r.h = ry2 - y2;
  73660. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73661. {
  73662. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73663. i += 2;
  73664. }
  73665. }
  73666. else
  73667. {
  73668. rects.remove (i);
  73669. }
  73670. }
  73671. }
  73672. if (rects.size() > originalNumRects + 10)
  73673. consolidate();
  73674. }
  73675. }
  73676. void RectangleList::subtract (const RectangleList& otherList) throw()
  73677. {
  73678. for (int i = otherList.rects.size(); --i >= 0;)
  73679. subtract (otherList.rects.getReference (i));
  73680. }
  73681. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73682. {
  73683. bool notEmpty = false;
  73684. if (rect.isEmpty())
  73685. {
  73686. clear();
  73687. }
  73688. else
  73689. {
  73690. for (int i = rects.size(); --i >= 0;)
  73691. {
  73692. Rectangle<int>& r = rects.getReference (i);
  73693. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73694. rects.remove (i);
  73695. else
  73696. notEmpty = true;
  73697. }
  73698. }
  73699. return notEmpty;
  73700. }
  73701. bool RectangleList::clipTo (const RectangleList& other) throw()
  73702. {
  73703. if (rects.size() == 0)
  73704. return false;
  73705. RectangleList result;
  73706. for (int j = 0; j < rects.size(); ++j)
  73707. {
  73708. const Rectangle<int>& rect = rects.getReference (j);
  73709. for (int i = other.rects.size(); --i >= 0;)
  73710. {
  73711. Rectangle<int> r (other.rects.getReference (i));
  73712. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73713. result.rects.add (r);
  73714. }
  73715. }
  73716. swapWith (result);
  73717. return ! isEmpty();
  73718. }
  73719. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73720. {
  73721. destRegion.clear();
  73722. if (! rect.isEmpty())
  73723. {
  73724. for (int i = rects.size(); --i >= 0;)
  73725. {
  73726. Rectangle<int> r (rects.getReference (i));
  73727. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73728. destRegion.rects.add (r);
  73729. }
  73730. }
  73731. return destRegion.rects.size() > 0;
  73732. }
  73733. void RectangleList::swapWith (RectangleList& otherList) throw()
  73734. {
  73735. rects.swapWithArray (otherList.rects);
  73736. }
  73737. void RectangleList::consolidate() throw()
  73738. {
  73739. int i;
  73740. for (i = 0; i < getNumRectangles() - 1; ++i)
  73741. {
  73742. Rectangle<int>& r = rects.getReference (i);
  73743. const int rx1 = r.x;
  73744. const int ry1 = r.y;
  73745. const int rx2 = rx1 + r.w;
  73746. const int ry2 = ry1 + r.h;
  73747. for (int j = rects.size(); --j > i;)
  73748. {
  73749. Rectangle<int>& r2 = rects.getReference (j);
  73750. const int jrx1 = r2.x;
  73751. const int jry1 = r2.y;
  73752. const int jrx2 = jrx1 + r2.w;
  73753. const int jry2 = jry1 + r2.h;
  73754. // if the vertical edges of any blocks are touching and their horizontals don't
  73755. // line up, split them horizontally..
  73756. if (jrx1 == rx2 || jrx2 == rx1)
  73757. {
  73758. if (jry1 > ry1 && jry1 < ry2)
  73759. {
  73760. r.h = jry1 - ry1;
  73761. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73762. i = -1;
  73763. break;
  73764. }
  73765. if (jry2 > ry1 && jry2 < ry2)
  73766. {
  73767. r.h = jry2 - ry1;
  73768. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73769. i = -1;
  73770. break;
  73771. }
  73772. else if (ry1 > jry1 && ry1 < jry2)
  73773. {
  73774. r2.h = ry1 - jry1;
  73775. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73776. i = -1;
  73777. break;
  73778. }
  73779. else if (ry2 > jry1 && ry2 < jry2)
  73780. {
  73781. r2.h = ry2 - jry1;
  73782. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73783. i = -1;
  73784. break;
  73785. }
  73786. }
  73787. }
  73788. }
  73789. for (i = 0; i < rects.size() - 1; ++i)
  73790. {
  73791. Rectangle<int>& r = rects.getReference (i);
  73792. for (int j = rects.size(); --j > i;)
  73793. {
  73794. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73795. {
  73796. rects.remove (j);
  73797. i = -1;
  73798. break;
  73799. }
  73800. }
  73801. }
  73802. }
  73803. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73804. {
  73805. for (int i = getNumRectangles(); --i >= 0;)
  73806. if (rects.getReference (i).contains (x, y))
  73807. return true;
  73808. return false;
  73809. }
  73810. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73811. {
  73812. if (rects.size() > 1)
  73813. {
  73814. RectangleList r (rectangleToCheck);
  73815. for (int i = rects.size(); --i >= 0;)
  73816. {
  73817. r.subtract (rects.getReference (i));
  73818. if (r.rects.size() == 0)
  73819. return true;
  73820. }
  73821. }
  73822. else if (rects.size() > 0)
  73823. {
  73824. return rects.getReference (0).contains (rectangleToCheck);
  73825. }
  73826. return false;
  73827. }
  73828. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73829. {
  73830. for (int i = rects.size(); --i >= 0;)
  73831. if (rects.getReference (i).intersects (rectangleToCheck))
  73832. return true;
  73833. return false;
  73834. }
  73835. bool RectangleList::intersects (const RectangleList& other) const throw()
  73836. {
  73837. for (int i = rects.size(); --i >= 0;)
  73838. if (other.intersectsRectangle (rects.getReference (i)))
  73839. return true;
  73840. return false;
  73841. }
  73842. const Rectangle<int> RectangleList::getBounds() const throw()
  73843. {
  73844. if (rects.size() <= 1)
  73845. {
  73846. if (rects.size() == 0)
  73847. return Rectangle<int>();
  73848. else
  73849. return rects.getReference (0);
  73850. }
  73851. else
  73852. {
  73853. const Rectangle<int>& r = rects.getReference (0);
  73854. int minX = r.x;
  73855. int minY = r.y;
  73856. int maxX = minX + r.w;
  73857. int maxY = minY + r.h;
  73858. for (int i = rects.size(); --i > 0;)
  73859. {
  73860. const Rectangle<int>& r2 = rects.getReference (i);
  73861. minX = jmin (minX, r2.x);
  73862. minY = jmin (minY, r2.y);
  73863. maxX = jmax (maxX, r2.getRight());
  73864. maxY = jmax (maxY, r2.getBottom());
  73865. }
  73866. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73867. }
  73868. }
  73869. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73870. {
  73871. for (int i = rects.size(); --i >= 0;)
  73872. {
  73873. Rectangle<int>& r = rects.getReference (i);
  73874. r.x += dx;
  73875. r.y += dy;
  73876. }
  73877. }
  73878. const Path RectangleList::toPath() const throw()
  73879. {
  73880. Path p;
  73881. for (int i = rects.size(); --i >= 0;)
  73882. {
  73883. const Rectangle<int>& r = rects.getReference (i);
  73884. p.addRectangle ((float) r.x,
  73885. (float) r.y,
  73886. (float) r.w,
  73887. (float) r.h);
  73888. }
  73889. return p;
  73890. }
  73891. END_JUCE_NAMESPACE
  73892. /*** End of inlined file: juce_RectangleList.cpp ***/
  73893. /*** Start of inlined file: juce_Image.cpp ***/
  73894. BEGIN_JUCE_NAMESPACE
  73895. static const int fullAlphaThreshold = 253;
  73896. Image::Image (const PixelFormat format_,
  73897. const int imageWidth_,
  73898. const int imageHeight_)
  73899. : format (format_),
  73900. imageWidth (imageWidth_),
  73901. imageHeight (imageHeight_),
  73902. imageData (0)
  73903. {
  73904. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73905. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73906. // actual image will be at least 1x1.
  73907. }
  73908. Image::Image (const PixelFormat format_,
  73909. const int imageWidth_,
  73910. const int imageHeight_,
  73911. const bool clearImage)
  73912. : format (format_),
  73913. imageWidth (imageWidth_),
  73914. imageHeight (imageHeight_)
  73915. {
  73916. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73917. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73918. // actual image will be at least 1x1.
  73919. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73920. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73921. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73922. imageData = imageDataAllocated;
  73923. }
  73924. Image::Image (const Image& other)
  73925. : format (other.format),
  73926. imageWidth (other.imageWidth),
  73927. imageHeight (other.imageHeight)
  73928. {
  73929. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73930. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73931. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73932. imageData = imageDataAllocated;
  73933. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73934. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73935. }
  73936. Image::~Image()
  73937. {
  73938. }
  73939. LowLevelGraphicsContext* Image::createLowLevelContext()
  73940. {
  73941. return new LowLevelGraphicsSoftwareRenderer (*this);
  73942. }
  73943. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73944. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73945. lineStride (image.lineStride),
  73946. pixelStride (image.pixelStride),
  73947. width (w),
  73948. height (h)
  73949. {
  73950. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73951. }
  73952. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73953. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73954. lineStride (image.lineStride),
  73955. pixelStride (image.pixelStride),
  73956. width (w),
  73957. height (h)
  73958. {
  73959. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73960. }
  73961. Image::BitmapData::~BitmapData()
  73962. {
  73963. }
  73964. void Image::setPixelData (int x, int y, int w, int h,
  73965. const uint8* sourcePixelData, int sourceLineStride)
  73966. {
  73967. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73968. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73969. {
  73970. const BitmapData dest (*this, x, y, w, h, true);
  73971. for (int i = 0; i < h; ++i)
  73972. {
  73973. memcpy (dest.getLinePointer(i),
  73974. sourcePixelData + sourceLineStride * i,
  73975. w * dest.pixelStride);
  73976. }
  73977. }
  73978. }
  73979. void Image::clear (int dx, int dy, int dw, int dh,
  73980. const Colour& colourToClearTo)
  73981. {
  73982. const PixelARGB col (colourToClearTo.getPixelARGB());
  73983. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73984. uint8* dest = destData.data;
  73985. while (--dh >= 0)
  73986. {
  73987. uint8* line = dest;
  73988. dest += destData.lineStride;
  73989. if (isARGB())
  73990. {
  73991. for (int x = dw; --x >= 0;)
  73992. {
  73993. ((PixelARGB*) line)->set (col);
  73994. line += destData.pixelStride;
  73995. }
  73996. }
  73997. else if (isRGB())
  73998. {
  73999. for (int x = dw; --x >= 0;)
  74000. {
  74001. ((PixelRGB*) line)->set (col);
  74002. line += destData.pixelStride;
  74003. }
  74004. }
  74005. else
  74006. {
  74007. for (int x = dw; --x >= 0;)
  74008. {
  74009. *line = col.getAlpha();
  74010. line += destData.pixelStride;
  74011. }
  74012. }
  74013. }
  74014. }
  74015. Image* Image::createCopy (int newWidth, int newHeight,
  74016. const Graphics::ResamplingQuality quality) const
  74017. {
  74018. if (newWidth < 0)
  74019. newWidth = imageWidth;
  74020. if (newHeight < 0)
  74021. newHeight = imageHeight;
  74022. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  74023. Graphics g (*newImage);
  74024. g.setImageResamplingQuality (quality);
  74025. g.drawImage (this,
  74026. 0, 0, newWidth, newHeight,
  74027. 0, 0, imageWidth, imageHeight,
  74028. false);
  74029. return newImage;
  74030. }
  74031. Image* Image::createCopyOfAlphaChannel() const
  74032. {
  74033. jassert (format != SingleChannel);
  74034. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  74035. if (! hasAlphaChannel())
  74036. {
  74037. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  74038. }
  74039. else
  74040. {
  74041. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  74042. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  74043. for (int y = 0; y < imageHeight; ++y)
  74044. {
  74045. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  74046. uint8* dst = destData.getLinePointer (y);
  74047. for (int x = imageWidth; --x >= 0;)
  74048. {
  74049. *dst++ = src->getAlpha();
  74050. ++src;
  74051. }
  74052. }
  74053. }
  74054. return newImage;
  74055. }
  74056. const Colour Image::getPixelAt (const int x, const int y) const
  74057. {
  74058. Colour c;
  74059. if (((unsigned int) x) < (unsigned int) imageWidth
  74060. && ((unsigned int) y) < (unsigned int) imageHeight)
  74061. {
  74062. const BitmapData srcData (*this, x, y, 1, 1);
  74063. if (isARGB())
  74064. {
  74065. PixelARGB p (*(const PixelARGB*) srcData.data);
  74066. p.unpremultiply();
  74067. c = Colour (p.getARGB());
  74068. }
  74069. else if (isRGB())
  74070. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  74071. else
  74072. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  74073. }
  74074. return c;
  74075. }
  74076. void Image::setPixelAt (const int x, const int y,
  74077. const Colour& colour)
  74078. {
  74079. if (((unsigned int) x) < (unsigned int) imageWidth
  74080. && ((unsigned int) y) < (unsigned int) imageHeight)
  74081. {
  74082. const BitmapData destData (*this, x, y, 1, 1, true);
  74083. const PixelARGB col (colour.getPixelARGB());
  74084. if (isARGB())
  74085. ((PixelARGB*) destData.data)->set (col);
  74086. else if (isRGB())
  74087. ((PixelRGB*) destData.data)->set (col);
  74088. else
  74089. *(destData.data) = col.getAlpha();
  74090. }
  74091. }
  74092. void Image::multiplyAlphaAt (const int x, const int y,
  74093. const float multiplier)
  74094. {
  74095. if (((unsigned int) x) < (unsigned int) imageWidth
  74096. && ((unsigned int) y) < (unsigned int) imageHeight
  74097. && hasAlphaChannel())
  74098. {
  74099. const BitmapData destData (*this, x, y, 1, 1, true);
  74100. if (isARGB())
  74101. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  74102. else
  74103. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  74104. }
  74105. }
  74106. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  74107. {
  74108. if (hasAlphaChannel())
  74109. {
  74110. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74111. if (isARGB())
  74112. {
  74113. for (int y = 0; y < imageHeight; ++y)
  74114. {
  74115. uint8* p = destData.getLinePointer (y);
  74116. for (int x = 0; x < imageWidth; ++x)
  74117. {
  74118. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  74119. p += destData.pixelStride;
  74120. }
  74121. }
  74122. }
  74123. else
  74124. {
  74125. for (int y = 0; y < imageHeight; ++y)
  74126. {
  74127. uint8* p = destData.getLinePointer (y);
  74128. for (int x = 0; x < imageWidth; ++x)
  74129. {
  74130. *p = (uint8) (*p * amountToMultiplyBy);
  74131. p += destData.pixelStride;
  74132. }
  74133. }
  74134. }
  74135. }
  74136. else
  74137. {
  74138. jassertfalse // can't do this without an alpha-channel!
  74139. }
  74140. }
  74141. void Image::desaturate()
  74142. {
  74143. if (isARGB() || isRGB())
  74144. {
  74145. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74146. if (isARGB())
  74147. {
  74148. for (int y = 0; y < imageHeight; ++y)
  74149. {
  74150. uint8* p = destData.getLinePointer (y);
  74151. for (int x = 0; x < imageWidth; ++x)
  74152. {
  74153. ((PixelARGB*) p)->desaturate();
  74154. p += destData.pixelStride;
  74155. }
  74156. }
  74157. }
  74158. else
  74159. {
  74160. for (int y = 0; y < imageHeight; ++y)
  74161. {
  74162. uint8* p = destData.getLinePointer (y);
  74163. for (int x = 0; x < imageWidth; ++x)
  74164. {
  74165. ((PixelRGB*) p)->desaturate();
  74166. p += destData.pixelStride;
  74167. }
  74168. }
  74169. }
  74170. }
  74171. }
  74172. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  74173. {
  74174. if (hasAlphaChannel())
  74175. {
  74176. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  74177. SparseSet <int> pixelsOnRow;
  74178. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  74179. for (int y = 0; y < imageHeight; ++y)
  74180. {
  74181. pixelsOnRow.clear();
  74182. const uint8* lineData = srcData.getLinePointer (y);
  74183. if (isARGB())
  74184. {
  74185. for (int x = 0; x < imageWidth; ++x)
  74186. {
  74187. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  74188. pixelsOnRow.addRange (x, 1);
  74189. lineData += srcData.pixelStride;
  74190. }
  74191. }
  74192. else
  74193. {
  74194. for (int x = 0; x < imageWidth; ++x)
  74195. {
  74196. if (*lineData >= threshold)
  74197. pixelsOnRow.addRange (x, 1);
  74198. lineData += srcData.pixelStride;
  74199. }
  74200. }
  74201. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  74202. {
  74203. int x, w;
  74204. if (pixelsOnRow.getRange (i, x, w))
  74205. result.add (Rectangle<int> (x, y, w, 1));
  74206. }
  74207. result.consolidate();
  74208. }
  74209. }
  74210. else
  74211. {
  74212. result.add (0, 0, imageWidth, imageHeight);
  74213. }
  74214. }
  74215. void Image::moveImageSection (int dx, int dy,
  74216. int sx, int sy,
  74217. int w, int h)
  74218. {
  74219. if (dx < 0)
  74220. {
  74221. w += dx;
  74222. sx -= dx;
  74223. dx = 0;
  74224. }
  74225. if (dy < 0)
  74226. {
  74227. h += dy;
  74228. sy -= dy;
  74229. dy = 0;
  74230. }
  74231. if (sx < 0)
  74232. {
  74233. w += sx;
  74234. dx -= sx;
  74235. sx = 0;
  74236. }
  74237. if (sy < 0)
  74238. {
  74239. h += sy;
  74240. dy -= sy;
  74241. sy = 0;
  74242. }
  74243. const int minX = jmin (dx, sx);
  74244. const int minY = jmin (dy, sy);
  74245. w = jmin (w, getWidth() - jmax (sx, dx));
  74246. h = jmin (h, getHeight() - jmax (sy, dy));
  74247. if (w > 0 && h > 0)
  74248. {
  74249. const int maxX = jmax (dx, sx) + w;
  74250. const int maxY = jmax (dy, sy) + h;
  74251. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  74252. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  74253. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  74254. const int lineSize = destData.pixelStride * w;
  74255. if (dy > sy)
  74256. {
  74257. while (--h >= 0)
  74258. {
  74259. const int offset = h * destData.lineStride;
  74260. memmove (dst + offset, src + offset, lineSize);
  74261. }
  74262. }
  74263. else if (dst != src)
  74264. {
  74265. while (--h >= 0)
  74266. {
  74267. memmove (dst, src, lineSize);
  74268. dst += destData.lineStride;
  74269. src += destData.lineStride;
  74270. }
  74271. }
  74272. }
  74273. }
  74274. END_JUCE_NAMESPACE
  74275. /*** End of inlined file: juce_Image.cpp ***/
  74276. /*** Start of inlined file: juce_ImageCache.cpp ***/
  74277. BEGIN_JUCE_NAMESPACE
  74278. struct ImageCacheItem
  74279. {
  74280. ScopedPointer <Image> image;
  74281. int64 hashCode;
  74282. int refCount;
  74283. uint32 releaseTime;
  74284. juce_UseDebuggingNewOperator
  74285. };
  74286. static ImageCache* instance = 0;
  74287. static int cacheTimeout = 5000;
  74288. ImageCache::ImageCache()
  74289. {
  74290. }
  74291. ImageCache::~ImageCache()
  74292. {
  74293. jassert (instance == this);
  74294. instance = 0;
  74295. }
  74296. Image* ImageCache::getFromHashCode (const int64 hashCode)
  74297. {
  74298. if (instance != 0)
  74299. {
  74300. const ScopedLock sl (instance->lock);
  74301. for (int i = instance->images.size(); --i >= 0;)
  74302. {
  74303. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74304. if (ci->hashCode == hashCode)
  74305. {
  74306. ci->refCount++;
  74307. return ci->image;
  74308. }
  74309. }
  74310. }
  74311. return 0;
  74312. }
  74313. void ImageCache::addImageToCache (Image* const image,
  74314. const int64 hashCode)
  74315. {
  74316. if (image != 0)
  74317. {
  74318. if (instance == 0)
  74319. instance = new ImageCache();
  74320. ImageCacheItem* const newC = new ImageCacheItem();
  74321. newC->hashCode = hashCode;
  74322. newC->image = image;
  74323. newC->refCount = 1;
  74324. newC->releaseTime = 0;
  74325. const ScopedLock sl (instance->lock);
  74326. instance->images.add (newC);
  74327. }
  74328. }
  74329. void ImageCache::release (Image* const imageToRelease)
  74330. {
  74331. if (imageToRelease != 0 && instance != 0)
  74332. {
  74333. const ScopedLock sl (instance->lock);
  74334. for (int i = instance->images.size(); --i >= 0;)
  74335. {
  74336. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74337. if ((Image*) ci->image == imageToRelease)
  74338. {
  74339. if (--(ci->refCount) == 0)
  74340. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74341. if (! instance->isTimerRunning())
  74342. instance->startTimer (999);
  74343. break;
  74344. }
  74345. }
  74346. }
  74347. }
  74348. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74349. {
  74350. if (isImageInCache (imageToRelease))
  74351. release (imageToRelease);
  74352. else
  74353. delete imageToRelease;
  74354. }
  74355. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74356. {
  74357. if (instance != 0)
  74358. {
  74359. const ScopedLock sl (instance->lock);
  74360. for (int i = instance->images.size(); --i >= 0;)
  74361. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74362. return true;
  74363. }
  74364. return false;
  74365. }
  74366. void ImageCache::incReferenceCount (Image* const image)
  74367. {
  74368. if (instance != 0)
  74369. {
  74370. const ScopedLock sl (instance->lock);
  74371. for (int i = instance->images.size(); --i >= 0;)
  74372. {
  74373. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74374. if ((Image*) ci->image == image)
  74375. {
  74376. ci->refCount++;
  74377. return;
  74378. }
  74379. }
  74380. }
  74381. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74382. }
  74383. void ImageCache::timerCallback()
  74384. {
  74385. int numberStillNeedingReleasing = 0;
  74386. const unsigned int now = Time::getApproximateMillisecondCounter();
  74387. const ScopedLock sl (lock);
  74388. for (int i = images.size(); --i >= 0;)
  74389. {
  74390. ImageCacheItem* const ci = images.getUnchecked(i);
  74391. if (ci->refCount <= 0)
  74392. {
  74393. if (now > ci->releaseTime + cacheTimeout
  74394. || now < ci->releaseTime - 1000)
  74395. {
  74396. images.remove (i);
  74397. }
  74398. else
  74399. {
  74400. ++numberStillNeedingReleasing;
  74401. }
  74402. }
  74403. }
  74404. if (numberStillNeedingReleasing == 0)
  74405. stopTimer();
  74406. }
  74407. Image* ImageCache::getFromFile (const File& file)
  74408. {
  74409. const int64 hashCode = file.hashCode64();
  74410. Image* image = getFromHashCode (hashCode);
  74411. if (image == 0)
  74412. {
  74413. image = ImageFileFormat::loadFrom (file);
  74414. addImageToCache (image, hashCode);
  74415. }
  74416. return image;
  74417. }
  74418. Image* ImageCache::getFromMemory (const void* imageData,
  74419. const int dataSize)
  74420. {
  74421. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74422. Image* image = getFromHashCode (hashCode);
  74423. if (image == 0)
  74424. {
  74425. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74426. addImageToCache (image, hashCode);
  74427. }
  74428. return image;
  74429. }
  74430. void ImageCache::setCacheTimeout (const int millisecs)
  74431. {
  74432. cacheTimeout = millisecs;
  74433. }
  74434. END_JUCE_NAMESPACE
  74435. /*** End of inlined file: juce_ImageCache.cpp ***/
  74436. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74437. BEGIN_JUCE_NAMESPACE
  74438. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74439. : values (size_ * size_),
  74440. size (size_)
  74441. {
  74442. clear();
  74443. }
  74444. ImageConvolutionKernel::~ImageConvolutionKernel()
  74445. {
  74446. }
  74447. void ImageConvolutionKernel::setKernelValue (const int x,
  74448. const int y,
  74449. const float value)
  74450. {
  74451. if (((unsigned int) x) < (unsigned int) size
  74452. && ((unsigned int) y) < (unsigned int) size)
  74453. {
  74454. values [x + y * size] = value;
  74455. }
  74456. else
  74457. {
  74458. jassertfalse
  74459. }
  74460. }
  74461. void ImageConvolutionKernel::clear()
  74462. {
  74463. for (int i = size * size; --i >= 0;)
  74464. values[i] = 0;
  74465. }
  74466. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74467. {
  74468. double currentTotal = 0.0;
  74469. for (int i = size * size; --i >= 0;)
  74470. currentTotal += values[i];
  74471. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74472. }
  74473. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74474. {
  74475. for (int i = size * size; --i >= 0;)
  74476. values[i] *= multiplier;
  74477. }
  74478. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74479. {
  74480. const double radiusFactor = -1.0 / (radius * radius * 2);
  74481. const int centre = size >> 1;
  74482. for (int y = size; --y >= 0;)
  74483. {
  74484. for (int x = size; --x >= 0;)
  74485. {
  74486. const int cx = x - centre;
  74487. const int cy = y - centre;
  74488. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74489. }
  74490. }
  74491. setOverallSum (1.0f);
  74492. }
  74493. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74494. const Image* sourceImage,
  74495. int dx,
  74496. int dy,
  74497. int dw,
  74498. int dh) const
  74499. {
  74500. ScopedPointer <Image> imageCreated;
  74501. if (sourceImage == 0)
  74502. {
  74503. sourceImage = imageCreated = destImage.createCopy();
  74504. }
  74505. else
  74506. {
  74507. jassert (sourceImage->getWidth() == destImage.getWidth()
  74508. && sourceImage->getHeight() == destImage.getHeight()
  74509. && sourceImage->getFormat() == destImage.getFormat());
  74510. if (sourceImage->getWidth() != destImage.getWidth()
  74511. || sourceImage->getHeight() != destImage.getHeight()
  74512. || sourceImage->getFormat() != destImage.getFormat())
  74513. return;
  74514. }
  74515. const int imageWidth = destImage.getWidth();
  74516. const int imageHeight = destImage.getHeight();
  74517. if (dx >= imageWidth || dy >= imageHeight)
  74518. return;
  74519. if (dx + dw > imageWidth)
  74520. dw = imageWidth - dx;
  74521. if (dy + dh > imageHeight)
  74522. dh = imageHeight - dy;
  74523. const int dx2 = dx + dw;
  74524. const int dy2 = dy + dh;
  74525. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74526. uint8* line = destData.data;
  74527. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74528. if (destData.pixelStride == 4)
  74529. {
  74530. for (int y = dy; y < dy2; ++y)
  74531. {
  74532. uint8* dest = line;
  74533. line += destData.lineStride;
  74534. for (int x = dx; x < dx2; ++x)
  74535. {
  74536. float c1 = 0;
  74537. float c2 = 0;
  74538. float c3 = 0;
  74539. float c4 = 0;
  74540. for (int yy = 0; yy < size; ++yy)
  74541. {
  74542. const int sy = y + yy - (size >> 1);
  74543. if (sy >= imageHeight)
  74544. break;
  74545. if (sy >= 0)
  74546. {
  74547. int sx = x - (size >> 1);
  74548. const uint8* src = srcData.getPixelPointer (sx, sy);
  74549. for (int xx = 0; xx < size; ++xx)
  74550. {
  74551. if (sx >= imageWidth)
  74552. break;
  74553. if (sx >= 0)
  74554. {
  74555. const float kernelMult = values [xx + yy * size];
  74556. c1 += kernelMult * *src++;
  74557. c2 += kernelMult * *src++;
  74558. c3 += kernelMult * *src++;
  74559. c4 += kernelMult * *src++;
  74560. }
  74561. else
  74562. {
  74563. src += 4;
  74564. }
  74565. ++sx;
  74566. }
  74567. }
  74568. }
  74569. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74570. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74571. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74572. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74573. }
  74574. }
  74575. }
  74576. else if (destData.pixelStride == 3)
  74577. {
  74578. for (int y = dy; y < dy2; ++y)
  74579. {
  74580. uint8* dest = line;
  74581. line += destData.lineStride;
  74582. for (int x = dx; x < dx2; ++x)
  74583. {
  74584. float c1 = 0;
  74585. float c2 = 0;
  74586. float c3 = 0;
  74587. for (int yy = 0; yy < size; ++yy)
  74588. {
  74589. const int sy = y + yy - (size >> 1);
  74590. if (sy >= imageHeight)
  74591. break;
  74592. if (sy >= 0)
  74593. {
  74594. int sx = x - (size >> 1);
  74595. const uint8* src = srcData.getPixelPointer (sx, sy);
  74596. for (int xx = 0; xx < size; ++xx)
  74597. {
  74598. if (sx >= imageWidth)
  74599. break;
  74600. if (sx >= 0)
  74601. {
  74602. const float kernelMult = values [xx + yy * size];
  74603. c1 += kernelMult * *src++;
  74604. c2 += kernelMult * *src++;
  74605. c3 += kernelMult * *src++;
  74606. }
  74607. else
  74608. {
  74609. src += 3;
  74610. }
  74611. ++sx;
  74612. }
  74613. }
  74614. }
  74615. *dest++ = (uint8) roundToInt (c1);
  74616. *dest++ = (uint8) roundToInt (c2);
  74617. *dest++ = (uint8) roundToInt (c3);
  74618. }
  74619. }
  74620. }
  74621. }
  74622. END_JUCE_NAMESPACE
  74623. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74624. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74625. BEGIN_JUCE_NAMESPACE
  74626. /*** Start of inlined file: juce_GIFLoader.h ***/
  74627. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74628. #define __JUCE_GIFLOADER_JUCEHEADER__
  74629. #ifndef DOXYGEN
  74630. class GIFLoader
  74631. {
  74632. public:
  74633. GIFLoader (InputStream& in);
  74634. ~GIFLoader();
  74635. Image* getImage() const { return image; }
  74636. private:
  74637. Image* image;
  74638. InputStream& input;
  74639. uint8 buffer [300];
  74640. uint8 palette [256][4];
  74641. bool dataBlockIsZero, fresh, finished;
  74642. int currentBit, lastBit, lastByteIndex;
  74643. int codeSize, setCodeSize;
  74644. int maxCode, maxCodeSize;
  74645. int firstcode, oldcode;
  74646. int clearCode, end_code;
  74647. enum { maxGifCode = 1 << 12 };
  74648. int table [2] [maxGifCode];
  74649. int stack [2 * maxGifCode];
  74650. int *sp;
  74651. bool getSizeFromHeader (int& width, int& height);
  74652. bool readPalette (const int numCols);
  74653. int readDataBlock (unsigned char* dest);
  74654. int processExtension (int type, int& transparent);
  74655. int readLZWByte (bool initialise, int input_code_size);
  74656. int getCode (int code_size, bool initialise);
  74657. bool readImage (int width, int height, int interlace, int transparent);
  74658. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74659. GIFLoader (const GIFLoader&);
  74660. GIFLoader& operator= (const GIFLoader&);
  74661. };
  74662. #endif // DOXYGEN
  74663. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74664. /*** End of inlined file: juce_GIFLoader.h ***/
  74665. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74666. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74667. PNGImageFormat::PNGImageFormat() {}
  74668. PNGImageFormat::~PNGImageFormat() {}
  74669. const String PNGImageFormat::getFormatName()
  74670. {
  74671. return T("PNG");
  74672. }
  74673. bool PNGImageFormat::canUnderstand (InputStream& in)
  74674. {
  74675. const int bytesNeeded = 4;
  74676. char header [bytesNeeded];
  74677. return in.read (header, bytesNeeded) == bytesNeeded
  74678. && header[1] == 'P'
  74679. && header[2] == 'N'
  74680. && header[3] == 'G';
  74681. }
  74682. Image* PNGImageFormat::decodeImage (InputStream& in)
  74683. {
  74684. return juce_loadPNGImageFromStream (in);
  74685. }
  74686. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74687. OutputStream& destStream)
  74688. {
  74689. return juce_writePNGImageToStream (sourceImage, destStream);
  74690. }
  74691. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74692. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74693. JPEGImageFormat::JPEGImageFormat()
  74694. : quality (-1.0f)
  74695. {
  74696. }
  74697. JPEGImageFormat::~JPEGImageFormat() {}
  74698. void JPEGImageFormat::setQuality (const float newQuality)
  74699. {
  74700. quality = newQuality;
  74701. }
  74702. const String JPEGImageFormat::getFormatName()
  74703. {
  74704. return T("JPEG");
  74705. }
  74706. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74707. {
  74708. const int bytesNeeded = 10;
  74709. uint8 header [bytesNeeded];
  74710. if (in.read (header, bytesNeeded) == bytesNeeded)
  74711. {
  74712. return header[0] == 0xff
  74713. && header[1] == 0xd8
  74714. && header[2] == 0xff
  74715. && (header[3] == 0xe0 || header[3] == 0xe1);
  74716. }
  74717. return false;
  74718. }
  74719. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74720. {
  74721. return juce_loadJPEGImageFromStream (in);
  74722. }
  74723. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74724. OutputStream& destStream)
  74725. {
  74726. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74727. }
  74728. class GIFImageFormat : public ImageFileFormat
  74729. {
  74730. public:
  74731. GIFImageFormat() {}
  74732. ~GIFImageFormat() {}
  74733. const String getFormatName()
  74734. {
  74735. return T("GIF");
  74736. }
  74737. bool canUnderstand (InputStream& in)
  74738. {
  74739. const int bytesNeeded = 4;
  74740. char header [bytesNeeded];
  74741. return (in.read (header, bytesNeeded) == bytesNeeded)
  74742. && header[0] == 'G'
  74743. && header[1] == 'I'
  74744. && header[2] == 'F';
  74745. }
  74746. Image* decodeImage (InputStream& in)
  74747. {
  74748. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74749. return loader->getImage();
  74750. }
  74751. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74752. {
  74753. return false;
  74754. }
  74755. };
  74756. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74757. {
  74758. static PNGImageFormat png;
  74759. static JPEGImageFormat jpg;
  74760. static GIFImageFormat gif;
  74761. ImageFileFormat* formats[4];
  74762. int numFormats = 0;
  74763. formats [numFormats++] = &png;
  74764. formats [numFormats++] = &jpg;
  74765. formats [numFormats++] = &gif;
  74766. const int64 streamPos = input.getPosition();
  74767. for (int i = 0; i < numFormats; ++i)
  74768. {
  74769. const bool found = formats[i]->canUnderstand (input);
  74770. input.setPosition (streamPos);
  74771. if (found)
  74772. return formats[i];
  74773. }
  74774. return 0;
  74775. }
  74776. Image* ImageFileFormat::loadFrom (InputStream& input)
  74777. {
  74778. ImageFileFormat* const format = findImageFormatForStream (input);
  74779. if (format != 0)
  74780. return format->decodeImage (input);
  74781. return 0;
  74782. }
  74783. Image* ImageFileFormat::loadFrom (const File& file)
  74784. {
  74785. InputStream* const in = file.createInputStream();
  74786. if (in != 0)
  74787. {
  74788. BufferedInputStream b (in, 8192, true);
  74789. return loadFrom (b);
  74790. }
  74791. return 0;
  74792. }
  74793. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74794. {
  74795. if (rawData != 0 && numBytes > 4)
  74796. {
  74797. MemoryInputStream stream (rawData, numBytes, false);
  74798. return loadFrom (stream);
  74799. }
  74800. return 0;
  74801. }
  74802. END_JUCE_NAMESPACE
  74803. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74804. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74805. BEGIN_JUCE_NAMESPACE
  74806. GIFLoader::GIFLoader (InputStream& in)
  74807. : image (0),
  74808. input (in),
  74809. dataBlockIsZero (false),
  74810. fresh (false),
  74811. finished (false)
  74812. {
  74813. currentBit = lastBit = lastByteIndex = 0;
  74814. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74815. firstcode = oldcode = 0;
  74816. clearCode = end_code = 0;
  74817. int imageWidth, imageHeight;
  74818. int transparent = -1;
  74819. if (! getSizeFromHeader (imageWidth, imageHeight))
  74820. return;
  74821. if ((imageWidth <= 0) || (imageHeight <= 0))
  74822. return;
  74823. unsigned char buf [16];
  74824. if (in.read (buf, 3) != 3)
  74825. return;
  74826. int numColours = 2 << (buf[0] & 7);
  74827. if ((buf[0] & 0x80) != 0)
  74828. readPalette (numColours);
  74829. for (;;)
  74830. {
  74831. if (input.read (buf, 1) != 1)
  74832. break;
  74833. if (buf[0] == ';')
  74834. break;
  74835. if (buf[0] == '!')
  74836. {
  74837. if (input.read (buf, 1) != 1)
  74838. break;
  74839. if (processExtension (buf[0], transparent) < 0)
  74840. break;
  74841. continue;
  74842. }
  74843. if (buf[0] != ',')
  74844. continue;
  74845. if (input.read (buf, 9) != 9)
  74846. break;
  74847. imageWidth = makeWord (buf[4], buf[5]);
  74848. imageHeight = makeWord (buf[6], buf[7]);
  74849. numColours = 2 << (buf[8] & 7);
  74850. if ((buf[8] & 0x80) != 0)
  74851. if (! readPalette (numColours))
  74852. break;
  74853. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74854. imageWidth, imageHeight, (transparent >= 0));
  74855. readImage (imageWidth, imageHeight,
  74856. (buf[8] & 0x40) != 0,
  74857. transparent);
  74858. break;
  74859. }
  74860. }
  74861. GIFLoader::~GIFLoader()
  74862. {
  74863. }
  74864. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74865. {
  74866. unsigned char b [8];
  74867. if (input.read (b, 6) == 6)
  74868. {
  74869. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74870. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74871. {
  74872. if (input.read (b, 4) == 4)
  74873. {
  74874. w = makeWord (b[0], b[1]);
  74875. h = makeWord (b[2], b[3]);
  74876. return true;
  74877. }
  74878. }
  74879. }
  74880. return false;
  74881. }
  74882. bool GIFLoader::readPalette (const int numCols)
  74883. {
  74884. unsigned char rgb[4];
  74885. for (int i = 0; i < numCols; ++i)
  74886. {
  74887. input.read (rgb, 3);
  74888. palette [i][0] = rgb[0];
  74889. palette [i][1] = rgb[1];
  74890. palette [i][2] = rgb[2];
  74891. palette [i][3] = 0xff;
  74892. }
  74893. return true;
  74894. }
  74895. int GIFLoader::readDataBlock (unsigned char* const dest)
  74896. {
  74897. unsigned char n;
  74898. if (input.read (&n, 1) == 1)
  74899. {
  74900. dataBlockIsZero = (n == 0);
  74901. if (dataBlockIsZero || (input.read (dest, n) == n))
  74902. return n;
  74903. }
  74904. return -1;
  74905. }
  74906. int GIFLoader::processExtension (const int type, int& transparent)
  74907. {
  74908. unsigned char b [300];
  74909. int n = 0;
  74910. if (type == 0xf9)
  74911. {
  74912. n = readDataBlock (b);
  74913. if (n < 0)
  74914. return 1;
  74915. if ((b[0] & 0x1) != 0)
  74916. transparent = b[3];
  74917. }
  74918. do
  74919. {
  74920. n = readDataBlock (b);
  74921. }
  74922. while (n > 0);
  74923. return n;
  74924. }
  74925. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74926. {
  74927. if (initialise)
  74928. {
  74929. currentBit = 0;
  74930. lastBit = 0;
  74931. finished = false;
  74932. return 0;
  74933. }
  74934. if ((currentBit + codeSize_) >= lastBit)
  74935. {
  74936. if (finished)
  74937. return -1;
  74938. buffer[0] = buffer [lastByteIndex - 2];
  74939. buffer[1] = buffer [lastByteIndex - 1];
  74940. const int n = readDataBlock (&buffer[2]);
  74941. if (n == 0)
  74942. finished = true;
  74943. lastByteIndex = 2 + n;
  74944. currentBit = (currentBit - lastBit) + 16;
  74945. lastBit = (2 + n) * 8 ;
  74946. }
  74947. int result = 0;
  74948. int i = currentBit;
  74949. for (int j = 0; j < codeSize_; ++j)
  74950. {
  74951. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74952. ++i;
  74953. }
  74954. currentBit += codeSize_;
  74955. return result;
  74956. }
  74957. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74958. {
  74959. int code, incode, i;
  74960. if (initialise)
  74961. {
  74962. setCodeSize = inputCodeSize;
  74963. codeSize = setCodeSize + 1;
  74964. clearCode = 1 << setCodeSize;
  74965. end_code = clearCode + 1;
  74966. maxCodeSize = 2 * clearCode;
  74967. maxCode = clearCode + 2;
  74968. getCode (0, true);
  74969. fresh = true;
  74970. for (i = 0; i < clearCode; ++i)
  74971. {
  74972. table[0][i] = 0;
  74973. table[1][i] = i;
  74974. }
  74975. for (; i < maxGifCode; ++i)
  74976. {
  74977. table[0][i] = 0;
  74978. table[1][i] = 0;
  74979. }
  74980. sp = stack;
  74981. return 0;
  74982. }
  74983. else if (fresh)
  74984. {
  74985. fresh = false;
  74986. do
  74987. {
  74988. firstcode = oldcode
  74989. = getCode (codeSize, false);
  74990. }
  74991. while (firstcode == clearCode);
  74992. return firstcode;
  74993. }
  74994. if (sp > stack)
  74995. return *--sp;
  74996. while ((code = getCode (codeSize, false)) >= 0)
  74997. {
  74998. if (code == clearCode)
  74999. {
  75000. for (i = 0; i < clearCode; ++i)
  75001. {
  75002. table[0][i] = 0;
  75003. table[1][i] = i;
  75004. }
  75005. for (; i < maxGifCode; ++i)
  75006. {
  75007. table[0][i] = 0;
  75008. table[1][i] = 0;
  75009. }
  75010. codeSize = setCodeSize + 1;
  75011. maxCodeSize = 2 * clearCode;
  75012. maxCode = clearCode + 2;
  75013. sp = stack;
  75014. firstcode = oldcode = getCode (codeSize, false);
  75015. return firstcode;
  75016. }
  75017. else if (code == end_code)
  75018. {
  75019. if (dataBlockIsZero)
  75020. return -2;
  75021. unsigned char buf [260];
  75022. int n;
  75023. while ((n = readDataBlock (buf)) > 0)
  75024. {}
  75025. if (n != 0)
  75026. return -2;
  75027. }
  75028. incode = code;
  75029. if (code >= maxCode)
  75030. {
  75031. *sp++ = firstcode;
  75032. code = oldcode;
  75033. }
  75034. while (code >= clearCode)
  75035. {
  75036. *sp++ = table[1][code];
  75037. if (code == table[0][code])
  75038. return -2;
  75039. code = table[0][code];
  75040. }
  75041. *sp++ = firstcode = table[1][code];
  75042. if ((code = maxCode) < maxGifCode)
  75043. {
  75044. table[0][code] = oldcode;
  75045. table[1][code] = firstcode;
  75046. ++maxCode;
  75047. if ((maxCode >= maxCodeSize)
  75048. && (maxCodeSize < maxGifCode))
  75049. {
  75050. maxCodeSize <<= 1;
  75051. ++codeSize;
  75052. }
  75053. }
  75054. oldcode = incode;
  75055. if (sp > stack)
  75056. return *--sp;
  75057. }
  75058. return code;
  75059. }
  75060. bool GIFLoader::readImage (const int width, const int height,
  75061. const int interlace, const int transparent)
  75062. {
  75063. unsigned char c;
  75064. if (input.read (&c, 1) != 1
  75065. || readLZWByte (true, c) < 0)
  75066. return false;
  75067. if (transparent >= 0)
  75068. {
  75069. palette [transparent][0] = 0;
  75070. palette [transparent][1] = 0;
  75071. palette [transparent][2] = 0;
  75072. palette [transparent][3] = 0;
  75073. }
  75074. int index;
  75075. int xpos = 0, ypos = 0, pass = 0;
  75076. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  75077. uint8* p = destData.data;
  75078. const bool hasAlpha = image->hasAlphaChannel();
  75079. while ((index = readLZWByte (false, c)) >= 0)
  75080. {
  75081. const uint8* const paletteEntry = palette [index];
  75082. if (hasAlpha)
  75083. {
  75084. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  75085. paletteEntry[0],
  75086. paletteEntry[1],
  75087. paletteEntry[2]);
  75088. ((PixelARGB*) p)->premultiply();
  75089. }
  75090. else
  75091. {
  75092. ((PixelRGB*) p)->setARGB (0,
  75093. paletteEntry[0],
  75094. paletteEntry[1],
  75095. paletteEntry[2]);
  75096. }
  75097. p += destData.pixelStride;
  75098. ++xpos;
  75099. if (xpos == width)
  75100. {
  75101. xpos = 0;
  75102. if (interlace)
  75103. {
  75104. switch (pass)
  75105. {
  75106. case 0:
  75107. case 1:
  75108. ypos += 8;
  75109. break;
  75110. case 2:
  75111. ypos += 4;
  75112. break;
  75113. case 3:
  75114. ypos += 2;
  75115. break;
  75116. }
  75117. while (ypos >= height)
  75118. {
  75119. ++pass;
  75120. switch (pass)
  75121. {
  75122. case 1:
  75123. ypos = 4;
  75124. break;
  75125. case 2:
  75126. ypos = 2;
  75127. break;
  75128. case 3:
  75129. ypos = 1;
  75130. break;
  75131. default:
  75132. return true;
  75133. }
  75134. }
  75135. }
  75136. else
  75137. {
  75138. ++ypos;
  75139. }
  75140. p = destData.getPixelPointer (xpos, ypos);
  75141. }
  75142. if (ypos >= height)
  75143. break;
  75144. }
  75145. return true;
  75146. }
  75147. END_JUCE_NAMESPACE
  75148. /*** End of inlined file: juce_GIFLoader.cpp ***/
  75149. #endif
  75150. //==============================================================================
  75151. // some files include lots of library code, so leave them to the end to avoid cluttering
  75152. // up the build for the clean files.
  75153. #if JUCE_BUILD_CORE
  75154. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75155. namespace zlibNamespace
  75156. {
  75157. #if JUCE_INCLUDE_ZLIB_CODE
  75158. #undef OS_CODE
  75159. #undef fdopen
  75160. /*** Start of inlined file: zlib.h ***/
  75161. #ifndef ZLIB_H
  75162. #define ZLIB_H
  75163. /*** Start of inlined file: zconf.h ***/
  75164. #ifndef ZCONF_H
  75165. #define ZCONF_H
  75166. // *** Just a few hacks here to make it compile nicely with Juce..
  75167. #define Z_PREFIX 1
  75168. #undef __MACTYPES__
  75169. #ifdef _MSC_VER
  75170. #pragma warning (disable : 4131 4127 4244 4267)
  75171. #endif
  75172. #ifdef Z_PREFIX
  75173. # define deflateInit_ z_deflateInit_
  75174. # define deflate z_deflate
  75175. # define deflateEnd z_deflateEnd
  75176. # define inflateInit_ z_inflateInit_
  75177. # define inflate z_inflate
  75178. # define inflateEnd z_inflateEnd
  75179. # define deflateInit2_ z_deflateInit2_
  75180. # define deflateSetDictionary z_deflateSetDictionary
  75181. # define deflateCopy z_deflateCopy
  75182. # define deflateReset z_deflateReset
  75183. # define deflateParams z_deflateParams
  75184. # define deflateBound z_deflateBound
  75185. # define deflatePrime z_deflatePrime
  75186. # define inflateInit2_ z_inflateInit2_
  75187. # define inflateSetDictionary z_inflateSetDictionary
  75188. # define inflateSync z_inflateSync
  75189. # define inflateSyncPoint z_inflateSyncPoint
  75190. # define inflateCopy z_inflateCopy
  75191. # define inflateReset z_inflateReset
  75192. # define inflateBack z_inflateBack
  75193. # define inflateBackEnd z_inflateBackEnd
  75194. # define compress z_compress
  75195. # define compress2 z_compress2
  75196. # define compressBound z_compressBound
  75197. # define uncompress z_uncompress
  75198. # define adler32 z_adler32
  75199. # define crc32 z_crc32
  75200. # define get_crc_table z_get_crc_table
  75201. # define zError z_zError
  75202. # define alloc_func z_alloc_func
  75203. # define free_func z_free_func
  75204. # define in_func z_in_func
  75205. # define out_func z_out_func
  75206. # define Byte z_Byte
  75207. # define uInt z_uInt
  75208. # define uLong z_uLong
  75209. # define Bytef z_Bytef
  75210. # define charf z_charf
  75211. # define intf z_intf
  75212. # define uIntf z_uIntf
  75213. # define uLongf z_uLongf
  75214. # define voidpf z_voidpf
  75215. # define voidp z_voidp
  75216. #endif
  75217. #if defined(__MSDOS__) && !defined(MSDOS)
  75218. # define MSDOS
  75219. #endif
  75220. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  75221. # define OS2
  75222. #endif
  75223. #if defined(_WINDOWS) && !defined(WINDOWS)
  75224. # define WINDOWS
  75225. #endif
  75226. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  75227. # ifndef WIN32
  75228. # define WIN32
  75229. # endif
  75230. #endif
  75231. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  75232. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  75233. # ifndef SYS16BIT
  75234. # define SYS16BIT
  75235. # endif
  75236. # endif
  75237. #endif
  75238. #ifdef SYS16BIT
  75239. # define MAXSEG_64K
  75240. #endif
  75241. #ifdef MSDOS
  75242. # define UNALIGNED_OK
  75243. #endif
  75244. #ifdef __STDC_VERSION__
  75245. # ifndef STDC
  75246. # define STDC
  75247. # endif
  75248. # if __STDC_VERSION__ >= 199901L
  75249. # ifndef STDC99
  75250. # define STDC99
  75251. # endif
  75252. # endif
  75253. #endif
  75254. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  75255. # define STDC
  75256. #endif
  75257. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  75258. # define STDC
  75259. #endif
  75260. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  75261. # define STDC
  75262. #endif
  75263. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  75264. # define STDC
  75265. #endif
  75266. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  75267. # define STDC
  75268. #endif
  75269. #ifndef STDC
  75270. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  75271. # define const /* note: need a more gentle solution here */
  75272. # endif
  75273. #endif
  75274. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  75275. # define NO_DUMMY_DECL
  75276. #endif
  75277. #ifndef MAX_MEM_LEVEL
  75278. # ifdef MAXSEG_64K
  75279. # define MAX_MEM_LEVEL 8
  75280. # else
  75281. # define MAX_MEM_LEVEL 9
  75282. # endif
  75283. #endif
  75284. #ifndef MAX_WBITS
  75285. # define MAX_WBITS 15 /* 32K LZ77 window */
  75286. #endif
  75287. #ifndef OF /* function prototypes */
  75288. # ifdef STDC
  75289. # define OF(args) args
  75290. # else
  75291. # define OF(args) ()
  75292. # endif
  75293. #endif
  75294. #ifdef SYS16BIT
  75295. # if defined(M_I86SM) || defined(M_I86MM)
  75296. # define SMALL_MEDIUM
  75297. # ifdef _MSC_VER
  75298. # define FAR _far
  75299. # else
  75300. # define FAR far
  75301. # endif
  75302. # endif
  75303. # if (defined(__SMALL__) || defined(__MEDIUM__))
  75304. # define SMALL_MEDIUM
  75305. # ifdef __BORLANDC__
  75306. # define FAR _far
  75307. # else
  75308. # define FAR far
  75309. # endif
  75310. # endif
  75311. #endif
  75312. #if defined(WINDOWS) || defined(WIN32)
  75313. # ifdef ZLIB_DLL
  75314. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  75315. # ifdef ZLIB_INTERNAL
  75316. # define ZEXTERN extern __declspec(dllexport)
  75317. # else
  75318. # define ZEXTERN extern __declspec(dllimport)
  75319. # endif
  75320. # endif
  75321. # endif /* ZLIB_DLL */
  75322. # ifdef ZLIB_WINAPI
  75323. # ifdef FAR
  75324. # undef FAR
  75325. # endif
  75326. # include <windows.h>
  75327. # define ZEXPORT WINAPI
  75328. # ifdef WIN32
  75329. # define ZEXPORTVA WINAPIV
  75330. # else
  75331. # define ZEXPORTVA FAR CDECL
  75332. # endif
  75333. # endif
  75334. #endif
  75335. #if defined (__BEOS__)
  75336. # ifdef ZLIB_DLL
  75337. # ifdef ZLIB_INTERNAL
  75338. # define ZEXPORT __declspec(dllexport)
  75339. # define ZEXPORTVA __declspec(dllexport)
  75340. # else
  75341. # define ZEXPORT __declspec(dllimport)
  75342. # define ZEXPORTVA __declspec(dllimport)
  75343. # endif
  75344. # endif
  75345. #endif
  75346. #ifndef ZEXTERN
  75347. # define ZEXTERN extern
  75348. #endif
  75349. #ifndef ZEXPORT
  75350. # define ZEXPORT
  75351. #endif
  75352. #ifndef ZEXPORTVA
  75353. # define ZEXPORTVA
  75354. #endif
  75355. #ifndef FAR
  75356. # define FAR
  75357. #endif
  75358. #if !defined(__MACTYPES__)
  75359. typedef unsigned char Byte; /* 8 bits */
  75360. #endif
  75361. typedef unsigned int uInt; /* 16 bits or more */
  75362. typedef unsigned long uLong; /* 32 bits or more */
  75363. #ifdef SMALL_MEDIUM
  75364. # define Bytef Byte FAR
  75365. #else
  75366. typedef Byte FAR Bytef;
  75367. #endif
  75368. typedef char FAR charf;
  75369. typedef int FAR intf;
  75370. typedef uInt FAR uIntf;
  75371. typedef uLong FAR uLongf;
  75372. #ifdef STDC
  75373. typedef void const *voidpc;
  75374. typedef void FAR *voidpf;
  75375. typedef void *voidp;
  75376. #else
  75377. typedef Byte const *voidpc;
  75378. typedef Byte FAR *voidpf;
  75379. typedef Byte *voidp;
  75380. #endif
  75381. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75382. # include <sys/types.h> /* for off_t */
  75383. # include <unistd.h> /* for SEEK_* and off_t */
  75384. # ifdef VMS
  75385. # include <unixio.h> /* for off_t */
  75386. # endif
  75387. # define z_off_t off_t
  75388. #endif
  75389. #ifndef SEEK_SET
  75390. # define SEEK_SET 0 /* Seek from beginning of file. */
  75391. # define SEEK_CUR 1 /* Seek from current position. */
  75392. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75393. #endif
  75394. #ifndef z_off_t
  75395. # define z_off_t long
  75396. #endif
  75397. #if defined(__OS400__)
  75398. # define NO_vsnprintf
  75399. #endif
  75400. #if defined(__MVS__)
  75401. # define NO_vsnprintf
  75402. # ifdef FAR
  75403. # undef FAR
  75404. # endif
  75405. #endif
  75406. #if defined(__MVS__)
  75407. # pragma map(deflateInit_,"DEIN")
  75408. # pragma map(deflateInit2_,"DEIN2")
  75409. # pragma map(deflateEnd,"DEEND")
  75410. # pragma map(deflateBound,"DEBND")
  75411. # pragma map(inflateInit_,"ININ")
  75412. # pragma map(inflateInit2_,"ININ2")
  75413. # pragma map(inflateEnd,"INEND")
  75414. # pragma map(inflateSync,"INSY")
  75415. # pragma map(inflateSetDictionary,"INSEDI")
  75416. # pragma map(compressBound,"CMBND")
  75417. # pragma map(inflate_table,"INTABL")
  75418. # pragma map(inflate_fast,"INFA")
  75419. # pragma map(inflate_copyright,"INCOPY")
  75420. #endif
  75421. #endif /* ZCONF_H */
  75422. /*** End of inlined file: zconf.h ***/
  75423. #ifdef __cplusplus
  75424. extern "C" {
  75425. #endif
  75426. #define ZLIB_VERSION "1.2.3"
  75427. #define ZLIB_VERNUM 0x1230
  75428. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75429. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75430. struct internal_state;
  75431. typedef struct z_stream_s {
  75432. Bytef *next_in; /* next input byte */
  75433. uInt avail_in; /* number of bytes available at next_in */
  75434. uLong total_in; /* total nb of input bytes read so far */
  75435. Bytef *next_out; /* next output byte should be put there */
  75436. uInt avail_out; /* remaining free space at next_out */
  75437. uLong total_out; /* total nb of bytes output so far */
  75438. char *msg; /* last error message, NULL if no error */
  75439. struct internal_state FAR *state; /* not visible by applications */
  75440. alloc_func zalloc; /* used to allocate the internal state */
  75441. free_func zfree; /* used to free the internal state */
  75442. voidpf opaque; /* private data object passed to zalloc and zfree */
  75443. int data_type; /* best guess about the data type: binary or text */
  75444. uLong adler; /* adler32 value of the uncompressed data */
  75445. uLong reserved; /* reserved for future use */
  75446. } z_stream;
  75447. typedef z_stream FAR *z_streamp;
  75448. typedef struct gz_header_s {
  75449. int text; /* true if compressed data believed to be text */
  75450. uLong time; /* modification time */
  75451. int xflags; /* extra flags (not used when writing a gzip file) */
  75452. int os; /* operating system */
  75453. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75454. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75455. uInt extra_max; /* space at extra (only when reading header) */
  75456. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75457. uInt name_max; /* space at name (only when reading header) */
  75458. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75459. uInt comm_max; /* space at comment (only when reading header) */
  75460. int hcrc; /* true if there was or will be a header crc */
  75461. int done; /* true when done reading gzip header (not used
  75462. when writing a gzip file) */
  75463. } gz_header;
  75464. typedef gz_header FAR *gz_headerp;
  75465. #define Z_NO_FLUSH 0
  75466. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75467. #define Z_SYNC_FLUSH 2
  75468. #define Z_FULL_FLUSH 3
  75469. #define Z_FINISH 4
  75470. #define Z_BLOCK 5
  75471. #define Z_OK 0
  75472. #define Z_STREAM_END 1
  75473. #define Z_NEED_DICT 2
  75474. #define Z_ERRNO (-1)
  75475. #define Z_STREAM_ERROR (-2)
  75476. #define Z_DATA_ERROR (-3)
  75477. #define Z_MEM_ERROR (-4)
  75478. #define Z_BUF_ERROR (-5)
  75479. #define Z_VERSION_ERROR (-6)
  75480. #define Z_NO_COMPRESSION 0
  75481. #define Z_BEST_SPEED 1
  75482. #define Z_BEST_COMPRESSION 9
  75483. #define Z_DEFAULT_COMPRESSION (-1)
  75484. #define Z_FILTERED 1
  75485. #define Z_HUFFMAN_ONLY 2
  75486. #define Z_RLE 3
  75487. #define Z_FIXED 4
  75488. #define Z_DEFAULT_STRATEGY 0
  75489. #define Z_BINARY 0
  75490. #define Z_TEXT 1
  75491. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75492. #define Z_UNKNOWN 2
  75493. #define Z_DEFLATED 8
  75494. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75495. #define zlib_version zlibVersion()
  75496. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75497. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75498. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75499. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75500. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75501. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75502. const Bytef *dictionary,
  75503. uInt dictLength));
  75504. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75505. z_streamp source));
  75506. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75507. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75508. int level,
  75509. int strategy));
  75510. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75511. int good_length,
  75512. int max_lazy,
  75513. int nice_length,
  75514. int max_chain));
  75515. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75516. uLong sourceLen));
  75517. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75518. int bits,
  75519. int value));
  75520. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75521. gz_headerp head));
  75522. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75523. const Bytef *dictionary,
  75524. uInt dictLength));
  75525. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75526. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75527. z_streamp source));
  75528. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75529. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75530. int bits,
  75531. int value));
  75532. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75533. gz_headerp head));
  75534. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75535. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75536. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75537. in_func in, void FAR *in_desc,
  75538. out_func out, void FAR *out_desc));
  75539. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75540. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75541. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75542. const Bytef *source, uLong sourceLen));
  75543. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75544. const Bytef *source, uLong sourceLen,
  75545. int level));
  75546. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75547. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75548. const Bytef *source, uLong sourceLen));
  75549. typedef voidp gzFile;
  75550. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75551. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75552. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75553. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75554. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75555. voidpc buf, unsigned len));
  75556. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75557. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75558. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75559. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75560. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75561. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75562. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75563. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75564. z_off_t offset, int whence));
  75565. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75566. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75567. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75568. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75569. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75570. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75571. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75572. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75573. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75574. z_off_t len2));
  75575. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75576. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75577. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75578. const char *version, int stream_size));
  75579. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75580. const char *version, int stream_size));
  75581. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75582. int windowBits, int memLevel,
  75583. int strategy, const char *version,
  75584. int stream_size));
  75585. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75586. const char *version, int stream_size));
  75587. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75588. unsigned char FAR *window,
  75589. const char *version,
  75590. int stream_size));
  75591. #define deflateInit(strm, level) \
  75592. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75593. #define inflateInit(strm) \
  75594. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75595. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75596. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75597. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75598. #define inflateInit2(strm, windowBits) \
  75599. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75600. #define inflateBackInit(strm, windowBits, window) \
  75601. inflateBackInit_((strm), (windowBits), (window), \
  75602. ZLIB_VERSION, sizeof(z_stream))
  75603. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75604. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75605. #endif
  75606. ZEXTERN const char * ZEXPORT zError OF((int));
  75607. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75608. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75609. #ifdef __cplusplus
  75610. }
  75611. #endif
  75612. #endif /* ZLIB_H */
  75613. /*** End of inlined file: zlib.h ***/
  75614. #undef OS_CODE
  75615. #else
  75616. #include <zlib.h>
  75617. #endif
  75618. }
  75619. BEGIN_JUCE_NAMESPACE
  75620. using namespace zlibNamespace;
  75621. // internal helper object that holds the zlib structures so they don't have to be
  75622. // included publicly.
  75623. class GZIPCompressorHelper
  75624. {
  75625. public:
  75626. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75627. : data (0),
  75628. dataSize (0),
  75629. compLevel (compressionLevel),
  75630. strategy (0),
  75631. setParams (true),
  75632. streamIsValid (false),
  75633. finished (false),
  75634. shouldFinish (false)
  75635. {
  75636. zerostruct (stream);
  75637. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75638. nowrap ? -MAX_WBITS : MAX_WBITS,
  75639. 8, strategy) == Z_OK);
  75640. }
  75641. ~GZIPCompressorHelper()
  75642. {
  75643. if (streamIsValid)
  75644. deflateEnd (&stream);
  75645. }
  75646. bool needsInput() const throw()
  75647. {
  75648. return dataSize <= 0;
  75649. }
  75650. void setInput (uint8* const newData, const int size) throw()
  75651. {
  75652. data = newData;
  75653. dataSize = size;
  75654. }
  75655. int doNextBlock (uint8* const dest, const int destSize) throw()
  75656. {
  75657. if (streamIsValid)
  75658. {
  75659. stream.next_in = data;
  75660. stream.next_out = dest;
  75661. stream.avail_in = dataSize;
  75662. stream.avail_out = destSize;
  75663. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75664. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75665. setParams = false;
  75666. switch (result)
  75667. {
  75668. case Z_STREAM_END:
  75669. finished = true;
  75670. // Deliberate fall-through..
  75671. case Z_OK:
  75672. data += dataSize - stream.avail_in;
  75673. dataSize = stream.avail_in;
  75674. return destSize - stream.avail_out;
  75675. default:
  75676. break;
  75677. }
  75678. }
  75679. return 0;
  75680. }
  75681. private:
  75682. z_stream stream;
  75683. uint8* data;
  75684. int dataSize, compLevel, strategy;
  75685. bool setParams, streamIsValid;
  75686. public:
  75687. bool finished, shouldFinish;
  75688. };
  75689. const int gzipCompBufferSize = 32768;
  75690. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75691. int compressionLevel,
  75692. const bool deleteDestStream,
  75693. const bool noWrap)
  75694. : destStream (destStream_),
  75695. streamToDelete (deleteDestStream ? destStream_ : 0),
  75696. buffer (gzipCompBufferSize)
  75697. {
  75698. if (compressionLevel < 1 || compressionLevel > 9)
  75699. compressionLevel = -1;
  75700. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75701. }
  75702. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75703. {
  75704. flush();
  75705. }
  75706. void GZIPCompressorOutputStream::flush()
  75707. {
  75708. if (! helper->finished)
  75709. {
  75710. helper->shouldFinish = true;
  75711. while (! helper->finished)
  75712. doNextBlock();
  75713. }
  75714. destStream->flush();
  75715. }
  75716. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75717. {
  75718. if (! helper->finished)
  75719. {
  75720. helper->setInput ((uint8*) destBuffer, howMany);
  75721. while (! helper->needsInput())
  75722. {
  75723. if (! doNextBlock())
  75724. return false;
  75725. }
  75726. }
  75727. return true;
  75728. }
  75729. bool GZIPCompressorOutputStream::doNextBlock()
  75730. {
  75731. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75732. if (len > 0)
  75733. return destStream->write (buffer, len);
  75734. else
  75735. return true;
  75736. }
  75737. int64 GZIPCompressorOutputStream::getPosition()
  75738. {
  75739. return destStream->getPosition();
  75740. }
  75741. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75742. {
  75743. jassertfalse // can't do it!
  75744. return false;
  75745. }
  75746. END_JUCE_NAMESPACE
  75747. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75748. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75749. #if JUCE_MSVC
  75750. #pragma warning (push)
  75751. #pragma warning (disable: 4309 4305)
  75752. #endif
  75753. namespace zlibNamespace
  75754. {
  75755. #if JUCE_INCLUDE_ZLIB_CODE
  75756. extern "C"
  75757. {
  75758. #undef OS_CODE
  75759. #undef fdopen
  75760. #define ZLIB_INTERNAL
  75761. #define NO_DUMMY_DECL
  75762. /*** Start of inlined file: adler32.c ***/
  75763. #define ZLIB_INTERNAL
  75764. #define BASE 65521UL /* largest prime smaller than 65536 */
  75765. #define NMAX 5552
  75766. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75767. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75768. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75769. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75770. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75771. #ifdef NO_DIVIDE
  75772. # define MOD(a) \
  75773. do { \
  75774. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75775. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75776. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75777. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75778. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75779. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75780. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75781. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75782. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75783. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75784. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75785. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75786. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75787. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75788. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75789. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75790. if (a >= BASE) a -= BASE; \
  75791. } while (0)
  75792. # define MOD4(a) \
  75793. do { \
  75794. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75795. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75796. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75797. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75798. if (a >= BASE) a -= BASE; \
  75799. } while (0)
  75800. #else
  75801. # define MOD(a) a %= BASE
  75802. # define MOD4(a) a %= BASE
  75803. #endif
  75804. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75805. {
  75806. unsigned long sum2;
  75807. unsigned n;
  75808. sum2 = (adler >> 16) & 0xffff;
  75809. adler &= 0xffff;
  75810. if (len == 1) {
  75811. adler += buf[0];
  75812. if (adler >= BASE)
  75813. adler -= BASE;
  75814. sum2 += adler;
  75815. if (sum2 >= BASE)
  75816. sum2 -= BASE;
  75817. return adler | (sum2 << 16);
  75818. }
  75819. if (buf == Z_NULL)
  75820. return 1L;
  75821. if (len < 16) {
  75822. while (len--) {
  75823. adler += *buf++;
  75824. sum2 += adler;
  75825. }
  75826. if (adler >= BASE)
  75827. adler -= BASE;
  75828. MOD4(sum2); /* only added so many BASE's */
  75829. return adler | (sum2 << 16);
  75830. }
  75831. while (len >= NMAX) {
  75832. len -= NMAX;
  75833. n = NMAX / 16; /* NMAX is divisible by 16 */
  75834. do {
  75835. DO16(buf); /* 16 sums unrolled */
  75836. buf += 16;
  75837. } while (--n);
  75838. MOD(adler);
  75839. MOD(sum2);
  75840. }
  75841. if (len) { /* avoid modulos if none remaining */
  75842. while (len >= 16) {
  75843. len -= 16;
  75844. DO16(buf);
  75845. buf += 16;
  75846. }
  75847. while (len--) {
  75848. adler += *buf++;
  75849. sum2 += adler;
  75850. }
  75851. MOD(adler);
  75852. MOD(sum2);
  75853. }
  75854. return adler | (sum2 << 16);
  75855. }
  75856. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75857. {
  75858. unsigned long sum1;
  75859. unsigned long sum2;
  75860. unsigned rem;
  75861. rem = (unsigned)(len2 % BASE);
  75862. sum1 = adler1 & 0xffff;
  75863. sum2 = rem * sum1;
  75864. MOD(sum2);
  75865. sum1 += (adler2 & 0xffff) + BASE - 1;
  75866. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75867. if (sum1 > BASE) sum1 -= BASE;
  75868. if (sum1 > BASE) sum1 -= BASE;
  75869. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75870. if (sum2 > BASE) sum2 -= BASE;
  75871. return sum1 | (sum2 << 16);
  75872. }
  75873. /*** End of inlined file: adler32.c ***/
  75874. /*** Start of inlined file: compress.c ***/
  75875. #define ZLIB_INTERNAL
  75876. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75877. uLong sourceLen, int level)
  75878. {
  75879. z_stream stream;
  75880. int err;
  75881. stream.next_in = (Bytef*)source;
  75882. stream.avail_in = (uInt)sourceLen;
  75883. #ifdef MAXSEG_64K
  75884. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75885. #endif
  75886. stream.next_out = dest;
  75887. stream.avail_out = (uInt)*destLen;
  75888. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75889. stream.zalloc = (alloc_func)0;
  75890. stream.zfree = (free_func)0;
  75891. stream.opaque = (voidpf)0;
  75892. err = deflateInit(&stream, level);
  75893. if (err != Z_OK) return err;
  75894. err = deflate(&stream, Z_FINISH);
  75895. if (err != Z_STREAM_END) {
  75896. deflateEnd(&stream);
  75897. return err == Z_OK ? Z_BUF_ERROR : err;
  75898. }
  75899. *destLen = stream.total_out;
  75900. err = deflateEnd(&stream);
  75901. return err;
  75902. }
  75903. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75904. {
  75905. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75906. }
  75907. uLong ZEXPORT compressBound (uLong sourceLen)
  75908. {
  75909. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75910. }
  75911. /*** End of inlined file: compress.c ***/
  75912. #undef DO1
  75913. #undef DO8
  75914. /*** Start of inlined file: crc32.c ***/
  75915. #ifdef MAKECRCH
  75916. # include <stdio.h>
  75917. # ifndef DYNAMIC_CRC_TABLE
  75918. # define DYNAMIC_CRC_TABLE
  75919. # endif /* !DYNAMIC_CRC_TABLE */
  75920. #endif /* MAKECRCH */
  75921. /*** Start of inlined file: zutil.h ***/
  75922. #ifndef ZUTIL_H
  75923. #define ZUTIL_H
  75924. #define ZLIB_INTERNAL
  75925. #ifdef STDC
  75926. # ifndef _WIN32_WCE
  75927. # include <stddef.h>
  75928. # endif
  75929. # include <string.h>
  75930. # include <stdlib.h>
  75931. #endif
  75932. #ifdef NO_ERRNO_H
  75933. # ifdef _WIN32_WCE
  75934. # define errno z_errno
  75935. # endif
  75936. extern int errno;
  75937. #else
  75938. # ifndef _WIN32_WCE
  75939. # include <errno.h>
  75940. # endif
  75941. #endif
  75942. #ifndef local
  75943. # define local static
  75944. #endif
  75945. typedef unsigned char uch;
  75946. typedef uch FAR uchf;
  75947. typedef unsigned short ush;
  75948. typedef ush FAR ushf;
  75949. typedef unsigned long ulg;
  75950. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75951. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75952. #define ERR_RETURN(strm,err) \
  75953. return (strm->msg = (char*)ERR_MSG(err), (err))
  75954. #ifndef DEF_WBITS
  75955. # define DEF_WBITS MAX_WBITS
  75956. #endif
  75957. #if MAX_MEM_LEVEL >= 8
  75958. # define DEF_MEM_LEVEL 8
  75959. #else
  75960. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75961. #endif
  75962. #define STORED_BLOCK 0
  75963. #define STATIC_TREES 1
  75964. #define DYN_TREES 2
  75965. #define MIN_MATCH 3
  75966. #define MAX_MATCH 258
  75967. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75968. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75969. # define OS_CODE 0x00
  75970. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75971. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75972. void _Cdecl farfree( void *block );
  75973. void *_Cdecl farmalloc( unsigned long nbytes );
  75974. # else
  75975. # include <alloc.h>
  75976. # endif
  75977. # else /* MSC or DJGPP */
  75978. # include <malloc.h>
  75979. # endif
  75980. #endif
  75981. #ifdef AMIGA
  75982. # define OS_CODE 0x01
  75983. #endif
  75984. #if defined(VAXC) || defined(VMS)
  75985. # define OS_CODE 0x02
  75986. # define F_OPEN(name, mode) \
  75987. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75988. #endif
  75989. #if defined(ATARI) || defined(atarist)
  75990. # define OS_CODE 0x05
  75991. #endif
  75992. #ifdef OS2
  75993. # define OS_CODE 0x06
  75994. # ifdef M_I86
  75995. #include <malloc.h>
  75996. # endif
  75997. #endif
  75998. #if defined(MACOS) || TARGET_OS_MAC
  75999. # define OS_CODE 0x07
  76000. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  76001. # include <unix.h> /* for fdopen */
  76002. # else
  76003. # ifndef fdopen
  76004. # define fdopen(fd,mode) NULL /* No fdopen() */
  76005. # endif
  76006. # endif
  76007. #endif
  76008. #ifdef TOPS20
  76009. # define OS_CODE 0x0a
  76010. #endif
  76011. #ifdef WIN32
  76012. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  76013. # define OS_CODE 0x0b
  76014. # endif
  76015. #endif
  76016. #ifdef __50SERIES /* Prime/PRIMOS */
  76017. # define OS_CODE 0x0f
  76018. #endif
  76019. #if defined(_BEOS_) || defined(RISCOS)
  76020. # define fdopen(fd,mode) NULL /* No fdopen() */
  76021. #endif
  76022. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  76023. # if defined(_WIN32_WCE)
  76024. # define fdopen(fd,mode) NULL /* No fdopen() */
  76025. # ifndef _PTRDIFF_T_DEFINED
  76026. typedef int ptrdiff_t;
  76027. # define _PTRDIFF_T_DEFINED
  76028. # endif
  76029. # else
  76030. # define fdopen(fd,type) _fdopen(fd,type)
  76031. # endif
  76032. #endif
  76033. #ifndef OS_CODE
  76034. # define OS_CODE 0x03 /* assume Unix */
  76035. #endif
  76036. #ifndef F_OPEN
  76037. # define F_OPEN(name, mode) fopen((name), (mode))
  76038. #endif
  76039. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  76040. # ifndef HAVE_VSNPRINTF
  76041. # define HAVE_VSNPRINTF
  76042. # endif
  76043. #endif
  76044. #if defined(__CYGWIN__)
  76045. # ifndef HAVE_VSNPRINTF
  76046. # define HAVE_VSNPRINTF
  76047. # endif
  76048. #endif
  76049. #ifndef HAVE_VSNPRINTF
  76050. # ifdef MSDOS
  76051. # define NO_vsnprintf
  76052. # endif
  76053. # ifdef __TURBOC__
  76054. # define NO_vsnprintf
  76055. # endif
  76056. # ifdef WIN32
  76057. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  76058. # define vsnprintf _vsnprintf
  76059. # endif
  76060. # endif
  76061. # ifdef __SASC
  76062. # define NO_vsnprintf
  76063. # endif
  76064. #endif
  76065. #ifdef VMS
  76066. # define NO_vsnprintf
  76067. #endif
  76068. #if defined(pyr)
  76069. # define NO_MEMCPY
  76070. #endif
  76071. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  76072. # define NO_MEMCPY
  76073. #endif
  76074. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  76075. # define HAVE_MEMCPY
  76076. #endif
  76077. #ifdef HAVE_MEMCPY
  76078. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  76079. # define zmemcpy _fmemcpy
  76080. # define zmemcmp _fmemcmp
  76081. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  76082. # else
  76083. # define zmemcpy memcpy
  76084. # define zmemcmp memcmp
  76085. # define zmemzero(dest, len) memset(dest, 0, len)
  76086. # endif
  76087. #else
  76088. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  76089. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  76090. extern void zmemzero OF((Bytef* dest, uInt len));
  76091. #endif
  76092. #ifdef DEBUG
  76093. # include <stdio.h>
  76094. extern int z_verbose;
  76095. extern void z_error OF((const char *m));
  76096. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  76097. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  76098. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  76099. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  76100. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  76101. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  76102. #else
  76103. # define Assert(cond,msg)
  76104. # define Trace(x)
  76105. # define Tracev(x)
  76106. # define Tracevv(x)
  76107. # define Tracec(c,x)
  76108. # define Tracecv(c,x)
  76109. #endif
  76110. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  76111. void zcfree OF((voidpf opaque, voidpf ptr));
  76112. #define ZALLOC(strm, items, size) \
  76113. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  76114. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  76115. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  76116. #endif /* ZUTIL_H */
  76117. /*** End of inlined file: zutil.h ***/
  76118. /* for STDC and FAR definitions */
  76119. #define local static
  76120. #ifndef NOBYFOUR
  76121. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  76122. # include <limits.h>
  76123. # define BYFOUR
  76124. # if (UINT_MAX == 0xffffffffUL)
  76125. typedef unsigned int u4;
  76126. # else
  76127. # if (ULONG_MAX == 0xffffffffUL)
  76128. typedef unsigned long u4;
  76129. # else
  76130. # if (USHRT_MAX == 0xffffffffUL)
  76131. typedef unsigned short u4;
  76132. # else
  76133. # undef BYFOUR /* can't find a four-byte integer type! */
  76134. # endif
  76135. # endif
  76136. # endif
  76137. # endif /* STDC */
  76138. #endif /* !NOBYFOUR */
  76139. #ifdef BYFOUR
  76140. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  76141. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  76142. local unsigned long crc32_little OF((unsigned long,
  76143. const unsigned char FAR *, unsigned));
  76144. local unsigned long crc32_big OF((unsigned long,
  76145. const unsigned char FAR *, unsigned));
  76146. # define TBLS 8
  76147. #else
  76148. # define TBLS 1
  76149. #endif /* BYFOUR */
  76150. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  76151. unsigned long vec));
  76152. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  76153. #ifdef DYNAMIC_CRC_TABLE
  76154. local volatile int crc_table_empty = 1;
  76155. local unsigned long FAR crc_table[TBLS][256];
  76156. local void make_crc_table OF((void));
  76157. #ifdef MAKECRCH
  76158. local void write_table OF((FILE *, const unsigned long FAR *));
  76159. #endif /* MAKECRCH */
  76160. local void make_crc_table()
  76161. {
  76162. unsigned long c;
  76163. int n, k;
  76164. unsigned long poly; /* polynomial exclusive-or pattern */
  76165. static volatile int first = 1; /* flag to limit concurrent making */
  76166. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  76167. if (first) {
  76168. first = 0;
  76169. poly = 0UL;
  76170. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  76171. poly |= 1UL << (31 - p[n]);
  76172. for (n = 0; n < 256; n++) {
  76173. c = (unsigned long)n;
  76174. for (k = 0; k < 8; k++)
  76175. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  76176. crc_table[0][n] = c;
  76177. }
  76178. #ifdef BYFOUR
  76179. for (n = 0; n < 256; n++) {
  76180. c = crc_table[0][n];
  76181. crc_table[4][n] = REV(c);
  76182. for (k = 1; k < 4; k++) {
  76183. c = crc_table[0][c & 0xff] ^ (c >> 8);
  76184. crc_table[k][n] = c;
  76185. crc_table[k + 4][n] = REV(c);
  76186. }
  76187. }
  76188. #endif /* BYFOUR */
  76189. crc_table_empty = 0;
  76190. }
  76191. else { /* not first */
  76192. while (crc_table_empty)
  76193. ;
  76194. }
  76195. #ifdef MAKECRCH
  76196. {
  76197. FILE *out;
  76198. out = fopen("crc32.h", "w");
  76199. if (out == NULL) return;
  76200. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  76201. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  76202. fprintf(out, "local const unsigned long FAR ");
  76203. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  76204. write_table(out, crc_table[0]);
  76205. # ifdef BYFOUR
  76206. fprintf(out, "#ifdef BYFOUR\n");
  76207. for (k = 1; k < 8; k++) {
  76208. fprintf(out, " },\n {\n");
  76209. write_table(out, crc_table[k]);
  76210. }
  76211. fprintf(out, "#endif\n");
  76212. # endif /* BYFOUR */
  76213. fprintf(out, " }\n};\n");
  76214. fclose(out);
  76215. }
  76216. #endif /* MAKECRCH */
  76217. }
  76218. #ifdef MAKECRCH
  76219. local void write_table(out, table)
  76220. FILE *out;
  76221. const unsigned long FAR *table;
  76222. {
  76223. int n;
  76224. for (n = 0; n < 256; n++)
  76225. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  76226. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  76227. }
  76228. #endif /* MAKECRCH */
  76229. #else /* !DYNAMIC_CRC_TABLE */
  76230. /*** Start of inlined file: crc32.h ***/
  76231. local const unsigned long FAR crc_table[TBLS][256] =
  76232. {
  76233. {
  76234. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  76235. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  76236. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  76237. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  76238. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  76239. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  76240. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  76241. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  76242. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  76243. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  76244. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  76245. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  76246. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  76247. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  76248. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  76249. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  76250. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  76251. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  76252. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  76253. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  76254. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  76255. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  76256. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  76257. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  76258. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  76259. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  76260. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  76261. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  76262. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  76263. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  76264. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  76265. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  76266. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  76267. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  76268. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  76269. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  76270. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  76271. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  76272. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  76273. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  76274. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  76275. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  76276. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  76277. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  76278. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  76279. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  76280. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  76281. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  76282. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  76283. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  76284. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  76285. 0x2d02ef8dUL
  76286. #ifdef BYFOUR
  76287. },
  76288. {
  76289. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  76290. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  76291. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  76292. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  76293. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  76294. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  76295. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  76296. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  76297. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  76298. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  76299. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  76300. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  76301. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  76302. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  76303. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  76304. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  76305. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  76306. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  76307. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  76308. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  76309. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  76310. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  76311. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  76312. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  76313. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  76314. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  76315. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  76316. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  76317. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  76318. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  76319. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  76320. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  76321. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  76322. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76323. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76324. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76325. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76326. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76327. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76328. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76329. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76330. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76331. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76332. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76333. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76334. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76335. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76336. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76337. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76338. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76339. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76340. 0x9324fd72UL
  76341. },
  76342. {
  76343. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76344. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76345. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76346. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76347. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76348. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76349. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76350. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76351. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76352. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76353. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76354. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76355. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76356. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76357. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76358. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76359. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76360. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76361. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76362. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76363. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76364. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76365. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76366. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76367. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76368. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76369. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76370. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76371. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76372. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76373. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76374. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76375. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76376. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76377. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76378. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76379. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76380. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76381. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76382. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76383. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76384. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76385. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76386. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76387. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76388. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76389. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76390. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76391. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76392. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76393. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76394. 0xbe9834edUL
  76395. },
  76396. {
  76397. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76398. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76399. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76400. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76401. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76402. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76403. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76404. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76405. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76406. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76407. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76408. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76409. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76410. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76411. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76412. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76413. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76414. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76415. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76416. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76417. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76418. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76419. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76420. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76421. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76422. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76423. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76424. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76425. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76426. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76427. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76428. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76429. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76430. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76431. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76432. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76433. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76434. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76435. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76436. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76437. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76438. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76439. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76440. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76441. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76442. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76443. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76444. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76445. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76446. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76447. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76448. 0xde0506f1UL
  76449. },
  76450. {
  76451. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76452. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76453. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76454. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76455. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76456. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76457. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76458. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76459. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76460. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76461. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76462. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76463. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76464. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76465. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76466. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76467. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76468. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76469. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76470. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76471. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76472. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76473. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76474. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76475. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76476. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76477. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76478. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76479. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76480. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76481. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76482. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76483. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76484. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76485. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76486. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76487. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76488. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76489. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76490. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76491. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76492. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76493. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76494. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76495. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76496. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76497. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76498. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76499. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76500. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76501. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76502. 0x8def022dUL
  76503. },
  76504. {
  76505. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76506. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76507. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76508. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76509. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76510. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76511. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76512. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76513. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76514. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76515. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76516. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76517. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76518. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76519. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76520. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76521. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76522. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76523. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76524. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76525. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76526. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76527. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76528. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76529. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76530. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76531. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76532. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76533. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76534. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76535. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76536. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76537. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76538. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76539. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76540. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76541. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76542. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76543. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76544. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76545. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76546. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76547. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76548. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76549. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76550. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76551. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76552. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76553. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76554. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76555. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76556. 0x72fd2493UL
  76557. },
  76558. {
  76559. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76560. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76561. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76562. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76563. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76564. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76565. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76566. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76567. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76568. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76569. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76570. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76571. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76572. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76573. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76574. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76575. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76576. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76577. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76578. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76579. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76580. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76581. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76582. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76583. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76584. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76585. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76586. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76587. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76588. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76589. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76590. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76591. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76592. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76593. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76594. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76595. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76596. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76597. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76598. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76599. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76600. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76601. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76602. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76603. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76604. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76605. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76606. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76607. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76608. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76609. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76610. 0xed3498beUL
  76611. },
  76612. {
  76613. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76614. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76615. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76616. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76617. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76618. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76619. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76620. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76621. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76622. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76623. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76624. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76625. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76626. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76627. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76628. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76629. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76630. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76631. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76632. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76633. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76634. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76635. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76636. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76637. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76638. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76639. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76640. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76641. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76642. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76643. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76644. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76645. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76646. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76647. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76648. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76649. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76650. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76651. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76652. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76653. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76654. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76655. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76656. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76657. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76658. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76659. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76660. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76661. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76662. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76663. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76664. 0xf10605deUL
  76665. #endif
  76666. }
  76667. };
  76668. /*** End of inlined file: crc32.h ***/
  76669. #endif /* DYNAMIC_CRC_TABLE */
  76670. const unsigned long FAR * ZEXPORT get_crc_table()
  76671. {
  76672. #ifdef DYNAMIC_CRC_TABLE
  76673. if (crc_table_empty)
  76674. make_crc_table();
  76675. #endif /* DYNAMIC_CRC_TABLE */
  76676. return (const unsigned long FAR *)crc_table;
  76677. }
  76678. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76679. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76680. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76681. {
  76682. if (buf == Z_NULL) return 0UL;
  76683. #ifdef DYNAMIC_CRC_TABLE
  76684. if (crc_table_empty)
  76685. make_crc_table();
  76686. #endif /* DYNAMIC_CRC_TABLE */
  76687. #ifdef BYFOUR
  76688. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76689. u4 endian;
  76690. endian = 1;
  76691. if (*((unsigned char *)(&endian)))
  76692. return crc32_little(crc, buf, len);
  76693. else
  76694. return crc32_big(crc, buf, len);
  76695. }
  76696. #endif /* BYFOUR */
  76697. crc = crc ^ 0xffffffffUL;
  76698. while (len >= 8) {
  76699. DO8;
  76700. len -= 8;
  76701. }
  76702. if (len) do {
  76703. DO1;
  76704. } while (--len);
  76705. return crc ^ 0xffffffffUL;
  76706. }
  76707. #ifdef BYFOUR
  76708. #define DOLIT4 c ^= *buf4++; \
  76709. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76710. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76711. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76712. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76713. {
  76714. register u4 c;
  76715. register const u4 FAR *buf4;
  76716. c = (u4)crc;
  76717. c = ~c;
  76718. while (len && ((ptrdiff_t)buf & 3)) {
  76719. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76720. len--;
  76721. }
  76722. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76723. while (len >= 32) {
  76724. DOLIT32;
  76725. len -= 32;
  76726. }
  76727. while (len >= 4) {
  76728. DOLIT4;
  76729. len -= 4;
  76730. }
  76731. buf = (const unsigned char FAR *)buf4;
  76732. if (len) do {
  76733. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76734. } while (--len);
  76735. c = ~c;
  76736. return (unsigned long)c;
  76737. }
  76738. #define DOBIG4 c ^= *++buf4; \
  76739. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76740. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76741. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76742. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76743. {
  76744. register u4 c;
  76745. register const u4 FAR *buf4;
  76746. c = REV((u4)crc);
  76747. c = ~c;
  76748. while (len && ((ptrdiff_t)buf & 3)) {
  76749. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76750. len--;
  76751. }
  76752. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76753. buf4--;
  76754. while (len >= 32) {
  76755. DOBIG32;
  76756. len -= 32;
  76757. }
  76758. while (len >= 4) {
  76759. DOBIG4;
  76760. len -= 4;
  76761. }
  76762. buf4++;
  76763. buf = (const unsigned char FAR *)buf4;
  76764. if (len) do {
  76765. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76766. } while (--len);
  76767. c = ~c;
  76768. return (unsigned long)(REV(c));
  76769. }
  76770. #endif /* BYFOUR */
  76771. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76772. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76773. {
  76774. unsigned long sum;
  76775. sum = 0;
  76776. while (vec) {
  76777. if (vec & 1)
  76778. sum ^= *mat;
  76779. vec >>= 1;
  76780. mat++;
  76781. }
  76782. return sum;
  76783. }
  76784. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76785. {
  76786. int n;
  76787. for (n = 0; n < GF2_DIM; n++)
  76788. square[n] = gf2_matrix_times(mat, mat[n]);
  76789. }
  76790. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76791. {
  76792. int n;
  76793. unsigned long row;
  76794. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76795. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76796. if (len2 == 0)
  76797. return crc1;
  76798. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76799. row = 1;
  76800. for (n = 1; n < GF2_DIM; n++) {
  76801. odd[n] = row;
  76802. row <<= 1;
  76803. }
  76804. gf2_matrix_square(even, odd);
  76805. gf2_matrix_square(odd, even);
  76806. do {
  76807. gf2_matrix_square(even, odd);
  76808. if (len2 & 1)
  76809. crc1 = gf2_matrix_times(even, crc1);
  76810. len2 >>= 1;
  76811. if (len2 == 0)
  76812. break;
  76813. gf2_matrix_square(odd, even);
  76814. if (len2 & 1)
  76815. crc1 = gf2_matrix_times(odd, crc1);
  76816. len2 >>= 1;
  76817. } while (len2 != 0);
  76818. crc1 ^= crc2;
  76819. return crc1;
  76820. }
  76821. /*** End of inlined file: crc32.c ***/
  76822. /*** Start of inlined file: deflate.c ***/
  76823. /*** Start of inlined file: deflate.h ***/
  76824. #ifndef DEFLATE_H
  76825. #define DEFLATE_H
  76826. #ifndef NO_GZIP
  76827. # define GZIP
  76828. #endif
  76829. #define NO_DUMMY_DECL
  76830. #define LENGTH_CODES 29
  76831. #define LITERALS 256
  76832. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76833. #define D_CODES 30
  76834. #define BL_CODES 19
  76835. #define HEAP_SIZE (2*L_CODES+1)
  76836. #define MAX_BITS 15
  76837. #define INIT_STATE 42
  76838. #define EXTRA_STATE 69
  76839. #define NAME_STATE 73
  76840. #define COMMENT_STATE 91
  76841. #define HCRC_STATE 103
  76842. #define BUSY_STATE 113
  76843. #define FINISH_STATE 666
  76844. typedef struct ct_data_s {
  76845. union {
  76846. ush freq; /* frequency count */
  76847. ush code; /* bit string */
  76848. } fc;
  76849. union {
  76850. ush dad; /* father node in Huffman tree */
  76851. ush len; /* length of bit string */
  76852. } dl;
  76853. } FAR ct_data;
  76854. #define Freq fc.freq
  76855. #define Code fc.code
  76856. #define Dad dl.dad
  76857. #define Len dl.len
  76858. typedef struct static_tree_desc_s static_tree_desc;
  76859. typedef struct tree_desc_s {
  76860. ct_data *dyn_tree; /* the dynamic tree */
  76861. int max_code; /* largest code with non zero frequency */
  76862. static_tree_desc *stat_desc; /* the corresponding static tree */
  76863. } FAR tree_desc;
  76864. typedef ush Pos;
  76865. typedef Pos FAR Posf;
  76866. typedef unsigned IPos;
  76867. typedef struct internal_state {
  76868. z_streamp strm; /* pointer back to this zlib stream */
  76869. int status; /* as the name implies */
  76870. Bytef *pending_buf; /* output still pending */
  76871. ulg pending_buf_size; /* size of pending_buf */
  76872. Bytef *pending_out; /* next pending byte to output to the stream */
  76873. uInt pending; /* nb of bytes in the pending buffer */
  76874. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76875. gz_headerp gzhead; /* gzip header information to write */
  76876. uInt gzindex; /* where in extra, name, or comment */
  76877. Byte method; /* STORED (for zip only) or DEFLATED */
  76878. int last_flush; /* value of flush param for previous deflate call */
  76879. uInt w_size; /* LZ77 window size (32K by default) */
  76880. uInt w_bits; /* log2(w_size) (8..16) */
  76881. uInt w_mask; /* w_size - 1 */
  76882. Bytef *window;
  76883. ulg window_size;
  76884. Posf *prev;
  76885. Posf *head; /* Heads of the hash chains or NIL. */
  76886. uInt ins_h; /* hash index of string to be inserted */
  76887. uInt hash_size; /* number of elements in hash table */
  76888. uInt hash_bits; /* log2(hash_size) */
  76889. uInt hash_mask; /* hash_size-1 */
  76890. uInt hash_shift;
  76891. long block_start;
  76892. uInt match_length; /* length of best match */
  76893. IPos prev_match; /* previous match */
  76894. int match_available; /* set if previous match exists */
  76895. uInt strstart; /* start of string to insert */
  76896. uInt match_start; /* start of matching string */
  76897. uInt lookahead; /* number of valid bytes ahead in window */
  76898. uInt prev_length;
  76899. uInt max_chain_length;
  76900. uInt max_lazy_match;
  76901. # define max_insert_length max_lazy_match
  76902. int level; /* compression level (1..9) */
  76903. int strategy; /* favor or force Huffman coding*/
  76904. uInt good_match;
  76905. int nice_match; /* Stop searching when current match exceeds this */
  76906. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76907. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76908. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76909. struct tree_desc_s l_desc; /* desc. for literal tree */
  76910. struct tree_desc_s d_desc; /* desc. for distance tree */
  76911. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76912. ush bl_count[MAX_BITS+1];
  76913. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76914. int heap_len; /* number of elements in the heap */
  76915. int heap_max; /* element of largest frequency */
  76916. uch depth[2*L_CODES+1];
  76917. uchf *l_buf; /* buffer for literals or lengths */
  76918. uInt lit_bufsize;
  76919. uInt last_lit; /* running index in l_buf */
  76920. ushf *d_buf;
  76921. ulg opt_len; /* bit length of current block with optimal trees */
  76922. ulg static_len; /* bit length of current block with static trees */
  76923. uInt matches; /* number of string matches in current block */
  76924. int last_eob_len; /* bit length of EOB code for last block */
  76925. #ifdef DEBUG
  76926. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76927. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76928. #endif
  76929. ush bi_buf;
  76930. int bi_valid;
  76931. } FAR deflate_state;
  76932. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76933. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76934. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76935. void _tr_init OF((deflate_state *s));
  76936. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76937. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76938. int eof));
  76939. void _tr_align OF((deflate_state *s));
  76940. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76941. int eof));
  76942. #define d_code(dist) \
  76943. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76944. #ifndef DEBUG
  76945. #if defined(GEN_TREES_H) || !defined(STDC)
  76946. extern uch _length_code[];
  76947. extern uch _dist_code[];
  76948. #else
  76949. extern const uch _length_code[];
  76950. extern const uch _dist_code[];
  76951. #endif
  76952. # define _tr_tally_lit(s, c, flush) \
  76953. { uch cc = (c); \
  76954. s->d_buf[s->last_lit] = 0; \
  76955. s->l_buf[s->last_lit++] = cc; \
  76956. s->dyn_ltree[cc].Freq++; \
  76957. flush = (s->last_lit == s->lit_bufsize-1); \
  76958. }
  76959. # define _tr_tally_dist(s, distance, length, flush) \
  76960. { uch len = (length); \
  76961. ush dist = (distance); \
  76962. s->d_buf[s->last_lit] = dist; \
  76963. s->l_buf[s->last_lit++] = len; \
  76964. dist--; \
  76965. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76966. s->dyn_dtree[d_code(dist)].Freq++; \
  76967. flush = (s->last_lit == s->lit_bufsize-1); \
  76968. }
  76969. #else
  76970. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76971. # define _tr_tally_dist(s, distance, length, flush) \
  76972. flush = _tr_tally(s, distance, length)
  76973. #endif
  76974. #endif /* DEFLATE_H */
  76975. /*** End of inlined file: deflate.h ***/
  76976. const char deflate_copyright[] =
  76977. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76978. typedef enum {
  76979. need_more, /* block not completed, need more input or more output */
  76980. block_done, /* block flush performed */
  76981. finish_started, /* finish started, need only more output at next deflate */
  76982. finish_done /* finish done, accept no more input or output */
  76983. } block_state;
  76984. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76985. local void fill_window OF((deflate_state *s));
  76986. local block_state deflate_stored OF((deflate_state *s, int flush));
  76987. local block_state deflate_fast OF((deflate_state *s, int flush));
  76988. #ifndef FASTEST
  76989. local block_state deflate_slow OF((deflate_state *s, int flush));
  76990. #endif
  76991. local void lm_init OF((deflate_state *s));
  76992. local void putShortMSB OF((deflate_state *s, uInt b));
  76993. local void flush_pending OF((z_streamp strm));
  76994. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76995. #ifndef FASTEST
  76996. #ifdef ASMV
  76997. void match_init OF((void)); /* asm code initialization */
  76998. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76999. #else
  77000. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  77001. #endif
  77002. #endif
  77003. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  77004. #ifdef DEBUG
  77005. local void check_match OF((deflate_state *s, IPos start, IPos match,
  77006. int length));
  77007. #endif
  77008. #define NIL 0
  77009. #ifndef TOO_FAR
  77010. # define TOO_FAR 4096
  77011. #endif
  77012. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77013. typedef struct config_s {
  77014. ush good_length; /* reduce lazy search above this match length */
  77015. ush max_lazy; /* do not perform lazy search above this match length */
  77016. ush nice_length; /* quit search above this match length */
  77017. ush max_chain;
  77018. compress_func func;
  77019. } config;
  77020. #ifdef FASTEST
  77021. local const config configuration_table[2] = {
  77022. {0, 0, 0, 0, deflate_stored}, /* store only */
  77023. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  77024. #else
  77025. local const config configuration_table[10] = {
  77026. {0, 0, 0, 0, deflate_stored}, /* store only */
  77027. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  77028. {4, 5, 16, 8, deflate_fast},
  77029. {4, 6, 32, 32, deflate_fast},
  77030. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  77031. {8, 16, 32, 32, deflate_slow},
  77032. {8, 16, 128, 128, deflate_slow},
  77033. {8, 32, 128, 256, deflate_slow},
  77034. {32, 128, 258, 1024, deflate_slow},
  77035. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  77036. #endif
  77037. #define EQUAL 0
  77038. #ifndef NO_DUMMY_DECL
  77039. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  77040. #endif
  77041. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  77042. #ifdef FASTEST
  77043. #define INSERT_STRING(s, str, match_head) \
  77044. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77045. match_head = s->head[s->ins_h], \
  77046. s->head[s->ins_h] = (Pos)(str))
  77047. #else
  77048. #define INSERT_STRING(s, str, match_head) \
  77049. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77050. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  77051. s->head[s->ins_h] = (Pos)(str))
  77052. #endif
  77053. #define CLEAR_HASH(s) \
  77054. s->head[s->hash_size-1] = NIL; \
  77055. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  77056. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  77057. {
  77058. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  77059. Z_DEFAULT_STRATEGY, version, stream_size);
  77060. }
  77061. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  77062. {
  77063. deflate_state *s;
  77064. int wrap = 1;
  77065. static const char my_version[] = ZLIB_VERSION;
  77066. ushf *overlay;
  77067. if (version == Z_NULL || version[0] != my_version[0] ||
  77068. stream_size != sizeof(z_stream)) {
  77069. return Z_VERSION_ERROR;
  77070. }
  77071. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77072. strm->msg = Z_NULL;
  77073. if (strm->zalloc == (alloc_func)0) {
  77074. strm->zalloc = zcalloc;
  77075. strm->opaque = (voidpf)0;
  77076. }
  77077. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77078. #ifdef FASTEST
  77079. if (level != 0) level = 1;
  77080. #else
  77081. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77082. #endif
  77083. if (windowBits < 0) { /* suppress zlib wrapper */
  77084. wrap = 0;
  77085. windowBits = -windowBits;
  77086. }
  77087. #ifdef GZIP
  77088. else if (windowBits > 15) {
  77089. wrap = 2; /* write gzip wrapper instead */
  77090. windowBits -= 16;
  77091. }
  77092. #endif
  77093. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  77094. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  77095. strategy < 0 || strategy > Z_FIXED) {
  77096. return Z_STREAM_ERROR;
  77097. }
  77098. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  77099. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  77100. if (s == Z_NULL) return Z_MEM_ERROR;
  77101. strm->state = (struct internal_state FAR *)s;
  77102. s->strm = strm;
  77103. s->wrap = wrap;
  77104. s->gzhead = Z_NULL;
  77105. s->w_bits = windowBits;
  77106. s->w_size = 1 << s->w_bits;
  77107. s->w_mask = s->w_size - 1;
  77108. s->hash_bits = memLevel + 7;
  77109. s->hash_size = 1 << s->hash_bits;
  77110. s->hash_mask = s->hash_size - 1;
  77111. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  77112. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  77113. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  77114. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  77115. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  77116. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  77117. s->pending_buf = (uchf *) overlay;
  77118. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  77119. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  77120. s->pending_buf == Z_NULL) {
  77121. s->status = FINISH_STATE;
  77122. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  77123. deflateEnd (strm);
  77124. return Z_MEM_ERROR;
  77125. }
  77126. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  77127. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  77128. s->level = level;
  77129. s->strategy = strategy;
  77130. s->method = (Byte)method;
  77131. return deflateReset(strm);
  77132. }
  77133. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  77134. {
  77135. deflate_state *s;
  77136. uInt length = dictLength;
  77137. uInt n;
  77138. IPos hash_head = 0;
  77139. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  77140. strm->state->wrap == 2 ||
  77141. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  77142. return Z_STREAM_ERROR;
  77143. s = strm->state;
  77144. if (s->wrap)
  77145. strm->adler = adler32(strm->adler, dictionary, dictLength);
  77146. if (length < MIN_MATCH) return Z_OK;
  77147. if (length > MAX_DIST(s)) {
  77148. length = MAX_DIST(s);
  77149. dictionary += dictLength - length; /* use the tail of the dictionary */
  77150. }
  77151. zmemcpy(s->window, dictionary, length);
  77152. s->strstart = length;
  77153. s->block_start = (long)length;
  77154. s->ins_h = s->window[0];
  77155. UPDATE_HASH(s, s->ins_h, s->window[1]);
  77156. for (n = 0; n <= length - MIN_MATCH; n++) {
  77157. INSERT_STRING(s, n, hash_head);
  77158. }
  77159. if (hash_head) hash_head = 0; /* to make compiler happy */
  77160. return Z_OK;
  77161. }
  77162. int ZEXPORT deflateReset (z_streamp strm)
  77163. {
  77164. deflate_state *s;
  77165. if (strm == Z_NULL || strm->state == Z_NULL ||
  77166. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  77167. return Z_STREAM_ERROR;
  77168. }
  77169. strm->total_in = strm->total_out = 0;
  77170. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  77171. strm->data_type = Z_UNKNOWN;
  77172. s = (deflate_state *)strm->state;
  77173. s->pending = 0;
  77174. s->pending_out = s->pending_buf;
  77175. if (s->wrap < 0) {
  77176. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  77177. }
  77178. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  77179. strm->adler =
  77180. #ifdef GZIP
  77181. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  77182. #endif
  77183. adler32(0L, Z_NULL, 0);
  77184. s->last_flush = Z_NO_FLUSH;
  77185. _tr_init(s);
  77186. lm_init(s);
  77187. return Z_OK;
  77188. }
  77189. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  77190. {
  77191. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77192. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  77193. strm->state->gzhead = head;
  77194. return Z_OK;
  77195. }
  77196. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  77197. {
  77198. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77199. strm->state->bi_valid = bits;
  77200. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  77201. return Z_OK;
  77202. }
  77203. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  77204. {
  77205. deflate_state *s;
  77206. compress_func func;
  77207. int err = Z_OK;
  77208. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77209. s = strm->state;
  77210. #ifdef FASTEST
  77211. if (level != 0) level = 1;
  77212. #else
  77213. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77214. #endif
  77215. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  77216. return Z_STREAM_ERROR;
  77217. }
  77218. func = configuration_table[s->level].func;
  77219. if (func != configuration_table[level].func && strm->total_in != 0) {
  77220. err = deflate(strm, Z_PARTIAL_FLUSH);
  77221. }
  77222. if (s->level != level) {
  77223. s->level = level;
  77224. s->max_lazy_match = configuration_table[level].max_lazy;
  77225. s->good_match = configuration_table[level].good_length;
  77226. s->nice_match = configuration_table[level].nice_length;
  77227. s->max_chain_length = configuration_table[level].max_chain;
  77228. }
  77229. s->strategy = strategy;
  77230. return err;
  77231. }
  77232. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  77233. {
  77234. deflate_state *s;
  77235. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77236. s = strm->state;
  77237. s->good_match = good_length;
  77238. s->max_lazy_match = max_lazy;
  77239. s->nice_match = nice_length;
  77240. s->max_chain_length = max_chain;
  77241. return Z_OK;
  77242. }
  77243. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  77244. {
  77245. deflate_state *s;
  77246. uLong destLen;
  77247. destLen = sourceLen +
  77248. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  77249. if (strm == Z_NULL || strm->state == Z_NULL)
  77250. return destLen;
  77251. s = strm->state;
  77252. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  77253. return destLen;
  77254. return compressBound(sourceLen);
  77255. }
  77256. local void putShortMSB (deflate_state *s, uInt b)
  77257. {
  77258. put_byte(s, (Byte)(b >> 8));
  77259. put_byte(s, (Byte)(b & 0xff));
  77260. }
  77261. local void flush_pending (z_streamp strm)
  77262. {
  77263. unsigned len = strm->state->pending;
  77264. if (len > strm->avail_out) len = strm->avail_out;
  77265. if (len == 0) return;
  77266. zmemcpy(strm->next_out, strm->state->pending_out, len);
  77267. strm->next_out += len;
  77268. strm->state->pending_out += len;
  77269. strm->total_out += len;
  77270. strm->avail_out -= len;
  77271. strm->state->pending -= len;
  77272. if (strm->state->pending == 0) {
  77273. strm->state->pending_out = strm->state->pending_buf;
  77274. }
  77275. }
  77276. int ZEXPORT deflate (z_streamp strm, int flush)
  77277. {
  77278. int old_flush; /* value of flush param for previous deflate call */
  77279. deflate_state *s;
  77280. if (strm == Z_NULL || strm->state == Z_NULL ||
  77281. flush > Z_FINISH || flush < 0) {
  77282. return Z_STREAM_ERROR;
  77283. }
  77284. s = strm->state;
  77285. if (strm->next_out == Z_NULL ||
  77286. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  77287. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  77288. ERR_RETURN(strm, Z_STREAM_ERROR);
  77289. }
  77290. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  77291. s->strm = strm; /* just in case */
  77292. old_flush = s->last_flush;
  77293. s->last_flush = flush;
  77294. if (s->status == INIT_STATE) {
  77295. #ifdef GZIP
  77296. if (s->wrap == 2) {
  77297. strm->adler = crc32(0L, Z_NULL, 0);
  77298. put_byte(s, 31);
  77299. put_byte(s, 139);
  77300. put_byte(s, 8);
  77301. if (s->gzhead == NULL) {
  77302. put_byte(s, 0);
  77303. put_byte(s, 0);
  77304. put_byte(s, 0);
  77305. put_byte(s, 0);
  77306. put_byte(s, 0);
  77307. put_byte(s, s->level == 9 ? 2 :
  77308. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77309. 4 : 0));
  77310. put_byte(s, OS_CODE);
  77311. s->status = BUSY_STATE;
  77312. }
  77313. else {
  77314. put_byte(s, (s->gzhead->text ? 1 : 0) +
  77315. (s->gzhead->hcrc ? 2 : 0) +
  77316. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  77317. (s->gzhead->name == Z_NULL ? 0 : 8) +
  77318. (s->gzhead->comment == Z_NULL ? 0 : 16)
  77319. );
  77320. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  77321. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  77322. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77323. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77324. put_byte(s, s->level == 9 ? 2 :
  77325. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77326. 4 : 0));
  77327. put_byte(s, s->gzhead->os & 0xff);
  77328. if (s->gzhead->extra != NULL) {
  77329. put_byte(s, s->gzhead->extra_len & 0xff);
  77330. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77331. }
  77332. if (s->gzhead->hcrc)
  77333. strm->adler = crc32(strm->adler, s->pending_buf,
  77334. s->pending);
  77335. s->gzindex = 0;
  77336. s->status = EXTRA_STATE;
  77337. }
  77338. }
  77339. else
  77340. #endif
  77341. {
  77342. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77343. uInt level_flags;
  77344. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77345. level_flags = 0;
  77346. else if (s->level < 6)
  77347. level_flags = 1;
  77348. else if (s->level == 6)
  77349. level_flags = 2;
  77350. else
  77351. level_flags = 3;
  77352. header |= (level_flags << 6);
  77353. if (s->strstart != 0) header |= PRESET_DICT;
  77354. header += 31 - (header % 31);
  77355. s->status = BUSY_STATE;
  77356. putShortMSB(s, header);
  77357. if (s->strstart != 0) {
  77358. putShortMSB(s, (uInt)(strm->adler >> 16));
  77359. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77360. }
  77361. strm->adler = adler32(0L, Z_NULL, 0);
  77362. }
  77363. }
  77364. #ifdef GZIP
  77365. if (s->status == EXTRA_STATE) {
  77366. if (s->gzhead->extra != NULL) {
  77367. uInt beg = s->pending; /* start of bytes to update crc */
  77368. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77369. if (s->pending == s->pending_buf_size) {
  77370. if (s->gzhead->hcrc && s->pending > beg)
  77371. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77372. s->pending - beg);
  77373. flush_pending(strm);
  77374. beg = s->pending;
  77375. if (s->pending == s->pending_buf_size)
  77376. break;
  77377. }
  77378. put_byte(s, s->gzhead->extra[s->gzindex]);
  77379. s->gzindex++;
  77380. }
  77381. if (s->gzhead->hcrc && s->pending > beg)
  77382. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77383. s->pending - beg);
  77384. if (s->gzindex == s->gzhead->extra_len) {
  77385. s->gzindex = 0;
  77386. s->status = NAME_STATE;
  77387. }
  77388. }
  77389. else
  77390. s->status = NAME_STATE;
  77391. }
  77392. if (s->status == NAME_STATE) {
  77393. if (s->gzhead->name != NULL) {
  77394. uInt beg = s->pending; /* start of bytes to update crc */
  77395. int val;
  77396. do {
  77397. if (s->pending == s->pending_buf_size) {
  77398. if (s->gzhead->hcrc && s->pending > beg)
  77399. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77400. s->pending - beg);
  77401. flush_pending(strm);
  77402. beg = s->pending;
  77403. if (s->pending == s->pending_buf_size) {
  77404. val = 1;
  77405. break;
  77406. }
  77407. }
  77408. val = s->gzhead->name[s->gzindex++];
  77409. put_byte(s, val);
  77410. } while (val != 0);
  77411. if (s->gzhead->hcrc && s->pending > beg)
  77412. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77413. s->pending - beg);
  77414. if (val == 0) {
  77415. s->gzindex = 0;
  77416. s->status = COMMENT_STATE;
  77417. }
  77418. }
  77419. else
  77420. s->status = COMMENT_STATE;
  77421. }
  77422. if (s->status == COMMENT_STATE) {
  77423. if (s->gzhead->comment != NULL) {
  77424. uInt beg = s->pending; /* start of bytes to update crc */
  77425. int val;
  77426. do {
  77427. if (s->pending == s->pending_buf_size) {
  77428. if (s->gzhead->hcrc && s->pending > beg)
  77429. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77430. s->pending - beg);
  77431. flush_pending(strm);
  77432. beg = s->pending;
  77433. if (s->pending == s->pending_buf_size) {
  77434. val = 1;
  77435. break;
  77436. }
  77437. }
  77438. val = s->gzhead->comment[s->gzindex++];
  77439. put_byte(s, val);
  77440. } while (val != 0);
  77441. if (s->gzhead->hcrc && s->pending > beg)
  77442. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77443. s->pending - beg);
  77444. if (val == 0)
  77445. s->status = HCRC_STATE;
  77446. }
  77447. else
  77448. s->status = HCRC_STATE;
  77449. }
  77450. if (s->status == HCRC_STATE) {
  77451. if (s->gzhead->hcrc) {
  77452. if (s->pending + 2 > s->pending_buf_size)
  77453. flush_pending(strm);
  77454. if (s->pending + 2 <= s->pending_buf_size) {
  77455. put_byte(s, (Byte)(strm->adler & 0xff));
  77456. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77457. strm->adler = crc32(0L, Z_NULL, 0);
  77458. s->status = BUSY_STATE;
  77459. }
  77460. }
  77461. else
  77462. s->status = BUSY_STATE;
  77463. }
  77464. #endif
  77465. if (s->pending != 0) {
  77466. flush_pending(strm);
  77467. if (strm->avail_out == 0) {
  77468. s->last_flush = -1;
  77469. return Z_OK;
  77470. }
  77471. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77472. flush != Z_FINISH) {
  77473. ERR_RETURN(strm, Z_BUF_ERROR);
  77474. }
  77475. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77476. ERR_RETURN(strm, Z_BUF_ERROR);
  77477. }
  77478. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77479. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77480. block_state bstate;
  77481. bstate = (*(configuration_table[s->level].func))(s, flush);
  77482. if (bstate == finish_started || bstate == finish_done) {
  77483. s->status = FINISH_STATE;
  77484. }
  77485. if (bstate == need_more || bstate == finish_started) {
  77486. if (strm->avail_out == 0) {
  77487. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77488. }
  77489. return Z_OK;
  77490. }
  77491. if (bstate == block_done) {
  77492. if (flush == Z_PARTIAL_FLUSH) {
  77493. _tr_align(s);
  77494. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77495. _tr_stored_block(s, (char*)0, 0L, 0);
  77496. if (flush == Z_FULL_FLUSH) {
  77497. CLEAR_HASH(s); /* forget history */
  77498. }
  77499. }
  77500. flush_pending(strm);
  77501. if (strm->avail_out == 0) {
  77502. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77503. return Z_OK;
  77504. }
  77505. }
  77506. }
  77507. Assert(strm->avail_out > 0, "bug2");
  77508. if (flush != Z_FINISH) return Z_OK;
  77509. if (s->wrap <= 0) return Z_STREAM_END;
  77510. #ifdef GZIP
  77511. if (s->wrap == 2) {
  77512. put_byte(s, (Byte)(strm->adler & 0xff));
  77513. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77514. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77515. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77516. put_byte(s, (Byte)(strm->total_in & 0xff));
  77517. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77518. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77519. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77520. }
  77521. else
  77522. #endif
  77523. {
  77524. putShortMSB(s, (uInt)(strm->adler >> 16));
  77525. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77526. }
  77527. flush_pending(strm);
  77528. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77529. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77530. }
  77531. int ZEXPORT deflateEnd (z_streamp strm)
  77532. {
  77533. int status;
  77534. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77535. status = strm->state->status;
  77536. if (status != INIT_STATE &&
  77537. status != EXTRA_STATE &&
  77538. status != NAME_STATE &&
  77539. status != COMMENT_STATE &&
  77540. status != HCRC_STATE &&
  77541. status != BUSY_STATE &&
  77542. status != FINISH_STATE) {
  77543. return Z_STREAM_ERROR;
  77544. }
  77545. TRY_FREE(strm, strm->state->pending_buf);
  77546. TRY_FREE(strm, strm->state->head);
  77547. TRY_FREE(strm, strm->state->prev);
  77548. TRY_FREE(strm, strm->state->window);
  77549. ZFREE(strm, strm->state);
  77550. strm->state = Z_NULL;
  77551. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77552. }
  77553. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77554. {
  77555. #ifdef MAXSEG_64K
  77556. return Z_STREAM_ERROR;
  77557. #else
  77558. deflate_state *ds;
  77559. deflate_state *ss;
  77560. ushf *overlay;
  77561. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77562. return Z_STREAM_ERROR;
  77563. }
  77564. ss = source->state;
  77565. zmemcpy(dest, source, sizeof(z_stream));
  77566. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77567. if (ds == Z_NULL) return Z_MEM_ERROR;
  77568. dest->state = (struct internal_state FAR *) ds;
  77569. zmemcpy(ds, ss, sizeof(deflate_state));
  77570. ds->strm = dest;
  77571. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77572. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77573. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77574. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77575. ds->pending_buf = (uchf *) overlay;
  77576. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77577. ds->pending_buf == Z_NULL) {
  77578. deflateEnd (dest);
  77579. return Z_MEM_ERROR;
  77580. }
  77581. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77582. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77583. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77584. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77585. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77586. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77587. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77588. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77589. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77590. ds->bl_desc.dyn_tree = ds->bl_tree;
  77591. return Z_OK;
  77592. #endif /* MAXSEG_64K */
  77593. }
  77594. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77595. {
  77596. unsigned len = strm->avail_in;
  77597. if (len > size) len = size;
  77598. if (len == 0) return 0;
  77599. strm->avail_in -= len;
  77600. if (strm->state->wrap == 1) {
  77601. strm->adler = adler32(strm->adler, strm->next_in, len);
  77602. }
  77603. #ifdef GZIP
  77604. else if (strm->state->wrap == 2) {
  77605. strm->adler = crc32(strm->adler, strm->next_in, len);
  77606. }
  77607. #endif
  77608. zmemcpy(buf, strm->next_in, len);
  77609. strm->next_in += len;
  77610. strm->total_in += len;
  77611. return (int)len;
  77612. }
  77613. local void lm_init (deflate_state *s)
  77614. {
  77615. s->window_size = (ulg)2L*s->w_size;
  77616. CLEAR_HASH(s);
  77617. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77618. s->good_match = configuration_table[s->level].good_length;
  77619. s->nice_match = configuration_table[s->level].nice_length;
  77620. s->max_chain_length = configuration_table[s->level].max_chain;
  77621. s->strstart = 0;
  77622. s->block_start = 0L;
  77623. s->lookahead = 0;
  77624. s->match_length = s->prev_length = MIN_MATCH-1;
  77625. s->match_available = 0;
  77626. s->ins_h = 0;
  77627. #ifndef FASTEST
  77628. #ifdef ASMV
  77629. match_init(); /* initialize the asm code */
  77630. #endif
  77631. #endif
  77632. }
  77633. #ifndef FASTEST
  77634. #ifndef ASMV
  77635. local uInt longest_match(deflate_state *s, IPos cur_match)
  77636. {
  77637. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77638. register Bytef *scan = s->window + s->strstart; /* current string */
  77639. register Bytef *match; /* matched string */
  77640. register int len; /* length of current match */
  77641. int best_len = s->prev_length; /* best match length so far */
  77642. int nice_match = s->nice_match; /* stop if match long enough */
  77643. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77644. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77645. Posf *prev = s->prev;
  77646. uInt wmask = s->w_mask;
  77647. #ifdef UNALIGNED_OK
  77648. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77649. register ush scan_start = *(ushf*)scan;
  77650. register ush scan_end = *(ushf*)(scan+best_len-1);
  77651. #else
  77652. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77653. register Byte scan_end1 = scan[best_len-1];
  77654. register Byte scan_end = scan[best_len];
  77655. #endif
  77656. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77657. if (s->prev_length >= s->good_match) {
  77658. chain_length >>= 2;
  77659. }
  77660. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77661. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77662. do {
  77663. Assert(cur_match < s->strstart, "no future");
  77664. match = s->window + cur_match;
  77665. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77666. if (*(ushf*)(match+best_len-1) != scan_end ||
  77667. *(ushf*)match != scan_start) continue;
  77668. Assert(scan[2] == match[2], "scan[2]?");
  77669. scan++, match++;
  77670. do {
  77671. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77672. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77673. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77674. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77675. scan < strend);
  77676. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77677. if (*scan == *match) scan++;
  77678. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77679. scan = strend - (MAX_MATCH-1);
  77680. #else /* UNALIGNED_OK */
  77681. if (match[best_len] != scan_end ||
  77682. match[best_len-1] != scan_end1 ||
  77683. *match != *scan ||
  77684. *++match != scan[1]) continue;
  77685. scan += 2, match++;
  77686. Assert(*scan == *match, "match[2]?");
  77687. do {
  77688. } while (*++scan == *++match && *++scan == *++match &&
  77689. *++scan == *++match && *++scan == *++match &&
  77690. *++scan == *++match && *++scan == *++match &&
  77691. *++scan == *++match && *++scan == *++match &&
  77692. scan < strend);
  77693. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77694. len = MAX_MATCH - (int)(strend - scan);
  77695. scan = strend - MAX_MATCH;
  77696. #endif /* UNALIGNED_OK */
  77697. if (len > best_len) {
  77698. s->match_start = cur_match;
  77699. best_len = len;
  77700. if (len >= nice_match) break;
  77701. #ifdef UNALIGNED_OK
  77702. scan_end = *(ushf*)(scan+best_len-1);
  77703. #else
  77704. scan_end1 = scan[best_len-1];
  77705. scan_end = scan[best_len];
  77706. #endif
  77707. }
  77708. } while ((cur_match = prev[cur_match & wmask]) > limit
  77709. && --chain_length != 0);
  77710. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77711. return s->lookahead;
  77712. }
  77713. #endif /* ASMV */
  77714. #endif /* FASTEST */
  77715. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77716. {
  77717. register Bytef *scan = s->window + s->strstart; /* current string */
  77718. register Bytef *match; /* matched string */
  77719. register int len; /* length of current match */
  77720. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77721. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77722. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77723. Assert(cur_match < s->strstart, "no future");
  77724. match = s->window + cur_match;
  77725. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77726. scan += 2, match += 2;
  77727. Assert(*scan == *match, "match[2]?");
  77728. do {
  77729. } while (*++scan == *++match && *++scan == *++match &&
  77730. *++scan == *++match && *++scan == *++match &&
  77731. *++scan == *++match && *++scan == *++match &&
  77732. *++scan == *++match && *++scan == *++match &&
  77733. scan < strend);
  77734. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77735. len = MAX_MATCH - (int)(strend - scan);
  77736. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77737. s->match_start = cur_match;
  77738. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77739. }
  77740. #ifdef DEBUG
  77741. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77742. {
  77743. if (zmemcmp(s->window + match,
  77744. s->window + start, length) != EQUAL) {
  77745. fprintf(stderr, " start %u, match %u, length %d\n",
  77746. start, match, length);
  77747. do {
  77748. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77749. } while (--length != 0);
  77750. z_error("invalid match");
  77751. }
  77752. if (z_verbose > 1) {
  77753. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77754. do { putc(s->window[start++], stderr); } while (--length != 0);
  77755. }
  77756. }
  77757. #else
  77758. # define check_match(s, start, match, length)
  77759. #endif /* DEBUG */
  77760. local void fill_window (deflate_state *s)
  77761. {
  77762. register unsigned n, m;
  77763. register Posf *p;
  77764. unsigned more; /* Amount of free space at the end of the window. */
  77765. uInt wsize = s->w_size;
  77766. do {
  77767. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77768. if (sizeof(int) <= 2) {
  77769. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77770. more = wsize;
  77771. } else if (more == (unsigned)(-1)) {
  77772. more--;
  77773. }
  77774. }
  77775. if (s->strstart >= wsize+MAX_DIST(s)) {
  77776. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77777. s->match_start -= wsize;
  77778. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77779. s->block_start -= (long) wsize;
  77780. n = s->hash_size;
  77781. p = &s->head[n];
  77782. do {
  77783. m = *--p;
  77784. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77785. } while (--n);
  77786. n = wsize;
  77787. #ifndef FASTEST
  77788. p = &s->prev[n];
  77789. do {
  77790. m = *--p;
  77791. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77792. } while (--n);
  77793. #endif
  77794. more += wsize;
  77795. }
  77796. if (s->strm->avail_in == 0) return;
  77797. Assert(more >= 2, "more < 2");
  77798. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77799. s->lookahead += n;
  77800. if (s->lookahead >= MIN_MATCH) {
  77801. s->ins_h = s->window[s->strstart];
  77802. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77803. #if MIN_MATCH != 3
  77804. Call UPDATE_HASH() MIN_MATCH-3 more times
  77805. #endif
  77806. }
  77807. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77808. }
  77809. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77810. _tr_flush_block(s, (s->block_start >= 0L ? \
  77811. (charf *)&s->window[(unsigned)s->block_start] : \
  77812. (charf *)Z_NULL), \
  77813. (ulg)((long)s->strstart - s->block_start), \
  77814. (eof)); \
  77815. s->block_start = s->strstart; \
  77816. flush_pending(s->strm); \
  77817. Tracev((stderr,"[FLUSH]")); \
  77818. }
  77819. #define FLUSH_BLOCK(s, eof) { \
  77820. FLUSH_BLOCK_ONLY(s, eof); \
  77821. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77822. }
  77823. local block_state deflate_stored(deflate_state *s, int flush)
  77824. {
  77825. ulg max_block_size = 0xffff;
  77826. ulg max_start;
  77827. if (max_block_size > s->pending_buf_size - 5) {
  77828. max_block_size = s->pending_buf_size - 5;
  77829. }
  77830. for (;;) {
  77831. if (s->lookahead <= 1) {
  77832. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77833. s->block_start >= (long)s->w_size, "slide too late");
  77834. fill_window(s);
  77835. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77836. if (s->lookahead == 0) break; /* flush the current block */
  77837. }
  77838. Assert(s->block_start >= 0L, "block gone");
  77839. s->strstart += s->lookahead;
  77840. s->lookahead = 0;
  77841. max_start = s->block_start + max_block_size;
  77842. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77843. s->lookahead = (uInt)(s->strstart - max_start);
  77844. s->strstart = (uInt)max_start;
  77845. FLUSH_BLOCK(s, 0);
  77846. }
  77847. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77848. FLUSH_BLOCK(s, 0);
  77849. }
  77850. }
  77851. FLUSH_BLOCK(s, flush == Z_FINISH);
  77852. return flush == Z_FINISH ? finish_done : block_done;
  77853. }
  77854. local block_state deflate_fast(deflate_state *s, int flush)
  77855. {
  77856. IPos hash_head = NIL; /* head of the hash chain */
  77857. int bflush; /* set if current block must be flushed */
  77858. for (;;) {
  77859. if (s->lookahead < MIN_LOOKAHEAD) {
  77860. fill_window(s);
  77861. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77862. return need_more;
  77863. }
  77864. if (s->lookahead == 0) break; /* flush the current block */
  77865. }
  77866. if (s->lookahead >= MIN_MATCH) {
  77867. INSERT_STRING(s, s->strstart, hash_head);
  77868. }
  77869. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77870. #ifdef FASTEST
  77871. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77872. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77873. s->match_length = longest_match_fast (s, hash_head);
  77874. }
  77875. #else
  77876. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77877. s->match_length = longest_match (s, hash_head);
  77878. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77879. s->match_length = longest_match_fast (s, hash_head);
  77880. }
  77881. #endif
  77882. }
  77883. if (s->match_length >= MIN_MATCH) {
  77884. check_match(s, s->strstart, s->match_start, s->match_length);
  77885. _tr_tally_dist(s, s->strstart - s->match_start,
  77886. s->match_length - MIN_MATCH, bflush);
  77887. s->lookahead -= s->match_length;
  77888. #ifndef FASTEST
  77889. if (s->match_length <= s->max_insert_length &&
  77890. s->lookahead >= MIN_MATCH) {
  77891. s->match_length--; /* string at strstart already in table */
  77892. do {
  77893. s->strstart++;
  77894. INSERT_STRING(s, s->strstart, hash_head);
  77895. } while (--s->match_length != 0);
  77896. s->strstart++;
  77897. } else
  77898. #endif
  77899. {
  77900. s->strstart += s->match_length;
  77901. s->match_length = 0;
  77902. s->ins_h = s->window[s->strstart];
  77903. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77904. #if MIN_MATCH != 3
  77905. Call UPDATE_HASH() MIN_MATCH-3 more times
  77906. #endif
  77907. }
  77908. } else {
  77909. Tracevv((stderr,"%c", s->window[s->strstart]));
  77910. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77911. s->lookahead--;
  77912. s->strstart++;
  77913. }
  77914. if (bflush) FLUSH_BLOCK(s, 0);
  77915. }
  77916. FLUSH_BLOCK(s, flush == Z_FINISH);
  77917. return flush == Z_FINISH ? finish_done : block_done;
  77918. }
  77919. #ifndef FASTEST
  77920. local block_state deflate_slow(deflate_state *s, int flush)
  77921. {
  77922. IPos hash_head = NIL; /* head of hash chain */
  77923. int bflush; /* set if current block must be flushed */
  77924. for (;;) {
  77925. if (s->lookahead < MIN_LOOKAHEAD) {
  77926. fill_window(s);
  77927. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77928. return need_more;
  77929. }
  77930. if (s->lookahead == 0) break; /* flush the current block */
  77931. }
  77932. if (s->lookahead >= MIN_MATCH) {
  77933. INSERT_STRING(s, s->strstart, hash_head);
  77934. }
  77935. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77936. s->match_length = MIN_MATCH-1;
  77937. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77938. s->strstart - hash_head <= MAX_DIST(s)) {
  77939. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77940. s->match_length = longest_match (s, hash_head);
  77941. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77942. s->match_length = longest_match_fast (s, hash_head);
  77943. }
  77944. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77945. #if TOO_FAR <= 32767
  77946. || (s->match_length == MIN_MATCH &&
  77947. s->strstart - s->match_start > TOO_FAR)
  77948. #endif
  77949. )) {
  77950. s->match_length = MIN_MATCH-1;
  77951. }
  77952. }
  77953. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77954. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77955. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77956. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77957. s->prev_length - MIN_MATCH, bflush);
  77958. s->lookahead -= s->prev_length-1;
  77959. s->prev_length -= 2;
  77960. do {
  77961. if (++s->strstart <= max_insert) {
  77962. INSERT_STRING(s, s->strstart, hash_head);
  77963. }
  77964. } while (--s->prev_length != 0);
  77965. s->match_available = 0;
  77966. s->match_length = MIN_MATCH-1;
  77967. s->strstart++;
  77968. if (bflush) FLUSH_BLOCK(s, 0);
  77969. } else if (s->match_available) {
  77970. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77971. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77972. if (bflush) {
  77973. FLUSH_BLOCK_ONLY(s, 0);
  77974. }
  77975. s->strstart++;
  77976. s->lookahead--;
  77977. if (s->strm->avail_out == 0) return need_more;
  77978. } else {
  77979. s->match_available = 1;
  77980. s->strstart++;
  77981. s->lookahead--;
  77982. }
  77983. }
  77984. Assert (flush != Z_NO_FLUSH, "no flush?");
  77985. if (s->match_available) {
  77986. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77987. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77988. s->match_available = 0;
  77989. }
  77990. FLUSH_BLOCK(s, flush == Z_FINISH);
  77991. return flush == Z_FINISH ? finish_done : block_done;
  77992. }
  77993. #endif /* FASTEST */
  77994. #if 0
  77995. local block_state deflate_rle(s, flush)
  77996. deflate_state *s;
  77997. int flush;
  77998. {
  77999. int bflush; /* set if current block must be flushed */
  78000. uInt run; /* length of run */
  78001. uInt max; /* maximum length of run */
  78002. uInt prev; /* byte at distance one to match */
  78003. Bytef *scan; /* scan for end of run */
  78004. for (;;) {
  78005. if (s->lookahead < MAX_MATCH) {
  78006. fill_window(s);
  78007. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  78008. return need_more;
  78009. }
  78010. if (s->lookahead == 0) break; /* flush the current block */
  78011. }
  78012. run = 0;
  78013. if (s->strstart > 0) { /* if there is a previous byte, that is */
  78014. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  78015. scan = s->window + s->strstart - 1;
  78016. prev = *scan++;
  78017. do {
  78018. if (*scan++ != prev)
  78019. break;
  78020. } while (++run < max);
  78021. }
  78022. if (run >= MIN_MATCH) {
  78023. check_match(s, s->strstart, s->strstart - 1, run);
  78024. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  78025. s->lookahead -= run;
  78026. s->strstart += run;
  78027. } else {
  78028. Tracevv((stderr,"%c", s->window[s->strstart]));
  78029. _tr_tally_lit (s, s->window[s->strstart], bflush);
  78030. s->lookahead--;
  78031. s->strstart++;
  78032. }
  78033. if (bflush) FLUSH_BLOCK(s, 0);
  78034. }
  78035. FLUSH_BLOCK(s, flush == Z_FINISH);
  78036. return flush == Z_FINISH ? finish_done : block_done;
  78037. }
  78038. #endif
  78039. /*** End of inlined file: deflate.c ***/
  78040. /*** Start of inlined file: inffast.c ***/
  78041. /*** Start of inlined file: inftrees.h ***/
  78042. #ifndef _INFTREES_H_
  78043. #define _INFTREES_H_
  78044. typedef struct {
  78045. unsigned char op; /* operation, extra bits, table bits */
  78046. unsigned char bits; /* bits in this part of the code */
  78047. unsigned short val; /* offset in table or code value */
  78048. } code;
  78049. #define ENOUGH 2048
  78050. #define MAXD 592
  78051. typedef enum {
  78052. CODES,
  78053. LENS,
  78054. DISTS
  78055. } codetype;
  78056. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  78057. unsigned codes, code FAR * FAR *table,
  78058. unsigned FAR *bits, unsigned short FAR *work));
  78059. #endif
  78060. /*** End of inlined file: inftrees.h ***/
  78061. /*** Start of inlined file: inflate.h ***/
  78062. #ifndef _INFLATE_H_
  78063. #define _INFLATE_H_
  78064. #ifndef NO_GZIP
  78065. # define GUNZIP
  78066. #endif
  78067. typedef enum {
  78068. HEAD, /* i: waiting for magic header */
  78069. FLAGS, /* i: waiting for method and flags (gzip) */
  78070. TIME, /* i: waiting for modification time (gzip) */
  78071. OS, /* i: waiting for extra flags and operating system (gzip) */
  78072. EXLEN, /* i: waiting for extra length (gzip) */
  78073. EXTRA, /* i: waiting for extra bytes (gzip) */
  78074. NAME, /* i: waiting for end of file name (gzip) */
  78075. COMMENT, /* i: waiting for end of comment (gzip) */
  78076. HCRC, /* i: waiting for header crc (gzip) */
  78077. DICTID, /* i: waiting for dictionary check value */
  78078. DICT, /* waiting for inflateSetDictionary() call */
  78079. TYPE, /* i: waiting for type bits, including last-flag bit */
  78080. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  78081. STORED, /* i: waiting for stored size (length and complement) */
  78082. COPY, /* i/o: waiting for input or output to copy stored block */
  78083. TABLE, /* i: waiting for dynamic block table lengths */
  78084. LENLENS, /* i: waiting for code length code lengths */
  78085. CODELENS, /* i: waiting for length/lit and distance code lengths */
  78086. LEN, /* i: waiting for length/lit code */
  78087. LENEXT, /* i: waiting for length extra bits */
  78088. DIST, /* i: waiting for distance code */
  78089. DISTEXT, /* i: waiting for distance extra bits */
  78090. MATCH, /* o: waiting for output space to copy string */
  78091. LIT, /* o: waiting for output space to write literal */
  78092. CHECK, /* i: waiting for 32-bit check value */
  78093. LENGTH, /* i: waiting for 32-bit length (gzip) */
  78094. DONE, /* finished check, done -- remain here until reset */
  78095. BAD, /* got a data error -- remain here until reset */
  78096. MEM, /* got an inflate() memory error -- remain here until reset */
  78097. SYNC /* looking for synchronization bytes to restart inflate() */
  78098. } inflate_mode;
  78099. struct inflate_state {
  78100. inflate_mode mode; /* current inflate mode */
  78101. int last; /* true if processing last block */
  78102. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  78103. int havedict; /* true if dictionary provided */
  78104. int flags; /* gzip header method and flags (0 if zlib) */
  78105. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  78106. unsigned long check; /* protected copy of check value */
  78107. unsigned long total; /* protected copy of output count */
  78108. gz_headerp head; /* where to save gzip header information */
  78109. unsigned wbits; /* log base 2 of requested window size */
  78110. unsigned wsize; /* window size or zero if not using window */
  78111. unsigned whave; /* valid bytes in the window */
  78112. unsigned write; /* window write index */
  78113. unsigned char FAR *window; /* allocated sliding window, if needed */
  78114. unsigned long hold; /* input bit accumulator */
  78115. unsigned bits; /* number of bits in "in" */
  78116. unsigned length; /* literal or length of data to copy */
  78117. unsigned offset; /* distance back to copy string from */
  78118. unsigned extra; /* extra bits needed */
  78119. code const FAR *lencode; /* starting table for length/literal codes */
  78120. code const FAR *distcode; /* starting table for distance codes */
  78121. unsigned lenbits; /* index bits for lencode */
  78122. unsigned distbits; /* index bits for distcode */
  78123. unsigned ncode; /* number of code length code lengths */
  78124. unsigned nlen; /* number of length code lengths */
  78125. unsigned ndist; /* number of distance code lengths */
  78126. unsigned have; /* number of code lengths in lens[] */
  78127. code FAR *next; /* next available space in codes[] */
  78128. unsigned short lens[320]; /* temporary storage for code lengths */
  78129. unsigned short work[288]; /* work area for code table building */
  78130. code codes[ENOUGH]; /* space for code tables */
  78131. };
  78132. #endif
  78133. /*** End of inlined file: inflate.h ***/
  78134. /*** Start of inlined file: inffast.h ***/
  78135. void inflate_fast OF((z_streamp strm, unsigned start));
  78136. /*** End of inlined file: inffast.h ***/
  78137. #ifndef ASMINF
  78138. #ifdef POSTINC
  78139. # define OFF 0
  78140. # define PUP(a) *(a)++
  78141. #else
  78142. # define OFF 1
  78143. # define PUP(a) *++(a)
  78144. #endif
  78145. void inflate_fast (z_streamp strm, unsigned start)
  78146. {
  78147. struct inflate_state FAR *state;
  78148. unsigned char FAR *in; /* local strm->next_in */
  78149. unsigned char FAR *last; /* while in < last, enough input available */
  78150. unsigned char FAR *out; /* local strm->next_out */
  78151. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  78152. unsigned char FAR *end; /* while out < end, enough space available */
  78153. #ifdef INFLATE_STRICT
  78154. unsigned dmax; /* maximum distance from zlib header */
  78155. #endif
  78156. unsigned wsize; /* window size or zero if not using window */
  78157. unsigned whave; /* valid bytes in the window */
  78158. unsigned write; /* window write index */
  78159. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  78160. unsigned long hold; /* local strm->hold */
  78161. unsigned bits; /* local strm->bits */
  78162. code const FAR *lcode; /* local strm->lencode */
  78163. code const FAR *dcode; /* local strm->distcode */
  78164. unsigned lmask; /* mask for first level of length codes */
  78165. unsigned dmask; /* mask for first level of distance codes */
  78166. code thisx; /* retrieved table entry */
  78167. unsigned op; /* code bits, operation, extra bits, or */
  78168. unsigned len; /* match length, unused bytes */
  78169. unsigned dist; /* match distance */
  78170. unsigned char FAR *from; /* where to copy match from */
  78171. state = (struct inflate_state FAR *)strm->state;
  78172. in = strm->next_in - OFF;
  78173. last = in + (strm->avail_in - 5);
  78174. out = strm->next_out - OFF;
  78175. beg = out - (start - strm->avail_out);
  78176. end = out + (strm->avail_out - 257);
  78177. #ifdef INFLATE_STRICT
  78178. dmax = state->dmax;
  78179. #endif
  78180. wsize = state->wsize;
  78181. whave = state->whave;
  78182. write = state->write;
  78183. window = state->window;
  78184. hold = state->hold;
  78185. bits = state->bits;
  78186. lcode = state->lencode;
  78187. dcode = state->distcode;
  78188. lmask = (1U << state->lenbits) - 1;
  78189. dmask = (1U << state->distbits) - 1;
  78190. do {
  78191. if (bits < 15) {
  78192. hold += (unsigned long)(PUP(in)) << bits;
  78193. bits += 8;
  78194. hold += (unsigned long)(PUP(in)) << bits;
  78195. bits += 8;
  78196. }
  78197. thisx = lcode[hold & lmask];
  78198. dolen:
  78199. op = (unsigned)(thisx.bits);
  78200. hold >>= op;
  78201. bits -= op;
  78202. op = (unsigned)(thisx.op);
  78203. if (op == 0) { /* literal */
  78204. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78205. "inflate: literal '%c'\n" :
  78206. "inflate: literal 0x%02x\n", thisx.val));
  78207. PUP(out) = (unsigned char)(thisx.val);
  78208. }
  78209. else if (op & 16) { /* length base */
  78210. len = (unsigned)(thisx.val);
  78211. op &= 15; /* number of extra bits */
  78212. if (op) {
  78213. if (bits < op) {
  78214. hold += (unsigned long)(PUP(in)) << bits;
  78215. bits += 8;
  78216. }
  78217. len += (unsigned)hold & ((1U << op) - 1);
  78218. hold >>= op;
  78219. bits -= op;
  78220. }
  78221. Tracevv((stderr, "inflate: length %u\n", len));
  78222. if (bits < 15) {
  78223. hold += (unsigned long)(PUP(in)) << bits;
  78224. bits += 8;
  78225. hold += (unsigned long)(PUP(in)) << bits;
  78226. bits += 8;
  78227. }
  78228. thisx = dcode[hold & dmask];
  78229. dodist:
  78230. op = (unsigned)(thisx.bits);
  78231. hold >>= op;
  78232. bits -= op;
  78233. op = (unsigned)(thisx.op);
  78234. if (op & 16) { /* distance base */
  78235. dist = (unsigned)(thisx.val);
  78236. op &= 15; /* number of extra bits */
  78237. if (bits < op) {
  78238. hold += (unsigned long)(PUP(in)) << bits;
  78239. bits += 8;
  78240. if (bits < op) {
  78241. hold += (unsigned long)(PUP(in)) << bits;
  78242. bits += 8;
  78243. }
  78244. }
  78245. dist += (unsigned)hold & ((1U << op) - 1);
  78246. #ifdef INFLATE_STRICT
  78247. if (dist > dmax) {
  78248. strm->msg = (char *)"invalid distance too far back";
  78249. state->mode = BAD;
  78250. break;
  78251. }
  78252. #endif
  78253. hold >>= op;
  78254. bits -= op;
  78255. Tracevv((stderr, "inflate: distance %u\n", dist));
  78256. op = (unsigned)(out - beg); /* max distance in output */
  78257. if (dist > op) { /* see if copy from window */
  78258. op = dist - op; /* distance back in window */
  78259. if (op > whave) {
  78260. strm->msg = (char *)"invalid distance too far back";
  78261. state->mode = BAD;
  78262. break;
  78263. }
  78264. from = window - OFF;
  78265. if (write == 0) { /* very common case */
  78266. from += wsize - op;
  78267. if (op < len) { /* some from window */
  78268. len -= op;
  78269. do {
  78270. PUP(out) = PUP(from);
  78271. } while (--op);
  78272. from = out - dist; /* rest from output */
  78273. }
  78274. }
  78275. else if (write < op) { /* wrap around window */
  78276. from += wsize + write - op;
  78277. op -= write;
  78278. if (op < len) { /* some from end of window */
  78279. len -= op;
  78280. do {
  78281. PUP(out) = PUP(from);
  78282. } while (--op);
  78283. from = window - OFF;
  78284. if (write < len) { /* some from start of window */
  78285. op = write;
  78286. len -= op;
  78287. do {
  78288. PUP(out) = PUP(from);
  78289. } while (--op);
  78290. from = out - dist; /* rest from output */
  78291. }
  78292. }
  78293. }
  78294. else { /* contiguous in window */
  78295. from += write - op;
  78296. if (op < len) { /* some from window */
  78297. len -= op;
  78298. do {
  78299. PUP(out) = PUP(from);
  78300. } while (--op);
  78301. from = out - dist; /* rest from output */
  78302. }
  78303. }
  78304. while (len > 2) {
  78305. PUP(out) = PUP(from);
  78306. PUP(out) = PUP(from);
  78307. PUP(out) = PUP(from);
  78308. len -= 3;
  78309. }
  78310. if (len) {
  78311. PUP(out) = PUP(from);
  78312. if (len > 1)
  78313. PUP(out) = PUP(from);
  78314. }
  78315. }
  78316. else {
  78317. from = out - dist; /* copy direct from output */
  78318. do { /* minimum length is three */
  78319. PUP(out) = PUP(from);
  78320. PUP(out) = PUP(from);
  78321. PUP(out) = PUP(from);
  78322. len -= 3;
  78323. } while (len > 2);
  78324. if (len) {
  78325. PUP(out) = PUP(from);
  78326. if (len > 1)
  78327. PUP(out) = PUP(from);
  78328. }
  78329. }
  78330. }
  78331. else if ((op & 64) == 0) { /* 2nd level distance code */
  78332. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78333. goto dodist;
  78334. }
  78335. else {
  78336. strm->msg = (char *)"invalid distance code";
  78337. state->mode = BAD;
  78338. break;
  78339. }
  78340. }
  78341. else if ((op & 64) == 0) { /* 2nd level length code */
  78342. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78343. goto dolen;
  78344. }
  78345. else if (op & 32) { /* end-of-block */
  78346. Tracevv((stderr, "inflate: end of block\n"));
  78347. state->mode = TYPE;
  78348. break;
  78349. }
  78350. else {
  78351. strm->msg = (char *)"invalid literal/length code";
  78352. state->mode = BAD;
  78353. break;
  78354. }
  78355. } while (in < last && out < end);
  78356. len = bits >> 3;
  78357. in -= len;
  78358. bits -= len << 3;
  78359. hold &= (1U << bits) - 1;
  78360. strm->next_in = in + OFF;
  78361. strm->next_out = out + OFF;
  78362. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78363. strm->avail_out = (unsigned)(out < end ?
  78364. 257 + (end - out) : 257 - (out - end));
  78365. state->hold = hold;
  78366. state->bits = bits;
  78367. return;
  78368. }
  78369. #endif /* !ASMINF */
  78370. /*** End of inlined file: inffast.c ***/
  78371. #undef PULLBYTE
  78372. #undef LOAD
  78373. #undef RESTORE
  78374. #undef INITBITS
  78375. #undef NEEDBITS
  78376. #undef DROPBITS
  78377. #undef BYTEBITS
  78378. /*** Start of inlined file: inflate.c ***/
  78379. /*** Start of inlined file: inffast.h ***/
  78380. void inflate_fast OF((z_streamp strm, unsigned start));
  78381. /*** End of inlined file: inffast.h ***/
  78382. #ifdef MAKEFIXED
  78383. # ifndef BUILDFIXED
  78384. # define BUILDFIXED
  78385. # endif
  78386. #endif
  78387. local void fixedtables OF((struct inflate_state FAR *state));
  78388. local int updatewindow OF((z_streamp strm, unsigned out));
  78389. #ifdef BUILDFIXED
  78390. void makefixed OF((void));
  78391. #endif
  78392. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78393. unsigned len));
  78394. int ZEXPORT inflateReset (z_streamp strm)
  78395. {
  78396. struct inflate_state FAR *state;
  78397. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78398. state = (struct inflate_state FAR *)strm->state;
  78399. strm->total_in = strm->total_out = state->total = 0;
  78400. strm->msg = Z_NULL;
  78401. strm->adler = 1; /* to support ill-conceived Java test suite */
  78402. state->mode = HEAD;
  78403. state->last = 0;
  78404. state->havedict = 0;
  78405. state->dmax = 32768U;
  78406. state->head = Z_NULL;
  78407. state->wsize = 0;
  78408. state->whave = 0;
  78409. state->write = 0;
  78410. state->hold = 0;
  78411. state->bits = 0;
  78412. state->lencode = state->distcode = state->next = state->codes;
  78413. Tracev((stderr, "inflate: reset\n"));
  78414. return Z_OK;
  78415. }
  78416. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78417. {
  78418. struct inflate_state FAR *state;
  78419. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78420. state = (struct inflate_state FAR *)strm->state;
  78421. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78422. value &= (1L << bits) - 1;
  78423. state->hold += value << state->bits;
  78424. state->bits += bits;
  78425. return Z_OK;
  78426. }
  78427. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78428. {
  78429. struct inflate_state FAR *state;
  78430. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78431. stream_size != (int)(sizeof(z_stream)))
  78432. return Z_VERSION_ERROR;
  78433. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78434. strm->msg = Z_NULL; /* in case we return an error */
  78435. if (strm->zalloc == (alloc_func)0) {
  78436. strm->zalloc = zcalloc;
  78437. strm->opaque = (voidpf)0;
  78438. }
  78439. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78440. state = (struct inflate_state FAR *)
  78441. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78442. if (state == Z_NULL) return Z_MEM_ERROR;
  78443. Tracev((stderr, "inflate: allocated\n"));
  78444. strm->state = (struct internal_state FAR *)state;
  78445. if (windowBits < 0) {
  78446. state->wrap = 0;
  78447. windowBits = -windowBits;
  78448. }
  78449. else {
  78450. state->wrap = (windowBits >> 4) + 1;
  78451. #ifdef GUNZIP
  78452. if (windowBits < 48) windowBits &= 15;
  78453. #endif
  78454. }
  78455. if (windowBits < 8 || windowBits > 15) {
  78456. ZFREE(strm, state);
  78457. strm->state = Z_NULL;
  78458. return Z_STREAM_ERROR;
  78459. }
  78460. state->wbits = (unsigned)windowBits;
  78461. state->window = Z_NULL;
  78462. return inflateReset(strm);
  78463. }
  78464. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78465. {
  78466. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78467. }
  78468. local void fixedtables (struct inflate_state FAR *state)
  78469. {
  78470. #ifdef BUILDFIXED
  78471. static int virgin = 1;
  78472. static code *lenfix, *distfix;
  78473. static code fixed[544];
  78474. if (virgin) {
  78475. unsigned sym, bits;
  78476. static code *next;
  78477. sym = 0;
  78478. while (sym < 144) state->lens[sym++] = 8;
  78479. while (sym < 256) state->lens[sym++] = 9;
  78480. while (sym < 280) state->lens[sym++] = 7;
  78481. while (sym < 288) state->lens[sym++] = 8;
  78482. next = fixed;
  78483. lenfix = next;
  78484. bits = 9;
  78485. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78486. sym = 0;
  78487. while (sym < 32) state->lens[sym++] = 5;
  78488. distfix = next;
  78489. bits = 5;
  78490. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78491. virgin = 0;
  78492. }
  78493. #else /* !BUILDFIXED */
  78494. /*** Start of inlined file: inffixed.h ***/
  78495. static const code lenfix[512] = {
  78496. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78497. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78498. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78499. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78500. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78501. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78502. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78503. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78504. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78505. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78506. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78507. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78508. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78509. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78510. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78511. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78512. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78513. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78514. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78515. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78516. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78517. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78518. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78519. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78520. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78521. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78522. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78523. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78524. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78525. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78526. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78527. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78528. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78529. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78530. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78531. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78532. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78533. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78534. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78535. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78536. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78537. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78538. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78539. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78540. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78541. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78542. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78543. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78544. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78545. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78546. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78547. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78548. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78549. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78550. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78551. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78552. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78553. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78554. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78555. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78556. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78557. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78558. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78559. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78560. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78561. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78562. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78563. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78564. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78565. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78566. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78567. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78568. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78569. {0,9,255}
  78570. };
  78571. static const code distfix[32] = {
  78572. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78573. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78574. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78575. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78576. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78577. {22,5,193},{64,5,0}
  78578. };
  78579. /*** End of inlined file: inffixed.h ***/
  78580. #endif /* BUILDFIXED */
  78581. state->lencode = lenfix;
  78582. state->lenbits = 9;
  78583. state->distcode = distfix;
  78584. state->distbits = 5;
  78585. }
  78586. #ifdef MAKEFIXED
  78587. #include <stdio.h>
  78588. void makefixed()
  78589. {
  78590. unsigned low, size;
  78591. struct inflate_state state;
  78592. fixedtables(&state);
  78593. puts(" /* inffixed.h -- table for decoding fixed codes");
  78594. puts(" * Generated automatically by makefixed().");
  78595. puts(" */");
  78596. puts("");
  78597. puts(" /* WARNING: this file should *not* be used by applications.");
  78598. puts(" It is part of the implementation of this library and is");
  78599. puts(" subject to change. Applications should only use zlib.h.");
  78600. puts(" */");
  78601. puts("");
  78602. size = 1U << 9;
  78603. printf(" static const code lenfix[%u] = {", size);
  78604. low = 0;
  78605. for (;;) {
  78606. if ((low % 7) == 0) printf("\n ");
  78607. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78608. state.lencode[low].val);
  78609. if (++low == size) break;
  78610. putchar(',');
  78611. }
  78612. puts("\n };");
  78613. size = 1U << 5;
  78614. printf("\n static const code distfix[%u] = {", size);
  78615. low = 0;
  78616. for (;;) {
  78617. if ((low % 6) == 0) printf("\n ");
  78618. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78619. state.distcode[low].val);
  78620. if (++low == size) break;
  78621. putchar(',');
  78622. }
  78623. puts("\n };");
  78624. }
  78625. #endif /* MAKEFIXED */
  78626. local int updatewindow (z_streamp strm, unsigned out)
  78627. {
  78628. struct inflate_state FAR *state;
  78629. unsigned copy, dist;
  78630. state = (struct inflate_state FAR *)strm->state;
  78631. if (state->window == Z_NULL) {
  78632. state->window = (unsigned char FAR *)
  78633. ZALLOC(strm, 1U << state->wbits,
  78634. sizeof(unsigned char));
  78635. if (state->window == Z_NULL) return 1;
  78636. }
  78637. if (state->wsize == 0) {
  78638. state->wsize = 1U << state->wbits;
  78639. state->write = 0;
  78640. state->whave = 0;
  78641. }
  78642. copy = out - strm->avail_out;
  78643. if (copy >= state->wsize) {
  78644. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78645. state->write = 0;
  78646. state->whave = state->wsize;
  78647. }
  78648. else {
  78649. dist = state->wsize - state->write;
  78650. if (dist > copy) dist = copy;
  78651. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78652. copy -= dist;
  78653. if (copy) {
  78654. zmemcpy(state->window, strm->next_out - copy, copy);
  78655. state->write = copy;
  78656. state->whave = state->wsize;
  78657. }
  78658. else {
  78659. state->write += dist;
  78660. if (state->write == state->wsize) state->write = 0;
  78661. if (state->whave < state->wsize) state->whave += dist;
  78662. }
  78663. }
  78664. return 0;
  78665. }
  78666. #ifdef GUNZIP
  78667. # define UPDATE(check, buf, len) \
  78668. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78669. #else
  78670. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78671. #endif
  78672. #ifdef GUNZIP
  78673. # define CRC2(check, word) \
  78674. do { \
  78675. hbuf[0] = (unsigned char)(word); \
  78676. hbuf[1] = (unsigned char)((word) >> 8); \
  78677. check = crc32(check, hbuf, 2); \
  78678. } while (0)
  78679. # define CRC4(check, word) \
  78680. do { \
  78681. hbuf[0] = (unsigned char)(word); \
  78682. hbuf[1] = (unsigned char)((word) >> 8); \
  78683. hbuf[2] = (unsigned char)((word) >> 16); \
  78684. hbuf[3] = (unsigned char)((word) >> 24); \
  78685. check = crc32(check, hbuf, 4); \
  78686. } while (0)
  78687. #endif
  78688. #define LOAD() \
  78689. do { \
  78690. put = strm->next_out; \
  78691. left = strm->avail_out; \
  78692. next = strm->next_in; \
  78693. have = strm->avail_in; \
  78694. hold = state->hold; \
  78695. bits = state->bits; \
  78696. } while (0)
  78697. #define RESTORE() \
  78698. do { \
  78699. strm->next_out = put; \
  78700. strm->avail_out = left; \
  78701. strm->next_in = next; \
  78702. strm->avail_in = have; \
  78703. state->hold = hold; \
  78704. state->bits = bits; \
  78705. } while (0)
  78706. #define INITBITS() \
  78707. do { \
  78708. hold = 0; \
  78709. bits = 0; \
  78710. } while (0)
  78711. #define PULLBYTE() \
  78712. do { \
  78713. if (have == 0) goto inf_leave; \
  78714. have--; \
  78715. hold += (unsigned long)(*next++) << bits; \
  78716. bits += 8; \
  78717. } while (0)
  78718. #define NEEDBITS(n) \
  78719. do { \
  78720. while (bits < (unsigned)(n)) \
  78721. PULLBYTE(); \
  78722. } while (0)
  78723. #define BITS(n) \
  78724. ((unsigned)hold & ((1U << (n)) - 1))
  78725. #define DROPBITS(n) \
  78726. do { \
  78727. hold >>= (n); \
  78728. bits -= (unsigned)(n); \
  78729. } while (0)
  78730. #define BYTEBITS() \
  78731. do { \
  78732. hold >>= bits & 7; \
  78733. bits -= bits & 7; \
  78734. } while (0)
  78735. #define REVERSE(q) \
  78736. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78737. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78738. int ZEXPORT inflate (z_streamp strm, int flush)
  78739. {
  78740. struct inflate_state FAR *state;
  78741. unsigned char FAR *next; /* next input */
  78742. unsigned char FAR *put; /* next output */
  78743. unsigned have, left; /* available input and output */
  78744. unsigned long hold; /* bit buffer */
  78745. unsigned bits; /* bits in bit buffer */
  78746. unsigned in, out; /* save starting available input and output */
  78747. unsigned copy; /* number of stored or match bytes to copy */
  78748. unsigned char FAR *from; /* where to copy match bytes from */
  78749. code thisx; /* current decoding table entry */
  78750. code last; /* parent table entry */
  78751. unsigned len; /* length to copy for repeats, bits to drop */
  78752. int ret; /* return code */
  78753. #ifdef GUNZIP
  78754. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78755. #endif
  78756. static const unsigned short order[19] = /* permutation of code lengths */
  78757. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78758. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78759. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78760. return Z_STREAM_ERROR;
  78761. state = (struct inflate_state FAR *)strm->state;
  78762. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78763. LOAD();
  78764. in = have;
  78765. out = left;
  78766. ret = Z_OK;
  78767. for (;;)
  78768. switch (state->mode) {
  78769. case HEAD:
  78770. if (state->wrap == 0) {
  78771. state->mode = TYPEDO;
  78772. break;
  78773. }
  78774. NEEDBITS(16);
  78775. #ifdef GUNZIP
  78776. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78777. state->check = crc32(0L, Z_NULL, 0);
  78778. CRC2(state->check, hold);
  78779. INITBITS();
  78780. state->mode = FLAGS;
  78781. break;
  78782. }
  78783. state->flags = 0; /* expect zlib header */
  78784. if (state->head != Z_NULL)
  78785. state->head->done = -1;
  78786. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78787. #else
  78788. if (
  78789. #endif
  78790. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78791. strm->msg = (char *)"incorrect header check";
  78792. state->mode = BAD;
  78793. break;
  78794. }
  78795. if (BITS(4) != Z_DEFLATED) {
  78796. strm->msg = (char *)"unknown compression method";
  78797. state->mode = BAD;
  78798. break;
  78799. }
  78800. DROPBITS(4);
  78801. len = BITS(4) + 8;
  78802. if (len > state->wbits) {
  78803. strm->msg = (char *)"invalid window size";
  78804. state->mode = BAD;
  78805. break;
  78806. }
  78807. state->dmax = 1U << len;
  78808. Tracev((stderr, "inflate: zlib header ok\n"));
  78809. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78810. state->mode = hold & 0x200 ? DICTID : TYPE;
  78811. INITBITS();
  78812. break;
  78813. #ifdef GUNZIP
  78814. case FLAGS:
  78815. NEEDBITS(16);
  78816. state->flags = (int)(hold);
  78817. if ((state->flags & 0xff) != Z_DEFLATED) {
  78818. strm->msg = (char *)"unknown compression method";
  78819. state->mode = BAD;
  78820. break;
  78821. }
  78822. if (state->flags & 0xe000) {
  78823. strm->msg = (char *)"unknown header flags set";
  78824. state->mode = BAD;
  78825. break;
  78826. }
  78827. if (state->head != Z_NULL)
  78828. state->head->text = (int)((hold >> 8) & 1);
  78829. if (state->flags & 0x0200) CRC2(state->check, hold);
  78830. INITBITS();
  78831. state->mode = TIME;
  78832. case TIME:
  78833. NEEDBITS(32);
  78834. if (state->head != Z_NULL)
  78835. state->head->time = hold;
  78836. if (state->flags & 0x0200) CRC4(state->check, hold);
  78837. INITBITS();
  78838. state->mode = OS;
  78839. case OS:
  78840. NEEDBITS(16);
  78841. if (state->head != Z_NULL) {
  78842. state->head->xflags = (int)(hold & 0xff);
  78843. state->head->os = (int)(hold >> 8);
  78844. }
  78845. if (state->flags & 0x0200) CRC2(state->check, hold);
  78846. INITBITS();
  78847. state->mode = EXLEN;
  78848. case EXLEN:
  78849. if (state->flags & 0x0400) {
  78850. NEEDBITS(16);
  78851. state->length = (unsigned)(hold);
  78852. if (state->head != Z_NULL)
  78853. state->head->extra_len = (unsigned)hold;
  78854. if (state->flags & 0x0200) CRC2(state->check, hold);
  78855. INITBITS();
  78856. }
  78857. else if (state->head != Z_NULL)
  78858. state->head->extra = Z_NULL;
  78859. state->mode = EXTRA;
  78860. case EXTRA:
  78861. if (state->flags & 0x0400) {
  78862. copy = state->length;
  78863. if (copy > have) copy = have;
  78864. if (copy) {
  78865. if (state->head != Z_NULL &&
  78866. state->head->extra != Z_NULL) {
  78867. len = state->head->extra_len - state->length;
  78868. zmemcpy(state->head->extra + len, next,
  78869. len + copy > state->head->extra_max ?
  78870. state->head->extra_max - len : copy);
  78871. }
  78872. if (state->flags & 0x0200)
  78873. state->check = crc32(state->check, next, copy);
  78874. have -= copy;
  78875. next += copy;
  78876. state->length -= copy;
  78877. }
  78878. if (state->length) goto inf_leave;
  78879. }
  78880. state->length = 0;
  78881. state->mode = NAME;
  78882. case NAME:
  78883. if (state->flags & 0x0800) {
  78884. if (have == 0) goto inf_leave;
  78885. copy = 0;
  78886. do {
  78887. len = (unsigned)(next[copy++]);
  78888. if (state->head != Z_NULL &&
  78889. state->head->name != Z_NULL &&
  78890. state->length < state->head->name_max)
  78891. state->head->name[state->length++] = len;
  78892. } while (len && copy < have);
  78893. if (state->flags & 0x0200)
  78894. state->check = crc32(state->check, next, copy);
  78895. have -= copy;
  78896. next += copy;
  78897. if (len) goto inf_leave;
  78898. }
  78899. else if (state->head != Z_NULL)
  78900. state->head->name = Z_NULL;
  78901. state->length = 0;
  78902. state->mode = COMMENT;
  78903. case COMMENT:
  78904. if (state->flags & 0x1000) {
  78905. if (have == 0) goto inf_leave;
  78906. copy = 0;
  78907. do {
  78908. len = (unsigned)(next[copy++]);
  78909. if (state->head != Z_NULL &&
  78910. state->head->comment != Z_NULL &&
  78911. state->length < state->head->comm_max)
  78912. state->head->comment[state->length++] = len;
  78913. } while (len && copy < have);
  78914. if (state->flags & 0x0200)
  78915. state->check = crc32(state->check, next, copy);
  78916. have -= copy;
  78917. next += copy;
  78918. if (len) goto inf_leave;
  78919. }
  78920. else if (state->head != Z_NULL)
  78921. state->head->comment = Z_NULL;
  78922. state->mode = HCRC;
  78923. case HCRC:
  78924. if (state->flags & 0x0200) {
  78925. NEEDBITS(16);
  78926. if (hold != (state->check & 0xffff)) {
  78927. strm->msg = (char *)"header crc mismatch";
  78928. state->mode = BAD;
  78929. break;
  78930. }
  78931. INITBITS();
  78932. }
  78933. if (state->head != Z_NULL) {
  78934. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78935. state->head->done = 1;
  78936. }
  78937. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78938. state->mode = TYPE;
  78939. break;
  78940. #endif
  78941. case DICTID:
  78942. NEEDBITS(32);
  78943. strm->adler = state->check = REVERSE(hold);
  78944. INITBITS();
  78945. state->mode = DICT;
  78946. case DICT:
  78947. if (state->havedict == 0) {
  78948. RESTORE();
  78949. return Z_NEED_DICT;
  78950. }
  78951. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78952. state->mode = TYPE;
  78953. case TYPE:
  78954. if (flush == Z_BLOCK) goto inf_leave;
  78955. case TYPEDO:
  78956. if (state->last) {
  78957. BYTEBITS();
  78958. state->mode = CHECK;
  78959. break;
  78960. }
  78961. NEEDBITS(3);
  78962. state->last = BITS(1);
  78963. DROPBITS(1);
  78964. switch (BITS(2)) {
  78965. case 0: /* stored block */
  78966. Tracev((stderr, "inflate: stored block%s\n",
  78967. state->last ? " (last)" : ""));
  78968. state->mode = STORED;
  78969. break;
  78970. case 1: /* fixed block */
  78971. fixedtables(state);
  78972. Tracev((stderr, "inflate: fixed codes block%s\n",
  78973. state->last ? " (last)" : ""));
  78974. state->mode = LEN; /* decode codes */
  78975. break;
  78976. case 2: /* dynamic block */
  78977. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78978. state->last ? " (last)" : ""));
  78979. state->mode = TABLE;
  78980. break;
  78981. case 3:
  78982. strm->msg = (char *)"invalid block type";
  78983. state->mode = BAD;
  78984. }
  78985. DROPBITS(2);
  78986. break;
  78987. case STORED:
  78988. BYTEBITS(); /* go to byte boundary */
  78989. NEEDBITS(32);
  78990. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78991. strm->msg = (char *)"invalid stored block lengths";
  78992. state->mode = BAD;
  78993. break;
  78994. }
  78995. state->length = (unsigned)hold & 0xffff;
  78996. Tracev((stderr, "inflate: stored length %u\n",
  78997. state->length));
  78998. INITBITS();
  78999. state->mode = COPY;
  79000. case COPY:
  79001. copy = state->length;
  79002. if (copy) {
  79003. if (copy > have) copy = have;
  79004. if (copy > left) copy = left;
  79005. if (copy == 0) goto inf_leave;
  79006. zmemcpy(put, next, copy);
  79007. have -= copy;
  79008. next += copy;
  79009. left -= copy;
  79010. put += copy;
  79011. state->length -= copy;
  79012. break;
  79013. }
  79014. Tracev((stderr, "inflate: stored end\n"));
  79015. state->mode = TYPE;
  79016. break;
  79017. case TABLE:
  79018. NEEDBITS(14);
  79019. state->nlen = BITS(5) + 257;
  79020. DROPBITS(5);
  79021. state->ndist = BITS(5) + 1;
  79022. DROPBITS(5);
  79023. state->ncode = BITS(4) + 4;
  79024. DROPBITS(4);
  79025. #ifndef PKZIP_BUG_WORKAROUND
  79026. if (state->nlen > 286 || state->ndist > 30) {
  79027. strm->msg = (char *)"too many length or distance symbols";
  79028. state->mode = BAD;
  79029. break;
  79030. }
  79031. #endif
  79032. Tracev((stderr, "inflate: table sizes ok\n"));
  79033. state->have = 0;
  79034. state->mode = LENLENS;
  79035. case LENLENS:
  79036. while (state->have < state->ncode) {
  79037. NEEDBITS(3);
  79038. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  79039. DROPBITS(3);
  79040. }
  79041. while (state->have < 19)
  79042. state->lens[order[state->have++]] = 0;
  79043. state->next = state->codes;
  79044. state->lencode = (code const FAR *)(state->next);
  79045. state->lenbits = 7;
  79046. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  79047. &(state->lenbits), state->work);
  79048. if (ret) {
  79049. strm->msg = (char *)"invalid code lengths set";
  79050. state->mode = BAD;
  79051. break;
  79052. }
  79053. Tracev((stderr, "inflate: code lengths ok\n"));
  79054. state->have = 0;
  79055. state->mode = CODELENS;
  79056. case CODELENS:
  79057. while (state->have < state->nlen + state->ndist) {
  79058. for (;;) {
  79059. thisx = state->lencode[BITS(state->lenbits)];
  79060. if ((unsigned)(thisx.bits) <= bits) break;
  79061. PULLBYTE();
  79062. }
  79063. if (thisx.val < 16) {
  79064. NEEDBITS(thisx.bits);
  79065. DROPBITS(thisx.bits);
  79066. state->lens[state->have++] = thisx.val;
  79067. }
  79068. else {
  79069. if (thisx.val == 16) {
  79070. NEEDBITS(thisx.bits + 2);
  79071. DROPBITS(thisx.bits);
  79072. if (state->have == 0) {
  79073. strm->msg = (char *)"invalid bit length repeat";
  79074. state->mode = BAD;
  79075. break;
  79076. }
  79077. len = state->lens[state->have - 1];
  79078. copy = 3 + BITS(2);
  79079. DROPBITS(2);
  79080. }
  79081. else if (thisx.val == 17) {
  79082. NEEDBITS(thisx.bits + 3);
  79083. DROPBITS(thisx.bits);
  79084. len = 0;
  79085. copy = 3 + BITS(3);
  79086. DROPBITS(3);
  79087. }
  79088. else {
  79089. NEEDBITS(thisx.bits + 7);
  79090. DROPBITS(thisx.bits);
  79091. len = 0;
  79092. copy = 11 + BITS(7);
  79093. DROPBITS(7);
  79094. }
  79095. if (state->have + copy > state->nlen + state->ndist) {
  79096. strm->msg = (char *)"invalid bit length repeat";
  79097. state->mode = BAD;
  79098. break;
  79099. }
  79100. while (copy--)
  79101. state->lens[state->have++] = (unsigned short)len;
  79102. }
  79103. }
  79104. if (state->mode == BAD) break;
  79105. state->next = state->codes;
  79106. state->lencode = (code const FAR *)(state->next);
  79107. state->lenbits = 9;
  79108. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  79109. &(state->lenbits), state->work);
  79110. if (ret) {
  79111. strm->msg = (char *)"invalid literal/lengths set";
  79112. state->mode = BAD;
  79113. break;
  79114. }
  79115. state->distcode = (code const FAR *)(state->next);
  79116. state->distbits = 6;
  79117. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  79118. &(state->next), &(state->distbits), state->work);
  79119. if (ret) {
  79120. strm->msg = (char *)"invalid distances set";
  79121. state->mode = BAD;
  79122. break;
  79123. }
  79124. Tracev((stderr, "inflate: codes ok\n"));
  79125. state->mode = LEN;
  79126. case LEN:
  79127. if (have >= 6 && left >= 258) {
  79128. RESTORE();
  79129. inflate_fast(strm, out);
  79130. LOAD();
  79131. break;
  79132. }
  79133. for (;;) {
  79134. thisx = state->lencode[BITS(state->lenbits)];
  79135. if ((unsigned)(thisx.bits) <= bits) break;
  79136. PULLBYTE();
  79137. }
  79138. if (thisx.op && (thisx.op & 0xf0) == 0) {
  79139. last = thisx;
  79140. for (;;) {
  79141. thisx = state->lencode[last.val +
  79142. (BITS(last.bits + last.op) >> last.bits)];
  79143. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79144. PULLBYTE();
  79145. }
  79146. DROPBITS(last.bits);
  79147. }
  79148. DROPBITS(thisx.bits);
  79149. state->length = (unsigned)thisx.val;
  79150. if ((int)(thisx.op) == 0) {
  79151. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  79152. "inflate: literal '%c'\n" :
  79153. "inflate: literal 0x%02x\n", thisx.val));
  79154. state->mode = LIT;
  79155. break;
  79156. }
  79157. if (thisx.op & 32) {
  79158. Tracevv((stderr, "inflate: end of block\n"));
  79159. state->mode = TYPE;
  79160. break;
  79161. }
  79162. if (thisx.op & 64) {
  79163. strm->msg = (char *)"invalid literal/length code";
  79164. state->mode = BAD;
  79165. break;
  79166. }
  79167. state->extra = (unsigned)(thisx.op) & 15;
  79168. state->mode = LENEXT;
  79169. case LENEXT:
  79170. if (state->extra) {
  79171. NEEDBITS(state->extra);
  79172. state->length += BITS(state->extra);
  79173. DROPBITS(state->extra);
  79174. }
  79175. Tracevv((stderr, "inflate: length %u\n", state->length));
  79176. state->mode = DIST;
  79177. case DIST:
  79178. for (;;) {
  79179. thisx = state->distcode[BITS(state->distbits)];
  79180. if ((unsigned)(thisx.bits) <= bits) break;
  79181. PULLBYTE();
  79182. }
  79183. if ((thisx.op & 0xf0) == 0) {
  79184. last = thisx;
  79185. for (;;) {
  79186. thisx = state->distcode[last.val +
  79187. (BITS(last.bits + last.op) >> last.bits)];
  79188. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79189. PULLBYTE();
  79190. }
  79191. DROPBITS(last.bits);
  79192. }
  79193. DROPBITS(thisx.bits);
  79194. if (thisx.op & 64) {
  79195. strm->msg = (char *)"invalid distance code";
  79196. state->mode = BAD;
  79197. break;
  79198. }
  79199. state->offset = (unsigned)thisx.val;
  79200. state->extra = (unsigned)(thisx.op) & 15;
  79201. state->mode = DISTEXT;
  79202. case DISTEXT:
  79203. if (state->extra) {
  79204. NEEDBITS(state->extra);
  79205. state->offset += BITS(state->extra);
  79206. DROPBITS(state->extra);
  79207. }
  79208. #ifdef INFLATE_STRICT
  79209. if (state->offset > state->dmax) {
  79210. strm->msg = (char *)"invalid distance too far back";
  79211. state->mode = BAD;
  79212. break;
  79213. }
  79214. #endif
  79215. if (state->offset > state->whave + out - left) {
  79216. strm->msg = (char *)"invalid distance too far back";
  79217. state->mode = BAD;
  79218. break;
  79219. }
  79220. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  79221. state->mode = MATCH;
  79222. case MATCH:
  79223. if (left == 0) goto inf_leave;
  79224. copy = out - left;
  79225. if (state->offset > copy) { /* copy from window */
  79226. copy = state->offset - copy;
  79227. if (copy > state->write) {
  79228. copy -= state->write;
  79229. from = state->window + (state->wsize - copy);
  79230. }
  79231. else
  79232. from = state->window + (state->write - copy);
  79233. if (copy > state->length) copy = state->length;
  79234. }
  79235. else { /* copy from output */
  79236. from = put - state->offset;
  79237. copy = state->length;
  79238. }
  79239. if (copy > left) copy = left;
  79240. left -= copy;
  79241. state->length -= copy;
  79242. do {
  79243. *put++ = *from++;
  79244. } while (--copy);
  79245. if (state->length == 0) state->mode = LEN;
  79246. break;
  79247. case LIT:
  79248. if (left == 0) goto inf_leave;
  79249. *put++ = (unsigned char)(state->length);
  79250. left--;
  79251. state->mode = LEN;
  79252. break;
  79253. case CHECK:
  79254. if (state->wrap) {
  79255. NEEDBITS(32);
  79256. out -= left;
  79257. strm->total_out += out;
  79258. state->total += out;
  79259. if (out)
  79260. strm->adler = state->check =
  79261. UPDATE(state->check, put - out, out);
  79262. out = left;
  79263. if ((
  79264. #ifdef GUNZIP
  79265. state->flags ? hold :
  79266. #endif
  79267. REVERSE(hold)) != state->check) {
  79268. strm->msg = (char *)"incorrect data check";
  79269. state->mode = BAD;
  79270. break;
  79271. }
  79272. INITBITS();
  79273. Tracev((stderr, "inflate: check matches trailer\n"));
  79274. }
  79275. #ifdef GUNZIP
  79276. state->mode = LENGTH;
  79277. case LENGTH:
  79278. if (state->wrap && state->flags) {
  79279. NEEDBITS(32);
  79280. if (hold != (state->total & 0xffffffffUL)) {
  79281. strm->msg = (char *)"incorrect length check";
  79282. state->mode = BAD;
  79283. break;
  79284. }
  79285. INITBITS();
  79286. Tracev((stderr, "inflate: length matches trailer\n"));
  79287. }
  79288. #endif
  79289. state->mode = DONE;
  79290. case DONE:
  79291. ret = Z_STREAM_END;
  79292. goto inf_leave;
  79293. case BAD:
  79294. ret = Z_DATA_ERROR;
  79295. goto inf_leave;
  79296. case MEM:
  79297. return Z_MEM_ERROR;
  79298. case SYNC:
  79299. default:
  79300. return Z_STREAM_ERROR;
  79301. }
  79302. inf_leave:
  79303. RESTORE();
  79304. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  79305. if (updatewindow(strm, out)) {
  79306. state->mode = MEM;
  79307. return Z_MEM_ERROR;
  79308. }
  79309. in -= strm->avail_in;
  79310. out -= strm->avail_out;
  79311. strm->total_in += in;
  79312. strm->total_out += out;
  79313. state->total += out;
  79314. if (state->wrap && out)
  79315. strm->adler = state->check =
  79316. UPDATE(state->check, strm->next_out - out, out);
  79317. strm->data_type = state->bits + (state->last ? 64 : 0) +
  79318. (state->mode == TYPE ? 128 : 0);
  79319. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  79320. ret = Z_BUF_ERROR;
  79321. return ret;
  79322. }
  79323. int ZEXPORT inflateEnd (z_streamp strm)
  79324. {
  79325. struct inflate_state FAR *state;
  79326. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79327. return Z_STREAM_ERROR;
  79328. state = (struct inflate_state FAR *)strm->state;
  79329. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79330. ZFREE(strm, strm->state);
  79331. strm->state = Z_NULL;
  79332. Tracev((stderr, "inflate: end\n"));
  79333. return Z_OK;
  79334. }
  79335. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79336. {
  79337. struct inflate_state FAR *state;
  79338. unsigned long id_;
  79339. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79340. state = (struct inflate_state FAR *)strm->state;
  79341. if (state->wrap != 0 && state->mode != DICT)
  79342. return Z_STREAM_ERROR;
  79343. if (state->mode == DICT) {
  79344. id_ = adler32(0L, Z_NULL, 0);
  79345. id_ = adler32(id_, dictionary, dictLength);
  79346. if (id_ != state->check)
  79347. return Z_DATA_ERROR;
  79348. }
  79349. if (updatewindow(strm, strm->avail_out)) {
  79350. state->mode = MEM;
  79351. return Z_MEM_ERROR;
  79352. }
  79353. if (dictLength > state->wsize) {
  79354. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79355. state->wsize);
  79356. state->whave = state->wsize;
  79357. }
  79358. else {
  79359. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79360. dictLength);
  79361. state->whave = dictLength;
  79362. }
  79363. state->havedict = 1;
  79364. Tracev((stderr, "inflate: dictionary set\n"));
  79365. return Z_OK;
  79366. }
  79367. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79368. {
  79369. struct inflate_state FAR *state;
  79370. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79371. state = (struct inflate_state FAR *)strm->state;
  79372. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79373. state->head = head;
  79374. head->done = 0;
  79375. return Z_OK;
  79376. }
  79377. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79378. {
  79379. unsigned got;
  79380. unsigned next;
  79381. got = *have;
  79382. next = 0;
  79383. while (next < len && got < 4) {
  79384. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79385. got++;
  79386. else if (buf[next])
  79387. got = 0;
  79388. else
  79389. got = 4 - got;
  79390. next++;
  79391. }
  79392. *have = got;
  79393. return next;
  79394. }
  79395. int ZEXPORT inflateSync (z_streamp strm)
  79396. {
  79397. unsigned len; /* number of bytes to look at or looked at */
  79398. unsigned long in, out; /* temporary to save total_in and total_out */
  79399. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79400. struct inflate_state FAR *state;
  79401. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79402. state = (struct inflate_state FAR *)strm->state;
  79403. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79404. if (state->mode != SYNC) {
  79405. state->mode = SYNC;
  79406. state->hold <<= state->bits & 7;
  79407. state->bits -= state->bits & 7;
  79408. len = 0;
  79409. while (state->bits >= 8) {
  79410. buf[len++] = (unsigned char)(state->hold);
  79411. state->hold >>= 8;
  79412. state->bits -= 8;
  79413. }
  79414. state->have = 0;
  79415. syncsearch(&(state->have), buf, len);
  79416. }
  79417. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79418. strm->avail_in -= len;
  79419. strm->next_in += len;
  79420. strm->total_in += len;
  79421. if (state->have != 4) return Z_DATA_ERROR;
  79422. in = strm->total_in; out = strm->total_out;
  79423. inflateReset(strm);
  79424. strm->total_in = in; strm->total_out = out;
  79425. state->mode = TYPE;
  79426. return Z_OK;
  79427. }
  79428. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79429. {
  79430. struct inflate_state FAR *state;
  79431. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79432. state = (struct inflate_state FAR *)strm->state;
  79433. return state->mode == STORED && state->bits == 0;
  79434. }
  79435. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79436. {
  79437. struct inflate_state FAR *state;
  79438. struct inflate_state FAR *copy;
  79439. unsigned char FAR *window;
  79440. unsigned wsize;
  79441. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79442. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79443. return Z_STREAM_ERROR;
  79444. state = (struct inflate_state FAR *)source->state;
  79445. copy = (struct inflate_state FAR *)
  79446. ZALLOC(source, 1, sizeof(struct inflate_state));
  79447. if (copy == Z_NULL) return Z_MEM_ERROR;
  79448. window = Z_NULL;
  79449. if (state->window != Z_NULL) {
  79450. window = (unsigned char FAR *)
  79451. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79452. if (window == Z_NULL) {
  79453. ZFREE(source, copy);
  79454. return Z_MEM_ERROR;
  79455. }
  79456. }
  79457. zmemcpy(dest, source, sizeof(z_stream));
  79458. zmemcpy(copy, state, sizeof(struct inflate_state));
  79459. if (state->lencode >= state->codes &&
  79460. state->lencode <= state->codes + ENOUGH - 1) {
  79461. copy->lencode = copy->codes + (state->lencode - state->codes);
  79462. copy->distcode = copy->codes + (state->distcode - state->codes);
  79463. }
  79464. copy->next = copy->codes + (state->next - state->codes);
  79465. if (window != Z_NULL) {
  79466. wsize = 1U << state->wbits;
  79467. zmemcpy(window, state->window, wsize);
  79468. }
  79469. copy->window = window;
  79470. dest->state = (struct internal_state FAR *)copy;
  79471. return Z_OK;
  79472. }
  79473. /*** End of inlined file: inflate.c ***/
  79474. /*** Start of inlined file: inftrees.c ***/
  79475. #define MAXBITS 15
  79476. const char inflate_copyright[] =
  79477. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79478. int inflate_table (codetype type,
  79479. unsigned short FAR *lens,
  79480. unsigned codes,
  79481. code FAR * FAR *table,
  79482. unsigned FAR *bits,
  79483. unsigned short FAR *work)
  79484. {
  79485. unsigned len; /* a code's length in bits */
  79486. unsigned sym; /* index of code symbols */
  79487. unsigned min, max; /* minimum and maximum code lengths */
  79488. unsigned root; /* number of index bits for root table */
  79489. unsigned curr; /* number of index bits for current table */
  79490. unsigned drop; /* code bits to drop for sub-table */
  79491. int left; /* number of prefix codes available */
  79492. unsigned used; /* code entries in table used */
  79493. unsigned huff; /* Huffman code */
  79494. unsigned incr; /* for incrementing code, index */
  79495. unsigned fill; /* index for replicating entries */
  79496. unsigned low; /* low bits for current root entry */
  79497. unsigned mask; /* mask for low root bits */
  79498. code thisx; /* table entry for duplication */
  79499. code FAR *next; /* next available space in table */
  79500. const unsigned short FAR *base; /* base value table to use */
  79501. const unsigned short FAR *extra; /* extra bits table to use */
  79502. int end; /* use base and extra for symbol > end */
  79503. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79504. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79505. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79506. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79507. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79508. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79509. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79510. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79511. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79512. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79513. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79514. 8193, 12289, 16385, 24577, 0, 0};
  79515. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79516. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79517. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79518. 28, 28, 29, 29, 64, 64};
  79519. for (len = 0; len <= MAXBITS; len++)
  79520. count[len] = 0;
  79521. for (sym = 0; sym < codes; sym++)
  79522. count[lens[sym]]++;
  79523. root = *bits;
  79524. for (max = MAXBITS; max >= 1; max--)
  79525. if (count[max] != 0) break;
  79526. if (root > max) root = max;
  79527. if (max == 0) { /* no symbols to code at all */
  79528. thisx.op = (unsigned char)64; /* invalid code marker */
  79529. thisx.bits = (unsigned char)1;
  79530. thisx.val = (unsigned short)0;
  79531. *(*table)++ = thisx; /* make a table to force an error */
  79532. *(*table)++ = thisx;
  79533. *bits = 1;
  79534. return 0; /* no symbols, but wait for decoding to report error */
  79535. }
  79536. for (min = 1; min <= MAXBITS; min++)
  79537. if (count[min] != 0) break;
  79538. if (root < min) root = min;
  79539. left = 1;
  79540. for (len = 1; len <= MAXBITS; len++) {
  79541. left <<= 1;
  79542. left -= count[len];
  79543. if (left < 0) return -1; /* over-subscribed */
  79544. }
  79545. if (left > 0 && (type == CODES || max != 1))
  79546. return -1; /* incomplete set */
  79547. offs[1] = 0;
  79548. for (len = 1; len < MAXBITS; len++)
  79549. offs[len + 1] = offs[len] + count[len];
  79550. for (sym = 0; sym < codes; sym++)
  79551. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79552. switch (type) {
  79553. case CODES:
  79554. base = extra = work; /* dummy value--not used */
  79555. end = 19;
  79556. break;
  79557. case LENS:
  79558. base = lbase;
  79559. base -= 257;
  79560. extra = lext;
  79561. extra -= 257;
  79562. end = 256;
  79563. break;
  79564. default: /* DISTS */
  79565. base = dbase;
  79566. extra = dext;
  79567. end = -1;
  79568. }
  79569. huff = 0; /* starting code */
  79570. sym = 0; /* starting code symbol */
  79571. len = min; /* starting code length */
  79572. next = *table; /* current table to fill in */
  79573. curr = root; /* current table index bits */
  79574. drop = 0; /* current bits to drop from code for index */
  79575. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79576. used = 1U << root; /* use root table entries */
  79577. mask = used - 1; /* mask for comparing low */
  79578. if (type == LENS && used >= ENOUGH - MAXD)
  79579. return 1;
  79580. for (;;) {
  79581. thisx.bits = (unsigned char)(len - drop);
  79582. if ((int)(work[sym]) < end) {
  79583. thisx.op = (unsigned char)0;
  79584. thisx.val = work[sym];
  79585. }
  79586. else if ((int)(work[sym]) > end) {
  79587. thisx.op = (unsigned char)(extra[work[sym]]);
  79588. thisx.val = base[work[sym]];
  79589. }
  79590. else {
  79591. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79592. thisx.val = 0;
  79593. }
  79594. incr = 1U << (len - drop);
  79595. fill = 1U << curr;
  79596. min = fill; /* save offset to next table */
  79597. do {
  79598. fill -= incr;
  79599. next[(huff >> drop) + fill] = thisx;
  79600. } while (fill != 0);
  79601. incr = 1U << (len - 1);
  79602. while (huff & incr)
  79603. incr >>= 1;
  79604. if (incr != 0) {
  79605. huff &= incr - 1;
  79606. huff += incr;
  79607. }
  79608. else
  79609. huff = 0;
  79610. sym++;
  79611. if (--(count[len]) == 0) {
  79612. if (len == max) break;
  79613. len = lens[work[sym]];
  79614. }
  79615. if (len > root && (huff & mask) != low) {
  79616. if (drop == 0)
  79617. drop = root;
  79618. next += min; /* here min is 1 << curr */
  79619. curr = len - drop;
  79620. left = (int)(1 << curr);
  79621. while (curr + drop < max) {
  79622. left -= count[curr + drop];
  79623. if (left <= 0) break;
  79624. curr++;
  79625. left <<= 1;
  79626. }
  79627. used += 1U << curr;
  79628. if (type == LENS && used >= ENOUGH - MAXD)
  79629. return 1;
  79630. low = huff & mask;
  79631. (*table)[low].op = (unsigned char)curr;
  79632. (*table)[low].bits = (unsigned char)root;
  79633. (*table)[low].val = (unsigned short)(next - *table);
  79634. }
  79635. }
  79636. thisx.op = (unsigned char)64; /* invalid code marker */
  79637. thisx.bits = (unsigned char)(len - drop);
  79638. thisx.val = (unsigned short)0;
  79639. while (huff != 0) {
  79640. if (drop != 0 && (huff & mask) != low) {
  79641. drop = 0;
  79642. len = root;
  79643. next = *table;
  79644. thisx.bits = (unsigned char)len;
  79645. }
  79646. next[huff >> drop] = thisx;
  79647. incr = 1U << (len - 1);
  79648. while (huff & incr)
  79649. incr >>= 1;
  79650. if (incr != 0) {
  79651. huff &= incr - 1;
  79652. huff += incr;
  79653. }
  79654. else
  79655. huff = 0;
  79656. }
  79657. *table += used;
  79658. *bits = root;
  79659. return 0;
  79660. }
  79661. /*** End of inlined file: inftrees.c ***/
  79662. /*** Start of inlined file: trees.c ***/
  79663. #ifdef DEBUG
  79664. # include <ctype.h>
  79665. #endif
  79666. #define MAX_BL_BITS 7
  79667. #define END_BLOCK 256
  79668. #define REP_3_6 16
  79669. #define REPZ_3_10 17
  79670. #define REPZ_11_138 18
  79671. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79672. = {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};
  79673. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79674. = {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};
  79675. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79676. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79677. local const uch bl_order[BL_CODES]
  79678. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79679. #define Buf_size (8 * 2*sizeof(char))
  79680. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79681. #if defined(GEN_TREES_H) || !defined(STDC)
  79682. local ct_data static_ltree[L_CODES+2];
  79683. local ct_data static_dtree[D_CODES];
  79684. uch _dist_code[DIST_CODE_LEN];
  79685. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79686. local int base_length[LENGTH_CODES];
  79687. local int base_dist[D_CODES];
  79688. #else
  79689. /*** Start of inlined file: trees.h ***/
  79690. local const ct_data static_ltree[L_CODES+2] = {
  79691. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79692. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79693. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79694. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79695. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79696. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79697. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79698. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79699. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79700. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79701. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79702. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79703. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79704. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79705. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79706. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79707. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79708. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79709. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79710. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79711. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79712. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79713. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79714. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79715. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79716. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79717. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79718. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79719. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79720. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79721. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79722. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79723. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79724. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79725. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79726. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79727. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79728. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79729. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79730. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79731. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79732. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79733. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79734. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79735. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79736. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79737. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79738. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79739. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79740. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79741. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79742. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79743. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79744. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79745. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79746. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79747. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79748. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79749. };
  79750. local const ct_data static_dtree[D_CODES] = {
  79751. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79752. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79753. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79754. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79755. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79756. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79757. };
  79758. const uch _dist_code[DIST_CODE_LEN] = {
  79759. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79760. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79761. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79762. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79763. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79764. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79765. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79766. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79767. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79768. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79769. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79770. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79771. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79772. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79773. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79774. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79775. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79776. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79777. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79778. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79779. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79780. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79781. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79782. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79783. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79784. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79785. };
  79786. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79787. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79788. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79789. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79790. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79791. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79792. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79793. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79794. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79795. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79796. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79797. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79798. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79799. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79800. };
  79801. local const int base_length[LENGTH_CODES] = {
  79802. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79803. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79804. };
  79805. local const int base_dist[D_CODES] = {
  79806. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79807. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79808. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79809. };
  79810. /*** End of inlined file: trees.h ***/
  79811. #endif /* GEN_TREES_H */
  79812. struct static_tree_desc_s {
  79813. const ct_data *static_tree; /* static tree or NULL */
  79814. const intf *extra_bits; /* extra bits for each code or NULL */
  79815. int extra_base; /* base index for extra_bits */
  79816. int elems; /* max number of elements in the tree */
  79817. int max_length; /* max bit length for the codes */
  79818. };
  79819. local static_tree_desc static_l_desc =
  79820. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79821. local static_tree_desc static_d_desc =
  79822. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79823. local static_tree_desc static_bl_desc =
  79824. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79825. local void tr_static_init OF((void));
  79826. local void init_block OF((deflate_state *s));
  79827. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79828. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79829. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79830. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79831. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79832. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79833. local int build_bl_tree OF((deflate_state *s));
  79834. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79835. int blcodes));
  79836. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79837. ct_data *dtree));
  79838. local void set_data_type OF((deflate_state *s));
  79839. local unsigned bi_reverse OF((unsigned value, int length));
  79840. local void bi_windup OF((deflate_state *s));
  79841. local void bi_flush OF((deflate_state *s));
  79842. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79843. int header));
  79844. #ifdef GEN_TREES_H
  79845. local void gen_trees_header OF((void));
  79846. #endif
  79847. #ifndef DEBUG
  79848. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79849. #else /* DEBUG */
  79850. # define send_code(s, c, tree) \
  79851. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79852. send_bits(s, tree[c].Code, tree[c].Len); }
  79853. #endif
  79854. #define put_short(s, w) { \
  79855. put_byte(s, (uch)((w) & 0xff)); \
  79856. put_byte(s, (uch)((ush)(w) >> 8)); \
  79857. }
  79858. #ifdef DEBUG
  79859. local void send_bits OF((deflate_state *s, int value, int length));
  79860. local void send_bits (deflate_state *s, int value, int length)
  79861. {
  79862. Tracevv((stderr," l %2d v %4x ", length, value));
  79863. Assert(length > 0 && length <= 15, "invalid length");
  79864. s->bits_sent += (ulg)length;
  79865. if (s->bi_valid > (int)Buf_size - length) {
  79866. s->bi_buf |= (value << s->bi_valid);
  79867. put_short(s, s->bi_buf);
  79868. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79869. s->bi_valid += length - Buf_size;
  79870. } else {
  79871. s->bi_buf |= value << s->bi_valid;
  79872. s->bi_valid += length;
  79873. }
  79874. }
  79875. #else /* !DEBUG */
  79876. #define send_bits(s, value, length) \
  79877. { int len = length;\
  79878. if (s->bi_valid > (int)Buf_size - len) {\
  79879. int val = value;\
  79880. s->bi_buf |= (val << s->bi_valid);\
  79881. put_short(s, s->bi_buf);\
  79882. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79883. s->bi_valid += len - Buf_size;\
  79884. } else {\
  79885. s->bi_buf |= (value) << s->bi_valid;\
  79886. s->bi_valid += len;\
  79887. }\
  79888. }
  79889. #endif /* DEBUG */
  79890. local void tr_static_init()
  79891. {
  79892. #if defined(GEN_TREES_H) || !defined(STDC)
  79893. static int static_init_done = 0;
  79894. int n; /* iterates over tree elements */
  79895. int bits; /* bit counter */
  79896. int length; /* length value */
  79897. int code; /* code value */
  79898. int dist; /* distance index */
  79899. ush bl_count[MAX_BITS+1];
  79900. if (static_init_done) return;
  79901. static_l_desc.static_tree = static_ltree;
  79902. static_l_desc.extra_bits = extra_lbits;
  79903. static_d_desc.static_tree = static_dtree;
  79904. static_d_desc.extra_bits = extra_dbits;
  79905. static_bl_desc.extra_bits = extra_blbits;
  79906. length = 0;
  79907. for (code = 0; code < LENGTH_CODES-1; code++) {
  79908. base_length[code] = length;
  79909. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79910. _length_code[length++] = (uch)code;
  79911. }
  79912. }
  79913. Assert (length == 256, "tr_static_init: length != 256");
  79914. _length_code[length-1] = (uch)code;
  79915. dist = 0;
  79916. for (code = 0 ; code < 16; code++) {
  79917. base_dist[code] = dist;
  79918. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79919. _dist_code[dist++] = (uch)code;
  79920. }
  79921. }
  79922. Assert (dist == 256, "tr_static_init: dist != 256");
  79923. dist >>= 7; /* from now on, all distances are divided by 128 */
  79924. for ( ; code < D_CODES; code++) {
  79925. base_dist[code] = dist << 7;
  79926. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79927. _dist_code[256 + dist++] = (uch)code;
  79928. }
  79929. }
  79930. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79931. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79932. n = 0;
  79933. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79934. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79935. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79936. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79937. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79938. for (n = 0; n < D_CODES; n++) {
  79939. static_dtree[n].Len = 5;
  79940. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79941. }
  79942. static_init_done = 1;
  79943. # ifdef GEN_TREES_H
  79944. gen_trees_header();
  79945. # endif
  79946. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79947. }
  79948. #ifdef GEN_TREES_H
  79949. # ifndef DEBUG
  79950. # include <stdio.h>
  79951. # endif
  79952. # define SEPARATOR(i, last, width) \
  79953. ((i) == (last)? "\n};\n\n" : \
  79954. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79955. void gen_trees_header()
  79956. {
  79957. FILE *header = fopen("trees.h", "w");
  79958. int i;
  79959. Assert (header != NULL, "Can't open trees.h");
  79960. fprintf(header,
  79961. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79962. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79963. for (i = 0; i < L_CODES+2; i++) {
  79964. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79965. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79966. }
  79967. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79968. for (i = 0; i < D_CODES; i++) {
  79969. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79970. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79971. }
  79972. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79973. for (i = 0; i < DIST_CODE_LEN; i++) {
  79974. fprintf(header, "%2u%s", _dist_code[i],
  79975. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79976. }
  79977. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79978. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79979. fprintf(header, "%2u%s", _length_code[i],
  79980. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79981. }
  79982. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79983. for (i = 0; i < LENGTH_CODES; i++) {
  79984. fprintf(header, "%1u%s", base_length[i],
  79985. SEPARATOR(i, LENGTH_CODES-1, 20));
  79986. }
  79987. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79988. for (i = 0; i < D_CODES; i++) {
  79989. fprintf(header, "%5u%s", base_dist[i],
  79990. SEPARATOR(i, D_CODES-1, 10));
  79991. }
  79992. fclose(header);
  79993. }
  79994. #endif /* GEN_TREES_H */
  79995. void _tr_init(deflate_state *s)
  79996. {
  79997. tr_static_init();
  79998. s->l_desc.dyn_tree = s->dyn_ltree;
  79999. s->l_desc.stat_desc = &static_l_desc;
  80000. s->d_desc.dyn_tree = s->dyn_dtree;
  80001. s->d_desc.stat_desc = &static_d_desc;
  80002. s->bl_desc.dyn_tree = s->bl_tree;
  80003. s->bl_desc.stat_desc = &static_bl_desc;
  80004. s->bi_buf = 0;
  80005. s->bi_valid = 0;
  80006. s->last_eob_len = 8; /* enough lookahead for inflate */
  80007. #ifdef DEBUG
  80008. s->compressed_len = 0L;
  80009. s->bits_sent = 0L;
  80010. #endif
  80011. init_block(s);
  80012. }
  80013. local void init_block (deflate_state *s)
  80014. {
  80015. int n; /* iterates over tree elements */
  80016. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  80017. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  80018. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  80019. s->dyn_ltree[END_BLOCK].Freq = 1;
  80020. s->opt_len = s->static_len = 0L;
  80021. s->last_lit = s->matches = 0;
  80022. }
  80023. #define SMALLEST 1
  80024. #define pqremove(s, tree, top) \
  80025. {\
  80026. top = s->heap[SMALLEST]; \
  80027. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  80028. pqdownheap(s, tree, SMALLEST); \
  80029. }
  80030. #define smaller(tree, n, m, depth) \
  80031. (tree[n].Freq < tree[m].Freq || \
  80032. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  80033. local void pqdownheap (deflate_state *s,
  80034. ct_data *tree, /* the tree to restore */
  80035. int k) /* node to move down */
  80036. {
  80037. int v = s->heap[k];
  80038. int j = k << 1; /* left son of k */
  80039. while (j <= s->heap_len) {
  80040. if (j < s->heap_len &&
  80041. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  80042. j++;
  80043. }
  80044. if (smaller(tree, v, s->heap[j], s->depth)) break;
  80045. s->heap[k] = s->heap[j]; k = j;
  80046. j <<= 1;
  80047. }
  80048. s->heap[k] = v;
  80049. }
  80050. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  80051. {
  80052. ct_data *tree = desc->dyn_tree;
  80053. int max_code = desc->max_code;
  80054. const ct_data *stree = desc->stat_desc->static_tree;
  80055. const intf *extra = desc->stat_desc->extra_bits;
  80056. int base = desc->stat_desc->extra_base;
  80057. int max_length = desc->stat_desc->max_length;
  80058. int h; /* heap index */
  80059. int n, m; /* iterate over the tree elements */
  80060. int bits; /* bit length */
  80061. int xbits; /* extra bits */
  80062. ush f; /* frequency */
  80063. int overflow = 0; /* number of elements with bit length too large */
  80064. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  80065. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  80066. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  80067. n = s->heap[h];
  80068. bits = tree[tree[n].Dad].Len + 1;
  80069. if (bits > max_length) bits = max_length, overflow++;
  80070. tree[n].Len = (ush)bits;
  80071. if (n > max_code) continue; /* not a leaf node */
  80072. s->bl_count[bits]++;
  80073. xbits = 0;
  80074. if (n >= base) xbits = extra[n-base];
  80075. f = tree[n].Freq;
  80076. s->opt_len += (ulg)f * (bits + xbits);
  80077. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  80078. }
  80079. if (overflow == 0) return;
  80080. Trace((stderr,"\nbit length overflow\n"));
  80081. do {
  80082. bits = max_length-1;
  80083. while (s->bl_count[bits] == 0) bits--;
  80084. s->bl_count[bits]--; /* move one leaf down the tree */
  80085. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  80086. s->bl_count[max_length]--;
  80087. overflow -= 2;
  80088. } while (overflow > 0);
  80089. for (bits = max_length; bits != 0; bits--) {
  80090. n = s->bl_count[bits];
  80091. while (n != 0) {
  80092. m = s->heap[--h];
  80093. if (m > max_code) continue;
  80094. if ((unsigned) tree[m].Len != (unsigned) bits) {
  80095. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  80096. s->opt_len += ((long)bits - (long)tree[m].Len)
  80097. *(long)tree[m].Freq;
  80098. tree[m].Len = (ush)bits;
  80099. }
  80100. n--;
  80101. }
  80102. }
  80103. }
  80104. local void gen_codes (ct_data *tree, /* the tree to decorate */
  80105. int max_code, /* largest code with non zero frequency */
  80106. ushf *bl_count) /* number of codes at each bit length */
  80107. {
  80108. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  80109. ush code = 0; /* running code value */
  80110. int bits; /* bit index */
  80111. int n; /* code index */
  80112. for (bits = 1; bits <= MAX_BITS; bits++) {
  80113. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  80114. }
  80115. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  80116. "inconsistent bit counts");
  80117. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  80118. for (n = 0; n <= max_code; n++) {
  80119. int len = tree[n].Len;
  80120. if (len == 0) continue;
  80121. tree[n].Code = bi_reverse(next_code[len]++, len);
  80122. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  80123. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  80124. }
  80125. }
  80126. local void build_tree (deflate_state *s,
  80127. tree_desc *desc) /* the tree descriptor */
  80128. {
  80129. ct_data *tree = desc->dyn_tree;
  80130. const ct_data *stree = desc->stat_desc->static_tree;
  80131. int elems = desc->stat_desc->elems;
  80132. int n, m; /* iterate over heap elements */
  80133. int max_code = -1; /* largest code with non zero frequency */
  80134. int node; /* new node being created */
  80135. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  80136. for (n = 0; n < elems; n++) {
  80137. if (tree[n].Freq != 0) {
  80138. s->heap[++(s->heap_len)] = max_code = n;
  80139. s->depth[n] = 0;
  80140. } else {
  80141. tree[n].Len = 0;
  80142. }
  80143. }
  80144. while (s->heap_len < 2) {
  80145. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  80146. tree[node].Freq = 1;
  80147. s->depth[node] = 0;
  80148. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  80149. }
  80150. desc->max_code = max_code;
  80151. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  80152. node = elems; /* next internal node of the tree */
  80153. do {
  80154. pqremove(s, tree, n); /* n = node of least frequency */
  80155. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  80156. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  80157. s->heap[--(s->heap_max)] = m;
  80158. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  80159. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  80160. s->depth[n] : s->depth[m]) + 1);
  80161. tree[n].Dad = tree[m].Dad = (ush)node;
  80162. #ifdef DUMP_BL_TREE
  80163. if (tree == s->bl_tree) {
  80164. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  80165. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  80166. }
  80167. #endif
  80168. s->heap[SMALLEST] = node++;
  80169. pqdownheap(s, tree, SMALLEST);
  80170. } while (s->heap_len >= 2);
  80171. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  80172. gen_bitlen(s, (tree_desc *)desc);
  80173. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  80174. }
  80175. local void scan_tree (deflate_state *s,
  80176. ct_data *tree, /* the tree to be scanned */
  80177. int max_code) /* and its largest code of non zero frequency */
  80178. {
  80179. int n; /* iterates over all tree elements */
  80180. int prevlen = -1; /* last emitted length */
  80181. int curlen; /* length of current code */
  80182. int nextlen = tree[0].Len; /* length of next code */
  80183. int count = 0; /* repeat count of the current code */
  80184. int max_count = 7; /* max repeat count */
  80185. int min_count = 4; /* min repeat count */
  80186. if (nextlen == 0) max_count = 138, min_count = 3;
  80187. tree[max_code+1].Len = (ush)0xffff; /* guard */
  80188. for (n = 0; n <= max_code; n++) {
  80189. curlen = nextlen; nextlen = tree[n+1].Len;
  80190. if (++count < max_count && curlen == nextlen) {
  80191. continue;
  80192. } else if (count < min_count) {
  80193. s->bl_tree[curlen].Freq += count;
  80194. } else if (curlen != 0) {
  80195. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  80196. s->bl_tree[REP_3_6].Freq++;
  80197. } else if (count <= 10) {
  80198. s->bl_tree[REPZ_3_10].Freq++;
  80199. } else {
  80200. s->bl_tree[REPZ_11_138].Freq++;
  80201. }
  80202. count = 0; prevlen = curlen;
  80203. if (nextlen == 0) {
  80204. max_count = 138, min_count = 3;
  80205. } else if (curlen == nextlen) {
  80206. max_count = 6, min_count = 3;
  80207. } else {
  80208. max_count = 7, min_count = 4;
  80209. }
  80210. }
  80211. }
  80212. local void send_tree (deflate_state *s,
  80213. ct_data *tree, /* the tree to be scanned */
  80214. int max_code) /* and its largest code of non zero frequency */
  80215. {
  80216. int n; /* iterates over all tree elements */
  80217. int prevlen = -1; /* last emitted length */
  80218. int curlen; /* length of current code */
  80219. int nextlen = tree[0].Len; /* length of next code */
  80220. int count = 0; /* repeat count of the current code */
  80221. int max_count = 7; /* max repeat count */
  80222. int min_count = 4; /* min repeat count */
  80223. /* guard already set */
  80224. if (nextlen == 0) max_count = 138, min_count = 3;
  80225. for (n = 0; n <= max_code; n++) {
  80226. curlen = nextlen; nextlen = tree[n+1].Len;
  80227. if (++count < max_count && curlen == nextlen) {
  80228. continue;
  80229. } else if (count < min_count) {
  80230. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  80231. } else if (curlen != 0) {
  80232. if (curlen != prevlen) {
  80233. send_code(s, curlen, s->bl_tree); count--;
  80234. }
  80235. Assert(count >= 3 && count <= 6, " 3_6?");
  80236. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  80237. } else if (count <= 10) {
  80238. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  80239. } else {
  80240. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  80241. }
  80242. count = 0; prevlen = curlen;
  80243. if (nextlen == 0) {
  80244. max_count = 138, min_count = 3;
  80245. } else if (curlen == nextlen) {
  80246. max_count = 6, min_count = 3;
  80247. } else {
  80248. max_count = 7, min_count = 4;
  80249. }
  80250. }
  80251. }
  80252. local int build_bl_tree (deflate_state *s)
  80253. {
  80254. int max_blindex; /* index of last bit length code of non zero freq */
  80255. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  80256. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  80257. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  80258. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  80259. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  80260. }
  80261. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  80262. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  80263. s->opt_len, s->static_len));
  80264. return max_blindex;
  80265. }
  80266. local void send_all_trees (deflate_state *s,
  80267. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  80268. {
  80269. int rank; /* index in bl_order */
  80270. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  80271. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  80272. "too many codes");
  80273. Tracev((stderr, "\nbl counts: "));
  80274. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  80275. send_bits(s, dcodes-1, 5);
  80276. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  80277. for (rank = 0; rank < blcodes; rank++) {
  80278. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  80279. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  80280. }
  80281. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  80282. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  80283. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  80284. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  80285. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  80286. }
  80287. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  80288. {
  80289. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  80290. #ifdef DEBUG
  80291. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  80292. s->compressed_len += (stored_len + 4) << 3;
  80293. #endif
  80294. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  80295. }
  80296. void _tr_align (deflate_state *s)
  80297. {
  80298. send_bits(s, STATIC_TREES<<1, 3);
  80299. send_code(s, END_BLOCK, static_ltree);
  80300. #ifdef DEBUG
  80301. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  80302. #endif
  80303. bi_flush(s);
  80304. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  80305. send_bits(s, STATIC_TREES<<1, 3);
  80306. send_code(s, END_BLOCK, static_ltree);
  80307. #ifdef DEBUG
  80308. s->compressed_len += 10L;
  80309. #endif
  80310. bi_flush(s);
  80311. }
  80312. s->last_eob_len = 7;
  80313. }
  80314. void _tr_flush_block (deflate_state *s,
  80315. charf *buf, /* input block, or NULL if too old */
  80316. ulg stored_len, /* length of input block */
  80317. int eof) /* true if this is the last block for a file */
  80318. {
  80319. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  80320. int max_blindex = 0; /* index of last bit length code of non zero freq */
  80321. if (s->level > 0) {
  80322. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80323. set_data_type(s);
  80324. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80325. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80326. s->static_len));
  80327. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80328. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80329. s->static_len));
  80330. max_blindex = build_bl_tree(s);
  80331. opt_lenb = (s->opt_len+3+7)>>3;
  80332. static_lenb = (s->static_len+3+7)>>3;
  80333. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80334. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80335. s->last_lit));
  80336. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80337. } else {
  80338. Assert(buf != (char*)0, "lost buf");
  80339. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80340. }
  80341. #ifdef FORCE_STORED
  80342. if (buf != (char*)0) { /* force stored block */
  80343. #else
  80344. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80345. #endif
  80346. _tr_stored_block(s, buf, stored_len, eof);
  80347. #ifdef FORCE_STATIC
  80348. } else if (static_lenb >= 0) { /* force static trees */
  80349. #else
  80350. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80351. #endif
  80352. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80353. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80354. #ifdef DEBUG
  80355. s->compressed_len += 3 + s->static_len;
  80356. #endif
  80357. } else {
  80358. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80359. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80360. max_blindex+1);
  80361. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80362. #ifdef DEBUG
  80363. s->compressed_len += 3 + s->opt_len;
  80364. #endif
  80365. }
  80366. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80367. init_block(s);
  80368. if (eof) {
  80369. bi_windup(s);
  80370. #ifdef DEBUG
  80371. s->compressed_len += 7; /* align on byte boundary */
  80372. #endif
  80373. }
  80374. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80375. s->compressed_len-7*eof));
  80376. }
  80377. int _tr_tally (deflate_state *s,
  80378. unsigned dist, /* distance of matched string */
  80379. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80380. {
  80381. s->d_buf[s->last_lit] = (ush)dist;
  80382. s->l_buf[s->last_lit++] = (uch)lc;
  80383. if (dist == 0) {
  80384. s->dyn_ltree[lc].Freq++;
  80385. } else {
  80386. s->matches++;
  80387. dist--; /* dist = match distance - 1 */
  80388. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80389. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80390. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80391. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80392. s->dyn_dtree[d_code(dist)].Freq++;
  80393. }
  80394. #ifdef TRUNCATE_BLOCK
  80395. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80396. ulg out_length = (ulg)s->last_lit*8L;
  80397. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80398. int dcode;
  80399. for (dcode = 0; dcode < D_CODES; dcode++) {
  80400. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80401. (5L+extra_dbits[dcode]);
  80402. }
  80403. out_length >>= 3;
  80404. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80405. s->last_lit, in_length, out_length,
  80406. 100L - out_length*100L/in_length));
  80407. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80408. }
  80409. #endif
  80410. return (s->last_lit == s->lit_bufsize-1);
  80411. }
  80412. local void compress_block (deflate_state *s,
  80413. ct_data *ltree, /* literal tree */
  80414. ct_data *dtree) /* distance tree */
  80415. {
  80416. unsigned dist; /* distance of matched string */
  80417. int lc; /* match length or unmatched char (if dist == 0) */
  80418. unsigned lx = 0; /* running index in l_buf */
  80419. unsigned code; /* the code to send */
  80420. int extra; /* number of extra bits to send */
  80421. if (s->last_lit != 0) do {
  80422. dist = s->d_buf[lx];
  80423. lc = s->l_buf[lx++];
  80424. if (dist == 0) {
  80425. send_code(s, lc, ltree); /* send a literal byte */
  80426. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80427. } else {
  80428. code = _length_code[lc];
  80429. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80430. extra = extra_lbits[code];
  80431. if (extra != 0) {
  80432. lc -= base_length[code];
  80433. send_bits(s, lc, extra); /* send the extra length bits */
  80434. }
  80435. dist--; /* dist is now the match distance - 1 */
  80436. code = d_code(dist);
  80437. Assert (code < D_CODES, "bad d_code");
  80438. send_code(s, code, dtree); /* send the distance code */
  80439. extra = extra_dbits[code];
  80440. if (extra != 0) {
  80441. dist -= base_dist[code];
  80442. send_bits(s, dist, extra); /* send the extra distance bits */
  80443. }
  80444. } /* literal or match pair ? */
  80445. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80446. "pendingBuf overflow");
  80447. } while (lx < s->last_lit);
  80448. send_code(s, END_BLOCK, ltree);
  80449. s->last_eob_len = ltree[END_BLOCK].Len;
  80450. }
  80451. local void set_data_type (deflate_state *s)
  80452. {
  80453. int n;
  80454. for (n = 0; n < 9; n++)
  80455. if (s->dyn_ltree[n].Freq != 0)
  80456. break;
  80457. if (n == 9)
  80458. for (n = 14; n < 32; n++)
  80459. if (s->dyn_ltree[n].Freq != 0)
  80460. break;
  80461. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80462. }
  80463. local unsigned bi_reverse (unsigned code, int len)
  80464. {
  80465. register unsigned res = 0;
  80466. do {
  80467. res |= code & 1;
  80468. code >>= 1, res <<= 1;
  80469. } while (--len > 0);
  80470. return res >> 1;
  80471. }
  80472. local void bi_flush (deflate_state *s)
  80473. {
  80474. if (s->bi_valid == 16) {
  80475. put_short(s, s->bi_buf);
  80476. s->bi_buf = 0;
  80477. s->bi_valid = 0;
  80478. } else if (s->bi_valid >= 8) {
  80479. put_byte(s, (Byte)s->bi_buf);
  80480. s->bi_buf >>= 8;
  80481. s->bi_valid -= 8;
  80482. }
  80483. }
  80484. local void bi_windup (deflate_state *s)
  80485. {
  80486. if (s->bi_valid > 8) {
  80487. put_short(s, s->bi_buf);
  80488. } else if (s->bi_valid > 0) {
  80489. put_byte(s, (Byte)s->bi_buf);
  80490. }
  80491. s->bi_buf = 0;
  80492. s->bi_valid = 0;
  80493. #ifdef DEBUG
  80494. s->bits_sent = (s->bits_sent+7) & ~7;
  80495. #endif
  80496. }
  80497. local void copy_block(deflate_state *s,
  80498. charf *buf, /* the input data */
  80499. unsigned len, /* its length */
  80500. int header) /* true if block header must be written */
  80501. {
  80502. bi_windup(s); /* align on byte boundary */
  80503. s->last_eob_len = 8; /* enough lookahead for inflate */
  80504. if (header) {
  80505. put_short(s, (ush)len);
  80506. put_short(s, (ush)~len);
  80507. #ifdef DEBUG
  80508. s->bits_sent += 2*16;
  80509. #endif
  80510. }
  80511. #ifdef DEBUG
  80512. s->bits_sent += (ulg)len<<3;
  80513. #endif
  80514. while (len--) {
  80515. put_byte(s, *buf++);
  80516. }
  80517. }
  80518. /*** End of inlined file: trees.c ***/
  80519. /*** Start of inlined file: zutil.c ***/
  80520. #ifndef NO_DUMMY_DECL
  80521. struct internal_state {int dummy;}; /* for buggy compilers */
  80522. #endif
  80523. const char * const z_errmsg[10] = {
  80524. "need dictionary", /* Z_NEED_DICT 2 */
  80525. "stream end", /* Z_STREAM_END 1 */
  80526. "", /* Z_OK 0 */
  80527. "file error", /* Z_ERRNO (-1) */
  80528. "stream error", /* Z_STREAM_ERROR (-2) */
  80529. "data error", /* Z_DATA_ERROR (-3) */
  80530. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80531. "buffer error", /* Z_BUF_ERROR (-5) */
  80532. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80533. ""};
  80534. #ifdef DEBUG
  80535. # ifndef verbose
  80536. # define verbose 0
  80537. # endif
  80538. int z_verbose = verbose;
  80539. void z_error (const char *m)
  80540. {
  80541. fprintf(stderr, "%s\n", m);
  80542. exit(1);
  80543. }
  80544. #endif
  80545. const char * ZEXPORT zError(int err)
  80546. {
  80547. return ERR_MSG(err);
  80548. }
  80549. #if defined(_WIN32_WCE)
  80550. int errno = 0;
  80551. #endif
  80552. #ifndef HAVE_MEMCPY
  80553. void zmemcpy(dest, source, len)
  80554. Bytef* dest;
  80555. const Bytef* source;
  80556. uInt len;
  80557. {
  80558. if (len == 0) return;
  80559. do {
  80560. *dest++ = *source++; /* ??? to be unrolled */
  80561. } while (--len != 0);
  80562. }
  80563. int zmemcmp(s1, s2, len)
  80564. const Bytef* s1;
  80565. const Bytef* s2;
  80566. uInt len;
  80567. {
  80568. uInt j;
  80569. for (j = 0; j < len; j++) {
  80570. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80571. }
  80572. return 0;
  80573. }
  80574. void zmemzero(dest, len)
  80575. Bytef* dest;
  80576. uInt len;
  80577. {
  80578. if (len == 0) return;
  80579. do {
  80580. *dest++ = 0; /* ??? to be unrolled */
  80581. } while (--len != 0);
  80582. }
  80583. #endif
  80584. #ifdef SYS16BIT
  80585. #ifdef __TURBOC__
  80586. # define MY_ZCALLOC
  80587. #define MAX_PTR 10
  80588. local int next_ptr = 0;
  80589. typedef struct ptr_table_s {
  80590. voidpf org_ptr;
  80591. voidpf new_ptr;
  80592. } ptr_table;
  80593. local ptr_table table[MAX_PTR];
  80594. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80595. {
  80596. voidpf buf = opaque; /* just to make some compilers happy */
  80597. ulg bsize = (ulg)items*size;
  80598. if (bsize < 65520L) {
  80599. buf = farmalloc(bsize);
  80600. if (*(ush*)&buf != 0) return buf;
  80601. } else {
  80602. buf = farmalloc(bsize + 16L);
  80603. }
  80604. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80605. table[next_ptr].org_ptr = buf;
  80606. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80607. *(ush*)&buf = 0;
  80608. table[next_ptr++].new_ptr = buf;
  80609. return buf;
  80610. }
  80611. void zcfree (voidpf opaque, voidpf ptr)
  80612. {
  80613. int n;
  80614. if (*(ush*)&ptr != 0) { /* object < 64K */
  80615. farfree(ptr);
  80616. return;
  80617. }
  80618. for (n = 0; n < next_ptr; n++) {
  80619. if (ptr != table[n].new_ptr) continue;
  80620. farfree(table[n].org_ptr);
  80621. while (++n < next_ptr) {
  80622. table[n-1] = table[n];
  80623. }
  80624. next_ptr--;
  80625. return;
  80626. }
  80627. ptr = opaque; /* just to make some compilers happy */
  80628. Assert(0, "zcfree: ptr not found");
  80629. }
  80630. #endif /* __TURBOC__ */
  80631. #ifdef M_I86
  80632. # define MY_ZCALLOC
  80633. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80634. # define _halloc halloc
  80635. # define _hfree hfree
  80636. #endif
  80637. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80638. {
  80639. if (opaque) opaque = 0; /* to make compiler happy */
  80640. return _halloc((long)items, size);
  80641. }
  80642. void zcfree (voidpf opaque, voidpf ptr)
  80643. {
  80644. if (opaque) opaque = 0; /* to make compiler happy */
  80645. _hfree(ptr);
  80646. }
  80647. #endif /* M_I86 */
  80648. #endif /* SYS16BIT */
  80649. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80650. #ifndef STDC
  80651. extern voidp malloc OF((uInt size));
  80652. extern voidp calloc OF((uInt items, uInt size));
  80653. extern void free OF((voidpf ptr));
  80654. #endif
  80655. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80656. {
  80657. if (opaque) items += size - size; /* make compiler happy */
  80658. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80659. (voidpf)calloc(items, size);
  80660. }
  80661. void zcfree (voidpf opaque, voidpf ptr)
  80662. {
  80663. free(ptr);
  80664. if (opaque) return; /* make compiler happy */
  80665. }
  80666. #endif /* MY_ZCALLOC */
  80667. /*** End of inlined file: zutil.c ***/
  80668. #undef Byte
  80669. }
  80670. #else
  80671. #include <zlib.h>
  80672. #endif
  80673. }
  80674. #if JUCE_MSVC
  80675. #pragma warning (pop)
  80676. #endif
  80677. BEGIN_JUCE_NAMESPACE
  80678. using namespace zlibNamespace;
  80679. // internal helper object that holds the zlib structures so they don't have to be
  80680. // included publicly.
  80681. class GZIPDecompressHelper
  80682. {
  80683. public:
  80684. GZIPDecompressHelper (const bool noWrap) throw()
  80685. : data (0),
  80686. dataSize (0),
  80687. finished (true),
  80688. needsDictionary (false),
  80689. error (true),
  80690. streamIsValid (false)
  80691. {
  80692. zerostruct (stream);
  80693. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80694. finished = error = ! streamIsValid;
  80695. }
  80696. ~GZIPDecompressHelper() throw()
  80697. {
  80698. if (streamIsValid)
  80699. inflateEnd (&stream);
  80700. }
  80701. bool needsInput() const throw() { return dataSize <= 0; }
  80702. void setInput (uint8* const data_, const int size) throw()
  80703. {
  80704. data = data_;
  80705. dataSize = size;
  80706. }
  80707. int doNextBlock (uint8* const dest, const int destSize) throw()
  80708. {
  80709. if (streamIsValid && data != 0 && ! finished)
  80710. {
  80711. stream.next_in = data;
  80712. stream.next_out = dest;
  80713. stream.avail_in = dataSize;
  80714. stream.avail_out = destSize;
  80715. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80716. {
  80717. case Z_STREAM_END:
  80718. finished = true;
  80719. // deliberate fall-through
  80720. case Z_OK:
  80721. data += dataSize - stream.avail_in;
  80722. dataSize = stream.avail_in;
  80723. return destSize - stream.avail_out;
  80724. case Z_NEED_DICT:
  80725. needsDictionary = true;
  80726. data += dataSize - stream.avail_in;
  80727. dataSize = stream.avail_in;
  80728. break;
  80729. case Z_DATA_ERROR:
  80730. case Z_MEM_ERROR:
  80731. error = true;
  80732. default:
  80733. break;
  80734. }
  80735. }
  80736. return 0;
  80737. }
  80738. private:
  80739. z_stream stream;
  80740. uint8* data;
  80741. int dataSize;
  80742. public:
  80743. bool finished, needsDictionary, error, streamIsValid;
  80744. };
  80745. const int gzipDecompBufferSize = 32768;
  80746. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80747. const bool deleteSourceWhenDestroyed,
  80748. const bool noWrap_,
  80749. const int64 uncompressedStreamLength_)
  80750. : sourceStream (sourceStream_),
  80751. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80752. uncompressedStreamLength (uncompressedStreamLength_),
  80753. noWrap (noWrap_),
  80754. isEof (false),
  80755. activeBufferSize (0),
  80756. originalSourcePos (sourceStream_->getPosition()),
  80757. currentPos (0),
  80758. buffer (gzipDecompBufferSize),
  80759. helper (new GZIPDecompressHelper (noWrap_))
  80760. {
  80761. }
  80762. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80763. {
  80764. }
  80765. int64 GZIPDecompressorInputStream::getTotalLength()
  80766. {
  80767. return uncompressedStreamLength;
  80768. }
  80769. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80770. {
  80771. if ((howMany > 0) && ! isEof)
  80772. {
  80773. jassert (destBuffer != 0);
  80774. if (destBuffer != 0)
  80775. {
  80776. int numRead = 0;
  80777. uint8* d = (uint8*) destBuffer;
  80778. while (! helper->error)
  80779. {
  80780. const int n = helper->doNextBlock (d, howMany);
  80781. currentPos += n;
  80782. if (n == 0)
  80783. {
  80784. if (helper->finished || helper->needsDictionary)
  80785. {
  80786. isEof = true;
  80787. return numRead;
  80788. }
  80789. if (helper->needsInput())
  80790. {
  80791. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80792. if (activeBufferSize > 0)
  80793. {
  80794. helper->setInput ((uint8*) buffer, activeBufferSize);
  80795. }
  80796. else
  80797. {
  80798. isEof = true;
  80799. return numRead;
  80800. }
  80801. }
  80802. }
  80803. else
  80804. {
  80805. numRead += n;
  80806. howMany -= n;
  80807. d += n;
  80808. if (howMany <= 0)
  80809. return numRead;
  80810. }
  80811. }
  80812. }
  80813. }
  80814. return 0;
  80815. }
  80816. bool GZIPDecompressorInputStream::isExhausted()
  80817. {
  80818. return helper->error || isEof;
  80819. }
  80820. int64 GZIPDecompressorInputStream::getPosition()
  80821. {
  80822. return currentPos;
  80823. }
  80824. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80825. {
  80826. if (newPos < currentPos)
  80827. {
  80828. // to go backwards, reset the stream and start again..
  80829. isEof = false;
  80830. activeBufferSize = 0;
  80831. currentPos = 0;
  80832. helper = new GZIPDecompressHelper (noWrap);
  80833. sourceStream->setPosition (originalSourcePos);
  80834. }
  80835. skipNextBytes (newPos - currentPos);
  80836. return true;
  80837. }
  80838. END_JUCE_NAMESPACE
  80839. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80840. #endif
  80841. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80842. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80843. #if JUCE_USE_FLAC
  80844. #if JUCE_WINDOWS
  80845. #include <windows.h>
  80846. #endif
  80847. #ifdef _MSC_VER
  80848. #pragma warning (disable : 4505)
  80849. #pragma warning (push)
  80850. #endif
  80851. namespace FlacNamespace
  80852. {
  80853. #if JUCE_INCLUDE_FLAC_CODE
  80854. #define FLAC__NO_DLL 1
  80855. #if ! defined (SIZE_MAX)
  80856. #define SIZE_MAX 0xffffffff
  80857. #endif
  80858. #define __STDC_LIMIT_MACROS 1
  80859. /*** Start of inlined file: all.h ***/
  80860. #ifndef FLAC__ALL_H
  80861. #define FLAC__ALL_H
  80862. /*** Start of inlined file: export.h ***/
  80863. #ifndef FLAC__EXPORT_H
  80864. #define FLAC__EXPORT_H
  80865. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80866. #define FLAC_API
  80867. #else
  80868. #ifdef FLAC_API_EXPORTS
  80869. #define FLAC_API _declspec(dllexport)
  80870. #else
  80871. #define FLAC_API _declspec(dllimport)
  80872. #endif
  80873. #endif
  80874. #define FLAC_API_VERSION_CURRENT 10
  80875. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80876. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80877. #ifdef __cplusplus
  80878. extern "C" {
  80879. #endif
  80880. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80881. #ifdef __cplusplus
  80882. }
  80883. #endif
  80884. #endif
  80885. /*** End of inlined file: export.h ***/
  80886. /*** Start of inlined file: assert.h ***/
  80887. #ifndef FLAC__ASSERT_H
  80888. #define FLAC__ASSERT_H
  80889. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80890. #ifdef DEBUG
  80891. #include <assert.h>
  80892. #define FLAC__ASSERT(x) assert(x)
  80893. #define FLAC__ASSERT_DECLARATION(x) x
  80894. #else
  80895. #define FLAC__ASSERT(x)
  80896. #define FLAC__ASSERT_DECLARATION(x)
  80897. #endif
  80898. #endif
  80899. /*** End of inlined file: assert.h ***/
  80900. /*** Start of inlined file: callback.h ***/
  80901. #ifndef FLAC__CALLBACK_H
  80902. #define FLAC__CALLBACK_H
  80903. /*** Start of inlined file: ordinals.h ***/
  80904. #ifndef FLAC__ORDINALS_H
  80905. #define FLAC__ORDINALS_H
  80906. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80907. #include <inttypes.h>
  80908. #endif
  80909. typedef signed char FLAC__int8;
  80910. typedef unsigned char FLAC__uint8;
  80911. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80912. typedef __int16 FLAC__int16;
  80913. typedef __int32 FLAC__int32;
  80914. typedef __int64 FLAC__int64;
  80915. typedef unsigned __int16 FLAC__uint16;
  80916. typedef unsigned __int32 FLAC__uint32;
  80917. typedef unsigned __int64 FLAC__uint64;
  80918. #elif defined(__EMX__)
  80919. typedef short FLAC__int16;
  80920. typedef long FLAC__int32;
  80921. typedef long long FLAC__int64;
  80922. typedef unsigned short FLAC__uint16;
  80923. typedef unsigned long FLAC__uint32;
  80924. typedef unsigned long long FLAC__uint64;
  80925. #else
  80926. typedef int16_t FLAC__int16;
  80927. typedef int32_t FLAC__int32;
  80928. typedef int64_t FLAC__int64;
  80929. typedef uint16_t FLAC__uint16;
  80930. typedef uint32_t FLAC__uint32;
  80931. typedef uint64_t FLAC__uint64;
  80932. #endif
  80933. typedef int FLAC__bool;
  80934. typedef FLAC__uint8 FLAC__byte;
  80935. #ifdef true
  80936. #undef true
  80937. #endif
  80938. #ifdef false
  80939. #undef false
  80940. #endif
  80941. #ifndef __cplusplus
  80942. #define true 1
  80943. #define false 0
  80944. #endif
  80945. #endif
  80946. /*** End of inlined file: ordinals.h ***/
  80947. #include <stdlib.h> /* for size_t */
  80948. #ifdef __cplusplus
  80949. extern "C" {
  80950. #endif
  80951. typedef void* FLAC__IOHandle;
  80952. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80953. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80954. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80955. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80956. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80957. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80958. typedef struct {
  80959. FLAC__IOCallback_Read read;
  80960. FLAC__IOCallback_Write write;
  80961. FLAC__IOCallback_Seek seek;
  80962. FLAC__IOCallback_Tell tell;
  80963. FLAC__IOCallback_Eof eof;
  80964. FLAC__IOCallback_Close close;
  80965. } FLAC__IOCallbacks;
  80966. #ifdef __cplusplus
  80967. }
  80968. #endif
  80969. #endif
  80970. /*** End of inlined file: callback.h ***/
  80971. /*** Start of inlined file: format.h ***/
  80972. #ifndef FLAC__FORMAT_H
  80973. #define FLAC__FORMAT_H
  80974. #ifdef __cplusplus
  80975. extern "C" {
  80976. #endif
  80977. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80978. #define FLAC__MIN_BLOCK_SIZE (16u)
  80979. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80980. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80981. #define FLAC__MAX_CHANNELS (8u)
  80982. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80983. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80984. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80985. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80986. #define FLAC__MAX_LPC_ORDER (32u)
  80987. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80988. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80989. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80990. #define FLAC__MAX_FIXED_ORDER (4u)
  80991. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80992. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80993. extern FLAC_API const char *FLAC__VERSION_STRING;
  80994. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80995. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80996. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80997. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80998. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80999. typedef enum {
  81000. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  81001. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  81002. } FLAC__EntropyCodingMethodType;
  81003. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  81004. typedef struct {
  81005. unsigned *parameters;
  81006. unsigned *raw_bits;
  81007. unsigned capacity_by_order;
  81008. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  81009. typedef struct {
  81010. unsigned order;
  81011. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  81012. } FLAC__EntropyCodingMethod_PartitionedRice;
  81013. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  81014. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  81015. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  81016. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  81017. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  81018. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  81019. typedef struct {
  81020. FLAC__EntropyCodingMethodType type;
  81021. union {
  81022. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  81023. } data;
  81024. } FLAC__EntropyCodingMethod;
  81025. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  81026. typedef enum {
  81027. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  81028. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  81029. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  81030. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  81031. } FLAC__SubframeType;
  81032. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  81033. typedef struct {
  81034. FLAC__int32 value; /**< The constant signal value. */
  81035. } FLAC__Subframe_Constant;
  81036. typedef struct {
  81037. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  81038. } FLAC__Subframe_Verbatim;
  81039. typedef struct {
  81040. FLAC__EntropyCodingMethod entropy_coding_method;
  81041. unsigned order;
  81042. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  81043. const FLAC__int32 *residual;
  81044. } FLAC__Subframe_Fixed;
  81045. typedef struct {
  81046. FLAC__EntropyCodingMethod entropy_coding_method;
  81047. unsigned order;
  81048. unsigned qlp_coeff_precision;
  81049. int quantization_level;
  81050. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  81051. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  81052. const FLAC__int32 *residual;
  81053. } FLAC__Subframe_LPC;
  81054. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  81055. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  81056. typedef struct {
  81057. FLAC__SubframeType type;
  81058. union {
  81059. FLAC__Subframe_Constant constant;
  81060. FLAC__Subframe_Fixed fixed;
  81061. FLAC__Subframe_LPC lpc;
  81062. FLAC__Subframe_Verbatim verbatim;
  81063. } data;
  81064. unsigned wasted_bits;
  81065. } FLAC__Subframe;
  81066. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  81067. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  81068. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  81069. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  81070. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  81071. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  81072. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  81073. typedef enum {
  81074. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  81075. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  81076. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  81077. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  81078. } FLAC__ChannelAssignment;
  81079. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  81080. typedef enum {
  81081. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  81082. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  81083. } FLAC__FrameNumberType;
  81084. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  81085. typedef struct {
  81086. unsigned blocksize;
  81087. unsigned sample_rate;
  81088. unsigned channels;
  81089. FLAC__ChannelAssignment channel_assignment;
  81090. unsigned bits_per_sample;
  81091. FLAC__FrameNumberType number_type;
  81092. union {
  81093. FLAC__uint32 frame_number;
  81094. FLAC__uint64 sample_number;
  81095. } number;
  81096. FLAC__uint8 crc;
  81097. } FLAC__FrameHeader;
  81098. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  81099. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  81100. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  81101. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  81102. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  81103. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  81104. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  81105. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  81106. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  81107. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  81108. typedef struct {
  81109. FLAC__uint16 crc;
  81110. } FLAC__FrameFooter;
  81111. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  81112. typedef struct {
  81113. FLAC__FrameHeader header;
  81114. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  81115. FLAC__FrameFooter footer;
  81116. } FLAC__Frame;
  81117. typedef enum {
  81118. FLAC__METADATA_TYPE_STREAMINFO = 0,
  81119. FLAC__METADATA_TYPE_PADDING = 1,
  81120. FLAC__METADATA_TYPE_APPLICATION = 2,
  81121. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  81122. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  81123. FLAC__METADATA_TYPE_CUESHEET = 5,
  81124. FLAC__METADATA_TYPE_PICTURE = 6,
  81125. FLAC__METADATA_TYPE_UNDEFINED = 7
  81126. } FLAC__MetadataType;
  81127. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  81128. typedef struct {
  81129. unsigned min_blocksize, max_blocksize;
  81130. unsigned min_framesize, max_framesize;
  81131. unsigned sample_rate;
  81132. unsigned channels;
  81133. unsigned bits_per_sample;
  81134. FLAC__uint64 total_samples;
  81135. FLAC__byte md5sum[16];
  81136. } FLAC__StreamMetadata_StreamInfo;
  81137. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81138. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81139. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81140. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81141. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  81142. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  81143. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  81144. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  81145. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  81146. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  81147. typedef struct {
  81148. int dummy;
  81149. } FLAC__StreamMetadata_Padding;
  81150. typedef struct {
  81151. FLAC__byte id[4];
  81152. FLAC__byte *data;
  81153. } FLAC__StreamMetadata_Application;
  81154. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  81155. typedef struct {
  81156. FLAC__uint64 sample_number;
  81157. FLAC__uint64 stream_offset;
  81158. unsigned frame_samples;
  81159. } FLAC__StreamMetadata_SeekPoint;
  81160. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  81161. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  81162. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  81163. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  81164. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  81165. typedef struct {
  81166. unsigned num_points;
  81167. FLAC__StreamMetadata_SeekPoint *points;
  81168. } FLAC__StreamMetadata_SeekTable;
  81169. typedef struct {
  81170. FLAC__uint32 length;
  81171. FLAC__byte *entry;
  81172. } FLAC__StreamMetadata_VorbisComment_Entry;
  81173. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  81174. typedef struct {
  81175. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  81176. FLAC__uint32 num_comments;
  81177. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  81178. } FLAC__StreamMetadata_VorbisComment;
  81179. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  81180. typedef struct {
  81181. FLAC__uint64 offset;
  81182. FLAC__byte number;
  81183. } FLAC__StreamMetadata_CueSheet_Index;
  81184. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  81185. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  81186. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  81187. typedef struct {
  81188. FLAC__uint64 offset;
  81189. FLAC__byte number;
  81190. char isrc[13];
  81191. unsigned type:1;
  81192. unsigned pre_emphasis:1;
  81193. FLAC__byte num_indices;
  81194. FLAC__StreamMetadata_CueSheet_Index *indices;
  81195. } FLAC__StreamMetadata_CueSheet_Track;
  81196. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  81197. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  81198. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  81199. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  81200. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  81201. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  81202. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  81203. typedef struct {
  81204. char media_catalog_number[129];
  81205. FLAC__uint64 lead_in;
  81206. FLAC__bool is_cd;
  81207. unsigned num_tracks;
  81208. FLAC__StreamMetadata_CueSheet_Track *tracks;
  81209. } FLAC__StreamMetadata_CueSheet;
  81210. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  81211. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  81212. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  81213. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  81214. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  81215. typedef enum {
  81216. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  81217. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  81218. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  81219. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  81220. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  81221. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  81222. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  81223. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  81224. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  81225. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  81226. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  81227. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  81228. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  81229. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  81230. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  81231. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  81232. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  81233. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  81234. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  81235. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  81236. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  81237. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  81238. } FLAC__StreamMetadata_Picture_Type;
  81239. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  81240. typedef struct {
  81241. FLAC__StreamMetadata_Picture_Type type;
  81242. char *mime_type;
  81243. FLAC__byte *description;
  81244. FLAC__uint32 width;
  81245. FLAC__uint32 height;
  81246. FLAC__uint32 depth;
  81247. FLAC__uint32 colors;
  81248. FLAC__uint32 data_length;
  81249. FLAC__byte *data;
  81250. } FLAC__StreamMetadata_Picture;
  81251. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  81252. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  81253. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  81254. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  81255. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  81256. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  81257. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  81258. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  81259. typedef struct {
  81260. FLAC__byte *data;
  81261. } FLAC__StreamMetadata_Unknown;
  81262. typedef struct {
  81263. FLAC__MetadataType type;
  81264. FLAC__bool is_last;
  81265. unsigned length;
  81266. union {
  81267. FLAC__StreamMetadata_StreamInfo stream_info;
  81268. FLAC__StreamMetadata_Padding padding;
  81269. FLAC__StreamMetadata_Application application;
  81270. FLAC__StreamMetadata_SeekTable seek_table;
  81271. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  81272. FLAC__StreamMetadata_CueSheet cue_sheet;
  81273. FLAC__StreamMetadata_Picture picture;
  81274. FLAC__StreamMetadata_Unknown unknown;
  81275. } data;
  81276. } FLAC__StreamMetadata;
  81277. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  81278. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  81279. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  81280. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  81281. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  81282. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  81283. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  81284. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  81285. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  81286. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  81287. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  81288. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  81289. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  81290. #ifdef __cplusplus
  81291. }
  81292. #endif
  81293. #endif
  81294. /*** End of inlined file: format.h ***/
  81295. /*** Start of inlined file: metadata.h ***/
  81296. #ifndef FLAC__METADATA_H
  81297. #define FLAC__METADATA_H
  81298. #include <sys/types.h> /* for off_t */
  81299. #ifdef __cplusplus
  81300. extern "C" {
  81301. #endif
  81302. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  81303. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  81304. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  81305. 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);
  81306. struct FLAC__Metadata_SimpleIterator;
  81307. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  81308. typedef enum {
  81309. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  81310. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  81311. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  81312. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  81313. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  81314. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  81315. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  81316. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  81317. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  81318. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  81319. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81320. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81321. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81322. } FLAC__Metadata_SimpleIteratorStatus;
  81323. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81324. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81325. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81326. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81327. 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);
  81328. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81329. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81330. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81331. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81332. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81333. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81334. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81335. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81336. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81337. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81338. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81339. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81340. struct FLAC__Metadata_Chain;
  81341. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81342. struct FLAC__Metadata_Iterator;
  81343. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81344. typedef enum {
  81345. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81346. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81347. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81348. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81349. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81350. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81351. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81352. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81353. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81354. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81355. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81356. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81357. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81358. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81359. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81360. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81361. } FLAC__Metadata_ChainStatus;
  81362. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81363. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81364. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81365. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81366. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81367. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81368. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81369. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81370. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81371. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81372. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81373. 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);
  81374. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81375. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81376. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81377. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81378. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81379. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81380. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81381. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81382. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81383. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81384. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81385. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81386. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81387. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81388. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81389. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81390. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81391. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81392. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81393. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81394. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81395. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81396. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81397. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81398. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81399. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81400. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81401. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81402. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81403. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81404. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81405. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81406. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81407. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81408. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81409. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81410. 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);
  81411. 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);
  81412. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81413. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81414. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81415. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81416. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81417. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81418. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81419. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81420. 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);
  81421. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81422. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81423. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81424. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81425. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81426. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81427. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81428. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81429. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81430. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81431. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81432. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81433. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81434. #ifdef __cplusplus
  81435. }
  81436. #endif
  81437. #endif
  81438. /*** End of inlined file: metadata.h ***/
  81439. /*** Start of inlined file: stream_decoder.h ***/
  81440. #ifndef FLAC__STREAM_DECODER_H
  81441. #define FLAC__STREAM_DECODER_H
  81442. #include <stdio.h> /* for FILE */
  81443. #ifdef __cplusplus
  81444. extern "C" {
  81445. #endif
  81446. typedef enum {
  81447. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81448. FLAC__STREAM_DECODER_READ_METADATA,
  81449. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81450. FLAC__STREAM_DECODER_READ_FRAME,
  81451. FLAC__STREAM_DECODER_END_OF_STREAM,
  81452. FLAC__STREAM_DECODER_OGG_ERROR,
  81453. FLAC__STREAM_DECODER_SEEK_ERROR,
  81454. FLAC__STREAM_DECODER_ABORTED,
  81455. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81456. FLAC__STREAM_DECODER_UNINITIALIZED
  81457. } FLAC__StreamDecoderState;
  81458. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81459. typedef enum {
  81460. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81461. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81462. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81463. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81464. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81465. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81466. } FLAC__StreamDecoderInitStatus;
  81467. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81468. typedef enum {
  81469. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81470. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81471. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81472. } FLAC__StreamDecoderReadStatus;
  81473. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81474. typedef enum {
  81475. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81476. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81477. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81478. } FLAC__StreamDecoderSeekStatus;
  81479. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81480. typedef enum {
  81481. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81482. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81483. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81484. } FLAC__StreamDecoderTellStatus;
  81485. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81486. typedef enum {
  81487. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81488. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81489. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81490. } FLAC__StreamDecoderLengthStatus;
  81491. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81492. typedef enum {
  81493. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81494. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81495. } FLAC__StreamDecoderWriteStatus;
  81496. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81497. typedef enum {
  81498. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81499. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81500. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81501. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81502. } FLAC__StreamDecoderErrorStatus;
  81503. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81504. struct FLAC__StreamDecoderProtected;
  81505. struct FLAC__StreamDecoderPrivate;
  81506. typedef struct {
  81507. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81508. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81509. } FLAC__StreamDecoder;
  81510. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81511. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81512. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81513. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81514. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81515. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81516. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81517. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81518. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81519. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81520. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81521. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81522. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81523. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81524. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81525. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81526. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81527. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81528. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81529. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81530. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81531. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81532. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81533. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81534. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81535. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81536. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81537. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81538. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81539. FLAC__StreamDecoder *decoder,
  81540. FLAC__StreamDecoderReadCallback read_callback,
  81541. FLAC__StreamDecoderSeekCallback seek_callback,
  81542. FLAC__StreamDecoderTellCallback tell_callback,
  81543. FLAC__StreamDecoderLengthCallback length_callback,
  81544. FLAC__StreamDecoderEofCallback eof_callback,
  81545. FLAC__StreamDecoderWriteCallback write_callback,
  81546. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81547. FLAC__StreamDecoderErrorCallback error_callback,
  81548. void *client_data
  81549. );
  81550. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81551. FLAC__StreamDecoder *decoder,
  81552. FLAC__StreamDecoderReadCallback read_callback,
  81553. FLAC__StreamDecoderSeekCallback seek_callback,
  81554. FLAC__StreamDecoderTellCallback tell_callback,
  81555. FLAC__StreamDecoderLengthCallback length_callback,
  81556. FLAC__StreamDecoderEofCallback eof_callback,
  81557. FLAC__StreamDecoderWriteCallback write_callback,
  81558. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81559. FLAC__StreamDecoderErrorCallback error_callback,
  81560. void *client_data
  81561. );
  81562. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81563. FLAC__StreamDecoder *decoder,
  81564. FILE *file,
  81565. FLAC__StreamDecoderWriteCallback write_callback,
  81566. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81567. FLAC__StreamDecoderErrorCallback error_callback,
  81568. void *client_data
  81569. );
  81570. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81571. FLAC__StreamDecoder *decoder,
  81572. FILE *file,
  81573. FLAC__StreamDecoderWriteCallback write_callback,
  81574. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81575. FLAC__StreamDecoderErrorCallback error_callback,
  81576. void *client_data
  81577. );
  81578. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81579. FLAC__StreamDecoder *decoder,
  81580. const char *filename,
  81581. FLAC__StreamDecoderWriteCallback write_callback,
  81582. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81583. FLAC__StreamDecoderErrorCallback error_callback,
  81584. void *client_data
  81585. );
  81586. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81587. FLAC__StreamDecoder *decoder,
  81588. const char *filename,
  81589. FLAC__StreamDecoderWriteCallback write_callback,
  81590. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81591. FLAC__StreamDecoderErrorCallback error_callback,
  81592. void *client_data
  81593. );
  81594. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81595. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81596. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81597. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81598. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81599. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81600. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81601. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81602. #ifdef __cplusplus
  81603. }
  81604. #endif
  81605. #endif
  81606. /*** End of inlined file: stream_decoder.h ***/
  81607. /*** Start of inlined file: stream_encoder.h ***/
  81608. #ifndef FLAC__STREAM_ENCODER_H
  81609. #define FLAC__STREAM_ENCODER_H
  81610. #include <stdio.h> /* for FILE */
  81611. #ifdef __cplusplus
  81612. extern "C" {
  81613. #endif
  81614. typedef enum {
  81615. FLAC__STREAM_ENCODER_OK = 0,
  81616. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81617. FLAC__STREAM_ENCODER_OGG_ERROR,
  81618. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81619. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81620. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81621. FLAC__STREAM_ENCODER_IO_ERROR,
  81622. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81623. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81624. } FLAC__StreamEncoderState;
  81625. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81626. typedef enum {
  81627. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81628. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81629. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81630. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81631. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81632. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81633. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81634. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81635. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81636. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81637. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81638. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81639. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81640. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81641. } FLAC__StreamEncoderInitStatus;
  81642. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81643. typedef enum {
  81644. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81645. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81646. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81647. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81648. } FLAC__StreamEncoderReadStatus;
  81649. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81650. typedef enum {
  81651. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81652. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81653. } FLAC__StreamEncoderWriteStatus;
  81654. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81655. typedef enum {
  81656. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81657. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81658. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81659. } FLAC__StreamEncoderSeekStatus;
  81660. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81661. typedef enum {
  81662. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81663. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81664. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81665. } FLAC__StreamEncoderTellStatus;
  81666. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81667. struct FLAC__StreamEncoderProtected;
  81668. struct FLAC__StreamEncoderPrivate;
  81669. typedef struct {
  81670. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81671. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81672. } FLAC__StreamEncoder;
  81673. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81674. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81675. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81676. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81677. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81678. 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);
  81679. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81680. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81681. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81682. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81683. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81684. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81685. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81686. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81687. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81688. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81689. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81690. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81691. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81692. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81693. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81694. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81695. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81696. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81697. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81698. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81699. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81700. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81701. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81702. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81703. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81704. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81705. 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);
  81706. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81707. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81708. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81709. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81710. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81711. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81712. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81713. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81714. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81715. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81716. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81717. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81718. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81719. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81720. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81721. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81722. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81723. 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);
  81724. 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);
  81725. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81726. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81727. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81728. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81729. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81730. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81731. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81732. #ifdef __cplusplus
  81733. }
  81734. #endif
  81735. #endif
  81736. /*** End of inlined file: stream_encoder.h ***/
  81737. #ifdef _MSC_VER
  81738. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81739. {
  81740. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81741. return (x>>16) | (x<<16);
  81742. }
  81743. #endif
  81744. #if defined(_MSC_VER) && defined(_X86_)
  81745. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81746. {
  81747. __asm {
  81748. mov edx, start
  81749. mov ecx, len
  81750. test ecx, ecx
  81751. loop1:
  81752. jz done1
  81753. mov eax, [edx]
  81754. bswap eax
  81755. mov [edx], eax
  81756. add edx, 4
  81757. dec ecx
  81758. jmp short loop1
  81759. done1:
  81760. }
  81761. }
  81762. #endif
  81763. #endif
  81764. /*** End of inlined file: all.h ***/
  81765. /*** Start of inlined file: bitmath.c ***/
  81766. /*** Start of inlined file: juce_FlacHeader.h ***/
  81767. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81768. // tasks..
  81769. #define VERSION "1.2.1"
  81770. #define FLAC__NO_DLL 1
  81771. #if JUCE_MSVC
  81772. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81773. #endif
  81774. #if JUCE_MAC
  81775. #define FLAC__SYS_DARWIN 1
  81776. #endif
  81777. /*** End of inlined file: juce_FlacHeader.h ***/
  81778. #if JUCE_USE_FLAC
  81779. #if HAVE_CONFIG_H
  81780. # include <config.h>
  81781. #endif
  81782. /*** Start of inlined file: bitmath.h ***/
  81783. #ifndef FLAC__PRIVATE__BITMATH_H
  81784. #define FLAC__PRIVATE__BITMATH_H
  81785. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81786. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81787. unsigned FLAC__bitmath_silog2(int v);
  81788. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81789. #endif
  81790. /*** End of inlined file: bitmath.h ***/
  81791. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81792. {
  81793. unsigned l = 0;
  81794. FLAC__ASSERT(v > 0);
  81795. while(v >>= 1)
  81796. l++;
  81797. return l;
  81798. }
  81799. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81800. {
  81801. unsigned l = 0;
  81802. FLAC__ASSERT(v > 0);
  81803. while(v >>= 1)
  81804. l++;
  81805. return l;
  81806. }
  81807. unsigned FLAC__bitmath_silog2(int v)
  81808. {
  81809. while(1) {
  81810. if(v == 0) {
  81811. return 0;
  81812. }
  81813. else if(v > 0) {
  81814. unsigned l = 0;
  81815. while(v) {
  81816. l++;
  81817. v >>= 1;
  81818. }
  81819. return l+1;
  81820. }
  81821. else if(v == -1) {
  81822. return 2;
  81823. }
  81824. else {
  81825. v++;
  81826. v = -v;
  81827. }
  81828. }
  81829. }
  81830. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81831. {
  81832. while(1) {
  81833. if(v == 0) {
  81834. return 0;
  81835. }
  81836. else if(v > 0) {
  81837. unsigned l = 0;
  81838. while(v) {
  81839. l++;
  81840. v >>= 1;
  81841. }
  81842. return l+1;
  81843. }
  81844. else if(v == -1) {
  81845. return 2;
  81846. }
  81847. else {
  81848. v++;
  81849. v = -v;
  81850. }
  81851. }
  81852. }
  81853. #endif
  81854. /*** End of inlined file: bitmath.c ***/
  81855. /*** Start of inlined file: bitreader.c ***/
  81856. /*** Start of inlined file: juce_FlacHeader.h ***/
  81857. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81858. // tasks..
  81859. #define VERSION "1.2.1"
  81860. #define FLAC__NO_DLL 1
  81861. #if JUCE_MSVC
  81862. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81863. #endif
  81864. #if JUCE_MAC
  81865. #define FLAC__SYS_DARWIN 1
  81866. #endif
  81867. /*** End of inlined file: juce_FlacHeader.h ***/
  81868. #if JUCE_USE_FLAC
  81869. #if HAVE_CONFIG_H
  81870. # include <config.h>
  81871. #endif
  81872. #include <stdlib.h> /* for malloc() */
  81873. #include <string.h> /* for memcpy(), memset() */
  81874. #ifdef _MSC_VER
  81875. #include <winsock.h> /* for ntohl() */
  81876. #elif defined FLAC__SYS_DARWIN
  81877. #include <machine/endian.h> /* for ntohl() */
  81878. #elif defined __MINGW32__
  81879. #include <winsock.h> /* for ntohl() */
  81880. #else
  81881. #include <netinet/in.h> /* for ntohl() */
  81882. #endif
  81883. /*** Start of inlined file: bitreader.h ***/
  81884. #ifndef FLAC__PRIVATE__BITREADER_H
  81885. #define FLAC__PRIVATE__BITREADER_H
  81886. #include <stdio.h> /* for FILE */
  81887. /*** Start of inlined file: cpu.h ***/
  81888. #ifndef FLAC__PRIVATE__CPU_H
  81889. #define FLAC__PRIVATE__CPU_H
  81890. #ifdef HAVE_CONFIG_H
  81891. #include <config.h>
  81892. #endif
  81893. typedef enum {
  81894. FLAC__CPUINFO_TYPE_IA32,
  81895. FLAC__CPUINFO_TYPE_PPC,
  81896. FLAC__CPUINFO_TYPE_UNKNOWN
  81897. } FLAC__CPUInfo_Type;
  81898. typedef struct {
  81899. FLAC__bool cpuid;
  81900. FLAC__bool bswap;
  81901. FLAC__bool cmov;
  81902. FLAC__bool mmx;
  81903. FLAC__bool fxsr;
  81904. FLAC__bool sse;
  81905. FLAC__bool sse2;
  81906. FLAC__bool sse3;
  81907. FLAC__bool ssse3;
  81908. FLAC__bool _3dnow;
  81909. FLAC__bool ext3dnow;
  81910. FLAC__bool extmmx;
  81911. } FLAC__CPUInfo_IA32;
  81912. typedef struct {
  81913. FLAC__bool altivec;
  81914. FLAC__bool ppc64;
  81915. } FLAC__CPUInfo_PPC;
  81916. typedef struct {
  81917. FLAC__bool use_asm;
  81918. FLAC__CPUInfo_Type type;
  81919. union {
  81920. FLAC__CPUInfo_IA32 ia32;
  81921. FLAC__CPUInfo_PPC ppc;
  81922. } data;
  81923. } FLAC__CPUInfo;
  81924. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81925. #ifndef FLAC__NO_ASM
  81926. #ifdef FLAC__CPU_IA32
  81927. #ifdef FLAC__HAS_NASM
  81928. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81929. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81930. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81931. #endif
  81932. #endif
  81933. #endif
  81934. #endif
  81935. /*** End of inlined file: cpu.h ***/
  81936. struct FLAC__BitReader;
  81937. typedef struct FLAC__BitReader FLAC__BitReader;
  81938. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81939. FLAC__BitReader *FLAC__bitreader_new(void);
  81940. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81941. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81942. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81943. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81944. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81945. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81946. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81947. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81948. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81949. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81950. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81951. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81952. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81953. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81954. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81955. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81956. 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! */
  81957. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81958. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81959. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81960. #ifndef FLAC__NO_ASM
  81961. # ifdef FLAC__CPU_IA32
  81962. # ifdef FLAC__HAS_NASM
  81963. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81964. # endif
  81965. # endif
  81966. #endif
  81967. #if 0 /* UNUSED */
  81968. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81969. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81970. #endif
  81971. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81972. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81973. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81974. #endif
  81975. /*** End of inlined file: bitreader.h ***/
  81976. /*** Start of inlined file: crc.h ***/
  81977. #ifndef FLAC__PRIVATE__CRC_H
  81978. #define FLAC__PRIVATE__CRC_H
  81979. extern FLAC__byte const FLAC__crc8_table[256];
  81980. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81981. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81982. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81983. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81984. extern unsigned FLAC__crc16_table[256];
  81985. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81986. #if 0
  81987. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81988. #endif
  81989. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81990. #endif
  81991. /*** End of inlined file: crc.h ***/
  81992. typedef FLAC__uint32 brword;
  81993. #define FLAC__BYTES_PER_WORD 4
  81994. #define FLAC__BITS_PER_WORD 32
  81995. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81996. #if WORDS_BIGENDIAN
  81997. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81998. #else
  81999. #if defined (_MSC_VER) && defined (_X86_)
  82000. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82001. #else
  82002. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82003. #endif
  82004. #endif
  82005. #define COUNT_ZERO_MSBS(word) ( \
  82006. (word) <= 0xffff ? \
  82007. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  82008. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  82009. )
  82010. #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])) )
  82011. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  82012. static const unsigned char byte_to_unary_table[] = {
  82013. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  82014. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  82015. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82016. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82017. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82018. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82019. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82020. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  82029. };
  82030. #ifdef min
  82031. #undef min
  82032. #endif
  82033. #define min(x,y) ((x)<(y)?(x):(y))
  82034. #ifdef max
  82035. #undef max
  82036. #endif
  82037. #define max(x,y) ((x)>(y)?(x):(y))
  82038. #ifdef _MSC_VER
  82039. #define FLAC__U64L(x) x
  82040. #else
  82041. #define FLAC__U64L(x) x##LLU
  82042. #endif
  82043. #ifndef FLaC__INLINE
  82044. #define FLaC__INLINE
  82045. #endif
  82046. struct FLAC__BitReader {
  82047. brword *buffer;
  82048. unsigned capacity; /* in words */
  82049. unsigned words; /* # of completed words in buffer */
  82050. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  82051. unsigned consumed_words; /* #words ... */
  82052. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  82053. unsigned read_crc16; /* the running frame CRC */
  82054. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  82055. FLAC__BitReaderReadCallback read_callback;
  82056. void *client_data;
  82057. FLAC__CPUInfo cpu_info;
  82058. };
  82059. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  82060. {
  82061. register unsigned crc = br->read_crc16;
  82062. #if FLAC__BYTES_PER_WORD == 4
  82063. switch(br->crc16_align) {
  82064. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  82065. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82066. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82067. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82068. }
  82069. #elif FLAC__BYTES_PER_WORD == 8
  82070. switch(br->crc16_align) {
  82071. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  82072. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  82073. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  82074. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  82075. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  82076. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82077. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82078. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82079. }
  82080. #else
  82081. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  82082. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  82083. br->read_crc16 = crc;
  82084. #endif
  82085. br->crc16_align = 0;
  82086. }
  82087. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  82088. {
  82089. unsigned start, end;
  82090. size_t bytes;
  82091. FLAC__byte *target;
  82092. if(br->consumed_words > 0) {
  82093. start = br->consumed_words;
  82094. end = br->words + (br->bytes? 1:0);
  82095. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  82096. br->words -= start;
  82097. br->consumed_words = 0;
  82098. }
  82099. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  82100. if(bytes == 0)
  82101. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  82102. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  82103. #if WORDS_BIGENDIAN
  82104. #else
  82105. if(br->bytes)
  82106. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  82107. #endif
  82108. if(!br->read_callback(target, &bytes, br->client_data))
  82109. return false;
  82110. #if WORDS_BIGENDIAN
  82111. #else
  82112. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  82113. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  82114. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  82115. start = br->words;
  82116. local_swap32_block_(br->buffer + start, end - start);
  82117. }
  82118. else
  82119. # endif
  82120. for(start = br->words; start < end; start++)
  82121. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  82122. #endif
  82123. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  82124. br->words = end / FLAC__BYTES_PER_WORD;
  82125. br->bytes = end % FLAC__BYTES_PER_WORD;
  82126. return true;
  82127. }
  82128. FLAC__BitReader *FLAC__bitreader_new(void)
  82129. {
  82130. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  82131. return br;
  82132. }
  82133. void FLAC__bitreader_delete(FLAC__BitReader *br)
  82134. {
  82135. FLAC__ASSERT(0 != br);
  82136. FLAC__bitreader_free(br);
  82137. free(br);
  82138. }
  82139. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  82140. {
  82141. FLAC__ASSERT(0 != br);
  82142. br->words = br->bytes = 0;
  82143. br->consumed_words = br->consumed_bits = 0;
  82144. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  82145. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  82146. if(br->buffer == 0)
  82147. return false;
  82148. br->read_callback = rcb;
  82149. br->client_data = cd;
  82150. br->cpu_info = cpu;
  82151. return true;
  82152. }
  82153. void FLAC__bitreader_free(FLAC__BitReader *br)
  82154. {
  82155. FLAC__ASSERT(0 != br);
  82156. if(0 != br->buffer)
  82157. free(br->buffer);
  82158. br->buffer = 0;
  82159. br->capacity = 0;
  82160. br->words = br->bytes = 0;
  82161. br->consumed_words = br->consumed_bits = 0;
  82162. br->read_callback = 0;
  82163. br->client_data = 0;
  82164. }
  82165. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  82166. {
  82167. br->words = br->bytes = 0;
  82168. br->consumed_words = br->consumed_bits = 0;
  82169. return true;
  82170. }
  82171. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  82172. {
  82173. unsigned i, j;
  82174. if(br == 0) {
  82175. fprintf(out, "bitreader is NULL\n");
  82176. }
  82177. else {
  82178. 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);
  82179. for(i = 0; i < br->words; i++) {
  82180. fprintf(out, "%08X: ", i);
  82181. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82182. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82183. fprintf(out, ".");
  82184. else
  82185. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82186. fprintf(out, "\n");
  82187. }
  82188. if(br->bytes > 0) {
  82189. fprintf(out, "%08X: ", i);
  82190. for(j = 0; j < br->bytes*8; j++)
  82191. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82192. fprintf(out, ".");
  82193. else
  82194. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  82195. fprintf(out, "\n");
  82196. }
  82197. }
  82198. }
  82199. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  82200. {
  82201. FLAC__ASSERT(0 != br);
  82202. FLAC__ASSERT(0 != br->buffer);
  82203. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82204. br->read_crc16 = (unsigned)seed;
  82205. br->crc16_align = br->consumed_bits;
  82206. }
  82207. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  82208. {
  82209. FLAC__ASSERT(0 != br);
  82210. FLAC__ASSERT(0 != br->buffer);
  82211. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82212. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  82213. if(br->consumed_bits) {
  82214. const brword tail = br->buffer[br->consumed_words];
  82215. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  82216. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  82217. }
  82218. return br->read_crc16;
  82219. }
  82220. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  82221. {
  82222. return ((br->consumed_bits & 7) == 0);
  82223. }
  82224. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  82225. {
  82226. return 8 - (br->consumed_bits & 7);
  82227. }
  82228. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  82229. {
  82230. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  82231. }
  82232. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  82233. {
  82234. FLAC__ASSERT(0 != br);
  82235. FLAC__ASSERT(0 != br->buffer);
  82236. FLAC__ASSERT(bits <= 32);
  82237. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  82238. FLAC__ASSERT(br->consumed_words <= br->words);
  82239. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82240. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  82241. *val = 0;
  82242. return true;
  82243. }
  82244. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  82245. if(!bitreader_read_from_client_(br))
  82246. return false;
  82247. }
  82248. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82249. if(br->consumed_bits) {
  82250. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  82251. const brword word = br->buffer[br->consumed_words];
  82252. if(bits < n) {
  82253. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  82254. br->consumed_bits += bits;
  82255. return true;
  82256. }
  82257. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  82258. bits -= n;
  82259. crc16_update_word_(br, word);
  82260. br->consumed_words++;
  82261. br->consumed_bits = 0;
  82262. 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 */
  82263. *val <<= bits;
  82264. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  82265. br->consumed_bits = bits;
  82266. }
  82267. return true;
  82268. }
  82269. else {
  82270. const brword word = br->buffer[br->consumed_words];
  82271. if(bits < FLAC__BITS_PER_WORD) {
  82272. *val = word >> (FLAC__BITS_PER_WORD-bits);
  82273. br->consumed_bits = bits;
  82274. return true;
  82275. }
  82276. *val = word;
  82277. crc16_update_word_(br, word);
  82278. br->consumed_words++;
  82279. return true;
  82280. }
  82281. }
  82282. else {
  82283. if(br->consumed_bits) {
  82284. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  82285. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  82286. br->consumed_bits += bits;
  82287. return true;
  82288. }
  82289. else {
  82290. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  82291. br->consumed_bits += bits;
  82292. return true;
  82293. }
  82294. }
  82295. }
  82296. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  82297. {
  82298. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  82299. return false;
  82300. *val <<= (32-bits);
  82301. *val >>= (32-bits);
  82302. return true;
  82303. }
  82304. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  82305. {
  82306. FLAC__uint32 hi, lo;
  82307. if(bits > 32) {
  82308. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  82309. return false;
  82310. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  82311. return false;
  82312. *val = hi;
  82313. *val <<= 32;
  82314. *val |= lo;
  82315. }
  82316. else {
  82317. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  82318. return false;
  82319. *val = lo;
  82320. }
  82321. return true;
  82322. }
  82323. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82324. {
  82325. FLAC__uint32 x8, x32 = 0;
  82326. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82327. return false;
  82328. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82329. return false;
  82330. x32 |= (x8 << 8);
  82331. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82332. return false;
  82333. x32 |= (x8 << 16);
  82334. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82335. return false;
  82336. x32 |= (x8 << 24);
  82337. *val = x32;
  82338. return true;
  82339. }
  82340. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82341. {
  82342. FLAC__ASSERT(0 != br);
  82343. FLAC__ASSERT(0 != br->buffer);
  82344. if(bits > 0) {
  82345. const unsigned n = br->consumed_bits & 7;
  82346. unsigned m;
  82347. FLAC__uint32 x;
  82348. if(n != 0) {
  82349. m = min(8-n, bits);
  82350. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82351. return false;
  82352. bits -= m;
  82353. }
  82354. m = bits / 8;
  82355. if(m > 0) {
  82356. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82357. return false;
  82358. bits %= 8;
  82359. }
  82360. if(bits > 0) {
  82361. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82362. return false;
  82363. }
  82364. }
  82365. return true;
  82366. }
  82367. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82368. {
  82369. FLAC__uint32 x;
  82370. FLAC__ASSERT(0 != br);
  82371. FLAC__ASSERT(0 != br->buffer);
  82372. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82373. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82374. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82375. return false;
  82376. nvals--;
  82377. }
  82378. if(0 == nvals)
  82379. return true;
  82380. while(nvals >= FLAC__BYTES_PER_WORD) {
  82381. if(br->consumed_words < br->words) {
  82382. br->consumed_words++;
  82383. nvals -= FLAC__BYTES_PER_WORD;
  82384. }
  82385. else if(!bitreader_read_from_client_(br))
  82386. return false;
  82387. }
  82388. while(nvals) {
  82389. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82390. return false;
  82391. nvals--;
  82392. }
  82393. return true;
  82394. }
  82395. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82396. {
  82397. FLAC__uint32 x;
  82398. FLAC__ASSERT(0 != br);
  82399. FLAC__ASSERT(0 != br->buffer);
  82400. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82401. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82402. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82403. return false;
  82404. *val++ = (FLAC__byte)x;
  82405. nvals--;
  82406. }
  82407. if(0 == nvals)
  82408. return true;
  82409. while(nvals >= FLAC__BYTES_PER_WORD) {
  82410. if(br->consumed_words < br->words) {
  82411. const brword word = br->buffer[br->consumed_words++];
  82412. #if FLAC__BYTES_PER_WORD == 4
  82413. val[0] = (FLAC__byte)(word >> 24);
  82414. val[1] = (FLAC__byte)(word >> 16);
  82415. val[2] = (FLAC__byte)(word >> 8);
  82416. val[3] = (FLAC__byte)word;
  82417. #elif FLAC__BYTES_PER_WORD == 8
  82418. val[0] = (FLAC__byte)(word >> 56);
  82419. val[1] = (FLAC__byte)(word >> 48);
  82420. val[2] = (FLAC__byte)(word >> 40);
  82421. val[3] = (FLAC__byte)(word >> 32);
  82422. val[4] = (FLAC__byte)(word >> 24);
  82423. val[5] = (FLAC__byte)(word >> 16);
  82424. val[6] = (FLAC__byte)(word >> 8);
  82425. val[7] = (FLAC__byte)word;
  82426. #else
  82427. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82428. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82429. #endif
  82430. val += FLAC__BYTES_PER_WORD;
  82431. nvals -= FLAC__BYTES_PER_WORD;
  82432. }
  82433. else if(!bitreader_read_from_client_(br))
  82434. return false;
  82435. }
  82436. while(nvals) {
  82437. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82438. return false;
  82439. *val++ = (FLAC__byte)x;
  82440. nvals--;
  82441. }
  82442. return true;
  82443. }
  82444. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82445. #if 0 /* slow but readable version */
  82446. {
  82447. unsigned bit;
  82448. FLAC__ASSERT(0 != br);
  82449. FLAC__ASSERT(0 != br->buffer);
  82450. *val = 0;
  82451. while(1) {
  82452. if(!FLAC__bitreader_read_bit(br, &bit))
  82453. return false;
  82454. if(bit)
  82455. break;
  82456. else
  82457. *val++;
  82458. }
  82459. return true;
  82460. }
  82461. #else
  82462. {
  82463. unsigned i;
  82464. FLAC__ASSERT(0 != br);
  82465. FLAC__ASSERT(0 != br->buffer);
  82466. *val = 0;
  82467. while(1) {
  82468. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82469. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82470. if(b) {
  82471. i = COUNT_ZERO_MSBS(b);
  82472. *val += i;
  82473. i++;
  82474. br->consumed_bits += i;
  82475. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82476. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82477. br->consumed_words++;
  82478. br->consumed_bits = 0;
  82479. }
  82480. return true;
  82481. }
  82482. else {
  82483. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82484. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82485. br->consumed_words++;
  82486. br->consumed_bits = 0;
  82487. }
  82488. }
  82489. if(br->bytes) {
  82490. const unsigned end = br->bytes * 8;
  82491. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82492. if(b) {
  82493. i = COUNT_ZERO_MSBS(b);
  82494. *val += i;
  82495. i++;
  82496. br->consumed_bits += i;
  82497. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82498. return true;
  82499. }
  82500. else {
  82501. *val += end - br->consumed_bits;
  82502. br->consumed_bits += end;
  82503. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82504. }
  82505. }
  82506. if(!bitreader_read_from_client_(br))
  82507. return false;
  82508. }
  82509. }
  82510. #endif
  82511. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82512. {
  82513. FLAC__uint32 lsbs = 0, msbs = 0;
  82514. unsigned uval;
  82515. FLAC__ASSERT(0 != br);
  82516. FLAC__ASSERT(0 != br->buffer);
  82517. FLAC__ASSERT(parameter <= 31);
  82518. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82519. return false;
  82520. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82521. return false;
  82522. uval = (msbs << parameter) | lsbs;
  82523. if(uval & 1)
  82524. *val = -((int)(uval >> 1)) - 1;
  82525. else
  82526. *val = (int)(uval >> 1);
  82527. return true;
  82528. }
  82529. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82530. #ifdef _MSC_VER
  82531. {
  82532. unsigned i;
  82533. unsigned uval = 0;
  82534. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82535. register unsigned cwords;
  82536. register unsigned cbits;
  82537. FLAC__ASSERT(0 != br);
  82538. FLAC__ASSERT(0 != br->buffer);
  82539. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82540. FLAC__ASSERT(parameter < 32);
  82541. if(nvals == 0)
  82542. return true;
  82543. cbits = br->consumed_bits;
  82544. cwords = br->consumed_words;
  82545. while(1) {
  82546. while(1) {
  82547. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82548. brword b = br->buffer[cwords] << cbits;
  82549. if(b) {
  82550. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82551. __asm {
  82552. bsr eax, b
  82553. not eax
  82554. and eax, 31
  82555. mov i, eax
  82556. }
  82557. #else
  82558. i = COUNT_ZERO_MSBS(b);
  82559. #endif
  82560. uval += i;
  82561. bits = parameter;
  82562. i++;
  82563. cbits += i;
  82564. if(cbits == FLAC__BITS_PER_WORD) {
  82565. crc16_update_word_(br, br->buffer[cwords]);
  82566. cwords++;
  82567. cbits = 0;
  82568. }
  82569. goto break1;
  82570. }
  82571. else {
  82572. uval += FLAC__BITS_PER_WORD - cbits;
  82573. crc16_update_word_(br, br->buffer[cwords]);
  82574. cwords++;
  82575. cbits = 0;
  82576. }
  82577. }
  82578. if(br->bytes) {
  82579. const unsigned end = br->bytes * 8;
  82580. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82581. if(b) {
  82582. i = COUNT_ZERO_MSBS(b);
  82583. uval += i;
  82584. bits = parameter;
  82585. i++;
  82586. cbits += i;
  82587. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82588. goto break1;
  82589. }
  82590. else {
  82591. uval += end - cbits;
  82592. cbits += end;
  82593. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82594. }
  82595. }
  82596. br->consumed_bits = cbits;
  82597. br->consumed_words = cwords;
  82598. if(!bitreader_read_from_client_(br))
  82599. return false;
  82600. cwords = br->consumed_words;
  82601. }
  82602. break1:
  82603. FLAC__ASSERT(cwords <= br->words);
  82604. if(bits) {
  82605. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82606. br->consumed_bits = cbits;
  82607. br->consumed_words = cwords;
  82608. if(!bitreader_read_from_client_(br))
  82609. return false;
  82610. cwords = br->consumed_words;
  82611. }
  82612. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82613. if(cbits) {
  82614. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82615. const brword word = br->buffer[cwords];
  82616. if(bits < n) {
  82617. uval <<= bits;
  82618. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82619. cbits += bits;
  82620. goto break2;
  82621. }
  82622. uval <<= n;
  82623. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82624. bits -= n;
  82625. crc16_update_word_(br, word);
  82626. cwords++;
  82627. cbits = 0;
  82628. 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 */
  82629. uval <<= bits;
  82630. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82631. cbits = bits;
  82632. }
  82633. goto break2;
  82634. }
  82635. else {
  82636. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82637. uval <<= bits;
  82638. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82639. cbits = bits;
  82640. goto break2;
  82641. }
  82642. }
  82643. else {
  82644. uval <<= bits;
  82645. if(cbits) {
  82646. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82647. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82648. cbits += bits;
  82649. goto break2;
  82650. }
  82651. else {
  82652. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82653. cbits += bits;
  82654. goto break2;
  82655. }
  82656. }
  82657. }
  82658. break2:
  82659. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82660. --nvals;
  82661. if(nvals == 0) {
  82662. br->consumed_bits = cbits;
  82663. br->consumed_words = cwords;
  82664. return true;
  82665. }
  82666. uval = 0;
  82667. ++vals;
  82668. }
  82669. }
  82670. #else
  82671. {
  82672. unsigned i;
  82673. unsigned uval = 0;
  82674. register unsigned cwords;
  82675. register unsigned cbits;
  82676. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82677. FLAC__ASSERT(0 != br);
  82678. FLAC__ASSERT(0 != br->buffer);
  82679. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82680. FLAC__ASSERT(parameter < 32);
  82681. if(nvals == 0)
  82682. return true;
  82683. cbits = br->consumed_bits;
  82684. cwords = br->consumed_words;
  82685. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82686. while(1) {
  82687. while(1) {
  82688. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82689. brword b = br->buffer[cwords] << cbits;
  82690. if(b) {
  82691. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82692. asm volatile (
  82693. "bsrl %1, %0;"
  82694. "notl %0;"
  82695. "andl $31, %0;"
  82696. : "=r"(i)
  82697. : "r"(b)
  82698. );
  82699. #else
  82700. i = COUNT_ZERO_MSBS(b);
  82701. #endif
  82702. uval += i;
  82703. cbits += i;
  82704. cbits++; /* skip over stop bit */
  82705. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82706. crc16_update_word_(br, br->buffer[cwords]);
  82707. cwords++;
  82708. cbits = 0;
  82709. }
  82710. goto break1;
  82711. }
  82712. else {
  82713. uval += FLAC__BITS_PER_WORD - cbits;
  82714. crc16_update_word_(br, br->buffer[cwords]);
  82715. cwords++;
  82716. cbits = 0;
  82717. }
  82718. }
  82719. if(br->bytes) {
  82720. const unsigned end = br->bytes * 8;
  82721. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82722. if(b) {
  82723. i = COUNT_ZERO_MSBS(b);
  82724. uval += i;
  82725. cbits += i;
  82726. cbits++; /* skip over stop bit */
  82727. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82728. goto break1;
  82729. }
  82730. else {
  82731. uval += end - cbits;
  82732. cbits += end;
  82733. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82734. }
  82735. }
  82736. br->consumed_bits = cbits;
  82737. br->consumed_words = cwords;
  82738. if(!bitreader_read_from_client_(br))
  82739. return false;
  82740. cwords = br->consumed_words;
  82741. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82742. }
  82743. break1:
  82744. ucbits -= uval;
  82745. ucbits--; /* account for stop bit */
  82746. FLAC__ASSERT(cwords <= br->words);
  82747. if(parameter) {
  82748. while(ucbits < parameter) {
  82749. br->consumed_bits = cbits;
  82750. br->consumed_words = cwords;
  82751. if(!bitreader_read_from_client_(br))
  82752. return false;
  82753. cwords = br->consumed_words;
  82754. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82755. }
  82756. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82757. if(cbits) {
  82758. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82759. const brword word = br->buffer[cwords];
  82760. if(parameter < n) {
  82761. uval <<= parameter;
  82762. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82763. cbits += parameter;
  82764. }
  82765. else {
  82766. uval <<= n;
  82767. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82768. crc16_update_word_(br, word);
  82769. cwords++;
  82770. cbits = parameter - n;
  82771. 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 */
  82772. uval <<= cbits;
  82773. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82774. }
  82775. }
  82776. }
  82777. else {
  82778. cbits = parameter;
  82779. uval <<= parameter;
  82780. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82781. }
  82782. }
  82783. else {
  82784. uval <<= parameter;
  82785. if(cbits) {
  82786. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82787. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82788. cbits += parameter;
  82789. }
  82790. else {
  82791. cbits = parameter;
  82792. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82793. }
  82794. }
  82795. }
  82796. ucbits -= parameter;
  82797. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82798. --nvals;
  82799. if(nvals == 0) {
  82800. br->consumed_bits = cbits;
  82801. br->consumed_words = cwords;
  82802. return true;
  82803. }
  82804. uval = 0;
  82805. ++vals;
  82806. }
  82807. }
  82808. #endif
  82809. #if 0 /* UNUSED */
  82810. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82811. {
  82812. FLAC__uint32 lsbs = 0, msbs = 0;
  82813. unsigned bit, uval, k;
  82814. FLAC__ASSERT(0 != br);
  82815. FLAC__ASSERT(0 != br->buffer);
  82816. k = FLAC__bitmath_ilog2(parameter);
  82817. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82818. return false;
  82819. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82820. return false;
  82821. if(parameter == 1u<<k) {
  82822. uval = (msbs << k) | lsbs;
  82823. }
  82824. else {
  82825. unsigned d = (1 << (k+1)) - parameter;
  82826. if(lsbs >= d) {
  82827. if(!FLAC__bitreader_read_bit(br, &bit))
  82828. return false;
  82829. lsbs <<= 1;
  82830. lsbs |= bit;
  82831. lsbs -= d;
  82832. }
  82833. uval = msbs * parameter + lsbs;
  82834. }
  82835. if(uval & 1)
  82836. *val = -((int)(uval >> 1)) - 1;
  82837. else
  82838. *val = (int)(uval >> 1);
  82839. return true;
  82840. }
  82841. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82842. {
  82843. FLAC__uint32 lsbs, msbs = 0;
  82844. unsigned bit, k;
  82845. FLAC__ASSERT(0 != br);
  82846. FLAC__ASSERT(0 != br->buffer);
  82847. k = FLAC__bitmath_ilog2(parameter);
  82848. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82849. return false;
  82850. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82851. return false;
  82852. if(parameter == 1u<<k) {
  82853. *val = (msbs << k) | lsbs;
  82854. }
  82855. else {
  82856. unsigned d = (1 << (k+1)) - parameter;
  82857. if(lsbs >= d) {
  82858. if(!FLAC__bitreader_read_bit(br, &bit))
  82859. return false;
  82860. lsbs <<= 1;
  82861. lsbs |= bit;
  82862. lsbs -= d;
  82863. }
  82864. *val = msbs * parameter + lsbs;
  82865. }
  82866. return true;
  82867. }
  82868. #endif /* UNUSED */
  82869. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82870. {
  82871. FLAC__uint32 v = 0;
  82872. FLAC__uint32 x;
  82873. unsigned i;
  82874. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82875. return false;
  82876. if(raw)
  82877. raw[(*rawlen)++] = (FLAC__byte)x;
  82878. if(!(x & 0x80)) { /* 0xxxxxxx */
  82879. v = x;
  82880. i = 0;
  82881. }
  82882. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82883. v = x & 0x1F;
  82884. i = 1;
  82885. }
  82886. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82887. v = x & 0x0F;
  82888. i = 2;
  82889. }
  82890. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82891. v = x & 0x07;
  82892. i = 3;
  82893. }
  82894. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82895. v = x & 0x03;
  82896. i = 4;
  82897. }
  82898. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82899. v = x & 0x01;
  82900. i = 5;
  82901. }
  82902. else {
  82903. *val = 0xffffffff;
  82904. return true;
  82905. }
  82906. for( ; i; i--) {
  82907. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82908. return false;
  82909. if(raw)
  82910. raw[(*rawlen)++] = (FLAC__byte)x;
  82911. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82912. *val = 0xffffffff;
  82913. return true;
  82914. }
  82915. v <<= 6;
  82916. v |= (x & 0x3F);
  82917. }
  82918. *val = v;
  82919. return true;
  82920. }
  82921. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82922. {
  82923. FLAC__uint64 v = 0;
  82924. FLAC__uint32 x;
  82925. unsigned i;
  82926. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82927. return false;
  82928. if(raw)
  82929. raw[(*rawlen)++] = (FLAC__byte)x;
  82930. if(!(x & 0x80)) { /* 0xxxxxxx */
  82931. v = x;
  82932. i = 0;
  82933. }
  82934. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82935. v = x & 0x1F;
  82936. i = 1;
  82937. }
  82938. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82939. v = x & 0x0F;
  82940. i = 2;
  82941. }
  82942. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82943. v = x & 0x07;
  82944. i = 3;
  82945. }
  82946. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82947. v = x & 0x03;
  82948. i = 4;
  82949. }
  82950. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82951. v = x & 0x01;
  82952. i = 5;
  82953. }
  82954. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82955. v = 0;
  82956. i = 6;
  82957. }
  82958. else {
  82959. *val = FLAC__U64L(0xffffffffffffffff);
  82960. return true;
  82961. }
  82962. for( ; i; i--) {
  82963. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82964. return false;
  82965. if(raw)
  82966. raw[(*rawlen)++] = (FLAC__byte)x;
  82967. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82968. *val = FLAC__U64L(0xffffffffffffffff);
  82969. return true;
  82970. }
  82971. v <<= 6;
  82972. v |= (x & 0x3F);
  82973. }
  82974. *val = v;
  82975. return true;
  82976. }
  82977. #endif
  82978. /*** End of inlined file: bitreader.c ***/
  82979. /*** Start of inlined file: bitwriter.c ***/
  82980. /*** Start of inlined file: juce_FlacHeader.h ***/
  82981. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82982. // tasks..
  82983. #define VERSION "1.2.1"
  82984. #define FLAC__NO_DLL 1
  82985. #if JUCE_MSVC
  82986. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82987. #endif
  82988. #if JUCE_MAC
  82989. #define FLAC__SYS_DARWIN 1
  82990. #endif
  82991. /*** End of inlined file: juce_FlacHeader.h ***/
  82992. #if JUCE_USE_FLAC
  82993. #if HAVE_CONFIG_H
  82994. # include <config.h>
  82995. #endif
  82996. #include <stdlib.h> /* for malloc() */
  82997. #include <string.h> /* for memcpy(), memset() */
  82998. #ifdef _MSC_VER
  82999. #include <winsock.h> /* for ntohl() */
  83000. #elif defined FLAC__SYS_DARWIN
  83001. #include <machine/endian.h> /* for ntohl() */
  83002. #elif defined __MINGW32__
  83003. #include <winsock.h> /* for ntohl() */
  83004. #else
  83005. #include <netinet/in.h> /* for ntohl() */
  83006. #endif
  83007. #if 0 /* UNUSED */
  83008. #endif
  83009. /*** Start of inlined file: bitwriter.h ***/
  83010. #ifndef FLAC__PRIVATE__BITWRITER_H
  83011. #define FLAC__PRIVATE__BITWRITER_H
  83012. #include <stdio.h> /* for FILE */
  83013. struct FLAC__BitWriter;
  83014. typedef struct FLAC__BitWriter FLAC__BitWriter;
  83015. FLAC__BitWriter *FLAC__bitwriter_new(void);
  83016. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  83017. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  83018. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  83019. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  83020. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  83021. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  83022. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  83023. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  83024. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  83025. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  83026. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  83027. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  83028. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  83029. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  83030. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  83031. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  83032. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  83033. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  83034. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  83035. #if 0 /* UNUSED */
  83036. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  83037. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  83038. #endif
  83039. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  83040. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  83041. #if 0 /* UNUSED */
  83042. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  83043. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  83044. #endif
  83045. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  83046. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  83047. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  83048. #endif
  83049. /*** End of inlined file: bitwriter.h ***/
  83050. /*** Start of inlined file: alloc.h ***/
  83051. #ifndef FLAC__SHARE__ALLOC_H
  83052. #define FLAC__SHARE__ALLOC_H
  83053. #if HAVE_CONFIG_H
  83054. # include <config.h>
  83055. #endif
  83056. #include <limits.h> /* for SIZE_MAX */
  83057. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  83058. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  83059. #endif
  83060. #include <stdlib.h> /* for size_t, malloc(), etc */
  83061. #ifndef SIZE_MAX
  83062. # ifndef SIZE_T_MAX
  83063. # ifdef _MSC_VER
  83064. # define SIZE_T_MAX UINT_MAX
  83065. # else
  83066. # error
  83067. # endif
  83068. # endif
  83069. # define SIZE_MAX SIZE_T_MAX
  83070. #endif
  83071. #ifndef FLaC__INLINE
  83072. #define FLaC__INLINE
  83073. #endif
  83074. static FLaC__INLINE void *safe_malloc_(size_t size)
  83075. {
  83076. if(!size)
  83077. size++;
  83078. return malloc(size);
  83079. }
  83080. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  83081. {
  83082. if(!nmemb || !size)
  83083. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83084. return calloc(nmemb, size);
  83085. }
  83086. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  83087. {
  83088. size2 += size1;
  83089. if(size2 < size1)
  83090. return 0;
  83091. return safe_malloc_(size2);
  83092. }
  83093. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  83094. {
  83095. size2 += size1;
  83096. if(size2 < size1)
  83097. return 0;
  83098. size3 += size2;
  83099. if(size3 < size2)
  83100. return 0;
  83101. return safe_malloc_(size3);
  83102. }
  83103. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  83104. {
  83105. size2 += size1;
  83106. if(size2 < size1)
  83107. return 0;
  83108. size3 += size2;
  83109. if(size3 < size2)
  83110. return 0;
  83111. size4 += size3;
  83112. if(size4 < size3)
  83113. return 0;
  83114. return safe_malloc_(size4);
  83115. }
  83116. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  83117. #if 0
  83118. needs support for cases where sizeof(size_t) != 4
  83119. {
  83120. if(sizeof(size_t) == 4) {
  83121. if ((double)size1 * (double)size2 < 4294967296.0)
  83122. return malloc(size1*size2);
  83123. }
  83124. return 0;
  83125. }
  83126. #else
  83127. {
  83128. if(!size1 || !size2)
  83129. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83130. if(size1 > SIZE_MAX / size2)
  83131. return 0;
  83132. return malloc(size1*size2);
  83133. }
  83134. #endif
  83135. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  83136. {
  83137. if(!size1 || !size2 || !size3)
  83138. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83139. if(size1 > SIZE_MAX / size2)
  83140. return 0;
  83141. size1 *= size2;
  83142. if(size1 > SIZE_MAX / size3)
  83143. return 0;
  83144. return malloc(size1*size3);
  83145. }
  83146. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  83147. {
  83148. if(!size1 || !size2)
  83149. return safe_malloc_(size3);
  83150. if(size1 > SIZE_MAX / size2)
  83151. return 0;
  83152. return safe_malloc_add_2op_(size1*size2, size3);
  83153. }
  83154. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  83155. {
  83156. if(!size1 || (!size2 && !size3))
  83157. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83158. size2 += size3;
  83159. if(size2 < size3)
  83160. return 0;
  83161. return safe_malloc_mul_2op_(size1, size2);
  83162. }
  83163. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  83164. {
  83165. size2 += size1;
  83166. if(size2 < size1)
  83167. return 0;
  83168. return realloc(ptr, size2);
  83169. }
  83170. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  83171. {
  83172. size2 += size1;
  83173. if(size2 < size1)
  83174. return 0;
  83175. size3 += size2;
  83176. if(size3 < size2)
  83177. return 0;
  83178. return realloc(ptr, size3);
  83179. }
  83180. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  83181. {
  83182. size2 += size1;
  83183. if(size2 < size1)
  83184. return 0;
  83185. size3 += size2;
  83186. if(size3 < size2)
  83187. return 0;
  83188. size4 += size3;
  83189. if(size4 < size3)
  83190. return 0;
  83191. return realloc(ptr, size4);
  83192. }
  83193. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  83194. {
  83195. if(!size1 || !size2)
  83196. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83197. if(size1 > SIZE_MAX / size2)
  83198. return 0;
  83199. return realloc(ptr, size1*size2);
  83200. }
  83201. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  83202. {
  83203. if(!size1 || (!size2 && !size3))
  83204. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83205. size2 += size3;
  83206. if(size2 < size3)
  83207. return 0;
  83208. return safe_realloc_mul_2op_(ptr, size1, size2);
  83209. }
  83210. #endif
  83211. /*** End of inlined file: alloc.h ***/
  83212. typedef FLAC__uint32 bwword;
  83213. #define FLAC__BYTES_PER_WORD 4
  83214. #define FLAC__BITS_PER_WORD 32
  83215. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  83216. #if WORDS_BIGENDIAN
  83217. #define SWAP_BE_WORD_TO_HOST(x) (x)
  83218. #else
  83219. #ifdef _MSC_VER
  83220. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  83221. #else
  83222. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  83223. #endif
  83224. #endif
  83225. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  83226. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  83227. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  83228. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  83229. #ifdef min
  83230. #undef min
  83231. #endif
  83232. #define min(x,y) ((x)<(y)?(x):(y))
  83233. #ifdef _MSC_VER
  83234. #define FLAC__U64L(x) x
  83235. #else
  83236. #define FLAC__U64L(x) x##LLU
  83237. #endif
  83238. #ifndef FLaC__INLINE
  83239. #define FLaC__INLINE
  83240. #endif
  83241. struct FLAC__BitWriter {
  83242. bwword *buffer;
  83243. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  83244. unsigned capacity; /* capacity of buffer in words */
  83245. unsigned words; /* # of complete words in buffer */
  83246. unsigned bits; /* # of used bits in accum */
  83247. };
  83248. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  83249. {
  83250. unsigned new_capacity;
  83251. bwword *new_buffer;
  83252. FLAC__ASSERT(0 != bw);
  83253. FLAC__ASSERT(0 != bw->buffer);
  83254. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  83255. if(bw->capacity >= new_capacity)
  83256. return true;
  83257. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  83258. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83259. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83260. FLAC__ASSERT(new_capacity > bw->capacity);
  83261. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  83262. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  83263. if(new_buffer == 0)
  83264. return false;
  83265. bw->buffer = new_buffer;
  83266. bw->capacity = new_capacity;
  83267. return true;
  83268. }
  83269. FLAC__BitWriter *FLAC__bitwriter_new(void)
  83270. {
  83271. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  83272. return bw;
  83273. }
  83274. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  83275. {
  83276. FLAC__ASSERT(0 != bw);
  83277. FLAC__bitwriter_free(bw);
  83278. free(bw);
  83279. }
  83280. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  83281. {
  83282. FLAC__ASSERT(0 != bw);
  83283. bw->words = bw->bits = 0;
  83284. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  83285. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  83286. if(bw->buffer == 0)
  83287. return false;
  83288. return true;
  83289. }
  83290. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  83291. {
  83292. FLAC__ASSERT(0 != bw);
  83293. if(0 != bw->buffer)
  83294. free(bw->buffer);
  83295. bw->buffer = 0;
  83296. bw->capacity = 0;
  83297. bw->words = bw->bits = 0;
  83298. }
  83299. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  83300. {
  83301. bw->words = bw->bits = 0;
  83302. }
  83303. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  83304. {
  83305. unsigned i, j;
  83306. if(bw == 0) {
  83307. fprintf(out, "bitwriter is NULL\n");
  83308. }
  83309. else {
  83310. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  83311. for(i = 0; i < bw->words; i++) {
  83312. fprintf(out, "%08X: ", i);
  83313. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  83314. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  83315. fprintf(out, "\n");
  83316. }
  83317. if(bw->bits > 0) {
  83318. fprintf(out, "%08X: ", i);
  83319. for(j = 0; j < bw->bits; j++)
  83320. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83321. fprintf(out, "\n");
  83322. }
  83323. }
  83324. }
  83325. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83326. {
  83327. const FLAC__byte *buffer;
  83328. size_t bytes;
  83329. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83330. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83331. return false;
  83332. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83333. FLAC__bitwriter_release_buffer(bw);
  83334. return true;
  83335. }
  83336. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83337. {
  83338. const FLAC__byte *buffer;
  83339. size_t bytes;
  83340. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83341. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83342. return false;
  83343. *crc = FLAC__crc8(buffer, bytes);
  83344. FLAC__bitwriter_release_buffer(bw);
  83345. return true;
  83346. }
  83347. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83348. {
  83349. return ((bw->bits & 7) == 0);
  83350. }
  83351. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83352. {
  83353. return FLAC__TOTAL_BITS(bw);
  83354. }
  83355. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83356. {
  83357. FLAC__ASSERT((bw->bits & 7) == 0);
  83358. if(bw->bits & 7)
  83359. return false;
  83360. if(bw->bits) {
  83361. FLAC__ASSERT(bw->words <= bw->capacity);
  83362. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83363. return false;
  83364. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83365. }
  83366. *buffer = (FLAC__byte*)bw->buffer;
  83367. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83368. return true;
  83369. }
  83370. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83371. {
  83372. (void)bw;
  83373. }
  83374. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83375. {
  83376. unsigned n;
  83377. FLAC__ASSERT(0 != bw);
  83378. FLAC__ASSERT(0 != bw->buffer);
  83379. if(bits == 0)
  83380. return true;
  83381. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83382. return false;
  83383. if(bw->bits) {
  83384. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83385. bw->accum <<= n;
  83386. bits -= n;
  83387. bw->bits += n;
  83388. if(bw->bits == FLAC__BITS_PER_WORD) {
  83389. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83390. bw->bits = 0;
  83391. }
  83392. else
  83393. return true;
  83394. }
  83395. while(bits >= FLAC__BITS_PER_WORD) {
  83396. bw->buffer[bw->words++] = 0;
  83397. bits -= FLAC__BITS_PER_WORD;
  83398. }
  83399. if(bits > 0) {
  83400. bw->accum = 0;
  83401. bw->bits = bits;
  83402. }
  83403. return true;
  83404. }
  83405. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83406. {
  83407. register unsigned left;
  83408. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83409. FLAC__ASSERT(0 != bw);
  83410. FLAC__ASSERT(0 != bw->buffer);
  83411. FLAC__ASSERT(bits <= 32);
  83412. if(bits == 0)
  83413. return true;
  83414. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83415. return false;
  83416. left = FLAC__BITS_PER_WORD - bw->bits;
  83417. if(bits < left) {
  83418. bw->accum <<= bits;
  83419. bw->accum |= val;
  83420. bw->bits += bits;
  83421. }
  83422. 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 */
  83423. bw->accum <<= left;
  83424. bw->accum |= val >> (bw->bits = bits - left);
  83425. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83426. bw->accum = val;
  83427. }
  83428. else {
  83429. bw->accum = val;
  83430. bw->bits = 0;
  83431. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83432. }
  83433. return true;
  83434. }
  83435. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83436. {
  83437. if(bits < 32)
  83438. val &= (~(0xffffffff << bits));
  83439. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83440. }
  83441. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83442. {
  83443. if(bits > 32) {
  83444. return
  83445. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83446. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83447. }
  83448. else
  83449. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83450. }
  83451. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83452. {
  83453. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83454. return false;
  83455. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83456. return false;
  83457. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83458. return false;
  83459. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83460. return false;
  83461. return true;
  83462. }
  83463. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83464. {
  83465. unsigned i;
  83466. for(i = 0; i < nvals; i++) {
  83467. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83468. return false;
  83469. }
  83470. return true;
  83471. }
  83472. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83473. {
  83474. if(val < 32)
  83475. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83476. else
  83477. return
  83478. FLAC__bitwriter_write_zeroes(bw, val) &&
  83479. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83480. }
  83481. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83482. {
  83483. FLAC__uint32 uval;
  83484. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83485. uval = (val<<1) ^ (val>>31);
  83486. return 1 + parameter + (uval >> parameter);
  83487. }
  83488. #if 0 /* UNUSED */
  83489. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83490. {
  83491. unsigned bits, msbs, uval;
  83492. unsigned k;
  83493. FLAC__ASSERT(parameter > 0);
  83494. if(val < 0)
  83495. uval = (unsigned)(((-(++val)) << 1) + 1);
  83496. else
  83497. uval = (unsigned)(val << 1);
  83498. k = FLAC__bitmath_ilog2(parameter);
  83499. if(parameter == 1u<<k) {
  83500. FLAC__ASSERT(k <= 30);
  83501. msbs = uval >> k;
  83502. bits = 1 + k + msbs;
  83503. }
  83504. else {
  83505. unsigned q, r, d;
  83506. d = (1 << (k+1)) - parameter;
  83507. q = uval / parameter;
  83508. r = uval - (q * parameter);
  83509. bits = 1 + q + k;
  83510. if(r >= d)
  83511. bits++;
  83512. }
  83513. return bits;
  83514. }
  83515. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83516. {
  83517. unsigned bits, msbs;
  83518. unsigned k;
  83519. FLAC__ASSERT(parameter > 0);
  83520. k = FLAC__bitmath_ilog2(parameter);
  83521. if(parameter == 1u<<k) {
  83522. FLAC__ASSERT(k <= 30);
  83523. msbs = uval >> k;
  83524. bits = 1 + k + msbs;
  83525. }
  83526. else {
  83527. unsigned q, r, d;
  83528. d = (1 << (k+1)) - parameter;
  83529. q = uval / parameter;
  83530. r = uval - (q * parameter);
  83531. bits = 1 + q + k;
  83532. if(r >= d)
  83533. bits++;
  83534. }
  83535. return bits;
  83536. }
  83537. #endif /* UNUSED */
  83538. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83539. {
  83540. unsigned total_bits, interesting_bits, msbs;
  83541. FLAC__uint32 uval, pattern;
  83542. FLAC__ASSERT(0 != bw);
  83543. FLAC__ASSERT(0 != bw->buffer);
  83544. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83545. uval = (val<<1) ^ (val>>31);
  83546. msbs = uval >> parameter;
  83547. interesting_bits = 1 + parameter;
  83548. total_bits = interesting_bits + msbs;
  83549. pattern = 1 << parameter; /* the unary end bit */
  83550. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83551. if(total_bits <= 32)
  83552. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83553. else
  83554. return
  83555. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83556. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83557. }
  83558. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83559. {
  83560. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83561. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83562. FLAC__uint32 uval;
  83563. unsigned left;
  83564. const unsigned lsbits = 1 + parameter;
  83565. unsigned msbits;
  83566. FLAC__ASSERT(0 != bw);
  83567. FLAC__ASSERT(0 != bw->buffer);
  83568. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83569. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83570. while(nvals) {
  83571. uval = (*vals<<1) ^ (*vals>>31);
  83572. msbits = uval >> parameter;
  83573. #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) */
  83574. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83575. bw->bits = bw->bits + msbits + lsbits;
  83576. uval |= mask1; /* set stop bit */
  83577. uval &= mask2; /* mask off unused top bits */
  83578. bw->accum <<= msbits;
  83579. bw->accum <<= lsbits;
  83580. bw->accum |= uval;
  83581. if(bw->bits == FLAC__BITS_PER_WORD) {
  83582. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83583. bw->bits = 0;
  83584. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83585. FLAC__ASSERT(bw->capacity == bw->words);
  83586. return false;
  83587. }
  83588. }
  83589. }
  83590. else {
  83591. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83592. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83593. bw->bits = bw->bits + msbits + lsbits;
  83594. uval |= mask1; /* set stop bit */
  83595. uval &= mask2; /* mask off unused top bits */
  83596. bw->accum <<= msbits + lsbits;
  83597. bw->accum |= uval;
  83598. }
  83599. else {
  83600. #endif
  83601. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83602. return false;
  83603. if(msbits) {
  83604. if(bw->bits) {
  83605. left = FLAC__BITS_PER_WORD - bw->bits;
  83606. if(msbits < left) {
  83607. bw->accum <<= msbits;
  83608. bw->bits += msbits;
  83609. goto break1;
  83610. }
  83611. else {
  83612. bw->accum <<= left;
  83613. msbits -= left;
  83614. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83615. bw->bits = 0;
  83616. }
  83617. }
  83618. while(msbits >= FLAC__BITS_PER_WORD) {
  83619. bw->buffer[bw->words++] = 0;
  83620. msbits -= FLAC__BITS_PER_WORD;
  83621. }
  83622. if(msbits > 0) {
  83623. bw->accum = 0;
  83624. bw->bits = msbits;
  83625. }
  83626. }
  83627. break1:
  83628. uval |= mask1; /* set stop bit */
  83629. uval &= mask2; /* mask off unused top bits */
  83630. left = FLAC__BITS_PER_WORD - bw->bits;
  83631. if(lsbits < left) {
  83632. bw->accum <<= lsbits;
  83633. bw->accum |= uval;
  83634. bw->bits += lsbits;
  83635. }
  83636. else {
  83637. FLAC__ASSERT(bw->bits);
  83638. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83639. bw->accum <<= left;
  83640. bw->accum |= uval >> (bw->bits = lsbits - left);
  83641. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83642. bw->accum = uval;
  83643. }
  83644. #if 1
  83645. }
  83646. #endif
  83647. vals++;
  83648. nvals--;
  83649. }
  83650. return true;
  83651. }
  83652. #if 0 /* UNUSED */
  83653. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83654. {
  83655. unsigned total_bits, msbs, uval;
  83656. unsigned k;
  83657. FLAC__ASSERT(0 != bw);
  83658. FLAC__ASSERT(0 != bw->buffer);
  83659. FLAC__ASSERT(parameter > 0);
  83660. if(val < 0)
  83661. uval = (unsigned)(((-(++val)) << 1) + 1);
  83662. else
  83663. uval = (unsigned)(val << 1);
  83664. k = FLAC__bitmath_ilog2(parameter);
  83665. if(parameter == 1u<<k) {
  83666. unsigned pattern;
  83667. FLAC__ASSERT(k <= 30);
  83668. msbs = uval >> k;
  83669. total_bits = 1 + k + msbs;
  83670. pattern = 1 << k; /* the unary end bit */
  83671. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83672. if(total_bits <= 32) {
  83673. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83674. return false;
  83675. }
  83676. else {
  83677. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83678. return false;
  83679. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83680. return false;
  83681. }
  83682. }
  83683. else {
  83684. unsigned q, r, d;
  83685. d = (1 << (k+1)) - parameter;
  83686. q = uval / parameter;
  83687. r = uval - (q * parameter);
  83688. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83689. return false;
  83690. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83691. return false;
  83692. if(r >= d) {
  83693. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83694. return false;
  83695. }
  83696. else {
  83697. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83698. return false;
  83699. }
  83700. }
  83701. return true;
  83702. }
  83703. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83704. {
  83705. unsigned total_bits, msbs;
  83706. unsigned k;
  83707. FLAC__ASSERT(0 != bw);
  83708. FLAC__ASSERT(0 != bw->buffer);
  83709. FLAC__ASSERT(parameter > 0);
  83710. k = FLAC__bitmath_ilog2(parameter);
  83711. if(parameter == 1u<<k) {
  83712. unsigned pattern;
  83713. FLAC__ASSERT(k <= 30);
  83714. msbs = uval >> k;
  83715. total_bits = 1 + k + msbs;
  83716. pattern = 1 << k; /* the unary end bit */
  83717. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83718. if(total_bits <= 32) {
  83719. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83720. return false;
  83721. }
  83722. else {
  83723. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83724. return false;
  83725. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83726. return false;
  83727. }
  83728. }
  83729. else {
  83730. unsigned q, r, d;
  83731. d = (1 << (k+1)) - parameter;
  83732. q = uval / parameter;
  83733. r = uval - (q * parameter);
  83734. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83735. return false;
  83736. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83737. return false;
  83738. if(r >= d) {
  83739. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83740. return false;
  83741. }
  83742. else {
  83743. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83744. return false;
  83745. }
  83746. }
  83747. return true;
  83748. }
  83749. #endif /* UNUSED */
  83750. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83751. {
  83752. FLAC__bool ok = 1;
  83753. FLAC__ASSERT(0 != bw);
  83754. FLAC__ASSERT(0 != bw->buffer);
  83755. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83756. if(val < 0x80) {
  83757. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83758. }
  83759. else if(val < 0x800) {
  83760. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83761. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83762. }
  83763. else if(val < 0x10000) {
  83764. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83765. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83766. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83767. }
  83768. else if(val < 0x200000) {
  83769. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83770. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83771. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83772. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83773. }
  83774. else if(val < 0x4000000) {
  83775. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83776. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83777. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83778. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83779. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83780. }
  83781. else {
  83782. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83783. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83784. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83785. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83786. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83787. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83788. }
  83789. return ok;
  83790. }
  83791. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83792. {
  83793. FLAC__bool ok = 1;
  83794. FLAC__ASSERT(0 != bw);
  83795. FLAC__ASSERT(0 != bw->buffer);
  83796. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83797. if(val < 0x80) {
  83798. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83799. }
  83800. else if(val < 0x800) {
  83801. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83802. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83803. }
  83804. else if(val < 0x10000) {
  83805. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83806. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83807. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83808. }
  83809. else if(val < 0x200000) {
  83810. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83811. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83812. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83813. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83814. }
  83815. else if(val < 0x4000000) {
  83816. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83817. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83818. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83819. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83820. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83821. }
  83822. else if(val < 0x80000000) {
  83823. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83824. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83825. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83826. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83827. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83828. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83829. }
  83830. else {
  83831. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83832. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83833. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83834. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83835. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83836. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83837. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83838. }
  83839. return ok;
  83840. }
  83841. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83842. {
  83843. if(bw->bits & 7u)
  83844. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83845. else
  83846. return true;
  83847. }
  83848. #endif
  83849. /*** End of inlined file: bitwriter.c ***/
  83850. /*** Start of inlined file: cpu.c ***/
  83851. /*** Start of inlined file: juce_FlacHeader.h ***/
  83852. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83853. // tasks..
  83854. #define VERSION "1.2.1"
  83855. #define FLAC__NO_DLL 1
  83856. #if JUCE_MSVC
  83857. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83858. #endif
  83859. #if JUCE_MAC
  83860. #define FLAC__SYS_DARWIN 1
  83861. #endif
  83862. /*** End of inlined file: juce_FlacHeader.h ***/
  83863. #if JUCE_USE_FLAC
  83864. #if HAVE_CONFIG_H
  83865. # include <config.h>
  83866. #endif
  83867. #include <stdlib.h>
  83868. #include <stdio.h>
  83869. #if defined FLAC__CPU_IA32
  83870. # include <signal.h>
  83871. #elif defined FLAC__CPU_PPC
  83872. # if !defined FLAC__NO_ASM
  83873. # if defined FLAC__SYS_DARWIN
  83874. # include <sys/sysctl.h>
  83875. # include <mach/mach.h>
  83876. # include <mach/mach_host.h>
  83877. # include <mach/host_info.h>
  83878. # include <mach/machine.h>
  83879. # ifndef CPU_SUBTYPE_POWERPC_970
  83880. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83881. # endif
  83882. # else /* FLAC__SYS_DARWIN */
  83883. # include <signal.h>
  83884. # include <setjmp.h>
  83885. static sigjmp_buf jmpbuf;
  83886. static volatile sig_atomic_t canjump = 0;
  83887. static void sigill_handler (int sig)
  83888. {
  83889. if (!canjump) {
  83890. signal (sig, SIG_DFL);
  83891. raise (sig);
  83892. }
  83893. canjump = 0;
  83894. siglongjmp (jmpbuf, 1);
  83895. }
  83896. # endif /* FLAC__SYS_DARWIN */
  83897. # endif /* FLAC__NO_ASM */
  83898. #endif /* FLAC__CPU_PPC */
  83899. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83900. #include <sys/param.h>
  83901. #include <sys/sysctl.h>
  83902. #include <machine/cpu.h>
  83903. #endif
  83904. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83905. #include <sys/types.h>
  83906. #include <sys/sysctl.h>
  83907. #endif
  83908. #if defined(__APPLE__)
  83909. #endif
  83910. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83911. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83912. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83913. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83914. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83915. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83916. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83917. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83918. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83919. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83920. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83921. # if defined(__linux__)
  83922. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83923. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83924. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83925. {
  83926. (void)signal;
  83927. sc.eip += 3 + 3 + 6;
  83928. }
  83929. # else
  83930. # include <sys/ucontext.h>
  83931. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83932. {
  83933. (void)signal, (void)si;
  83934. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83935. }
  83936. # endif
  83937. # elif defined(_MSC_VER)
  83938. # include <windows.h>
  83939. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83940. # ifdef USE_TRY_CATCH_FLAVOR
  83941. # else
  83942. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83943. {
  83944. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83945. ep->ContextRecord->Eip += 3 + 3 + 6;
  83946. return EXCEPTION_CONTINUE_EXECUTION;
  83947. }
  83948. return EXCEPTION_CONTINUE_SEARCH;
  83949. }
  83950. # endif
  83951. # endif
  83952. #endif
  83953. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83954. {
  83955. #ifdef FLAC__CPU_IA32
  83956. info->type = FLAC__CPUINFO_TYPE_IA32;
  83957. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83958. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83959. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83960. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83961. info->data.ia32.cmov = false;
  83962. info->data.ia32.mmx = false;
  83963. info->data.ia32.fxsr = false;
  83964. info->data.ia32.sse = false;
  83965. info->data.ia32.sse2 = false;
  83966. info->data.ia32.sse3 = false;
  83967. info->data.ia32.ssse3 = false;
  83968. info->data.ia32._3dnow = false;
  83969. info->data.ia32.ext3dnow = false;
  83970. info->data.ia32.extmmx = false;
  83971. if(info->data.ia32.cpuid) {
  83972. FLAC__uint32 flags_edx, flags_ecx;
  83973. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83974. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83975. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83976. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83977. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83978. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83979. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83980. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83981. #ifdef FLAC__USE_3DNOW
  83982. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83983. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83984. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83985. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83986. #else
  83987. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83988. #endif
  83989. #ifdef DEBUG
  83990. fprintf(stderr, "CPU info (IA-32):\n");
  83991. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83992. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83993. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83994. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83995. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83996. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83997. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83998. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83999. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  84000. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  84001. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  84002. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  84003. #endif
  84004. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  84005. #if defined FLAC__NO_SSE_OS
  84006. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84007. #elif defined FLAC__SSE_OS
  84008. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  84009. int sse = 0;
  84010. size_t len;
  84011. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  84012. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  84013. if(!sse)
  84014. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84015. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  84016. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  84017. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  84018. size_t len = sizeof(val);
  84019. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84020. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84021. else { /* double-check SSE2 */
  84022. mib[1] = CPU_SSE2;
  84023. len = sizeof(val);
  84024. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84025. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84026. }
  84027. # else
  84028. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84029. # endif
  84030. #elif defined(__linux__)
  84031. int sse = 0;
  84032. struct sigaction sigill_save;
  84033. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84034. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  84035. #else
  84036. struct sigaction sigill_sse;
  84037. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  84038. __sigemptyset(&sigill_sse.sa_mask);
  84039. 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 */
  84040. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  84041. #endif
  84042. {
  84043. asm volatile (
  84044. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  84045. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  84046. "incl %0\n\t" /* SIGILL handler will jump over this */
  84047. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  84048. "nop\n\t"
  84049. "nop\n\t"
  84050. "nop\n\t"
  84051. "nop\n\t"
  84052. "nop\n\t"
  84053. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  84054. "nop\n\t"
  84055. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  84056. : "=r"(sse)
  84057. : "r"(sse)
  84058. );
  84059. sigaction(SIGILL, &sigill_save, NULL);
  84060. }
  84061. if(!sse)
  84062. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84063. #elif defined(_MSC_VER)
  84064. # ifdef USE_TRY_CATCH_FLAVOR
  84065. _try {
  84066. __asm {
  84067. # if _MSC_VER <= 1200
  84068. _emit 0x0F
  84069. _emit 0x57
  84070. _emit 0xC0
  84071. # else
  84072. xorps xmm0,xmm0
  84073. # endif
  84074. }
  84075. }
  84076. _except(EXCEPTION_EXECUTE_HANDLER) {
  84077. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  84078. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84079. }
  84080. # else
  84081. int sse = 0;
  84082. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  84083. __asm {
  84084. # if _MSC_VER <= 1200
  84085. _emit 0x0F
  84086. _emit 0x57
  84087. _emit 0xC0
  84088. # else
  84089. xorps xmm0,xmm0
  84090. # endif
  84091. inc sse
  84092. nop
  84093. nop
  84094. nop
  84095. nop
  84096. nop
  84097. nop
  84098. nop
  84099. nop
  84100. nop
  84101. }
  84102. SetUnhandledExceptionFilter(save);
  84103. if(!sse)
  84104. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84105. # endif
  84106. #else
  84107. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84108. #endif
  84109. #ifdef DEBUG
  84110. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84111. #endif
  84112. }
  84113. }
  84114. #else
  84115. info->use_asm = false;
  84116. #endif
  84117. #elif defined FLAC__CPU_PPC
  84118. info->type = FLAC__CPUINFO_TYPE_PPC;
  84119. # if !defined FLAC__NO_ASM
  84120. info->use_asm = true;
  84121. # ifdef FLAC__USE_ALTIVEC
  84122. # if defined FLAC__SYS_DARWIN
  84123. {
  84124. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  84125. size_t len = sizeof(val);
  84126. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  84127. }
  84128. {
  84129. host_basic_info_data_t hostInfo;
  84130. mach_msg_type_number_t infoCount;
  84131. infoCount = HOST_BASIC_INFO_COUNT;
  84132. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  84133. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  84134. }
  84135. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  84136. {
  84137. info->data.ppc.altivec = 0;
  84138. info->data.ppc.ppc64 = 0;
  84139. signal (SIGILL, sigill_handler);
  84140. canjump = 0;
  84141. if (!sigsetjmp (jmpbuf, 1)) {
  84142. canjump = 1;
  84143. asm volatile (
  84144. "mtspr 256, %0\n\t"
  84145. "vand %%v0, %%v0, %%v0"
  84146. :
  84147. : "r" (-1)
  84148. );
  84149. info->data.ppc.altivec = 1;
  84150. }
  84151. canjump = 0;
  84152. if (!sigsetjmp (jmpbuf, 1)) {
  84153. int x = 0;
  84154. canjump = 1;
  84155. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  84156. info->data.ppc.ppc64 = 1;
  84157. }
  84158. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  84159. }
  84160. # endif
  84161. # else /* !FLAC__USE_ALTIVEC */
  84162. info->data.ppc.altivec = 0;
  84163. info->data.ppc.ppc64 = 0;
  84164. # endif
  84165. # else
  84166. info->use_asm = false;
  84167. # endif
  84168. #else
  84169. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  84170. info->use_asm = false;
  84171. #endif
  84172. }
  84173. #endif
  84174. /*** End of inlined file: cpu.c ***/
  84175. /*** Start of inlined file: crc.c ***/
  84176. /*** Start of inlined file: juce_FlacHeader.h ***/
  84177. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84178. // tasks..
  84179. #define VERSION "1.2.1"
  84180. #define FLAC__NO_DLL 1
  84181. #if JUCE_MSVC
  84182. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84183. #endif
  84184. #if JUCE_MAC
  84185. #define FLAC__SYS_DARWIN 1
  84186. #endif
  84187. /*** End of inlined file: juce_FlacHeader.h ***/
  84188. #if JUCE_USE_FLAC
  84189. #if HAVE_CONFIG_H
  84190. # include <config.h>
  84191. #endif
  84192. FLAC__byte const FLAC__crc8_table[256] = {
  84193. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  84194. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  84195. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  84196. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  84197. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  84198. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  84199. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  84200. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  84201. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  84202. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  84203. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  84204. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  84205. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  84206. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  84207. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  84208. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  84209. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  84210. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  84211. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  84212. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  84213. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  84214. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  84215. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  84216. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  84217. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  84218. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  84219. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  84220. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  84221. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  84222. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  84223. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  84224. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  84225. };
  84226. unsigned FLAC__crc16_table[256] = {
  84227. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  84228. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  84229. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  84230. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  84231. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  84232. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  84233. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  84234. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  84235. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  84236. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  84237. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  84238. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  84239. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  84240. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  84241. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  84242. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  84243. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  84244. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  84245. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  84246. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  84247. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  84248. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  84249. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  84250. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  84251. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  84252. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  84253. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  84254. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  84255. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  84256. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  84257. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  84258. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  84259. };
  84260. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  84261. {
  84262. *crc = FLAC__crc8_table[*crc ^ data];
  84263. }
  84264. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  84265. {
  84266. while(len--)
  84267. *crc = FLAC__crc8_table[*crc ^ *data++];
  84268. }
  84269. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  84270. {
  84271. FLAC__uint8 crc = 0;
  84272. while(len--)
  84273. crc = FLAC__crc8_table[crc ^ *data++];
  84274. return crc;
  84275. }
  84276. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  84277. {
  84278. unsigned crc = 0;
  84279. while(len--)
  84280. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  84281. return crc;
  84282. }
  84283. #endif
  84284. /*** End of inlined file: crc.c ***/
  84285. /*** Start of inlined file: fixed.c ***/
  84286. /*** Start of inlined file: juce_FlacHeader.h ***/
  84287. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84288. // tasks..
  84289. #define VERSION "1.2.1"
  84290. #define FLAC__NO_DLL 1
  84291. #if JUCE_MSVC
  84292. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84293. #endif
  84294. #if JUCE_MAC
  84295. #define FLAC__SYS_DARWIN 1
  84296. #endif
  84297. /*** End of inlined file: juce_FlacHeader.h ***/
  84298. #if JUCE_USE_FLAC
  84299. #if HAVE_CONFIG_H
  84300. # include <config.h>
  84301. #endif
  84302. #include <math.h>
  84303. #include <string.h>
  84304. /*** Start of inlined file: fixed.h ***/
  84305. #ifndef FLAC__PRIVATE__FIXED_H
  84306. #define FLAC__PRIVATE__FIXED_H
  84307. #ifdef HAVE_CONFIG_H
  84308. #include <config.h>
  84309. #endif
  84310. /*** Start of inlined file: float.h ***/
  84311. #ifndef FLAC__PRIVATE__FLOAT_H
  84312. #define FLAC__PRIVATE__FLOAT_H
  84313. #ifdef HAVE_CONFIG_H
  84314. #include <config.h>
  84315. #endif
  84316. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84317. typedef double FLAC__double;
  84318. typedef float FLAC__float;
  84319. typedef float FLAC__real;
  84320. #else
  84321. typedef FLAC__int32 FLAC__fixedpoint;
  84322. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84323. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84324. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84325. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84326. extern const FLAC__fixedpoint FLAC__FP_E;
  84327. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84328. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84329. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84330. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84331. #endif
  84332. #endif
  84333. /*** End of inlined file: float.h ***/
  84334. /*** Start of inlined file: format.h ***/
  84335. #ifndef FLAC__PRIVATE__FORMAT_H
  84336. #define FLAC__PRIVATE__FORMAT_H
  84337. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84338. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84339. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84340. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84341. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84342. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84343. #endif
  84344. /*** End of inlined file: format.h ***/
  84345. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84346. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84347. # ifndef FLAC__NO_ASM
  84348. # ifdef FLAC__CPU_IA32
  84349. # ifdef FLAC__HAS_NASM
  84350. 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]);
  84351. # endif
  84352. # endif
  84353. # endif
  84354. 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]);
  84355. #else
  84356. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84357. 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]);
  84358. #endif
  84359. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84360. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84361. #endif
  84362. /*** End of inlined file: fixed.h ***/
  84363. #ifndef M_LN2
  84364. #define M_LN2 0.69314718055994530942
  84365. #endif
  84366. #ifdef min
  84367. #undef min
  84368. #endif
  84369. #define min(x,y) ((x) < (y)? (x) : (y))
  84370. #ifdef local_abs
  84371. #undef local_abs
  84372. #endif
  84373. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84374. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84375. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84376. {
  84377. FLAC__uint32 rbps;
  84378. unsigned bits; /* the number of bits required to represent a number */
  84379. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84380. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84381. FLAC__ASSERT(err > 0);
  84382. FLAC__ASSERT(n > 0);
  84383. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84384. if(err <= n)
  84385. return 0;
  84386. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84387. err <<= fracbits;
  84388. err /= n;
  84389. FLAC__ASSERT(err > 0);
  84390. bits = FLAC__bitmath_ilog2(err)+1;
  84391. if(bits > 16) {
  84392. err >>= (bits-16);
  84393. fracbits -= (bits-16);
  84394. }
  84395. rbps = (FLAC__uint32)err;
  84396. rbps *= FLAC__FP_LN2;
  84397. fracbits += 16;
  84398. FLAC__ASSERT(fracbits >= 0);
  84399. {
  84400. const int f = fracbits & 3;
  84401. if(f) {
  84402. rbps >>= f;
  84403. fracbits -= f;
  84404. }
  84405. }
  84406. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84407. if(rbps == 0)
  84408. return 0;
  84409. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84410. FLAC__ASSERT(fracbits >= -3);
  84411. if(fracbits < 16)
  84412. return rbps << (16-fracbits);
  84413. else if(fracbits > 16)
  84414. return rbps >> (fracbits-16);
  84415. else
  84416. return rbps;
  84417. }
  84418. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84419. {
  84420. FLAC__uint32 rbps;
  84421. unsigned bits; /* the number of bits required to represent a number */
  84422. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84423. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84424. FLAC__ASSERT(err > 0);
  84425. FLAC__ASSERT(n > 0);
  84426. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84427. if(err <= n)
  84428. return 0;
  84429. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84430. err <<= fracbits;
  84431. err /= n;
  84432. FLAC__ASSERT(err > 0);
  84433. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84434. if(bits > 16) {
  84435. err >>= (bits-16);
  84436. fracbits -= (bits-16);
  84437. }
  84438. rbps = (FLAC__uint32)err;
  84439. rbps *= FLAC__FP_LN2;
  84440. fracbits += 16;
  84441. FLAC__ASSERT(fracbits >= 0);
  84442. {
  84443. const int f = fracbits & 3;
  84444. if(f) {
  84445. rbps >>= f;
  84446. fracbits -= f;
  84447. }
  84448. }
  84449. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84450. if(rbps == 0)
  84451. return 0;
  84452. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84453. FLAC__ASSERT(fracbits >= -3);
  84454. if(fracbits < 16)
  84455. return rbps << (16-fracbits);
  84456. else if(fracbits > 16)
  84457. return rbps >> (fracbits-16);
  84458. else
  84459. return rbps;
  84460. }
  84461. #endif
  84462. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84463. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84464. #else
  84465. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84466. #endif
  84467. {
  84468. FLAC__int32 last_error_0 = data[-1];
  84469. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84470. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84471. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84472. FLAC__int32 error, save;
  84473. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84474. unsigned i, order;
  84475. for(i = 0; i < data_len; i++) {
  84476. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84477. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84478. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84479. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84480. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84481. }
  84482. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84483. order = 0;
  84484. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84485. order = 1;
  84486. else if(total_error_2 < min(total_error_3, total_error_4))
  84487. order = 2;
  84488. else if(total_error_3 < total_error_4)
  84489. order = 3;
  84490. else
  84491. order = 4;
  84492. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84493. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84494. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84495. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84496. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84497. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84498. 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);
  84499. 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);
  84500. 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);
  84501. 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);
  84502. 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);
  84503. #else
  84504. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84505. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84506. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84507. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84508. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84509. #endif
  84510. return order;
  84511. }
  84512. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84513. 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])
  84514. #else
  84515. 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])
  84516. #endif
  84517. {
  84518. FLAC__int32 last_error_0 = data[-1];
  84519. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84520. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84521. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84522. FLAC__int32 error, save;
  84523. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84524. unsigned i, order;
  84525. for(i = 0; i < data_len; i++) {
  84526. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84527. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84528. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84529. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84530. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84531. }
  84532. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84533. order = 0;
  84534. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84535. order = 1;
  84536. else if(total_error_2 < min(total_error_3, total_error_4))
  84537. order = 2;
  84538. else if(total_error_3 < total_error_4)
  84539. order = 3;
  84540. else
  84541. order = 4;
  84542. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84543. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84544. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84545. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84546. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84547. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84548. #if defined _MSC_VER || defined __MINGW32__
  84549. 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);
  84550. 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);
  84551. 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);
  84552. 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);
  84553. 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);
  84554. #else
  84555. 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);
  84556. 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);
  84557. 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);
  84558. 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);
  84559. 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);
  84560. #endif
  84561. #else
  84562. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84563. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84564. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84565. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84566. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84567. #endif
  84568. return order;
  84569. }
  84570. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84571. {
  84572. const int idata_len = (int)data_len;
  84573. int i;
  84574. switch(order) {
  84575. case 0:
  84576. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84577. memcpy(residual, data, sizeof(residual[0])*data_len);
  84578. break;
  84579. case 1:
  84580. for(i = 0; i < idata_len; i++)
  84581. residual[i] = data[i] - data[i-1];
  84582. break;
  84583. case 2:
  84584. for(i = 0; i < idata_len; i++)
  84585. #if 1 /* OPT: may be faster with some compilers on some systems */
  84586. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84587. #else
  84588. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84589. #endif
  84590. break;
  84591. case 3:
  84592. for(i = 0; i < idata_len; i++)
  84593. #if 1 /* OPT: may be faster with some compilers on some systems */
  84594. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84595. #else
  84596. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84597. #endif
  84598. break;
  84599. case 4:
  84600. for(i = 0; i < idata_len; i++)
  84601. #if 1 /* OPT: may be faster with some compilers on some systems */
  84602. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84603. #else
  84604. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84605. #endif
  84606. break;
  84607. default:
  84608. FLAC__ASSERT(0);
  84609. }
  84610. }
  84611. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84612. {
  84613. int i, idata_len = (int)data_len;
  84614. switch(order) {
  84615. case 0:
  84616. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84617. memcpy(data, residual, sizeof(residual[0])*data_len);
  84618. break;
  84619. case 1:
  84620. for(i = 0; i < idata_len; i++)
  84621. data[i] = residual[i] + data[i-1];
  84622. break;
  84623. case 2:
  84624. for(i = 0; i < idata_len; i++)
  84625. #if 1 /* OPT: may be faster with some compilers on some systems */
  84626. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84627. #else
  84628. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84629. #endif
  84630. break;
  84631. case 3:
  84632. for(i = 0; i < idata_len; i++)
  84633. #if 1 /* OPT: may be faster with some compilers on some systems */
  84634. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84635. #else
  84636. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84637. #endif
  84638. break;
  84639. case 4:
  84640. for(i = 0; i < idata_len; i++)
  84641. #if 1 /* OPT: may be faster with some compilers on some systems */
  84642. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84643. #else
  84644. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84645. #endif
  84646. break;
  84647. default:
  84648. FLAC__ASSERT(0);
  84649. }
  84650. }
  84651. #endif
  84652. /*** End of inlined file: fixed.c ***/
  84653. /*** Start of inlined file: float.c ***/
  84654. /*** Start of inlined file: juce_FlacHeader.h ***/
  84655. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84656. // tasks..
  84657. #define VERSION "1.2.1"
  84658. #define FLAC__NO_DLL 1
  84659. #if JUCE_MSVC
  84660. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84661. #endif
  84662. #if JUCE_MAC
  84663. #define FLAC__SYS_DARWIN 1
  84664. #endif
  84665. /*** End of inlined file: juce_FlacHeader.h ***/
  84666. #if JUCE_USE_FLAC
  84667. #if HAVE_CONFIG_H
  84668. # include <config.h>
  84669. #endif
  84670. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84671. #ifdef _MSC_VER
  84672. #define FLAC__U64L(x) x
  84673. #else
  84674. #define FLAC__U64L(x) x##LLU
  84675. #endif
  84676. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84677. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84678. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84679. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84680. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84681. #define LOG2_LOOKUP_PRECISION 16
  84682. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84683. {
  84684. 0x00000000,
  84685. 0x00000001,
  84686. 0x00000000,
  84687. 0x00000000,
  84688. 0x00000000,
  84689. 0x00000000,
  84690. 0x00000000,
  84691. 0x00000000,
  84692. 0x00000000,
  84693. 0x00000000,
  84694. 0x00000000,
  84695. 0x00000000,
  84696. 0x00000000,
  84697. 0x00000000,
  84698. 0x00000000,
  84699. 0x00000000
  84700. },
  84701. {
  84702. 0x00000000,
  84703. 0x00000010,
  84704. 0x00000007,
  84705. 0x00000003,
  84706. 0x00000001,
  84707. 0x00000001,
  84708. 0x00000000,
  84709. 0x00000000,
  84710. 0x00000000,
  84711. 0x00000000,
  84712. 0x00000000,
  84713. 0x00000000,
  84714. 0x00000000,
  84715. 0x00000000,
  84716. 0x00000000,
  84717. 0x00000000
  84718. },
  84719. {
  84720. 0x00000000,
  84721. 0x00000100,
  84722. 0x0000006a,
  84723. 0x00000031,
  84724. 0x00000018,
  84725. 0x0000000c,
  84726. 0x00000006,
  84727. 0x00000003,
  84728. 0x00000001,
  84729. 0x00000001,
  84730. 0x00000000,
  84731. 0x00000000,
  84732. 0x00000000,
  84733. 0x00000000,
  84734. 0x00000000,
  84735. 0x00000000
  84736. },
  84737. {
  84738. 0x00000000,
  84739. 0x00001000,
  84740. 0x000006a4,
  84741. 0x00000315,
  84742. 0x0000017d,
  84743. 0x000000bc,
  84744. 0x0000005d,
  84745. 0x0000002e,
  84746. 0x00000017,
  84747. 0x0000000c,
  84748. 0x00000006,
  84749. 0x00000003,
  84750. 0x00000001,
  84751. 0x00000001,
  84752. 0x00000000,
  84753. 0x00000000
  84754. },
  84755. {
  84756. 0x00000000,
  84757. 0x00010000,
  84758. 0x00006a40,
  84759. 0x00003151,
  84760. 0x000017d6,
  84761. 0x00000bba,
  84762. 0x000005d1,
  84763. 0x000002e6,
  84764. 0x00000172,
  84765. 0x000000b9,
  84766. 0x0000005c,
  84767. 0x0000002e,
  84768. 0x00000017,
  84769. 0x0000000c,
  84770. 0x00000006,
  84771. 0x00000003
  84772. },
  84773. {
  84774. 0x00000000,
  84775. 0x00100000,
  84776. 0x0006a3fe,
  84777. 0x00031513,
  84778. 0x00017d60,
  84779. 0x0000bb9d,
  84780. 0x00005d10,
  84781. 0x00002e59,
  84782. 0x00001721,
  84783. 0x00000b8e,
  84784. 0x000005c6,
  84785. 0x000002e3,
  84786. 0x00000171,
  84787. 0x000000b9,
  84788. 0x0000005c,
  84789. 0x0000002e
  84790. },
  84791. {
  84792. 0x00000000,
  84793. 0x01000000,
  84794. 0x006a3fe6,
  84795. 0x00315130,
  84796. 0x0017d605,
  84797. 0x000bb9ca,
  84798. 0x0005d0fc,
  84799. 0x0002e58f,
  84800. 0x0001720e,
  84801. 0x0000b8d8,
  84802. 0x00005c61,
  84803. 0x00002e2d,
  84804. 0x00001716,
  84805. 0x00000b8b,
  84806. 0x000005c5,
  84807. 0x000002e3
  84808. },
  84809. {
  84810. 0x00000000,
  84811. 0x10000000,
  84812. 0x06a3fe5c,
  84813. 0x03151301,
  84814. 0x017d6049,
  84815. 0x00bb9ca6,
  84816. 0x005d0fba,
  84817. 0x002e58f7,
  84818. 0x001720da,
  84819. 0x000b8d87,
  84820. 0x0005c60b,
  84821. 0x0002e2d7,
  84822. 0x00017160,
  84823. 0x0000b8ad,
  84824. 0x00005c56,
  84825. 0x00002e2b
  84826. }
  84827. };
  84828. #if 0
  84829. static const FLAC__uint64 log2_lookup_wide[] = {
  84830. {
  84831. 0x00000000,
  84832. FLAC__U64L(0x100000000),
  84833. FLAC__U64L(0x6a3fe5c6),
  84834. FLAC__U64L(0x31513015),
  84835. FLAC__U64L(0x17d60497),
  84836. FLAC__U64L(0x0bb9ca65),
  84837. FLAC__U64L(0x05d0fba2),
  84838. FLAC__U64L(0x02e58f74),
  84839. FLAC__U64L(0x01720d9c),
  84840. FLAC__U64L(0x00b8d875),
  84841. FLAC__U64L(0x005c60aa),
  84842. FLAC__U64L(0x002e2d72),
  84843. FLAC__U64L(0x00171600),
  84844. FLAC__U64L(0x000b8ad2),
  84845. FLAC__U64L(0x0005c55d),
  84846. FLAC__U64L(0x0002e2ac)
  84847. },
  84848. {
  84849. 0x00000000,
  84850. FLAC__U64L(0x1000000000000),
  84851. FLAC__U64L(0x6a3fe5c60429),
  84852. FLAC__U64L(0x315130157f7a),
  84853. FLAC__U64L(0x17d60496cfbb),
  84854. FLAC__U64L(0xbb9ca64ecac),
  84855. FLAC__U64L(0x5d0fba187cd),
  84856. FLAC__U64L(0x2e58f7441ee),
  84857. FLAC__U64L(0x1720d9c06a8),
  84858. FLAC__U64L(0xb8d8752173),
  84859. FLAC__U64L(0x5c60aa252e),
  84860. FLAC__U64L(0x2e2d71b0d8),
  84861. FLAC__U64L(0x1716001719),
  84862. FLAC__U64L(0xb8ad1de1b),
  84863. FLAC__U64L(0x5c55d640d),
  84864. FLAC__U64L(0x2e2abcf52)
  84865. }
  84866. };
  84867. #endif
  84868. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84869. {
  84870. const FLAC__uint32 ONE = (1u << fracbits);
  84871. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84872. FLAC__ASSERT(fracbits < 32);
  84873. FLAC__ASSERT((fracbits & 0x3) == 0);
  84874. if(x < ONE)
  84875. return 0;
  84876. if(precision > LOG2_LOOKUP_PRECISION)
  84877. precision = LOG2_LOOKUP_PRECISION;
  84878. {
  84879. FLAC__uint32 y = 0;
  84880. FLAC__uint32 z = x >> 1, k = 1;
  84881. while (x > ONE && k < precision) {
  84882. if (x - z >= ONE) {
  84883. x -= z;
  84884. z = x >> k;
  84885. y += table[k];
  84886. }
  84887. else {
  84888. z >>= 1;
  84889. k++;
  84890. }
  84891. }
  84892. return y;
  84893. }
  84894. }
  84895. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84896. #endif
  84897. /*** End of inlined file: float.c ***/
  84898. /*** Start of inlined file: format.c ***/
  84899. /*** Start of inlined file: juce_FlacHeader.h ***/
  84900. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84901. // tasks..
  84902. #define VERSION "1.2.1"
  84903. #define FLAC__NO_DLL 1
  84904. #if JUCE_MSVC
  84905. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84906. #endif
  84907. #if JUCE_MAC
  84908. #define FLAC__SYS_DARWIN 1
  84909. #endif
  84910. /*** End of inlined file: juce_FlacHeader.h ***/
  84911. #if JUCE_USE_FLAC
  84912. #if HAVE_CONFIG_H
  84913. # include <config.h>
  84914. #endif
  84915. #include <stdio.h>
  84916. #include <stdlib.h> /* for qsort() */
  84917. #include <string.h> /* for memset() */
  84918. #ifndef FLaC__INLINE
  84919. #define FLaC__INLINE
  84920. #endif
  84921. #ifdef min
  84922. #undef min
  84923. #endif
  84924. #define min(a,b) ((a)<(b)?(a):(b))
  84925. #ifdef _MSC_VER
  84926. #define FLAC__U64L(x) x
  84927. #else
  84928. #define FLAC__U64L(x) x##LLU
  84929. #endif
  84930. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84931. ;
  84932. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84933. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84934. #else
  84935. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84936. #endif
  84937. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84938. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84939. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84940. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84941. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84942. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84943. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84944. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84945. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84946. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84947. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84948. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84949. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84950. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84951. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84952. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84953. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84954. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84955. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84956. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84957. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84958. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84959. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84960. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84961. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84962. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84963. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84964. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84965. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84966. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84967. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84968. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84969. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84970. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84971. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84972. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84973. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84974. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84975. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84976. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84977. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84978. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84979. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84980. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84981. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84982. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84983. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84984. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84985. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84986. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84987. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84988. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84989. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84990. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84991. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84992. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84993. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84994. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84995. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84996. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84997. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84998. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84999. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  85000. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  85001. "PARTITIONED_RICE",
  85002. "PARTITIONED_RICE2"
  85003. };
  85004. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  85005. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  85006. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  85007. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  85008. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  85009. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  85010. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  85011. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  85012. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  85013. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  85014. "CONSTANT",
  85015. "VERBATIM",
  85016. "FIXED",
  85017. "LPC"
  85018. };
  85019. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  85020. "INDEPENDENT",
  85021. "LEFT_SIDE",
  85022. "RIGHT_SIDE",
  85023. "MID_SIDE"
  85024. };
  85025. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  85026. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  85027. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  85028. };
  85029. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  85030. "STREAMINFO",
  85031. "PADDING",
  85032. "APPLICATION",
  85033. "SEEKTABLE",
  85034. "VORBIS_COMMENT",
  85035. "CUESHEET",
  85036. "PICTURE"
  85037. };
  85038. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  85039. "Other",
  85040. "32x32 pixels 'file icon' (PNG only)",
  85041. "Other file icon",
  85042. "Cover (front)",
  85043. "Cover (back)",
  85044. "Leaflet page",
  85045. "Media (e.g. label side of CD)",
  85046. "Lead artist/lead performer/soloist",
  85047. "Artist/performer",
  85048. "Conductor",
  85049. "Band/Orchestra",
  85050. "Composer",
  85051. "Lyricist/text writer",
  85052. "Recording Location",
  85053. "During recording",
  85054. "During performance",
  85055. "Movie/video screen capture",
  85056. "A bright coloured fish",
  85057. "Illustration",
  85058. "Band/artist logotype",
  85059. "Publisher/Studio logotype"
  85060. };
  85061. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  85062. {
  85063. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  85064. return false;
  85065. }
  85066. else
  85067. return true;
  85068. }
  85069. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  85070. {
  85071. if(
  85072. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  85073. (
  85074. sample_rate >= (1u << 16) &&
  85075. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  85076. )
  85077. ) {
  85078. return false;
  85079. }
  85080. else
  85081. return true;
  85082. }
  85083. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  85084. {
  85085. unsigned i;
  85086. FLAC__uint64 prev_sample_number = 0;
  85087. FLAC__bool got_prev = false;
  85088. FLAC__ASSERT(0 != seek_table);
  85089. for(i = 0; i < seek_table->num_points; i++) {
  85090. if(got_prev) {
  85091. if(
  85092. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  85093. seek_table->points[i].sample_number <= prev_sample_number
  85094. )
  85095. return false;
  85096. }
  85097. prev_sample_number = seek_table->points[i].sample_number;
  85098. got_prev = true;
  85099. }
  85100. return true;
  85101. }
  85102. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  85103. {
  85104. if(l->sample_number == r->sample_number)
  85105. return 0;
  85106. else if(l->sample_number < r->sample_number)
  85107. return -1;
  85108. else
  85109. return 1;
  85110. }
  85111. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  85112. {
  85113. unsigned i, j;
  85114. FLAC__bool first;
  85115. FLAC__ASSERT(0 != seek_table);
  85116. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  85117. first = true;
  85118. for(i = j = 0; i < seek_table->num_points; i++) {
  85119. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  85120. if(!first) {
  85121. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  85122. continue;
  85123. }
  85124. }
  85125. first = false;
  85126. seek_table->points[j++] = seek_table->points[i];
  85127. }
  85128. for(i = j; i < seek_table->num_points; i++) {
  85129. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  85130. seek_table->points[i].stream_offset = 0;
  85131. seek_table->points[i].frame_samples = 0;
  85132. }
  85133. return j;
  85134. }
  85135. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  85136. {
  85137. FLAC__ASSERT(0 != utf8);
  85138. if ((utf8[0] & 0x80) == 0) {
  85139. return 1;
  85140. }
  85141. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  85142. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  85143. return 0;
  85144. return 2;
  85145. }
  85146. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  85147. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  85148. return 0;
  85149. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  85150. return 0;
  85151. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  85152. return 0;
  85153. return 3;
  85154. }
  85155. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  85156. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  85157. return 0;
  85158. return 4;
  85159. }
  85160. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  85161. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  85162. return 0;
  85163. return 5;
  85164. }
  85165. 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) {
  85166. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  85167. return 0;
  85168. return 6;
  85169. }
  85170. else {
  85171. return 0;
  85172. }
  85173. }
  85174. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  85175. {
  85176. char c;
  85177. for(c = *name; c; c = *(++name))
  85178. if(c < 0x20 || c == 0x3d || c > 0x7d)
  85179. return false;
  85180. return true;
  85181. }
  85182. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  85183. {
  85184. if(length == (unsigned)(-1)) {
  85185. while(*value) {
  85186. unsigned n = utf8len_(value);
  85187. if(n == 0)
  85188. return false;
  85189. value += n;
  85190. }
  85191. }
  85192. else {
  85193. const FLAC__byte *end = value + length;
  85194. while(value < end) {
  85195. unsigned n = utf8len_(value);
  85196. if(n == 0)
  85197. return false;
  85198. value += n;
  85199. }
  85200. if(value != end)
  85201. return false;
  85202. }
  85203. return true;
  85204. }
  85205. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  85206. {
  85207. const FLAC__byte *s, *end;
  85208. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  85209. if(*s < 0x20 || *s > 0x7D)
  85210. return false;
  85211. }
  85212. if(s == end)
  85213. return false;
  85214. s++; /* skip '=' */
  85215. while(s < end) {
  85216. unsigned n = utf8len_(s);
  85217. if(n == 0)
  85218. return false;
  85219. s += n;
  85220. }
  85221. if(s != end)
  85222. return false;
  85223. return true;
  85224. }
  85225. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  85226. {
  85227. unsigned i, j;
  85228. if(check_cd_da_subset) {
  85229. if(cue_sheet->lead_in < 2 * 44100) {
  85230. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  85231. return false;
  85232. }
  85233. if(cue_sheet->lead_in % 588 != 0) {
  85234. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  85235. return false;
  85236. }
  85237. }
  85238. if(cue_sheet->num_tracks == 0) {
  85239. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  85240. return false;
  85241. }
  85242. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  85243. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  85244. return false;
  85245. }
  85246. for(i = 0; i < cue_sheet->num_tracks; i++) {
  85247. if(cue_sheet->tracks[i].number == 0) {
  85248. if(violation) *violation = "cue sheet may not have a track number 0";
  85249. return false;
  85250. }
  85251. if(check_cd_da_subset) {
  85252. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  85253. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  85254. return false;
  85255. }
  85256. }
  85257. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  85258. if(violation) {
  85259. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  85260. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  85261. else
  85262. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  85263. }
  85264. return false;
  85265. }
  85266. if(i < cue_sheet->num_tracks - 1) {
  85267. if(cue_sheet->tracks[i].num_indices == 0) {
  85268. if(violation) *violation = "cue sheet track must have at least one index point";
  85269. return false;
  85270. }
  85271. if(cue_sheet->tracks[i].indices[0].number > 1) {
  85272. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  85273. return false;
  85274. }
  85275. }
  85276. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  85277. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  85278. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  85279. return false;
  85280. }
  85281. if(j > 0) {
  85282. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  85283. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  85284. return false;
  85285. }
  85286. }
  85287. }
  85288. }
  85289. return true;
  85290. }
  85291. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  85292. {
  85293. char *p;
  85294. FLAC__byte *b;
  85295. for(p = picture->mime_type; *p; p++) {
  85296. if(*p < 0x20 || *p > 0x7e) {
  85297. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  85298. return false;
  85299. }
  85300. }
  85301. for(b = picture->description; *b; ) {
  85302. unsigned n = utf8len_(b);
  85303. if(n == 0) {
  85304. if(violation) *violation = "description string must be valid UTF-8";
  85305. return false;
  85306. }
  85307. b += n;
  85308. }
  85309. return true;
  85310. }
  85311. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  85312. {
  85313. return
  85314. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  85315. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  85316. blocksize,
  85317. predictor_order
  85318. );
  85319. }
  85320. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85321. {
  85322. unsigned max_rice_partition_order = 0;
  85323. while(!(blocksize & 1)) {
  85324. max_rice_partition_order++;
  85325. blocksize >>= 1;
  85326. }
  85327. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85328. }
  85329. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85330. {
  85331. unsigned max_rice_partition_order = limit;
  85332. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85333. max_rice_partition_order--;
  85334. FLAC__ASSERT(
  85335. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85336. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85337. );
  85338. return max_rice_partition_order;
  85339. }
  85340. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85341. {
  85342. FLAC__ASSERT(0 != object);
  85343. object->parameters = 0;
  85344. object->raw_bits = 0;
  85345. object->capacity_by_order = 0;
  85346. }
  85347. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85348. {
  85349. FLAC__ASSERT(0 != object);
  85350. if(0 != object->parameters)
  85351. free(object->parameters);
  85352. if(0 != object->raw_bits)
  85353. free(object->raw_bits);
  85354. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85355. }
  85356. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85357. {
  85358. FLAC__ASSERT(0 != object);
  85359. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85360. if(object->capacity_by_order < max_partition_order) {
  85361. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85362. return false;
  85363. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85364. return false;
  85365. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85366. object->capacity_by_order = max_partition_order;
  85367. }
  85368. return true;
  85369. }
  85370. #endif
  85371. /*** End of inlined file: format.c ***/
  85372. /*** Start of inlined file: lpc_flac.c ***/
  85373. /*** Start of inlined file: juce_FlacHeader.h ***/
  85374. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85375. // tasks..
  85376. #define VERSION "1.2.1"
  85377. #define FLAC__NO_DLL 1
  85378. #if JUCE_MSVC
  85379. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85380. #endif
  85381. #if JUCE_MAC
  85382. #define FLAC__SYS_DARWIN 1
  85383. #endif
  85384. /*** End of inlined file: juce_FlacHeader.h ***/
  85385. #if JUCE_USE_FLAC
  85386. #if HAVE_CONFIG_H
  85387. # include <config.h>
  85388. #endif
  85389. #include <math.h>
  85390. /*** Start of inlined file: lpc.h ***/
  85391. #ifndef FLAC__PRIVATE__LPC_H
  85392. #define FLAC__PRIVATE__LPC_H
  85393. #ifdef HAVE_CONFIG_H
  85394. #include <config.h>
  85395. #endif
  85396. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85397. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85398. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85399. #ifndef FLAC__NO_ASM
  85400. # ifdef FLAC__CPU_IA32
  85401. # ifdef FLAC__HAS_NASM
  85402. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85403. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85404. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85405. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85406. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85407. # endif
  85408. # endif
  85409. #endif
  85410. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85411. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85412. 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[]);
  85413. 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[]);
  85414. #ifndef FLAC__NO_ASM
  85415. # ifdef FLAC__CPU_IA32
  85416. # ifdef FLAC__HAS_NASM
  85417. 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[]);
  85418. 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[]);
  85419. # endif
  85420. # endif
  85421. #endif
  85422. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85423. 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[]);
  85424. 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[]);
  85425. #ifndef FLAC__NO_ASM
  85426. # ifdef FLAC__CPU_IA32
  85427. # ifdef FLAC__HAS_NASM
  85428. 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[]);
  85429. 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[]);
  85430. # endif /* FLAC__HAS_NASM */
  85431. # elif defined FLAC__CPU_PPC
  85432. 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[]);
  85433. 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[]);
  85434. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85435. #endif /* FLAC__NO_ASM */
  85436. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85437. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85438. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85439. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85440. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85441. #endif
  85442. /*** End of inlined file: lpc.h ***/
  85443. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85444. #include <stdio.h>
  85445. #endif
  85446. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85447. #ifndef M_LN2
  85448. #define M_LN2 0.69314718055994530942
  85449. #endif
  85450. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85451. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85452. {
  85453. unsigned i;
  85454. for(i = 0; i < data_len; i++)
  85455. out[i] = in[i] * window[i];
  85456. }
  85457. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85458. {
  85459. #if 0
  85460. FLAC__real d;
  85461. unsigned i;
  85462. FLAC__ASSERT(lag > 0);
  85463. FLAC__ASSERT(lag <= data_len);
  85464. while(lag--) {
  85465. for(i = lag, d = 0.0; i < data_len; i++)
  85466. d += data[i] * data[i - lag];
  85467. autoc[lag] = d;
  85468. }
  85469. #endif
  85470. FLAC__real d;
  85471. unsigned sample, coeff;
  85472. const unsigned limit = data_len - lag;
  85473. FLAC__ASSERT(lag > 0);
  85474. FLAC__ASSERT(lag <= data_len);
  85475. for(coeff = 0; coeff < lag; coeff++)
  85476. autoc[coeff] = 0.0;
  85477. for(sample = 0; sample <= limit; sample++) {
  85478. d = data[sample];
  85479. for(coeff = 0; coeff < lag; coeff++)
  85480. autoc[coeff] += d * data[sample+coeff];
  85481. }
  85482. for(; sample < data_len; sample++) {
  85483. d = data[sample];
  85484. for(coeff = 0; coeff < data_len - sample; coeff++)
  85485. autoc[coeff] += d * data[sample+coeff];
  85486. }
  85487. }
  85488. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85489. {
  85490. unsigned i, j;
  85491. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85492. FLAC__ASSERT(0 != max_order);
  85493. FLAC__ASSERT(0 < *max_order);
  85494. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85495. FLAC__ASSERT(autoc[0] != 0.0);
  85496. err = autoc[0];
  85497. for(i = 0; i < *max_order; i++) {
  85498. r = -autoc[i+1];
  85499. for(j = 0; j < i; j++)
  85500. r -= lpc[j] * autoc[i-j];
  85501. ref[i] = (r/=err);
  85502. lpc[i]=r;
  85503. for(j = 0; j < (i>>1); j++) {
  85504. FLAC__double tmp = lpc[j];
  85505. lpc[j] += r * lpc[i-1-j];
  85506. lpc[i-1-j] += r * tmp;
  85507. }
  85508. if(i & 1)
  85509. lpc[j] += lpc[j] * r;
  85510. err *= (1.0 - r * r);
  85511. for(j = 0; j <= i; j++)
  85512. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85513. error[i] = err;
  85514. if(err == 0.0) {
  85515. *max_order = i+1;
  85516. return;
  85517. }
  85518. }
  85519. }
  85520. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85521. {
  85522. unsigned i;
  85523. FLAC__double cmax;
  85524. FLAC__int32 qmax, qmin;
  85525. FLAC__ASSERT(precision > 0);
  85526. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85527. precision--;
  85528. qmax = 1 << precision;
  85529. qmin = -qmax;
  85530. qmax--;
  85531. cmax = 0.0;
  85532. for(i = 0; i < order; i++) {
  85533. const FLAC__double d = fabs(lp_coeff[i]);
  85534. if(d > cmax)
  85535. cmax = d;
  85536. }
  85537. if(cmax <= 0.0) {
  85538. return 2;
  85539. }
  85540. else {
  85541. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85542. const int min_shiftlimit = -max_shiftlimit - 1;
  85543. int log2cmax;
  85544. (void)frexp(cmax, &log2cmax);
  85545. log2cmax--;
  85546. *shift = (int)precision - log2cmax - 1;
  85547. if(*shift > max_shiftlimit)
  85548. *shift = max_shiftlimit;
  85549. else if(*shift < min_shiftlimit)
  85550. return 1;
  85551. }
  85552. if(*shift >= 0) {
  85553. FLAC__double error = 0.0;
  85554. FLAC__int32 q;
  85555. for(i = 0; i < order; i++) {
  85556. error += lp_coeff[i] * (1 << *shift);
  85557. #if 1 /* unfortunately lround() is C99 */
  85558. if(error >= 0.0)
  85559. q = (FLAC__int32)(error + 0.5);
  85560. else
  85561. q = (FLAC__int32)(error - 0.5);
  85562. #else
  85563. q = lround(error);
  85564. #endif
  85565. #ifdef FLAC__OVERFLOW_DETECT
  85566. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85567. 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]);
  85568. else if(q < qmin)
  85569. 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]);
  85570. #endif
  85571. if(q > qmax)
  85572. q = qmax;
  85573. else if(q < qmin)
  85574. q = qmin;
  85575. error -= q;
  85576. qlp_coeff[i] = q;
  85577. }
  85578. }
  85579. else {
  85580. const int nshift = -(*shift);
  85581. FLAC__double error = 0.0;
  85582. FLAC__int32 q;
  85583. #ifdef DEBUG
  85584. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85585. #endif
  85586. for(i = 0; i < order; i++) {
  85587. error += lp_coeff[i] / (1 << nshift);
  85588. #if 1 /* unfortunately lround() is C99 */
  85589. if(error >= 0.0)
  85590. q = (FLAC__int32)(error + 0.5);
  85591. else
  85592. q = (FLAC__int32)(error - 0.5);
  85593. #else
  85594. q = lround(error);
  85595. #endif
  85596. #ifdef FLAC__OVERFLOW_DETECT
  85597. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85598. 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]);
  85599. else if(q < qmin)
  85600. 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]);
  85601. #endif
  85602. if(q > qmax)
  85603. q = qmax;
  85604. else if(q < qmin)
  85605. q = qmin;
  85606. error -= q;
  85607. qlp_coeff[i] = q;
  85608. }
  85609. *shift = 0;
  85610. }
  85611. return 0;
  85612. }
  85613. 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[])
  85614. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85615. {
  85616. FLAC__int64 sumo;
  85617. unsigned i, j;
  85618. FLAC__int32 sum;
  85619. const FLAC__int32 *history;
  85620. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85621. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85622. for(i=0;i<order;i++)
  85623. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85624. fprintf(stderr,"\n");
  85625. #endif
  85626. FLAC__ASSERT(order > 0);
  85627. for(i = 0; i < data_len; i++) {
  85628. sumo = 0;
  85629. sum = 0;
  85630. history = data;
  85631. for(j = 0; j < order; j++) {
  85632. sum += qlp_coeff[j] * (*(--history));
  85633. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85634. #if defined _MSC_VER
  85635. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85636. 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);
  85637. #else
  85638. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85639. 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);
  85640. #endif
  85641. }
  85642. *(residual++) = *(data++) - (sum >> lp_quantization);
  85643. }
  85644. }
  85645. #else /* fully unrolled version for normal use */
  85646. {
  85647. int i;
  85648. FLAC__int32 sum;
  85649. FLAC__ASSERT(order > 0);
  85650. FLAC__ASSERT(order <= 32);
  85651. if(order <= 12) {
  85652. if(order > 8) {
  85653. if(order > 10) {
  85654. if(order == 12) {
  85655. for(i = 0; i < (int)data_len; i++) {
  85656. sum = 0;
  85657. sum += qlp_coeff[11] * data[i-12];
  85658. sum += qlp_coeff[10] * data[i-11];
  85659. sum += qlp_coeff[9] * data[i-10];
  85660. sum += qlp_coeff[8] * data[i-9];
  85661. sum += qlp_coeff[7] * data[i-8];
  85662. sum += qlp_coeff[6] * data[i-7];
  85663. sum += qlp_coeff[5] * data[i-6];
  85664. sum += qlp_coeff[4] * data[i-5];
  85665. sum += qlp_coeff[3] * data[i-4];
  85666. sum += qlp_coeff[2] * data[i-3];
  85667. sum += qlp_coeff[1] * data[i-2];
  85668. sum += qlp_coeff[0] * data[i-1];
  85669. residual[i] = data[i] - (sum >> lp_quantization);
  85670. }
  85671. }
  85672. else { /* order == 11 */
  85673. for(i = 0; i < (int)data_len; i++) {
  85674. sum = 0;
  85675. sum += qlp_coeff[10] * data[i-11];
  85676. sum += qlp_coeff[9] * data[i-10];
  85677. sum += qlp_coeff[8] * data[i-9];
  85678. sum += qlp_coeff[7] * data[i-8];
  85679. sum += qlp_coeff[6] * data[i-7];
  85680. sum += qlp_coeff[5] * data[i-6];
  85681. sum += qlp_coeff[4] * data[i-5];
  85682. sum += qlp_coeff[3] * data[i-4];
  85683. sum += qlp_coeff[2] * data[i-3];
  85684. sum += qlp_coeff[1] * data[i-2];
  85685. sum += qlp_coeff[0] * data[i-1];
  85686. residual[i] = data[i] - (sum >> lp_quantization);
  85687. }
  85688. }
  85689. }
  85690. else {
  85691. if(order == 10) {
  85692. for(i = 0; i < (int)data_len; i++) {
  85693. sum = 0;
  85694. sum += qlp_coeff[9] * data[i-10];
  85695. sum += qlp_coeff[8] * data[i-9];
  85696. sum += qlp_coeff[7] * data[i-8];
  85697. sum += qlp_coeff[6] * data[i-7];
  85698. sum += qlp_coeff[5] * data[i-6];
  85699. sum += qlp_coeff[4] * data[i-5];
  85700. sum += qlp_coeff[3] * data[i-4];
  85701. sum += qlp_coeff[2] * data[i-3];
  85702. sum += qlp_coeff[1] * data[i-2];
  85703. sum += qlp_coeff[0] * data[i-1];
  85704. residual[i] = data[i] - (sum >> lp_quantization);
  85705. }
  85706. }
  85707. else { /* order == 9 */
  85708. for(i = 0; i < (int)data_len; i++) {
  85709. sum = 0;
  85710. sum += qlp_coeff[8] * data[i-9];
  85711. sum += qlp_coeff[7] * data[i-8];
  85712. sum += qlp_coeff[6] * data[i-7];
  85713. sum += qlp_coeff[5] * data[i-6];
  85714. sum += qlp_coeff[4] * data[i-5];
  85715. sum += qlp_coeff[3] * data[i-4];
  85716. sum += qlp_coeff[2] * data[i-3];
  85717. sum += qlp_coeff[1] * data[i-2];
  85718. sum += qlp_coeff[0] * data[i-1];
  85719. residual[i] = data[i] - (sum >> lp_quantization);
  85720. }
  85721. }
  85722. }
  85723. }
  85724. else if(order > 4) {
  85725. if(order > 6) {
  85726. if(order == 8) {
  85727. for(i = 0; i < (int)data_len; i++) {
  85728. sum = 0;
  85729. sum += qlp_coeff[7] * data[i-8];
  85730. sum += qlp_coeff[6] * data[i-7];
  85731. sum += qlp_coeff[5] * data[i-6];
  85732. sum += qlp_coeff[4] * data[i-5];
  85733. sum += qlp_coeff[3] * data[i-4];
  85734. sum += qlp_coeff[2] * data[i-3];
  85735. sum += qlp_coeff[1] * data[i-2];
  85736. sum += qlp_coeff[0] * data[i-1];
  85737. residual[i] = data[i] - (sum >> lp_quantization);
  85738. }
  85739. }
  85740. else { /* order == 7 */
  85741. for(i = 0; i < (int)data_len; i++) {
  85742. sum = 0;
  85743. sum += qlp_coeff[6] * data[i-7];
  85744. sum += qlp_coeff[5] * data[i-6];
  85745. sum += qlp_coeff[4] * data[i-5];
  85746. sum += qlp_coeff[3] * data[i-4];
  85747. sum += qlp_coeff[2] * data[i-3];
  85748. sum += qlp_coeff[1] * data[i-2];
  85749. sum += qlp_coeff[0] * data[i-1];
  85750. residual[i] = data[i] - (sum >> lp_quantization);
  85751. }
  85752. }
  85753. }
  85754. else {
  85755. if(order == 6) {
  85756. for(i = 0; i < (int)data_len; i++) {
  85757. sum = 0;
  85758. sum += qlp_coeff[5] * data[i-6];
  85759. sum += qlp_coeff[4] * data[i-5];
  85760. sum += qlp_coeff[3] * data[i-4];
  85761. sum += qlp_coeff[2] * data[i-3];
  85762. sum += qlp_coeff[1] * data[i-2];
  85763. sum += qlp_coeff[0] * data[i-1];
  85764. residual[i] = data[i] - (sum >> lp_quantization);
  85765. }
  85766. }
  85767. else { /* order == 5 */
  85768. for(i = 0; i < (int)data_len; i++) {
  85769. sum = 0;
  85770. sum += qlp_coeff[4] * data[i-5];
  85771. sum += qlp_coeff[3] * data[i-4];
  85772. sum += qlp_coeff[2] * data[i-3];
  85773. sum += qlp_coeff[1] * data[i-2];
  85774. sum += qlp_coeff[0] * data[i-1];
  85775. residual[i] = data[i] - (sum >> lp_quantization);
  85776. }
  85777. }
  85778. }
  85779. }
  85780. else {
  85781. if(order > 2) {
  85782. if(order == 4) {
  85783. for(i = 0; i < (int)data_len; i++) {
  85784. sum = 0;
  85785. sum += qlp_coeff[3] * data[i-4];
  85786. sum += qlp_coeff[2] * data[i-3];
  85787. sum += qlp_coeff[1] * data[i-2];
  85788. sum += qlp_coeff[0] * data[i-1];
  85789. residual[i] = data[i] - (sum >> lp_quantization);
  85790. }
  85791. }
  85792. else { /* order == 3 */
  85793. for(i = 0; i < (int)data_len; i++) {
  85794. sum = 0;
  85795. sum += qlp_coeff[2] * data[i-3];
  85796. sum += qlp_coeff[1] * data[i-2];
  85797. sum += qlp_coeff[0] * data[i-1];
  85798. residual[i] = data[i] - (sum >> lp_quantization);
  85799. }
  85800. }
  85801. }
  85802. else {
  85803. if(order == 2) {
  85804. for(i = 0; i < (int)data_len; i++) {
  85805. sum = 0;
  85806. sum += qlp_coeff[1] * data[i-2];
  85807. sum += qlp_coeff[0] * data[i-1];
  85808. residual[i] = data[i] - (sum >> lp_quantization);
  85809. }
  85810. }
  85811. else { /* order == 1 */
  85812. for(i = 0; i < (int)data_len; i++)
  85813. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85814. }
  85815. }
  85816. }
  85817. }
  85818. else { /* order > 12 */
  85819. for(i = 0; i < (int)data_len; i++) {
  85820. sum = 0;
  85821. switch(order) {
  85822. case 32: sum += qlp_coeff[31] * data[i-32];
  85823. case 31: sum += qlp_coeff[30] * data[i-31];
  85824. case 30: sum += qlp_coeff[29] * data[i-30];
  85825. case 29: sum += qlp_coeff[28] * data[i-29];
  85826. case 28: sum += qlp_coeff[27] * data[i-28];
  85827. case 27: sum += qlp_coeff[26] * data[i-27];
  85828. case 26: sum += qlp_coeff[25] * data[i-26];
  85829. case 25: sum += qlp_coeff[24] * data[i-25];
  85830. case 24: sum += qlp_coeff[23] * data[i-24];
  85831. case 23: sum += qlp_coeff[22] * data[i-23];
  85832. case 22: sum += qlp_coeff[21] * data[i-22];
  85833. case 21: sum += qlp_coeff[20] * data[i-21];
  85834. case 20: sum += qlp_coeff[19] * data[i-20];
  85835. case 19: sum += qlp_coeff[18] * data[i-19];
  85836. case 18: sum += qlp_coeff[17] * data[i-18];
  85837. case 17: sum += qlp_coeff[16] * data[i-17];
  85838. case 16: sum += qlp_coeff[15] * data[i-16];
  85839. case 15: sum += qlp_coeff[14] * data[i-15];
  85840. case 14: sum += qlp_coeff[13] * data[i-14];
  85841. case 13: sum += qlp_coeff[12] * data[i-13];
  85842. sum += qlp_coeff[11] * data[i-12];
  85843. sum += qlp_coeff[10] * data[i-11];
  85844. sum += qlp_coeff[ 9] * data[i-10];
  85845. sum += qlp_coeff[ 8] * data[i- 9];
  85846. sum += qlp_coeff[ 7] * data[i- 8];
  85847. sum += qlp_coeff[ 6] * data[i- 7];
  85848. sum += qlp_coeff[ 5] * data[i- 6];
  85849. sum += qlp_coeff[ 4] * data[i- 5];
  85850. sum += qlp_coeff[ 3] * data[i- 4];
  85851. sum += qlp_coeff[ 2] * data[i- 3];
  85852. sum += qlp_coeff[ 1] * data[i- 2];
  85853. sum += qlp_coeff[ 0] * data[i- 1];
  85854. }
  85855. residual[i] = data[i] - (sum >> lp_quantization);
  85856. }
  85857. }
  85858. }
  85859. #endif
  85860. 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[])
  85861. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85862. {
  85863. unsigned i, j;
  85864. FLAC__int64 sum;
  85865. const FLAC__int32 *history;
  85866. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85867. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85868. for(i=0;i<order;i++)
  85869. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85870. fprintf(stderr,"\n");
  85871. #endif
  85872. FLAC__ASSERT(order > 0);
  85873. for(i = 0; i < data_len; i++) {
  85874. sum = 0;
  85875. history = data;
  85876. for(j = 0; j < order; j++)
  85877. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85878. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85879. #if defined _MSC_VER
  85880. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85881. #else
  85882. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85883. #endif
  85884. break;
  85885. }
  85886. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85887. #if defined _MSC_VER
  85888. 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));
  85889. #else
  85890. 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)));
  85891. #endif
  85892. break;
  85893. }
  85894. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85895. }
  85896. }
  85897. #else /* fully unrolled version for normal use */
  85898. {
  85899. int i;
  85900. FLAC__int64 sum;
  85901. FLAC__ASSERT(order > 0);
  85902. FLAC__ASSERT(order <= 32);
  85903. if(order <= 12) {
  85904. if(order > 8) {
  85905. if(order > 10) {
  85906. if(order == 12) {
  85907. for(i = 0; i < (int)data_len; i++) {
  85908. sum = 0;
  85909. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85910. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85911. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85912. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85913. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85914. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85915. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85916. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85917. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85918. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85919. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85920. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85921. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85922. }
  85923. }
  85924. else { /* order == 11 */
  85925. for(i = 0; i < (int)data_len; i++) {
  85926. sum = 0;
  85927. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85928. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85929. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85930. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85931. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85932. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85933. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85934. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85935. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85936. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85937. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85938. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85939. }
  85940. }
  85941. }
  85942. else {
  85943. if(order == 10) {
  85944. for(i = 0; i < (int)data_len; i++) {
  85945. sum = 0;
  85946. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85947. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85948. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85949. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85950. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85951. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85952. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85953. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85954. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85955. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85956. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85957. }
  85958. }
  85959. else { /* order == 9 */
  85960. for(i = 0; i < (int)data_len; i++) {
  85961. sum = 0;
  85962. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85963. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85964. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85965. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85966. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85967. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85968. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85969. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85970. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85971. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85972. }
  85973. }
  85974. }
  85975. }
  85976. else if(order > 4) {
  85977. if(order > 6) {
  85978. if(order == 8) {
  85979. for(i = 0; i < (int)data_len; i++) {
  85980. sum = 0;
  85981. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85982. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85983. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85984. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85985. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85986. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85987. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85988. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85989. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85990. }
  85991. }
  85992. else { /* order == 7 */
  85993. for(i = 0; i < (int)data_len; i++) {
  85994. sum = 0;
  85995. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85996. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85997. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85998. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85999. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86000. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86001. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86002. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86003. }
  86004. }
  86005. }
  86006. else {
  86007. if(order == 6) {
  86008. for(i = 0; i < (int)data_len; i++) {
  86009. sum = 0;
  86010. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86011. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86012. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86013. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86014. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86015. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86016. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86017. }
  86018. }
  86019. else { /* order == 5 */
  86020. for(i = 0; i < (int)data_len; i++) {
  86021. sum = 0;
  86022. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86023. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86024. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86025. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86026. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86027. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86028. }
  86029. }
  86030. }
  86031. }
  86032. else {
  86033. if(order > 2) {
  86034. if(order == 4) {
  86035. for(i = 0; i < (int)data_len; i++) {
  86036. sum = 0;
  86037. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86038. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86039. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86040. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86041. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86042. }
  86043. }
  86044. else { /* order == 3 */
  86045. for(i = 0; i < (int)data_len; i++) {
  86046. sum = 0;
  86047. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86048. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86049. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86050. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86051. }
  86052. }
  86053. }
  86054. else {
  86055. if(order == 2) {
  86056. for(i = 0; i < (int)data_len; i++) {
  86057. sum = 0;
  86058. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86059. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86060. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86061. }
  86062. }
  86063. else { /* order == 1 */
  86064. for(i = 0; i < (int)data_len; i++)
  86065. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86066. }
  86067. }
  86068. }
  86069. }
  86070. else { /* order > 12 */
  86071. for(i = 0; i < (int)data_len; i++) {
  86072. sum = 0;
  86073. switch(order) {
  86074. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86075. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86076. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86077. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86078. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86079. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86080. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86081. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86082. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86083. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86084. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86085. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86086. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86087. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86088. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86089. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86090. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86091. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86092. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86093. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86094. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86095. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86096. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86097. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86098. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86099. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86100. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86101. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86102. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86103. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86104. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86105. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86106. }
  86107. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86108. }
  86109. }
  86110. }
  86111. #endif
  86112. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86113. 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[])
  86114. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86115. {
  86116. FLAC__int64 sumo;
  86117. unsigned i, j;
  86118. FLAC__int32 sum;
  86119. const FLAC__int32 *r = residual, *history;
  86120. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86121. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86122. for(i=0;i<order;i++)
  86123. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86124. fprintf(stderr,"\n");
  86125. #endif
  86126. FLAC__ASSERT(order > 0);
  86127. for(i = 0; i < data_len; i++) {
  86128. sumo = 0;
  86129. sum = 0;
  86130. history = data;
  86131. for(j = 0; j < order; j++) {
  86132. sum += qlp_coeff[j] * (*(--history));
  86133. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86134. #if defined _MSC_VER
  86135. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86136. 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);
  86137. #else
  86138. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86139. 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);
  86140. #endif
  86141. }
  86142. *(data++) = *(r++) + (sum >> lp_quantization);
  86143. }
  86144. }
  86145. #else /* fully unrolled version for normal use */
  86146. {
  86147. int i;
  86148. FLAC__int32 sum;
  86149. FLAC__ASSERT(order > 0);
  86150. FLAC__ASSERT(order <= 32);
  86151. if(order <= 12) {
  86152. if(order > 8) {
  86153. if(order > 10) {
  86154. if(order == 12) {
  86155. for(i = 0; i < (int)data_len; i++) {
  86156. sum = 0;
  86157. sum += qlp_coeff[11] * data[i-12];
  86158. sum += qlp_coeff[10] * data[i-11];
  86159. sum += qlp_coeff[9] * data[i-10];
  86160. sum += qlp_coeff[8] * data[i-9];
  86161. sum += qlp_coeff[7] * data[i-8];
  86162. sum += qlp_coeff[6] * data[i-7];
  86163. sum += qlp_coeff[5] * data[i-6];
  86164. sum += qlp_coeff[4] * data[i-5];
  86165. sum += qlp_coeff[3] * data[i-4];
  86166. sum += qlp_coeff[2] * data[i-3];
  86167. sum += qlp_coeff[1] * data[i-2];
  86168. sum += qlp_coeff[0] * data[i-1];
  86169. data[i] = residual[i] + (sum >> lp_quantization);
  86170. }
  86171. }
  86172. else { /* order == 11 */
  86173. for(i = 0; i < (int)data_len; i++) {
  86174. sum = 0;
  86175. sum += qlp_coeff[10] * data[i-11];
  86176. sum += qlp_coeff[9] * data[i-10];
  86177. sum += qlp_coeff[8] * data[i-9];
  86178. sum += qlp_coeff[7] * data[i-8];
  86179. sum += qlp_coeff[6] * data[i-7];
  86180. sum += qlp_coeff[5] * data[i-6];
  86181. sum += qlp_coeff[4] * data[i-5];
  86182. sum += qlp_coeff[3] * data[i-4];
  86183. sum += qlp_coeff[2] * data[i-3];
  86184. sum += qlp_coeff[1] * data[i-2];
  86185. sum += qlp_coeff[0] * data[i-1];
  86186. data[i] = residual[i] + (sum >> lp_quantization);
  86187. }
  86188. }
  86189. }
  86190. else {
  86191. if(order == 10) {
  86192. for(i = 0; i < (int)data_len; i++) {
  86193. sum = 0;
  86194. sum += qlp_coeff[9] * data[i-10];
  86195. sum += qlp_coeff[8] * data[i-9];
  86196. sum += qlp_coeff[7] * data[i-8];
  86197. sum += qlp_coeff[6] * data[i-7];
  86198. sum += qlp_coeff[5] * data[i-6];
  86199. sum += qlp_coeff[4] * data[i-5];
  86200. sum += qlp_coeff[3] * data[i-4];
  86201. sum += qlp_coeff[2] * data[i-3];
  86202. sum += qlp_coeff[1] * data[i-2];
  86203. sum += qlp_coeff[0] * data[i-1];
  86204. data[i] = residual[i] + (sum >> lp_quantization);
  86205. }
  86206. }
  86207. else { /* order == 9 */
  86208. for(i = 0; i < (int)data_len; i++) {
  86209. sum = 0;
  86210. sum += qlp_coeff[8] * data[i-9];
  86211. sum += qlp_coeff[7] * data[i-8];
  86212. sum += qlp_coeff[6] * data[i-7];
  86213. sum += qlp_coeff[5] * data[i-6];
  86214. sum += qlp_coeff[4] * data[i-5];
  86215. sum += qlp_coeff[3] * data[i-4];
  86216. sum += qlp_coeff[2] * data[i-3];
  86217. sum += qlp_coeff[1] * data[i-2];
  86218. sum += qlp_coeff[0] * data[i-1];
  86219. data[i] = residual[i] + (sum >> lp_quantization);
  86220. }
  86221. }
  86222. }
  86223. }
  86224. else if(order > 4) {
  86225. if(order > 6) {
  86226. if(order == 8) {
  86227. for(i = 0; i < (int)data_len; i++) {
  86228. sum = 0;
  86229. sum += qlp_coeff[7] * data[i-8];
  86230. sum += qlp_coeff[6] * data[i-7];
  86231. sum += qlp_coeff[5] * data[i-6];
  86232. sum += qlp_coeff[4] * data[i-5];
  86233. sum += qlp_coeff[3] * data[i-4];
  86234. sum += qlp_coeff[2] * data[i-3];
  86235. sum += qlp_coeff[1] * data[i-2];
  86236. sum += qlp_coeff[0] * data[i-1];
  86237. data[i] = residual[i] + (sum >> lp_quantization);
  86238. }
  86239. }
  86240. else { /* order == 7 */
  86241. for(i = 0; i < (int)data_len; i++) {
  86242. sum = 0;
  86243. sum += qlp_coeff[6] * data[i-7];
  86244. sum += qlp_coeff[5] * data[i-6];
  86245. sum += qlp_coeff[4] * data[i-5];
  86246. sum += qlp_coeff[3] * data[i-4];
  86247. sum += qlp_coeff[2] * data[i-3];
  86248. sum += qlp_coeff[1] * data[i-2];
  86249. sum += qlp_coeff[0] * data[i-1];
  86250. data[i] = residual[i] + (sum >> lp_quantization);
  86251. }
  86252. }
  86253. }
  86254. else {
  86255. if(order == 6) {
  86256. for(i = 0; i < (int)data_len; i++) {
  86257. sum = 0;
  86258. sum += qlp_coeff[5] * data[i-6];
  86259. sum += qlp_coeff[4] * data[i-5];
  86260. sum += qlp_coeff[3] * data[i-4];
  86261. sum += qlp_coeff[2] * data[i-3];
  86262. sum += qlp_coeff[1] * data[i-2];
  86263. sum += qlp_coeff[0] * data[i-1];
  86264. data[i] = residual[i] + (sum >> lp_quantization);
  86265. }
  86266. }
  86267. else { /* order == 5 */
  86268. for(i = 0; i < (int)data_len; i++) {
  86269. sum = 0;
  86270. sum += qlp_coeff[4] * data[i-5];
  86271. sum += qlp_coeff[3] * data[i-4];
  86272. sum += qlp_coeff[2] * data[i-3];
  86273. sum += qlp_coeff[1] * data[i-2];
  86274. sum += qlp_coeff[0] * data[i-1];
  86275. data[i] = residual[i] + (sum >> lp_quantization);
  86276. }
  86277. }
  86278. }
  86279. }
  86280. else {
  86281. if(order > 2) {
  86282. if(order == 4) {
  86283. for(i = 0; i < (int)data_len; i++) {
  86284. sum = 0;
  86285. sum += qlp_coeff[3] * data[i-4];
  86286. sum += qlp_coeff[2] * data[i-3];
  86287. sum += qlp_coeff[1] * data[i-2];
  86288. sum += qlp_coeff[0] * data[i-1];
  86289. data[i] = residual[i] + (sum >> lp_quantization);
  86290. }
  86291. }
  86292. else { /* order == 3 */
  86293. for(i = 0; i < (int)data_len; i++) {
  86294. sum = 0;
  86295. sum += qlp_coeff[2] * data[i-3];
  86296. sum += qlp_coeff[1] * data[i-2];
  86297. sum += qlp_coeff[0] * data[i-1];
  86298. data[i] = residual[i] + (sum >> lp_quantization);
  86299. }
  86300. }
  86301. }
  86302. else {
  86303. if(order == 2) {
  86304. for(i = 0; i < (int)data_len; i++) {
  86305. sum = 0;
  86306. sum += qlp_coeff[1] * data[i-2];
  86307. sum += qlp_coeff[0] * data[i-1];
  86308. data[i] = residual[i] + (sum >> lp_quantization);
  86309. }
  86310. }
  86311. else { /* order == 1 */
  86312. for(i = 0; i < (int)data_len; i++)
  86313. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86314. }
  86315. }
  86316. }
  86317. }
  86318. else { /* order > 12 */
  86319. for(i = 0; i < (int)data_len; i++) {
  86320. sum = 0;
  86321. switch(order) {
  86322. case 32: sum += qlp_coeff[31] * data[i-32];
  86323. case 31: sum += qlp_coeff[30] * data[i-31];
  86324. case 30: sum += qlp_coeff[29] * data[i-30];
  86325. case 29: sum += qlp_coeff[28] * data[i-29];
  86326. case 28: sum += qlp_coeff[27] * data[i-28];
  86327. case 27: sum += qlp_coeff[26] * data[i-27];
  86328. case 26: sum += qlp_coeff[25] * data[i-26];
  86329. case 25: sum += qlp_coeff[24] * data[i-25];
  86330. case 24: sum += qlp_coeff[23] * data[i-24];
  86331. case 23: sum += qlp_coeff[22] * data[i-23];
  86332. case 22: sum += qlp_coeff[21] * data[i-22];
  86333. case 21: sum += qlp_coeff[20] * data[i-21];
  86334. case 20: sum += qlp_coeff[19] * data[i-20];
  86335. case 19: sum += qlp_coeff[18] * data[i-19];
  86336. case 18: sum += qlp_coeff[17] * data[i-18];
  86337. case 17: sum += qlp_coeff[16] * data[i-17];
  86338. case 16: sum += qlp_coeff[15] * data[i-16];
  86339. case 15: sum += qlp_coeff[14] * data[i-15];
  86340. case 14: sum += qlp_coeff[13] * data[i-14];
  86341. case 13: sum += qlp_coeff[12] * data[i-13];
  86342. sum += qlp_coeff[11] * data[i-12];
  86343. sum += qlp_coeff[10] * data[i-11];
  86344. sum += qlp_coeff[ 9] * data[i-10];
  86345. sum += qlp_coeff[ 8] * data[i- 9];
  86346. sum += qlp_coeff[ 7] * data[i- 8];
  86347. sum += qlp_coeff[ 6] * data[i- 7];
  86348. sum += qlp_coeff[ 5] * data[i- 6];
  86349. sum += qlp_coeff[ 4] * data[i- 5];
  86350. sum += qlp_coeff[ 3] * data[i- 4];
  86351. sum += qlp_coeff[ 2] * data[i- 3];
  86352. sum += qlp_coeff[ 1] * data[i- 2];
  86353. sum += qlp_coeff[ 0] * data[i- 1];
  86354. }
  86355. data[i] = residual[i] + (sum >> lp_quantization);
  86356. }
  86357. }
  86358. }
  86359. #endif
  86360. 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[])
  86361. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86362. {
  86363. unsigned i, j;
  86364. FLAC__int64 sum;
  86365. const FLAC__int32 *r = residual, *history;
  86366. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86367. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86368. for(i=0;i<order;i++)
  86369. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86370. fprintf(stderr,"\n");
  86371. #endif
  86372. FLAC__ASSERT(order > 0);
  86373. for(i = 0; i < data_len; i++) {
  86374. sum = 0;
  86375. history = data;
  86376. for(j = 0; j < order; j++)
  86377. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86378. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86379. #ifdef _MSC_VER
  86380. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86381. #else
  86382. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86383. #endif
  86384. break;
  86385. }
  86386. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86387. #ifdef _MSC_VER
  86388. 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));
  86389. #else
  86390. 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)));
  86391. #endif
  86392. break;
  86393. }
  86394. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86395. }
  86396. }
  86397. #else /* fully unrolled version for normal use */
  86398. {
  86399. int i;
  86400. FLAC__int64 sum;
  86401. FLAC__ASSERT(order > 0);
  86402. FLAC__ASSERT(order <= 32);
  86403. if(order <= 12) {
  86404. if(order > 8) {
  86405. if(order > 10) {
  86406. if(order == 12) {
  86407. for(i = 0; i < (int)data_len; i++) {
  86408. sum = 0;
  86409. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86410. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86411. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86412. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86413. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86414. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86415. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86416. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86417. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86418. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86419. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86420. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86421. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86422. }
  86423. }
  86424. else { /* order == 11 */
  86425. for(i = 0; i < (int)data_len; i++) {
  86426. sum = 0;
  86427. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86428. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86429. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86430. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86431. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86432. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86433. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86434. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86435. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86436. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86437. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86438. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86439. }
  86440. }
  86441. }
  86442. else {
  86443. if(order == 10) {
  86444. for(i = 0; i < (int)data_len; i++) {
  86445. sum = 0;
  86446. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86447. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86448. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86449. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86450. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86451. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86452. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86453. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86454. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86455. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86456. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86457. }
  86458. }
  86459. else { /* order == 9 */
  86460. for(i = 0; i < (int)data_len; i++) {
  86461. sum = 0;
  86462. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86463. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86464. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86465. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86466. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86467. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86468. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86469. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86470. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86471. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86472. }
  86473. }
  86474. }
  86475. }
  86476. else if(order > 4) {
  86477. if(order > 6) {
  86478. if(order == 8) {
  86479. for(i = 0; i < (int)data_len; i++) {
  86480. sum = 0;
  86481. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86482. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86483. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86484. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86485. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86486. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86487. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86488. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86489. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86490. }
  86491. }
  86492. else { /* order == 7 */
  86493. for(i = 0; i < (int)data_len; i++) {
  86494. sum = 0;
  86495. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86496. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86497. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86498. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86499. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86500. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86501. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86502. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86503. }
  86504. }
  86505. }
  86506. else {
  86507. if(order == 6) {
  86508. for(i = 0; i < (int)data_len; i++) {
  86509. sum = 0;
  86510. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86511. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86512. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86513. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86514. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86515. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86516. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86517. }
  86518. }
  86519. else { /* order == 5 */
  86520. for(i = 0; i < (int)data_len; i++) {
  86521. sum = 0;
  86522. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86523. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86524. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86525. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86526. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86527. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86528. }
  86529. }
  86530. }
  86531. }
  86532. else {
  86533. if(order > 2) {
  86534. if(order == 4) {
  86535. for(i = 0; i < (int)data_len; i++) {
  86536. sum = 0;
  86537. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86538. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86539. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86540. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86541. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86542. }
  86543. }
  86544. else { /* order == 3 */
  86545. for(i = 0; i < (int)data_len; i++) {
  86546. sum = 0;
  86547. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86548. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86549. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86550. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86551. }
  86552. }
  86553. }
  86554. else {
  86555. if(order == 2) {
  86556. for(i = 0; i < (int)data_len; i++) {
  86557. sum = 0;
  86558. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86559. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86560. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86561. }
  86562. }
  86563. else { /* order == 1 */
  86564. for(i = 0; i < (int)data_len; i++)
  86565. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86566. }
  86567. }
  86568. }
  86569. }
  86570. else { /* order > 12 */
  86571. for(i = 0; i < (int)data_len; i++) {
  86572. sum = 0;
  86573. switch(order) {
  86574. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86575. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86576. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86577. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86578. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86579. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86580. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86581. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86582. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86583. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86584. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86585. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86586. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86587. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86588. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86589. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86590. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86591. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86592. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86593. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86594. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86595. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86596. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86597. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86598. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86599. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86600. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86601. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86602. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86603. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86604. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86605. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86606. }
  86607. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86608. }
  86609. }
  86610. }
  86611. #endif
  86612. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86613. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86614. {
  86615. FLAC__double error_scale;
  86616. FLAC__ASSERT(total_samples > 0);
  86617. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86618. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86619. }
  86620. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86621. {
  86622. if(lpc_error > 0.0) {
  86623. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86624. if(bps >= 0.0)
  86625. return bps;
  86626. else
  86627. return 0.0;
  86628. }
  86629. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86630. return 1e32;
  86631. }
  86632. else {
  86633. return 0.0;
  86634. }
  86635. }
  86636. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86637. {
  86638. 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 */
  86639. FLAC__double bits, best_bits, error_scale;
  86640. FLAC__ASSERT(max_order > 0);
  86641. FLAC__ASSERT(total_samples > 0);
  86642. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86643. best_index = 0;
  86644. best_bits = (unsigned)(-1);
  86645. for(index = 0, order = 1; index < max_order; index++, order++) {
  86646. 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);
  86647. if(bits < best_bits) {
  86648. best_index = index;
  86649. best_bits = bits;
  86650. }
  86651. }
  86652. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86653. }
  86654. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86655. #endif
  86656. /*** End of inlined file: lpc_flac.c ***/
  86657. /*** Start of inlined file: md5.c ***/
  86658. /*** Start of inlined file: juce_FlacHeader.h ***/
  86659. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86660. // tasks..
  86661. #define VERSION "1.2.1"
  86662. #define FLAC__NO_DLL 1
  86663. #if JUCE_MSVC
  86664. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86665. #endif
  86666. #if JUCE_MAC
  86667. #define FLAC__SYS_DARWIN 1
  86668. #endif
  86669. /*** End of inlined file: juce_FlacHeader.h ***/
  86670. #if JUCE_USE_FLAC
  86671. #if HAVE_CONFIG_H
  86672. # include <config.h>
  86673. #endif
  86674. #include <stdlib.h> /* for malloc() */
  86675. #include <string.h> /* for memcpy() */
  86676. /*** Start of inlined file: md5.h ***/
  86677. #ifndef FLAC__PRIVATE__MD5_H
  86678. #define FLAC__PRIVATE__MD5_H
  86679. typedef struct {
  86680. FLAC__uint32 in[16];
  86681. FLAC__uint32 buf[4];
  86682. FLAC__uint32 bytes[2];
  86683. FLAC__byte *internal_buf;
  86684. size_t capacity;
  86685. } FLAC__MD5Context;
  86686. void FLAC__MD5Init(FLAC__MD5Context *context);
  86687. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86688. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86689. #endif
  86690. /*** End of inlined file: md5.h ***/
  86691. #ifndef FLaC__INLINE
  86692. #define FLaC__INLINE
  86693. #endif
  86694. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86695. #define F2(x, y, z) F1(z, x, y)
  86696. #define F3(x, y, z) (x ^ y ^ z)
  86697. #define F4(x, y, z) (y ^ (x | ~z))
  86698. #define MD5STEP(f,w,x,y,z,in,s) \
  86699. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86700. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86701. {
  86702. register FLAC__uint32 a, b, c, d;
  86703. a = buf[0];
  86704. b = buf[1];
  86705. c = buf[2];
  86706. d = buf[3];
  86707. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86708. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86709. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86710. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86711. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86712. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86713. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86714. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86715. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86716. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86717. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86718. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86719. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86720. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86721. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86722. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86723. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86724. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86725. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86726. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86727. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86728. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86729. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86730. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86731. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86732. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86733. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86734. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86735. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86736. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86737. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86738. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86739. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86740. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86741. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86742. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86743. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86744. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86745. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86746. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86747. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86748. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86749. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86750. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86751. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86752. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86753. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86754. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86755. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86756. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86757. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86758. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86759. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86760. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86761. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86762. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86763. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86764. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86765. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86766. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86767. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86768. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86769. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86770. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86771. buf[0] += a;
  86772. buf[1] += b;
  86773. buf[2] += c;
  86774. buf[3] += d;
  86775. }
  86776. #if WORDS_BIGENDIAN
  86777. //@@@@@@ OPT: use bswap/intrinsics
  86778. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86779. {
  86780. register FLAC__uint32 x;
  86781. do {
  86782. x = *buf;
  86783. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86784. *buf++ = (x >> 16) | (x << 16);
  86785. } while (--words);
  86786. }
  86787. static void byteSwapX16(FLAC__uint32 *buf)
  86788. {
  86789. register FLAC__uint32 x;
  86790. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86791. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86792. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86793. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86794. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86795. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86796. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86797. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86798. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86799. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86800. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86801. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86802. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86803. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86804. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86805. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86806. }
  86807. #else
  86808. #define byteSwap(buf, words)
  86809. #define byteSwapX16(buf)
  86810. #endif
  86811. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86812. {
  86813. FLAC__uint32 t;
  86814. t = ctx->bytes[0];
  86815. if ((ctx->bytes[0] = t + len) < t)
  86816. ctx->bytes[1]++; /* Carry from low to high */
  86817. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86818. if (t > len) {
  86819. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86820. return;
  86821. }
  86822. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86823. byteSwapX16(ctx->in);
  86824. FLAC__MD5Transform(ctx->buf, ctx->in);
  86825. buf += t;
  86826. len -= t;
  86827. while (len >= 64) {
  86828. memcpy(ctx->in, buf, 64);
  86829. byteSwapX16(ctx->in);
  86830. FLAC__MD5Transform(ctx->buf, ctx->in);
  86831. buf += 64;
  86832. len -= 64;
  86833. }
  86834. memcpy(ctx->in, buf, len);
  86835. }
  86836. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86837. {
  86838. ctx->buf[0] = 0x67452301;
  86839. ctx->buf[1] = 0xefcdab89;
  86840. ctx->buf[2] = 0x98badcfe;
  86841. ctx->buf[3] = 0x10325476;
  86842. ctx->bytes[0] = 0;
  86843. ctx->bytes[1] = 0;
  86844. ctx->internal_buf = 0;
  86845. ctx->capacity = 0;
  86846. }
  86847. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86848. {
  86849. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86850. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86851. *p++ = 0x80;
  86852. count = 56 - 1 - count;
  86853. if (count < 0) { /* Padding forces an extra block */
  86854. memset(p, 0, count + 8);
  86855. byteSwapX16(ctx->in);
  86856. FLAC__MD5Transform(ctx->buf, ctx->in);
  86857. p = (FLAC__byte *)ctx->in;
  86858. count = 56;
  86859. }
  86860. memset(p, 0, count);
  86861. byteSwap(ctx->in, 14);
  86862. ctx->in[14] = ctx->bytes[0] << 3;
  86863. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86864. FLAC__MD5Transform(ctx->buf, ctx->in);
  86865. byteSwap(ctx->buf, 4);
  86866. memcpy(digest, ctx->buf, 16);
  86867. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86868. if(0 != ctx->internal_buf) {
  86869. free(ctx->internal_buf);
  86870. ctx->internal_buf = 0;
  86871. ctx->capacity = 0;
  86872. }
  86873. }
  86874. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86875. {
  86876. unsigned channel, sample;
  86877. register FLAC__int32 a_word;
  86878. register FLAC__byte *buf_ = buf;
  86879. #if WORDS_BIGENDIAN
  86880. #else
  86881. if(channels == 2 && bytes_per_sample == 2) {
  86882. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86883. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86884. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86885. *buf1_ = (FLAC__int16)signal[1][sample];
  86886. }
  86887. else if(channels == 1 && bytes_per_sample == 2) {
  86888. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86889. for(sample = 0; sample < samples; sample++)
  86890. *buf1_++ = (FLAC__int16)signal[0][sample];
  86891. }
  86892. else
  86893. #endif
  86894. if(bytes_per_sample == 2) {
  86895. if(channels == 2) {
  86896. for(sample = 0; sample < samples; sample++) {
  86897. a_word = signal[0][sample];
  86898. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86899. *buf_++ = (FLAC__byte)a_word;
  86900. a_word = signal[1][sample];
  86901. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86902. *buf_++ = (FLAC__byte)a_word;
  86903. }
  86904. }
  86905. else if(channels == 1) {
  86906. for(sample = 0; sample < samples; sample++) {
  86907. a_word = signal[0][sample];
  86908. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86909. *buf_++ = (FLAC__byte)a_word;
  86910. }
  86911. }
  86912. else {
  86913. for(sample = 0; sample < samples; sample++) {
  86914. for(channel = 0; channel < channels; channel++) {
  86915. a_word = signal[channel][sample];
  86916. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86917. *buf_++ = (FLAC__byte)a_word;
  86918. }
  86919. }
  86920. }
  86921. }
  86922. else if(bytes_per_sample == 3) {
  86923. if(channels == 2) {
  86924. for(sample = 0; sample < samples; sample++) {
  86925. a_word = signal[0][sample];
  86926. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86927. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86928. *buf_++ = (FLAC__byte)a_word;
  86929. a_word = signal[1][sample];
  86930. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86931. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86932. *buf_++ = (FLAC__byte)a_word;
  86933. }
  86934. }
  86935. else if(channels == 1) {
  86936. for(sample = 0; sample < samples; sample++) {
  86937. a_word = signal[0][sample];
  86938. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86939. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86940. *buf_++ = (FLAC__byte)a_word;
  86941. }
  86942. }
  86943. else {
  86944. for(sample = 0; sample < samples; sample++) {
  86945. for(channel = 0; channel < channels; channel++) {
  86946. a_word = signal[channel][sample];
  86947. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86948. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86949. *buf_++ = (FLAC__byte)a_word;
  86950. }
  86951. }
  86952. }
  86953. }
  86954. else if(bytes_per_sample == 1) {
  86955. if(channels == 2) {
  86956. for(sample = 0; sample < samples; sample++) {
  86957. a_word = signal[0][sample];
  86958. *buf_++ = (FLAC__byte)a_word;
  86959. a_word = signal[1][sample];
  86960. *buf_++ = (FLAC__byte)a_word;
  86961. }
  86962. }
  86963. else if(channels == 1) {
  86964. for(sample = 0; sample < samples; sample++) {
  86965. a_word = signal[0][sample];
  86966. *buf_++ = (FLAC__byte)a_word;
  86967. }
  86968. }
  86969. else {
  86970. for(sample = 0; sample < samples; sample++) {
  86971. for(channel = 0; channel < channels; channel++) {
  86972. a_word = signal[channel][sample];
  86973. *buf_++ = (FLAC__byte)a_word;
  86974. }
  86975. }
  86976. }
  86977. }
  86978. else { /* bytes_per_sample == 4, maybe optimize more later */
  86979. for(sample = 0; sample < samples; sample++) {
  86980. for(channel = 0; channel < channels; channel++) {
  86981. a_word = signal[channel][sample];
  86982. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86983. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86984. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86985. *buf_++ = (FLAC__byte)a_word;
  86986. }
  86987. }
  86988. }
  86989. }
  86990. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86991. {
  86992. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86993. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86994. return false;
  86995. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86996. return false;
  86997. if(ctx->capacity < bytes_needed) {
  86998. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86999. if(0 == tmp) {
  87000. free(ctx->internal_buf);
  87001. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  87002. return false;
  87003. }
  87004. ctx->internal_buf = tmp;
  87005. ctx->capacity = bytes_needed;
  87006. }
  87007. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  87008. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  87009. return true;
  87010. }
  87011. #endif
  87012. /*** End of inlined file: md5.c ***/
  87013. /*** Start of inlined file: memory.c ***/
  87014. /*** Start of inlined file: juce_FlacHeader.h ***/
  87015. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87016. // tasks..
  87017. #define VERSION "1.2.1"
  87018. #define FLAC__NO_DLL 1
  87019. #if JUCE_MSVC
  87020. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87021. #endif
  87022. #if JUCE_MAC
  87023. #define FLAC__SYS_DARWIN 1
  87024. #endif
  87025. /*** End of inlined file: juce_FlacHeader.h ***/
  87026. #if JUCE_USE_FLAC
  87027. #if HAVE_CONFIG_H
  87028. # include <config.h>
  87029. #endif
  87030. /*** Start of inlined file: memory.h ***/
  87031. #ifndef FLAC__PRIVATE__MEMORY_H
  87032. #define FLAC__PRIVATE__MEMORY_H
  87033. #ifdef HAVE_CONFIG_H
  87034. #include <config.h>
  87035. #endif
  87036. #include <stdlib.h> /* for size_t */
  87037. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  87038. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  87039. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  87040. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  87041. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  87042. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87043. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  87044. #endif
  87045. #endif
  87046. /*** End of inlined file: memory.h ***/
  87047. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  87048. {
  87049. void *x;
  87050. FLAC__ASSERT(0 != aligned_address);
  87051. #ifdef FLAC__ALIGN_MALLOC_DATA
  87052. x = safe_malloc_add_2op_(bytes, /*+*/31);
  87053. #ifdef SIZEOF_VOIDP
  87054. #if SIZEOF_VOIDP == 4
  87055. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87056. #elif SIZEOF_VOIDP == 8
  87057. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87058. #else
  87059. # error Unsupported sizeof(void*)
  87060. #endif
  87061. #else
  87062. if(sizeof(void*) == sizeof(unsigned))
  87063. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87064. else if(sizeof(void*) == sizeof(FLAC__uint64))
  87065. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87066. else
  87067. return 0;
  87068. #endif
  87069. #else
  87070. x = safe_malloc_(bytes);
  87071. *aligned_address = x;
  87072. #endif
  87073. return x;
  87074. }
  87075. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  87076. {
  87077. FLAC__int32 *pu; /* unaligned pointer */
  87078. union { /* union needed to comply with C99 pointer aliasing rules */
  87079. FLAC__int32 *pa; /* aligned pointer */
  87080. void *pv; /* aligned pointer alias */
  87081. } u;
  87082. FLAC__ASSERT(elements > 0);
  87083. FLAC__ASSERT(0 != unaligned_pointer);
  87084. FLAC__ASSERT(0 != aligned_pointer);
  87085. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87086. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  87087. if(0 == pu) {
  87088. return false;
  87089. }
  87090. else {
  87091. if(*unaligned_pointer != 0)
  87092. free(*unaligned_pointer);
  87093. *unaligned_pointer = pu;
  87094. *aligned_pointer = u.pa;
  87095. return true;
  87096. }
  87097. }
  87098. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  87099. {
  87100. FLAC__uint32 *pu; /* unaligned pointer */
  87101. union { /* union needed to comply with C99 pointer aliasing rules */
  87102. FLAC__uint32 *pa; /* aligned pointer */
  87103. void *pv; /* aligned pointer alias */
  87104. } u;
  87105. FLAC__ASSERT(elements > 0);
  87106. FLAC__ASSERT(0 != unaligned_pointer);
  87107. FLAC__ASSERT(0 != aligned_pointer);
  87108. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87109. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87110. if(0 == pu) {
  87111. return false;
  87112. }
  87113. else {
  87114. if(*unaligned_pointer != 0)
  87115. free(*unaligned_pointer);
  87116. *unaligned_pointer = pu;
  87117. *aligned_pointer = u.pa;
  87118. return true;
  87119. }
  87120. }
  87121. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  87122. {
  87123. FLAC__uint64 *pu; /* unaligned pointer */
  87124. union { /* union needed to comply with C99 pointer aliasing rules */
  87125. FLAC__uint64 *pa; /* aligned pointer */
  87126. void *pv; /* aligned pointer alias */
  87127. } u;
  87128. FLAC__ASSERT(elements > 0);
  87129. FLAC__ASSERT(0 != unaligned_pointer);
  87130. FLAC__ASSERT(0 != aligned_pointer);
  87131. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87132. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87133. if(0 == pu) {
  87134. return false;
  87135. }
  87136. else {
  87137. if(*unaligned_pointer != 0)
  87138. free(*unaligned_pointer);
  87139. *unaligned_pointer = pu;
  87140. *aligned_pointer = u.pa;
  87141. return true;
  87142. }
  87143. }
  87144. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  87145. {
  87146. unsigned *pu; /* unaligned pointer */
  87147. union { /* union needed to comply with C99 pointer aliasing rules */
  87148. unsigned *pa; /* aligned pointer */
  87149. void *pv; /* aligned pointer alias */
  87150. } u;
  87151. FLAC__ASSERT(elements > 0);
  87152. FLAC__ASSERT(0 != unaligned_pointer);
  87153. FLAC__ASSERT(0 != aligned_pointer);
  87154. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87155. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87156. if(0 == pu) {
  87157. return false;
  87158. }
  87159. else {
  87160. if(*unaligned_pointer != 0)
  87161. free(*unaligned_pointer);
  87162. *unaligned_pointer = pu;
  87163. *aligned_pointer = u.pa;
  87164. return true;
  87165. }
  87166. }
  87167. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87168. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  87169. {
  87170. FLAC__real *pu; /* unaligned pointer */
  87171. union { /* union needed to comply with C99 pointer aliasing rules */
  87172. FLAC__real *pa; /* aligned pointer */
  87173. void *pv; /* aligned pointer alias */
  87174. } u;
  87175. FLAC__ASSERT(elements > 0);
  87176. FLAC__ASSERT(0 != unaligned_pointer);
  87177. FLAC__ASSERT(0 != aligned_pointer);
  87178. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87179. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87180. if(0 == pu) {
  87181. return false;
  87182. }
  87183. else {
  87184. if(*unaligned_pointer != 0)
  87185. free(*unaligned_pointer);
  87186. *unaligned_pointer = pu;
  87187. *aligned_pointer = u.pa;
  87188. return true;
  87189. }
  87190. }
  87191. #endif
  87192. #endif
  87193. /*** End of inlined file: memory.c ***/
  87194. /*** Start of inlined file: stream_decoder.c ***/
  87195. /*** Start of inlined file: juce_FlacHeader.h ***/
  87196. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87197. // tasks..
  87198. #define VERSION "1.2.1"
  87199. #define FLAC__NO_DLL 1
  87200. #if JUCE_MSVC
  87201. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87202. #endif
  87203. #if JUCE_MAC
  87204. #define FLAC__SYS_DARWIN 1
  87205. #endif
  87206. /*** End of inlined file: juce_FlacHeader.h ***/
  87207. #if JUCE_USE_FLAC
  87208. #if HAVE_CONFIG_H
  87209. # include <config.h>
  87210. #endif
  87211. #if defined _MSC_VER || defined __MINGW32__
  87212. #include <io.h> /* for _setmode() */
  87213. #include <fcntl.h> /* for _O_BINARY */
  87214. #endif
  87215. #if defined __CYGWIN__ || defined __EMX__
  87216. #include <io.h> /* for setmode(), O_BINARY */
  87217. #include <fcntl.h> /* for _O_BINARY */
  87218. #endif
  87219. #include <stdio.h>
  87220. #include <stdlib.h> /* for malloc() */
  87221. #include <string.h> /* for memset/memcpy() */
  87222. #include <sys/stat.h> /* for stat() */
  87223. #include <sys/types.h> /* for off_t */
  87224. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  87225. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  87226. #define fseeko fseek
  87227. #define ftello ftell
  87228. #endif
  87229. #endif
  87230. /*** Start of inlined file: stream_decoder.h ***/
  87231. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  87232. #define FLAC__PROTECTED__STREAM_DECODER_H
  87233. #if FLAC__HAS_OGG
  87234. #include "include/private/ogg_decoder_aspect.h"
  87235. #endif
  87236. typedef struct FLAC__StreamDecoderProtected {
  87237. FLAC__StreamDecoderState state;
  87238. unsigned channels;
  87239. FLAC__ChannelAssignment channel_assignment;
  87240. unsigned bits_per_sample;
  87241. unsigned sample_rate; /* in Hz */
  87242. unsigned blocksize; /* in samples (per channel) */
  87243. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  87244. #if FLAC__HAS_OGG
  87245. FLAC__OggDecoderAspect ogg_decoder_aspect;
  87246. #endif
  87247. } FLAC__StreamDecoderProtected;
  87248. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  87249. #endif
  87250. /*** End of inlined file: stream_decoder.h ***/
  87251. #ifdef max
  87252. #undef max
  87253. #endif
  87254. #define max(a,b) ((a)>(b)?(a):(b))
  87255. #ifdef _MSC_VER
  87256. #define FLAC__U64L(x) x
  87257. #else
  87258. #define FLAC__U64L(x) x##LLU
  87259. #endif
  87260. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  87261. #if FLAC__HAS_OGG
  87262. 1
  87263. #else
  87264. 0
  87265. #endif
  87266. ;
  87267. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  87268. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  87269. static FILE *get_binary_stdin_(void);
  87270. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  87271. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  87272. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  87273. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  87274. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87275. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87276. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  87277. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  87278. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  87279. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  87280. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  87281. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  87282. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  87283. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87284. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87285. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87286. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87287. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87288. 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);
  87289. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  87290. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  87291. #if FLAC__HAS_OGG
  87292. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  87293. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87294. #endif
  87295. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  87296. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  87297. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87298. #if FLAC__HAS_OGG
  87299. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87300. #endif
  87301. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87302. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  87303. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  87304. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  87305. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  87306. typedef struct FLAC__StreamDecoderPrivate {
  87307. #if FLAC__HAS_OGG
  87308. FLAC__bool is_ogg;
  87309. #endif
  87310. FLAC__StreamDecoderReadCallback read_callback;
  87311. FLAC__StreamDecoderSeekCallback seek_callback;
  87312. FLAC__StreamDecoderTellCallback tell_callback;
  87313. FLAC__StreamDecoderLengthCallback length_callback;
  87314. FLAC__StreamDecoderEofCallback eof_callback;
  87315. FLAC__StreamDecoderWriteCallback write_callback;
  87316. FLAC__StreamDecoderMetadataCallback metadata_callback;
  87317. FLAC__StreamDecoderErrorCallback error_callback;
  87318. 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[]);
  87319. 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[]);
  87320. 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[]);
  87321. 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[]);
  87322. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87323. void *client_data;
  87324. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87325. FLAC__BitReader *input;
  87326. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87327. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87328. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87329. unsigned output_capacity, output_channels;
  87330. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87331. FLAC__uint64 samples_decoded;
  87332. FLAC__bool has_stream_info, has_seek_table;
  87333. FLAC__StreamMetadata stream_info;
  87334. FLAC__StreamMetadata seek_table;
  87335. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87336. FLAC__byte *metadata_filter_ids;
  87337. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87338. FLAC__Frame frame;
  87339. FLAC__bool cached; /* true if there is a byte in lookahead */
  87340. FLAC__CPUInfo cpuinfo;
  87341. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87342. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87343. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87344. 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 */
  87345. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87346. FLAC__bool is_seeking;
  87347. FLAC__MD5Context md5context;
  87348. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87349. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87350. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87351. FLAC__uint64 target_sample;
  87352. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87353. #if FLAC__HAS_OGG
  87354. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87355. #endif
  87356. } FLAC__StreamDecoderPrivate;
  87357. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87358. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87359. "FLAC__STREAM_DECODER_READ_METADATA",
  87360. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87361. "FLAC__STREAM_DECODER_READ_FRAME",
  87362. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87363. "FLAC__STREAM_DECODER_OGG_ERROR",
  87364. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87365. "FLAC__STREAM_DECODER_ABORTED",
  87366. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87367. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87368. };
  87369. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87370. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87371. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87372. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87373. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87374. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87375. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87376. };
  87377. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87378. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87379. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87380. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87381. };
  87382. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87383. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87384. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87385. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87386. };
  87387. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87388. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87389. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87390. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87391. };
  87392. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87393. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87394. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87395. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87396. };
  87397. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87398. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87399. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87400. };
  87401. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87402. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87403. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87404. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87405. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87406. };
  87407. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87408. {
  87409. FLAC__StreamDecoder *decoder;
  87410. unsigned i;
  87411. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87412. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87413. if(decoder == 0) {
  87414. return 0;
  87415. }
  87416. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87417. if(decoder->protected_ == 0) {
  87418. free(decoder);
  87419. return 0;
  87420. }
  87421. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87422. if(decoder->private_ == 0) {
  87423. free(decoder->protected_);
  87424. free(decoder);
  87425. return 0;
  87426. }
  87427. decoder->private_->input = FLAC__bitreader_new();
  87428. if(decoder->private_->input == 0) {
  87429. free(decoder->private_);
  87430. free(decoder->protected_);
  87431. free(decoder);
  87432. return 0;
  87433. }
  87434. decoder->private_->metadata_filter_ids_capacity = 16;
  87435. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87436. FLAC__bitreader_delete(decoder->private_->input);
  87437. free(decoder->private_);
  87438. free(decoder->protected_);
  87439. free(decoder);
  87440. return 0;
  87441. }
  87442. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87443. decoder->private_->output[i] = 0;
  87444. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87445. }
  87446. decoder->private_->output_capacity = 0;
  87447. decoder->private_->output_channels = 0;
  87448. decoder->private_->has_seek_table = false;
  87449. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87450. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87451. decoder->private_->file = 0;
  87452. set_defaults_dec(decoder);
  87453. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87454. return decoder;
  87455. }
  87456. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87457. {
  87458. unsigned i;
  87459. FLAC__ASSERT(0 != decoder);
  87460. FLAC__ASSERT(0 != decoder->protected_);
  87461. FLAC__ASSERT(0 != decoder->private_);
  87462. FLAC__ASSERT(0 != decoder->private_->input);
  87463. (void)FLAC__stream_decoder_finish(decoder);
  87464. if(0 != decoder->private_->metadata_filter_ids)
  87465. free(decoder->private_->metadata_filter_ids);
  87466. FLAC__bitreader_delete(decoder->private_->input);
  87467. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87468. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87469. free(decoder->private_);
  87470. free(decoder->protected_);
  87471. free(decoder);
  87472. }
  87473. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87474. FLAC__StreamDecoder *decoder,
  87475. FLAC__StreamDecoderReadCallback read_callback,
  87476. FLAC__StreamDecoderSeekCallback seek_callback,
  87477. FLAC__StreamDecoderTellCallback tell_callback,
  87478. FLAC__StreamDecoderLengthCallback length_callback,
  87479. FLAC__StreamDecoderEofCallback eof_callback,
  87480. FLAC__StreamDecoderWriteCallback write_callback,
  87481. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87482. FLAC__StreamDecoderErrorCallback error_callback,
  87483. void *client_data,
  87484. FLAC__bool is_ogg
  87485. )
  87486. {
  87487. FLAC__ASSERT(0 != decoder);
  87488. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87489. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87490. #if !FLAC__HAS_OGG
  87491. if(is_ogg)
  87492. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87493. #endif
  87494. if(
  87495. 0 == read_callback ||
  87496. 0 == write_callback ||
  87497. 0 == error_callback ||
  87498. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87499. )
  87500. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87501. #if FLAC__HAS_OGG
  87502. decoder->private_->is_ogg = is_ogg;
  87503. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87504. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87505. #endif
  87506. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87507. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87508. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87509. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87510. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87511. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87512. #ifndef FLAC__NO_ASM
  87513. if(decoder->private_->cpuinfo.use_asm) {
  87514. #ifdef FLAC__CPU_IA32
  87515. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87516. #ifdef FLAC__HAS_NASM
  87517. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87518. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87519. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87520. #endif
  87521. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87522. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87523. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87524. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87525. }
  87526. else {
  87527. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87528. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87529. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87530. }
  87531. #endif
  87532. #elif defined FLAC__CPU_PPC
  87533. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87534. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87535. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87536. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87537. }
  87538. #endif
  87539. }
  87540. #endif
  87541. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87542. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87543. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87544. }
  87545. decoder->private_->read_callback = read_callback;
  87546. decoder->private_->seek_callback = seek_callback;
  87547. decoder->private_->tell_callback = tell_callback;
  87548. decoder->private_->length_callback = length_callback;
  87549. decoder->private_->eof_callback = eof_callback;
  87550. decoder->private_->write_callback = write_callback;
  87551. decoder->private_->metadata_callback = metadata_callback;
  87552. decoder->private_->error_callback = error_callback;
  87553. decoder->private_->client_data = client_data;
  87554. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87555. decoder->private_->samples_decoded = 0;
  87556. decoder->private_->has_stream_info = false;
  87557. decoder->private_->cached = false;
  87558. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87559. decoder->private_->is_seeking = false;
  87560. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87561. if(!FLAC__stream_decoder_reset(decoder)) {
  87562. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87563. }
  87564. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87565. }
  87566. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87567. FLAC__StreamDecoder *decoder,
  87568. FLAC__StreamDecoderReadCallback read_callback,
  87569. FLAC__StreamDecoderSeekCallback seek_callback,
  87570. FLAC__StreamDecoderTellCallback tell_callback,
  87571. FLAC__StreamDecoderLengthCallback length_callback,
  87572. FLAC__StreamDecoderEofCallback eof_callback,
  87573. FLAC__StreamDecoderWriteCallback write_callback,
  87574. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87575. FLAC__StreamDecoderErrorCallback error_callback,
  87576. void *client_data
  87577. )
  87578. {
  87579. return init_stream_internal_dec(
  87580. decoder,
  87581. read_callback,
  87582. seek_callback,
  87583. tell_callback,
  87584. length_callback,
  87585. eof_callback,
  87586. write_callback,
  87587. metadata_callback,
  87588. error_callback,
  87589. client_data,
  87590. false
  87591. );
  87592. }
  87593. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87594. FLAC__StreamDecoder *decoder,
  87595. FLAC__StreamDecoderReadCallback read_callback,
  87596. FLAC__StreamDecoderSeekCallback seek_callback,
  87597. FLAC__StreamDecoderTellCallback tell_callback,
  87598. FLAC__StreamDecoderLengthCallback length_callback,
  87599. FLAC__StreamDecoderEofCallback eof_callback,
  87600. FLAC__StreamDecoderWriteCallback write_callback,
  87601. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87602. FLAC__StreamDecoderErrorCallback error_callback,
  87603. void *client_data
  87604. )
  87605. {
  87606. return init_stream_internal_dec(
  87607. decoder,
  87608. read_callback,
  87609. seek_callback,
  87610. tell_callback,
  87611. length_callback,
  87612. eof_callback,
  87613. write_callback,
  87614. metadata_callback,
  87615. error_callback,
  87616. client_data,
  87617. true
  87618. );
  87619. }
  87620. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87621. FLAC__StreamDecoder *decoder,
  87622. FILE *file,
  87623. FLAC__StreamDecoderWriteCallback write_callback,
  87624. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87625. FLAC__StreamDecoderErrorCallback error_callback,
  87626. void *client_data,
  87627. FLAC__bool is_ogg
  87628. )
  87629. {
  87630. FLAC__ASSERT(0 != decoder);
  87631. FLAC__ASSERT(0 != file);
  87632. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87633. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87634. if(0 == write_callback || 0 == error_callback)
  87635. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87636. if(file == stdin)
  87637. file = get_binary_stdin_(); /* just to be safe */
  87638. decoder->private_->file = file;
  87639. return init_stream_internal_dec(
  87640. decoder,
  87641. file_read_callback_dec,
  87642. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87643. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87644. decoder->private_->file == stdin? 0: file_length_callback_,
  87645. file_eof_callback_,
  87646. write_callback,
  87647. metadata_callback,
  87648. error_callback,
  87649. client_data,
  87650. is_ogg
  87651. );
  87652. }
  87653. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87654. FLAC__StreamDecoder *decoder,
  87655. FILE *file,
  87656. FLAC__StreamDecoderWriteCallback write_callback,
  87657. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87658. FLAC__StreamDecoderErrorCallback error_callback,
  87659. void *client_data
  87660. )
  87661. {
  87662. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87663. }
  87664. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87665. FLAC__StreamDecoder *decoder,
  87666. FILE *file,
  87667. FLAC__StreamDecoderWriteCallback write_callback,
  87668. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87669. FLAC__StreamDecoderErrorCallback error_callback,
  87670. void *client_data
  87671. )
  87672. {
  87673. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87674. }
  87675. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87676. FLAC__StreamDecoder *decoder,
  87677. const char *filename,
  87678. FLAC__StreamDecoderWriteCallback write_callback,
  87679. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87680. FLAC__StreamDecoderErrorCallback error_callback,
  87681. void *client_data,
  87682. FLAC__bool is_ogg
  87683. )
  87684. {
  87685. FILE *file;
  87686. FLAC__ASSERT(0 != decoder);
  87687. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87688. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87689. if(0 == write_callback || 0 == error_callback)
  87690. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87691. file = filename? fopen(filename, "rb") : stdin;
  87692. if(0 == file)
  87693. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87694. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87695. }
  87696. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87697. FLAC__StreamDecoder *decoder,
  87698. const char *filename,
  87699. FLAC__StreamDecoderWriteCallback write_callback,
  87700. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87701. FLAC__StreamDecoderErrorCallback error_callback,
  87702. void *client_data
  87703. )
  87704. {
  87705. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87706. }
  87707. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87708. FLAC__StreamDecoder *decoder,
  87709. const char *filename,
  87710. FLAC__StreamDecoderWriteCallback write_callback,
  87711. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87712. FLAC__StreamDecoderErrorCallback error_callback,
  87713. void *client_data
  87714. )
  87715. {
  87716. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87717. }
  87718. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87719. {
  87720. FLAC__bool md5_failed = false;
  87721. unsigned i;
  87722. FLAC__ASSERT(0 != decoder);
  87723. FLAC__ASSERT(0 != decoder->private_);
  87724. FLAC__ASSERT(0 != decoder->protected_);
  87725. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87726. return true;
  87727. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87728. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87729. free(decoder->private_->seek_table.data.seek_table.points);
  87730. decoder->private_->seek_table.data.seek_table.points = 0;
  87731. decoder->private_->has_seek_table = false;
  87732. }
  87733. FLAC__bitreader_free(decoder->private_->input);
  87734. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87735. if(0 != decoder->private_->output[i]) {
  87736. free(decoder->private_->output[i]-4);
  87737. decoder->private_->output[i] = 0;
  87738. }
  87739. if(0 != decoder->private_->residual_unaligned[i]) {
  87740. free(decoder->private_->residual_unaligned[i]);
  87741. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87742. }
  87743. }
  87744. decoder->private_->output_capacity = 0;
  87745. decoder->private_->output_channels = 0;
  87746. #if FLAC__HAS_OGG
  87747. if(decoder->private_->is_ogg)
  87748. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87749. #endif
  87750. if(0 != decoder->private_->file) {
  87751. if(decoder->private_->file != stdin)
  87752. fclose(decoder->private_->file);
  87753. decoder->private_->file = 0;
  87754. }
  87755. if(decoder->private_->do_md5_checking) {
  87756. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87757. md5_failed = true;
  87758. }
  87759. decoder->private_->is_seeking = false;
  87760. set_defaults_dec(decoder);
  87761. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87762. return !md5_failed;
  87763. }
  87764. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87765. {
  87766. FLAC__ASSERT(0 != decoder);
  87767. FLAC__ASSERT(0 != decoder->private_);
  87768. FLAC__ASSERT(0 != decoder->protected_);
  87769. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87770. return false;
  87771. #if FLAC__HAS_OGG
  87772. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87773. return true;
  87774. #else
  87775. (void)value;
  87776. return false;
  87777. #endif
  87778. }
  87779. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87780. {
  87781. FLAC__ASSERT(0 != decoder);
  87782. FLAC__ASSERT(0 != decoder->protected_);
  87783. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87784. return false;
  87785. decoder->protected_->md5_checking = value;
  87786. return true;
  87787. }
  87788. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87789. {
  87790. FLAC__ASSERT(0 != decoder);
  87791. FLAC__ASSERT(0 != decoder->private_);
  87792. FLAC__ASSERT(0 != decoder->protected_);
  87793. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87794. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87795. return false;
  87796. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87797. return false;
  87798. decoder->private_->metadata_filter[type] = true;
  87799. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87800. decoder->private_->metadata_filter_ids_count = 0;
  87801. return true;
  87802. }
  87803. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87804. {
  87805. FLAC__ASSERT(0 != decoder);
  87806. FLAC__ASSERT(0 != decoder->private_);
  87807. FLAC__ASSERT(0 != decoder->protected_);
  87808. FLAC__ASSERT(0 != id);
  87809. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87810. return false;
  87811. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87812. return true;
  87813. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87814. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87815. 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))) {
  87816. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87817. return false;
  87818. }
  87819. decoder->private_->metadata_filter_ids_capacity *= 2;
  87820. }
  87821. 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));
  87822. decoder->private_->metadata_filter_ids_count++;
  87823. return true;
  87824. }
  87825. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87826. {
  87827. unsigned i;
  87828. FLAC__ASSERT(0 != decoder);
  87829. FLAC__ASSERT(0 != decoder->private_);
  87830. FLAC__ASSERT(0 != decoder->protected_);
  87831. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87832. return false;
  87833. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87834. decoder->private_->metadata_filter[i] = true;
  87835. decoder->private_->metadata_filter_ids_count = 0;
  87836. return true;
  87837. }
  87838. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87839. {
  87840. FLAC__ASSERT(0 != decoder);
  87841. FLAC__ASSERT(0 != decoder->private_);
  87842. FLAC__ASSERT(0 != decoder->protected_);
  87843. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87844. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87845. return false;
  87846. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87847. return false;
  87848. decoder->private_->metadata_filter[type] = false;
  87849. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87850. decoder->private_->metadata_filter_ids_count = 0;
  87851. return true;
  87852. }
  87853. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87854. {
  87855. FLAC__ASSERT(0 != decoder);
  87856. FLAC__ASSERT(0 != decoder->private_);
  87857. FLAC__ASSERT(0 != decoder->protected_);
  87858. FLAC__ASSERT(0 != id);
  87859. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87860. return false;
  87861. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87862. return true;
  87863. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87864. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87865. 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))) {
  87866. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87867. return false;
  87868. }
  87869. decoder->private_->metadata_filter_ids_capacity *= 2;
  87870. }
  87871. 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));
  87872. decoder->private_->metadata_filter_ids_count++;
  87873. return true;
  87874. }
  87875. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87876. {
  87877. FLAC__ASSERT(0 != decoder);
  87878. FLAC__ASSERT(0 != decoder->private_);
  87879. FLAC__ASSERT(0 != decoder->protected_);
  87880. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87881. return false;
  87882. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87883. decoder->private_->metadata_filter_ids_count = 0;
  87884. return true;
  87885. }
  87886. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87887. {
  87888. FLAC__ASSERT(0 != decoder);
  87889. FLAC__ASSERT(0 != decoder->protected_);
  87890. return decoder->protected_->state;
  87891. }
  87892. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87893. {
  87894. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87895. }
  87896. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87897. {
  87898. FLAC__ASSERT(0 != decoder);
  87899. FLAC__ASSERT(0 != decoder->protected_);
  87900. return decoder->protected_->md5_checking;
  87901. }
  87902. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87903. {
  87904. FLAC__ASSERT(0 != decoder);
  87905. FLAC__ASSERT(0 != decoder->protected_);
  87906. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87907. }
  87908. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87909. {
  87910. FLAC__ASSERT(0 != decoder);
  87911. FLAC__ASSERT(0 != decoder->protected_);
  87912. return decoder->protected_->channels;
  87913. }
  87914. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87915. {
  87916. FLAC__ASSERT(0 != decoder);
  87917. FLAC__ASSERT(0 != decoder->protected_);
  87918. return decoder->protected_->channel_assignment;
  87919. }
  87920. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87921. {
  87922. FLAC__ASSERT(0 != decoder);
  87923. FLAC__ASSERT(0 != decoder->protected_);
  87924. return decoder->protected_->bits_per_sample;
  87925. }
  87926. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87927. {
  87928. FLAC__ASSERT(0 != decoder);
  87929. FLAC__ASSERT(0 != decoder->protected_);
  87930. return decoder->protected_->sample_rate;
  87931. }
  87932. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87933. {
  87934. FLAC__ASSERT(0 != decoder);
  87935. FLAC__ASSERT(0 != decoder->protected_);
  87936. return decoder->protected_->blocksize;
  87937. }
  87938. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87939. {
  87940. FLAC__ASSERT(0 != decoder);
  87941. FLAC__ASSERT(0 != decoder->private_);
  87942. FLAC__ASSERT(0 != position);
  87943. #if FLAC__HAS_OGG
  87944. if(decoder->private_->is_ogg)
  87945. return false;
  87946. #endif
  87947. if(0 == decoder->private_->tell_callback)
  87948. return false;
  87949. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87950. return false;
  87951. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87952. return false;
  87953. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87954. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87955. return true;
  87956. }
  87957. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87958. {
  87959. FLAC__ASSERT(0 != decoder);
  87960. FLAC__ASSERT(0 != decoder->private_);
  87961. FLAC__ASSERT(0 != decoder->protected_);
  87962. decoder->private_->samples_decoded = 0;
  87963. decoder->private_->do_md5_checking = false;
  87964. #if FLAC__HAS_OGG
  87965. if(decoder->private_->is_ogg)
  87966. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87967. #endif
  87968. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87969. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87970. return false;
  87971. }
  87972. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87973. return true;
  87974. }
  87975. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87976. {
  87977. FLAC__ASSERT(0 != decoder);
  87978. FLAC__ASSERT(0 != decoder->private_);
  87979. FLAC__ASSERT(0 != decoder->protected_);
  87980. if(!FLAC__stream_decoder_flush(decoder)) {
  87981. return false;
  87982. }
  87983. #if FLAC__HAS_OGG
  87984. if(decoder->private_->is_ogg)
  87985. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87986. #endif
  87987. if(!decoder->private_->internal_reset_hack) {
  87988. if(decoder->private_->file == stdin)
  87989. return false; /* can't rewind stdin, reset fails */
  87990. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87991. return false; /* seekable and seek fails, reset fails */
  87992. }
  87993. else
  87994. decoder->private_->internal_reset_hack = false;
  87995. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87996. decoder->private_->has_stream_info = false;
  87997. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87998. free(decoder->private_->seek_table.data.seek_table.points);
  87999. decoder->private_->seek_table.data.seek_table.points = 0;
  88000. decoder->private_->has_seek_table = false;
  88001. }
  88002. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  88003. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  88004. FLAC__MD5Init(&decoder->private_->md5context);
  88005. decoder->private_->first_frame_offset = 0;
  88006. decoder->private_->unparseable_frame_count = 0;
  88007. return true;
  88008. }
  88009. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  88010. {
  88011. FLAC__bool got_a_frame;
  88012. FLAC__ASSERT(0 != decoder);
  88013. FLAC__ASSERT(0 != decoder->protected_);
  88014. while(1) {
  88015. switch(decoder->protected_->state) {
  88016. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88017. if(!find_metadata_(decoder))
  88018. return false; /* above function sets the status for us */
  88019. break;
  88020. case FLAC__STREAM_DECODER_READ_METADATA:
  88021. if(!read_metadata_(decoder))
  88022. return false; /* above function sets the status for us */
  88023. else
  88024. return true;
  88025. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88026. if(!frame_sync_(decoder))
  88027. return true; /* above function sets the status for us */
  88028. break;
  88029. case FLAC__STREAM_DECODER_READ_FRAME:
  88030. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  88031. return false; /* above function sets the status for us */
  88032. if(got_a_frame)
  88033. return true; /* above function sets the status for us */
  88034. break;
  88035. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88036. case FLAC__STREAM_DECODER_ABORTED:
  88037. return true;
  88038. default:
  88039. FLAC__ASSERT(0);
  88040. return false;
  88041. }
  88042. }
  88043. }
  88044. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  88045. {
  88046. FLAC__ASSERT(0 != decoder);
  88047. FLAC__ASSERT(0 != decoder->protected_);
  88048. while(1) {
  88049. switch(decoder->protected_->state) {
  88050. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88051. if(!find_metadata_(decoder))
  88052. return false; /* above function sets the status for us */
  88053. break;
  88054. case FLAC__STREAM_DECODER_READ_METADATA:
  88055. if(!read_metadata_(decoder))
  88056. return false; /* above function sets the status for us */
  88057. break;
  88058. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88059. case FLAC__STREAM_DECODER_READ_FRAME:
  88060. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88061. case FLAC__STREAM_DECODER_ABORTED:
  88062. return true;
  88063. default:
  88064. FLAC__ASSERT(0);
  88065. return false;
  88066. }
  88067. }
  88068. }
  88069. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  88070. {
  88071. FLAC__bool dummy;
  88072. FLAC__ASSERT(0 != decoder);
  88073. FLAC__ASSERT(0 != decoder->protected_);
  88074. while(1) {
  88075. switch(decoder->protected_->state) {
  88076. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88077. if(!find_metadata_(decoder))
  88078. return false; /* above function sets the status for us */
  88079. break;
  88080. case FLAC__STREAM_DECODER_READ_METADATA:
  88081. if(!read_metadata_(decoder))
  88082. return false; /* above function sets the status for us */
  88083. break;
  88084. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88085. if(!frame_sync_(decoder))
  88086. return true; /* above function sets the status for us */
  88087. break;
  88088. case FLAC__STREAM_DECODER_READ_FRAME:
  88089. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  88090. return false; /* above function sets the status for us */
  88091. break;
  88092. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88093. case FLAC__STREAM_DECODER_ABORTED:
  88094. return true;
  88095. default:
  88096. FLAC__ASSERT(0);
  88097. return false;
  88098. }
  88099. }
  88100. }
  88101. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  88102. {
  88103. FLAC__bool got_a_frame;
  88104. FLAC__ASSERT(0 != decoder);
  88105. FLAC__ASSERT(0 != decoder->protected_);
  88106. while(1) {
  88107. switch(decoder->protected_->state) {
  88108. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88109. case FLAC__STREAM_DECODER_READ_METADATA:
  88110. return false; /* above function sets the status for us */
  88111. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88112. if(!frame_sync_(decoder))
  88113. return true; /* above function sets the status for us */
  88114. break;
  88115. case FLAC__STREAM_DECODER_READ_FRAME:
  88116. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  88117. return false; /* above function sets the status for us */
  88118. if(got_a_frame)
  88119. return true; /* above function sets the status for us */
  88120. break;
  88121. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88122. case FLAC__STREAM_DECODER_ABORTED:
  88123. return true;
  88124. default:
  88125. FLAC__ASSERT(0);
  88126. return false;
  88127. }
  88128. }
  88129. }
  88130. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  88131. {
  88132. FLAC__uint64 length;
  88133. FLAC__ASSERT(0 != decoder);
  88134. if(
  88135. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  88136. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  88137. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  88138. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  88139. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  88140. )
  88141. return false;
  88142. if(0 == decoder->private_->seek_callback)
  88143. return false;
  88144. FLAC__ASSERT(decoder->private_->seek_callback);
  88145. FLAC__ASSERT(decoder->private_->tell_callback);
  88146. FLAC__ASSERT(decoder->private_->length_callback);
  88147. FLAC__ASSERT(decoder->private_->eof_callback);
  88148. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  88149. return false;
  88150. decoder->private_->is_seeking = true;
  88151. decoder->private_->do_md5_checking = false;
  88152. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  88153. decoder->private_->is_seeking = false;
  88154. return false;
  88155. }
  88156. if(
  88157. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  88158. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  88159. ) {
  88160. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  88161. decoder->private_->is_seeking = false;
  88162. return false;
  88163. }
  88164. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88165. decoder->private_->is_seeking = false;
  88166. return false;
  88167. }
  88168. }
  88169. {
  88170. const FLAC__bool ok =
  88171. #if FLAC__HAS_OGG
  88172. decoder->private_->is_ogg?
  88173. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  88174. #endif
  88175. seek_to_absolute_sample_(decoder, length, sample)
  88176. ;
  88177. decoder->private_->is_seeking = false;
  88178. return ok;
  88179. }
  88180. }
  88181. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  88182. {
  88183. FLAC__ASSERT(0 != decoder);
  88184. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88185. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  88186. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  88187. }
  88188. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  88189. {
  88190. #if FLAC__HAS_OGG
  88191. decoder->private_->is_ogg = false;
  88192. #endif
  88193. decoder->private_->read_callback = 0;
  88194. decoder->private_->seek_callback = 0;
  88195. decoder->private_->tell_callback = 0;
  88196. decoder->private_->length_callback = 0;
  88197. decoder->private_->eof_callback = 0;
  88198. decoder->private_->write_callback = 0;
  88199. decoder->private_->metadata_callback = 0;
  88200. decoder->private_->error_callback = 0;
  88201. decoder->private_->client_data = 0;
  88202. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88203. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  88204. decoder->private_->metadata_filter_ids_count = 0;
  88205. decoder->protected_->md5_checking = false;
  88206. #if FLAC__HAS_OGG
  88207. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  88208. #endif
  88209. }
  88210. FILE *get_binary_stdin_(void)
  88211. {
  88212. #if defined _MSC_VER || defined __MINGW32__
  88213. _setmode(_fileno(stdin), _O_BINARY);
  88214. #elif defined __CYGWIN__
  88215. setmode(_fileno(stdin), _O_BINARY);
  88216. #elif defined __EMX__
  88217. setmode(fileno(stdin), O_BINARY);
  88218. #endif
  88219. return stdin;
  88220. }
  88221. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  88222. {
  88223. unsigned i;
  88224. FLAC__int32 *tmp;
  88225. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  88226. return true;
  88227. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88228. if(0 != decoder->private_->output[i]) {
  88229. free(decoder->private_->output[i]-4);
  88230. decoder->private_->output[i] = 0;
  88231. }
  88232. if(0 != decoder->private_->residual_unaligned[i]) {
  88233. free(decoder->private_->residual_unaligned[i]);
  88234. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88235. }
  88236. }
  88237. for(i = 0; i < channels; i++) {
  88238. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  88239. if(tmp == 0) {
  88240. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88241. return false;
  88242. }
  88243. memset(tmp, 0, sizeof(FLAC__int32)*4);
  88244. decoder->private_->output[i] = tmp + 4;
  88245. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  88246. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88247. return false;
  88248. }
  88249. }
  88250. decoder->private_->output_capacity = size;
  88251. decoder->private_->output_channels = channels;
  88252. return true;
  88253. }
  88254. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  88255. {
  88256. size_t i;
  88257. FLAC__ASSERT(0 != decoder);
  88258. FLAC__ASSERT(0 != decoder->private_);
  88259. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  88260. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  88261. return true;
  88262. return false;
  88263. }
  88264. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  88265. {
  88266. FLAC__uint32 x;
  88267. unsigned i, id_;
  88268. FLAC__bool first = true;
  88269. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88270. for(i = id_ = 0; i < 4; ) {
  88271. if(decoder->private_->cached) {
  88272. x = (FLAC__uint32)decoder->private_->lookahead;
  88273. decoder->private_->cached = false;
  88274. }
  88275. else {
  88276. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88277. return false; /* read_callback_ sets the state for us */
  88278. }
  88279. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  88280. first = true;
  88281. i++;
  88282. id_ = 0;
  88283. continue;
  88284. }
  88285. if(x == ID3V2_TAG_[id_]) {
  88286. id_++;
  88287. i = 0;
  88288. if(id_ == 3) {
  88289. if(!skip_id3v2_tag_(decoder))
  88290. return false; /* skip_id3v2_tag_ sets the state for us */
  88291. }
  88292. continue;
  88293. }
  88294. id_ = 0;
  88295. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88296. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88297. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88298. return false; /* read_callback_ sets the state for us */
  88299. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88300. decoder->private_->lookahead = (FLAC__byte)x;
  88301. decoder->private_->cached = true;
  88302. }
  88303. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88304. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88305. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88306. return true;
  88307. }
  88308. }
  88309. i = 0;
  88310. if(first) {
  88311. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88312. first = false;
  88313. }
  88314. }
  88315. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  88316. return true;
  88317. }
  88318. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  88319. {
  88320. FLAC__bool is_last;
  88321. FLAC__uint32 i, x, type, length;
  88322. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88323. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88324. return false; /* read_callback_ sets the state for us */
  88325. is_last = x? true : false;
  88326. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88327. return false; /* read_callback_ sets the state for us */
  88328. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88329. return false; /* read_callback_ sets the state for us */
  88330. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88331. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88332. return false;
  88333. decoder->private_->has_stream_info = true;
  88334. 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))
  88335. decoder->private_->do_md5_checking = false;
  88336. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88337. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88338. }
  88339. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88340. if(!read_metadata_seektable_(decoder, is_last, length))
  88341. return false;
  88342. decoder->private_->has_seek_table = true;
  88343. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88344. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88345. }
  88346. else {
  88347. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88348. unsigned real_length = length;
  88349. FLAC__StreamMetadata block;
  88350. block.is_last = is_last;
  88351. block.type = (FLAC__MetadataType)type;
  88352. block.length = length;
  88353. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88354. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88355. return false; /* read_callback_ sets the state for us */
  88356. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88357. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88358. return false;
  88359. }
  88360. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88361. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88362. skip_it = !skip_it;
  88363. }
  88364. if(skip_it) {
  88365. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88366. return false; /* read_callback_ sets the state for us */
  88367. }
  88368. else {
  88369. switch(type) {
  88370. case FLAC__METADATA_TYPE_PADDING:
  88371. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88372. return false; /* read_callback_ sets the state for us */
  88373. break;
  88374. case FLAC__METADATA_TYPE_APPLICATION:
  88375. if(real_length > 0) {
  88376. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88377. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88378. return false;
  88379. }
  88380. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88381. return false; /* read_callback_ sets the state for us */
  88382. }
  88383. else
  88384. block.data.application.data = 0;
  88385. break;
  88386. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88387. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88388. return false;
  88389. break;
  88390. case FLAC__METADATA_TYPE_CUESHEET:
  88391. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88392. return false;
  88393. break;
  88394. case FLAC__METADATA_TYPE_PICTURE:
  88395. if(!read_metadata_picture_(decoder, &block.data.picture))
  88396. return false;
  88397. break;
  88398. case FLAC__METADATA_TYPE_STREAMINFO:
  88399. case FLAC__METADATA_TYPE_SEEKTABLE:
  88400. FLAC__ASSERT(0);
  88401. break;
  88402. default:
  88403. if(real_length > 0) {
  88404. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88405. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88406. return false;
  88407. }
  88408. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88409. return false; /* read_callback_ sets the state for us */
  88410. }
  88411. else
  88412. block.data.unknown.data = 0;
  88413. break;
  88414. }
  88415. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88416. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88417. switch(type) {
  88418. case FLAC__METADATA_TYPE_PADDING:
  88419. break;
  88420. case FLAC__METADATA_TYPE_APPLICATION:
  88421. if(0 != block.data.application.data)
  88422. free(block.data.application.data);
  88423. break;
  88424. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88425. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88426. free(block.data.vorbis_comment.vendor_string.entry);
  88427. if(block.data.vorbis_comment.num_comments > 0)
  88428. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88429. if(0 != block.data.vorbis_comment.comments[i].entry)
  88430. free(block.data.vorbis_comment.comments[i].entry);
  88431. if(0 != block.data.vorbis_comment.comments)
  88432. free(block.data.vorbis_comment.comments);
  88433. break;
  88434. case FLAC__METADATA_TYPE_CUESHEET:
  88435. if(block.data.cue_sheet.num_tracks > 0)
  88436. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88437. if(0 != block.data.cue_sheet.tracks[i].indices)
  88438. free(block.data.cue_sheet.tracks[i].indices);
  88439. if(0 != block.data.cue_sheet.tracks)
  88440. free(block.data.cue_sheet.tracks);
  88441. break;
  88442. case FLAC__METADATA_TYPE_PICTURE:
  88443. if(0 != block.data.picture.mime_type)
  88444. free(block.data.picture.mime_type);
  88445. if(0 != block.data.picture.description)
  88446. free(block.data.picture.description);
  88447. if(0 != block.data.picture.data)
  88448. free(block.data.picture.data);
  88449. break;
  88450. case FLAC__METADATA_TYPE_STREAMINFO:
  88451. case FLAC__METADATA_TYPE_SEEKTABLE:
  88452. FLAC__ASSERT(0);
  88453. default:
  88454. if(0 != block.data.unknown.data)
  88455. free(block.data.unknown.data);
  88456. break;
  88457. }
  88458. }
  88459. }
  88460. if(is_last) {
  88461. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88462. decoder->private_->first_frame_offset = 0;
  88463. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88464. }
  88465. return true;
  88466. }
  88467. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88468. {
  88469. FLAC__uint32 x;
  88470. unsigned bits, used_bits = 0;
  88471. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88472. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88473. decoder->private_->stream_info.is_last = is_last;
  88474. decoder->private_->stream_info.length = length;
  88475. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88476. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88477. return false; /* read_callback_ sets the state for us */
  88478. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88479. used_bits += bits;
  88480. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88481. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88482. return false; /* read_callback_ sets the state for us */
  88483. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88484. used_bits += bits;
  88485. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88486. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88487. return false; /* read_callback_ sets the state for us */
  88488. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88489. used_bits += bits;
  88490. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88491. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88492. return false; /* read_callback_ sets the state for us */
  88493. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88494. used_bits += bits;
  88495. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88496. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88497. return false; /* read_callback_ sets the state for us */
  88498. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88499. used_bits += bits;
  88500. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88501. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88502. return false; /* read_callback_ sets the state for us */
  88503. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88504. used_bits += bits;
  88505. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88506. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88507. return false; /* read_callback_ sets the state for us */
  88508. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88509. used_bits += bits;
  88510. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88511. 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))
  88512. return false; /* read_callback_ sets the state for us */
  88513. used_bits += bits;
  88514. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88515. return false; /* read_callback_ sets the state for us */
  88516. used_bits += 16*8;
  88517. FLAC__ASSERT(used_bits % 8 == 0);
  88518. length -= (used_bits / 8);
  88519. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88520. return false; /* read_callback_ sets the state for us */
  88521. return true;
  88522. }
  88523. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88524. {
  88525. FLAC__uint32 i, x;
  88526. FLAC__uint64 xx;
  88527. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88528. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88529. decoder->private_->seek_table.is_last = is_last;
  88530. decoder->private_->seek_table.length = length;
  88531. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88532. 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)))) {
  88533. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88534. return false;
  88535. }
  88536. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88537. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88538. return false; /* read_callback_ sets the state for us */
  88539. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88540. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88541. return false; /* read_callback_ sets the state for us */
  88542. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88543. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88544. return false; /* read_callback_ sets the state for us */
  88545. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88546. }
  88547. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88548. if(length > 0) {
  88549. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88550. return false; /* read_callback_ sets the state for us */
  88551. }
  88552. return true;
  88553. }
  88554. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88555. {
  88556. FLAC__uint32 i;
  88557. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88558. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88559. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88560. return false; /* read_callback_ sets the state for us */
  88561. if(obj->vendor_string.length > 0) {
  88562. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88563. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88564. return false;
  88565. }
  88566. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88567. return false; /* read_callback_ sets the state for us */
  88568. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88569. }
  88570. else
  88571. obj->vendor_string.entry = 0;
  88572. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88573. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88574. return false; /* read_callback_ sets the state for us */
  88575. if(obj->num_comments > 0) {
  88576. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88577. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88578. return false;
  88579. }
  88580. for(i = 0; i < obj->num_comments; i++) {
  88581. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88582. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88583. return false; /* read_callback_ sets the state for us */
  88584. if(obj->comments[i].length > 0) {
  88585. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88586. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88587. return false;
  88588. }
  88589. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88590. return false; /* read_callback_ sets the state for us */
  88591. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88592. }
  88593. else
  88594. obj->comments[i].entry = 0;
  88595. }
  88596. }
  88597. else {
  88598. obj->comments = 0;
  88599. }
  88600. return true;
  88601. }
  88602. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88603. {
  88604. FLAC__uint32 i, j, x;
  88605. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88606. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88607. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88608. 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))
  88609. return false; /* read_callback_ sets the state for us */
  88610. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88611. return false; /* read_callback_ sets the state for us */
  88612. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88613. return false; /* read_callback_ sets the state for us */
  88614. obj->is_cd = x? true : false;
  88615. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88616. return false; /* read_callback_ sets the state for us */
  88617. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88618. return false; /* read_callback_ sets the state for us */
  88619. obj->num_tracks = x;
  88620. if(obj->num_tracks > 0) {
  88621. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88622. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88623. return false;
  88624. }
  88625. for(i = 0; i < obj->num_tracks; i++) {
  88626. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88627. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88628. return false; /* read_callback_ sets the state for us */
  88629. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88630. return false; /* read_callback_ sets the state for us */
  88631. track->number = (FLAC__byte)x;
  88632. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88633. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88634. return false; /* read_callback_ sets the state for us */
  88635. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88636. return false; /* read_callback_ sets the state for us */
  88637. track->type = x;
  88638. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88639. return false; /* read_callback_ sets the state for us */
  88640. track->pre_emphasis = x;
  88641. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88642. return false; /* read_callback_ sets the state for us */
  88643. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88644. return false; /* read_callback_ sets the state for us */
  88645. track->num_indices = (FLAC__byte)x;
  88646. if(track->num_indices > 0) {
  88647. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88648. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88649. return false;
  88650. }
  88651. for(j = 0; j < track->num_indices; j++) {
  88652. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88653. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88654. return false; /* read_callback_ sets the state for us */
  88655. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88656. return false; /* read_callback_ sets the state for us */
  88657. index->number = (FLAC__byte)x;
  88658. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88659. return false; /* read_callback_ sets the state for us */
  88660. }
  88661. }
  88662. }
  88663. }
  88664. return true;
  88665. }
  88666. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88667. {
  88668. FLAC__uint32 x;
  88669. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88670. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88671. return false; /* read_callback_ sets the state for us */
  88672. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88673. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88674. return false; /* read_callback_ sets the state for us */
  88675. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88676. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88677. return false;
  88678. }
  88679. if(x > 0) {
  88680. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88681. return false; /* read_callback_ sets the state for us */
  88682. }
  88683. obj->mime_type[x] = '\0';
  88684. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88685. return false; /* read_callback_ sets the state for us */
  88686. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88687. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88688. return false;
  88689. }
  88690. if(x > 0) {
  88691. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88692. return false; /* read_callback_ sets the state for us */
  88693. }
  88694. obj->description[x] = '\0';
  88695. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88696. return false; /* read_callback_ sets the state for us */
  88697. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88698. return false; /* read_callback_ sets the state for us */
  88699. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88700. return false; /* read_callback_ sets the state for us */
  88701. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88702. return false; /* read_callback_ sets the state for us */
  88703. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88704. return false; /* read_callback_ sets the state for us */
  88705. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88706. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88707. return false;
  88708. }
  88709. if(obj->data_length > 0) {
  88710. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88711. return false; /* read_callback_ sets the state for us */
  88712. }
  88713. return true;
  88714. }
  88715. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88716. {
  88717. FLAC__uint32 x;
  88718. unsigned i, skip;
  88719. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88720. return false; /* read_callback_ sets the state for us */
  88721. skip = 0;
  88722. for(i = 0; i < 4; i++) {
  88723. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88724. return false; /* read_callback_ sets the state for us */
  88725. skip <<= 7;
  88726. skip |= (x & 0x7f);
  88727. }
  88728. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88729. return false; /* read_callback_ sets the state for us */
  88730. return true;
  88731. }
  88732. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88733. {
  88734. FLAC__uint32 x;
  88735. FLAC__bool first = true;
  88736. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88737. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88738. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88739. return true;
  88740. }
  88741. }
  88742. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88743. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88744. return false; /* read_callback_ sets the state for us */
  88745. }
  88746. while(1) {
  88747. if(decoder->private_->cached) {
  88748. x = (FLAC__uint32)decoder->private_->lookahead;
  88749. decoder->private_->cached = false;
  88750. }
  88751. else {
  88752. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88753. return false; /* read_callback_ sets the state for us */
  88754. }
  88755. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88756. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88757. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88758. return false; /* read_callback_ sets the state for us */
  88759. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88760. decoder->private_->lookahead = (FLAC__byte)x;
  88761. decoder->private_->cached = true;
  88762. }
  88763. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88764. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88765. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88766. return true;
  88767. }
  88768. }
  88769. if(first) {
  88770. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88771. first = false;
  88772. }
  88773. }
  88774. return true;
  88775. }
  88776. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88777. {
  88778. unsigned channel;
  88779. unsigned i;
  88780. FLAC__int32 mid, side;
  88781. unsigned frame_crc; /* the one we calculate from the input stream */
  88782. FLAC__uint32 x;
  88783. *got_a_frame = false;
  88784. frame_crc = 0;
  88785. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88786. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88787. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88788. if(!read_frame_header_(decoder))
  88789. return false;
  88790. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88791. return true;
  88792. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88793. return false;
  88794. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88795. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88796. switch(decoder->private_->frame.header.channel_assignment) {
  88797. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88798. break;
  88799. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88800. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88801. if(channel == 1)
  88802. bps++;
  88803. break;
  88804. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88805. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88806. if(channel == 0)
  88807. bps++;
  88808. break;
  88809. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88810. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88811. if(channel == 1)
  88812. bps++;
  88813. break;
  88814. default:
  88815. FLAC__ASSERT(0);
  88816. }
  88817. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88818. return false;
  88819. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88820. return true;
  88821. }
  88822. if(!read_zero_padding_(decoder))
  88823. return false;
  88824. 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) */
  88825. return true;
  88826. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88827. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88828. return false; /* read_callback_ sets the state for us */
  88829. if(frame_crc == x) {
  88830. if(do_full_decode) {
  88831. switch(decoder->private_->frame.header.channel_assignment) {
  88832. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88833. break;
  88834. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88835. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88836. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88837. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88838. break;
  88839. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88840. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88841. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88842. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88843. break;
  88844. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88845. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88846. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88847. #if 1
  88848. mid = decoder->private_->output[0][i];
  88849. side = decoder->private_->output[1][i];
  88850. mid <<= 1;
  88851. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88852. decoder->private_->output[0][i] = (mid + side) >> 1;
  88853. decoder->private_->output[1][i] = (mid - side) >> 1;
  88854. #else
  88855. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88856. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88857. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88858. #endif
  88859. }
  88860. break;
  88861. default:
  88862. FLAC__ASSERT(0);
  88863. break;
  88864. }
  88865. }
  88866. }
  88867. else {
  88868. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88869. if(do_full_decode) {
  88870. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88871. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88872. }
  88873. }
  88874. }
  88875. *got_a_frame = true;
  88876. if(decoder->private_->next_fixed_block_size)
  88877. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88878. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88879. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88880. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88881. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88882. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88883. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88884. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88885. if(do_full_decode) {
  88886. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88887. return false;
  88888. }
  88889. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88890. return true;
  88891. }
  88892. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88893. {
  88894. FLAC__uint32 x;
  88895. FLAC__uint64 xx;
  88896. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88897. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88898. unsigned raw_header_len;
  88899. FLAC__bool is_unparseable = false;
  88900. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88901. raw_header[0] = decoder->private_->header_warmup[0];
  88902. raw_header[1] = decoder->private_->header_warmup[1];
  88903. raw_header_len = 2;
  88904. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88905. is_unparseable = true;
  88906. for(i = 0; i < 2; i++) {
  88907. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88908. return false; /* read_callback_ sets the state for us */
  88909. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88910. decoder->private_->lookahead = (FLAC__byte)x;
  88911. decoder->private_->cached = true;
  88912. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88913. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88914. return true;
  88915. }
  88916. raw_header[raw_header_len++] = (FLAC__byte)x;
  88917. }
  88918. switch(x = raw_header[2] >> 4) {
  88919. case 0:
  88920. is_unparseable = true;
  88921. break;
  88922. case 1:
  88923. decoder->private_->frame.header.blocksize = 192;
  88924. break;
  88925. case 2:
  88926. case 3:
  88927. case 4:
  88928. case 5:
  88929. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88930. break;
  88931. case 6:
  88932. case 7:
  88933. blocksize_hint = x;
  88934. break;
  88935. case 8:
  88936. case 9:
  88937. case 10:
  88938. case 11:
  88939. case 12:
  88940. case 13:
  88941. case 14:
  88942. case 15:
  88943. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88944. break;
  88945. default:
  88946. FLAC__ASSERT(0);
  88947. break;
  88948. }
  88949. switch(x = raw_header[2] & 0x0f) {
  88950. case 0:
  88951. if(decoder->private_->has_stream_info)
  88952. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88953. else
  88954. is_unparseable = true;
  88955. break;
  88956. case 1:
  88957. decoder->private_->frame.header.sample_rate = 88200;
  88958. break;
  88959. case 2:
  88960. decoder->private_->frame.header.sample_rate = 176400;
  88961. break;
  88962. case 3:
  88963. decoder->private_->frame.header.sample_rate = 192000;
  88964. break;
  88965. case 4:
  88966. decoder->private_->frame.header.sample_rate = 8000;
  88967. break;
  88968. case 5:
  88969. decoder->private_->frame.header.sample_rate = 16000;
  88970. break;
  88971. case 6:
  88972. decoder->private_->frame.header.sample_rate = 22050;
  88973. break;
  88974. case 7:
  88975. decoder->private_->frame.header.sample_rate = 24000;
  88976. break;
  88977. case 8:
  88978. decoder->private_->frame.header.sample_rate = 32000;
  88979. break;
  88980. case 9:
  88981. decoder->private_->frame.header.sample_rate = 44100;
  88982. break;
  88983. case 10:
  88984. decoder->private_->frame.header.sample_rate = 48000;
  88985. break;
  88986. case 11:
  88987. decoder->private_->frame.header.sample_rate = 96000;
  88988. break;
  88989. case 12:
  88990. case 13:
  88991. case 14:
  88992. sample_rate_hint = x;
  88993. break;
  88994. case 15:
  88995. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88996. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88997. return true;
  88998. default:
  88999. FLAC__ASSERT(0);
  89000. }
  89001. x = (unsigned)(raw_header[3] >> 4);
  89002. if(x & 8) {
  89003. decoder->private_->frame.header.channels = 2;
  89004. switch(x & 7) {
  89005. case 0:
  89006. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  89007. break;
  89008. case 1:
  89009. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  89010. break;
  89011. case 2:
  89012. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  89013. break;
  89014. default:
  89015. is_unparseable = true;
  89016. break;
  89017. }
  89018. }
  89019. else {
  89020. decoder->private_->frame.header.channels = (unsigned)x + 1;
  89021. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  89022. }
  89023. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  89024. case 0:
  89025. if(decoder->private_->has_stream_info)
  89026. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89027. else
  89028. is_unparseable = true;
  89029. break;
  89030. case 1:
  89031. decoder->private_->frame.header.bits_per_sample = 8;
  89032. break;
  89033. case 2:
  89034. decoder->private_->frame.header.bits_per_sample = 12;
  89035. break;
  89036. case 4:
  89037. decoder->private_->frame.header.bits_per_sample = 16;
  89038. break;
  89039. case 5:
  89040. decoder->private_->frame.header.bits_per_sample = 20;
  89041. break;
  89042. case 6:
  89043. decoder->private_->frame.header.bits_per_sample = 24;
  89044. break;
  89045. case 3:
  89046. case 7:
  89047. is_unparseable = true;
  89048. break;
  89049. default:
  89050. FLAC__ASSERT(0);
  89051. break;
  89052. }
  89053. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  89054. is_unparseable = true;
  89055. if(
  89056. raw_header[1] & 0x01 ||
  89057. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  89058. ) { /* variable blocksize */
  89059. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  89060. return false; /* read_callback_ sets the state for us */
  89061. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  89062. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89063. decoder->private_->cached = true;
  89064. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89065. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89066. return true;
  89067. }
  89068. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89069. decoder->private_->frame.header.number.sample_number = xx;
  89070. }
  89071. else { /* fixed blocksize */
  89072. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  89073. return false; /* read_callback_ sets the state for us */
  89074. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  89075. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89076. decoder->private_->cached = true;
  89077. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89078. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89079. return true;
  89080. }
  89081. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  89082. decoder->private_->frame.header.number.frame_number = x;
  89083. }
  89084. if(blocksize_hint) {
  89085. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89086. return false; /* read_callback_ sets the state for us */
  89087. raw_header[raw_header_len++] = (FLAC__byte)x;
  89088. if(blocksize_hint == 7) {
  89089. FLAC__uint32 _x;
  89090. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89091. return false; /* read_callback_ sets the state for us */
  89092. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89093. x = (x << 8) | _x;
  89094. }
  89095. decoder->private_->frame.header.blocksize = x+1;
  89096. }
  89097. if(sample_rate_hint) {
  89098. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89099. return false; /* read_callback_ sets the state for us */
  89100. raw_header[raw_header_len++] = (FLAC__byte)x;
  89101. if(sample_rate_hint != 12) {
  89102. FLAC__uint32 _x;
  89103. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89104. return false; /* read_callback_ sets the state for us */
  89105. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89106. x = (x << 8) | _x;
  89107. }
  89108. if(sample_rate_hint == 12)
  89109. decoder->private_->frame.header.sample_rate = x*1000;
  89110. else if(sample_rate_hint == 13)
  89111. decoder->private_->frame.header.sample_rate = x;
  89112. else
  89113. decoder->private_->frame.header.sample_rate = x*10;
  89114. }
  89115. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89116. return false; /* read_callback_ sets the state for us */
  89117. crc8 = (FLAC__byte)x;
  89118. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  89119. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89120. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89121. return true;
  89122. }
  89123. decoder->private_->next_fixed_block_size = 0;
  89124. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  89125. x = decoder->private_->frame.header.number.frame_number;
  89126. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89127. if(decoder->private_->fixed_block_size)
  89128. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  89129. else if(decoder->private_->has_stream_info) {
  89130. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  89131. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  89132. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89133. }
  89134. else
  89135. is_unparseable = true;
  89136. }
  89137. else if(x == 0) {
  89138. decoder->private_->frame.header.number.sample_number = 0;
  89139. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  89140. }
  89141. else {
  89142. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  89143. }
  89144. }
  89145. if(is_unparseable) {
  89146. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89147. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89148. return true;
  89149. }
  89150. return true;
  89151. }
  89152. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89153. {
  89154. FLAC__uint32 x;
  89155. FLAC__bool wasted_bits;
  89156. unsigned i;
  89157. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  89158. return false; /* read_callback_ sets the state for us */
  89159. wasted_bits = (x & 1);
  89160. x &= 0xfe;
  89161. if(wasted_bits) {
  89162. unsigned u;
  89163. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  89164. return false; /* read_callback_ sets the state for us */
  89165. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  89166. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  89167. }
  89168. else
  89169. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  89170. if(x & 0x80) {
  89171. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89172. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89173. return true;
  89174. }
  89175. else if(x == 0) {
  89176. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  89177. return false;
  89178. }
  89179. else if(x == 2) {
  89180. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  89181. return false;
  89182. }
  89183. else if(x < 16) {
  89184. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89185. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89186. return true;
  89187. }
  89188. else if(x <= 24) {
  89189. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  89190. return false;
  89191. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89192. return true;
  89193. }
  89194. else if(x < 64) {
  89195. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89196. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89197. return true;
  89198. }
  89199. else {
  89200. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  89201. return false;
  89202. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89203. return true;
  89204. }
  89205. if(wasted_bits && do_full_decode) {
  89206. x = decoder->private_->frame.subframes[channel].wasted_bits;
  89207. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89208. decoder->private_->output[channel][i] <<= x;
  89209. }
  89210. return true;
  89211. }
  89212. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89213. {
  89214. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  89215. FLAC__int32 x;
  89216. unsigned i;
  89217. FLAC__int32 *output = decoder->private_->output[channel];
  89218. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  89219. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89220. return false; /* read_callback_ sets the state for us */
  89221. subframe->value = x;
  89222. if(do_full_decode) {
  89223. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89224. output[i] = x;
  89225. }
  89226. return true;
  89227. }
  89228. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89229. {
  89230. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  89231. FLAC__int32 i32;
  89232. FLAC__uint32 u32;
  89233. unsigned u;
  89234. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  89235. subframe->residual = decoder->private_->residual[channel];
  89236. subframe->order = order;
  89237. for(u = 0; u < order; u++) {
  89238. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89239. return false; /* read_callback_ sets the state for us */
  89240. subframe->warmup[u] = i32;
  89241. }
  89242. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89243. return false; /* read_callback_ sets the state for us */
  89244. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89245. switch(subframe->entropy_coding_method.type) {
  89246. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89247. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89248. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89249. return false; /* read_callback_ sets the state for us */
  89250. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89251. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89252. break;
  89253. default:
  89254. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89255. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89256. return true;
  89257. }
  89258. switch(subframe->entropy_coding_method.type) {
  89259. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89260. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89261. 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))
  89262. return false;
  89263. break;
  89264. default:
  89265. FLAC__ASSERT(0);
  89266. }
  89267. if(do_full_decode) {
  89268. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89269. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  89270. }
  89271. return true;
  89272. }
  89273. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89274. {
  89275. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  89276. FLAC__int32 i32;
  89277. FLAC__uint32 u32;
  89278. unsigned u;
  89279. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  89280. subframe->residual = decoder->private_->residual[channel];
  89281. subframe->order = order;
  89282. for(u = 0; u < order; u++) {
  89283. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89284. return false; /* read_callback_ sets the state for us */
  89285. subframe->warmup[u] = i32;
  89286. }
  89287. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  89288. return false; /* read_callback_ sets the state for us */
  89289. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  89290. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89291. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89292. return true;
  89293. }
  89294. subframe->qlp_coeff_precision = u32+1;
  89295. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  89296. return false; /* read_callback_ sets the state for us */
  89297. subframe->quantization_level = i32;
  89298. for(u = 0; u < order; u++) {
  89299. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  89300. return false; /* read_callback_ sets the state for us */
  89301. subframe->qlp_coeff[u] = i32;
  89302. }
  89303. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89304. return false; /* read_callback_ sets the state for us */
  89305. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89306. switch(subframe->entropy_coding_method.type) {
  89307. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89308. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89309. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89310. return false; /* read_callback_ sets the state for us */
  89311. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89312. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89313. break;
  89314. default:
  89315. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89316. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89317. return true;
  89318. }
  89319. switch(subframe->entropy_coding_method.type) {
  89320. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89321. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89322. 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))
  89323. return false;
  89324. break;
  89325. default:
  89326. FLAC__ASSERT(0);
  89327. }
  89328. if(do_full_decode) {
  89329. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89330. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89331. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89332. if(order <= 8)
  89333. 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);
  89334. else
  89335. 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);
  89336. }
  89337. else
  89338. 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);
  89339. else
  89340. 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);
  89341. }
  89342. return true;
  89343. }
  89344. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89345. {
  89346. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89347. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89348. unsigned i;
  89349. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89350. subframe->data = residual;
  89351. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89352. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89353. return false; /* read_callback_ sets the state for us */
  89354. residual[i] = x;
  89355. }
  89356. if(do_full_decode)
  89357. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89358. return true;
  89359. }
  89360. 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)
  89361. {
  89362. FLAC__uint32 rice_parameter;
  89363. int i;
  89364. unsigned partition, sample, u;
  89365. const unsigned partitions = 1u << partition_order;
  89366. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89367. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89368. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89369. if(partition_order == 0) {
  89370. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89371. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89372. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89373. return true;
  89374. }
  89375. }
  89376. else {
  89377. if(partition_samples < predictor_order) {
  89378. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89379. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89380. return true;
  89381. }
  89382. }
  89383. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89384. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89385. return false;
  89386. }
  89387. sample = 0;
  89388. for(partition = 0; partition < partitions; partition++) {
  89389. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89390. return false; /* read_callback_ sets the state for us */
  89391. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89392. if(rice_parameter < pesc) {
  89393. partitioned_rice_contents->raw_bits[partition] = 0;
  89394. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89395. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89396. return false; /* read_callback_ sets the state for us */
  89397. sample += u;
  89398. }
  89399. else {
  89400. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89401. return false; /* read_callback_ sets the state for us */
  89402. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89403. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89404. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89405. return false; /* read_callback_ sets the state for us */
  89406. residual[sample] = i;
  89407. }
  89408. }
  89409. }
  89410. return true;
  89411. }
  89412. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89413. {
  89414. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89415. FLAC__uint32 zero = 0;
  89416. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89417. return false; /* read_callback_ sets the state for us */
  89418. if(zero != 0) {
  89419. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89420. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89421. }
  89422. }
  89423. return true;
  89424. }
  89425. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89426. {
  89427. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89428. if(
  89429. #if FLAC__HAS_OGG
  89430. !decoder->private_->is_ogg &&
  89431. #endif
  89432. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89433. ) {
  89434. *bytes = 0;
  89435. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89436. return false;
  89437. }
  89438. else if(*bytes > 0) {
  89439. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89440. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89441. return false;
  89442. }
  89443. else {
  89444. const FLAC__StreamDecoderReadStatus status =
  89445. #if FLAC__HAS_OGG
  89446. decoder->private_->is_ogg?
  89447. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89448. #endif
  89449. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89450. ;
  89451. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89452. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89453. return false;
  89454. }
  89455. else if(*bytes == 0) {
  89456. if(
  89457. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89458. (
  89459. #if FLAC__HAS_OGG
  89460. !decoder->private_->is_ogg &&
  89461. #endif
  89462. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89463. )
  89464. ) {
  89465. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89466. return false;
  89467. }
  89468. else
  89469. return true;
  89470. }
  89471. else
  89472. return true;
  89473. }
  89474. }
  89475. else {
  89476. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89477. return false;
  89478. }
  89479. }
  89480. #if FLAC__HAS_OGG
  89481. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89482. {
  89483. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89484. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89485. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89486. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89487. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89488. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89489. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89490. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89491. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89492. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89493. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89494. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89495. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89496. default:
  89497. FLAC__ASSERT(0);
  89498. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89499. }
  89500. }
  89501. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89502. {
  89503. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89504. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89505. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89506. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89507. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89508. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89509. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89510. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89511. default:
  89512. FLAC__ASSERT(0);
  89513. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89514. }
  89515. }
  89516. #endif
  89517. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89518. {
  89519. if(decoder->private_->is_seeking) {
  89520. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89521. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89522. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89523. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89524. #if FLAC__HAS_OGG
  89525. decoder->private_->got_a_frame = true;
  89526. #endif
  89527. decoder->private_->last_frame = *frame; /* save the frame */
  89528. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89529. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89530. decoder->private_->is_seeking = false;
  89531. if(delta > 0) {
  89532. unsigned channel;
  89533. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89534. for(channel = 0; channel < frame->header.channels; channel++)
  89535. newbuffer[channel] = buffer[channel] + delta;
  89536. decoder->private_->last_frame.header.blocksize -= delta;
  89537. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89538. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89539. }
  89540. else {
  89541. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89542. }
  89543. }
  89544. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89545. }
  89546. if(!decoder->private_->has_stream_info)
  89547. decoder->private_->do_md5_checking = false;
  89548. if(decoder->private_->do_md5_checking) {
  89549. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89550. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89551. }
  89552. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89553. }
  89554. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89555. {
  89556. if(!decoder->private_->is_seeking)
  89557. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89558. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89559. decoder->private_->unparseable_frame_count++;
  89560. }
  89561. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89562. {
  89563. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89564. FLAC__int64 pos = -1;
  89565. int i;
  89566. unsigned approx_bytes_per_frame;
  89567. FLAC__bool first_seek = true;
  89568. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89569. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89570. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89571. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89572. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89573. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89574. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89575. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89576. if(channels == 0)
  89577. channels = decoder->private_->stream_info.data.stream_info.channels;
  89578. if(bps == 0)
  89579. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89580. if(max_framesize > 0)
  89581. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89582. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89583. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89584. }
  89585. else
  89586. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89587. lower_bound = first_frame_offset;
  89588. lower_bound_sample = 0;
  89589. upper_bound = stream_length;
  89590. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89591. if(seek_table) {
  89592. FLAC__uint64 new_lower_bound = lower_bound;
  89593. FLAC__uint64 new_upper_bound = upper_bound;
  89594. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89595. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89596. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89597. if(
  89598. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89599. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89600. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89601. seek_table->points[i].sample_number <= target_sample
  89602. )
  89603. break;
  89604. }
  89605. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89606. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89607. new_lower_bound_sample = seek_table->points[i].sample_number;
  89608. }
  89609. for(i = 0; i < (int)seek_table->num_points; i++) {
  89610. if(
  89611. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89612. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89613. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89614. seek_table->points[i].sample_number > target_sample
  89615. )
  89616. break;
  89617. }
  89618. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89619. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89620. new_upper_bound_sample = seek_table->points[i].sample_number;
  89621. }
  89622. if(new_upper_bound >= new_lower_bound) {
  89623. lower_bound = new_lower_bound;
  89624. upper_bound = new_upper_bound;
  89625. lower_bound_sample = new_lower_bound_sample;
  89626. upper_bound_sample = new_upper_bound_sample;
  89627. }
  89628. }
  89629. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89630. if(upper_bound_sample == lower_bound_sample)
  89631. upper_bound_sample++;
  89632. decoder->private_->target_sample = target_sample;
  89633. while(1) {
  89634. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89635. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89636. return false;
  89637. }
  89638. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89639. #if defined _MSC_VER || defined __MINGW32__
  89640. 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;
  89641. #else
  89642. 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;
  89643. #endif
  89644. #else
  89645. if(upper_bound - lower_bound < 0xffffffff)
  89646. 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;
  89647. else /* @@@ WATCHOUT, ~2TB limit */
  89648. 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;
  89649. #endif
  89650. if(pos >= (FLAC__int64)upper_bound)
  89651. pos = (FLAC__int64)upper_bound - 1;
  89652. if(pos < (FLAC__int64)lower_bound)
  89653. pos = (FLAC__int64)lower_bound;
  89654. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89655. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89656. return false;
  89657. }
  89658. if(!FLAC__stream_decoder_flush(decoder)) {
  89659. return false;
  89660. }
  89661. decoder->private_->unparseable_frame_count = 0;
  89662. if(!FLAC__stream_decoder_process_single(decoder)) {
  89663. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89664. return false;
  89665. }
  89666. #if 0
  89667. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89668. break;
  89669. #endif
  89670. if(!decoder->private_->is_seeking)
  89671. break;
  89672. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89673. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89674. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89675. if (pos == (FLAC__int64)lower_bound) {
  89676. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89677. return false;
  89678. }
  89679. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89680. continue;
  89681. }
  89682. first_seek = false;
  89683. if (this_frame_sample < lower_bound_sample) {
  89684. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89685. return false;
  89686. }
  89687. if(target_sample < this_frame_sample) {
  89688. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89689. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89690. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89691. return false;
  89692. }
  89693. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89694. }
  89695. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89696. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89697. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89698. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89699. return false;
  89700. }
  89701. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89702. }
  89703. }
  89704. return true;
  89705. }
  89706. #if FLAC__HAS_OGG
  89707. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89708. {
  89709. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89710. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89711. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89712. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89713. FLAC__bool did_a_seek;
  89714. unsigned iteration = 0;
  89715. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89716. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89717. if(right_sample == 0) {
  89718. right_sample = (FLAC__uint64)(-1);
  89719. BINARY_SEARCH_AFTER_ITERATION = 0;
  89720. }
  89721. decoder->private_->target_sample = target_sample;
  89722. for( ; ; iteration++) {
  89723. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89724. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89725. pos = (right_pos + left_pos) / 2;
  89726. }
  89727. else {
  89728. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89729. #if defined _MSC_VER || defined __MINGW32__
  89730. 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));
  89731. #else
  89732. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89733. #endif
  89734. #else
  89735. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89736. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89737. else /* @@@ WATCHOUT, ~2TB limit */
  89738. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89739. #endif
  89740. }
  89741. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89742. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89743. return false;
  89744. }
  89745. if(!FLAC__stream_decoder_flush(decoder)) {
  89746. return false;
  89747. }
  89748. did_a_seek = true;
  89749. }
  89750. else
  89751. did_a_seek = false;
  89752. decoder->private_->got_a_frame = false;
  89753. if(!FLAC__stream_decoder_process_single(decoder)) {
  89754. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89755. return false;
  89756. }
  89757. if(!decoder->private_->got_a_frame) {
  89758. if(did_a_seek) {
  89759. right_pos = pos;
  89760. BINARY_SEARCH_AFTER_ITERATION = 0;
  89761. }
  89762. else {
  89763. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89764. return false;
  89765. }
  89766. }
  89767. else if(!decoder->private_->is_seeking) {
  89768. break;
  89769. }
  89770. else {
  89771. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89772. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89773. if (did_a_seek) {
  89774. if (this_frame_sample <= target_sample) {
  89775. FLAC__ASSERT(this_frame_sample != target_sample);
  89776. left_sample = this_frame_sample;
  89777. if (left_pos == pos) {
  89778. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89779. return false;
  89780. }
  89781. left_pos = pos;
  89782. }
  89783. else if(this_frame_sample > target_sample) {
  89784. right_sample = this_frame_sample;
  89785. if (right_pos == pos) {
  89786. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89787. return false;
  89788. }
  89789. right_pos = pos;
  89790. }
  89791. }
  89792. }
  89793. }
  89794. return true;
  89795. }
  89796. #endif
  89797. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89798. {
  89799. (void)client_data;
  89800. if(*bytes > 0) {
  89801. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89802. if(ferror(decoder->private_->file))
  89803. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89804. else if(*bytes == 0)
  89805. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89806. else
  89807. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89808. }
  89809. else
  89810. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89811. }
  89812. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89813. {
  89814. (void)client_data;
  89815. if(decoder->private_->file == stdin)
  89816. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89817. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89818. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89819. else
  89820. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89821. }
  89822. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89823. {
  89824. off_t pos;
  89825. (void)client_data;
  89826. if(decoder->private_->file == stdin)
  89827. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89828. else if((pos = ftello(decoder->private_->file)) < 0)
  89829. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89830. else {
  89831. *absolute_byte_offset = (FLAC__uint64)pos;
  89832. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89833. }
  89834. }
  89835. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89836. {
  89837. struct stat filestats;
  89838. (void)client_data;
  89839. if(decoder->private_->file == stdin)
  89840. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89841. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89842. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89843. else {
  89844. *stream_length = (FLAC__uint64)filestats.st_size;
  89845. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89846. }
  89847. }
  89848. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89849. {
  89850. (void)client_data;
  89851. return feof(decoder->private_->file)? true : false;
  89852. }
  89853. #endif
  89854. /*** End of inlined file: stream_decoder.c ***/
  89855. /*** Start of inlined file: stream_encoder.c ***/
  89856. /*** Start of inlined file: juce_FlacHeader.h ***/
  89857. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89858. // tasks..
  89859. #define VERSION "1.2.1"
  89860. #define FLAC__NO_DLL 1
  89861. #if JUCE_MSVC
  89862. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89863. #endif
  89864. #if JUCE_MAC
  89865. #define FLAC__SYS_DARWIN 1
  89866. #endif
  89867. /*** End of inlined file: juce_FlacHeader.h ***/
  89868. #if JUCE_USE_FLAC
  89869. #if HAVE_CONFIG_H
  89870. # include <config.h>
  89871. #endif
  89872. #if defined _MSC_VER || defined __MINGW32__
  89873. #include <io.h> /* for _setmode() */
  89874. #include <fcntl.h> /* for _O_BINARY */
  89875. #endif
  89876. #if defined __CYGWIN__ || defined __EMX__
  89877. #include <io.h> /* for setmode(), O_BINARY */
  89878. #include <fcntl.h> /* for _O_BINARY */
  89879. #endif
  89880. #include <limits.h>
  89881. #include <stdio.h>
  89882. #include <stdlib.h> /* for malloc() */
  89883. #include <string.h> /* for memcpy() */
  89884. #include <sys/types.h> /* for off_t */
  89885. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89886. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89887. #define fseeko fseek
  89888. #define ftello ftell
  89889. #endif
  89890. #endif
  89891. /*** Start of inlined file: stream_encoder.h ***/
  89892. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89893. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89894. #if FLAC__HAS_OGG
  89895. #include "private/ogg_encoder_aspect.h"
  89896. #endif
  89897. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89898. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89899. typedef enum {
  89900. FLAC__APODIZATION_BARTLETT,
  89901. FLAC__APODIZATION_BARTLETT_HANN,
  89902. FLAC__APODIZATION_BLACKMAN,
  89903. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89904. FLAC__APODIZATION_CONNES,
  89905. FLAC__APODIZATION_FLATTOP,
  89906. FLAC__APODIZATION_GAUSS,
  89907. FLAC__APODIZATION_HAMMING,
  89908. FLAC__APODIZATION_HANN,
  89909. FLAC__APODIZATION_KAISER_BESSEL,
  89910. FLAC__APODIZATION_NUTTALL,
  89911. FLAC__APODIZATION_RECTANGLE,
  89912. FLAC__APODIZATION_TRIANGLE,
  89913. FLAC__APODIZATION_TUKEY,
  89914. FLAC__APODIZATION_WELCH
  89915. } FLAC__ApodizationFunction;
  89916. typedef struct {
  89917. FLAC__ApodizationFunction type;
  89918. union {
  89919. struct {
  89920. FLAC__real stddev;
  89921. } gauss;
  89922. struct {
  89923. FLAC__real p;
  89924. } tukey;
  89925. } parameters;
  89926. } FLAC__ApodizationSpecification;
  89927. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89928. typedef struct FLAC__StreamEncoderProtected {
  89929. FLAC__StreamEncoderState state;
  89930. FLAC__bool verify;
  89931. FLAC__bool streamable_subset;
  89932. FLAC__bool do_md5;
  89933. FLAC__bool do_mid_side_stereo;
  89934. FLAC__bool loose_mid_side_stereo;
  89935. unsigned channels;
  89936. unsigned bits_per_sample;
  89937. unsigned sample_rate;
  89938. unsigned blocksize;
  89939. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89940. unsigned num_apodizations;
  89941. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89942. #endif
  89943. unsigned max_lpc_order;
  89944. unsigned qlp_coeff_precision;
  89945. FLAC__bool do_qlp_coeff_prec_search;
  89946. FLAC__bool do_exhaustive_model_search;
  89947. FLAC__bool do_escape_coding;
  89948. unsigned min_residual_partition_order;
  89949. unsigned max_residual_partition_order;
  89950. unsigned rice_parameter_search_dist;
  89951. FLAC__uint64 total_samples_estimate;
  89952. FLAC__StreamMetadata **metadata;
  89953. unsigned num_metadata_blocks;
  89954. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89955. #if FLAC__HAS_OGG
  89956. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89957. #endif
  89958. } FLAC__StreamEncoderProtected;
  89959. #endif
  89960. /*** End of inlined file: stream_encoder.h ***/
  89961. #if FLAC__HAS_OGG
  89962. #include "include/private/ogg_helper.h"
  89963. #include "include/private/ogg_mapping.h"
  89964. #endif
  89965. /*** Start of inlined file: stream_encoder_framing.h ***/
  89966. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89967. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89968. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89969. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89970. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89971. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89972. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89973. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89974. #endif
  89975. /*** End of inlined file: stream_encoder_framing.h ***/
  89976. /*** Start of inlined file: window.h ***/
  89977. #ifndef FLAC__PRIVATE__WINDOW_H
  89978. #define FLAC__PRIVATE__WINDOW_H
  89979. #ifdef HAVE_CONFIG_H
  89980. #include <config.h>
  89981. #endif
  89982. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89983. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89984. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89985. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89986. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89987. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89988. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89989. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89990. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89991. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89992. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89993. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89994. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89995. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89996. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89997. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89998. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89999. #endif
  90000. /*** End of inlined file: window.h ***/
  90001. #ifndef FLaC__INLINE
  90002. #define FLaC__INLINE
  90003. #endif
  90004. #ifdef min
  90005. #undef min
  90006. #endif
  90007. #define min(x,y) ((x)<(y)?(x):(y))
  90008. #ifdef max
  90009. #undef max
  90010. #endif
  90011. #define max(x,y) ((x)>(y)?(x):(y))
  90012. #undef EXACT_RICE_BITS_CALCULATION
  90013. #undef ENABLE_RICE_PARAMETER_SEARCH
  90014. typedef struct {
  90015. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  90016. unsigned size; /* of each data[] in samples */
  90017. unsigned tail;
  90018. } verify_input_fifo;
  90019. typedef struct {
  90020. const FLAC__byte *data;
  90021. unsigned capacity;
  90022. unsigned bytes;
  90023. } verify_output;
  90024. typedef enum {
  90025. ENCODER_IN_MAGIC = 0,
  90026. ENCODER_IN_METADATA = 1,
  90027. ENCODER_IN_AUDIO = 2
  90028. } EncoderStateHint;
  90029. static struct CompressionLevels {
  90030. FLAC__bool do_mid_side_stereo;
  90031. FLAC__bool loose_mid_side_stereo;
  90032. unsigned max_lpc_order;
  90033. unsigned qlp_coeff_precision;
  90034. FLAC__bool do_qlp_coeff_prec_search;
  90035. FLAC__bool do_escape_coding;
  90036. FLAC__bool do_exhaustive_model_search;
  90037. unsigned min_residual_partition_order;
  90038. unsigned max_residual_partition_order;
  90039. unsigned rice_parameter_search_dist;
  90040. } compression_levels_[] = {
  90041. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  90042. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  90043. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  90044. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  90045. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  90046. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  90047. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  90048. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  90049. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  90050. };
  90051. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  90052. static void free_(FLAC__StreamEncoder *encoder);
  90053. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  90054. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  90055. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  90056. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  90057. #if FLAC__HAS_OGG
  90058. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  90059. #endif
  90060. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  90061. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  90062. static FLAC__bool process_subframe_(
  90063. FLAC__StreamEncoder *encoder,
  90064. unsigned min_partition_order,
  90065. unsigned max_partition_order,
  90066. const FLAC__FrameHeader *frame_header,
  90067. unsigned subframe_bps,
  90068. const FLAC__int32 integer_signal[],
  90069. FLAC__Subframe *subframe[2],
  90070. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  90071. FLAC__int32 *residual[2],
  90072. unsigned *best_subframe,
  90073. unsigned *best_bits
  90074. );
  90075. static FLAC__bool add_subframe_(
  90076. FLAC__StreamEncoder *encoder,
  90077. unsigned blocksize,
  90078. unsigned subframe_bps,
  90079. const FLAC__Subframe *subframe,
  90080. FLAC__BitWriter *frame
  90081. );
  90082. static unsigned evaluate_constant_subframe_(
  90083. FLAC__StreamEncoder *encoder,
  90084. const FLAC__int32 signal,
  90085. unsigned blocksize,
  90086. unsigned subframe_bps,
  90087. FLAC__Subframe *subframe
  90088. );
  90089. static unsigned evaluate_fixed_subframe_(
  90090. FLAC__StreamEncoder *encoder,
  90091. const FLAC__int32 signal[],
  90092. FLAC__int32 residual[],
  90093. FLAC__uint64 abs_residual_partition_sums[],
  90094. unsigned raw_bits_per_partition[],
  90095. unsigned blocksize,
  90096. unsigned subframe_bps,
  90097. unsigned order,
  90098. unsigned rice_parameter,
  90099. unsigned rice_parameter_limit,
  90100. unsigned min_partition_order,
  90101. unsigned max_partition_order,
  90102. FLAC__bool do_escape_coding,
  90103. unsigned rice_parameter_search_dist,
  90104. FLAC__Subframe *subframe,
  90105. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90106. );
  90107. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90108. static unsigned evaluate_lpc_subframe_(
  90109. FLAC__StreamEncoder *encoder,
  90110. const FLAC__int32 signal[],
  90111. FLAC__int32 residual[],
  90112. FLAC__uint64 abs_residual_partition_sums[],
  90113. unsigned raw_bits_per_partition[],
  90114. const FLAC__real lp_coeff[],
  90115. unsigned blocksize,
  90116. unsigned subframe_bps,
  90117. unsigned order,
  90118. unsigned qlp_coeff_precision,
  90119. unsigned rice_parameter,
  90120. unsigned rice_parameter_limit,
  90121. unsigned min_partition_order,
  90122. unsigned max_partition_order,
  90123. FLAC__bool do_escape_coding,
  90124. unsigned rice_parameter_search_dist,
  90125. FLAC__Subframe *subframe,
  90126. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90127. );
  90128. #endif
  90129. static unsigned evaluate_verbatim_subframe_(
  90130. FLAC__StreamEncoder *encoder,
  90131. const FLAC__int32 signal[],
  90132. unsigned blocksize,
  90133. unsigned subframe_bps,
  90134. FLAC__Subframe *subframe
  90135. );
  90136. static unsigned find_best_partition_order_(
  90137. struct FLAC__StreamEncoderPrivate *private_,
  90138. const FLAC__int32 residual[],
  90139. FLAC__uint64 abs_residual_partition_sums[],
  90140. unsigned raw_bits_per_partition[],
  90141. unsigned residual_samples,
  90142. unsigned predictor_order,
  90143. unsigned rice_parameter,
  90144. unsigned rice_parameter_limit,
  90145. unsigned min_partition_order,
  90146. unsigned max_partition_order,
  90147. unsigned bps,
  90148. FLAC__bool do_escape_coding,
  90149. unsigned rice_parameter_search_dist,
  90150. FLAC__EntropyCodingMethod *best_ecm
  90151. );
  90152. static void precompute_partition_info_sums_(
  90153. const FLAC__int32 residual[],
  90154. FLAC__uint64 abs_residual_partition_sums[],
  90155. unsigned residual_samples,
  90156. unsigned predictor_order,
  90157. unsigned min_partition_order,
  90158. unsigned max_partition_order,
  90159. unsigned bps
  90160. );
  90161. static void precompute_partition_info_escapes_(
  90162. const FLAC__int32 residual[],
  90163. unsigned raw_bits_per_partition[],
  90164. unsigned residual_samples,
  90165. unsigned predictor_order,
  90166. unsigned min_partition_order,
  90167. unsigned max_partition_order
  90168. );
  90169. static FLAC__bool set_partitioned_rice_(
  90170. #ifdef EXACT_RICE_BITS_CALCULATION
  90171. const FLAC__int32 residual[],
  90172. #endif
  90173. const FLAC__uint64 abs_residual_partition_sums[],
  90174. const unsigned raw_bits_per_partition[],
  90175. const unsigned residual_samples,
  90176. const unsigned predictor_order,
  90177. const unsigned suggested_rice_parameter,
  90178. const unsigned rice_parameter_limit,
  90179. const unsigned rice_parameter_search_dist,
  90180. const unsigned partition_order,
  90181. const FLAC__bool search_for_escapes,
  90182. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  90183. unsigned *bits
  90184. );
  90185. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  90186. static void append_to_verify_fifo_(
  90187. verify_input_fifo *fifo,
  90188. const FLAC__int32 * const input[],
  90189. unsigned input_offset,
  90190. unsigned channels,
  90191. unsigned wide_samples
  90192. );
  90193. static void append_to_verify_fifo_interleaved_(
  90194. verify_input_fifo *fifo,
  90195. const FLAC__int32 input[],
  90196. unsigned input_offset,
  90197. unsigned channels,
  90198. unsigned wide_samples
  90199. );
  90200. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90201. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  90202. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  90203. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  90204. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90205. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  90206. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  90207. 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);
  90208. static FILE *get_binary_stdout_(void);
  90209. typedef struct FLAC__StreamEncoderPrivate {
  90210. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  90211. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  90212. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  90213. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90214. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  90215. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  90216. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  90217. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  90218. #endif
  90219. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  90220. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  90221. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  90222. FLAC__int32 *residual_workspace_mid_side[2][2];
  90223. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  90224. FLAC__Subframe subframe_workspace_mid_side[2][2];
  90225. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90226. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  90227. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  90228. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  90229. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90230. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  90231. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  90232. unsigned best_subframe_mid_side[2];
  90233. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  90234. unsigned best_subframe_bits_mid_side[2];
  90235. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  90236. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  90237. FLAC__BitWriter *frame; /* the current frame being worked on */
  90238. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  90239. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  90240. FLAC__ChannelAssignment last_channel_assignment;
  90241. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  90242. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  90243. unsigned current_sample_number;
  90244. unsigned current_frame_number;
  90245. FLAC__MD5Context md5context;
  90246. FLAC__CPUInfo cpuinfo;
  90247. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90248. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90249. #else
  90250. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90251. #endif
  90252. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90253. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  90254. 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[]);
  90255. 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[]);
  90256. 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[]);
  90257. #endif
  90258. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  90259. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  90260. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  90261. FLAC__bool disable_constant_subframes;
  90262. FLAC__bool disable_fixed_subframes;
  90263. FLAC__bool disable_verbatim_subframes;
  90264. #if FLAC__HAS_OGG
  90265. FLAC__bool is_ogg;
  90266. #endif
  90267. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  90268. FLAC__StreamEncoderSeekCallback seek_callback;
  90269. FLAC__StreamEncoderTellCallback tell_callback;
  90270. FLAC__StreamEncoderWriteCallback write_callback;
  90271. FLAC__StreamEncoderMetadataCallback metadata_callback;
  90272. FLAC__StreamEncoderProgressCallback progress_callback;
  90273. void *client_data;
  90274. unsigned first_seekpoint_to_check;
  90275. FILE *file; /* only used when encoding to a file */
  90276. FLAC__uint64 bytes_written;
  90277. FLAC__uint64 samples_written;
  90278. unsigned frames_written;
  90279. unsigned total_frames_estimate;
  90280. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  90281. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  90282. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90283. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  90284. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  90285. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  90286. FLAC__real *windowed_signal_unaligned;
  90287. #endif
  90288. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  90289. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  90290. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  90291. unsigned *raw_bits_per_partition_unaligned;
  90292. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90293. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  90294. #endif
  90295. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  90296. struct {
  90297. FLAC__StreamDecoder *decoder;
  90298. EncoderStateHint state_hint;
  90299. FLAC__bool needs_magic_hack;
  90300. verify_input_fifo input_fifo;
  90301. verify_output output;
  90302. struct {
  90303. FLAC__uint64 absolute_sample;
  90304. unsigned frame_number;
  90305. unsigned channel;
  90306. unsigned sample;
  90307. FLAC__int32 expected;
  90308. FLAC__int32 got;
  90309. } error_stats;
  90310. } verify;
  90311. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  90312. } FLAC__StreamEncoderPrivate;
  90313. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  90314. "FLAC__STREAM_ENCODER_OK",
  90315. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  90316. "FLAC__STREAM_ENCODER_OGG_ERROR",
  90317. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  90318. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  90319. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90320. "FLAC__STREAM_ENCODER_IO_ERROR",
  90321. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90322. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90323. };
  90324. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90325. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90326. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90327. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90328. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90329. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90330. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90331. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90332. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90333. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90334. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90335. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90336. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90337. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90338. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90339. };
  90340. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90341. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90342. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90343. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90344. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90345. };
  90346. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90347. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90348. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90349. };
  90350. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90351. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90352. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90353. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90354. };
  90355. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90356. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90357. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90358. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90359. };
  90360. static const unsigned OVERREAD_ = 1;
  90361. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90362. {
  90363. FLAC__StreamEncoder *encoder;
  90364. unsigned i;
  90365. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90366. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90367. if(encoder == 0) {
  90368. return 0;
  90369. }
  90370. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90371. if(encoder->protected_ == 0) {
  90372. free(encoder);
  90373. return 0;
  90374. }
  90375. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90376. if(encoder->private_ == 0) {
  90377. free(encoder->protected_);
  90378. free(encoder);
  90379. return 0;
  90380. }
  90381. encoder->private_->frame = FLAC__bitwriter_new();
  90382. if(encoder->private_->frame == 0) {
  90383. free(encoder->private_);
  90384. free(encoder->protected_);
  90385. free(encoder);
  90386. return 0;
  90387. }
  90388. encoder->private_->file = 0;
  90389. set_defaults_enc(encoder);
  90390. encoder->private_->is_being_deleted = false;
  90391. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90392. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90393. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90394. }
  90395. for(i = 0; i < 2; i++) {
  90396. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90397. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90398. }
  90399. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90400. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90401. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90402. }
  90403. for(i = 0; i < 2; i++) {
  90404. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90405. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90406. }
  90407. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90408. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90409. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90410. }
  90411. for(i = 0; i < 2; i++) {
  90412. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90413. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90414. }
  90415. for(i = 0; i < 2; i++)
  90416. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90417. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90418. return encoder;
  90419. }
  90420. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90421. {
  90422. unsigned i;
  90423. FLAC__ASSERT(0 != encoder);
  90424. FLAC__ASSERT(0 != encoder->protected_);
  90425. FLAC__ASSERT(0 != encoder->private_);
  90426. FLAC__ASSERT(0 != encoder->private_->frame);
  90427. encoder->private_->is_being_deleted = true;
  90428. (void)FLAC__stream_encoder_finish(encoder);
  90429. if(0 != encoder->private_->verify.decoder)
  90430. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90431. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90432. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90433. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90434. }
  90435. for(i = 0; i < 2; i++) {
  90436. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90437. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90438. }
  90439. for(i = 0; i < 2; i++)
  90440. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90441. FLAC__bitwriter_delete(encoder->private_->frame);
  90442. free(encoder->private_);
  90443. free(encoder->protected_);
  90444. free(encoder);
  90445. }
  90446. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90447. FLAC__StreamEncoder *encoder,
  90448. FLAC__StreamEncoderReadCallback read_callback,
  90449. FLAC__StreamEncoderWriteCallback write_callback,
  90450. FLAC__StreamEncoderSeekCallback seek_callback,
  90451. FLAC__StreamEncoderTellCallback tell_callback,
  90452. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90453. void *client_data,
  90454. FLAC__bool is_ogg
  90455. )
  90456. {
  90457. unsigned i;
  90458. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90459. FLAC__ASSERT(0 != encoder);
  90460. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90461. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90462. #if !FLAC__HAS_OGG
  90463. if(is_ogg)
  90464. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90465. #endif
  90466. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90467. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90468. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90469. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90470. if(encoder->protected_->channels != 2) {
  90471. encoder->protected_->do_mid_side_stereo = false;
  90472. encoder->protected_->loose_mid_side_stereo = false;
  90473. }
  90474. else if(!encoder->protected_->do_mid_side_stereo)
  90475. encoder->protected_->loose_mid_side_stereo = false;
  90476. if(encoder->protected_->bits_per_sample >= 32)
  90477. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90478. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90479. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90480. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90481. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90482. if(encoder->protected_->blocksize == 0) {
  90483. if(encoder->protected_->max_lpc_order == 0)
  90484. encoder->protected_->blocksize = 1152;
  90485. else
  90486. encoder->protected_->blocksize = 4096;
  90487. }
  90488. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90489. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90490. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90491. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90492. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90493. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90494. if(encoder->protected_->qlp_coeff_precision == 0) {
  90495. if(encoder->protected_->bits_per_sample < 16) {
  90496. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90497. }
  90498. else if(encoder->protected_->bits_per_sample == 16) {
  90499. if(encoder->protected_->blocksize <= 192)
  90500. encoder->protected_->qlp_coeff_precision = 7;
  90501. else if(encoder->protected_->blocksize <= 384)
  90502. encoder->protected_->qlp_coeff_precision = 8;
  90503. else if(encoder->protected_->blocksize <= 576)
  90504. encoder->protected_->qlp_coeff_precision = 9;
  90505. else if(encoder->protected_->blocksize <= 1152)
  90506. encoder->protected_->qlp_coeff_precision = 10;
  90507. else if(encoder->protected_->blocksize <= 2304)
  90508. encoder->protected_->qlp_coeff_precision = 11;
  90509. else if(encoder->protected_->blocksize <= 4608)
  90510. encoder->protected_->qlp_coeff_precision = 12;
  90511. else
  90512. encoder->protected_->qlp_coeff_precision = 13;
  90513. }
  90514. else {
  90515. if(encoder->protected_->blocksize <= 384)
  90516. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90517. else if(encoder->protected_->blocksize <= 1152)
  90518. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90519. else
  90520. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90521. }
  90522. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90523. }
  90524. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90525. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90526. if(encoder->protected_->streamable_subset) {
  90527. if(
  90528. encoder->protected_->blocksize != 192 &&
  90529. encoder->protected_->blocksize != 576 &&
  90530. encoder->protected_->blocksize != 1152 &&
  90531. encoder->protected_->blocksize != 2304 &&
  90532. encoder->protected_->blocksize != 4608 &&
  90533. encoder->protected_->blocksize != 256 &&
  90534. encoder->protected_->blocksize != 512 &&
  90535. encoder->protected_->blocksize != 1024 &&
  90536. encoder->protected_->blocksize != 2048 &&
  90537. encoder->protected_->blocksize != 4096 &&
  90538. encoder->protected_->blocksize != 8192 &&
  90539. encoder->protected_->blocksize != 16384
  90540. )
  90541. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90542. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90543. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90544. if(
  90545. encoder->protected_->bits_per_sample != 8 &&
  90546. encoder->protected_->bits_per_sample != 12 &&
  90547. encoder->protected_->bits_per_sample != 16 &&
  90548. encoder->protected_->bits_per_sample != 20 &&
  90549. encoder->protected_->bits_per_sample != 24
  90550. )
  90551. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90552. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90553. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90554. if(
  90555. encoder->protected_->sample_rate <= 48000 &&
  90556. (
  90557. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90558. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90559. )
  90560. ) {
  90561. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90562. }
  90563. }
  90564. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90565. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90566. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90567. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90568. #if FLAC__HAS_OGG
  90569. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90570. unsigned i;
  90571. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90572. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90573. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90574. for( ; i > 0; i--)
  90575. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90576. encoder->protected_->metadata[0] = vc;
  90577. break;
  90578. }
  90579. }
  90580. }
  90581. #endif
  90582. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90583. unsigned i;
  90584. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90585. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90586. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90587. break; /* take only the first one */
  90588. }
  90589. }
  90590. }
  90591. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90592. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90593. metadata_has_seektable = false;
  90594. metadata_has_vorbis_comment = false;
  90595. metadata_picture_has_type1 = false;
  90596. metadata_picture_has_type2 = false;
  90597. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90598. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90599. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90600. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90601. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90602. if(metadata_has_seektable) /* only one is allowed */
  90603. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90604. metadata_has_seektable = true;
  90605. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90606. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90607. }
  90608. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90609. if(metadata_has_vorbis_comment) /* only one is allowed */
  90610. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90611. metadata_has_vorbis_comment = true;
  90612. }
  90613. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90614. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90615. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90616. }
  90617. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90618. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90619. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90620. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90621. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90622. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90623. metadata_picture_has_type1 = true;
  90624. if(
  90625. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90626. (
  90627. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90628. m->data.picture.width != 32 ||
  90629. m->data.picture.height != 32
  90630. )
  90631. )
  90632. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90633. }
  90634. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90635. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90636. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90637. metadata_picture_has_type2 = true;
  90638. }
  90639. }
  90640. }
  90641. encoder->private_->input_capacity = 0;
  90642. for(i = 0; i < encoder->protected_->channels; i++) {
  90643. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90644. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90645. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90646. #endif
  90647. }
  90648. for(i = 0; i < 2; i++) {
  90649. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90650. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90651. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90652. #endif
  90653. }
  90654. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90655. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90656. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90657. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90658. #endif
  90659. for(i = 0; i < encoder->protected_->channels; i++) {
  90660. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90661. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90662. encoder->private_->best_subframe[i] = 0;
  90663. }
  90664. for(i = 0; i < 2; i++) {
  90665. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90666. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90667. encoder->private_->best_subframe_mid_side[i] = 0;
  90668. }
  90669. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90670. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90671. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90672. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90673. #else
  90674. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90675. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90676. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90677. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90678. 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);
  90679. #endif
  90680. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90681. encoder->private_->loose_mid_side_stereo_frames = 1;
  90682. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90683. encoder->private_->current_sample_number = 0;
  90684. encoder->private_->current_frame_number = 0;
  90685. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90686. 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? */
  90687. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90688. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90689. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90690. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90691. #endif
  90692. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90693. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90694. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90695. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90696. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90697. #endif
  90698. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90699. # ifndef FLAC__NO_ASM
  90700. if(encoder->private_->cpuinfo.use_asm) {
  90701. # ifdef FLAC__CPU_IA32
  90702. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90703. # ifdef FLAC__HAS_NASM
  90704. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90705. if(encoder->protected_->max_lpc_order < 4)
  90706. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90707. else if(encoder->protected_->max_lpc_order < 8)
  90708. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90709. else if(encoder->protected_->max_lpc_order < 12)
  90710. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90711. else
  90712. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90713. }
  90714. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90715. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90716. else
  90717. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90718. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90719. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90720. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90721. }
  90722. else {
  90723. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90724. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90725. }
  90726. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90727. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90728. # endif /* FLAC__HAS_NASM */
  90729. # endif /* FLAC__CPU_IA32 */
  90730. }
  90731. # endif /* !FLAC__NO_ASM */
  90732. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90733. if(encoder->private_->use_wide_by_block) {
  90734. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90735. }
  90736. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90737. #if FLAC__HAS_OGG
  90738. encoder->private_->is_ogg = is_ogg;
  90739. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90740. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90741. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90742. }
  90743. #endif
  90744. encoder->private_->read_callback = read_callback;
  90745. encoder->private_->write_callback = write_callback;
  90746. encoder->private_->seek_callback = seek_callback;
  90747. encoder->private_->tell_callback = tell_callback;
  90748. encoder->private_->metadata_callback = metadata_callback;
  90749. encoder->private_->client_data = client_data;
  90750. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90751. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90752. }
  90753. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90754. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90755. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90756. }
  90757. if(encoder->protected_->verify) {
  90758. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90759. for(i = 0; i < encoder->protected_->channels; i++) {
  90760. 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))) {
  90761. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90762. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90763. }
  90764. }
  90765. encoder->private_->verify.input_fifo.tail = 0;
  90766. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90767. if(0 == encoder->private_->verify.decoder) {
  90768. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90769. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90770. }
  90771. 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) {
  90772. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90773. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90774. }
  90775. }
  90776. encoder->private_->verify.error_stats.absolute_sample = 0;
  90777. encoder->private_->verify.error_stats.frame_number = 0;
  90778. encoder->private_->verify.error_stats.channel = 0;
  90779. encoder->private_->verify.error_stats.sample = 0;
  90780. encoder->private_->verify.error_stats.expected = 0;
  90781. encoder->private_->verify.error_stats.got = 0;
  90782. encoder->private_->first_seekpoint_to_check = 0;
  90783. encoder->private_->samples_written = 0;
  90784. encoder->protected_->streaminfo_offset = 0;
  90785. encoder->protected_->seektable_offset = 0;
  90786. encoder->protected_->audio_offset = 0;
  90787. if(encoder->protected_->verify)
  90788. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90789. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90790. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90791. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90792. }
  90793. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90794. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90795. }
  90796. if(encoder->protected_->verify)
  90797. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90798. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90799. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90800. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90801. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90802. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90803. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90804. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90805. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90806. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90807. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90808. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90809. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90810. if(encoder->protected_->do_md5)
  90811. FLAC__MD5Init(&encoder->private_->md5context);
  90812. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90813. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90814. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90815. }
  90816. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90817. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90818. }
  90819. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90820. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90821. if(!metadata_has_vorbis_comment) {
  90822. FLAC__StreamMetadata vorbis_comment;
  90823. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90824. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90825. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90826. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90827. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90828. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90829. vorbis_comment.data.vorbis_comment.comments = 0;
  90830. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90831. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90832. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90833. }
  90834. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90835. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90836. }
  90837. }
  90838. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90839. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90840. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90841. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90842. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90843. }
  90844. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90845. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90846. }
  90847. }
  90848. 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 */
  90849. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90850. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90851. }
  90852. if(encoder->protected_->verify)
  90853. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90854. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90855. }
  90856. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90857. FLAC__StreamEncoder *encoder,
  90858. FLAC__StreamEncoderWriteCallback write_callback,
  90859. FLAC__StreamEncoderSeekCallback seek_callback,
  90860. FLAC__StreamEncoderTellCallback tell_callback,
  90861. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90862. void *client_data
  90863. )
  90864. {
  90865. return init_stream_internal_enc(
  90866. encoder,
  90867. 0,
  90868. write_callback,
  90869. seek_callback,
  90870. tell_callback,
  90871. metadata_callback,
  90872. client_data,
  90873. false
  90874. );
  90875. }
  90876. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90877. FLAC__StreamEncoder *encoder,
  90878. FLAC__StreamEncoderReadCallback read_callback,
  90879. FLAC__StreamEncoderWriteCallback write_callback,
  90880. FLAC__StreamEncoderSeekCallback seek_callback,
  90881. FLAC__StreamEncoderTellCallback tell_callback,
  90882. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90883. void *client_data
  90884. )
  90885. {
  90886. return init_stream_internal_enc(
  90887. encoder,
  90888. read_callback,
  90889. write_callback,
  90890. seek_callback,
  90891. tell_callback,
  90892. metadata_callback,
  90893. client_data,
  90894. true
  90895. );
  90896. }
  90897. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90898. FLAC__StreamEncoder *encoder,
  90899. FILE *file,
  90900. FLAC__StreamEncoderProgressCallback progress_callback,
  90901. void *client_data,
  90902. FLAC__bool is_ogg
  90903. )
  90904. {
  90905. FLAC__StreamEncoderInitStatus init_status;
  90906. FLAC__ASSERT(0 != encoder);
  90907. FLAC__ASSERT(0 != file);
  90908. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90909. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90910. if(file == 0) {
  90911. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90912. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90913. }
  90914. if(file == stdout)
  90915. file = get_binary_stdout_(); /* just to be safe */
  90916. encoder->private_->file = file;
  90917. encoder->private_->progress_callback = progress_callback;
  90918. encoder->private_->bytes_written = 0;
  90919. encoder->private_->samples_written = 0;
  90920. encoder->private_->frames_written = 0;
  90921. init_status = init_stream_internal_enc(
  90922. encoder,
  90923. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90924. file_write_callback_,
  90925. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90926. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90927. 0,
  90928. client_data,
  90929. is_ogg
  90930. );
  90931. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90932. return init_status;
  90933. }
  90934. {
  90935. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90936. FLAC__ASSERT(blocksize != 0);
  90937. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90938. }
  90939. return init_status;
  90940. }
  90941. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90942. FLAC__StreamEncoder *encoder,
  90943. FILE *file,
  90944. FLAC__StreamEncoderProgressCallback progress_callback,
  90945. void *client_data
  90946. )
  90947. {
  90948. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90949. }
  90950. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90951. FLAC__StreamEncoder *encoder,
  90952. FILE *file,
  90953. FLAC__StreamEncoderProgressCallback progress_callback,
  90954. void *client_data
  90955. )
  90956. {
  90957. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90958. }
  90959. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90960. FLAC__StreamEncoder *encoder,
  90961. const char *filename,
  90962. FLAC__StreamEncoderProgressCallback progress_callback,
  90963. void *client_data,
  90964. FLAC__bool is_ogg
  90965. )
  90966. {
  90967. FILE *file;
  90968. FLAC__ASSERT(0 != encoder);
  90969. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90970. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90971. file = filename? fopen(filename, "w+b") : stdout;
  90972. if(file == 0) {
  90973. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90974. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90975. }
  90976. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90977. }
  90978. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90979. FLAC__StreamEncoder *encoder,
  90980. const char *filename,
  90981. FLAC__StreamEncoderProgressCallback progress_callback,
  90982. void *client_data
  90983. )
  90984. {
  90985. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90986. }
  90987. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90988. FLAC__StreamEncoder *encoder,
  90989. const char *filename,
  90990. FLAC__StreamEncoderProgressCallback progress_callback,
  90991. void *client_data
  90992. )
  90993. {
  90994. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90995. }
  90996. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90997. {
  90998. FLAC__bool error = false;
  90999. FLAC__ASSERT(0 != encoder);
  91000. FLAC__ASSERT(0 != encoder->private_);
  91001. FLAC__ASSERT(0 != encoder->protected_);
  91002. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  91003. return true;
  91004. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  91005. if(encoder->private_->current_sample_number != 0) {
  91006. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  91007. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  91008. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  91009. error = true;
  91010. }
  91011. }
  91012. if(encoder->protected_->do_md5)
  91013. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  91014. if(!encoder->private_->is_being_deleted) {
  91015. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  91016. if(encoder->private_->seek_callback) {
  91017. #if FLAC__HAS_OGG
  91018. if(encoder->private_->is_ogg)
  91019. update_ogg_metadata_(encoder);
  91020. else
  91021. #endif
  91022. update_metadata_(encoder);
  91023. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  91024. error = true;
  91025. }
  91026. if(encoder->private_->metadata_callback)
  91027. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  91028. }
  91029. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  91030. if(!error)
  91031. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  91032. error = true;
  91033. }
  91034. }
  91035. if(0 != encoder->private_->file) {
  91036. if(encoder->private_->file != stdout)
  91037. fclose(encoder->private_->file);
  91038. encoder->private_->file = 0;
  91039. }
  91040. #if FLAC__HAS_OGG
  91041. if(encoder->private_->is_ogg)
  91042. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  91043. #endif
  91044. free_(encoder);
  91045. set_defaults_enc(encoder);
  91046. if(!error)
  91047. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  91048. return !error;
  91049. }
  91050. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  91051. {
  91052. FLAC__ASSERT(0 != encoder);
  91053. FLAC__ASSERT(0 != encoder->private_);
  91054. FLAC__ASSERT(0 != encoder->protected_);
  91055. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91056. return false;
  91057. #if FLAC__HAS_OGG
  91058. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  91059. return true;
  91060. #else
  91061. (void)value;
  91062. return false;
  91063. #endif
  91064. }
  91065. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91066. {
  91067. FLAC__ASSERT(0 != encoder);
  91068. FLAC__ASSERT(0 != encoder->private_);
  91069. FLAC__ASSERT(0 != encoder->protected_);
  91070. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91071. return false;
  91072. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91073. encoder->protected_->verify = value;
  91074. #endif
  91075. return true;
  91076. }
  91077. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91078. {
  91079. FLAC__ASSERT(0 != encoder);
  91080. FLAC__ASSERT(0 != encoder->private_);
  91081. FLAC__ASSERT(0 != encoder->protected_);
  91082. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91083. return false;
  91084. encoder->protected_->streamable_subset = value;
  91085. return true;
  91086. }
  91087. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91088. {
  91089. FLAC__ASSERT(0 != encoder);
  91090. FLAC__ASSERT(0 != encoder->private_);
  91091. FLAC__ASSERT(0 != encoder->protected_);
  91092. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91093. return false;
  91094. encoder->protected_->do_md5 = value;
  91095. return true;
  91096. }
  91097. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  91098. {
  91099. FLAC__ASSERT(0 != encoder);
  91100. FLAC__ASSERT(0 != encoder->private_);
  91101. FLAC__ASSERT(0 != encoder->protected_);
  91102. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91103. return false;
  91104. encoder->protected_->channels = value;
  91105. return true;
  91106. }
  91107. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  91108. {
  91109. FLAC__ASSERT(0 != encoder);
  91110. FLAC__ASSERT(0 != encoder->private_);
  91111. FLAC__ASSERT(0 != encoder->protected_);
  91112. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91113. return false;
  91114. encoder->protected_->bits_per_sample = value;
  91115. return true;
  91116. }
  91117. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  91118. {
  91119. FLAC__ASSERT(0 != encoder);
  91120. FLAC__ASSERT(0 != encoder->private_);
  91121. FLAC__ASSERT(0 != encoder->protected_);
  91122. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91123. return false;
  91124. encoder->protected_->sample_rate = value;
  91125. return true;
  91126. }
  91127. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  91128. {
  91129. FLAC__bool ok = true;
  91130. FLAC__ASSERT(0 != encoder);
  91131. FLAC__ASSERT(0 != encoder->private_);
  91132. FLAC__ASSERT(0 != encoder->protected_);
  91133. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91134. return false;
  91135. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  91136. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  91137. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  91138. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  91139. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91140. #if 0
  91141. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  91142. #else
  91143. encoder->protected_->num_apodizations = 1;
  91144. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91145. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91146. #endif
  91147. #endif
  91148. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  91149. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  91150. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  91151. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  91152. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  91153. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  91154. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  91155. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  91156. return ok;
  91157. }
  91158. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  91159. {
  91160. FLAC__ASSERT(0 != encoder);
  91161. FLAC__ASSERT(0 != encoder->private_);
  91162. FLAC__ASSERT(0 != encoder->protected_);
  91163. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91164. return false;
  91165. encoder->protected_->blocksize = value;
  91166. return true;
  91167. }
  91168. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91169. {
  91170. FLAC__ASSERT(0 != encoder);
  91171. FLAC__ASSERT(0 != encoder->private_);
  91172. FLAC__ASSERT(0 != encoder->protected_);
  91173. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91174. return false;
  91175. encoder->protected_->do_mid_side_stereo = value;
  91176. return true;
  91177. }
  91178. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91179. {
  91180. FLAC__ASSERT(0 != encoder);
  91181. FLAC__ASSERT(0 != encoder->private_);
  91182. FLAC__ASSERT(0 != encoder->protected_);
  91183. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91184. return false;
  91185. encoder->protected_->loose_mid_side_stereo = value;
  91186. return true;
  91187. }
  91188. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  91189. {
  91190. FLAC__ASSERT(0 != encoder);
  91191. FLAC__ASSERT(0 != encoder->private_);
  91192. FLAC__ASSERT(0 != encoder->protected_);
  91193. FLAC__ASSERT(0 != specification);
  91194. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91195. return false;
  91196. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  91197. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  91198. #else
  91199. encoder->protected_->num_apodizations = 0;
  91200. while(1) {
  91201. const char *s = strchr(specification, ';');
  91202. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  91203. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  91204. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  91205. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  91206. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  91207. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  91208. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  91209. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  91210. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  91211. else if(n==6 && 0 == strncmp("connes" , specification, n))
  91212. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  91213. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  91214. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  91215. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  91216. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  91217. if (stddev > 0.0 && stddev <= 0.5) {
  91218. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  91219. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  91220. }
  91221. }
  91222. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  91223. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  91224. else if(n==4 && 0 == strncmp("hann" , specification, n))
  91225. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  91226. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  91227. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  91228. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  91229. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  91230. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  91231. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  91232. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  91233. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  91234. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  91235. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  91236. if (p >= 0.0 && p <= 1.0) {
  91237. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  91238. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  91239. }
  91240. }
  91241. else if(n==5 && 0 == strncmp("welch" , specification, n))
  91242. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  91243. if (encoder->protected_->num_apodizations == 32)
  91244. break;
  91245. if (s)
  91246. specification = s+1;
  91247. else
  91248. break;
  91249. }
  91250. if(encoder->protected_->num_apodizations == 0) {
  91251. encoder->protected_->num_apodizations = 1;
  91252. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91253. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91254. }
  91255. #endif
  91256. return true;
  91257. }
  91258. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  91259. {
  91260. FLAC__ASSERT(0 != encoder);
  91261. FLAC__ASSERT(0 != encoder->private_);
  91262. FLAC__ASSERT(0 != encoder->protected_);
  91263. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91264. return false;
  91265. encoder->protected_->max_lpc_order = value;
  91266. return true;
  91267. }
  91268. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  91269. {
  91270. FLAC__ASSERT(0 != encoder);
  91271. FLAC__ASSERT(0 != encoder->private_);
  91272. FLAC__ASSERT(0 != encoder->protected_);
  91273. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91274. return false;
  91275. encoder->protected_->qlp_coeff_precision = value;
  91276. return true;
  91277. }
  91278. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91279. {
  91280. FLAC__ASSERT(0 != encoder);
  91281. FLAC__ASSERT(0 != encoder->private_);
  91282. FLAC__ASSERT(0 != encoder->protected_);
  91283. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91284. return false;
  91285. encoder->protected_->do_qlp_coeff_prec_search = value;
  91286. return true;
  91287. }
  91288. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91289. {
  91290. FLAC__ASSERT(0 != encoder);
  91291. FLAC__ASSERT(0 != encoder->private_);
  91292. FLAC__ASSERT(0 != encoder->protected_);
  91293. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91294. return false;
  91295. #if 0
  91296. encoder->protected_->do_escape_coding = value;
  91297. #else
  91298. (void)value;
  91299. #endif
  91300. return true;
  91301. }
  91302. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91303. {
  91304. FLAC__ASSERT(0 != encoder);
  91305. FLAC__ASSERT(0 != encoder->private_);
  91306. FLAC__ASSERT(0 != encoder->protected_);
  91307. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91308. return false;
  91309. encoder->protected_->do_exhaustive_model_search = value;
  91310. return true;
  91311. }
  91312. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91313. {
  91314. FLAC__ASSERT(0 != encoder);
  91315. FLAC__ASSERT(0 != encoder->private_);
  91316. FLAC__ASSERT(0 != encoder->protected_);
  91317. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91318. return false;
  91319. encoder->protected_->min_residual_partition_order = value;
  91320. return true;
  91321. }
  91322. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91323. {
  91324. FLAC__ASSERT(0 != encoder);
  91325. FLAC__ASSERT(0 != encoder->private_);
  91326. FLAC__ASSERT(0 != encoder->protected_);
  91327. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91328. return false;
  91329. encoder->protected_->max_residual_partition_order = value;
  91330. return true;
  91331. }
  91332. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91333. {
  91334. FLAC__ASSERT(0 != encoder);
  91335. FLAC__ASSERT(0 != encoder->private_);
  91336. FLAC__ASSERT(0 != encoder->protected_);
  91337. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91338. return false;
  91339. #if 0
  91340. encoder->protected_->rice_parameter_search_dist = value;
  91341. #else
  91342. (void)value;
  91343. #endif
  91344. return true;
  91345. }
  91346. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91347. {
  91348. FLAC__ASSERT(0 != encoder);
  91349. FLAC__ASSERT(0 != encoder->private_);
  91350. FLAC__ASSERT(0 != encoder->protected_);
  91351. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91352. return false;
  91353. encoder->protected_->total_samples_estimate = value;
  91354. return true;
  91355. }
  91356. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91357. {
  91358. FLAC__ASSERT(0 != encoder);
  91359. FLAC__ASSERT(0 != encoder->private_);
  91360. FLAC__ASSERT(0 != encoder->protected_);
  91361. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91362. return false;
  91363. if(0 == metadata)
  91364. num_blocks = 0;
  91365. if(0 == num_blocks)
  91366. metadata = 0;
  91367. if(encoder->protected_->metadata) {
  91368. free(encoder->protected_->metadata);
  91369. encoder->protected_->metadata = 0;
  91370. encoder->protected_->num_metadata_blocks = 0;
  91371. }
  91372. if(num_blocks) {
  91373. FLAC__StreamMetadata **m;
  91374. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91375. return false;
  91376. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91377. encoder->protected_->metadata = m;
  91378. encoder->protected_->num_metadata_blocks = num_blocks;
  91379. }
  91380. #if FLAC__HAS_OGG
  91381. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91382. return false;
  91383. #endif
  91384. return true;
  91385. }
  91386. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91387. {
  91388. FLAC__ASSERT(0 != encoder);
  91389. FLAC__ASSERT(0 != encoder->private_);
  91390. FLAC__ASSERT(0 != encoder->protected_);
  91391. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91392. return false;
  91393. encoder->private_->disable_constant_subframes = value;
  91394. return true;
  91395. }
  91396. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91397. {
  91398. FLAC__ASSERT(0 != encoder);
  91399. FLAC__ASSERT(0 != encoder->private_);
  91400. FLAC__ASSERT(0 != encoder->protected_);
  91401. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91402. return false;
  91403. encoder->private_->disable_fixed_subframes = value;
  91404. return true;
  91405. }
  91406. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91407. {
  91408. FLAC__ASSERT(0 != encoder);
  91409. FLAC__ASSERT(0 != encoder->private_);
  91410. FLAC__ASSERT(0 != encoder->protected_);
  91411. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91412. return false;
  91413. encoder->private_->disable_verbatim_subframes = value;
  91414. return true;
  91415. }
  91416. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91417. {
  91418. FLAC__ASSERT(0 != encoder);
  91419. FLAC__ASSERT(0 != encoder->private_);
  91420. FLAC__ASSERT(0 != encoder->protected_);
  91421. return encoder->protected_->state;
  91422. }
  91423. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91424. {
  91425. FLAC__ASSERT(0 != encoder);
  91426. FLAC__ASSERT(0 != encoder->private_);
  91427. FLAC__ASSERT(0 != encoder->protected_);
  91428. if(encoder->protected_->verify)
  91429. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91430. else
  91431. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91432. }
  91433. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91434. {
  91435. FLAC__ASSERT(0 != encoder);
  91436. FLAC__ASSERT(0 != encoder->private_);
  91437. FLAC__ASSERT(0 != encoder->protected_);
  91438. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91439. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91440. else
  91441. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91442. }
  91443. 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)
  91444. {
  91445. FLAC__ASSERT(0 != encoder);
  91446. FLAC__ASSERT(0 != encoder->private_);
  91447. FLAC__ASSERT(0 != encoder->protected_);
  91448. if(0 != absolute_sample)
  91449. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91450. if(0 != frame_number)
  91451. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91452. if(0 != channel)
  91453. *channel = encoder->private_->verify.error_stats.channel;
  91454. if(0 != sample)
  91455. *sample = encoder->private_->verify.error_stats.sample;
  91456. if(0 != expected)
  91457. *expected = encoder->private_->verify.error_stats.expected;
  91458. if(0 != got)
  91459. *got = encoder->private_->verify.error_stats.got;
  91460. }
  91461. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91462. {
  91463. FLAC__ASSERT(0 != encoder);
  91464. FLAC__ASSERT(0 != encoder->private_);
  91465. FLAC__ASSERT(0 != encoder->protected_);
  91466. return encoder->protected_->verify;
  91467. }
  91468. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91469. {
  91470. FLAC__ASSERT(0 != encoder);
  91471. FLAC__ASSERT(0 != encoder->private_);
  91472. FLAC__ASSERT(0 != encoder->protected_);
  91473. return encoder->protected_->streamable_subset;
  91474. }
  91475. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91476. {
  91477. FLAC__ASSERT(0 != encoder);
  91478. FLAC__ASSERT(0 != encoder->private_);
  91479. FLAC__ASSERT(0 != encoder->protected_);
  91480. return encoder->protected_->do_md5;
  91481. }
  91482. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91483. {
  91484. FLAC__ASSERT(0 != encoder);
  91485. FLAC__ASSERT(0 != encoder->private_);
  91486. FLAC__ASSERT(0 != encoder->protected_);
  91487. return encoder->protected_->channels;
  91488. }
  91489. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91490. {
  91491. FLAC__ASSERT(0 != encoder);
  91492. FLAC__ASSERT(0 != encoder->private_);
  91493. FLAC__ASSERT(0 != encoder->protected_);
  91494. return encoder->protected_->bits_per_sample;
  91495. }
  91496. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91497. {
  91498. FLAC__ASSERT(0 != encoder);
  91499. FLAC__ASSERT(0 != encoder->private_);
  91500. FLAC__ASSERT(0 != encoder->protected_);
  91501. return encoder->protected_->sample_rate;
  91502. }
  91503. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91504. {
  91505. FLAC__ASSERT(0 != encoder);
  91506. FLAC__ASSERT(0 != encoder->private_);
  91507. FLAC__ASSERT(0 != encoder->protected_);
  91508. return encoder->protected_->blocksize;
  91509. }
  91510. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91511. {
  91512. FLAC__ASSERT(0 != encoder);
  91513. FLAC__ASSERT(0 != encoder->private_);
  91514. FLAC__ASSERT(0 != encoder->protected_);
  91515. return encoder->protected_->do_mid_side_stereo;
  91516. }
  91517. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91518. {
  91519. FLAC__ASSERT(0 != encoder);
  91520. FLAC__ASSERT(0 != encoder->private_);
  91521. FLAC__ASSERT(0 != encoder->protected_);
  91522. return encoder->protected_->loose_mid_side_stereo;
  91523. }
  91524. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91525. {
  91526. FLAC__ASSERT(0 != encoder);
  91527. FLAC__ASSERT(0 != encoder->private_);
  91528. FLAC__ASSERT(0 != encoder->protected_);
  91529. return encoder->protected_->max_lpc_order;
  91530. }
  91531. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91532. {
  91533. FLAC__ASSERT(0 != encoder);
  91534. FLAC__ASSERT(0 != encoder->private_);
  91535. FLAC__ASSERT(0 != encoder->protected_);
  91536. return encoder->protected_->qlp_coeff_precision;
  91537. }
  91538. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91539. {
  91540. FLAC__ASSERT(0 != encoder);
  91541. FLAC__ASSERT(0 != encoder->private_);
  91542. FLAC__ASSERT(0 != encoder->protected_);
  91543. return encoder->protected_->do_qlp_coeff_prec_search;
  91544. }
  91545. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91546. {
  91547. FLAC__ASSERT(0 != encoder);
  91548. FLAC__ASSERT(0 != encoder->private_);
  91549. FLAC__ASSERT(0 != encoder->protected_);
  91550. return encoder->protected_->do_escape_coding;
  91551. }
  91552. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91553. {
  91554. FLAC__ASSERT(0 != encoder);
  91555. FLAC__ASSERT(0 != encoder->private_);
  91556. FLAC__ASSERT(0 != encoder->protected_);
  91557. return encoder->protected_->do_exhaustive_model_search;
  91558. }
  91559. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91560. {
  91561. FLAC__ASSERT(0 != encoder);
  91562. FLAC__ASSERT(0 != encoder->private_);
  91563. FLAC__ASSERT(0 != encoder->protected_);
  91564. return encoder->protected_->min_residual_partition_order;
  91565. }
  91566. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91567. {
  91568. FLAC__ASSERT(0 != encoder);
  91569. FLAC__ASSERT(0 != encoder->private_);
  91570. FLAC__ASSERT(0 != encoder->protected_);
  91571. return encoder->protected_->max_residual_partition_order;
  91572. }
  91573. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91574. {
  91575. FLAC__ASSERT(0 != encoder);
  91576. FLAC__ASSERT(0 != encoder->private_);
  91577. FLAC__ASSERT(0 != encoder->protected_);
  91578. return encoder->protected_->rice_parameter_search_dist;
  91579. }
  91580. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91581. {
  91582. FLAC__ASSERT(0 != encoder);
  91583. FLAC__ASSERT(0 != encoder->private_);
  91584. FLAC__ASSERT(0 != encoder->protected_);
  91585. return encoder->protected_->total_samples_estimate;
  91586. }
  91587. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91588. {
  91589. unsigned i, j = 0, channel;
  91590. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91591. FLAC__ASSERT(0 != encoder);
  91592. FLAC__ASSERT(0 != encoder->private_);
  91593. FLAC__ASSERT(0 != encoder->protected_);
  91594. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91595. do {
  91596. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91597. if(encoder->protected_->verify)
  91598. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91599. for(channel = 0; channel < channels; channel++)
  91600. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91601. if(encoder->protected_->do_mid_side_stereo) {
  91602. FLAC__ASSERT(channels == 2);
  91603. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91604. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91605. 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' ! */
  91606. }
  91607. }
  91608. else
  91609. j += n;
  91610. encoder->private_->current_sample_number += n;
  91611. if(encoder->private_->current_sample_number > blocksize) {
  91612. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91613. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91614. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91615. return false;
  91616. for(channel = 0; channel < channels; channel++)
  91617. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91618. if(encoder->protected_->do_mid_side_stereo) {
  91619. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91620. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91621. }
  91622. encoder->private_->current_sample_number = 1;
  91623. }
  91624. } while(j < samples);
  91625. return true;
  91626. }
  91627. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91628. {
  91629. unsigned i, j, k, channel;
  91630. FLAC__int32 x, mid, side;
  91631. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91632. FLAC__ASSERT(0 != encoder);
  91633. FLAC__ASSERT(0 != encoder->private_);
  91634. FLAC__ASSERT(0 != encoder->protected_);
  91635. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91636. j = k = 0;
  91637. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91638. do {
  91639. if(encoder->protected_->verify)
  91640. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91641. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91642. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91643. x = buffer[k++];
  91644. encoder->private_->integer_signal[1][i] = x;
  91645. mid += x;
  91646. side -= x;
  91647. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91648. encoder->private_->integer_signal_mid_side[1][i] = side;
  91649. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91650. }
  91651. encoder->private_->current_sample_number = i;
  91652. if(i > blocksize) {
  91653. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91654. return false;
  91655. /* move unprocessed overread samples to beginnings of arrays */
  91656. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91657. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91658. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91659. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91660. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91661. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91662. encoder->private_->current_sample_number = 1;
  91663. }
  91664. } while(j < samples);
  91665. }
  91666. else {
  91667. do {
  91668. if(encoder->protected_->verify)
  91669. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91670. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91671. for(channel = 0; channel < channels; channel++)
  91672. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91673. }
  91674. encoder->private_->current_sample_number = i;
  91675. if(i > blocksize) {
  91676. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91677. return false;
  91678. /* move unprocessed overread samples to beginnings of arrays */
  91679. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91680. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91681. for(channel = 0; channel < channels; channel++)
  91682. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91683. encoder->private_->current_sample_number = 1;
  91684. }
  91685. } while(j < samples);
  91686. }
  91687. return true;
  91688. }
  91689. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91690. {
  91691. FLAC__ASSERT(0 != encoder);
  91692. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91693. encoder->protected_->verify = true;
  91694. #else
  91695. encoder->protected_->verify = false;
  91696. #endif
  91697. encoder->protected_->streamable_subset = true;
  91698. encoder->protected_->do_md5 = true;
  91699. encoder->protected_->do_mid_side_stereo = false;
  91700. encoder->protected_->loose_mid_side_stereo = false;
  91701. encoder->protected_->channels = 2;
  91702. encoder->protected_->bits_per_sample = 16;
  91703. encoder->protected_->sample_rate = 44100;
  91704. encoder->protected_->blocksize = 0;
  91705. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91706. encoder->protected_->num_apodizations = 1;
  91707. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91708. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91709. #endif
  91710. encoder->protected_->max_lpc_order = 0;
  91711. encoder->protected_->qlp_coeff_precision = 0;
  91712. encoder->protected_->do_qlp_coeff_prec_search = false;
  91713. encoder->protected_->do_exhaustive_model_search = false;
  91714. encoder->protected_->do_escape_coding = false;
  91715. encoder->protected_->min_residual_partition_order = 0;
  91716. encoder->protected_->max_residual_partition_order = 0;
  91717. encoder->protected_->rice_parameter_search_dist = 0;
  91718. encoder->protected_->total_samples_estimate = 0;
  91719. encoder->protected_->metadata = 0;
  91720. encoder->protected_->num_metadata_blocks = 0;
  91721. encoder->private_->seek_table = 0;
  91722. encoder->private_->disable_constant_subframes = false;
  91723. encoder->private_->disable_fixed_subframes = false;
  91724. encoder->private_->disable_verbatim_subframes = false;
  91725. #if FLAC__HAS_OGG
  91726. encoder->private_->is_ogg = false;
  91727. #endif
  91728. encoder->private_->read_callback = 0;
  91729. encoder->private_->write_callback = 0;
  91730. encoder->private_->seek_callback = 0;
  91731. encoder->private_->tell_callback = 0;
  91732. encoder->private_->metadata_callback = 0;
  91733. encoder->private_->progress_callback = 0;
  91734. encoder->private_->client_data = 0;
  91735. #if FLAC__HAS_OGG
  91736. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91737. #endif
  91738. }
  91739. void free_(FLAC__StreamEncoder *encoder)
  91740. {
  91741. unsigned i, channel;
  91742. FLAC__ASSERT(0 != encoder);
  91743. if(encoder->protected_->metadata) {
  91744. free(encoder->protected_->metadata);
  91745. encoder->protected_->metadata = 0;
  91746. encoder->protected_->num_metadata_blocks = 0;
  91747. }
  91748. for(i = 0; i < encoder->protected_->channels; i++) {
  91749. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91750. free(encoder->private_->integer_signal_unaligned[i]);
  91751. encoder->private_->integer_signal_unaligned[i] = 0;
  91752. }
  91753. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91754. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91755. free(encoder->private_->real_signal_unaligned[i]);
  91756. encoder->private_->real_signal_unaligned[i] = 0;
  91757. }
  91758. #endif
  91759. }
  91760. for(i = 0; i < 2; i++) {
  91761. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91762. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91763. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91764. }
  91765. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91766. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91767. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91768. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91769. }
  91770. #endif
  91771. }
  91772. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91773. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91774. if(0 != encoder->private_->window_unaligned[i]) {
  91775. free(encoder->private_->window_unaligned[i]);
  91776. encoder->private_->window_unaligned[i] = 0;
  91777. }
  91778. }
  91779. if(0 != encoder->private_->windowed_signal_unaligned) {
  91780. free(encoder->private_->windowed_signal_unaligned);
  91781. encoder->private_->windowed_signal_unaligned = 0;
  91782. }
  91783. #endif
  91784. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91785. for(i = 0; i < 2; i++) {
  91786. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91787. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91788. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91789. }
  91790. }
  91791. }
  91792. for(channel = 0; channel < 2; channel++) {
  91793. for(i = 0; i < 2; i++) {
  91794. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91795. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91796. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91797. }
  91798. }
  91799. }
  91800. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91801. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91802. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91803. }
  91804. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91805. free(encoder->private_->raw_bits_per_partition_unaligned);
  91806. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91807. }
  91808. if(encoder->protected_->verify) {
  91809. for(i = 0; i < encoder->protected_->channels; i++) {
  91810. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91811. free(encoder->private_->verify.input_fifo.data[i]);
  91812. encoder->private_->verify.input_fifo.data[i] = 0;
  91813. }
  91814. }
  91815. }
  91816. FLAC__bitwriter_free(encoder->private_->frame);
  91817. }
  91818. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91819. {
  91820. FLAC__bool ok;
  91821. unsigned i, channel;
  91822. FLAC__ASSERT(new_blocksize > 0);
  91823. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91824. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91825. if(new_blocksize <= encoder->private_->input_capacity)
  91826. return true;
  91827. ok = true;
  91828. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91829. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91830. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91831. encoder->private_->integer_signal[i] += 4;
  91832. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91833. #if 0 /* @@@ currently unused */
  91834. if(encoder->protected_->max_lpc_order > 0)
  91835. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91836. #endif
  91837. #endif
  91838. }
  91839. for(i = 0; ok && i < 2; i++) {
  91840. 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]);
  91841. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91842. encoder->private_->integer_signal_mid_side[i] += 4;
  91843. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91844. #if 0 /* @@@ currently unused */
  91845. if(encoder->protected_->max_lpc_order > 0)
  91846. 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]);
  91847. #endif
  91848. #endif
  91849. }
  91850. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91851. if(ok && encoder->protected_->max_lpc_order > 0) {
  91852. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91853. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91854. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91855. }
  91856. #endif
  91857. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91858. for(i = 0; ok && i < 2; i++) {
  91859. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91860. }
  91861. }
  91862. for(channel = 0; ok && channel < 2; channel++) {
  91863. for(i = 0; ok && i < 2; i++) {
  91864. 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]);
  91865. }
  91866. }
  91867. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91868. if(encoder->protected_->do_escape_coding)
  91869. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91870. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91871. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91872. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91873. switch(encoder->protected_->apodizations[i].type) {
  91874. case FLAC__APODIZATION_BARTLETT:
  91875. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91876. break;
  91877. case FLAC__APODIZATION_BARTLETT_HANN:
  91878. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91879. break;
  91880. case FLAC__APODIZATION_BLACKMAN:
  91881. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91882. break;
  91883. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91884. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91885. break;
  91886. case FLAC__APODIZATION_CONNES:
  91887. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91888. break;
  91889. case FLAC__APODIZATION_FLATTOP:
  91890. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91891. break;
  91892. case FLAC__APODIZATION_GAUSS:
  91893. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91894. break;
  91895. case FLAC__APODIZATION_HAMMING:
  91896. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91897. break;
  91898. case FLAC__APODIZATION_HANN:
  91899. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91900. break;
  91901. case FLAC__APODIZATION_KAISER_BESSEL:
  91902. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91903. break;
  91904. case FLAC__APODIZATION_NUTTALL:
  91905. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91906. break;
  91907. case FLAC__APODIZATION_RECTANGLE:
  91908. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91909. break;
  91910. case FLAC__APODIZATION_TRIANGLE:
  91911. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91912. break;
  91913. case FLAC__APODIZATION_TUKEY:
  91914. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91915. break;
  91916. case FLAC__APODIZATION_WELCH:
  91917. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91918. break;
  91919. default:
  91920. FLAC__ASSERT(0);
  91921. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91922. break;
  91923. }
  91924. }
  91925. }
  91926. #endif
  91927. if(ok)
  91928. encoder->private_->input_capacity = new_blocksize;
  91929. else
  91930. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91931. return ok;
  91932. }
  91933. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91934. {
  91935. const FLAC__byte *buffer;
  91936. size_t bytes;
  91937. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91938. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91939. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91940. return false;
  91941. }
  91942. if(encoder->protected_->verify) {
  91943. encoder->private_->verify.output.data = buffer;
  91944. encoder->private_->verify.output.bytes = bytes;
  91945. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91946. encoder->private_->verify.needs_magic_hack = true;
  91947. }
  91948. else {
  91949. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91950. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91951. FLAC__bitwriter_clear(encoder->private_->frame);
  91952. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91953. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91954. return false;
  91955. }
  91956. }
  91957. }
  91958. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91959. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91960. FLAC__bitwriter_clear(encoder->private_->frame);
  91961. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91962. return false;
  91963. }
  91964. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91965. FLAC__bitwriter_clear(encoder->private_->frame);
  91966. if(samples > 0) {
  91967. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91968. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91969. }
  91970. return true;
  91971. }
  91972. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91973. {
  91974. FLAC__StreamEncoderWriteStatus status;
  91975. FLAC__uint64 output_position = 0;
  91976. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91977. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91978. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91979. }
  91980. if(samples == 0) {
  91981. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91982. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91983. encoder->protected_->streaminfo_offset = output_position;
  91984. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91985. encoder->protected_->seektable_offset = output_position;
  91986. }
  91987. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91988. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91989. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91990. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91991. FLAC__uint64 test_sample;
  91992. unsigned i;
  91993. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91994. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91995. if(test_sample > frame_last_sample) {
  91996. break;
  91997. }
  91998. else if(test_sample >= frame_first_sample) {
  91999. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  92000. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  92001. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  92002. encoder->private_->first_seekpoint_to_check++;
  92003. }
  92004. else {
  92005. encoder->private_->first_seekpoint_to_check++;
  92006. }
  92007. }
  92008. }
  92009. #if FLAC__HAS_OGG
  92010. if(encoder->private_->is_ogg) {
  92011. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  92012. &encoder->protected_->ogg_encoder_aspect,
  92013. buffer,
  92014. bytes,
  92015. samples,
  92016. encoder->private_->current_frame_number,
  92017. is_last_block,
  92018. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  92019. encoder,
  92020. encoder->private_->client_data
  92021. );
  92022. }
  92023. else
  92024. #endif
  92025. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  92026. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92027. encoder->private_->bytes_written += bytes;
  92028. encoder->private_->samples_written += samples;
  92029. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  92030. }
  92031. else
  92032. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92033. return status;
  92034. }
  92035. void update_metadata_(const FLAC__StreamEncoder *encoder)
  92036. {
  92037. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92038. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92039. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92040. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92041. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92042. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  92043. FLAC__StreamEncoderSeekStatus seek_status;
  92044. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92045. {
  92046. const unsigned md5_offset =
  92047. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92048. (
  92049. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92050. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92051. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92052. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92053. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92054. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92055. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92056. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92057. ) / 8;
  92058. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92059. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92060. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92061. return;
  92062. }
  92063. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92064. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92065. return;
  92066. }
  92067. }
  92068. {
  92069. const unsigned total_samples_byte_offset =
  92070. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92071. (
  92072. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92073. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92074. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92075. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92076. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92077. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92078. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92079. - 4
  92080. ) / 8;
  92081. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  92082. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92083. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92084. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92085. b[4] = (FLAC__byte)(samples & 0xFF);
  92086. 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) {
  92087. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92088. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92089. return;
  92090. }
  92091. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92092. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92093. return;
  92094. }
  92095. }
  92096. {
  92097. const unsigned min_framesize_offset =
  92098. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92099. (
  92100. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92101. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92102. ) / 8;
  92103. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92104. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92105. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92106. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92107. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92108. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92109. 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) {
  92110. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92111. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92112. return;
  92113. }
  92114. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92115. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92116. return;
  92117. }
  92118. }
  92119. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92120. unsigned i;
  92121. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92122. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92123. 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) {
  92124. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92125. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92126. return;
  92127. }
  92128. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  92129. FLAC__uint64 xx;
  92130. unsigned x;
  92131. xx = encoder->private_->seek_table->points[i].sample_number;
  92132. b[7] = (FLAC__byte)xx; xx >>= 8;
  92133. b[6] = (FLAC__byte)xx; xx >>= 8;
  92134. b[5] = (FLAC__byte)xx; xx >>= 8;
  92135. b[4] = (FLAC__byte)xx; xx >>= 8;
  92136. b[3] = (FLAC__byte)xx; xx >>= 8;
  92137. b[2] = (FLAC__byte)xx; xx >>= 8;
  92138. b[1] = (FLAC__byte)xx; xx >>= 8;
  92139. b[0] = (FLAC__byte)xx; xx >>= 8;
  92140. xx = encoder->private_->seek_table->points[i].stream_offset;
  92141. b[15] = (FLAC__byte)xx; xx >>= 8;
  92142. b[14] = (FLAC__byte)xx; xx >>= 8;
  92143. b[13] = (FLAC__byte)xx; xx >>= 8;
  92144. b[12] = (FLAC__byte)xx; xx >>= 8;
  92145. b[11] = (FLAC__byte)xx; xx >>= 8;
  92146. b[10] = (FLAC__byte)xx; xx >>= 8;
  92147. b[9] = (FLAC__byte)xx; xx >>= 8;
  92148. b[8] = (FLAC__byte)xx; xx >>= 8;
  92149. x = encoder->private_->seek_table->points[i].frame_samples;
  92150. b[17] = (FLAC__byte)x; x >>= 8;
  92151. b[16] = (FLAC__byte)x; x >>= 8;
  92152. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92153. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92154. return;
  92155. }
  92156. }
  92157. }
  92158. }
  92159. #if FLAC__HAS_OGG
  92160. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  92161. {
  92162. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  92163. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  92164. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  92165. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  92166. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  92167. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  92168. FLAC__STREAM_SYNC_LENGTH
  92169. ;
  92170. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92171. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92172. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92173. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92174. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92175. ogg_page page;
  92176. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92177. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  92178. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  92179. return;
  92180. simple_ogg_page__init(&page);
  92181. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92182. simple_ogg_page__clear(&page);
  92183. return; /* state already set */
  92184. }
  92185. {
  92186. const unsigned md5_offset =
  92187. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92188. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92189. (
  92190. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92191. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92192. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92193. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92194. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92195. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92196. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92197. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92198. ) / 8;
  92199. if(md5_offset + 16 > (unsigned)page.body_len) {
  92200. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92201. simple_ogg_page__clear(&page);
  92202. return;
  92203. }
  92204. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  92205. }
  92206. {
  92207. const unsigned total_samples_byte_offset =
  92208. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92209. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92210. (
  92211. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92212. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92213. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92214. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92215. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92216. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92217. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92218. - 4
  92219. ) / 8;
  92220. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  92221. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92222. simple_ogg_page__clear(&page);
  92223. return;
  92224. }
  92225. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  92226. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  92227. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92228. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92229. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92230. b[4] = (FLAC__byte)(samples & 0xFF);
  92231. memcpy(page.body + total_samples_byte_offset, b, 5);
  92232. }
  92233. {
  92234. const unsigned min_framesize_offset =
  92235. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92236. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92237. (
  92238. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92239. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92240. ) / 8;
  92241. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  92242. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92243. simple_ogg_page__clear(&page);
  92244. return;
  92245. }
  92246. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92247. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92248. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92249. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92250. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92251. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92252. memcpy(page.body + min_framesize_offset, b, 6);
  92253. }
  92254. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92255. simple_ogg_page__clear(&page);
  92256. return; /* state already set */
  92257. }
  92258. simple_ogg_page__clear(&page);
  92259. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92260. unsigned i;
  92261. FLAC__byte *p;
  92262. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92263. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92264. simple_ogg_page__init(&page);
  92265. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92266. simple_ogg_page__clear(&page);
  92267. return; /* state already set */
  92268. }
  92269. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  92270. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92271. simple_ogg_page__clear(&page);
  92272. return;
  92273. }
  92274. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  92275. FLAC__uint64 xx;
  92276. unsigned x;
  92277. xx = encoder->private_->seek_table->points[i].sample_number;
  92278. b[7] = (FLAC__byte)xx; xx >>= 8;
  92279. b[6] = (FLAC__byte)xx; xx >>= 8;
  92280. b[5] = (FLAC__byte)xx; xx >>= 8;
  92281. b[4] = (FLAC__byte)xx; xx >>= 8;
  92282. b[3] = (FLAC__byte)xx; xx >>= 8;
  92283. b[2] = (FLAC__byte)xx; xx >>= 8;
  92284. b[1] = (FLAC__byte)xx; xx >>= 8;
  92285. b[0] = (FLAC__byte)xx; xx >>= 8;
  92286. xx = encoder->private_->seek_table->points[i].stream_offset;
  92287. b[15] = (FLAC__byte)xx; xx >>= 8;
  92288. b[14] = (FLAC__byte)xx; xx >>= 8;
  92289. b[13] = (FLAC__byte)xx; xx >>= 8;
  92290. b[12] = (FLAC__byte)xx; xx >>= 8;
  92291. b[11] = (FLAC__byte)xx; xx >>= 8;
  92292. b[10] = (FLAC__byte)xx; xx >>= 8;
  92293. b[9] = (FLAC__byte)xx; xx >>= 8;
  92294. b[8] = (FLAC__byte)xx; xx >>= 8;
  92295. x = encoder->private_->seek_table->points[i].frame_samples;
  92296. b[17] = (FLAC__byte)x; x >>= 8;
  92297. b[16] = (FLAC__byte)x; x >>= 8;
  92298. memcpy(p, b, 18);
  92299. }
  92300. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92301. simple_ogg_page__clear(&page);
  92302. return; /* state already set */
  92303. }
  92304. simple_ogg_page__clear(&page);
  92305. }
  92306. }
  92307. #endif
  92308. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  92309. {
  92310. FLAC__uint16 crc;
  92311. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92312. 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)) {
  92313. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92314. return false;
  92315. }
  92316. if(!process_subframes_(encoder, is_fractional_block)) {
  92317. return false;
  92318. }
  92319. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92320. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92321. return false;
  92322. }
  92323. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92324. if(
  92325. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92326. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92327. ) {
  92328. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92329. return false;
  92330. }
  92331. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92332. return false;
  92333. }
  92334. encoder->private_->current_sample_number = 0;
  92335. encoder->private_->current_frame_number++;
  92336. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92337. return true;
  92338. }
  92339. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92340. {
  92341. FLAC__FrameHeader frame_header;
  92342. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92343. FLAC__bool do_independent, do_mid_side;
  92344. if(is_fractional_block) {
  92345. max_partition_order = 0;
  92346. }
  92347. else {
  92348. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92349. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92350. }
  92351. min_partition_order = min(min_partition_order, max_partition_order);
  92352. frame_header.blocksize = encoder->protected_->blocksize;
  92353. frame_header.sample_rate = encoder->protected_->sample_rate;
  92354. frame_header.channels = encoder->protected_->channels;
  92355. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92356. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92357. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92358. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92359. if(encoder->protected_->do_mid_side_stereo) {
  92360. if(encoder->protected_->loose_mid_side_stereo) {
  92361. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92362. do_independent = true;
  92363. do_mid_side = true;
  92364. }
  92365. else {
  92366. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92367. do_mid_side = !do_independent;
  92368. }
  92369. }
  92370. else {
  92371. do_independent = true;
  92372. do_mid_side = true;
  92373. }
  92374. }
  92375. else {
  92376. do_independent = true;
  92377. do_mid_side = false;
  92378. }
  92379. FLAC__ASSERT(do_independent || do_mid_side);
  92380. if(do_independent) {
  92381. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92382. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92383. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92384. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92385. }
  92386. }
  92387. if(do_mid_side) {
  92388. FLAC__ASSERT(encoder->protected_->channels == 2);
  92389. for(channel = 0; channel < 2; channel++) {
  92390. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92391. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92392. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92393. }
  92394. }
  92395. if(do_independent) {
  92396. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92397. if(!
  92398. process_subframe_(
  92399. encoder,
  92400. min_partition_order,
  92401. max_partition_order,
  92402. &frame_header,
  92403. encoder->private_->subframe_bps[channel],
  92404. encoder->private_->integer_signal[channel],
  92405. encoder->private_->subframe_workspace_ptr[channel],
  92406. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92407. encoder->private_->residual_workspace[channel],
  92408. encoder->private_->best_subframe+channel,
  92409. encoder->private_->best_subframe_bits+channel
  92410. )
  92411. )
  92412. return false;
  92413. }
  92414. }
  92415. if(do_mid_side) {
  92416. FLAC__ASSERT(encoder->protected_->channels == 2);
  92417. for(channel = 0; channel < 2; channel++) {
  92418. if(!
  92419. process_subframe_(
  92420. encoder,
  92421. min_partition_order,
  92422. max_partition_order,
  92423. &frame_header,
  92424. encoder->private_->subframe_bps_mid_side[channel],
  92425. encoder->private_->integer_signal_mid_side[channel],
  92426. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92427. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92428. encoder->private_->residual_workspace_mid_side[channel],
  92429. encoder->private_->best_subframe_mid_side+channel,
  92430. encoder->private_->best_subframe_bits_mid_side+channel
  92431. )
  92432. )
  92433. return false;
  92434. }
  92435. }
  92436. if(do_mid_side) {
  92437. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92438. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92439. FLAC__ChannelAssignment channel_assignment;
  92440. FLAC__ASSERT(encoder->protected_->channels == 2);
  92441. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92442. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92443. }
  92444. else {
  92445. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92446. unsigned min_bits;
  92447. int ca;
  92448. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92449. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92450. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92451. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92452. FLAC__ASSERT(do_independent && do_mid_side);
  92453. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92454. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92455. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92456. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92457. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92458. min_bits = bits[channel_assignment];
  92459. for(ca = 1; ca <= 3; ca++) {
  92460. if(bits[ca] < min_bits) {
  92461. min_bits = bits[ca];
  92462. channel_assignment = (FLAC__ChannelAssignment)ca;
  92463. }
  92464. }
  92465. }
  92466. frame_header.channel_assignment = channel_assignment;
  92467. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92468. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92469. return false;
  92470. }
  92471. switch(channel_assignment) {
  92472. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92473. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92474. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92475. break;
  92476. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92477. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92478. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92479. break;
  92480. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92481. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92482. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92483. break;
  92484. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92485. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92486. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92487. break;
  92488. default:
  92489. FLAC__ASSERT(0);
  92490. }
  92491. switch(channel_assignment) {
  92492. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92493. left_bps = encoder->private_->subframe_bps [0];
  92494. right_bps = encoder->private_->subframe_bps [1];
  92495. break;
  92496. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92497. left_bps = encoder->private_->subframe_bps [0];
  92498. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92499. break;
  92500. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92501. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92502. right_bps = encoder->private_->subframe_bps [1];
  92503. break;
  92504. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92505. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92506. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92507. break;
  92508. default:
  92509. FLAC__ASSERT(0);
  92510. }
  92511. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92512. return false;
  92513. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92514. return false;
  92515. }
  92516. else {
  92517. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92518. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92519. return false;
  92520. }
  92521. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92522. 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)) {
  92523. return false;
  92524. }
  92525. }
  92526. }
  92527. if(encoder->protected_->loose_mid_side_stereo) {
  92528. encoder->private_->loose_mid_side_stereo_frame_count++;
  92529. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92530. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92531. }
  92532. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92533. return true;
  92534. }
  92535. FLAC__bool process_subframe_(
  92536. FLAC__StreamEncoder *encoder,
  92537. unsigned min_partition_order,
  92538. unsigned max_partition_order,
  92539. const FLAC__FrameHeader *frame_header,
  92540. unsigned subframe_bps,
  92541. const FLAC__int32 integer_signal[],
  92542. FLAC__Subframe *subframe[2],
  92543. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92544. FLAC__int32 *residual[2],
  92545. unsigned *best_subframe,
  92546. unsigned *best_bits
  92547. )
  92548. {
  92549. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92550. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92551. #else
  92552. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92553. #endif
  92554. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92555. FLAC__double lpc_residual_bits_per_sample;
  92556. 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 */
  92557. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92558. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92559. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92560. #endif
  92561. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92562. unsigned rice_parameter;
  92563. unsigned _candidate_bits, _best_bits;
  92564. unsigned _best_subframe;
  92565. 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;
  92566. FLAC__ASSERT(frame_header->blocksize > 0);
  92567. _best_subframe = 0;
  92568. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92569. _best_bits = UINT_MAX;
  92570. else
  92571. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92572. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92573. unsigned signal_is_constant = false;
  92574. 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);
  92575. if(
  92576. !encoder->private_->disable_constant_subframes &&
  92577. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92578. fixed_residual_bits_per_sample[1] == 0.0
  92579. #else
  92580. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92581. #endif
  92582. ) {
  92583. unsigned i;
  92584. signal_is_constant = true;
  92585. for(i = 1; i < frame_header->blocksize; i++) {
  92586. if(integer_signal[0] != integer_signal[i]) {
  92587. signal_is_constant = false;
  92588. break;
  92589. }
  92590. }
  92591. }
  92592. if(signal_is_constant) {
  92593. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92594. if(_candidate_bits < _best_bits) {
  92595. _best_subframe = !_best_subframe;
  92596. _best_bits = _candidate_bits;
  92597. }
  92598. }
  92599. else {
  92600. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92601. if(encoder->protected_->do_exhaustive_model_search) {
  92602. min_fixed_order = 0;
  92603. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92604. }
  92605. else {
  92606. min_fixed_order = max_fixed_order = guess_fixed_order;
  92607. }
  92608. if(max_fixed_order >= frame_header->blocksize)
  92609. max_fixed_order = frame_header->blocksize - 1;
  92610. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92611. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92612. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92613. continue; /* don't even try */
  92614. 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 */
  92615. #else
  92616. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92617. continue; /* don't even try */
  92618. 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 */
  92619. #endif
  92620. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92621. if(rice_parameter >= rice_parameter_limit) {
  92622. #ifdef DEBUG_VERBOSE
  92623. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92624. #endif
  92625. rice_parameter = rice_parameter_limit - 1;
  92626. }
  92627. _candidate_bits =
  92628. evaluate_fixed_subframe_(
  92629. encoder,
  92630. integer_signal,
  92631. residual[!_best_subframe],
  92632. encoder->private_->abs_residual_partition_sums,
  92633. encoder->private_->raw_bits_per_partition,
  92634. frame_header->blocksize,
  92635. subframe_bps,
  92636. fixed_order,
  92637. rice_parameter,
  92638. rice_parameter_limit,
  92639. min_partition_order,
  92640. max_partition_order,
  92641. encoder->protected_->do_escape_coding,
  92642. encoder->protected_->rice_parameter_search_dist,
  92643. subframe[!_best_subframe],
  92644. partitioned_rice_contents[!_best_subframe]
  92645. );
  92646. if(_candidate_bits < _best_bits) {
  92647. _best_subframe = !_best_subframe;
  92648. _best_bits = _candidate_bits;
  92649. }
  92650. }
  92651. }
  92652. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92653. if(encoder->protected_->max_lpc_order > 0) {
  92654. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92655. max_lpc_order = frame_header->blocksize-1;
  92656. else
  92657. max_lpc_order = encoder->protected_->max_lpc_order;
  92658. if(max_lpc_order > 0) {
  92659. unsigned a;
  92660. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92661. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92662. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92663. if(autoc[0] != 0.0) {
  92664. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92665. if(encoder->protected_->do_exhaustive_model_search) {
  92666. min_lpc_order = 1;
  92667. }
  92668. else {
  92669. const unsigned guess_lpc_order =
  92670. FLAC__lpc_compute_best_order(
  92671. lpc_error,
  92672. max_lpc_order,
  92673. frame_header->blocksize,
  92674. subframe_bps + (
  92675. encoder->protected_->do_qlp_coeff_prec_search?
  92676. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92677. encoder->protected_->qlp_coeff_precision
  92678. )
  92679. );
  92680. min_lpc_order = max_lpc_order = guess_lpc_order;
  92681. }
  92682. if(max_lpc_order >= frame_header->blocksize)
  92683. max_lpc_order = frame_header->blocksize - 1;
  92684. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92685. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92686. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92687. continue; /* don't even try */
  92688. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92689. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92690. if(rice_parameter >= rice_parameter_limit) {
  92691. #ifdef DEBUG_VERBOSE
  92692. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92693. #endif
  92694. rice_parameter = rice_parameter_limit - 1;
  92695. }
  92696. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92697. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92698. if(subframe_bps <= 17) {
  92699. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92700. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92701. }
  92702. else
  92703. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92704. }
  92705. else {
  92706. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92707. }
  92708. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92709. _candidate_bits =
  92710. evaluate_lpc_subframe_(
  92711. encoder,
  92712. integer_signal,
  92713. residual[!_best_subframe],
  92714. encoder->private_->abs_residual_partition_sums,
  92715. encoder->private_->raw_bits_per_partition,
  92716. encoder->private_->lp_coeff[lpc_order-1],
  92717. frame_header->blocksize,
  92718. subframe_bps,
  92719. lpc_order,
  92720. qlp_coeff_precision,
  92721. rice_parameter,
  92722. rice_parameter_limit,
  92723. min_partition_order,
  92724. max_partition_order,
  92725. encoder->protected_->do_escape_coding,
  92726. encoder->protected_->rice_parameter_search_dist,
  92727. subframe[!_best_subframe],
  92728. partitioned_rice_contents[!_best_subframe]
  92729. );
  92730. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92731. if(_candidate_bits < _best_bits) {
  92732. _best_subframe = !_best_subframe;
  92733. _best_bits = _candidate_bits;
  92734. }
  92735. }
  92736. }
  92737. }
  92738. }
  92739. }
  92740. }
  92741. }
  92742. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92743. }
  92744. }
  92745. if(_best_bits == UINT_MAX) {
  92746. FLAC__ASSERT(_best_subframe == 0);
  92747. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92748. }
  92749. *best_subframe = _best_subframe;
  92750. *best_bits = _best_bits;
  92751. return true;
  92752. }
  92753. FLAC__bool add_subframe_(
  92754. FLAC__StreamEncoder *encoder,
  92755. unsigned blocksize,
  92756. unsigned subframe_bps,
  92757. const FLAC__Subframe *subframe,
  92758. FLAC__BitWriter *frame
  92759. )
  92760. {
  92761. switch(subframe->type) {
  92762. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92763. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92764. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92765. return false;
  92766. }
  92767. break;
  92768. case FLAC__SUBFRAME_TYPE_FIXED:
  92769. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92770. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92771. return false;
  92772. }
  92773. break;
  92774. case FLAC__SUBFRAME_TYPE_LPC:
  92775. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92776. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92777. return false;
  92778. }
  92779. break;
  92780. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92781. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92782. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92783. return false;
  92784. }
  92785. break;
  92786. default:
  92787. FLAC__ASSERT(0);
  92788. }
  92789. return true;
  92790. }
  92791. #define SPOTCHECK_ESTIMATE 0
  92792. #if SPOTCHECK_ESTIMATE
  92793. static void spotcheck_subframe_estimate_(
  92794. FLAC__StreamEncoder *encoder,
  92795. unsigned blocksize,
  92796. unsigned subframe_bps,
  92797. const FLAC__Subframe *subframe,
  92798. unsigned estimate
  92799. )
  92800. {
  92801. FLAC__bool ret;
  92802. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92803. if(frame == 0) {
  92804. fprintf(stderr, "EST: can't allocate frame\n");
  92805. return;
  92806. }
  92807. if(!FLAC__bitwriter_init(frame)) {
  92808. fprintf(stderr, "EST: can't init frame\n");
  92809. return;
  92810. }
  92811. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92812. FLAC__ASSERT(ret);
  92813. {
  92814. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92815. if(estimate != actual)
  92816. 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);
  92817. }
  92818. FLAC__bitwriter_delete(frame);
  92819. }
  92820. #endif
  92821. unsigned evaluate_constant_subframe_(
  92822. FLAC__StreamEncoder *encoder,
  92823. const FLAC__int32 signal,
  92824. unsigned blocksize,
  92825. unsigned subframe_bps,
  92826. FLAC__Subframe *subframe
  92827. )
  92828. {
  92829. unsigned estimate;
  92830. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92831. subframe->data.constant.value = signal;
  92832. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92833. #if SPOTCHECK_ESTIMATE
  92834. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92835. #else
  92836. (void)encoder, (void)blocksize;
  92837. #endif
  92838. return estimate;
  92839. }
  92840. unsigned evaluate_fixed_subframe_(
  92841. FLAC__StreamEncoder *encoder,
  92842. const FLAC__int32 signal[],
  92843. FLAC__int32 residual[],
  92844. FLAC__uint64 abs_residual_partition_sums[],
  92845. unsigned raw_bits_per_partition[],
  92846. unsigned blocksize,
  92847. unsigned subframe_bps,
  92848. unsigned order,
  92849. unsigned rice_parameter,
  92850. unsigned rice_parameter_limit,
  92851. unsigned min_partition_order,
  92852. unsigned max_partition_order,
  92853. FLAC__bool do_escape_coding,
  92854. unsigned rice_parameter_search_dist,
  92855. FLAC__Subframe *subframe,
  92856. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92857. )
  92858. {
  92859. unsigned i, residual_bits, estimate;
  92860. const unsigned residual_samples = blocksize - order;
  92861. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92862. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92863. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92864. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92865. subframe->data.fixed.residual = residual;
  92866. residual_bits =
  92867. find_best_partition_order_(
  92868. encoder->private_,
  92869. residual,
  92870. abs_residual_partition_sums,
  92871. raw_bits_per_partition,
  92872. residual_samples,
  92873. order,
  92874. rice_parameter,
  92875. rice_parameter_limit,
  92876. min_partition_order,
  92877. max_partition_order,
  92878. subframe_bps,
  92879. do_escape_coding,
  92880. rice_parameter_search_dist,
  92881. &subframe->data.fixed.entropy_coding_method
  92882. );
  92883. subframe->data.fixed.order = order;
  92884. for(i = 0; i < order; i++)
  92885. subframe->data.fixed.warmup[i] = signal[i];
  92886. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92887. #if SPOTCHECK_ESTIMATE
  92888. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92889. #endif
  92890. return estimate;
  92891. }
  92892. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92893. unsigned evaluate_lpc_subframe_(
  92894. FLAC__StreamEncoder *encoder,
  92895. const FLAC__int32 signal[],
  92896. FLAC__int32 residual[],
  92897. FLAC__uint64 abs_residual_partition_sums[],
  92898. unsigned raw_bits_per_partition[],
  92899. const FLAC__real lp_coeff[],
  92900. unsigned blocksize,
  92901. unsigned subframe_bps,
  92902. unsigned order,
  92903. unsigned qlp_coeff_precision,
  92904. unsigned rice_parameter,
  92905. unsigned rice_parameter_limit,
  92906. unsigned min_partition_order,
  92907. unsigned max_partition_order,
  92908. FLAC__bool do_escape_coding,
  92909. unsigned rice_parameter_search_dist,
  92910. FLAC__Subframe *subframe,
  92911. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92912. )
  92913. {
  92914. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92915. unsigned i, residual_bits, estimate;
  92916. int quantization, ret;
  92917. const unsigned residual_samples = blocksize - order;
  92918. if(subframe_bps <= 16) {
  92919. FLAC__ASSERT(order > 0);
  92920. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92921. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92922. }
  92923. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92924. if(ret != 0)
  92925. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92926. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92927. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92928. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92929. else
  92930. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92931. else
  92932. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92933. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92934. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92935. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92936. subframe->data.lpc.residual = residual;
  92937. residual_bits =
  92938. find_best_partition_order_(
  92939. encoder->private_,
  92940. residual,
  92941. abs_residual_partition_sums,
  92942. raw_bits_per_partition,
  92943. residual_samples,
  92944. order,
  92945. rice_parameter,
  92946. rice_parameter_limit,
  92947. min_partition_order,
  92948. max_partition_order,
  92949. subframe_bps,
  92950. do_escape_coding,
  92951. rice_parameter_search_dist,
  92952. &subframe->data.lpc.entropy_coding_method
  92953. );
  92954. subframe->data.lpc.order = order;
  92955. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92956. subframe->data.lpc.quantization_level = quantization;
  92957. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92958. for(i = 0; i < order; i++)
  92959. subframe->data.lpc.warmup[i] = signal[i];
  92960. 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;
  92961. #if SPOTCHECK_ESTIMATE
  92962. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92963. #endif
  92964. return estimate;
  92965. }
  92966. #endif
  92967. unsigned evaluate_verbatim_subframe_(
  92968. FLAC__StreamEncoder *encoder,
  92969. const FLAC__int32 signal[],
  92970. unsigned blocksize,
  92971. unsigned subframe_bps,
  92972. FLAC__Subframe *subframe
  92973. )
  92974. {
  92975. unsigned estimate;
  92976. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92977. subframe->data.verbatim.data = signal;
  92978. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92979. #if SPOTCHECK_ESTIMATE
  92980. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92981. #else
  92982. (void)encoder;
  92983. #endif
  92984. return estimate;
  92985. }
  92986. unsigned find_best_partition_order_(
  92987. FLAC__StreamEncoderPrivate *private_,
  92988. const FLAC__int32 residual[],
  92989. FLAC__uint64 abs_residual_partition_sums[],
  92990. unsigned raw_bits_per_partition[],
  92991. unsigned residual_samples,
  92992. unsigned predictor_order,
  92993. unsigned rice_parameter,
  92994. unsigned rice_parameter_limit,
  92995. unsigned min_partition_order,
  92996. unsigned max_partition_order,
  92997. unsigned bps,
  92998. FLAC__bool do_escape_coding,
  92999. unsigned rice_parameter_search_dist,
  93000. FLAC__EntropyCodingMethod *best_ecm
  93001. )
  93002. {
  93003. unsigned residual_bits, best_residual_bits = 0;
  93004. unsigned best_parameters_index = 0;
  93005. unsigned best_partition_order = 0;
  93006. const unsigned blocksize = residual_samples + predictor_order;
  93007. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  93008. min_partition_order = min(min_partition_order, max_partition_order);
  93009. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  93010. if(do_escape_coding)
  93011. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  93012. {
  93013. int partition_order;
  93014. unsigned sum;
  93015. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  93016. if(!
  93017. set_partitioned_rice_(
  93018. #ifdef EXACT_RICE_BITS_CALCULATION
  93019. residual,
  93020. #endif
  93021. abs_residual_partition_sums+sum,
  93022. raw_bits_per_partition+sum,
  93023. residual_samples,
  93024. predictor_order,
  93025. rice_parameter,
  93026. rice_parameter_limit,
  93027. rice_parameter_search_dist,
  93028. (unsigned)partition_order,
  93029. do_escape_coding,
  93030. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  93031. &residual_bits
  93032. )
  93033. )
  93034. {
  93035. FLAC__ASSERT(best_residual_bits != 0);
  93036. break;
  93037. }
  93038. sum += 1u << partition_order;
  93039. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  93040. best_residual_bits = residual_bits;
  93041. best_parameters_index = !best_parameters_index;
  93042. best_partition_order = partition_order;
  93043. }
  93044. }
  93045. }
  93046. best_ecm->data.partitioned_rice.order = best_partition_order;
  93047. {
  93048. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  93049. unsigned partition;
  93050. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  93051. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  93052. if(do_escape_coding)
  93053. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  93054. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  93055. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  93056. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  93057. break;
  93058. }
  93059. }
  93060. }
  93061. return best_residual_bits;
  93062. }
  93063. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93064. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  93065. const FLAC__int32 residual[],
  93066. FLAC__uint64 abs_residual_partition_sums[],
  93067. unsigned blocksize,
  93068. unsigned predictor_order,
  93069. unsigned min_partition_order,
  93070. unsigned max_partition_order
  93071. );
  93072. #endif
  93073. void precompute_partition_info_sums_(
  93074. const FLAC__int32 residual[],
  93075. FLAC__uint64 abs_residual_partition_sums[],
  93076. unsigned residual_samples,
  93077. unsigned predictor_order,
  93078. unsigned min_partition_order,
  93079. unsigned max_partition_order,
  93080. unsigned bps
  93081. )
  93082. {
  93083. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  93084. unsigned partitions = 1u << max_partition_order;
  93085. FLAC__ASSERT(default_partition_samples > predictor_order);
  93086. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93087. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93088. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  93089. return;
  93090. }
  93091. #endif
  93092. {
  93093. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  93094. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93095. FLAC__uint32 abs_residual_partition_sum;
  93096. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93097. end += default_partition_samples;
  93098. abs_residual_partition_sum = 0;
  93099. for( ; residual_sample < end; residual_sample++)
  93100. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93101. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93102. }
  93103. }
  93104. else { /* have to pessimistically use 64 bits for accumulator */
  93105. FLAC__uint64 abs_residual_partition_sum;
  93106. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93107. end += default_partition_samples;
  93108. abs_residual_partition_sum = 0;
  93109. for( ; residual_sample < end; residual_sample++)
  93110. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93111. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93112. }
  93113. }
  93114. }
  93115. {
  93116. unsigned from_partition = 0, to_partition = partitions;
  93117. int partition_order;
  93118. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  93119. unsigned i;
  93120. partitions >>= 1;
  93121. for(i = 0; i < partitions; i++) {
  93122. abs_residual_partition_sums[to_partition++] =
  93123. abs_residual_partition_sums[from_partition ] +
  93124. abs_residual_partition_sums[from_partition+1];
  93125. from_partition += 2;
  93126. }
  93127. }
  93128. }
  93129. }
  93130. void precompute_partition_info_escapes_(
  93131. const FLAC__int32 residual[],
  93132. unsigned raw_bits_per_partition[],
  93133. unsigned residual_samples,
  93134. unsigned predictor_order,
  93135. unsigned min_partition_order,
  93136. unsigned max_partition_order
  93137. )
  93138. {
  93139. int partition_order;
  93140. unsigned from_partition, to_partition = 0;
  93141. const unsigned blocksize = residual_samples + predictor_order;
  93142. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  93143. FLAC__int32 r;
  93144. FLAC__uint32 rmax;
  93145. unsigned partition, partition_sample, partition_samples, residual_sample;
  93146. const unsigned partitions = 1u << partition_order;
  93147. const unsigned default_partition_samples = blocksize >> partition_order;
  93148. FLAC__ASSERT(default_partition_samples > predictor_order);
  93149. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93150. partition_samples = default_partition_samples;
  93151. if(partition == 0)
  93152. partition_samples -= predictor_order;
  93153. rmax = 0;
  93154. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  93155. r = residual[residual_sample++];
  93156. if(r < 0)
  93157. rmax |= ~r;
  93158. else
  93159. rmax |= r;
  93160. }
  93161. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  93162. }
  93163. to_partition = partitions;
  93164. break; /*@@@ yuck, should remove the 'for' loop instead */
  93165. }
  93166. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  93167. unsigned m;
  93168. unsigned i;
  93169. const unsigned partitions = 1u << partition_order;
  93170. for(i = 0; i < partitions; i++) {
  93171. m = raw_bits_per_partition[from_partition];
  93172. from_partition++;
  93173. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  93174. from_partition++;
  93175. to_partition++;
  93176. }
  93177. }
  93178. }
  93179. #ifdef EXACT_RICE_BITS_CALCULATION
  93180. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93181. const unsigned rice_parameter,
  93182. const unsigned partition_samples,
  93183. const FLAC__int32 *residual
  93184. )
  93185. {
  93186. unsigned i, partition_bits =
  93187. 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 */
  93188. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  93189. ;
  93190. for(i = 0; i < partition_samples; i++)
  93191. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  93192. return partition_bits;
  93193. }
  93194. #else
  93195. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93196. const unsigned rice_parameter,
  93197. const unsigned partition_samples,
  93198. const FLAC__uint64 abs_residual_partition_sum
  93199. )
  93200. {
  93201. return
  93202. 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 */
  93203. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  93204. (
  93205. rice_parameter?
  93206. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  93207. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  93208. )
  93209. - (partition_samples >> 1)
  93210. ;
  93211. }
  93212. #endif
  93213. FLAC__bool set_partitioned_rice_(
  93214. #ifdef EXACT_RICE_BITS_CALCULATION
  93215. const FLAC__int32 residual[],
  93216. #endif
  93217. const FLAC__uint64 abs_residual_partition_sums[],
  93218. const unsigned raw_bits_per_partition[],
  93219. const unsigned residual_samples,
  93220. const unsigned predictor_order,
  93221. const unsigned suggested_rice_parameter,
  93222. const unsigned rice_parameter_limit,
  93223. const unsigned rice_parameter_search_dist,
  93224. const unsigned partition_order,
  93225. const FLAC__bool search_for_escapes,
  93226. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  93227. unsigned *bits
  93228. )
  93229. {
  93230. unsigned rice_parameter, partition_bits;
  93231. unsigned best_partition_bits, best_rice_parameter = 0;
  93232. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  93233. unsigned *parameters, *raw_bits;
  93234. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93235. unsigned min_rice_parameter, max_rice_parameter;
  93236. #else
  93237. (void)rice_parameter_search_dist;
  93238. #endif
  93239. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93240. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93241. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  93242. parameters = partitioned_rice_contents->parameters;
  93243. raw_bits = partitioned_rice_contents->raw_bits;
  93244. if(partition_order == 0) {
  93245. best_partition_bits = (unsigned)(-1);
  93246. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93247. if(rice_parameter_search_dist) {
  93248. if(suggested_rice_parameter < rice_parameter_search_dist)
  93249. min_rice_parameter = 0;
  93250. else
  93251. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  93252. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  93253. if(max_rice_parameter >= rice_parameter_limit) {
  93254. #ifdef DEBUG_VERBOSE
  93255. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  93256. #endif
  93257. max_rice_parameter = rice_parameter_limit - 1;
  93258. }
  93259. }
  93260. else
  93261. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  93262. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93263. #else
  93264. rice_parameter = suggested_rice_parameter;
  93265. #endif
  93266. #ifdef EXACT_RICE_BITS_CALCULATION
  93267. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  93268. #else
  93269. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  93270. #endif
  93271. if(partition_bits < best_partition_bits) {
  93272. best_rice_parameter = rice_parameter;
  93273. best_partition_bits = partition_bits;
  93274. }
  93275. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93276. }
  93277. #endif
  93278. if(search_for_escapes) {
  93279. 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;
  93280. if(partition_bits <= best_partition_bits) {
  93281. raw_bits[0] = raw_bits_per_partition[0];
  93282. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93283. best_partition_bits = partition_bits;
  93284. }
  93285. else
  93286. raw_bits[0] = 0;
  93287. }
  93288. parameters[0] = best_rice_parameter;
  93289. bits_ += best_partition_bits;
  93290. }
  93291. else {
  93292. unsigned partition, residual_sample;
  93293. unsigned partition_samples;
  93294. FLAC__uint64 mean, k;
  93295. const unsigned partitions = 1u << partition_order;
  93296. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93297. partition_samples = (residual_samples+predictor_order) >> partition_order;
  93298. if(partition == 0) {
  93299. if(partition_samples <= predictor_order)
  93300. return false;
  93301. else
  93302. partition_samples -= predictor_order;
  93303. }
  93304. mean = abs_residual_partition_sums[partition];
  93305. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  93306. ;
  93307. if(rice_parameter >= rice_parameter_limit) {
  93308. #ifdef DEBUG_VERBOSE
  93309. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  93310. #endif
  93311. rice_parameter = rice_parameter_limit - 1;
  93312. }
  93313. best_partition_bits = (unsigned)(-1);
  93314. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93315. if(rice_parameter_search_dist) {
  93316. if(rice_parameter < rice_parameter_search_dist)
  93317. min_rice_parameter = 0;
  93318. else
  93319. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93320. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93321. if(max_rice_parameter >= rice_parameter_limit) {
  93322. #ifdef DEBUG_VERBOSE
  93323. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93324. #endif
  93325. max_rice_parameter = rice_parameter_limit - 1;
  93326. }
  93327. }
  93328. else
  93329. min_rice_parameter = max_rice_parameter = rice_parameter;
  93330. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93331. #endif
  93332. #ifdef EXACT_RICE_BITS_CALCULATION
  93333. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93334. #else
  93335. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93336. #endif
  93337. if(partition_bits < best_partition_bits) {
  93338. best_rice_parameter = rice_parameter;
  93339. best_partition_bits = partition_bits;
  93340. }
  93341. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93342. }
  93343. #endif
  93344. if(search_for_escapes) {
  93345. 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;
  93346. if(partition_bits <= best_partition_bits) {
  93347. raw_bits[partition] = raw_bits_per_partition[partition];
  93348. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93349. best_partition_bits = partition_bits;
  93350. }
  93351. else
  93352. raw_bits[partition] = 0;
  93353. }
  93354. parameters[partition] = best_rice_parameter;
  93355. bits_ += best_partition_bits;
  93356. residual_sample += partition_samples;
  93357. }
  93358. }
  93359. *bits = bits_;
  93360. return true;
  93361. }
  93362. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93363. {
  93364. unsigned i, shift;
  93365. FLAC__int32 x = 0;
  93366. for(i = 0; i < samples && !(x&1); i++)
  93367. x |= signal[i];
  93368. if(x == 0) {
  93369. shift = 0;
  93370. }
  93371. else {
  93372. for(shift = 0; !(x&1); shift++)
  93373. x >>= 1;
  93374. }
  93375. if(shift > 0) {
  93376. for(i = 0; i < samples; i++)
  93377. signal[i] >>= shift;
  93378. }
  93379. return shift;
  93380. }
  93381. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93382. {
  93383. unsigned channel;
  93384. for(channel = 0; channel < channels; channel++)
  93385. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93386. fifo->tail += wide_samples;
  93387. FLAC__ASSERT(fifo->tail <= fifo->size);
  93388. }
  93389. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93390. {
  93391. unsigned channel;
  93392. unsigned sample, wide_sample;
  93393. unsigned tail = fifo->tail;
  93394. sample = input_offset * channels;
  93395. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93396. for(channel = 0; channel < channels; channel++)
  93397. fifo->data[channel][tail] = input[sample++];
  93398. tail++;
  93399. }
  93400. fifo->tail = tail;
  93401. FLAC__ASSERT(fifo->tail <= fifo->size);
  93402. }
  93403. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93404. {
  93405. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93406. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93407. (void)decoder;
  93408. if(encoder->private_->verify.needs_magic_hack) {
  93409. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93410. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93411. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93412. encoder->private_->verify.needs_magic_hack = false;
  93413. }
  93414. else {
  93415. if(encoded_bytes == 0) {
  93416. FLAC__ASSERT(0);
  93417. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93418. }
  93419. else if(encoded_bytes < *bytes)
  93420. *bytes = encoded_bytes;
  93421. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93422. encoder->private_->verify.output.data += *bytes;
  93423. encoder->private_->verify.output.bytes -= *bytes;
  93424. }
  93425. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93426. }
  93427. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93428. {
  93429. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93430. unsigned channel;
  93431. const unsigned channels = frame->header.channels;
  93432. const unsigned blocksize = frame->header.blocksize;
  93433. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93434. (void)decoder;
  93435. for(channel = 0; channel < channels; channel++) {
  93436. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93437. unsigned i, sample = 0;
  93438. FLAC__int32 expect = 0, got = 0;
  93439. for(i = 0; i < blocksize; i++) {
  93440. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93441. sample = i;
  93442. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93443. got = (FLAC__int32)buffer[channel][i];
  93444. break;
  93445. }
  93446. }
  93447. FLAC__ASSERT(i < blocksize);
  93448. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93449. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93450. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93451. encoder->private_->verify.error_stats.channel = channel;
  93452. encoder->private_->verify.error_stats.sample = sample;
  93453. encoder->private_->verify.error_stats.expected = expect;
  93454. encoder->private_->verify.error_stats.got = got;
  93455. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93456. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93457. }
  93458. }
  93459. encoder->private_->verify.input_fifo.tail -= blocksize;
  93460. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93461. for(channel = 0; channel < channels; channel++)
  93462. 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]));
  93463. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93464. }
  93465. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93466. {
  93467. (void)decoder, (void)metadata, (void)client_data;
  93468. }
  93469. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93470. {
  93471. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93472. (void)decoder, (void)status;
  93473. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93474. }
  93475. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93476. {
  93477. (void)client_data;
  93478. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93479. if (*bytes == 0) {
  93480. if (feof(encoder->private_->file))
  93481. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93482. else if (ferror(encoder->private_->file))
  93483. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93484. }
  93485. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93486. }
  93487. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93488. {
  93489. (void)client_data;
  93490. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93491. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93492. else
  93493. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93494. }
  93495. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93496. {
  93497. off_t offset;
  93498. (void)client_data;
  93499. offset = ftello(encoder->private_->file);
  93500. if(offset < 0) {
  93501. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93502. }
  93503. else {
  93504. *absolute_byte_offset = (FLAC__uint64)offset;
  93505. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93506. }
  93507. }
  93508. #ifdef FLAC__VALGRIND_TESTING
  93509. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93510. {
  93511. size_t ret = fwrite(ptr, size, nmemb, stream);
  93512. if(!ferror(stream))
  93513. fflush(stream);
  93514. return ret;
  93515. }
  93516. #else
  93517. #define local__fwrite fwrite
  93518. #endif
  93519. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93520. {
  93521. (void)client_data, (void)current_frame;
  93522. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93523. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93524. #if FLAC__HAS_OGG
  93525. encoder->private_->is_ogg? true :
  93526. #endif
  93527. samples > 0
  93528. );
  93529. if(call_it) {
  93530. 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);
  93531. }
  93532. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93533. }
  93534. else
  93535. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93536. }
  93537. FILE *get_binary_stdout_(void)
  93538. {
  93539. #if defined _MSC_VER || defined __MINGW32__
  93540. _setmode(_fileno(stdout), _O_BINARY);
  93541. #elif defined __CYGWIN__
  93542. setmode(_fileno(stdout), _O_BINARY);
  93543. #elif defined __EMX__
  93544. setmode(fileno(stdout), O_BINARY);
  93545. #endif
  93546. return stdout;
  93547. }
  93548. #endif
  93549. /*** End of inlined file: stream_encoder.c ***/
  93550. /*** Start of inlined file: stream_encoder_framing.c ***/
  93551. /*** Start of inlined file: juce_FlacHeader.h ***/
  93552. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93553. // tasks..
  93554. #define VERSION "1.2.1"
  93555. #define FLAC__NO_DLL 1
  93556. #if JUCE_MSVC
  93557. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93558. #endif
  93559. #if JUCE_MAC
  93560. #define FLAC__SYS_DARWIN 1
  93561. #endif
  93562. /*** End of inlined file: juce_FlacHeader.h ***/
  93563. #if JUCE_USE_FLAC
  93564. #if HAVE_CONFIG_H
  93565. # include <config.h>
  93566. #endif
  93567. #include <stdio.h>
  93568. #include <string.h> /* for strlen() */
  93569. #ifdef max
  93570. #undef max
  93571. #endif
  93572. #define max(x,y) ((x)>(y)?(x):(y))
  93573. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93574. 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);
  93575. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93576. {
  93577. unsigned i, j;
  93578. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93579. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93580. return false;
  93581. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93582. return false;
  93583. i = metadata->length;
  93584. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93585. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93586. i -= metadata->data.vorbis_comment.vendor_string.length;
  93587. i += vendor_string_length;
  93588. }
  93589. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93590. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93591. return false;
  93592. switch(metadata->type) {
  93593. case FLAC__METADATA_TYPE_STREAMINFO:
  93594. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93595. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93596. return false;
  93597. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93598. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93599. return false;
  93600. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93601. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93602. return false;
  93603. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93604. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93605. return false;
  93606. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93607. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93608. return false;
  93609. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93610. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93611. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93612. return false;
  93613. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93614. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93615. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93616. return false;
  93617. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93618. return false;
  93619. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93620. return false;
  93621. break;
  93622. case FLAC__METADATA_TYPE_PADDING:
  93623. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93624. return false;
  93625. break;
  93626. case FLAC__METADATA_TYPE_APPLICATION:
  93627. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93628. return false;
  93629. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93630. return false;
  93631. break;
  93632. case FLAC__METADATA_TYPE_SEEKTABLE:
  93633. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93634. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93635. return false;
  93636. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93637. return false;
  93638. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93639. return false;
  93640. }
  93641. break;
  93642. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93643. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93644. return false;
  93645. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93646. return false;
  93647. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93648. return false;
  93649. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93650. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93651. return false;
  93652. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93653. return false;
  93654. }
  93655. break;
  93656. case FLAC__METADATA_TYPE_CUESHEET:
  93657. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93658. 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))
  93659. return false;
  93660. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93661. return false;
  93662. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93663. return false;
  93664. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93665. return false;
  93666. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93667. return false;
  93668. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93669. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93670. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93671. return false;
  93672. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93673. return false;
  93674. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93675. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93676. return false;
  93677. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93678. return false;
  93679. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93680. return false;
  93681. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93682. return false;
  93683. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93684. return false;
  93685. for(j = 0; j < track->num_indices; j++) {
  93686. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93687. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93688. return false;
  93689. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93690. return false;
  93691. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93692. return false;
  93693. }
  93694. }
  93695. break;
  93696. case FLAC__METADATA_TYPE_PICTURE:
  93697. {
  93698. size_t len;
  93699. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93700. return false;
  93701. len = strlen(metadata->data.picture.mime_type);
  93702. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93703. return false;
  93704. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93705. return false;
  93706. len = strlen((const char *)metadata->data.picture.description);
  93707. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93708. return false;
  93709. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93710. return false;
  93711. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93712. return false;
  93713. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93714. return false;
  93715. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93716. return false;
  93717. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93718. return false;
  93719. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93720. return false;
  93721. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93722. return false;
  93723. }
  93724. break;
  93725. default:
  93726. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93727. return false;
  93728. break;
  93729. }
  93730. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93731. return true;
  93732. }
  93733. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93734. {
  93735. unsigned u, blocksize_hint, sample_rate_hint;
  93736. FLAC__byte crc;
  93737. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93738. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93739. return false;
  93740. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93741. return false;
  93742. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93743. return false;
  93744. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93745. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93746. blocksize_hint = 0;
  93747. switch(header->blocksize) {
  93748. case 192: u = 1; break;
  93749. case 576: u = 2; break;
  93750. case 1152: u = 3; break;
  93751. case 2304: u = 4; break;
  93752. case 4608: u = 5; break;
  93753. case 256: u = 8; break;
  93754. case 512: u = 9; break;
  93755. case 1024: u = 10; break;
  93756. case 2048: u = 11; break;
  93757. case 4096: u = 12; break;
  93758. case 8192: u = 13; break;
  93759. case 16384: u = 14; break;
  93760. case 32768: u = 15; break;
  93761. default:
  93762. if(header->blocksize <= 0x100)
  93763. blocksize_hint = u = 6;
  93764. else
  93765. blocksize_hint = u = 7;
  93766. break;
  93767. }
  93768. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93769. return false;
  93770. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93771. sample_rate_hint = 0;
  93772. switch(header->sample_rate) {
  93773. case 88200: u = 1; break;
  93774. case 176400: u = 2; break;
  93775. case 192000: u = 3; break;
  93776. case 8000: u = 4; break;
  93777. case 16000: u = 5; break;
  93778. case 22050: u = 6; break;
  93779. case 24000: u = 7; break;
  93780. case 32000: u = 8; break;
  93781. case 44100: u = 9; break;
  93782. case 48000: u = 10; break;
  93783. case 96000: u = 11; break;
  93784. default:
  93785. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93786. sample_rate_hint = u = 12;
  93787. else if(header->sample_rate % 10 == 0)
  93788. sample_rate_hint = u = 14;
  93789. else if(header->sample_rate <= 0xffff)
  93790. sample_rate_hint = u = 13;
  93791. else
  93792. u = 0;
  93793. break;
  93794. }
  93795. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93796. return false;
  93797. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93798. switch(header->channel_assignment) {
  93799. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93800. u = header->channels - 1;
  93801. break;
  93802. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93803. FLAC__ASSERT(header->channels == 2);
  93804. u = 8;
  93805. break;
  93806. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93807. FLAC__ASSERT(header->channels == 2);
  93808. u = 9;
  93809. break;
  93810. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93811. FLAC__ASSERT(header->channels == 2);
  93812. u = 10;
  93813. break;
  93814. default:
  93815. FLAC__ASSERT(0);
  93816. }
  93817. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93818. return false;
  93819. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93820. switch(header->bits_per_sample) {
  93821. case 8 : u = 1; break;
  93822. case 12: u = 2; break;
  93823. case 16: u = 4; break;
  93824. case 20: u = 5; break;
  93825. case 24: u = 6; break;
  93826. default: u = 0; break;
  93827. }
  93828. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93829. return false;
  93830. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93831. return false;
  93832. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93833. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93834. return false;
  93835. }
  93836. else {
  93837. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93838. return false;
  93839. }
  93840. if(blocksize_hint)
  93841. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93842. return false;
  93843. switch(sample_rate_hint) {
  93844. case 12:
  93845. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93846. return false;
  93847. break;
  93848. case 13:
  93849. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93850. return false;
  93851. break;
  93852. case 14:
  93853. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93854. return false;
  93855. break;
  93856. }
  93857. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93858. return false;
  93859. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93860. return false;
  93861. return true;
  93862. }
  93863. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93864. {
  93865. FLAC__bool ok;
  93866. ok =
  93867. 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) &&
  93868. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93869. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93870. ;
  93871. return ok;
  93872. }
  93873. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93874. {
  93875. unsigned i;
  93876. 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))
  93877. return false;
  93878. if(wasted_bits)
  93879. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93880. return false;
  93881. for(i = 0; i < subframe->order; i++)
  93882. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93883. return false;
  93884. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93885. return false;
  93886. switch(subframe->entropy_coding_method.type) {
  93887. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93888. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93889. if(!add_residual_partitioned_rice_(
  93890. bw,
  93891. subframe->residual,
  93892. residual_samples,
  93893. subframe->order,
  93894. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93895. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93896. subframe->entropy_coding_method.data.partitioned_rice.order,
  93897. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93898. ))
  93899. return false;
  93900. break;
  93901. default:
  93902. FLAC__ASSERT(0);
  93903. }
  93904. return true;
  93905. }
  93906. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93907. {
  93908. unsigned i;
  93909. 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))
  93910. return false;
  93911. if(wasted_bits)
  93912. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93913. return false;
  93914. for(i = 0; i < subframe->order; i++)
  93915. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93916. return false;
  93917. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93918. return false;
  93919. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93920. return false;
  93921. for(i = 0; i < subframe->order; i++)
  93922. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93923. return false;
  93924. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93925. return false;
  93926. switch(subframe->entropy_coding_method.type) {
  93927. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93928. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93929. if(!add_residual_partitioned_rice_(
  93930. bw,
  93931. subframe->residual,
  93932. residual_samples,
  93933. subframe->order,
  93934. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93935. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93936. subframe->entropy_coding_method.data.partitioned_rice.order,
  93937. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93938. ))
  93939. return false;
  93940. break;
  93941. default:
  93942. FLAC__ASSERT(0);
  93943. }
  93944. return true;
  93945. }
  93946. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93947. {
  93948. unsigned i;
  93949. const FLAC__int32 *signal = subframe->data;
  93950. 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))
  93951. return false;
  93952. if(wasted_bits)
  93953. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93954. return false;
  93955. for(i = 0; i < samples; i++)
  93956. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93957. return false;
  93958. return true;
  93959. }
  93960. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93961. {
  93962. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93963. return false;
  93964. switch(method->type) {
  93965. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93966. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93967. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93968. return false;
  93969. break;
  93970. default:
  93971. FLAC__ASSERT(0);
  93972. }
  93973. return true;
  93974. }
  93975. 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)
  93976. {
  93977. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93978. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93979. if(partition_order == 0) {
  93980. unsigned i;
  93981. if(raw_bits[0] == 0) {
  93982. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93983. return false;
  93984. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93985. return false;
  93986. }
  93987. else {
  93988. FLAC__ASSERT(rice_parameters[0] == 0);
  93989. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93990. return false;
  93991. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93992. return false;
  93993. for(i = 0; i < residual_samples; i++) {
  93994. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93995. return false;
  93996. }
  93997. }
  93998. return true;
  93999. }
  94000. else {
  94001. unsigned i, j, k = 0, k_last = 0;
  94002. unsigned partition_samples;
  94003. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  94004. for(i = 0; i < (1u<<partition_order); i++) {
  94005. partition_samples = default_partition_samples;
  94006. if(i == 0)
  94007. partition_samples -= predictor_order;
  94008. k += partition_samples;
  94009. if(raw_bits[i] == 0) {
  94010. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  94011. return false;
  94012. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  94013. return false;
  94014. }
  94015. else {
  94016. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94017. return false;
  94018. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94019. return false;
  94020. for(j = k_last; j < k; j++) {
  94021. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  94022. return false;
  94023. }
  94024. }
  94025. k_last = k;
  94026. }
  94027. return true;
  94028. }
  94029. }
  94030. #endif
  94031. /*** End of inlined file: stream_encoder_framing.c ***/
  94032. /*** Start of inlined file: window_flac.c ***/
  94033. /*** Start of inlined file: juce_FlacHeader.h ***/
  94034. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  94035. // tasks..
  94036. #define VERSION "1.2.1"
  94037. #define FLAC__NO_DLL 1
  94038. #if JUCE_MSVC
  94039. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  94040. #endif
  94041. #if JUCE_MAC
  94042. #define FLAC__SYS_DARWIN 1
  94043. #endif
  94044. /*** End of inlined file: juce_FlacHeader.h ***/
  94045. #if JUCE_USE_FLAC
  94046. #if HAVE_CONFIG_H
  94047. # include <config.h>
  94048. #endif
  94049. #include <math.h>
  94050. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  94051. #ifndef M_PI
  94052. #define M_PI 3.14159265358979323846
  94053. #endif
  94054. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  94055. {
  94056. const FLAC__int32 N = L - 1;
  94057. FLAC__int32 n;
  94058. if (L & 1) {
  94059. for (n = 0; n <= N/2; n++)
  94060. window[n] = 2.0f * n / (float)N;
  94061. for (; n <= N; n++)
  94062. window[n] = 2.0f - 2.0f * n / (float)N;
  94063. }
  94064. else {
  94065. for (n = 0; n <= L/2-1; n++)
  94066. window[n] = 2.0f * n / (float)N;
  94067. for (; n <= N; n++)
  94068. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  94069. }
  94070. }
  94071. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  94072. {
  94073. const FLAC__int32 N = L - 1;
  94074. FLAC__int32 n;
  94075. for (n = 0; n < L; n++)
  94076. 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)));
  94077. }
  94078. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  94079. {
  94080. const FLAC__int32 N = L - 1;
  94081. FLAC__int32 n;
  94082. for (n = 0; n < L; n++)
  94083. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  94084. }
  94085. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  94086. {
  94087. const FLAC__int32 N = L - 1;
  94088. FLAC__int32 n;
  94089. for (n = 0; n <= N; n++)
  94090. 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));
  94091. }
  94092. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  94093. {
  94094. const FLAC__int32 N = L - 1;
  94095. const double N2 = (double)N / 2.;
  94096. FLAC__int32 n;
  94097. for (n = 0; n <= N; n++) {
  94098. double k = ((double)n - N2) / N2;
  94099. k = 1.0f - k * k;
  94100. window[n] = (FLAC__real)(k * k);
  94101. }
  94102. }
  94103. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  94104. {
  94105. const FLAC__int32 N = L - 1;
  94106. FLAC__int32 n;
  94107. for (n = 0; n < L; n++)
  94108. 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));
  94109. }
  94110. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  94111. {
  94112. const FLAC__int32 N = L - 1;
  94113. const double N2 = (double)N / 2.;
  94114. FLAC__int32 n;
  94115. for (n = 0; n <= N; n++) {
  94116. const double k = ((double)n - N2) / (stddev * N2);
  94117. window[n] = (FLAC__real)exp(-0.5f * k * k);
  94118. }
  94119. }
  94120. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  94121. {
  94122. const FLAC__int32 N = L - 1;
  94123. FLAC__int32 n;
  94124. for (n = 0; n < L; n++)
  94125. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  94126. }
  94127. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  94128. {
  94129. const FLAC__int32 N = L - 1;
  94130. FLAC__int32 n;
  94131. for (n = 0; n < L; n++)
  94132. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  94133. }
  94134. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  94135. {
  94136. const FLAC__int32 N = L - 1;
  94137. FLAC__int32 n;
  94138. for (n = 0; n < L; n++)
  94139. 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));
  94140. }
  94141. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  94142. {
  94143. const FLAC__int32 N = L - 1;
  94144. FLAC__int32 n;
  94145. for (n = 0; n < L; n++)
  94146. 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));
  94147. }
  94148. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  94149. {
  94150. FLAC__int32 n;
  94151. for (n = 0; n < L; n++)
  94152. window[n] = 1.0f;
  94153. }
  94154. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  94155. {
  94156. FLAC__int32 n;
  94157. if (L & 1) {
  94158. for (n = 1; n <= L+1/2; n++)
  94159. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  94160. for (; n <= L; n++)
  94161. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  94162. }
  94163. else {
  94164. for (n = 1; n <= L/2; n++)
  94165. window[n-1] = 2.0f * n / (float)L;
  94166. for (; n <= L; n++)
  94167. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  94168. }
  94169. }
  94170. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  94171. {
  94172. if (p <= 0.0)
  94173. FLAC__window_rectangle(window, L);
  94174. else if (p >= 1.0)
  94175. FLAC__window_hann(window, L);
  94176. else {
  94177. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  94178. FLAC__int32 n;
  94179. FLAC__window_rectangle(window, L);
  94180. if (Np > 0) {
  94181. for (n = 0; n <= Np; n++) {
  94182. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  94183. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  94184. }
  94185. }
  94186. }
  94187. }
  94188. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  94189. {
  94190. const FLAC__int32 N = L - 1;
  94191. const double N2 = (double)N / 2.;
  94192. FLAC__int32 n;
  94193. for (n = 0; n <= N; n++) {
  94194. const double k = ((double)n - N2) / N2;
  94195. window[n] = (FLAC__real)(1.0f - k * k);
  94196. }
  94197. }
  94198. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  94199. #endif
  94200. /*** End of inlined file: window_flac.c ***/
  94201. #else
  94202. #include <FLAC/all.h>
  94203. #endif
  94204. }
  94205. #ifdef _MSC_VER
  94206. #pragma warning (pop)
  94207. #endif
  94208. BEGIN_JUCE_NAMESPACE
  94209. using namespace FlacNamespace;
  94210. static const char* const flacFormatName = "FLAC file";
  94211. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  94212. class FlacReader : public AudioFormatReader
  94213. {
  94214. FLAC__StreamDecoder* decoder;
  94215. AudioSampleBuffer reservoir;
  94216. int reservoirStart, samplesInReservoir;
  94217. bool ok, scanningForLength;
  94218. public:
  94219. FlacReader (InputStream* const in)
  94220. : AudioFormatReader (in, TRANS (flacFormatName)),
  94221. reservoir (2, 0),
  94222. reservoirStart (0),
  94223. samplesInReservoir (0),
  94224. scanningForLength (false)
  94225. {
  94226. using namespace FlacNamespace;
  94227. lengthInSamples = 0;
  94228. decoder = FLAC__stream_decoder_new();
  94229. ok = FLAC__stream_decoder_init_stream (decoder,
  94230. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  94231. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  94232. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  94233. if (ok)
  94234. {
  94235. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94236. if (lengthInSamples == 0 && sampleRate > 0)
  94237. {
  94238. // the length hasn't been stored in the metadata, so we'll need to
  94239. // work it out the length the hard way, by scanning the whole file..
  94240. scanningForLength = true;
  94241. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  94242. scanningForLength = false;
  94243. const int64 tempLength = lengthInSamples;
  94244. FLAC__stream_decoder_reset (decoder);
  94245. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94246. lengthInSamples = tempLength;
  94247. }
  94248. }
  94249. }
  94250. ~FlacReader()
  94251. {
  94252. FLAC__stream_decoder_delete (decoder);
  94253. }
  94254. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  94255. {
  94256. sampleRate = info.sample_rate;
  94257. bitsPerSample = info.bits_per_sample;
  94258. lengthInSamples = (unsigned int) info.total_samples;
  94259. numChannels = info.channels;
  94260. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  94261. }
  94262. // returns the number of samples read
  94263. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  94264. int64 startSampleInFile, int numSamples)
  94265. {
  94266. using namespace FlacNamespace;
  94267. if (! ok)
  94268. return false;
  94269. while (numSamples > 0)
  94270. {
  94271. if (startSampleInFile >= reservoirStart
  94272. && startSampleInFile < reservoirStart + samplesInReservoir)
  94273. {
  94274. const int num = (int) jmin ((int64) numSamples,
  94275. reservoirStart + samplesInReservoir - startSampleInFile);
  94276. jassert (num > 0);
  94277. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  94278. if (destSamples[i] != 0)
  94279. memcpy (destSamples[i] + startOffsetInDestBuffer,
  94280. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  94281. sizeof (int) * num);
  94282. startOffsetInDestBuffer += num;
  94283. startSampleInFile += num;
  94284. numSamples -= num;
  94285. }
  94286. else
  94287. {
  94288. if (startSampleInFile >= (int) lengthInSamples)
  94289. {
  94290. samplesInReservoir = 0;
  94291. }
  94292. else if (startSampleInFile < reservoirStart
  94293. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  94294. {
  94295. // had some problems with flac crashing if the read pos is aligned more
  94296. // accurately than this. Probably fixed in newer versions of the library, though.
  94297. reservoirStart = (int) (startSampleInFile & ~511);
  94298. samplesInReservoir = 0;
  94299. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  94300. }
  94301. else
  94302. {
  94303. reservoirStart += samplesInReservoir;
  94304. samplesInReservoir = 0;
  94305. FLAC__stream_decoder_process_single (decoder);
  94306. }
  94307. if (samplesInReservoir == 0)
  94308. break;
  94309. }
  94310. }
  94311. if (numSamples > 0)
  94312. {
  94313. for (int i = numDestChannels; --i >= 0;)
  94314. if (destSamples[i] != 0)
  94315. zeromem (destSamples[i] + startOffsetInDestBuffer,
  94316. sizeof (int) * numSamples);
  94317. }
  94318. return true;
  94319. }
  94320. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  94321. {
  94322. if (scanningForLength)
  94323. {
  94324. lengthInSamples += numSamples;
  94325. }
  94326. else
  94327. {
  94328. if (numSamples > reservoir.getNumSamples())
  94329. reservoir.setSize (numChannels, numSamples, false, false, true);
  94330. const int bitsToShift = 32 - bitsPerSample;
  94331. for (int i = 0; i < (int) numChannels; ++i)
  94332. {
  94333. const FLAC__int32* src = buffer[i];
  94334. int n = i;
  94335. while (src == 0 && n > 0)
  94336. src = buffer [--n];
  94337. if (src != 0)
  94338. {
  94339. int* dest = (int*) reservoir.getSampleData(i);
  94340. for (int j = 0; j < numSamples; ++j)
  94341. dest[j] = src[j] << bitsToShift;
  94342. }
  94343. }
  94344. samplesInReservoir = numSamples;
  94345. }
  94346. }
  94347. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94348. {
  94349. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94350. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94351. }
  94352. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94353. {
  94354. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94355. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94356. }
  94357. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94358. {
  94359. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94360. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94361. }
  94362. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94363. {
  94364. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94365. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94366. }
  94367. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94368. {
  94369. return ((const FlacReader*) client_data)->input->isExhausted();
  94370. }
  94371. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94372. const FLAC__Frame* frame,
  94373. const FLAC__int32* const buffer[],
  94374. void* client_data)
  94375. {
  94376. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94377. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94378. }
  94379. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94380. const FLAC__StreamMetadata* metadata,
  94381. void* client_data)
  94382. {
  94383. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94384. }
  94385. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94386. {
  94387. }
  94388. juce_UseDebuggingNewOperator
  94389. };
  94390. class FlacWriter : public AudioFormatWriter
  94391. {
  94392. FLAC__StreamEncoder* encoder;
  94393. MemoryBlock temp;
  94394. public:
  94395. bool ok;
  94396. FlacWriter (OutputStream* const out,
  94397. const double sampleRate_,
  94398. const int numChannels_,
  94399. const int bitsPerSample_)
  94400. : AudioFormatWriter (out, TRANS (flacFormatName),
  94401. sampleRate_,
  94402. numChannels_,
  94403. bitsPerSample_)
  94404. {
  94405. using namespace FlacNamespace;
  94406. encoder = FLAC__stream_encoder_new();
  94407. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94408. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94409. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94410. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94411. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94412. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94413. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94414. ok = FLAC__stream_encoder_init_stream (encoder,
  94415. encodeWriteCallback, encodeSeekCallback,
  94416. encodeTellCallback, encodeMetadataCallback,
  94417. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94418. }
  94419. ~FlacWriter()
  94420. {
  94421. if (ok)
  94422. {
  94423. FLAC__stream_encoder_finish (encoder);
  94424. output->flush();
  94425. }
  94426. else
  94427. {
  94428. output = 0; // to stop the base class deleting this, as it needs to be returned
  94429. // to the caller of createWriter()
  94430. }
  94431. FLAC__stream_encoder_delete (encoder);
  94432. }
  94433. bool write (const int** samplesToWrite, int numSamples)
  94434. {
  94435. if (! ok)
  94436. return false;
  94437. int* buf[3];
  94438. const int bitsToShift = 32 - bitsPerSample;
  94439. if (bitsToShift > 0)
  94440. {
  94441. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94442. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94443. buf[0] = (int*) temp.getData();
  94444. buf[1] = buf[0] + numSamples;
  94445. buf[2] = 0;
  94446. for (int i = numChannelsToWrite; --i >= 0;)
  94447. {
  94448. if (samplesToWrite[i] != 0)
  94449. {
  94450. for (int j = 0; j < numSamples; ++j)
  94451. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94452. }
  94453. }
  94454. samplesToWrite = (const int**) buf;
  94455. }
  94456. return FLAC__stream_encoder_process (encoder,
  94457. (const FLAC__int32**) samplesToWrite,
  94458. numSamples) != 0;
  94459. }
  94460. bool writeData (const void* const data, const int size) const
  94461. {
  94462. return output->write (data, size);
  94463. }
  94464. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94465. {
  94466. b += bytes;
  94467. for (int i = 0; i < bytes; ++i)
  94468. {
  94469. *(--b) = (FLAC__byte) (val & 0xff);
  94470. val >>= 8;
  94471. }
  94472. }
  94473. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94474. {
  94475. using namespace FlacNamespace;
  94476. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94477. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94478. const unsigned int channelsMinus1 = info.channels - 1;
  94479. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94480. packUint32 (info.min_blocksize, buffer, 2);
  94481. packUint32 (info.max_blocksize, buffer + 2, 2);
  94482. packUint32 (info.min_framesize, buffer + 4, 3);
  94483. packUint32 (info.max_framesize, buffer + 7, 3);
  94484. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94485. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94486. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94487. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94488. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94489. memcpy (buffer + 18, info.md5sum, 16);
  94490. const bool seekOk = output->setPosition (4);
  94491. (void) seekOk;
  94492. // if this fails, you've given it an output stream that can't seek! It needs
  94493. // to be able to seek back to write the header
  94494. jassert (seekOk);
  94495. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94496. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94497. }
  94498. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94499. const FLAC__byte buffer[],
  94500. size_t bytes,
  94501. unsigned int /*samples*/,
  94502. unsigned int /*current_frame*/,
  94503. void* client_data)
  94504. {
  94505. using namespace FlacNamespace;
  94506. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94507. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94508. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94509. }
  94510. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94511. {
  94512. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94513. }
  94514. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94515. {
  94516. if (client_data == 0)
  94517. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94518. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94519. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94520. }
  94521. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94522. const FLAC__StreamMetadata* metadata,
  94523. void* client_data)
  94524. {
  94525. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94526. }
  94527. juce_UseDebuggingNewOperator
  94528. };
  94529. FlacAudioFormat::FlacAudioFormat()
  94530. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94531. {
  94532. }
  94533. FlacAudioFormat::~FlacAudioFormat()
  94534. {
  94535. }
  94536. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94537. {
  94538. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94539. return Array <int> (rates);
  94540. }
  94541. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94542. {
  94543. const int depths[] = { 16, 24, 0 };
  94544. return Array <int> (depths);
  94545. }
  94546. bool FlacAudioFormat::canDoStereo()
  94547. {
  94548. return true;
  94549. }
  94550. bool FlacAudioFormat::canDoMono()
  94551. {
  94552. return true;
  94553. }
  94554. bool FlacAudioFormat::isCompressed()
  94555. {
  94556. return true;
  94557. }
  94558. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94559. const bool deleteStreamIfOpeningFails)
  94560. {
  94561. ScopedPointer <FlacReader> r (new FlacReader (in));
  94562. if (r->sampleRate != 0)
  94563. return r.release();
  94564. if (! deleteStreamIfOpeningFails)
  94565. r->input = 0;
  94566. return 0;
  94567. }
  94568. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94569. double sampleRate,
  94570. unsigned int numberOfChannels,
  94571. int bitsPerSample,
  94572. const StringPairArray& /*metadataValues*/,
  94573. int /*qualityOptionIndex*/)
  94574. {
  94575. if (getPossibleBitDepths().contains (bitsPerSample))
  94576. {
  94577. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94578. sampleRate,
  94579. numberOfChannels,
  94580. bitsPerSample));
  94581. if (w->ok)
  94582. return w.release();
  94583. }
  94584. return 0;
  94585. }
  94586. END_JUCE_NAMESPACE
  94587. #endif
  94588. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94589. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94590. #if JUCE_USE_OGGVORBIS
  94591. #if JUCE_MAC
  94592. #define __MACOSX__ 1
  94593. #endif
  94594. namespace OggVorbisNamespace
  94595. {
  94596. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94597. /*** Start of inlined file: vorbisenc.h ***/
  94598. #ifndef _OV_ENC_H_
  94599. #define _OV_ENC_H_
  94600. #ifdef __cplusplus
  94601. extern "C"
  94602. {
  94603. #endif /* __cplusplus */
  94604. /*** Start of inlined file: codec.h ***/
  94605. #ifndef _vorbis_codec_h_
  94606. #define _vorbis_codec_h_
  94607. #ifdef __cplusplus
  94608. extern "C"
  94609. {
  94610. #endif /* __cplusplus */
  94611. /*** Start of inlined file: ogg.h ***/
  94612. #ifndef _OGG_H
  94613. #define _OGG_H
  94614. #ifdef __cplusplus
  94615. extern "C" {
  94616. #endif
  94617. /*** Start of inlined file: os_types.h ***/
  94618. #ifndef _OS_TYPES_H
  94619. #define _OS_TYPES_H
  94620. #define _ogg_malloc malloc
  94621. #define _ogg_calloc calloc
  94622. #define _ogg_realloc realloc
  94623. #define _ogg_free free
  94624. #if defined(_WIN32)
  94625. # if defined(__CYGWIN__)
  94626. # include <_G_config.h>
  94627. typedef _G_int64_t ogg_int64_t;
  94628. typedef _G_int32_t ogg_int32_t;
  94629. typedef _G_uint32_t ogg_uint32_t;
  94630. typedef _G_int16_t ogg_int16_t;
  94631. typedef _G_uint16_t ogg_uint16_t;
  94632. # elif defined(__MINGW32__)
  94633. typedef short ogg_int16_t;
  94634. typedef unsigned short ogg_uint16_t;
  94635. typedef int ogg_int32_t;
  94636. typedef unsigned int ogg_uint32_t;
  94637. typedef long long ogg_int64_t;
  94638. typedef unsigned long long ogg_uint64_t;
  94639. # elif defined(__MWERKS__)
  94640. typedef long long ogg_int64_t;
  94641. typedef int ogg_int32_t;
  94642. typedef unsigned int ogg_uint32_t;
  94643. typedef short ogg_int16_t;
  94644. typedef unsigned short ogg_uint16_t;
  94645. # else
  94646. typedef __int64 ogg_int64_t;
  94647. typedef __int32 ogg_int32_t;
  94648. typedef unsigned __int32 ogg_uint32_t;
  94649. typedef __int16 ogg_int16_t;
  94650. typedef unsigned __int16 ogg_uint16_t;
  94651. # endif
  94652. #elif defined(__MACOS__)
  94653. # include <sys/types.h>
  94654. typedef SInt16 ogg_int16_t;
  94655. typedef UInt16 ogg_uint16_t;
  94656. typedef SInt32 ogg_int32_t;
  94657. typedef UInt32 ogg_uint32_t;
  94658. typedef SInt64 ogg_int64_t;
  94659. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94660. # include <sys/types.h>
  94661. typedef int16_t ogg_int16_t;
  94662. typedef u_int16_t ogg_uint16_t;
  94663. typedef int32_t ogg_int32_t;
  94664. typedef u_int32_t ogg_uint32_t;
  94665. typedef int64_t ogg_int64_t;
  94666. #elif defined(__BEOS__)
  94667. # include <inttypes.h>
  94668. typedef int16_t ogg_int16_t;
  94669. typedef u_int16_t ogg_uint16_t;
  94670. typedef int32_t ogg_int32_t;
  94671. typedef u_int32_t ogg_uint32_t;
  94672. typedef int64_t ogg_int64_t;
  94673. #elif defined (__EMX__)
  94674. typedef short ogg_int16_t;
  94675. typedef unsigned short ogg_uint16_t;
  94676. typedef int ogg_int32_t;
  94677. typedef unsigned int ogg_uint32_t;
  94678. typedef long long ogg_int64_t;
  94679. #elif defined (DJGPP)
  94680. typedef short ogg_int16_t;
  94681. typedef int ogg_int32_t;
  94682. typedef unsigned int ogg_uint32_t;
  94683. typedef long long ogg_int64_t;
  94684. #elif defined(R5900)
  94685. typedef long ogg_int64_t;
  94686. typedef int ogg_int32_t;
  94687. typedef unsigned ogg_uint32_t;
  94688. typedef short ogg_int16_t;
  94689. #elif defined(__SYMBIAN32__)
  94690. typedef signed short ogg_int16_t;
  94691. typedef unsigned short ogg_uint16_t;
  94692. typedef signed int ogg_int32_t;
  94693. typedef unsigned int ogg_uint32_t;
  94694. typedef long long int ogg_int64_t;
  94695. #else
  94696. # include <sys/types.h>
  94697. /*** Start of inlined file: config_types.h ***/
  94698. #ifndef __CONFIG_TYPES_H__
  94699. #define __CONFIG_TYPES_H__
  94700. typedef int16_t ogg_int16_t;
  94701. typedef unsigned short ogg_uint16_t;
  94702. typedef int32_t ogg_int32_t;
  94703. typedef unsigned int ogg_uint32_t;
  94704. typedef int64_t ogg_int64_t;
  94705. #endif
  94706. /*** End of inlined file: config_types.h ***/
  94707. #endif
  94708. #endif /* _OS_TYPES_H */
  94709. /*** End of inlined file: os_types.h ***/
  94710. typedef struct {
  94711. long endbyte;
  94712. int endbit;
  94713. unsigned char *buffer;
  94714. unsigned char *ptr;
  94715. long storage;
  94716. } oggpack_buffer;
  94717. typedef struct {
  94718. unsigned char *header;
  94719. long header_len;
  94720. unsigned char *body;
  94721. long body_len;
  94722. } ogg_page;
  94723. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94724. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94725. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94726. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94727. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94728. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94729. }
  94730. typedef struct {
  94731. unsigned char *body_data; /* bytes from packet bodies */
  94732. long body_storage; /* storage elements allocated */
  94733. long body_fill; /* elements stored; fill mark */
  94734. long body_returned; /* elements of fill returned */
  94735. int *lacing_vals; /* The values that will go to the segment table */
  94736. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94737. this way, but it is simple coupled to the
  94738. lacing fifo */
  94739. long lacing_storage;
  94740. long lacing_fill;
  94741. long lacing_packet;
  94742. long lacing_returned;
  94743. unsigned char header[282]; /* working space for header encode */
  94744. int header_fill;
  94745. int e_o_s; /* set when we have buffered the last packet in the
  94746. logical bitstream */
  94747. int b_o_s; /* set after we've written the initial page
  94748. of a logical bitstream */
  94749. long serialno;
  94750. long pageno;
  94751. ogg_int64_t packetno; /* sequence number for decode; the framing
  94752. knows where there's a hole in the data,
  94753. but we need coupling so that the codec
  94754. (which is in a seperate abstraction
  94755. layer) also knows about the gap */
  94756. ogg_int64_t granulepos;
  94757. } ogg_stream_state;
  94758. typedef struct {
  94759. unsigned char *packet;
  94760. long bytes;
  94761. long b_o_s;
  94762. long e_o_s;
  94763. ogg_int64_t granulepos;
  94764. ogg_int64_t packetno; /* sequence number for decode; the framing
  94765. knows where there's a hole in the data,
  94766. but we need coupling so that the codec
  94767. (which is in a seperate abstraction
  94768. layer) also knows about the gap */
  94769. } ogg_packet;
  94770. typedef struct {
  94771. unsigned char *data;
  94772. int storage;
  94773. int fill;
  94774. int returned;
  94775. int unsynced;
  94776. int headerbytes;
  94777. int bodybytes;
  94778. } ogg_sync_state;
  94779. extern void oggpack_writeinit(oggpack_buffer *b);
  94780. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94781. extern void oggpack_writealign(oggpack_buffer *b);
  94782. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94783. extern void oggpack_reset(oggpack_buffer *b);
  94784. extern void oggpack_writeclear(oggpack_buffer *b);
  94785. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94786. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94787. extern long oggpack_look(oggpack_buffer *b,int bits);
  94788. extern long oggpack_look1(oggpack_buffer *b);
  94789. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94790. extern void oggpack_adv1(oggpack_buffer *b);
  94791. extern long oggpack_read(oggpack_buffer *b,int bits);
  94792. extern long oggpack_read1(oggpack_buffer *b);
  94793. extern long oggpack_bytes(oggpack_buffer *b);
  94794. extern long oggpack_bits(oggpack_buffer *b);
  94795. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94796. extern void oggpackB_writeinit(oggpack_buffer *b);
  94797. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94798. extern void oggpackB_writealign(oggpack_buffer *b);
  94799. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94800. extern void oggpackB_reset(oggpack_buffer *b);
  94801. extern void oggpackB_writeclear(oggpack_buffer *b);
  94802. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94803. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94804. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94805. extern long oggpackB_look1(oggpack_buffer *b);
  94806. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94807. extern void oggpackB_adv1(oggpack_buffer *b);
  94808. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94809. extern long oggpackB_read1(oggpack_buffer *b);
  94810. extern long oggpackB_bytes(oggpack_buffer *b);
  94811. extern long oggpackB_bits(oggpack_buffer *b);
  94812. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94813. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94814. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94815. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94816. extern int ogg_sync_init(ogg_sync_state *oy);
  94817. extern int ogg_sync_clear(ogg_sync_state *oy);
  94818. extern int ogg_sync_reset(ogg_sync_state *oy);
  94819. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94820. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94821. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94822. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94823. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94824. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94825. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94826. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94827. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94828. extern int ogg_stream_clear(ogg_stream_state *os);
  94829. extern int ogg_stream_reset(ogg_stream_state *os);
  94830. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94831. extern int ogg_stream_destroy(ogg_stream_state *os);
  94832. extern int ogg_stream_eos(ogg_stream_state *os);
  94833. extern void ogg_page_checksum_set(ogg_page *og);
  94834. extern int ogg_page_version(ogg_page *og);
  94835. extern int ogg_page_continued(ogg_page *og);
  94836. extern int ogg_page_bos(ogg_page *og);
  94837. extern int ogg_page_eos(ogg_page *og);
  94838. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94839. extern int ogg_page_serialno(ogg_page *og);
  94840. extern long ogg_page_pageno(ogg_page *og);
  94841. extern int ogg_page_packets(ogg_page *og);
  94842. extern void ogg_packet_clear(ogg_packet *op);
  94843. #ifdef __cplusplus
  94844. }
  94845. #endif
  94846. #endif /* _OGG_H */
  94847. /*** End of inlined file: ogg.h ***/
  94848. typedef struct vorbis_info{
  94849. int version;
  94850. int channels;
  94851. long rate;
  94852. long bitrate_upper;
  94853. long bitrate_nominal;
  94854. long bitrate_lower;
  94855. long bitrate_window;
  94856. void *codec_setup;
  94857. } vorbis_info;
  94858. typedef struct vorbis_dsp_state{
  94859. int analysisp;
  94860. vorbis_info *vi;
  94861. float **pcm;
  94862. float **pcmret;
  94863. int pcm_storage;
  94864. int pcm_current;
  94865. int pcm_returned;
  94866. int preextrapolate;
  94867. int eofflag;
  94868. long lW;
  94869. long W;
  94870. long nW;
  94871. long centerW;
  94872. ogg_int64_t granulepos;
  94873. ogg_int64_t sequence;
  94874. ogg_int64_t glue_bits;
  94875. ogg_int64_t time_bits;
  94876. ogg_int64_t floor_bits;
  94877. ogg_int64_t res_bits;
  94878. void *backend_state;
  94879. } vorbis_dsp_state;
  94880. typedef struct vorbis_block{
  94881. float **pcm; /* this is a pointer into local storage */
  94882. oggpack_buffer opb;
  94883. long lW;
  94884. long W;
  94885. long nW;
  94886. int pcmend;
  94887. int mode;
  94888. int eofflag;
  94889. ogg_int64_t granulepos;
  94890. ogg_int64_t sequence;
  94891. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94892. void *localstore;
  94893. long localtop;
  94894. long localalloc;
  94895. long totaluse;
  94896. struct alloc_chain *reap;
  94897. long glue_bits;
  94898. long time_bits;
  94899. long floor_bits;
  94900. long res_bits;
  94901. void *internal;
  94902. } vorbis_block;
  94903. struct alloc_chain{
  94904. void *ptr;
  94905. struct alloc_chain *next;
  94906. };
  94907. typedef struct vorbis_comment{
  94908. char **user_comments;
  94909. int *comment_lengths;
  94910. int comments;
  94911. char *vendor;
  94912. } vorbis_comment;
  94913. extern void vorbis_info_init(vorbis_info *vi);
  94914. extern void vorbis_info_clear(vorbis_info *vi);
  94915. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94916. extern void vorbis_comment_init(vorbis_comment *vc);
  94917. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94918. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94919. const char *tag, char *contents);
  94920. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94921. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94922. extern void vorbis_comment_clear(vorbis_comment *vc);
  94923. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94924. extern int vorbis_block_clear(vorbis_block *vb);
  94925. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94926. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94927. ogg_int64_t granulepos);
  94928. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94929. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94930. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94931. vorbis_comment *vc,
  94932. ogg_packet *op,
  94933. ogg_packet *op_comm,
  94934. ogg_packet *op_code);
  94935. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94936. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94937. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94938. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94939. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94940. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94941. ogg_packet *op);
  94942. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94943. ogg_packet *op);
  94944. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94945. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94946. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94947. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94948. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94949. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94950. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94951. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94952. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94953. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94954. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94955. #define OV_FALSE -1
  94956. #define OV_EOF -2
  94957. #define OV_HOLE -3
  94958. #define OV_EREAD -128
  94959. #define OV_EFAULT -129
  94960. #define OV_EIMPL -130
  94961. #define OV_EINVAL -131
  94962. #define OV_ENOTVORBIS -132
  94963. #define OV_EBADHEADER -133
  94964. #define OV_EVERSION -134
  94965. #define OV_ENOTAUDIO -135
  94966. #define OV_EBADPACKET -136
  94967. #define OV_EBADLINK -137
  94968. #define OV_ENOSEEK -138
  94969. #ifdef __cplusplus
  94970. }
  94971. #endif /* __cplusplus */
  94972. #endif
  94973. /*** End of inlined file: codec.h ***/
  94974. extern int vorbis_encode_init(vorbis_info *vi,
  94975. long channels,
  94976. long rate,
  94977. long max_bitrate,
  94978. long nominal_bitrate,
  94979. long min_bitrate);
  94980. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94981. long channels,
  94982. long rate,
  94983. long max_bitrate,
  94984. long nominal_bitrate,
  94985. long min_bitrate);
  94986. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94987. long channels,
  94988. long rate,
  94989. float quality /* quality level from 0. (lo) to 1. (hi) */
  94990. );
  94991. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94992. long channels,
  94993. long rate,
  94994. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94995. );
  94996. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94997. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94998. #define OV_ECTL_RATEMANAGE_GET 0x10
  94999. #define OV_ECTL_RATEMANAGE_SET 0x11
  95000. #define OV_ECTL_RATEMANAGE_AVG 0x12
  95001. #define OV_ECTL_RATEMANAGE_HARD 0x13
  95002. struct ovectl_ratemanage_arg {
  95003. int management_active;
  95004. long bitrate_hard_min;
  95005. long bitrate_hard_max;
  95006. double bitrate_hard_window;
  95007. long bitrate_av_lo;
  95008. long bitrate_av_hi;
  95009. double bitrate_av_window;
  95010. double bitrate_av_window_center;
  95011. };
  95012. #define OV_ECTL_RATEMANAGE2_GET 0x14
  95013. #define OV_ECTL_RATEMANAGE2_SET 0x15
  95014. struct ovectl_ratemanage2_arg {
  95015. int management_active;
  95016. long bitrate_limit_min_kbps;
  95017. long bitrate_limit_max_kbps;
  95018. long bitrate_limit_reservoir_bits;
  95019. double bitrate_limit_reservoir_bias;
  95020. long bitrate_average_kbps;
  95021. double bitrate_average_damping;
  95022. };
  95023. #define OV_ECTL_LOWPASS_GET 0x20
  95024. #define OV_ECTL_LOWPASS_SET 0x21
  95025. #define OV_ECTL_IBLOCK_GET 0x30
  95026. #define OV_ECTL_IBLOCK_SET 0x31
  95027. #ifdef __cplusplus
  95028. }
  95029. #endif /* __cplusplus */
  95030. #endif
  95031. /*** End of inlined file: vorbisenc.h ***/
  95032. /*** Start of inlined file: vorbisfile.h ***/
  95033. #ifndef _OV_FILE_H_
  95034. #define _OV_FILE_H_
  95035. #ifdef __cplusplus
  95036. extern "C"
  95037. {
  95038. #endif /* __cplusplus */
  95039. #include <stdio.h>
  95040. typedef struct {
  95041. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  95042. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  95043. int (*close_func) (void *datasource);
  95044. long (*tell_func) (void *datasource);
  95045. } ov_callbacks;
  95046. #define NOTOPEN 0
  95047. #define PARTOPEN 1
  95048. #define OPENED 2
  95049. #define STREAMSET 3
  95050. #define INITSET 4
  95051. typedef struct OggVorbis_File {
  95052. void *datasource; /* Pointer to a FILE *, etc. */
  95053. int seekable;
  95054. ogg_int64_t offset;
  95055. ogg_int64_t end;
  95056. ogg_sync_state oy;
  95057. int links;
  95058. ogg_int64_t *offsets;
  95059. ogg_int64_t *dataoffsets;
  95060. long *serialnos;
  95061. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  95062. compatability; x2 size, stores both
  95063. beginning and end values */
  95064. vorbis_info *vi;
  95065. vorbis_comment *vc;
  95066. ogg_int64_t pcm_offset;
  95067. int ready_state;
  95068. long current_serialno;
  95069. int current_link;
  95070. double bittrack;
  95071. double samptrack;
  95072. ogg_stream_state os; /* take physical pages, weld into a logical
  95073. stream of packets */
  95074. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  95075. vorbis_block vb; /* local working space for packet->PCM decode */
  95076. ov_callbacks callbacks;
  95077. } OggVorbis_File;
  95078. extern int ov_clear(OggVorbis_File *vf);
  95079. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95080. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  95081. char *initial, long ibytes, ov_callbacks callbacks);
  95082. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95083. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  95084. char *initial, long ibytes, ov_callbacks callbacks);
  95085. extern int ov_test_open(OggVorbis_File *vf);
  95086. extern long ov_bitrate(OggVorbis_File *vf,int i);
  95087. extern long ov_bitrate_instant(OggVorbis_File *vf);
  95088. extern long ov_streams(OggVorbis_File *vf);
  95089. extern long ov_seekable(OggVorbis_File *vf);
  95090. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  95091. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  95092. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  95093. extern double ov_time_total(OggVorbis_File *vf,int i);
  95094. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95095. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95096. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  95097. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  95098. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  95099. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95100. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95101. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95102. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  95103. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  95104. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  95105. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  95106. extern double ov_time_tell(OggVorbis_File *vf);
  95107. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  95108. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  95109. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  95110. int *bitstream);
  95111. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  95112. int bigendianp,int word,int sgned,int *bitstream);
  95113. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  95114. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  95115. extern int ov_halfrate_p(OggVorbis_File *vf);
  95116. #ifdef __cplusplus
  95117. }
  95118. #endif /* __cplusplus */
  95119. #endif
  95120. /*** End of inlined file: vorbisfile.h ***/
  95121. /*** Start of inlined file: bitwise.c ***/
  95122. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95123. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95124. // tasks..
  95125. #if JUCE_MSVC
  95126. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95127. #endif
  95128. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95129. #if JUCE_USE_OGGVORBIS
  95130. #include <string.h>
  95131. #include <stdlib.h>
  95132. #define BUFFER_INCREMENT 256
  95133. static const unsigned long mask[]=
  95134. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  95135. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  95136. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  95137. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  95138. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  95139. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  95140. 0x3fffffff,0x7fffffff,0xffffffff };
  95141. static const unsigned int mask8B[]=
  95142. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  95143. void oggpack_writeinit(oggpack_buffer *b){
  95144. memset(b,0,sizeof(*b));
  95145. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  95146. b->buffer[0]='\0';
  95147. b->storage=BUFFER_INCREMENT;
  95148. }
  95149. void oggpackB_writeinit(oggpack_buffer *b){
  95150. oggpack_writeinit(b);
  95151. }
  95152. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  95153. long bytes=bits>>3;
  95154. bits-=bytes*8;
  95155. b->ptr=b->buffer+bytes;
  95156. b->endbit=bits;
  95157. b->endbyte=bytes;
  95158. *b->ptr&=mask[bits];
  95159. }
  95160. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  95161. long bytes=bits>>3;
  95162. bits-=bytes*8;
  95163. b->ptr=b->buffer+bytes;
  95164. b->endbit=bits;
  95165. b->endbyte=bytes;
  95166. *b->ptr&=mask8B[bits];
  95167. }
  95168. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  95169. if(b->endbyte+4>=b->storage){
  95170. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95171. b->storage+=BUFFER_INCREMENT;
  95172. b->ptr=b->buffer+b->endbyte;
  95173. }
  95174. value&=mask[bits];
  95175. bits+=b->endbit;
  95176. b->ptr[0]|=value<<b->endbit;
  95177. if(bits>=8){
  95178. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  95179. if(bits>=16){
  95180. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  95181. if(bits>=24){
  95182. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  95183. if(bits>=32){
  95184. if(b->endbit)
  95185. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  95186. else
  95187. b->ptr[4]=0;
  95188. }
  95189. }
  95190. }
  95191. }
  95192. b->endbyte+=bits/8;
  95193. b->ptr+=bits/8;
  95194. b->endbit=bits&7;
  95195. }
  95196. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  95197. if(b->endbyte+4>=b->storage){
  95198. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95199. b->storage+=BUFFER_INCREMENT;
  95200. b->ptr=b->buffer+b->endbyte;
  95201. }
  95202. value=(value&mask[bits])<<(32-bits);
  95203. bits+=b->endbit;
  95204. b->ptr[0]|=value>>(24+b->endbit);
  95205. if(bits>=8){
  95206. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  95207. if(bits>=16){
  95208. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  95209. if(bits>=24){
  95210. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  95211. if(bits>=32){
  95212. if(b->endbit)
  95213. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  95214. else
  95215. b->ptr[4]=0;
  95216. }
  95217. }
  95218. }
  95219. }
  95220. b->endbyte+=bits/8;
  95221. b->ptr+=bits/8;
  95222. b->endbit=bits&7;
  95223. }
  95224. void oggpack_writealign(oggpack_buffer *b){
  95225. int bits=8-b->endbit;
  95226. if(bits<8)
  95227. oggpack_write(b,0,bits);
  95228. }
  95229. void oggpackB_writealign(oggpack_buffer *b){
  95230. int bits=8-b->endbit;
  95231. if(bits<8)
  95232. oggpackB_write(b,0,bits);
  95233. }
  95234. static void oggpack_writecopy_helper(oggpack_buffer *b,
  95235. void *source,
  95236. long bits,
  95237. void (*w)(oggpack_buffer *,
  95238. unsigned long,
  95239. int),
  95240. int msb){
  95241. unsigned char *ptr=(unsigned char *)source;
  95242. long bytes=bits/8;
  95243. bits-=bytes*8;
  95244. if(b->endbit){
  95245. int i;
  95246. for(i=0;i<bytes;i++)
  95247. w(b,(unsigned long)(ptr[i]),8);
  95248. }else{
  95249. if(b->endbyte+bytes+1>=b->storage){
  95250. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  95251. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  95252. b->ptr=b->buffer+b->endbyte;
  95253. }
  95254. memmove(b->ptr,source,bytes);
  95255. b->ptr+=bytes;
  95256. b->endbyte+=bytes;
  95257. *b->ptr=0;
  95258. }
  95259. if(bits){
  95260. if(msb)
  95261. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  95262. else
  95263. w(b,(unsigned long)(ptr[bytes]),bits);
  95264. }
  95265. }
  95266. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  95267. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  95268. }
  95269. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  95270. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  95271. }
  95272. void oggpack_reset(oggpack_buffer *b){
  95273. b->ptr=b->buffer;
  95274. b->buffer[0]=0;
  95275. b->endbit=b->endbyte=0;
  95276. }
  95277. void oggpackB_reset(oggpack_buffer *b){
  95278. oggpack_reset(b);
  95279. }
  95280. void oggpack_writeclear(oggpack_buffer *b){
  95281. _ogg_free(b->buffer);
  95282. memset(b,0,sizeof(*b));
  95283. }
  95284. void oggpackB_writeclear(oggpack_buffer *b){
  95285. oggpack_writeclear(b);
  95286. }
  95287. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95288. memset(b,0,sizeof(*b));
  95289. b->buffer=b->ptr=buf;
  95290. b->storage=bytes;
  95291. }
  95292. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95293. oggpack_readinit(b,buf,bytes);
  95294. }
  95295. long oggpack_look(oggpack_buffer *b,int bits){
  95296. unsigned long ret;
  95297. unsigned long m=mask[bits];
  95298. bits+=b->endbit;
  95299. if(b->endbyte+4>=b->storage){
  95300. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95301. }
  95302. ret=b->ptr[0]>>b->endbit;
  95303. if(bits>8){
  95304. ret|=b->ptr[1]<<(8-b->endbit);
  95305. if(bits>16){
  95306. ret|=b->ptr[2]<<(16-b->endbit);
  95307. if(bits>24){
  95308. ret|=b->ptr[3]<<(24-b->endbit);
  95309. if(bits>32 && b->endbit)
  95310. ret|=b->ptr[4]<<(32-b->endbit);
  95311. }
  95312. }
  95313. }
  95314. return(m&ret);
  95315. }
  95316. long oggpackB_look(oggpack_buffer *b,int bits){
  95317. unsigned long ret;
  95318. int m=32-bits;
  95319. bits+=b->endbit;
  95320. if(b->endbyte+4>=b->storage){
  95321. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95322. }
  95323. ret=b->ptr[0]<<(24+b->endbit);
  95324. if(bits>8){
  95325. ret|=b->ptr[1]<<(16+b->endbit);
  95326. if(bits>16){
  95327. ret|=b->ptr[2]<<(8+b->endbit);
  95328. if(bits>24){
  95329. ret|=b->ptr[3]<<(b->endbit);
  95330. if(bits>32 && b->endbit)
  95331. ret|=b->ptr[4]>>(8-b->endbit);
  95332. }
  95333. }
  95334. }
  95335. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95336. }
  95337. long oggpack_look1(oggpack_buffer *b){
  95338. if(b->endbyte>=b->storage)return(-1);
  95339. return((b->ptr[0]>>b->endbit)&1);
  95340. }
  95341. long oggpackB_look1(oggpack_buffer *b){
  95342. if(b->endbyte>=b->storage)return(-1);
  95343. return((b->ptr[0]>>(7-b->endbit))&1);
  95344. }
  95345. void oggpack_adv(oggpack_buffer *b,int bits){
  95346. bits+=b->endbit;
  95347. b->ptr+=bits/8;
  95348. b->endbyte+=bits/8;
  95349. b->endbit=bits&7;
  95350. }
  95351. void oggpackB_adv(oggpack_buffer *b,int bits){
  95352. oggpack_adv(b,bits);
  95353. }
  95354. void oggpack_adv1(oggpack_buffer *b){
  95355. if(++(b->endbit)>7){
  95356. b->endbit=0;
  95357. b->ptr++;
  95358. b->endbyte++;
  95359. }
  95360. }
  95361. void oggpackB_adv1(oggpack_buffer *b){
  95362. oggpack_adv1(b);
  95363. }
  95364. long oggpack_read(oggpack_buffer *b,int bits){
  95365. long ret;
  95366. unsigned long m=mask[bits];
  95367. bits+=b->endbit;
  95368. if(b->endbyte+4>=b->storage){
  95369. ret=-1L;
  95370. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95371. }
  95372. ret=b->ptr[0]>>b->endbit;
  95373. if(bits>8){
  95374. ret|=b->ptr[1]<<(8-b->endbit);
  95375. if(bits>16){
  95376. ret|=b->ptr[2]<<(16-b->endbit);
  95377. if(bits>24){
  95378. ret|=b->ptr[3]<<(24-b->endbit);
  95379. if(bits>32 && b->endbit){
  95380. ret|=b->ptr[4]<<(32-b->endbit);
  95381. }
  95382. }
  95383. }
  95384. }
  95385. ret&=m;
  95386. overflow:
  95387. b->ptr+=bits/8;
  95388. b->endbyte+=bits/8;
  95389. b->endbit=bits&7;
  95390. return(ret);
  95391. }
  95392. long oggpackB_read(oggpack_buffer *b,int bits){
  95393. long ret;
  95394. long m=32-bits;
  95395. bits+=b->endbit;
  95396. if(b->endbyte+4>=b->storage){
  95397. ret=-1L;
  95398. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95399. }
  95400. ret=b->ptr[0]<<(24+b->endbit);
  95401. if(bits>8){
  95402. ret|=b->ptr[1]<<(16+b->endbit);
  95403. if(bits>16){
  95404. ret|=b->ptr[2]<<(8+b->endbit);
  95405. if(bits>24){
  95406. ret|=b->ptr[3]<<(b->endbit);
  95407. if(bits>32 && b->endbit)
  95408. ret|=b->ptr[4]>>(8-b->endbit);
  95409. }
  95410. }
  95411. }
  95412. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95413. overflow:
  95414. b->ptr+=bits/8;
  95415. b->endbyte+=bits/8;
  95416. b->endbit=bits&7;
  95417. return(ret);
  95418. }
  95419. long oggpack_read1(oggpack_buffer *b){
  95420. long ret;
  95421. if(b->endbyte>=b->storage){
  95422. ret=-1L;
  95423. goto overflow;
  95424. }
  95425. ret=(b->ptr[0]>>b->endbit)&1;
  95426. overflow:
  95427. b->endbit++;
  95428. if(b->endbit>7){
  95429. b->endbit=0;
  95430. b->ptr++;
  95431. b->endbyte++;
  95432. }
  95433. return(ret);
  95434. }
  95435. long oggpackB_read1(oggpack_buffer *b){
  95436. long ret;
  95437. if(b->endbyte>=b->storage){
  95438. ret=-1L;
  95439. goto overflow;
  95440. }
  95441. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95442. overflow:
  95443. b->endbit++;
  95444. if(b->endbit>7){
  95445. b->endbit=0;
  95446. b->ptr++;
  95447. b->endbyte++;
  95448. }
  95449. return(ret);
  95450. }
  95451. long oggpack_bytes(oggpack_buffer *b){
  95452. return(b->endbyte+(b->endbit+7)/8);
  95453. }
  95454. long oggpack_bits(oggpack_buffer *b){
  95455. return(b->endbyte*8+b->endbit);
  95456. }
  95457. long oggpackB_bytes(oggpack_buffer *b){
  95458. return oggpack_bytes(b);
  95459. }
  95460. long oggpackB_bits(oggpack_buffer *b){
  95461. return oggpack_bits(b);
  95462. }
  95463. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95464. return(b->buffer);
  95465. }
  95466. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95467. return oggpack_get_buffer(b);
  95468. }
  95469. #ifdef _V_SELFTEST
  95470. #include <stdio.h>
  95471. static int ilog(unsigned int v){
  95472. int ret=0;
  95473. while(v){
  95474. ret++;
  95475. v>>=1;
  95476. }
  95477. return(ret);
  95478. }
  95479. oggpack_buffer o;
  95480. oggpack_buffer r;
  95481. void report(char *in){
  95482. fprintf(stderr,"%s",in);
  95483. exit(1);
  95484. }
  95485. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95486. long bytes,i;
  95487. unsigned char *buffer;
  95488. oggpack_reset(&o);
  95489. for(i=0;i<vals;i++)
  95490. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95491. buffer=oggpack_get_buffer(&o);
  95492. bytes=oggpack_bytes(&o);
  95493. if(bytes!=compsize)report("wrong number of bytes!\n");
  95494. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95495. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95496. report("wrote incorrect value!\n");
  95497. }
  95498. oggpack_readinit(&r,buffer,bytes);
  95499. for(i=0;i<vals;i++){
  95500. int tbit=bits?bits:ilog(b[i]);
  95501. if(oggpack_look(&r,tbit)==-1)
  95502. report("out of data!\n");
  95503. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95504. report("looked at incorrect value!\n");
  95505. if(tbit==1)
  95506. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95507. report("looked at single bit incorrect value!\n");
  95508. if(tbit==1){
  95509. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95510. report("read incorrect single bit value!\n");
  95511. }else{
  95512. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95513. report("read incorrect value!\n");
  95514. }
  95515. }
  95516. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95517. }
  95518. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95519. long bytes,i;
  95520. unsigned char *buffer;
  95521. oggpackB_reset(&o);
  95522. for(i=0;i<vals;i++)
  95523. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95524. buffer=oggpackB_get_buffer(&o);
  95525. bytes=oggpackB_bytes(&o);
  95526. if(bytes!=compsize)report("wrong number of bytes!\n");
  95527. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95528. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95529. report("wrote incorrect value!\n");
  95530. }
  95531. oggpackB_readinit(&r,buffer,bytes);
  95532. for(i=0;i<vals;i++){
  95533. int tbit=bits?bits:ilog(b[i]);
  95534. if(oggpackB_look(&r,tbit)==-1)
  95535. report("out of data!\n");
  95536. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95537. report("looked at incorrect value!\n");
  95538. if(tbit==1)
  95539. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95540. report("looked at single bit incorrect value!\n");
  95541. if(tbit==1){
  95542. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95543. report("read incorrect single bit value!\n");
  95544. }else{
  95545. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95546. report("read incorrect value!\n");
  95547. }
  95548. }
  95549. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95550. }
  95551. int main(void){
  95552. unsigned char *buffer;
  95553. long bytes,i;
  95554. static unsigned long testbuffer1[]=
  95555. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95556. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95557. int test1size=43;
  95558. static unsigned long testbuffer2[]=
  95559. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95560. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95561. 85525151,0,12321,1,349528352};
  95562. int test2size=21;
  95563. static unsigned long testbuffer3[]=
  95564. {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,
  95565. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95566. int test3size=56;
  95567. static unsigned long large[]=
  95568. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95569. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95570. 85525151,0,12321,1,2146528352};
  95571. int onesize=33;
  95572. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95573. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95574. 223,4};
  95575. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95576. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95577. 245,251,128};
  95578. int twosize=6;
  95579. static int two[6]={61,255,255,251,231,29};
  95580. static int twoB[6]={247,63,255,253,249,120};
  95581. int threesize=54;
  95582. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95583. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95584. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95585. 100,52,4,14,18,86,77,1};
  95586. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95587. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95588. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95589. 200,20,254,4,58,106,176,144,0};
  95590. int foursize=38;
  95591. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95592. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95593. 28,2,133,0,1};
  95594. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95595. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95596. 129,10,4,32};
  95597. int fivesize=45;
  95598. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95599. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95600. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95601. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95602. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95603. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95604. int sixsize=7;
  95605. static int six[7]={17,177,170,242,169,19,148};
  95606. static int sixB[7]={136,141,85,79,149,200,41};
  95607. oggpack_writeinit(&o);
  95608. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95609. cliptest(testbuffer1,test1size,0,one,onesize);
  95610. fprintf(stderr,"ok.");
  95611. fprintf(stderr,"\nNull bit call (LSb): ");
  95612. cliptest(testbuffer3,test3size,0,two,twosize);
  95613. fprintf(stderr,"ok.");
  95614. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95615. cliptest(testbuffer2,test2size,0,three,threesize);
  95616. fprintf(stderr,"ok.");
  95617. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95618. oggpack_reset(&o);
  95619. for(i=0;i<test2size;i++)
  95620. oggpack_write(&o,large[i],32);
  95621. buffer=oggpack_get_buffer(&o);
  95622. bytes=oggpack_bytes(&o);
  95623. oggpack_readinit(&r,buffer,bytes);
  95624. for(i=0;i<test2size;i++){
  95625. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95626. if(oggpack_look(&r,32)!=large[i]){
  95627. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95628. oggpack_look(&r,32),large[i]);
  95629. report("read incorrect value!\n");
  95630. }
  95631. oggpack_adv(&r,32);
  95632. }
  95633. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95634. fprintf(stderr,"ok.");
  95635. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95636. cliptest(testbuffer1,test1size,7,four,foursize);
  95637. fprintf(stderr,"ok.");
  95638. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95639. cliptest(testbuffer2,test2size,17,five,fivesize);
  95640. fprintf(stderr,"ok.");
  95641. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95642. cliptest(testbuffer3,test3size,1,six,sixsize);
  95643. fprintf(stderr,"ok.");
  95644. fprintf(stderr,"\nTesting read past end (LSb): ");
  95645. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95646. for(i=0;i<64;i++){
  95647. if(oggpack_read(&r,1)!=0){
  95648. fprintf(stderr,"failed; got -1 prematurely.\n");
  95649. exit(1);
  95650. }
  95651. }
  95652. if(oggpack_look(&r,1)!=-1 ||
  95653. oggpack_read(&r,1)!=-1){
  95654. fprintf(stderr,"failed; read past end without -1.\n");
  95655. exit(1);
  95656. }
  95657. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95658. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95659. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95660. exit(1);
  95661. }
  95662. if(oggpack_look(&r,18)!=0 ||
  95663. oggpack_look(&r,18)!=0){
  95664. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95665. exit(1);
  95666. }
  95667. if(oggpack_look(&r,19)!=-1 ||
  95668. oggpack_look(&r,19)!=-1){
  95669. fprintf(stderr,"failed; read past end without -1.\n");
  95670. exit(1);
  95671. }
  95672. if(oggpack_look(&r,32)!=-1 ||
  95673. oggpack_look(&r,32)!=-1){
  95674. fprintf(stderr,"failed; read past end without -1.\n");
  95675. exit(1);
  95676. }
  95677. oggpack_writeclear(&o);
  95678. fprintf(stderr,"ok.\n");
  95679. oggpackB_writeinit(&o);
  95680. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95681. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95682. fprintf(stderr,"ok.");
  95683. fprintf(stderr,"\nNull bit call (MSb): ");
  95684. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95685. fprintf(stderr,"ok.");
  95686. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95687. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95688. fprintf(stderr,"ok.");
  95689. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95690. oggpackB_reset(&o);
  95691. for(i=0;i<test2size;i++)
  95692. oggpackB_write(&o,large[i],32);
  95693. buffer=oggpackB_get_buffer(&o);
  95694. bytes=oggpackB_bytes(&o);
  95695. oggpackB_readinit(&r,buffer,bytes);
  95696. for(i=0;i<test2size;i++){
  95697. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95698. if(oggpackB_look(&r,32)!=large[i]){
  95699. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95700. oggpackB_look(&r,32),large[i]);
  95701. report("read incorrect value!\n");
  95702. }
  95703. oggpackB_adv(&r,32);
  95704. }
  95705. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95706. fprintf(stderr,"ok.");
  95707. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95708. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95709. fprintf(stderr,"ok.");
  95710. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95711. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95712. fprintf(stderr,"ok.");
  95713. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95714. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95715. fprintf(stderr,"ok.");
  95716. fprintf(stderr,"\nTesting read past end (MSb): ");
  95717. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95718. for(i=0;i<64;i++){
  95719. if(oggpackB_read(&r,1)!=0){
  95720. fprintf(stderr,"failed; got -1 prematurely.\n");
  95721. exit(1);
  95722. }
  95723. }
  95724. if(oggpackB_look(&r,1)!=-1 ||
  95725. oggpackB_read(&r,1)!=-1){
  95726. fprintf(stderr,"failed; read past end without -1.\n");
  95727. exit(1);
  95728. }
  95729. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95730. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95731. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95732. exit(1);
  95733. }
  95734. if(oggpackB_look(&r,18)!=0 ||
  95735. oggpackB_look(&r,18)!=0){
  95736. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95737. exit(1);
  95738. }
  95739. if(oggpackB_look(&r,19)!=-1 ||
  95740. oggpackB_look(&r,19)!=-1){
  95741. fprintf(stderr,"failed; read past end without -1.\n");
  95742. exit(1);
  95743. }
  95744. if(oggpackB_look(&r,32)!=-1 ||
  95745. oggpackB_look(&r,32)!=-1){
  95746. fprintf(stderr,"failed; read past end without -1.\n");
  95747. exit(1);
  95748. }
  95749. oggpackB_writeclear(&o);
  95750. fprintf(stderr,"ok.\n\n");
  95751. return(0);
  95752. }
  95753. #endif /* _V_SELFTEST */
  95754. #undef BUFFER_INCREMENT
  95755. #endif
  95756. /*** End of inlined file: bitwise.c ***/
  95757. /*** Start of inlined file: framing.c ***/
  95758. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95759. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95760. // tasks..
  95761. #if JUCE_MSVC
  95762. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95763. #endif
  95764. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95765. #if JUCE_USE_OGGVORBIS
  95766. #include <stdlib.h>
  95767. #include <string.h>
  95768. int ogg_page_version(ogg_page *og){
  95769. return((int)(og->header[4]));
  95770. }
  95771. int ogg_page_continued(ogg_page *og){
  95772. return((int)(og->header[5]&0x01));
  95773. }
  95774. int ogg_page_bos(ogg_page *og){
  95775. return((int)(og->header[5]&0x02));
  95776. }
  95777. int ogg_page_eos(ogg_page *og){
  95778. return((int)(og->header[5]&0x04));
  95779. }
  95780. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95781. unsigned char *page=og->header;
  95782. ogg_int64_t granulepos=page[13]&(0xff);
  95783. granulepos= (granulepos<<8)|(page[12]&0xff);
  95784. granulepos= (granulepos<<8)|(page[11]&0xff);
  95785. granulepos= (granulepos<<8)|(page[10]&0xff);
  95786. granulepos= (granulepos<<8)|(page[9]&0xff);
  95787. granulepos= (granulepos<<8)|(page[8]&0xff);
  95788. granulepos= (granulepos<<8)|(page[7]&0xff);
  95789. granulepos= (granulepos<<8)|(page[6]&0xff);
  95790. return(granulepos);
  95791. }
  95792. int ogg_page_serialno(ogg_page *og){
  95793. return(og->header[14] |
  95794. (og->header[15]<<8) |
  95795. (og->header[16]<<16) |
  95796. (og->header[17]<<24));
  95797. }
  95798. long ogg_page_pageno(ogg_page *og){
  95799. return(og->header[18] |
  95800. (og->header[19]<<8) |
  95801. (og->header[20]<<16) |
  95802. (og->header[21]<<24));
  95803. }
  95804. int ogg_page_packets(ogg_page *og){
  95805. int i,n=og->header[26],count=0;
  95806. for(i=0;i<n;i++)
  95807. if(og->header[27+i]<255)count++;
  95808. return(count);
  95809. }
  95810. #if 0
  95811. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95812. int i;
  95813. unsigned long r;
  95814. r = index << 24;
  95815. for (i=0; i<8; i++)
  95816. if (r & 0x80000000UL)
  95817. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95818. polynomial, although we use an
  95819. unreflected alg and an init/final
  95820. of 0, not 0xffffffff */
  95821. else
  95822. r<<=1;
  95823. return (r & 0xffffffffUL);
  95824. }
  95825. #endif
  95826. static const ogg_uint32_t crc_lookup[256]={
  95827. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95828. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95829. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95830. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95831. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95832. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95833. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95834. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95835. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95836. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95837. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95838. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95839. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95840. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95841. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95842. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95843. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95844. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95845. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95846. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95847. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95848. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95849. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95850. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95851. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95852. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95853. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95854. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95855. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95856. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95857. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95858. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95859. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95860. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95861. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95862. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95863. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95864. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95865. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95866. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95867. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95868. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95869. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95870. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95871. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95872. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95873. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95874. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95875. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95876. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95877. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95878. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95879. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95880. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95881. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95882. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95883. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95884. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95885. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95886. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95887. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95888. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95889. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95890. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95891. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95892. if(os){
  95893. memset(os,0,sizeof(*os));
  95894. os->body_storage=16*1024;
  95895. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95896. os->lacing_storage=1024;
  95897. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95898. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95899. os->serialno=serialno;
  95900. return(0);
  95901. }
  95902. return(-1);
  95903. }
  95904. int ogg_stream_clear(ogg_stream_state *os){
  95905. if(os){
  95906. if(os->body_data)_ogg_free(os->body_data);
  95907. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95908. if(os->granule_vals)_ogg_free(os->granule_vals);
  95909. memset(os,0,sizeof(*os));
  95910. }
  95911. return(0);
  95912. }
  95913. int ogg_stream_destroy(ogg_stream_state *os){
  95914. if(os){
  95915. ogg_stream_clear(os);
  95916. _ogg_free(os);
  95917. }
  95918. return(0);
  95919. }
  95920. static void _os_body_expand(ogg_stream_state *os,int needed){
  95921. if(os->body_storage<=os->body_fill+needed){
  95922. os->body_storage+=(needed+1024);
  95923. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95924. }
  95925. }
  95926. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95927. if(os->lacing_storage<=os->lacing_fill+needed){
  95928. os->lacing_storage+=(needed+32);
  95929. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95930. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95931. }
  95932. }
  95933. void ogg_page_checksum_set(ogg_page *og){
  95934. if(og){
  95935. ogg_uint32_t crc_reg=0;
  95936. int i;
  95937. og->header[22]=0;
  95938. og->header[23]=0;
  95939. og->header[24]=0;
  95940. og->header[25]=0;
  95941. for(i=0;i<og->header_len;i++)
  95942. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95943. for(i=0;i<og->body_len;i++)
  95944. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95945. og->header[22]=(unsigned char)(crc_reg&0xff);
  95946. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95947. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95948. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95949. }
  95950. }
  95951. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95952. int lacing_vals=op->bytes/255+1,i;
  95953. if(os->body_returned){
  95954. os->body_fill-=os->body_returned;
  95955. if(os->body_fill)
  95956. memmove(os->body_data,os->body_data+os->body_returned,
  95957. os->body_fill);
  95958. os->body_returned=0;
  95959. }
  95960. _os_body_expand(os,op->bytes);
  95961. _os_lacing_expand(os,lacing_vals);
  95962. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95963. os->body_fill+=op->bytes;
  95964. for(i=0;i<lacing_vals-1;i++){
  95965. os->lacing_vals[os->lacing_fill+i]=255;
  95966. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95967. }
  95968. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95969. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95970. os->lacing_vals[os->lacing_fill]|= 0x100;
  95971. os->lacing_fill+=lacing_vals;
  95972. os->packetno++;
  95973. if(op->e_o_s)os->e_o_s=1;
  95974. return(0);
  95975. }
  95976. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95977. int i;
  95978. int vals=0;
  95979. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95980. int bytes=0;
  95981. long acc=0;
  95982. ogg_int64_t granule_pos=-1;
  95983. if(maxvals==0)return(0);
  95984. if(os->b_o_s==0){ /* 'initial header page' case */
  95985. granule_pos=0;
  95986. for(vals=0;vals<maxvals;vals++){
  95987. if((os->lacing_vals[vals]&0x0ff)<255){
  95988. vals++;
  95989. break;
  95990. }
  95991. }
  95992. }else{
  95993. for(vals=0;vals<maxvals;vals++){
  95994. if(acc>4096)break;
  95995. acc+=os->lacing_vals[vals]&0x0ff;
  95996. if((os->lacing_vals[vals]&0xff)<255)
  95997. granule_pos=os->granule_vals[vals];
  95998. }
  95999. }
  96000. memcpy(os->header,"OggS",4);
  96001. os->header[4]=0x00;
  96002. os->header[5]=0x00;
  96003. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  96004. if(os->b_o_s==0)os->header[5]|=0x02;
  96005. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  96006. os->b_o_s=1;
  96007. for(i=6;i<14;i++){
  96008. os->header[i]=(unsigned char)(granule_pos&0xff);
  96009. granule_pos>>=8;
  96010. }
  96011. {
  96012. long serialno=os->serialno;
  96013. for(i=14;i<18;i++){
  96014. os->header[i]=(unsigned char)(serialno&0xff);
  96015. serialno>>=8;
  96016. }
  96017. }
  96018. if(os->pageno==-1)os->pageno=0; /* because someone called
  96019. stream_reset; this would be a
  96020. strange thing to do in an
  96021. encode stream, but it has
  96022. plausible uses */
  96023. {
  96024. long pageno=os->pageno++;
  96025. for(i=18;i<22;i++){
  96026. os->header[i]=(unsigned char)(pageno&0xff);
  96027. pageno>>=8;
  96028. }
  96029. }
  96030. os->header[22]=0;
  96031. os->header[23]=0;
  96032. os->header[24]=0;
  96033. os->header[25]=0;
  96034. os->header[26]=(unsigned char)(vals&0xff);
  96035. for(i=0;i<vals;i++)
  96036. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  96037. og->header=os->header;
  96038. og->header_len=os->header_fill=vals+27;
  96039. og->body=os->body_data+os->body_returned;
  96040. og->body_len=bytes;
  96041. os->lacing_fill-=vals;
  96042. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  96043. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  96044. os->body_returned+=bytes;
  96045. ogg_page_checksum_set(og);
  96046. return(1);
  96047. }
  96048. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  96049. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  96050. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  96051. os->lacing_fill>=255 || /* 'segment table full' case */
  96052. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  96053. return(ogg_stream_flush(os,og));
  96054. }
  96055. return(0);
  96056. }
  96057. int ogg_stream_eos(ogg_stream_state *os){
  96058. return os->e_o_s;
  96059. }
  96060. int ogg_sync_init(ogg_sync_state *oy){
  96061. if(oy){
  96062. memset(oy,0,sizeof(*oy));
  96063. }
  96064. return(0);
  96065. }
  96066. int ogg_sync_clear(ogg_sync_state *oy){
  96067. if(oy){
  96068. if(oy->data)_ogg_free(oy->data);
  96069. ogg_sync_init(oy);
  96070. }
  96071. return(0);
  96072. }
  96073. int ogg_sync_destroy(ogg_sync_state *oy){
  96074. if(oy){
  96075. ogg_sync_clear(oy);
  96076. _ogg_free(oy);
  96077. }
  96078. return(0);
  96079. }
  96080. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  96081. if(oy->returned){
  96082. oy->fill-=oy->returned;
  96083. if(oy->fill>0)
  96084. memmove(oy->data,oy->data+oy->returned,oy->fill);
  96085. oy->returned=0;
  96086. }
  96087. if(size>oy->storage-oy->fill){
  96088. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  96089. if(oy->data)
  96090. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  96091. else
  96092. oy->data=(unsigned char*) _ogg_malloc(newsize);
  96093. oy->storage=newsize;
  96094. }
  96095. return((char *)oy->data+oy->fill);
  96096. }
  96097. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  96098. if(oy->fill+bytes>oy->storage)return(-1);
  96099. oy->fill+=bytes;
  96100. return(0);
  96101. }
  96102. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  96103. unsigned char *page=oy->data+oy->returned;
  96104. unsigned char *next;
  96105. long bytes=oy->fill-oy->returned;
  96106. if(oy->headerbytes==0){
  96107. int headerbytes,i;
  96108. if(bytes<27)return(0); /* not enough for a header */
  96109. if(memcmp(page,"OggS",4))goto sync_fail;
  96110. headerbytes=page[26]+27;
  96111. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  96112. for(i=0;i<page[26];i++)
  96113. oy->bodybytes+=page[27+i];
  96114. oy->headerbytes=headerbytes;
  96115. }
  96116. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  96117. {
  96118. char chksum[4];
  96119. ogg_page log;
  96120. memcpy(chksum,page+22,4);
  96121. memset(page+22,0,4);
  96122. log.header=page;
  96123. log.header_len=oy->headerbytes;
  96124. log.body=page+oy->headerbytes;
  96125. log.body_len=oy->bodybytes;
  96126. ogg_page_checksum_set(&log);
  96127. if(memcmp(chksum,page+22,4)){
  96128. memcpy(page+22,chksum,4);
  96129. goto sync_fail;
  96130. }
  96131. }
  96132. {
  96133. unsigned char *page=oy->data+oy->returned;
  96134. long bytes;
  96135. if(og){
  96136. og->header=page;
  96137. og->header_len=oy->headerbytes;
  96138. og->body=page+oy->headerbytes;
  96139. og->body_len=oy->bodybytes;
  96140. }
  96141. oy->unsynced=0;
  96142. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  96143. oy->headerbytes=0;
  96144. oy->bodybytes=0;
  96145. return(bytes);
  96146. }
  96147. sync_fail:
  96148. oy->headerbytes=0;
  96149. oy->bodybytes=0;
  96150. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  96151. if(!next)
  96152. next=oy->data+oy->fill;
  96153. oy->returned=next-oy->data;
  96154. return(-(next-page));
  96155. }
  96156. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  96157. for(;;){
  96158. long ret=ogg_sync_pageseek(oy,og);
  96159. if(ret>0){
  96160. return(1);
  96161. }
  96162. if(ret==0){
  96163. return(0);
  96164. }
  96165. if(!oy->unsynced){
  96166. oy->unsynced=1;
  96167. return(-1);
  96168. }
  96169. }
  96170. }
  96171. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  96172. unsigned char *header=og->header;
  96173. unsigned char *body=og->body;
  96174. long bodysize=og->body_len;
  96175. int segptr=0;
  96176. int version=ogg_page_version(og);
  96177. int continued=ogg_page_continued(og);
  96178. int bos=ogg_page_bos(og);
  96179. int eos=ogg_page_eos(og);
  96180. ogg_int64_t granulepos=ogg_page_granulepos(og);
  96181. int serialno=ogg_page_serialno(og);
  96182. long pageno=ogg_page_pageno(og);
  96183. int segments=header[26];
  96184. {
  96185. long lr=os->lacing_returned;
  96186. long br=os->body_returned;
  96187. if(br){
  96188. os->body_fill-=br;
  96189. if(os->body_fill)
  96190. memmove(os->body_data,os->body_data+br,os->body_fill);
  96191. os->body_returned=0;
  96192. }
  96193. if(lr){
  96194. if(os->lacing_fill-lr){
  96195. memmove(os->lacing_vals,os->lacing_vals+lr,
  96196. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  96197. memmove(os->granule_vals,os->granule_vals+lr,
  96198. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  96199. }
  96200. os->lacing_fill-=lr;
  96201. os->lacing_packet-=lr;
  96202. os->lacing_returned=0;
  96203. }
  96204. }
  96205. if(serialno!=os->serialno)return(-1);
  96206. if(version>0)return(-1);
  96207. _os_lacing_expand(os,segments+1);
  96208. if(pageno!=os->pageno){
  96209. int i;
  96210. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  96211. os->body_fill-=os->lacing_vals[i]&0xff;
  96212. os->lacing_fill=os->lacing_packet;
  96213. if(os->pageno!=-1){
  96214. os->lacing_vals[os->lacing_fill++]=0x400;
  96215. os->lacing_packet++;
  96216. }
  96217. }
  96218. if(continued){
  96219. if(os->lacing_fill<1 ||
  96220. os->lacing_vals[os->lacing_fill-1]==0x400){
  96221. bos=0;
  96222. for(;segptr<segments;segptr++){
  96223. int val=header[27+segptr];
  96224. body+=val;
  96225. bodysize-=val;
  96226. if(val<255){
  96227. segptr++;
  96228. break;
  96229. }
  96230. }
  96231. }
  96232. }
  96233. if(bodysize){
  96234. _os_body_expand(os,bodysize);
  96235. memcpy(os->body_data+os->body_fill,body,bodysize);
  96236. os->body_fill+=bodysize;
  96237. }
  96238. {
  96239. int saved=-1;
  96240. while(segptr<segments){
  96241. int val=header[27+segptr];
  96242. os->lacing_vals[os->lacing_fill]=val;
  96243. os->granule_vals[os->lacing_fill]=-1;
  96244. if(bos){
  96245. os->lacing_vals[os->lacing_fill]|=0x100;
  96246. bos=0;
  96247. }
  96248. if(val<255)saved=os->lacing_fill;
  96249. os->lacing_fill++;
  96250. segptr++;
  96251. if(val<255)os->lacing_packet=os->lacing_fill;
  96252. }
  96253. if(saved!=-1){
  96254. os->granule_vals[saved]=granulepos;
  96255. }
  96256. }
  96257. if(eos){
  96258. os->e_o_s=1;
  96259. if(os->lacing_fill>0)
  96260. os->lacing_vals[os->lacing_fill-1]|=0x200;
  96261. }
  96262. os->pageno=pageno+1;
  96263. return(0);
  96264. }
  96265. int ogg_sync_reset(ogg_sync_state *oy){
  96266. oy->fill=0;
  96267. oy->returned=0;
  96268. oy->unsynced=0;
  96269. oy->headerbytes=0;
  96270. oy->bodybytes=0;
  96271. return(0);
  96272. }
  96273. int ogg_stream_reset(ogg_stream_state *os){
  96274. os->body_fill=0;
  96275. os->body_returned=0;
  96276. os->lacing_fill=0;
  96277. os->lacing_packet=0;
  96278. os->lacing_returned=0;
  96279. os->header_fill=0;
  96280. os->e_o_s=0;
  96281. os->b_o_s=0;
  96282. os->pageno=-1;
  96283. os->packetno=0;
  96284. os->granulepos=0;
  96285. return(0);
  96286. }
  96287. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  96288. ogg_stream_reset(os);
  96289. os->serialno=serialno;
  96290. return(0);
  96291. }
  96292. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  96293. int ptr=os->lacing_returned;
  96294. if(os->lacing_packet<=ptr)return(0);
  96295. if(os->lacing_vals[ptr]&0x400){
  96296. os->lacing_returned++;
  96297. os->packetno++;
  96298. return(-1);
  96299. }
  96300. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  96301. to ask if there's a whole packet
  96302. waiting */
  96303. {
  96304. int size=os->lacing_vals[ptr]&0xff;
  96305. int bytes=size;
  96306. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96307. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96308. while(size==255){
  96309. int val=os->lacing_vals[++ptr];
  96310. size=val&0xff;
  96311. if(val&0x200)eos=0x200;
  96312. bytes+=size;
  96313. }
  96314. if(op){
  96315. op->e_o_s=eos;
  96316. op->b_o_s=bos;
  96317. op->packet=os->body_data+os->body_returned;
  96318. op->packetno=os->packetno;
  96319. op->granulepos=os->granule_vals[ptr];
  96320. op->bytes=bytes;
  96321. }
  96322. if(adv){
  96323. os->body_returned+=bytes;
  96324. os->lacing_returned=ptr+1;
  96325. os->packetno++;
  96326. }
  96327. }
  96328. return(1);
  96329. }
  96330. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96331. return _packetout(os,op,1);
  96332. }
  96333. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96334. return _packetout(os,op,0);
  96335. }
  96336. void ogg_packet_clear(ogg_packet *op) {
  96337. _ogg_free(op->packet);
  96338. memset(op, 0, sizeof(*op));
  96339. }
  96340. #ifdef _V_SELFTEST
  96341. #include <stdio.h>
  96342. ogg_stream_state os_en, os_de;
  96343. ogg_sync_state oy;
  96344. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96345. long j;
  96346. static int sequence=0;
  96347. static int lastno=0;
  96348. if(op->bytes!=len){
  96349. fprintf(stderr,"incorrect packet length!\n");
  96350. exit(1);
  96351. }
  96352. if(op->granulepos!=pos){
  96353. fprintf(stderr,"incorrect packet position!\n");
  96354. exit(1);
  96355. }
  96356. if(no==0){
  96357. sequence=0;
  96358. }else{
  96359. sequence++;
  96360. if(no>lastno+1)
  96361. sequence++;
  96362. }
  96363. lastno=no;
  96364. if(op->packetno!=sequence){
  96365. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96366. (long)(op->packetno),sequence);
  96367. exit(1);
  96368. }
  96369. for(j=0;j<op->bytes;j++)
  96370. if(op->packet[j]!=((j+no)&0xff)){
  96371. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96372. j,op->packet[j],(j+no)&0xff);
  96373. exit(1);
  96374. }
  96375. }
  96376. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96377. long j;
  96378. for(j=0;j<og->body_len;j++)
  96379. if(og->body[j]!=data[j]){
  96380. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96381. j,data[j],og->body[j]);
  96382. exit(1);
  96383. }
  96384. for(j=0;j<og->header_len;j++){
  96385. if(og->header[j]!=header[j]){
  96386. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96387. for(j=0;j<header[26]+27;j++)
  96388. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96389. fprintf(stderr,"\n");
  96390. exit(1);
  96391. }
  96392. }
  96393. if(og->header_len!=header[26]+27){
  96394. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96395. og->header_len,header[26]+27);
  96396. exit(1);
  96397. }
  96398. }
  96399. void print_header(ogg_page *og){
  96400. int j;
  96401. fprintf(stderr,"\nHEADER:\n");
  96402. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96403. og->header[0],og->header[1],og->header[2],og->header[3],
  96404. (int)og->header[4],(int)og->header[5]);
  96405. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96406. (og->header[9]<<24)|(og->header[8]<<16)|
  96407. (og->header[7]<<8)|og->header[6],
  96408. (og->header[17]<<24)|(og->header[16]<<16)|
  96409. (og->header[15]<<8)|og->header[14],
  96410. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96411. (og->header[19]<<8)|og->header[18]);
  96412. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96413. (int)og->header[22],(int)og->header[23],
  96414. (int)og->header[24],(int)og->header[25],
  96415. (int)og->header[26]);
  96416. for(j=27;j<og->header_len;j++)
  96417. fprintf(stderr,"%d ",(int)og->header[j]);
  96418. fprintf(stderr,")\n\n");
  96419. }
  96420. void copy_page(ogg_page *og){
  96421. unsigned char *temp=_ogg_malloc(og->header_len);
  96422. memcpy(temp,og->header,og->header_len);
  96423. og->header=temp;
  96424. temp=_ogg_malloc(og->body_len);
  96425. memcpy(temp,og->body,og->body_len);
  96426. og->body=temp;
  96427. }
  96428. void free_page(ogg_page *og){
  96429. _ogg_free (og->header);
  96430. _ogg_free (og->body);
  96431. }
  96432. void error(void){
  96433. fprintf(stderr,"error!\n");
  96434. exit(1);
  96435. }
  96436. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96437. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96438. 0x01,0x02,0x03,0x04,0,0,0,0,
  96439. 0x15,0xed,0xec,0x91,
  96440. 1,
  96441. 17};
  96442. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96443. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96444. 0x01,0x02,0x03,0x04,0,0,0,0,
  96445. 0x59,0x10,0x6c,0x2c,
  96446. 1,
  96447. 17};
  96448. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96449. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96450. 0x01,0x02,0x03,0x04,1,0,0,0,
  96451. 0x89,0x33,0x85,0xce,
  96452. 13,
  96453. 254,255,0,255,1,255,245,255,255,0,
  96454. 255,255,90};
  96455. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96456. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96457. 0x01,0x02,0x03,0x04,0,0,0,0,
  96458. 0xff,0x7b,0x23,0x17,
  96459. 1,
  96460. 0};
  96461. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96462. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96463. 0x01,0x02,0x03,0x04,1,0,0,0,
  96464. 0x5c,0x3f,0x66,0xcb,
  96465. 17,
  96466. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96467. 255,255,90,0};
  96468. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96469. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96470. 0x01,0x02,0x03,0x04,0,0,0,0,
  96471. 0x01,0x27,0x31,0xaa,
  96472. 18,
  96473. 255,255,255,255,255,255,255,255,
  96474. 255,255,255,255,255,255,255,255,255,10};
  96475. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96476. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96477. 0x01,0x02,0x03,0x04,1,0,0,0,
  96478. 0x7f,0x4e,0x8a,0xd2,
  96479. 4,
  96480. 255,4,255,0};
  96481. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96482. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96483. 0x01,0x02,0x03,0x04,0,0,0,0,
  96484. 0xff,0x7b,0x23,0x17,
  96485. 1,
  96486. 0};
  96487. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96488. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96489. 0x01,0x02,0x03,0x04,1,0,0,0,
  96490. 0x54,0x05,0x51,0xc8,
  96491. 17,
  96492. 255,255,255,255,255,255,255,255,
  96493. 255,255,255,255,255,255,255,255,255};
  96494. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96495. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96496. 0x01,0x02,0x03,0x04,2,0,0,0,
  96497. 0xc8,0xc3,0xcb,0xed,
  96498. 5,
  96499. 10,255,4,255,0};
  96500. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96501. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96502. 0x01,0x02,0x03,0x04,0,0,0,0,
  96503. 0xff,0x7b,0x23,0x17,
  96504. 1,
  96505. 0};
  96506. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96507. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96508. 0x01,0x02,0x03,0x04,1,0,0,0,
  96509. 0xed,0x2a,0x2e,0xa7,
  96510. 255,
  96511. 10,10,10,10,10,10,10,10,
  96512. 10,10,10,10,10,10,10,10,
  96513. 10,10,10,10,10,10,10,10,
  96514. 10,10,10,10,10,10,10,10,
  96515. 10,10,10,10,10,10,10,10,
  96516. 10,10,10,10,10,10,10,10,
  96517. 10,10,10,10,10,10,10,10,
  96518. 10,10,10,10,10,10,10,10,
  96519. 10,10,10,10,10,10,10,10,
  96520. 10,10,10,10,10,10,10,10,
  96521. 10,10,10,10,10,10,10,10,
  96522. 10,10,10,10,10,10,10,10,
  96523. 10,10,10,10,10,10,10,10,
  96524. 10,10,10,10,10,10,10,10,
  96525. 10,10,10,10,10,10,10,10,
  96526. 10,10,10,10,10,10,10,10,
  96527. 10,10,10,10,10,10,10,10,
  96528. 10,10,10,10,10,10,10,10,
  96529. 10,10,10,10,10,10,10,10,
  96530. 10,10,10,10,10,10,10,10,
  96531. 10,10,10,10,10,10,10,10,
  96532. 10,10,10,10,10,10,10,10,
  96533. 10,10,10,10,10,10,10,10,
  96534. 10,10,10,10,10,10,10,10,
  96535. 10,10,10,10,10,10,10,10,
  96536. 10,10,10,10,10,10,10,10,
  96537. 10,10,10,10,10,10,10,10,
  96538. 10,10,10,10,10,10,10,10,
  96539. 10,10,10,10,10,10,10,10,
  96540. 10,10,10,10,10,10,10,10,
  96541. 10,10,10,10,10,10,10,10,
  96542. 10,10,10,10,10,10,10};
  96543. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96544. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96545. 0x01,0x02,0x03,0x04,2,0,0,0,
  96546. 0x6c,0x3b,0x82,0x3d,
  96547. 1,
  96548. 50};
  96549. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96550. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96551. 0x01,0x02,0x03,0x04,0,0,0,0,
  96552. 0xff,0x7b,0x23,0x17,
  96553. 1,
  96554. 0};
  96555. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96556. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96557. 0x01,0x02,0x03,0x04,1,0,0,0,
  96558. 0x3c,0xd9,0x4d,0x3f,
  96559. 17,
  96560. 100,255,255,255,255,255,255,255,255,
  96561. 255,255,255,255,255,255,255,255};
  96562. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96563. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96564. 0x01,0x02,0x03,0x04,2,0,0,0,
  96565. 0x01,0xd2,0xe5,0xe5,
  96566. 17,
  96567. 255,255,255,255,255,255,255,255,
  96568. 255,255,255,255,255,255,255,255,255};
  96569. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96570. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96571. 0x01,0x02,0x03,0x04,3,0,0,0,
  96572. 0xef,0xdd,0x88,0xde,
  96573. 7,
  96574. 255,255,75,255,4,255,0};
  96575. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96576. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96577. 0x01,0x02,0x03,0x04,0,0,0,0,
  96578. 0xff,0x7b,0x23,0x17,
  96579. 1,
  96580. 0};
  96581. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96582. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96583. 0x01,0x02,0x03,0x04,1,0,0,0,
  96584. 0x3c,0xd9,0x4d,0x3f,
  96585. 17,
  96586. 100,255,255,255,255,255,255,255,255,
  96587. 255,255,255,255,255,255,255,255};
  96588. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96589. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96590. 0x01,0x02,0x03,0x04,2,0,0,0,
  96591. 0xd4,0xe0,0x60,0xe5,
  96592. 1,0};
  96593. void test_pack(const int *pl, const int **headers, int byteskip,
  96594. int pageskip, int packetskip){
  96595. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96596. long inptr=0;
  96597. long outptr=0;
  96598. long deptr=0;
  96599. long depacket=0;
  96600. long granule_pos=7,pageno=0;
  96601. int i,j,packets,pageout=pageskip;
  96602. int eosflag=0;
  96603. int bosflag=0;
  96604. int byteskipcount=0;
  96605. ogg_stream_reset(&os_en);
  96606. ogg_stream_reset(&os_de);
  96607. ogg_sync_reset(&oy);
  96608. for(packets=0;packets<packetskip;packets++)
  96609. depacket+=pl[packets];
  96610. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96611. for(i=0;i<packets;i++){
  96612. ogg_packet op;
  96613. int len=pl[i];
  96614. op.packet=data+inptr;
  96615. op.bytes=len;
  96616. op.e_o_s=(pl[i+1]<0?1:0);
  96617. op.granulepos=granule_pos;
  96618. granule_pos+=1024;
  96619. for(j=0;j<len;j++)data[inptr++]=i+j;
  96620. ogg_stream_packetin(&os_en,&op);
  96621. {
  96622. ogg_page og;
  96623. while(ogg_stream_pageout(&os_en,&og)){
  96624. fprintf(stderr,"%ld, ",pageno);
  96625. if(headers[pageno]==NULL){
  96626. fprintf(stderr,"coded too many pages!\n");
  96627. exit(1);
  96628. }
  96629. check_page(data+outptr,headers[pageno],&og);
  96630. outptr+=og.body_len;
  96631. pageno++;
  96632. if(pageskip){
  96633. bosflag=1;
  96634. pageskip--;
  96635. deptr+=og.body_len;
  96636. }
  96637. {
  96638. ogg_page og_de;
  96639. ogg_packet op_de,op_de2;
  96640. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96641. char *next=buf;
  96642. byteskipcount+=og.header_len;
  96643. if(byteskipcount>byteskip){
  96644. memcpy(next,og.header,byteskipcount-byteskip);
  96645. next+=byteskipcount-byteskip;
  96646. byteskipcount=byteskip;
  96647. }
  96648. byteskipcount+=og.body_len;
  96649. if(byteskipcount>byteskip){
  96650. memcpy(next,og.body,byteskipcount-byteskip);
  96651. next+=byteskipcount-byteskip;
  96652. byteskipcount=byteskip;
  96653. }
  96654. ogg_sync_wrote(&oy,next-buf);
  96655. while(1){
  96656. int ret=ogg_sync_pageout(&oy,&og_de);
  96657. if(ret==0)break;
  96658. if(ret<0)continue;
  96659. fprintf(stderr,"(%ld), ",pageout);
  96660. check_page(data+deptr,headers[pageout],&og_de);
  96661. deptr+=og_de.body_len;
  96662. pageout++;
  96663. ogg_stream_pagein(&os_de,&og_de);
  96664. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96665. ogg_stream_packetpeek(&os_de,NULL);
  96666. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96667. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96668. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96669. depacket);
  96670. exit(1);
  96671. }
  96672. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96673. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96674. depacket);
  96675. exit(1);
  96676. }
  96677. if(bosflag==0 && op_de.b_o_s==0){
  96678. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96679. exit(1);
  96680. }
  96681. if(bosflag && op_de.b_o_s){
  96682. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96683. exit(1);
  96684. }
  96685. bosflag=1;
  96686. depacket+=op_de.bytes;
  96687. if(eosflag){
  96688. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96689. exit(1);
  96690. }
  96691. if(op_de.e_o_s)eosflag=1;
  96692. if(op_de.granulepos!=-1){
  96693. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96694. }
  96695. }
  96696. }
  96697. }
  96698. }
  96699. }
  96700. }
  96701. _ogg_free(data);
  96702. if(headers[pageno]!=NULL){
  96703. fprintf(stderr,"did not write last page!\n");
  96704. exit(1);
  96705. }
  96706. if(headers[pageout]!=NULL){
  96707. fprintf(stderr,"did not decode last page!\n");
  96708. exit(1);
  96709. }
  96710. if(inptr!=outptr){
  96711. fprintf(stderr,"encoded page data incomplete!\n");
  96712. exit(1);
  96713. }
  96714. if(inptr!=deptr){
  96715. fprintf(stderr,"decoded page data incomplete!\n");
  96716. exit(1);
  96717. }
  96718. if(inptr!=depacket){
  96719. fprintf(stderr,"decoded packet data incomplete!\n");
  96720. exit(1);
  96721. }
  96722. if(!eosflag){
  96723. fprintf(stderr,"Never got a packet with EOS set!\n");
  96724. exit(1);
  96725. }
  96726. fprintf(stderr,"ok.\n");
  96727. }
  96728. int main(void){
  96729. ogg_stream_init(&os_en,0x04030201);
  96730. ogg_stream_init(&os_de,0x04030201);
  96731. ogg_sync_init(&oy);
  96732. {
  96733. const int packets[]={17, -1};
  96734. const int *headret[]={head1_0,NULL};
  96735. fprintf(stderr,"testing single page encoding... ");
  96736. test_pack(packets,headret,0,0,0);
  96737. }
  96738. {
  96739. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96740. const int *headret[]={head1_1,head2_1,NULL};
  96741. fprintf(stderr,"testing basic page encoding... ");
  96742. test_pack(packets,headret,0,0,0);
  96743. }
  96744. {
  96745. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96746. const int *headret[]={head1_2,head2_2,NULL};
  96747. fprintf(stderr,"testing basic nil packets... ");
  96748. test_pack(packets,headret,0,0,0);
  96749. }
  96750. {
  96751. const int packets[]={4345,259,255,-1};
  96752. const int *headret[]={head1_3,head2_3,NULL};
  96753. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96754. test_pack(packets,headret,0,0,0);
  96755. }
  96756. {
  96757. const int packets[]={0,4345,259,255,-1};
  96758. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96759. fprintf(stderr,"testing single packet page span... ");
  96760. test_pack(packets,headret,0,0,0);
  96761. }
  96762. {
  96763. const int packets[]={0,10,10,10,10,10,10,10,10,
  96764. 10,10,10,10,10,10,10,10,
  96765. 10,10,10,10,10,10,10,10,
  96766. 10,10,10,10,10,10,10,10,
  96767. 10,10,10,10,10,10,10,10,
  96768. 10,10,10,10,10,10,10,10,
  96769. 10,10,10,10,10,10,10,10,
  96770. 10,10,10,10,10,10,10,10,
  96771. 10,10,10,10,10,10,10,10,
  96772. 10,10,10,10,10,10,10,10,
  96773. 10,10,10,10,10,10,10,10,
  96774. 10,10,10,10,10,10,10,10,
  96775. 10,10,10,10,10,10,10,10,
  96776. 10,10,10,10,10,10,10,10,
  96777. 10,10,10,10,10,10,10,10,
  96778. 10,10,10,10,10,10,10,10,
  96779. 10,10,10,10,10,10,10,10,
  96780. 10,10,10,10,10,10,10,10,
  96781. 10,10,10,10,10,10,10,10,
  96782. 10,10,10,10,10,10,10,10,
  96783. 10,10,10,10,10,10,10,10,
  96784. 10,10,10,10,10,10,10,10,
  96785. 10,10,10,10,10,10,10,10,
  96786. 10,10,10,10,10,10,10,10,
  96787. 10,10,10,10,10,10,10,10,
  96788. 10,10,10,10,10,10,10,10,
  96789. 10,10,10,10,10,10,10,10,
  96790. 10,10,10,10,10,10,10,10,
  96791. 10,10,10,10,10,10,10,10,
  96792. 10,10,10,10,10,10,10,10,
  96793. 10,10,10,10,10,10,10,10,
  96794. 10,10,10,10,10,10,10,50,-1};
  96795. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96796. fprintf(stderr,"testing max packet segments... ");
  96797. test_pack(packets,headret,0,0,0);
  96798. }
  96799. {
  96800. const int packets[]={0,100,9000,259,255,-1};
  96801. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96802. fprintf(stderr,"testing very large packets... ");
  96803. test_pack(packets,headret,0,0,0);
  96804. }
  96805. {
  96806. const int packets[]={0,100,9000,259,255,-1};
  96807. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96808. fprintf(stderr,"testing continuation resync in very large packets... ");
  96809. test_pack(packets,headret,100,2,3);
  96810. }
  96811. {
  96812. const int packets[]={0,100,4080,-1};
  96813. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96814. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96815. test_pack(packets,headret,0,0,0);
  96816. }
  96817. {
  96818. unsigned char *data=_ogg_malloc(1024*1024);
  96819. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96820. int inptr=0,i,j;
  96821. ogg_page og[5];
  96822. ogg_stream_reset(&os_en);
  96823. for(i=0;pl[i]!=-1;i++){
  96824. ogg_packet op;
  96825. int len=pl[i];
  96826. op.packet=data+inptr;
  96827. op.bytes=len;
  96828. op.e_o_s=(pl[i+1]<0?1:0);
  96829. op.granulepos=(i+1)*1000;
  96830. for(j=0;j<len;j++)data[inptr++]=i+j;
  96831. ogg_stream_packetin(&os_en,&op);
  96832. }
  96833. _ogg_free(data);
  96834. for(i=0;i<5;i++){
  96835. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96836. fprintf(stderr,"Too few pages output building sync tests!\n");
  96837. exit(1);
  96838. }
  96839. copy_page(&og[i]);
  96840. }
  96841. {
  96842. ogg_page temp;
  96843. ogg_packet test;
  96844. fprintf(stderr,"Testing loss of pages... ");
  96845. ogg_sync_reset(&oy);
  96846. ogg_stream_reset(&os_de);
  96847. for(i=0;i<5;i++){
  96848. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96849. og[i].header_len);
  96850. ogg_sync_wrote(&oy,og[i].header_len);
  96851. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96852. ogg_sync_wrote(&oy,og[i].body_len);
  96853. }
  96854. ogg_sync_pageout(&oy,&temp);
  96855. ogg_stream_pagein(&os_de,&temp);
  96856. ogg_sync_pageout(&oy,&temp);
  96857. ogg_stream_pagein(&os_de,&temp);
  96858. ogg_sync_pageout(&oy,&temp);
  96859. ogg_sync_pageout(&oy,&temp);
  96860. ogg_stream_pagein(&os_de,&temp);
  96861. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96862. checkpacket(&test,0,0,0);
  96863. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96864. checkpacket(&test,100,1,-1);
  96865. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96866. checkpacket(&test,4079,2,3000);
  96867. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96868. fprintf(stderr,"Error: loss of page did not return error\n");
  96869. exit(1);
  96870. }
  96871. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96872. checkpacket(&test,76,5,-1);
  96873. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96874. checkpacket(&test,34,6,-1);
  96875. fprintf(stderr,"ok.\n");
  96876. }
  96877. {
  96878. ogg_page temp;
  96879. ogg_packet test;
  96880. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96881. ogg_sync_reset(&oy);
  96882. ogg_stream_reset(&os_de);
  96883. for(i=0;i<5;i++){
  96884. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96885. og[i].header_len);
  96886. ogg_sync_wrote(&oy,og[i].header_len);
  96887. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96888. ogg_sync_wrote(&oy,og[i].body_len);
  96889. }
  96890. ogg_sync_pageout(&oy,&temp);
  96891. ogg_stream_pagein(&os_de,&temp);
  96892. ogg_sync_pageout(&oy,&temp);
  96893. ogg_stream_pagein(&os_de,&temp);
  96894. ogg_sync_pageout(&oy,&temp);
  96895. ogg_stream_pagein(&os_de,&temp);
  96896. ogg_sync_pageout(&oy,&temp);
  96897. ogg_sync_pageout(&oy,&temp);
  96898. ogg_stream_pagein(&os_de,&temp);
  96899. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96900. checkpacket(&test,0,0,0);
  96901. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96902. checkpacket(&test,100,1,-1);
  96903. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96904. checkpacket(&test,4079,2,3000);
  96905. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96906. checkpacket(&test,2956,3,4000);
  96907. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96908. fprintf(stderr,"Error: loss of page did not return error\n");
  96909. exit(1);
  96910. }
  96911. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96912. checkpacket(&test,300,13,14000);
  96913. fprintf(stderr,"ok.\n");
  96914. }
  96915. {
  96916. ogg_page og_de;
  96917. fprintf(stderr,"Testing sync on partial inputs... ");
  96918. ogg_sync_reset(&oy);
  96919. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96920. 3);
  96921. ogg_sync_wrote(&oy,3);
  96922. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96923. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96924. 20);
  96925. ogg_sync_wrote(&oy,20);
  96926. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96927. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96928. 5);
  96929. ogg_sync_wrote(&oy,5);
  96930. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96931. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96932. og[1].header_len-28);
  96933. ogg_sync_wrote(&oy,og[1].header_len-28);
  96934. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96935. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96936. ogg_sync_wrote(&oy,1000);
  96937. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96938. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96939. og[1].body_len-1000);
  96940. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96941. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96942. fprintf(stderr,"ok.\n");
  96943. }
  96944. {
  96945. ogg_page og_de;
  96946. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96947. ogg_sync_reset(&oy);
  96948. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96949. og[1].header_len);
  96950. ogg_sync_wrote(&oy,og[1].header_len);
  96951. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96952. og[1].body_len);
  96953. ogg_sync_wrote(&oy,og[1].body_len);
  96954. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96955. 20);
  96956. ogg_sync_wrote(&oy,20);
  96957. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96958. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96959. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96960. og[1].header_len-20);
  96961. ogg_sync_wrote(&oy,og[1].header_len-20);
  96962. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96963. og[1].body_len);
  96964. ogg_sync_wrote(&oy,og[1].body_len);
  96965. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96966. fprintf(stderr,"ok.\n");
  96967. }
  96968. {
  96969. ogg_page og_de;
  96970. fprintf(stderr,"Testing search for capture... ");
  96971. ogg_sync_reset(&oy);
  96972. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96973. og[1].body_len);
  96974. ogg_sync_wrote(&oy,og[1].body_len);
  96975. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96976. og[1].header_len);
  96977. ogg_sync_wrote(&oy,og[1].header_len);
  96978. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96979. og[1].body_len);
  96980. ogg_sync_wrote(&oy,og[1].body_len);
  96981. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96982. 20);
  96983. ogg_sync_wrote(&oy,20);
  96984. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96985. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96986. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96987. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96988. og[2].header_len-20);
  96989. ogg_sync_wrote(&oy,og[2].header_len-20);
  96990. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96991. og[2].body_len);
  96992. ogg_sync_wrote(&oy,og[2].body_len);
  96993. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96994. fprintf(stderr,"ok.\n");
  96995. }
  96996. {
  96997. ogg_page og_de;
  96998. fprintf(stderr,"Testing recapture... ");
  96999. ogg_sync_reset(&oy);
  97000. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97001. og[1].header_len);
  97002. ogg_sync_wrote(&oy,og[1].header_len);
  97003. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97004. og[1].body_len);
  97005. ogg_sync_wrote(&oy,og[1].body_len);
  97006. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97007. og[2].header_len);
  97008. ogg_sync_wrote(&oy,og[2].header_len);
  97009. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97010. og[2].header_len);
  97011. ogg_sync_wrote(&oy,og[2].header_len);
  97012. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97013. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97014. og[2].body_len-5);
  97015. ogg_sync_wrote(&oy,og[2].body_len-5);
  97016. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  97017. og[3].header_len);
  97018. ogg_sync_wrote(&oy,og[3].header_len);
  97019. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  97020. og[3].body_len);
  97021. ogg_sync_wrote(&oy,og[3].body_len);
  97022. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97023. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97024. fprintf(stderr,"ok.\n");
  97025. }
  97026. {
  97027. for(i=0;i<5;i++){
  97028. free_page(&og[i]);
  97029. }
  97030. }
  97031. }
  97032. return(0);
  97033. }
  97034. #endif
  97035. #endif
  97036. /*** End of inlined file: framing.c ***/
  97037. /*** Start of inlined file: analysis.c ***/
  97038. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97039. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97040. // tasks..
  97041. #if JUCE_MSVC
  97042. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97043. #endif
  97044. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97045. #if JUCE_USE_OGGVORBIS
  97046. #include <stdio.h>
  97047. #include <string.h>
  97048. #include <math.h>
  97049. /*** Start of inlined file: codec_internal.h ***/
  97050. #ifndef _V_CODECI_H_
  97051. #define _V_CODECI_H_
  97052. /*** Start of inlined file: envelope.h ***/
  97053. #ifndef _V_ENVELOPE_
  97054. #define _V_ENVELOPE_
  97055. /*** Start of inlined file: mdct.h ***/
  97056. #ifndef _OGG_mdct_H_
  97057. #define _OGG_mdct_H_
  97058. #ifdef MDCT_INTEGERIZED
  97059. #define DATA_TYPE int
  97060. #define REG_TYPE register int
  97061. #define TRIGBITS 14
  97062. #define cPI3_8 6270
  97063. #define cPI2_8 11585
  97064. #define cPI1_8 15137
  97065. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  97066. #define MULT_NORM(x) ((x)>>TRIGBITS)
  97067. #define HALVE(x) ((x)>>1)
  97068. #else
  97069. #define DATA_TYPE float
  97070. #define REG_TYPE float
  97071. #define cPI3_8 .38268343236508977175F
  97072. #define cPI2_8 .70710678118654752441F
  97073. #define cPI1_8 .92387953251128675613F
  97074. #define FLOAT_CONV(x) (x)
  97075. #define MULT_NORM(x) (x)
  97076. #define HALVE(x) ((x)*.5f)
  97077. #endif
  97078. typedef struct {
  97079. int n;
  97080. int log2n;
  97081. DATA_TYPE *trig;
  97082. int *bitrev;
  97083. DATA_TYPE scale;
  97084. } mdct_lookup;
  97085. extern void mdct_init(mdct_lookup *lookup,int n);
  97086. extern void mdct_clear(mdct_lookup *l);
  97087. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97088. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97089. #endif
  97090. /*** End of inlined file: mdct.h ***/
  97091. #define VE_PRE 16
  97092. #define VE_WIN 4
  97093. #define VE_POST 2
  97094. #define VE_AMP (VE_PRE+VE_POST-1)
  97095. #define VE_BANDS 7
  97096. #define VE_NEARDC 15
  97097. #define VE_MINSTRETCH 2 /* a bit less than short block */
  97098. #define VE_MAXSTRETCH 12 /* one-third full block */
  97099. typedef struct {
  97100. float ampbuf[VE_AMP];
  97101. int ampptr;
  97102. float nearDC[VE_NEARDC];
  97103. float nearDC_acc;
  97104. float nearDC_partialacc;
  97105. int nearptr;
  97106. } envelope_filter_state;
  97107. typedef struct {
  97108. int begin;
  97109. int end;
  97110. float *window;
  97111. float total;
  97112. } envelope_band;
  97113. typedef struct {
  97114. int ch;
  97115. int winlength;
  97116. int searchstep;
  97117. float minenergy;
  97118. mdct_lookup mdct;
  97119. float *mdct_win;
  97120. envelope_band band[VE_BANDS];
  97121. envelope_filter_state *filter;
  97122. int stretch;
  97123. int *mark;
  97124. long storage;
  97125. long current;
  97126. long curmark;
  97127. long cursor;
  97128. } envelope_lookup;
  97129. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  97130. extern void _ve_envelope_clear(envelope_lookup *e);
  97131. extern long _ve_envelope_search(vorbis_dsp_state *v);
  97132. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  97133. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  97134. #endif
  97135. /*** End of inlined file: envelope.h ***/
  97136. /*** Start of inlined file: codebook.h ***/
  97137. #ifndef _V_CODEBOOK_H_
  97138. #define _V_CODEBOOK_H_
  97139. typedef struct static_codebook{
  97140. long dim; /* codebook dimensions (elements per vector) */
  97141. long entries; /* codebook entries */
  97142. long *lengthlist; /* codeword lengths in bits */
  97143. int maptype; /* 0=none
  97144. 1=implicitly populated values from map column
  97145. 2=listed arbitrary values */
  97146. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  97147. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  97148. int q_quant; /* bits: 0 < quant <= 16 */
  97149. int q_sequencep; /* bitflag */
  97150. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  97151. map == 2: list of dim*entries quantized entry vals
  97152. */
  97153. struct encode_aux_nearestmatch *nearest_tree;
  97154. struct encode_aux_threshmatch *thresh_tree;
  97155. struct encode_aux_pigeonhole *pigeon_tree;
  97156. int allocedp;
  97157. } static_codebook;
  97158. typedef struct encode_aux_nearestmatch{
  97159. long *ptr0;
  97160. long *ptr1;
  97161. long *p; /* decision points (each is an entry) */
  97162. long *q; /* decision points (each is an entry) */
  97163. long aux; /* number of tree entries */
  97164. long alloc;
  97165. } encode_aux_nearestmatch;
  97166. typedef struct encode_aux_threshmatch{
  97167. float *quantthresh;
  97168. long *quantmap;
  97169. int quantvals;
  97170. int threshvals;
  97171. } encode_aux_threshmatch;
  97172. typedef struct encode_aux_pigeonhole{
  97173. float min;
  97174. float del;
  97175. int mapentries;
  97176. int quantvals;
  97177. long *pigeonmap;
  97178. long fittotal;
  97179. long *fitlist;
  97180. long *fitmap;
  97181. long *fitlength;
  97182. } encode_aux_pigeonhole;
  97183. typedef struct codebook{
  97184. long dim; /* codebook dimensions (elements per vector) */
  97185. long entries; /* codebook entries */
  97186. long used_entries; /* populated codebook entries */
  97187. const static_codebook *c;
  97188. float *valuelist; /* list of dim*entries actual entry values */
  97189. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  97190. int *dec_index; /* only used if sparseness collapsed */
  97191. char *dec_codelengths;
  97192. ogg_uint32_t *dec_firsttable;
  97193. int dec_firsttablen;
  97194. int dec_maxlength;
  97195. } codebook;
  97196. extern void vorbis_staticbook_clear(static_codebook *b);
  97197. extern void vorbis_staticbook_destroy(static_codebook *b);
  97198. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  97199. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  97200. extern void vorbis_book_clear(codebook *b);
  97201. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  97202. extern float *_book_logdist(const static_codebook *b,float *vals);
  97203. extern float _float32_unpack(long val);
  97204. extern long _float32_pack(float val);
  97205. extern int _best(codebook *book, float *a, int step);
  97206. extern int _ilog(unsigned int v);
  97207. extern long _book_maptype1_quantvals(const static_codebook *b);
  97208. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  97209. extern long vorbis_book_codeword(codebook *book,int entry);
  97210. extern long vorbis_book_codelen(codebook *book,int entry);
  97211. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  97212. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  97213. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  97214. extern int vorbis_book_errorv(codebook *book, float *a);
  97215. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  97216. oggpack_buffer *b);
  97217. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  97218. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  97219. oggpack_buffer *b,int n);
  97220. extern long vorbis_book_decodev_set(codebook *book, float *a,
  97221. oggpack_buffer *b,int n);
  97222. extern long vorbis_book_decodev_add(codebook *book, float *a,
  97223. oggpack_buffer *b,int n);
  97224. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  97225. long off,int ch,
  97226. oggpack_buffer *b,int n);
  97227. #endif
  97228. /*** End of inlined file: codebook.h ***/
  97229. #define BLOCKTYPE_IMPULSE 0
  97230. #define BLOCKTYPE_PADDING 1
  97231. #define BLOCKTYPE_TRANSITION 0
  97232. #define BLOCKTYPE_LONG 1
  97233. #define PACKETBLOBS 15
  97234. typedef struct vorbis_block_internal{
  97235. float **pcmdelay; /* this is a pointer into local storage */
  97236. float ampmax;
  97237. int blocktype;
  97238. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  97239. blob [PACKETBLOBS/2] points to
  97240. the oggpack_buffer in the
  97241. main vorbis_block */
  97242. } vorbis_block_internal;
  97243. typedef void vorbis_look_floor;
  97244. typedef void vorbis_look_residue;
  97245. typedef void vorbis_look_transform;
  97246. typedef struct {
  97247. int blockflag;
  97248. int windowtype;
  97249. int transformtype;
  97250. int mapping;
  97251. } vorbis_info_mode;
  97252. typedef void vorbis_info_floor;
  97253. typedef void vorbis_info_residue;
  97254. typedef void vorbis_info_mapping;
  97255. /*** Start of inlined file: psy.h ***/
  97256. #ifndef _V_PSY_H_
  97257. #define _V_PSY_H_
  97258. /*** Start of inlined file: smallft.h ***/
  97259. #ifndef _V_SMFT_H_
  97260. #define _V_SMFT_H_
  97261. typedef struct {
  97262. int n;
  97263. float *trigcache;
  97264. int *splitcache;
  97265. } drft_lookup;
  97266. extern void drft_forward(drft_lookup *l,float *data);
  97267. extern void drft_backward(drft_lookup *l,float *data);
  97268. extern void drft_init(drft_lookup *l,int n);
  97269. extern void drft_clear(drft_lookup *l);
  97270. #endif
  97271. /*** End of inlined file: smallft.h ***/
  97272. /*** Start of inlined file: backends.h ***/
  97273. #ifndef _vorbis_backend_h_
  97274. #define _vorbis_backend_h_
  97275. typedef struct{
  97276. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  97277. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  97278. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  97279. void (*free_info) (vorbis_info_floor *);
  97280. void (*free_look) (vorbis_look_floor *);
  97281. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  97282. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  97283. void *buffer,float *);
  97284. } vorbis_func_floor;
  97285. typedef struct{
  97286. int order;
  97287. long rate;
  97288. long barkmap;
  97289. int ampbits;
  97290. int ampdB;
  97291. int numbooks; /* <= 16 */
  97292. int books[16];
  97293. float lessthan; /* encode-only config setting hacks for libvorbis */
  97294. float greaterthan; /* encode-only config setting hacks for libvorbis */
  97295. } vorbis_info_floor0;
  97296. #define VIF_POSIT 63
  97297. #define VIF_CLASS 16
  97298. #define VIF_PARTS 31
  97299. typedef struct{
  97300. int partitions; /* 0 to 31 */
  97301. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  97302. int class_dim[VIF_CLASS]; /* 1 to 8 */
  97303. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  97304. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  97305. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97306. int mult; /* 1 2 3 or 4 */
  97307. int postlist[VIF_POSIT+2]; /* first two implicit */
  97308. float maxover;
  97309. float maxunder;
  97310. float maxerr;
  97311. float twofitweight;
  97312. float twofitatten;
  97313. int n;
  97314. } vorbis_info_floor1;
  97315. typedef struct{
  97316. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97317. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97318. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97319. vorbis_info_residue *);
  97320. void (*free_info) (vorbis_info_residue *);
  97321. void (*free_look) (vorbis_look_residue *);
  97322. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97323. float **,int *,int);
  97324. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97325. vorbis_look_residue *,
  97326. float **,float **,int *,int,long **);
  97327. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97328. float **,int *,int);
  97329. } vorbis_func_residue;
  97330. typedef struct vorbis_info_residue0{
  97331. long begin;
  97332. long end;
  97333. int grouping; /* group n vectors per partition */
  97334. int partitions; /* possible codebooks for a partition */
  97335. int groupbook; /* huffbook for partitioning */
  97336. int secondstages[64]; /* expanded out to pointers in lookup */
  97337. int booklist[256]; /* list of second stage books */
  97338. float classmetric1[64];
  97339. float classmetric2[64];
  97340. } vorbis_info_residue0;
  97341. typedef struct{
  97342. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97343. oggpack_buffer *);
  97344. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97345. void (*free_info) (vorbis_info_mapping *);
  97346. int (*forward) (struct vorbis_block *vb);
  97347. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97348. } vorbis_func_mapping;
  97349. typedef struct vorbis_info_mapping0{
  97350. int submaps; /* <= 16 */
  97351. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97352. int floorsubmap[16]; /* [mux] submap to floors */
  97353. int residuesubmap[16]; /* [mux] submap to residue */
  97354. int coupling_steps;
  97355. int coupling_mag[256];
  97356. int coupling_ang[256];
  97357. } vorbis_info_mapping0;
  97358. #endif
  97359. /*** End of inlined file: backends.h ***/
  97360. #ifndef EHMER_MAX
  97361. #define EHMER_MAX 56
  97362. #endif
  97363. #define P_BANDS 17 /* 62Hz to 16kHz */
  97364. #define P_LEVELS 8 /* 30dB to 100dB */
  97365. #define P_LEVEL_0 30. /* 30 dB */
  97366. #define P_NOISECURVES 3
  97367. #define NOISE_COMPAND_LEVELS 40
  97368. typedef struct vorbis_info_psy{
  97369. int blockflag;
  97370. float ath_adjatt;
  97371. float ath_maxatt;
  97372. float tone_masteratt[P_NOISECURVES];
  97373. float tone_centerboost;
  97374. float tone_decay;
  97375. float tone_abs_limit;
  97376. float toneatt[P_BANDS];
  97377. int noisemaskp;
  97378. float noisemaxsupp;
  97379. float noisewindowlo;
  97380. float noisewindowhi;
  97381. int noisewindowlomin;
  97382. int noisewindowhimin;
  97383. int noisewindowfixed;
  97384. float noiseoff[P_NOISECURVES][P_BANDS];
  97385. float noisecompand[NOISE_COMPAND_LEVELS];
  97386. float max_curve_dB;
  97387. int normal_channel_p;
  97388. int normal_point_p;
  97389. int normal_start;
  97390. int normal_partition;
  97391. double normal_thresh;
  97392. } vorbis_info_psy;
  97393. typedef struct{
  97394. int eighth_octave_lines;
  97395. float preecho_thresh[VE_BANDS];
  97396. float postecho_thresh[VE_BANDS];
  97397. float stretch_penalty;
  97398. float preecho_minenergy;
  97399. float ampmax_att_per_sec;
  97400. int coupling_pkHz[PACKETBLOBS];
  97401. int coupling_pointlimit[2][PACKETBLOBS];
  97402. int coupling_prepointamp[PACKETBLOBS];
  97403. int coupling_postpointamp[PACKETBLOBS];
  97404. int sliding_lowpass[2][PACKETBLOBS];
  97405. } vorbis_info_psy_global;
  97406. typedef struct {
  97407. float ampmax;
  97408. int channels;
  97409. vorbis_info_psy_global *gi;
  97410. int coupling_pointlimit[2][P_NOISECURVES];
  97411. } vorbis_look_psy_global;
  97412. typedef struct {
  97413. int n;
  97414. struct vorbis_info_psy *vi;
  97415. float ***tonecurves;
  97416. float **noiseoffset;
  97417. float *ath;
  97418. long *octave; /* in n.ocshift format */
  97419. long *bark;
  97420. long firstoc;
  97421. long shiftoc;
  97422. int eighth_octave_lines; /* power of two, please */
  97423. int total_octave_lines;
  97424. long rate; /* cache it */
  97425. float m_val; /* Masking compensation value */
  97426. } vorbis_look_psy;
  97427. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97428. vorbis_info_psy_global *gi,int n,long rate);
  97429. extern void _vp_psy_clear(vorbis_look_psy *p);
  97430. extern void *_vi_psy_dup(void *source);
  97431. extern void _vi_psy_free(vorbis_info_psy *i);
  97432. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97433. extern void _vp_remove_floor(vorbis_look_psy *p,
  97434. float *mdct,
  97435. int *icodedflr,
  97436. float *residue,
  97437. int sliding_lowpass);
  97438. extern void _vp_noisemask(vorbis_look_psy *p,
  97439. float *logmdct,
  97440. float *logmask);
  97441. extern void _vp_tonemask(vorbis_look_psy *p,
  97442. float *logfft,
  97443. float *logmask,
  97444. float global_specmax,
  97445. float local_specmax);
  97446. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97447. float *noise,
  97448. float *tone,
  97449. int offset_select,
  97450. float *logmask,
  97451. float *mdct,
  97452. float *logmdct);
  97453. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97454. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97455. vorbis_info_psy_global *g,
  97456. vorbis_look_psy *p,
  97457. vorbis_info_mapping0 *vi,
  97458. float **mdct);
  97459. extern void _vp_couple(int blobno,
  97460. vorbis_info_psy_global *g,
  97461. vorbis_look_psy *p,
  97462. vorbis_info_mapping0 *vi,
  97463. float **res,
  97464. float **mag_memo,
  97465. int **mag_sort,
  97466. int **ifloor,
  97467. int *nonzero,
  97468. int sliding_lowpass);
  97469. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97470. float *in,float *out,int *sortedindex);
  97471. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97472. float *magnitudes,int *sortedindex);
  97473. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97474. vorbis_look_psy *p,
  97475. vorbis_info_mapping0 *vi,
  97476. float **mags);
  97477. extern void hf_reduction(vorbis_info_psy_global *g,
  97478. vorbis_look_psy *p,
  97479. vorbis_info_mapping0 *vi,
  97480. float **mdct);
  97481. #endif
  97482. /*** End of inlined file: psy.h ***/
  97483. /*** Start of inlined file: bitrate.h ***/
  97484. #ifndef _V_BITRATE_H_
  97485. #define _V_BITRATE_H_
  97486. /*** Start of inlined file: os.h ***/
  97487. #ifndef _OS_H
  97488. #define _OS_H
  97489. #ifdef HAVE_CONFIG_H
  97490. #include "config.h"
  97491. #endif
  97492. #include <math.h>
  97493. /*** Start of inlined file: misc.h ***/
  97494. #ifndef _V_RANDOM_H_
  97495. #define _V_RANDOM_H_
  97496. extern int analysis_noisy;
  97497. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97498. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97499. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97500. ogg_int64_t off);
  97501. #ifdef DEBUG_MALLOC
  97502. #define _VDBG_GRAPHFILE "malloc.m"
  97503. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97504. extern void _VDBG_free(void *ptr,char *file,long line);
  97505. #ifndef MISC_C
  97506. #undef _ogg_malloc
  97507. #undef _ogg_calloc
  97508. #undef _ogg_realloc
  97509. #undef _ogg_free
  97510. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97511. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97512. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97513. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97514. #endif
  97515. #endif
  97516. #endif
  97517. /*** End of inlined file: misc.h ***/
  97518. #ifndef _V_IFDEFJAIL_H_
  97519. # define _V_IFDEFJAIL_H_
  97520. # ifdef __GNUC__
  97521. # define STIN static __inline__
  97522. # elif _WIN32
  97523. # define STIN static __inline
  97524. # else
  97525. # define STIN static
  97526. # endif
  97527. #ifdef DJGPP
  97528. # define rint(x) (floor((x)+0.5f))
  97529. #endif
  97530. #ifndef M_PI
  97531. # define M_PI (3.1415926536f)
  97532. #endif
  97533. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97534. # include <malloc.h>
  97535. # define rint(x) (floor((x)+0.5f))
  97536. # define NO_FLOAT_MATH_LIB
  97537. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97538. #endif
  97539. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97540. void *_alloca(size_t size);
  97541. # define alloca _alloca
  97542. #endif
  97543. #ifndef FAST_HYPOT
  97544. # define FAST_HYPOT hypot
  97545. #endif
  97546. #endif
  97547. #ifdef HAVE_ALLOCA_H
  97548. # include <alloca.h>
  97549. #endif
  97550. #ifdef USE_MEMORY_H
  97551. # include <memory.h>
  97552. #endif
  97553. #ifndef min
  97554. # define min(x,y) ((x)>(y)?(y):(x))
  97555. #endif
  97556. #ifndef max
  97557. # define max(x,y) ((x)<(y)?(y):(x))
  97558. #endif
  97559. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97560. # define VORBIS_FPU_CONTROL
  97561. typedef ogg_int16_t vorbis_fpu_control;
  97562. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97563. ogg_int16_t ret;
  97564. ogg_int16_t temp;
  97565. __asm__ __volatile__("fnstcw %0\n\t"
  97566. "movw %0,%%dx\n\t"
  97567. "orw $62463,%%dx\n\t"
  97568. "movw %%dx,%1\n\t"
  97569. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97570. *fpu=ret;
  97571. }
  97572. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97573. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97574. }
  97575. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97576. we get extra fst/fld to
  97577. truncate precision */
  97578. int i;
  97579. __asm__("fistl %0": "=m"(i) : "t"(f));
  97580. return(i);
  97581. }
  97582. #endif
  97583. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97584. # define VORBIS_FPU_CONTROL
  97585. typedef ogg_int16_t vorbis_fpu_control;
  97586. static __inline int vorbis_ftoi(double f){
  97587. int i;
  97588. __asm{
  97589. fld f
  97590. fistp i
  97591. }
  97592. return i;
  97593. }
  97594. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97595. }
  97596. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97597. }
  97598. #endif
  97599. #ifndef VORBIS_FPU_CONTROL
  97600. typedef int vorbis_fpu_control;
  97601. static int vorbis_ftoi(double f){
  97602. return (int)(f+.5);
  97603. }
  97604. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97605. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97606. #endif
  97607. #endif /* _OS_H */
  97608. /*** End of inlined file: os.h ***/
  97609. typedef struct bitrate_manager_state {
  97610. int managed;
  97611. long avg_reservoir;
  97612. long minmax_reservoir;
  97613. long avg_bitsper;
  97614. long min_bitsper;
  97615. long max_bitsper;
  97616. long short_per_long;
  97617. double avgfloat;
  97618. vorbis_block *vb;
  97619. int choice;
  97620. } bitrate_manager_state;
  97621. typedef struct bitrate_manager_info{
  97622. long avg_rate;
  97623. long min_rate;
  97624. long max_rate;
  97625. long reservoir_bits;
  97626. double reservoir_bias;
  97627. double slew_damp;
  97628. } bitrate_manager_info;
  97629. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97630. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97631. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97632. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97633. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97634. #endif
  97635. /*** End of inlined file: bitrate.h ***/
  97636. static int ilog(unsigned int v){
  97637. int ret=0;
  97638. while(v){
  97639. ret++;
  97640. v>>=1;
  97641. }
  97642. return(ret);
  97643. }
  97644. static int ilog2(unsigned int v){
  97645. int ret=0;
  97646. if(v)--v;
  97647. while(v){
  97648. ret++;
  97649. v>>=1;
  97650. }
  97651. return(ret);
  97652. }
  97653. typedef struct private_state {
  97654. envelope_lookup *ve; /* envelope lookup */
  97655. int window[2];
  97656. vorbis_look_transform **transform[2]; /* block, type */
  97657. drft_lookup fft_look[2];
  97658. int modebits;
  97659. vorbis_look_floor **flr;
  97660. vorbis_look_residue **residue;
  97661. vorbis_look_psy *psy;
  97662. vorbis_look_psy_global *psy_g_look;
  97663. unsigned char *header;
  97664. unsigned char *header1;
  97665. unsigned char *header2;
  97666. bitrate_manager_state bms;
  97667. ogg_int64_t sample_count;
  97668. } private_state;
  97669. /*** Start of inlined file: highlevel.h ***/
  97670. typedef struct highlevel_byblocktype {
  97671. double tone_mask_setting;
  97672. double tone_peaklimit_setting;
  97673. double noise_bias_setting;
  97674. double noise_compand_setting;
  97675. } highlevel_byblocktype;
  97676. typedef struct highlevel_encode_setup {
  97677. void *setup;
  97678. int set_in_stone;
  97679. double base_setting;
  97680. double long_setting;
  97681. double short_setting;
  97682. double impulse_noisetune;
  97683. int managed;
  97684. long bitrate_min;
  97685. long bitrate_av;
  97686. double bitrate_av_damp;
  97687. long bitrate_max;
  97688. long bitrate_reservoir;
  97689. double bitrate_reservoir_bias;
  97690. int impulse_block_p;
  97691. int noise_normalize_p;
  97692. double stereo_point_setting;
  97693. double lowpass_kHz;
  97694. double ath_floating_dB;
  97695. double ath_absolute_dB;
  97696. double amplitude_track_dBpersec;
  97697. double trigger_setting;
  97698. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97699. } highlevel_encode_setup;
  97700. /*** End of inlined file: highlevel.h ***/
  97701. typedef struct codec_setup_info {
  97702. long blocksizes[2];
  97703. int modes;
  97704. int maps;
  97705. int floors;
  97706. int residues;
  97707. int books;
  97708. int psys; /* encode only */
  97709. vorbis_info_mode *mode_param[64];
  97710. int map_type[64];
  97711. vorbis_info_mapping *map_param[64];
  97712. int floor_type[64];
  97713. vorbis_info_floor *floor_param[64];
  97714. int residue_type[64];
  97715. vorbis_info_residue *residue_param[64];
  97716. static_codebook *book_param[256];
  97717. codebook *fullbooks;
  97718. vorbis_info_psy *psy_param[4]; /* encode only */
  97719. vorbis_info_psy_global psy_g_param;
  97720. bitrate_manager_info bi;
  97721. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97722. highly redundant structure, but
  97723. improves clarity of program flow. */
  97724. int halfrate_flag; /* painless downsample for decode */
  97725. } codec_setup_info;
  97726. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97727. extern void _vp_global_free(vorbis_look_psy_global *look);
  97728. #endif
  97729. /*** End of inlined file: codec_internal.h ***/
  97730. /*** Start of inlined file: registry.h ***/
  97731. #ifndef _V_REG_H_
  97732. #define _V_REG_H_
  97733. #define VI_TRANSFORMB 1
  97734. #define VI_WINDOWB 1
  97735. #define VI_TIMEB 1
  97736. #define VI_FLOORB 2
  97737. #define VI_RESB 3
  97738. #define VI_MAPB 1
  97739. extern vorbis_func_floor *_floor_P[];
  97740. extern vorbis_func_residue *_residue_P[];
  97741. extern vorbis_func_mapping *_mapping_P[];
  97742. #endif
  97743. /*** End of inlined file: registry.h ***/
  97744. /*** Start of inlined file: scales.h ***/
  97745. #ifndef _V_SCALES_H_
  97746. #define _V_SCALES_H_
  97747. #include <math.h>
  97748. #define VORBIS_IEEE_FLOAT32 1
  97749. #ifdef VORBIS_IEEE_FLOAT32
  97750. static float unitnorm(float x){
  97751. union {
  97752. ogg_uint32_t i;
  97753. float f;
  97754. } ix;
  97755. ix.f = x;
  97756. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97757. return ix.f;
  97758. }
  97759. static float todB(const float *x){
  97760. union {
  97761. ogg_uint32_t i;
  97762. float f;
  97763. } ix;
  97764. ix.f = *x;
  97765. ix.i = ix.i&0x7fffffff;
  97766. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97767. }
  97768. #define todB_nn(x) todB(x)
  97769. #else
  97770. static float unitnorm(float x){
  97771. if(x<0)return(-1.f);
  97772. return(1.f);
  97773. }
  97774. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97775. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97776. #endif
  97777. #define fromdB(x) (exp((x)*.11512925f))
  97778. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97779. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97780. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97781. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97782. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97783. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97784. #endif
  97785. /*** End of inlined file: scales.h ***/
  97786. int analysis_noisy=1;
  97787. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97788. int ret,i;
  97789. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97790. vb->glue_bits=0;
  97791. vb->time_bits=0;
  97792. vb->floor_bits=0;
  97793. vb->res_bits=0;
  97794. for(i=0;i<PACKETBLOBS;i++)
  97795. oggpack_reset(vbi->packetblob[i]);
  97796. if((ret=_mapping_P[0]->forward(vb)))
  97797. return(ret);
  97798. if(op){
  97799. if(vorbis_bitrate_managed(vb))
  97800. return(OV_EINVAL);
  97801. op->packet=oggpack_get_buffer(&vb->opb);
  97802. op->bytes=oggpack_bytes(&vb->opb);
  97803. op->b_o_s=0;
  97804. op->e_o_s=vb->eofflag;
  97805. op->granulepos=vb->granulepos;
  97806. op->packetno=vb->sequence; /* for sake of completeness */
  97807. }
  97808. return(0);
  97809. }
  97810. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97811. int j;
  97812. FILE *of;
  97813. char buffer[80];
  97814. sprintf(buffer,"%s_%d.m",base,i);
  97815. of=fopen(buffer,"w");
  97816. if(!of)perror("failed to open data dump file");
  97817. for(j=0;j<n;j++){
  97818. if(bark){
  97819. float b=toBARK((4000.f*j/n)+.25);
  97820. fprintf(of,"%f ",b);
  97821. }else
  97822. if(off!=0)
  97823. fprintf(of,"%f ",(double)(j+off)/8000.);
  97824. else
  97825. fprintf(of,"%f ",(double)j);
  97826. if(dB){
  97827. float val;
  97828. if(v[j]==0.)
  97829. val=-140.;
  97830. else
  97831. val=todB(v+j);
  97832. fprintf(of,"%f\n",val);
  97833. }else{
  97834. fprintf(of,"%f\n",v[j]);
  97835. }
  97836. }
  97837. fclose(of);
  97838. }
  97839. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97840. ogg_int64_t off){
  97841. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97842. }
  97843. #endif
  97844. /*** End of inlined file: analysis.c ***/
  97845. /*** Start of inlined file: bitrate.c ***/
  97846. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97847. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97848. // tasks..
  97849. #if JUCE_MSVC
  97850. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97851. #endif
  97852. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97853. #if JUCE_USE_OGGVORBIS
  97854. #include <stdlib.h>
  97855. #include <string.h>
  97856. #include <math.h>
  97857. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97858. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97859. bitrate_manager_info *bi=&ci->bi;
  97860. memset(bm,0,sizeof(*bm));
  97861. if(bi && (bi->reservoir_bits>0)){
  97862. long ratesamples=vi->rate;
  97863. int halfsamples=ci->blocksizes[0]>>1;
  97864. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97865. bm->managed=1;
  97866. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97867. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97868. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97869. bm->avgfloat=PACKETBLOBS/2;
  97870. {
  97871. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97872. bm->minmax_reservoir=desired_fill;
  97873. bm->avg_reservoir=desired_fill;
  97874. }
  97875. }
  97876. }
  97877. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97878. memset(bm,0,sizeof(*bm));
  97879. return;
  97880. }
  97881. int vorbis_bitrate_managed(vorbis_block *vb){
  97882. vorbis_dsp_state *vd=vb->vd;
  97883. private_state *b=(private_state*)vd->backend_state;
  97884. bitrate_manager_state *bm=&b->bms;
  97885. if(bm && bm->managed)return(1);
  97886. return(0);
  97887. }
  97888. int vorbis_bitrate_addblock(vorbis_block *vb){
  97889. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97890. vorbis_dsp_state *vd=vb->vd;
  97891. private_state *b=(private_state*)vd->backend_state;
  97892. bitrate_manager_state *bm=&b->bms;
  97893. vorbis_info *vi=vd->vi;
  97894. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97895. bitrate_manager_info *bi=&ci->bi;
  97896. int choice=rint(bm->avgfloat);
  97897. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97898. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97899. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97900. int samples=ci->blocksizes[vb->W]>>1;
  97901. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97902. if(!bm->managed){
  97903. if(bm->vb)return(-1); /* one has been submitted without
  97904. being claimed */
  97905. bm->vb=vb;
  97906. return(0);
  97907. }
  97908. bm->vb=vb;
  97909. if(bm->avg_bitsper>0){
  97910. double slew=0.;
  97911. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97912. double slewlimit= 15./bi->slew_damp;
  97913. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97914. while(choice>0 && this_bits>avg_target_bits &&
  97915. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97916. choice--;
  97917. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97918. }
  97919. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97920. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97921. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97922. choice++;
  97923. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97924. }
  97925. }
  97926. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97927. if(slew<-slewlimit)slew=-slewlimit;
  97928. if(slew>slewlimit)slew=slewlimit;
  97929. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97930. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97931. }
  97932. if(bm->min_bitsper>0){
  97933. if(this_bits<min_target_bits){
  97934. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97935. choice++;
  97936. if(choice>=PACKETBLOBS)break;
  97937. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97938. }
  97939. }
  97940. }
  97941. if(bm->max_bitsper>0){
  97942. if(this_bits>max_target_bits){
  97943. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97944. choice--;
  97945. if(choice<0)break;
  97946. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97947. }
  97948. }
  97949. }
  97950. if(choice<0){
  97951. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97952. bm->choice=choice=0;
  97953. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97954. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97955. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97956. }
  97957. }else{
  97958. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97959. if(choice>=PACKETBLOBS)
  97960. choice=PACKETBLOBS-1;
  97961. bm->choice=choice;
  97962. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97963. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97964. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97965. }
  97966. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97967. if(max_target_bits>0 && this_bits>max_target_bits){
  97968. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97969. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97970. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97971. }else{
  97972. if(bm->minmax_reservoir>desired_fill){
  97973. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97974. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97975. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97976. }else{
  97977. bm->minmax_reservoir=desired_fill;
  97978. }
  97979. }else{
  97980. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97981. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97982. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97983. }else{
  97984. bm->minmax_reservoir=desired_fill;
  97985. }
  97986. }
  97987. }
  97988. }
  97989. if(bm->avg_bitsper>0){
  97990. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97991. bm->avg_reservoir+=this_bits-avg_target_bits;
  97992. }
  97993. return(0);
  97994. }
  97995. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97996. private_state *b=(private_state*)vd->backend_state;
  97997. bitrate_manager_state *bm=&b->bms;
  97998. vorbis_block *vb=bm->vb;
  97999. int choice=PACKETBLOBS/2;
  98000. if(!vb)return 0;
  98001. if(op){
  98002. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98003. if(vorbis_bitrate_managed(vb))
  98004. choice=bm->choice;
  98005. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  98006. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  98007. op->b_o_s=0;
  98008. op->e_o_s=vb->eofflag;
  98009. op->granulepos=vb->granulepos;
  98010. op->packetno=vb->sequence; /* for sake of completeness */
  98011. }
  98012. bm->vb=0;
  98013. return(1);
  98014. }
  98015. #endif
  98016. /*** End of inlined file: bitrate.c ***/
  98017. /*** Start of inlined file: block.c ***/
  98018. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98019. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98020. // tasks..
  98021. #if JUCE_MSVC
  98022. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98023. #endif
  98024. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98025. #if JUCE_USE_OGGVORBIS
  98026. #include <stdio.h>
  98027. #include <stdlib.h>
  98028. #include <string.h>
  98029. /*** Start of inlined file: window.h ***/
  98030. #ifndef _V_WINDOW_
  98031. #define _V_WINDOW_
  98032. extern float *_vorbis_window_get(int n);
  98033. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  98034. int lW,int W,int nW);
  98035. #endif
  98036. /*** End of inlined file: window.h ***/
  98037. /*** Start of inlined file: lpc.h ***/
  98038. #ifndef _V_LPC_H_
  98039. #define _V_LPC_H_
  98040. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  98041. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  98042. float *data,long n);
  98043. #endif
  98044. /*** End of inlined file: lpc.h ***/
  98045. #ifndef WORD_ALIGN
  98046. #define WORD_ALIGN 8
  98047. #endif
  98048. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  98049. int i;
  98050. memset(vb,0,sizeof(*vb));
  98051. vb->vd=v;
  98052. vb->localalloc=0;
  98053. vb->localstore=NULL;
  98054. if(v->analysisp){
  98055. vorbis_block_internal *vbi=(vorbis_block_internal*)
  98056. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  98057. vbi->ampmax=-9999;
  98058. for(i=0;i<PACKETBLOBS;i++){
  98059. if(i==PACKETBLOBS/2){
  98060. vbi->packetblob[i]=&vb->opb;
  98061. }else{
  98062. vbi->packetblob[i]=
  98063. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  98064. }
  98065. oggpack_writeinit(vbi->packetblob[i]);
  98066. }
  98067. }
  98068. return(0);
  98069. }
  98070. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  98071. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  98072. if(bytes+vb->localtop>vb->localalloc){
  98073. if(vb->localstore){
  98074. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  98075. vb->totaluse+=vb->localtop;
  98076. link->next=vb->reap;
  98077. link->ptr=vb->localstore;
  98078. vb->reap=link;
  98079. }
  98080. vb->localalloc=bytes;
  98081. vb->localstore=_ogg_malloc(vb->localalloc);
  98082. vb->localtop=0;
  98083. }
  98084. {
  98085. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  98086. vb->localtop+=bytes;
  98087. return ret;
  98088. }
  98089. }
  98090. void _vorbis_block_ripcord(vorbis_block *vb){
  98091. struct alloc_chain *reap=vb->reap;
  98092. while(reap){
  98093. struct alloc_chain *next=reap->next;
  98094. _ogg_free(reap->ptr);
  98095. memset(reap,0,sizeof(*reap));
  98096. _ogg_free(reap);
  98097. reap=next;
  98098. }
  98099. if(vb->totaluse){
  98100. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  98101. vb->localalloc+=vb->totaluse;
  98102. vb->totaluse=0;
  98103. }
  98104. vb->localtop=0;
  98105. vb->reap=NULL;
  98106. }
  98107. int vorbis_block_clear(vorbis_block *vb){
  98108. int i;
  98109. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98110. _vorbis_block_ripcord(vb);
  98111. if(vb->localstore)_ogg_free(vb->localstore);
  98112. if(vbi){
  98113. for(i=0;i<PACKETBLOBS;i++){
  98114. oggpack_writeclear(vbi->packetblob[i]);
  98115. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  98116. }
  98117. _ogg_free(vbi);
  98118. }
  98119. memset(vb,0,sizeof(*vb));
  98120. return(0);
  98121. }
  98122. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  98123. int i;
  98124. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98125. private_state *b=NULL;
  98126. int hs;
  98127. if(ci==NULL) return 1;
  98128. hs=ci->halfrate_flag;
  98129. memset(v,0,sizeof(*v));
  98130. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  98131. v->vi=vi;
  98132. b->modebits=ilog2(ci->modes);
  98133. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  98134. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  98135. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98136. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98137. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  98138. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  98139. b->window[0]=ilog2(ci->blocksizes[0])-6;
  98140. b->window[1]=ilog2(ci->blocksizes[1])-6;
  98141. if(encp){ /* encode/decode differ here */
  98142. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  98143. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  98144. if(!ci->fullbooks){
  98145. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98146. for(i=0;i<ci->books;i++)
  98147. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  98148. }
  98149. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  98150. for(i=0;i<ci->psys;i++){
  98151. _vp_psy_init(b->psy+i,
  98152. ci->psy_param[i],
  98153. &ci->psy_g_param,
  98154. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  98155. vi->rate);
  98156. }
  98157. v->analysisp=1;
  98158. }else{
  98159. if(!ci->fullbooks){
  98160. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98161. for(i=0;i<ci->books;i++){
  98162. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  98163. vorbis_staticbook_destroy(ci->book_param[i]);
  98164. ci->book_param[i]=NULL;
  98165. }
  98166. }
  98167. }
  98168. v->pcm_storage=ci->blocksizes[1];
  98169. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  98170. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  98171. {
  98172. int i;
  98173. for(i=0;i<vi->channels;i++)
  98174. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  98175. }
  98176. v->lW=0; /* previous window size */
  98177. v->W=0; /* current window size */
  98178. v->centerW=ci->blocksizes[1]/2;
  98179. v->pcm_current=v->centerW;
  98180. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  98181. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  98182. for(i=0;i<ci->floors;i++)
  98183. b->flr[i]=_floor_P[ci->floor_type[i]]->
  98184. look(v,ci->floor_param[i]);
  98185. for(i=0;i<ci->residues;i++)
  98186. b->residue[i]=_residue_P[ci->residue_type[i]]->
  98187. look(v,ci->residue_param[i]);
  98188. return 0;
  98189. }
  98190. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98191. private_state *b=NULL;
  98192. if(_vds_shared_init(v,vi,1))return 1;
  98193. b=(private_state*)v->backend_state;
  98194. b->psy_g_look=_vp_global_look(vi);
  98195. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  98196. _ve_envelope_init(b->ve,vi);
  98197. vorbis_bitrate_init(vi,&b->bms);
  98198. v->sequence=3;
  98199. return(0);
  98200. }
  98201. void vorbis_dsp_clear(vorbis_dsp_state *v){
  98202. int i;
  98203. if(v){
  98204. vorbis_info *vi=v->vi;
  98205. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  98206. private_state *b=(private_state*)v->backend_state;
  98207. if(b){
  98208. if(b->ve){
  98209. _ve_envelope_clear(b->ve);
  98210. _ogg_free(b->ve);
  98211. }
  98212. if(b->transform[0]){
  98213. mdct_clear((mdct_lookup*) b->transform[0][0]);
  98214. _ogg_free(b->transform[0][0]);
  98215. _ogg_free(b->transform[0]);
  98216. }
  98217. if(b->transform[1]){
  98218. mdct_clear((mdct_lookup*) b->transform[1][0]);
  98219. _ogg_free(b->transform[1][0]);
  98220. _ogg_free(b->transform[1]);
  98221. }
  98222. if(b->flr){
  98223. for(i=0;i<ci->floors;i++)
  98224. _floor_P[ci->floor_type[i]]->
  98225. free_look(b->flr[i]);
  98226. _ogg_free(b->flr);
  98227. }
  98228. if(b->residue){
  98229. for(i=0;i<ci->residues;i++)
  98230. _residue_P[ci->residue_type[i]]->
  98231. free_look(b->residue[i]);
  98232. _ogg_free(b->residue);
  98233. }
  98234. if(b->psy){
  98235. for(i=0;i<ci->psys;i++)
  98236. _vp_psy_clear(b->psy+i);
  98237. _ogg_free(b->psy);
  98238. }
  98239. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  98240. vorbis_bitrate_clear(&b->bms);
  98241. drft_clear(&b->fft_look[0]);
  98242. drft_clear(&b->fft_look[1]);
  98243. }
  98244. if(v->pcm){
  98245. for(i=0;i<vi->channels;i++)
  98246. if(v->pcm[i])_ogg_free(v->pcm[i]);
  98247. _ogg_free(v->pcm);
  98248. if(v->pcmret)_ogg_free(v->pcmret);
  98249. }
  98250. if(b){
  98251. if(b->header)_ogg_free(b->header);
  98252. if(b->header1)_ogg_free(b->header1);
  98253. if(b->header2)_ogg_free(b->header2);
  98254. _ogg_free(b);
  98255. }
  98256. memset(v,0,sizeof(*v));
  98257. }
  98258. }
  98259. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  98260. int i;
  98261. vorbis_info *vi=v->vi;
  98262. private_state *b=(private_state*)v->backend_state;
  98263. if(b->header)_ogg_free(b->header);b->header=NULL;
  98264. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  98265. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  98266. if(v->pcm_current+vals>=v->pcm_storage){
  98267. v->pcm_storage=v->pcm_current+vals*2;
  98268. for(i=0;i<vi->channels;i++){
  98269. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  98270. }
  98271. }
  98272. for(i=0;i<vi->channels;i++)
  98273. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  98274. return(v->pcmret);
  98275. }
  98276. static void _preextrapolate_helper(vorbis_dsp_state *v){
  98277. int i;
  98278. int order=32;
  98279. float *lpc=(float*)alloca(order*sizeof(*lpc));
  98280. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  98281. long j;
  98282. v->preextrapolate=1;
  98283. if(v->pcm_current-v->centerW>order*2){ /* safety */
  98284. for(i=0;i<v->vi->channels;i++){
  98285. for(j=0;j<v->pcm_current;j++)
  98286. work[j]=v->pcm[i][v->pcm_current-j-1];
  98287. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  98288. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  98289. order,
  98290. work+v->pcm_current-v->centerW,
  98291. v->centerW);
  98292. for(j=0;j<v->pcm_current;j++)
  98293. v->pcm[i][v->pcm_current-j-1]=work[j];
  98294. }
  98295. }
  98296. }
  98297. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  98298. vorbis_info *vi=v->vi;
  98299. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98300. if(vals<=0){
  98301. int order=32;
  98302. int i;
  98303. float *lpc=(float*) alloca(order*sizeof(*lpc));
  98304. if(!v->preextrapolate)
  98305. _preextrapolate_helper(v);
  98306. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98307. v->eofflag=v->pcm_current;
  98308. v->pcm_current+=ci->blocksizes[1]*3;
  98309. for(i=0;i<vi->channels;i++){
  98310. if(v->eofflag>order*2){
  98311. long n;
  98312. n=v->eofflag;
  98313. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98314. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98315. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98316. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98317. }else{
  98318. memset(v->pcm[i]+v->eofflag,0,
  98319. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98320. }
  98321. }
  98322. }else{
  98323. if(v->pcm_current+vals>v->pcm_storage)
  98324. return(OV_EINVAL);
  98325. v->pcm_current+=vals;
  98326. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98327. _preextrapolate_helper(v);
  98328. }
  98329. return(0);
  98330. }
  98331. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98332. int i;
  98333. vorbis_info *vi=v->vi;
  98334. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98335. private_state *b=(private_state*)v->backend_state;
  98336. vorbis_look_psy_global *g=b->psy_g_look;
  98337. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98338. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98339. if(!v->preextrapolate)return(0);
  98340. if(v->eofflag==-1)return(0);
  98341. {
  98342. long bp=_ve_envelope_search(v);
  98343. if(bp==-1){
  98344. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98345. full long block */
  98346. v->nW=0;
  98347. }else{
  98348. if(ci->blocksizes[0]==ci->blocksizes[1])
  98349. v->nW=0;
  98350. else
  98351. v->nW=bp;
  98352. }
  98353. }
  98354. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98355. {
  98356. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98357. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98358. although this check is
  98359. less strict that the
  98360. _ve_envelope_search,
  98361. the search is not run
  98362. if we only use one
  98363. block size */
  98364. }
  98365. _vorbis_block_ripcord(vb);
  98366. vb->lW=v->lW;
  98367. vb->W=v->W;
  98368. vb->nW=v->nW;
  98369. if(v->W){
  98370. if(!v->lW || !v->nW){
  98371. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98372. }else{
  98373. vbi->blocktype=BLOCKTYPE_LONG;
  98374. }
  98375. }else{
  98376. if(_ve_envelope_mark(v)){
  98377. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98378. }else{
  98379. vbi->blocktype=BLOCKTYPE_PADDING;
  98380. }
  98381. }
  98382. vb->vd=v;
  98383. vb->sequence=v->sequence++;
  98384. vb->granulepos=v->granulepos;
  98385. vb->pcmend=ci->blocksizes[v->W];
  98386. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98387. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98388. vbi->ampmax=g->ampmax;
  98389. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98390. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98391. for(i=0;i<vi->channels;i++){
  98392. vbi->pcmdelay[i]=
  98393. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98394. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98395. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98396. }
  98397. if(v->eofflag){
  98398. if(v->centerW>=v->eofflag){
  98399. v->eofflag=-1;
  98400. vb->eofflag=1;
  98401. return(1);
  98402. }
  98403. }
  98404. {
  98405. int new_centerNext=ci->blocksizes[1]/2;
  98406. int movementW=centerNext-new_centerNext;
  98407. if(movementW>0){
  98408. _ve_envelope_shift(b->ve,movementW);
  98409. v->pcm_current-=movementW;
  98410. for(i=0;i<vi->channels;i++)
  98411. memmove(v->pcm[i],v->pcm[i]+movementW,
  98412. v->pcm_current*sizeof(*v->pcm[i]));
  98413. v->lW=v->W;
  98414. v->W=v->nW;
  98415. v->centerW=new_centerNext;
  98416. if(v->eofflag){
  98417. v->eofflag-=movementW;
  98418. if(v->eofflag<=0)v->eofflag=-1;
  98419. if(v->centerW>=v->eofflag){
  98420. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98421. }else{
  98422. v->granulepos+=movementW;
  98423. }
  98424. }else{
  98425. v->granulepos+=movementW;
  98426. }
  98427. }
  98428. }
  98429. return(1);
  98430. }
  98431. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98432. vorbis_info *vi=v->vi;
  98433. codec_setup_info *ci;
  98434. int hs;
  98435. if(!v->backend_state)return -1;
  98436. if(!vi)return -1;
  98437. ci=(codec_setup_info*) vi->codec_setup;
  98438. if(!ci)return -1;
  98439. hs=ci->halfrate_flag;
  98440. v->centerW=ci->blocksizes[1]>>(hs+1);
  98441. v->pcm_current=v->centerW>>hs;
  98442. v->pcm_returned=-1;
  98443. v->granulepos=-1;
  98444. v->sequence=-1;
  98445. v->eofflag=0;
  98446. ((private_state *)(v->backend_state))->sample_count=-1;
  98447. return(0);
  98448. }
  98449. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98450. if(_vds_shared_init(v,vi,0)) return 1;
  98451. vorbis_synthesis_restart(v);
  98452. return 0;
  98453. }
  98454. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98455. vorbis_info *vi=v->vi;
  98456. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98457. private_state *b=(private_state*)v->backend_state;
  98458. int hs=ci->halfrate_flag;
  98459. int i,j;
  98460. if(!vb)return(OV_EINVAL);
  98461. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98462. v->lW=v->W;
  98463. v->W=vb->W;
  98464. v->nW=-1;
  98465. if((v->sequence==-1)||
  98466. (v->sequence+1 != vb->sequence)){
  98467. v->granulepos=-1; /* out of sequence; lose count */
  98468. b->sample_count=-1;
  98469. }
  98470. v->sequence=vb->sequence;
  98471. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98472. was called on block */
  98473. int n=ci->blocksizes[v->W]>>(hs+1);
  98474. int n0=ci->blocksizes[0]>>(hs+1);
  98475. int n1=ci->blocksizes[1]>>(hs+1);
  98476. int thisCenter;
  98477. int prevCenter;
  98478. v->glue_bits+=vb->glue_bits;
  98479. v->time_bits+=vb->time_bits;
  98480. v->floor_bits+=vb->floor_bits;
  98481. v->res_bits+=vb->res_bits;
  98482. if(v->centerW){
  98483. thisCenter=n1;
  98484. prevCenter=0;
  98485. }else{
  98486. thisCenter=0;
  98487. prevCenter=n1;
  98488. }
  98489. for(j=0;j<vi->channels;j++){
  98490. if(v->lW){
  98491. if(v->W){
  98492. float *w=_vorbis_window_get(b->window[1]-hs);
  98493. float *pcm=v->pcm[j]+prevCenter;
  98494. float *p=vb->pcm[j];
  98495. for(i=0;i<n1;i++)
  98496. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98497. }else{
  98498. float *w=_vorbis_window_get(b->window[0]-hs);
  98499. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98500. float *p=vb->pcm[j];
  98501. for(i=0;i<n0;i++)
  98502. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98503. }
  98504. }else{
  98505. if(v->W){
  98506. float *w=_vorbis_window_get(b->window[0]-hs);
  98507. float *pcm=v->pcm[j]+prevCenter;
  98508. float *p=vb->pcm[j]+n1/2-n0/2;
  98509. for(i=0;i<n0;i++)
  98510. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98511. for(;i<n1/2+n0/2;i++)
  98512. pcm[i]=p[i];
  98513. }else{
  98514. float *w=_vorbis_window_get(b->window[0]-hs);
  98515. float *pcm=v->pcm[j]+prevCenter;
  98516. float *p=vb->pcm[j];
  98517. for(i=0;i<n0;i++)
  98518. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98519. }
  98520. }
  98521. {
  98522. float *pcm=v->pcm[j]+thisCenter;
  98523. float *p=vb->pcm[j]+n;
  98524. for(i=0;i<n;i++)
  98525. pcm[i]=p[i];
  98526. }
  98527. }
  98528. if(v->centerW)
  98529. v->centerW=0;
  98530. else
  98531. v->centerW=n1;
  98532. if(v->pcm_returned==-1){
  98533. v->pcm_returned=thisCenter;
  98534. v->pcm_current=thisCenter;
  98535. }else{
  98536. v->pcm_returned=prevCenter;
  98537. v->pcm_current=prevCenter+
  98538. ((ci->blocksizes[v->lW]/4+
  98539. ci->blocksizes[v->W]/4)>>hs);
  98540. }
  98541. }
  98542. if(b->sample_count==-1){
  98543. b->sample_count=0;
  98544. }else{
  98545. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98546. }
  98547. if(v->granulepos==-1){
  98548. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98549. v->granulepos=vb->granulepos;
  98550. if(b->sample_count>v->granulepos){
  98551. if(vb->eofflag){
  98552. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98553. }else{
  98554. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98555. if(v->pcm_returned>v->pcm_current)
  98556. v->pcm_returned=v->pcm_current;
  98557. }
  98558. }
  98559. }
  98560. }else{
  98561. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98562. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98563. if(v->granulepos>vb->granulepos){
  98564. long extra=v->granulepos-vb->granulepos;
  98565. if(extra)
  98566. if(vb->eofflag){
  98567. v->pcm_current-=extra>>hs;
  98568. } /* else {Shouldn't happen *unless* the bitstream is out of
  98569. spec. Either way, believe the bitstream } */
  98570. } /* else {Shouldn't happen *unless* the bitstream is out of
  98571. spec. Either way, believe the bitstream } */
  98572. v->granulepos=vb->granulepos;
  98573. }
  98574. }
  98575. if(vb->eofflag)v->eofflag=1;
  98576. return(0);
  98577. }
  98578. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98579. vorbis_info *vi=v->vi;
  98580. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98581. if(pcm){
  98582. int i;
  98583. for(i=0;i<vi->channels;i++)
  98584. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98585. *pcm=v->pcmret;
  98586. }
  98587. return(v->pcm_current-v->pcm_returned);
  98588. }
  98589. return(0);
  98590. }
  98591. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98592. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98593. v->pcm_returned+=n;
  98594. return(0);
  98595. }
  98596. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98597. vorbis_info *vi=v->vi;
  98598. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98599. int hs=ci->halfrate_flag;
  98600. int n=ci->blocksizes[v->W]>>(hs+1);
  98601. int n0=ci->blocksizes[0]>>(hs+1);
  98602. int n1=ci->blocksizes[1]>>(hs+1);
  98603. int i,j;
  98604. if(v->pcm_returned<0)return 0;
  98605. if(v->centerW==n1){
  98606. for(j=0;j<vi->channels;j++){
  98607. float *p=v->pcm[j];
  98608. for(i=0;i<n1;i++){
  98609. float temp=p[i];
  98610. p[i]=p[i+n1];
  98611. p[i+n1]=temp;
  98612. }
  98613. }
  98614. v->pcm_current-=n1;
  98615. v->pcm_returned-=n1;
  98616. v->centerW=0;
  98617. }
  98618. if((v->lW^v->W)==1){
  98619. for(j=0;j<vi->channels;j++){
  98620. float *s=v->pcm[j];
  98621. float *d=v->pcm[j]+(n1-n0)/2;
  98622. for(i=(n1+n0)/2-1;i>=0;--i)
  98623. d[i]=s[i];
  98624. }
  98625. v->pcm_returned+=(n1-n0)/2;
  98626. v->pcm_current+=(n1-n0)/2;
  98627. }else{
  98628. if(v->lW==0){
  98629. for(j=0;j<vi->channels;j++){
  98630. float *s=v->pcm[j];
  98631. float *d=v->pcm[j]+n1-n0;
  98632. for(i=n0-1;i>=0;--i)
  98633. d[i]=s[i];
  98634. }
  98635. v->pcm_returned+=n1-n0;
  98636. v->pcm_current+=n1-n0;
  98637. }
  98638. }
  98639. if(pcm){
  98640. int i;
  98641. for(i=0;i<vi->channels;i++)
  98642. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98643. *pcm=v->pcmret;
  98644. }
  98645. return(n1+n-v->pcm_returned);
  98646. }
  98647. float *vorbis_window(vorbis_dsp_state *v,int W){
  98648. vorbis_info *vi=v->vi;
  98649. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98650. int hs=ci->halfrate_flag;
  98651. private_state *b=(private_state*)v->backend_state;
  98652. if(b->window[W]-1<0)return NULL;
  98653. return _vorbis_window_get(b->window[W]-hs);
  98654. }
  98655. #endif
  98656. /*** End of inlined file: block.c ***/
  98657. /*** Start of inlined file: codebook.c ***/
  98658. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98659. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98660. // tasks..
  98661. #if JUCE_MSVC
  98662. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98663. #endif
  98664. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98665. #if JUCE_USE_OGGVORBIS
  98666. #include <stdlib.h>
  98667. #include <string.h>
  98668. #include <math.h>
  98669. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98670. long i,j;
  98671. int ordered=0;
  98672. oggpack_write(opb,0x564342,24);
  98673. oggpack_write(opb,c->dim,16);
  98674. oggpack_write(opb,c->entries,24);
  98675. for(i=1;i<c->entries;i++)
  98676. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98677. if(i==c->entries)ordered=1;
  98678. if(ordered){
  98679. long count=0;
  98680. oggpack_write(opb,1,1); /* ordered */
  98681. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98682. for(i=1;i<c->entries;i++){
  98683. long thisx=c->lengthlist[i];
  98684. long last=c->lengthlist[i-1];
  98685. if(thisx>last){
  98686. for(j=last;j<thisx;j++){
  98687. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98688. count=i;
  98689. }
  98690. }
  98691. }
  98692. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98693. }else{
  98694. oggpack_write(opb,0,1); /* unordered */
  98695. for(i=0;i<c->entries;i++)
  98696. if(c->lengthlist[i]==0)break;
  98697. if(i==c->entries){
  98698. oggpack_write(opb,0,1); /* no unused entries */
  98699. for(i=0;i<c->entries;i++)
  98700. oggpack_write(opb,c->lengthlist[i]-1,5);
  98701. }else{
  98702. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98703. for(i=0;i<c->entries;i++){
  98704. if(c->lengthlist[i]==0){
  98705. oggpack_write(opb,0,1);
  98706. }else{
  98707. oggpack_write(opb,1,1);
  98708. oggpack_write(opb,c->lengthlist[i]-1,5);
  98709. }
  98710. }
  98711. }
  98712. }
  98713. oggpack_write(opb,c->maptype,4);
  98714. switch(c->maptype){
  98715. case 0:
  98716. break;
  98717. case 1:case 2:
  98718. if(!c->quantlist){
  98719. return(-1);
  98720. }
  98721. oggpack_write(opb,c->q_min,32);
  98722. oggpack_write(opb,c->q_delta,32);
  98723. oggpack_write(opb,c->q_quant-1,4);
  98724. oggpack_write(opb,c->q_sequencep,1);
  98725. {
  98726. int quantvals;
  98727. switch(c->maptype){
  98728. case 1:
  98729. quantvals=_book_maptype1_quantvals(c);
  98730. break;
  98731. case 2:
  98732. quantvals=c->entries*c->dim;
  98733. break;
  98734. default: /* NOT_REACHABLE */
  98735. quantvals=-1;
  98736. }
  98737. for(i=0;i<quantvals;i++)
  98738. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98739. }
  98740. break;
  98741. default:
  98742. return(-1);
  98743. }
  98744. return(0);
  98745. }
  98746. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98747. long i,j;
  98748. memset(s,0,sizeof(*s));
  98749. s->allocedp=1;
  98750. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98751. s->dim=oggpack_read(opb,16);
  98752. s->entries=oggpack_read(opb,24);
  98753. if(s->entries==-1)goto _eofout;
  98754. switch((int)oggpack_read(opb,1)){
  98755. case 0:
  98756. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98757. if(oggpack_read(opb,1)){
  98758. for(i=0;i<s->entries;i++){
  98759. if(oggpack_read(opb,1)){
  98760. long num=oggpack_read(opb,5);
  98761. if(num==-1)goto _eofout;
  98762. s->lengthlist[i]=num+1;
  98763. }else
  98764. s->lengthlist[i]=0;
  98765. }
  98766. }else{
  98767. for(i=0;i<s->entries;i++){
  98768. long num=oggpack_read(opb,5);
  98769. if(num==-1)goto _eofout;
  98770. s->lengthlist[i]=num+1;
  98771. }
  98772. }
  98773. break;
  98774. case 1:
  98775. {
  98776. long length=oggpack_read(opb,5)+1;
  98777. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98778. for(i=0;i<s->entries;){
  98779. long num=oggpack_read(opb,_ilog(s->entries-i));
  98780. if(num==-1)goto _eofout;
  98781. for(j=0;j<num && i<s->entries;j++,i++)
  98782. s->lengthlist[i]=length;
  98783. length++;
  98784. }
  98785. }
  98786. break;
  98787. default:
  98788. return(-1);
  98789. }
  98790. switch((s->maptype=oggpack_read(opb,4))){
  98791. case 0:
  98792. break;
  98793. case 1: case 2:
  98794. s->q_min=oggpack_read(opb,32);
  98795. s->q_delta=oggpack_read(opb,32);
  98796. s->q_quant=oggpack_read(opb,4)+1;
  98797. s->q_sequencep=oggpack_read(opb,1);
  98798. {
  98799. int quantvals=0;
  98800. switch(s->maptype){
  98801. case 1:
  98802. quantvals=_book_maptype1_quantvals(s);
  98803. break;
  98804. case 2:
  98805. quantvals=s->entries*s->dim;
  98806. break;
  98807. }
  98808. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98809. for(i=0;i<quantvals;i++)
  98810. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98811. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98812. }
  98813. break;
  98814. default:
  98815. goto _errout;
  98816. }
  98817. return(0);
  98818. _errout:
  98819. _eofout:
  98820. vorbis_staticbook_clear(s);
  98821. return(-1);
  98822. }
  98823. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98824. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98825. return(book->c->lengthlist[a]);
  98826. }
  98827. int vorbis_book_errorv(codebook *book,float *a){
  98828. int dim=book->dim,k;
  98829. int best=_best(book,a,1);
  98830. for(k=0;k<dim;k++)
  98831. a[k]=(book->valuelist+best*dim)[k];
  98832. return(best);
  98833. }
  98834. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98835. int k,dim=book->dim;
  98836. for(k=0;k<dim;k++)
  98837. a[k]=(book->valuelist+best*dim)[k];
  98838. return(vorbis_book_encode(book,best,b));
  98839. }
  98840. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98841. int read=book->dec_maxlength;
  98842. long lo,hi;
  98843. long lok = oggpack_look(b,book->dec_firsttablen);
  98844. if (lok >= 0) {
  98845. long entry = book->dec_firsttable[lok];
  98846. if(entry&0x80000000UL){
  98847. lo=(entry>>15)&0x7fff;
  98848. hi=book->used_entries-(entry&0x7fff);
  98849. }else{
  98850. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98851. return(entry-1);
  98852. }
  98853. }else{
  98854. lo=0;
  98855. hi=book->used_entries;
  98856. }
  98857. lok = oggpack_look(b, read);
  98858. while(lok<0 && read>1)
  98859. lok = oggpack_look(b, --read);
  98860. if(lok<0)return -1;
  98861. {
  98862. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98863. while(hi-lo>1){
  98864. long p=(hi-lo)>>1;
  98865. long test=book->codelist[lo+p]>testword;
  98866. lo+=p&(test-1);
  98867. hi-=p&(-test);
  98868. }
  98869. if(book->dec_codelengths[lo]<=read){
  98870. oggpack_adv(b, book->dec_codelengths[lo]);
  98871. return(lo);
  98872. }
  98873. }
  98874. oggpack_adv(b, read);
  98875. return(-1);
  98876. }
  98877. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98878. long packed_entry=decode_packed_entry_number(book,b);
  98879. if(packed_entry>=0)
  98880. return(book->dec_index[packed_entry]);
  98881. return(packed_entry);
  98882. }
  98883. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98884. int step=n/book->dim;
  98885. long *entry = (long*)alloca(sizeof(*entry)*step);
  98886. float **t = (float**)alloca(sizeof(*t)*step);
  98887. int i,j,o;
  98888. for (i = 0; i < step; i++) {
  98889. entry[i]=decode_packed_entry_number(book,b);
  98890. if(entry[i]==-1)return(-1);
  98891. t[i] = book->valuelist+entry[i]*book->dim;
  98892. }
  98893. for(i=0,o=0;i<book->dim;i++,o+=step)
  98894. for (j=0;j<step;j++)
  98895. a[o+j]+=t[j][i];
  98896. return(0);
  98897. }
  98898. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98899. int i,j,entry;
  98900. float *t;
  98901. if(book->dim>8){
  98902. for(i=0;i<n;){
  98903. entry = decode_packed_entry_number(book,b);
  98904. if(entry==-1)return(-1);
  98905. t = book->valuelist+entry*book->dim;
  98906. for (j=0;j<book->dim;)
  98907. a[i++]+=t[j++];
  98908. }
  98909. }else{
  98910. for(i=0;i<n;){
  98911. entry = decode_packed_entry_number(book,b);
  98912. if(entry==-1)return(-1);
  98913. t = book->valuelist+entry*book->dim;
  98914. j=0;
  98915. switch((int)book->dim){
  98916. case 8:
  98917. a[i++]+=t[j++];
  98918. case 7:
  98919. a[i++]+=t[j++];
  98920. case 6:
  98921. a[i++]+=t[j++];
  98922. case 5:
  98923. a[i++]+=t[j++];
  98924. case 4:
  98925. a[i++]+=t[j++];
  98926. case 3:
  98927. a[i++]+=t[j++];
  98928. case 2:
  98929. a[i++]+=t[j++];
  98930. case 1:
  98931. a[i++]+=t[j++];
  98932. case 0:
  98933. break;
  98934. }
  98935. }
  98936. }
  98937. return(0);
  98938. }
  98939. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98940. int i,j,entry;
  98941. float *t;
  98942. for(i=0;i<n;){
  98943. entry = decode_packed_entry_number(book,b);
  98944. if(entry==-1)return(-1);
  98945. t = book->valuelist+entry*book->dim;
  98946. for (j=0;j<book->dim;)
  98947. a[i++]=t[j++];
  98948. }
  98949. return(0);
  98950. }
  98951. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98952. oggpack_buffer *b,int n){
  98953. long i,j,entry;
  98954. int chptr=0;
  98955. for(i=offset/ch;i<(offset+n)/ch;){
  98956. entry = decode_packed_entry_number(book,b);
  98957. if(entry==-1)return(-1);
  98958. {
  98959. const float *t = book->valuelist+entry*book->dim;
  98960. for (j=0;j<book->dim;j++){
  98961. a[chptr++][i]+=t[j];
  98962. if(chptr==ch){
  98963. chptr=0;
  98964. i++;
  98965. }
  98966. }
  98967. }
  98968. }
  98969. return(0);
  98970. }
  98971. #ifdef _V_SELFTEST
  98972. #include <stdio.h>
  98973. #include "vorbis/book/lsp20_0.vqh"
  98974. #include "vorbis/book/res0a_13.vqh"
  98975. #define TESTSIZE 40
  98976. float test1[TESTSIZE]={
  98977. 0.105939f,
  98978. 0.215373f,
  98979. 0.429117f,
  98980. 0.587974f,
  98981. 0.181173f,
  98982. 0.296583f,
  98983. 0.515707f,
  98984. 0.715261f,
  98985. 0.162327f,
  98986. 0.263834f,
  98987. 0.342876f,
  98988. 0.406025f,
  98989. 0.103571f,
  98990. 0.223561f,
  98991. 0.368513f,
  98992. 0.540313f,
  98993. 0.136672f,
  98994. 0.395882f,
  98995. 0.587183f,
  98996. 0.652476f,
  98997. 0.114338f,
  98998. 0.417300f,
  98999. 0.525486f,
  99000. 0.698679f,
  99001. 0.147492f,
  99002. 0.324481f,
  99003. 0.643089f,
  99004. 0.757582f,
  99005. 0.139556f,
  99006. 0.215795f,
  99007. 0.324559f,
  99008. 0.399387f,
  99009. 0.120236f,
  99010. 0.267420f,
  99011. 0.446940f,
  99012. 0.608760f,
  99013. 0.115587f,
  99014. 0.287234f,
  99015. 0.571081f,
  99016. 0.708603f,
  99017. };
  99018. float test3[TESTSIZE]={
  99019. 0,1,-2,3,4,-5,6,7,8,9,
  99020. 8,-2,7,-1,4,6,8,3,1,-9,
  99021. 10,11,12,13,14,15,26,17,18,19,
  99022. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  99023. static_codebook *testlist[]={&_vq_book_lsp20_0,
  99024. &_vq_book_res0a_13,NULL};
  99025. float *testvec[]={test1,test3};
  99026. int main(){
  99027. oggpack_buffer write;
  99028. oggpack_buffer read;
  99029. long ptr=0,i;
  99030. oggpack_writeinit(&write);
  99031. fprintf(stderr,"Testing codebook abstraction...:\n");
  99032. while(testlist[ptr]){
  99033. codebook c;
  99034. static_codebook s;
  99035. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  99036. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  99037. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  99038. memset(iv,0,sizeof(*iv)*TESTSIZE);
  99039. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  99040. oggpack_reset(&write);
  99041. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  99042. we can write */
  99043. vorbis_staticbook_pack(testlist[ptr],&write);
  99044. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  99045. for(i=0;i<TESTSIZE;i+=c.dim){
  99046. int best=_best(&c,qv+i,1);
  99047. vorbis_book_encodev(&c,best,qv+i,&write);
  99048. }
  99049. vorbis_book_clear(&c);
  99050. fprintf(stderr,"OK.\n");
  99051. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  99052. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  99053. if(vorbis_staticbook_unpack(&read,&s)){
  99054. fprintf(stderr,"Error unpacking codebook.\n");
  99055. exit(1);
  99056. }
  99057. if(vorbis_book_init_decode(&c,&s)){
  99058. fprintf(stderr,"Error initializing codebook.\n");
  99059. exit(1);
  99060. }
  99061. for(i=0;i<TESTSIZE;i+=c.dim)
  99062. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  99063. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  99064. exit(1);
  99065. }
  99066. for(i=0;i<TESTSIZE;i++)
  99067. if(fabs(qv[i]-iv[i])>.000001){
  99068. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  99069. iv[i],qv[i],i);
  99070. exit(1);
  99071. }
  99072. fprintf(stderr,"OK\n");
  99073. ptr++;
  99074. }
  99075. exit(0);
  99076. }
  99077. #endif
  99078. #endif
  99079. /*** End of inlined file: codebook.c ***/
  99080. /*** Start of inlined file: envelope.c ***/
  99081. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99082. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99083. // tasks..
  99084. #if JUCE_MSVC
  99085. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99086. #endif
  99087. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99088. #if JUCE_USE_OGGVORBIS
  99089. #include <stdlib.h>
  99090. #include <string.h>
  99091. #include <stdio.h>
  99092. #include <math.h>
  99093. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  99094. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99095. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99096. int ch=vi->channels;
  99097. int i,j;
  99098. int n=e->winlength=128;
  99099. e->searchstep=64; /* not random */
  99100. e->minenergy=gi->preecho_minenergy;
  99101. e->ch=ch;
  99102. e->storage=128;
  99103. e->cursor=ci->blocksizes[1]/2;
  99104. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  99105. mdct_init(&e->mdct,n);
  99106. for(i=0;i<n;i++){
  99107. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  99108. e->mdct_win[i]*=e->mdct_win[i];
  99109. }
  99110. e->band[0].begin=2; e->band[0].end=4;
  99111. e->band[1].begin=4; e->band[1].end=5;
  99112. e->band[2].begin=6; e->band[2].end=6;
  99113. e->band[3].begin=9; e->band[3].end=8;
  99114. e->band[4].begin=13; e->band[4].end=8;
  99115. e->band[5].begin=17; e->band[5].end=8;
  99116. e->band[6].begin=22; e->band[6].end=8;
  99117. for(j=0;j<VE_BANDS;j++){
  99118. n=e->band[j].end;
  99119. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  99120. for(i=0;i<n;i++){
  99121. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  99122. e->band[j].total+=e->band[j].window[i];
  99123. }
  99124. e->band[j].total=1./e->band[j].total;
  99125. }
  99126. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  99127. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  99128. }
  99129. void _ve_envelope_clear(envelope_lookup *e){
  99130. int i;
  99131. mdct_clear(&e->mdct);
  99132. for(i=0;i<VE_BANDS;i++)
  99133. _ogg_free(e->band[i].window);
  99134. _ogg_free(e->mdct_win);
  99135. _ogg_free(e->filter);
  99136. _ogg_free(e->mark);
  99137. memset(e,0,sizeof(*e));
  99138. }
  99139. static int _ve_amp(envelope_lookup *ve,
  99140. vorbis_info_psy_global *gi,
  99141. float *data,
  99142. envelope_band *bands,
  99143. envelope_filter_state *filters,
  99144. long pos){
  99145. long n=ve->winlength;
  99146. int ret=0;
  99147. long i,j;
  99148. float decay;
  99149. float minV=ve->minenergy;
  99150. float *vec=(float*) alloca(n*sizeof(*vec));
  99151. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  99152. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  99153. if(penalty<0.f)penalty=0.f;
  99154. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  99155. for(i=0;i<n;i++)
  99156. vec[i]=data[i]*ve->mdct_win[i];
  99157. mdct_forward(&ve->mdct,vec,vec);
  99158. {
  99159. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  99160. int ptr=filters->nearptr;
  99161. if(ptr==0){
  99162. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  99163. filters->nearDC_partialacc=temp;
  99164. }else{
  99165. decay=filters->nearDC_acc+=temp;
  99166. filters->nearDC_partialacc+=temp;
  99167. }
  99168. filters->nearDC_acc-=filters->nearDC[ptr];
  99169. filters->nearDC[ptr]=temp;
  99170. decay*=(1./(VE_NEARDC+1));
  99171. filters->nearptr++;
  99172. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  99173. decay=todB(&decay)*.5-15.f;
  99174. }
  99175. for(i=0;i<n/2;i+=2){
  99176. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  99177. val=todB(&val)*.5f;
  99178. if(val<decay)val=decay;
  99179. if(val<minV)val=minV;
  99180. vec[i>>1]=val;
  99181. decay-=8.;
  99182. }
  99183. for(j=0;j<VE_BANDS;j++){
  99184. float acc=0.;
  99185. float valmax,valmin;
  99186. for(i=0;i<bands[j].end;i++)
  99187. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  99188. acc*=bands[j].total;
  99189. {
  99190. int p,thisx=filters[j].ampptr;
  99191. float postmax,postmin,premax=-99999.f,premin=99999.f;
  99192. p=thisx;
  99193. p--;
  99194. if(p<0)p+=VE_AMP;
  99195. postmax=max(acc,filters[j].ampbuf[p]);
  99196. postmin=min(acc,filters[j].ampbuf[p]);
  99197. for(i=0;i<stretch;i++){
  99198. p--;
  99199. if(p<0)p+=VE_AMP;
  99200. premax=max(premax,filters[j].ampbuf[p]);
  99201. premin=min(premin,filters[j].ampbuf[p]);
  99202. }
  99203. valmin=postmin-premin;
  99204. valmax=postmax-premax;
  99205. filters[j].ampbuf[thisx]=acc;
  99206. filters[j].ampptr++;
  99207. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  99208. }
  99209. if(valmax>gi->preecho_thresh[j]+penalty){
  99210. ret|=1;
  99211. ret|=4;
  99212. }
  99213. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  99214. }
  99215. return(ret);
  99216. }
  99217. #if 0
  99218. static int seq=0;
  99219. static ogg_int64_t totalshift=-1024;
  99220. #endif
  99221. long _ve_envelope_search(vorbis_dsp_state *v){
  99222. vorbis_info *vi=v->vi;
  99223. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  99224. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99225. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99226. long i,j;
  99227. int first=ve->current/ve->searchstep;
  99228. int last=v->pcm_current/ve->searchstep-VE_WIN;
  99229. if(first<0)first=0;
  99230. if(last+VE_WIN+VE_POST>ve->storage){
  99231. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  99232. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  99233. }
  99234. for(j=first;j<last;j++){
  99235. int ret=0;
  99236. ve->stretch++;
  99237. if(ve->stretch>VE_MAXSTRETCH*2)
  99238. ve->stretch=VE_MAXSTRETCH*2;
  99239. for(i=0;i<ve->ch;i++){
  99240. float *pcm=v->pcm[i]+ve->searchstep*(j);
  99241. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  99242. }
  99243. ve->mark[j+VE_POST]=0;
  99244. if(ret&1){
  99245. ve->mark[j]=1;
  99246. ve->mark[j+1]=1;
  99247. }
  99248. if(ret&2){
  99249. ve->mark[j]=1;
  99250. if(j>0)ve->mark[j-1]=1;
  99251. }
  99252. if(ret&4)ve->stretch=-1;
  99253. }
  99254. ve->current=last*ve->searchstep;
  99255. {
  99256. long centerW=v->centerW;
  99257. long testW=
  99258. centerW+
  99259. ci->blocksizes[v->W]/4+
  99260. ci->blocksizes[1]/2+
  99261. ci->blocksizes[0]/4;
  99262. j=ve->cursor;
  99263. while(j<ve->current-(ve->searchstep)){/* account for postecho
  99264. working back one window */
  99265. if(j>=testW)return(1);
  99266. ve->cursor=j;
  99267. if(ve->mark[j/ve->searchstep]){
  99268. if(j>centerW){
  99269. #if 0
  99270. if(j>ve->curmark){
  99271. float *marker=alloca(v->pcm_current*sizeof(*marker));
  99272. int l,m;
  99273. memset(marker,0,sizeof(*marker)*v->pcm_current);
  99274. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  99275. seq,
  99276. (totalshift+ve->cursor)/44100.,
  99277. (totalshift+j)/44100.);
  99278. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  99279. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  99280. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  99281. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  99282. for(m=0;m<VE_BANDS;m++){
  99283. char buf[80];
  99284. sprintf(buf,"delL%d",m);
  99285. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  99286. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99287. }
  99288. for(m=0;m<VE_BANDS;m++){
  99289. char buf[80];
  99290. sprintf(buf,"delR%d",m);
  99291. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  99292. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99293. }
  99294. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  99295. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  99296. seq++;
  99297. }
  99298. #endif
  99299. ve->curmark=j;
  99300. if(j>=testW)return(1);
  99301. return(0);
  99302. }
  99303. }
  99304. j+=ve->searchstep;
  99305. }
  99306. }
  99307. return(-1);
  99308. }
  99309. int _ve_envelope_mark(vorbis_dsp_state *v){
  99310. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99311. vorbis_info *vi=v->vi;
  99312. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99313. long centerW=v->centerW;
  99314. long beginW=centerW-ci->blocksizes[v->W]/4;
  99315. long endW=centerW+ci->blocksizes[v->W]/4;
  99316. if(v->W){
  99317. beginW-=ci->blocksizes[v->lW]/4;
  99318. endW+=ci->blocksizes[v->nW]/4;
  99319. }else{
  99320. beginW-=ci->blocksizes[0]/4;
  99321. endW+=ci->blocksizes[0]/4;
  99322. }
  99323. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99324. {
  99325. long first=beginW/ve->searchstep;
  99326. long last=endW/ve->searchstep;
  99327. long i;
  99328. for(i=first;i<last;i++)
  99329. if(ve->mark[i])return(1);
  99330. }
  99331. return(0);
  99332. }
  99333. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99334. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99335. ahead of ve->current */
  99336. int smallshift=shift/e->searchstep;
  99337. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99338. #if 0
  99339. for(i=0;i<VE_BANDS*e->ch;i++)
  99340. memmove(e->filter[i].markers,
  99341. e->filter[i].markers+smallshift,
  99342. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99343. totalshift+=shift;
  99344. #endif
  99345. e->current-=shift;
  99346. if(e->curmark>=0)
  99347. e->curmark-=shift;
  99348. e->cursor-=shift;
  99349. }
  99350. #endif
  99351. /*** End of inlined file: envelope.c ***/
  99352. /*** Start of inlined file: floor0.c ***/
  99353. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99354. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99355. // tasks..
  99356. #if JUCE_MSVC
  99357. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99358. #endif
  99359. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99360. #if JUCE_USE_OGGVORBIS
  99361. #include <stdlib.h>
  99362. #include <string.h>
  99363. #include <math.h>
  99364. /*** Start of inlined file: lsp.h ***/
  99365. #ifndef _V_LSP_H_
  99366. #define _V_LSP_H_
  99367. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99368. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99369. float *lsp,int m,
  99370. float amp,float ampoffset);
  99371. #endif
  99372. /*** End of inlined file: lsp.h ***/
  99373. #include <stdio.h>
  99374. typedef struct {
  99375. int ln;
  99376. int m;
  99377. int **linearmap;
  99378. int n[2];
  99379. vorbis_info_floor0 *vi;
  99380. long bits;
  99381. long frames;
  99382. } vorbis_look_floor0;
  99383. static void floor0_free_info(vorbis_info_floor *i){
  99384. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99385. if(info){
  99386. memset(info,0,sizeof(*info));
  99387. _ogg_free(info);
  99388. }
  99389. }
  99390. static void floor0_free_look(vorbis_look_floor *i){
  99391. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99392. if(look){
  99393. if(look->linearmap){
  99394. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99395. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99396. _ogg_free(look->linearmap);
  99397. }
  99398. memset(look,0,sizeof(*look));
  99399. _ogg_free(look);
  99400. }
  99401. }
  99402. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99403. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99404. int j;
  99405. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99406. info->order=oggpack_read(opb,8);
  99407. info->rate=oggpack_read(opb,16);
  99408. info->barkmap=oggpack_read(opb,16);
  99409. info->ampbits=oggpack_read(opb,6);
  99410. info->ampdB=oggpack_read(opb,8);
  99411. info->numbooks=oggpack_read(opb,4)+1;
  99412. if(info->order<1)goto err_out;
  99413. if(info->rate<1)goto err_out;
  99414. if(info->barkmap<1)goto err_out;
  99415. if(info->numbooks<1)goto err_out;
  99416. for(j=0;j<info->numbooks;j++){
  99417. info->books[j]=oggpack_read(opb,8);
  99418. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99419. }
  99420. return(info);
  99421. err_out:
  99422. floor0_free_info(info);
  99423. return(NULL);
  99424. }
  99425. static void floor0_map_lazy_init(vorbis_block *vb,
  99426. vorbis_info_floor *infoX,
  99427. vorbis_look_floor0 *look){
  99428. if(!look->linearmap[vb->W]){
  99429. vorbis_dsp_state *vd=vb->vd;
  99430. vorbis_info *vi=vd->vi;
  99431. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99432. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99433. int W=vb->W;
  99434. int n=ci->blocksizes[W]/2,j;
  99435. float scale=look->ln/toBARK(info->rate/2.f);
  99436. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99437. for(j=0;j<n;j++){
  99438. int val=floor( toBARK((info->rate/2.f)/n*j)
  99439. *scale); /* bark numbers represent band edges */
  99440. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99441. look->linearmap[W][j]=val;
  99442. }
  99443. look->linearmap[W][j]=-1;
  99444. look->n[W]=n;
  99445. }
  99446. }
  99447. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99448. vorbis_info_floor *i){
  99449. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99450. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99451. look->m=info->order;
  99452. look->ln=info->barkmap;
  99453. look->vi=info;
  99454. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99455. return look;
  99456. }
  99457. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99458. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99459. vorbis_info_floor0 *info=look->vi;
  99460. int j,k;
  99461. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99462. if(ampraw>0){ /* also handles the -1 out of data case */
  99463. long maxval=(1<<info->ampbits)-1;
  99464. float amp=(float)ampraw/maxval*info->ampdB;
  99465. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99466. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99467. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99468. codebook *b=ci->fullbooks+info->books[booknum];
  99469. float last=0.f;
  99470. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99471. for(j=0;j<look->m;j+=b->dim)
  99472. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99473. for(j=0;j<look->m;){
  99474. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99475. last=lsp[j-1];
  99476. }
  99477. lsp[look->m]=amp;
  99478. return(lsp);
  99479. }
  99480. }
  99481. eop:
  99482. return(NULL);
  99483. }
  99484. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99485. void *memo,float *out){
  99486. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99487. vorbis_info_floor0 *info=look->vi;
  99488. floor0_map_lazy_init(vb,info,look);
  99489. if(memo){
  99490. float *lsp=(float *)memo;
  99491. float amp=lsp[look->m];
  99492. vorbis_lsp_to_curve(out,
  99493. look->linearmap[vb->W],
  99494. look->n[vb->W],
  99495. look->ln,
  99496. lsp,look->m,amp,(float)info->ampdB);
  99497. return(1);
  99498. }
  99499. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99500. return(0);
  99501. }
  99502. vorbis_func_floor floor0_exportbundle={
  99503. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99504. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99505. };
  99506. #endif
  99507. /*** End of inlined file: floor0.c ***/
  99508. /*** Start of inlined file: floor1.c ***/
  99509. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99510. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99511. // tasks..
  99512. #if JUCE_MSVC
  99513. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99514. #endif
  99515. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99516. #if JUCE_USE_OGGVORBIS
  99517. #include <stdlib.h>
  99518. #include <string.h>
  99519. #include <math.h>
  99520. #include <stdio.h>
  99521. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99522. typedef struct {
  99523. int sorted_index[VIF_POSIT+2];
  99524. int forward_index[VIF_POSIT+2];
  99525. int reverse_index[VIF_POSIT+2];
  99526. int hineighbor[VIF_POSIT];
  99527. int loneighbor[VIF_POSIT];
  99528. int posts;
  99529. int n;
  99530. int quant_q;
  99531. vorbis_info_floor1 *vi;
  99532. long phrasebits;
  99533. long postbits;
  99534. long frames;
  99535. } vorbis_look_floor1;
  99536. typedef struct lsfit_acc{
  99537. long x0;
  99538. long x1;
  99539. long xa;
  99540. long ya;
  99541. long x2a;
  99542. long y2a;
  99543. long xya;
  99544. long an;
  99545. } lsfit_acc;
  99546. static void floor1_free_info(vorbis_info_floor *i){
  99547. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99548. if(info){
  99549. memset(info,0,sizeof(*info));
  99550. _ogg_free(info);
  99551. }
  99552. }
  99553. static void floor1_free_look(vorbis_look_floor *i){
  99554. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99555. if(look){
  99556. memset(look,0,sizeof(*look));
  99557. _ogg_free(look);
  99558. }
  99559. }
  99560. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99561. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99562. int j,k;
  99563. int count=0;
  99564. int rangebits;
  99565. int maxposit=info->postlist[1];
  99566. int maxclass=-1;
  99567. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99568. for(j=0;j<info->partitions;j++){
  99569. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99570. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99571. }
  99572. for(j=0;j<maxclass+1;j++){
  99573. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99574. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99575. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99576. for(k=0;k<(1<<info->class_subs[j]);k++)
  99577. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99578. }
  99579. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99580. oggpack_write(opb,ilog2(maxposit),4);
  99581. rangebits=ilog2(maxposit);
  99582. for(j=0,k=0;j<info->partitions;j++){
  99583. count+=info->class_dim[info->partitionclass[j]];
  99584. for(;k<count;k++)
  99585. oggpack_write(opb,info->postlist[k+2],rangebits);
  99586. }
  99587. }
  99588. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99589. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99590. int j,k,count=0,maxclass=-1,rangebits;
  99591. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99592. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99593. for(j=0;j<info->partitions;j++){
  99594. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99595. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99596. }
  99597. for(j=0;j<maxclass+1;j++){
  99598. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99599. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99600. if(info->class_subs[j]<0)
  99601. goto err_out;
  99602. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99603. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99604. goto err_out;
  99605. for(k=0;k<(1<<info->class_subs[j]);k++){
  99606. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99607. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99608. goto err_out;
  99609. }
  99610. }
  99611. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99612. rangebits=oggpack_read(opb,4);
  99613. for(j=0,k=0;j<info->partitions;j++){
  99614. count+=info->class_dim[info->partitionclass[j]];
  99615. for(;k<count;k++){
  99616. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99617. if(t<0 || t>=(1<<rangebits))
  99618. goto err_out;
  99619. }
  99620. }
  99621. info->postlist[0]=0;
  99622. info->postlist[1]=1<<rangebits;
  99623. return(info);
  99624. err_out:
  99625. floor1_free_info(info);
  99626. return(NULL);
  99627. }
  99628. static int icomp(const void *a,const void *b){
  99629. return(**(int **)a-**(int **)b);
  99630. }
  99631. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99632. vorbis_info_floor *in){
  99633. int *sortpointer[VIF_POSIT+2];
  99634. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99635. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99636. int i,j,n=0;
  99637. look->vi=info;
  99638. look->n=info->postlist[1];
  99639. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99640. n+=2;
  99641. look->posts=n;
  99642. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99643. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99644. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99645. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99646. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99647. switch(info->mult){
  99648. case 1: /* 1024 -> 256 */
  99649. look->quant_q=256;
  99650. break;
  99651. case 2: /* 1024 -> 128 */
  99652. look->quant_q=128;
  99653. break;
  99654. case 3: /* 1024 -> 86 */
  99655. look->quant_q=86;
  99656. break;
  99657. case 4: /* 1024 -> 64 */
  99658. look->quant_q=64;
  99659. break;
  99660. }
  99661. for(i=0;i<n-2;i++){
  99662. int lo=0;
  99663. int hi=1;
  99664. int lx=0;
  99665. int hx=look->n;
  99666. int currentx=info->postlist[i+2];
  99667. for(j=0;j<i+2;j++){
  99668. int x=info->postlist[j];
  99669. if(x>lx && x<currentx){
  99670. lo=j;
  99671. lx=x;
  99672. }
  99673. if(x<hx && x>currentx){
  99674. hi=j;
  99675. hx=x;
  99676. }
  99677. }
  99678. look->loneighbor[i]=lo;
  99679. look->hineighbor[i]=hi;
  99680. }
  99681. return(look);
  99682. }
  99683. static int render_point(int x0,int x1,int y0,int y1,int x){
  99684. y0&=0x7fff; /* mask off flag */
  99685. y1&=0x7fff;
  99686. {
  99687. int dy=y1-y0;
  99688. int adx=x1-x0;
  99689. int ady=abs(dy);
  99690. int err=ady*(x-x0);
  99691. int off=err/adx;
  99692. if(dy<0)return(y0-off);
  99693. return(y0+off);
  99694. }
  99695. }
  99696. static int vorbis_dBquant(const float *x){
  99697. int i= *x*7.3142857f+1023.5f;
  99698. if(i>1023)return(1023);
  99699. if(i<0)return(0);
  99700. return i;
  99701. }
  99702. static float FLOOR1_fromdB_LOOKUP[256]={
  99703. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99704. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99705. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99706. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99707. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99708. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99709. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99710. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99711. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99712. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99713. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99714. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99715. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99716. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99717. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99718. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99719. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99720. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99721. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99722. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99723. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99724. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99725. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99726. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99727. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99728. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99729. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99730. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99731. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99732. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99733. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99734. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99735. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99736. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99737. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99738. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99739. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99740. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99741. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99742. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99743. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99744. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99745. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99746. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99747. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99748. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99749. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99750. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99751. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99752. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99753. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99754. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99755. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99756. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99757. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99758. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99759. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99760. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99761. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99762. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99763. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99764. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99765. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99766. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99767. };
  99768. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99769. int dy=y1-y0;
  99770. int adx=x1-x0;
  99771. int ady=abs(dy);
  99772. int base=dy/adx;
  99773. int sy=(dy<0?base-1:base+1);
  99774. int x=x0;
  99775. int y=y0;
  99776. int err=0;
  99777. ady-=abs(base*adx);
  99778. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99779. while(++x<x1){
  99780. err=err+ady;
  99781. if(err>=adx){
  99782. err-=adx;
  99783. y+=sy;
  99784. }else{
  99785. y+=base;
  99786. }
  99787. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99788. }
  99789. }
  99790. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99791. int dy=y1-y0;
  99792. int adx=x1-x0;
  99793. int ady=abs(dy);
  99794. int base=dy/adx;
  99795. int sy=(dy<0?base-1:base+1);
  99796. int x=x0;
  99797. int y=y0;
  99798. int err=0;
  99799. ady-=abs(base*adx);
  99800. d[x]=y;
  99801. while(++x<x1){
  99802. err=err+ady;
  99803. if(err>=adx){
  99804. err-=adx;
  99805. y+=sy;
  99806. }else{
  99807. y+=base;
  99808. }
  99809. d[x]=y;
  99810. }
  99811. }
  99812. static int accumulate_fit(const float *flr,const float *mdct,
  99813. int x0, int x1,lsfit_acc *a,
  99814. int n,vorbis_info_floor1 *info){
  99815. long i;
  99816. 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;
  99817. memset(a,0,sizeof(*a));
  99818. a->x0=x0;
  99819. a->x1=x1;
  99820. if(x1>=n)x1=n-1;
  99821. for(i=x0;i<=x1;i++){
  99822. int quantized=vorbis_dBquant(flr+i);
  99823. if(quantized){
  99824. if(mdct[i]+info->twofitatten>=flr[i]){
  99825. xa += i;
  99826. ya += quantized;
  99827. x2a += i*i;
  99828. y2a += quantized*quantized;
  99829. xya += i*quantized;
  99830. na++;
  99831. }else{
  99832. xb += i;
  99833. yb += quantized;
  99834. x2b += i*i;
  99835. y2b += quantized*quantized;
  99836. xyb += i*quantized;
  99837. nb++;
  99838. }
  99839. }
  99840. }
  99841. xb+=xa;
  99842. yb+=ya;
  99843. x2b+=x2a;
  99844. y2b+=y2a;
  99845. xyb+=xya;
  99846. nb+=na;
  99847. {
  99848. int weight=nb*info->twofitweight/(na+1);
  99849. a->xa=xa*weight+xb;
  99850. a->ya=ya*weight+yb;
  99851. a->x2a=x2a*weight+x2b;
  99852. a->y2a=y2a*weight+y2b;
  99853. a->xya=xya*weight+xyb;
  99854. a->an=na*weight+nb;
  99855. }
  99856. return(na);
  99857. }
  99858. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99859. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99860. long x0=a[0].x0;
  99861. long x1=a[fits-1].x1;
  99862. for(i=0;i<fits;i++){
  99863. x+=a[i].xa;
  99864. y+=a[i].ya;
  99865. x2+=a[i].x2a;
  99866. y2+=a[i].y2a;
  99867. xy+=a[i].xya;
  99868. an+=a[i].an;
  99869. }
  99870. if(*y0>=0){
  99871. x+= x0;
  99872. y+= *y0;
  99873. x2+= x0 * x0;
  99874. y2+= *y0 * *y0;
  99875. xy+= *y0 * x0;
  99876. an++;
  99877. }
  99878. if(*y1>=0){
  99879. x+= x1;
  99880. y+= *y1;
  99881. x2+= x1 * x1;
  99882. y2+= *y1 * *y1;
  99883. xy+= *y1 * x1;
  99884. an++;
  99885. }
  99886. if(an){
  99887. double fx=x;
  99888. double fy=y;
  99889. double fx2=x2;
  99890. double fxy=xy;
  99891. double denom=1./(an*fx2-fx*fx);
  99892. double a=(fy*fx2-fxy*fx)*denom;
  99893. double b=(an*fxy-fx*fy)*denom;
  99894. *y0=rint(a+b*x0);
  99895. *y1=rint(a+b*x1);
  99896. if(*y0>1023)*y0=1023;
  99897. if(*y1>1023)*y1=1023;
  99898. if(*y0<0)*y0=0;
  99899. if(*y1<0)*y1=0;
  99900. }else{
  99901. *y0=0;
  99902. *y1=0;
  99903. }
  99904. }
  99905. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99906. const float *mdct,
  99907. vorbis_info_floor1 *info){
  99908. int dy=y1-y0;
  99909. int adx=x1-x0;
  99910. int ady=abs(dy);
  99911. int base=dy/adx;
  99912. int sy=(dy<0?base-1:base+1);
  99913. int x=x0;
  99914. int y=y0;
  99915. int err=0;
  99916. int val=vorbis_dBquant(mask+x);
  99917. int mse=0;
  99918. int n=0;
  99919. ady-=abs(base*adx);
  99920. mse=(y-val);
  99921. mse*=mse;
  99922. n++;
  99923. if(mdct[x]+info->twofitatten>=mask[x]){
  99924. if(y+info->maxover<val)return(1);
  99925. if(y-info->maxunder>val)return(1);
  99926. }
  99927. while(++x<x1){
  99928. err=err+ady;
  99929. if(err>=adx){
  99930. err-=adx;
  99931. y+=sy;
  99932. }else{
  99933. y+=base;
  99934. }
  99935. val=vorbis_dBquant(mask+x);
  99936. mse+=((y-val)*(y-val));
  99937. n++;
  99938. if(mdct[x]+info->twofitatten>=mask[x]){
  99939. if(val){
  99940. if(y+info->maxover<val)return(1);
  99941. if(y-info->maxunder>val)return(1);
  99942. }
  99943. }
  99944. }
  99945. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99946. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99947. if(mse/n>info->maxerr)return(1);
  99948. return(0);
  99949. }
  99950. static int post_Y(int *A,int *B,int pos){
  99951. if(A[pos]<0)
  99952. return B[pos];
  99953. if(B[pos]<0)
  99954. return A[pos];
  99955. return (A[pos]+B[pos])>>1;
  99956. }
  99957. int *floor1_fit(vorbis_block *vb,void *look_,
  99958. const float *logmdct, /* in */
  99959. const float *logmask){
  99960. long i,j;
  99961. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99962. vorbis_info_floor1 *info=look->vi;
  99963. long n=look->n;
  99964. long posts=look->posts;
  99965. long nonzero=0;
  99966. lsfit_acc fits[VIF_POSIT+1];
  99967. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99968. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99969. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99970. int hineighbor[VIF_POSIT+2];
  99971. int *output=NULL;
  99972. int memo[VIF_POSIT+2];
  99973. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99974. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99975. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99976. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99977. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99978. if(posts==0){
  99979. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99980. }else{
  99981. for(i=0;i<posts-1;i++)
  99982. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99983. look->sorted_index[i+1],fits+i,
  99984. n,info);
  99985. }
  99986. if(nonzero){
  99987. int y0=-200;
  99988. int y1=-200;
  99989. fit_line(fits,posts-1,&y0,&y1);
  99990. fit_valueA[0]=y0;
  99991. fit_valueB[0]=y0;
  99992. fit_valueB[1]=y1;
  99993. fit_valueA[1]=y1;
  99994. for(i=2;i<posts;i++){
  99995. int sortpos=look->reverse_index[i];
  99996. int ln=loneighbor[sortpos];
  99997. int hn=hineighbor[sortpos];
  99998. if(memo[ln]!=hn){
  99999. int lsortpos=look->reverse_index[ln];
  100000. int hsortpos=look->reverse_index[hn];
  100001. memo[ln]=hn;
  100002. {
  100003. int lx=info->postlist[ln];
  100004. int hx=info->postlist[hn];
  100005. int ly=post_Y(fit_valueA,fit_valueB,ln);
  100006. int hy=post_Y(fit_valueA,fit_valueB,hn);
  100007. if(ly==-1 || hy==-1){
  100008. exit(1);
  100009. }
  100010. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  100011. int ly0=-200;
  100012. int ly1=-200;
  100013. int hy0=-200;
  100014. int hy1=-200;
  100015. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  100016. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  100017. fit_valueB[ln]=ly0;
  100018. if(ln==0)fit_valueA[ln]=ly0;
  100019. fit_valueA[i]=ly1;
  100020. fit_valueB[i]=hy0;
  100021. fit_valueA[hn]=hy1;
  100022. if(hn==1)fit_valueB[hn]=hy1;
  100023. if(ly1>=0 || hy0>=0){
  100024. for(j=sortpos-1;j>=0;j--)
  100025. if(hineighbor[j]==hn)
  100026. hineighbor[j]=i;
  100027. else
  100028. break;
  100029. for(j=sortpos+1;j<posts;j++)
  100030. if(loneighbor[j]==ln)
  100031. loneighbor[j]=i;
  100032. else
  100033. break;
  100034. }
  100035. }else{
  100036. fit_valueA[i]=-200;
  100037. fit_valueB[i]=-200;
  100038. }
  100039. }
  100040. }
  100041. }
  100042. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100043. output[0]=post_Y(fit_valueA,fit_valueB,0);
  100044. output[1]=post_Y(fit_valueA,fit_valueB,1);
  100045. for(i=2;i<posts;i++){
  100046. int ln=look->loneighbor[i-2];
  100047. int hn=look->hineighbor[i-2];
  100048. int x0=info->postlist[ln];
  100049. int x1=info->postlist[hn];
  100050. int y0=output[ln];
  100051. int y1=output[hn];
  100052. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100053. int vx=post_Y(fit_valueA,fit_valueB,i);
  100054. if(vx>=0 && predicted!=vx){
  100055. output[i]=vx;
  100056. }else{
  100057. output[i]= predicted|0x8000;
  100058. }
  100059. }
  100060. }
  100061. return(output);
  100062. }
  100063. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  100064. int *A,int *B,
  100065. int del){
  100066. long i;
  100067. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  100068. long posts=look->posts;
  100069. int *output=NULL;
  100070. if(A && B){
  100071. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100072. for(i=0;i<posts;i++){
  100073. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  100074. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  100075. }
  100076. }
  100077. return(output);
  100078. }
  100079. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  100080. void*look_,
  100081. int *post,int *ilogmask){
  100082. long i,j;
  100083. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  100084. vorbis_info_floor1 *info=look->vi;
  100085. long posts=look->posts;
  100086. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100087. int out[VIF_POSIT+2];
  100088. static_codebook **sbooks=ci->book_param;
  100089. codebook *books=ci->fullbooks;
  100090. static long seq=0;
  100091. if(post){
  100092. for(i=0;i<posts;i++){
  100093. int val=post[i]&0x7fff;
  100094. switch(info->mult){
  100095. case 1: /* 1024 -> 256 */
  100096. val>>=2;
  100097. break;
  100098. case 2: /* 1024 -> 128 */
  100099. val>>=3;
  100100. break;
  100101. case 3: /* 1024 -> 86 */
  100102. val/=12;
  100103. break;
  100104. case 4: /* 1024 -> 64 */
  100105. val>>=4;
  100106. break;
  100107. }
  100108. post[i]=val | (post[i]&0x8000);
  100109. }
  100110. out[0]=post[0];
  100111. out[1]=post[1];
  100112. for(i=2;i<posts;i++){
  100113. int ln=look->loneighbor[i-2];
  100114. int hn=look->hineighbor[i-2];
  100115. int x0=info->postlist[ln];
  100116. int x1=info->postlist[hn];
  100117. int y0=post[ln];
  100118. int y1=post[hn];
  100119. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100120. if((post[i]&0x8000) || (predicted==post[i])){
  100121. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  100122. in interpolation */
  100123. out[i]=0;
  100124. }else{
  100125. int headroom=(look->quant_q-predicted<predicted?
  100126. look->quant_q-predicted:predicted);
  100127. int val=post[i]-predicted;
  100128. if(val<0)
  100129. if(val<-headroom)
  100130. val=headroom-val-1;
  100131. else
  100132. val=-1-(val<<1);
  100133. else
  100134. if(val>=headroom)
  100135. val= val+headroom;
  100136. else
  100137. val<<=1;
  100138. out[i]=val;
  100139. post[ln]&=0x7fff;
  100140. post[hn]&=0x7fff;
  100141. }
  100142. }
  100143. oggpack_write(opb,1,1);
  100144. look->frames++;
  100145. look->postbits+=ilog(look->quant_q-1)*2;
  100146. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  100147. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  100148. for(i=0,j=2;i<info->partitions;i++){
  100149. int classx=info->partitionclass[i];
  100150. int cdim=info->class_dim[classx];
  100151. int csubbits=info->class_subs[classx];
  100152. int csub=1<<csubbits;
  100153. int bookas[8]={0,0,0,0,0,0,0,0};
  100154. int cval=0;
  100155. int cshift=0;
  100156. int k,l;
  100157. if(csubbits){
  100158. int maxval[8];
  100159. for(k=0;k<csub;k++){
  100160. int booknum=info->class_subbook[classx][k];
  100161. if(booknum<0){
  100162. maxval[k]=1;
  100163. }else{
  100164. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  100165. }
  100166. }
  100167. for(k=0;k<cdim;k++){
  100168. for(l=0;l<csub;l++){
  100169. int val=out[j+k];
  100170. if(val<maxval[l]){
  100171. bookas[k]=l;
  100172. break;
  100173. }
  100174. }
  100175. cval|= bookas[k]<<cshift;
  100176. cshift+=csubbits;
  100177. }
  100178. look->phrasebits+=
  100179. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  100180. #ifdef TRAIN_FLOOR1
  100181. {
  100182. FILE *of;
  100183. char buffer[80];
  100184. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  100185. vb->pcmend/2,posts-2,class);
  100186. of=fopen(buffer,"a");
  100187. fprintf(of,"%d\n",cval);
  100188. fclose(of);
  100189. }
  100190. #endif
  100191. }
  100192. for(k=0;k<cdim;k++){
  100193. int book=info->class_subbook[classx][bookas[k]];
  100194. if(book>=0){
  100195. if(out[j+k]<(books+book)->entries)
  100196. look->postbits+=vorbis_book_encode(books+book,
  100197. out[j+k],opb);
  100198. #ifdef TRAIN_FLOOR1
  100199. {
  100200. FILE *of;
  100201. char buffer[80];
  100202. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  100203. vb->pcmend/2,posts-2,class,bookas[k]);
  100204. of=fopen(buffer,"a");
  100205. fprintf(of,"%d\n",out[j+k]);
  100206. fclose(of);
  100207. }
  100208. #endif
  100209. }
  100210. }
  100211. j+=cdim;
  100212. }
  100213. {
  100214. int hx=0;
  100215. int lx=0;
  100216. int ly=post[0]*info->mult;
  100217. for(j=1;j<look->posts;j++){
  100218. int current=look->forward_index[j];
  100219. int hy=post[current]&0x7fff;
  100220. if(hy==post[current]){
  100221. hy*=info->mult;
  100222. hx=info->postlist[current];
  100223. render_line0(lx,hx,ly,hy,ilogmask);
  100224. lx=hx;
  100225. ly=hy;
  100226. }
  100227. }
  100228. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  100229. seq++;
  100230. return(1);
  100231. }
  100232. }else{
  100233. oggpack_write(opb,0,1);
  100234. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  100235. seq++;
  100236. return(0);
  100237. }
  100238. }
  100239. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  100240. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100241. vorbis_info_floor1 *info=look->vi;
  100242. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100243. int i,j,k;
  100244. codebook *books=ci->fullbooks;
  100245. if(oggpack_read(&vb->opb,1)==1){
  100246. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  100247. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100248. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100249. for(i=0,j=2;i<info->partitions;i++){
  100250. int classx=info->partitionclass[i];
  100251. int cdim=info->class_dim[classx];
  100252. int csubbits=info->class_subs[classx];
  100253. int csub=1<<csubbits;
  100254. int cval=0;
  100255. if(csubbits){
  100256. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  100257. if(cval==-1)goto eop;
  100258. }
  100259. for(k=0;k<cdim;k++){
  100260. int book=info->class_subbook[classx][cval&(csub-1)];
  100261. cval>>=csubbits;
  100262. if(book>=0){
  100263. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  100264. goto eop;
  100265. }else{
  100266. fit_value[j+k]=0;
  100267. }
  100268. }
  100269. j+=cdim;
  100270. }
  100271. for(i=2;i<look->posts;i++){
  100272. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  100273. info->postlist[look->hineighbor[i-2]],
  100274. fit_value[look->loneighbor[i-2]],
  100275. fit_value[look->hineighbor[i-2]],
  100276. info->postlist[i]);
  100277. int hiroom=look->quant_q-predicted;
  100278. int loroom=predicted;
  100279. int room=(hiroom<loroom?hiroom:loroom)<<1;
  100280. int val=fit_value[i];
  100281. if(val){
  100282. if(val>=room){
  100283. if(hiroom>loroom){
  100284. val = val-loroom;
  100285. }else{
  100286. val = -1-(val-hiroom);
  100287. }
  100288. }else{
  100289. if(val&1){
  100290. val= -((val+1)>>1);
  100291. }else{
  100292. val>>=1;
  100293. }
  100294. }
  100295. fit_value[i]=val+predicted;
  100296. fit_value[look->loneighbor[i-2]]&=0x7fff;
  100297. fit_value[look->hineighbor[i-2]]&=0x7fff;
  100298. }else{
  100299. fit_value[i]=predicted|0x8000;
  100300. }
  100301. }
  100302. return(fit_value);
  100303. }
  100304. eop:
  100305. return(NULL);
  100306. }
  100307. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100308. float *out){
  100309. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100310. vorbis_info_floor1 *info=look->vi;
  100311. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100312. int n=ci->blocksizes[vb->W]/2;
  100313. int j;
  100314. if(memo){
  100315. int *fit_value=(int *)memo;
  100316. int hx=0;
  100317. int lx=0;
  100318. int ly=fit_value[0]*info->mult;
  100319. for(j=1;j<look->posts;j++){
  100320. int current=look->forward_index[j];
  100321. int hy=fit_value[current]&0x7fff;
  100322. if(hy==fit_value[current]){
  100323. hy*=info->mult;
  100324. hx=info->postlist[current];
  100325. render_line(lx,hx,ly,hy,out);
  100326. lx=hx;
  100327. ly=hy;
  100328. }
  100329. }
  100330. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100331. return(1);
  100332. }
  100333. memset(out,0,sizeof(*out)*n);
  100334. return(0);
  100335. }
  100336. vorbis_func_floor floor1_exportbundle={
  100337. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100338. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100339. };
  100340. #endif
  100341. /*** End of inlined file: floor1.c ***/
  100342. /*** Start of inlined file: info.c ***/
  100343. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100344. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100345. // tasks..
  100346. #if JUCE_MSVC
  100347. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100348. #endif
  100349. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100350. #if JUCE_USE_OGGVORBIS
  100351. #include <stdlib.h>
  100352. #include <string.h>
  100353. #include <ctype.h>
  100354. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100355. while(bytes--){
  100356. oggpack_write(o,*s++,8);
  100357. }
  100358. }
  100359. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100360. while(bytes--){
  100361. *buf++=oggpack_read(o,8);
  100362. }
  100363. }
  100364. void vorbis_comment_init(vorbis_comment *vc){
  100365. memset(vc,0,sizeof(*vc));
  100366. }
  100367. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100368. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100369. (vc->comments+2)*sizeof(*vc->user_comments));
  100370. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100371. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100372. vc->comment_lengths[vc->comments]=strlen(comment);
  100373. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100374. strcpy(vc->user_comments[vc->comments], comment);
  100375. vc->comments++;
  100376. vc->user_comments[vc->comments]=NULL;
  100377. }
  100378. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100379. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100380. strcpy(comment, tag);
  100381. strcat(comment, "=");
  100382. strcat(comment, contents);
  100383. vorbis_comment_add(vc, comment);
  100384. }
  100385. static int tagcompare(const char *s1, const char *s2, int n){
  100386. int c=0;
  100387. while(c < n){
  100388. if(toupper(s1[c]) != toupper(s2[c]))
  100389. return !0;
  100390. c++;
  100391. }
  100392. return 0;
  100393. }
  100394. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100395. long i;
  100396. int found = 0;
  100397. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100398. char *fulltag = (char*)alloca(taglen+ 1);
  100399. strcpy(fulltag, tag);
  100400. strcat(fulltag, "=");
  100401. for(i=0;i<vc->comments;i++){
  100402. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100403. if(count == found)
  100404. return vc->user_comments[i] + taglen;
  100405. else
  100406. found++;
  100407. }
  100408. }
  100409. return NULL; /* didn't find anything */
  100410. }
  100411. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100412. int i,count=0;
  100413. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100414. char *fulltag = (char*)alloca(taglen+1);
  100415. strcpy(fulltag,tag);
  100416. strcat(fulltag, "=");
  100417. for(i=0;i<vc->comments;i++){
  100418. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100419. count++;
  100420. }
  100421. return count;
  100422. }
  100423. void vorbis_comment_clear(vorbis_comment *vc){
  100424. if(vc){
  100425. long i;
  100426. for(i=0;i<vc->comments;i++)
  100427. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100428. if(vc->user_comments)_ogg_free(vc->user_comments);
  100429. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100430. if(vc->vendor)_ogg_free(vc->vendor);
  100431. }
  100432. memset(vc,0,sizeof(*vc));
  100433. }
  100434. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100435. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100436. return ci ? ci->blocksizes[zo] : -1;
  100437. }
  100438. void vorbis_info_init(vorbis_info *vi){
  100439. memset(vi,0,sizeof(*vi));
  100440. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100441. }
  100442. void vorbis_info_clear(vorbis_info *vi){
  100443. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100444. int i;
  100445. if(ci){
  100446. for(i=0;i<ci->modes;i++)
  100447. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100448. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100449. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100450. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100451. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100452. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100453. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100454. for(i=0;i<ci->books;i++){
  100455. if(ci->book_param[i]){
  100456. vorbis_staticbook_destroy(ci->book_param[i]);
  100457. }
  100458. if(ci->fullbooks)
  100459. vorbis_book_clear(ci->fullbooks+i);
  100460. }
  100461. if(ci->fullbooks)
  100462. _ogg_free(ci->fullbooks);
  100463. for(i=0;i<ci->psys;i++)
  100464. _vi_psy_free(ci->psy_param[i]);
  100465. _ogg_free(ci);
  100466. }
  100467. memset(vi,0,sizeof(*vi));
  100468. }
  100469. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100470. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100471. if(!ci)return(OV_EFAULT);
  100472. vi->version=oggpack_read(opb,32);
  100473. if(vi->version!=0)return(OV_EVERSION);
  100474. vi->channels=oggpack_read(opb,8);
  100475. vi->rate=oggpack_read(opb,32);
  100476. vi->bitrate_upper=oggpack_read(opb,32);
  100477. vi->bitrate_nominal=oggpack_read(opb,32);
  100478. vi->bitrate_lower=oggpack_read(opb,32);
  100479. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100480. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100481. if(vi->rate<1)goto err_out;
  100482. if(vi->channels<1)goto err_out;
  100483. if(ci->blocksizes[0]<8)goto err_out;
  100484. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100485. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100486. return(0);
  100487. err_out:
  100488. vorbis_info_clear(vi);
  100489. return(OV_EBADHEADER);
  100490. }
  100491. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100492. int i;
  100493. int vendorlen=oggpack_read(opb,32);
  100494. if(vendorlen<0)goto err_out;
  100495. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100496. _v_readstring(opb,vc->vendor,vendorlen);
  100497. vc->comments=oggpack_read(opb,32);
  100498. if(vc->comments<0)goto err_out;
  100499. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100500. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100501. for(i=0;i<vc->comments;i++){
  100502. int len=oggpack_read(opb,32);
  100503. if(len<0)goto err_out;
  100504. vc->comment_lengths[i]=len;
  100505. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100506. _v_readstring(opb,vc->user_comments[i],len);
  100507. }
  100508. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100509. return(0);
  100510. err_out:
  100511. vorbis_comment_clear(vc);
  100512. return(OV_EBADHEADER);
  100513. }
  100514. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100515. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100516. int i;
  100517. if(!ci)return(OV_EFAULT);
  100518. ci->books=oggpack_read(opb,8)+1;
  100519. for(i=0;i<ci->books;i++){
  100520. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100521. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100522. }
  100523. {
  100524. int times=oggpack_read(opb,6)+1;
  100525. for(i=0;i<times;i++){
  100526. int test=oggpack_read(opb,16);
  100527. if(test<0 || test>=VI_TIMEB)goto err_out;
  100528. }
  100529. }
  100530. ci->floors=oggpack_read(opb,6)+1;
  100531. for(i=0;i<ci->floors;i++){
  100532. ci->floor_type[i]=oggpack_read(opb,16);
  100533. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100534. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100535. if(!ci->floor_param[i])goto err_out;
  100536. }
  100537. ci->residues=oggpack_read(opb,6)+1;
  100538. for(i=0;i<ci->residues;i++){
  100539. ci->residue_type[i]=oggpack_read(opb,16);
  100540. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100541. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100542. if(!ci->residue_param[i])goto err_out;
  100543. }
  100544. ci->maps=oggpack_read(opb,6)+1;
  100545. for(i=0;i<ci->maps;i++){
  100546. ci->map_type[i]=oggpack_read(opb,16);
  100547. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100548. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100549. if(!ci->map_param[i])goto err_out;
  100550. }
  100551. ci->modes=oggpack_read(opb,6)+1;
  100552. for(i=0;i<ci->modes;i++){
  100553. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100554. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100555. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100556. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100557. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100558. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100559. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100560. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100561. }
  100562. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100563. return(0);
  100564. err_out:
  100565. vorbis_info_clear(vi);
  100566. return(OV_EBADHEADER);
  100567. }
  100568. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100569. oggpack_buffer opb;
  100570. if(op){
  100571. oggpack_readinit(&opb,op->packet,op->bytes);
  100572. {
  100573. char buffer[6];
  100574. int packtype=oggpack_read(&opb,8);
  100575. memset(buffer,0,6);
  100576. _v_readstring(&opb,buffer,6);
  100577. if(memcmp(buffer,"vorbis",6)){
  100578. return(OV_ENOTVORBIS);
  100579. }
  100580. switch(packtype){
  100581. case 0x01: /* least significant *bit* is read first */
  100582. if(!op->b_o_s){
  100583. return(OV_EBADHEADER);
  100584. }
  100585. if(vi->rate!=0){
  100586. return(OV_EBADHEADER);
  100587. }
  100588. return(_vorbis_unpack_info(vi,&opb));
  100589. case 0x03: /* least significant *bit* is read first */
  100590. if(vi->rate==0){
  100591. return(OV_EBADHEADER);
  100592. }
  100593. return(_vorbis_unpack_comment(vc,&opb));
  100594. case 0x05: /* least significant *bit* is read first */
  100595. if(vi->rate==0 || vc->vendor==NULL){
  100596. return(OV_EBADHEADER);
  100597. }
  100598. return(_vorbis_unpack_books(vi,&opb));
  100599. default:
  100600. return(OV_EBADHEADER);
  100601. break;
  100602. }
  100603. }
  100604. }
  100605. return(OV_EBADHEADER);
  100606. }
  100607. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100608. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100609. if(!ci)return(OV_EFAULT);
  100610. oggpack_write(opb,0x01,8);
  100611. _v_writestring(opb,"vorbis", 6);
  100612. oggpack_write(opb,0x00,32);
  100613. oggpack_write(opb,vi->channels,8);
  100614. oggpack_write(opb,vi->rate,32);
  100615. oggpack_write(opb,vi->bitrate_upper,32);
  100616. oggpack_write(opb,vi->bitrate_nominal,32);
  100617. oggpack_write(opb,vi->bitrate_lower,32);
  100618. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100619. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100620. oggpack_write(opb,1,1);
  100621. return(0);
  100622. }
  100623. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100624. char temp[]="Xiph.Org libVorbis I 20050304";
  100625. int bytes = strlen(temp);
  100626. oggpack_write(opb,0x03,8);
  100627. _v_writestring(opb,"vorbis", 6);
  100628. oggpack_write(opb,bytes,32);
  100629. _v_writestring(opb,temp, bytes);
  100630. oggpack_write(opb,vc->comments,32);
  100631. if(vc->comments){
  100632. int i;
  100633. for(i=0;i<vc->comments;i++){
  100634. if(vc->user_comments[i]){
  100635. oggpack_write(opb,vc->comment_lengths[i],32);
  100636. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100637. }else{
  100638. oggpack_write(opb,0,32);
  100639. }
  100640. }
  100641. }
  100642. oggpack_write(opb,1,1);
  100643. return(0);
  100644. }
  100645. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100646. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100647. int i;
  100648. if(!ci)return(OV_EFAULT);
  100649. oggpack_write(opb,0x05,8);
  100650. _v_writestring(opb,"vorbis", 6);
  100651. oggpack_write(opb,ci->books-1,8);
  100652. for(i=0;i<ci->books;i++)
  100653. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100654. oggpack_write(opb,0,6);
  100655. oggpack_write(opb,0,16);
  100656. oggpack_write(opb,ci->floors-1,6);
  100657. for(i=0;i<ci->floors;i++){
  100658. oggpack_write(opb,ci->floor_type[i],16);
  100659. if(_floor_P[ci->floor_type[i]]->pack)
  100660. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100661. else
  100662. goto err_out;
  100663. }
  100664. oggpack_write(opb,ci->residues-1,6);
  100665. for(i=0;i<ci->residues;i++){
  100666. oggpack_write(opb,ci->residue_type[i],16);
  100667. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100668. }
  100669. oggpack_write(opb,ci->maps-1,6);
  100670. for(i=0;i<ci->maps;i++){
  100671. oggpack_write(opb,ci->map_type[i],16);
  100672. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100673. }
  100674. oggpack_write(opb,ci->modes-1,6);
  100675. for(i=0;i<ci->modes;i++){
  100676. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100677. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100678. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100679. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100680. }
  100681. oggpack_write(opb,1,1);
  100682. return(0);
  100683. err_out:
  100684. return(-1);
  100685. }
  100686. int vorbis_commentheader_out(vorbis_comment *vc,
  100687. ogg_packet *op){
  100688. oggpack_buffer opb;
  100689. oggpack_writeinit(&opb);
  100690. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100691. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100692. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100693. op->bytes=oggpack_bytes(&opb);
  100694. op->b_o_s=0;
  100695. op->e_o_s=0;
  100696. op->granulepos=0;
  100697. op->packetno=1;
  100698. return 0;
  100699. }
  100700. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100701. vorbis_comment *vc,
  100702. ogg_packet *op,
  100703. ogg_packet *op_comm,
  100704. ogg_packet *op_code){
  100705. int ret=OV_EIMPL;
  100706. vorbis_info *vi=v->vi;
  100707. oggpack_buffer opb;
  100708. private_state *b=(private_state*)v->backend_state;
  100709. if(!b){
  100710. ret=OV_EFAULT;
  100711. goto err_out;
  100712. }
  100713. oggpack_writeinit(&opb);
  100714. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100715. if(b->header)_ogg_free(b->header);
  100716. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100717. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100718. op->packet=b->header;
  100719. op->bytes=oggpack_bytes(&opb);
  100720. op->b_o_s=1;
  100721. op->e_o_s=0;
  100722. op->granulepos=0;
  100723. op->packetno=0;
  100724. oggpack_reset(&opb);
  100725. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100726. if(b->header1)_ogg_free(b->header1);
  100727. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100728. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100729. op_comm->packet=b->header1;
  100730. op_comm->bytes=oggpack_bytes(&opb);
  100731. op_comm->b_o_s=0;
  100732. op_comm->e_o_s=0;
  100733. op_comm->granulepos=0;
  100734. op_comm->packetno=1;
  100735. oggpack_reset(&opb);
  100736. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100737. if(b->header2)_ogg_free(b->header2);
  100738. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100739. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100740. op_code->packet=b->header2;
  100741. op_code->bytes=oggpack_bytes(&opb);
  100742. op_code->b_o_s=0;
  100743. op_code->e_o_s=0;
  100744. op_code->granulepos=0;
  100745. op_code->packetno=2;
  100746. oggpack_writeclear(&opb);
  100747. return(0);
  100748. err_out:
  100749. oggpack_writeclear(&opb);
  100750. memset(op,0,sizeof(*op));
  100751. memset(op_comm,0,sizeof(*op_comm));
  100752. memset(op_code,0,sizeof(*op_code));
  100753. if(b->header)_ogg_free(b->header);
  100754. if(b->header1)_ogg_free(b->header1);
  100755. if(b->header2)_ogg_free(b->header2);
  100756. b->header=NULL;
  100757. b->header1=NULL;
  100758. b->header2=NULL;
  100759. return(ret);
  100760. }
  100761. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100762. if(granulepos>=0)
  100763. return((double)granulepos/v->vi->rate);
  100764. return(-1);
  100765. }
  100766. #endif
  100767. /*** End of inlined file: info.c ***/
  100768. /*** Start of inlined file: lpc.c ***/
  100769. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100770. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100771. // tasks..
  100772. #if JUCE_MSVC
  100773. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100774. #endif
  100775. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100776. #if JUCE_USE_OGGVORBIS
  100777. #include <stdlib.h>
  100778. #include <string.h>
  100779. #include <math.h>
  100780. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100781. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100782. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100783. double error;
  100784. int i,j;
  100785. j=m+1;
  100786. while(j--){
  100787. double d=0; /* double needed for accumulator depth */
  100788. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100789. aut[j]=d;
  100790. }
  100791. error=aut[0];
  100792. for(i=0;i<m;i++){
  100793. double r= -aut[i+1];
  100794. if(error==0){
  100795. memset(lpci,0,m*sizeof(*lpci));
  100796. return 0;
  100797. }
  100798. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100799. r/=error;
  100800. lpc[i]=r;
  100801. for(j=0;j<i/2;j++){
  100802. double tmp=lpc[j];
  100803. lpc[j]+=r*lpc[i-1-j];
  100804. lpc[i-1-j]+=r*tmp;
  100805. }
  100806. if(i%2)lpc[j]+=lpc[j]*r;
  100807. error*=1.f-r*r;
  100808. }
  100809. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100810. return error;
  100811. }
  100812. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100813. float *data,long n){
  100814. long i,j,o,p;
  100815. float y;
  100816. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100817. if(!prime)
  100818. for(i=0;i<m;i++)
  100819. work[i]=0.f;
  100820. else
  100821. for(i=0;i<m;i++)
  100822. work[i]=prime[i];
  100823. for(i=0;i<n;i++){
  100824. y=0;
  100825. o=i;
  100826. p=m;
  100827. for(j=0;j<m;j++)
  100828. y-=work[o++]*coeff[--p];
  100829. data[i]=work[o]=y;
  100830. }
  100831. }
  100832. #endif
  100833. /*** End of inlined file: lpc.c ***/
  100834. /*** Start of inlined file: lsp.c ***/
  100835. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100836. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100837. // tasks..
  100838. #if JUCE_MSVC
  100839. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100840. #endif
  100841. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100842. #if JUCE_USE_OGGVORBIS
  100843. #include <math.h>
  100844. #include <string.h>
  100845. #include <stdlib.h>
  100846. /*** Start of inlined file: lookup.h ***/
  100847. #ifndef _V_LOOKUP_H_
  100848. #ifdef FLOAT_LOOKUP
  100849. extern float vorbis_coslook(float a);
  100850. extern float vorbis_invsqlook(float a);
  100851. extern float vorbis_invsq2explook(int a);
  100852. extern float vorbis_fromdBlook(float a);
  100853. #endif
  100854. #ifdef INT_LOOKUP
  100855. extern long vorbis_invsqlook_i(long a,long e);
  100856. extern long vorbis_coslook_i(long a);
  100857. extern float vorbis_fromdBlook_i(long a);
  100858. #endif
  100859. #endif
  100860. /*** End of inlined file: lookup.h ***/
  100861. #define FLOAT_LOOKUP
  100862. #undef INT_LOOKUP
  100863. #ifdef FLOAT_LOOKUP
  100864. /*** Start of inlined file: lookup.c ***/
  100865. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100866. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100867. // tasks..
  100868. #if JUCE_MSVC
  100869. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100870. #endif
  100871. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100872. #if JUCE_USE_OGGVORBIS
  100873. #include <math.h>
  100874. /*** Start of inlined file: lookup.h ***/
  100875. #ifndef _V_LOOKUP_H_
  100876. #ifdef FLOAT_LOOKUP
  100877. extern float vorbis_coslook(float a);
  100878. extern float vorbis_invsqlook(float a);
  100879. extern float vorbis_invsq2explook(int a);
  100880. extern float vorbis_fromdBlook(float a);
  100881. #endif
  100882. #ifdef INT_LOOKUP
  100883. extern long vorbis_invsqlook_i(long a,long e);
  100884. extern long vorbis_coslook_i(long a);
  100885. extern float vorbis_fromdBlook_i(long a);
  100886. #endif
  100887. #endif
  100888. /*** End of inlined file: lookup.h ***/
  100889. /*** Start of inlined file: lookup_data.h ***/
  100890. #ifndef _V_LOOKUP_DATA_H_
  100891. #ifdef FLOAT_LOOKUP
  100892. #define COS_LOOKUP_SZ 128
  100893. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100894. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100895. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100896. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100897. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100898. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100899. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100900. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100901. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100902. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100903. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100904. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100905. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100906. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100907. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100908. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100909. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100910. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100911. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100912. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100913. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100914. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100915. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100916. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100917. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100918. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100919. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100920. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100921. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100922. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100923. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100924. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100925. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100926. -1.0000000000000f,
  100927. };
  100928. #define INVSQ_LOOKUP_SZ 32
  100929. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100930. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100931. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100932. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100933. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100934. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100935. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100936. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100937. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100938. 1.000000000000f,
  100939. };
  100940. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100941. #define INVSQ2EXP_LOOKUP_MAX 32
  100942. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100943. INVSQ2EXP_LOOKUP_MIN+1]={
  100944. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100945. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100946. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100947. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100948. 256.f, 181.019336f, 128.f, 90.50966799f,
  100949. 64.f, 45.254834f, 32.f, 22.627417f,
  100950. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100951. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100952. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100953. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100954. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100955. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100956. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100957. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100958. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100959. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100960. 1.525878906e-05f,
  100961. };
  100962. #endif
  100963. #define FROMdB_LOOKUP_SZ 35
  100964. #define FROMdB2_LOOKUP_SZ 32
  100965. #define FROMdB_SHIFT 5
  100966. #define FROMdB2_SHIFT 3
  100967. #define FROMdB2_MASK 31
  100968. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100969. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100970. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100971. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100972. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100973. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100974. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100975. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100976. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100977. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100978. };
  100979. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100980. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100981. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100982. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100983. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100984. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100985. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100986. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100987. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100988. };
  100989. #ifdef INT_LOOKUP
  100990. #define INVSQ_LOOKUP_I_SHIFT 10
  100991. #define INVSQ_LOOKUP_I_MASK 1023
  100992. static long INVSQ_LOOKUP_I[64+1]={
  100993. 92682l, 91966l, 91267l, 90583l,
  100994. 89915l, 89261l, 88621l, 87995l,
  100995. 87381l, 86781l, 86192l, 85616l,
  100996. 85051l, 84497l, 83953l, 83420l,
  100997. 82897l, 82384l, 81880l, 81385l,
  100998. 80899l, 80422l, 79953l, 79492l,
  100999. 79039l, 78594l, 78156l, 77726l,
  101000. 77302l, 76885l, 76475l, 76072l,
  101001. 75674l, 75283l, 74898l, 74519l,
  101002. 74146l, 73778l, 73415l, 73058l,
  101003. 72706l, 72359l, 72016l, 71679l,
  101004. 71347l, 71019l, 70695l, 70376l,
  101005. 70061l, 69750l, 69444l, 69141l,
  101006. 68842l, 68548l, 68256l, 67969l,
  101007. 67685l, 67405l, 67128l, 66855l,
  101008. 66585l, 66318l, 66054l, 65794l,
  101009. 65536l,
  101010. };
  101011. #define COS_LOOKUP_I_SHIFT 9
  101012. #define COS_LOOKUP_I_MASK 511
  101013. #define COS_LOOKUP_I_SZ 128
  101014. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101015. 16384l, 16379l, 16364l, 16340l,
  101016. 16305l, 16261l, 16207l, 16143l,
  101017. 16069l, 15986l, 15893l, 15791l,
  101018. 15679l, 15557l, 15426l, 15286l,
  101019. 15137l, 14978l, 14811l, 14635l,
  101020. 14449l, 14256l, 14053l, 13842l,
  101021. 13623l, 13395l, 13160l, 12916l,
  101022. 12665l, 12406l, 12140l, 11866l,
  101023. 11585l, 11297l, 11003l, 10702l,
  101024. 10394l, 10080l, 9760l, 9434l,
  101025. 9102l, 8765l, 8423l, 8076l,
  101026. 7723l, 7366l, 7005l, 6639l,
  101027. 6270l, 5897l, 5520l, 5139l,
  101028. 4756l, 4370l, 3981l, 3590l,
  101029. 3196l, 2801l, 2404l, 2006l,
  101030. 1606l, 1205l, 804l, 402l,
  101031. 0l, -401l, -803l, -1204l,
  101032. -1605l, -2005l, -2403l, -2800l,
  101033. -3195l, -3589l, -3980l, -4369l,
  101034. -4755l, -5138l, -5519l, -5896l,
  101035. -6269l, -6638l, -7004l, -7365l,
  101036. -7722l, -8075l, -8422l, -8764l,
  101037. -9101l, -9433l, -9759l, -10079l,
  101038. -10393l, -10701l, -11002l, -11296l,
  101039. -11584l, -11865l, -12139l, -12405l,
  101040. -12664l, -12915l, -13159l, -13394l,
  101041. -13622l, -13841l, -14052l, -14255l,
  101042. -14448l, -14634l, -14810l, -14977l,
  101043. -15136l, -15285l, -15425l, -15556l,
  101044. -15678l, -15790l, -15892l, -15985l,
  101045. -16068l, -16142l, -16206l, -16260l,
  101046. -16304l, -16339l, -16363l, -16378l,
  101047. -16383l,
  101048. };
  101049. #endif
  101050. #endif
  101051. /*** End of inlined file: lookup_data.h ***/
  101052. #ifdef FLOAT_LOOKUP
  101053. float vorbis_coslook(float a){
  101054. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101055. int i=vorbis_ftoi(d-.5);
  101056. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101057. }
  101058. float vorbis_invsqlook(float a){
  101059. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101060. int i=vorbis_ftoi(d-.5f);
  101061. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101062. }
  101063. float vorbis_invsq2explook(int a){
  101064. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101065. }
  101066. #include <stdio.h>
  101067. float vorbis_fromdBlook(float a){
  101068. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101069. return (i<0)?1.f:
  101070. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101071. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101072. }
  101073. #endif
  101074. #ifdef INT_LOOKUP
  101075. long vorbis_invsqlook_i(long a,long e){
  101076. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101077. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101078. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101079. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101080. d)>>16); /* result 1.16 */
  101081. e+=32;
  101082. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101083. e=(e>>1)-8;
  101084. return(val>>e);
  101085. }
  101086. float vorbis_fromdBlook_i(long a){
  101087. int i=(-a)>>(12-FROMdB2_SHIFT);
  101088. return (i<0)?1.f:
  101089. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101090. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101091. }
  101092. long vorbis_coslook_i(long a){
  101093. int i=a>>COS_LOOKUP_I_SHIFT;
  101094. int d=a&COS_LOOKUP_I_MASK;
  101095. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101096. COS_LOOKUP_I_SHIFT);
  101097. }
  101098. #endif
  101099. #endif
  101100. /*** End of inlined file: lookup.c ***/
  101101. /* catch this in the build system; we #include for
  101102. compilers (like gcc) that can't inline across
  101103. modules */
  101104. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101105. float amp,float ampoffset){
  101106. int i;
  101107. float wdel=M_PI/ln;
  101108. vorbis_fpu_control fpu;
  101109. (void) fpu; // to avoid an unused variable warning
  101110. vorbis_fpu_setround(&fpu);
  101111. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  101112. i=0;
  101113. while(i<n){
  101114. int k=map[i];
  101115. int qexp;
  101116. float p=.7071067812f;
  101117. float q=.7071067812f;
  101118. float w=vorbis_coslook(wdel*k);
  101119. float *ftmp=lsp;
  101120. int c=m>>1;
  101121. do{
  101122. q*=ftmp[0]-w;
  101123. p*=ftmp[1]-w;
  101124. ftmp+=2;
  101125. }while(--c);
  101126. if(m&1){
  101127. q*=ftmp[0]-w;
  101128. q*=q;
  101129. p*=p*(1.f-w*w);
  101130. }else{
  101131. q*=q*(1.f+w);
  101132. p*=p*(1.f-w);
  101133. }
  101134. q=frexp(p+q,&qexp);
  101135. q=vorbis_fromdBlook(amp*
  101136. vorbis_invsqlook(q)*
  101137. vorbis_invsq2explook(qexp+m)-
  101138. ampoffset);
  101139. do{
  101140. curve[i++]*=q;
  101141. }while(map[i]==k);
  101142. }
  101143. vorbis_fpu_restore(fpu);
  101144. }
  101145. #else
  101146. #ifdef INT_LOOKUP
  101147. /*** Start of inlined file: lookup.c ***/
  101148. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101149. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101150. // tasks..
  101151. #if JUCE_MSVC
  101152. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101153. #endif
  101154. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101155. #if JUCE_USE_OGGVORBIS
  101156. #include <math.h>
  101157. /*** Start of inlined file: lookup.h ***/
  101158. #ifndef _V_LOOKUP_H_
  101159. #ifdef FLOAT_LOOKUP
  101160. extern float vorbis_coslook(float a);
  101161. extern float vorbis_invsqlook(float a);
  101162. extern float vorbis_invsq2explook(int a);
  101163. extern float vorbis_fromdBlook(float a);
  101164. #endif
  101165. #ifdef INT_LOOKUP
  101166. extern long vorbis_invsqlook_i(long a,long e);
  101167. extern long vorbis_coslook_i(long a);
  101168. extern float vorbis_fromdBlook_i(long a);
  101169. #endif
  101170. #endif
  101171. /*** End of inlined file: lookup.h ***/
  101172. /*** Start of inlined file: lookup_data.h ***/
  101173. #ifndef _V_LOOKUP_DATA_H_
  101174. #ifdef FLOAT_LOOKUP
  101175. #define COS_LOOKUP_SZ 128
  101176. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101177. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101178. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101179. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101180. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101181. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101182. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101183. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101184. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101185. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101186. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101187. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101188. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101189. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101190. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101191. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101192. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101193. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101194. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101195. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101196. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101197. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101198. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101199. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101200. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101201. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101202. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101203. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101204. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101205. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101206. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101207. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101208. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101209. -1.0000000000000f,
  101210. };
  101211. #define INVSQ_LOOKUP_SZ 32
  101212. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101213. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101214. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101215. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101216. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101217. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101218. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101219. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101220. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101221. 1.000000000000f,
  101222. };
  101223. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101224. #define INVSQ2EXP_LOOKUP_MAX 32
  101225. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101226. INVSQ2EXP_LOOKUP_MIN+1]={
  101227. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101228. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101229. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101230. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101231. 256.f, 181.019336f, 128.f, 90.50966799f,
  101232. 64.f, 45.254834f, 32.f, 22.627417f,
  101233. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101234. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101235. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101236. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101237. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101238. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101239. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101240. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101241. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101242. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101243. 1.525878906e-05f,
  101244. };
  101245. #endif
  101246. #define FROMdB_LOOKUP_SZ 35
  101247. #define FROMdB2_LOOKUP_SZ 32
  101248. #define FROMdB_SHIFT 5
  101249. #define FROMdB2_SHIFT 3
  101250. #define FROMdB2_MASK 31
  101251. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101252. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101253. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101254. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101255. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101256. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101257. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101258. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101259. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101260. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101261. };
  101262. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101263. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101264. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101265. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101266. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101267. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101268. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101269. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101270. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101271. };
  101272. #ifdef INT_LOOKUP
  101273. #define INVSQ_LOOKUP_I_SHIFT 10
  101274. #define INVSQ_LOOKUP_I_MASK 1023
  101275. static long INVSQ_LOOKUP_I[64+1]={
  101276. 92682l, 91966l, 91267l, 90583l,
  101277. 89915l, 89261l, 88621l, 87995l,
  101278. 87381l, 86781l, 86192l, 85616l,
  101279. 85051l, 84497l, 83953l, 83420l,
  101280. 82897l, 82384l, 81880l, 81385l,
  101281. 80899l, 80422l, 79953l, 79492l,
  101282. 79039l, 78594l, 78156l, 77726l,
  101283. 77302l, 76885l, 76475l, 76072l,
  101284. 75674l, 75283l, 74898l, 74519l,
  101285. 74146l, 73778l, 73415l, 73058l,
  101286. 72706l, 72359l, 72016l, 71679l,
  101287. 71347l, 71019l, 70695l, 70376l,
  101288. 70061l, 69750l, 69444l, 69141l,
  101289. 68842l, 68548l, 68256l, 67969l,
  101290. 67685l, 67405l, 67128l, 66855l,
  101291. 66585l, 66318l, 66054l, 65794l,
  101292. 65536l,
  101293. };
  101294. #define COS_LOOKUP_I_SHIFT 9
  101295. #define COS_LOOKUP_I_MASK 511
  101296. #define COS_LOOKUP_I_SZ 128
  101297. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101298. 16384l, 16379l, 16364l, 16340l,
  101299. 16305l, 16261l, 16207l, 16143l,
  101300. 16069l, 15986l, 15893l, 15791l,
  101301. 15679l, 15557l, 15426l, 15286l,
  101302. 15137l, 14978l, 14811l, 14635l,
  101303. 14449l, 14256l, 14053l, 13842l,
  101304. 13623l, 13395l, 13160l, 12916l,
  101305. 12665l, 12406l, 12140l, 11866l,
  101306. 11585l, 11297l, 11003l, 10702l,
  101307. 10394l, 10080l, 9760l, 9434l,
  101308. 9102l, 8765l, 8423l, 8076l,
  101309. 7723l, 7366l, 7005l, 6639l,
  101310. 6270l, 5897l, 5520l, 5139l,
  101311. 4756l, 4370l, 3981l, 3590l,
  101312. 3196l, 2801l, 2404l, 2006l,
  101313. 1606l, 1205l, 804l, 402l,
  101314. 0l, -401l, -803l, -1204l,
  101315. -1605l, -2005l, -2403l, -2800l,
  101316. -3195l, -3589l, -3980l, -4369l,
  101317. -4755l, -5138l, -5519l, -5896l,
  101318. -6269l, -6638l, -7004l, -7365l,
  101319. -7722l, -8075l, -8422l, -8764l,
  101320. -9101l, -9433l, -9759l, -10079l,
  101321. -10393l, -10701l, -11002l, -11296l,
  101322. -11584l, -11865l, -12139l, -12405l,
  101323. -12664l, -12915l, -13159l, -13394l,
  101324. -13622l, -13841l, -14052l, -14255l,
  101325. -14448l, -14634l, -14810l, -14977l,
  101326. -15136l, -15285l, -15425l, -15556l,
  101327. -15678l, -15790l, -15892l, -15985l,
  101328. -16068l, -16142l, -16206l, -16260l,
  101329. -16304l, -16339l, -16363l, -16378l,
  101330. -16383l,
  101331. };
  101332. #endif
  101333. #endif
  101334. /*** End of inlined file: lookup_data.h ***/
  101335. #ifdef FLOAT_LOOKUP
  101336. float vorbis_coslook(float a){
  101337. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101338. int i=vorbis_ftoi(d-.5);
  101339. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101340. }
  101341. float vorbis_invsqlook(float a){
  101342. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101343. int i=vorbis_ftoi(d-.5f);
  101344. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101345. }
  101346. float vorbis_invsq2explook(int a){
  101347. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101348. }
  101349. #include <stdio.h>
  101350. float vorbis_fromdBlook(float a){
  101351. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101352. return (i<0)?1.f:
  101353. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101354. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101355. }
  101356. #endif
  101357. #ifdef INT_LOOKUP
  101358. long vorbis_invsqlook_i(long a,long e){
  101359. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101360. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101361. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101362. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101363. d)>>16); /* result 1.16 */
  101364. e+=32;
  101365. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101366. e=(e>>1)-8;
  101367. return(val>>e);
  101368. }
  101369. float vorbis_fromdBlook_i(long a){
  101370. int i=(-a)>>(12-FROMdB2_SHIFT);
  101371. return (i<0)?1.f:
  101372. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101373. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101374. }
  101375. long vorbis_coslook_i(long a){
  101376. int i=a>>COS_LOOKUP_I_SHIFT;
  101377. int d=a&COS_LOOKUP_I_MASK;
  101378. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101379. COS_LOOKUP_I_SHIFT);
  101380. }
  101381. #endif
  101382. #endif
  101383. /*** End of inlined file: lookup.c ***/
  101384. /* catch this in the build system; we #include for
  101385. compilers (like gcc) that can't inline across
  101386. modules */
  101387. static int MLOOP_1[64]={
  101388. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101389. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101390. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101391. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101392. };
  101393. static int MLOOP_2[64]={
  101394. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101395. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101396. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101397. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101398. };
  101399. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101400. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101401. float amp,float ampoffset){
  101402. int i;
  101403. int ampoffseti=rint(ampoffset*4096.f);
  101404. int ampi=rint(amp*16.f);
  101405. long *ilsp=alloca(m*sizeof(*ilsp));
  101406. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101407. i=0;
  101408. while(i<n){
  101409. int j,k=map[i];
  101410. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101411. unsigned long qi=46341;
  101412. int qexp=0,shift;
  101413. long wi=vorbis_coslook_i(k*65536/ln);
  101414. qi*=labs(ilsp[0]-wi);
  101415. pi*=labs(ilsp[1]-wi);
  101416. for(j=3;j<m;j+=2){
  101417. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101418. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101419. shift=MLOOP_3[(pi|qi)>>16];
  101420. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101421. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101422. qexp+=shift;
  101423. }
  101424. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101425. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101426. shift=MLOOP_3[(pi|qi)>>16];
  101427. if(m&1){
  101428. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101429. pi=(pi>>shift)<<14;
  101430. qexp+=shift;
  101431. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101432. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101433. shift=MLOOP_3[(pi|qi)>>16];
  101434. pi>>=shift;
  101435. qi>>=shift;
  101436. qexp+=shift-14*((m+1)>>1);
  101437. pi=((pi*pi)>>16);
  101438. qi=((qi*qi)>>16);
  101439. qexp=qexp*2+m;
  101440. pi*=(1<<14)-((wi*wi)>>14);
  101441. qi+=pi>>14;
  101442. }else{
  101443. pi>>=shift;
  101444. qi>>=shift;
  101445. qexp+=shift-7*m;
  101446. pi=((pi*pi)>>16);
  101447. qi=((qi*qi)>>16);
  101448. qexp=qexp*2+m;
  101449. pi*=(1<<14)-wi;
  101450. qi*=(1<<14)+wi;
  101451. qi=(qi+pi)>>14;
  101452. }
  101453. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101454. qi>>=1; qexp++;
  101455. }else
  101456. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101457. qi<<=1; qexp--;
  101458. }
  101459. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101460. vorbis_invsqlook_i(qi,qexp)-
  101461. ampoffseti); /* 8.12[0] */
  101462. curve[i]*=amp;
  101463. while(map[++i]==k)curve[i]*=amp;
  101464. }
  101465. }
  101466. #else
  101467. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101468. float amp,float ampoffset){
  101469. int i;
  101470. float wdel=M_PI/ln;
  101471. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101472. i=0;
  101473. while(i<n){
  101474. int j,k=map[i];
  101475. float p=.5f;
  101476. float q=.5f;
  101477. float w=2.f*cos(wdel*k);
  101478. for(j=1;j<m;j+=2){
  101479. q *= w-lsp[j-1];
  101480. p *= w-lsp[j];
  101481. }
  101482. if(j==m){
  101483. q*=w-lsp[j-1];
  101484. p*=p*(4.f-w*w);
  101485. q*=q;
  101486. }else{
  101487. p*=p*(2.f-w);
  101488. q*=q*(2.f+w);
  101489. }
  101490. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101491. curve[i]*=q;
  101492. while(map[++i]==k)curve[i]*=q;
  101493. }
  101494. }
  101495. #endif
  101496. #endif
  101497. static void cheby(float *g, int ord) {
  101498. int i, j;
  101499. g[0] *= .5f;
  101500. for(i=2; i<= ord; i++) {
  101501. for(j=ord; j >= i; j--) {
  101502. g[j-2] -= g[j];
  101503. g[j] += g[j];
  101504. }
  101505. }
  101506. }
  101507. static int comp(const void *a,const void *b){
  101508. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101509. }
  101510. #define EPSILON 10e-7
  101511. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101512. int i,m;
  101513. double lastdelta=0.f;
  101514. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101515. for(i=0;i<=ord;i++)defl[i]=a[i];
  101516. for(m=ord;m>0;m--){
  101517. double newx=0.f,delta;
  101518. while(1){
  101519. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101520. for(i=m;i>0;i--){
  101521. ppp = newx*ppp + pp;
  101522. pp = newx*pp + p;
  101523. p = newx*p + defl[i-1];
  101524. }
  101525. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101526. if(denom<0)
  101527. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101528. if(pp>0){
  101529. denom = pp + sqrt(denom);
  101530. if(denom<EPSILON)denom=EPSILON;
  101531. }else{
  101532. denom = pp - sqrt(denom);
  101533. if(denom>-(EPSILON))denom=-(EPSILON);
  101534. }
  101535. delta = m*p/denom;
  101536. newx -= delta;
  101537. if(delta<0.f)delta*=-1;
  101538. if(fabs(delta/newx)<10e-12)break;
  101539. lastdelta=delta;
  101540. }
  101541. r[m-1]=newx;
  101542. for(i=m;i>0;i--)
  101543. defl[i-1]+=newx*defl[i];
  101544. defl++;
  101545. }
  101546. return(0);
  101547. }
  101548. static int Newton_Raphson(float *a,int ord,float *r){
  101549. int i, k, count=0;
  101550. double error=1.f;
  101551. double *root=(double*)alloca(ord*sizeof(*root));
  101552. for(i=0; i<ord;i++) root[i] = r[i];
  101553. while(error>1e-20){
  101554. error=0;
  101555. for(i=0; i<ord; i++) { /* Update each point. */
  101556. double pp=0.,delta;
  101557. double rooti=root[i];
  101558. double p=a[ord];
  101559. for(k=ord-1; k>= 0; k--) {
  101560. pp= pp* rooti + p;
  101561. p = p * rooti + a[k];
  101562. }
  101563. delta = p/pp;
  101564. root[i] -= delta;
  101565. error+= delta*delta;
  101566. }
  101567. if(count>40)return(-1);
  101568. count++;
  101569. }
  101570. for(i=0; i<ord;i++) r[i] = root[i];
  101571. return(0);
  101572. }
  101573. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101574. int order2=(m+1)>>1;
  101575. int g1_order,g2_order;
  101576. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101577. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101578. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101579. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101580. int i;
  101581. g1_order=(m+1)>>1;
  101582. g2_order=(m) >>1;
  101583. g1[g1_order] = 1.f;
  101584. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101585. g2[g2_order] = 1.f;
  101586. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101587. if(g1_order>g2_order){
  101588. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101589. }else{
  101590. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101591. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101592. }
  101593. cheby(g1,g1_order);
  101594. cheby(g2,g2_order);
  101595. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101596. Laguerre_With_Deflation(g2,g2_order,g2r))
  101597. return(-1);
  101598. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101599. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101600. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101601. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101602. for(i=0;i<g1_order;i++)
  101603. lsp[i*2] = acos(g1r[i]);
  101604. for(i=0;i<g2_order;i++)
  101605. lsp[i*2+1] = acos(g2r[i]);
  101606. return(0);
  101607. }
  101608. #endif
  101609. /*** End of inlined file: lsp.c ***/
  101610. /*** Start of inlined file: mapping0.c ***/
  101611. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101612. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101613. // tasks..
  101614. #if JUCE_MSVC
  101615. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101616. #endif
  101617. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101618. #if JUCE_USE_OGGVORBIS
  101619. #include <stdlib.h>
  101620. #include <stdio.h>
  101621. #include <string.h>
  101622. #include <math.h>
  101623. static void mapping0_free_info(vorbis_info_mapping *i){
  101624. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101625. if(info){
  101626. memset(info,0,sizeof(*info));
  101627. _ogg_free(info);
  101628. }
  101629. }
  101630. static int ilog3(unsigned int v){
  101631. int ret=0;
  101632. if(v)--v;
  101633. while(v){
  101634. ret++;
  101635. v>>=1;
  101636. }
  101637. return(ret);
  101638. }
  101639. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101640. oggpack_buffer *opb){
  101641. int i;
  101642. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101643. if(info->submaps>1){
  101644. oggpack_write(opb,1,1);
  101645. oggpack_write(opb,info->submaps-1,4);
  101646. }else
  101647. oggpack_write(opb,0,1);
  101648. if(info->coupling_steps>0){
  101649. oggpack_write(opb,1,1);
  101650. oggpack_write(opb,info->coupling_steps-1,8);
  101651. for(i=0;i<info->coupling_steps;i++){
  101652. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101653. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101654. }
  101655. }else
  101656. oggpack_write(opb,0,1);
  101657. oggpack_write(opb,0,2); /* 2,3:reserved */
  101658. if(info->submaps>1){
  101659. for(i=0;i<vi->channels;i++)
  101660. oggpack_write(opb,info->chmuxlist[i],4);
  101661. }
  101662. for(i=0;i<info->submaps;i++){
  101663. oggpack_write(opb,0,8); /* time submap unused */
  101664. oggpack_write(opb,info->floorsubmap[i],8);
  101665. oggpack_write(opb,info->residuesubmap[i],8);
  101666. }
  101667. }
  101668. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101669. int i;
  101670. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101671. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101672. memset(info,0,sizeof(*info));
  101673. if(oggpack_read(opb,1))
  101674. info->submaps=oggpack_read(opb,4)+1;
  101675. else
  101676. info->submaps=1;
  101677. if(oggpack_read(opb,1)){
  101678. info->coupling_steps=oggpack_read(opb,8)+1;
  101679. for(i=0;i<info->coupling_steps;i++){
  101680. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101681. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101682. if(testM<0 ||
  101683. testA<0 ||
  101684. testM==testA ||
  101685. testM>=vi->channels ||
  101686. testA>=vi->channels) goto err_out;
  101687. }
  101688. }
  101689. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101690. if(info->submaps>1){
  101691. for(i=0;i<vi->channels;i++){
  101692. info->chmuxlist[i]=oggpack_read(opb,4);
  101693. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101694. }
  101695. }
  101696. for(i=0;i<info->submaps;i++){
  101697. oggpack_read(opb,8); /* time submap unused */
  101698. info->floorsubmap[i]=oggpack_read(opb,8);
  101699. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101700. info->residuesubmap[i]=oggpack_read(opb,8);
  101701. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101702. }
  101703. return info;
  101704. err_out:
  101705. mapping0_free_info(info);
  101706. return(NULL);
  101707. }
  101708. #if 0
  101709. static long seq=0;
  101710. static ogg_int64_t total=0;
  101711. static float FLOOR1_fromdB_LOOKUP[256]={
  101712. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101713. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101714. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101715. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101716. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101717. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101718. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101719. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101720. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101721. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101722. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101723. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101724. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101725. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101726. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101727. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101728. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101729. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101730. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101731. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101732. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101733. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101734. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101735. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101736. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101737. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101738. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101739. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101740. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101741. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101742. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101743. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101744. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101745. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101746. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101747. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101748. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101749. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101750. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101751. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101752. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101753. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101754. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101755. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101756. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101757. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101758. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101759. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101760. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101761. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101762. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101763. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101764. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101765. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101766. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101767. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101768. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101769. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101770. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101771. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101772. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101773. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101774. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101775. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101776. };
  101777. #endif
  101778. extern int *floor1_fit(vorbis_block *vb,void *look,
  101779. const float *logmdct, /* in */
  101780. const float *logmask);
  101781. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101782. int *A,int *B,
  101783. int del);
  101784. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101785. void*look,
  101786. int *post,int *ilogmask);
  101787. static int mapping0_forward(vorbis_block *vb){
  101788. vorbis_dsp_state *vd=vb->vd;
  101789. vorbis_info *vi=vd->vi;
  101790. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101791. private_state *b=(private_state*)vb->vd->backend_state;
  101792. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101793. int n=vb->pcmend;
  101794. int i,j,k;
  101795. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101796. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101797. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101798. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101799. float global_ampmax=vbi->ampmax;
  101800. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101801. int blocktype=vbi->blocktype;
  101802. int modenumber=vb->W;
  101803. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101804. vorbis_look_psy *psy_look=
  101805. b->psy+blocktype+(vb->W?2:0);
  101806. vb->mode=modenumber;
  101807. for(i=0;i<vi->channels;i++){
  101808. float scale=4.f/n;
  101809. float scale_dB;
  101810. float *pcm =vb->pcm[i];
  101811. float *logfft =pcm;
  101812. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101813. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101814. todB estimation used on IEEE 754
  101815. compliant machines had a bug that
  101816. returned dB values about a third
  101817. of a decibel too high. The bug
  101818. was harmless because tunings
  101819. implicitly took that into
  101820. account. However, fixing the bug
  101821. in the estimator requires
  101822. changing all the tunings as well.
  101823. For now, it's easier to sync
  101824. things back up here, and
  101825. recalibrate the tunings in the
  101826. next major model upgrade. */
  101827. #if 0
  101828. if(vi->channels==2)
  101829. if(i==0)
  101830. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101831. else
  101832. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101833. #endif
  101834. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101835. #if 0
  101836. if(vi->channels==2)
  101837. if(i==0)
  101838. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101839. else
  101840. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101841. #endif
  101842. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101843. drft_forward(&b->fft_look[vb->W],pcm);
  101844. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101845. original todB estimation used on
  101846. IEEE 754 compliant machines had a
  101847. bug that returned dB values about
  101848. a third of a decibel too high.
  101849. The bug was harmless because
  101850. tunings implicitly took that into
  101851. account. However, fixing the bug
  101852. in the estimator requires
  101853. changing all the tunings as well.
  101854. For now, it's easier to sync
  101855. things back up here, and
  101856. recalibrate the tunings in the
  101857. next major model upgrade. */
  101858. local_ampmax[i]=logfft[0];
  101859. for(j=1;j<n-1;j+=2){
  101860. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101861. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101862. .345 is a hack; the original todB
  101863. estimation used on IEEE 754
  101864. compliant machines had a bug that
  101865. returned dB values about a third
  101866. of a decibel too high. The bug
  101867. was harmless because tunings
  101868. implicitly took that into
  101869. account. However, fixing the bug
  101870. in the estimator requires
  101871. changing all the tunings as well.
  101872. For now, it's easier to sync
  101873. things back up here, and
  101874. recalibrate the tunings in the
  101875. next major model upgrade. */
  101876. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101877. }
  101878. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101879. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101880. #if 0
  101881. if(vi->channels==2){
  101882. if(i==0){
  101883. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101884. }else{
  101885. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101886. }
  101887. }
  101888. #endif
  101889. }
  101890. {
  101891. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101892. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101893. for(i=0;i<vi->channels;i++){
  101894. int submap=info->chmuxlist[i];
  101895. float *mdct =gmdct[i];
  101896. float *logfft =vb->pcm[i];
  101897. float *logmdct =logfft+n/2;
  101898. float *logmask =logfft;
  101899. vb->mode=modenumber;
  101900. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101901. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101902. for(j=0;j<n/2;j++)
  101903. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101904. todB estimation used on IEEE 754
  101905. compliant machines had a bug that
  101906. returned dB values about a third
  101907. of a decibel too high. The bug
  101908. was harmless because tunings
  101909. implicitly took that into
  101910. account. However, fixing the bug
  101911. in the estimator requires
  101912. changing all the tunings as well.
  101913. For now, it's easier to sync
  101914. things back up here, and
  101915. recalibrate the tunings in the
  101916. next major model upgrade. */
  101917. #if 0
  101918. if(vi->channels==2){
  101919. if(i==0)
  101920. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101921. else
  101922. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101923. }else{
  101924. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101925. }
  101926. #endif
  101927. _vp_noisemask(psy_look,
  101928. logmdct,
  101929. noise); /* noise does not have by-frequency offset
  101930. bias applied yet */
  101931. #if 0
  101932. if(vi->channels==2){
  101933. if(i==0)
  101934. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101935. else
  101936. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101937. }
  101938. #endif
  101939. _vp_tonemask(psy_look,
  101940. logfft,
  101941. tone,
  101942. global_ampmax,
  101943. local_ampmax[i]);
  101944. #if 0
  101945. if(vi->channels==2){
  101946. if(i==0)
  101947. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101948. else
  101949. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101950. }
  101951. #endif
  101952. #if 0
  101953. {
  101954. float aotuv[psy_look->n];
  101955. #endif
  101956. _vp_offset_and_mix(psy_look,
  101957. noise,
  101958. tone,
  101959. 1,
  101960. logmask,
  101961. mdct,
  101962. logmdct);
  101963. #if 0
  101964. if(vi->channels==2){
  101965. if(i==0)
  101966. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101967. else
  101968. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101969. }
  101970. }
  101971. #endif
  101972. #if 0
  101973. if(vi->channels==2){
  101974. if(i==0)
  101975. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101976. else
  101977. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101978. }
  101979. #endif
  101980. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101981. floor_posts[i][PACKETBLOBS/2]=
  101982. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101983. logmdct,
  101984. logmask);
  101985. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101986. _vp_offset_and_mix(psy_look,
  101987. noise,
  101988. tone,
  101989. 2,
  101990. logmask,
  101991. mdct,
  101992. logmdct);
  101993. #if 0
  101994. if(vi->channels==2){
  101995. if(i==0)
  101996. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101997. else
  101998. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101999. }
  102000. #endif
  102001. floor_posts[i][PACKETBLOBS-1]=
  102002. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102003. logmdct,
  102004. logmask);
  102005. _vp_offset_and_mix(psy_look,
  102006. noise,
  102007. tone,
  102008. 0,
  102009. logmask,
  102010. mdct,
  102011. logmdct);
  102012. #if 0
  102013. if(vi->channels==2)
  102014. if(i==0)
  102015. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  102016. else
  102017. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  102018. #endif
  102019. floor_posts[i][0]=
  102020. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102021. logmdct,
  102022. logmask);
  102023. for(k=1;k<PACKETBLOBS/2;k++)
  102024. floor_posts[i][k]=
  102025. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102026. floor_posts[i][0],
  102027. floor_posts[i][PACKETBLOBS/2],
  102028. k*65536/(PACKETBLOBS/2));
  102029. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  102030. floor_posts[i][k]=
  102031. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102032. floor_posts[i][PACKETBLOBS/2],
  102033. floor_posts[i][PACKETBLOBS-1],
  102034. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  102035. }
  102036. }
  102037. }
  102038. vbi->ampmax=global_ampmax;
  102039. {
  102040. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  102041. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  102042. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102043. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  102044. float **mag_memo;
  102045. int **mag_sort;
  102046. if(info->coupling_steps){
  102047. mag_memo=_vp_quantize_couple_memo(vb,
  102048. &ci->psy_g_param,
  102049. psy_look,
  102050. info,
  102051. gmdct);
  102052. mag_sort=_vp_quantize_couple_sort(vb,
  102053. psy_look,
  102054. info,
  102055. mag_memo);
  102056. hf_reduction(&ci->psy_g_param,
  102057. psy_look,
  102058. info,
  102059. mag_memo);
  102060. }
  102061. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  102062. if(psy_look->vi->normal_channel_p){
  102063. for(i=0;i<vi->channels;i++){
  102064. float *mdct =gmdct[i];
  102065. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  102066. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  102067. }
  102068. }
  102069. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  102070. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  102071. k++){
  102072. oggpack_buffer *opb=vbi->packetblob[k];
  102073. oggpack_write(opb,0,1);
  102074. oggpack_write(opb,modenumber,b->modebits);
  102075. if(vb->W){
  102076. oggpack_write(opb,vb->lW,1);
  102077. oggpack_write(opb,vb->nW,1);
  102078. }
  102079. for(i=0;i<vi->channels;i++){
  102080. int submap=info->chmuxlist[i];
  102081. float *mdct =gmdct[i];
  102082. float *res =vb->pcm[i];
  102083. int *ilogmask=ilogmaskch[i]=
  102084. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102085. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  102086. floor_posts[i][k],
  102087. ilogmask);
  102088. #if 0
  102089. {
  102090. char buf[80];
  102091. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  102092. float work[n/2];
  102093. for(j=0;j<n/2;j++)
  102094. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  102095. _analysis_output(buf,seq,work,n/2,1,1,0);
  102096. }
  102097. #endif
  102098. _vp_remove_floor(psy_look,
  102099. mdct,
  102100. ilogmask,
  102101. res,
  102102. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102103. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  102104. #if 0
  102105. {
  102106. char buf[80];
  102107. float work[n/2];
  102108. for(j=0;j<n/2;j++)
  102109. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  102110. sprintf(buf,"resI%c%d",i?'R':'L',k);
  102111. _analysis_output(buf,seq,work,n/2,1,1,0);
  102112. }
  102113. #endif
  102114. }
  102115. if(info->coupling_steps){
  102116. _vp_couple(k,
  102117. &ci->psy_g_param,
  102118. psy_look,
  102119. info,
  102120. vb->pcm,
  102121. mag_memo,
  102122. mag_sort,
  102123. ilogmaskch,
  102124. nonzero,
  102125. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102126. }
  102127. for(i=0;i<info->submaps;i++){
  102128. int ch_in_bundle=0;
  102129. long **classifications;
  102130. int resnum=info->residuesubmap[i];
  102131. for(j=0;j<vi->channels;j++){
  102132. if(info->chmuxlist[j]==i){
  102133. zerobundle[ch_in_bundle]=0;
  102134. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  102135. res_bundle[ch_in_bundle]=vb->pcm[j];
  102136. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  102137. }
  102138. }
  102139. classifications=_residue_P[ci->residue_type[resnum]]->
  102140. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  102141. _residue_P[ci->residue_type[resnum]]->
  102142. forward(opb,vb,b->residue[resnum],
  102143. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  102144. }
  102145. }
  102146. }
  102147. #if 0
  102148. seq++;
  102149. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  102150. #endif
  102151. return(0);
  102152. }
  102153. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  102154. vorbis_dsp_state *vd=vb->vd;
  102155. vorbis_info *vi=vd->vi;
  102156. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  102157. private_state *b=(private_state*)vd->backend_state;
  102158. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  102159. int i,j;
  102160. long n=vb->pcmend=ci->blocksizes[vb->W];
  102161. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  102162. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102163. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  102164. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  102165. for(i=0;i<vi->channels;i++){
  102166. int submap=info->chmuxlist[i];
  102167. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102168. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  102169. if(floormemo[i])
  102170. nonzero[i]=1;
  102171. else
  102172. nonzero[i]=0;
  102173. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  102174. }
  102175. for(i=0;i<info->coupling_steps;i++){
  102176. if(nonzero[info->coupling_mag[i]] ||
  102177. nonzero[info->coupling_ang[i]]){
  102178. nonzero[info->coupling_mag[i]]=1;
  102179. nonzero[info->coupling_ang[i]]=1;
  102180. }
  102181. }
  102182. for(i=0;i<info->submaps;i++){
  102183. int ch_in_bundle=0;
  102184. for(j=0;j<vi->channels;j++){
  102185. if(info->chmuxlist[j]==i){
  102186. if(nonzero[j])
  102187. zerobundle[ch_in_bundle]=1;
  102188. else
  102189. zerobundle[ch_in_bundle]=0;
  102190. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  102191. }
  102192. }
  102193. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  102194. inverse(vb,b->residue[info->residuesubmap[i]],
  102195. pcmbundle,zerobundle,ch_in_bundle);
  102196. }
  102197. for(i=info->coupling_steps-1;i>=0;i--){
  102198. float *pcmM=vb->pcm[info->coupling_mag[i]];
  102199. float *pcmA=vb->pcm[info->coupling_ang[i]];
  102200. for(j=0;j<n/2;j++){
  102201. float mag=pcmM[j];
  102202. float ang=pcmA[j];
  102203. if(mag>0)
  102204. if(ang>0){
  102205. pcmM[j]=mag;
  102206. pcmA[j]=mag-ang;
  102207. }else{
  102208. pcmA[j]=mag;
  102209. pcmM[j]=mag+ang;
  102210. }
  102211. else
  102212. if(ang>0){
  102213. pcmM[j]=mag;
  102214. pcmA[j]=mag+ang;
  102215. }else{
  102216. pcmA[j]=mag;
  102217. pcmM[j]=mag-ang;
  102218. }
  102219. }
  102220. }
  102221. for(i=0;i<vi->channels;i++){
  102222. float *pcm=vb->pcm[i];
  102223. int submap=info->chmuxlist[i];
  102224. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102225. inverse2(vb,b->flr[info->floorsubmap[submap]],
  102226. floormemo[i],pcm);
  102227. }
  102228. for(i=0;i<vi->channels;i++){
  102229. float *pcm=vb->pcm[i];
  102230. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  102231. }
  102232. return(0);
  102233. }
  102234. vorbis_func_mapping mapping0_exportbundle={
  102235. &mapping0_pack,
  102236. &mapping0_unpack,
  102237. &mapping0_free_info,
  102238. &mapping0_forward,
  102239. &mapping0_inverse
  102240. };
  102241. #endif
  102242. /*** End of inlined file: mapping0.c ***/
  102243. /*** Start of inlined file: mdct.c ***/
  102244. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102245. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102246. // tasks..
  102247. #if JUCE_MSVC
  102248. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102249. #endif
  102250. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102251. #if JUCE_USE_OGGVORBIS
  102252. #include <stdio.h>
  102253. #include <stdlib.h>
  102254. #include <string.h>
  102255. #include <math.h>
  102256. void mdct_init(mdct_lookup *lookup,int n){
  102257. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  102258. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  102259. int i;
  102260. int n2=n>>1;
  102261. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  102262. lookup->n=n;
  102263. lookup->trig=T;
  102264. lookup->bitrev=bitrev;
  102265. for(i=0;i<n/4;i++){
  102266. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  102267. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  102268. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  102269. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  102270. }
  102271. for(i=0;i<n/8;i++){
  102272. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  102273. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  102274. }
  102275. {
  102276. int mask=(1<<(log2n-1))-1,i,j;
  102277. int msb=1<<(log2n-2);
  102278. for(i=0;i<n/8;i++){
  102279. int acc=0;
  102280. for(j=0;msb>>j;j++)
  102281. if((msb>>j)&i)acc|=1<<j;
  102282. bitrev[i*2]=((~acc)&mask)-1;
  102283. bitrev[i*2+1]=acc;
  102284. }
  102285. }
  102286. lookup->scale=FLOAT_CONV(4.f/n);
  102287. }
  102288. STIN void mdct_butterfly_8(DATA_TYPE *x){
  102289. REG_TYPE r0 = x[6] + x[2];
  102290. REG_TYPE r1 = x[6] - x[2];
  102291. REG_TYPE r2 = x[4] + x[0];
  102292. REG_TYPE r3 = x[4] - x[0];
  102293. x[6] = r0 + r2;
  102294. x[4] = r0 - r2;
  102295. r0 = x[5] - x[1];
  102296. r2 = x[7] - x[3];
  102297. x[0] = r1 + r0;
  102298. x[2] = r1 - r0;
  102299. r0 = x[5] + x[1];
  102300. r1 = x[7] + x[3];
  102301. x[3] = r2 + r3;
  102302. x[1] = r2 - r3;
  102303. x[7] = r1 + r0;
  102304. x[5] = r1 - r0;
  102305. }
  102306. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102307. REG_TYPE r0 = x[1] - x[9];
  102308. REG_TYPE r1 = x[0] - x[8];
  102309. x[8] += x[0];
  102310. x[9] += x[1];
  102311. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102312. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102313. r0 = x[3] - x[11];
  102314. r1 = x[10] - x[2];
  102315. x[10] += x[2];
  102316. x[11] += x[3];
  102317. x[2] = r0;
  102318. x[3] = r1;
  102319. r0 = x[12] - x[4];
  102320. r1 = x[13] - x[5];
  102321. x[12] += x[4];
  102322. x[13] += x[5];
  102323. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102324. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102325. r0 = x[14] - x[6];
  102326. r1 = x[15] - x[7];
  102327. x[14] += x[6];
  102328. x[15] += x[7];
  102329. x[6] = r0;
  102330. x[7] = r1;
  102331. mdct_butterfly_8(x);
  102332. mdct_butterfly_8(x+8);
  102333. }
  102334. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102335. REG_TYPE r0 = x[30] - x[14];
  102336. REG_TYPE r1 = x[31] - x[15];
  102337. x[30] += x[14];
  102338. x[31] += x[15];
  102339. x[14] = r0;
  102340. x[15] = r1;
  102341. r0 = x[28] - x[12];
  102342. r1 = x[29] - x[13];
  102343. x[28] += x[12];
  102344. x[29] += x[13];
  102345. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102346. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102347. r0 = x[26] - x[10];
  102348. r1 = x[27] - x[11];
  102349. x[26] += x[10];
  102350. x[27] += x[11];
  102351. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102352. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102353. r0 = x[24] - x[8];
  102354. r1 = x[25] - x[9];
  102355. x[24] += x[8];
  102356. x[25] += x[9];
  102357. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102358. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102359. r0 = x[22] - x[6];
  102360. r1 = x[7] - x[23];
  102361. x[22] += x[6];
  102362. x[23] += x[7];
  102363. x[6] = r1;
  102364. x[7] = r0;
  102365. r0 = x[4] - x[20];
  102366. r1 = x[5] - x[21];
  102367. x[20] += x[4];
  102368. x[21] += x[5];
  102369. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102370. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102371. r0 = x[2] - x[18];
  102372. r1 = x[3] - x[19];
  102373. x[18] += x[2];
  102374. x[19] += x[3];
  102375. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102376. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102377. r0 = x[0] - x[16];
  102378. r1 = x[1] - x[17];
  102379. x[16] += x[0];
  102380. x[17] += x[1];
  102381. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102382. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102383. mdct_butterfly_16(x);
  102384. mdct_butterfly_16(x+16);
  102385. }
  102386. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102387. DATA_TYPE *x,
  102388. int points){
  102389. DATA_TYPE *x1 = x + points - 8;
  102390. DATA_TYPE *x2 = x + (points>>1) - 8;
  102391. REG_TYPE r0;
  102392. REG_TYPE r1;
  102393. do{
  102394. r0 = x1[6] - x2[6];
  102395. r1 = x1[7] - x2[7];
  102396. x1[6] += x2[6];
  102397. x1[7] += x2[7];
  102398. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102399. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102400. r0 = x1[4] - x2[4];
  102401. r1 = x1[5] - x2[5];
  102402. x1[4] += x2[4];
  102403. x1[5] += x2[5];
  102404. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102405. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102406. r0 = x1[2] - x2[2];
  102407. r1 = x1[3] - x2[3];
  102408. x1[2] += x2[2];
  102409. x1[3] += x2[3];
  102410. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102411. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102412. r0 = x1[0] - x2[0];
  102413. r1 = x1[1] - x2[1];
  102414. x1[0] += x2[0];
  102415. x1[1] += x2[1];
  102416. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102417. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102418. x1-=8;
  102419. x2-=8;
  102420. T+=16;
  102421. }while(x2>=x);
  102422. }
  102423. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102424. DATA_TYPE *x,
  102425. int points,
  102426. int trigint){
  102427. DATA_TYPE *x1 = x + points - 8;
  102428. DATA_TYPE *x2 = x + (points>>1) - 8;
  102429. REG_TYPE r0;
  102430. REG_TYPE r1;
  102431. do{
  102432. r0 = x1[6] - x2[6];
  102433. r1 = x1[7] - x2[7];
  102434. x1[6] += x2[6];
  102435. x1[7] += x2[7];
  102436. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102437. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102438. T+=trigint;
  102439. r0 = x1[4] - x2[4];
  102440. r1 = x1[5] - x2[5];
  102441. x1[4] += x2[4];
  102442. x1[5] += x2[5];
  102443. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102444. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102445. T+=trigint;
  102446. r0 = x1[2] - x2[2];
  102447. r1 = x1[3] - x2[3];
  102448. x1[2] += x2[2];
  102449. x1[3] += x2[3];
  102450. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102451. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102452. T+=trigint;
  102453. r0 = x1[0] - x2[0];
  102454. r1 = x1[1] - x2[1];
  102455. x1[0] += x2[0];
  102456. x1[1] += x2[1];
  102457. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102458. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102459. T+=trigint;
  102460. x1-=8;
  102461. x2-=8;
  102462. }while(x2>=x);
  102463. }
  102464. STIN void mdct_butterflies(mdct_lookup *init,
  102465. DATA_TYPE *x,
  102466. int points){
  102467. DATA_TYPE *T=init->trig;
  102468. int stages=init->log2n-5;
  102469. int i,j;
  102470. if(--stages>0){
  102471. mdct_butterfly_first(T,x,points);
  102472. }
  102473. for(i=1;--stages>0;i++){
  102474. for(j=0;j<(1<<i);j++)
  102475. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102476. }
  102477. for(j=0;j<points;j+=32)
  102478. mdct_butterfly_32(x+j);
  102479. }
  102480. void mdct_clear(mdct_lookup *l){
  102481. if(l){
  102482. if(l->trig)_ogg_free(l->trig);
  102483. if(l->bitrev)_ogg_free(l->bitrev);
  102484. memset(l,0,sizeof(*l));
  102485. }
  102486. }
  102487. STIN void mdct_bitreverse(mdct_lookup *init,
  102488. DATA_TYPE *x){
  102489. int n = init->n;
  102490. int *bit = init->bitrev;
  102491. DATA_TYPE *w0 = x;
  102492. DATA_TYPE *w1 = x = w0+(n>>1);
  102493. DATA_TYPE *T = init->trig+n;
  102494. do{
  102495. DATA_TYPE *x0 = x+bit[0];
  102496. DATA_TYPE *x1 = x+bit[1];
  102497. REG_TYPE r0 = x0[1] - x1[1];
  102498. REG_TYPE r1 = x0[0] + x1[0];
  102499. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102500. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102501. w1 -= 4;
  102502. r0 = HALVE(x0[1] + x1[1]);
  102503. r1 = HALVE(x0[0] - x1[0]);
  102504. w0[0] = r0 + r2;
  102505. w1[2] = r0 - r2;
  102506. w0[1] = r1 + r3;
  102507. w1[3] = r3 - r1;
  102508. x0 = x+bit[2];
  102509. x1 = x+bit[3];
  102510. r0 = x0[1] - x1[1];
  102511. r1 = x0[0] + x1[0];
  102512. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102513. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102514. r0 = HALVE(x0[1] + x1[1]);
  102515. r1 = HALVE(x0[0] - x1[0]);
  102516. w0[2] = r0 + r2;
  102517. w1[0] = r0 - r2;
  102518. w0[3] = r1 + r3;
  102519. w1[1] = r3 - r1;
  102520. T += 4;
  102521. bit += 4;
  102522. w0 += 4;
  102523. }while(w0<w1);
  102524. }
  102525. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102526. int n=init->n;
  102527. int n2=n>>1;
  102528. int n4=n>>2;
  102529. DATA_TYPE *iX = in+n2-7;
  102530. DATA_TYPE *oX = out+n2+n4;
  102531. DATA_TYPE *T = init->trig+n4;
  102532. do{
  102533. oX -= 4;
  102534. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102535. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102536. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102537. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102538. iX -= 8;
  102539. T += 4;
  102540. }while(iX>=in);
  102541. iX = in+n2-8;
  102542. oX = out+n2+n4;
  102543. T = init->trig+n4;
  102544. do{
  102545. T -= 4;
  102546. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102547. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102548. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102549. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102550. iX -= 8;
  102551. oX += 4;
  102552. }while(iX>=in);
  102553. mdct_butterflies(init,out+n2,n2);
  102554. mdct_bitreverse(init,out);
  102555. {
  102556. DATA_TYPE *oX1=out+n2+n4;
  102557. DATA_TYPE *oX2=out+n2+n4;
  102558. DATA_TYPE *iX =out;
  102559. T =init->trig+n2;
  102560. do{
  102561. oX1-=4;
  102562. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102563. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102564. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102565. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102566. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102567. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102568. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102569. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102570. oX2+=4;
  102571. iX += 8;
  102572. T += 8;
  102573. }while(iX<oX1);
  102574. iX=out+n2+n4;
  102575. oX1=out+n4;
  102576. oX2=oX1;
  102577. do{
  102578. oX1-=4;
  102579. iX-=4;
  102580. oX2[0] = -(oX1[3] = iX[3]);
  102581. oX2[1] = -(oX1[2] = iX[2]);
  102582. oX2[2] = -(oX1[1] = iX[1]);
  102583. oX2[3] = -(oX1[0] = iX[0]);
  102584. oX2+=4;
  102585. }while(oX2<iX);
  102586. iX=out+n2+n4;
  102587. oX1=out+n2+n4;
  102588. oX2=out+n2;
  102589. do{
  102590. oX1-=4;
  102591. oX1[0]= iX[3];
  102592. oX1[1]= iX[2];
  102593. oX1[2]= iX[1];
  102594. oX1[3]= iX[0];
  102595. iX+=4;
  102596. }while(oX1>oX2);
  102597. }
  102598. }
  102599. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102600. int n=init->n;
  102601. int n2=n>>1;
  102602. int n4=n>>2;
  102603. int n8=n>>3;
  102604. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102605. DATA_TYPE *w2=w+n2;
  102606. REG_TYPE r0;
  102607. REG_TYPE r1;
  102608. DATA_TYPE *x0=in+n2+n4;
  102609. DATA_TYPE *x1=x0+1;
  102610. DATA_TYPE *T=init->trig+n2;
  102611. int i=0;
  102612. for(i=0;i<n8;i+=2){
  102613. x0 -=4;
  102614. T-=2;
  102615. r0= x0[2] + x1[0];
  102616. r1= x0[0] + x1[2];
  102617. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102618. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102619. x1 +=4;
  102620. }
  102621. x1=in+1;
  102622. for(;i<n2-n8;i+=2){
  102623. T-=2;
  102624. x0 -=4;
  102625. r0= x0[2] - x1[0];
  102626. r1= x0[0] - x1[2];
  102627. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102628. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102629. x1 +=4;
  102630. }
  102631. x0=in+n;
  102632. for(;i<n2;i+=2){
  102633. T-=2;
  102634. x0 -=4;
  102635. r0= -x0[2] - x1[0];
  102636. r1= -x0[0] - x1[2];
  102637. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102638. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102639. x1 +=4;
  102640. }
  102641. mdct_butterflies(init,w+n2,n2);
  102642. mdct_bitreverse(init,w);
  102643. T=init->trig+n2;
  102644. x0=out+n2;
  102645. for(i=0;i<n4;i++){
  102646. x0--;
  102647. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102648. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102649. w+=2;
  102650. T+=2;
  102651. }
  102652. }
  102653. #endif
  102654. /*** End of inlined file: mdct.c ***/
  102655. /*** Start of inlined file: psy.c ***/
  102656. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102657. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102658. // tasks..
  102659. #if JUCE_MSVC
  102660. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102661. #endif
  102662. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102663. #if JUCE_USE_OGGVORBIS
  102664. #include <stdlib.h>
  102665. #include <math.h>
  102666. #include <string.h>
  102667. /*** Start of inlined file: masking.h ***/
  102668. #ifndef _V_MASKING_H_
  102669. #define _V_MASKING_H_
  102670. #define MAX_ATH 88
  102671. static float ATH[]={
  102672. -51, -52, -53, -54, -55, -56, -57, -58,
  102673. -59, -60, -61, -62, -63, -64, -65, -66,
  102674. -67, -68, -69, -70, -71, -72, -73, -74,
  102675. -75, -76, -77, -78, -80, -81, -82, -83,
  102676. -84, -85, -86, -87, -88, -88, -89, -89,
  102677. -90, -91, -91, -92, -93, -94, -95, -96,
  102678. -96, -97, -98, -98, -99, -99,-100,-100,
  102679. -101,-102,-103,-104,-106,-107,-107,-107,
  102680. -107,-105,-103,-102,-101, -99, -98, -96,
  102681. -95, -95, -96, -97, -96, -95, -93, -90,
  102682. -80, -70, -50, -40, -30, -30, -30, -30
  102683. };
  102684. #define EHMER_OFFSET 16
  102685. #define EHMER_MAX 56
  102686. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102687. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102688. -60, -60, -60, -60, -62, -62, -65, -73,
  102689. -69, -68, -68, -67, -70, -70, -72, -74,
  102690. -75, -79, -79, -80, -83, -88, -93, -100,
  102691. -110, -999, -999, -999, -999, -999, -999, -999,
  102692. -999, -999, -999, -999, -999, -999, -999, -999,
  102693. -999, -999, -999, -999, -999, -999, -999, -999},
  102694. { -48, -48, -48, -48, -48, -48, -48, -48,
  102695. -48, -48, -48, -48, -48, -53, -61, -66,
  102696. -66, -68, -67, -70, -76, -76, -72, -73,
  102697. -75, -76, -78, -79, -83, -88, -93, -100,
  102698. -110, -999, -999, -999, -999, -999, -999, -999,
  102699. -999, -999, -999, -999, -999, -999, -999, -999,
  102700. -999, -999, -999, -999, -999, -999, -999, -999},
  102701. { -37, -37, -37, -37, -37, -37, -37, -37,
  102702. -38, -40, -42, -46, -48, -53, -55, -62,
  102703. -65, -58, -56, -56, -61, -60, -65, -67,
  102704. -69, -71, -77, -77, -78, -80, -82, -84,
  102705. -88, -93, -98, -106, -112, -999, -999, -999,
  102706. -999, -999, -999, -999, -999, -999, -999, -999,
  102707. -999, -999, -999, -999, -999, -999, -999, -999},
  102708. { -25, -25, -25, -25, -25, -25, -25, -25,
  102709. -25, -26, -27, -29, -32, -38, -48, -52,
  102710. -52, -50, -48, -48, -51, -52, -54, -60,
  102711. -67, -67, -66, -68, -69, -73, -73, -76,
  102712. -80, -81, -81, -85, -85, -86, -88, -93,
  102713. -100, -110, -999, -999, -999, -999, -999, -999,
  102714. -999, -999, -999, -999, -999, -999, -999, -999},
  102715. { -16, -16, -16, -16, -16, -16, -16, -16,
  102716. -17, -19, -20, -22, -26, -28, -31, -40,
  102717. -47, -39, -39, -40, -42, -43, -47, -51,
  102718. -57, -52, -55, -55, -60, -58, -62, -63,
  102719. -70, -67, -69, -72, -73, -77, -80, -82,
  102720. -83, -87, -90, -94, -98, -104, -115, -999,
  102721. -999, -999, -999, -999, -999, -999, -999, -999},
  102722. { -8, -8, -8, -8, -8, -8, -8, -8,
  102723. -8, -8, -10, -11, -15, -19, -25, -30,
  102724. -34, -31, -30, -31, -29, -32, -35, -42,
  102725. -48, -42, -44, -46, -50, -50, -51, -52,
  102726. -59, -54, -55, -55, -58, -62, -63, -66,
  102727. -72, -73, -76, -75, -78, -80, -80, -81,
  102728. -84, -88, -90, -94, -98, -101, -106, -110}},
  102729. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102730. -66, -66, -66, -66, -66, -67, -67, -67,
  102731. -76, -72, -71, -74, -76, -76, -75, -78,
  102732. -79, -79, -81, -83, -86, -89, -93, -97,
  102733. -100, -105, -110, -999, -999, -999, -999, -999,
  102734. -999, -999, -999, -999, -999, -999, -999, -999,
  102735. -999, -999, -999, -999, -999, -999, -999, -999},
  102736. { -47, -47, -47, -47, -47, -47, -47, -47,
  102737. -47, -47, -47, -48, -51, -55, -59, -66,
  102738. -66, -66, -67, -66, -68, -69, -70, -74,
  102739. -79, -77, -77, -78, -80, -81, -82, -84,
  102740. -86, -88, -91, -95, -100, -108, -116, -999,
  102741. -999, -999, -999, -999, -999, -999, -999, -999,
  102742. -999, -999, -999, -999, -999, -999, -999, -999},
  102743. { -36, -36, -36, -36, -36, -36, -36, -36,
  102744. -36, -37, -37, -41, -44, -48, -51, -58,
  102745. -62, -60, -57, -59, -59, -60, -63, -65,
  102746. -72, -71, -70, -72, -74, -77, -76, -78,
  102747. -81, -81, -80, -83, -86, -91, -96, -100,
  102748. -105, -110, -999, -999, -999, -999, -999, -999,
  102749. -999, -999, -999, -999, -999, -999, -999, -999},
  102750. { -28, -28, -28, -28, -28, -28, -28, -28,
  102751. -28, -30, -32, -32, -33, -35, -41, -49,
  102752. -50, -49, -47, -48, -48, -52, -51, -57,
  102753. -65, -61, -59, -61, -64, -69, -70, -74,
  102754. -77, -77, -78, -81, -84, -85, -87, -90,
  102755. -92, -96, -100, -107, -112, -999, -999, -999,
  102756. -999, -999, -999, -999, -999, -999, -999, -999},
  102757. { -19, -19, -19, -19, -19, -19, -19, -19,
  102758. -20, -21, -23, -27, -30, -35, -36, -41,
  102759. -46, -44, -42, -40, -41, -41, -43, -48,
  102760. -55, -53, -52, -53, -56, -59, -58, -60,
  102761. -67, -66, -69, -71, -72, -75, -79, -81,
  102762. -84, -87, -90, -93, -97, -101, -107, -114,
  102763. -999, -999, -999, -999, -999, -999, -999, -999},
  102764. { -9, -9, -9, -9, -9, -9, -9, -9,
  102765. -11, -12, -12, -15, -16, -20, -23, -30,
  102766. -37, -34, -33, -34, -31, -32, -32, -38,
  102767. -47, -44, -41, -40, -47, -49, -46, -46,
  102768. -58, -50, -50, -54, -58, -62, -64, -67,
  102769. -67, -70, -72, -76, -79, -83, -87, -91,
  102770. -96, -100, -104, -110, -999, -999, -999, -999}},
  102771. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102772. -62, -62, -63, -64, -66, -67, -66, -68,
  102773. -75, -72, -76, -75, -76, -78, -79, -82,
  102774. -84, -85, -90, -94, -101, -110, -999, -999,
  102775. -999, -999, -999, -999, -999, -999, -999, -999,
  102776. -999, -999, -999, -999, -999, -999, -999, -999,
  102777. -999, -999, -999, -999, -999, -999, -999, -999},
  102778. { -59, -59, -59, -59, -59, -59, -59, -59,
  102779. -59, -59, -59, -60, -60, -61, -63, -66,
  102780. -71, -68, -70, -70, -71, -72, -72, -75,
  102781. -81, -78, -79, -82, -83, -86, -90, -97,
  102782. -103, -113, -999, -999, -999, -999, -999, -999,
  102783. -999, -999, -999, -999, -999, -999, -999, -999,
  102784. -999, -999, -999, -999, -999, -999, -999, -999},
  102785. { -53, -53, -53, -53, -53, -53, -53, -53,
  102786. -53, -54, -55, -57, -56, -57, -55, -61,
  102787. -65, -60, -60, -62, -63, -63, -66, -68,
  102788. -74, -73, -75, -75, -78, -80, -80, -82,
  102789. -85, -90, -96, -101, -108, -999, -999, -999,
  102790. -999, -999, -999, -999, -999, -999, -999, -999,
  102791. -999, -999, -999, -999, -999, -999, -999, -999},
  102792. { -46, -46, -46, -46, -46, -46, -46, -46,
  102793. -46, -46, -47, -47, -47, -47, -48, -51,
  102794. -57, -51, -49, -50, -51, -53, -54, -59,
  102795. -66, -60, -62, -67, -67, -70, -72, -75,
  102796. -76, -78, -81, -85, -88, -94, -97, -104,
  102797. -112, -999, -999, -999, -999, -999, -999, -999,
  102798. -999, -999, -999, -999, -999, -999, -999, -999},
  102799. { -36, -36, -36, -36, -36, -36, -36, -36,
  102800. -39, -41, -42, -42, -39, -38, -41, -43,
  102801. -52, -44, -40, -39, -37, -37, -40, -47,
  102802. -54, -50, -48, -50, -55, -61, -59, -62,
  102803. -66, -66, -66, -69, -69, -73, -74, -74,
  102804. -75, -77, -79, -82, -87, -91, -95, -100,
  102805. -108, -115, -999, -999, -999, -999, -999, -999},
  102806. { -28, -26, -24, -22, -20, -20, -23, -29,
  102807. -30, -31, -28, -27, -28, -28, -28, -35,
  102808. -40, -33, -32, -29, -30, -30, -30, -37,
  102809. -45, -41, -37, -38, -45, -47, -47, -48,
  102810. -53, -49, -48, -50, -49, -49, -51, -52,
  102811. -58, -56, -57, -56, -60, -61, -62, -70,
  102812. -72, -74, -78, -83, -88, -93, -100, -106}},
  102813. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102814. -999, -110, -105, -100, -95, -91, -87, -83,
  102815. -80, -78, -76, -78, -78, -81, -83, -85,
  102816. -86, -85, -86, -87, -90, -97, -107, -999,
  102817. -999, -999, -999, -999, -999, -999, -999, -999,
  102818. -999, -999, -999, -999, -999, -999, -999, -999,
  102819. -999, -999, -999, -999, -999, -999, -999, -999},
  102820. {-999, -999, -999, -110, -105, -100, -95, -90,
  102821. -85, -81, -77, -73, -70, -67, -67, -68,
  102822. -75, -73, -70, -69, -70, -72, -75, -79,
  102823. -84, -83, -84, -86, -88, -89, -89, -93,
  102824. -98, -105, -112, -999, -999, -999, -999, -999,
  102825. -999, -999, -999, -999, -999, -999, -999, -999,
  102826. -999, -999, -999, -999, -999, -999, -999, -999},
  102827. {-105, -100, -95, -90, -85, -80, -76, -71,
  102828. -68, -68, -65, -63, -63, -62, -62, -64,
  102829. -65, -64, -61, -62, -63, -64, -66, -68,
  102830. -73, -73, -74, -75, -76, -81, -83, -85,
  102831. -88, -89, -92, -95, -100, -108, -999, -999,
  102832. -999, -999, -999, -999, -999, -999, -999, -999,
  102833. -999, -999, -999, -999, -999, -999, -999, -999},
  102834. { -80, -75, -71, -68, -65, -63, -62, -61,
  102835. -61, -61, -61, -59, -56, -57, -53, -50,
  102836. -58, -52, -50, -50, -52, -53, -54, -58,
  102837. -67, -63, -67, -68, -72, -75, -78, -80,
  102838. -81, -81, -82, -85, -89, -90, -93, -97,
  102839. -101, -107, -114, -999, -999, -999, -999, -999,
  102840. -999, -999, -999, -999, -999, -999, -999, -999},
  102841. { -65, -61, -59, -57, -56, -55, -55, -56,
  102842. -56, -57, -55, -53, -52, -47, -44, -44,
  102843. -50, -44, -41, -39, -39, -42, -40, -46,
  102844. -51, -49, -50, -53, -54, -63, -60, -61,
  102845. -62, -66, -66, -66, -70, -73, -74, -75,
  102846. -76, -75, -79, -85, -89, -91, -96, -102,
  102847. -110, -999, -999, -999, -999, -999, -999, -999},
  102848. { -52, -50, -49, -49, -48, -48, -48, -49,
  102849. -50, -50, -49, -46, -43, -39, -35, -33,
  102850. -38, -36, -32, -29, -32, -32, -32, -35,
  102851. -44, -39, -38, -38, -46, -50, -45, -46,
  102852. -53, -50, -50, -50, -54, -54, -53, -53,
  102853. -56, -57, -59, -66, -70, -72, -74, -79,
  102854. -83, -85, -90, -97, -114, -999, -999, -999}},
  102855. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102856. -100, -95, -90, -86, -80, -75, -75, -79,
  102857. -80, -79, -80, -81, -82, -88, -95, -103,
  102858. -110, -999, -999, -999, -999, -999, -999, -999,
  102859. -999, -999, -999, -999, -999, -999, -999, -999,
  102860. -999, -999, -999, -999, -999, -999, -999, -999,
  102861. -999, -999, -999, -999, -999, -999, -999, -999},
  102862. {-999, -999, -999, -999, -108, -103, -98, -93,
  102863. -88, -83, -79, -78, -75, -71, -67, -68,
  102864. -73, -73, -72, -73, -75, -77, -80, -82,
  102865. -88, -93, -100, -107, -114, -999, -999, -999,
  102866. -999, -999, -999, -999, -999, -999, -999, -999,
  102867. -999, -999, -999, -999, -999, -999, -999, -999,
  102868. -999, -999, -999, -999, -999, -999, -999, -999},
  102869. {-999, -999, -999, -110, -105, -101, -96, -90,
  102870. -86, -81, -77, -73, -69, -66, -61, -62,
  102871. -66, -64, -62, -65, -66, -70, -72, -76,
  102872. -81, -80, -84, -90, -95, -102, -110, -999,
  102873. -999, -999, -999, -999, -999, -999, -999, -999,
  102874. -999, -999, -999, -999, -999, -999, -999, -999,
  102875. -999, -999, -999, -999, -999, -999, -999, -999},
  102876. {-999, -999, -999, -107, -103, -97, -92, -88,
  102877. -83, -79, -74, -70, -66, -59, -53, -58,
  102878. -62, -55, -54, -54, -54, -58, -61, -62,
  102879. -72, -70, -72, -75, -78, -80, -81, -80,
  102880. -83, -83, -88, -93, -100, -107, -115, -999,
  102881. -999, -999, -999, -999, -999, -999, -999, -999,
  102882. -999, -999, -999, -999, -999, -999, -999, -999},
  102883. {-999, -999, -999, -105, -100, -95, -90, -85,
  102884. -80, -75, -70, -66, -62, -56, -48, -44,
  102885. -48, -46, -46, -43, -46, -48, -48, -51,
  102886. -58, -58, -59, -60, -62, -62, -61, -61,
  102887. -65, -64, -65, -68, -70, -74, -75, -78,
  102888. -81, -86, -95, -110, -999, -999, -999, -999,
  102889. -999, -999, -999, -999, -999, -999, -999, -999},
  102890. {-999, -999, -105, -100, -95, -90, -85, -80,
  102891. -75, -70, -65, -61, -55, -49, -39, -33,
  102892. -40, -35, -32, -38, -40, -33, -35, -37,
  102893. -46, -41, -45, -44, -46, -42, -45, -46,
  102894. -52, -50, -50, -50, -54, -54, -55, -57,
  102895. -62, -64, -66, -68, -70, -76, -81, -90,
  102896. -100, -110, -999, -999, -999, -999, -999, -999}},
  102897. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102898. -105, -98, -90, -85, -82, -83, -80, -78,
  102899. -84, -79, -80, -83, -87, -89, -91, -93,
  102900. -99, -106, -117, -999, -999, -999, -999, -999,
  102901. -999, -999, -999, -999, -999, -999, -999, -999,
  102902. -999, -999, -999, -999, -999, -999, -999, -999,
  102903. -999, -999, -999, -999, -999, -999, -999, -999},
  102904. {-999, -999, -999, -999, -999, -999, -999, -999,
  102905. -105, -98, -90, -85, -80, -75, -70, -68,
  102906. -74, -72, -74, -77, -80, -82, -85, -87,
  102907. -92, -89, -91, -95, -100, -106, -112, -999,
  102908. -999, -999, -999, -999, -999, -999, -999, -999,
  102909. -999, -999, -999, -999, -999, -999, -999, -999,
  102910. -999, -999, -999, -999, -999, -999, -999, -999},
  102911. {-999, -999, -999, -999, -999, -999, -999, -999,
  102912. -105, -98, -90, -83, -75, -71, -63, -64,
  102913. -67, -62, -64, -67, -70, -73, -77, -81,
  102914. -84, -83, -85, -89, -90, -93, -98, -104,
  102915. -109, -114, -999, -999, -999, -999, -999, -999,
  102916. -999, -999, -999, -999, -999, -999, -999, -999,
  102917. -999, -999, -999, -999, -999, -999, -999, -999},
  102918. {-999, -999, -999, -999, -999, -999, -999, -999,
  102919. -103, -96, -88, -81, -75, -68, -58, -54,
  102920. -56, -54, -56, -56, -58, -60, -63, -66,
  102921. -74, -69, -72, -72, -75, -74, -77, -81,
  102922. -81, -82, -84, -87, -93, -96, -99, -104,
  102923. -110, -999, -999, -999, -999, -999, -999, -999,
  102924. -999, -999, -999, -999, -999, -999, -999, -999},
  102925. {-999, -999, -999, -999, -999, -108, -102, -96,
  102926. -91, -85, -80, -74, -68, -60, -51, -46,
  102927. -48, -46, -43, -45, -47, -47, -49, -48,
  102928. -56, -53, -55, -58, -57, -63, -58, -60,
  102929. -66, -64, -67, -70, -70, -74, -77, -84,
  102930. -86, -89, -91, -93, -94, -101, -109, -118,
  102931. -999, -999, -999, -999, -999, -999, -999, -999},
  102932. {-999, -999, -999, -108, -103, -98, -93, -88,
  102933. -83, -78, -73, -68, -60, -53, -44, -35,
  102934. -38, -38, -34, -34, -36, -40, -41, -44,
  102935. -51, -45, -46, -47, -46, -54, -50, -49,
  102936. -50, -50, -50, -51, -54, -57, -58, -60,
  102937. -66, -66, -66, -64, -65, -68, -77, -82,
  102938. -87, -95, -110, -999, -999, -999, -999, -999}},
  102939. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102940. -107, -102, -97, -92, -87, -83, -78, -75,
  102941. -82, -79, -83, -85, -89, -92, -95, -98,
  102942. -101, -105, -109, -113, -999, -999, -999, -999,
  102943. -999, -999, -999, -999, -999, -999, -999, -999,
  102944. -999, -999, -999, -999, -999, -999, -999, -999,
  102945. -999, -999, -999, -999, -999, -999, -999, -999},
  102946. {-999, -999, -999, -999, -999, -999, -999, -106,
  102947. -100, -95, -90, -86, -81, -78, -74, -69,
  102948. -74, -74, -76, -79, -83, -84, -86, -89,
  102949. -92, -97, -93, -100, -103, -107, -110, -999,
  102950. -999, -999, -999, -999, -999, -999, -999, -999,
  102951. -999, -999, -999, -999, -999, -999, -999, -999,
  102952. -999, -999, -999, -999, -999, -999, -999, -999},
  102953. {-999, -999, -999, -999, -999, -999, -106, -100,
  102954. -95, -90, -87, -83, -80, -75, -69, -60,
  102955. -66, -66, -68, -70, -74, -78, -79, -81,
  102956. -81, -83, -84, -87, -93, -96, -99, -103,
  102957. -107, -110, -999, -999, -999, -999, -999, -999,
  102958. -999, -999, -999, -999, -999, -999, -999, -999,
  102959. -999, -999, -999, -999, -999, -999, -999, -999},
  102960. {-999, -999, -999, -999, -999, -108, -103, -98,
  102961. -93, -89, -85, -82, -78, -71, -62, -55,
  102962. -58, -58, -54, -54, -55, -59, -61, -62,
  102963. -70, -66, -66, -67, -70, -72, -75, -78,
  102964. -84, -84, -84, -88, -91, -90, -95, -98,
  102965. -102, -103, -106, -110, -999, -999, -999, -999,
  102966. -999, -999, -999, -999, -999, -999, -999, -999},
  102967. {-999, -999, -999, -999, -108, -103, -98, -94,
  102968. -90, -87, -82, -79, -73, -67, -58, -47,
  102969. -50, -45, -41, -45, -48, -44, -44, -49,
  102970. -54, -51, -48, -47, -49, -50, -51, -57,
  102971. -58, -60, -63, -69, -70, -69, -71, -74,
  102972. -78, -82, -90, -95, -101, -105, -110, -999,
  102973. -999, -999, -999, -999, -999, -999, -999, -999},
  102974. {-999, -999, -999, -105, -101, -97, -93, -90,
  102975. -85, -80, -77, -72, -65, -56, -48, -37,
  102976. -40, -36, -34, -40, -50, -47, -38, -41,
  102977. -47, -38, -35, -39, -38, -43, -40, -45,
  102978. -50, -45, -44, -47, -50, -55, -48, -48,
  102979. -52, -66, -70, -76, -82, -90, -97, -105,
  102980. -110, -999, -999, -999, -999, -999, -999, -999}},
  102981. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102982. -999, -108, -103, -98, -93, -86, -79, -76,
  102983. -83, -81, -85, -87, -89, -93, -98, -102,
  102984. -107, -112, -999, -999, -999, -999, -999, -999,
  102985. -999, -999, -999, -999, -999, -999, -999, -999,
  102986. -999, -999, -999, -999, -999, -999, -999, -999,
  102987. -999, -999, -999, -999, -999, -999, -999, -999},
  102988. {-999, -999, -999, -999, -999, -999, -999, -999,
  102989. -999, -108, -103, -98, -93, -86, -79, -71,
  102990. -77, -74, -77, -79, -81, -84, -85, -90,
  102991. -92, -93, -92, -98, -101, -108, -112, -999,
  102992. -999, -999, -999, -999, -999, -999, -999, -999,
  102993. -999, -999, -999, -999, -999, -999, -999, -999,
  102994. -999, -999, -999, -999, -999, -999, -999, -999},
  102995. {-999, -999, -999, -999, -999, -999, -999, -999,
  102996. -108, -103, -98, -93, -87, -78, -68, -65,
  102997. -66, -62, -65, -67, -70, -73, -75, -78,
  102998. -82, -82, -83, -84, -91, -93, -98, -102,
  102999. -106, -110, -999, -999, -999, -999, -999, -999,
  103000. -999, -999, -999, -999, -999, -999, -999, -999,
  103001. -999, -999, -999, -999, -999, -999, -999, -999},
  103002. {-999, -999, -999, -999, -999, -999, -999, -999,
  103003. -105, -100, -95, -90, -82, -74, -62, -57,
  103004. -58, -56, -51, -52, -52, -54, -54, -58,
  103005. -66, -59, -60, -63, -66, -69, -73, -79,
  103006. -83, -84, -80, -81, -81, -82, -88, -92,
  103007. -98, -105, -113, -999, -999, -999, -999, -999,
  103008. -999, -999, -999, -999, -999, -999, -999, -999},
  103009. {-999, -999, -999, -999, -999, -999, -999, -107,
  103010. -102, -97, -92, -84, -79, -69, -57, -47,
  103011. -52, -47, -44, -45, -50, -52, -42, -42,
  103012. -53, -43, -43, -48, -51, -56, -55, -52,
  103013. -57, -59, -61, -62, -67, -71, -78, -83,
  103014. -86, -94, -98, -103, -110, -999, -999, -999,
  103015. -999, -999, -999, -999, -999, -999, -999, -999},
  103016. {-999, -999, -999, -999, -999, -999, -105, -100,
  103017. -95, -90, -84, -78, -70, -61, -51, -41,
  103018. -40, -38, -40, -46, -52, -51, -41, -40,
  103019. -46, -40, -38, -38, -41, -46, -41, -46,
  103020. -47, -43, -43, -45, -41, -45, -56, -67,
  103021. -68, -83, -87, -90, -95, -102, -107, -113,
  103022. -999, -999, -999, -999, -999, -999, -999, -999}},
  103023. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103024. -999, -109, -105, -101, -96, -91, -84, -77,
  103025. -82, -82, -85, -89, -94, -100, -106, -110,
  103026. -999, -999, -999, -999, -999, -999, -999, -999,
  103027. -999, -999, -999, -999, -999, -999, -999, -999,
  103028. -999, -999, -999, -999, -999, -999, -999, -999,
  103029. -999, -999, -999, -999, -999, -999, -999, -999},
  103030. {-999, -999, -999, -999, -999, -999, -999, -999,
  103031. -999, -106, -103, -98, -92, -85, -80, -71,
  103032. -75, -72, -76, -80, -84, -86, -89, -93,
  103033. -100, -107, -113, -999, -999, -999, -999, -999,
  103034. -999, -999, -999, -999, -999, -999, -999, -999,
  103035. -999, -999, -999, -999, -999, -999, -999, -999,
  103036. -999, -999, -999, -999, -999, -999, -999, -999},
  103037. {-999, -999, -999, -999, -999, -999, -999, -107,
  103038. -104, -101, -97, -92, -88, -84, -80, -64,
  103039. -66, -63, -64, -66, -69, -73, -77, -83,
  103040. -83, -86, -91, -98, -104, -111, -999, -999,
  103041. -999, -999, -999, -999, -999, -999, -999, -999,
  103042. -999, -999, -999, -999, -999, -999, -999, -999,
  103043. -999, -999, -999, -999, -999, -999, -999, -999},
  103044. {-999, -999, -999, -999, -999, -999, -999, -107,
  103045. -104, -101, -97, -92, -90, -84, -74, -57,
  103046. -58, -52, -55, -54, -50, -52, -50, -52,
  103047. -63, -62, -69, -76, -77, -78, -78, -79,
  103048. -82, -88, -94, -100, -106, -111, -999, -999,
  103049. -999, -999, -999, -999, -999, -999, -999, -999,
  103050. -999, -999, -999, -999, -999, -999, -999, -999},
  103051. {-999, -999, -999, -999, -999, -999, -106, -102,
  103052. -98, -95, -90, -85, -83, -78, -70, -50,
  103053. -50, -41, -44, -49, -47, -50, -50, -44,
  103054. -55, -46, -47, -48, -48, -54, -49, -49,
  103055. -58, -62, -71, -81, -87, -92, -97, -102,
  103056. -108, -114, -999, -999, -999, -999, -999, -999,
  103057. -999, -999, -999, -999, -999, -999, -999, -999},
  103058. {-999, -999, -999, -999, -999, -999, -106, -102,
  103059. -98, -95, -90, -85, -83, -78, -70, -45,
  103060. -43, -41, -47, -50, -51, -50, -49, -45,
  103061. -47, -41, -44, -41, -39, -43, -38, -37,
  103062. -40, -41, -44, -50, -58, -65, -73, -79,
  103063. -85, -92, -97, -101, -105, -109, -113, -999,
  103064. -999, -999, -999, -999, -999, -999, -999, -999}},
  103065. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103066. -999, -999, -999, -107, -100, -95, -87, -81,
  103067. -85, -83, -88, -93, -100, -107, -114, -999,
  103068. -999, -999, -999, -999, -999, -999, -999, -999,
  103069. -999, -999, -999, -999, -999, -999, -999, -999,
  103070. -999, -999, -999, -999, -999, -999, -999, -999,
  103071. -999, -999, -999, -999, -999, -999, -999, -999},
  103072. {-999, -999, -999, -999, -999, -999, -999, -999,
  103073. -999, -999, -107, -101, -95, -88, -83, -76,
  103074. -73, -72, -79, -84, -90, -95, -100, -105,
  103075. -110, -115, -999, -999, -999, -999, -999, -999,
  103076. -999, -999, -999, -999, -999, -999, -999, -999,
  103077. -999, -999, -999, -999, -999, -999, -999, -999,
  103078. -999, -999, -999, -999, -999, -999, -999, -999},
  103079. {-999, -999, -999, -999, -999, -999, -999, -999,
  103080. -999, -999, -104, -98, -92, -87, -81, -70,
  103081. -65, -62, -67, -71, -74, -80, -85, -91,
  103082. -95, -99, -103, -108, -111, -114, -999, -999,
  103083. -999, -999, -999, -999, -999, -999, -999, -999,
  103084. -999, -999, -999, -999, -999, -999, -999, -999,
  103085. -999, -999, -999, -999, -999, -999, -999, -999},
  103086. {-999, -999, -999, -999, -999, -999, -999, -999,
  103087. -999, -999, -103, -97, -90, -85, -76, -60,
  103088. -56, -54, -60, -62, -61, -56, -63, -65,
  103089. -73, -74, -77, -75, -78, -81, -86, -87,
  103090. -88, -91, -94, -98, -103, -110, -999, -999,
  103091. -999, -999, -999, -999, -999, -999, -999, -999,
  103092. -999, -999, -999, -999, -999, -999, -999, -999},
  103093. {-999, -999, -999, -999, -999, -999, -999, -105,
  103094. -100, -97, -92, -86, -81, -79, -70, -57,
  103095. -51, -47, -51, -58, -60, -56, -53, -50,
  103096. -58, -52, -50, -50, -53, -55, -64, -69,
  103097. -71, -85, -82, -78, -81, -85, -95, -102,
  103098. -112, -999, -999, -999, -999, -999, -999, -999,
  103099. -999, -999, -999, -999, -999, -999, -999, -999},
  103100. {-999, -999, -999, -999, -999, -999, -999, -105,
  103101. -100, -97, -92, -85, -83, -79, -72, -49,
  103102. -40, -43, -43, -54, -56, -51, -50, -40,
  103103. -43, -38, -36, -35, -37, -38, -37, -44,
  103104. -54, -60, -57, -60, -70, -75, -84, -92,
  103105. -103, -112, -999, -999, -999, -999, -999, -999,
  103106. -999, -999, -999, -999, -999, -999, -999, -999}},
  103107. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103108. -999, -999, -999, -110, -102, -95, -89, -82,
  103109. -83, -84, -90, -92, -99, -107, -113, -999,
  103110. -999, -999, -999, -999, -999, -999, -999, -999,
  103111. -999, -999, -999, -999, -999, -999, -999, -999,
  103112. -999, -999, -999, -999, -999, -999, -999, -999,
  103113. -999, -999, -999, -999, -999, -999, -999, -999},
  103114. {-999, -999, -999, -999, -999, -999, -999, -999,
  103115. -999, -999, -107, -101, -95, -89, -83, -72,
  103116. -74, -78, -85, -88, -88, -90, -92, -98,
  103117. -105, -111, -999, -999, -999, -999, -999, -999,
  103118. -999, -999, -999, -999, -999, -999, -999, -999,
  103119. -999, -999, -999, -999, -999, -999, -999, -999,
  103120. -999, -999, -999, -999, -999, -999, -999, -999},
  103121. {-999, -999, -999, -999, -999, -999, -999, -999,
  103122. -999, -109, -103, -97, -93, -87, -81, -70,
  103123. -70, -67, -75, -73, -76, -79, -81, -83,
  103124. -88, -89, -97, -103, -110, -999, -999, -999,
  103125. -999, -999, -999, -999, -999, -999, -999, -999,
  103126. -999, -999, -999, -999, -999, -999, -999, -999,
  103127. -999, -999, -999, -999, -999, -999, -999, -999},
  103128. {-999, -999, -999, -999, -999, -999, -999, -999,
  103129. -999, -107, -100, -94, -88, -83, -75, -63,
  103130. -59, -59, -63, -66, -60, -62, -67, -67,
  103131. -77, -76, -81, -88, -86, -92, -96, -102,
  103132. -109, -116, -999, -999, -999, -999, -999, -999,
  103133. -999, -999, -999, -999, -999, -999, -999, -999,
  103134. -999, -999, -999, -999, -999, -999, -999, -999},
  103135. {-999, -999, -999, -999, -999, -999, -999, -999,
  103136. -999, -105, -98, -92, -86, -81, -73, -56,
  103137. -52, -47, -55, -60, -58, -52, -51, -45,
  103138. -49, -50, -53, -54, -61, -71, -70, -69,
  103139. -78, -79, -87, -90, -96, -104, -112, -999,
  103140. -999, -999, -999, -999, -999, -999, -999, -999,
  103141. -999, -999, -999, -999, -999, -999, -999, -999},
  103142. {-999, -999, -999, -999, -999, -999, -999, -999,
  103143. -999, -103, -96, -90, -86, -78, -70, -51,
  103144. -42, -47, -48, -55, -54, -54, -53, -42,
  103145. -35, -28, -33, -38, -37, -44, -47, -49,
  103146. -54, -63, -68, -78, -82, -89, -94, -99,
  103147. -104, -109, -114, -999, -999, -999, -999, -999,
  103148. -999, -999, -999, -999, -999, -999, -999, -999}},
  103149. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103150. -999, -999, -999, -999, -110, -100, -90, -79,
  103151. -85, -81, -82, -82, -89, -94, -99, -103,
  103152. -109, -115, -999, -999, -999, -999, -999, -999,
  103153. -999, -999, -999, -999, -999, -999, -999, -999,
  103154. -999, -999, -999, -999, -999, -999, -999, -999,
  103155. -999, -999, -999, -999, -999, -999, -999, -999},
  103156. {-999, -999, -999, -999, -999, -999, -999, -999,
  103157. -999, -999, -999, -999, -105, -97, -85, -72,
  103158. -74, -70, -70, -70, -76, -85, -91, -93,
  103159. -97, -103, -109, -115, -999, -999, -999, -999,
  103160. -999, -999, -999, -999, -999, -999, -999, -999,
  103161. -999, -999, -999, -999, -999, -999, -999, -999,
  103162. -999, -999, -999, -999, -999, -999, -999, -999},
  103163. {-999, -999, -999, -999, -999, -999, -999, -999,
  103164. -999, -999, -999, -999, -112, -93, -81, -68,
  103165. -62, -60, -60, -57, -63, -70, -77, -82,
  103166. -90, -93, -98, -104, -109, -113, -999, -999,
  103167. -999, -999, -999, -999, -999, -999, -999, -999,
  103168. -999, -999, -999, -999, -999, -999, -999, -999,
  103169. -999, -999, -999, -999, -999, -999, -999, -999},
  103170. {-999, -999, -999, -999, -999, -999, -999, -999,
  103171. -999, -999, -999, -113, -100, -93, -84, -63,
  103172. -58, -48, -53, -54, -52, -52, -57, -64,
  103173. -66, -76, -83, -81, -85, -85, -90, -95,
  103174. -98, -101, -103, -106, -108, -111, -999, -999,
  103175. -999, -999, -999, -999, -999, -999, -999, -999,
  103176. -999, -999, -999, -999, -999, -999, -999, -999},
  103177. {-999, -999, -999, -999, -999, -999, -999, -999,
  103178. -999, -999, -999, -105, -95, -86, -74, -53,
  103179. -50, -38, -43, -49, -43, -42, -39, -39,
  103180. -46, -52, -57, -56, -72, -69, -74, -81,
  103181. -87, -92, -94, -97, -99, -102, -105, -108,
  103182. -999, -999, -999, -999, -999, -999, -999, -999,
  103183. -999, -999, -999, -999, -999, -999, -999, -999},
  103184. {-999, -999, -999, -999, -999, -999, -999, -999,
  103185. -999, -999, -108, -99, -90, -76, -66, -45,
  103186. -43, -41, -44, -47, -43, -47, -40, -30,
  103187. -31, -31, -39, -33, -40, -41, -43, -53,
  103188. -59, -70, -73, -77, -79, -82, -84, -87,
  103189. -999, -999, -999, -999, -999, -999, -999, -999,
  103190. -999, -999, -999, -999, -999, -999, -999, -999}},
  103191. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103192. -999, -999, -999, -999, -999, -110, -91, -76,
  103193. -75, -85, -93, -98, -104, -110, -999, -999,
  103194. -999, -999, -999, -999, -999, -999, -999, -999,
  103195. -999, -999, -999, -999, -999, -999, -999, -999,
  103196. -999, -999, -999, -999, -999, -999, -999, -999,
  103197. -999, -999, -999, -999, -999, -999, -999, -999},
  103198. {-999, -999, -999, -999, -999, -999, -999, -999,
  103199. -999, -999, -999, -999, -999, -110, -91, -70,
  103200. -70, -75, -86, -89, -94, -98, -101, -106,
  103201. -110, -999, -999, -999, -999, -999, -999, -999,
  103202. -999, -999, -999, -999, -999, -999, -999, -999,
  103203. -999, -999, -999, -999, -999, -999, -999, -999,
  103204. -999, -999, -999, -999, -999, -999, -999, -999},
  103205. {-999, -999, -999, -999, -999, -999, -999, -999,
  103206. -999, -999, -999, -999, -110, -95, -80, -60,
  103207. -65, -64, -74, -83, -88, -91, -95, -99,
  103208. -103, -107, -110, -999, -999, -999, -999, -999,
  103209. -999, -999, -999, -999, -999, -999, -999, -999,
  103210. -999, -999, -999, -999, -999, -999, -999, -999,
  103211. -999, -999, -999, -999, -999, -999, -999, -999},
  103212. {-999, -999, -999, -999, -999, -999, -999, -999,
  103213. -999, -999, -999, -999, -110, -95, -80, -58,
  103214. -55, -49, -66, -68, -71, -78, -78, -80,
  103215. -88, -85, -89, -97, -100, -105, -110, -999,
  103216. -999, -999, -999, -999, -999, -999, -999, -999,
  103217. -999, -999, -999, -999, -999, -999, -999, -999,
  103218. -999, -999, -999, -999, -999, -999, -999, -999},
  103219. {-999, -999, -999, -999, -999, -999, -999, -999,
  103220. -999, -999, -999, -999, -110, -95, -80, -53,
  103221. -52, -41, -59, -59, -49, -58, -56, -63,
  103222. -86, -79, -90, -93, -98, -103, -107, -112,
  103223. -999, -999, -999, -999, -999, -999, -999, -999,
  103224. -999, -999, -999, -999, -999, -999, -999, -999,
  103225. -999, -999, -999, -999, -999, -999, -999, -999},
  103226. {-999, -999, -999, -999, -999, -999, -999, -999,
  103227. -999, -999, -999, -110, -97, -91, -73, -45,
  103228. -40, -33, -53, -61, -49, -54, -50, -50,
  103229. -60, -52, -67, -74, -81, -92, -96, -100,
  103230. -105, -110, -999, -999, -999, -999, -999, -999,
  103231. -999, -999, -999, -999, -999, -999, -999, -999,
  103232. -999, -999, -999, -999, -999, -999, -999, -999}},
  103233. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103234. -999, -999, -999, -113, -106, -99, -92, -77,
  103235. -80, -88, -97, -106, -115, -999, -999, -999,
  103236. -999, -999, -999, -999, -999, -999, -999, -999,
  103237. -999, -999, -999, -999, -999, -999, -999, -999,
  103238. -999, -999, -999, -999, -999, -999, -999, -999,
  103239. -999, -999, -999, -999, -999, -999, -999, -999},
  103240. {-999, -999, -999, -999, -999, -999, -999, -999,
  103241. -999, -999, -116, -109, -102, -95, -89, -74,
  103242. -72, -88, -87, -95, -102, -109, -116, -999,
  103243. -999, -999, -999, -999, -999, -999, -999, -999,
  103244. -999, -999, -999, -999, -999, -999, -999, -999,
  103245. -999, -999, -999, -999, -999, -999, -999, -999,
  103246. -999, -999, -999, -999, -999, -999, -999, -999},
  103247. {-999, -999, -999, -999, -999, -999, -999, -999,
  103248. -999, -999, -116, -109, -102, -95, -89, -75,
  103249. -66, -74, -77, -78, -86, -87, -90, -96,
  103250. -105, -115, -999, -999, -999, -999, -999, -999,
  103251. -999, -999, -999, -999, -999, -999, -999, -999,
  103252. -999, -999, -999, -999, -999, -999, -999, -999,
  103253. -999, -999, -999, -999, -999, -999, -999, -999},
  103254. {-999, -999, -999, -999, -999, -999, -999, -999,
  103255. -999, -999, -115, -108, -101, -94, -88, -66,
  103256. -56, -61, -70, -65, -78, -72, -83, -84,
  103257. -93, -98, -105, -110, -999, -999, -999, -999,
  103258. -999, -999, -999, -999, -999, -999, -999, -999,
  103259. -999, -999, -999, -999, -999, -999, -999, -999,
  103260. -999, -999, -999, -999, -999, -999, -999, -999},
  103261. {-999, -999, -999, -999, -999, -999, -999, -999,
  103262. -999, -999, -110, -105, -95, -89, -82, -57,
  103263. -52, -52, -59, -56, -59, -58, -69, -67,
  103264. -88, -82, -82, -89, -94, -100, -108, -999,
  103265. -999, -999, -999, -999, -999, -999, -999, -999,
  103266. -999, -999, -999, -999, -999, -999, -999, -999,
  103267. -999, -999, -999, -999, -999, -999, -999, -999},
  103268. {-999, -999, -999, -999, -999, -999, -999, -999,
  103269. -999, -110, -101, -96, -90, -83, -77, -54,
  103270. -43, -38, -50, -48, -52, -48, -42, -42,
  103271. -51, -52, -53, -59, -65, -71, -78, -85,
  103272. -95, -999, -999, -999, -999, -999, -999, -999,
  103273. -999, -999, -999, -999, -999, -999, -999, -999,
  103274. -999, -999, -999, -999, -999, -999, -999, -999}},
  103275. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103276. -999, -999, -999, -999, -120, -105, -86, -68,
  103277. -78, -79, -90, -100, -110, -999, -999, -999,
  103278. -999, -999, -999, -999, -999, -999, -999, -999,
  103279. -999, -999, -999, -999, -999, -999, -999, -999,
  103280. -999, -999, -999, -999, -999, -999, -999, -999,
  103281. -999, -999, -999, -999, -999, -999, -999, -999},
  103282. {-999, -999, -999, -999, -999, -999, -999, -999,
  103283. -999, -999, -999, -999, -120, -105, -86, -66,
  103284. -73, -77, -88, -96, -105, -115, -999, -999,
  103285. -999, -999, -999, -999, -999, -999, -999, -999,
  103286. -999, -999, -999, -999, -999, -999, -999, -999,
  103287. -999, -999, -999, -999, -999, -999, -999, -999,
  103288. -999, -999, -999, -999, -999, -999, -999, -999},
  103289. {-999, -999, -999, -999, -999, -999, -999, -999,
  103290. -999, -999, -999, -120, -105, -92, -80, -61,
  103291. -64, -68, -80, -87, -92, -100, -110, -999,
  103292. -999, -999, -999, -999, -999, -999, -999, -999,
  103293. -999, -999, -999, -999, -999, -999, -999, -999,
  103294. -999, -999, -999, -999, -999, -999, -999, -999,
  103295. -999, -999, -999, -999, -999, -999, -999, -999},
  103296. {-999, -999, -999, -999, -999, -999, -999, -999,
  103297. -999, -999, -999, -120, -104, -91, -79, -52,
  103298. -60, -54, -64, -69, -77, -80, -82, -84,
  103299. -85, -87, -88, -90, -999, -999, -999, -999,
  103300. -999, -999, -999, -999, -999, -999, -999, -999,
  103301. -999, -999, -999, -999, -999, -999, -999, -999,
  103302. -999, -999, -999, -999, -999, -999, -999, -999},
  103303. {-999, -999, -999, -999, -999, -999, -999, -999,
  103304. -999, -999, -999, -118, -100, -87, -77, -49,
  103305. -50, -44, -58, -61, -61, -67, -65, -62,
  103306. -62, -62, -65, -68, -999, -999, -999, -999,
  103307. -999, -999, -999, -999, -999, -999, -999, -999,
  103308. -999, -999, -999, -999, -999, -999, -999, -999,
  103309. -999, -999, -999, -999, -999, -999, -999, -999},
  103310. {-999, -999, -999, -999, -999, -999, -999, -999,
  103311. -999, -999, -999, -115, -98, -84, -62, -49,
  103312. -44, -38, -46, -49, -49, -46, -39, -37,
  103313. -39, -40, -42, -43, -999, -999, -999, -999,
  103314. -999, -999, -999, -999, -999, -999, -999, -999,
  103315. -999, -999, -999, -999, -999, -999, -999, -999,
  103316. -999, -999, -999, -999, -999, -999, -999, -999}},
  103317. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103318. -999, -999, -999, -999, -999, -110, -88, -74,
  103319. -77, -82, -82, -85, -90, -94, -99, -104,
  103320. -999, -999, -999, -999, -999, -999, -999, -999,
  103321. -999, -999, -999, -999, -999, -999, -999, -999,
  103322. -999, -999, -999, -999, -999, -999, -999, -999,
  103323. -999, -999, -999, -999, -999, -999, -999, -999},
  103324. {-999, -999, -999, -999, -999, -999, -999, -999,
  103325. -999, -999, -999, -999, -999, -110, -88, -66,
  103326. -70, -81, -80, -81, -84, -88, -91, -93,
  103327. -999, -999, -999, -999, -999, -999, -999, -999,
  103328. -999, -999, -999, -999, -999, -999, -999, -999,
  103329. -999, -999, -999, -999, -999, -999, -999, -999,
  103330. -999, -999, -999, -999, -999, -999, -999, -999},
  103331. {-999, -999, -999, -999, -999, -999, -999, -999,
  103332. -999, -999, -999, -999, -999, -110, -88, -61,
  103333. -63, -70, -71, -74, -77, -80, -83, -85,
  103334. -999, -999, -999, -999, -999, -999, -999, -999,
  103335. -999, -999, -999, -999, -999, -999, -999, -999,
  103336. -999, -999, -999, -999, -999, -999, -999, -999,
  103337. -999, -999, -999, -999, -999, -999, -999, -999},
  103338. {-999, -999, -999, -999, -999, -999, -999, -999,
  103339. -999, -999, -999, -999, -999, -110, -86, -62,
  103340. -63, -62, -62, -58, -52, -50, -50, -52,
  103341. -54, -999, -999, -999, -999, -999, -999, -999,
  103342. -999, -999, -999, -999, -999, -999, -999, -999,
  103343. -999, -999, -999, -999, -999, -999, -999, -999,
  103344. -999, -999, -999, -999, -999, -999, -999, -999},
  103345. {-999, -999, -999, -999, -999, -999, -999, -999,
  103346. -999, -999, -999, -999, -118, -108, -84, -53,
  103347. -50, -50, -50, -55, -47, -45, -40, -40,
  103348. -40, -999, -999, -999, -999, -999, -999, -999,
  103349. -999, -999, -999, -999, -999, -999, -999, -999,
  103350. -999, -999, -999, -999, -999, -999, -999, -999,
  103351. -999, -999, -999, -999, -999, -999, -999, -999},
  103352. {-999, -999, -999, -999, -999, -999, -999, -999,
  103353. -999, -999, -999, -999, -118, -100, -73, -43,
  103354. -37, -42, -43, -53, -38, -37, -35, -35,
  103355. -38, -999, -999, -999, -999, -999, -999, -999,
  103356. -999, -999, -999, -999, -999, -999, -999, -999,
  103357. -999, -999, -999, -999, -999, -999, -999, -999,
  103358. -999, -999, -999, -999, -999, -999, -999, -999}},
  103359. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103360. -999, -999, -999, -110, -100, -91, -84, -74,
  103361. -80, -80, -80, -80, -80, -999, -999, -999,
  103362. -999, -999, -999, -999, -999, -999, -999, -999,
  103363. -999, -999, -999, -999, -999, -999, -999, -999,
  103364. -999, -999, -999, -999, -999, -999, -999, -999,
  103365. -999, -999, -999, -999, -999, -999, -999, -999},
  103366. {-999, -999, -999, -999, -999, -999, -999, -999,
  103367. -999, -999, -999, -110, -100, -91, -84, -74,
  103368. -68, -68, -68, -68, -68, -999, -999, -999,
  103369. -999, -999, -999, -999, -999, -999, -999, -999,
  103370. -999, -999, -999, -999, -999, -999, -999, -999,
  103371. -999, -999, -999, -999, -999, -999, -999, -999,
  103372. -999, -999, -999, -999, -999, -999, -999, -999},
  103373. {-999, -999, -999, -999, -999, -999, -999, -999,
  103374. -999, -999, -999, -110, -100, -86, -78, -70,
  103375. -60, -45, -30, -21, -999, -999, -999, -999,
  103376. -999, -999, -999, -999, -999, -999, -999, -999,
  103377. -999, -999, -999, -999, -999, -999, -999, -999,
  103378. -999, -999, -999, -999, -999, -999, -999, -999,
  103379. -999, -999, -999, -999, -999, -999, -999, -999},
  103380. {-999, -999, -999, -999, -999, -999, -999, -999,
  103381. -999, -999, -999, -110, -100, -87, -78, -67,
  103382. -48, -38, -29, -21, -999, -999, -999, -999,
  103383. -999, -999, -999, -999, -999, -999, -999, -999,
  103384. -999, -999, -999, -999, -999, -999, -999, -999,
  103385. -999, -999, -999, -999, -999, -999, -999, -999,
  103386. -999, -999, -999, -999, -999, -999, -999, -999},
  103387. {-999, -999, -999, -999, -999, -999, -999, -999,
  103388. -999, -999, -999, -110, -100, -86, -69, -56,
  103389. -45, -35, -33, -29, -999, -999, -999, -999,
  103390. -999, -999, -999, -999, -999, -999, -999, -999,
  103391. -999, -999, -999, -999, -999, -999, -999, -999,
  103392. -999, -999, -999, -999, -999, -999, -999, -999,
  103393. -999, -999, -999, -999, -999, -999, -999, -999},
  103394. {-999, -999, -999, -999, -999, -999, -999, -999,
  103395. -999, -999, -999, -110, -100, -83, -71, -48,
  103396. -27, -38, -37, -34, -999, -999, -999, -999,
  103397. -999, -999, -999, -999, -999, -999, -999, -999,
  103398. -999, -999, -999, -999, -999, -999, -999, -999,
  103399. -999, -999, -999, -999, -999, -999, -999, -999,
  103400. -999, -999, -999, -999, -999, -999, -999, -999}}
  103401. };
  103402. #endif
  103403. /*** End of inlined file: masking.h ***/
  103404. #define NEGINF -9999.f
  103405. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103406. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103407. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103408. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103409. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103410. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103411. look->channels=vi->channels;
  103412. look->ampmax=-9999.;
  103413. look->gi=gi;
  103414. return(look);
  103415. }
  103416. void _vp_global_free(vorbis_look_psy_global *look){
  103417. if(look){
  103418. memset(look,0,sizeof(*look));
  103419. _ogg_free(look);
  103420. }
  103421. }
  103422. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103423. if(i){
  103424. memset(i,0,sizeof(*i));
  103425. _ogg_free(i);
  103426. }
  103427. }
  103428. void _vi_psy_free(vorbis_info_psy *i){
  103429. if(i){
  103430. memset(i,0,sizeof(*i));
  103431. _ogg_free(i);
  103432. }
  103433. }
  103434. static void min_curve(float *c,
  103435. float *c2){
  103436. int i;
  103437. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103438. }
  103439. static void max_curve(float *c,
  103440. float *c2){
  103441. int i;
  103442. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103443. }
  103444. static void attenuate_curve(float *c,float att){
  103445. int i;
  103446. for(i=0;i<EHMER_MAX;i++)
  103447. c[i]+=att;
  103448. }
  103449. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103450. float center_boost, float center_decay_rate){
  103451. int i,j,k,m;
  103452. float ath[EHMER_MAX];
  103453. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103454. float athc[P_LEVELS][EHMER_MAX];
  103455. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103456. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103457. memset(workc,0,sizeof(workc));
  103458. for(i=0;i<P_BANDS;i++){
  103459. int ath_offset=i*4;
  103460. for(j=0;j<EHMER_MAX;j++){
  103461. float min=999.;
  103462. for(k=0;k<4;k++)
  103463. if(j+k+ath_offset<MAX_ATH){
  103464. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103465. }else{
  103466. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103467. }
  103468. ath[j]=min;
  103469. }
  103470. for(j=0;j<6;j++)
  103471. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103472. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103473. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103474. for(j=0;j<P_LEVELS;j++){
  103475. for(k=0;k<EHMER_MAX;k++){
  103476. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103477. if(adj<0. && center_boost>0)adj=0.;
  103478. if(adj>0. && center_boost<0)adj=0.;
  103479. workc[i][j][k]+=adj;
  103480. }
  103481. }
  103482. for(j=0;j<P_LEVELS;j++){
  103483. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103484. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103485. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103486. max_curve(athc[j],workc[i][j]);
  103487. }
  103488. for(j=1;j<P_LEVELS;j++){
  103489. min_curve(athc[j],athc[j-1]);
  103490. min_curve(workc[i][j],athc[j]);
  103491. }
  103492. }
  103493. for(i=0;i<P_BANDS;i++){
  103494. int hi_curve,lo_curve,bin;
  103495. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103496. bin=floor(fromOC(i*.5)/binHz);
  103497. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103498. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103499. if(lo_curve>i)lo_curve=i;
  103500. if(lo_curve<0)lo_curve=0;
  103501. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103502. for(m=0;m<P_LEVELS;m++){
  103503. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103504. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103505. for(k=lo_curve;k<=hi_curve;k++){
  103506. int l=0;
  103507. for(j=0;j<EHMER_MAX;j++){
  103508. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103509. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103510. if(lo_bin<0)lo_bin=0;
  103511. if(lo_bin>n)lo_bin=n;
  103512. if(lo_bin<l)l=lo_bin;
  103513. if(hi_bin<0)hi_bin=0;
  103514. if(hi_bin>n)hi_bin=n;
  103515. for(;l<hi_bin && l<n;l++)
  103516. if(brute_buffer[l]>workc[k][m][j])
  103517. brute_buffer[l]=workc[k][m][j];
  103518. }
  103519. for(;l<n;l++)
  103520. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103521. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103522. }
  103523. if(i+1<P_BANDS){
  103524. int l=0;
  103525. k=i+1;
  103526. for(j=0;j<EHMER_MAX;j++){
  103527. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103528. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103529. if(lo_bin<0)lo_bin=0;
  103530. if(lo_bin>n)lo_bin=n;
  103531. if(lo_bin<l)l=lo_bin;
  103532. if(hi_bin<0)hi_bin=0;
  103533. if(hi_bin>n)hi_bin=n;
  103534. for(;l<hi_bin && l<n;l++)
  103535. if(brute_buffer[l]>workc[k][m][j])
  103536. brute_buffer[l]=workc[k][m][j];
  103537. }
  103538. for(;l<n;l++)
  103539. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103540. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103541. }
  103542. for(j=0;j<EHMER_MAX;j++){
  103543. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103544. if(bin<0){
  103545. ret[i][m][j+2]=-999.;
  103546. }else{
  103547. if(bin>=n){
  103548. ret[i][m][j+2]=-999.;
  103549. }else{
  103550. ret[i][m][j+2]=brute_buffer[bin];
  103551. }
  103552. }
  103553. }
  103554. for(j=0;j<EHMER_OFFSET;j++)
  103555. if(ret[i][m][j+2]>-200.f)break;
  103556. ret[i][m][0]=j;
  103557. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103558. if(ret[i][m][j+2]>-200.f)
  103559. break;
  103560. ret[i][m][1]=j;
  103561. }
  103562. }
  103563. return(ret);
  103564. }
  103565. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103566. vorbis_info_psy_global *gi,int n,long rate){
  103567. long i,j,lo=-99,hi=1;
  103568. long maxoc;
  103569. memset(p,0,sizeof(*p));
  103570. p->eighth_octave_lines=gi->eighth_octave_lines;
  103571. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103572. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103573. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103574. p->total_octave_lines=maxoc-p->firstoc+1;
  103575. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103576. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103577. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103578. p->vi=vi;
  103579. p->n=n;
  103580. p->rate=rate;
  103581. p->m_val = 1.;
  103582. if(rate < 26000) p->m_val = 0;
  103583. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103584. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103585. for(i=0,j=0;i<MAX_ATH-1;i++){
  103586. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103587. float base=ATH[i];
  103588. if(j<endpos){
  103589. float delta=(ATH[i+1]-base)/(endpos-j);
  103590. for(;j<endpos && j<n;j++){
  103591. p->ath[j]=base+100.;
  103592. base+=delta;
  103593. }
  103594. }
  103595. }
  103596. for(i=0;i<n;i++){
  103597. float bark=toBARK(rate/(2*n)*i);
  103598. for(;lo+vi->noisewindowlomin<i &&
  103599. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103600. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103601. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103602. p->bark[i]=((lo-1)<<16)+(hi-1);
  103603. }
  103604. for(i=0;i<n;i++)
  103605. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103606. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103607. vi->tone_centerboost,vi->tone_decay);
  103608. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103609. for(i=0;i<P_NOISECURVES;i++)
  103610. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103611. for(i=0;i<n;i++){
  103612. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103613. int inthalfoc;
  103614. float del;
  103615. if(halfoc<0)halfoc=0;
  103616. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103617. inthalfoc=(int)halfoc;
  103618. del=halfoc-inthalfoc;
  103619. for(j=0;j<P_NOISECURVES;j++)
  103620. p->noiseoffset[j][i]=
  103621. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103622. p->vi->noiseoff[j][inthalfoc+1]*del;
  103623. }
  103624. #if 0
  103625. {
  103626. static int ls=0;
  103627. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103628. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103629. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103630. }
  103631. #endif
  103632. }
  103633. void _vp_psy_clear(vorbis_look_psy *p){
  103634. int i,j;
  103635. if(p){
  103636. if(p->ath)_ogg_free(p->ath);
  103637. if(p->octave)_ogg_free(p->octave);
  103638. if(p->bark)_ogg_free(p->bark);
  103639. if(p->tonecurves){
  103640. for(i=0;i<P_BANDS;i++){
  103641. for(j=0;j<P_LEVELS;j++){
  103642. _ogg_free(p->tonecurves[i][j]);
  103643. }
  103644. _ogg_free(p->tonecurves[i]);
  103645. }
  103646. _ogg_free(p->tonecurves);
  103647. }
  103648. if(p->noiseoffset){
  103649. for(i=0;i<P_NOISECURVES;i++){
  103650. _ogg_free(p->noiseoffset[i]);
  103651. }
  103652. _ogg_free(p->noiseoffset);
  103653. }
  103654. memset(p,0,sizeof(*p));
  103655. }
  103656. }
  103657. static void seed_curve(float *seed,
  103658. const float **curves,
  103659. float amp,
  103660. int oc, int n,
  103661. int linesper,float dBoffset){
  103662. int i,post1;
  103663. int seedptr;
  103664. const float *posts,*curve;
  103665. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103666. choice=max(choice,0);
  103667. choice=min(choice,P_LEVELS-1);
  103668. posts=curves[choice];
  103669. curve=posts+2;
  103670. post1=(int)posts[1];
  103671. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103672. for(i=posts[0];i<post1;i++){
  103673. if(seedptr>0){
  103674. float lin=amp+curve[i];
  103675. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103676. }
  103677. seedptr+=linesper;
  103678. if(seedptr>=n)break;
  103679. }
  103680. }
  103681. static void seed_loop(vorbis_look_psy *p,
  103682. const float ***curves,
  103683. const float *f,
  103684. const float *flr,
  103685. float *seed,
  103686. float specmax){
  103687. vorbis_info_psy *vi=p->vi;
  103688. long n=p->n,i;
  103689. float dBoffset=vi->max_curve_dB-specmax;
  103690. for(i=0;i<n;i++){
  103691. float max=f[i];
  103692. long oc=p->octave[i];
  103693. while(i+1<n && p->octave[i+1]==oc){
  103694. i++;
  103695. if(f[i]>max)max=f[i];
  103696. }
  103697. if(max+6.f>flr[i]){
  103698. oc=oc>>p->shiftoc;
  103699. if(oc>=P_BANDS)oc=P_BANDS-1;
  103700. if(oc<0)oc=0;
  103701. seed_curve(seed,
  103702. curves[oc],
  103703. max,
  103704. p->octave[i]-p->firstoc,
  103705. p->total_octave_lines,
  103706. p->eighth_octave_lines,
  103707. dBoffset);
  103708. }
  103709. }
  103710. }
  103711. static void seed_chase(float *seeds, int linesper, long n){
  103712. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103713. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103714. long stack=0;
  103715. long pos=0;
  103716. long i;
  103717. for(i=0;i<n;i++){
  103718. if(stack<2){
  103719. posstack[stack]=i;
  103720. ampstack[stack++]=seeds[i];
  103721. }else{
  103722. while(1){
  103723. if(seeds[i]<ampstack[stack-1]){
  103724. posstack[stack]=i;
  103725. ampstack[stack++]=seeds[i];
  103726. break;
  103727. }else{
  103728. if(i<posstack[stack-1]+linesper){
  103729. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103730. i<posstack[stack-2]+linesper){
  103731. stack--;
  103732. continue;
  103733. }
  103734. }
  103735. posstack[stack]=i;
  103736. ampstack[stack++]=seeds[i];
  103737. break;
  103738. }
  103739. }
  103740. }
  103741. }
  103742. for(i=0;i<stack;i++){
  103743. long endpos;
  103744. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103745. endpos=posstack[i+1];
  103746. }else{
  103747. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103748. discarded in short frames */
  103749. }
  103750. if(endpos>n)endpos=n;
  103751. for(;pos<endpos;pos++)
  103752. seeds[pos]=ampstack[i];
  103753. }
  103754. }
  103755. #include<stdio.h>
  103756. static void max_seeds(vorbis_look_psy *p,
  103757. float *seed,
  103758. float *flr){
  103759. long n=p->total_octave_lines;
  103760. int linesper=p->eighth_octave_lines;
  103761. long linpos=0;
  103762. long pos;
  103763. seed_chase(seed,linesper,n); /* for masking */
  103764. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103765. while(linpos+1<p->n){
  103766. float minV=seed[pos];
  103767. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103768. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103769. while(pos+1<=end){
  103770. pos++;
  103771. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103772. minV=seed[pos];
  103773. }
  103774. end=pos+p->firstoc;
  103775. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103776. if(flr[linpos]<minV)flr[linpos]=minV;
  103777. }
  103778. {
  103779. float minV=seed[p->total_octave_lines-1];
  103780. for(;linpos<p->n;linpos++)
  103781. if(flr[linpos]<minV)flr[linpos]=minV;
  103782. }
  103783. }
  103784. static void bark_noise_hybridmp(int n,const long *b,
  103785. const float *f,
  103786. float *noise,
  103787. const float offset,
  103788. const int fixed){
  103789. float *N=(float*) alloca(n*sizeof(*N));
  103790. float *X=(float*) alloca(n*sizeof(*N));
  103791. float *XX=(float*) alloca(n*sizeof(*N));
  103792. float *Y=(float*) alloca(n*sizeof(*N));
  103793. float *XY=(float*) alloca(n*sizeof(*N));
  103794. float tN, tX, tXX, tY, tXY;
  103795. int i;
  103796. int lo, hi;
  103797. float R, A, B, D;
  103798. float w, x, y;
  103799. tN = tX = tXX = tY = tXY = 0.f;
  103800. y = f[0] + offset;
  103801. if (y < 1.f) y = 1.f;
  103802. w = y * y * .5;
  103803. tN += w;
  103804. tX += w;
  103805. tY += w * y;
  103806. N[0] = tN;
  103807. X[0] = tX;
  103808. XX[0] = tXX;
  103809. Y[0] = tY;
  103810. XY[0] = tXY;
  103811. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103812. y = f[i] + offset;
  103813. if (y < 1.f) y = 1.f;
  103814. w = y * y;
  103815. tN += w;
  103816. tX += w * x;
  103817. tXX += w * x * x;
  103818. tY += w * y;
  103819. tXY += w * x * y;
  103820. N[i] = tN;
  103821. X[i] = tX;
  103822. XX[i] = tXX;
  103823. Y[i] = tY;
  103824. XY[i] = tXY;
  103825. }
  103826. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103827. lo = b[i] >> 16;
  103828. if( lo>=0 ) break;
  103829. hi = b[i] & 0xffff;
  103830. tN = N[hi] + N[-lo];
  103831. tX = X[hi] - X[-lo];
  103832. tXX = XX[hi] + XX[-lo];
  103833. tY = Y[hi] + Y[-lo];
  103834. tXY = XY[hi] - XY[-lo];
  103835. A = tY * tXX - tX * tXY;
  103836. B = tN * tXY - tX * tY;
  103837. D = tN * tXX - tX * tX;
  103838. R = (A + x * B) / D;
  103839. if (R < 0.f)
  103840. R = 0.f;
  103841. noise[i] = R - offset;
  103842. }
  103843. for ( ;; i++, x += 1.f) {
  103844. lo = b[i] >> 16;
  103845. hi = b[i] & 0xffff;
  103846. if(hi>=n)break;
  103847. tN = N[hi] - N[lo];
  103848. tX = X[hi] - X[lo];
  103849. tXX = XX[hi] - XX[lo];
  103850. tY = Y[hi] - Y[lo];
  103851. tXY = XY[hi] - XY[lo];
  103852. A = tY * tXX - tX * tXY;
  103853. B = tN * tXY - tX * tY;
  103854. D = tN * tXX - tX * tX;
  103855. R = (A + x * B) / D;
  103856. if (R < 0.f) R = 0.f;
  103857. noise[i] = R - offset;
  103858. }
  103859. for ( ; i < n; i++, x += 1.f) {
  103860. R = (A + x * B) / D;
  103861. if (R < 0.f) R = 0.f;
  103862. noise[i] = R - offset;
  103863. }
  103864. if (fixed <= 0) return;
  103865. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103866. hi = i + fixed / 2;
  103867. lo = hi - fixed;
  103868. if(lo>=0)break;
  103869. tN = N[hi] + N[-lo];
  103870. tX = X[hi] - X[-lo];
  103871. tXX = XX[hi] + XX[-lo];
  103872. tY = Y[hi] + Y[-lo];
  103873. tXY = XY[hi] - XY[-lo];
  103874. A = tY * tXX - tX * tXY;
  103875. B = tN * tXY - tX * tY;
  103876. D = tN * tXX - tX * tX;
  103877. R = (A + x * B) / D;
  103878. if (R - offset < noise[i]) noise[i] = R - offset;
  103879. }
  103880. for ( ;; i++, x += 1.f) {
  103881. hi = i + fixed / 2;
  103882. lo = hi - fixed;
  103883. if(hi>=n)break;
  103884. tN = N[hi] - N[lo];
  103885. tX = X[hi] - X[lo];
  103886. tXX = XX[hi] - XX[lo];
  103887. tY = Y[hi] - Y[lo];
  103888. tXY = XY[hi] - XY[lo];
  103889. A = tY * tXX - tX * tXY;
  103890. B = tN * tXY - tX * tY;
  103891. D = tN * tXX - tX * tX;
  103892. R = (A + x * B) / D;
  103893. if (R - offset < noise[i]) noise[i] = R - offset;
  103894. }
  103895. for ( ; i < n; i++, x += 1.f) {
  103896. R = (A + x * B) / D;
  103897. if (R - offset < noise[i]) noise[i] = R - offset;
  103898. }
  103899. }
  103900. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103901. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103902. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103903. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103904. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103905. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103906. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103907. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103908. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103909. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103910. 973377.F, 913981.F, 858210.F, 805842.F,
  103911. 756669.F, 710497.F, 667142.F, 626433.F,
  103912. 588208.F, 552316.F, 518613.F, 486967.F,
  103913. 457252.F, 429351.F, 403152.F, 378551.F,
  103914. 355452.F, 333762.F, 313396.F, 294273.F,
  103915. 276316.F, 259455.F, 243623.F, 228757.F,
  103916. 214798.F, 201691.F, 189384.F, 177828.F,
  103917. 166977.F, 156788.F, 147221.F, 138237.F,
  103918. 129802.F, 121881.F, 114444.F, 107461.F,
  103919. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103920. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103921. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103922. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103923. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103924. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103925. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103926. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103927. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103928. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103929. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103930. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103931. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103932. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103933. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103934. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103935. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103936. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103937. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103938. 842.910F, 791.475F, 743.179F, 697.830F,
  103939. 655.249F, 615.265F, 577.722F, 542.469F,
  103940. 509.367F, 478.286F, 449.101F, 421.696F,
  103941. 395.964F, 371.803F, 349.115F, 327.812F,
  103942. 307.809F, 289.026F, 271.390F, 254.830F,
  103943. 239.280F, 224.679F, 210.969F, 198.096F,
  103944. 186.008F, 174.658F, 164.000F, 153.993F,
  103945. 144.596F, 135.773F, 127.488F, 119.708F,
  103946. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103947. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103948. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103949. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103950. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103951. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103952. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103953. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103954. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103955. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103956. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103957. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103958. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103959. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103960. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103961. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103962. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103963. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103964. 1.20790F, 1.13419F, 1.06499F, 1.F
  103965. };
  103966. void _vp_remove_floor(vorbis_look_psy *p,
  103967. float *mdct,
  103968. int *codedflr,
  103969. float *residue,
  103970. int sliding_lowpass){
  103971. int i,n=p->n;
  103972. if(sliding_lowpass>n)sliding_lowpass=n;
  103973. for(i=0;i<sliding_lowpass;i++){
  103974. residue[i]=
  103975. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103976. }
  103977. for(;i<n;i++)
  103978. residue[i]=0.;
  103979. }
  103980. void _vp_noisemask(vorbis_look_psy *p,
  103981. float *logmdct,
  103982. float *logmask){
  103983. int i,n=p->n;
  103984. float *work=(float*) alloca(n*sizeof(*work));
  103985. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103986. 140.,-1);
  103987. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103988. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103989. p->vi->noisewindowfixed);
  103990. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103991. #if 0
  103992. {
  103993. static int seq=0;
  103994. float work2[n];
  103995. for(i=0;i<n;i++){
  103996. work2[i]=logmask[i]+work[i];
  103997. }
  103998. if(seq&1)
  103999. _analysis_output("median2R",seq/2,work,n,1,0,0);
  104000. else
  104001. _analysis_output("median2L",seq/2,work,n,1,0,0);
  104002. if(seq&1)
  104003. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  104004. else
  104005. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  104006. seq++;
  104007. }
  104008. #endif
  104009. for(i=0;i<n;i++){
  104010. int dB=logmask[i]+.5;
  104011. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  104012. if(dB<0)dB=0;
  104013. logmask[i]= work[i]+p->vi->noisecompand[dB];
  104014. }
  104015. }
  104016. void _vp_tonemask(vorbis_look_psy *p,
  104017. float *logfft,
  104018. float *logmask,
  104019. float global_specmax,
  104020. float local_specmax){
  104021. int i,n=p->n;
  104022. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  104023. float att=local_specmax+p->vi->ath_adjatt;
  104024. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  104025. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  104026. for(i=0;i<n;i++)
  104027. logmask[i]=p->ath[i]+att;
  104028. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  104029. max_seeds(p,seed,logmask);
  104030. }
  104031. void _vp_offset_and_mix(vorbis_look_psy *p,
  104032. float *noise,
  104033. float *tone,
  104034. int offset_select,
  104035. float *logmask,
  104036. float *mdct,
  104037. float *logmdct){
  104038. int i,n=p->n;
  104039. float de, coeffi, cx;/* AoTuV */
  104040. float toneatt=p->vi->tone_masteratt[offset_select];
  104041. cx = p->m_val;
  104042. for(i=0;i<n;i++){
  104043. float val= noise[i]+p->noiseoffset[offset_select][i];
  104044. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  104045. logmask[i]=max(val,tone[i]+toneatt);
  104046. if(offset_select == 1) {
  104047. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  104048. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  104049. if(val > coeffi){
  104050. de = 1.0-((val-coeffi)*0.005*cx);
  104051. if(de < 0) de = 0.0001;
  104052. }else
  104053. de = 1.0-((val-coeffi)*0.0003*cx);
  104054. mdct[i] *= de;
  104055. }
  104056. }
  104057. }
  104058. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  104059. vorbis_info *vi=vd->vi;
  104060. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  104061. vorbis_info_psy_global *gi=&ci->psy_g_param;
  104062. int n=ci->blocksizes[vd->W]/2;
  104063. float secs=(float)n/vi->rate;
  104064. amp+=secs*gi->ampmax_att_per_sec;
  104065. if(amp<-9999)amp=-9999;
  104066. return(amp);
  104067. }
  104068. static void couple_lossless(float A, float B,
  104069. float *qA, float *qB){
  104070. int test1=fabs(*qA)>fabs(*qB);
  104071. test1-= fabs(*qA)<fabs(*qB);
  104072. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  104073. if(test1==1){
  104074. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  104075. }else{
  104076. float temp=*qB;
  104077. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  104078. *qA=temp;
  104079. }
  104080. if(*qB>fabs(*qA)*1.9999f){
  104081. *qB= -fabs(*qA)*2.f;
  104082. *qA= -*qA;
  104083. }
  104084. }
  104085. static float hypot_lookup[32]={
  104086. -0.009935, -0.011245, -0.012726, -0.014397,
  104087. -0.016282, -0.018407, -0.020800, -0.023494,
  104088. -0.026522, -0.029923, -0.033737, -0.038010,
  104089. -0.042787, -0.048121, -0.054064, -0.060671,
  104090. -0.068000, -0.076109, -0.085054, -0.094892,
  104091. -0.105675, -0.117451, -0.130260, -0.144134,
  104092. -0.159093, -0.175146, -0.192286, -0.210490,
  104093. -0.229718, -0.249913, -0.271001, -0.292893};
  104094. static void precomputed_couple_point(float premag,
  104095. int floorA,int floorB,
  104096. float *mag, float *ang){
  104097. int test=(floorA>floorB)-1;
  104098. int offset=31-abs(floorA-floorB);
  104099. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  104100. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  104101. *mag=premag*floormag;
  104102. *ang=0.f;
  104103. }
  104104. static float dipole_hypot(float a, float b){
  104105. if(a>0.){
  104106. if(b>0.)return sqrt(a*a+b*b);
  104107. if(a>-b)return sqrt(a*a-b*b);
  104108. return -sqrt(b*b-a*a);
  104109. }
  104110. if(b<0.)return -sqrt(a*a+b*b);
  104111. if(-a>b)return -sqrt(a*a-b*b);
  104112. return sqrt(b*b-a*a);
  104113. }
  104114. static float round_hypot(float a, float b){
  104115. if(a>0.){
  104116. if(b>0.)return sqrt(a*a+b*b);
  104117. if(a>-b)return sqrt(a*a+b*b);
  104118. return -sqrt(b*b+a*a);
  104119. }
  104120. if(b<0.)return -sqrt(a*a+b*b);
  104121. if(-a>b)return -sqrt(a*a+b*b);
  104122. return sqrt(b*b+a*a);
  104123. }
  104124. float **_vp_quantize_couple_memo(vorbis_block *vb,
  104125. vorbis_info_psy_global *g,
  104126. vorbis_look_psy *p,
  104127. vorbis_info_mapping0 *vi,
  104128. float **mdct){
  104129. int i,j,n=p->n;
  104130. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104131. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104132. for(i=0;i<vi->coupling_steps;i++){
  104133. float *mdctM=mdct[vi->coupling_mag[i]];
  104134. float *mdctA=mdct[vi->coupling_ang[i]];
  104135. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104136. for(j=0;j<limit;j++)
  104137. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  104138. for(;j<n;j++)
  104139. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  104140. }
  104141. return(ret);
  104142. }
  104143. static int apsort(const void *a, const void *b){
  104144. float f1=fabs(**(float**)a);
  104145. float f2=fabs(**(float**)b);
  104146. return (f1<f2)-(f1>f2);
  104147. }
  104148. int **_vp_quantize_couple_sort(vorbis_block *vb,
  104149. vorbis_look_psy *p,
  104150. vorbis_info_mapping0 *vi,
  104151. float **mags){
  104152. if(p->vi->normal_point_p){
  104153. int i,j,k,n=p->n;
  104154. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104155. int partition=p->vi->normal_partition;
  104156. float **work=(float**) alloca(sizeof(*work)*partition);
  104157. for(i=0;i<vi->coupling_steps;i++){
  104158. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104159. for(j=0;j<n;j+=partition){
  104160. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  104161. qsort(work,partition,sizeof(*work),apsort);
  104162. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  104163. }
  104164. }
  104165. return(ret);
  104166. }
  104167. return(NULL);
  104168. }
  104169. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  104170. float *magnitudes,int *sortedindex){
  104171. int i,j,n=p->n;
  104172. vorbis_info_psy *vi=p->vi;
  104173. int partition=vi->normal_partition;
  104174. float **work=(float**) alloca(sizeof(*work)*partition);
  104175. int start=vi->normal_start;
  104176. for(j=start;j<n;j+=partition){
  104177. if(j+partition>n)partition=n-j;
  104178. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  104179. qsort(work,partition,sizeof(*work),apsort);
  104180. for(i=0;i<partition;i++){
  104181. sortedindex[i+j-start]=work[i]-magnitudes;
  104182. }
  104183. }
  104184. }
  104185. void _vp_noise_normalize(vorbis_look_psy *p,
  104186. float *in,float *out,int *sortedindex){
  104187. int flag=0,i,j=0,n=p->n;
  104188. vorbis_info_psy *vi=p->vi;
  104189. int partition=vi->normal_partition;
  104190. int start=vi->normal_start;
  104191. if(start>n)start=n;
  104192. if(vi->normal_channel_p){
  104193. for(;j<start;j++)
  104194. out[j]=rint(in[j]);
  104195. for(;j+partition<=n;j+=partition){
  104196. float acc=0.;
  104197. int k;
  104198. for(i=j;i<j+partition;i++)
  104199. acc+=in[i]*in[i];
  104200. for(i=0;i<partition;i++){
  104201. k=sortedindex[i+j-start];
  104202. if(in[k]*in[k]>=.25f){
  104203. out[k]=rint(in[k]);
  104204. acc-=in[k]*in[k];
  104205. flag=1;
  104206. }else{
  104207. if(acc<vi->normal_thresh)break;
  104208. out[k]=unitnorm(in[k]);
  104209. acc-=1.;
  104210. }
  104211. }
  104212. for(;i<partition;i++){
  104213. k=sortedindex[i+j-start];
  104214. out[k]=0.;
  104215. }
  104216. }
  104217. }
  104218. for(;j<n;j++)
  104219. out[j]=rint(in[j]);
  104220. }
  104221. void _vp_couple(int blobno,
  104222. vorbis_info_psy_global *g,
  104223. vorbis_look_psy *p,
  104224. vorbis_info_mapping0 *vi,
  104225. float **res,
  104226. float **mag_memo,
  104227. int **mag_sort,
  104228. int **ifloor,
  104229. int *nonzero,
  104230. int sliding_lowpass){
  104231. int i,j,k,n=p->n;
  104232. for(i=0;i<vi->coupling_steps;i++){
  104233. if(nonzero[vi->coupling_mag[i]] ||
  104234. nonzero[vi->coupling_ang[i]]){
  104235. float *rM=res[vi->coupling_mag[i]];
  104236. float *rA=res[vi->coupling_ang[i]];
  104237. float *qM=rM+n;
  104238. float *qA=rA+n;
  104239. int *floorM=ifloor[vi->coupling_mag[i]];
  104240. int *floorA=ifloor[vi->coupling_ang[i]];
  104241. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  104242. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  104243. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  104244. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  104245. int pointlimit=limit;
  104246. nonzero[vi->coupling_mag[i]]=1;
  104247. nonzero[vi->coupling_ang[i]]=1;
  104248. if(n > 1000)
  104249. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  104250. for(j=0;j<p->n;j+=partition){
  104251. float acc=0.f;
  104252. for(k=0;k<partition;k++){
  104253. int l=k+j;
  104254. if(l<sliding_lowpass){
  104255. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  104256. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  104257. precomputed_couple_point(mag_memo[i][l],
  104258. floorM[l],floorA[l],
  104259. qM+l,qA+l);
  104260. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  104261. }else{
  104262. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  104263. }
  104264. }else{
  104265. qM[l]=0.;
  104266. qA[l]=0.;
  104267. }
  104268. }
  104269. if(p->vi->normal_point_p){
  104270. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  104271. int l=mag_sort[i][j+k];
  104272. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  104273. qM[l]=unitnorm(qM[l]);
  104274. acc-=1.f;
  104275. }
  104276. }
  104277. }
  104278. }
  104279. }
  104280. }
  104281. }
  104282. void hf_reduction(vorbis_info_psy_global *g,
  104283. vorbis_look_psy *p,
  104284. vorbis_info_mapping0 *vi,
  104285. float **mdct){
  104286. int i,j,n=p->n, de=0.3*p->m_val;
  104287. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104288. for(i=0; i<vi->coupling_steps; i++){
  104289. for(j=limit; j<n; j++)
  104290. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  104291. }
  104292. }
  104293. #endif
  104294. /*** End of inlined file: psy.c ***/
  104295. /*** Start of inlined file: registry.c ***/
  104296. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104297. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104298. // tasks..
  104299. #if JUCE_MSVC
  104300. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104301. #endif
  104302. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104303. #if JUCE_USE_OGGVORBIS
  104304. extern vorbis_func_floor floor0_exportbundle;
  104305. extern vorbis_func_floor floor1_exportbundle;
  104306. extern vorbis_func_residue residue0_exportbundle;
  104307. extern vorbis_func_residue residue1_exportbundle;
  104308. extern vorbis_func_residue residue2_exportbundle;
  104309. extern vorbis_func_mapping mapping0_exportbundle;
  104310. vorbis_func_floor *_floor_P[]={
  104311. &floor0_exportbundle,
  104312. &floor1_exportbundle,
  104313. };
  104314. vorbis_func_residue *_residue_P[]={
  104315. &residue0_exportbundle,
  104316. &residue1_exportbundle,
  104317. &residue2_exportbundle,
  104318. };
  104319. vorbis_func_mapping *_mapping_P[]={
  104320. &mapping0_exportbundle,
  104321. };
  104322. #endif
  104323. /*** End of inlined file: registry.c ***/
  104324. /*** Start of inlined file: res0.c ***/
  104325. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104326. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104327. // tasks..
  104328. #if JUCE_MSVC
  104329. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104330. #endif
  104331. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104332. #if JUCE_USE_OGGVORBIS
  104333. #include <stdlib.h>
  104334. #include <string.h>
  104335. #include <math.h>
  104336. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104337. #include <stdio.h>
  104338. #endif
  104339. typedef struct {
  104340. vorbis_info_residue0 *info;
  104341. int parts;
  104342. int stages;
  104343. codebook *fullbooks;
  104344. codebook *phrasebook;
  104345. codebook ***partbooks;
  104346. int partvals;
  104347. int **decodemap;
  104348. long postbits;
  104349. long phrasebits;
  104350. long frames;
  104351. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104352. int train_seq;
  104353. long *training_data[8][64];
  104354. float training_max[8][64];
  104355. float training_min[8][64];
  104356. float tmin;
  104357. float tmax;
  104358. #endif
  104359. } vorbis_look_residue0;
  104360. void res0_free_info(vorbis_info_residue *i){
  104361. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104362. if(info){
  104363. memset(info,0,sizeof(*info));
  104364. _ogg_free(info);
  104365. }
  104366. }
  104367. void res0_free_look(vorbis_look_residue *i){
  104368. int j;
  104369. if(i){
  104370. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104371. #ifdef TRAIN_RES
  104372. {
  104373. int j,k,l;
  104374. for(j=0;j<look->parts;j++){
  104375. for(k=0;k<8;k++)
  104376. if(look->training_data[k][j]){
  104377. char buffer[80];
  104378. FILE *of;
  104379. codebook *statebook=look->partbooks[j][k];
  104380. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104381. of=fopen(buffer,"a");
  104382. for(l=0;l<statebook->entries;l++)
  104383. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104384. fclose(of);
  104385. _ogg_free(look->training_data[k][j]);
  104386. look->training_data[k][j]=NULL;
  104387. }
  104388. }
  104389. }
  104390. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104391. #endif
  104392. for(j=0;j<look->parts;j++)
  104393. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104394. _ogg_free(look->partbooks);
  104395. for(j=0;j<look->partvals;j++)
  104396. _ogg_free(look->decodemap[j]);
  104397. _ogg_free(look->decodemap);
  104398. memset(look,0,sizeof(*look));
  104399. _ogg_free(look);
  104400. }
  104401. }
  104402. static int icount(unsigned int v){
  104403. int ret=0;
  104404. while(v){
  104405. ret+=v&1;
  104406. v>>=1;
  104407. }
  104408. return(ret);
  104409. }
  104410. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104411. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104412. int j,acc=0;
  104413. oggpack_write(opb,info->begin,24);
  104414. oggpack_write(opb,info->end,24);
  104415. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104416. code with a partitioned book */
  104417. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104418. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104419. for(j=0;j<info->partitions;j++){
  104420. if(ilog(info->secondstages[j])>3){
  104421. oggpack_write(opb,info->secondstages[j],3);
  104422. oggpack_write(opb,1,1);
  104423. oggpack_write(opb,info->secondstages[j]>>3,5);
  104424. }else
  104425. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104426. acc+=icount(info->secondstages[j]);
  104427. }
  104428. for(j=0;j<acc;j++)
  104429. oggpack_write(opb,info->booklist[j],8);
  104430. }
  104431. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104432. int j,acc=0;
  104433. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104434. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104435. info->begin=oggpack_read(opb,24);
  104436. info->end=oggpack_read(opb,24);
  104437. info->grouping=oggpack_read(opb,24)+1;
  104438. info->partitions=oggpack_read(opb,6)+1;
  104439. info->groupbook=oggpack_read(opb,8);
  104440. for(j=0;j<info->partitions;j++){
  104441. int cascade=oggpack_read(opb,3);
  104442. if(oggpack_read(opb,1))
  104443. cascade|=(oggpack_read(opb,5)<<3);
  104444. info->secondstages[j]=cascade;
  104445. acc+=icount(cascade);
  104446. }
  104447. for(j=0;j<acc;j++)
  104448. info->booklist[j]=oggpack_read(opb,8);
  104449. if(info->groupbook>=ci->books)goto errout;
  104450. for(j=0;j<acc;j++)
  104451. if(info->booklist[j]>=ci->books)goto errout;
  104452. return(info);
  104453. errout:
  104454. res0_free_info(info);
  104455. return(NULL);
  104456. }
  104457. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104458. vorbis_info_residue *vr){
  104459. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104460. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104461. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104462. int j,k,acc=0;
  104463. int dim;
  104464. int maxstage=0;
  104465. look->info=info;
  104466. look->parts=info->partitions;
  104467. look->fullbooks=ci->fullbooks;
  104468. look->phrasebook=ci->fullbooks+info->groupbook;
  104469. dim=look->phrasebook->dim;
  104470. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104471. for(j=0;j<look->parts;j++){
  104472. int stages=ilog(info->secondstages[j]);
  104473. if(stages){
  104474. if(stages>maxstage)maxstage=stages;
  104475. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104476. for(k=0;k<stages;k++)
  104477. if(info->secondstages[j]&(1<<k)){
  104478. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104479. #ifdef TRAIN_RES
  104480. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104481. sizeof(***look->training_data));
  104482. #endif
  104483. }
  104484. }
  104485. }
  104486. look->partvals=rint(pow((float)look->parts,(float)dim));
  104487. look->stages=maxstage;
  104488. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104489. for(j=0;j<look->partvals;j++){
  104490. long val=j;
  104491. long mult=look->partvals/look->parts;
  104492. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104493. for(k=0;k<dim;k++){
  104494. long deco=val/mult;
  104495. val-=deco*mult;
  104496. mult/=look->parts;
  104497. look->decodemap[j][k]=deco;
  104498. }
  104499. }
  104500. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104501. {
  104502. static int train_seq=0;
  104503. look->train_seq=train_seq++;
  104504. }
  104505. #endif
  104506. return(look);
  104507. }
  104508. static int local_book_besterror(codebook *book,float *a){
  104509. int dim=book->dim,i,k,o;
  104510. int best=0;
  104511. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104512. for(k=0,o=dim;k<dim;++k){
  104513. float val=a[--o];
  104514. i=tt->threshvals>>1;
  104515. if(val<tt->quantthresh[i]){
  104516. if(val<tt->quantthresh[i-1]){
  104517. for(--i;i>0;--i)
  104518. if(val>=tt->quantthresh[i-1])
  104519. break;
  104520. }
  104521. }else{
  104522. for(++i;i<tt->threshvals-1;++i)
  104523. if(val<tt->quantthresh[i])break;
  104524. }
  104525. best=(best*tt->quantvals)+tt->quantmap[i];
  104526. }
  104527. if(book->c->lengthlist[best]<=0){
  104528. const static_codebook *c=book->c;
  104529. int i,j;
  104530. float bestf=0.f;
  104531. float *e=book->valuelist;
  104532. best=-1;
  104533. for(i=0;i<book->entries;i++){
  104534. if(c->lengthlist[i]>0){
  104535. float thisx=0.f;
  104536. for(j=0;j<dim;j++){
  104537. float val=(e[j]-a[j]);
  104538. thisx+=val*val;
  104539. }
  104540. if(best==-1 || thisx<bestf){
  104541. bestf=thisx;
  104542. best=i;
  104543. }
  104544. }
  104545. e+=dim;
  104546. }
  104547. }
  104548. {
  104549. float *ptr=book->valuelist+best*dim;
  104550. for(i=0;i<dim;i++)
  104551. *a++ -= *ptr++;
  104552. }
  104553. return(best);
  104554. }
  104555. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104556. codebook *book,long *acc){
  104557. int i,bits=0;
  104558. int dim=book->dim;
  104559. int step=n/dim;
  104560. for(i=0;i<step;i++){
  104561. int entry=local_book_besterror(book,vec+i*dim);
  104562. #ifdef TRAIN_RES
  104563. acc[entry]++;
  104564. #endif
  104565. bits+=vorbis_book_encode(book,entry,opb);
  104566. }
  104567. return(bits);
  104568. }
  104569. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104570. float **in,int ch){
  104571. long i,j,k;
  104572. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104573. vorbis_info_residue0 *info=look->info;
  104574. int samples_per_partition=info->grouping;
  104575. int possible_partitions=info->partitions;
  104576. int n=info->end-info->begin;
  104577. int partvals=n/samples_per_partition;
  104578. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104579. float scale=100./samples_per_partition;
  104580. for(i=0;i<ch;i++){
  104581. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104582. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104583. }
  104584. for(i=0;i<partvals;i++){
  104585. int offset=i*samples_per_partition+info->begin;
  104586. for(j=0;j<ch;j++){
  104587. float max=0.;
  104588. float ent=0.;
  104589. for(k=0;k<samples_per_partition;k++){
  104590. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104591. ent+=fabs(rint(in[j][offset+k]));
  104592. }
  104593. ent*=scale;
  104594. for(k=0;k<possible_partitions-1;k++)
  104595. if(max<=info->classmetric1[k] &&
  104596. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104597. break;
  104598. partword[j][i]=k;
  104599. }
  104600. }
  104601. #ifdef TRAIN_RESAUX
  104602. {
  104603. FILE *of;
  104604. char buffer[80];
  104605. for(i=0;i<ch;i++){
  104606. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104607. of=fopen(buffer,"a");
  104608. for(j=0;j<partvals;j++)
  104609. fprintf(of,"%ld, ",partword[i][j]);
  104610. fprintf(of,"\n");
  104611. fclose(of);
  104612. }
  104613. }
  104614. #endif
  104615. look->frames++;
  104616. return(partword);
  104617. }
  104618. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104619. int ch){
  104620. long i,j,k,l;
  104621. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104622. vorbis_info_residue0 *info=look->info;
  104623. int samples_per_partition=info->grouping;
  104624. int possible_partitions=info->partitions;
  104625. int n=info->end-info->begin;
  104626. int partvals=n/samples_per_partition;
  104627. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104628. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104629. FILE *of;
  104630. char buffer[80];
  104631. #endif
  104632. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104633. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104634. for(i=0,l=info->begin/ch;i<partvals;i++){
  104635. float magmax=0.f;
  104636. float angmax=0.f;
  104637. for(j=0;j<samples_per_partition;j+=ch){
  104638. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104639. for(k=1;k<ch;k++)
  104640. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104641. l++;
  104642. }
  104643. for(j=0;j<possible_partitions-1;j++)
  104644. if(magmax<=info->classmetric1[j] &&
  104645. angmax<=info->classmetric2[j])
  104646. break;
  104647. partword[0][i]=j;
  104648. }
  104649. #ifdef TRAIN_RESAUX
  104650. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104651. of=fopen(buffer,"a");
  104652. for(i=0;i<partvals;i++)
  104653. fprintf(of,"%ld, ",partword[0][i]);
  104654. fprintf(of,"\n");
  104655. fclose(of);
  104656. #endif
  104657. look->frames++;
  104658. return(partword);
  104659. }
  104660. static int _01forward(oggpack_buffer *opb,
  104661. vorbis_block *vb,vorbis_look_residue *vl,
  104662. float **in,int ch,
  104663. long **partword,
  104664. int (*encode)(oggpack_buffer *,float *,int,
  104665. codebook *,long *)){
  104666. long i,j,k,s;
  104667. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104668. vorbis_info_residue0 *info=look->info;
  104669. int samples_per_partition=info->grouping;
  104670. int possible_partitions=info->partitions;
  104671. int partitions_per_word=look->phrasebook->dim;
  104672. int n=info->end-info->begin;
  104673. int partvals=n/samples_per_partition;
  104674. long resbits[128];
  104675. long resvals[128];
  104676. #ifdef TRAIN_RES
  104677. for(i=0;i<ch;i++)
  104678. for(j=info->begin;j<info->end;j++){
  104679. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104680. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104681. }
  104682. #endif
  104683. memset(resbits,0,sizeof(resbits));
  104684. memset(resvals,0,sizeof(resvals));
  104685. for(s=0;s<look->stages;s++){
  104686. for(i=0;i<partvals;){
  104687. if(s==0){
  104688. for(j=0;j<ch;j++){
  104689. long val=partword[j][i];
  104690. for(k=1;k<partitions_per_word;k++){
  104691. val*=possible_partitions;
  104692. if(i+k<partvals)
  104693. val+=partword[j][i+k];
  104694. }
  104695. if(val<look->phrasebook->entries)
  104696. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104697. #if 0 /*def TRAIN_RES*/
  104698. else
  104699. fprintf(stderr,"!");
  104700. #endif
  104701. }
  104702. }
  104703. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104704. long offset=i*samples_per_partition+info->begin;
  104705. for(j=0;j<ch;j++){
  104706. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104707. if(info->secondstages[partword[j][i]]&(1<<s)){
  104708. codebook *statebook=look->partbooks[partword[j][i]][s];
  104709. if(statebook){
  104710. int ret;
  104711. long *accumulator=NULL;
  104712. #ifdef TRAIN_RES
  104713. accumulator=look->training_data[s][partword[j][i]];
  104714. {
  104715. int l;
  104716. float *samples=in[j]+offset;
  104717. for(l=0;l<samples_per_partition;l++){
  104718. if(samples[l]<look->training_min[s][partword[j][i]])
  104719. look->training_min[s][partword[j][i]]=samples[l];
  104720. if(samples[l]>look->training_max[s][partword[j][i]])
  104721. look->training_max[s][partword[j][i]]=samples[l];
  104722. }
  104723. }
  104724. #endif
  104725. ret=encode(opb,in[j]+offset,samples_per_partition,
  104726. statebook,accumulator);
  104727. look->postbits+=ret;
  104728. resbits[partword[j][i]]+=ret;
  104729. }
  104730. }
  104731. }
  104732. }
  104733. }
  104734. }
  104735. return(0);
  104736. }
  104737. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104738. float **in,int ch,
  104739. long (*decodepart)(codebook *, float *,
  104740. oggpack_buffer *,int)){
  104741. long i,j,k,l,s;
  104742. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104743. vorbis_info_residue0 *info=look->info;
  104744. int samples_per_partition=info->grouping;
  104745. int partitions_per_word=look->phrasebook->dim;
  104746. int n=info->end-info->begin;
  104747. int partvals=n/samples_per_partition;
  104748. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104749. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104750. for(j=0;j<ch;j++)
  104751. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104752. for(s=0;s<look->stages;s++){
  104753. for(i=0,l=0;i<partvals;l++){
  104754. if(s==0){
  104755. for(j=0;j<ch;j++){
  104756. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104757. if(temp==-1)goto eopbreak;
  104758. partword[j][l]=look->decodemap[temp];
  104759. if(partword[j][l]==NULL)goto errout;
  104760. }
  104761. }
  104762. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104763. for(j=0;j<ch;j++){
  104764. long offset=info->begin+i*samples_per_partition;
  104765. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104766. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104767. if(stagebook){
  104768. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104769. samples_per_partition)==-1)goto eopbreak;
  104770. }
  104771. }
  104772. }
  104773. }
  104774. }
  104775. errout:
  104776. eopbreak:
  104777. return(0);
  104778. }
  104779. #if 0
  104780. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104781. float **in,int *nonzero,int ch){
  104782. int i,used=0;
  104783. for(i=0;i<ch;i++)
  104784. if(nonzero[i])
  104785. in[used++]=in[i];
  104786. if(used)
  104787. return(_01class(vb,vl,in,used));
  104788. else
  104789. return(0);
  104790. }
  104791. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104792. float **in,float **out,int *nonzero,int ch,
  104793. long **partword){
  104794. int i,j,used=0,n=vb->pcmend/2;
  104795. for(i=0;i<ch;i++)
  104796. if(nonzero[i]){
  104797. if(out)
  104798. for(j=0;j<n;j++)
  104799. out[i][j]+=in[i][j];
  104800. in[used++]=in[i];
  104801. }
  104802. if(used){
  104803. int ret=_01forward(vb,vl,in,used,partword,
  104804. _interleaved_encodepart);
  104805. if(out){
  104806. used=0;
  104807. for(i=0;i<ch;i++)
  104808. if(nonzero[i]){
  104809. for(j=0;j<n;j++)
  104810. out[i][j]-=in[used][j];
  104811. used++;
  104812. }
  104813. }
  104814. return(ret);
  104815. }else{
  104816. return(0);
  104817. }
  104818. }
  104819. #endif
  104820. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104821. float **in,int *nonzero,int ch){
  104822. int i,used=0;
  104823. for(i=0;i<ch;i++)
  104824. if(nonzero[i])
  104825. in[used++]=in[i];
  104826. if(used)
  104827. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104828. else
  104829. return(0);
  104830. }
  104831. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104832. float **in,float **out,int *nonzero,int ch,
  104833. long **partword){
  104834. int i,j,used=0,n=vb->pcmend/2;
  104835. for(i=0;i<ch;i++)
  104836. if(nonzero[i]){
  104837. if(out)
  104838. for(j=0;j<n;j++)
  104839. out[i][j]+=in[i][j];
  104840. in[used++]=in[i];
  104841. }
  104842. if(used){
  104843. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104844. if(out){
  104845. used=0;
  104846. for(i=0;i<ch;i++)
  104847. if(nonzero[i]){
  104848. for(j=0;j<n;j++)
  104849. out[i][j]-=in[used][j];
  104850. used++;
  104851. }
  104852. }
  104853. return(ret);
  104854. }else{
  104855. return(0);
  104856. }
  104857. }
  104858. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104859. float **in,int *nonzero,int ch){
  104860. int i,used=0;
  104861. for(i=0;i<ch;i++)
  104862. if(nonzero[i])
  104863. in[used++]=in[i];
  104864. if(used)
  104865. return(_01class(vb,vl,in,used));
  104866. else
  104867. return(0);
  104868. }
  104869. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104870. float **in,int *nonzero,int ch){
  104871. int i,used=0;
  104872. for(i=0;i<ch;i++)
  104873. if(nonzero[i])
  104874. in[used++]=in[i];
  104875. if(used)
  104876. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104877. else
  104878. return(0);
  104879. }
  104880. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104881. float **in,int *nonzero,int ch){
  104882. int i,used=0;
  104883. for(i=0;i<ch;i++)
  104884. if(nonzero[i])used++;
  104885. if(used)
  104886. return(_2class(vb,vl,in,ch));
  104887. else
  104888. return(0);
  104889. }
  104890. int res2_forward(oggpack_buffer *opb,
  104891. vorbis_block *vb,vorbis_look_residue *vl,
  104892. float **in,float **out,int *nonzero,int ch,
  104893. long **partword){
  104894. long i,j,k,n=vb->pcmend/2,used=0;
  104895. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104896. for(i=0;i<ch;i++){
  104897. float *pcm=in[i];
  104898. if(nonzero[i])used++;
  104899. for(j=0,k=i;j<n;j++,k+=ch)
  104900. work[k]=pcm[j];
  104901. }
  104902. if(used){
  104903. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104904. if(out){
  104905. for(i=0;i<ch;i++){
  104906. float *pcm=in[i];
  104907. float *sofar=out[i];
  104908. for(j=0,k=i;j<n;j++,k+=ch)
  104909. sofar[j]+=pcm[j]-work[k];
  104910. }
  104911. }
  104912. return(ret);
  104913. }else{
  104914. return(0);
  104915. }
  104916. }
  104917. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104918. float **in,int *nonzero,int ch){
  104919. long i,k,l,s;
  104920. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104921. vorbis_info_residue0 *info=look->info;
  104922. int samples_per_partition=info->grouping;
  104923. int partitions_per_word=look->phrasebook->dim;
  104924. int n=info->end-info->begin;
  104925. int partvals=n/samples_per_partition;
  104926. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104927. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104928. for(i=0;i<ch;i++)if(nonzero[i])break;
  104929. if(i==ch)return(0); /* no nonzero vectors */
  104930. for(s=0;s<look->stages;s++){
  104931. for(i=0,l=0;i<partvals;l++){
  104932. if(s==0){
  104933. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104934. if(temp==-1)goto eopbreak;
  104935. partword[l]=look->decodemap[temp];
  104936. if(partword[l]==NULL)goto errout;
  104937. }
  104938. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104939. if(info->secondstages[partword[l][k]]&(1<<s)){
  104940. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104941. if(stagebook){
  104942. if(vorbis_book_decodevv_add(stagebook,in,
  104943. i*samples_per_partition+info->begin,ch,
  104944. &vb->opb,samples_per_partition)==-1)
  104945. goto eopbreak;
  104946. }
  104947. }
  104948. }
  104949. }
  104950. errout:
  104951. eopbreak:
  104952. return(0);
  104953. }
  104954. vorbis_func_residue residue0_exportbundle={
  104955. NULL,
  104956. &res0_unpack,
  104957. &res0_look,
  104958. &res0_free_info,
  104959. &res0_free_look,
  104960. NULL,
  104961. NULL,
  104962. &res0_inverse
  104963. };
  104964. vorbis_func_residue residue1_exportbundle={
  104965. &res0_pack,
  104966. &res0_unpack,
  104967. &res0_look,
  104968. &res0_free_info,
  104969. &res0_free_look,
  104970. &res1_class,
  104971. &res1_forward,
  104972. &res1_inverse
  104973. };
  104974. vorbis_func_residue residue2_exportbundle={
  104975. &res0_pack,
  104976. &res0_unpack,
  104977. &res0_look,
  104978. &res0_free_info,
  104979. &res0_free_look,
  104980. &res2_class,
  104981. &res2_forward,
  104982. &res2_inverse
  104983. };
  104984. #endif
  104985. /*** End of inlined file: res0.c ***/
  104986. /*** Start of inlined file: sharedbook.c ***/
  104987. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104988. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104989. // tasks..
  104990. #if JUCE_MSVC
  104991. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104992. #endif
  104993. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104994. #if JUCE_USE_OGGVORBIS
  104995. #include <stdlib.h>
  104996. #include <math.h>
  104997. #include <string.h>
  104998. int _ilog(unsigned int v){
  104999. int ret=0;
  105000. while(v){
  105001. ret++;
  105002. v>>=1;
  105003. }
  105004. return(ret);
  105005. }
  105006. #define VQ_FEXP 10
  105007. #define VQ_FMAN 21
  105008. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  105009. long _float32_pack(float val){
  105010. int sign=0;
  105011. long exp;
  105012. long mant;
  105013. if(val<0){
  105014. sign=0x80000000;
  105015. val= -val;
  105016. }
  105017. exp= floor(log(val)/log(2.f));
  105018. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  105019. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  105020. return(sign|exp|mant);
  105021. }
  105022. float _float32_unpack(long val){
  105023. double mant=val&0x1fffff;
  105024. int sign=val&0x80000000;
  105025. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  105026. if(sign)mant= -mant;
  105027. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  105028. }
  105029. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  105030. long i,j,count=0;
  105031. ogg_uint32_t marker[33];
  105032. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  105033. memset(marker,0,sizeof(marker));
  105034. for(i=0;i<n;i++){
  105035. long length=l[i];
  105036. if(length>0){
  105037. ogg_uint32_t entry=marker[length];
  105038. if(length<32 && (entry>>length)){
  105039. _ogg_free(r);
  105040. return(NULL);
  105041. }
  105042. r[count++]=entry;
  105043. {
  105044. for(j=length;j>0;j--){
  105045. if(marker[j]&1){
  105046. if(j==1)
  105047. marker[1]++;
  105048. else
  105049. marker[j]=marker[j-1]<<1;
  105050. break; /* invariant says next upper marker would already
  105051. have been moved if it was on the same path */
  105052. }
  105053. marker[j]++;
  105054. }
  105055. }
  105056. for(j=length+1;j<33;j++)
  105057. if((marker[j]>>1) == entry){
  105058. entry=marker[j];
  105059. marker[j]=marker[j-1]<<1;
  105060. }else
  105061. break;
  105062. }else
  105063. if(sparsecount==0)count++;
  105064. }
  105065. for(i=0,count=0;i<n;i++){
  105066. ogg_uint32_t temp=0;
  105067. for(j=0;j<l[i];j++){
  105068. temp<<=1;
  105069. temp|=(r[count]>>j)&1;
  105070. }
  105071. if(sparsecount){
  105072. if(l[i])
  105073. r[count++]=temp;
  105074. }else
  105075. r[count++]=temp;
  105076. }
  105077. return(r);
  105078. }
  105079. long _book_maptype1_quantvals(const static_codebook *b){
  105080. long vals=floor(pow((float)b->entries,1.f/b->dim));
  105081. while(1){
  105082. long acc=1;
  105083. long acc1=1;
  105084. int i;
  105085. for(i=0;i<b->dim;i++){
  105086. acc*=vals;
  105087. acc1*=vals+1;
  105088. }
  105089. if(acc<=b->entries && acc1>b->entries){
  105090. return(vals);
  105091. }else{
  105092. if(acc>b->entries){
  105093. vals--;
  105094. }else{
  105095. vals++;
  105096. }
  105097. }
  105098. }
  105099. }
  105100. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  105101. long j,k,count=0;
  105102. if(b->maptype==1 || b->maptype==2){
  105103. int quantvals;
  105104. float mindel=_float32_unpack(b->q_min);
  105105. float delta=_float32_unpack(b->q_delta);
  105106. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  105107. switch(b->maptype){
  105108. case 1:
  105109. quantvals=_book_maptype1_quantvals(b);
  105110. for(j=0;j<b->entries;j++){
  105111. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105112. float last=0.f;
  105113. int indexdiv=1;
  105114. for(k=0;k<b->dim;k++){
  105115. int index= (j/indexdiv)%quantvals;
  105116. float val=b->quantlist[index];
  105117. val=fabs(val)*delta+mindel+last;
  105118. if(b->q_sequencep)last=val;
  105119. if(sparsemap)
  105120. r[sparsemap[count]*b->dim+k]=val;
  105121. else
  105122. r[count*b->dim+k]=val;
  105123. indexdiv*=quantvals;
  105124. }
  105125. count++;
  105126. }
  105127. }
  105128. break;
  105129. case 2:
  105130. for(j=0;j<b->entries;j++){
  105131. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105132. float last=0.f;
  105133. for(k=0;k<b->dim;k++){
  105134. float val=b->quantlist[j*b->dim+k];
  105135. val=fabs(val)*delta+mindel+last;
  105136. if(b->q_sequencep)last=val;
  105137. if(sparsemap)
  105138. r[sparsemap[count]*b->dim+k]=val;
  105139. else
  105140. r[count*b->dim+k]=val;
  105141. }
  105142. count++;
  105143. }
  105144. }
  105145. break;
  105146. }
  105147. return(r);
  105148. }
  105149. return(NULL);
  105150. }
  105151. void vorbis_staticbook_clear(static_codebook *b){
  105152. if(b->allocedp){
  105153. if(b->quantlist)_ogg_free(b->quantlist);
  105154. if(b->lengthlist)_ogg_free(b->lengthlist);
  105155. if(b->nearest_tree){
  105156. _ogg_free(b->nearest_tree->ptr0);
  105157. _ogg_free(b->nearest_tree->ptr1);
  105158. _ogg_free(b->nearest_tree->p);
  105159. _ogg_free(b->nearest_tree->q);
  105160. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  105161. _ogg_free(b->nearest_tree);
  105162. }
  105163. if(b->thresh_tree){
  105164. _ogg_free(b->thresh_tree->quantthresh);
  105165. _ogg_free(b->thresh_tree->quantmap);
  105166. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  105167. _ogg_free(b->thresh_tree);
  105168. }
  105169. memset(b,0,sizeof(*b));
  105170. }
  105171. }
  105172. void vorbis_staticbook_destroy(static_codebook *b){
  105173. if(b->allocedp){
  105174. vorbis_staticbook_clear(b);
  105175. _ogg_free(b);
  105176. }
  105177. }
  105178. void vorbis_book_clear(codebook *b){
  105179. if(b->valuelist)_ogg_free(b->valuelist);
  105180. if(b->codelist)_ogg_free(b->codelist);
  105181. if(b->dec_index)_ogg_free(b->dec_index);
  105182. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  105183. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  105184. memset(b,0,sizeof(*b));
  105185. }
  105186. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  105187. memset(c,0,sizeof(*c));
  105188. c->c=s;
  105189. c->entries=s->entries;
  105190. c->used_entries=s->entries;
  105191. c->dim=s->dim;
  105192. c->codelist=_make_words(s->lengthlist,s->entries,0);
  105193. c->valuelist=_book_unquantize(s,s->entries,NULL);
  105194. return(0);
  105195. }
  105196. static int sort32a(const void *a,const void *b){
  105197. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  105198. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  105199. }
  105200. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  105201. int i,j,n=0,tabn;
  105202. int *sortindex;
  105203. memset(c,0,sizeof(*c));
  105204. for(i=0;i<s->entries;i++)
  105205. if(s->lengthlist[i]>0)
  105206. n++;
  105207. c->entries=s->entries;
  105208. c->used_entries=n;
  105209. c->dim=s->dim;
  105210. {
  105211. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  105212. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  105213. if(codes==NULL)goto err_out;
  105214. for(i=0;i<n;i++){
  105215. codes[i]=ogg_bitreverse(codes[i]);
  105216. codep[i]=codes+i;
  105217. }
  105218. qsort(codep,n,sizeof(*codep),sort32a);
  105219. sortindex=(int*)alloca(n*sizeof(*sortindex));
  105220. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  105221. for(i=0;i<n;i++){
  105222. int position=codep[i]-codes;
  105223. sortindex[position]=i;
  105224. }
  105225. for(i=0;i<n;i++)
  105226. c->codelist[sortindex[i]]=codes[i];
  105227. _ogg_free(codes);
  105228. }
  105229. c->valuelist=_book_unquantize(s,n,sortindex);
  105230. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  105231. for(n=0,i=0;i<s->entries;i++)
  105232. if(s->lengthlist[i]>0)
  105233. c->dec_index[sortindex[n++]]=i;
  105234. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  105235. for(n=0,i=0;i<s->entries;i++)
  105236. if(s->lengthlist[i]>0)
  105237. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  105238. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  105239. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  105240. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  105241. tabn=1<<c->dec_firsttablen;
  105242. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  105243. c->dec_maxlength=0;
  105244. for(i=0;i<n;i++){
  105245. if(c->dec_maxlength<c->dec_codelengths[i])
  105246. c->dec_maxlength=c->dec_codelengths[i];
  105247. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  105248. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  105249. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  105250. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  105251. }
  105252. }
  105253. {
  105254. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  105255. long lo=0,hi=0;
  105256. for(i=0;i<tabn;i++){
  105257. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  105258. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  105259. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  105260. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  105261. {
  105262. unsigned long loval=lo;
  105263. unsigned long hival=n-hi;
  105264. if(loval>0x7fff)loval=0x7fff;
  105265. if(hival>0x7fff)hival=0x7fff;
  105266. c->dec_firsttable[ogg_bitreverse(word)]=
  105267. 0x80000000UL | (loval<<15) | hival;
  105268. }
  105269. }
  105270. }
  105271. }
  105272. return(0);
  105273. err_out:
  105274. vorbis_book_clear(c);
  105275. return(-1);
  105276. }
  105277. static float _dist(int el,float *ref, float *b,int step){
  105278. int i;
  105279. float acc=0.f;
  105280. for(i=0;i<el;i++){
  105281. float val=(ref[i]-b[i*step]);
  105282. acc+=val*val;
  105283. }
  105284. return(acc);
  105285. }
  105286. int _best(codebook *book, float *a, int step){
  105287. encode_aux_threshmatch *tt=book->c->thresh_tree;
  105288. #if 0
  105289. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  105290. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  105291. #endif
  105292. int dim=book->dim;
  105293. int k,o;
  105294. if(tt){
  105295. int index=0,i;
  105296. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105297. i=tt->threshvals>>1;
  105298. if(a[o]<tt->quantthresh[i]){
  105299. for(;i>0;i--)
  105300. if(a[o]>=tt->quantthresh[i-1])
  105301. break;
  105302. }else{
  105303. for(i++;i<tt->threshvals-1;i++)
  105304. if(a[o]<tt->quantthresh[i])break;
  105305. }
  105306. index=(index*tt->quantvals)+tt->quantmap[i];
  105307. }
  105308. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105309. use a decision tree after all
  105310. and fall through*/
  105311. return(index);
  105312. }
  105313. #if 0
  105314. if(pt){
  105315. const static_codebook *c=book->c;
  105316. int i,besti=-1;
  105317. float best=0.f;
  105318. int entry=0;
  105319. if(c->q_sequencep){
  105320. int pv;
  105321. long mul=1;
  105322. float qlast=0;
  105323. for(k=0,o=0;k<dim;k++,o+=step){
  105324. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105325. if(pv<0 || pv>=pt->mapentries)break;
  105326. entry+=pt->pigeonmap[pv]*mul;
  105327. mul*=pt->quantvals;
  105328. qlast+=pv*pt->del+pt->min;
  105329. }
  105330. }else{
  105331. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105332. int pv=(int)((a[o]-pt->min)/pt->del);
  105333. if(pv<0 || pv>=pt->mapentries)break;
  105334. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105335. }
  105336. }
  105337. if(k==dim && pt->fitlength[entry]){
  105338. long *list=pt->fitlist+pt->fitmap[entry];
  105339. for(i=0;i<pt->fitlength[entry];i++){
  105340. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105341. if(besti==-1 || this<best){
  105342. best=this;
  105343. besti=list[i];
  105344. }
  105345. }
  105346. return(besti);
  105347. }
  105348. }
  105349. if(nt){
  105350. while(1){
  105351. float c=0.f;
  105352. float *p=book->valuelist+nt->p[ptr];
  105353. float *q=book->valuelist+nt->q[ptr];
  105354. for(k=0,o=0;k<dim;k++,o+=step)
  105355. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105356. if(c>0.f) /* in A */
  105357. ptr= -nt->ptr0[ptr];
  105358. else /* in B */
  105359. ptr= -nt->ptr1[ptr];
  105360. if(ptr<=0)break;
  105361. }
  105362. return(-ptr);
  105363. }
  105364. #endif
  105365. {
  105366. const static_codebook *c=book->c;
  105367. int i,besti=-1;
  105368. float best=0.f;
  105369. float *e=book->valuelist;
  105370. for(i=0;i<book->entries;i++){
  105371. if(c->lengthlist[i]>0){
  105372. float thisx=_dist(dim,e,a,step);
  105373. if(besti==-1 || thisx<best){
  105374. best=thisx;
  105375. besti=i;
  105376. }
  105377. }
  105378. e+=dim;
  105379. }
  105380. return(besti);
  105381. }
  105382. }
  105383. long vorbis_book_codeword(codebook *book,int entry){
  105384. if(book->c) /* only use with encode; decode optimizations are
  105385. allowed to break this */
  105386. return book->codelist[entry];
  105387. return -1;
  105388. }
  105389. long vorbis_book_codelen(codebook *book,int entry){
  105390. if(book->c) /* only use with encode; decode optimizations are
  105391. allowed to break this */
  105392. return book->c->lengthlist[entry];
  105393. return -1;
  105394. }
  105395. #ifdef _V_SELFTEST
  105396. #include <stdio.h>
  105397. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105398. static long partial_quantlist1[]={0,7,2};
  105399. static_codebook test1={
  105400. 4,16,
  105401. NULL,
  105402. 0,
  105403. 0,0,0,0,
  105404. NULL,
  105405. NULL,NULL
  105406. };
  105407. static float *test1_result=NULL;
  105408. static_codebook test2={
  105409. 4,3,
  105410. NULL,
  105411. 2,
  105412. -533200896,1611661312,4,0,
  105413. full_quantlist1,
  105414. NULL,NULL
  105415. };
  105416. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105417. static_codebook test3={
  105418. 4,3,
  105419. NULL,
  105420. 2,
  105421. -533200896,1611661312,4,1,
  105422. full_quantlist1,
  105423. NULL,NULL
  105424. };
  105425. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105426. static_codebook test4={
  105427. 3,27,
  105428. NULL,
  105429. 1,
  105430. -533200896,1611661312,4,0,
  105431. partial_quantlist1,
  105432. NULL,NULL
  105433. };
  105434. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105435. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105436. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105437. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105438. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105439. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105440. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105441. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105442. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105443. static_codebook test5={
  105444. 3,27,
  105445. NULL,
  105446. 1,
  105447. -533200896,1611661312,4,1,
  105448. partial_quantlist1,
  105449. NULL,NULL
  105450. };
  105451. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105452. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105453. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105454. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105455. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105456. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105457. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105458. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105459. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105460. void run_test(static_codebook *b,float *comp){
  105461. float *out=_book_unquantize(b,b->entries,NULL);
  105462. int i;
  105463. if(comp){
  105464. if(!out){
  105465. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105466. exit(1);
  105467. }
  105468. for(i=0;i<b->entries*b->dim;i++)
  105469. if(fabs(out[i]-comp[i])>.0001){
  105470. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105471. "position %d, %g != %g\n",i,out[i],comp[i]);
  105472. exit(1);
  105473. }
  105474. }else{
  105475. if(out){
  105476. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105477. " correct result should have been NULL\n");
  105478. exit(1);
  105479. }
  105480. }
  105481. }
  105482. int main(){
  105483. fprintf(stderr,"Dequant test 1... ");
  105484. run_test(&test1,test1_result);
  105485. fprintf(stderr,"OK\nDequant test 2... ");
  105486. run_test(&test2,test2_result);
  105487. fprintf(stderr,"OK\nDequant test 3... ");
  105488. run_test(&test3,test3_result);
  105489. fprintf(stderr,"OK\nDequant test 4... ");
  105490. run_test(&test4,test4_result);
  105491. fprintf(stderr,"OK\nDequant test 5... ");
  105492. run_test(&test5,test5_result);
  105493. fprintf(stderr,"OK\n\n");
  105494. return(0);
  105495. }
  105496. #endif
  105497. #endif
  105498. /*** End of inlined file: sharedbook.c ***/
  105499. /*** Start of inlined file: smallft.c ***/
  105500. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105501. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105502. // tasks..
  105503. #if JUCE_MSVC
  105504. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105505. #endif
  105506. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105507. #if JUCE_USE_OGGVORBIS
  105508. #include <stdlib.h>
  105509. #include <string.h>
  105510. #include <math.h>
  105511. static void drfti1(int n, float *wa, int *ifac){
  105512. static int ntryh[4] = { 4,2,3,5 };
  105513. static float tpi = 6.28318530717958648f;
  105514. float arg,argh,argld,fi;
  105515. int ntry=0,i,j=-1;
  105516. int k1, l1, l2, ib;
  105517. int ld, ii, ip, is, nq, nr;
  105518. int ido, ipm, nfm1;
  105519. int nl=n;
  105520. int nf=0;
  105521. L101:
  105522. j++;
  105523. if (j < 4)
  105524. ntry=ntryh[j];
  105525. else
  105526. ntry+=2;
  105527. L104:
  105528. nq=nl/ntry;
  105529. nr=nl-ntry*nq;
  105530. if (nr!=0) goto L101;
  105531. nf++;
  105532. ifac[nf+1]=ntry;
  105533. nl=nq;
  105534. if(ntry!=2)goto L107;
  105535. if(nf==1)goto L107;
  105536. for (i=1;i<nf;i++){
  105537. ib=nf-i+1;
  105538. ifac[ib+1]=ifac[ib];
  105539. }
  105540. ifac[2] = 2;
  105541. L107:
  105542. if(nl!=1)goto L104;
  105543. ifac[0]=n;
  105544. ifac[1]=nf;
  105545. argh=tpi/n;
  105546. is=0;
  105547. nfm1=nf-1;
  105548. l1=1;
  105549. if(nfm1==0)return;
  105550. for (k1=0;k1<nfm1;k1++){
  105551. ip=ifac[k1+2];
  105552. ld=0;
  105553. l2=l1*ip;
  105554. ido=n/l2;
  105555. ipm=ip-1;
  105556. for (j=0;j<ipm;j++){
  105557. ld+=l1;
  105558. i=is;
  105559. argld=(float)ld*argh;
  105560. fi=0.f;
  105561. for (ii=2;ii<ido;ii+=2){
  105562. fi+=1.f;
  105563. arg=fi*argld;
  105564. wa[i++]=cos(arg);
  105565. wa[i++]=sin(arg);
  105566. }
  105567. is+=ido;
  105568. }
  105569. l1=l2;
  105570. }
  105571. }
  105572. static void fdrffti(int n, float *wsave, int *ifac){
  105573. if (n == 1) return;
  105574. drfti1(n, wsave+n, ifac);
  105575. }
  105576. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105577. int i,k;
  105578. float ti2,tr2;
  105579. int t0,t1,t2,t3,t4,t5,t6;
  105580. t1=0;
  105581. t0=(t2=l1*ido);
  105582. t3=ido<<1;
  105583. for(k=0;k<l1;k++){
  105584. ch[t1<<1]=cc[t1]+cc[t2];
  105585. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105586. t1+=ido;
  105587. t2+=ido;
  105588. }
  105589. if(ido<2)return;
  105590. if(ido==2)goto L105;
  105591. t1=0;
  105592. t2=t0;
  105593. for(k=0;k<l1;k++){
  105594. t3=t2;
  105595. t4=(t1<<1)+(ido<<1);
  105596. t5=t1;
  105597. t6=t1+t1;
  105598. for(i=2;i<ido;i+=2){
  105599. t3+=2;
  105600. t4-=2;
  105601. t5+=2;
  105602. t6+=2;
  105603. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105604. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105605. ch[t6]=cc[t5]+ti2;
  105606. ch[t4]=ti2-cc[t5];
  105607. ch[t6-1]=cc[t5-1]+tr2;
  105608. ch[t4-1]=cc[t5-1]-tr2;
  105609. }
  105610. t1+=ido;
  105611. t2+=ido;
  105612. }
  105613. if(ido%2==1)return;
  105614. L105:
  105615. t3=(t2=(t1=ido)-1);
  105616. t2+=t0;
  105617. for(k=0;k<l1;k++){
  105618. ch[t1]=-cc[t2];
  105619. ch[t1-1]=cc[t3];
  105620. t1+=ido<<1;
  105621. t2+=ido;
  105622. t3+=ido;
  105623. }
  105624. }
  105625. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105626. float *wa2,float *wa3){
  105627. static float hsqt2 = .70710678118654752f;
  105628. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105629. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105630. t0=l1*ido;
  105631. t1=t0;
  105632. t4=t1<<1;
  105633. t2=t1+(t1<<1);
  105634. t3=0;
  105635. for(k=0;k<l1;k++){
  105636. tr1=cc[t1]+cc[t2];
  105637. tr2=cc[t3]+cc[t4];
  105638. ch[t5=t3<<2]=tr1+tr2;
  105639. ch[(ido<<2)+t5-1]=tr2-tr1;
  105640. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105641. ch[t5]=cc[t2]-cc[t1];
  105642. t1+=ido;
  105643. t2+=ido;
  105644. t3+=ido;
  105645. t4+=ido;
  105646. }
  105647. if(ido<2)return;
  105648. if(ido==2)goto L105;
  105649. t1=0;
  105650. for(k=0;k<l1;k++){
  105651. t2=t1;
  105652. t4=t1<<2;
  105653. t5=(t6=ido<<1)+t4;
  105654. for(i=2;i<ido;i+=2){
  105655. t3=(t2+=2);
  105656. t4+=2;
  105657. t5-=2;
  105658. t3+=t0;
  105659. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105660. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105661. t3+=t0;
  105662. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105663. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105664. t3+=t0;
  105665. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105666. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105667. tr1=cr2+cr4;
  105668. tr4=cr4-cr2;
  105669. ti1=ci2+ci4;
  105670. ti4=ci2-ci4;
  105671. ti2=cc[t2]+ci3;
  105672. ti3=cc[t2]-ci3;
  105673. tr2=cc[t2-1]+cr3;
  105674. tr3=cc[t2-1]-cr3;
  105675. ch[t4-1]=tr1+tr2;
  105676. ch[t4]=ti1+ti2;
  105677. ch[t5-1]=tr3-ti4;
  105678. ch[t5]=tr4-ti3;
  105679. ch[t4+t6-1]=ti4+tr3;
  105680. ch[t4+t6]=tr4+ti3;
  105681. ch[t5+t6-1]=tr2-tr1;
  105682. ch[t5+t6]=ti1-ti2;
  105683. }
  105684. t1+=ido;
  105685. }
  105686. if(ido&1)return;
  105687. L105:
  105688. t2=(t1=t0+ido-1)+(t0<<1);
  105689. t3=ido<<2;
  105690. t4=ido;
  105691. t5=ido<<1;
  105692. t6=ido;
  105693. for(k=0;k<l1;k++){
  105694. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105695. tr1=hsqt2*(cc[t1]-cc[t2]);
  105696. ch[t4-1]=tr1+cc[t6-1];
  105697. ch[t4+t5-1]=cc[t6-1]-tr1;
  105698. ch[t4]=ti1-cc[t1+t0];
  105699. ch[t4+t5]=ti1+cc[t1+t0];
  105700. t1+=ido;
  105701. t2+=ido;
  105702. t4+=t3;
  105703. t6+=ido;
  105704. }
  105705. }
  105706. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105707. float *c2,float *ch,float *ch2,float *wa){
  105708. static float tpi=6.283185307179586f;
  105709. int idij,ipph,i,j,k,l,ic,ik,is;
  105710. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105711. float dc2,ai1,ai2,ar1,ar2,ds2;
  105712. int nbd;
  105713. float dcp,arg,dsp,ar1h,ar2h;
  105714. int idp2,ipp2;
  105715. arg=tpi/(float)ip;
  105716. dcp=cos(arg);
  105717. dsp=sin(arg);
  105718. ipph=(ip+1)>>1;
  105719. ipp2=ip;
  105720. idp2=ido;
  105721. nbd=(ido-1)>>1;
  105722. t0=l1*ido;
  105723. t10=ip*ido;
  105724. if(ido==1)goto L119;
  105725. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105726. t1=0;
  105727. for(j=1;j<ip;j++){
  105728. t1+=t0;
  105729. t2=t1;
  105730. for(k=0;k<l1;k++){
  105731. ch[t2]=c1[t2];
  105732. t2+=ido;
  105733. }
  105734. }
  105735. is=-ido;
  105736. t1=0;
  105737. if(nbd>l1){
  105738. for(j=1;j<ip;j++){
  105739. t1+=t0;
  105740. is+=ido;
  105741. t2= -ido+t1;
  105742. for(k=0;k<l1;k++){
  105743. idij=is-1;
  105744. t2+=ido;
  105745. t3=t2;
  105746. for(i=2;i<ido;i+=2){
  105747. idij+=2;
  105748. t3+=2;
  105749. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105750. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105751. }
  105752. }
  105753. }
  105754. }else{
  105755. for(j=1;j<ip;j++){
  105756. is+=ido;
  105757. idij=is-1;
  105758. t1+=t0;
  105759. t2=t1;
  105760. for(i=2;i<ido;i+=2){
  105761. idij+=2;
  105762. t2+=2;
  105763. t3=t2;
  105764. for(k=0;k<l1;k++){
  105765. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105766. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105767. t3+=ido;
  105768. }
  105769. }
  105770. }
  105771. }
  105772. t1=0;
  105773. t2=ipp2*t0;
  105774. if(nbd<l1){
  105775. for(j=1;j<ipph;j++){
  105776. t1+=t0;
  105777. t2-=t0;
  105778. t3=t1;
  105779. t4=t2;
  105780. for(i=2;i<ido;i+=2){
  105781. t3+=2;
  105782. t4+=2;
  105783. t5=t3-ido;
  105784. t6=t4-ido;
  105785. for(k=0;k<l1;k++){
  105786. t5+=ido;
  105787. t6+=ido;
  105788. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105789. c1[t6-1]=ch[t5]-ch[t6];
  105790. c1[t5]=ch[t5]+ch[t6];
  105791. c1[t6]=ch[t6-1]-ch[t5-1];
  105792. }
  105793. }
  105794. }
  105795. }else{
  105796. for(j=1;j<ipph;j++){
  105797. t1+=t0;
  105798. t2-=t0;
  105799. t3=t1;
  105800. t4=t2;
  105801. for(k=0;k<l1;k++){
  105802. t5=t3;
  105803. t6=t4;
  105804. for(i=2;i<ido;i+=2){
  105805. t5+=2;
  105806. t6+=2;
  105807. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105808. c1[t6-1]=ch[t5]-ch[t6];
  105809. c1[t5]=ch[t5]+ch[t6];
  105810. c1[t6]=ch[t6-1]-ch[t5-1];
  105811. }
  105812. t3+=ido;
  105813. t4+=ido;
  105814. }
  105815. }
  105816. }
  105817. L119:
  105818. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105819. t1=0;
  105820. t2=ipp2*idl1;
  105821. for(j=1;j<ipph;j++){
  105822. t1+=t0;
  105823. t2-=t0;
  105824. t3=t1-ido;
  105825. t4=t2-ido;
  105826. for(k=0;k<l1;k++){
  105827. t3+=ido;
  105828. t4+=ido;
  105829. c1[t3]=ch[t3]+ch[t4];
  105830. c1[t4]=ch[t4]-ch[t3];
  105831. }
  105832. }
  105833. ar1=1.f;
  105834. ai1=0.f;
  105835. t1=0;
  105836. 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=t3;
  105847. t7=idl1;
  105848. for(ik=0;ik<idl1;ik++){
  105849. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105850. ch2[t5++]=ai1*c2[t6++];
  105851. }
  105852. dc2=ar1;
  105853. ds2=ai1;
  105854. ar2=ar1;
  105855. ai2=ai1;
  105856. t4=idl1;
  105857. t5=(ipp2-1)*idl1;
  105858. for(j=2;j<ipph;j++){
  105859. t4+=idl1;
  105860. t5-=idl1;
  105861. ar2h=dc2*ar2-ds2*ai2;
  105862. ai2=dc2*ai2+ds2*ar2;
  105863. ar2=ar2h;
  105864. t6=t1;
  105865. t7=t2;
  105866. t8=t4;
  105867. t9=t5;
  105868. for(ik=0;ik<idl1;ik++){
  105869. ch2[t6++]+=ar2*c2[t8++];
  105870. ch2[t7++]+=ai2*c2[t9++];
  105871. }
  105872. }
  105873. }
  105874. t1=0;
  105875. for(j=1;j<ipph;j++){
  105876. t1+=idl1;
  105877. t2=t1;
  105878. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105879. }
  105880. if(ido<l1)goto L132;
  105881. t1=0;
  105882. t2=0;
  105883. for(k=0;k<l1;k++){
  105884. t3=t1;
  105885. t4=t2;
  105886. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105887. t1+=ido;
  105888. t2+=t10;
  105889. }
  105890. goto L135;
  105891. L132:
  105892. for(i=0;i<ido;i++){
  105893. t1=i;
  105894. t2=i;
  105895. for(k=0;k<l1;k++){
  105896. cc[t2]=ch[t1];
  105897. t1+=ido;
  105898. t2+=t10;
  105899. }
  105900. }
  105901. L135:
  105902. t1=0;
  105903. t2=ido<<1;
  105904. t3=0;
  105905. t4=ipp2*t0;
  105906. for(j=1;j<ipph;j++){
  105907. t1+=t2;
  105908. t3+=t0;
  105909. t4-=t0;
  105910. t5=t1;
  105911. t6=t3;
  105912. t7=t4;
  105913. for(k=0;k<l1;k++){
  105914. cc[t5-1]=ch[t6];
  105915. cc[t5]=ch[t7];
  105916. t5+=t10;
  105917. t6+=ido;
  105918. t7+=ido;
  105919. }
  105920. }
  105921. if(ido==1)return;
  105922. if(nbd<l1)goto L141;
  105923. t1=-ido;
  105924. t3=0;
  105925. t4=0;
  105926. t5=ipp2*t0;
  105927. for(j=1;j<ipph;j++){
  105928. t1+=t2;
  105929. t3+=t2;
  105930. t4+=t0;
  105931. t5-=t0;
  105932. t6=t1;
  105933. t7=t3;
  105934. t8=t4;
  105935. t9=t5;
  105936. for(k=0;k<l1;k++){
  105937. for(i=2;i<ido;i+=2){
  105938. ic=idp2-i;
  105939. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105940. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105941. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105942. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105943. }
  105944. t6+=t10;
  105945. t7+=t10;
  105946. t8+=ido;
  105947. t9+=ido;
  105948. }
  105949. }
  105950. return;
  105951. L141:
  105952. t1=-ido;
  105953. t3=0;
  105954. t4=0;
  105955. t5=ipp2*t0;
  105956. for(j=1;j<ipph;j++){
  105957. t1+=t2;
  105958. t3+=t2;
  105959. t4+=t0;
  105960. t5-=t0;
  105961. for(i=2;i<ido;i+=2){
  105962. t6=idp2+t1-i;
  105963. t7=i+t3;
  105964. t8=i+t4;
  105965. t9=i+t5;
  105966. for(k=0;k<l1;k++){
  105967. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105968. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105969. cc[t7]=ch[t8]+ch[t9];
  105970. cc[t6]=ch[t9]-ch[t8];
  105971. t6+=t10;
  105972. t7+=t10;
  105973. t8+=ido;
  105974. t9+=ido;
  105975. }
  105976. }
  105977. }
  105978. }
  105979. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105980. int i,k1,l1,l2;
  105981. int na,kh,nf;
  105982. int ip,iw,ido,idl1,ix2,ix3;
  105983. nf=ifac[1];
  105984. na=1;
  105985. l2=n;
  105986. iw=n;
  105987. for(k1=0;k1<nf;k1++){
  105988. kh=nf-k1;
  105989. ip=ifac[kh+1];
  105990. l1=l2/ip;
  105991. ido=n/l2;
  105992. idl1=ido*l1;
  105993. iw-=(ip-1)*ido;
  105994. na=1-na;
  105995. if(ip!=4)goto L102;
  105996. ix2=iw+ido;
  105997. ix3=ix2+ido;
  105998. if(na!=0)
  105999. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106000. else
  106001. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106002. goto L110;
  106003. L102:
  106004. if(ip!=2)goto L104;
  106005. if(na!=0)goto L103;
  106006. dradf2(ido,l1,c,ch,wa+iw-1);
  106007. goto L110;
  106008. L103:
  106009. dradf2(ido,l1,ch,c,wa+iw-1);
  106010. goto L110;
  106011. L104:
  106012. if(ido==1)na=1-na;
  106013. if(na!=0)goto L109;
  106014. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106015. na=1;
  106016. goto L110;
  106017. L109:
  106018. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106019. na=0;
  106020. L110:
  106021. l2=l1;
  106022. }
  106023. if(na==1)return;
  106024. for(i=0;i<n;i++)c[i]=ch[i];
  106025. }
  106026. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  106027. int i,k,t0,t1,t2,t3,t4,t5,t6;
  106028. float ti2,tr2;
  106029. t0=l1*ido;
  106030. t1=0;
  106031. t2=0;
  106032. t3=(ido<<1)-1;
  106033. for(k=0;k<l1;k++){
  106034. ch[t1]=cc[t2]+cc[t3+t2];
  106035. ch[t1+t0]=cc[t2]-cc[t3+t2];
  106036. t2=(t1+=ido)<<1;
  106037. }
  106038. if(ido<2)return;
  106039. if(ido==2)goto L105;
  106040. t1=0;
  106041. t2=0;
  106042. for(k=0;k<l1;k++){
  106043. t3=t1;
  106044. t5=(t4=t2)+(ido<<1);
  106045. t6=t0+t1;
  106046. for(i=2;i<ido;i+=2){
  106047. t3+=2;
  106048. t4+=2;
  106049. t5-=2;
  106050. t6+=2;
  106051. ch[t3-1]=cc[t4-1]+cc[t5-1];
  106052. tr2=cc[t4-1]-cc[t5-1];
  106053. ch[t3]=cc[t4]-cc[t5];
  106054. ti2=cc[t4]+cc[t5];
  106055. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  106056. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  106057. }
  106058. t2=(t1+=ido)<<1;
  106059. }
  106060. if(ido%2==1)return;
  106061. L105:
  106062. t1=ido-1;
  106063. t2=ido-1;
  106064. for(k=0;k<l1;k++){
  106065. ch[t1]=cc[t2]+cc[t2];
  106066. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  106067. t1+=ido;
  106068. t2+=ido<<1;
  106069. }
  106070. }
  106071. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  106072. float *wa2){
  106073. static float taur = -.5f;
  106074. static float taui = .8660254037844386f;
  106075. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106076. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  106077. t0=l1*ido;
  106078. t1=0;
  106079. t2=t0<<1;
  106080. t3=ido<<1;
  106081. t4=ido+(ido<<1);
  106082. t5=0;
  106083. for(k=0;k<l1;k++){
  106084. tr2=cc[t3-1]+cc[t3-1];
  106085. cr2=cc[t5]+(taur*tr2);
  106086. ch[t1]=cc[t5]+tr2;
  106087. ci3=taui*(cc[t3]+cc[t3]);
  106088. ch[t1+t0]=cr2-ci3;
  106089. ch[t1+t2]=cr2+ci3;
  106090. t1+=ido;
  106091. t3+=t4;
  106092. t5+=t4;
  106093. }
  106094. if(ido==1)return;
  106095. t1=0;
  106096. t3=ido<<1;
  106097. for(k=0;k<l1;k++){
  106098. t7=t1+(t1<<1);
  106099. t6=(t5=t7+t3);
  106100. t8=t1;
  106101. t10=(t9=t1+t0)+t0;
  106102. for(i=2;i<ido;i+=2){
  106103. t5+=2;
  106104. t6-=2;
  106105. t7+=2;
  106106. t8+=2;
  106107. t9+=2;
  106108. t10+=2;
  106109. tr2=cc[t5-1]+cc[t6-1];
  106110. cr2=cc[t7-1]+(taur*tr2);
  106111. ch[t8-1]=cc[t7-1]+tr2;
  106112. ti2=cc[t5]-cc[t6];
  106113. ci2=cc[t7]+(taur*ti2);
  106114. ch[t8]=cc[t7]+ti2;
  106115. cr3=taui*(cc[t5-1]-cc[t6-1]);
  106116. ci3=taui*(cc[t5]+cc[t6]);
  106117. dr2=cr2-ci3;
  106118. dr3=cr2+ci3;
  106119. di2=ci2+cr3;
  106120. di3=ci2-cr3;
  106121. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  106122. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  106123. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  106124. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  106125. }
  106126. t1+=ido;
  106127. }
  106128. }
  106129. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  106130. float *wa2,float *wa3){
  106131. static float sqrt2=1.414213562373095f;
  106132. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  106133. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106134. t0=l1*ido;
  106135. t1=0;
  106136. t2=ido<<2;
  106137. t3=0;
  106138. t6=ido<<1;
  106139. for(k=0;k<l1;k++){
  106140. t4=t3+t6;
  106141. t5=t1;
  106142. tr3=cc[t4-1]+cc[t4-1];
  106143. tr4=cc[t4]+cc[t4];
  106144. tr1=cc[t3]-cc[(t4+=t6)-1];
  106145. tr2=cc[t3]+cc[t4-1];
  106146. ch[t5]=tr2+tr3;
  106147. ch[t5+=t0]=tr1-tr4;
  106148. ch[t5+=t0]=tr2-tr3;
  106149. ch[t5+=t0]=tr1+tr4;
  106150. t1+=ido;
  106151. t3+=t2;
  106152. }
  106153. if(ido<2)return;
  106154. if(ido==2)goto L105;
  106155. t1=0;
  106156. for(k=0;k<l1;k++){
  106157. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  106158. t7=t1;
  106159. for(i=2;i<ido;i+=2){
  106160. t2+=2;
  106161. t3+=2;
  106162. t4-=2;
  106163. t5-=2;
  106164. t7+=2;
  106165. ti1=cc[t2]+cc[t5];
  106166. ti2=cc[t2]-cc[t5];
  106167. ti3=cc[t3]-cc[t4];
  106168. tr4=cc[t3]+cc[t4];
  106169. tr1=cc[t2-1]-cc[t5-1];
  106170. tr2=cc[t2-1]+cc[t5-1];
  106171. ti4=cc[t3-1]-cc[t4-1];
  106172. tr3=cc[t3-1]+cc[t4-1];
  106173. ch[t7-1]=tr2+tr3;
  106174. cr3=tr2-tr3;
  106175. ch[t7]=ti2+ti3;
  106176. ci3=ti2-ti3;
  106177. cr2=tr1-tr4;
  106178. cr4=tr1+tr4;
  106179. ci2=ti1+ti4;
  106180. ci4=ti1-ti4;
  106181. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  106182. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  106183. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  106184. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  106185. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  106186. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  106187. }
  106188. t1+=ido;
  106189. }
  106190. if(ido%2 == 1)return;
  106191. L105:
  106192. t1=ido;
  106193. t2=ido<<2;
  106194. t3=ido-1;
  106195. t4=ido+(ido<<1);
  106196. for(k=0;k<l1;k++){
  106197. t5=t3;
  106198. ti1=cc[t1]+cc[t4];
  106199. ti2=cc[t4]-cc[t1];
  106200. tr1=cc[t1-1]-cc[t4-1];
  106201. tr2=cc[t1-1]+cc[t4-1];
  106202. ch[t5]=tr2+tr2;
  106203. ch[t5+=t0]=sqrt2*(tr1-ti1);
  106204. ch[t5+=t0]=ti2+ti2;
  106205. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  106206. t3+=ido;
  106207. t1+=t2;
  106208. t4+=t2;
  106209. }
  106210. }
  106211. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106212. float *c2,float *ch,float *ch2,float *wa){
  106213. static float tpi=6.283185307179586f;
  106214. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  106215. t11,t12;
  106216. float dc2,ai1,ai2,ar1,ar2,ds2;
  106217. int nbd;
  106218. float dcp,arg,dsp,ar1h,ar2h;
  106219. int ipp2;
  106220. t10=ip*ido;
  106221. t0=l1*ido;
  106222. arg=tpi/(float)ip;
  106223. dcp=cos(arg);
  106224. dsp=sin(arg);
  106225. nbd=(ido-1)>>1;
  106226. ipp2=ip;
  106227. ipph=(ip+1)>>1;
  106228. if(ido<l1)goto L103;
  106229. t1=0;
  106230. t2=0;
  106231. for(k=0;k<l1;k++){
  106232. t3=t1;
  106233. t4=t2;
  106234. for(i=0;i<ido;i++){
  106235. ch[t3]=cc[t4];
  106236. t3++;
  106237. t4++;
  106238. }
  106239. t1+=ido;
  106240. t2+=t10;
  106241. }
  106242. goto L106;
  106243. L103:
  106244. t1=0;
  106245. for(i=0;i<ido;i++){
  106246. t2=t1;
  106247. t3=t1;
  106248. for(k=0;k<l1;k++){
  106249. ch[t2]=cc[t3];
  106250. t2+=ido;
  106251. t3+=t10;
  106252. }
  106253. t1++;
  106254. }
  106255. L106:
  106256. t1=0;
  106257. t2=ipp2*t0;
  106258. t7=(t5=ido<<1);
  106259. for(j=1;j<ipph;j++){
  106260. t1+=t0;
  106261. t2-=t0;
  106262. t3=t1;
  106263. t4=t2;
  106264. t6=t5;
  106265. for(k=0;k<l1;k++){
  106266. ch[t3]=cc[t6-1]+cc[t6-1];
  106267. ch[t4]=cc[t6]+cc[t6];
  106268. t3+=ido;
  106269. t4+=ido;
  106270. t6+=t10;
  106271. }
  106272. t5+=t7;
  106273. }
  106274. if (ido == 1)goto L116;
  106275. if(nbd<l1)goto L112;
  106276. t1=0;
  106277. t2=ipp2*t0;
  106278. t7=0;
  106279. for(j=1;j<ipph;j++){
  106280. t1+=t0;
  106281. t2-=t0;
  106282. t3=t1;
  106283. t4=t2;
  106284. t7+=(ido<<1);
  106285. t8=t7;
  106286. for(k=0;k<l1;k++){
  106287. t5=t3;
  106288. t6=t4;
  106289. t9=t8;
  106290. t11=t8;
  106291. for(i=2;i<ido;i+=2){
  106292. t5+=2;
  106293. t6+=2;
  106294. t9+=2;
  106295. t11-=2;
  106296. ch[t5-1]=cc[t9-1]+cc[t11-1];
  106297. ch[t6-1]=cc[t9-1]-cc[t11-1];
  106298. ch[t5]=cc[t9]-cc[t11];
  106299. ch[t6]=cc[t9]+cc[t11];
  106300. }
  106301. t3+=ido;
  106302. t4+=ido;
  106303. t8+=t10;
  106304. }
  106305. }
  106306. goto L116;
  106307. L112:
  106308. t1=0;
  106309. t2=ipp2*t0;
  106310. t7=0;
  106311. for(j=1;j<ipph;j++){
  106312. t1+=t0;
  106313. t2-=t0;
  106314. t3=t1;
  106315. t4=t2;
  106316. t7+=(ido<<1);
  106317. t8=t7;
  106318. t9=t7;
  106319. for(i=2;i<ido;i+=2){
  106320. t3+=2;
  106321. t4+=2;
  106322. t8+=2;
  106323. t9-=2;
  106324. t5=t3;
  106325. t6=t4;
  106326. t11=t8;
  106327. t12=t9;
  106328. for(k=0;k<l1;k++){
  106329. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106330. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106331. ch[t5]=cc[t11]-cc[t12];
  106332. ch[t6]=cc[t11]+cc[t12];
  106333. t5+=ido;
  106334. t6+=ido;
  106335. t11+=t10;
  106336. t12+=t10;
  106337. }
  106338. }
  106339. }
  106340. L116:
  106341. ar1=1.f;
  106342. ai1=0.f;
  106343. t1=0;
  106344. t9=(t2=ipp2*idl1);
  106345. t3=(ip-1)*idl1;
  106346. for(l=1;l<ipph;l++){
  106347. t1+=idl1;
  106348. t2-=idl1;
  106349. ar1h=dcp*ar1-dsp*ai1;
  106350. ai1=dcp*ai1+dsp*ar1;
  106351. ar1=ar1h;
  106352. t4=t1;
  106353. t5=t2;
  106354. t6=0;
  106355. t7=idl1;
  106356. t8=t3;
  106357. for(ik=0;ik<idl1;ik++){
  106358. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106359. c2[t5++]=ai1*ch2[t8++];
  106360. }
  106361. dc2=ar1;
  106362. ds2=ai1;
  106363. ar2=ar1;
  106364. ai2=ai1;
  106365. t6=idl1;
  106366. t7=t9-idl1;
  106367. for(j=2;j<ipph;j++){
  106368. t6+=idl1;
  106369. t7-=idl1;
  106370. ar2h=dc2*ar2-ds2*ai2;
  106371. ai2=dc2*ai2+ds2*ar2;
  106372. ar2=ar2h;
  106373. t4=t1;
  106374. t5=t2;
  106375. t11=t6;
  106376. t12=t7;
  106377. for(ik=0;ik<idl1;ik++){
  106378. c2[t4++]+=ar2*ch2[t11++];
  106379. c2[t5++]+=ai2*ch2[t12++];
  106380. }
  106381. }
  106382. }
  106383. t1=0;
  106384. for(j=1;j<ipph;j++){
  106385. t1+=idl1;
  106386. t2=t1;
  106387. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106388. }
  106389. t1=0;
  106390. t2=ipp2*t0;
  106391. for(j=1;j<ipph;j++){
  106392. t1+=t0;
  106393. t2-=t0;
  106394. t3=t1;
  106395. t4=t2;
  106396. for(k=0;k<l1;k++){
  106397. ch[t3]=c1[t3]-c1[t4];
  106398. ch[t4]=c1[t3]+c1[t4];
  106399. t3+=ido;
  106400. t4+=ido;
  106401. }
  106402. }
  106403. if(ido==1)goto L132;
  106404. if(nbd<l1)goto L128;
  106405. t1=0;
  106406. t2=ipp2*t0;
  106407. for(j=1;j<ipph;j++){
  106408. t1+=t0;
  106409. t2-=t0;
  106410. t3=t1;
  106411. t4=t2;
  106412. for(k=0;k<l1;k++){
  106413. t5=t3;
  106414. t6=t4;
  106415. for(i=2;i<ido;i+=2){
  106416. t5+=2;
  106417. t6+=2;
  106418. ch[t5-1]=c1[t5-1]-c1[t6];
  106419. ch[t6-1]=c1[t5-1]+c1[t6];
  106420. ch[t5]=c1[t5]+c1[t6-1];
  106421. ch[t6]=c1[t5]-c1[t6-1];
  106422. }
  106423. t3+=ido;
  106424. t4+=ido;
  106425. }
  106426. }
  106427. goto L132;
  106428. L128:
  106429. t1=0;
  106430. t2=ipp2*t0;
  106431. for(j=1;j<ipph;j++){
  106432. t1+=t0;
  106433. t2-=t0;
  106434. t3=t1;
  106435. t4=t2;
  106436. for(i=2;i<ido;i+=2){
  106437. t3+=2;
  106438. t4+=2;
  106439. t5=t3;
  106440. t6=t4;
  106441. for(k=0;k<l1;k++){
  106442. ch[t5-1]=c1[t5-1]-c1[t6];
  106443. ch[t6-1]=c1[t5-1]+c1[t6];
  106444. ch[t5]=c1[t5]+c1[t6-1];
  106445. ch[t6]=c1[t5]-c1[t6-1];
  106446. t5+=ido;
  106447. t6+=ido;
  106448. }
  106449. }
  106450. }
  106451. L132:
  106452. if(ido==1)return;
  106453. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106454. t1=0;
  106455. for(j=1;j<ip;j++){
  106456. t2=(t1+=t0);
  106457. for(k=0;k<l1;k++){
  106458. c1[t2]=ch[t2];
  106459. t2+=ido;
  106460. }
  106461. }
  106462. if(nbd>l1)goto L139;
  106463. is= -ido-1;
  106464. t1=0;
  106465. for(j=1;j<ip;j++){
  106466. is+=ido;
  106467. t1+=t0;
  106468. idij=is;
  106469. t2=t1;
  106470. for(i=2;i<ido;i+=2){
  106471. t2+=2;
  106472. idij+=2;
  106473. t3=t2;
  106474. for(k=0;k<l1;k++){
  106475. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106476. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106477. t3+=ido;
  106478. }
  106479. }
  106480. }
  106481. return;
  106482. L139:
  106483. is= -ido-1;
  106484. t1=0;
  106485. for(j=1;j<ip;j++){
  106486. is+=ido;
  106487. t1+=t0;
  106488. t2=t1;
  106489. for(k=0;k<l1;k++){
  106490. idij=is;
  106491. t3=t2;
  106492. for(i=2;i<ido;i+=2){
  106493. idij+=2;
  106494. t3+=2;
  106495. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106496. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106497. }
  106498. t2+=ido;
  106499. }
  106500. }
  106501. }
  106502. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106503. int i,k1,l1,l2;
  106504. int na;
  106505. int nf,ip,iw,ix2,ix3,ido,idl1;
  106506. nf=ifac[1];
  106507. na=0;
  106508. l1=1;
  106509. iw=1;
  106510. for(k1=0;k1<nf;k1++){
  106511. ip=ifac[k1 + 2];
  106512. l2=ip*l1;
  106513. ido=n/l2;
  106514. idl1=ido*l1;
  106515. if(ip!=4)goto L103;
  106516. ix2=iw+ido;
  106517. ix3=ix2+ido;
  106518. if(na!=0)
  106519. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106520. else
  106521. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106522. na=1-na;
  106523. goto L115;
  106524. L103:
  106525. if(ip!=2)goto L106;
  106526. if(na!=0)
  106527. dradb2(ido,l1,ch,c,wa+iw-1);
  106528. else
  106529. dradb2(ido,l1,c,ch,wa+iw-1);
  106530. na=1-na;
  106531. goto L115;
  106532. L106:
  106533. if(ip!=3)goto L109;
  106534. ix2=iw+ido;
  106535. if(na!=0)
  106536. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106537. else
  106538. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106539. na=1-na;
  106540. goto L115;
  106541. L109:
  106542. if(na!=0)
  106543. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106544. else
  106545. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106546. if(ido==1)na=1-na;
  106547. L115:
  106548. l1=l2;
  106549. iw+=(ip-1)*ido;
  106550. }
  106551. if(na==0)return;
  106552. for(i=0;i<n;i++)c[i]=ch[i];
  106553. }
  106554. void drft_forward(drft_lookup *l,float *data){
  106555. if(l->n==1)return;
  106556. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106557. }
  106558. void drft_backward(drft_lookup *l,float *data){
  106559. if (l->n==1)return;
  106560. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106561. }
  106562. void drft_init(drft_lookup *l,int n){
  106563. l->n=n;
  106564. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106565. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106566. fdrffti(n, l->trigcache, l->splitcache);
  106567. }
  106568. void drft_clear(drft_lookup *l){
  106569. if(l){
  106570. if(l->trigcache)_ogg_free(l->trigcache);
  106571. if(l->splitcache)_ogg_free(l->splitcache);
  106572. memset(l,0,sizeof(*l));
  106573. }
  106574. }
  106575. #endif
  106576. /*** End of inlined file: smallft.c ***/
  106577. /*** Start of inlined file: synthesis.c ***/
  106578. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106579. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106580. // tasks..
  106581. #if JUCE_MSVC
  106582. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106583. #endif
  106584. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106585. #if JUCE_USE_OGGVORBIS
  106586. #include <stdio.h>
  106587. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106588. vorbis_dsp_state *vd=vb->vd;
  106589. private_state *b=(private_state*)vd->backend_state;
  106590. vorbis_info *vi=vd->vi;
  106591. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106592. oggpack_buffer *opb=&vb->opb;
  106593. int type,mode,i;
  106594. _vorbis_block_ripcord(vb);
  106595. oggpack_readinit(opb,op->packet,op->bytes);
  106596. if(oggpack_read(opb,1)!=0){
  106597. return(OV_ENOTAUDIO);
  106598. }
  106599. mode=oggpack_read(opb,b->modebits);
  106600. if(mode==-1)return(OV_EBADPACKET);
  106601. vb->mode=mode;
  106602. vb->W=ci->mode_param[mode]->blockflag;
  106603. if(vb->W){
  106604. vb->lW=oggpack_read(opb,1);
  106605. vb->nW=oggpack_read(opb,1);
  106606. if(vb->nW==-1) return(OV_EBADPACKET);
  106607. }else{
  106608. vb->lW=0;
  106609. vb->nW=0;
  106610. }
  106611. vb->granulepos=op->granulepos;
  106612. vb->sequence=op->packetno;
  106613. vb->eofflag=op->e_o_s;
  106614. vb->pcmend=ci->blocksizes[vb->W];
  106615. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106616. for(i=0;i<vi->channels;i++)
  106617. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106618. type=ci->map_type[ci->mode_param[mode]->mapping];
  106619. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106620. mapping]));
  106621. }
  106622. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106623. vorbis_dsp_state *vd=vb->vd;
  106624. private_state *b=(private_state*)vd->backend_state;
  106625. vorbis_info *vi=vd->vi;
  106626. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106627. oggpack_buffer *opb=&vb->opb;
  106628. int mode;
  106629. _vorbis_block_ripcord(vb);
  106630. oggpack_readinit(opb,op->packet,op->bytes);
  106631. if(oggpack_read(opb,1)!=0){
  106632. return(OV_ENOTAUDIO);
  106633. }
  106634. mode=oggpack_read(opb,b->modebits);
  106635. if(mode==-1)return(OV_EBADPACKET);
  106636. vb->mode=mode;
  106637. vb->W=ci->mode_param[mode]->blockflag;
  106638. if(vb->W){
  106639. vb->lW=oggpack_read(opb,1);
  106640. vb->nW=oggpack_read(opb,1);
  106641. if(vb->nW==-1) return(OV_EBADPACKET);
  106642. }else{
  106643. vb->lW=0;
  106644. vb->nW=0;
  106645. }
  106646. vb->granulepos=op->granulepos;
  106647. vb->sequence=op->packetno;
  106648. vb->eofflag=op->e_o_s;
  106649. vb->pcmend=0;
  106650. vb->pcm=NULL;
  106651. return(0);
  106652. }
  106653. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106654. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106655. oggpack_buffer opb;
  106656. int mode;
  106657. oggpack_readinit(&opb,op->packet,op->bytes);
  106658. if(oggpack_read(&opb,1)!=0){
  106659. return(OV_ENOTAUDIO);
  106660. }
  106661. {
  106662. int modebits=0;
  106663. int v=ci->modes;
  106664. while(v>1){
  106665. modebits++;
  106666. v>>=1;
  106667. }
  106668. mode=oggpack_read(&opb,modebits);
  106669. }
  106670. if(mode==-1)return(OV_EBADPACKET);
  106671. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106672. }
  106673. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106674. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106675. if(ci->blocksizes[0]<=64 && flag)return -1;
  106676. ci->halfrate_flag=(flag?1:0);
  106677. return 0;
  106678. }
  106679. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106680. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106681. return ci->halfrate_flag;
  106682. }
  106683. #endif
  106684. /*** End of inlined file: synthesis.c ***/
  106685. /*** Start of inlined file: vorbisenc.c ***/
  106686. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106687. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106688. // tasks..
  106689. #if JUCE_MSVC
  106690. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106691. #endif
  106692. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106693. #if JUCE_USE_OGGVORBIS
  106694. #include <stdlib.h>
  106695. #include <string.h>
  106696. #include <math.h>
  106697. typedef struct {
  106698. static_codebook *books[12][3];
  106699. } static_bookblock;
  106700. typedef struct {
  106701. int res_type;
  106702. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106703. vorbis_info_residue0 *res;
  106704. static_codebook *book_aux;
  106705. static_codebook *book_aux_managed;
  106706. static_bookblock *books_base;
  106707. static_bookblock *books_base_managed;
  106708. } vorbis_residue_template;
  106709. typedef struct {
  106710. vorbis_info_mapping0 *map;
  106711. vorbis_residue_template *res;
  106712. } vorbis_mapping_template;
  106713. typedef struct vp_adjblock{
  106714. int block[P_BANDS];
  106715. } vp_adjblock;
  106716. typedef struct {
  106717. int data[NOISE_COMPAND_LEVELS];
  106718. } compandblock;
  106719. typedef struct {
  106720. int att[P_NOISECURVES];
  106721. float boost;
  106722. float decay;
  106723. } att3;
  106724. typedef struct { int data[P_NOISECURVES]; } adj3;
  106725. typedef struct {
  106726. int pre[PACKETBLOBS];
  106727. int post[PACKETBLOBS];
  106728. float kHz[PACKETBLOBS];
  106729. float lowpasskHz[PACKETBLOBS];
  106730. } adj_stereo;
  106731. typedef struct {
  106732. int lo;
  106733. int hi;
  106734. int fixed;
  106735. } noiseguard;
  106736. typedef struct {
  106737. int data[P_NOISECURVES][17];
  106738. } noise3;
  106739. typedef struct {
  106740. int mappings;
  106741. double *rate_mapping;
  106742. double *quality_mapping;
  106743. int coupling_restriction;
  106744. long samplerate_min_restriction;
  106745. long samplerate_max_restriction;
  106746. int *blocksize_short;
  106747. int *blocksize_long;
  106748. att3 *psy_tone_masteratt;
  106749. int *psy_tone_0dB;
  106750. int *psy_tone_dBsuppress;
  106751. vp_adjblock *psy_tone_adj_impulse;
  106752. vp_adjblock *psy_tone_adj_long;
  106753. vp_adjblock *psy_tone_adj_other;
  106754. noiseguard *psy_noiseguards;
  106755. noise3 *psy_noise_bias_impulse;
  106756. noise3 *psy_noise_bias_padding;
  106757. noise3 *psy_noise_bias_trans;
  106758. noise3 *psy_noise_bias_long;
  106759. int *psy_noise_dBsuppress;
  106760. compandblock *psy_noise_compand;
  106761. double *psy_noise_compand_short_mapping;
  106762. double *psy_noise_compand_long_mapping;
  106763. int *psy_noise_normal_start[2];
  106764. int *psy_noise_normal_partition[2];
  106765. double *psy_noise_normal_thresh;
  106766. int *psy_ath_float;
  106767. int *psy_ath_abs;
  106768. double *psy_lowpass;
  106769. vorbis_info_psy_global *global_params;
  106770. double *global_mapping;
  106771. adj_stereo *stereo_modes;
  106772. static_codebook ***floor_books;
  106773. vorbis_info_floor1 *floor_params;
  106774. int *floor_short_mapping;
  106775. int *floor_long_mapping;
  106776. vorbis_mapping_template *maps;
  106777. } ve_setup_data_template;
  106778. static vorbis_info_mode _mode_template[2]={
  106779. {0,0,0,0},
  106780. {1,0,0,1}
  106781. };
  106782. static vorbis_info_mapping0 _map_nominal[2]={
  106783. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106784. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106785. };
  106786. /*** Start of inlined file: setup_44.h ***/
  106787. /*** Start of inlined file: floor_all.h ***/
  106788. /*** Start of inlined file: floor_books.h ***/
  106789. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106790. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106791. };
  106792. static static_codebook _huff_book_line_256x7_0sub1 = {
  106793. 1, 9,
  106794. _huff_lengthlist_line_256x7_0sub1,
  106795. 0, 0, 0, 0, 0,
  106796. NULL,
  106797. NULL,
  106798. NULL,
  106799. NULL,
  106800. 0
  106801. };
  106802. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106804. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106805. };
  106806. static static_codebook _huff_book_line_256x7_0sub2 = {
  106807. 1, 25,
  106808. _huff_lengthlist_line_256x7_0sub2,
  106809. 0, 0, 0, 0, 0,
  106810. NULL,
  106811. NULL,
  106812. NULL,
  106813. NULL,
  106814. 0
  106815. };
  106816. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106819. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106820. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106821. };
  106822. static static_codebook _huff_book_line_256x7_0sub3 = {
  106823. 1, 64,
  106824. _huff_lengthlist_line_256x7_0sub3,
  106825. 0, 0, 0, 0, 0,
  106826. NULL,
  106827. NULL,
  106828. NULL,
  106829. NULL,
  106830. 0
  106831. };
  106832. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106833. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106834. };
  106835. static static_codebook _huff_book_line_256x7_1sub1 = {
  106836. 1, 9,
  106837. _huff_lengthlist_line_256x7_1sub1,
  106838. 0, 0, 0, 0, 0,
  106839. NULL,
  106840. NULL,
  106841. NULL,
  106842. NULL,
  106843. 0
  106844. };
  106845. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106847. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106848. };
  106849. static static_codebook _huff_book_line_256x7_1sub2 = {
  106850. 1, 25,
  106851. _huff_lengthlist_line_256x7_1sub2,
  106852. 0, 0, 0, 0, 0,
  106853. NULL,
  106854. NULL,
  106855. NULL,
  106856. NULL,
  106857. 0
  106858. };
  106859. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106862. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106863. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106864. };
  106865. static static_codebook _huff_book_line_256x7_1sub3 = {
  106866. 1, 64,
  106867. _huff_lengthlist_line_256x7_1sub3,
  106868. 0, 0, 0, 0, 0,
  106869. NULL,
  106870. NULL,
  106871. NULL,
  106872. NULL,
  106873. 0
  106874. };
  106875. static long _huff_lengthlist_line_256x7_class0[] = {
  106876. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106877. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106878. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106879. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106880. };
  106881. static static_codebook _huff_book_line_256x7_class0 = {
  106882. 1, 64,
  106883. _huff_lengthlist_line_256x7_class0,
  106884. 0, 0, 0, 0, 0,
  106885. NULL,
  106886. NULL,
  106887. NULL,
  106888. NULL,
  106889. 0
  106890. };
  106891. static long _huff_lengthlist_line_256x7_class1[] = {
  106892. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106893. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106894. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106895. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106896. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106897. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106898. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106899. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106900. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106901. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106902. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106903. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106904. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106905. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106906. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106907. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106908. };
  106909. static static_codebook _huff_book_line_256x7_class1 = {
  106910. 1, 256,
  106911. _huff_lengthlist_line_256x7_class1,
  106912. 0, 0, 0, 0, 0,
  106913. NULL,
  106914. NULL,
  106915. NULL,
  106916. NULL,
  106917. 0
  106918. };
  106919. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106920. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106921. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106922. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106923. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106924. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106925. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106926. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106927. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106928. };
  106929. static static_codebook _huff_book_line_512x17_0sub0 = {
  106930. 1, 128,
  106931. _huff_lengthlist_line_512x17_0sub0,
  106932. 0, 0, 0, 0, 0,
  106933. NULL,
  106934. NULL,
  106935. NULL,
  106936. NULL,
  106937. 0
  106938. };
  106939. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106940. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106941. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106942. };
  106943. static static_codebook _huff_book_line_512x17_1sub0 = {
  106944. 1, 32,
  106945. _huff_lengthlist_line_512x17_1sub0,
  106946. 0, 0, 0, 0, 0,
  106947. NULL,
  106948. NULL,
  106949. NULL,
  106950. NULL,
  106951. 0
  106952. };
  106953. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106956. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106957. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106958. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106959. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106960. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106961. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106962. };
  106963. static static_codebook _huff_book_line_512x17_1sub1 = {
  106964. 1, 128,
  106965. _huff_lengthlist_line_512x17_1sub1,
  106966. 0, 0, 0, 0, 0,
  106967. NULL,
  106968. NULL,
  106969. NULL,
  106970. NULL,
  106971. 0
  106972. };
  106973. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106974. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106975. 5, 3,
  106976. };
  106977. static static_codebook _huff_book_line_512x17_2sub1 = {
  106978. 1, 18,
  106979. _huff_lengthlist_line_512x17_2sub1,
  106980. 0, 0, 0, 0, 0,
  106981. NULL,
  106982. NULL,
  106983. NULL,
  106984. NULL,
  106985. 0
  106986. };
  106987. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106989. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106990. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106991. 9, 8,
  106992. };
  106993. static static_codebook _huff_book_line_512x17_2sub2 = {
  106994. 1, 50,
  106995. _huff_lengthlist_line_512x17_2sub2,
  106996. 0, 0, 0, 0, 0,
  106997. NULL,
  106998. NULL,
  106999. NULL,
  107000. NULL,
  107001. 0
  107002. };
  107003. static long _huff_lengthlist_line_512x17_2sub3[] = {
  107004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107007. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  107008. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  107009. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107010. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107011. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107012. };
  107013. static static_codebook _huff_book_line_512x17_2sub3 = {
  107014. 1, 128,
  107015. _huff_lengthlist_line_512x17_2sub3,
  107016. 0, 0, 0, 0, 0,
  107017. NULL,
  107018. NULL,
  107019. NULL,
  107020. NULL,
  107021. 0
  107022. };
  107023. static long _huff_lengthlist_line_512x17_3sub1[] = {
  107024. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  107025. 5, 5,
  107026. };
  107027. static static_codebook _huff_book_line_512x17_3sub1 = {
  107028. 1, 18,
  107029. _huff_lengthlist_line_512x17_3sub1,
  107030. 0, 0, 0, 0, 0,
  107031. NULL,
  107032. NULL,
  107033. NULL,
  107034. NULL,
  107035. 0
  107036. };
  107037. static long _huff_lengthlist_line_512x17_3sub2[] = {
  107038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107039. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  107040. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  107041. 11,14,
  107042. };
  107043. static static_codebook _huff_book_line_512x17_3sub2 = {
  107044. 1, 50,
  107045. _huff_lengthlist_line_512x17_3sub2,
  107046. 0, 0, 0, 0, 0,
  107047. NULL,
  107048. NULL,
  107049. NULL,
  107050. NULL,
  107051. 0
  107052. };
  107053. static long _huff_lengthlist_line_512x17_3sub3[] = {
  107054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107057. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  107058. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107059. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107060. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107061. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107062. };
  107063. static static_codebook _huff_book_line_512x17_3sub3 = {
  107064. 1, 128,
  107065. _huff_lengthlist_line_512x17_3sub3,
  107066. 0, 0, 0, 0, 0,
  107067. NULL,
  107068. NULL,
  107069. NULL,
  107070. NULL,
  107071. 0
  107072. };
  107073. static long _huff_lengthlist_line_512x17_class1[] = {
  107074. 1, 2, 3, 6, 5, 4, 7, 7,
  107075. };
  107076. static static_codebook _huff_book_line_512x17_class1 = {
  107077. 1, 8,
  107078. _huff_lengthlist_line_512x17_class1,
  107079. 0, 0, 0, 0, 0,
  107080. NULL,
  107081. NULL,
  107082. NULL,
  107083. NULL,
  107084. 0
  107085. };
  107086. static long _huff_lengthlist_line_512x17_class2[] = {
  107087. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  107088. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  107089. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  107090. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  107091. };
  107092. static static_codebook _huff_book_line_512x17_class2 = {
  107093. 1, 64,
  107094. _huff_lengthlist_line_512x17_class2,
  107095. 0, 0, 0, 0, 0,
  107096. NULL,
  107097. NULL,
  107098. NULL,
  107099. NULL,
  107100. 0
  107101. };
  107102. static long _huff_lengthlist_line_512x17_class3[] = {
  107103. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  107104. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  107105. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  107106. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  107107. };
  107108. static static_codebook _huff_book_line_512x17_class3 = {
  107109. 1, 64,
  107110. _huff_lengthlist_line_512x17_class3,
  107111. 0, 0, 0, 0, 0,
  107112. NULL,
  107113. NULL,
  107114. NULL,
  107115. NULL,
  107116. 0
  107117. };
  107118. static long _huff_lengthlist_line_128x4_class0[] = {
  107119. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  107120. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  107121. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  107122. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  107123. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  107124. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  107125. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  107126. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  107127. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  107128. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  107129. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  107130. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  107131. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  107132. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  107133. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  107134. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  107135. };
  107136. static static_codebook _huff_book_line_128x4_class0 = {
  107137. 1, 256,
  107138. _huff_lengthlist_line_128x4_class0,
  107139. 0, 0, 0, 0, 0,
  107140. NULL,
  107141. NULL,
  107142. NULL,
  107143. NULL,
  107144. 0
  107145. };
  107146. static long _huff_lengthlist_line_128x4_0sub0[] = {
  107147. 2, 2, 2, 2,
  107148. };
  107149. static static_codebook _huff_book_line_128x4_0sub0 = {
  107150. 1, 4,
  107151. _huff_lengthlist_line_128x4_0sub0,
  107152. 0, 0, 0, 0, 0,
  107153. NULL,
  107154. NULL,
  107155. NULL,
  107156. NULL,
  107157. 0
  107158. };
  107159. static long _huff_lengthlist_line_128x4_0sub1[] = {
  107160. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  107161. };
  107162. static static_codebook _huff_book_line_128x4_0sub1 = {
  107163. 1, 10,
  107164. _huff_lengthlist_line_128x4_0sub1,
  107165. 0, 0, 0, 0, 0,
  107166. NULL,
  107167. NULL,
  107168. NULL,
  107169. NULL,
  107170. 0
  107171. };
  107172. static long _huff_lengthlist_line_128x4_0sub2[] = {
  107173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  107174. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  107175. };
  107176. static static_codebook _huff_book_line_128x4_0sub2 = {
  107177. 1, 25,
  107178. _huff_lengthlist_line_128x4_0sub2,
  107179. 0, 0, 0, 0, 0,
  107180. NULL,
  107181. NULL,
  107182. NULL,
  107183. NULL,
  107184. 0
  107185. };
  107186. static long _huff_lengthlist_line_128x4_0sub3[] = {
  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, 2, 4, 3, 5, 3, 5, 3,
  107189. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  107190. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  107191. };
  107192. static static_codebook _huff_book_line_128x4_0sub3 = {
  107193. 1, 64,
  107194. _huff_lengthlist_line_128x4_0sub3,
  107195. 0, 0, 0, 0, 0,
  107196. NULL,
  107197. NULL,
  107198. NULL,
  107199. NULL,
  107200. 0
  107201. };
  107202. static long _huff_lengthlist_line_256x4_class0[] = {
  107203. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  107204. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  107205. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  107206. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  107207. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  107208. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  107209. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  107210. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  107211. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  107212. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  107213. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  107214. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  107215. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  107216. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  107217. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  107218. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  107219. };
  107220. static static_codebook _huff_book_line_256x4_class0 = {
  107221. 1, 256,
  107222. _huff_lengthlist_line_256x4_class0,
  107223. 0, 0, 0, 0, 0,
  107224. NULL,
  107225. NULL,
  107226. NULL,
  107227. NULL,
  107228. 0
  107229. };
  107230. static long _huff_lengthlist_line_256x4_0sub0[] = {
  107231. 2, 2, 2, 2,
  107232. };
  107233. static static_codebook _huff_book_line_256x4_0sub0 = {
  107234. 1, 4,
  107235. _huff_lengthlist_line_256x4_0sub0,
  107236. 0, 0, 0, 0, 0,
  107237. NULL,
  107238. NULL,
  107239. NULL,
  107240. NULL,
  107241. 0
  107242. };
  107243. static long _huff_lengthlist_line_256x4_0sub1[] = {
  107244. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  107245. };
  107246. static static_codebook _huff_book_line_256x4_0sub1 = {
  107247. 1, 10,
  107248. _huff_lengthlist_line_256x4_0sub1,
  107249. 0, 0, 0, 0, 0,
  107250. NULL,
  107251. NULL,
  107252. NULL,
  107253. NULL,
  107254. 0
  107255. };
  107256. static long _huff_lengthlist_line_256x4_0sub2[] = {
  107257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  107258. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  107259. };
  107260. static static_codebook _huff_book_line_256x4_0sub2 = {
  107261. 1, 25,
  107262. _huff_lengthlist_line_256x4_0sub2,
  107263. 0, 0, 0, 0, 0,
  107264. NULL,
  107265. NULL,
  107266. NULL,
  107267. NULL,
  107268. 0
  107269. };
  107270. static long _huff_lengthlist_line_256x4_0sub3[] = {
  107271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107273. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  107274. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  107275. };
  107276. static static_codebook _huff_book_line_256x4_0sub3 = {
  107277. 1, 64,
  107278. _huff_lengthlist_line_256x4_0sub3,
  107279. 0, 0, 0, 0, 0,
  107280. NULL,
  107281. NULL,
  107282. NULL,
  107283. NULL,
  107284. 0
  107285. };
  107286. static long _huff_lengthlist_line_128x7_class0[] = {
  107287. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  107288. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  107289. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  107290. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  107291. };
  107292. static static_codebook _huff_book_line_128x7_class0 = {
  107293. 1, 64,
  107294. _huff_lengthlist_line_128x7_class0,
  107295. 0, 0, 0, 0, 0,
  107296. NULL,
  107297. NULL,
  107298. NULL,
  107299. NULL,
  107300. 0
  107301. };
  107302. static long _huff_lengthlist_line_128x7_class1[] = {
  107303. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  107304. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  107305. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107306. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107307. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107308. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107309. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107310. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107311. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107312. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107313. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107314. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107315. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107316. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107317. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107318. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107319. };
  107320. static static_codebook _huff_book_line_128x7_class1 = {
  107321. 1, 256,
  107322. _huff_lengthlist_line_128x7_class1,
  107323. 0, 0, 0, 0, 0,
  107324. NULL,
  107325. NULL,
  107326. NULL,
  107327. NULL,
  107328. 0
  107329. };
  107330. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107331. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107332. };
  107333. static static_codebook _huff_book_line_128x7_0sub1 = {
  107334. 1, 9,
  107335. _huff_lengthlist_line_128x7_0sub1,
  107336. 0, 0, 0, 0, 0,
  107337. NULL,
  107338. NULL,
  107339. NULL,
  107340. NULL,
  107341. 0
  107342. };
  107343. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107345. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107346. };
  107347. static static_codebook _huff_book_line_128x7_0sub2 = {
  107348. 1, 25,
  107349. _huff_lengthlist_line_128x7_0sub2,
  107350. 0, 0, 0, 0, 0,
  107351. NULL,
  107352. NULL,
  107353. NULL,
  107354. NULL,
  107355. 0
  107356. };
  107357. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107360. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107361. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107362. };
  107363. static static_codebook _huff_book_line_128x7_0sub3 = {
  107364. 1, 64,
  107365. _huff_lengthlist_line_128x7_0sub3,
  107366. 0, 0, 0, 0, 0,
  107367. NULL,
  107368. NULL,
  107369. NULL,
  107370. NULL,
  107371. 0
  107372. };
  107373. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107374. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107375. };
  107376. static static_codebook _huff_book_line_128x7_1sub1 = {
  107377. 1, 9,
  107378. _huff_lengthlist_line_128x7_1sub1,
  107379. 0, 0, 0, 0, 0,
  107380. NULL,
  107381. NULL,
  107382. NULL,
  107383. NULL,
  107384. 0
  107385. };
  107386. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107388. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107389. };
  107390. static static_codebook _huff_book_line_128x7_1sub2 = {
  107391. 1, 25,
  107392. _huff_lengthlist_line_128x7_1sub2,
  107393. 0, 0, 0, 0, 0,
  107394. NULL,
  107395. NULL,
  107396. NULL,
  107397. NULL,
  107398. 0
  107399. };
  107400. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107403. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107404. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107405. };
  107406. static static_codebook _huff_book_line_128x7_1sub3 = {
  107407. 1, 64,
  107408. _huff_lengthlist_line_128x7_1sub3,
  107409. 0, 0, 0, 0, 0,
  107410. NULL,
  107411. NULL,
  107412. NULL,
  107413. NULL,
  107414. 0
  107415. };
  107416. static long _huff_lengthlist_line_128x11_class1[] = {
  107417. 1, 6, 3, 7, 2, 4, 5, 7,
  107418. };
  107419. static static_codebook _huff_book_line_128x11_class1 = {
  107420. 1, 8,
  107421. _huff_lengthlist_line_128x11_class1,
  107422. 0, 0, 0, 0, 0,
  107423. NULL,
  107424. NULL,
  107425. NULL,
  107426. NULL,
  107427. 0
  107428. };
  107429. static long _huff_lengthlist_line_128x11_class2[] = {
  107430. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107431. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107432. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107433. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107434. };
  107435. static static_codebook _huff_book_line_128x11_class2 = {
  107436. 1, 64,
  107437. _huff_lengthlist_line_128x11_class2,
  107438. 0, 0, 0, 0, 0,
  107439. NULL,
  107440. NULL,
  107441. NULL,
  107442. NULL,
  107443. 0
  107444. };
  107445. static long _huff_lengthlist_line_128x11_class3[] = {
  107446. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107447. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107448. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107449. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107450. };
  107451. static static_codebook _huff_book_line_128x11_class3 = {
  107452. 1, 64,
  107453. _huff_lengthlist_line_128x11_class3,
  107454. 0, 0, 0, 0, 0,
  107455. NULL,
  107456. NULL,
  107457. NULL,
  107458. NULL,
  107459. 0
  107460. };
  107461. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107462. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107463. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107464. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107465. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107466. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107467. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107468. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107469. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107470. };
  107471. static static_codebook _huff_book_line_128x11_0sub0 = {
  107472. 1, 128,
  107473. _huff_lengthlist_line_128x11_0sub0,
  107474. 0, 0, 0, 0, 0,
  107475. NULL,
  107476. NULL,
  107477. NULL,
  107478. NULL,
  107479. 0
  107480. };
  107481. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107482. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107483. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107484. };
  107485. static static_codebook _huff_book_line_128x11_1sub0 = {
  107486. 1, 32,
  107487. _huff_lengthlist_line_128x11_1sub0,
  107488. 0, 0, 0, 0, 0,
  107489. NULL,
  107490. NULL,
  107491. NULL,
  107492. NULL,
  107493. 0
  107494. };
  107495. static long _huff_lengthlist_line_128x11_1sub1[] = {
  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. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107499. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107500. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107501. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107502. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107503. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107504. };
  107505. static static_codebook _huff_book_line_128x11_1sub1 = {
  107506. 1, 128,
  107507. _huff_lengthlist_line_128x11_1sub1,
  107508. 0, 0, 0, 0, 0,
  107509. NULL,
  107510. NULL,
  107511. NULL,
  107512. NULL,
  107513. 0
  107514. };
  107515. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107516. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107517. 5, 5,
  107518. };
  107519. static static_codebook _huff_book_line_128x11_2sub1 = {
  107520. 1, 18,
  107521. _huff_lengthlist_line_128x11_2sub1,
  107522. 0, 0, 0, 0, 0,
  107523. NULL,
  107524. NULL,
  107525. NULL,
  107526. NULL,
  107527. 0
  107528. };
  107529. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107531. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107532. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107533. 8,11,
  107534. };
  107535. static static_codebook _huff_book_line_128x11_2sub2 = {
  107536. 1, 50,
  107537. _huff_lengthlist_line_128x11_2sub2,
  107538. 0, 0, 0, 0, 0,
  107539. NULL,
  107540. NULL,
  107541. NULL,
  107542. NULL,
  107543. 0
  107544. };
  107545. static long _huff_lengthlist_line_128x11_2sub3[] = {
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107549. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107550. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107551. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107552. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107553. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107554. };
  107555. static static_codebook _huff_book_line_128x11_2sub3 = {
  107556. 1, 128,
  107557. _huff_lengthlist_line_128x11_2sub3,
  107558. 0, 0, 0, 0, 0,
  107559. NULL,
  107560. NULL,
  107561. NULL,
  107562. NULL,
  107563. 0
  107564. };
  107565. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107566. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107567. 5, 4,
  107568. };
  107569. static static_codebook _huff_book_line_128x11_3sub1 = {
  107570. 1, 18,
  107571. _huff_lengthlist_line_128x11_3sub1,
  107572. 0, 0, 0, 0, 0,
  107573. NULL,
  107574. NULL,
  107575. NULL,
  107576. NULL,
  107577. 0
  107578. };
  107579. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107581. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107582. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107583. 12, 6,
  107584. };
  107585. static static_codebook _huff_book_line_128x11_3sub2 = {
  107586. 1, 50,
  107587. _huff_lengthlist_line_128x11_3sub2,
  107588. 0, 0, 0, 0, 0,
  107589. NULL,
  107590. NULL,
  107591. NULL,
  107592. NULL,
  107593. 0
  107594. };
  107595. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107599. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107600. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107601. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107602. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107603. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107604. };
  107605. static static_codebook _huff_book_line_128x11_3sub3 = {
  107606. 1, 128,
  107607. _huff_lengthlist_line_128x11_3sub3,
  107608. 0, 0, 0, 0, 0,
  107609. NULL,
  107610. NULL,
  107611. NULL,
  107612. NULL,
  107613. 0
  107614. };
  107615. static long _huff_lengthlist_line_128x17_class1[] = {
  107616. 1, 3, 4, 7, 2, 5, 6, 7,
  107617. };
  107618. static static_codebook _huff_book_line_128x17_class1 = {
  107619. 1, 8,
  107620. _huff_lengthlist_line_128x17_class1,
  107621. 0, 0, 0, 0, 0,
  107622. NULL,
  107623. NULL,
  107624. NULL,
  107625. NULL,
  107626. 0
  107627. };
  107628. static long _huff_lengthlist_line_128x17_class2[] = {
  107629. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107630. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107631. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107632. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107633. };
  107634. static static_codebook _huff_book_line_128x17_class2 = {
  107635. 1, 64,
  107636. _huff_lengthlist_line_128x17_class2,
  107637. 0, 0, 0, 0, 0,
  107638. NULL,
  107639. NULL,
  107640. NULL,
  107641. NULL,
  107642. 0
  107643. };
  107644. static long _huff_lengthlist_line_128x17_class3[] = {
  107645. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107646. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107647. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107648. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107649. };
  107650. static static_codebook _huff_book_line_128x17_class3 = {
  107651. 1, 64,
  107652. _huff_lengthlist_line_128x17_class3,
  107653. 0, 0, 0, 0, 0,
  107654. NULL,
  107655. NULL,
  107656. NULL,
  107657. NULL,
  107658. 0
  107659. };
  107660. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107661. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107662. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107663. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107664. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107665. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107666. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107667. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107668. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107669. };
  107670. static static_codebook _huff_book_line_128x17_0sub0 = {
  107671. 1, 128,
  107672. _huff_lengthlist_line_128x17_0sub0,
  107673. 0, 0, 0, 0, 0,
  107674. NULL,
  107675. NULL,
  107676. NULL,
  107677. NULL,
  107678. 0
  107679. };
  107680. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107681. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107682. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107683. };
  107684. static static_codebook _huff_book_line_128x17_1sub0 = {
  107685. 1, 32,
  107686. _huff_lengthlist_line_128x17_1sub0,
  107687. 0, 0, 0, 0, 0,
  107688. NULL,
  107689. NULL,
  107690. NULL,
  107691. NULL,
  107692. 0
  107693. };
  107694. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107697. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107698. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107699. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107700. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107701. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107702. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107703. };
  107704. static static_codebook _huff_book_line_128x17_1sub1 = {
  107705. 1, 128,
  107706. _huff_lengthlist_line_128x17_1sub1,
  107707. 0, 0, 0, 0, 0,
  107708. NULL,
  107709. NULL,
  107710. NULL,
  107711. NULL,
  107712. 0
  107713. };
  107714. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107715. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107716. 9, 4,
  107717. };
  107718. static static_codebook _huff_book_line_128x17_2sub1 = {
  107719. 1, 18,
  107720. _huff_lengthlist_line_128x17_2sub1,
  107721. 0, 0, 0, 0, 0,
  107722. NULL,
  107723. NULL,
  107724. NULL,
  107725. NULL,
  107726. 0
  107727. };
  107728. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107730. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107731. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107732. 13,13,
  107733. };
  107734. static static_codebook _huff_book_line_128x17_2sub2 = {
  107735. 1, 50,
  107736. _huff_lengthlist_line_128x17_2sub2,
  107737. 0, 0, 0, 0, 0,
  107738. NULL,
  107739. NULL,
  107740. NULL,
  107741. NULL,
  107742. 0
  107743. };
  107744. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107748. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107749. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107750. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107751. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107752. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107753. };
  107754. static static_codebook _huff_book_line_128x17_2sub3 = {
  107755. 1, 128,
  107756. _huff_lengthlist_line_128x17_2sub3,
  107757. 0, 0, 0, 0, 0,
  107758. NULL,
  107759. NULL,
  107760. NULL,
  107761. NULL,
  107762. 0
  107763. };
  107764. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107765. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107766. 6, 4,
  107767. };
  107768. static static_codebook _huff_book_line_128x17_3sub1 = {
  107769. 1, 18,
  107770. _huff_lengthlist_line_128x17_3sub1,
  107771. 0, 0, 0, 0, 0,
  107772. NULL,
  107773. NULL,
  107774. NULL,
  107775. NULL,
  107776. 0
  107777. };
  107778. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107780. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107781. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107782. 10, 8,
  107783. };
  107784. static static_codebook _huff_book_line_128x17_3sub2 = {
  107785. 1, 50,
  107786. _huff_lengthlist_line_128x17_3sub2,
  107787. 0, 0, 0, 0, 0,
  107788. NULL,
  107789. NULL,
  107790. NULL,
  107791. NULL,
  107792. 0
  107793. };
  107794. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107798. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107799. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107800. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107801. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107802. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107803. };
  107804. static static_codebook _huff_book_line_128x17_3sub3 = {
  107805. 1, 128,
  107806. _huff_lengthlist_line_128x17_3sub3,
  107807. 0, 0, 0, 0, 0,
  107808. NULL,
  107809. NULL,
  107810. NULL,
  107811. NULL,
  107812. 0
  107813. };
  107814. static long _huff_lengthlist_line_1024x27_class1[] = {
  107815. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107816. };
  107817. static static_codebook _huff_book_line_1024x27_class1 = {
  107818. 1, 16,
  107819. _huff_lengthlist_line_1024x27_class1,
  107820. 0, 0, 0, 0, 0,
  107821. NULL,
  107822. NULL,
  107823. NULL,
  107824. NULL,
  107825. 0
  107826. };
  107827. static long _huff_lengthlist_line_1024x27_class2[] = {
  107828. 1, 4, 2, 6, 3, 7, 5, 7,
  107829. };
  107830. static static_codebook _huff_book_line_1024x27_class2 = {
  107831. 1, 8,
  107832. _huff_lengthlist_line_1024x27_class2,
  107833. 0, 0, 0, 0, 0,
  107834. NULL,
  107835. NULL,
  107836. NULL,
  107837. NULL,
  107838. 0
  107839. };
  107840. static long _huff_lengthlist_line_1024x27_class3[] = {
  107841. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107842. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107843. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107844. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107845. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107846. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107847. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107848. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107849. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107850. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107851. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107852. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107853. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107854. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107855. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107856. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107857. };
  107858. static static_codebook _huff_book_line_1024x27_class3 = {
  107859. 1, 256,
  107860. _huff_lengthlist_line_1024x27_class3,
  107861. 0, 0, 0, 0, 0,
  107862. NULL,
  107863. NULL,
  107864. NULL,
  107865. NULL,
  107866. 0
  107867. };
  107868. static long _huff_lengthlist_line_1024x27_class4[] = {
  107869. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107870. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107871. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107872. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107873. };
  107874. static static_codebook _huff_book_line_1024x27_class4 = {
  107875. 1, 64,
  107876. _huff_lengthlist_line_1024x27_class4,
  107877. 0, 0, 0, 0, 0,
  107878. NULL,
  107879. NULL,
  107880. NULL,
  107881. NULL,
  107882. 0
  107883. };
  107884. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107885. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107886. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107887. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107888. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107889. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107890. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107891. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107892. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107893. };
  107894. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107895. 1, 128,
  107896. _huff_lengthlist_line_1024x27_0sub0,
  107897. 0, 0, 0, 0, 0,
  107898. NULL,
  107899. NULL,
  107900. NULL,
  107901. NULL,
  107902. 0
  107903. };
  107904. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107905. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107906. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107907. };
  107908. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107909. 1, 32,
  107910. _huff_lengthlist_line_1024x27_1sub0,
  107911. 0, 0, 0, 0, 0,
  107912. NULL,
  107913. NULL,
  107914. NULL,
  107915. NULL,
  107916. 0
  107917. };
  107918. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107921. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107922. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107923. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107924. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107925. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107926. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107927. };
  107928. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107929. 1, 128,
  107930. _huff_lengthlist_line_1024x27_1sub1,
  107931. 0, 0, 0, 0, 0,
  107932. NULL,
  107933. NULL,
  107934. NULL,
  107935. NULL,
  107936. 0
  107937. };
  107938. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107939. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107940. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107941. };
  107942. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107943. 1, 32,
  107944. _huff_lengthlist_line_1024x27_2sub0,
  107945. 0, 0, 0, 0, 0,
  107946. NULL,
  107947. NULL,
  107948. NULL,
  107949. NULL,
  107950. 0
  107951. };
  107952. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107955. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107956. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107957. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107958. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107959. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107960. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107961. };
  107962. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107963. 1, 128,
  107964. _huff_lengthlist_line_1024x27_2sub1,
  107965. 0, 0, 0, 0, 0,
  107966. NULL,
  107967. NULL,
  107968. NULL,
  107969. NULL,
  107970. 0
  107971. };
  107972. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107973. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107974. 5, 5,
  107975. };
  107976. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107977. 1, 18,
  107978. _huff_lengthlist_line_1024x27_3sub1,
  107979. 0, 0, 0, 0, 0,
  107980. NULL,
  107981. NULL,
  107982. NULL,
  107983. NULL,
  107984. 0
  107985. };
  107986. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107988. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107989. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107990. 9,11,
  107991. };
  107992. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107993. 1, 50,
  107994. _huff_lengthlist_line_1024x27_3sub2,
  107995. 0, 0, 0, 0, 0,
  107996. NULL,
  107997. NULL,
  107998. NULL,
  107999. NULL,
  108000. 0
  108001. };
  108002. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  108003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108006. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  108007. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  108008. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108009. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108010. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108011. };
  108012. static static_codebook _huff_book_line_1024x27_3sub3 = {
  108013. 1, 128,
  108014. _huff_lengthlist_line_1024x27_3sub3,
  108015. 0, 0, 0, 0, 0,
  108016. NULL,
  108017. NULL,
  108018. NULL,
  108019. NULL,
  108020. 0
  108021. };
  108022. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  108023. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  108024. 5, 4,
  108025. };
  108026. static static_codebook _huff_book_line_1024x27_4sub1 = {
  108027. 1, 18,
  108028. _huff_lengthlist_line_1024x27_4sub1,
  108029. 0, 0, 0, 0, 0,
  108030. NULL,
  108031. NULL,
  108032. NULL,
  108033. NULL,
  108034. 0
  108035. };
  108036. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  108037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108038. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  108039. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  108040. 9,12,
  108041. };
  108042. static static_codebook _huff_book_line_1024x27_4sub2 = {
  108043. 1, 50,
  108044. _huff_lengthlist_line_1024x27_4sub2,
  108045. 0, 0, 0, 0, 0,
  108046. NULL,
  108047. NULL,
  108048. NULL,
  108049. NULL,
  108050. 0
  108051. };
  108052. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  108053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108056. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  108057. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  108058. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108059. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108060. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  108061. };
  108062. static static_codebook _huff_book_line_1024x27_4sub3 = {
  108063. 1, 128,
  108064. _huff_lengthlist_line_1024x27_4sub3,
  108065. 0, 0, 0, 0, 0,
  108066. NULL,
  108067. NULL,
  108068. NULL,
  108069. NULL,
  108070. 0
  108071. };
  108072. static long _huff_lengthlist_line_2048x27_class1[] = {
  108073. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  108074. };
  108075. static static_codebook _huff_book_line_2048x27_class1 = {
  108076. 1, 16,
  108077. _huff_lengthlist_line_2048x27_class1,
  108078. 0, 0, 0, 0, 0,
  108079. NULL,
  108080. NULL,
  108081. NULL,
  108082. NULL,
  108083. 0
  108084. };
  108085. static long _huff_lengthlist_line_2048x27_class2[] = {
  108086. 1, 2, 3, 6, 4, 7, 5, 7,
  108087. };
  108088. static static_codebook _huff_book_line_2048x27_class2 = {
  108089. 1, 8,
  108090. _huff_lengthlist_line_2048x27_class2,
  108091. 0, 0, 0, 0, 0,
  108092. NULL,
  108093. NULL,
  108094. NULL,
  108095. NULL,
  108096. 0
  108097. };
  108098. static long _huff_lengthlist_line_2048x27_class3[] = {
  108099. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  108100. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  108101. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  108102. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  108103. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  108104. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  108105. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  108106. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  108107. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  108108. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  108109. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  108110. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108111. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  108112. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  108113. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108114. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108115. };
  108116. static static_codebook _huff_book_line_2048x27_class3 = {
  108117. 1, 256,
  108118. _huff_lengthlist_line_2048x27_class3,
  108119. 0, 0, 0, 0, 0,
  108120. NULL,
  108121. NULL,
  108122. NULL,
  108123. NULL,
  108124. 0
  108125. };
  108126. static long _huff_lengthlist_line_2048x27_class4[] = {
  108127. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  108128. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  108129. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  108130. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  108131. };
  108132. static static_codebook _huff_book_line_2048x27_class4 = {
  108133. 1, 64,
  108134. _huff_lengthlist_line_2048x27_class4,
  108135. 0, 0, 0, 0, 0,
  108136. NULL,
  108137. NULL,
  108138. NULL,
  108139. NULL,
  108140. 0
  108141. };
  108142. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  108143. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108144. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  108145. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  108146. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  108147. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  108148. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  108149. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  108150. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  108151. };
  108152. static static_codebook _huff_book_line_2048x27_0sub0 = {
  108153. 1, 128,
  108154. _huff_lengthlist_line_2048x27_0sub0,
  108155. 0, 0, 0, 0, 0,
  108156. NULL,
  108157. NULL,
  108158. NULL,
  108159. NULL,
  108160. 0
  108161. };
  108162. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  108163. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  108164. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  108165. };
  108166. static static_codebook _huff_book_line_2048x27_1sub0 = {
  108167. 1, 32,
  108168. _huff_lengthlist_line_2048x27_1sub0,
  108169. 0, 0, 0, 0, 0,
  108170. NULL,
  108171. NULL,
  108172. NULL,
  108173. NULL,
  108174. 0
  108175. };
  108176. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  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. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  108180. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  108181. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  108182. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  108183. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  108184. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  108185. };
  108186. static static_codebook _huff_book_line_2048x27_1sub1 = {
  108187. 1, 128,
  108188. _huff_lengthlist_line_2048x27_1sub1,
  108189. 0, 0, 0, 0, 0,
  108190. NULL,
  108191. NULL,
  108192. NULL,
  108193. NULL,
  108194. 0
  108195. };
  108196. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  108197. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108198. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  108199. };
  108200. static static_codebook _huff_book_line_2048x27_2sub0 = {
  108201. 1, 32,
  108202. _huff_lengthlist_line_2048x27_2sub0,
  108203. 0, 0, 0, 0, 0,
  108204. NULL,
  108205. NULL,
  108206. NULL,
  108207. NULL,
  108208. 0
  108209. };
  108210. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  108211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108213. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  108214. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  108215. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  108216. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  108217. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  108218. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108219. };
  108220. static static_codebook _huff_book_line_2048x27_2sub1 = {
  108221. 1, 128,
  108222. _huff_lengthlist_line_2048x27_2sub1,
  108223. 0, 0, 0, 0, 0,
  108224. NULL,
  108225. NULL,
  108226. NULL,
  108227. NULL,
  108228. 0
  108229. };
  108230. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  108231. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  108232. 5, 5,
  108233. };
  108234. static static_codebook _huff_book_line_2048x27_3sub1 = {
  108235. 1, 18,
  108236. _huff_lengthlist_line_2048x27_3sub1,
  108237. 0, 0, 0, 0, 0,
  108238. NULL,
  108239. NULL,
  108240. NULL,
  108241. NULL,
  108242. 0
  108243. };
  108244. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  108245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108246. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  108247. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  108248. 10,12,
  108249. };
  108250. static static_codebook _huff_book_line_2048x27_3sub2 = {
  108251. 1, 50,
  108252. _huff_lengthlist_line_2048x27_3sub2,
  108253. 0, 0, 0, 0, 0,
  108254. NULL,
  108255. NULL,
  108256. NULL,
  108257. NULL,
  108258. 0
  108259. };
  108260. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  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, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  108265. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108266. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108267. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108268. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108269. };
  108270. static static_codebook _huff_book_line_2048x27_3sub3 = {
  108271. 1, 128,
  108272. _huff_lengthlist_line_2048x27_3sub3,
  108273. 0, 0, 0, 0, 0,
  108274. NULL,
  108275. NULL,
  108276. NULL,
  108277. NULL,
  108278. 0
  108279. };
  108280. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  108281. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  108282. 4, 5,
  108283. };
  108284. static static_codebook _huff_book_line_2048x27_4sub1 = {
  108285. 1, 18,
  108286. _huff_lengthlist_line_2048x27_4sub1,
  108287. 0, 0, 0, 0, 0,
  108288. NULL,
  108289. NULL,
  108290. NULL,
  108291. NULL,
  108292. 0
  108293. };
  108294. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  108295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108296. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  108297. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  108298. 10,10,
  108299. };
  108300. static static_codebook _huff_book_line_2048x27_4sub2 = {
  108301. 1, 50,
  108302. _huff_lengthlist_line_2048x27_4sub2,
  108303. 0, 0, 0, 0, 0,
  108304. NULL,
  108305. NULL,
  108306. NULL,
  108307. NULL,
  108308. 0
  108309. };
  108310. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  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, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108315. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108316. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108317. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108318. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108319. };
  108320. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108321. 1, 128,
  108322. _huff_lengthlist_line_2048x27_4sub3,
  108323. 0, 0, 0, 0, 0,
  108324. NULL,
  108325. NULL,
  108326. NULL,
  108327. NULL,
  108328. 0
  108329. };
  108330. static long _huff_lengthlist_line_256x4low_class0[] = {
  108331. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108332. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108333. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108334. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108335. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108336. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108337. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108338. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108339. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108340. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108341. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108342. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108343. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108344. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108345. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108346. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108347. };
  108348. static static_codebook _huff_book_line_256x4low_class0 = {
  108349. 1, 256,
  108350. _huff_lengthlist_line_256x4low_class0,
  108351. 0, 0, 0, 0, 0,
  108352. NULL,
  108353. NULL,
  108354. NULL,
  108355. NULL,
  108356. 0
  108357. };
  108358. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108359. 1, 3, 2, 3,
  108360. };
  108361. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108362. 1, 4,
  108363. _huff_lengthlist_line_256x4low_0sub0,
  108364. 0, 0, 0, 0, 0,
  108365. NULL,
  108366. NULL,
  108367. NULL,
  108368. NULL,
  108369. 0
  108370. };
  108371. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108372. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108373. };
  108374. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108375. 1, 10,
  108376. _huff_lengthlist_line_256x4low_0sub1,
  108377. 0, 0, 0, 0, 0,
  108378. NULL,
  108379. NULL,
  108380. NULL,
  108381. NULL,
  108382. 0
  108383. };
  108384. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108386. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108387. };
  108388. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108389. 1, 25,
  108390. _huff_lengthlist_line_256x4low_0sub2,
  108391. 0, 0, 0, 0, 0,
  108392. NULL,
  108393. NULL,
  108394. NULL,
  108395. NULL,
  108396. 0
  108397. };
  108398. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  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, 3, 4, 2, 4, 3, 5, 4,
  108401. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108402. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108403. };
  108404. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108405. 1, 64,
  108406. _huff_lengthlist_line_256x4low_0sub3,
  108407. 0, 0, 0, 0, 0,
  108408. NULL,
  108409. NULL,
  108410. NULL,
  108411. NULL,
  108412. 0
  108413. };
  108414. /*** End of inlined file: floor_books.h ***/
  108415. static static_codebook *_floor_128x4_books[]={
  108416. &_huff_book_line_128x4_class0,
  108417. &_huff_book_line_128x4_0sub0,
  108418. &_huff_book_line_128x4_0sub1,
  108419. &_huff_book_line_128x4_0sub2,
  108420. &_huff_book_line_128x4_0sub3,
  108421. };
  108422. static static_codebook *_floor_256x4_books[]={
  108423. &_huff_book_line_256x4_class0,
  108424. &_huff_book_line_256x4_0sub0,
  108425. &_huff_book_line_256x4_0sub1,
  108426. &_huff_book_line_256x4_0sub2,
  108427. &_huff_book_line_256x4_0sub3,
  108428. };
  108429. static static_codebook *_floor_128x7_books[]={
  108430. &_huff_book_line_128x7_class0,
  108431. &_huff_book_line_128x7_class1,
  108432. &_huff_book_line_128x7_0sub1,
  108433. &_huff_book_line_128x7_0sub2,
  108434. &_huff_book_line_128x7_0sub3,
  108435. &_huff_book_line_128x7_1sub1,
  108436. &_huff_book_line_128x7_1sub2,
  108437. &_huff_book_line_128x7_1sub3,
  108438. };
  108439. static static_codebook *_floor_256x7_books[]={
  108440. &_huff_book_line_256x7_class0,
  108441. &_huff_book_line_256x7_class1,
  108442. &_huff_book_line_256x7_0sub1,
  108443. &_huff_book_line_256x7_0sub2,
  108444. &_huff_book_line_256x7_0sub3,
  108445. &_huff_book_line_256x7_1sub1,
  108446. &_huff_book_line_256x7_1sub2,
  108447. &_huff_book_line_256x7_1sub3,
  108448. };
  108449. static static_codebook *_floor_128x11_books[]={
  108450. &_huff_book_line_128x11_class1,
  108451. &_huff_book_line_128x11_class2,
  108452. &_huff_book_line_128x11_class3,
  108453. &_huff_book_line_128x11_0sub0,
  108454. &_huff_book_line_128x11_1sub0,
  108455. &_huff_book_line_128x11_1sub1,
  108456. &_huff_book_line_128x11_2sub1,
  108457. &_huff_book_line_128x11_2sub2,
  108458. &_huff_book_line_128x11_2sub3,
  108459. &_huff_book_line_128x11_3sub1,
  108460. &_huff_book_line_128x11_3sub2,
  108461. &_huff_book_line_128x11_3sub3,
  108462. };
  108463. static static_codebook *_floor_128x17_books[]={
  108464. &_huff_book_line_128x17_class1,
  108465. &_huff_book_line_128x17_class2,
  108466. &_huff_book_line_128x17_class3,
  108467. &_huff_book_line_128x17_0sub0,
  108468. &_huff_book_line_128x17_1sub0,
  108469. &_huff_book_line_128x17_1sub1,
  108470. &_huff_book_line_128x17_2sub1,
  108471. &_huff_book_line_128x17_2sub2,
  108472. &_huff_book_line_128x17_2sub3,
  108473. &_huff_book_line_128x17_3sub1,
  108474. &_huff_book_line_128x17_3sub2,
  108475. &_huff_book_line_128x17_3sub3,
  108476. };
  108477. static static_codebook *_floor_256x4low_books[]={
  108478. &_huff_book_line_256x4low_class0,
  108479. &_huff_book_line_256x4low_0sub0,
  108480. &_huff_book_line_256x4low_0sub1,
  108481. &_huff_book_line_256x4low_0sub2,
  108482. &_huff_book_line_256x4low_0sub3,
  108483. };
  108484. static static_codebook *_floor_1024x27_books[]={
  108485. &_huff_book_line_1024x27_class1,
  108486. &_huff_book_line_1024x27_class2,
  108487. &_huff_book_line_1024x27_class3,
  108488. &_huff_book_line_1024x27_class4,
  108489. &_huff_book_line_1024x27_0sub0,
  108490. &_huff_book_line_1024x27_1sub0,
  108491. &_huff_book_line_1024x27_1sub1,
  108492. &_huff_book_line_1024x27_2sub0,
  108493. &_huff_book_line_1024x27_2sub1,
  108494. &_huff_book_line_1024x27_3sub1,
  108495. &_huff_book_line_1024x27_3sub2,
  108496. &_huff_book_line_1024x27_3sub3,
  108497. &_huff_book_line_1024x27_4sub1,
  108498. &_huff_book_line_1024x27_4sub2,
  108499. &_huff_book_line_1024x27_4sub3,
  108500. };
  108501. static static_codebook *_floor_2048x27_books[]={
  108502. &_huff_book_line_2048x27_class1,
  108503. &_huff_book_line_2048x27_class2,
  108504. &_huff_book_line_2048x27_class3,
  108505. &_huff_book_line_2048x27_class4,
  108506. &_huff_book_line_2048x27_0sub0,
  108507. &_huff_book_line_2048x27_1sub0,
  108508. &_huff_book_line_2048x27_1sub1,
  108509. &_huff_book_line_2048x27_2sub0,
  108510. &_huff_book_line_2048x27_2sub1,
  108511. &_huff_book_line_2048x27_3sub1,
  108512. &_huff_book_line_2048x27_3sub2,
  108513. &_huff_book_line_2048x27_3sub3,
  108514. &_huff_book_line_2048x27_4sub1,
  108515. &_huff_book_line_2048x27_4sub2,
  108516. &_huff_book_line_2048x27_4sub3,
  108517. };
  108518. static static_codebook *_floor_512x17_books[]={
  108519. &_huff_book_line_512x17_class1,
  108520. &_huff_book_line_512x17_class2,
  108521. &_huff_book_line_512x17_class3,
  108522. &_huff_book_line_512x17_0sub0,
  108523. &_huff_book_line_512x17_1sub0,
  108524. &_huff_book_line_512x17_1sub1,
  108525. &_huff_book_line_512x17_2sub1,
  108526. &_huff_book_line_512x17_2sub2,
  108527. &_huff_book_line_512x17_2sub3,
  108528. &_huff_book_line_512x17_3sub1,
  108529. &_huff_book_line_512x17_3sub2,
  108530. &_huff_book_line_512x17_3sub3,
  108531. };
  108532. static static_codebook **_floor_books[10]={
  108533. _floor_128x4_books,
  108534. _floor_256x4_books,
  108535. _floor_128x7_books,
  108536. _floor_256x7_books,
  108537. _floor_128x11_books,
  108538. _floor_128x17_books,
  108539. _floor_256x4low_books,
  108540. _floor_1024x27_books,
  108541. _floor_2048x27_books,
  108542. _floor_512x17_books,
  108543. };
  108544. static vorbis_info_floor1 _floor[10]={
  108545. {
  108546. 1,{0},{4},{2},{0},
  108547. {{1,2,3,4}},
  108548. 4,{0,128, 33,8,16,70},
  108549. 60,30,500, 1.,18., -1
  108550. },
  108551. {
  108552. 1,{0},{4},{2},{0},
  108553. {{1,2,3,4}},
  108554. 4,{0,256, 66,16,32,140},
  108555. 60,30,500, 1.,18., -1
  108556. },
  108557. {
  108558. 2,{0,1},{3,4},{2,2},{0,1},
  108559. {{-1,2,3,4},{-1,5,6,7}},
  108560. 4,{0,128, 14,4,58, 2,8,28,90},
  108561. 60,30,500, 1.,18., -1
  108562. },
  108563. {
  108564. 2,{0,1},{3,4},{2,2},{0,1},
  108565. {{-1,2,3,4},{-1,5,6,7}},
  108566. 4,{0,256, 28,8,116, 4,16,56,180},
  108567. 60,30,500, 1.,18., -1
  108568. },
  108569. {
  108570. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108571. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108572. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108573. 60,30,500, 1,18., -1
  108574. },
  108575. {
  108576. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108577. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108578. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108579. 60,30,500, 1,18., -1
  108580. },
  108581. {
  108582. 1,{0},{4},{2},{0},
  108583. {{1,2,3,4}},
  108584. 4,{0,256, 66,16,32,140},
  108585. 60,30,500, 1.,18., -1
  108586. },
  108587. {
  108588. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108589. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108590. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108591. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108592. 60,30,500, 3,18., -1 /* lowpass */
  108593. },
  108594. {
  108595. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108596. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108597. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108598. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108599. 60,30,500, 3,18., -1 /* lowpass */
  108600. },
  108601. {
  108602. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108603. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108604. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108605. 7,23,39, 55,79,110, 156,232,360},
  108606. 60,30,500, 1,18., -1 /* lowpass! */
  108607. },
  108608. };
  108609. /*** End of inlined file: floor_all.h ***/
  108610. /*** Start of inlined file: residue_44.h ***/
  108611. /*** Start of inlined file: res_books_stereo.h ***/
  108612. static long _vq_quantlist__16c0_s_p1_0[] = {
  108613. 1,
  108614. 0,
  108615. 2,
  108616. };
  108617. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108618. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108619. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108623. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108624. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108628. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108629. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108660. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108664. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  108669. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  108674. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108709. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108710. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108714. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108715. 0, 0, 0, 0, 0, 9,10,12, 0, 0, 0, 0, 0, 0, 0, 0,
  108716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108719. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108720. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109028. 0,
  109029. };
  109030. static float _vq_quantthresh__16c0_s_p1_0[] = {
  109031. -0.5, 0.5,
  109032. };
  109033. static long _vq_quantmap__16c0_s_p1_0[] = {
  109034. 1, 0, 2,
  109035. };
  109036. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  109037. _vq_quantthresh__16c0_s_p1_0,
  109038. _vq_quantmap__16c0_s_p1_0,
  109039. 3,
  109040. 3
  109041. };
  109042. static static_codebook _16c0_s_p1_0 = {
  109043. 8, 6561,
  109044. _vq_lengthlist__16c0_s_p1_0,
  109045. 1, -535822336, 1611661312, 2, 0,
  109046. _vq_quantlist__16c0_s_p1_0,
  109047. NULL,
  109048. &_vq_auxt__16c0_s_p1_0,
  109049. NULL,
  109050. 0
  109051. };
  109052. static long _vq_quantlist__16c0_s_p2_0[] = {
  109053. 2,
  109054. 1,
  109055. 3,
  109056. 0,
  109057. 4,
  109058. };
  109059. static long _vq_lengthlist__16c0_s_p2_0[] = {
  109060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109099. 0,
  109100. };
  109101. static float _vq_quantthresh__16c0_s_p2_0[] = {
  109102. -1.5, -0.5, 0.5, 1.5,
  109103. };
  109104. static long _vq_quantmap__16c0_s_p2_0[] = {
  109105. 3, 1, 0, 2, 4,
  109106. };
  109107. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  109108. _vq_quantthresh__16c0_s_p2_0,
  109109. _vq_quantmap__16c0_s_p2_0,
  109110. 5,
  109111. 5
  109112. };
  109113. static static_codebook _16c0_s_p2_0 = {
  109114. 4, 625,
  109115. _vq_lengthlist__16c0_s_p2_0,
  109116. 1, -533725184, 1611661312, 3, 0,
  109117. _vq_quantlist__16c0_s_p2_0,
  109118. NULL,
  109119. &_vq_auxt__16c0_s_p2_0,
  109120. NULL,
  109121. 0
  109122. };
  109123. static long _vq_quantlist__16c0_s_p3_0[] = {
  109124. 2,
  109125. 1,
  109126. 3,
  109127. 0,
  109128. 4,
  109129. };
  109130. static long _vq_lengthlist__16c0_s_p3_0[] = {
  109131. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  109133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109134. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  109136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109137. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109170. 0,
  109171. };
  109172. static float _vq_quantthresh__16c0_s_p3_0[] = {
  109173. -1.5, -0.5, 0.5, 1.5,
  109174. };
  109175. static long _vq_quantmap__16c0_s_p3_0[] = {
  109176. 3, 1, 0, 2, 4,
  109177. };
  109178. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  109179. _vq_quantthresh__16c0_s_p3_0,
  109180. _vq_quantmap__16c0_s_p3_0,
  109181. 5,
  109182. 5
  109183. };
  109184. static static_codebook _16c0_s_p3_0 = {
  109185. 4, 625,
  109186. _vq_lengthlist__16c0_s_p3_0,
  109187. 1, -533725184, 1611661312, 3, 0,
  109188. _vq_quantlist__16c0_s_p3_0,
  109189. NULL,
  109190. &_vq_auxt__16c0_s_p3_0,
  109191. NULL,
  109192. 0
  109193. };
  109194. static long _vq_quantlist__16c0_s_p4_0[] = {
  109195. 4,
  109196. 3,
  109197. 5,
  109198. 2,
  109199. 6,
  109200. 1,
  109201. 7,
  109202. 0,
  109203. 8,
  109204. };
  109205. static long _vq_lengthlist__16c0_s_p4_0[] = {
  109206. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109207. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109208. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109209. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  109210. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109211. 0,
  109212. };
  109213. static float _vq_quantthresh__16c0_s_p4_0[] = {
  109214. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109215. };
  109216. static long _vq_quantmap__16c0_s_p4_0[] = {
  109217. 7, 5, 3, 1, 0, 2, 4, 6,
  109218. 8,
  109219. };
  109220. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  109221. _vq_quantthresh__16c0_s_p4_0,
  109222. _vq_quantmap__16c0_s_p4_0,
  109223. 9,
  109224. 9
  109225. };
  109226. static static_codebook _16c0_s_p4_0 = {
  109227. 2, 81,
  109228. _vq_lengthlist__16c0_s_p4_0,
  109229. 1, -531628032, 1611661312, 4, 0,
  109230. _vq_quantlist__16c0_s_p4_0,
  109231. NULL,
  109232. &_vq_auxt__16c0_s_p4_0,
  109233. NULL,
  109234. 0
  109235. };
  109236. static long _vq_quantlist__16c0_s_p5_0[] = {
  109237. 4,
  109238. 3,
  109239. 5,
  109240. 2,
  109241. 6,
  109242. 1,
  109243. 7,
  109244. 0,
  109245. 8,
  109246. };
  109247. static long _vq_lengthlist__16c0_s_p5_0[] = {
  109248. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109249. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  109250. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  109251. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  109252. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109253. 10,
  109254. };
  109255. static float _vq_quantthresh__16c0_s_p5_0[] = {
  109256. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109257. };
  109258. static long _vq_quantmap__16c0_s_p5_0[] = {
  109259. 7, 5, 3, 1, 0, 2, 4, 6,
  109260. 8,
  109261. };
  109262. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  109263. _vq_quantthresh__16c0_s_p5_0,
  109264. _vq_quantmap__16c0_s_p5_0,
  109265. 9,
  109266. 9
  109267. };
  109268. static static_codebook _16c0_s_p5_0 = {
  109269. 2, 81,
  109270. _vq_lengthlist__16c0_s_p5_0,
  109271. 1, -531628032, 1611661312, 4, 0,
  109272. _vq_quantlist__16c0_s_p5_0,
  109273. NULL,
  109274. &_vq_auxt__16c0_s_p5_0,
  109275. NULL,
  109276. 0
  109277. };
  109278. static long _vq_quantlist__16c0_s_p6_0[] = {
  109279. 8,
  109280. 7,
  109281. 9,
  109282. 6,
  109283. 10,
  109284. 5,
  109285. 11,
  109286. 4,
  109287. 12,
  109288. 3,
  109289. 13,
  109290. 2,
  109291. 14,
  109292. 1,
  109293. 15,
  109294. 0,
  109295. 16,
  109296. };
  109297. static long _vq_lengthlist__16c0_s_p6_0[] = {
  109298. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  109299. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  109300. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  109301. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  109302. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  109303. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109304. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109305. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109306. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109307. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109308. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109309. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109310. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109311. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109312. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109313. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109314. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109315. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109316. 14,
  109317. };
  109318. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109319. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109320. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109321. };
  109322. static long _vq_quantmap__16c0_s_p6_0[] = {
  109323. 15, 13, 11, 9, 7, 5, 3, 1,
  109324. 0, 2, 4, 6, 8, 10, 12, 14,
  109325. 16,
  109326. };
  109327. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109328. _vq_quantthresh__16c0_s_p6_0,
  109329. _vq_quantmap__16c0_s_p6_0,
  109330. 17,
  109331. 17
  109332. };
  109333. static static_codebook _16c0_s_p6_0 = {
  109334. 2, 289,
  109335. _vq_lengthlist__16c0_s_p6_0,
  109336. 1, -529530880, 1611661312, 5, 0,
  109337. _vq_quantlist__16c0_s_p6_0,
  109338. NULL,
  109339. &_vq_auxt__16c0_s_p6_0,
  109340. NULL,
  109341. 0
  109342. };
  109343. static long _vq_quantlist__16c0_s_p7_0[] = {
  109344. 1,
  109345. 0,
  109346. 2,
  109347. };
  109348. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109349. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109350. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109351. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109352. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109353. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109354. 13,
  109355. };
  109356. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109357. -5.5, 5.5,
  109358. };
  109359. static long _vq_quantmap__16c0_s_p7_0[] = {
  109360. 1, 0, 2,
  109361. };
  109362. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109363. _vq_quantthresh__16c0_s_p7_0,
  109364. _vq_quantmap__16c0_s_p7_0,
  109365. 3,
  109366. 3
  109367. };
  109368. static static_codebook _16c0_s_p7_0 = {
  109369. 4, 81,
  109370. _vq_lengthlist__16c0_s_p7_0,
  109371. 1, -529137664, 1618345984, 2, 0,
  109372. _vq_quantlist__16c0_s_p7_0,
  109373. NULL,
  109374. &_vq_auxt__16c0_s_p7_0,
  109375. NULL,
  109376. 0
  109377. };
  109378. static long _vq_quantlist__16c0_s_p7_1[] = {
  109379. 5,
  109380. 4,
  109381. 6,
  109382. 3,
  109383. 7,
  109384. 2,
  109385. 8,
  109386. 1,
  109387. 9,
  109388. 0,
  109389. 10,
  109390. };
  109391. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109392. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109393. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109394. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109395. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109396. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109397. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109398. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109399. 11,11,11, 9, 9, 9, 9,10,10,
  109400. };
  109401. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109402. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109403. 3.5, 4.5,
  109404. };
  109405. static long _vq_quantmap__16c0_s_p7_1[] = {
  109406. 9, 7, 5, 3, 1, 0, 2, 4,
  109407. 6, 8, 10,
  109408. };
  109409. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109410. _vq_quantthresh__16c0_s_p7_1,
  109411. _vq_quantmap__16c0_s_p7_1,
  109412. 11,
  109413. 11
  109414. };
  109415. static static_codebook _16c0_s_p7_1 = {
  109416. 2, 121,
  109417. _vq_lengthlist__16c0_s_p7_1,
  109418. 1, -531365888, 1611661312, 4, 0,
  109419. _vq_quantlist__16c0_s_p7_1,
  109420. NULL,
  109421. &_vq_auxt__16c0_s_p7_1,
  109422. NULL,
  109423. 0
  109424. };
  109425. static long _vq_quantlist__16c0_s_p8_0[] = {
  109426. 6,
  109427. 5,
  109428. 7,
  109429. 4,
  109430. 8,
  109431. 3,
  109432. 9,
  109433. 2,
  109434. 10,
  109435. 1,
  109436. 11,
  109437. 0,
  109438. 12,
  109439. };
  109440. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109441. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109442. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109443. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109444. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109445. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109446. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109447. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109448. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109449. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109450. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109451. 0,12,13,13,12,13,14,14,14,
  109452. };
  109453. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109454. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109455. 12.5, 17.5, 22.5, 27.5,
  109456. };
  109457. static long _vq_quantmap__16c0_s_p8_0[] = {
  109458. 11, 9, 7, 5, 3, 1, 0, 2,
  109459. 4, 6, 8, 10, 12,
  109460. };
  109461. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109462. _vq_quantthresh__16c0_s_p8_0,
  109463. _vq_quantmap__16c0_s_p8_0,
  109464. 13,
  109465. 13
  109466. };
  109467. static static_codebook _16c0_s_p8_0 = {
  109468. 2, 169,
  109469. _vq_lengthlist__16c0_s_p8_0,
  109470. 1, -526516224, 1616117760, 4, 0,
  109471. _vq_quantlist__16c0_s_p8_0,
  109472. NULL,
  109473. &_vq_auxt__16c0_s_p8_0,
  109474. NULL,
  109475. 0
  109476. };
  109477. static long _vq_quantlist__16c0_s_p8_1[] = {
  109478. 2,
  109479. 1,
  109480. 3,
  109481. 0,
  109482. 4,
  109483. };
  109484. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109485. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109486. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109487. };
  109488. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109489. -1.5, -0.5, 0.5, 1.5,
  109490. };
  109491. static long _vq_quantmap__16c0_s_p8_1[] = {
  109492. 3, 1, 0, 2, 4,
  109493. };
  109494. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109495. _vq_quantthresh__16c0_s_p8_1,
  109496. _vq_quantmap__16c0_s_p8_1,
  109497. 5,
  109498. 5
  109499. };
  109500. static static_codebook _16c0_s_p8_1 = {
  109501. 2, 25,
  109502. _vq_lengthlist__16c0_s_p8_1,
  109503. 1, -533725184, 1611661312, 3, 0,
  109504. _vq_quantlist__16c0_s_p8_1,
  109505. NULL,
  109506. &_vq_auxt__16c0_s_p8_1,
  109507. NULL,
  109508. 0
  109509. };
  109510. static long _vq_quantlist__16c0_s_p9_0[] = {
  109511. 1,
  109512. 0,
  109513. 2,
  109514. };
  109515. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109516. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109517. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109518. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109519. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109520. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109521. 7,
  109522. };
  109523. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109524. -157.5, 157.5,
  109525. };
  109526. static long _vq_quantmap__16c0_s_p9_0[] = {
  109527. 1, 0, 2,
  109528. };
  109529. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109530. _vq_quantthresh__16c0_s_p9_0,
  109531. _vq_quantmap__16c0_s_p9_0,
  109532. 3,
  109533. 3
  109534. };
  109535. static static_codebook _16c0_s_p9_0 = {
  109536. 4, 81,
  109537. _vq_lengthlist__16c0_s_p9_0,
  109538. 1, -518803456, 1628680192, 2, 0,
  109539. _vq_quantlist__16c0_s_p9_0,
  109540. NULL,
  109541. &_vq_auxt__16c0_s_p9_0,
  109542. NULL,
  109543. 0
  109544. };
  109545. static long _vq_quantlist__16c0_s_p9_1[] = {
  109546. 7,
  109547. 6,
  109548. 8,
  109549. 5,
  109550. 9,
  109551. 4,
  109552. 10,
  109553. 3,
  109554. 11,
  109555. 2,
  109556. 12,
  109557. 1,
  109558. 13,
  109559. 0,
  109560. 14,
  109561. };
  109562. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109563. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109564. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109565. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109566. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109567. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109568. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109569. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109570. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109571. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109572. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109573. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109574. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109575. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109576. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109577. 10,
  109578. };
  109579. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109580. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109581. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109582. };
  109583. static long _vq_quantmap__16c0_s_p9_1[] = {
  109584. 13, 11, 9, 7, 5, 3, 1, 0,
  109585. 2, 4, 6, 8, 10, 12, 14,
  109586. };
  109587. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109588. _vq_quantthresh__16c0_s_p9_1,
  109589. _vq_quantmap__16c0_s_p9_1,
  109590. 15,
  109591. 15
  109592. };
  109593. static static_codebook _16c0_s_p9_1 = {
  109594. 2, 225,
  109595. _vq_lengthlist__16c0_s_p9_1,
  109596. 1, -520986624, 1620377600, 4, 0,
  109597. _vq_quantlist__16c0_s_p9_1,
  109598. NULL,
  109599. &_vq_auxt__16c0_s_p9_1,
  109600. NULL,
  109601. 0
  109602. };
  109603. static long _vq_quantlist__16c0_s_p9_2[] = {
  109604. 10,
  109605. 9,
  109606. 11,
  109607. 8,
  109608. 12,
  109609. 7,
  109610. 13,
  109611. 6,
  109612. 14,
  109613. 5,
  109614. 15,
  109615. 4,
  109616. 16,
  109617. 3,
  109618. 17,
  109619. 2,
  109620. 18,
  109621. 1,
  109622. 19,
  109623. 0,
  109624. 20,
  109625. };
  109626. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109627. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109628. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109629. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109630. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109631. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109632. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109633. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109634. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109635. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109636. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109637. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109638. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109639. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109640. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109641. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109642. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109643. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109644. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109645. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109646. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109647. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109648. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109649. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109650. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109651. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109652. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109653. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109654. 10,11,10,10,11, 9,10,10,10,
  109655. };
  109656. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109657. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109658. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109659. 6.5, 7.5, 8.5, 9.5,
  109660. };
  109661. static long _vq_quantmap__16c0_s_p9_2[] = {
  109662. 19, 17, 15, 13, 11, 9, 7, 5,
  109663. 3, 1, 0, 2, 4, 6, 8, 10,
  109664. 12, 14, 16, 18, 20,
  109665. };
  109666. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109667. _vq_quantthresh__16c0_s_p9_2,
  109668. _vq_quantmap__16c0_s_p9_2,
  109669. 21,
  109670. 21
  109671. };
  109672. static static_codebook _16c0_s_p9_2 = {
  109673. 2, 441,
  109674. _vq_lengthlist__16c0_s_p9_2,
  109675. 1, -529268736, 1611661312, 5, 0,
  109676. _vq_quantlist__16c0_s_p9_2,
  109677. NULL,
  109678. &_vq_auxt__16c0_s_p9_2,
  109679. NULL,
  109680. 0
  109681. };
  109682. static long _huff_lengthlist__16c0_s_single[] = {
  109683. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109684. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109685. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109686. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109687. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109688. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109689. 16,16,18,18,
  109690. };
  109691. static static_codebook _huff_book__16c0_s_single = {
  109692. 2, 100,
  109693. _huff_lengthlist__16c0_s_single,
  109694. 0, 0, 0, 0, 0,
  109695. NULL,
  109696. NULL,
  109697. NULL,
  109698. NULL,
  109699. 0
  109700. };
  109701. static long _huff_lengthlist__16c1_s_long[] = {
  109702. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109703. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109704. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109705. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109706. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109707. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109708. 12,11,11,13,
  109709. };
  109710. static static_codebook _huff_book__16c1_s_long = {
  109711. 2, 100,
  109712. _huff_lengthlist__16c1_s_long,
  109713. 0, 0, 0, 0, 0,
  109714. NULL,
  109715. NULL,
  109716. NULL,
  109717. NULL,
  109718. 0
  109719. };
  109720. static long _vq_quantlist__16c1_s_p1_0[] = {
  109721. 1,
  109722. 0,
  109723. 2,
  109724. };
  109725. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109726. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109727. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109731. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109732. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109736. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109737. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109768. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109772. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109777. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109782. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109817. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109818. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109822. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109823. 0, 0, 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  109824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109827. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109828. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110136. 0,
  110137. };
  110138. static float _vq_quantthresh__16c1_s_p1_0[] = {
  110139. -0.5, 0.5,
  110140. };
  110141. static long _vq_quantmap__16c1_s_p1_0[] = {
  110142. 1, 0, 2,
  110143. };
  110144. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  110145. _vq_quantthresh__16c1_s_p1_0,
  110146. _vq_quantmap__16c1_s_p1_0,
  110147. 3,
  110148. 3
  110149. };
  110150. static static_codebook _16c1_s_p1_0 = {
  110151. 8, 6561,
  110152. _vq_lengthlist__16c1_s_p1_0,
  110153. 1, -535822336, 1611661312, 2, 0,
  110154. _vq_quantlist__16c1_s_p1_0,
  110155. NULL,
  110156. &_vq_auxt__16c1_s_p1_0,
  110157. NULL,
  110158. 0
  110159. };
  110160. static long _vq_quantlist__16c1_s_p2_0[] = {
  110161. 2,
  110162. 1,
  110163. 3,
  110164. 0,
  110165. 4,
  110166. };
  110167. static long _vq_lengthlist__16c1_s_p2_0[] = {
  110168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110207. 0,
  110208. };
  110209. static float _vq_quantthresh__16c1_s_p2_0[] = {
  110210. -1.5, -0.5, 0.5, 1.5,
  110211. };
  110212. static long _vq_quantmap__16c1_s_p2_0[] = {
  110213. 3, 1, 0, 2, 4,
  110214. };
  110215. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  110216. _vq_quantthresh__16c1_s_p2_0,
  110217. _vq_quantmap__16c1_s_p2_0,
  110218. 5,
  110219. 5
  110220. };
  110221. static static_codebook _16c1_s_p2_0 = {
  110222. 4, 625,
  110223. _vq_lengthlist__16c1_s_p2_0,
  110224. 1, -533725184, 1611661312, 3, 0,
  110225. _vq_quantlist__16c1_s_p2_0,
  110226. NULL,
  110227. &_vq_auxt__16c1_s_p2_0,
  110228. NULL,
  110229. 0
  110230. };
  110231. static long _vq_quantlist__16c1_s_p3_0[] = {
  110232. 2,
  110233. 1,
  110234. 3,
  110235. 0,
  110236. 4,
  110237. };
  110238. static long _vq_lengthlist__16c1_s_p3_0[] = {
  110239. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  110241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110242. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  110244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110245. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  110246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110278. 0,
  110279. };
  110280. static float _vq_quantthresh__16c1_s_p3_0[] = {
  110281. -1.5, -0.5, 0.5, 1.5,
  110282. };
  110283. static long _vq_quantmap__16c1_s_p3_0[] = {
  110284. 3, 1, 0, 2, 4,
  110285. };
  110286. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  110287. _vq_quantthresh__16c1_s_p3_0,
  110288. _vq_quantmap__16c1_s_p3_0,
  110289. 5,
  110290. 5
  110291. };
  110292. static static_codebook _16c1_s_p3_0 = {
  110293. 4, 625,
  110294. _vq_lengthlist__16c1_s_p3_0,
  110295. 1, -533725184, 1611661312, 3, 0,
  110296. _vq_quantlist__16c1_s_p3_0,
  110297. NULL,
  110298. &_vq_auxt__16c1_s_p3_0,
  110299. NULL,
  110300. 0
  110301. };
  110302. static long _vq_quantlist__16c1_s_p4_0[] = {
  110303. 4,
  110304. 3,
  110305. 5,
  110306. 2,
  110307. 6,
  110308. 1,
  110309. 7,
  110310. 0,
  110311. 8,
  110312. };
  110313. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110314. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110315. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110316. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110317. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110318. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110319. 0,
  110320. };
  110321. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110322. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110323. };
  110324. static long _vq_quantmap__16c1_s_p4_0[] = {
  110325. 7, 5, 3, 1, 0, 2, 4, 6,
  110326. 8,
  110327. };
  110328. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110329. _vq_quantthresh__16c1_s_p4_0,
  110330. _vq_quantmap__16c1_s_p4_0,
  110331. 9,
  110332. 9
  110333. };
  110334. static static_codebook _16c1_s_p4_0 = {
  110335. 2, 81,
  110336. _vq_lengthlist__16c1_s_p4_0,
  110337. 1, -531628032, 1611661312, 4, 0,
  110338. _vq_quantlist__16c1_s_p4_0,
  110339. NULL,
  110340. &_vq_auxt__16c1_s_p4_0,
  110341. NULL,
  110342. 0
  110343. };
  110344. static long _vq_quantlist__16c1_s_p5_0[] = {
  110345. 4,
  110346. 3,
  110347. 5,
  110348. 2,
  110349. 6,
  110350. 1,
  110351. 7,
  110352. 0,
  110353. 8,
  110354. };
  110355. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110356. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110357. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110358. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110359. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110360. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110361. 10,
  110362. };
  110363. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110364. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110365. };
  110366. static long _vq_quantmap__16c1_s_p5_0[] = {
  110367. 7, 5, 3, 1, 0, 2, 4, 6,
  110368. 8,
  110369. };
  110370. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110371. _vq_quantthresh__16c1_s_p5_0,
  110372. _vq_quantmap__16c1_s_p5_0,
  110373. 9,
  110374. 9
  110375. };
  110376. static static_codebook _16c1_s_p5_0 = {
  110377. 2, 81,
  110378. _vq_lengthlist__16c1_s_p5_0,
  110379. 1, -531628032, 1611661312, 4, 0,
  110380. _vq_quantlist__16c1_s_p5_0,
  110381. NULL,
  110382. &_vq_auxt__16c1_s_p5_0,
  110383. NULL,
  110384. 0
  110385. };
  110386. static long _vq_quantlist__16c1_s_p6_0[] = {
  110387. 8,
  110388. 7,
  110389. 9,
  110390. 6,
  110391. 10,
  110392. 5,
  110393. 11,
  110394. 4,
  110395. 12,
  110396. 3,
  110397. 13,
  110398. 2,
  110399. 14,
  110400. 1,
  110401. 15,
  110402. 0,
  110403. 16,
  110404. };
  110405. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110406. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110407. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110408. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110409. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110410. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110411. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110412. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110413. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110414. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110415. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110416. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110417. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110418. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110419. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110420. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110421. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110422. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110423. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110424. 14,
  110425. };
  110426. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110427. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110428. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110429. };
  110430. static long _vq_quantmap__16c1_s_p6_0[] = {
  110431. 15, 13, 11, 9, 7, 5, 3, 1,
  110432. 0, 2, 4, 6, 8, 10, 12, 14,
  110433. 16,
  110434. };
  110435. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110436. _vq_quantthresh__16c1_s_p6_0,
  110437. _vq_quantmap__16c1_s_p6_0,
  110438. 17,
  110439. 17
  110440. };
  110441. static static_codebook _16c1_s_p6_0 = {
  110442. 2, 289,
  110443. _vq_lengthlist__16c1_s_p6_0,
  110444. 1, -529530880, 1611661312, 5, 0,
  110445. _vq_quantlist__16c1_s_p6_0,
  110446. NULL,
  110447. &_vq_auxt__16c1_s_p6_0,
  110448. NULL,
  110449. 0
  110450. };
  110451. static long _vq_quantlist__16c1_s_p7_0[] = {
  110452. 1,
  110453. 0,
  110454. 2,
  110455. };
  110456. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110457. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110458. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110459. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110460. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110461. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110462. 11,
  110463. };
  110464. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110465. -5.5, 5.5,
  110466. };
  110467. static long _vq_quantmap__16c1_s_p7_0[] = {
  110468. 1, 0, 2,
  110469. };
  110470. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110471. _vq_quantthresh__16c1_s_p7_0,
  110472. _vq_quantmap__16c1_s_p7_0,
  110473. 3,
  110474. 3
  110475. };
  110476. static static_codebook _16c1_s_p7_0 = {
  110477. 4, 81,
  110478. _vq_lengthlist__16c1_s_p7_0,
  110479. 1, -529137664, 1618345984, 2, 0,
  110480. _vq_quantlist__16c1_s_p7_0,
  110481. NULL,
  110482. &_vq_auxt__16c1_s_p7_0,
  110483. NULL,
  110484. 0
  110485. };
  110486. static long _vq_quantlist__16c1_s_p7_1[] = {
  110487. 5,
  110488. 4,
  110489. 6,
  110490. 3,
  110491. 7,
  110492. 2,
  110493. 8,
  110494. 1,
  110495. 9,
  110496. 0,
  110497. 10,
  110498. };
  110499. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110500. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110501. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110502. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110503. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110504. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110505. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110506. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110507. 10,10,10, 8, 8, 8, 8, 9, 9,
  110508. };
  110509. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110510. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110511. 3.5, 4.5,
  110512. };
  110513. static long _vq_quantmap__16c1_s_p7_1[] = {
  110514. 9, 7, 5, 3, 1, 0, 2, 4,
  110515. 6, 8, 10,
  110516. };
  110517. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110518. _vq_quantthresh__16c1_s_p7_1,
  110519. _vq_quantmap__16c1_s_p7_1,
  110520. 11,
  110521. 11
  110522. };
  110523. static static_codebook _16c1_s_p7_1 = {
  110524. 2, 121,
  110525. _vq_lengthlist__16c1_s_p7_1,
  110526. 1, -531365888, 1611661312, 4, 0,
  110527. _vq_quantlist__16c1_s_p7_1,
  110528. NULL,
  110529. &_vq_auxt__16c1_s_p7_1,
  110530. NULL,
  110531. 0
  110532. };
  110533. static long _vq_quantlist__16c1_s_p8_0[] = {
  110534. 6,
  110535. 5,
  110536. 7,
  110537. 4,
  110538. 8,
  110539. 3,
  110540. 9,
  110541. 2,
  110542. 10,
  110543. 1,
  110544. 11,
  110545. 0,
  110546. 12,
  110547. };
  110548. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110549. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110550. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110551. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110552. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110553. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110554. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110555. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110556. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110557. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110558. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110559. 0,12,12,12,12,13,13,14,15,
  110560. };
  110561. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110562. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110563. 12.5, 17.5, 22.5, 27.5,
  110564. };
  110565. static long _vq_quantmap__16c1_s_p8_0[] = {
  110566. 11, 9, 7, 5, 3, 1, 0, 2,
  110567. 4, 6, 8, 10, 12,
  110568. };
  110569. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110570. _vq_quantthresh__16c1_s_p8_0,
  110571. _vq_quantmap__16c1_s_p8_0,
  110572. 13,
  110573. 13
  110574. };
  110575. static static_codebook _16c1_s_p8_0 = {
  110576. 2, 169,
  110577. _vq_lengthlist__16c1_s_p8_0,
  110578. 1, -526516224, 1616117760, 4, 0,
  110579. _vq_quantlist__16c1_s_p8_0,
  110580. NULL,
  110581. &_vq_auxt__16c1_s_p8_0,
  110582. NULL,
  110583. 0
  110584. };
  110585. static long _vq_quantlist__16c1_s_p8_1[] = {
  110586. 2,
  110587. 1,
  110588. 3,
  110589. 0,
  110590. 4,
  110591. };
  110592. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110593. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110594. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110595. };
  110596. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110597. -1.5, -0.5, 0.5, 1.5,
  110598. };
  110599. static long _vq_quantmap__16c1_s_p8_1[] = {
  110600. 3, 1, 0, 2, 4,
  110601. };
  110602. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110603. _vq_quantthresh__16c1_s_p8_1,
  110604. _vq_quantmap__16c1_s_p8_1,
  110605. 5,
  110606. 5
  110607. };
  110608. static static_codebook _16c1_s_p8_1 = {
  110609. 2, 25,
  110610. _vq_lengthlist__16c1_s_p8_1,
  110611. 1, -533725184, 1611661312, 3, 0,
  110612. _vq_quantlist__16c1_s_p8_1,
  110613. NULL,
  110614. &_vq_auxt__16c1_s_p8_1,
  110615. NULL,
  110616. 0
  110617. };
  110618. static long _vq_quantlist__16c1_s_p9_0[] = {
  110619. 6,
  110620. 5,
  110621. 7,
  110622. 4,
  110623. 8,
  110624. 3,
  110625. 9,
  110626. 2,
  110627. 10,
  110628. 1,
  110629. 11,
  110630. 0,
  110631. 12,
  110632. };
  110633. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110634. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110635. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110636. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110637. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110638. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110639. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110640. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110641. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110642. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110643. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110644. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110645. };
  110646. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110647. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110648. 787.5, 1102.5, 1417.5, 1732.5,
  110649. };
  110650. static long _vq_quantmap__16c1_s_p9_0[] = {
  110651. 11, 9, 7, 5, 3, 1, 0, 2,
  110652. 4, 6, 8, 10, 12,
  110653. };
  110654. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110655. _vq_quantthresh__16c1_s_p9_0,
  110656. _vq_quantmap__16c1_s_p9_0,
  110657. 13,
  110658. 13
  110659. };
  110660. static static_codebook _16c1_s_p9_0 = {
  110661. 2, 169,
  110662. _vq_lengthlist__16c1_s_p9_0,
  110663. 1, -513964032, 1628680192, 4, 0,
  110664. _vq_quantlist__16c1_s_p9_0,
  110665. NULL,
  110666. &_vq_auxt__16c1_s_p9_0,
  110667. NULL,
  110668. 0
  110669. };
  110670. static long _vq_quantlist__16c1_s_p9_1[] = {
  110671. 7,
  110672. 6,
  110673. 8,
  110674. 5,
  110675. 9,
  110676. 4,
  110677. 10,
  110678. 3,
  110679. 11,
  110680. 2,
  110681. 12,
  110682. 1,
  110683. 13,
  110684. 0,
  110685. 14,
  110686. };
  110687. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110688. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110689. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110690. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110691. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110692. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110693. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110694. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110695. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110696. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110697. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110698. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110699. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110700. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110701. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110702. 13,
  110703. };
  110704. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110705. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110706. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110707. };
  110708. static long _vq_quantmap__16c1_s_p9_1[] = {
  110709. 13, 11, 9, 7, 5, 3, 1, 0,
  110710. 2, 4, 6, 8, 10, 12, 14,
  110711. };
  110712. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110713. _vq_quantthresh__16c1_s_p9_1,
  110714. _vq_quantmap__16c1_s_p9_1,
  110715. 15,
  110716. 15
  110717. };
  110718. static static_codebook _16c1_s_p9_1 = {
  110719. 2, 225,
  110720. _vq_lengthlist__16c1_s_p9_1,
  110721. 1, -520986624, 1620377600, 4, 0,
  110722. _vq_quantlist__16c1_s_p9_1,
  110723. NULL,
  110724. &_vq_auxt__16c1_s_p9_1,
  110725. NULL,
  110726. 0
  110727. };
  110728. static long _vq_quantlist__16c1_s_p9_2[] = {
  110729. 10,
  110730. 9,
  110731. 11,
  110732. 8,
  110733. 12,
  110734. 7,
  110735. 13,
  110736. 6,
  110737. 14,
  110738. 5,
  110739. 15,
  110740. 4,
  110741. 16,
  110742. 3,
  110743. 17,
  110744. 2,
  110745. 18,
  110746. 1,
  110747. 19,
  110748. 0,
  110749. 20,
  110750. };
  110751. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110752. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110753. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110754. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110755. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110756. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110757. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110758. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110759. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110760. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110761. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110762. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110763. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110764. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110765. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110766. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110767. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110768. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110769. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110770. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110771. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110772. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110773. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110774. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110775. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110776. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110777. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110778. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110779. 11,11,11,11,12,11,11,12,11,
  110780. };
  110781. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110782. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110783. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110784. 6.5, 7.5, 8.5, 9.5,
  110785. };
  110786. static long _vq_quantmap__16c1_s_p9_2[] = {
  110787. 19, 17, 15, 13, 11, 9, 7, 5,
  110788. 3, 1, 0, 2, 4, 6, 8, 10,
  110789. 12, 14, 16, 18, 20,
  110790. };
  110791. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110792. _vq_quantthresh__16c1_s_p9_2,
  110793. _vq_quantmap__16c1_s_p9_2,
  110794. 21,
  110795. 21
  110796. };
  110797. static static_codebook _16c1_s_p9_2 = {
  110798. 2, 441,
  110799. _vq_lengthlist__16c1_s_p9_2,
  110800. 1, -529268736, 1611661312, 5, 0,
  110801. _vq_quantlist__16c1_s_p9_2,
  110802. NULL,
  110803. &_vq_auxt__16c1_s_p9_2,
  110804. NULL,
  110805. 0
  110806. };
  110807. static long _huff_lengthlist__16c1_s_short[] = {
  110808. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110809. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110810. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110811. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110812. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110813. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110814. 9, 9,10,13,
  110815. };
  110816. static static_codebook _huff_book__16c1_s_short = {
  110817. 2, 100,
  110818. _huff_lengthlist__16c1_s_short,
  110819. 0, 0, 0, 0, 0,
  110820. NULL,
  110821. NULL,
  110822. NULL,
  110823. NULL,
  110824. 0
  110825. };
  110826. static long _huff_lengthlist__16c2_s_long[] = {
  110827. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110828. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110829. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110830. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110831. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110832. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110833. 14,14,16,18,
  110834. };
  110835. static static_codebook _huff_book__16c2_s_long = {
  110836. 2, 100,
  110837. _huff_lengthlist__16c2_s_long,
  110838. 0, 0, 0, 0, 0,
  110839. NULL,
  110840. NULL,
  110841. NULL,
  110842. NULL,
  110843. 0
  110844. };
  110845. static long _vq_quantlist__16c2_s_p1_0[] = {
  110846. 1,
  110847. 0,
  110848. 2,
  110849. };
  110850. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110851. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110852. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110856. 0,
  110857. };
  110858. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110859. -0.5, 0.5,
  110860. };
  110861. static long _vq_quantmap__16c2_s_p1_0[] = {
  110862. 1, 0, 2,
  110863. };
  110864. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110865. _vq_quantthresh__16c2_s_p1_0,
  110866. _vq_quantmap__16c2_s_p1_0,
  110867. 3,
  110868. 3
  110869. };
  110870. static static_codebook _16c2_s_p1_0 = {
  110871. 4, 81,
  110872. _vq_lengthlist__16c2_s_p1_0,
  110873. 1, -535822336, 1611661312, 2, 0,
  110874. _vq_quantlist__16c2_s_p1_0,
  110875. NULL,
  110876. &_vq_auxt__16c2_s_p1_0,
  110877. NULL,
  110878. 0
  110879. };
  110880. static long _vq_quantlist__16c2_s_p2_0[] = {
  110881. 2,
  110882. 1,
  110883. 3,
  110884. 0,
  110885. 4,
  110886. };
  110887. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110888. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110889. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110890. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110891. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110892. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110893. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110894. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110895. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110900. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110901. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110902. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110903. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110908. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110909. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110910. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110911. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110916. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110917. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110918. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110919. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110924. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110925. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110926. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110927. 13,
  110928. };
  110929. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110930. -1.5, -0.5, 0.5, 1.5,
  110931. };
  110932. static long _vq_quantmap__16c2_s_p2_0[] = {
  110933. 3, 1, 0, 2, 4,
  110934. };
  110935. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110936. _vq_quantthresh__16c2_s_p2_0,
  110937. _vq_quantmap__16c2_s_p2_0,
  110938. 5,
  110939. 5
  110940. };
  110941. static static_codebook _16c2_s_p2_0 = {
  110942. 4, 625,
  110943. _vq_lengthlist__16c2_s_p2_0,
  110944. 1, -533725184, 1611661312, 3, 0,
  110945. _vq_quantlist__16c2_s_p2_0,
  110946. NULL,
  110947. &_vq_auxt__16c2_s_p2_0,
  110948. NULL,
  110949. 0
  110950. };
  110951. static long _vq_quantlist__16c2_s_p3_0[] = {
  110952. 4,
  110953. 3,
  110954. 5,
  110955. 2,
  110956. 6,
  110957. 1,
  110958. 7,
  110959. 0,
  110960. 8,
  110961. };
  110962. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110963. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110964. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110965. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110966. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110968. 0,
  110969. };
  110970. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110971. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110972. };
  110973. static long _vq_quantmap__16c2_s_p3_0[] = {
  110974. 7, 5, 3, 1, 0, 2, 4, 6,
  110975. 8,
  110976. };
  110977. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110978. _vq_quantthresh__16c2_s_p3_0,
  110979. _vq_quantmap__16c2_s_p3_0,
  110980. 9,
  110981. 9
  110982. };
  110983. static static_codebook _16c2_s_p3_0 = {
  110984. 2, 81,
  110985. _vq_lengthlist__16c2_s_p3_0,
  110986. 1, -531628032, 1611661312, 4, 0,
  110987. _vq_quantlist__16c2_s_p3_0,
  110988. NULL,
  110989. &_vq_auxt__16c2_s_p3_0,
  110990. NULL,
  110991. 0
  110992. };
  110993. static long _vq_quantlist__16c2_s_p4_0[] = {
  110994. 8,
  110995. 7,
  110996. 9,
  110997. 6,
  110998. 10,
  110999. 5,
  111000. 11,
  111001. 4,
  111002. 12,
  111003. 3,
  111004. 13,
  111005. 2,
  111006. 14,
  111007. 1,
  111008. 15,
  111009. 0,
  111010. 16,
  111011. };
  111012. static long _vq_lengthlist__16c2_s_p4_0[] = {
  111013. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  111014. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  111015. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  111016. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  111017. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  111018. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  111019. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  111020. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  111021. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  111022. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  111023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111031. 0,
  111032. };
  111033. static float _vq_quantthresh__16c2_s_p4_0[] = {
  111034. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111035. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111036. };
  111037. static long _vq_quantmap__16c2_s_p4_0[] = {
  111038. 15, 13, 11, 9, 7, 5, 3, 1,
  111039. 0, 2, 4, 6, 8, 10, 12, 14,
  111040. 16,
  111041. };
  111042. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  111043. _vq_quantthresh__16c2_s_p4_0,
  111044. _vq_quantmap__16c2_s_p4_0,
  111045. 17,
  111046. 17
  111047. };
  111048. static static_codebook _16c2_s_p4_0 = {
  111049. 2, 289,
  111050. _vq_lengthlist__16c2_s_p4_0,
  111051. 1, -529530880, 1611661312, 5, 0,
  111052. _vq_quantlist__16c2_s_p4_0,
  111053. NULL,
  111054. &_vq_auxt__16c2_s_p4_0,
  111055. NULL,
  111056. 0
  111057. };
  111058. static long _vq_quantlist__16c2_s_p5_0[] = {
  111059. 1,
  111060. 0,
  111061. 2,
  111062. };
  111063. static long _vq_lengthlist__16c2_s_p5_0[] = {
  111064. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  111065. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  111066. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  111067. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  111068. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  111069. 12,
  111070. };
  111071. static float _vq_quantthresh__16c2_s_p5_0[] = {
  111072. -5.5, 5.5,
  111073. };
  111074. static long _vq_quantmap__16c2_s_p5_0[] = {
  111075. 1, 0, 2,
  111076. };
  111077. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  111078. _vq_quantthresh__16c2_s_p5_0,
  111079. _vq_quantmap__16c2_s_p5_0,
  111080. 3,
  111081. 3
  111082. };
  111083. static static_codebook _16c2_s_p5_0 = {
  111084. 4, 81,
  111085. _vq_lengthlist__16c2_s_p5_0,
  111086. 1, -529137664, 1618345984, 2, 0,
  111087. _vq_quantlist__16c2_s_p5_0,
  111088. NULL,
  111089. &_vq_auxt__16c2_s_p5_0,
  111090. NULL,
  111091. 0
  111092. };
  111093. static long _vq_quantlist__16c2_s_p5_1[] = {
  111094. 5,
  111095. 4,
  111096. 6,
  111097. 3,
  111098. 7,
  111099. 2,
  111100. 8,
  111101. 1,
  111102. 9,
  111103. 0,
  111104. 10,
  111105. };
  111106. static long _vq_lengthlist__16c2_s_p5_1[] = {
  111107. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  111108. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  111109. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  111110. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  111111. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  111112. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  111113. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  111114. 11,11,11, 7, 7, 8, 8, 8, 8,
  111115. };
  111116. static float _vq_quantthresh__16c2_s_p5_1[] = {
  111117. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111118. 3.5, 4.5,
  111119. };
  111120. static long _vq_quantmap__16c2_s_p5_1[] = {
  111121. 9, 7, 5, 3, 1, 0, 2, 4,
  111122. 6, 8, 10,
  111123. };
  111124. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  111125. _vq_quantthresh__16c2_s_p5_1,
  111126. _vq_quantmap__16c2_s_p5_1,
  111127. 11,
  111128. 11
  111129. };
  111130. static static_codebook _16c2_s_p5_1 = {
  111131. 2, 121,
  111132. _vq_lengthlist__16c2_s_p5_1,
  111133. 1, -531365888, 1611661312, 4, 0,
  111134. _vq_quantlist__16c2_s_p5_1,
  111135. NULL,
  111136. &_vq_auxt__16c2_s_p5_1,
  111137. NULL,
  111138. 0
  111139. };
  111140. static long _vq_quantlist__16c2_s_p6_0[] = {
  111141. 6,
  111142. 5,
  111143. 7,
  111144. 4,
  111145. 8,
  111146. 3,
  111147. 9,
  111148. 2,
  111149. 10,
  111150. 1,
  111151. 11,
  111152. 0,
  111153. 12,
  111154. };
  111155. static long _vq_lengthlist__16c2_s_p6_0[] = {
  111156. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111157. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  111158. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  111159. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  111160. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  111161. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  111162. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0,
  111167. };
  111168. static float _vq_quantthresh__16c2_s_p6_0[] = {
  111169. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111170. 12.5, 17.5, 22.5, 27.5,
  111171. };
  111172. static long _vq_quantmap__16c2_s_p6_0[] = {
  111173. 11, 9, 7, 5, 3, 1, 0, 2,
  111174. 4, 6, 8, 10, 12,
  111175. };
  111176. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  111177. _vq_quantthresh__16c2_s_p6_0,
  111178. _vq_quantmap__16c2_s_p6_0,
  111179. 13,
  111180. 13
  111181. };
  111182. static static_codebook _16c2_s_p6_0 = {
  111183. 2, 169,
  111184. _vq_lengthlist__16c2_s_p6_0,
  111185. 1, -526516224, 1616117760, 4, 0,
  111186. _vq_quantlist__16c2_s_p6_0,
  111187. NULL,
  111188. &_vq_auxt__16c2_s_p6_0,
  111189. NULL,
  111190. 0
  111191. };
  111192. static long _vq_quantlist__16c2_s_p6_1[] = {
  111193. 2,
  111194. 1,
  111195. 3,
  111196. 0,
  111197. 4,
  111198. };
  111199. static long _vq_lengthlist__16c2_s_p6_1[] = {
  111200. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  111201. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  111202. };
  111203. static float _vq_quantthresh__16c2_s_p6_1[] = {
  111204. -1.5, -0.5, 0.5, 1.5,
  111205. };
  111206. static long _vq_quantmap__16c2_s_p6_1[] = {
  111207. 3, 1, 0, 2, 4,
  111208. };
  111209. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  111210. _vq_quantthresh__16c2_s_p6_1,
  111211. _vq_quantmap__16c2_s_p6_1,
  111212. 5,
  111213. 5
  111214. };
  111215. static static_codebook _16c2_s_p6_1 = {
  111216. 2, 25,
  111217. _vq_lengthlist__16c2_s_p6_1,
  111218. 1, -533725184, 1611661312, 3, 0,
  111219. _vq_quantlist__16c2_s_p6_1,
  111220. NULL,
  111221. &_vq_auxt__16c2_s_p6_1,
  111222. NULL,
  111223. 0
  111224. };
  111225. static long _vq_quantlist__16c2_s_p7_0[] = {
  111226. 6,
  111227. 5,
  111228. 7,
  111229. 4,
  111230. 8,
  111231. 3,
  111232. 9,
  111233. 2,
  111234. 10,
  111235. 1,
  111236. 11,
  111237. 0,
  111238. 12,
  111239. };
  111240. static long _vq_lengthlist__16c2_s_p7_0[] = {
  111241. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111242. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  111243. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  111244. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  111245. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  111246. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  111247. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  111248. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  111249. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  111250. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  111251. 18,13,14,13,13,14,13,15,14,
  111252. };
  111253. static float _vq_quantthresh__16c2_s_p7_0[] = {
  111254. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  111255. 27.5, 38.5, 49.5, 60.5,
  111256. };
  111257. static long _vq_quantmap__16c2_s_p7_0[] = {
  111258. 11, 9, 7, 5, 3, 1, 0, 2,
  111259. 4, 6, 8, 10, 12,
  111260. };
  111261. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  111262. _vq_quantthresh__16c2_s_p7_0,
  111263. _vq_quantmap__16c2_s_p7_0,
  111264. 13,
  111265. 13
  111266. };
  111267. static static_codebook _16c2_s_p7_0 = {
  111268. 2, 169,
  111269. _vq_lengthlist__16c2_s_p7_0,
  111270. 1, -523206656, 1618345984, 4, 0,
  111271. _vq_quantlist__16c2_s_p7_0,
  111272. NULL,
  111273. &_vq_auxt__16c2_s_p7_0,
  111274. NULL,
  111275. 0
  111276. };
  111277. static long _vq_quantlist__16c2_s_p7_1[] = {
  111278. 5,
  111279. 4,
  111280. 6,
  111281. 3,
  111282. 7,
  111283. 2,
  111284. 8,
  111285. 1,
  111286. 9,
  111287. 0,
  111288. 10,
  111289. };
  111290. static long _vq_lengthlist__16c2_s_p7_1[] = {
  111291. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  111292. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  111293. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  111294. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111295. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  111296. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  111297. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  111298. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111299. };
  111300. static float _vq_quantthresh__16c2_s_p7_1[] = {
  111301. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111302. 3.5, 4.5,
  111303. };
  111304. static long _vq_quantmap__16c2_s_p7_1[] = {
  111305. 9, 7, 5, 3, 1, 0, 2, 4,
  111306. 6, 8, 10,
  111307. };
  111308. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111309. _vq_quantthresh__16c2_s_p7_1,
  111310. _vq_quantmap__16c2_s_p7_1,
  111311. 11,
  111312. 11
  111313. };
  111314. static static_codebook _16c2_s_p7_1 = {
  111315. 2, 121,
  111316. _vq_lengthlist__16c2_s_p7_1,
  111317. 1, -531365888, 1611661312, 4, 0,
  111318. _vq_quantlist__16c2_s_p7_1,
  111319. NULL,
  111320. &_vq_auxt__16c2_s_p7_1,
  111321. NULL,
  111322. 0
  111323. };
  111324. static long _vq_quantlist__16c2_s_p8_0[] = {
  111325. 7,
  111326. 6,
  111327. 8,
  111328. 5,
  111329. 9,
  111330. 4,
  111331. 10,
  111332. 3,
  111333. 11,
  111334. 2,
  111335. 12,
  111336. 1,
  111337. 13,
  111338. 0,
  111339. 14,
  111340. };
  111341. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111342. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111343. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111344. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111345. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111346. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111347. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111348. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111349. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111350. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111351. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111352. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111353. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111354. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111355. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111356. 13,
  111357. };
  111358. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111359. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111360. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111361. };
  111362. static long _vq_quantmap__16c2_s_p8_0[] = {
  111363. 13, 11, 9, 7, 5, 3, 1, 0,
  111364. 2, 4, 6, 8, 10, 12, 14,
  111365. };
  111366. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111367. _vq_quantthresh__16c2_s_p8_0,
  111368. _vq_quantmap__16c2_s_p8_0,
  111369. 15,
  111370. 15
  111371. };
  111372. static static_codebook _16c2_s_p8_0 = {
  111373. 2, 225,
  111374. _vq_lengthlist__16c2_s_p8_0,
  111375. 1, -520986624, 1620377600, 4, 0,
  111376. _vq_quantlist__16c2_s_p8_0,
  111377. NULL,
  111378. &_vq_auxt__16c2_s_p8_0,
  111379. NULL,
  111380. 0
  111381. };
  111382. static long _vq_quantlist__16c2_s_p8_1[] = {
  111383. 10,
  111384. 9,
  111385. 11,
  111386. 8,
  111387. 12,
  111388. 7,
  111389. 13,
  111390. 6,
  111391. 14,
  111392. 5,
  111393. 15,
  111394. 4,
  111395. 16,
  111396. 3,
  111397. 17,
  111398. 2,
  111399. 18,
  111400. 1,
  111401. 19,
  111402. 0,
  111403. 20,
  111404. };
  111405. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111406. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111407. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111408. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111409. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111410. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111411. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111412. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111413. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111414. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111415. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111416. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111417. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111418. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111419. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111420. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111421. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111422. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111423. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111424. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111425. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111426. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111427. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111428. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111429. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111430. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111431. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111432. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111433. 10,11,10,10,10,10,10,10,10,
  111434. };
  111435. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111436. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111437. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111438. 6.5, 7.5, 8.5, 9.5,
  111439. };
  111440. static long _vq_quantmap__16c2_s_p8_1[] = {
  111441. 19, 17, 15, 13, 11, 9, 7, 5,
  111442. 3, 1, 0, 2, 4, 6, 8, 10,
  111443. 12, 14, 16, 18, 20,
  111444. };
  111445. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111446. _vq_quantthresh__16c2_s_p8_1,
  111447. _vq_quantmap__16c2_s_p8_1,
  111448. 21,
  111449. 21
  111450. };
  111451. static static_codebook _16c2_s_p8_1 = {
  111452. 2, 441,
  111453. _vq_lengthlist__16c2_s_p8_1,
  111454. 1, -529268736, 1611661312, 5, 0,
  111455. _vq_quantlist__16c2_s_p8_1,
  111456. NULL,
  111457. &_vq_auxt__16c2_s_p8_1,
  111458. NULL,
  111459. 0
  111460. };
  111461. static long _vq_quantlist__16c2_s_p9_0[] = {
  111462. 6,
  111463. 5,
  111464. 7,
  111465. 4,
  111466. 8,
  111467. 3,
  111468. 9,
  111469. 2,
  111470. 10,
  111471. 1,
  111472. 11,
  111473. 0,
  111474. 12,
  111475. };
  111476. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111477. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111478. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111479. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111480. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111481. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111482. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111483. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111484. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111485. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111486. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111487. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111488. };
  111489. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111490. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111491. 2327.5, 3258.5, 4189.5, 5120.5,
  111492. };
  111493. static long _vq_quantmap__16c2_s_p9_0[] = {
  111494. 11, 9, 7, 5, 3, 1, 0, 2,
  111495. 4, 6, 8, 10, 12,
  111496. };
  111497. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111498. _vq_quantthresh__16c2_s_p9_0,
  111499. _vq_quantmap__16c2_s_p9_0,
  111500. 13,
  111501. 13
  111502. };
  111503. static static_codebook _16c2_s_p9_0 = {
  111504. 2, 169,
  111505. _vq_lengthlist__16c2_s_p9_0,
  111506. 1, -510275072, 1631393792, 4, 0,
  111507. _vq_quantlist__16c2_s_p9_0,
  111508. NULL,
  111509. &_vq_auxt__16c2_s_p9_0,
  111510. NULL,
  111511. 0
  111512. };
  111513. static long _vq_quantlist__16c2_s_p9_1[] = {
  111514. 8,
  111515. 7,
  111516. 9,
  111517. 6,
  111518. 10,
  111519. 5,
  111520. 11,
  111521. 4,
  111522. 12,
  111523. 3,
  111524. 13,
  111525. 2,
  111526. 14,
  111527. 1,
  111528. 15,
  111529. 0,
  111530. 16,
  111531. };
  111532. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111533. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111534. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111535. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111536. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111537. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111538. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111539. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111540. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111541. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111542. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111543. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111544. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111545. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111546. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111547. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111548. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111549. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111550. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111551. 10,
  111552. };
  111553. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111554. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111555. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111556. };
  111557. static long _vq_quantmap__16c2_s_p9_1[] = {
  111558. 15, 13, 11, 9, 7, 5, 3, 1,
  111559. 0, 2, 4, 6, 8, 10, 12, 14,
  111560. 16,
  111561. };
  111562. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111563. _vq_quantthresh__16c2_s_p9_1,
  111564. _vq_quantmap__16c2_s_p9_1,
  111565. 17,
  111566. 17
  111567. };
  111568. static static_codebook _16c2_s_p9_1 = {
  111569. 2, 289,
  111570. _vq_lengthlist__16c2_s_p9_1,
  111571. 1, -518488064, 1622704128, 5, 0,
  111572. _vq_quantlist__16c2_s_p9_1,
  111573. NULL,
  111574. &_vq_auxt__16c2_s_p9_1,
  111575. NULL,
  111576. 0
  111577. };
  111578. static long _vq_quantlist__16c2_s_p9_2[] = {
  111579. 13,
  111580. 12,
  111581. 14,
  111582. 11,
  111583. 15,
  111584. 10,
  111585. 16,
  111586. 9,
  111587. 17,
  111588. 8,
  111589. 18,
  111590. 7,
  111591. 19,
  111592. 6,
  111593. 20,
  111594. 5,
  111595. 21,
  111596. 4,
  111597. 22,
  111598. 3,
  111599. 23,
  111600. 2,
  111601. 24,
  111602. 1,
  111603. 25,
  111604. 0,
  111605. 26,
  111606. };
  111607. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111608. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111609. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111610. };
  111611. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111612. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111613. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111614. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111615. 11.5, 12.5,
  111616. };
  111617. static long _vq_quantmap__16c2_s_p9_2[] = {
  111618. 25, 23, 21, 19, 17, 15, 13, 11,
  111619. 9, 7, 5, 3, 1, 0, 2, 4,
  111620. 6, 8, 10, 12, 14, 16, 18, 20,
  111621. 22, 24, 26,
  111622. };
  111623. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111624. _vq_quantthresh__16c2_s_p9_2,
  111625. _vq_quantmap__16c2_s_p9_2,
  111626. 27,
  111627. 27
  111628. };
  111629. static static_codebook _16c2_s_p9_2 = {
  111630. 1, 27,
  111631. _vq_lengthlist__16c2_s_p9_2,
  111632. 1, -528875520, 1611661312, 5, 0,
  111633. _vq_quantlist__16c2_s_p9_2,
  111634. NULL,
  111635. &_vq_auxt__16c2_s_p9_2,
  111636. NULL,
  111637. 0
  111638. };
  111639. static long _huff_lengthlist__16c2_s_short[] = {
  111640. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111641. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111642. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111643. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111644. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111645. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111646. 15,12,14,14,
  111647. };
  111648. static static_codebook _huff_book__16c2_s_short = {
  111649. 2, 100,
  111650. _huff_lengthlist__16c2_s_short,
  111651. 0, 0, 0, 0, 0,
  111652. NULL,
  111653. NULL,
  111654. NULL,
  111655. NULL,
  111656. 0
  111657. };
  111658. static long _vq_quantlist__8c0_s_p1_0[] = {
  111659. 1,
  111660. 0,
  111661. 2,
  111662. };
  111663. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111664. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111665. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111669. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111670. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111674. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111675. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111706. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111710. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  111715. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  111720. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111755. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111756. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111760. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111761. 0, 0, 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 0, 0,
  111762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111765. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111766. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112074. 0,
  112075. };
  112076. static float _vq_quantthresh__8c0_s_p1_0[] = {
  112077. -0.5, 0.5,
  112078. };
  112079. static long _vq_quantmap__8c0_s_p1_0[] = {
  112080. 1, 0, 2,
  112081. };
  112082. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  112083. _vq_quantthresh__8c0_s_p1_0,
  112084. _vq_quantmap__8c0_s_p1_0,
  112085. 3,
  112086. 3
  112087. };
  112088. static static_codebook _8c0_s_p1_0 = {
  112089. 8, 6561,
  112090. _vq_lengthlist__8c0_s_p1_0,
  112091. 1, -535822336, 1611661312, 2, 0,
  112092. _vq_quantlist__8c0_s_p1_0,
  112093. NULL,
  112094. &_vq_auxt__8c0_s_p1_0,
  112095. NULL,
  112096. 0
  112097. };
  112098. static long _vq_quantlist__8c0_s_p2_0[] = {
  112099. 2,
  112100. 1,
  112101. 3,
  112102. 0,
  112103. 4,
  112104. };
  112105. static long _vq_lengthlist__8c0_s_p2_0[] = {
  112106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112145. 0,
  112146. };
  112147. static float _vq_quantthresh__8c0_s_p2_0[] = {
  112148. -1.5, -0.5, 0.5, 1.5,
  112149. };
  112150. static long _vq_quantmap__8c0_s_p2_0[] = {
  112151. 3, 1, 0, 2, 4,
  112152. };
  112153. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  112154. _vq_quantthresh__8c0_s_p2_0,
  112155. _vq_quantmap__8c0_s_p2_0,
  112156. 5,
  112157. 5
  112158. };
  112159. static static_codebook _8c0_s_p2_0 = {
  112160. 4, 625,
  112161. _vq_lengthlist__8c0_s_p2_0,
  112162. 1, -533725184, 1611661312, 3, 0,
  112163. _vq_quantlist__8c0_s_p2_0,
  112164. NULL,
  112165. &_vq_auxt__8c0_s_p2_0,
  112166. NULL,
  112167. 0
  112168. };
  112169. static long _vq_quantlist__8c0_s_p3_0[] = {
  112170. 2,
  112171. 1,
  112172. 3,
  112173. 0,
  112174. 4,
  112175. };
  112176. static long _vq_lengthlist__8c0_s_p3_0[] = {
  112177. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  112179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112180. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  112182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112183. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  112184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112216. 0,
  112217. };
  112218. static float _vq_quantthresh__8c0_s_p3_0[] = {
  112219. -1.5, -0.5, 0.5, 1.5,
  112220. };
  112221. static long _vq_quantmap__8c0_s_p3_0[] = {
  112222. 3, 1, 0, 2, 4,
  112223. };
  112224. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  112225. _vq_quantthresh__8c0_s_p3_0,
  112226. _vq_quantmap__8c0_s_p3_0,
  112227. 5,
  112228. 5
  112229. };
  112230. static static_codebook _8c0_s_p3_0 = {
  112231. 4, 625,
  112232. _vq_lengthlist__8c0_s_p3_0,
  112233. 1, -533725184, 1611661312, 3, 0,
  112234. _vq_quantlist__8c0_s_p3_0,
  112235. NULL,
  112236. &_vq_auxt__8c0_s_p3_0,
  112237. NULL,
  112238. 0
  112239. };
  112240. static long _vq_quantlist__8c0_s_p4_0[] = {
  112241. 4,
  112242. 3,
  112243. 5,
  112244. 2,
  112245. 6,
  112246. 1,
  112247. 7,
  112248. 0,
  112249. 8,
  112250. };
  112251. static long _vq_lengthlist__8c0_s_p4_0[] = {
  112252. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112253. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112254. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112255. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112256. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112257. 0,
  112258. };
  112259. static float _vq_quantthresh__8c0_s_p4_0[] = {
  112260. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112261. };
  112262. static long _vq_quantmap__8c0_s_p4_0[] = {
  112263. 7, 5, 3, 1, 0, 2, 4, 6,
  112264. 8,
  112265. };
  112266. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  112267. _vq_quantthresh__8c0_s_p4_0,
  112268. _vq_quantmap__8c0_s_p4_0,
  112269. 9,
  112270. 9
  112271. };
  112272. static static_codebook _8c0_s_p4_0 = {
  112273. 2, 81,
  112274. _vq_lengthlist__8c0_s_p4_0,
  112275. 1, -531628032, 1611661312, 4, 0,
  112276. _vq_quantlist__8c0_s_p4_0,
  112277. NULL,
  112278. &_vq_auxt__8c0_s_p4_0,
  112279. NULL,
  112280. 0
  112281. };
  112282. static long _vq_quantlist__8c0_s_p5_0[] = {
  112283. 4,
  112284. 3,
  112285. 5,
  112286. 2,
  112287. 6,
  112288. 1,
  112289. 7,
  112290. 0,
  112291. 8,
  112292. };
  112293. static long _vq_lengthlist__8c0_s_p5_0[] = {
  112294. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  112295. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  112296. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  112297. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  112298. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112299. 10,
  112300. };
  112301. static float _vq_quantthresh__8c0_s_p5_0[] = {
  112302. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112303. };
  112304. static long _vq_quantmap__8c0_s_p5_0[] = {
  112305. 7, 5, 3, 1, 0, 2, 4, 6,
  112306. 8,
  112307. };
  112308. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112309. _vq_quantthresh__8c0_s_p5_0,
  112310. _vq_quantmap__8c0_s_p5_0,
  112311. 9,
  112312. 9
  112313. };
  112314. static static_codebook _8c0_s_p5_0 = {
  112315. 2, 81,
  112316. _vq_lengthlist__8c0_s_p5_0,
  112317. 1, -531628032, 1611661312, 4, 0,
  112318. _vq_quantlist__8c0_s_p5_0,
  112319. NULL,
  112320. &_vq_auxt__8c0_s_p5_0,
  112321. NULL,
  112322. 0
  112323. };
  112324. static long _vq_quantlist__8c0_s_p6_0[] = {
  112325. 8,
  112326. 7,
  112327. 9,
  112328. 6,
  112329. 10,
  112330. 5,
  112331. 11,
  112332. 4,
  112333. 12,
  112334. 3,
  112335. 13,
  112336. 2,
  112337. 14,
  112338. 1,
  112339. 15,
  112340. 0,
  112341. 16,
  112342. };
  112343. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112344. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112345. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112346. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112347. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112348. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112349. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112350. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112351. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112352. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112353. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112354. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112355. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112356. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112357. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112358. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112359. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112360. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112361. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112362. 14,
  112363. };
  112364. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112365. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112366. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112367. };
  112368. static long _vq_quantmap__8c0_s_p6_0[] = {
  112369. 15, 13, 11, 9, 7, 5, 3, 1,
  112370. 0, 2, 4, 6, 8, 10, 12, 14,
  112371. 16,
  112372. };
  112373. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112374. _vq_quantthresh__8c0_s_p6_0,
  112375. _vq_quantmap__8c0_s_p6_0,
  112376. 17,
  112377. 17
  112378. };
  112379. static static_codebook _8c0_s_p6_0 = {
  112380. 2, 289,
  112381. _vq_lengthlist__8c0_s_p6_0,
  112382. 1, -529530880, 1611661312, 5, 0,
  112383. _vq_quantlist__8c0_s_p6_0,
  112384. NULL,
  112385. &_vq_auxt__8c0_s_p6_0,
  112386. NULL,
  112387. 0
  112388. };
  112389. static long _vq_quantlist__8c0_s_p7_0[] = {
  112390. 1,
  112391. 0,
  112392. 2,
  112393. };
  112394. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112395. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112396. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112397. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112398. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112399. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112400. 10,
  112401. };
  112402. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112403. -5.5, 5.5,
  112404. };
  112405. static long _vq_quantmap__8c0_s_p7_0[] = {
  112406. 1, 0, 2,
  112407. };
  112408. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112409. _vq_quantthresh__8c0_s_p7_0,
  112410. _vq_quantmap__8c0_s_p7_0,
  112411. 3,
  112412. 3
  112413. };
  112414. static static_codebook _8c0_s_p7_0 = {
  112415. 4, 81,
  112416. _vq_lengthlist__8c0_s_p7_0,
  112417. 1, -529137664, 1618345984, 2, 0,
  112418. _vq_quantlist__8c0_s_p7_0,
  112419. NULL,
  112420. &_vq_auxt__8c0_s_p7_0,
  112421. NULL,
  112422. 0
  112423. };
  112424. static long _vq_quantlist__8c0_s_p7_1[] = {
  112425. 5,
  112426. 4,
  112427. 6,
  112428. 3,
  112429. 7,
  112430. 2,
  112431. 8,
  112432. 1,
  112433. 9,
  112434. 0,
  112435. 10,
  112436. };
  112437. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112438. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112439. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112440. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112441. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112442. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112443. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112444. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112445. 10,10,10, 9, 9, 9,10,10,10,
  112446. };
  112447. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112448. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112449. 3.5, 4.5,
  112450. };
  112451. static long _vq_quantmap__8c0_s_p7_1[] = {
  112452. 9, 7, 5, 3, 1, 0, 2, 4,
  112453. 6, 8, 10,
  112454. };
  112455. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112456. _vq_quantthresh__8c0_s_p7_1,
  112457. _vq_quantmap__8c0_s_p7_1,
  112458. 11,
  112459. 11
  112460. };
  112461. static static_codebook _8c0_s_p7_1 = {
  112462. 2, 121,
  112463. _vq_lengthlist__8c0_s_p7_1,
  112464. 1, -531365888, 1611661312, 4, 0,
  112465. _vq_quantlist__8c0_s_p7_1,
  112466. NULL,
  112467. &_vq_auxt__8c0_s_p7_1,
  112468. NULL,
  112469. 0
  112470. };
  112471. static long _vq_quantlist__8c0_s_p8_0[] = {
  112472. 6,
  112473. 5,
  112474. 7,
  112475. 4,
  112476. 8,
  112477. 3,
  112478. 9,
  112479. 2,
  112480. 10,
  112481. 1,
  112482. 11,
  112483. 0,
  112484. 12,
  112485. };
  112486. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112487. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112488. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112489. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112490. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112491. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112492. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112493. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112494. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112495. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112496. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112497. 0, 0,13,13,11,13,13,11,12,
  112498. };
  112499. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112500. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112501. 12.5, 17.5, 22.5, 27.5,
  112502. };
  112503. static long _vq_quantmap__8c0_s_p8_0[] = {
  112504. 11, 9, 7, 5, 3, 1, 0, 2,
  112505. 4, 6, 8, 10, 12,
  112506. };
  112507. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112508. _vq_quantthresh__8c0_s_p8_0,
  112509. _vq_quantmap__8c0_s_p8_0,
  112510. 13,
  112511. 13
  112512. };
  112513. static static_codebook _8c0_s_p8_0 = {
  112514. 2, 169,
  112515. _vq_lengthlist__8c0_s_p8_0,
  112516. 1, -526516224, 1616117760, 4, 0,
  112517. _vq_quantlist__8c0_s_p8_0,
  112518. NULL,
  112519. &_vq_auxt__8c0_s_p8_0,
  112520. NULL,
  112521. 0
  112522. };
  112523. static long _vq_quantlist__8c0_s_p8_1[] = {
  112524. 2,
  112525. 1,
  112526. 3,
  112527. 0,
  112528. 4,
  112529. };
  112530. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112531. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112532. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112533. };
  112534. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112535. -1.5, -0.5, 0.5, 1.5,
  112536. };
  112537. static long _vq_quantmap__8c0_s_p8_1[] = {
  112538. 3, 1, 0, 2, 4,
  112539. };
  112540. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112541. _vq_quantthresh__8c0_s_p8_1,
  112542. _vq_quantmap__8c0_s_p8_1,
  112543. 5,
  112544. 5
  112545. };
  112546. static static_codebook _8c0_s_p8_1 = {
  112547. 2, 25,
  112548. _vq_lengthlist__8c0_s_p8_1,
  112549. 1, -533725184, 1611661312, 3, 0,
  112550. _vq_quantlist__8c0_s_p8_1,
  112551. NULL,
  112552. &_vq_auxt__8c0_s_p8_1,
  112553. NULL,
  112554. 0
  112555. };
  112556. static long _vq_quantlist__8c0_s_p9_0[] = {
  112557. 1,
  112558. 0,
  112559. 2,
  112560. };
  112561. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112562. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112563. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112564. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112565. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112566. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112567. 7,
  112568. };
  112569. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112570. -157.5, 157.5,
  112571. };
  112572. static long _vq_quantmap__8c0_s_p9_0[] = {
  112573. 1, 0, 2,
  112574. };
  112575. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112576. _vq_quantthresh__8c0_s_p9_0,
  112577. _vq_quantmap__8c0_s_p9_0,
  112578. 3,
  112579. 3
  112580. };
  112581. static static_codebook _8c0_s_p9_0 = {
  112582. 4, 81,
  112583. _vq_lengthlist__8c0_s_p9_0,
  112584. 1, -518803456, 1628680192, 2, 0,
  112585. _vq_quantlist__8c0_s_p9_0,
  112586. NULL,
  112587. &_vq_auxt__8c0_s_p9_0,
  112588. NULL,
  112589. 0
  112590. };
  112591. static long _vq_quantlist__8c0_s_p9_1[] = {
  112592. 7,
  112593. 6,
  112594. 8,
  112595. 5,
  112596. 9,
  112597. 4,
  112598. 10,
  112599. 3,
  112600. 11,
  112601. 2,
  112602. 12,
  112603. 1,
  112604. 13,
  112605. 0,
  112606. 14,
  112607. };
  112608. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112609. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112610. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112611. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112612. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112613. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112614. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112615. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112616. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112617. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112618. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112619. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112620. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112621. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112622. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112623. 11,
  112624. };
  112625. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112626. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112627. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112628. };
  112629. static long _vq_quantmap__8c0_s_p9_1[] = {
  112630. 13, 11, 9, 7, 5, 3, 1, 0,
  112631. 2, 4, 6, 8, 10, 12, 14,
  112632. };
  112633. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112634. _vq_quantthresh__8c0_s_p9_1,
  112635. _vq_quantmap__8c0_s_p9_1,
  112636. 15,
  112637. 15
  112638. };
  112639. static static_codebook _8c0_s_p9_1 = {
  112640. 2, 225,
  112641. _vq_lengthlist__8c0_s_p9_1,
  112642. 1, -520986624, 1620377600, 4, 0,
  112643. _vq_quantlist__8c0_s_p9_1,
  112644. NULL,
  112645. &_vq_auxt__8c0_s_p9_1,
  112646. NULL,
  112647. 0
  112648. };
  112649. static long _vq_quantlist__8c0_s_p9_2[] = {
  112650. 10,
  112651. 9,
  112652. 11,
  112653. 8,
  112654. 12,
  112655. 7,
  112656. 13,
  112657. 6,
  112658. 14,
  112659. 5,
  112660. 15,
  112661. 4,
  112662. 16,
  112663. 3,
  112664. 17,
  112665. 2,
  112666. 18,
  112667. 1,
  112668. 19,
  112669. 0,
  112670. 20,
  112671. };
  112672. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112673. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112674. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112675. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112676. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112677. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112678. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112679. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112680. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112681. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112682. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112683. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112684. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112685. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112686. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112687. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112688. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112689. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112690. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112691. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112692. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112693. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112694. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112695. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112696. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112697. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112698. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112699. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112700. 10,11, 9,11,10, 9,10, 9,10,
  112701. };
  112702. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112703. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112704. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112705. 6.5, 7.5, 8.5, 9.5,
  112706. };
  112707. static long _vq_quantmap__8c0_s_p9_2[] = {
  112708. 19, 17, 15, 13, 11, 9, 7, 5,
  112709. 3, 1, 0, 2, 4, 6, 8, 10,
  112710. 12, 14, 16, 18, 20,
  112711. };
  112712. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112713. _vq_quantthresh__8c0_s_p9_2,
  112714. _vq_quantmap__8c0_s_p9_2,
  112715. 21,
  112716. 21
  112717. };
  112718. static static_codebook _8c0_s_p9_2 = {
  112719. 2, 441,
  112720. _vq_lengthlist__8c0_s_p9_2,
  112721. 1, -529268736, 1611661312, 5, 0,
  112722. _vq_quantlist__8c0_s_p9_2,
  112723. NULL,
  112724. &_vq_auxt__8c0_s_p9_2,
  112725. NULL,
  112726. 0
  112727. };
  112728. static long _huff_lengthlist__8c0_s_single[] = {
  112729. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112730. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112731. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112732. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112733. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112734. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112735. 17,16,17,17,
  112736. };
  112737. static static_codebook _huff_book__8c0_s_single = {
  112738. 2, 100,
  112739. _huff_lengthlist__8c0_s_single,
  112740. 0, 0, 0, 0, 0,
  112741. NULL,
  112742. NULL,
  112743. NULL,
  112744. NULL,
  112745. 0
  112746. };
  112747. static long _vq_quantlist__8c1_s_p1_0[] = {
  112748. 1,
  112749. 0,
  112750. 2,
  112751. };
  112752. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112753. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112754. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112758. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112759. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112763. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112764. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112795. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112799. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  112804. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112809. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112844. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112845. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112849. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112850. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  112851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112854. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112855. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113163. 0,
  113164. };
  113165. static float _vq_quantthresh__8c1_s_p1_0[] = {
  113166. -0.5, 0.5,
  113167. };
  113168. static long _vq_quantmap__8c1_s_p1_0[] = {
  113169. 1, 0, 2,
  113170. };
  113171. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  113172. _vq_quantthresh__8c1_s_p1_0,
  113173. _vq_quantmap__8c1_s_p1_0,
  113174. 3,
  113175. 3
  113176. };
  113177. static static_codebook _8c1_s_p1_0 = {
  113178. 8, 6561,
  113179. _vq_lengthlist__8c1_s_p1_0,
  113180. 1, -535822336, 1611661312, 2, 0,
  113181. _vq_quantlist__8c1_s_p1_0,
  113182. NULL,
  113183. &_vq_auxt__8c1_s_p1_0,
  113184. NULL,
  113185. 0
  113186. };
  113187. static long _vq_quantlist__8c1_s_p2_0[] = {
  113188. 2,
  113189. 1,
  113190. 3,
  113191. 0,
  113192. 4,
  113193. };
  113194. static long _vq_lengthlist__8c1_s_p2_0[] = {
  113195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113234. 0,
  113235. };
  113236. static float _vq_quantthresh__8c1_s_p2_0[] = {
  113237. -1.5, -0.5, 0.5, 1.5,
  113238. };
  113239. static long _vq_quantmap__8c1_s_p2_0[] = {
  113240. 3, 1, 0, 2, 4,
  113241. };
  113242. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  113243. _vq_quantthresh__8c1_s_p2_0,
  113244. _vq_quantmap__8c1_s_p2_0,
  113245. 5,
  113246. 5
  113247. };
  113248. static static_codebook _8c1_s_p2_0 = {
  113249. 4, 625,
  113250. _vq_lengthlist__8c1_s_p2_0,
  113251. 1, -533725184, 1611661312, 3, 0,
  113252. _vq_quantlist__8c1_s_p2_0,
  113253. NULL,
  113254. &_vq_auxt__8c1_s_p2_0,
  113255. NULL,
  113256. 0
  113257. };
  113258. static long _vq_quantlist__8c1_s_p3_0[] = {
  113259. 2,
  113260. 1,
  113261. 3,
  113262. 0,
  113263. 4,
  113264. };
  113265. static long _vq_lengthlist__8c1_s_p3_0[] = {
  113266. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113269. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  113271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113272. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113305. 0,
  113306. };
  113307. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113308. -1.5, -0.5, 0.5, 1.5,
  113309. };
  113310. static long _vq_quantmap__8c1_s_p3_0[] = {
  113311. 3, 1, 0, 2, 4,
  113312. };
  113313. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113314. _vq_quantthresh__8c1_s_p3_0,
  113315. _vq_quantmap__8c1_s_p3_0,
  113316. 5,
  113317. 5
  113318. };
  113319. static static_codebook _8c1_s_p3_0 = {
  113320. 4, 625,
  113321. _vq_lengthlist__8c1_s_p3_0,
  113322. 1, -533725184, 1611661312, 3, 0,
  113323. _vq_quantlist__8c1_s_p3_0,
  113324. NULL,
  113325. &_vq_auxt__8c1_s_p3_0,
  113326. NULL,
  113327. 0
  113328. };
  113329. static long _vq_quantlist__8c1_s_p4_0[] = {
  113330. 4,
  113331. 3,
  113332. 5,
  113333. 2,
  113334. 6,
  113335. 1,
  113336. 7,
  113337. 0,
  113338. 8,
  113339. };
  113340. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113341. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113342. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113343. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113344. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113345. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113346. 0,
  113347. };
  113348. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113349. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113350. };
  113351. static long _vq_quantmap__8c1_s_p4_0[] = {
  113352. 7, 5, 3, 1, 0, 2, 4, 6,
  113353. 8,
  113354. };
  113355. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113356. _vq_quantthresh__8c1_s_p4_0,
  113357. _vq_quantmap__8c1_s_p4_0,
  113358. 9,
  113359. 9
  113360. };
  113361. static static_codebook _8c1_s_p4_0 = {
  113362. 2, 81,
  113363. _vq_lengthlist__8c1_s_p4_0,
  113364. 1, -531628032, 1611661312, 4, 0,
  113365. _vq_quantlist__8c1_s_p4_0,
  113366. NULL,
  113367. &_vq_auxt__8c1_s_p4_0,
  113368. NULL,
  113369. 0
  113370. };
  113371. static long _vq_quantlist__8c1_s_p5_0[] = {
  113372. 4,
  113373. 3,
  113374. 5,
  113375. 2,
  113376. 6,
  113377. 1,
  113378. 7,
  113379. 0,
  113380. 8,
  113381. };
  113382. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113383. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113384. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113385. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113386. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113387. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113388. 10,
  113389. };
  113390. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113391. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113392. };
  113393. static long _vq_quantmap__8c1_s_p5_0[] = {
  113394. 7, 5, 3, 1, 0, 2, 4, 6,
  113395. 8,
  113396. };
  113397. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113398. _vq_quantthresh__8c1_s_p5_0,
  113399. _vq_quantmap__8c1_s_p5_0,
  113400. 9,
  113401. 9
  113402. };
  113403. static static_codebook _8c1_s_p5_0 = {
  113404. 2, 81,
  113405. _vq_lengthlist__8c1_s_p5_0,
  113406. 1, -531628032, 1611661312, 4, 0,
  113407. _vq_quantlist__8c1_s_p5_0,
  113408. NULL,
  113409. &_vq_auxt__8c1_s_p5_0,
  113410. NULL,
  113411. 0
  113412. };
  113413. static long _vq_quantlist__8c1_s_p6_0[] = {
  113414. 8,
  113415. 7,
  113416. 9,
  113417. 6,
  113418. 10,
  113419. 5,
  113420. 11,
  113421. 4,
  113422. 12,
  113423. 3,
  113424. 13,
  113425. 2,
  113426. 14,
  113427. 1,
  113428. 15,
  113429. 0,
  113430. 16,
  113431. };
  113432. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113433. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113434. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113435. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113436. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113437. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113438. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113439. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113440. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113441. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113442. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113443. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113444. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113445. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113446. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113447. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113448. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113449. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113450. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113451. 14,
  113452. };
  113453. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113454. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113455. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113456. };
  113457. static long _vq_quantmap__8c1_s_p6_0[] = {
  113458. 15, 13, 11, 9, 7, 5, 3, 1,
  113459. 0, 2, 4, 6, 8, 10, 12, 14,
  113460. 16,
  113461. };
  113462. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113463. _vq_quantthresh__8c1_s_p6_0,
  113464. _vq_quantmap__8c1_s_p6_0,
  113465. 17,
  113466. 17
  113467. };
  113468. static static_codebook _8c1_s_p6_0 = {
  113469. 2, 289,
  113470. _vq_lengthlist__8c1_s_p6_0,
  113471. 1, -529530880, 1611661312, 5, 0,
  113472. _vq_quantlist__8c1_s_p6_0,
  113473. NULL,
  113474. &_vq_auxt__8c1_s_p6_0,
  113475. NULL,
  113476. 0
  113477. };
  113478. static long _vq_quantlist__8c1_s_p7_0[] = {
  113479. 1,
  113480. 0,
  113481. 2,
  113482. };
  113483. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113484. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113485. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113486. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113487. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113488. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113489. 9,
  113490. };
  113491. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113492. -5.5, 5.5,
  113493. };
  113494. static long _vq_quantmap__8c1_s_p7_0[] = {
  113495. 1, 0, 2,
  113496. };
  113497. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113498. _vq_quantthresh__8c1_s_p7_0,
  113499. _vq_quantmap__8c1_s_p7_0,
  113500. 3,
  113501. 3
  113502. };
  113503. static static_codebook _8c1_s_p7_0 = {
  113504. 4, 81,
  113505. _vq_lengthlist__8c1_s_p7_0,
  113506. 1, -529137664, 1618345984, 2, 0,
  113507. _vq_quantlist__8c1_s_p7_0,
  113508. NULL,
  113509. &_vq_auxt__8c1_s_p7_0,
  113510. NULL,
  113511. 0
  113512. };
  113513. static long _vq_quantlist__8c1_s_p7_1[] = {
  113514. 5,
  113515. 4,
  113516. 6,
  113517. 3,
  113518. 7,
  113519. 2,
  113520. 8,
  113521. 1,
  113522. 9,
  113523. 0,
  113524. 10,
  113525. };
  113526. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113527. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113528. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113529. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113530. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113531. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113532. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113533. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113534. 10,10,10, 8, 8, 8, 8, 8, 8,
  113535. };
  113536. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113537. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113538. 3.5, 4.5,
  113539. };
  113540. static long _vq_quantmap__8c1_s_p7_1[] = {
  113541. 9, 7, 5, 3, 1, 0, 2, 4,
  113542. 6, 8, 10,
  113543. };
  113544. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113545. _vq_quantthresh__8c1_s_p7_1,
  113546. _vq_quantmap__8c1_s_p7_1,
  113547. 11,
  113548. 11
  113549. };
  113550. static static_codebook _8c1_s_p7_1 = {
  113551. 2, 121,
  113552. _vq_lengthlist__8c1_s_p7_1,
  113553. 1, -531365888, 1611661312, 4, 0,
  113554. _vq_quantlist__8c1_s_p7_1,
  113555. NULL,
  113556. &_vq_auxt__8c1_s_p7_1,
  113557. NULL,
  113558. 0
  113559. };
  113560. static long _vq_quantlist__8c1_s_p8_0[] = {
  113561. 6,
  113562. 5,
  113563. 7,
  113564. 4,
  113565. 8,
  113566. 3,
  113567. 9,
  113568. 2,
  113569. 10,
  113570. 1,
  113571. 11,
  113572. 0,
  113573. 12,
  113574. };
  113575. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113576. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113577. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113578. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113579. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113580. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113581. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113582. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113583. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113584. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113585. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113586. 0,12,12,11,10,12,11,13,12,
  113587. };
  113588. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113589. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113590. 12.5, 17.5, 22.5, 27.5,
  113591. };
  113592. static long _vq_quantmap__8c1_s_p8_0[] = {
  113593. 11, 9, 7, 5, 3, 1, 0, 2,
  113594. 4, 6, 8, 10, 12,
  113595. };
  113596. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113597. _vq_quantthresh__8c1_s_p8_0,
  113598. _vq_quantmap__8c1_s_p8_0,
  113599. 13,
  113600. 13
  113601. };
  113602. static static_codebook _8c1_s_p8_0 = {
  113603. 2, 169,
  113604. _vq_lengthlist__8c1_s_p8_0,
  113605. 1, -526516224, 1616117760, 4, 0,
  113606. _vq_quantlist__8c1_s_p8_0,
  113607. NULL,
  113608. &_vq_auxt__8c1_s_p8_0,
  113609. NULL,
  113610. 0
  113611. };
  113612. static long _vq_quantlist__8c1_s_p8_1[] = {
  113613. 2,
  113614. 1,
  113615. 3,
  113616. 0,
  113617. 4,
  113618. };
  113619. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113620. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113621. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113622. };
  113623. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113624. -1.5, -0.5, 0.5, 1.5,
  113625. };
  113626. static long _vq_quantmap__8c1_s_p8_1[] = {
  113627. 3, 1, 0, 2, 4,
  113628. };
  113629. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113630. _vq_quantthresh__8c1_s_p8_1,
  113631. _vq_quantmap__8c1_s_p8_1,
  113632. 5,
  113633. 5
  113634. };
  113635. static static_codebook _8c1_s_p8_1 = {
  113636. 2, 25,
  113637. _vq_lengthlist__8c1_s_p8_1,
  113638. 1, -533725184, 1611661312, 3, 0,
  113639. _vq_quantlist__8c1_s_p8_1,
  113640. NULL,
  113641. &_vq_auxt__8c1_s_p8_1,
  113642. NULL,
  113643. 0
  113644. };
  113645. static long _vq_quantlist__8c1_s_p9_0[] = {
  113646. 6,
  113647. 5,
  113648. 7,
  113649. 4,
  113650. 8,
  113651. 3,
  113652. 9,
  113653. 2,
  113654. 10,
  113655. 1,
  113656. 11,
  113657. 0,
  113658. 12,
  113659. };
  113660. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113661. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113662. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113663. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113664. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113665. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113666. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113667. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113668. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113669. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113670. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113671. 10,10,10,10,10, 9, 9, 9, 9,
  113672. };
  113673. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113674. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113675. 787.5, 1102.5, 1417.5, 1732.5,
  113676. };
  113677. static long _vq_quantmap__8c1_s_p9_0[] = {
  113678. 11, 9, 7, 5, 3, 1, 0, 2,
  113679. 4, 6, 8, 10, 12,
  113680. };
  113681. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113682. _vq_quantthresh__8c1_s_p9_0,
  113683. _vq_quantmap__8c1_s_p9_0,
  113684. 13,
  113685. 13
  113686. };
  113687. static static_codebook _8c1_s_p9_0 = {
  113688. 2, 169,
  113689. _vq_lengthlist__8c1_s_p9_0,
  113690. 1, -513964032, 1628680192, 4, 0,
  113691. _vq_quantlist__8c1_s_p9_0,
  113692. NULL,
  113693. &_vq_auxt__8c1_s_p9_0,
  113694. NULL,
  113695. 0
  113696. };
  113697. static long _vq_quantlist__8c1_s_p9_1[] = {
  113698. 7,
  113699. 6,
  113700. 8,
  113701. 5,
  113702. 9,
  113703. 4,
  113704. 10,
  113705. 3,
  113706. 11,
  113707. 2,
  113708. 12,
  113709. 1,
  113710. 13,
  113711. 0,
  113712. 14,
  113713. };
  113714. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113715. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113716. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113717. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113718. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113719. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113720. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113721. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113722. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113723. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113724. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113725. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113726. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113727. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113728. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113729. 15,
  113730. };
  113731. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113732. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113733. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113734. };
  113735. static long _vq_quantmap__8c1_s_p9_1[] = {
  113736. 13, 11, 9, 7, 5, 3, 1, 0,
  113737. 2, 4, 6, 8, 10, 12, 14,
  113738. };
  113739. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113740. _vq_quantthresh__8c1_s_p9_1,
  113741. _vq_quantmap__8c1_s_p9_1,
  113742. 15,
  113743. 15
  113744. };
  113745. static static_codebook _8c1_s_p9_1 = {
  113746. 2, 225,
  113747. _vq_lengthlist__8c1_s_p9_1,
  113748. 1, -520986624, 1620377600, 4, 0,
  113749. _vq_quantlist__8c1_s_p9_1,
  113750. NULL,
  113751. &_vq_auxt__8c1_s_p9_1,
  113752. NULL,
  113753. 0
  113754. };
  113755. static long _vq_quantlist__8c1_s_p9_2[] = {
  113756. 10,
  113757. 9,
  113758. 11,
  113759. 8,
  113760. 12,
  113761. 7,
  113762. 13,
  113763. 6,
  113764. 14,
  113765. 5,
  113766. 15,
  113767. 4,
  113768. 16,
  113769. 3,
  113770. 17,
  113771. 2,
  113772. 18,
  113773. 1,
  113774. 19,
  113775. 0,
  113776. 20,
  113777. };
  113778. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113779. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113780. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113781. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113782. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113783. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113784. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113785. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113786. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113787. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113788. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113789. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113790. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113791. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113792. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113793. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113794. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113795. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113796. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113797. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113798. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113799. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113800. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113801. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113802. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113803. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113804. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113805. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113806. 10,10,10,10,10,10,10,10,10,
  113807. };
  113808. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113809. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113810. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113811. 6.5, 7.5, 8.5, 9.5,
  113812. };
  113813. static long _vq_quantmap__8c1_s_p9_2[] = {
  113814. 19, 17, 15, 13, 11, 9, 7, 5,
  113815. 3, 1, 0, 2, 4, 6, 8, 10,
  113816. 12, 14, 16, 18, 20,
  113817. };
  113818. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113819. _vq_quantthresh__8c1_s_p9_2,
  113820. _vq_quantmap__8c1_s_p9_2,
  113821. 21,
  113822. 21
  113823. };
  113824. static static_codebook _8c1_s_p9_2 = {
  113825. 2, 441,
  113826. _vq_lengthlist__8c1_s_p9_2,
  113827. 1, -529268736, 1611661312, 5, 0,
  113828. _vq_quantlist__8c1_s_p9_2,
  113829. NULL,
  113830. &_vq_auxt__8c1_s_p9_2,
  113831. NULL,
  113832. 0
  113833. };
  113834. static long _huff_lengthlist__8c1_s_single[] = {
  113835. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113836. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113837. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113838. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113839. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113840. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113841. 9, 7, 7, 8,
  113842. };
  113843. static static_codebook _huff_book__8c1_s_single = {
  113844. 2, 100,
  113845. _huff_lengthlist__8c1_s_single,
  113846. 0, 0, 0, 0, 0,
  113847. NULL,
  113848. NULL,
  113849. NULL,
  113850. NULL,
  113851. 0
  113852. };
  113853. static long _huff_lengthlist__44c2_s_long[] = {
  113854. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113855. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113856. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113857. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113858. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113859. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113860. 10, 8, 8, 9,
  113861. };
  113862. static static_codebook _huff_book__44c2_s_long = {
  113863. 2, 100,
  113864. _huff_lengthlist__44c2_s_long,
  113865. 0, 0, 0, 0, 0,
  113866. NULL,
  113867. NULL,
  113868. NULL,
  113869. NULL,
  113870. 0
  113871. };
  113872. static long _vq_quantlist__44c2_s_p1_0[] = {
  113873. 1,
  113874. 0,
  113875. 2,
  113876. };
  113877. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113878. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113879. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113883. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113884. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113888. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113889. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113920. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113924. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113929. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  113934. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113969. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113970. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113974. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113975. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  113976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113979. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113980. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114288. 0,
  114289. };
  114290. static float _vq_quantthresh__44c2_s_p1_0[] = {
  114291. -0.5, 0.5,
  114292. };
  114293. static long _vq_quantmap__44c2_s_p1_0[] = {
  114294. 1, 0, 2,
  114295. };
  114296. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  114297. _vq_quantthresh__44c2_s_p1_0,
  114298. _vq_quantmap__44c2_s_p1_0,
  114299. 3,
  114300. 3
  114301. };
  114302. static static_codebook _44c2_s_p1_0 = {
  114303. 8, 6561,
  114304. _vq_lengthlist__44c2_s_p1_0,
  114305. 1, -535822336, 1611661312, 2, 0,
  114306. _vq_quantlist__44c2_s_p1_0,
  114307. NULL,
  114308. &_vq_auxt__44c2_s_p1_0,
  114309. NULL,
  114310. 0
  114311. };
  114312. static long _vq_quantlist__44c2_s_p2_0[] = {
  114313. 2,
  114314. 1,
  114315. 3,
  114316. 0,
  114317. 4,
  114318. };
  114319. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114320. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114321. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114322. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114323. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114324. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114329. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114330. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114331. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114332. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114337. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114338. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114339. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  114340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114345. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114346. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114347. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114359. 0,
  114360. };
  114361. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114362. -1.5, -0.5, 0.5, 1.5,
  114363. };
  114364. static long _vq_quantmap__44c2_s_p2_0[] = {
  114365. 3, 1, 0, 2, 4,
  114366. };
  114367. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114368. _vq_quantthresh__44c2_s_p2_0,
  114369. _vq_quantmap__44c2_s_p2_0,
  114370. 5,
  114371. 5
  114372. };
  114373. static static_codebook _44c2_s_p2_0 = {
  114374. 4, 625,
  114375. _vq_lengthlist__44c2_s_p2_0,
  114376. 1, -533725184, 1611661312, 3, 0,
  114377. _vq_quantlist__44c2_s_p2_0,
  114378. NULL,
  114379. &_vq_auxt__44c2_s_p2_0,
  114380. NULL,
  114381. 0
  114382. };
  114383. static long _vq_quantlist__44c2_s_p3_0[] = {
  114384. 2,
  114385. 1,
  114386. 3,
  114387. 0,
  114388. 4,
  114389. };
  114390. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114391. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114394. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114397. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114430. 0,
  114431. };
  114432. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114433. -1.5, -0.5, 0.5, 1.5,
  114434. };
  114435. static long _vq_quantmap__44c2_s_p3_0[] = {
  114436. 3, 1, 0, 2, 4,
  114437. };
  114438. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114439. _vq_quantthresh__44c2_s_p3_0,
  114440. _vq_quantmap__44c2_s_p3_0,
  114441. 5,
  114442. 5
  114443. };
  114444. static static_codebook _44c2_s_p3_0 = {
  114445. 4, 625,
  114446. _vq_lengthlist__44c2_s_p3_0,
  114447. 1, -533725184, 1611661312, 3, 0,
  114448. _vq_quantlist__44c2_s_p3_0,
  114449. NULL,
  114450. &_vq_auxt__44c2_s_p3_0,
  114451. NULL,
  114452. 0
  114453. };
  114454. static long _vq_quantlist__44c2_s_p4_0[] = {
  114455. 4,
  114456. 3,
  114457. 5,
  114458. 2,
  114459. 6,
  114460. 1,
  114461. 7,
  114462. 0,
  114463. 8,
  114464. };
  114465. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114466. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114467. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114468. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114469. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114470. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114471. 0,
  114472. };
  114473. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114474. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114475. };
  114476. static long _vq_quantmap__44c2_s_p4_0[] = {
  114477. 7, 5, 3, 1, 0, 2, 4, 6,
  114478. 8,
  114479. };
  114480. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114481. _vq_quantthresh__44c2_s_p4_0,
  114482. _vq_quantmap__44c2_s_p4_0,
  114483. 9,
  114484. 9
  114485. };
  114486. static static_codebook _44c2_s_p4_0 = {
  114487. 2, 81,
  114488. _vq_lengthlist__44c2_s_p4_0,
  114489. 1, -531628032, 1611661312, 4, 0,
  114490. _vq_quantlist__44c2_s_p4_0,
  114491. NULL,
  114492. &_vq_auxt__44c2_s_p4_0,
  114493. NULL,
  114494. 0
  114495. };
  114496. static long _vq_quantlist__44c2_s_p5_0[] = {
  114497. 4,
  114498. 3,
  114499. 5,
  114500. 2,
  114501. 6,
  114502. 1,
  114503. 7,
  114504. 0,
  114505. 8,
  114506. };
  114507. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114508. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114509. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114510. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114511. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114512. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114513. 11,
  114514. };
  114515. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114516. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114517. };
  114518. static long _vq_quantmap__44c2_s_p5_0[] = {
  114519. 7, 5, 3, 1, 0, 2, 4, 6,
  114520. 8,
  114521. };
  114522. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114523. _vq_quantthresh__44c2_s_p5_0,
  114524. _vq_quantmap__44c2_s_p5_0,
  114525. 9,
  114526. 9
  114527. };
  114528. static static_codebook _44c2_s_p5_0 = {
  114529. 2, 81,
  114530. _vq_lengthlist__44c2_s_p5_0,
  114531. 1, -531628032, 1611661312, 4, 0,
  114532. _vq_quantlist__44c2_s_p5_0,
  114533. NULL,
  114534. &_vq_auxt__44c2_s_p5_0,
  114535. NULL,
  114536. 0
  114537. };
  114538. static long _vq_quantlist__44c2_s_p6_0[] = {
  114539. 8,
  114540. 7,
  114541. 9,
  114542. 6,
  114543. 10,
  114544. 5,
  114545. 11,
  114546. 4,
  114547. 12,
  114548. 3,
  114549. 13,
  114550. 2,
  114551. 14,
  114552. 1,
  114553. 15,
  114554. 0,
  114555. 16,
  114556. };
  114557. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114558. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114559. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114560. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114561. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114562. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114563. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114564. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114565. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114566. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114567. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114568. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114569. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114570. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114571. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114572. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114573. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114574. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114575. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114576. 14,
  114577. };
  114578. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114579. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114580. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114581. };
  114582. static long _vq_quantmap__44c2_s_p6_0[] = {
  114583. 15, 13, 11, 9, 7, 5, 3, 1,
  114584. 0, 2, 4, 6, 8, 10, 12, 14,
  114585. 16,
  114586. };
  114587. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114588. _vq_quantthresh__44c2_s_p6_0,
  114589. _vq_quantmap__44c2_s_p6_0,
  114590. 17,
  114591. 17
  114592. };
  114593. static static_codebook _44c2_s_p6_0 = {
  114594. 2, 289,
  114595. _vq_lengthlist__44c2_s_p6_0,
  114596. 1, -529530880, 1611661312, 5, 0,
  114597. _vq_quantlist__44c2_s_p6_0,
  114598. NULL,
  114599. &_vq_auxt__44c2_s_p6_0,
  114600. NULL,
  114601. 0
  114602. };
  114603. static long _vq_quantlist__44c2_s_p7_0[] = {
  114604. 1,
  114605. 0,
  114606. 2,
  114607. };
  114608. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114609. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114610. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114611. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114612. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114613. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114614. 11,
  114615. };
  114616. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114617. -5.5, 5.5,
  114618. };
  114619. static long _vq_quantmap__44c2_s_p7_0[] = {
  114620. 1, 0, 2,
  114621. };
  114622. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114623. _vq_quantthresh__44c2_s_p7_0,
  114624. _vq_quantmap__44c2_s_p7_0,
  114625. 3,
  114626. 3
  114627. };
  114628. static static_codebook _44c2_s_p7_0 = {
  114629. 4, 81,
  114630. _vq_lengthlist__44c2_s_p7_0,
  114631. 1, -529137664, 1618345984, 2, 0,
  114632. _vq_quantlist__44c2_s_p7_0,
  114633. NULL,
  114634. &_vq_auxt__44c2_s_p7_0,
  114635. NULL,
  114636. 0
  114637. };
  114638. static long _vq_quantlist__44c2_s_p7_1[] = {
  114639. 5,
  114640. 4,
  114641. 6,
  114642. 3,
  114643. 7,
  114644. 2,
  114645. 8,
  114646. 1,
  114647. 9,
  114648. 0,
  114649. 10,
  114650. };
  114651. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114652. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114653. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114654. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114655. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114656. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114657. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114658. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114659. 10,10,10, 8, 8, 8, 8, 8, 8,
  114660. };
  114661. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114662. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114663. 3.5, 4.5,
  114664. };
  114665. static long _vq_quantmap__44c2_s_p7_1[] = {
  114666. 9, 7, 5, 3, 1, 0, 2, 4,
  114667. 6, 8, 10,
  114668. };
  114669. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114670. _vq_quantthresh__44c2_s_p7_1,
  114671. _vq_quantmap__44c2_s_p7_1,
  114672. 11,
  114673. 11
  114674. };
  114675. static static_codebook _44c2_s_p7_1 = {
  114676. 2, 121,
  114677. _vq_lengthlist__44c2_s_p7_1,
  114678. 1, -531365888, 1611661312, 4, 0,
  114679. _vq_quantlist__44c2_s_p7_1,
  114680. NULL,
  114681. &_vq_auxt__44c2_s_p7_1,
  114682. NULL,
  114683. 0
  114684. };
  114685. static long _vq_quantlist__44c2_s_p8_0[] = {
  114686. 6,
  114687. 5,
  114688. 7,
  114689. 4,
  114690. 8,
  114691. 3,
  114692. 9,
  114693. 2,
  114694. 10,
  114695. 1,
  114696. 11,
  114697. 0,
  114698. 12,
  114699. };
  114700. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114701. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114702. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114703. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114704. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114705. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114706. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114707. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114708. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114709. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114710. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114711. 0,12,12,12,12,13,12,14,14,
  114712. };
  114713. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114714. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114715. 12.5, 17.5, 22.5, 27.5,
  114716. };
  114717. static long _vq_quantmap__44c2_s_p8_0[] = {
  114718. 11, 9, 7, 5, 3, 1, 0, 2,
  114719. 4, 6, 8, 10, 12,
  114720. };
  114721. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114722. _vq_quantthresh__44c2_s_p8_0,
  114723. _vq_quantmap__44c2_s_p8_0,
  114724. 13,
  114725. 13
  114726. };
  114727. static static_codebook _44c2_s_p8_0 = {
  114728. 2, 169,
  114729. _vq_lengthlist__44c2_s_p8_0,
  114730. 1, -526516224, 1616117760, 4, 0,
  114731. _vq_quantlist__44c2_s_p8_0,
  114732. NULL,
  114733. &_vq_auxt__44c2_s_p8_0,
  114734. NULL,
  114735. 0
  114736. };
  114737. static long _vq_quantlist__44c2_s_p8_1[] = {
  114738. 2,
  114739. 1,
  114740. 3,
  114741. 0,
  114742. 4,
  114743. };
  114744. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114745. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114746. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114747. };
  114748. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114749. -1.5, -0.5, 0.5, 1.5,
  114750. };
  114751. static long _vq_quantmap__44c2_s_p8_1[] = {
  114752. 3, 1, 0, 2, 4,
  114753. };
  114754. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114755. _vq_quantthresh__44c2_s_p8_1,
  114756. _vq_quantmap__44c2_s_p8_1,
  114757. 5,
  114758. 5
  114759. };
  114760. static static_codebook _44c2_s_p8_1 = {
  114761. 2, 25,
  114762. _vq_lengthlist__44c2_s_p8_1,
  114763. 1, -533725184, 1611661312, 3, 0,
  114764. _vq_quantlist__44c2_s_p8_1,
  114765. NULL,
  114766. &_vq_auxt__44c2_s_p8_1,
  114767. NULL,
  114768. 0
  114769. };
  114770. static long _vq_quantlist__44c2_s_p9_0[] = {
  114771. 6,
  114772. 5,
  114773. 7,
  114774. 4,
  114775. 8,
  114776. 3,
  114777. 9,
  114778. 2,
  114779. 10,
  114780. 1,
  114781. 11,
  114782. 0,
  114783. 12,
  114784. };
  114785. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114786. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114787. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114788. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114789. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114790. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114791. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114792. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114793. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114794. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114795. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114796. 11,11,11,11,11,11,11,11,11,
  114797. };
  114798. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114799. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114800. 552.5, 773.5, 994.5, 1215.5,
  114801. };
  114802. static long _vq_quantmap__44c2_s_p9_0[] = {
  114803. 11, 9, 7, 5, 3, 1, 0, 2,
  114804. 4, 6, 8, 10, 12,
  114805. };
  114806. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114807. _vq_quantthresh__44c2_s_p9_0,
  114808. _vq_quantmap__44c2_s_p9_0,
  114809. 13,
  114810. 13
  114811. };
  114812. static static_codebook _44c2_s_p9_0 = {
  114813. 2, 169,
  114814. _vq_lengthlist__44c2_s_p9_0,
  114815. 1, -514541568, 1627103232, 4, 0,
  114816. _vq_quantlist__44c2_s_p9_0,
  114817. NULL,
  114818. &_vq_auxt__44c2_s_p9_0,
  114819. NULL,
  114820. 0
  114821. };
  114822. static long _vq_quantlist__44c2_s_p9_1[] = {
  114823. 6,
  114824. 5,
  114825. 7,
  114826. 4,
  114827. 8,
  114828. 3,
  114829. 9,
  114830. 2,
  114831. 10,
  114832. 1,
  114833. 11,
  114834. 0,
  114835. 12,
  114836. };
  114837. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114838. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114839. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114840. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114841. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114842. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114843. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114844. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114845. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114846. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114847. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114848. 17,13,12,12,10,13,11,14,14,
  114849. };
  114850. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114851. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114852. 42.5, 59.5, 76.5, 93.5,
  114853. };
  114854. static long _vq_quantmap__44c2_s_p9_1[] = {
  114855. 11, 9, 7, 5, 3, 1, 0, 2,
  114856. 4, 6, 8, 10, 12,
  114857. };
  114858. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114859. _vq_quantthresh__44c2_s_p9_1,
  114860. _vq_quantmap__44c2_s_p9_1,
  114861. 13,
  114862. 13
  114863. };
  114864. static static_codebook _44c2_s_p9_1 = {
  114865. 2, 169,
  114866. _vq_lengthlist__44c2_s_p9_1,
  114867. 1, -522616832, 1620115456, 4, 0,
  114868. _vq_quantlist__44c2_s_p9_1,
  114869. NULL,
  114870. &_vq_auxt__44c2_s_p9_1,
  114871. NULL,
  114872. 0
  114873. };
  114874. static long _vq_quantlist__44c2_s_p9_2[] = {
  114875. 8,
  114876. 7,
  114877. 9,
  114878. 6,
  114879. 10,
  114880. 5,
  114881. 11,
  114882. 4,
  114883. 12,
  114884. 3,
  114885. 13,
  114886. 2,
  114887. 14,
  114888. 1,
  114889. 15,
  114890. 0,
  114891. 16,
  114892. };
  114893. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114894. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114895. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114896. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114897. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114898. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114899. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114900. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114901. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114902. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114903. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114904. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114905. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114906. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114907. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114908. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114909. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114910. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114911. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114912. 10,
  114913. };
  114914. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114915. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114916. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114917. };
  114918. static long _vq_quantmap__44c2_s_p9_2[] = {
  114919. 15, 13, 11, 9, 7, 5, 3, 1,
  114920. 0, 2, 4, 6, 8, 10, 12, 14,
  114921. 16,
  114922. };
  114923. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114924. _vq_quantthresh__44c2_s_p9_2,
  114925. _vq_quantmap__44c2_s_p9_2,
  114926. 17,
  114927. 17
  114928. };
  114929. static static_codebook _44c2_s_p9_2 = {
  114930. 2, 289,
  114931. _vq_lengthlist__44c2_s_p9_2,
  114932. 1, -529530880, 1611661312, 5, 0,
  114933. _vq_quantlist__44c2_s_p9_2,
  114934. NULL,
  114935. &_vq_auxt__44c2_s_p9_2,
  114936. NULL,
  114937. 0
  114938. };
  114939. static long _huff_lengthlist__44c2_s_short[] = {
  114940. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114941. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114942. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114943. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114944. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114945. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114946. 6, 8, 9,12,
  114947. };
  114948. static static_codebook _huff_book__44c2_s_short = {
  114949. 2, 100,
  114950. _huff_lengthlist__44c2_s_short,
  114951. 0, 0, 0, 0, 0,
  114952. NULL,
  114953. NULL,
  114954. NULL,
  114955. NULL,
  114956. 0
  114957. };
  114958. static long _huff_lengthlist__44c3_s_long[] = {
  114959. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114960. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114961. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114962. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114963. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114964. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114965. 9, 8, 8, 8,
  114966. };
  114967. static static_codebook _huff_book__44c3_s_long = {
  114968. 2, 100,
  114969. _huff_lengthlist__44c3_s_long,
  114970. 0, 0, 0, 0, 0,
  114971. NULL,
  114972. NULL,
  114973. NULL,
  114974. NULL,
  114975. 0
  114976. };
  114977. static long _vq_quantlist__44c3_s_p1_0[] = {
  114978. 1,
  114979. 0,
  114980. 2,
  114981. };
  114982. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114983. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114984. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114988. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114989. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114993. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114994. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115025. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115029. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115034. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  115039. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115074. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115075. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115079. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115080. 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  115081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115084. 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115085. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  115086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115393. 0,
  115394. };
  115395. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115396. -0.5, 0.5,
  115397. };
  115398. static long _vq_quantmap__44c3_s_p1_0[] = {
  115399. 1, 0, 2,
  115400. };
  115401. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115402. _vq_quantthresh__44c3_s_p1_0,
  115403. _vq_quantmap__44c3_s_p1_0,
  115404. 3,
  115405. 3
  115406. };
  115407. static static_codebook _44c3_s_p1_0 = {
  115408. 8, 6561,
  115409. _vq_lengthlist__44c3_s_p1_0,
  115410. 1, -535822336, 1611661312, 2, 0,
  115411. _vq_quantlist__44c3_s_p1_0,
  115412. NULL,
  115413. &_vq_auxt__44c3_s_p1_0,
  115414. NULL,
  115415. 0
  115416. };
  115417. static long _vq_quantlist__44c3_s_p2_0[] = {
  115418. 2,
  115419. 1,
  115420. 3,
  115421. 0,
  115422. 4,
  115423. };
  115424. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115425. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115426. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115427. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115428. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115429. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115434. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115435. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115436. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115437. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115442. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115443. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115444. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115450. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115451. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115452. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115464. 0,
  115465. };
  115466. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115467. -1.5, -0.5, 0.5, 1.5,
  115468. };
  115469. static long _vq_quantmap__44c3_s_p2_0[] = {
  115470. 3, 1, 0, 2, 4,
  115471. };
  115472. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115473. _vq_quantthresh__44c3_s_p2_0,
  115474. _vq_quantmap__44c3_s_p2_0,
  115475. 5,
  115476. 5
  115477. };
  115478. static static_codebook _44c3_s_p2_0 = {
  115479. 4, 625,
  115480. _vq_lengthlist__44c3_s_p2_0,
  115481. 1, -533725184, 1611661312, 3, 0,
  115482. _vq_quantlist__44c3_s_p2_0,
  115483. NULL,
  115484. &_vq_auxt__44c3_s_p2_0,
  115485. NULL,
  115486. 0
  115487. };
  115488. static long _vq_quantlist__44c3_s_p3_0[] = {
  115489. 2,
  115490. 1,
  115491. 3,
  115492. 0,
  115493. 4,
  115494. };
  115495. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115496. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115499. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115502. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115535. 0,
  115536. };
  115537. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115538. -1.5, -0.5, 0.5, 1.5,
  115539. };
  115540. static long _vq_quantmap__44c3_s_p3_0[] = {
  115541. 3, 1, 0, 2, 4,
  115542. };
  115543. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115544. _vq_quantthresh__44c3_s_p3_0,
  115545. _vq_quantmap__44c3_s_p3_0,
  115546. 5,
  115547. 5
  115548. };
  115549. static static_codebook _44c3_s_p3_0 = {
  115550. 4, 625,
  115551. _vq_lengthlist__44c3_s_p3_0,
  115552. 1, -533725184, 1611661312, 3, 0,
  115553. _vq_quantlist__44c3_s_p3_0,
  115554. NULL,
  115555. &_vq_auxt__44c3_s_p3_0,
  115556. NULL,
  115557. 0
  115558. };
  115559. static long _vq_quantlist__44c3_s_p4_0[] = {
  115560. 4,
  115561. 3,
  115562. 5,
  115563. 2,
  115564. 6,
  115565. 1,
  115566. 7,
  115567. 0,
  115568. 8,
  115569. };
  115570. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115571. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115572. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115573. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115574. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115575. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115576. 0,
  115577. };
  115578. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115579. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115580. };
  115581. static long _vq_quantmap__44c3_s_p4_0[] = {
  115582. 7, 5, 3, 1, 0, 2, 4, 6,
  115583. 8,
  115584. };
  115585. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115586. _vq_quantthresh__44c3_s_p4_0,
  115587. _vq_quantmap__44c3_s_p4_0,
  115588. 9,
  115589. 9
  115590. };
  115591. static static_codebook _44c3_s_p4_0 = {
  115592. 2, 81,
  115593. _vq_lengthlist__44c3_s_p4_0,
  115594. 1, -531628032, 1611661312, 4, 0,
  115595. _vq_quantlist__44c3_s_p4_0,
  115596. NULL,
  115597. &_vq_auxt__44c3_s_p4_0,
  115598. NULL,
  115599. 0
  115600. };
  115601. static long _vq_quantlist__44c3_s_p5_0[] = {
  115602. 4,
  115603. 3,
  115604. 5,
  115605. 2,
  115606. 6,
  115607. 1,
  115608. 7,
  115609. 0,
  115610. 8,
  115611. };
  115612. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115613. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115614. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115615. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115616. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115617. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115618. 11,
  115619. };
  115620. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115621. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115622. };
  115623. static long _vq_quantmap__44c3_s_p5_0[] = {
  115624. 7, 5, 3, 1, 0, 2, 4, 6,
  115625. 8,
  115626. };
  115627. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115628. _vq_quantthresh__44c3_s_p5_0,
  115629. _vq_quantmap__44c3_s_p5_0,
  115630. 9,
  115631. 9
  115632. };
  115633. static static_codebook _44c3_s_p5_0 = {
  115634. 2, 81,
  115635. _vq_lengthlist__44c3_s_p5_0,
  115636. 1, -531628032, 1611661312, 4, 0,
  115637. _vq_quantlist__44c3_s_p5_0,
  115638. NULL,
  115639. &_vq_auxt__44c3_s_p5_0,
  115640. NULL,
  115641. 0
  115642. };
  115643. static long _vq_quantlist__44c3_s_p6_0[] = {
  115644. 8,
  115645. 7,
  115646. 9,
  115647. 6,
  115648. 10,
  115649. 5,
  115650. 11,
  115651. 4,
  115652. 12,
  115653. 3,
  115654. 13,
  115655. 2,
  115656. 14,
  115657. 1,
  115658. 15,
  115659. 0,
  115660. 16,
  115661. };
  115662. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115663. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115664. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115665. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115666. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115667. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115668. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115669. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115670. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115671. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115672. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115673. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115674. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115675. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115676. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115677. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115678. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115679. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115680. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115681. 13,
  115682. };
  115683. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115684. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115685. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115686. };
  115687. static long _vq_quantmap__44c3_s_p6_0[] = {
  115688. 15, 13, 11, 9, 7, 5, 3, 1,
  115689. 0, 2, 4, 6, 8, 10, 12, 14,
  115690. 16,
  115691. };
  115692. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115693. _vq_quantthresh__44c3_s_p6_0,
  115694. _vq_quantmap__44c3_s_p6_0,
  115695. 17,
  115696. 17
  115697. };
  115698. static static_codebook _44c3_s_p6_0 = {
  115699. 2, 289,
  115700. _vq_lengthlist__44c3_s_p6_0,
  115701. 1, -529530880, 1611661312, 5, 0,
  115702. _vq_quantlist__44c3_s_p6_0,
  115703. NULL,
  115704. &_vq_auxt__44c3_s_p6_0,
  115705. NULL,
  115706. 0
  115707. };
  115708. static long _vq_quantlist__44c3_s_p7_0[] = {
  115709. 1,
  115710. 0,
  115711. 2,
  115712. };
  115713. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115714. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115715. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115716. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115717. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115718. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115719. 10,
  115720. };
  115721. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115722. -5.5, 5.5,
  115723. };
  115724. static long _vq_quantmap__44c3_s_p7_0[] = {
  115725. 1, 0, 2,
  115726. };
  115727. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115728. _vq_quantthresh__44c3_s_p7_0,
  115729. _vq_quantmap__44c3_s_p7_0,
  115730. 3,
  115731. 3
  115732. };
  115733. static static_codebook _44c3_s_p7_0 = {
  115734. 4, 81,
  115735. _vq_lengthlist__44c3_s_p7_0,
  115736. 1, -529137664, 1618345984, 2, 0,
  115737. _vq_quantlist__44c3_s_p7_0,
  115738. NULL,
  115739. &_vq_auxt__44c3_s_p7_0,
  115740. NULL,
  115741. 0
  115742. };
  115743. static long _vq_quantlist__44c3_s_p7_1[] = {
  115744. 5,
  115745. 4,
  115746. 6,
  115747. 3,
  115748. 7,
  115749. 2,
  115750. 8,
  115751. 1,
  115752. 9,
  115753. 0,
  115754. 10,
  115755. };
  115756. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115757. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115758. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115759. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115760. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115761. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115762. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115763. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115764. 10,10,10, 8, 8, 8, 8, 8, 8,
  115765. };
  115766. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115767. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115768. 3.5, 4.5,
  115769. };
  115770. static long _vq_quantmap__44c3_s_p7_1[] = {
  115771. 9, 7, 5, 3, 1, 0, 2, 4,
  115772. 6, 8, 10,
  115773. };
  115774. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115775. _vq_quantthresh__44c3_s_p7_1,
  115776. _vq_quantmap__44c3_s_p7_1,
  115777. 11,
  115778. 11
  115779. };
  115780. static static_codebook _44c3_s_p7_1 = {
  115781. 2, 121,
  115782. _vq_lengthlist__44c3_s_p7_1,
  115783. 1, -531365888, 1611661312, 4, 0,
  115784. _vq_quantlist__44c3_s_p7_1,
  115785. NULL,
  115786. &_vq_auxt__44c3_s_p7_1,
  115787. NULL,
  115788. 0
  115789. };
  115790. static long _vq_quantlist__44c3_s_p8_0[] = {
  115791. 6,
  115792. 5,
  115793. 7,
  115794. 4,
  115795. 8,
  115796. 3,
  115797. 9,
  115798. 2,
  115799. 10,
  115800. 1,
  115801. 11,
  115802. 0,
  115803. 12,
  115804. };
  115805. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115806. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115807. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115808. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115809. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115810. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115811. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115812. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115813. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115814. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115815. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115816. 0,13,13,12,12,13,12,14,13,
  115817. };
  115818. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115819. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115820. 12.5, 17.5, 22.5, 27.5,
  115821. };
  115822. static long _vq_quantmap__44c3_s_p8_0[] = {
  115823. 11, 9, 7, 5, 3, 1, 0, 2,
  115824. 4, 6, 8, 10, 12,
  115825. };
  115826. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115827. _vq_quantthresh__44c3_s_p8_0,
  115828. _vq_quantmap__44c3_s_p8_0,
  115829. 13,
  115830. 13
  115831. };
  115832. static static_codebook _44c3_s_p8_0 = {
  115833. 2, 169,
  115834. _vq_lengthlist__44c3_s_p8_0,
  115835. 1, -526516224, 1616117760, 4, 0,
  115836. _vq_quantlist__44c3_s_p8_0,
  115837. NULL,
  115838. &_vq_auxt__44c3_s_p8_0,
  115839. NULL,
  115840. 0
  115841. };
  115842. static long _vq_quantlist__44c3_s_p8_1[] = {
  115843. 2,
  115844. 1,
  115845. 3,
  115846. 0,
  115847. 4,
  115848. };
  115849. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115850. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115851. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115852. };
  115853. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115854. -1.5, -0.5, 0.5, 1.5,
  115855. };
  115856. static long _vq_quantmap__44c3_s_p8_1[] = {
  115857. 3, 1, 0, 2, 4,
  115858. };
  115859. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115860. _vq_quantthresh__44c3_s_p8_1,
  115861. _vq_quantmap__44c3_s_p8_1,
  115862. 5,
  115863. 5
  115864. };
  115865. static static_codebook _44c3_s_p8_1 = {
  115866. 2, 25,
  115867. _vq_lengthlist__44c3_s_p8_1,
  115868. 1, -533725184, 1611661312, 3, 0,
  115869. _vq_quantlist__44c3_s_p8_1,
  115870. NULL,
  115871. &_vq_auxt__44c3_s_p8_1,
  115872. NULL,
  115873. 0
  115874. };
  115875. static long _vq_quantlist__44c3_s_p9_0[] = {
  115876. 6,
  115877. 5,
  115878. 7,
  115879. 4,
  115880. 8,
  115881. 3,
  115882. 9,
  115883. 2,
  115884. 10,
  115885. 1,
  115886. 11,
  115887. 0,
  115888. 12,
  115889. };
  115890. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115891. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115892. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115893. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115894. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115895. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115896. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115897. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115898. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115899. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115900. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115901. 11,11,11,11,11,11,11,11,11,
  115902. };
  115903. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115904. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115905. 637.5, 892.5, 1147.5, 1402.5,
  115906. };
  115907. static long _vq_quantmap__44c3_s_p9_0[] = {
  115908. 11, 9, 7, 5, 3, 1, 0, 2,
  115909. 4, 6, 8, 10, 12,
  115910. };
  115911. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115912. _vq_quantthresh__44c3_s_p9_0,
  115913. _vq_quantmap__44c3_s_p9_0,
  115914. 13,
  115915. 13
  115916. };
  115917. static static_codebook _44c3_s_p9_0 = {
  115918. 2, 169,
  115919. _vq_lengthlist__44c3_s_p9_0,
  115920. 1, -514332672, 1627381760, 4, 0,
  115921. _vq_quantlist__44c3_s_p9_0,
  115922. NULL,
  115923. &_vq_auxt__44c3_s_p9_0,
  115924. NULL,
  115925. 0
  115926. };
  115927. static long _vq_quantlist__44c3_s_p9_1[] = {
  115928. 7,
  115929. 6,
  115930. 8,
  115931. 5,
  115932. 9,
  115933. 4,
  115934. 10,
  115935. 3,
  115936. 11,
  115937. 2,
  115938. 12,
  115939. 1,
  115940. 13,
  115941. 0,
  115942. 14,
  115943. };
  115944. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115945. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115946. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115947. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115948. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115949. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115950. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115951. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115952. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115953. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115954. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115955. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115956. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115957. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115958. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115959. 15,
  115960. };
  115961. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115962. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115963. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115964. };
  115965. static long _vq_quantmap__44c3_s_p9_1[] = {
  115966. 13, 11, 9, 7, 5, 3, 1, 0,
  115967. 2, 4, 6, 8, 10, 12, 14,
  115968. };
  115969. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115970. _vq_quantthresh__44c3_s_p9_1,
  115971. _vq_quantmap__44c3_s_p9_1,
  115972. 15,
  115973. 15
  115974. };
  115975. static static_codebook _44c3_s_p9_1 = {
  115976. 2, 225,
  115977. _vq_lengthlist__44c3_s_p9_1,
  115978. 1, -522338304, 1620115456, 4, 0,
  115979. _vq_quantlist__44c3_s_p9_1,
  115980. NULL,
  115981. &_vq_auxt__44c3_s_p9_1,
  115982. NULL,
  115983. 0
  115984. };
  115985. static long _vq_quantlist__44c3_s_p9_2[] = {
  115986. 8,
  115987. 7,
  115988. 9,
  115989. 6,
  115990. 10,
  115991. 5,
  115992. 11,
  115993. 4,
  115994. 12,
  115995. 3,
  115996. 13,
  115997. 2,
  115998. 14,
  115999. 1,
  116000. 15,
  116001. 0,
  116002. 16,
  116003. };
  116004. static long _vq_lengthlist__44c3_s_p9_2[] = {
  116005. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  116006. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  116007. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  116008. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  116009. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  116010. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  116011. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  116012. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  116013. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  116014. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  116015. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  116016. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  116017. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  116018. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  116019. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  116020. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  116021. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  116022. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  116023. 10,
  116024. };
  116025. static float _vq_quantthresh__44c3_s_p9_2[] = {
  116026. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116027. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116028. };
  116029. static long _vq_quantmap__44c3_s_p9_2[] = {
  116030. 15, 13, 11, 9, 7, 5, 3, 1,
  116031. 0, 2, 4, 6, 8, 10, 12, 14,
  116032. 16,
  116033. };
  116034. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  116035. _vq_quantthresh__44c3_s_p9_2,
  116036. _vq_quantmap__44c3_s_p9_2,
  116037. 17,
  116038. 17
  116039. };
  116040. static static_codebook _44c3_s_p9_2 = {
  116041. 2, 289,
  116042. _vq_lengthlist__44c3_s_p9_2,
  116043. 1, -529530880, 1611661312, 5, 0,
  116044. _vq_quantlist__44c3_s_p9_2,
  116045. NULL,
  116046. &_vq_auxt__44c3_s_p9_2,
  116047. NULL,
  116048. 0
  116049. };
  116050. static long _huff_lengthlist__44c3_s_short[] = {
  116051. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  116052. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  116053. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  116054. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  116055. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  116056. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  116057. 6, 8, 9,11,
  116058. };
  116059. static static_codebook _huff_book__44c3_s_short = {
  116060. 2, 100,
  116061. _huff_lengthlist__44c3_s_short,
  116062. 0, 0, 0, 0, 0,
  116063. NULL,
  116064. NULL,
  116065. NULL,
  116066. NULL,
  116067. 0
  116068. };
  116069. static long _huff_lengthlist__44c4_s_long[] = {
  116070. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  116071. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  116072. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  116073. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  116074. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  116075. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  116076. 9, 8, 7, 7,
  116077. };
  116078. static static_codebook _huff_book__44c4_s_long = {
  116079. 2, 100,
  116080. _huff_lengthlist__44c4_s_long,
  116081. 0, 0, 0, 0, 0,
  116082. NULL,
  116083. NULL,
  116084. NULL,
  116085. NULL,
  116086. 0
  116087. };
  116088. static long _vq_quantlist__44c4_s_p1_0[] = {
  116089. 1,
  116090. 0,
  116091. 2,
  116092. };
  116093. static long _vq_lengthlist__44c4_s_p1_0[] = {
  116094. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  116095. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116099. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116100. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116104. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  116105. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116136. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  116140. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116145. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  116150. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116185. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116186. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116190. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116191. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  116192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116195. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116196. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116504. 0,
  116505. };
  116506. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116507. -0.5, 0.5,
  116508. };
  116509. static long _vq_quantmap__44c4_s_p1_0[] = {
  116510. 1, 0, 2,
  116511. };
  116512. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116513. _vq_quantthresh__44c4_s_p1_0,
  116514. _vq_quantmap__44c4_s_p1_0,
  116515. 3,
  116516. 3
  116517. };
  116518. static static_codebook _44c4_s_p1_0 = {
  116519. 8, 6561,
  116520. _vq_lengthlist__44c4_s_p1_0,
  116521. 1, -535822336, 1611661312, 2, 0,
  116522. _vq_quantlist__44c4_s_p1_0,
  116523. NULL,
  116524. &_vq_auxt__44c4_s_p1_0,
  116525. NULL,
  116526. 0
  116527. };
  116528. static long _vq_quantlist__44c4_s_p2_0[] = {
  116529. 2,
  116530. 1,
  116531. 3,
  116532. 0,
  116533. 4,
  116534. };
  116535. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116536. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116537. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116538. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116539. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116540. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116545. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116546. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116547. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116548. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116553. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116554. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116555. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116561. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116562. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116563. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116575. 0,
  116576. };
  116577. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116578. -1.5, -0.5, 0.5, 1.5,
  116579. };
  116580. static long _vq_quantmap__44c4_s_p2_0[] = {
  116581. 3, 1, 0, 2, 4,
  116582. };
  116583. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116584. _vq_quantthresh__44c4_s_p2_0,
  116585. _vq_quantmap__44c4_s_p2_0,
  116586. 5,
  116587. 5
  116588. };
  116589. static static_codebook _44c4_s_p2_0 = {
  116590. 4, 625,
  116591. _vq_lengthlist__44c4_s_p2_0,
  116592. 1, -533725184, 1611661312, 3, 0,
  116593. _vq_quantlist__44c4_s_p2_0,
  116594. NULL,
  116595. &_vq_auxt__44c4_s_p2_0,
  116596. NULL,
  116597. 0
  116598. };
  116599. static long _vq_quantlist__44c4_s_p3_0[] = {
  116600. 2,
  116601. 1,
  116602. 3,
  116603. 0,
  116604. 4,
  116605. };
  116606. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116607. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116610. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116613. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116646. 0,
  116647. };
  116648. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116649. -1.5, -0.5, 0.5, 1.5,
  116650. };
  116651. static long _vq_quantmap__44c4_s_p3_0[] = {
  116652. 3, 1, 0, 2, 4,
  116653. };
  116654. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116655. _vq_quantthresh__44c4_s_p3_0,
  116656. _vq_quantmap__44c4_s_p3_0,
  116657. 5,
  116658. 5
  116659. };
  116660. static static_codebook _44c4_s_p3_0 = {
  116661. 4, 625,
  116662. _vq_lengthlist__44c4_s_p3_0,
  116663. 1, -533725184, 1611661312, 3, 0,
  116664. _vq_quantlist__44c4_s_p3_0,
  116665. NULL,
  116666. &_vq_auxt__44c4_s_p3_0,
  116667. NULL,
  116668. 0
  116669. };
  116670. static long _vq_quantlist__44c4_s_p4_0[] = {
  116671. 4,
  116672. 3,
  116673. 5,
  116674. 2,
  116675. 6,
  116676. 1,
  116677. 7,
  116678. 0,
  116679. 8,
  116680. };
  116681. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116682. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116683. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116684. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116685. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116686. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116687. 0,
  116688. };
  116689. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116690. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116691. };
  116692. static long _vq_quantmap__44c4_s_p4_0[] = {
  116693. 7, 5, 3, 1, 0, 2, 4, 6,
  116694. 8,
  116695. };
  116696. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116697. _vq_quantthresh__44c4_s_p4_0,
  116698. _vq_quantmap__44c4_s_p4_0,
  116699. 9,
  116700. 9
  116701. };
  116702. static static_codebook _44c4_s_p4_0 = {
  116703. 2, 81,
  116704. _vq_lengthlist__44c4_s_p4_0,
  116705. 1, -531628032, 1611661312, 4, 0,
  116706. _vq_quantlist__44c4_s_p4_0,
  116707. NULL,
  116708. &_vq_auxt__44c4_s_p4_0,
  116709. NULL,
  116710. 0
  116711. };
  116712. static long _vq_quantlist__44c4_s_p5_0[] = {
  116713. 4,
  116714. 3,
  116715. 5,
  116716. 2,
  116717. 6,
  116718. 1,
  116719. 7,
  116720. 0,
  116721. 8,
  116722. };
  116723. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116724. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116725. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116726. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116727. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116728. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116729. 10,
  116730. };
  116731. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116732. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116733. };
  116734. static long _vq_quantmap__44c4_s_p5_0[] = {
  116735. 7, 5, 3, 1, 0, 2, 4, 6,
  116736. 8,
  116737. };
  116738. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116739. _vq_quantthresh__44c4_s_p5_0,
  116740. _vq_quantmap__44c4_s_p5_0,
  116741. 9,
  116742. 9
  116743. };
  116744. static static_codebook _44c4_s_p5_0 = {
  116745. 2, 81,
  116746. _vq_lengthlist__44c4_s_p5_0,
  116747. 1, -531628032, 1611661312, 4, 0,
  116748. _vq_quantlist__44c4_s_p5_0,
  116749. NULL,
  116750. &_vq_auxt__44c4_s_p5_0,
  116751. NULL,
  116752. 0
  116753. };
  116754. static long _vq_quantlist__44c4_s_p6_0[] = {
  116755. 8,
  116756. 7,
  116757. 9,
  116758. 6,
  116759. 10,
  116760. 5,
  116761. 11,
  116762. 4,
  116763. 12,
  116764. 3,
  116765. 13,
  116766. 2,
  116767. 14,
  116768. 1,
  116769. 15,
  116770. 0,
  116771. 16,
  116772. };
  116773. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116774. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116775. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116776. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116777. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116778. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116779. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116780. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116781. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116782. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116783. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116784. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116785. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116786. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116787. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116788. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116789. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116790. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116791. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116792. 13,
  116793. };
  116794. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116795. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116796. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116797. };
  116798. static long _vq_quantmap__44c4_s_p6_0[] = {
  116799. 15, 13, 11, 9, 7, 5, 3, 1,
  116800. 0, 2, 4, 6, 8, 10, 12, 14,
  116801. 16,
  116802. };
  116803. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116804. _vq_quantthresh__44c4_s_p6_0,
  116805. _vq_quantmap__44c4_s_p6_0,
  116806. 17,
  116807. 17
  116808. };
  116809. static static_codebook _44c4_s_p6_0 = {
  116810. 2, 289,
  116811. _vq_lengthlist__44c4_s_p6_0,
  116812. 1, -529530880, 1611661312, 5, 0,
  116813. _vq_quantlist__44c4_s_p6_0,
  116814. NULL,
  116815. &_vq_auxt__44c4_s_p6_0,
  116816. NULL,
  116817. 0
  116818. };
  116819. static long _vq_quantlist__44c4_s_p7_0[] = {
  116820. 1,
  116821. 0,
  116822. 2,
  116823. };
  116824. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116825. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116826. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116827. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116828. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116829. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116830. 10,
  116831. };
  116832. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116833. -5.5, 5.5,
  116834. };
  116835. static long _vq_quantmap__44c4_s_p7_0[] = {
  116836. 1, 0, 2,
  116837. };
  116838. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116839. _vq_quantthresh__44c4_s_p7_0,
  116840. _vq_quantmap__44c4_s_p7_0,
  116841. 3,
  116842. 3
  116843. };
  116844. static static_codebook _44c4_s_p7_0 = {
  116845. 4, 81,
  116846. _vq_lengthlist__44c4_s_p7_0,
  116847. 1, -529137664, 1618345984, 2, 0,
  116848. _vq_quantlist__44c4_s_p7_0,
  116849. NULL,
  116850. &_vq_auxt__44c4_s_p7_0,
  116851. NULL,
  116852. 0
  116853. };
  116854. static long _vq_quantlist__44c4_s_p7_1[] = {
  116855. 5,
  116856. 4,
  116857. 6,
  116858. 3,
  116859. 7,
  116860. 2,
  116861. 8,
  116862. 1,
  116863. 9,
  116864. 0,
  116865. 10,
  116866. };
  116867. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116868. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116869. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116870. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116871. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116872. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116873. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116874. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116875. 10,10,10, 8, 8, 8, 8, 9, 9,
  116876. };
  116877. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116878. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116879. 3.5, 4.5,
  116880. };
  116881. static long _vq_quantmap__44c4_s_p7_1[] = {
  116882. 9, 7, 5, 3, 1, 0, 2, 4,
  116883. 6, 8, 10,
  116884. };
  116885. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116886. _vq_quantthresh__44c4_s_p7_1,
  116887. _vq_quantmap__44c4_s_p7_1,
  116888. 11,
  116889. 11
  116890. };
  116891. static static_codebook _44c4_s_p7_1 = {
  116892. 2, 121,
  116893. _vq_lengthlist__44c4_s_p7_1,
  116894. 1, -531365888, 1611661312, 4, 0,
  116895. _vq_quantlist__44c4_s_p7_1,
  116896. NULL,
  116897. &_vq_auxt__44c4_s_p7_1,
  116898. NULL,
  116899. 0
  116900. };
  116901. static long _vq_quantlist__44c4_s_p8_0[] = {
  116902. 6,
  116903. 5,
  116904. 7,
  116905. 4,
  116906. 8,
  116907. 3,
  116908. 9,
  116909. 2,
  116910. 10,
  116911. 1,
  116912. 11,
  116913. 0,
  116914. 12,
  116915. };
  116916. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116917. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116918. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116919. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116920. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116921. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116922. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116923. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116924. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116925. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116926. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116927. 0,13,12,12,12,12,12,13,13,
  116928. };
  116929. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116930. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116931. 12.5, 17.5, 22.5, 27.5,
  116932. };
  116933. static long _vq_quantmap__44c4_s_p8_0[] = {
  116934. 11, 9, 7, 5, 3, 1, 0, 2,
  116935. 4, 6, 8, 10, 12,
  116936. };
  116937. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116938. _vq_quantthresh__44c4_s_p8_0,
  116939. _vq_quantmap__44c4_s_p8_0,
  116940. 13,
  116941. 13
  116942. };
  116943. static static_codebook _44c4_s_p8_0 = {
  116944. 2, 169,
  116945. _vq_lengthlist__44c4_s_p8_0,
  116946. 1, -526516224, 1616117760, 4, 0,
  116947. _vq_quantlist__44c4_s_p8_0,
  116948. NULL,
  116949. &_vq_auxt__44c4_s_p8_0,
  116950. NULL,
  116951. 0
  116952. };
  116953. static long _vq_quantlist__44c4_s_p8_1[] = {
  116954. 2,
  116955. 1,
  116956. 3,
  116957. 0,
  116958. 4,
  116959. };
  116960. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116961. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116962. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116963. };
  116964. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116965. -1.5, -0.5, 0.5, 1.5,
  116966. };
  116967. static long _vq_quantmap__44c4_s_p8_1[] = {
  116968. 3, 1, 0, 2, 4,
  116969. };
  116970. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116971. _vq_quantthresh__44c4_s_p8_1,
  116972. _vq_quantmap__44c4_s_p8_1,
  116973. 5,
  116974. 5
  116975. };
  116976. static static_codebook _44c4_s_p8_1 = {
  116977. 2, 25,
  116978. _vq_lengthlist__44c4_s_p8_1,
  116979. 1, -533725184, 1611661312, 3, 0,
  116980. _vq_quantlist__44c4_s_p8_1,
  116981. NULL,
  116982. &_vq_auxt__44c4_s_p8_1,
  116983. NULL,
  116984. 0
  116985. };
  116986. static long _vq_quantlist__44c4_s_p9_0[] = {
  116987. 6,
  116988. 5,
  116989. 7,
  116990. 4,
  116991. 8,
  116992. 3,
  116993. 9,
  116994. 2,
  116995. 10,
  116996. 1,
  116997. 11,
  116998. 0,
  116999. 12,
  117000. };
  117001. static long _vq_lengthlist__44c4_s_p9_0[] = {
  117002. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  117003. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  117004. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117005. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117006. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117007. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117008. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117009. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117010. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117011. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117012. 12,12,12,12,12,12,12,12,12,
  117013. };
  117014. static float _vq_quantthresh__44c4_s_p9_0[] = {
  117015. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  117016. 787.5, 1102.5, 1417.5, 1732.5,
  117017. };
  117018. static long _vq_quantmap__44c4_s_p9_0[] = {
  117019. 11, 9, 7, 5, 3, 1, 0, 2,
  117020. 4, 6, 8, 10, 12,
  117021. };
  117022. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  117023. _vq_quantthresh__44c4_s_p9_0,
  117024. _vq_quantmap__44c4_s_p9_0,
  117025. 13,
  117026. 13
  117027. };
  117028. static static_codebook _44c4_s_p9_0 = {
  117029. 2, 169,
  117030. _vq_lengthlist__44c4_s_p9_0,
  117031. 1, -513964032, 1628680192, 4, 0,
  117032. _vq_quantlist__44c4_s_p9_0,
  117033. NULL,
  117034. &_vq_auxt__44c4_s_p9_0,
  117035. NULL,
  117036. 0
  117037. };
  117038. static long _vq_quantlist__44c4_s_p9_1[] = {
  117039. 7,
  117040. 6,
  117041. 8,
  117042. 5,
  117043. 9,
  117044. 4,
  117045. 10,
  117046. 3,
  117047. 11,
  117048. 2,
  117049. 12,
  117050. 1,
  117051. 13,
  117052. 0,
  117053. 14,
  117054. };
  117055. static long _vq_lengthlist__44c4_s_p9_1[] = {
  117056. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  117057. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  117058. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  117059. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  117060. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  117061. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  117062. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  117063. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  117064. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  117065. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  117066. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  117067. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  117068. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  117069. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  117070. 15,
  117071. };
  117072. static float _vq_quantthresh__44c4_s_p9_1[] = {
  117073. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  117074. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  117075. };
  117076. static long _vq_quantmap__44c4_s_p9_1[] = {
  117077. 13, 11, 9, 7, 5, 3, 1, 0,
  117078. 2, 4, 6, 8, 10, 12, 14,
  117079. };
  117080. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  117081. _vq_quantthresh__44c4_s_p9_1,
  117082. _vq_quantmap__44c4_s_p9_1,
  117083. 15,
  117084. 15
  117085. };
  117086. static static_codebook _44c4_s_p9_1 = {
  117087. 2, 225,
  117088. _vq_lengthlist__44c4_s_p9_1,
  117089. 1, -520986624, 1620377600, 4, 0,
  117090. _vq_quantlist__44c4_s_p9_1,
  117091. NULL,
  117092. &_vq_auxt__44c4_s_p9_1,
  117093. NULL,
  117094. 0
  117095. };
  117096. static long _vq_quantlist__44c4_s_p9_2[] = {
  117097. 10,
  117098. 9,
  117099. 11,
  117100. 8,
  117101. 12,
  117102. 7,
  117103. 13,
  117104. 6,
  117105. 14,
  117106. 5,
  117107. 15,
  117108. 4,
  117109. 16,
  117110. 3,
  117111. 17,
  117112. 2,
  117113. 18,
  117114. 1,
  117115. 19,
  117116. 0,
  117117. 20,
  117118. };
  117119. static long _vq_lengthlist__44c4_s_p9_2[] = {
  117120. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117121. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  117122. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  117123. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  117124. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  117125. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  117126. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  117127. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  117128. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  117129. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  117130. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117131. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  117132. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117133. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  117134. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  117135. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  117136. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  117137. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117138. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  117139. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  117140. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117141. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117142. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  117143. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  117144. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  117145. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  117146. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  117147. 10,10,10,10,10,10,10,10,10,
  117148. };
  117149. static float _vq_quantthresh__44c4_s_p9_2[] = {
  117150. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117151. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117152. 6.5, 7.5, 8.5, 9.5,
  117153. };
  117154. static long _vq_quantmap__44c4_s_p9_2[] = {
  117155. 19, 17, 15, 13, 11, 9, 7, 5,
  117156. 3, 1, 0, 2, 4, 6, 8, 10,
  117157. 12, 14, 16, 18, 20,
  117158. };
  117159. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  117160. _vq_quantthresh__44c4_s_p9_2,
  117161. _vq_quantmap__44c4_s_p9_2,
  117162. 21,
  117163. 21
  117164. };
  117165. static static_codebook _44c4_s_p9_2 = {
  117166. 2, 441,
  117167. _vq_lengthlist__44c4_s_p9_2,
  117168. 1, -529268736, 1611661312, 5, 0,
  117169. _vq_quantlist__44c4_s_p9_2,
  117170. NULL,
  117171. &_vq_auxt__44c4_s_p9_2,
  117172. NULL,
  117173. 0
  117174. };
  117175. static long _huff_lengthlist__44c4_s_short[] = {
  117176. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  117177. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  117178. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  117179. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  117180. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  117181. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  117182. 7, 9,12,17,
  117183. };
  117184. static static_codebook _huff_book__44c4_s_short = {
  117185. 2, 100,
  117186. _huff_lengthlist__44c4_s_short,
  117187. 0, 0, 0, 0, 0,
  117188. NULL,
  117189. NULL,
  117190. NULL,
  117191. NULL,
  117192. 0
  117193. };
  117194. static long _huff_lengthlist__44c5_s_long[] = {
  117195. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  117196. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  117197. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  117198. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  117199. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  117200. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  117201. 9, 8, 7, 7,
  117202. };
  117203. static static_codebook _huff_book__44c5_s_long = {
  117204. 2, 100,
  117205. _huff_lengthlist__44c5_s_long,
  117206. 0, 0, 0, 0, 0,
  117207. NULL,
  117208. NULL,
  117209. NULL,
  117210. NULL,
  117211. 0
  117212. };
  117213. static long _vq_quantlist__44c5_s_p1_0[] = {
  117214. 1,
  117215. 0,
  117216. 2,
  117217. };
  117218. static long _vq_lengthlist__44c5_s_p1_0[] = {
  117219. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117220. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117224. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117225. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117229. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  117230. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117261. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117265. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117270. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  117271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117275. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  117276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117310. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117311. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117315. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117316. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  117317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117320. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117321. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  117322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117629. 0,
  117630. };
  117631. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117632. -0.5, 0.5,
  117633. };
  117634. static long _vq_quantmap__44c5_s_p1_0[] = {
  117635. 1, 0, 2,
  117636. };
  117637. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117638. _vq_quantthresh__44c5_s_p1_0,
  117639. _vq_quantmap__44c5_s_p1_0,
  117640. 3,
  117641. 3
  117642. };
  117643. static static_codebook _44c5_s_p1_0 = {
  117644. 8, 6561,
  117645. _vq_lengthlist__44c5_s_p1_0,
  117646. 1, -535822336, 1611661312, 2, 0,
  117647. _vq_quantlist__44c5_s_p1_0,
  117648. NULL,
  117649. &_vq_auxt__44c5_s_p1_0,
  117650. NULL,
  117651. 0
  117652. };
  117653. static long _vq_quantlist__44c5_s_p2_0[] = {
  117654. 2,
  117655. 1,
  117656. 3,
  117657. 0,
  117658. 4,
  117659. };
  117660. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117661. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117662. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117663. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117664. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117665. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117670. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117671. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117672. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117673. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117678. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117679. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117680. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117686. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117687. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117688. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117700. 0,
  117701. };
  117702. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117703. -1.5, -0.5, 0.5, 1.5,
  117704. };
  117705. static long _vq_quantmap__44c5_s_p2_0[] = {
  117706. 3, 1, 0, 2, 4,
  117707. };
  117708. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117709. _vq_quantthresh__44c5_s_p2_0,
  117710. _vq_quantmap__44c5_s_p2_0,
  117711. 5,
  117712. 5
  117713. };
  117714. static static_codebook _44c5_s_p2_0 = {
  117715. 4, 625,
  117716. _vq_lengthlist__44c5_s_p2_0,
  117717. 1, -533725184, 1611661312, 3, 0,
  117718. _vq_quantlist__44c5_s_p2_0,
  117719. NULL,
  117720. &_vq_auxt__44c5_s_p2_0,
  117721. NULL,
  117722. 0
  117723. };
  117724. static long _vq_quantlist__44c5_s_p3_0[] = {
  117725. 2,
  117726. 1,
  117727. 3,
  117728. 0,
  117729. 4,
  117730. };
  117731. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117732. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117735. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117738. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117771. 0,
  117772. };
  117773. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117774. -1.5, -0.5, 0.5, 1.5,
  117775. };
  117776. static long _vq_quantmap__44c5_s_p3_0[] = {
  117777. 3, 1, 0, 2, 4,
  117778. };
  117779. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117780. _vq_quantthresh__44c5_s_p3_0,
  117781. _vq_quantmap__44c5_s_p3_0,
  117782. 5,
  117783. 5
  117784. };
  117785. static static_codebook _44c5_s_p3_0 = {
  117786. 4, 625,
  117787. _vq_lengthlist__44c5_s_p3_0,
  117788. 1, -533725184, 1611661312, 3, 0,
  117789. _vq_quantlist__44c5_s_p3_0,
  117790. NULL,
  117791. &_vq_auxt__44c5_s_p3_0,
  117792. NULL,
  117793. 0
  117794. };
  117795. static long _vq_quantlist__44c5_s_p4_0[] = {
  117796. 4,
  117797. 3,
  117798. 5,
  117799. 2,
  117800. 6,
  117801. 1,
  117802. 7,
  117803. 0,
  117804. 8,
  117805. };
  117806. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117807. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117808. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117809. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117810. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117811. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117812. 0,
  117813. };
  117814. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117815. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117816. };
  117817. static long _vq_quantmap__44c5_s_p4_0[] = {
  117818. 7, 5, 3, 1, 0, 2, 4, 6,
  117819. 8,
  117820. };
  117821. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117822. _vq_quantthresh__44c5_s_p4_0,
  117823. _vq_quantmap__44c5_s_p4_0,
  117824. 9,
  117825. 9
  117826. };
  117827. static static_codebook _44c5_s_p4_0 = {
  117828. 2, 81,
  117829. _vq_lengthlist__44c5_s_p4_0,
  117830. 1, -531628032, 1611661312, 4, 0,
  117831. _vq_quantlist__44c5_s_p4_0,
  117832. NULL,
  117833. &_vq_auxt__44c5_s_p4_0,
  117834. NULL,
  117835. 0
  117836. };
  117837. static long _vq_quantlist__44c5_s_p5_0[] = {
  117838. 4,
  117839. 3,
  117840. 5,
  117841. 2,
  117842. 6,
  117843. 1,
  117844. 7,
  117845. 0,
  117846. 8,
  117847. };
  117848. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117849. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117850. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117851. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117852. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117853. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117854. 10,
  117855. };
  117856. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117857. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117858. };
  117859. static long _vq_quantmap__44c5_s_p5_0[] = {
  117860. 7, 5, 3, 1, 0, 2, 4, 6,
  117861. 8,
  117862. };
  117863. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117864. _vq_quantthresh__44c5_s_p5_0,
  117865. _vq_quantmap__44c5_s_p5_0,
  117866. 9,
  117867. 9
  117868. };
  117869. static static_codebook _44c5_s_p5_0 = {
  117870. 2, 81,
  117871. _vq_lengthlist__44c5_s_p5_0,
  117872. 1, -531628032, 1611661312, 4, 0,
  117873. _vq_quantlist__44c5_s_p5_0,
  117874. NULL,
  117875. &_vq_auxt__44c5_s_p5_0,
  117876. NULL,
  117877. 0
  117878. };
  117879. static long _vq_quantlist__44c5_s_p6_0[] = {
  117880. 8,
  117881. 7,
  117882. 9,
  117883. 6,
  117884. 10,
  117885. 5,
  117886. 11,
  117887. 4,
  117888. 12,
  117889. 3,
  117890. 13,
  117891. 2,
  117892. 14,
  117893. 1,
  117894. 15,
  117895. 0,
  117896. 16,
  117897. };
  117898. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117899. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117900. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117901. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117902. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117903. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117904. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117905. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117906. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117907. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117908. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117909. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117910. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117911. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117912. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117913. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117914. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117915. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117916. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117917. 13,
  117918. };
  117919. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117920. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117921. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117922. };
  117923. static long _vq_quantmap__44c5_s_p6_0[] = {
  117924. 15, 13, 11, 9, 7, 5, 3, 1,
  117925. 0, 2, 4, 6, 8, 10, 12, 14,
  117926. 16,
  117927. };
  117928. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117929. _vq_quantthresh__44c5_s_p6_0,
  117930. _vq_quantmap__44c5_s_p6_0,
  117931. 17,
  117932. 17
  117933. };
  117934. static static_codebook _44c5_s_p6_0 = {
  117935. 2, 289,
  117936. _vq_lengthlist__44c5_s_p6_0,
  117937. 1, -529530880, 1611661312, 5, 0,
  117938. _vq_quantlist__44c5_s_p6_0,
  117939. NULL,
  117940. &_vq_auxt__44c5_s_p6_0,
  117941. NULL,
  117942. 0
  117943. };
  117944. static long _vq_quantlist__44c5_s_p7_0[] = {
  117945. 1,
  117946. 0,
  117947. 2,
  117948. };
  117949. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117950. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117951. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117952. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117953. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117954. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117955. 10,
  117956. };
  117957. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117958. -5.5, 5.5,
  117959. };
  117960. static long _vq_quantmap__44c5_s_p7_0[] = {
  117961. 1, 0, 2,
  117962. };
  117963. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117964. _vq_quantthresh__44c5_s_p7_0,
  117965. _vq_quantmap__44c5_s_p7_0,
  117966. 3,
  117967. 3
  117968. };
  117969. static static_codebook _44c5_s_p7_0 = {
  117970. 4, 81,
  117971. _vq_lengthlist__44c5_s_p7_0,
  117972. 1, -529137664, 1618345984, 2, 0,
  117973. _vq_quantlist__44c5_s_p7_0,
  117974. NULL,
  117975. &_vq_auxt__44c5_s_p7_0,
  117976. NULL,
  117977. 0
  117978. };
  117979. static long _vq_quantlist__44c5_s_p7_1[] = {
  117980. 5,
  117981. 4,
  117982. 6,
  117983. 3,
  117984. 7,
  117985. 2,
  117986. 8,
  117987. 1,
  117988. 9,
  117989. 0,
  117990. 10,
  117991. };
  117992. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117993. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117994. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117995. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117996. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117997. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117998. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117999. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  118000. 10,10,10, 8, 8, 8, 8, 8, 8,
  118001. };
  118002. static float _vq_quantthresh__44c5_s_p7_1[] = {
  118003. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118004. 3.5, 4.5,
  118005. };
  118006. static long _vq_quantmap__44c5_s_p7_1[] = {
  118007. 9, 7, 5, 3, 1, 0, 2, 4,
  118008. 6, 8, 10,
  118009. };
  118010. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  118011. _vq_quantthresh__44c5_s_p7_1,
  118012. _vq_quantmap__44c5_s_p7_1,
  118013. 11,
  118014. 11
  118015. };
  118016. static static_codebook _44c5_s_p7_1 = {
  118017. 2, 121,
  118018. _vq_lengthlist__44c5_s_p7_1,
  118019. 1, -531365888, 1611661312, 4, 0,
  118020. _vq_quantlist__44c5_s_p7_1,
  118021. NULL,
  118022. &_vq_auxt__44c5_s_p7_1,
  118023. NULL,
  118024. 0
  118025. };
  118026. static long _vq_quantlist__44c5_s_p8_0[] = {
  118027. 6,
  118028. 5,
  118029. 7,
  118030. 4,
  118031. 8,
  118032. 3,
  118033. 9,
  118034. 2,
  118035. 10,
  118036. 1,
  118037. 11,
  118038. 0,
  118039. 12,
  118040. };
  118041. static long _vq_lengthlist__44c5_s_p8_0[] = {
  118042. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  118043. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  118044. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  118045. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  118046. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  118047. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  118048. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  118049. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  118050. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  118051. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  118052. 0,12,12,12,12,12,12,13,13,
  118053. };
  118054. static float _vq_quantthresh__44c5_s_p8_0[] = {
  118055. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118056. 12.5, 17.5, 22.5, 27.5,
  118057. };
  118058. static long _vq_quantmap__44c5_s_p8_0[] = {
  118059. 11, 9, 7, 5, 3, 1, 0, 2,
  118060. 4, 6, 8, 10, 12,
  118061. };
  118062. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  118063. _vq_quantthresh__44c5_s_p8_0,
  118064. _vq_quantmap__44c5_s_p8_0,
  118065. 13,
  118066. 13
  118067. };
  118068. static static_codebook _44c5_s_p8_0 = {
  118069. 2, 169,
  118070. _vq_lengthlist__44c5_s_p8_0,
  118071. 1, -526516224, 1616117760, 4, 0,
  118072. _vq_quantlist__44c5_s_p8_0,
  118073. NULL,
  118074. &_vq_auxt__44c5_s_p8_0,
  118075. NULL,
  118076. 0
  118077. };
  118078. static long _vq_quantlist__44c5_s_p8_1[] = {
  118079. 2,
  118080. 1,
  118081. 3,
  118082. 0,
  118083. 4,
  118084. };
  118085. static long _vq_lengthlist__44c5_s_p8_1[] = {
  118086. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  118087. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118088. };
  118089. static float _vq_quantthresh__44c5_s_p8_1[] = {
  118090. -1.5, -0.5, 0.5, 1.5,
  118091. };
  118092. static long _vq_quantmap__44c5_s_p8_1[] = {
  118093. 3, 1, 0, 2, 4,
  118094. };
  118095. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  118096. _vq_quantthresh__44c5_s_p8_1,
  118097. _vq_quantmap__44c5_s_p8_1,
  118098. 5,
  118099. 5
  118100. };
  118101. static static_codebook _44c5_s_p8_1 = {
  118102. 2, 25,
  118103. _vq_lengthlist__44c5_s_p8_1,
  118104. 1, -533725184, 1611661312, 3, 0,
  118105. _vq_quantlist__44c5_s_p8_1,
  118106. NULL,
  118107. &_vq_auxt__44c5_s_p8_1,
  118108. NULL,
  118109. 0
  118110. };
  118111. static long _vq_quantlist__44c5_s_p9_0[] = {
  118112. 7,
  118113. 6,
  118114. 8,
  118115. 5,
  118116. 9,
  118117. 4,
  118118. 10,
  118119. 3,
  118120. 11,
  118121. 2,
  118122. 12,
  118123. 1,
  118124. 13,
  118125. 0,
  118126. 14,
  118127. };
  118128. static long _vq_lengthlist__44c5_s_p9_0[] = {
  118129. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  118130. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  118131. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118132. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118133. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118134. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118135. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118136. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118137. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118138. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118139. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118140. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118141. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118142. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  118143. 12,
  118144. };
  118145. static float _vq_quantthresh__44c5_s_p9_0[] = {
  118146. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  118147. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  118148. };
  118149. static long _vq_quantmap__44c5_s_p9_0[] = {
  118150. 13, 11, 9, 7, 5, 3, 1, 0,
  118151. 2, 4, 6, 8, 10, 12, 14,
  118152. };
  118153. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  118154. _vq_quantthresh__44c5_s_p9_0,
  118155. _vq_quantmap__44c5_s_p9_0,
  118156. 15,
  118157. 15
  118158. };
  118159. static static_codebook _44c5_s_p9_0 = {
  118160. 2, 225,
  118161. _vq_lengthlist__44c5_s_p9_0,
  118162. 1, -512522752, 1628852224, 4, 0,
  118163. _vq_quantlist__44c5_s_p9_0,
  118164. NULL,
  118165. &_vq_auxt__44c5_s_p9_0,
  118166. NULL,
  118167. 0
  118168. };
  118169. static long _vq_quantlist__44c5_s_p9_1[] = {
  118170. 8,
  118171. 7,
  118172. 9,
  118173. 6,
  118174. 10,
  118175. 5,
  118176. 11,
  118177. 4,
  118178. 12,
  118179. 3,
  118180. 13,
  118181. 2,
  118182. 14,
  118183. 1,
  118184. 15,
  118185. 0,
  118186. 16,
  118187. };
  118188. static long _vq_lengthlist__44c5_s_p9_1[] = {
  118189. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  118190. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  118191. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  118192. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  118193. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  118194. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  118195. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  118196. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  118197. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  118198. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  118199. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  118200. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  118201. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  118202. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  118203. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  118204. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  118205. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  118206. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  118207. 15,
  118208. };
  118209. static float _vq_quantthresh__44c5_s_p9_1[] = {
  118210. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  118211. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  118212. };
  118213. static long _vq_quantmap__44c5_s_p9_1[] = {
  118214. 15, 13, 11, 9, 7, 5, 3, 1,
  118215. 0, 2, 4, 6, 8, 10, 12, 14,
  118216. 16,
  118217. };
  118218. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  118219. _vq_quantthresh__44c5_s_p9_1,
  118220. _vq_quantmap__44c5_s_p9_1,
  118221. 17,
  118222. 17
  118223. };
  118224. static static_codebook _44c5_s_p9_1 = {
  118225. 2, 289,
  118226. _vq_lengthlist__44c5_s_p9_1,
  118227. 1, -520814592, 1620377600, 5, 0,
  118228. _vq_quantlist__44c5_s_p9_1,
  118229. NULL,
  118230. &_vq_auxt__44c5_s_p9_1,
  118231. NULL,
  118232. 0
  118233. };
  118234. static long _vq_quantlist__44c5_s_p9_2[] = {
  118235. 10,
  118236. 9,
  118237. 11,
  118238. 8,
  118239. 12,
  118240. 7,
  118241. 13,
  118242. 6,
  118243. 14,
  118244. 5,
  118245. 15,
  118246. 4,
  118247. 16,
  118248. 3,
  118249. 17,
  118250. 2,
  118251. 18,
  118252. 1,
  118253. 19,
  118254. 0,
  118255. 20,
  118256. };
  118257. static long _vq_lengthlist__44c5_s_p9_2[] = {
  118258. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  118259. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  118260. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  118261. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  118262. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  118263. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  118264. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  118265. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  118266. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  118267. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118268. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  118269. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  118270. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  118271. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  118272. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  118273. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  118274. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  118275. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118276. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  118277. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  118278. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118279. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118280. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118281. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118282. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  118283. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118284. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  118285. 10,10,10,10,10,10,10,10,10,
  118286. };
  118287. static float _vq_quantthresh__44c5_s_p9_2[] = {
  118288. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118289. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118290. 6.5, 7.5, 8.5, 9.5,
  118291. };
  118292. static long _vq_quantmap__44c5_s_p9_2[] = {
  118293. 19, 17, 15, 13, 11, 9, 7, 5,
  118294. 3, 1, 0, 2, 4, 6, 8, 10,
  118295. 12, 14, 16, 18, 20,
  118296. };
  118297. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  118298. _vq_quantthresh__44c5_s_p9_2,
  118299. _vq_quantmap__44c5_s_p9_2,
  118300. 21,
  118301. 21
  118302. };
  118303. static static_codebook _44c5_s_p9_2 = {
  118304. 2, 441,
  118305. _vq_lengthlist__44c5_s_p9_2,
  118306. 1, -529268736, 1611661312, 5, 0,
  118307. _vq_quantlist__44c5_s_p9_2,
  118308. NULL,
  118309. &_vq_auxt__44c5_s_p9_2,
  118310. NULL,
  118311. 0
  118312. };
  118313. static long _huff_lengthlist__44c5_s_short[] = {
  118314. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118315. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118316. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118317. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118318. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118319. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118320. 6, 8,11,16,
  118321. };
  118322. static static_codebook _huff_book__44c5_s_short = {
  118323. 2, 100,
  118324. _huff_lengthlist__44c5_s_short,
  118325. 0, 0, 0, 0, 0,
  118326. NULL,
  118327. NULL,
  118328. NULL,
  118329. NULL,
  118330. 0
  118331. };
  118332. static long _huff_lengthlist__44c6_s_long[] = {
  118333. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118334. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118335. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118336. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118337. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118338. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118339. 11,10,10,12,
  118340. };
  118341. static static_codebook _huff_book__44c6_s_long = {
  118342. 2, 100,
  118343. _huff_lengthlist__44c6_s_long,
  118344. 0, 0, 0, 0, 0,
  118345. NULL,
  118346. NULL,
  118347. NULL,
  118348. NULL,
  118349. 0
  118350. };
  118351. static long _vq_quantlist__44c6_s_p1_0[] = {
  118352. 1,
  118353. 0,
  118354. 2,
  118355. };
  118356. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118357. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118358. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118359. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118360. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118361. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118362. 8,
  118363. };
  118364. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118365. -0.5, 0.5,
  118366. };
  118367. static long _vq_quantmap__44c6_s_p1_0[] = {
  118368. 1, 0, 2,
  118369. };
  118370. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118371. _vq_quantthresh__44c6_s_p1_0,
  118372. _vq_quantmap__44c6_s_p1_0,
  118373. 3,
  118374. 3
  118375. };
  118376. static static_codebook _44c6_s_p1_0 = {
  118377. 4, 81,
  118378. _vq_lengthlist__44c6_s_p1_0,
  118379. 1, -535822336, 1611661312, 2, 0,
  118380. _vq_quantlist__44c6_s_p1_0,
  118381. NULL,
  118382. &_vq_auxt__44c6_s_p1_0,
  118383. NULL,
  118384. 0
  118385. };
  118386. static long _vq_quantlist__44c6_s_p2_0[] = {
  118387. 2,
  118388. 1,
  118389. 3,
  118390. 0,
  118391. 4,
  118392. };
  118393. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118394. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118395. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118396. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118397. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118398. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118399. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118400. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118401. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118403. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118404. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118405. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118406. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118407. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118408. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118409. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118411. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118412. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118413. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118414. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118415. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118416. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118417. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118419. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118420. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118421. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118422. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118423. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118424. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118425. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118430. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118431. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118432. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118433. 13,
  118434. };
  118435. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118436. -1.5, -0.5, 0.5, 1.5,
  118437. };
  118438. static long _vq_quantmap__44c6_s_p2_0[] = {
  118439. 3, 1, 0, 2, 4,
  118440. };
  118441. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118442. _vq_quantthresh__44c6_s_p2_0,
  118443. _vq_quantmap__44c6_s_p2_0,
  118444. 5,
  118445. 5
  118446. };
  118447. static static_codebook _44c6_s_p2_0 = {
  118448. 4, 625,
  118449. _vq_lengthlist__44c6_s_p2_0,
  118450. 1, -533725184, 1611661312, 3, 0,
  118451. _vq_quantlist__44c6_s_p2_0,
  118452. NULL,
  118453. &_vq_auxt__44c6_s_p2_0,
  118454. NULL,
  118455. 0
  118456. };
  118457. static long _vq_quantlist__44c6_s_p3_0[] = {
  118458. 4,
  118459. 3,
  118460. 5,
  118461. 2,
  118462. 6,
  118463. 1,
  118464. 7,
  118465. 0,
  118466. 8,
  118467. };
  118468. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118469. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118470. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118471. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118472. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118474. 0,
  118475. };
  118476. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118477. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118478. };
  118479. static long _vq_quantmap__44c6_s_p3_0[] = {
  118480. 7, 5, 3, 1, 0, 2, 4, 6,
  118481. 8,
  118482. };
  118483. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118484. _vq_quantthresh__44c6_s_p3_0,
  118485. _vq_quantmap__44c6_s_p3_0,
  118486. 9,
  118487. 9
  118488. };
  118489. static static_codebook _44c6_s_p3_0 = {
  118490. 2, 81,
  118491. _vq_lengthlist__44c6_s_p3_0,
  118492. 1, -531628032, 1611661312, 4, 0,
  118493. _vq_quantlist__44c6_s_p3_0,
  118494. NULL,
  118495. &_vq_auxt__44c6_s_p3_0,
  118496. NULL,
  118497. 0
  118498. };
  118499. static long _vq_quantlist__44c6_s_p4_0[] = {
  118500. 8,
  118501. 7,
  118502. 9,
  118503. 6,
  118504. 10,
  118505. 5,
  118506. 11,
  118507. 4,
  118508. 12,
  118509. 3,
  118510. 13,
  118511. 2,
  118512. 14,
  118513. 1,
  118514. 15,
  118515. 0,
  118516. 16,
  118517. };
  118518. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118519. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118520. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118521. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118522. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118523. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118524. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118525. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118526. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118527. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118528. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118537. 0,
  118538. };
  118539. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118540. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118541. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118542. };
  118543. static long _vq_quantmap__44c6_s_p4_0[] = {
  118544. 15, 13, 11, 9, 7, 5, 3, 1,
  118545. 0, 2, 4, 6, 8, 10, 12, 14,
  118546. 16,
  118547. };
  118548. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118549. _vq_quantthresh__44c6_s_p4_0,
  118550. _vq_quantmap__44c6_s_p4_0,
  118551. 17,
  118552. 17
  118553. };
  118554. static static_codebook _44c6_s_p4_0 = {
  118555. 2, 289,
  118556. _vq_lengthlist__44c6_s_p4_0,
  118557. 1, -529530880, 1611661312, 5, 0,
  118558. _vq_quantlist__44c6_s_p4_0,
  118559. NULL,
  118560. &_vq_auxt__44c6_s_p4_0,
  118561. NULL,
  118562. 0
  118563. };
  118564. static long _vq_quantlist__44c6_s_p5_0[] = {
  118565. 1,
  118566. 0,
  118567. 2,
  118568. };
  118569. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118570. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118571. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118572. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118573. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118574. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118575. 12,
  118576. };
  118577. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118578. -5.5, 5.5,
  118579. };
  118580. static long _vq_quantmap__44c6_s_p5_0[] = {
  118581. 1, 0, 2,
  118582. };
  118583. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118584. _vq_quantthresh__44c6_s_p5_0,
  118585. _vq_quantmap__44c6_s_p5_0,
  118586. 3,
  118587. 3
  118588. };
  118589. static static_codebook _44c6_s_p5_0 = {
  118590. 4, 81,
  118591. _vq_lengthlist__44c6_s_p5_0,
  118592. 1, -529137664, 1618345984, 2, 0,
  118593. _vq_quantlist__44c6_s_p5_0,
  118594. NULL,
  118595. &_vq_auxt__44c6_s_p5_0,
  118596. NULL,
  118597. 0
  118598. };
  118599. static long _vq_quantlist__44c6_s_p5_1[] = {
  118600. 5,
  118601. 4,
  118602. 6,
  118603. 3,
  118604. 7,
  118605. 2,
  118606. 8,
  118607. 1,
  118608. 9,
  118609. 0,
  118610. 10,
  118611. };
  118612. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118613. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118614. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118615. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118616. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118617. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118618. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118619. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118620. 11,10,10, 7, 7, 8, 8, 8, 8,
  118621. };
  118622. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118623. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118624. 3.5, 4.5,
  118625. };
  118626. static long _vq_quantmap__44c6_s_p5_1[] = {
  118627. 9, 7, 5, 3, 1, 0, 2, 4,
  118628. 6, 8, 10,
  118629. };
  118630. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118631. _vq_quantthresh__44c6_s_p5_1,
  118632. _vq_quantmap__44c6_s_p5_1,
  118633. 11,
  118634. 11
  118635. };
  118636. static static_codebook _44c6_s_p5_1 = {
  118637. 2, 121,
  118638. _vq_lengthlist__44c6_s_p5_1,
  118639. 1, -531365888, 1611661312, 4, 0,
  118640. _vq_quantlist__44c6_s_p5_1,
  118641. NULL,
  118642. &_vq_auxt__44c6_s_p5_1,
  118643. NULL,
  118644. 0
  118645. };
  118646. static long _vq_quantlist__44c6_s_p6_0[] = {
  118647. 6,
  118648. 5,
  118649. 7,
  118650. 4,
  118651. 8,
  118652. 3,
  118653. 9,
  118654. 2,
  118655. 10,
  118656. 1,
  118657. 11,
  118658. 0,
  118659. 12,
  118660. };
  118661. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118662. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118663. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118664. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118665. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118666. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118667. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118672. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118673. };
  118674. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118675. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118676. 12.5, 17.5, 22.5, 27.5,
  118677. };
  118678. static long _vq_quantmap__44c6_s_p6_0[] = {
  118679. 11, 9, 7, 5, 3, 1, 0, 2,
  118680. 4, 6, 8, 10, 12,
  118681. };
  118682. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118683. _vq_quantthresh__44c6_s_p6_0,
  118684. _vq_quantmap__44c6_s_p6_0,
  118685. 13,
  118686. 13
  118687. };
  118688. static static_codebook _44c6_s_p6_0 = {
  118689. 2, 169,
  118690. _vq_lengthlist__44c6_s_p6_0,
  118691. 1, -526516224, 1616117760, 4, 0,
  118692. _vq_quantlist__44c6_s_p6_0,
  118693. NULL,
  118694. &_vq_auxt__44c6_s_p6_0,
  118695. NULL,
  118696. 0
  118697. };
  118698. static long _vq_quantlist__44c6_s_p6_1[] = {
  118699. 2,
  118700. 1,
  118701. 3,
  118702. 0,
  118703. 4,
  118704. };
  118705. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118706. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118707. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118708. };
  118709. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118710. -1.5, -0.5, 0.5, 1.5,
  118711. };
  118712. static long _vq_quantmap__44c6_s_p6_1[] = {
  118713. 3, 1, 0, 2, 4,
  118714. };
  118715. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118716. _vq_quantthresh__44c6_s_p6_1,
  118717. _vq_quantmap__44c6_s_p6_1,
  118718. 5,
  118719. 5
  118720. };
  118721. static static_codebook _44c6_s_p6_1 = {
  118722. 2, 25,
  118723. _vq_lengthlist__44c6_s_p6_1,
  118724. 1, -533725184, 1611661312, 3, 0,
  118725. _vq_quantlist__44c6_s_p6_1,
  118726. NULL,
  118727. &_vq_auxt__44c6_s_p6_1,
  118728. NULL,
  118729. 0
  118730. };
  118731. static long _vq_quantlist__44c6_s_p7_0[] = {
  118732. 6,
  118733. 5,
  118734. 7,
  118735. 4,
  118736. 8,
  118737. 3,
  118738. 9,
  118739. 2,
  118740. 10,
  118741. 1,
  118742. 11,
  118743. 0,
  118744. 12,
  118745. };
  118746. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118747. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118748. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118749. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118750. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118751. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118752. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118753. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118754. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118755. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118756. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118757. 20,13,13,13,13,13,13,14,14,
  118758. };
  118759. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118760. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118761. 27.5, 38.5, 49.5, 60.5,
  118762. };
  118763. static long _vq_quantmap__44c6_s_p7_0[] = {
  118764. 11, 9, 7, 5, 3, 1, 0, 2,
  118765. 4, 6, 8, 10, 12,
  118766. };
  118767. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118768. _vq_quantthresh__44c6_s_p7_0,
  118769. _vq_quantmap__44c6_s_p7_0,
  118770. 13,
  118771. 13
  118772. };
  118773. static static_codebook _44c6_s_p7_0 = {
  118774. 2, 169,
  118775. _vq_lengthlist__44c6_s_p7_0,
  118776. 1, -523206656, 1618345984, 4, 0,
  118777. _vq_quantlist__44c6_s_p7_0,
  118778. NULL,
  118779. &_vq_auxt__44c6_s_p7_0,
  118780. NULL,
  118781. 0
  118782. };
  118783. static long _vq_quantlist__44c6_s_p7_1[] = {
  118784. 5,
  118785. 4,
  118786. 6,
  118787. 3,
  118788. 7,
  118789. 2,
  118790. 8,
  118791. 1,
  118792. 9,
  118793. 0,
  118794. 10,
  118795. };
  118796. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118797. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118798. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118799. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118800. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118801. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118802. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118803. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118804. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118805. };
  118806. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118807. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118808. 3.5, 4.5,
  118809. };
  118810. static long _vq_quantmap__44c6_s_p7_1[] = {
  118811. 9, 7, 5, 3, 1, 0, 2, 4,
  118812. 6, 8, 10,
  118813. };
  118814. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118815. _vq_quantthresh__44c6_s_p7_1,
  118816. _vq_quantmap__44c6_s_p7_1,
  118817. 11,
  118818. 11
  118819. };
  118820. static static_codebook _44c6_s_p7_1 = {
  118821. 2, 121,
  118822. _vq_lengthlist__44c6_s_p7_1,
  118823. 1, -531365888, 1611661312, 4, 0,
  118824. _vq_quantlist__44c6_s_p7_1,
  118825. NULL,
  118826. &_vq_auxt__44c6_s_p7_1,
  118827. NULL,
  118828. 0
  118829. };
  118830. static long _vq_quantlist__44c6_s_p8_0[] = {
  118831. 7,
  118832. 6,
  118833. 8,
  118834. 5,
  118835. 9,
  118836. 4,
  118837. 10,
  118838. 3,
  118839. 11,
  118840. 2,
  118841. 12,
  118842. 1,
  118843. 13,
  118844. 0,
  118845. 14,
  118846. };
  118847. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118848. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118849. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118850. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118851. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118852. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118853. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118854. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118855. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118856. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118857. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118858. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118859. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118860. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118861. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118862. 14,
  118863. };
  118864. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118865. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118866. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118867. };
  118868. static long _vq_quantmap__44c6_s_p8_0[] = {
  118869. 13, 11, 9, 7, 5, 3, 1, 0,
  118870. 2, 4, 6, 8, 10, 12, 14,
  118871. };
  118872. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118873. _vq_quantthresh__44c6_s_p8_0,
  118874. _vq_quantmap__44c6_s_p8_0,
  118875. 15,
  118876. 15
  118877. };
  118878. static static_codebook _44c6_s_p8_0 = {
  118879. 2, 225,
  118880. _vq_lengthlist__44c6_s_p8_0,
  118881. 1, -520986624, 1620377600, 4, 0,
  118882. _vq_quantlist__44c6_s_p8_0,
  118883. NULL,
  118884. &_vq_auxt__44c6_s_p8_0,
  118885. NULL,
  118886. 0
  118887. };
  118888. static long _vq_quantlist__44c6_s_p8_1[] = {
  118889. 10,
  118890. 9,
  118891. 11,
  118892. 8,
  118893. 12,
  118894. 7,
  118895. 13,
  118896. 6,
  118897. 14,
  118898. 5,
  118899. 15,
  118900. 4,
  118901. 16,
  118902. 3,
  118903. 17,
  118904. 2,
  118905. 18,
  118906. 1,
  118907. 19,
  118908. 0,
  118909. 20,
  118910. };
  118911. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118912. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118913. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118914. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118915. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118916. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118917. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118918. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118919. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118920. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118921. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118922. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118923. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118924. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118925. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118926. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118927. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118928. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118929. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118930. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118931. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118932. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118933. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118934. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118935. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118936. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118937. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118938. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118939. 10,10,10,10,10,10,10,10,10,
  118940. };
  118941. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118942. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118943. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118944. 6.5, 7.5, 8.5, 9.5,
  118945. };
  118946. static long _vq_quantmap__44c6_s_p8_1[] = {
  118947. 19, 17, 15, 13, 11, 9, 7, 5,
  118948. 3, 1, 0, 2, 4, 6, 8, 10,
  118949. 12, 14, 16, 18, 20,
  118950. };
  118951. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118952. _vq_quantthresh__44c6_s_p8_1,
  118953. _vq_quantmap__44c6_s_p8_1,
  118954. 21,
  118955. 21
  118956. };
  118957. static static_codebook _44c6_s_p8_1 = {
  118958. 2, 441,
  118959. _vq_lengthlist__44c6_s_p8_1,
  118960. 1, -529268736, 1611661312, 5, 0,
  118961. _vq_quantlist__44c6_s_p8_1,
  118962. NULL,
  118963. &_vq_auxt__44c6_s_p8_1,
  118964. NULL,
  118965. 0
  118966. };
  118967. static long _vq_quantlist__44c6_s_p9_0[] = {
  118968. 6,
  118969. 5,
  118970. 7,
  118971. 4,
  118972. 8,
  118973. 3,
  118974. 9,
  118975. 2,
  118976. 10,
  118977. 1,
  118978. 11,
  118979. 0,
  118980. 12,
  118981. };
  118982. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118983. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118984. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118985. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118986. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118987. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118988. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118989. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118990. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118991. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118992. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118993. 10,10,10,10,10,10,10,10,10,
  118994. };
  118995. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118996. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118997. 1592.5, 2229.5, 2866.5, 3503.5,
  118998. };
  118999. static long _vq_quantmap__44c6_s_p9_0[] = {
  119000. 11, 9, 7, 5, 3, 1, 0, 2,
  119001. 4, 6, 8, 10, 12,
  119002. };
  119003. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  119004. _vq_quantthresh__44c6_s_p9_0,
  119005. _vq_quantmap__44c6_s_p9_0,
  119006. 13,
  119007. 13
  119008. };
  119009. static static_codebook _44c6_s_p9_0 = {
  119010. 2, 169,
  119011. _vq_lengthlist__44c6_s_p9_0,
  119012. 1, -511845376, 1630791680, 4, 0,
  119013. _vq_quantlist__44c6_s_p9_0,
  119014. NULL,
  119015. &_vq_auxt__44c6_s_p9_0,
  119016. NULL,
  119017. 0
  119018. };
  119019. static long _vq_quantlist__44c6_s_p9_1[] = {
  119020. 6,
  119021. 5,
  119022. 7,
  119023. 4,
  119024. 8,
  119025. 3,
  119026. 9,
  119027. 2,
  119028. 10,
  119029. 1,
  119030. 11,
  119031. 0,
  119032. 12,
  119033. };
  119034. static long _vq_lengthlist__44c6_s_p9_1[] = {
  119035. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119036. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  119037. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  119038. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  119039. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  119040. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  119041. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  119042. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  119043. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  119044. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  119045. 15,12,10,11,11,13,11,12,13,
  119046. };
  119047. static float _vq_quantthresh__44c6_s_p9_1[] = {
  119048. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119049. 122.5, 171.5, 220.5, 269.5,
  119050. };
  119051. static long _vq_quantmap__44c6_s_p9_1[] = {
  119052. 11, 9, 7, 5, 3, 1, 0, 2,
  119053. 4, 6, 8, 10, 12,
  119054. };
  119055. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  119056. _vq_quantthresh__44c6_s_p9_1,
  119057. _vq_quantmap__44c6_s_p9_1,
  119058. 13,
  119059. 13
  119060. };
  119061. static static_codebook _44c6_s_p9_1 = {
  119062. 2, 169,
  119063. _vq_lengthlist__44c6_s_p9_1,
  119064. 1, -518889472, 1622704128, 4, 0,
  119065. _vq_quantlist__44c6_s_p9_1,
  119066. NULL,
  119067. &_vq_auxt__44c6_s_p9_1,
  119068. NULL,
  119069. 0
  119070. };
  119071. static long _vq_quantlist__44c6_s_p9_2[] = {
  119072. 24,
  119073. 23,
  119074. 25,
  119075. 22,
  119076. 26,
  119077. 21,
  119078. 27,
  119079. 20,
  119080. 28,
  119081. 19,
  119082. 29,
  119083. 18,
  119084. 30,
  119085. 17,
  119086. 31,
  119087. 16,
  119088. 32,
  119089. 15,
  119090. 33,
  119091. 14,
  119092. 34,
  119093. 13,
  119094. 35,
  119095. 12,
  119096. 36,
  119097. 11,
  119098. 37,
  119099. 10,
  119100. 38,
  119101. 9,
  119102. 39,
  119103. 8,
  119104. 40,
  119105. 7,
  119106. 41,
  119107. 6,
  119108. 42,
  119109. 5,
  119110. 43,
  119111. 4,
  119112. 44,
  119113. 3,
  119114. 45,
  119115. 2,
  119116. 46,
  119117. 1,
  119118. 47,
  119119. 0,
  119120. 48,
  119121. };
  119122. static long _vq_lengthlist__44c6_s_p9_2[] = {
  119123. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119124. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119125. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119126. 7,
  119127. };
  119128. static float _vq_quantthresh__44c6_s_p9_2[] = {
  119129. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119130. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119131. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119132. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119133. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119134. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119135. };
  119136. static long _vq_quantmap__44c6_s_p9_2[] = {
  119137. 47, 45, 43, 41, 39, 37, 35, 33,
  119138. 31, 29, 27, 25, 23, 21, 19, 17,
  119139. 15, 13, 11, 9, 7, 5, 3, 1,
  119140. 0, 2, 4, 6, 8, 10, 12, 14,
  119141. 16, 18, 20, 22, 24, 26, 28, 30,
  119142. 32, 34, 36, 38, 40, 42, 44, 46,
  119143. 48,
  119144. };
  119145. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  119146. _vq_quantthresh__44c6_s_p9_2,
  119147. _vq_quantmap__44c6_s_p9_2,
  119148. 49,
  119149. 49
  119150. };
  119151. static static_codebook _44c6_s_p9_2 = {
  119152. 1, 49,
  119153. _vq_lengthlist__44c6_s_p9_2,
  119154. 1, -526909440, 1611661312, 6, 0,
  119155. _vq_quantlist__44c6_s_p9_2,
  119156. NULL,
  119157. &_vq_auxt__44c6_s_p9_2,
  119158. NULL,
  119159. 0
  119160. };
  119161. static long _huff_lengthlist__44c6_s_short[] = {
  119162. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  119163. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  119164. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  119165. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  119166. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  119167. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  119168. 9,10,17,18,
  119169. };
  119170. static static_codebook _huff_book__44c6_s_short = {
  119171. 2, 100,
  119172. _huff_lengthlist__44c6_s_short,
  119173. 0, 0, 0, 0, 0,
  119174. NULL,
  119175. NULL,
  119176. NULL,
  119177. NULL,
  119178. 0
  119179. };
  119180. static long _huff_lengthlist__44c7_s_long[] = {
  119181. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  119182. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  119183. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  119184. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  119185. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  119186. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  119187. 11,10,10,12,
  119188. };
  119189. static static_codebook _huff_book__44c7_s_long = {
  119190. 2, 100,
  119191. _huff_lengthlist__44c7_s_long,
  119192. 0, 0, 0, 0, 0,
  119193. NULL,
  119194. NULL,
  119195. NULL,
  119196. NULL,
  119197. 0
  119198. };
  119199. static long _vq_quantlist__44c7_s_p1_0[] = {
  119200. 1,
  119201. 0,
  119202. 2,
  119203. };
  119204. static long _vq_lengthlist__44c7_s_p1_0[] = {
  119205. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  119206. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119207. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119208. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119209. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119210. 8,
  119211. };
  119212. static float _vq_quantthresh__44c7_s_p1_0[] = {
  119213. -0.5, 0.5,
  119214. };
  119215. static long _vq_quantmap__44c7_s_p1_0[] = {
  119216. 1, 0, 2,
  119217. };
  119218. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  119219. _vq_quantthresh__44c7_s_p1_0,
  119220. _vq_quantmap__44c7_s_p1_0,
  119221. 3,
  119222. 3
  119223. };
  119224. static static_codebook _44c7_s_p1_0 = {
  119225. 4, 81,
  119226. _vq_lengthlist__44c7_s_p1_0,
  119227. 1, -535822336, 1611661312, 2, 0,
  119228. _vq_quantlist__44c7_s_p1_0,
  119229. NULL,
  119230. &_vq_auxt__44c7_s_p1_0,
  119231. NULL,
  119232. 0
  119233. };
  119234. static long _vq_quantlist__44c7_s_p2_0[] = {
  119235. 2,
  119236. 1,
  119237. 3,
  119238. 0,
  119239. 4,
  119240. };
  119241. static long _vq_lengthlist__44c7_s_p2_0[] = {
  119242. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119243. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119244. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119245. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  119246. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119247. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  119248. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  119249. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119251. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119252. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  119253. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119254. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  119255. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  119256. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  119257. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  119258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119259. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  119260. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  119261. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  119262. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  119263. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  119264. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  119265. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119267. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119268. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  119269. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119270. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  119271. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  119272. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  119273. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119278. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  119279. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119280. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  119281. 13,
  119282. };
  119283. static float _vq_quantthresh__44c7_s_p2_0[] = {
  119284. -1.5, -0.5, 0.5, 1.5,
  119285. };
  119286. static long _vq_quantmap__44c7_s_p2_0[] = {
  119287. 3, 1, 0, 2, 4,
  119288. };
  119289. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  119290. _vq_quantthresh__44c7_s_p2_0,
  119291. _vq_quantmap__44c7_s_p2_0,
  119292. 5,
  119293. 5
  119294. };
  119295. static static_codebook _44c7_s_p2_0 = {
  119296. 4, 625,
  119297. _vq_lengthlist__44c7_s_p2_0,
  119298. 1, -533725184, 1611661312, 3, 0,
  119299. _vq_quantlist__44c7_s_p2_0,
  119300. NULL,
  119301. &_vq_auxt__44c7_s_p2_0,
  119302. NULL,
  119303. 0
  119304. };
  119305. static long _vq_quantlist__44c7_s_p3_0[] = {
  119306. 4,
  119307. 3,
  119308. 5,
  119309. 2,
  119310. 6,
  119311. 1,
  119312. 7,
  119313. 0,
  119314. 8,
  119315. };
  119316. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119317. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119318. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119319. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119320. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119322. 0,
  119323. };
  119324. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119325. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119326. };
  119327. static long _vq_quantmap__44c7_s_p3_0[] = {
  119328. 7, 5, 3, 1, 0, 2, 4, 6,
  119329. 8,
  119330. };
  119331. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119332. _vq_quantthresh__44c7_s_p3_0,
  119333. _vq_quantmap__44c7_s_p3_0,
  119334. 9,
  119335. 9
  119336. };
  119337. static static_codebook _44c7_s_p3_0 = {
  119338. 2, 81,
  119339. _vq_lengthlist__44c7_s_p3_0,
  119340. 1, -531628032, 1611661312, 4, 0,
  119341. _vq_quantlist__44c7_s_p3_0,
  119342. NULL,
  119343. &_vq_auxt__44c7_s_p3_0,
  119344. NULL,
  119345. 0
  119346. };
  119347. static long _vq_quantlist__44c7_s_p4_0[] = {
  119348. 8,
  119349. 7,
  119350. 9,
  119351. 6,
  119352. 10,
  119353. 5,
  119354. 11,
  119355. 4,
  119356. 12,
  119357. 3,
  119358. 13,
  119359. 2,
  119360. 14,
  119361. 1,
  119362. 15,
  119363. 0,
  119364. 16,
  119365. };
  119366. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119367. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119368. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119369. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119370. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119371. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119372. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119373. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119374. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119375. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119376. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119385. 0,
  119386. };
  119387. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119388. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119389. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119390. };
  119391. static long _vq_quantmap__44c7_s_p4_0[] = {
  119392. 15, 13, 11, 9, 7, 5, 3, 1,
  119393. 0, 2, 4, 6, 8, 10, 12, 14,
  119394. 16,
  119395. };
  119396. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119397. _vq_quantthresh__44c7_s_p4_0,
  119398. _vq_quantmap__44c7_s_p4_0,
  119399. 17,
  119400. 17
  119401. };
  119402. static static_codebook _44c7_s_p4_0 = {
  119403. 2, 289,
  119404. _vq_lengthlist__44c7_s_p4_0,
  119405. 1, -529530880, 1611661312, 5, 0,
  119406. _vq_quantlist__44c7_s_p4_0,
  119407. NULL,
  119408. &_vq_auxt__44c7_s_p4_0,
  119409. NULL,
  119410. 0
  119411. };
  119412. static long _vq_quantlist__44c7_s_p5_0[] = {
  119413. 1,
  119414. 0,
  119415. 2,
  119416. };
  119417. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119418. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119419. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119420. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119421. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119422. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119423. 12,
  119424. };
  119425. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119426. -5.5, 5.5,
  119427. };
  119428. static long _vq_quantmap__44c7_s_p5_0[] = {
  119429. 1, 0, 2,
  119430. };
  119431. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119432. _vq_quantthresh__44c7_s_p5_0,
  119433. _vq_quantmap__44c7_s_p5_0,
  119434. 3,
  119435. 3
  119436. };
  119437. static static_codebook _44c7_s_p5_0 = {
  119438. 4, 81,
  119439. _vq_lengthlist__44c7_s_p5_0,
  119440. 1, -529137664, 1618345984, 2, 0,
  119441. _vq_quantlist__44c7_s_p5_0,
  119442. NULL,
  119443. &_vq_auxt__44c7_s_p5_0,
  119444. NULL,
  119445. 0
  119446. };
  119447. static long _vq_quantlist__44c7_s_p5_1[] = {
  119448. 5,
  119449. 4,
  119450. 6,
  119451. 3,
  119452. 7,
  119453. 2,
  119454. 8,
  119455. 1,
  119456. 9,
  119457. 0,
  119458. 10,
  119459. };
  119460. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119461. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119462. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119463. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119464. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119465. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119466. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119467. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119468. 11,11,11, 7, 7, 8, 8, 8, 8,
  119469. };
  119470. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119471. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119472. 3.5, 4.5,
  119473. };
  119474. static long _vq_quantmap__44c7_s_p5_1[] = {
  119475. 9, 7, 5, 3, 1, 0, 2, 4,
  119476. 6, 8, 10,
  119477. };
  119478. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119479. _vq_quantthresh__44c7_s_p5_1,
  119480. _vq_quantmap__44c7_s_p5_1,
  119481. 11,
  119482. 11
  119483. };
  119484. static static_codebook _44c7_s_p5_1 = {
  119485. 2, 121,
  119486. _vq_lengthlist__44c7_s_p5_1,
  119487. 1, -531365888, 1611661312, 4, 0,
  119488. _vq_quantlist__44c7_s_p5_1,
  119489. NULL,
  119490. &_vq_auxt__44c7_s_p5_1,
  119491. NULL,
  119492. 0
  119493. };
  119494. static long _vq_quantlist__44c7_s_p6_0[] = {
  119495. 6,
  119496. 5,
  119497. 7,
  119498. 4,
  119499. 8,
  119500. 3,
  119501. 9,
  119502. 2,
  119503. 10,
  119504. 1,
  119505. 11,
  119506. 0,
  119507. 12,
  119508. };
  119509. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119510. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119511. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119512. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119513. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119514. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119515. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119520. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119521. };
  119522. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119523. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119524. 12.5, 17.5, 22.5, 27.5,
  119525. };
  119526. static long _vq_quantmap__44c7_s_p6_0[] = {
  119527. 11, 9, 7, 5, 3, 1, 0, 2,
  119528. 4, 6, 8, 10, 12,
  119529. };
  119530. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119531. _vq_quantthresh__44c7_s_p6_0,
  119532. _vq_quantmap__44c7_s_p6_0,
  119533. 13,
  119534. 13
  119535. };
  119536. static static_codebook _44c7_s_p6_0 = {
  119537. 2, 169,
  119538. _vq_lengthlist__44c7_s_p6_0,
  119539. 1, -526516224, 1616117760, 4, 0,
  119540. _vq_quantlist__44c7_s_p6_0,
  119541. NULL,
  119542. &_vq_auxt__44c7_s_p6_0,
  119543. NULL,
  119544. 0
  119545. };
  119546. static long _vq_quantlist__44c7_s_p6_1[] = {
  119547. 2,
  119548. 1,
  119549. 3,
  119550. 0,
  119551. 4,
  119552. };
  119553. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119554. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119555. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119556. };
  119557. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119558. -1.5, -0.5, 0.5, 1.5,
  119559. };
  119560. static long _vq_quantmap__44c7_s_p6_1[] = {
  119561. 3, 1, 0, 2, 4,
  119562. };
  119563. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119564. _vq_quantthresh__44c7_s_p6_1,
  119565. _vq_quantmap__44c7_s_p6_1,
  119566. 5,
  119567. 5
  119568. };
  119569. static static_codebook _44c7_s_p6_1 = {
  119570. 2, 25,
  119571. _vq_lengthlist__44c7_s_p6_1,
  119572. 1, -533725184, 1611661312, 3, 0,
  119573. _vq_quantlist__44c7_s_p6_1,
  119574. NULL,
  119575. &_vq_auxt__44c7_s_p6_1,
  119576. NULL,
  119577. 0
  119578. };
  119579. static long _vq_quantlist__44c7_s_p7_0[] = {
  119580. 6,
  119581. 5,
  119582. 7,
  119583. 4,
  119584. 8,
  119585. 3,
  119586. 9,
  119587. 2,
  119588. 10,
  119589. 1,
  119590. 11,
  119591. 0,
  119592. 12,
  119593. };
  119594. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119595. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119596. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119597. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119598. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119599. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119600. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119601. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119602. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119603. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119604. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119605. 19,13,13,13,13,14,14,15,15,
  119606. };
  119607. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119608. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119609. 27.5, 38.5, 49.5, 60.5,
  119610. };
  119611. static long _vq_quantmap__44c7_s_p7_0[] = {
  119612. 11, 9, 7, 5, 3, 1, 0, 2,
  119613. 4, 6, 8, 10, 12,
  119614. };
  119615. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119616. _vq_quantthresh__44c7_s_p7_0,
  119617. _vq_quantmap__44c7_s_p7_0,
  119618. 13,
  119619. 13
  119620. };
  119621. static static_codebook _44c7_s_p7_0 = {
  119622. 2, 169,
  119623. _vq_lengthlist__44c7_s_p7_0,
  119624. 1, -523206656, 1618345984, 4, 0,
  119625. _vq_quantlist__44c7_s_p7_0,
  119626. NULL,
  119627. &_vq_auxt__44c7_s_p7_0,
  119628. NULL,
  119629. 0
  119630. };
  119631. static long _vq_quantlist__44c7_s_p7_1[] = {
  119632. 5,
  119633. 4,
  119634. 6,
  119635. 3,
  119636. 7,
  119637. 2,
  119638. 8,
  119639. 1,
  119640. 9,
  119641. 0,
  119642. 10,
  119643. };
  119644. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119645. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119646. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119647. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119648. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119649. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119650. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119651. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119652. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119653. };
  119654. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119655. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119656. 3.5, 4.5,
  119657. };
  119658. static long _vq_quantmap__44c7_s_p7_1[] = {
  119659. 9, 7, 5, 3, 1, 0, 2, 4,
  119660. 6, 8, 10,
  119661. };
  119662. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119663. _vq_quantthresh__44c7_s_p7_1,
  119664. _vq_quantmap__44c7_s_p7_1,
  119665. 11,
  119666. 11
  119667. };
  119668. static static_codebook _44c7_s_p7_1 = {
  119669. 2, 121,
  119670. _vq_lengthlist__44c7_s_p7_1,
  119671. 1, -531365888, 1611661312, 4, 0,
  119672. _vq_quantlist__44c7_s_p7_1,
  119673. NULL,
  119674. &_vq_auxt__44c7_s_p7_1,
  119675. NULL,
  119676. 0
  119677. };
  119678. static long _vq_quantlist__44c7_s_p8_0[] = {
  119679. 7,
  119680. 6,
  119681. 8,
  119682. 5,
  119683. 9,
  119684. 4,
  119685. 10,
  119686. 3,
  119687. 11,
  119688. 2,
  119689. 12,
  119690. 1,
  119691. 13,
  119692. 0,
  119693. 14,
  119694. };
  119695. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119696. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119697. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119698. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119699. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119700. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119701. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119702. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119703. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119704. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119705. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119706. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119707. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119708. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119709. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119710. 14,
  119711. };
  119712. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119713. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119714. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119715. };
  119716. static long _vq_quantmap__44c7_s_p8_0[] = {
  119717. 13, 11, 9, 7, 5, 3, 1, 0,
  119718. 2, 4, 6, 8, 10, 12, 14,
  119719. };
  119720. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119721. _vq_quantthresh__44c7_s_p8_0,
  119722. _vq_quantmap__44c7_s_p8_0,
  119723. 15,
  119724. 15
  119725. };
  119726. static static_codebook _44c7_s_p8_0 = {
  119727. 2, 225,
  119728. _vq_lengthlist__44c7_s_p8_0,
  119729. 1, -520986624, 1620377600, 4, 0,
  119730. _vq_quantlist__44c7_s_p8_0,
  119731. NULL,
  119732. &_vq_auxt__44c7_s_p8_0,
  119733. NULL,
  119734. 0
  119735. };
  119736. static long _vq_quantlist__44c7_s_p8_1[] = {
  119737. 10,
  119738. 9,
  119739. 11,
  119740. 8,
  119741. 12,
  119742. 7,
  119743. 13,
  119744. 6,
  119745. 14,
  119746. 5,
  119747. 15,
  119748. 4,
  119749. 16,
  119750. 3,
  119751. 17,
  119752. 2,
  119753. 18,
  119754. 1,
  119755. 19,
  119756. 0,
  119757. 20,
  119758. };
  119759. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119760. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119761. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119762. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119763. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119764. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119765. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119766. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119767. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119768. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119769. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119770. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119771. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119772. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119773. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119774. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119775. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119776. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119777. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119778. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119779. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119780. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119781. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119782. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119783. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119784. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119785. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119786. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119787. 10,10,10,10,10,10,10,10,10,
  119788. };
  119789. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119790. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119791. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119792. 6.5, 7.5, 8.5, 9.5,
  119793. };
  119794. static long _vq_quantmap__44c7_s_p8_1[] = {
  119795. 19, 17, 15, 13, 11, 9, 7, 5,
  119796. 3, 1, 0, 2, 4, 6, 8, 10,
  119797. 12, 14, 16, 18, 20,
  119798. };
  119799. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119800. _vq_quantthresh__44c7_s_p8_1,
  119801. _vq_quantmap__44c7_s_p8_1,
  119802. 21,
  119803. 21
  119804. };
  119805. static static_codebook _44c7_s_p8_1 = {
  119806. 2, 441,
  119807. _vq_lengthlist__44c7_s_p8_1,
  119808. 1, -529268736, 1611661312, 5, 0,
  119809. _vq_quantlist__44c7_s_p8_1,
  119810. NULL,
  119811. &_vq_auxt__44c7_s_p8_1,
  119812. NULL,
  119813. 0
  119814. };
  119815. static long _vq_quantlist__44c7_s_p9_0[] = {
  119816. 6,
  119817. 5,
  119818. 7,
  119819. 4,
  119820. 8,
  119821. 3,
  119822. 9,
  119823. 2,
  119824. 10,
  119825. 1,
  119826. 11,
  119827. 0,
  119828. 12,
  119829. };
  119830. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119831. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119832. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119833. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119834. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119835. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119836. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119837. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119838. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119839. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119840. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119841. 11,11,11,11,11,11,11,11,11,
  119842. };
  119843. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119844. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119845. 1592.5, 2229.5, 2866.5, 3503.5,
  119846. };
  119847. static long _vq_quantmap__44c7_s_p9_0[] = {
  119848. 11, 9, 7, 5, 3, 1, 0, 2,
  119849. 4, 6, 8, 10, 12,
  119850. };
  119851. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119852. _vq_quantthresh__44c7_s_p9_0,
  119853. _vq_quantmap__44c7_s_p9_0,
  119854. 13,
  119855. 13
  119856. };
  119857. static static_codebook _44c7_s_p9_0 = {
  119858. 2, 169,
  119859. _vq_lengthlist__44c7_s_p9_0,
  119860. 1, -511845376, 1630791680, 4, 0,
  119861. _vq_quantlist__44c7_s_p9_0,
  119862. NULL,
  119863. &_vq_auxt__44c7_s_p9_0,
  119864. NULL,
  119865. 0
  119866. };
  119867. static long _vq_quantlist__44c7_s_p9_1[] = {
  119868. 6,
  119869. 5,
  119870. 7,
  119871. 4,
  119872. 8,
  119873. 3,
  119874. 9,
  119875. 2,
  119876. 10,
  119877. 1,
  119878. 11,
  119879. 0,
  119880. 12,
  119881. };
  119882. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119883. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119884. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119885. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119886. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119887. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119888. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119889. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119890. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119891. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119892. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119893. 15,11,11,10,10,12,12,12,12,
  119894. };
  119895. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119896. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119897. 122.5, 171.5, 220.5, 269.5,
  119898. };
  119899. static long _vq_quantmap__44c7_s_p9_1[] = {
  119900. 11, 9, 7, 5, 3, 1, 0, 2,
  119901. 4, 6, 8, 10, 12,
  119902. };
  119903. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119904. _vq_quantthresh__44c7_s_p9_1,
  119905. _vq_quantmap__44c7_s_p9_1,
  119906. 13,
  119907. 13
  119908. };
  119909. static static_codebook _44c7_s_p9_1 = {
  119910. 2, 169,
  119911. _vq_lengthlist__44c7_s_p9_1,
  119912. 1, -518889472, 1622704128, 4, 0,
  119913. _vq_quantlist__44c7_s_p9_1,
  119914. NULL,
  119915. &_vq_auxt__44c7_s_p9_1,
  119916. NULL,
  119917. 0
  119918. };
  119919. static long _vq_quantlist__44c7_s_p9_2[] = {
  119920. 24,
  119921. 23,
  119922. 25,
  119923. 22,
  119924. 26,
  119925. 21,
  119926. 27,
  119927. 20,
  119928. 28,
  119929. 19,
  119930. 29,
  119931. 18,
  119932. 30,
  119933. 17,
  119934. 31,
  119935. 16,
  119936. 32,
  119937. 15,
  119938. 33,
  119939. 14,
  119940. 34,
  119941. 13,
  119942. 35,
  119943. 12,
  119944. 36,
  119945. 11,
  119946. 37,
  119947. 10,
  119948. 38,
  119949. 9,
  119950. 39,
  119951. 8,
  119952. 40,
  119953. 7,
  119954. 41,
  119955. 6,
  119956. 42,
  119957. 5,
  119958. 43,
  119959. 4,
  119960. 44,
  119961. 3,
  119962. 45,
  119963. 2,
  119964. 46,
  119965. 1,
  119966. 47,
  119967. 0,
  119968. 48,
  119969. };
  119970. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119971. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119972. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119973. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119974. 7,
  119975. };
  119976. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119977. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119978. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119979. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119980. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119981. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119982. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119983. };
  119984. static long _vq_quantmap__44c7_s_p9_2[] = {
  119985. 47, 45, 43, 41, 39, 37, 35, 33,
  119986. 31, 29, 27, 25, 23, 21, 19, 17,
  119987. 15, 13, 11, 9, 7, 5, 3, 1,
  119988. 0, 2, 4, 6, 8, 10, 12, 14,
  119989. 16, 18, 20, 22, 24, 26, 28, 30,
  119990. 32, 34, 36, 38, 40, 42, 44, 46,
  119991. 48,
  119992. };
  119993. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119994. _vq_quantthresh__44c7_s_p9_2,
  119995. _vq_quantmap__44c7_s_p9_2,
  119996. 49,
  119997. 49
  119998. };
  119999. static static_codebook _44c7_s_p9_2 = {
  120000. 1, 49,
  120001. _vq_lengthlist__44c7_s_p9_2,
  120002. 1, -526909440, 1611661312, 6, 0,
  120003. _vq_quantlist__44c7_s_p9_2,
  120004. NULL,
  120005. &_vq_auxt__44c7_s_p9_2,
  120006. NULL,
  120007. 0
  120008. };
  120009. static long _huff_lengthlist__44c7_s_short[] = {
  120010. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  120011. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  120012. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  120013. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  120014. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  120015. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  120016. 10, 9,11,14,
  120017. };
  120018. static static_codebook _huff_book__44c7_s_short = {
  120019. 2, 100,
  120020. _huff_lengthlist__44c7_s_short,
  120021. 0, 0, 0, 0, 0,
  120022. NULL,
  120023. NULL,
  120024. NULL,
  120025. NULL,
  120026. 0
  120027. };
  120028. static long _huff_lengthlist__44c8_s_long[] = {
  120029. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  120030. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  120031. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  120032. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  120033. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  120034. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  120035. 11, 9, 9,10,
  120036. };
  120037. static static_codebook _huff_book__44c8_s_long = {
  120038. 2, 100,
  120039. _huff_lengthlist__44c8_s_long,
  120040. 0, 0, 0, 0, 0,
  120041. NULL,
  120042. NULL,
  120043. NULL,
  120044. NULL,
  120045. 0
  120046. };
  120047. static long _vq_quantlist__44c8_s_p1_0[] = {
  120048. 1,
  120049. 0,
  120050. 2,
  120051. };
  120052. static long _vq_lengthlist__44c8_s_p1_0[] = {
  120053. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  120054. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120055. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  120056. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120057. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  120058. 8,
  120059. };
  120060. static float _vq_quantthresh__44c8_s_p1_0[] = {
  120061. -0.5, 0.5,
  120062. };
  120063. static long _vq_quantmap__44c8_s_p1_0[] = {
  120064. 1, 0, 2,
  120065. };
  120066. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  120067. _vq_quantthresh__44c8_s_p1_0,
  120068. _vq_quantmap__44c8_s_p1_0,
  120069. 3,
  120070. 3
  120071. };
  120072. static static_codebook _44c8_s_p1_0 = {
  120073. 4, 81,
  120074. _vq_lengthlist__44c8_s_p1_0,
  120075. 1, -535822336, 1611661312, 2, 0,
  120076. _vq_quantlist__44c8_s_p1_0,
  120077. NULL,
  120078. &_vq_auxt__44c8_s_p1_0,
  120079. NULL,
  120080. 0
  120081. };
  120082. static long _vq_quantlist__44c8_s_p2_0[] = {
  120083. 2,
  120084. 1,
  120085. 3,
  120086. 0,
  120087. 4,
  120088. };
  120089. static long _vq_lengthlist__44c8_s_p2_0[] = {
  120090. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120091. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  120092. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  120093. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  120094. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  120095. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  120096. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  120097. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  120098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120099. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  120100. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  120101. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  120102. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  120103. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  120104. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  120105. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  120106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120107. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  120108. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  120109. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  120110. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  120111. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  120112. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  120113. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120115. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  120116. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  120117. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  120118. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  120119. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  120120. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  120121. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120126. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  120127. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  120128. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  120129. 13,
  120130. };
  120131. static float _vq_quantthresh__44c8_s_p2_0[] = {
  120132. -1.5, -0.5, 0.5, 1.5,
  120133. };
  120134. static long _vq_quantmap__44c8_s_p2_0[] = {
  120135. 3, 1, 0, 2, 4,
  120136. };
  120137. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  120138. _vq_quantthresh__44c8_s_p2_0,
  120139. _vq_quantmap__44c8_s_p2_0,
  120140. 5,
  120141. 5
  120142. };
  120143. static static_codebook _44c8_s_p2_0 = {
  120144. 4, 625,
  120145. _vq_lengthlist__44c8_s_p2_0,
  120146. 1, -533725184, 1611661312, 3, 0,
  120147. _vq_quantlist__44c8_s_p2_0,
  120148. NULL,
  120149. &_vq_auxt__44c8_s_p2_0,
  120150. NULL,
  120151. 0
  120152. };
  120153. static long _vq_quantlist__44c8_s_p3_0[] = {
  120154. 4,
  120155. 3,
  120156. 5,
  120157. 2,
  120158. 6,
  120159. 1,
  120160. 7,
  120161. 0,
  120162. 8,
  120163. };
  120164. static long _vq_lengthlist__44c8_s_p3_0[] = {
  120165. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  120166. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  120167. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  120168. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  120169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120170. 0,
  120171. };
  120172. static float _vq_quantthresh__44c8_s_p3_0[] = {
  120173. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120174. };
  120175. static long _vq_quantmap__44c8_s_p3_0[] = {
  120176. 7, 5, 3, 1, 0, 2, 4, 6,
  120177. 8,
  120178. };
  120179. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  120180. _vq_quantthresh__44c8_s_p3_0,
  120181. _vq_quantmap__44c8_s_p3_0,
  120182. 9,
  120183. 9
  120184. };
  120185. static static_codebook _44c8_s_p3_0 = {
  120186. 2, 81,
  120187. _vq_lengthlist__44c8_s_p3_0,
  120188. 1, -531628032, 1611661312, 4, 0,
  120189. _vq_quantlist__44c8_s_p3_0,
  120190. NULL,
  120191. &_vq_auxt__44c8_s_p3_0,
  120192. NULL,
  120193. 0
  120194. };
  120195. static long _vq_quantlist__44c8_s_p4_0[] = {
  120196. 8,
  120197. 7,
  120198. 9,
  120199. 6,
  120200. 10,
  120201. 5,
  120202. 11,
  120203. 4,
  120204. 12,
  120205. 3,
  120206. 13,
  120207. 2,
  120208. 14,
  120209. 1,
  120210. 15,
  120211. 0,
  120212. 16,
  120213. };
  120214. static long _vq_lengthlist__44c8_s_p4_0[] = {
  120215. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  120216. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  120217. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120218. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  120219. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  120220. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  120221. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  120222. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120223. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120224. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  120225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120233. 0,
  120234. };
  120235. static float _vq_quantthresh__44c8_s_p4_0[] = {
  120236. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120237. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120238. };
  120239. static long _vq_quantmap__44c8_s_p4_0[] = {
  120240. 15, 13, 11, 9, 7, 5, 3, 1,
  120241. 0, 2, 4, 6, 8, 10, 12, 14,
  120242. 16,
  120243. };
  120244. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  120245. _vq_quantthresh__44c8_s_p4_0,
  120246. _vq_quantmap__44c8_s_p4_0,
  120247. 17,
  120248. 17
  120249. };
  120250. static static_codebook _44c8_s_p4_0 = {
  120251. 2, 289,
  120252. _vq_lengthlist__44c8_s_p4_0,
  120253. 1, -529530880, 1611661312, 5, 0,
  120254. _vq_quantlist__44c8_s_p4_0,
  120255. NULL,
  120256. &_vq_auxt__44c8_s_p4_0,
  120257. NULL,
  120258. 0
  120259. };
  120260. static long _vq_quantlist__44c8_s_p5_0[] = {
  120261. 1,
  120262. 0,
  120263. 2,
  120264. };
  120265. static long _vq_lengthlist__44c8_s_p5_0[] = {
  120266. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  120267. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  120268. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  120269. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  120270. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  120271. 12,
  120272. };
  120273. static float _vq_quantthresh__44c8_s_p5_0[] = {
  120274. -5.5, 5.5,
  120275. };
  120276. static long _vq_quantmap__44c8_s_p5_0[] = {
  120277. 1, 0, 2,
  120278. };
  120279. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  120280. _vq_quantthresh__44c8_s_p5_0,
  120281. _vq_quantmap__44c8_s_p5_0,
  120282. 3,
  120283. 3
  120284. };
  120285. static static_codebook _44c8_s_p5_0 = {
  120286. 4, 81,
  120287. _vq_lengthlist__44c8_s_p5_0,
  120288. 1, -529137664, 1618345984, 2, 0,
  120289. _vq_quantlist__44c8_s_p5_0,
  120290. NULL,
  120291. &_vq_auxt__44c8_s_p5_0,
  120292. NULL,
  120293. 0
  120294. };
  120295. static long _vq_quantlist__44c8_s_p5_1[] = {
  120296. 5,
  120297. 4,
  120298. 6,
  120299. 3,
  120300. 7,
  120301. 2,
  120302. 8,
  120303. 1,
  120304. 9,
  120305. 0,
  120306. 10,
  120307. };
  120308. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120309. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120310. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120311. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120312. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120313. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120314. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120315. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120316. 11,11,11, 7, 7, 7, 7, 8, 8,
  120317. };
  120318. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120319. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120320. 3.5, 4.5,
  120321. };
  120322. static long _vq_quantmap__44c8_s_p5_1[] = {
  120323. 9, 7, 5, 3, 1, 0, 2, 4,
  120324. 6, 8, 10,
  120325. };
  120326. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120327. _vq_quantthresh__44c8_s_p5_1,
  120328. _vq_quantmap__44c8_s_p5_1,
  120329. 11,
  120330. 11
  120331. };
  120332. static static_codebook _44c8_s_p5_1 = {
  120333. 2, 121,
  120334. _vq_lengthlist__44c8_s_p5_1,
  120335. 1, -531365888, 1611661312, 4, 0,
  120336. _vq_quantlist__44c8_s_p5_1,
  120337. NULL,
  120338. &_vq_auxt__44c8_s_p5_1,
  120339. NULL,
  120340. 0
  120341. };
  120342. static long _vq_quantlist__44c8_s_p6_0[] = {
  120343. 6,
  120344. 5,
  120345. 7,
  120346. 4,
  120347. 8,
  120348. 3,
  120349. 9,
  120350. 2,
  120351. 10,
  120352. 1,
  120353. 11,
  120354. 0,
  120355. 12,
  120356. };
  120357. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120358. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120359. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120360. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120361. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120362. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120363. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120368. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120369. };
  120370. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120371. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120372. 12.5, 17.5, 22.5, 27.5,
  120373. };
  120374. static long _vq_quantmap__44c8_s_p6_0[] = {
  120375. 11, 9, 7, 5, 3, 1, 0, 2,
  120376. 4, 6, 8, 10, 12,
  120377. };
  120378. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120379. _vq_quantthresh__44c8_s_p6_0,
  120380. _vq_quantmap__44c8_s_p6_0,
  120381. 13,
  120382. 13
  120383. };
  120384. static static_codebook _44c8_s_p6_0 = {
  120385. 2, 169,
  120386. _vq_lengthlist__44c8_s_p6_0,
  120387. 1, -526516224, 1616117760, 4, 0,
  120388. _vq_quantlist__44c8_s_p6_0,
  120389. NULL,
  120390. &_vq_auxt__44c8_s_p6_0,
  120391. NULL,
  120392. 0
  120393. };
  120394. static long _vq_quantlist__44c8_s_p6_1[] = {
  120395. 2,
  120396. 1,
  120397. 3,
  120398. 0,
  120399. 4,
  120400. };
  120401. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120402. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120403. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120404. };
  120405. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120406. -1.5, -0.5, 0.5, 1.5,
  120407. };
  120408. static long _vq_quantmap__44c8_s_p6_1[] = {
  120409. 3, 1, 0, 2, 4,
  120410. };
  120411. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120412. _vq_quantthresh__44c8_s_p6_1,
  120413. _vq_quantmap__44c8_s_p6_1,
  120414. 5,
  120415. 5
  120416. };
  120417. static static_codebook _44c8_s_p6_1 = {
  120418. 2, 25,
  120419. _vq_lengthlist__44c8_s_p6_1,
  120420. 1, -533725184, 1611661312, 3, 0,
  120421. _vq_quantlist__44c8_s_p6_1,
  120422. NULL,
  120423. &_vq_auxt__44c8_s_p6_1,
  120424. NULL,
  120425. 0
  120426. };
  120427. static long _vq_quantlist__44c8_s_p7_0[] = {
  120428. 6,
  120429. 5,
  120430. 7,
  120431. 4,
  120432. 8,
  120433. 3,
  120434. 9,
  120435. 2,
  120436. 10,
  120437. 1,
  120438. 11,
  120439. 0,
  120440. 12,
  120441. };
  120442. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120443. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120444. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120445. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120446. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120447. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120448. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120449. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120450. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120451. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120452. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120453. 20,13,13,13,13,14,13,15,15,
  120454. };
  120455. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120456. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120457. 27.5, 38.5, 49.5, 60.5,
  120458. };
  120459. static long _vq_quantmap__44c8_s_p7_0[] = {
  120460. 11, 9, 7, 5, 3, 1, 0, 2,
  120461. 4, 6, 8, 10, 12,
  120462. };
  120463. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120464. _vq_quantthresh__44c8_s_p7_0,
  120465. _vq_quantmap__44c8_s_p7_0,
  120466. 13,
  120467. 13
  120468. };
  120469. static static_codebook _44c8_s_p7_0 = {
  120470. 2, 169,
  120471. _vq_lengthlist__44c8_s_p7_0,
  120472. 1, -523206656, 1618345984, 4, 0,
  120473. _vq_quantlist__44c8_s_p7_0,
  120474. NULL,
  120475. &_vq_auxt__44c8_s_p7_0,
  120476. NULL,
  120477. 0
  120478. };
  120479. static long _vq_quantlist__44c8_s_p7_1[] = {
  120480. 5,
  120481. 4,
  120482. 6,
  120483. 3,
  120484. 7,
  120485. 2,
  120486. 8,
  120487. 1,
  120488. 9,
  120489. 0,
  120490. 10,
  120491. };
  120492. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120493. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120494. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120495. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120496. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120497. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120498. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120499. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120500. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120501. };
  120502. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120503. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120504. 3.5, 4.5,
  120505. };
  120506. static long _vq_quantmap__44c8_s_p7_1[] = {
  120507. 9, 7, 5, 3, 1, 0, 2, 4,
  120508. 6, 8, 10,
  120509. };
  120510. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120511. _vq_quantthresh__44c8_s_p7_1,
  120512. _vq_quantmap__44c8_s_p7_1,
  120513. 11,
  120514. 11
  120515. };
  120516. static static_codebook _44c8_s_p7_1 = {
  120517. 2, 121,
  120518. _vq_lengthlist__44c8_s_p7_1,
  120519. 1, -531365888, 1611661312, 4, 0,
  120520. _vq_quantlist__44c8_s_p7_1,
  120521. NULL,
  120522. &_vq_auxt__44c8_s_p7_1,
  120523. NULL,
  120524. 0
  120525. };
  120526. static long _vq_quantlist__44c8_s_p8_0[] = {
  120527. 7,
  120528. 6,
  120529. 8,
  120530. 5,
  120531. 9,
  120532. 4,
  120533. 10,
  120534. 3,
  120535. 11,
  120536. 2,
  120537. 12,
  120538. 1,
  120539. 13,
  120540. 0,
  120541. 14,
  120542. };
  120543. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120544. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120545. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120546. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120547. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120548. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120549. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120550. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120551. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120552. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120553. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120554. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120555. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120556. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120557. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120558. 15,
  120559. };
  120560. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120561. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120562. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120563. };
  120564. static long _vq_quantmap__44c8_s_p8_0[] = {
  120565. 13, 11, 9, 7, 5, 3, 1, 0,
  120566. 2, 4, 6, 8, 10, 12, 14,
  120567. };
  120568. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120569. _vq_quantthresh__44c8_s_p8_0,
  120570. _vq_quantmap__44c8_s_p8_0,
  120571. 15,
  120572. 15
  120573. };
  120574. static static_codebook _44c8_s_p8_0 = {
  120575. 2, 225,
  120576. _vq_lengthlist__44c8_s_p8_0,
  120577. 1, -520986624, 1620377600, 4, 0,
  120578. _vq_quantlist__44c8_s_p8_0,
  120579. NULL,
  120580. &_vq_auxt__44c8_s_p8_0,
  120581. NULL,
  120582. 0
  120583. };
  120584. static long _vq_quantlist__44c8_s_p8_1[] = {
  120585. 10,
  120586. 9,
  120587. 11,
  120588. 8,
  120589. 12,
  120590. 7,
  120591. 13,
  120592. 6,
  120593. 14,
  120594. 5,
  120595. 15,
  120596. 4,
  120597. 16,
  120598. 3,
  120599. 17,
  120600. 2,
  120601. 18,
  120602. 1,
  120603. 19,
  120604. 0,
  120605. 20,
  120606. };
  120607. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120608. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120609. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120610. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120611. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120612. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120613. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120614. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120615. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120616. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120617. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120618. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120619. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120620. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120621. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120622. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120623. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120624. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120625. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120626. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120627. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120628. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120629. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120630. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120631. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120632. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120633. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120634. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120635. 10, 9, 9,10,10, 9,10, 9, 9,
  120636. };
  120637. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120638. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120639. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120640. 6.5, 7.5, 8.5, 9.5,
  120641. };
  120642. static long _vq_quantmap__44c8_s_p8_1[] = {
  120643. 19, 17, 15, 13, 11, 9, 7, 5,
  120644. 3, 1, 0, 2, 4, 6, 8, 10,
  120645. 12, 14, 16, 18, 20,
  120646. };
  120647. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120648. _vq_quantthresh__44c8_s_p8_1,
  120649. _vq_quantmap__44c8_s_p8_1,
  120650. 21,
  120651. 21
  120652. };
  120653. static static_codebook _44c8_s_p8_1 = {
  120654. 2, 441,
  120655. _vq_lengthlist__44c8_s_p8_1,
  120656. 1, -529268736, 1611661312, 5, 0,
  120657. _vq_quantlist__44c8_s_p8_1,
  120658. NULL,
  120659. &_vq_auxt__44c8_s_p8_1,
  120660. NULL,
  120661. 0
  120662. };
  120663. static long _vq_quantlist__44c8_s_p9_0[] = {
  120664. 8,
  120665. 7,
  120666. 9,
  120667. 6,
  120668. 10,
  120669. 5,
  120670. 11,
  120671. 4,
  120672. 12,
  120673. 3,
  120674. 13,
  120675. 2,
  120676. 14,
  120677. 1,
  120678. 15,
  120679. 0,
  120680. 16,
  120681. };
  120682. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120683. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120684. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120685. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120686. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120687. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120688. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120689. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120690. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120691. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120692. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120693. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120694. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120695. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120696. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120697. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120698. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120699. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120700. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120701. 10,
  120702. };
  120703. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120704. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120705. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120706. };
  120707. static long _vq_quantmap__44c8_s_p9_0[] = {
  120708. 15, 13, 11, 9, 7, 5, 3, 1,
  120709. 0, 2, 4, 6, 8, 10, 12, 14,
  120710. 16,
  120711. };
  120712. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120713. _vq_quantthresh__44c8_s_p9_0,
  120714. _vq_quantmap__44c8_s_p9_0,
  120715. 17,
  120716. 17
  120717. };
  120718. static static_codebook _44c8_s_p9_0 = {
  120719. 2, 289,
  120720. _vq_lengthlist__44c8_s_p9_0,
  120721. 1, -509798400, 1631393792, 5, 0,
  120722. _vq_quantlist__44c8_s_p9_0,
  120723. NULL,
  120724. &_vq_auxt__44c8_s_p9_0,
  120725. NULL,
  120726. 0
  120727. };
  120728. static long _vq_quantlist__44c8_s_p9_1[] = {
  120729. 9,
  120730. 8,
  120731. 10,
  120732. 7,
  120733. 11,
  120734. 6,
  120735. 12,
  120736. 5,
  120737. 13,
  120738. 4,
  120739. 14,
  120740. 3,
  120741. 15,
  120742. 2,
  120743. 16,
  120744. 1,
  120745. 17,
  120746. 0,
  120747. 18,
  120748. };
  120749. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120750. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120751. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120752. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120753. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120754. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120755. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120756. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120757. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120758. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120759. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120760. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120761. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120762. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120763. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120764. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120765. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120766. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120767. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120768. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120769. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120770. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120771. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120772. 14,13,13,14,14,15,14,15,14,
  120773. };
  120774. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120775. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120776. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120777. 367.5, 416.5,
  120778. };
  120779. static long _vq_quantmap__44c8_s_p9_1[] = {
  120780. 17, 15, 13, 11, 9, 7, 5, 3,
  120781. 1, 0, 2, 4, 6, 8, 10, 12,
  120782. 14, 16, 18,
  120783. };
  120784. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120785. _vq_quantthresh__44c8_s_p9_1,
  120786. _vq_quantmap__44c8_s_p9_1,
  120787. 19,
  120788. 19
  120789. };
  120790. static static_codebook _44c8_s_p9_1 = {
  120791. 2, 361,
  120792. _vq_lengthlist__44c8_s_p9_1,
  120793. 1, -518287360, 1622704128, 5, 0,
  120794. _vq_quantlist__44c8_s_p9_1,
  120795. NULL,
  120796. &_vq_auxt__44c8_s_p9_1,
  120797. NULL,
  120798. 0
  120799. };
  120800. static long _vq_quantlist__44c8_s_p9_2[] = {
  120801. 24,
  120802. 23,
  120803. 25,
  120804. 22,
  120805. 26,
  120806. 21,
  120807. 27,
  120808. 20,
  120809. 28,
  120810. 19,
  120811. 29,
  120812. 18,
  120813. 30,
  120814. 17,
  120815. 31,
  120816. 16,
  120817. 32,
  120818. 15,
  120819. 33,
  120820. 14,
  120821. 34,
  120822. 13,
  120823. 35,
  120824. 12,
  120825. 36,
  120826. 11,
  120827. 37,
  120828. 10,
  120829. 38,
  120830. 9,
  120831. 39,
  120832. 8,
  120833. 40,
  120834. 7,
  120835. 41,
  120836. 6,
  120837. 42,
  120838. 5,
  120839. 43,
  120840. 4,
  120841. 44,
  120842. 3,
  120843. 45,
  120844. 2,
  120845. 46,
  120846. 1,
  120847. 47,
  120848. 0,
  120849. 48,
  120850. };
  120851. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120852. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120853. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120854. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120855. 7,
  120856. };
  120857. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120858. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120859. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120860. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120861. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120862. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120863. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120864. };
  120865. static long _vq_quantmap__44c8_s_p9_2[] = {
  120866. 47, 45, 43, 41, 39, 37, 35, 33,
  120867. 31, 29, 27, 25, 23, 21, 19, 17,
  120868. 15, 13, 11, 9, 7, 5, 3, 1,
  120869. 0, 2, 4, 6, 8, 10, 12, 14,
  120870. 16, 18, 20, 22, 24, 26, 28, 30,
  120871. 32, 34, 36, 38, 40, 42, 44, 46,
  120872. 48,
  120873. };
  120874. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120875. _vq_quantthresh__44c8_s_p9_2,
  120876. _vq_quantmap__44c8_s_p9_2,
  120877. 49,
  120878. 49
  120879. };
  120880. static static_codebook _44c8_s_p9_2 = {
  120881. 1, 49,
  120882. _vq_lengthlist__44c8_s_p9_2,
  120883. 1, -526909440, 1611661312, 6, 0,
  120884. _vq_quantlist__44c8_s_p9_2,
  120885. NULL,
  120886. &_vq_auxt__44c8_s_p9_2,
  120887. NULL,
  120888. 0
  120889. };
  120890. static long _huff_lengthlist__44c8_s_short[] = {
  120891. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120892. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120893. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120894. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120895. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120896. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120897. 10, 9,11,14,
  120898. };
  120899. static static_codebook _huff_book__44c8_s_short = {
  120900. 2, 100,
  120901. _huff_lengthlist__44c8_s_short,
  120902. 0, 0, 0, 0, 0,
  120903. NULL,
  120904. NULL,
  120905. NULL,
  120906. NULL,
  120907. 0
  120908. };
  120909. static long _huff_lengthlist__44c9_s_long[] = {
  120910. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120911. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120912. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120913. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120914. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120915. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120916. 10, 9, 8, 9,
  120917. };
  120918. static static_codebook _huff_book__44c9_s_long = {
  120919. 2, 100,
  120920. _huff_lengthlist__44c9_s_long,
  120921. 0, 0, 0, 0, 0,
  120922. NULL,
  120923. NULL,
  120924. NULL,
  120925. NULL,
  120926. 0
  120927. };
  120928. static long _vq_quantlist__44c9_s_p1_0[] = {
  120929. 1,
  120930. 0,
  120931. 2,
  120932. };
  120933. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120934. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120935. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120936. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120937. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120938. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120939. 7,
  120940. };
  120941. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120942. -0.5, 0.5,
  120943. };
  120944. static long _vq_quantmap__44c9_s_p1_0[] = {
  120945. 1, 0, 2,
  120946. };
  120947. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120948. _vq_quantthresh__44c9_s_p1_0,
  120949. _vq_quantmap__44c9_s_p1_0,
  120950. 3,
  120951. 3
  120952. };
  120953. static static_codebook _44c9_s_p1_0 = {
  120954. 4, 81,
  120955. _vq_lengthlist__44c9_s_p1_0,
  120956. 1, -535822336, 1611661312, 2, 0,
  120957. _vq_quantlist__44c9_s_p1_0,
  120958. NULL,
  120959. &_vq_auxt__44c9_s_p1_0,
  120960. NULL,
  120961. 0
  120962. };
  120963. static long _vq_quantlist__44c9_s_p2_0[] = {
  120964. 2,
  120965. 1,
  120966. 3,
  120967. 0,
  120968. 4,
  120969. };
  120970. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120971. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120972. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120973. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120974. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120975. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120976. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120977. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120978. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120980. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120981. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120982. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120983. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120984. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120985. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120986. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120988. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120989. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120990. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120991. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120992. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120993. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120994. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120996. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120997. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120998. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120999. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  121000. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  121001. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  121002. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  121007. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  121008. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  121009. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  121010. 12,
  121011. };
  121012. static float _vq_quantthresh__44c9_s_p2_0[] = {
  121013. -1.5, -0.5, 0.5, 1.5,
  121014. };
  121015. static long _vq_quantmap__44c9_s_p2_0[] = {
  121016. 3, 1, 0, 2, 4,
  121017. };
  121018. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  121019. _vq_quantthresh__44c9_s_p2_0,
  121020. _vq_quantmap__44c9_s_p2_0,
  121021. 5,
  121022. 5
  121023. };
  121024. static static_codebook _44c9_s_p2_0 = {
  121025. 4, 625,
  121026. _vq_lengthlist__44c9_s_p2_0,
  121027. 1, -533725184, 1611661312, 3, 0,
  121028. _vq_quantlist__44c9_s_p2_0,
  121029. NULL,
  121030. &_vq_auxt__44c9_s_p2_0,
  121031. NULL,
  121032. 0
  121033. };
  121034. static long _vq_quantlist__44c9_s_p3_0[] = {
  121035. 4,
  121036. 3,
  121037. 5,
  121038. 2,
  121039. 6,
  121040. 1,
  121041. 7,
  121042. 0,
  121043. 8,
  121044. };
  121045. static long _vq_lengthlist__44c9_s_p3_0[] = {
  121046. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  121047. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  121048. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  121049. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  121050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121051. 0,
  121052. };
  121053. static float _vq_quantthresh__44c9_s_p3_0[] = {
  121054. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121055. };
  121056. static long _vq_quantmap__44c9_s_p3_0[] = {
  121057. 7, 5, 3, 1, 0, 2, 4, 6,
  121058. 8,
  121059. };
  121060. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  121061. _vq_quantthresh__44c9_s_p3_0,
  121062. _vq_quantmap__44c9_s_p3_0,
  121063. 9,
  121064. 9
  121065. };
  121066. static static_codebook _44c9_s_p3_0 = {
  121067. 2, 81,
  121068. _vq_lengthlist__44c9_s_p3_0,
  121069. 1, -531628032, 1611661312, 4, 0,
  121070. _vq_quantlist__44c9_s_p3_0,
  121071. NULL,
  121072. &_vq_auxt__44c9_s_p3_0,
  121073. NULL,
  121074. 0
  121075. };
  121076. static long _vq_quantlist__44c9_s_p4_0[] = {
  121077. 8,
  121078. 7,
  121079. 9,
  121080. 6,
  121081. 10,
  121082. 5,
  121083. 11,
  121084. 4,
  121085. 12,
  121086. 3,
  121087. 13,
  121088. 2,
  121089. 14,
  121090. 1,
  121091. 15,
  121092. 0,
  121093. 16,
  121094. };
  121095. static long _vq_lengthlist__44c9_s_p4_0[] = {
  121096. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  121097. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  121098. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  121099. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  121100. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  121101. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  121102. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  121103. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  121104. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  121105. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  121106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121114. 0,
  121115. };
  121116. static float _vq_quantthresh__44c9_s_p4_0[] = {
  121117. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121118. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121119. };
  121120. static long _vq_quantmap__44c9_s_p4_0[] = {
  121121. 15, 13, 11, 9, 7, 5, 3, 1,
  121122. 0, 2, 4, 6, 8, 10, 12, 14,
  121123. 16,
  121124. };
  121125. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  121126. _vq_quantthresh__44c9_s_p4_0,
  121127. _vq_quantmap__44c9_s_p4_0,
  121128. 17,
  121129. 17
  121130. };
  121131. static static_codebook _44c9_s_p4_0 = {
  121132. 2, 289,
  121133. _vq_lengthlist__44c9_s_p4_0,
  121134. 1, -529530880, 1611661312, 5, 0,
  121135. _vq_quantlist__44c9_s_p4_0,
  121136. NULL,
  121137. &_vq_auxt__44c9_s_p4_0,
  121138. NULL,
  121139. 0
  121140. };
  121141. static long _vq_quantlist__44c9_s_p5_0[] = {
  121142. 1,
  121143. 0,
  121144. 2,
  121145. };
  121146. static long _vq_lengthlist__44c9_s_p5_0[] = {
  121147. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  121148. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  121149. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  121150. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  121151. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  121152. 12,
  121153. };
  121154. static float _vq_quantthresh__44c9_s_p5_0[] = {
  121155. -5.5, 5.5,
  121156. };
  121157. static long _vq_quantmap__44c9_s_p5_0[] = {
  121158. 1, 0, 2,
  121159. };
  121160. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  121161. _vq_quantthresh__44c9_s_p5_0,
  121162. _vq_quantmap__44c9_s_p5_0,
  121163. 3,
  121164. 3
  121165. };
  121166. static static_codebook _44c9_s_p5_0 = {
  121167. 4, 81,
  121168. _vq_lengthlist__44c9_s_p5_0,
  121169. 1, -529137664, 1618345984, 2, 0,
  121170. _vq_quantlist__44c9_s_p5_0,
  121171. NULL,
  121172. &_vq_auxt__44c9_s_p5_0,
  121173. NULL,
  121174. 0
  121175. };
  121176. static long _vq_quantlist__44c9_s_p5_1[] = {
  121177. 5,
  121178. 4,
  121179. 6,
  121180. 3,
  121181. 7,
  121182. 2,
  121183. 8,
  121184. 1,
  121185. 9,
  121186. 0,
  121187. 10,
  121188. };
  121189. static long _vq_lengthlist__44c9_s_p5_1[] = {
  121190. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  121191. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  121192. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  121193. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  121194. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  121195. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  121196. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  121197. 11,11,11, 7, 7, 7, 7, 7, 7,
  121198. };
  121199. static float _vq_quantthresh__44c9_s_p5_1[] = {
  121200. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121201. 3.5, 4.5,
  121202. };
  121203. static long _vq_quantmap__44c9_s_p5_1[] = {
  121204. 9, 7, 5, 3, 1, 0, 2, 4,
  121205. 6, 8, 10,
  121206. };
  121207. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  121208. _vq_quantthresh__44c9_s_p5_1,
  121209. _vq_quantmap__44c9_s_p5_1,
  121210. 11,
  121211. 11
  121212. };
  121213. static static_codebook _44c9_s_p5_1 = {
  121214. 2, 121,
  121215. _vq_lengthlist__44c9_s_p5_1,
  121216. 1, -531365888, 1611661312, 4, 0,
  121217. _vq_quantlist__44c9_s_p5_1,
  121218. NULL,
  121219. &_vq_auxt__44c9_s_p5_1,
  121220. NULL,
  121221. 0
  121222. };
  121223. static long _vq_quantlist__44c9_s_p6_0[] = {
  121224. 6,
  121225. 5,
  121226. 7,
  121227. 4,
  121228. 8,
  121229. 3,
  121230. 9,
  121231. 2,
  121232. 10,
  121233. 1,
  121234. 11,
  121235. 0,
  121236. 12,
  121237. };
  121238. static long _vq_lengthlist__44c9_s_p6_0[] = {
  121239. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  121240. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  121241. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  121242. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  121243. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  121244. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  121245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121249. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121250. };
  121251. static float _vq_quantthresh__44c9_s_p6_0[] = {
  121252. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121253. 12.5, 17.5, 22.5, 27.5,
  121254. };
  121255. static long _vq_quantmap__44c9_s_p6_0[] = {
  121256. 11, 9, 7, 5, 3, 1, 0, 2,
  121257. 4, 6, 8, 10, 12,
  121258. };
  121259. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  121260. _vq_quantthresh__44c9_s_p6_0,
  121261. _vq_quantmap__44c9_s_p6_0,
  121262. 13,
  121263. 13
  121264. };
  121265. static static_codebook _44c9_s_p6_0 = {
  121266. 2, 169,
  121267. _vq_lengthlist__44c9_s_p6_0,
  121268. 1, -526516224, 1616117760, 4, 0,
  121269. _vq_quantlist__44c9_s_p6_0,
  121270. NULL,
  121271. &_vq_auxt__44c9_s_p6_0,
  121272. NULL,
  121273. 0
  121274. };
  121275. static long _vq_quantlist__44c9_s_p6_1[] = {
  121276. 2,
  121277. 1,
  121278. 3,
  121279. 0,
  121280. 4,
  121281. };
  121282. static long _vq_lengthlist__44c9_s_p6_1[] = {
  121283. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  121284. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  121285. };
  121286. static float _vq_quantthresh__44c9_s_p6_1[] = {
  121287. -1.5, -0.5, 0.5, 1.5,
  121288. };
  121289. static long _vq_quantmap__44c9_s_p6_1[] = {
  121290. 3, 1, 0, 2, 4,
  121291. };
  121292. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  121293. _vq_quantthresh__44c9_s_p6_1,
  121294. _vq_quantmap__44c9_s_p6_1,
  121295. 5,
  121296. 5
  121297. };
  121298. static static_codebook _44c9_s_p6_1 = {
  121299. 2, 25,
  121300. _vq_lengthlist__44c9_s_p6_1,
  121301. 1, -533725184, 1611661312, 3, 0,
  121302. _vq_quantlist__44c9_s_p6_1,
  121303. NULL,
  121304. &_vq_auxt__44c9_s_p6_1,
  121305. NULL,
  121306. 0
  121307. };
  121308. static long _vq_quantlist__44c9_s_p7_0[] = {
  121309. 6,
  121310. 5,
  121311. 7,
  121312. 4,
  121313. 8,
  121314. 3,
  121315. 9,
  121316. 2,
  121317. 10,
  121318. 1,
  121319. 11,
  121320. 0,
  121321. 12,
  121322. };
  121323. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121324. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121325. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121326. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121327. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121328. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121329. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121330. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121331. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121332. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121333. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121334. 19,12,12,12,12,13,13,14,14,
  121335. };
  121336. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121337. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121338. 27.5, 38.5, 49.5, 60.5,
  121339. };
  121340. static long _vq_quantmap__44c9_s_p7_0[] = {
  121341. 11, 9, 7, 5, 3, 1, 0, 2,
  121342. 4, 6, 8, 10, 12,
  121343. };
  121344. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121345. _vq_quantthresh__44c9_s_p7_0,
  121346. _vq_quantmap__44c9_s_p7_0,
  121347. 13,
  121348. 13
  121349. };
  121350. static static_codebook _44c9_s_p7_0 = {
  121351. 2, 169,
  121352. _vq_lengthlist__44c9_s_p7_0,
  121353. 1, -523206656, 1618345984, 4, 0,
  121354. _vq_quantlist__44c9_s_p7_0,
  121355. NULL,
  121356. &_vq_auxt__44c9_s_p7_0,
  121357. NULL,
  121358. 0
  121359. };
  121360. static long _vq_quantlist__44c9_s_p7_1[] = {
  121361. 5,
  121362. 4,
  121363. 6,
  121364. 3,
  121365. 7,
  121366. 2,
  121367. 8,
  121368. 1,
  121369. 9,
  121370. 0,
  121371. 10,
  121372. };
  121373. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121374. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121375. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121376. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121377. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121378. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121379. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121380. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121381. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121382. };
  121383. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121384. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121385. 3.5, 4.5,
  121386. };
  121387. static long _vq_quantmap__44c9_s_p7_1[] = {
  121388. 9, 7, 5, 3, 1, 0, 2, 4,
  121389. 6, 8, 10,
  121390. };
  121391. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121392. _vq_quantthresh__44c9_s_p7_1,
  121393. _vq_quantmap__44c9_s_p7_1,
  121394. 11,
  121395. 11
  121396. };
  121397. static static_codebook _44c9_s_p7_1 = {
  121398. 2, 121,
  121399. _vq_lengthlist__44c9_s_p7_1,
  121400. 1, -531365888, 1611661312, 4, 0,
  121401. _vq_quantlist__44c9_s_p7_1,
  121402. NULL,
  121403. &_vq_auxt__44c9_s_p7_1,
  121404. NULL,
  121405. 0
  121406. };
  121407. static long _vq_quantlist__44c9_s_p8_0[] = {
  121408. 7,
  121409. 6,
  121410. 8,
  121411. 5,
  121412. 9,
  121413. 4,
  121414. 10,
  121415. 3,
  121416. 11,
  121417. 2,
  121418. 12,
  121419. 1,
  121420. 13,
  121421. 0,
  121422. 14,
  121423. };
  121424. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121425. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121426. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121427. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121428. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121429. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121430. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121431. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121432. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121433. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121434. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121435. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121436. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121437. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121438. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121439. 14,
  121440. };
  121441. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121442. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121443. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121444. };
  121445. static long _vq_quantmap__44c9_s_p8_0[] = {
  121446. 13, 11, 9, 7, 5, 3, 1, 0,
  121447. 2, 4, 6, 8, 10, 12, 14,
  121448. };
  121449. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121450. _vq_quantthresh__44c9_s_p8_0,
  121451. _vq_quantmap__44c9_s_p8_0,
  121452. 15,
  121453. 15
  121454. };
  121455. static static_codebook _44c9_s_p8_0 = {
  121456. 2, 225,
  121457. _vq_lengthlist__44c9_s_p8_0,
  121458. 1, -520986624, 1620377600, 4, 0,
  121459. _vq_quantlist__44c9_s_p8_0,
  121460. NULL,
  121461. &_vq_auxt__44c9_s_p8_0,
  121462. NULL,
  121463. 0
  121464. };
  121465. static long _vq_quantlist__44c9_s_p8_1[] = {
  121466. 10,
  121467. 9,
  121468. 11,
  121469. 8,
  121470. 12,
  121471. 7,
  121472. 13,
  121473. 6,
  121474. 14,
  121475. 5,
  121476. 15,
  121477. 4,
  121478. 16,
  121479. 3,
  121480. 17,
  121481. 2,
  121482. 18,
  121483. 1,
  121484. 19,
  121485. 0,
  121486. 20,
  121487. };
  121488. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121489. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121490. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121491. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121492. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121493. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121494. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121495. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121496. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121497. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121498. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121499. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121500. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121501. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121502. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121503. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121504. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121505. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121506. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121507. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121508. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121509. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121510. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121511. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121512. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121513. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121514. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121515. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121516. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121517. };
  121518. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121519. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121520. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121521. 6.5, 7.5, 8.5, 9.5,
  121522. };
  121523. static long _vq_quantmap__44c9_s_p8_1[] = {
  121524. 19, 17, 15, 13, 11, 9, 7, 5,
  121525. 3, 1, 0, 2, 4, 6, 8, 10,
  121526. 12, 14, 16, 18, 20,
  121527. };
  121528. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121529. _vq_quantthresh__44c9_s_p8_1,
  121530. _vq_quantmap__44c9_s_p8_1,
  121531. 21,
  121532. 21
  121533. };
  121534. static static_codebook _44c9_s_p8_1 = {
  121535. 2, 441,
  121536. _vq_lengthlist__44c9_s_p8_1,
  121537. 1, -529268736, 1611661312, 5, 0,
  121538. _vq_quantlist__44c9_s_p8_1,
  121539. NULL,
  121540. &_vq_auxt__44c9_s_p8_1,
  121541. NULL,
  121542. 0
  121543. };
  121544. static long _vq_quantlist__44c9_s_p9_0[] = {
  121545. 9,
  121546. 8,
  121547. 10,
  121548. 7,
  121549. 11,
  121550. 6,
  121551. 12,
  121552. 5,
  121553. 13,
  121554. 4,
  121555. 14,
  121556. 3,
  121557. 15,
  121558. 2,
  121559. 16,
  121560. 1,
  121561. 17,
  121562. 0,
  121563. 18,
  121564. };
  121565. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121566. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121567. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121568. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121569. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121570. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121571. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121572. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121573. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121574. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121575. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121576. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121577. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121578. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121579. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121580. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121581. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121582. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121583. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121584. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121585. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121586. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121587. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121588. 11,11,11,11,11,11,11,11,11,
  121589. };
  121590. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121591. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121592. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121593. 6982.5, 7913.5,
  121594. };
  121595. static long _vq_quantmap__44c9_s_p9_0[] = {
  121596. 17, 15, 13, 11, 9, 7, 5, 3,
  121597. 1, 0, 2, 4, 6, 8, 10, 12,
  121598. 14, 16, 18,
  121599. };
  121600. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121601. _vq_quantthresh__44c9_s_p9_0,
  121602. _vq_quantmap__44c9_s_p9_0,
  121603. 19,
  121604. 19
  121605. };
  121606. static static_codebook _44c9_s_p9_0 = {
  121607. 2, 361,
  121608. _vq_lengthlist__44c9_s_p9_0,
  121609. 1, -508535424, 1631393792, 5, 0,
  121610. _vq_quantlist__44c9_s_p9_0,
  121611. NULL,
  121612. &_vq_auxt__44c9_s_p9_0,
  121613. NULL,
  121614. 0
  121615. };
  121616. static long _vq_quantlist__44c9_s_p9_1[] = {
  121617. 9,
  121618. 8,
  121619. 10,
  121620. 7,
  121621. 11,
  121622. 6,
  121623. 12,
  121624. 5,
  121625. 13,
  121626. 4,
  121627. 14,
  121628. 3,
  121629. 15,
  121630. 2,
  121631. 16,
  121632. 1,
  121633. 17,
  121634. 0,
  121635. 18,
  121636. };
  121637. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121638. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121639. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121640. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121641. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121642. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121643. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121644. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121645. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121646. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121647. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121648. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121649. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121650. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121651. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121652. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121653. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121654. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121655. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121656. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121657. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121658. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121659. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121660. 13,13,13,14,13,14,15,15,15,
  121661. };
  121662. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121663. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121664. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121665. 367.5, 416.5,
  121666. };
  121667. static long _vq_quantmap__44c9_s_p9_1[] = {
  121668. 17, 15, 13, 11, 9, 7, 5, 3,
  121669. 1, 0, 2, 4, 6, 8, 10, 12,
  121670. 14, 16, 18,
  121671. };
  121672. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121673. _vq_quantthresh__44c9_s_p9_1,
  121674. _vq_quantmap__44c9_s_p9_1,
  121675. 19,
  121676. 19
  121677. };
  121678. static static_codebook _44c9_s_p9_1 = {
  121679. 2, 361,
  121680. _vq_lengthlist__44c9_s_p9_1,
  121681. 1, -518287360, 1622704128, 5, 0,
  121682. _vq_quantlist__44c9_s_p9_1,
  121683. NULL,
  121684. &_vq_auxt__44c9_s_p9_1,
  121685. NULL,
  121686. 0
  121687. };
  121688. static long _vq_quantlist__44c9_s_p9_2[] = {
  121689. 24,
  121690. 23,
  121691. 25,
  121692. 22,
  121693. 26,
  121694. 21,
  121695. 27,
  121696. 20,
  121697. 28,
  121698. 19,
  121699. 29,
  121700. 18,
  121701. 30,
  121702. 17,
  121703. 31,
  121704. 16,
  121705. 32,
  121706. 15,
  121707. 33,
  121708. 14,
  121709. 34,
  121710. 13,
  121711. 35,
  121712. 12,
  121713. 36,
  121714. 11,
  121715. 37,
  121716. 10,
  121717. 38,
  121718. 9,
  121719. 39,
  121720. 8,
  121721. 40,
  121722. 7,
  121723. 41,
  121724. 6,
  121725. 42,
  121726. 5,
  121727. 43,
  121728. 4,
  121729. 44,
  121730. 3,
  121731. 45,
  121732. 2,
  121733. 46,
  121734. 1,
  121735. 47,
  121736. 0,
  121737. 48,
  121738. };
  121739. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121740. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121741. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121742. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121743. 7,
  121744. };
  121745. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121746. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121747. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121748. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121749. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121750. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121751. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121752. };
  121753. static long _vq_quantmap__44c9_s_p9_2[] = {
  121754. 47, 45, 43, 41, 39, 37, 35, 33,
  121755. 31, 29, 27, 25, 23, 21, 19, 17,
  121756. 15, 13, 11, 9, 7, 5, 3, 1,
  121757. 0, 2, 4, 6, 8, 10, 12, 14,
  121758. 16, 18, 20, 22, 24, 26, 28, 30,
  121759. 32, 34, 36, 38, 40, 42, 44, 46,
  121760. 48,
  121761. };
  121762. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121763. _vq_quantthresh__44c9_s_p9_2,
  121764. _vq_quantmap__44c9_s_p9_2,
  121765. 49,
  121766. 49
  121767. };
  121768. static static_codebook _44c9_s_p9_2 = {
  121769. 1, 49,
  121770. _vq_lengthlist__44c9_s_p9_2,
  121771. 1, -526909440, 1611661312, 6, 0,
  121772. _vq_quantlist__44c9_s_p9_2,
  121773. NULL,
  121774. &_vq_auxt__44c9_s_p9_2,
  121775. NULL,
  121776. 0
  121777. };
  121778. static long _huff_lengthlist__44c9_s_short[] = {
  121779. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121780. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121781. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121782. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121783. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121784. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121785. 9, 8,10,13,
  121786. };
  121787. static static_codebook _huff_book__44c9_s_short = {
  121788. 2, 100,
  121789. _huff_lengthlist__44c9_s_short,
  121790. 0, 0, 0, 0, 0,
  121791. NULL,
  121792. NULL,
  121793. NULL,
  121794. NULL,
  121795. 0
  121796. };
  121797. static long _huff_lengthlist__44c0_s_long[] = {
  121798. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121799. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121800. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121801. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121802. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121803. 12,
  121804. };
  121805. static static_codebook _huff_book__44c0_s_long = {
  121806. 2, 81,
  121807. _huff_lengthlist__44c0_s_long,
  121808. 0, 0, 0, 0, 0,
  121809. NULL,
  121810. NULL,
  121811. NULL,
  121812. NULL,
  121813. 0
  121814. };
  121815. static long _vq_quantlist__44c0_s_p1_0[] = {
  121816. 1,
  121817. 0,
  121818. 2,
  121819. };
  121820. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121821. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121822. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121826. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121827. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121831. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121832. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121867. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121872. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121877. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121912. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121913. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121917. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121918. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  121919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121922. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121923. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  121924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122231. 0,
  122232. };
  122233. static float _vq_quantthresh__44c0_s_p1_0[] = {
  122234. -0.5, 0.5,
  122235. };
  122236. static long _vq_quantmap__44c0_s_p1_0[] = {
  122237. 1, 0, 2,
  122238. };
  122239. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  122240. _vq_quantthresh__44c0_s_p1_0,
  122241. _vq_quantmap__44c0_s_p1_0,
  122242. 3,
  122243. 3
  122244. };
  122245. static static_codebook _44c0_s_p1_0 = {
  122246. 8, 6561,
  122247. _vq_lengthlist__44c0_s_p1_0,
  122248. 1, -535822336, 1611661312, 2, 0,
  122249. _vq_quantlist__44c0_s_p1_0,
  122250. NULL,
  122251. &_vq_auxt__44c0_s_p1_0,
  122252. NULL,
  122253. 0
  122254. };
  122255. static long _vq_quantlist__44c0_s_p2_0[] = {
  122256. 2,
  122257. 1,
  122258. 3,
  122259. 0,
  122260. 4,
  122261. };
  122262. static long _vq_lengthlist__44c0_s_p2_0[] = {
  122263. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  122265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122266. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122269. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122302. 0,
  122303. };
  122304. static float _vq_quantthresh__44c0_s_p2_0[] = {
  122305. -1.5, -0.5, 0.5, 1.5,
  122306. };
  122307. static long _vq_quantmap__44c0_s_p2_0[] = {
  122308. 3, 1, 0, 2, 4,
  122309. };
  122310. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122311. _vq_quantthresh__44c0_s_p2_0,
  122312. _vq_quantmap__44c0_s_p2_0,
  122313. 5,
  122314. 5
  122315. };
  122316. static static_codebook _44c0_s_p2_0 = {
  122317. 4, 625,
  122318. _vq_lengthlist__44c0_s_p2_0,
  122319. 1, -533725184, 1611661312, 3, 0,
  122320. _vq_quantlist__44c0_s_p2_0,
  122321. NULL,
  122322. &_vq_auxt__44c0_s_p2_0,
  122323. NULL,
  122324. 0
  122325. };
  122326. static long _vq_quantlist__44c0_s_p3_0[] = {
  122327. 4,
  122328. 3,
  122329. 5,
  122330. 2,
  122331. 6,
  122332. 1,
  122333. 7,
  122334. 0,
  122335. 8,
  122336. };
  122337. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122338. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122339. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122340. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122341. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122342. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122343. 0,
  122344. };
  122345. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122346. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122347. };
  122348. static long _vq_quantmap__44c0_s_p3_0[] = {
  122349. 7, 5, 3, 1, 0, 2, 4, 6,
  122350. 8,
  122351. };
  122352. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122353. _vq_quantthresh__44c0_s_p3_0,
  122354. _vq_quantmap__44c0_s_p3_0,
  122355. 9,
  122356. 9
  122357. };
  122358. static static_codebook _44c0_s_p3_0 = {
  122359. 2, 81,
  122360. _vq_lengthlist__44c0_s_p3_0,
  122361. 1, -531628032, 1611661312, 4, 0,
  122362. _vq_quantlist__44c0_s_p3_0,
  122363. NULL,
  122364. &_vq_auxt__44c0_s_p3_0,
  122365. NULL,
  122366. 0
  122367. };
  122368. static long _vq_quantlist__44c0_s_p4_0[] = {
  122369. 4,
  122370. 3,
  122371. 5,
  122372. 2,
  122373. 6,
  122374. 1,
  122375. 7,
  122376. 0,
  122377. 8,
  122378. };
  122379. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122380. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122381. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122382. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122383. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122384. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122385. 10,
  122386. };
  122387. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122388. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122389. };
  122390. static long _vq_quantmap__44c0_s_p4_0[] = {
  122391. 7, 5, 3, 1, 0, 2, 4, 6,
  122392. 8,
  122393. };
  122394. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122395. _vq_quantthresh__44c0_s_p4_0,
  122396. _vq_quantmap__44c0_s_p4_0,
  122397. 9,
  122398. 9
  122399. };
  122400. static static_codebook _44c0_s_p4_0 = {
  122401. 2, 81,
  122402. _vq_lengthlist__44c0_s_p4_0,
  122403. 1, -531628032, 1611661312, 4, 0,
  122404. _vq_quantlist__44c0_s_p4_0,
  122405. NULL,
  122406. &_vq_auxt__44c0_s_p4_0,
  122407. NULL,
  122408. 0
  122409. };
  122410. static long _vq_quantlist__44c0_s_p5_0[] = {
  122411. 8,
  122412. 7,
  122413. 9,
  122414. 6,
  122415. 10,
  122416. 5,
  122417. 11,
  122418. 4,
  122419. 12,
  122420. 3,
  122421. 13,
  122422. 2,
  122423. 14,
  122424. 1,
  122425. 15,
  122426. 0,
  122427. 16,
  122428. };
  122429. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122430. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122431. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122432. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122433. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122434. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122435. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122436. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122437. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122438. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122439. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122440. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122441. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122442. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122443. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122444. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122445. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122446. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122447. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122448. 14,
  122449. };
  122450. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122451. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122452. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122453. };
  122454. static long _vq_quantmap__44c0_s_p5_0[] = {
  122455. 15, 13, 11, 9, 7, 5, 3, 1,
  122456. 0, 2, 4, 6, 8, 10, 12, 14,
  122457. 16,
  122458. };
  122459. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122460. _vq_quantthresh__44c0_s_p5_0,
  122461. _vq_quantmap__44c0_s_p5_0,
  122462. 17,
  122463. 17
  122464. };
  122465. static static_codebook _44c0_s_p5_0 = {
  122466. 2, 289,
  122467. _vq_lengthlist__44c0_s_p5_0,
  122468. 1, -529530880, 1611661312, 5, 0,
  122469. _vq_quantlist__44c0_s_p5_0,
  122470. NULL,
  122471. &_vq_auxt__44c0_s_p5_0,
  122472. NULL,
  122473. 0
  122474. };
  122475. static long _vq_quantlist__44c0_s_p6_0[] = {
  122476. 1,
  122477. 0,
  122478. 2,
  122479. };
  122480. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122481. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122482. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122483. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122484. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122485. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122486. 10,
  122487. };
  122488. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122489. -5.5, 5.5,
  122490. };
  122491. static long _vq_quantmap__44c0_s_p6_0[] = {
  122492. 1, 0, 2,
  122493. };
  122494. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122495. _vq_quantthresh__44c0_s_p6_0,
  122496. _vq_quantmap__44c0_s_p6_0,
  122497. 3,
  122498. 3
  122499. };
  122500. static static_codebook _44c0_s_p6_0 = {
  122501. 4, 81,
  122502. _vq_lengthlist__44c0_s_p6_0,
  122503. 1, -529137664, 1618345984, 2, 0,
  122504. _vq_quantlist__44c0_s_p6_0,
  122505. NULL,
  122506. &_vq_auxt__44c0_s_p6_0,
  122507. NULL,
  122508. 0
  122509. };
  122510. static long _vq_quantlist__44c0_s_p6_1[] = {
  122511. 5,
  122512. 4,
  122513. 6,
  122514. 3,
  122515. 7,
  122516. 2,
  122517. 8,
  122518. 1,
  122519. 9,
  122520. 0,
  122521. 10,
  122522. };
  122523. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122524. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122525. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122526. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122527. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122528. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122529. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122530. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122531. 10,10,10, 8, 8, 8, 8, 8, 8,
  122532. };
  122533. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122534. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122535. 3.5, 4.5,
  122536. };
  122537. static long _vq_quantmap__44c0_s_p6_1[] = {
  122538. 9, 7, 5, 3, 1, 0, 2, 4,
  122539. 6, 8, 10,
  122540. };
  122541. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122542. _vq_quantthresh__44c0_s_p6_1,
  122543. _vq_quantmap__44c0_s_p6_1,
  122544. 11,
  122545. 11
  122546. };
  122547. static static_codebook _44c0_s_p6_1 = {
  122548. 2, 121,
  122549. _vq_lengthlist__44c0_s_p6_1,
  122550. 1, -531365888, 1611661312, 4, 0,
  122551. _vq_quantlist__44c0_s_p6_1,
  122552. NULL,
  122553. &_vq_auxt__44c0_s_p6_1,
  122554. NULL,
  122555. 0
  122556. };
  122557. static long _vq_quantlist__44c0_s_p7_0[] = {
  122558. 6,
  122559. 5,
  122560. 7,
  122561. 4,
  122562. 8,
  122563. 3,
  122564. 9,
  122565. 2,
  122566. 10,
  122567. 1,
  122568. 11,
  122569. 0,
  122570. 12,
  122571. };
  122572. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122573. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122574. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122575. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122576. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122577. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122578. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122579. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122580. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122581. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122582. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122583. 0,12,12,11,11,12,12,13,13,
  122584. };
  122585. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122586. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122587. 12.5, 17.5, 22.5, 27.5,
  122588. };
  122589. static long _vq_quantmap__44c0_s_p7_0[] = {
  122590. 11, 9, 7, 5, 3, 1, 0, 2,
  122591. 4, 6, 8, 10, 12,
  122592. };
  122593. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122594. _vq_quantthresh__44c0_s_p7_0,
  122595. _vq_quantmap__44c0_s_p7_0,
  122596. 13,
  122597. 13
  122598. };
  122599. static static_codebook _44c0_s_p7_0 = {
  122600. 2, 169,
  122601. _vq_lengthlist__44c0_s_p7_0,
  122602. 1, -526516224, 1616117760, 4, 0,
  122603. _vq_quantlist__44c0_s_p7_0,
  122604. NULL,
  122605. &_vq_auxt__44c0_s_p7_0,
  122606. NULL,
  122607. 0
  122608. };
  122609. static long _vq_quantlist__44c0_s_p7_1[] = {
  122610. 2,
  122611. 1,
  122612. 3,
  122613. 0,
  122614. 4,
  122615. };
  122616. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122617. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122618. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122619. };
  122620. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122621. -1.5, -0.5, 0.5, 1.5,
  122622. };
  122623. static long _vq_quantmap__44c0_s_p7_1[] = {
  122624. 3, 1, 0, 2, 4,
  122625. };
  122626. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122627. _vq_quantthresh__44c0_s_p7_1,
  122628. _vq_quantmap__44c0_s_p7_1,
  122629. 5,
  122630. 5
  122631. };
  122632. static static_codebook _44c0_s_p7_1 = {
  122633. 2, 25,
  122634. _vq_lengthlist__44c0_s_p7_1,
  122635. 1, -533725184, 1611661312, 3, 0,
  122636. _vq_quantlist__44c0_s_p7_1,
  122637. NULL,
  122638. &_vq_auxt__44c0_s_p7_1,
  122639. NULL,
  122640. 0
  122641. };
  122642. static long _vq_quantlist__44c0_s_p8_0[] = {
  122643. 2,
  122644. 1,
  122645. 3,
  122646. 0,
  122647. 4,
  122648. };
  122649. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122650. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122651. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122652. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122653. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122654. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122655. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122656. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122657. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122658. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122659. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122660. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122661. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122662. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122663. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122664. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122665. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122666. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122667. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122668. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122669. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122670. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122671. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122672. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122673. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122674. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122675. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122676. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122677. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122678. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122679. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122680. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122681. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122682. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122683. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122684. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122685. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122686. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122687. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122688. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122689. 11,
  122690. };
  122691. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122692. -331.5, -110.5, 110.5, 331.5,
  122693. };
  122694. static long _vq_quantmap__44c0_s_p8_0[] = {
  122695. 3, 1, 0, 2, 4,
  122696. };
  122697. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122698. _vq_quantthresh__44c0_s_p8_0,
  122699. _vq_quantmap__44c0_s_p8_0,
  122700. 5,
  122701. 5
  122702. };
  122703. static static_codebook _44c0_s_p8_0 = {
  122704. 4, 625,
  122705. _vq_lengthlist__44c0_s_p8_0,
  122706. 1, -518283264, 1627103232, 3, 0,
  122707. _vq_quantlist__44c0_s_p8_0,
  122708. NULL,
  122709. &_vq_auxt__44c0_s_p8_0,
  122710. NULL,
  122711. 0
  122712. };
  122713. static long _vq_quantlist__44c0_s_p8_1[] = {
  122714. 6,
  122715. 5,
  122716. 7,
  122717. 4,
  122718. 8,
  122719. 3,
  122720. 9,
  122721. 2,
  122722. 10,
  122723. 1,
  122724. 11,
  122725. 0,
  122726. 12,
  122727. };
  122728. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122729. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122730. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122731. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122732. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122733. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122734. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122735. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122736. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122737. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122738. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122739. 16,13,13,12,12,14,14,15,13,
  122740. };
  122741. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122742. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122743. 42.5, 59.5, 76.5, 93.5,
  122744. };
  122745. static long _vq_quantmap__44c0_s_p8_1[] = {
  122746. 11, 9, 7, 5, 3, 1, 0, 2,
  122747. 4, 6, 8, 10, 12,
  122748. };
  122749. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122750. _vq_quantthresh__44c0_s_p8_1,
  122751. _vq_quantmap__44c0_s_p8_1,
  122752. 13,
  122753. 13
  122754. };
  122755. static static_codebook _44c0_s_p8_1 = {
  122756. 2, 169,
  122757. _vq_lengthlist__44c0_s_p8_1,
  122758. 1, -522616832, 1620115456, 4, 0,
  122759. _vq_quantlist__44c0_s_p8_1,
  122760. NULL,
  122761. &_vq_auxt__44c0_s_p8_1,
  122762. NULL,
  122763. 0
  122764. };
  122765. static long _vq_quantlist__44c0_s_p8_2[] = {
  122766. 8,
  122767. 7,
  122768. 9,
  122769. 6,
  122770. 10,
  122771. 5,
  122772. 11,
  122773. 4,
  122774. 12,
  122775. 3,
  122776. 13,
  122777. 2,
  122778. 14,
  122779. 1,
  122780. 15,
  122781. 0,
  122782. 16,
  122783. };
  122784. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122785. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122786. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122787. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122788. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122789. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122790. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122791. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122792. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122793. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122794. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122795. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122796. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122797. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122798. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122799. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122800. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122801. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122802. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122803. 10,
  122804. };
  122805. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122806. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122807. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122808. };
  122809. static long _vq_quantmap__44c0_s_p8_2[] = {
  122810. 15, 13, 11, 9, 7, 5, 3, 1,
  122811. 0, 2, 4, 6, 8, 10, 12, 14,
  122812. 16,
  122813. };
  122814. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122815. _vq_quantthresh__44c0_s_p8_2,
  122816. _vq_quantmap__44c0_s_p8_2,
  122817. 17,
  122818. 17
  122819. };
  122820. static static_codebook _44c0_s_p8_2 = {
  122821. 2, 289,
  122822. _vq_lengthlist__44c0_s_p8_2,
  122823. 1, -529530880, 1611661312, 5, 0,
  122824. _vq_quantlist__44c0_s_p8_2,
  122825. NULL,
  122826. &_vq_auxt__44c0_s_p8_2,
  122827. NULL,
  122828. 0
  122829. };
  122830. static long _huff_lengthlist__44c0_s_short[] = {
  122831. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122832. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122833. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122834. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122835. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122836. 12,
  122837. };
  122838. static static_codebook _huff_book__44c0_s_short = {
  122839. 2, 81,
  122840. _huff_lengthlist__44c0_s_short,
  122841. 0, 0, 0, 0, 0,
  122842. NULL,
  122843. NULL,
  122844. NULL,
  122845. NULL,
  122846. 0
  122847. };
  122848. static long _huff_lengthlist__44c0_sm_long[] = {
  122849. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122850. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122851. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122852. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122853. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122854. 13,
  122855. };
  122856. static static_codebook _huff_book__44c0_sm_long = {
  122857. 2, 81,
  122858. _huff_lengthlist__44c0_sm_long,
  122859. 0, 0, 0, 0, 0,
  122860. NULL,
  122861. NULL,
  122862. NULL,
  122863. NULL,
  122864. 0
  122865. };
  122866. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122867. 1,
  122868. 0,
  122869. 2,
  122870. };
  122871. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122872. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122873. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122877. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122878. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122882. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122883. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122918. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  122919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122923. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122928. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122963. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122964. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122968. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122969. 0, 0, 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  122970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122973. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122974. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  122975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123282. 0,
  123283. };
  123284. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  123285. -0.5, 0.5,
  123286. };
  123287. static long _vq_quantmap__44c0_sm_p1_0[] = {
  123288. 1, 0, 2,
  123289. };
  123290. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  123291. _vq_quantthresh__44c0_sm_p1_0,
  123292. _vq_quantmap__44c0_sm_p1_0,
  123293. 3,
  123294. 3
  123295. };
  123296. static static_codebook _44c0_sm_p1_0 = {
  123297. 8, 6561,
  123298. _vq_lengthlist__44c0_sm_p1_0,
  123299. 1, -535822336, 1611661312, 2, 0,
  123300. _vq_quantlist__44c0_sm_p1_0,
  123301. NULL,
  123302. &_vq_auxt__44c0_sm_p1_0,
  123303. NULL,
  123304. 0
  123305. };
  123306. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123307. 2,
  123308. 1,
  123309. 3,
  123310. 0,
  123311. 4,
  123312. };
  123313. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123314. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123317. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123320. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123353. 0,
  123354. };
  123355. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123356. -1.5, -0.5, 0.5, 1.5,
  123357. };
  123358. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123359. 3, 1, 0, 2, 4,
  123360. };
  123361. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123362. _vq_quantthresh__44c0_sm_p2_0,
  123363. _vq_quantmap__44c0_sm_p2_0,
  123364. 5,
  123365. 5
  123366. };
  123367. static static_codebook _44c0_sm_p2_0 = {
  123368. 4, 625,
  123369. _vq_lengthlist__44c0_sm_p2_0,
  123370. 1, -533725184, 1611661312, 3, 0,
  123371. _vq_quantlist__44c0_sm_p2_0,
  123372. NULL,
  123373. &_vq_auxt__44c0_sm_p2_0,
  123374. NULL,
  123375. 0
  123376. };
  123377. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123378. 4,
  123379. 3,
  123380. 5,
  123381. 2,
  123382. 6,
  123383. 1,
  123384. 7,
  123385. 0,
  123386. 8,
  123387. };
  123388. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123389. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123390. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123391. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123392. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123393. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123394. 0,
  123395. };
  123396. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123397. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123398. };
  123399. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123400. 7, 5, 3, 1, 0, 2, 4, 6,
  123401. 8,
  123402. };
  123403. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123404. _vq_quantthresh__44c0_sm_p3_0,
  123405. _vq_quantmap__44c0_sm_p3_0,
  123406. 9,
  123407. 9
  123408. };
  123409. static static_codebook _44c0_sm_p3_0 = {
  123410. 2, 81,
  123411. _vq_lengthlist__44c0_sm_p3_0,
  123412. 1, -531628032, 1611661312, 4, 0,
  123413. _vq_quantlist__44c0_sm_p3_0,
  123414. NULL,
  123415. &_vq_auxt__44c0_sm_p3_0,
  123416. NULL,
  123417. 0
  123418. };
  123419. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123420. 4,
  123421. 3,
  123422. 5,
  123423. 2,
  123424. 6,
  123425. 1,
  123426. 7,
  123427. 0,
  123428. 8,
  123429. };
  123430. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123431. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123432. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123433. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123434. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123435. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123436. 11,
  123437. };
  123438. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123439. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123440. };
  123441. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123442. 7, 5, 3, 1, 0, 2, 4, 6,
  123443. 8,
  123444. };
  123445. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123446. _vq_quantthresh__44c0_sm_p4_0,
  123447. _vq_quantmap__44c0_sm_p4_0,
  123448. 9,
  123449. 9
  123450. };
  123451. static static_codebook _44c0_sm_p4_0 = {
  123452. 2, 81,
  123453. _vq_lengthlist__44c0_sm_p4_0,
  123454. 1, -531628032, 1611661312, 4, 0,
  123455. _vq_quantlist__44c0_sm_p4_0,
  123456. NULL,
  123457. &_vq_auxt__44c0_sm_p4_0,
  123458. NULL,
  123459. 0
  123460. };
  123461. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123462. 8,
  123463. 7,
  123464. 9,
  123465. 6,
  123466. 10,
  123467. 5,
  123468. 11,
  123469. 4,
  123470. 12,
  123471. 3,
  123472. 13,
  123473. 2,
  123474. 14,
  123475. 1,
  123476. 15,
  123477. 0,
  123478. 16,
  123479. };
  123480. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123481. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123482. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123483. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123484. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123485. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123486. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123487. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123488. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123489. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123490. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123491. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123492. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123493. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123494. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123495. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123496. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123497. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123498. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123499. 14,
  123500. };
  123501. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123502. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123503. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123504. };
  123505. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123506. 15, 13, 11, 9, 7, 5, 3, 1,
  123507. 0, 2, 4, 6, 8, 10, 12, 14,
  123508. 16,
  123509. };
  123510. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123511. _vq_quantthresh__44c0_sm_p5_0,
  123512. _vq_quantmap__44c0_sm_p5_0,
  123513. 17,
  123514. 17
  123515. };
  123516. static static_codebook _44c0_sm_p5_0 = {
  123517. 2, 289,
  123518. _vq_lengthlist__44c0_sm_p5_0,
  123519. 1, -529530880, 1611661312, 5, 0,
  123520. _vq_quantlist__44c0_sm_p5_0,
  123521. NULL,
  123522. &_vq_auxt__44c0_sm_p5_0,
  123523. NULL,
  123524. 0
  123525. };
  123526. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123527. 1,
  123528. 0,
  123529. 2,
  123530. };
  123531. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123532. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123533. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123534. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123535. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123536. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123537. 11,
  123538. };
  123539. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123540. -5.5, 5.5,
  123541. };
  123542. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123543. 1, 0, 2,
  123544. };
  123545. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123546. _vq_quantthresh__44c0_sm_p6_0,
  123547. _vq_quantmap__44c0_sm_p6_0,
  123548. 3,
  123549. 3
  123550. };
  123551. static static_codebook _44c0_sm_p6_0 = {
  123552. 4, 81,
  123553. _vq_lengthlist__44c0_sm_p6_0,
  123554. 1, -529137664, 1618345984, 2, 0,
  123555. _vq_quantlist__44c0_sm_p6_0,
  123556. NULL,
  123557. &_vq_auxt__44c0_sm_p6_0,
  123558. NULL,
  123559. 0
  123560. };
  123561. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123562. 5,
  123563. 4,
  123564. 6,
  123565. 3,
  123566. 7,
  123567. 2,
  123568. 8,
  123569. 1,
  123570. 9,
  123571. 0,
  123572. 10,
  123573. };
  123574. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123575. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123576. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123577. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123578. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123579. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123580. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123581. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123582. 10,10,10, 8, 8, 8, 8, 8, 8,
  123583. };
  123584. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123585. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123586. 3.5, 4.5,
  123587. };
  123588. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123589. 9, 7, 5, 3, 1, 0, 2, 4,
  123590. 6, 8, 10,
  123591. };
  123592. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123593. _vq_quantthresh__44c0_sm_p6_1,
  123594. _vq_quantmap__44c0_sm_p6_1,
  123595. 11,
  123596. 11
  123597. };
  123598. static static_codebook _44c0_sm_p6_1 = {
  123599. 2, 121,
  123600. _vq_lengthlist__44c0_sm_p6_1,
  123601. 1, -531365888, 1611661312, 4, 0,
  123602. _vq_quantlist__44c0_sm_p6_1,
  123603. NULL,
  123604. &_vq_auxt__44c0_sm_p6_1,
  123605. NULL,
  123606. 0
  123607. };
  123608. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123609. 6,
  123610. 5,
  123611. 7,
  123612. 4,
  123613. 8,
  123614. 3,
  123615. 9,
  123616. 2,
  123617. 10,
  123618. 1,
  123619. 11,
  123620. 0,
  123621. 12,
  123622. };
  123623. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123624. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123625. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123626. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123627. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123628. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123629. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123630. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123631. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123632. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123633. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123634. 0,12,12,11,11,13,12,14,14,
  123635. };
  123636. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123637. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123638. 12.5, 17.5, 22.5, 27.5,
  123639. };
  123640. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123641. 11, 9, 7, 5, 3, 1, 0, 2,
  123642. 4, 6, 8, 10, 12,
  123643. };
  123644. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123645. _vq_quantthresh__44c0_sm_p7_0,
  123646. _vq_quantmap__44c0_sm_p7_0,
  123647. 13,
  123648. 13
  123649. };
  123650. static static_codebook _44c0_sm_p7_0 = {
  123651. 2, 169,
  123652. _vq_lengthlist__44c0_sm_p7_0,
  123653. 1, -526516224, 1616117760, 4, 0,
  123654. _vq_quantlist__44c0_sm_p7_0,
  123655. NULL,
  123656. &_vq_auxt__44c0_sm_p7_0,
  123657. NULL,
  123658. 0
  123659. };
  123660. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123661. 2,
  123662. 1,
  123663. 3,
  123664. 0,
  123665. 4,
  123666. };
  123667. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123668. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123669. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123670. };
  123671. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123672. -1.5, -0.5, 0.5, 1.5,
  123673. };
  123674. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123675. 3, 1, 0, 2, 4,
  123676. };
  123677. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123678. _vq_quantthresh__44c0_sm_p7_1,
  123679. _vq_quantmap__44c0_sm_p7_1,
  123680. 5,
  123681. 5
  123682. };
  123683. static static_codebook _44c0_sm_p7_1 = {
  123684. 2, 25,
  123685. _vq_lengthlist__44c0_sm_p7_1,
  123686. 1, -533725184, 1611661312, 3, 0,
  123687. _vq_quantlist__44c0_sm_p7_1,
  123688. NULL,
  123689. &_vq_auxt__44c0_sm_p7_1,
  123690. NULL,
  123691. 0
  123692. };
  123693. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123694. 4,
  123695. 3,
  123696. 5,
  123697. 2,
  123698. 6,
  123699. 1,
  123700. 7,
  123701. 0,
  123702. 8,
  123703. };
  123704. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123705. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123706. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123707. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123708. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123709. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123710. 12,
  123711. };
  123712. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123713. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123714. };
  123715. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123716. 7, 5, 3, 1, 0, 2, 4, 6,
  123717. 8,
  123718. };
  123719. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123720. _vq_quantthresh__44c0_sm_p8_0,
  123721. _vq_quantmap__44c0_sm_p8_0,
  123722. 9,
  123723. 9
  123724. };
  123725. static static_codebook _44c0_sm_p8_0 = {
  123726. 2, 81,
  123727. _vq_lengthlist__44c0_sm_p8_0,
  123728. 1, -516186112, 1627103232, 4, 0,
  123729. _vq_quantlist__44c0_sm_p8_0,
  123730. NULL,
  123731. &_vq_auxt__44c0_sm_p8_0,
  123732. NULL,
  123733. 0
  123734. };
  123735. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123736. 6,
  123737. 5,
  123738. 7,
  123739. 4,
  123740. 8,
  123741. 3,
  123742. 9,
  123743. 2,
  123744. 10,
  123745. 1,
  123746. 11,
  123747. 0,
  123748. 12,
  123749. };
  123750. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123751. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123752. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123753. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123754. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123755. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123756. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123757. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123758. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123759. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123760. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123761. 20,13,13,12,12,16,13,15,13,
  123762. };
  123763. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123764. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123765. 42.5, 59.5, 76.5, 93.5,
  123766. };
  123767. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123768. 11, 9, 7, 5, 3, 1, 0, 2,
  123769. 4, 6, 8, 10, 12,
  123770. };
  123771. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123772. _vq_quantthresh__44c0_sm_p8_1,
  123773. _vq_quantmap__44c0_sm_p8_1,
  123774. 13,
  123775. 13
  123776. };
  123777. static static_codebook _44c0_sm_p8_1 = {
  123778. 2, 169,
  123779. _vq_lengthlist__44c0_sm_p8_1,
  123780. 1, -522616832, 1620115456, 4, 0,
  123781. _vq_quantlist__44c0_sm_p8_1,
  123782. NULL,
  123783. &_vq_auxt__44c0_sm_p8_1,
  123784. NULL,
  123785. 0
  123786. };
  123787. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123788. 8,
  123789. 7,
  123790. 9,
  123791. 6,
  123792. 10,
  123793. 5,
  123794. 11,
  123795. 4,
  123796. 12,
  123797. 3,
  123798. 13,
  123799. 2,
  123800. 14,
  123801. 1,
  123802. 15,
  123803. 0,
  123804. 16,
  123805. };
  123806. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123807. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123808. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123809. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123810. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123811. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123812. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123813. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123814. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123815. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123816. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123817. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123818. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123819. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123820. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123821. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123822. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123823. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123824. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123825. 9,
  123826. };
  123827. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123828. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123829. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123830. };
  123831. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123832. 15, 13, 11, 9, 7, 5, 3, 1,
  123833. 0, 2, 4, 6, 8, 10, 12, 14,
  123834. 16,
  123835. };
  123836. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123837. _vq_quantthresh__44c0_sm_p8_2,
  123838. _vq_quantmap__44c0_sm_p8_2,
  123839. 17,
  123840. 17
  123841. };
  123842. static static_codebook _44c0_sm_p8_2 = {
  123843. 2, 289,
  123844. _vq_lengthlist__44c0_sm_p8_2,
  123845. 1, -529530880, 1611661312, 5, 0,
  123846. _vq_quantlist__44c0_sm_p8_2,
  123847. NULL,
  123848. &_vq_auxt__44c0_sm_p8_2,
  123849. NULL,
  123850. 0
  123851. };
  123852. static long _huff_lengthlist__44c0_sm_short[] = {
  123853. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123854. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123855. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123856. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123857. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123858. 12,
  123859. };
  123860. static static_codebook _huff_book__44c0_sm_short = {
  123861. 2, 81,
  123862. _huff_lengthlist__44c0_sm_short,
  123863. 0, 0, 0, 0, 0,
  123864. NULL,
  123865. NULL,
  123866. NULL,
  123867. NULL,
  123868. 0
  123869. };
  123870. static long _huff_lengthlist__44c1_s_long[] = {
  123871. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123872. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123873. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123874. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123875. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123876. 11,
  123877. };
  123878. static static_codebook _huff_book__44c1_s_long = {
  123879. 2, 81,
  123880. _huff_lengthlist__44c1_s_long,
  123881. 0, 0, 0, 0, 0,
  123882. NULL,
  123883. NULL,
  123884. NULL,
  123885. NULL,
  123886. 0
  123887. };
  123888. static long _vq_quantlist__44c1_s_p1_0[] = {
  123889. 1,
  123890. 0,
  123891. 2,
  123892. };
  123893. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123894. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123895. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123899. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123900. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123904. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123905. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123940. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123945. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  123946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  123950. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123985. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123986. 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123990. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123991. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  123992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123995. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123996. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124304. 0,
  124305. };
  124306. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124307. -0.5, 0.5,
  124308. };
  124309. static long _vq_quantmap__44c1_s_p1_0[] = {
  124310. 1, 0, 2,
  124311. };
  124312. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124313. _vq_quantthresh__44c1_s_p1_0,
  124314. _vq_quantmap__44c1_s_p1_0,
  124315. 3,
  124316. 3
  124317. };
  124318. static static_codebook _44c1_s_p1_0 = {
  124319. 8, 6561,
  124320. _vq_lengthlist__44c1_s_p1_0,
  124321. 1, -535822336, 1611661312, 2, 0,
  124322. _vq_quantlist__44c1_s_p1_0,
  124323. NULL,
  124324. &_vq_auxt__44c1_s_p1_0,
  124325. NULL,
  124326. 0
  124327. };
  124328. static long _vq_quantlist__44c1_s_p2_0[] = {
  124329. 2,
  124330. 1,
  124331. 3,
  124332. 0,
  124333. 4,
  124334. };
  124335. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124336. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124339. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124342. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  124343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124375. 0,
  124376. };
  124377. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124378. -1.5, -0.5, 0.5, 1.5,
  124379. };
  124380. static long _vq_quantmap__44c1_s_p2_0[] = {
  124381. 3, 1, 0, 2, 4,
  124382. };
  124383. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124384. _vq_quantthresh__44c1_s_p2_0,
  124385. _vq_quantmap__44c1_s_p2_0,
  124386. 5,
  124387. 5
  124388. };
  124389. static static_codebook _44c1_s_p2_0 = {
  124390. 4, 625,
  124391. _vq_lengthlist__44c1_s_p2_0,
  124392. 1, -533725184, 1611661312, 3, 0,
  124393. _vq_quantlist__44c1_s_p2_0,
  124394. NULL,
  124395. &_vq_auxt__44c1_s_p2_0,
  124396. NULL,
  124397. 0
  124398. };
  124399. static long _vq_quantlist__44c1_s_p3_0[] = {
  124400. 4,
  124401. 3,
  124402. 5,
  124403. 2,
  124404. 6,
  124405. 1,
  124406. 7,
  124407. 0,
  124408. 8,
  124409. };
  124410. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124411. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124412. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124413. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124414. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124415. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124416. 0,
  124417. };
  124418. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124419. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124420. };
  124421. static long _vq_quantmap__44c1_s_p3_0[] = {
  124422. 7, 5, 3, 1, 0, 2, 4, 6,
  124423. 8,
  124424. };
  124425. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124426. _vq_quantthresh__44c1_s_p3_0,
  124427. _vq_quantmap__44c1_s_p3_0,
  124428. 9,
  124429. 9
  124430. };
  124431. static static_codebook _44c1_s_p3_0 = {
  124432. 2, 81,
  124433. _vq_lengthlist__44c1_s_p3_0,
  124434. 1, -531628032, 1611661312, 4, 0,
  124435. _vq_quantlist__44c1_s_p3_0,
  124436. NULL,
  124437. &_vq_auxt__44c1_s_p3_0,
  124438. NULL,
  124439. 0
  124440. };
  124441. static long _vq_quantlist__44c1_s_p4_0[] = {
  124442. 4,
  124443. 3,
  124444. 5,
  124445. 2,
  124446. 6,
  124447. 1,
  124448. 7,
  124449. 0,
  124450. 8,
  124451. };
  124452. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124453. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124454. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124455. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124456. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124457. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124458. 11,
  124459. };
  124460. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124461. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124462. };
  124463. static long _vq_quantmap__44c1_s_p4_0[] = {
  124464. 7, 5, 3, 1, 0, 2, 4, 6,
  124465. 8,
  124466. };
  124467. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124468. _vq_quantthresh__44c1_s_p4_0,
  124469. _vq_quantmap__44c1_s_p4_0,
  124470. 9,
  124471. 9
  124472. };
  124473. static static_codebook _44c1_s_p4_0 = {
  124474. 2, 81,
  124475. _vq_lengthlist__44c1_s_p4_0,
  124476. 1, -531628032, 1611661312, 4, 0,
  124477. _vq_quantlist__44c1_s_p4_0,
  124478. NULL,
  124479. &_vq_auxt__44c1_s_p4_0,
  124480. NULL,
  124481. 0
  124482. };
  124483. static long _vq_quantlist__44c1_s_p5_0[] = {
  124484. 8,
  124485. 7,
  124486. 9,
  124487. 6,
  124488. 10,
  124489. 5,
  124490. 11,
  124491. 4,
  124492. 12,
  124493. 3,
  124494. 13,
  124495. 2,
  124496. 14,
  124497. 1,
  124498. 15,
  124499. 0,
  124500. 16,
  124501. };
  124502. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124503. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124504. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124505. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124506. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124507. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124508. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124509. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124510. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124511. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124512. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124513. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124514. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124515. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124516. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124517. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124518. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124519. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124520. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124521. 14,
  124522. };
  124523. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124524. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124525. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124526. };
  124527. static long _vq_quantmap__44c1_s_p5_0[] = {
  124528. 15, 13, 11, 9, 7, 5, 3, 1,
  124529. 0, 2, 4, 6, 8, 10, 12, 14,
  124530. 16,
  124531. };
  124532. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124533. _vq_quantthresh__44c1_s_p5_0,
  124534. _vq_quantmap__44c1_s_p5_0,
  124535. 17,
  124536. 17
  124537. };
  124538. static static_codebook _44c1_s_p5_0 = {
  124539. 2, 289,
  124540. _vq_lengthlist__44c1_s_p5_0,
  124541. 1, -529530880, 1611661312, 5, 0,
  124542. _vq_quantlist__44c1_s_p5_0,
  124543. NULL,
  124544. &_vq_auxt__44c1_s_p5_0,
  124545. NULL,
  124546. 0
  124547. };
  124548. static long _vq_quantlist__44c1_s_p6_0[] = {
  124549. 1,
  124550. 0,
  124551. 2,
  124552. };
  124553. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124554. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124555. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124556. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124557. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124558. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124559. 11,
  124560. };
  124561. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124562. -5.5, 5.5,
  124563. };
  124564. static long _vq_quantmap__44c1_s_p6_0[] = {
  124565. 1, 0, 2,
  124566. };
  124567. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124568. _vq_quantthresh__44c1_s_p6_0,
  124569. _vq_quantmap__44c1_s_p6_0,
  124570. 3,
  124571. 3
  124572. };
  124573. static static_codebook _44c1_s_p6_0 = {
  124574. 4, 81,
  124575. _vq_lengthlist__44c1_s_p6_0,
  124576. 1, -529137664, 1618345984, 2, 0,
  124577. _vq_quantlist__44c1_s_p6_0,
  124578. NULL,
  124579. &_vq_auxt__44c1_s_p6_0,
  124580. NULL,
  124581. 0
  124582. };
  124583. static long _vq_quantlist__44c1_s_p6_1[] = {
  124584. 5,
  124585. 4,
  124586. 6,
  124587. 3,
  124588. 7,
  124589. 2,
  124590. 8,
  124591. 1,
  124592. 9,
  124593. 0,
  124594. 10,
  124595. };
  124596. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124597. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124598. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124599. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124600. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124601. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124602. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124603. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124604. 10,10,10, 8, 8, 8, 8, 8, 8,
  124605. };
  124606. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124607. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124608. 3.5, 4.5,
  124609. };
  124610. static long _vq_quantmap__44c1_s_p6_1[] = {
  124611. 9, 7, 5, 3, 1, 0, 2, 4,
  124612. 6, 8, 10,
  124613. };
  124614. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124615. _vq_quantthresh__44c1_s_p6_1,
  124616. _vq_quantmap__44c1_s_p6_1,
  124617. 11,
  124618. 11
  124619. };
  124620. static static_codebook _44c1_s_p6_1 = {
  124621. 2, 121,
  124622. _vq_lengthlist__44c1_s_p6_1,
  124623. 1, -531365888, 1611661312, 4, 0,
  124624. _vq_quantlist__44c1_s_p6_1,
  124625. NULL,
  124626. &_vq_auxt__44c1_s_p6_1,
  124627. NULL,
  124628. 0
  124629. };
  124630. static long _vq_quantlist__44c1_s_p7_0[] = {
  124631. 6,
  124632. 5,
  124633. 7,
  124634. 4,
  124635. 8,
  124636. 3,
  124637. 9,
  124638. 2,
  124639. 10,
  124640. 1,
  124641. 11,
  124642. 0,
  124643. 12,
  124644. };
  124645. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124646. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124647. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124648. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124649. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124650. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124651. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124652. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124653. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124654. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124655. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124656. 0,12,11,11,11,13,10,14,13,
  124657. };
  124658. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124659. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124660. 12.5, 17.5, 22.5, 27.5,
  124661. };
  124662. static long _vq_quantmap__44c1_s_p7_0[] = {
  124663. 11, 9, 7, 5, 3, 1, 0, 2,
  124664. 4, 6, 8, 10, 12,
  124665. };
  124666. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124667. _vq_quantthresh__44c1_s_p7_0,
  124668. _vq_quantmap__44c1_s_p7_0,
  124669. 13,
  124670. 13
  124671. };
  124672. static static_codebook _44c1_s_p7_0 = {
  124673. 2, 169,
  124674. _vq_lengthlist__44c1_s_p7_0,
  124675. 1, -526516224, 1616117760, 4, 0,
  124676. _vq_quantlist__44c1_s_p7_0,
  124677. NULL,
  124678. &_vq_auxt__44c1_s_p7_0,
  124679. NULL,
  124680. 0
  124681. };
  124682. static long _vq_quantlist__44c1_s_p7_1[] = {
  124683. 2,
  124684. 1,
  124685. 3,
  124686. 0,
  124687. 4,
  124688. };
  124689. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124690. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124691. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124692. };
  124693. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124694. -1.5, -0.5, 0.5, 1.5,
  124695. };
  124696. static long _vq_quantmap__44c1_s_p7_1[] = {
  124697. 3, 1, 0, 2, 4,
  124698. };
  124699. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124700. _vq_quantthresh__44c1_s_p7_1,
  124701. _vq_quantmap__44c1_s_p7_1,
  124702. 5,
  124703. 5
  124704. };
  124705. static static_codebook _44c1_s_p7_1 = {
  124706. 2, 25,
  124707. _vq_lengthlist__44c1_s_p7_1,
  124708. 1, -533725184, 1611661312, 3, 0,
  124709. _vq_quantlist__44c1_s_p7_1,
  124710. NULL,
  124711. &_vq_auxt__44c1_s_p7_1,
  124712. NULL,
  124713. 0
  124714. };
  124715. static long _vq_quantlist__44c1_s_p8_0[] = {
  124716. 6,
  124717. 5,
  124718. 7,
  124719. 4,
  124720. 8,
  124721. 3,
  124722. 9,
  124723. 2,
  124724. 10,
  124725. 1,
  124726. 11,
  124727. 0,
  124728. 12,
  124729. };
  124730. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124731. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124732. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124733. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124734. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124735. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124736. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124737. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124738. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124739. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124740. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124741. 10,10,10,10,10,10,10,10,10,
  124742. };
  124743. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124744. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124745. 552.5, 773.5, 994.5, 1215.5,
  124746. };
  124747. static long _vq_quantmap__44c1_s_p8_0[] = {
  124748. 11, 9, 7, 5, 3, 1, 0, 2,
  124749. 4, 6, 8, 10, 12,
  124750. };
  124751. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124752. _vq_quantthresh__44c1_s_p8_0,
  124753. _vq_quantmap__44c1_s_p8_0,
  124754. 13,
  124755. 13
  124756. };
  124757. static static_codebook _44c1_s_p8_0 = {
  124758. 2, 169,
  124759. _vq_lengthlist__44c1_s_p8_0,
  124760. 1, -514541568, 1627103232, 4, 0,
  124761. _vq_quantlist__44c1_s_p8_0,
  124762. NULL,
  124763. &_vq_auxt__44c1_s_p8_0,
  124764. NULL,
  124765. 0
  124766. };
  124767. static long _vq_quantlist__44c1_s_p8_1[] = {
  124768. 6,
  124769. 5,
  124770. 7,
  124771. 4,
  124772. 8,
  124773. 3,
  124774. 9,
  124775. 2,
  124776. 10,
  124777. 1,
  124778. 11,
  124779. 0,
  124780. 12,
  124781. };
  124782. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124783. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124784. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124785. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124786. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124787. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124788. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124789. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124790. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124791. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124792. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124793. 16,13,12,12,11,14,12,15,13,
  124794. };
  124795. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124796. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124797. 42.5, 59.5, 76.5, 93.5,
  124798. };
  124799. static long _vq_quantmap__44c1_s_p8_1[] = {
  124800. 11, 9, 7, 5, 3, 1, 0, 2,
  124801. 4, 6, 8, 10, 12,
  124802. };
  124803. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124804. _vq_quantthresh__44c1_s_p8_1,
  124805. _vq_quantmap__44c1_s_p8_1,
  124806. 13,
  124807. 13
  124808. };
  124809. static static_codebook _44c1_s_p8_1 = {
  124810. 2, 169,
  124811. _vq_lengthlist__44c1_s_p8_1,
  124812. 1, -522616832, 1620115456, 4, 0,
  124813. _vq_quantlist__44c1_s_p8_1,
  124814. NULL,
  124815. &_vq_auxt__44c1_s_p8_1,
  124816. NULL,
  124817. 0
  124818. };
  124819. static long _vq_quantlist__44c1_s_p8_2[] = {
  124820. 8,
  124821. 7,
  124822. 9,
  124823. 6,
  124824. 10,
  124825. 5,
  124826. 11,
  124827. 4,
  124828. 12,
  124829. 3,
  124830. 13,
  124831. 2,
  124832. 14,
  124833. 1,
  124834. 15,
  124835. 0,
  124836. 16,
  124837. };
  124838. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124839. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124840. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124841. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124842. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124843. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124844. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124845. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124846. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124847. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124848. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124849. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124850. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124851. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124852. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124853. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124854. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124855. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124856. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124857. 9,
  124858. };
  124859. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124860. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124861. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124862. };
  124863. static long _vq_quantmap__44c1_s_p8_2[] = {
  124864. 15, 13, 11, 9, 7, 5, 3, 1,
  124865. 0, 2, 4, 6, 8, 10, 12, 14,
  124866. 16,
  124867. };
  124868. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124869. _vq_quantthresh__44c1_s_p8_2,
  124870. _vq_quantmap__44c1_s_p8_2,
  124871. 17,
  124872. 17
  124873. };
  124874. static static_codebook _44c1_s_p8_2 = {
  124875. 2, 289,
  124876. _vq_lengthlist__44c1_s_p8_2,
  124877. 1, -529530880, 1611661312, 5, 0,
  124878. _vq_quantlist__44c1_s_p8_2,
  124879. NULL,
  124880. &_vq_auxt__44c1_s_p8_2,
  124881. NULL,
  124882. 0
  124883. };
  124884. static long _huff_lengthlist__44c1_s_short[] = {
  124885. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124886. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124887. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124888. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124889. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124890. 11,
  124891. };
  124892. static static_codebook _huff_book__44c1_s_short = {
  124893. 2, 81,
  124894. _huff_lengthlist__44c1_s_short,
  124895. 0, 0, 0, 0, 0,
  124896. NULL,
  124897. NULL,
  124898. NULL,
  124899. NULL,
  124900. 0
  124901. };
  124902. static long _huff_lengthlist__44c1_sm_long[] = {
  124903. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124904. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124905. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124906. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124907. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124908. 11,
  124909. };
  124910. static static_codebook _huff_book__44c1_sm_long = {
  124911. 2, 81,
  124912. _huff_lengthlist__44c1_sm_long,
  124913. 0, 0, 0, 0, 0,
  124914. NULL,
  124915. NULL,
  124916. NULL,
  124917. NULL,
  124918. 0
  124919. };
  124920. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124921. 1,
  124922. 0,
  124923. 2,
  124924. };
  124925. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124926. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124927. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124931. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124932. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124936. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124937. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  124972. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124977. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  124982. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125017. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  125018. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125022. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  125023. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  125024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125027. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  125028. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  125029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125336. 0,
  125337. };
  125338. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125339. -0.5, 0.5,
  125340. };
  125341. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125342. 1, 0, 2,
  125343. };
  125344. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125345. _vq_quantthresh__44c1_sm_p1_0,
  125346. _vq_quantmap__44c1_sm_p1_0,
  125347. 3,
  125348. 3
  125349. };
  125350. static static_codebook _44c1_sm_p1_0 = {
  125351. 8, 6561,
  125352. _vq_lengthlist__44c1_sm_p1_0,
  125353. 1, -535822336, 1611661312, 2, 0,
  125354. _vq_quantlist__44c1_sm_p1_0,
  125355. NULL,
  125356. &_vq_auxt__44c1_sm_p1_0,
  125357. NULL,
  125358. 0
  125359. };
  125360. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125361. 2,
  125362. 1,
  125363. 3,
  125364. 0,
  125365. 4,
  125366. };
  125367. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125368. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125371. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125374. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125407. 0,
  125408. };
  125409. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125410. -1.5, -0.5, 0.5, 1.5,
  125411. };
  125412. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125413. 3, 1, 0, 2, 4,
  125414. };
  125415. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125416. _vq_quantthresh__44c1_sm_p2_0,
  125417. _vq_quantmap__44c1_sm_p2_0,
  125418. 5,
  125419. 5
  125420. };
  125421. static static_codebook _44c1_sm_p2_0 = {
  125422. 4, 625,
  125423. _vq_lengthlist__44c1_sm_p2_0,
  125424. 1, -533725184, 1611661312, 3, 0,
  125425. _vq_quantlist__44c1_sm_p2_0,
  125426. NULL,
  125427. &_vq_auxt__44c1_sm_p2_0,
  125428. NULL,
  125429. 0
  125430. };
  125431. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125432. 4,
  125433. 3,
  125434. 5,
  125435. 2,
  125436. 6,
  125437. 1,
  125438. 7,
  125439. 0,
  125440. 8,
  125441. };
  125442. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125443. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125444. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125445. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125446. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125447. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125448. 0,
  125449. };
  125450. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125451. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125452. };
  125453. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125454. 7, 5, 3, 1, 0, 2, 4, 6,
  125455. 8,
  125456. };
  125457. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125458. _vq_quantthresh__44c1_sm_p3_0,
  125459. _vq_quantmap__44c1_sm_p3_0,
  125460. 9,
  125461. 9
  125462. };
  125463. static static_codebook _44c1_sm_p3_0 = {
  125464. 2, 81,
  125465. _vq_lengthlist__44c1_sm_p3_0,
  125466. 1, -531628032, 1611661312, 4, 0,
  125467. _vq_quantlist__44c1_sm_p3_0,
  125468. NULL,
  125469. &_vq_auxt__44c1_sm_p3_0,
  125470. NULL,
  125471. 0
  125472. };
  125473. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125474. 4,
  125475. 3,
  125476. 5,
  125477. 2,
  125478. 6,
  125479. 1,
  125480. 7,
  125481. 0,
  125482. 8,
  125483. };
  125484. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125485. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125486. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125487. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125488. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125489. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125490. 11,
  125491. };
  125492. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125493. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125494. };
  125495. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125496. 7, 5, 3, 1, 0, 2, 4, 6,
  125497. 8,
  125498. };
  125499. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125500. _vq_quantthresh__44c1_sm_p4_0,
  125501. _vq_quantmap__44c1_sm_p4_0,
  125502. 9,
  125503. 9
  125504. };
  125505. static static_codebook _44c1_sm_p4_0 = {
  125506. 2, 81,
  125507. _vq_lengthlist__44c1_sm_p4_0,
  125508. 1, -531628032, 1611661312, 4, 0,
  125509. _vq_quantlist__44c1_sm_p4_0,
  125510. NULL,
  125511. &_vq_auxt__44c1_sm_p4_0,
  125512. NULL,
  125513. 0
  125514. };
  125515. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125516. 8,
  125517. 7,
  125518. 9,
  125519. 6,
  125520. 10,
  125521. 5,
  125522. 11,
  125523. 4,
  125524. 12,
  125525. 3,
  125526. 13,
  125527. 2,
  125528. 14,
  125529. 1,
  125530. 15,
  125531. 0,
  125532. 16,
  125533. };
  125534. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125535. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125536. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125537. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125538. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125539. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125540. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125541. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125542. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125543. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125544. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125545. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125546. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125547. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125548. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125549. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125550. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125551. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125552. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125553. 14,
  125554. };
  125555. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125556. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125557. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125558. };
  125559. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125560. 15, 13, 11, 9, 7, 5, 3, 1,
  125561. 0, 2, 4, 6, 8, 10, 12, 14,
  125562. 16,
  125563. };
  125564. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125565. _vq_quantthresh__44c1_sm_p5_0,
  125566. _vq_quantmap__44c1_sm_p5_0,
  125567. 17,
  125568. 17
  125569. };
  125570. static static_codebook _44c1_sm_p5_0 = {
  125571. 2, 289,
  125572. _vq_lengthlist__44c1_sm_p5_0,
  125573. 1, -529530880, 1611661312, 5, 0,
  125574. _vq_quantlist__44c1_sm_p5_0,
  125575. NULL,
  125576. &_vq_auxt__44c1_sm_p5_0,
  125577. NULL,
  125578. 0
  125579. };
  125580. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125581. 1,
  125582. 0,
  125583. 2,
  125584. };
  125585. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125586. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125587. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125588. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125589. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125590. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125591. 11,
  125592. };
  125593. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125594. -5.5, 5.5,
  125595. };
  125596. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125597. 1, 0, 2,
  125598. };
  125599. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125600. _vq_quantthresh__44c1_sm_p6_0,
  125601. _vq_quantmap__44c1_sm_p6_0,
  125602. 3,
  125603. 3
  125604. };
  125605. static static_codebook _44c1_sm_p6_0 = {
  125606. 4, 81,
  125607. _vq_lengthlist__44c1_sm_p6_0,
  125608. 1, -529137664, 1618345984, 2, 0,
  125609. _vq_quantlist__44c1_sm_p6_0,
  125610. NULL,
  125611. &_vq_auxt__44c1_sm_p6_0,
  125612. NULL,
  125613. 0
  125614. };
  125615. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125616. 5,
  125617. 4,
  125618. 6,
  125619. 3,
  125620. 7,
  125621. 2,
  125622. 8,
  125623. 1,
  125624. 9,
  125625. 0,
  125626. 10,
  125627. };
  125628. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125629. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125630. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125631. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125632. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125633. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125634. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125635. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125636. 10,10,10, 8, 8, 8, 8, 8, 8,
  125637. };
  125638. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125639. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125640. 3.5, 4.5,
  125641. };
  125642. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125643. 9, 7, 5, 3, 1, 0, 2, 4,
  125644. 6, 8, 10,
  125645. };
  125646. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125647. _vq_quantthresh__44c1_sm_p6_1,
  125648. _vq_quantmap__44c1_sm_p6_1,
  125649. 11,
  125650. 11
  125651. };
  125652. static static_codebook _44c1_sm_p6_1 = {
  125653. 2, 121,
  125654. _vq_lengthlist__44c1_sm_p6_1,
  125655. 1, -531365888, 1611661312, 4, 0,
  125656. _vq_quantlist__44c1_sm_p6_1,
  125657. NULL,
  125658. &_vq_auxt__44c1_sm_p6_1,
  125659. NULL,
  125660. 0
  125661. };
  125662. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125663. 6,
  125664. 5,
  125665. 7,
  125666. 4,
  125667. 8,
  125668. 3,
  125669. 9,
  125670. 2,
  125671. 10,
  125672. 1,
  125673. 11,
  125674. 0,
  125675. 12,
  125676. };
  125677. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125678. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125679. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125680. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125681. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125682. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125683. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125684. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125685. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125686. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125687. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125688. 0,12,12,11,11,13,12,14,13,
  125689. };
  125690. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125691. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125692. 12.5, 17.5, 22.5, 27.5,
  125693. };
  125694. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125695. 11, 9, 7, 5, 3, 1, 0, 2,
  125696. 4, 6, 8, 10, 12,
  125697. };
  125698. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125699. _vq_quantthresh__44c1_sm_p7_0,
  125700. _vq_quantmap__44c1_sm_p7_0,
  125701. 13,
  125702. 13
  125703. };
  125704. static static_codebook _44c1_sm_p7_0 = {
  125705. 2, 169,
  125706. _vq_lengthlist__44c1_sm_p7_0,
  125707. 1, -526516224, 1616117760, 4, 0,
  125708. _vq_quantlist__44c1_sm_p7_0,
  125709. NULL,
  125710. &_vq_auxt__44c1_sm_p7_0,
  125711. NULL,
  125712. 0
  125713. };
  125714. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125715. 2,
  125716. 1,
  125717. 3,
  125718. 0,
  125719. 4,
  125720. };
  125721. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125722. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125723. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125724. };
  125725. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125726. -1.5, -0.5, 0.5, 1.5,
  125727. };
  125728. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125729. 3, 1, 0, 2, 4,
  125730. };
  125731. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125732. _vq_quantthresh__44c1_sm_p7_1,
  125733. _vq_quantmap__44c1_sm_p7_1,
  125734. 5,
  125735. 5
  125736. };
  125737. static static_codebook _44c1_sm_p7_1 = {
  125738. 2, 25,
  125739. _vq_lengthlist__44c1_sm_p7_1,
  125740. 1, -533725184, 1611661312, 3, 0,
  125741. _vq_quantlist__44c1_sm_p7_1,
  125742. NULL,
  125743. &_vq_auxt__44c1_sm_p7_1,
  125744. NULL,
  125745. 0
  125746. };
  125747. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125748. 6,
  125749. 5,
  125750. 7,
  125751. 4,
  125752. 8,
  125753. 3,
  125754. 9,
  125755. 2,
  125756. 10,
  125757. 1,
  125758. 11,
  125759. 0,
  125760. 12,
  125761. };
  125762. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125763. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125764. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125765. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125766. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125767. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125768. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125769. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125770. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125771. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125772. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125773. 13,13,13,13,13,13,13,13,13,
  125774. };
  125775. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125776. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125777. 552.5, 773.5, 994.5, 1215.5,
  125778. };
  125779. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125780. 11, 9, 7, 5, 3, 1, 0, 2,
  125781. 4, 6, 8, 10, 12,
  125782. };
  125783. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125784. _vq_quantthresh__44c1_sm_p8_0,
  125785. _vq_quantmap__44c1_sm_p8_0,
  125786. 13,
  125787. 13
  125788. };
  125789. static static_codebook _44c1_sm_p8_0 = {
  125790. 2, 169,
  125791. _vq_lengthlist__44c1_sm_p8_0,
  125792. 1, -514541568, 1627103232, 4, 0,
  125793. _vq_quantlist__44c1_sm_p8_0,
  125794. NULL,
  125795. &_vq_auxt__44c1_sm_p8_0,
  125796. NULL,
  125797. 0
  125798. };
  125799. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125800. 6,
  125801. 5,
  125802. 7,
  125803. 4,
  125804. 8,
  125805. 3,
  125806. 9,
  125807. 2,
  125808. 10,
  125809. 1,
  125810. 11,
  125811. 0,
  125812. 12,
  125813. };
  125814. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125815. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125816. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125817. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125818. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125819. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125820. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125821. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125822. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125823. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125824. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125825. 20,13,12,12,12,14,12,14,13,
  125826. };
  125827. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125828. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125829. 42.5, 59.5, 76.5, 93.5,
  125830. };
  125831. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125832. 11, 9, 7, 5, 3, 1, 0, 2,
  125833. 4, 6, 8, 10, 12,
  125834. };
  125835. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125836. _vq_quantthresh__44c1_sm_p8_1,
  125837. _vq_quantmap__44c1_sm_p8_1,
  125838. 13,
  125839. 13
  125840. };
  125841. static static_codebook _44c1_sm_p8_1 = {
  125842. 2, 169,
  125843. _vq_lengthlist__44c1_sm_p8_1,
  125844. 1, -522616832, 1620115456, 4, 0,
  125845. _vq_quantlist__44c1_sm_p8_1,
  125846. NULL,
  125847. &_vq_auxt__44c1_sm_p8_1,
  125848. NULL,
  125849. 0
  125850. };
  125851. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125852. 8,
  125853. 7,
  125854. 9,
  125855. 6,
  125856. 10,
  125857. 5,
  125858. 11,
  125859. 4,
  125860. 12,
  125861. 3,
  125862. 13,
  125863. 2,
  125864. 14,
  125865. 1,
  125866. 15,
  125867. 0,
  125868. 16,
  125869. };
  125870. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125871. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125872. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125873. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125874. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125875. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125876. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125877. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125878. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125879. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125880. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125881. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125882. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125883. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125884. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125885. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125886. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125887. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125888. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125889. 9,
  125890. };
  125891. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125892. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125893. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125894. };
  125895. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125896. 15, 13, 11, 9, 7, 5, 3, 1,
  125897. 0, 2, 4, 6, 8, 10, 12, 14,
  125898. 16,
  125899. };
  125900. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125901. _vq_quantthresh__44c1_sm_p8_2,
  125902. _vq_quantmap__44c1_sm_p8_2,
  125903. 17,
  125904. 17
  125905. };
  125906. static static_codebook _44c1_sm_p8_2 = {
  125907. 2, 289,
  125908. _vq_lengthlist__44c1_sm_p8_2,
  125909. 1, -529530880, 1611661312, 5, 0,
  125910. _vq_quantlist__44c1_sm_p8_2,
  125911. NULL,
  125912. &_vq_auxt__44c1_sm_p8_2,
  125913. NULL,
  125914. 0
  125915. };
  125916. static long _huff_lengthlist__44c1_sm_short[] = {
  125917. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125918. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125919. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125920. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125921. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125922. 11,
  125923. };
  125924. static static_codebook _huff_book__44c1_sm_short = {
  125925. 2, 81,
  125926. _huff_lengthlist__44c1_sm_short,
  125927. 0, 0, 0, 0, 0,
  125928. NULL,
  125929. NULL,
  125930. NULL,
  125931. NULL,
  125932. 0
  125933. };
  125934. static long _huff_lengthlist__44cn1_s_long[] = {
  125935. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125936. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125937. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125938. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125939. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125940. 20,
  125941. };
  125942. static static_codebook _huff_book__44cn1_s_long = {
  125943. 2, 81,
  125944. _huff_lengthlist__44cn1_s_long,
  125945. 0, 0, 0, 0, 0,
  125946. NULL,
  125947. NULL,
  125948. NULL,
  125949. NULL,
  125950. 0
  125951. };
  125952. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125953. 1,
  125954. 0,
  125955. 2,
  125956. };
  125957. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125958. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125959. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125963. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125964. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125968. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125969. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126004. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0,
  126005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  126009. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  126014. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  126015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126049. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  126050. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126054. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126055. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  126056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126059. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  126060. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  126061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126368. 0,
  126369. };
  126370. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126371. -0.5, 0.5,
  126372. };
  126373. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126374. 1, 0, 2,
  126375. };
  126376. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126377. _vq_quantthresh__44cn1_s_p1_0,
  126378. _vq_quantmap__44cn1_s_p1_0,
  126379. 3,
  126380. 3
  126381. };
  126382. static static_codebook _44cn1_s_p1_0 = {
  126383. 8, 6561,
  126384. _vq_lengthlist__44cn1_s_p1_0,
  126385. 1, -535822336, 1611661312, 2, 0,
  126386. _vq_quantlist__44cn1_s_p1_0,
  126387. NULL,
  126388. &_vq_auxt__44cn1_s_p1_0,
  126389. NULL,
  126390. 0
  126391. };
  126392. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126393. 2,
  126394. 1,
  126395. 3,
  126396. 0,
  126397. 4,
  126398. };
  126399. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126400. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126403. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126406. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126439. 0,
  126440. };
  126441. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126442. -1.5, -0.5, 0.5, 1.5,
  126443. };
  126444. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126445. 3, 1, 0, 2, 4,
  126446. };
  126447. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126448. _vq_quantthresh__44cn1_s_p2_0,
  126449. _vq_quantmap__44cn1_s_p2_0,
  126450. 5,
  126451. 5
  126452. };
  126453. static static_codebook _44cn1_s_p2_0 = {
  126454. 4, 625,
  126455. _vq_lengthlist__44cn1_s_p2_0,
  126456. 1, -533725184, 1611661312, 3, 0,
  126457. _vq_quantlist__44cn1_s_p2_0,
  126458. NULL,
  126459. &_vq_auxt__44cn1_s_p2_0,
  126460. NULL,
  126461. 0
  126462. };
  126463. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126464. 4,
  126465. 3,
  126466. 5,
  126467. 2,
  126468. 6,
  126469. 1,
  126470. 7,
  126471. 0,
  126472. 8,
  126473. };
  126474. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126475. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126476. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126477. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126478. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126479. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126480. 0,
  126481. };
  126482. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126483. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126484. };
  126485. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126486. 7, 5, 3, 1, 0, 2, 4, 6,
  126487. 8,
  126488. };
  126489. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126490. _vq_quantthresh__44cn1_s_p3_0,
  126491. _vq_quantmap__44cn1_s_p3_0,
  126492. 9,
  126493. 9
  126494. };
  126495. static static_codebook _44cn1_s_p3_0 = {
  126496. 2, 81,
  126497. _vq_lengthlist__44cn1_s_p3_0,
  126498. 1, -531628032, 1611661312, 4, 0,
  126499. _vq_quantlist__44cn1_s_p3_0,
  126500. NULL,
  126501. &_vq_auxt__44cn1_s_p3_0,
  126502. NULL,
  126503. 0
  126504. };
  126505. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126506. 4,
  126507. 3,
  126508. 5,
  126509. 2,
  126510. 6,
  126511. 1,
  126512. 7,
  126513. 0,
  126514. 8,
  126515. };
  126516. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126517. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126518. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126519. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126520. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126521. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126522. 11,
  126523. };
  126524. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126525. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126526. };
  126527. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126528. 7, 5, 3, 1, 0, 2, 4, 6,
  126529. 8,
  126530. };
  126531. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126532. _vq_quantthresh__44cn1_s_p4_0,
  126533. _vq_quantmap__44cn1_s_p4_0,
  126534. 9,
  126535. 9
  126536. };
  126537. static static_codebook _44cn1_s_p4_0 = {
  126538. 2, 81,
  126539. _vq_lengthlist__44cn1_s_p4_0,
  126540. 1, -531628032, 1611661312, 4, 0,
  126541. _vq_quantlist__44cn1_s_p4_0,
  126542. NULL,
  126543. &_vq_auxt__44cn1_s_p4_0,
  126544. NULL,
  126545. 0
  126546. };
  126547. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126548. 8,
  126549. 7,
  126550. 9,
  126551. 6,
  126552. 10,
  126553. 5,
  126554. 11,
  126555. 4,
  126556. 12,
  126557. 3,
  126558. 13,
  126559. 2,
  126560. 14,
  126561. 1,
  126562. 15,
  126563. 0,
  126564. 16,
  126565. };
  126566. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126567. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126568. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126569. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126570. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126571. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126572. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126573. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126574. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126575. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126576. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126577. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126578. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126579. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126580. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126581. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126582. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126583. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126584. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126585. 14,
  126586. };
  126587. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126588. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126589. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126590. };
  126591. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126592. 15, 13, 11, 9, 7, 5, 3, 1,
  126593. 0, 2, 4, 6, 8, 10, 12, 14,
  126594. 16,
  126595. };
  126596. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126597. _vq_quantthresh__44cn1_s_p5_0,
  126598. _vq_quantmap__44cn1_s_p5_0,
  126599. 17,
  126600. 17
  126601. };
  126602. static static_codebook _44cn1_s_p5_0 = {
  126603. 2, 289,
  126604. _vq_lengthlist__44cn1_s_p5_0,
  126605. 1, -529530880, 1611661312, 5, 0,
  126606. _vq_quantlist__44cn1_s_p5_0,
  126607. NULL,
  126608. &_vq_auxt__44cn1_s_p5_0,
  126609. NULL,
  126610. 0
  126611. };
  126612. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126613. 1,
  126614. 0,
  126615. 2,
  126616. };
  126617. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126618. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126619. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126620. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126621. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126622. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126623. 10,
  126624. };
  126625. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126626. -5.5, 5.5,
  126627. };
  126628. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126629. 1, 0, 2,
  126630. };
  126631. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126632. _vq_quantthresh__44cn1_s_p6_0,
  126633. _vq_quantmap__44cn1_s_p6_0,
  126634. 3,
  126635. 3
  126636. };
  126637. static static_codebook _44cn1_s_p6_0 = {
  126638. 4, 81,
  126639. _vq_lengthlist__44cn1_s_p6_0,
  126640. 1, -529137664, 1618345984, 2, 0,
  126641. _vq_quantlist__44cn1_s_p6_0,
  126642. NULL,
  126643. &_vq_auxt__44cn1_s_p6_0,
  126644. NULL,
  126645. 0
  126646. };
  126647. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126648. 5,
  126649. 4,
  126650. 6,
  126651. 3,
  126652. 7,
  126653. 2,
  126654. 8,
  126655. 1,
  126656. 9,
  126657. 0,
  126658. 10,
  126659. };
  126660. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126661. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126662. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126663. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126664. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126665. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126666. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126667. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126668. 10,10,10, 9, 9, 9, 9, 9, 9,
  126669. };
  126670. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126671. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126672. 3.5, 4.5,
  126673. };
  126674. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126675. 9, 7, 5, 3, 1, 0, 2, 4,
  126676. 6, 8, 10,
  126677. };
  126678. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126679. _vq_quantthresh__44cn1_s_p6_1,
  126680. _vq_quantmap__44cn1_s_p6_1,
  126681. 11,
  126682. 11
  126683. };
  126684. static static_codebook _44cn1_s_p6_1 = {
  126685. 2, 121,
  126686. _vq_lengthlist__44cn1_s_p6_1,
  126687. 1, -531365888, 1611661312, 4, 0,
  126688. _vq_quantlist__44cn1_s_p6_1,
  126689. NULL,
  126690. &_vq_auxt__44cn1_s_p6_1,
  126691. NULL,
  126692. 0
  126693. };
  126694. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126695. 6,
  126696. 5,
  126697. 7,
  126698. 4,
  126699. 8,
  126700. 3,
  126701. 9,
  126702. 2,
  126703. 10,
  126704. 1,
  126705. 11,
  126706. 0,
  126707. 12,
  126708. };
  126709. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126710. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126711. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126712. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126713. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126714. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126715. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126716. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126717. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126718. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126719. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126720. 0,13,13,12,12,13,13,13,14,
  126721. };
  126722. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126723. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126724. 12.5, 17.5, 22.5, 27.5,
  126725. };
  126726. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126727. 11, 9, 7, 5, 3, 1, 0, 2,
  126728. 4, 6, 8, 10, 12,
  126729. };
  126730. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126731. _vq_quantthresh__44cn1_s_p7_0,
  126732. _vq_quantmap__44cn1_s_p7_0,
  126733. 13,
  126734. 13
  126735. };
  126736. static static_codebook _44cn1_s_p7_0 = {
  126737. 2, 169,
  126738. _vq_lengthlist__44cn1_s_p7_0,
  126739. 1, -526516224, 1616117760, 4, 0,
  126740. _vq_quantlist__44cn1_s_p7_0,
  126741. NULL,
  126742. &_vq_auxt__44cn1_s_p7_0,
  126743. NULL,
  126744. 0
  126745. };
  126746. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126747. 2,
  126748. 1,
  126749. 3,
  126750. 0,
  126751. 4,
  126752. };
  126753. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126754. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126755. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126756. };
  126757. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126758. -1.5, -0.5, 0.5, 1.5,
  126759. };
  126760. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126761. 3, 1, 0, 2, 4,
  126762. };
  126763. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126764. _vq_quantthresh__44cn1_s_p7_1,
  126765. _vq_quantmap__44cn1_s_p7_1,
  126766. 5,
  126767. 5
  126768. };
  126769. static static_codebook _44cn1_s_p7_1 = {
  126770. 2, 25,
  126771. _vq_lengthlist__44cn1_s_p7_1,
  126772. 1, -533725184, 1611661312, 3, 0,
  126773. _vq_quantlist__44cn1_s_p7_1,
  126774. NULL,
  126775. &_vq_auxt__44cn1_s_p7_1,
  126776. NULL,
  126777. 0
  126778. };
  126779. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126780. 2,
  126781. 1,
  126782. 3,
  126783. 0,
  126784. 4,
  126785. };
  126786. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126787. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126788. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126789. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126790. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126791. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126792. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126793. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126794. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126795. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126796. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126797. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126798. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126799. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126800. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126801. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126802. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126803. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126804. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126805. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126806. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126807. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126808. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126809. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126810. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126811. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126812. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126813. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126814. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126815. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126816. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126817. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126818. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126819. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126820. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126821. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126822. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126823. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126824. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126825. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126826. 12,
  126827. };
  126828. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126829. -331.5, -110.5, 110.5, 331.5,
  126830. };
  126831. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126832. 3, 1, 0, 2, 4,
  126833. };
  126834. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126835. _vq_quantthresh__44cn1_s_p8_0,
  126836. _vq_quantmap__44cn1_s_p8_0,
  126837. 5,
  126838. 5
  126839. };
  126840. static static_codebook _44cn1_s_p8_0 = {
  126841. 4, 625,
  126842. _vq_lengthlist__44cn1_s_p8_0,
  126843. 1, -518283264, 1627103232, 3, 0,
  126844. _vq_quantlist__44cn1_s_p8_0,
  126845. NULL,
  126846. &_vq_auxt__44cn1_s_p8_0,
  126847. NULL,
  126848. 0
  126849. };
  126850. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126851. 6,
  126852. 5,
  126853. 7,
  126854. 4,
  126855. 8,
  126856. 3,
  126857. 9,
  126858. 2,
  126859. 10,
  126860. 1,
  126861. 11,
  126862. 0,
  126863. 12,
  126864. };
  126865. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126866. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126867. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126868. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126869. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126870. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126871. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126872. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126873. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126874. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126875. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126876. 15,12,12,11,11,14,12,13,14,
  126877. };
  126878. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126879. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126880. 42.5, 59.5, 76.5, 93.5,
  126881. };
  126882. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126883. 11, 9, 7, 5, 3, 1, 0, 2,
  126884. 4, 6, 8, 10, 12,
  126885. };
  126886. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126887. _vq_quantthresh__44cn1_s_p8_1,
  126888. _vq_quantmap__44cn1_s_p8_1,
  126889. 13,
  126890. 13
  126891. };
  126892. static static_codebook _44cn1_s_p8_1 = {
  126893. 2, 169,
  126894. _vq_lengthlist__44cn1_s_p8_1,
  126895. 1, -522616832, 1620115456, 4, 0,
  126896. _vq_quantlist__44cn1_s_p8_1,
  126897. NULL,
  126898. &_vq_auxt__44cn1_s_p8_1,
  126899. NULL,
  126900. 0
  126901. };
  126902. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126903. 8,
  126904. 7,
  126905. 9,
  126906. 6,
  126907. 10,
  126908. 5,
  126909. 11,
  126910. 4,
  126911. 12,
  126912. 3,
  126913. 13,
  126914. 2,
  126915. 14,
  126916. 1,
  126917. 15,
  126918. 0,
  126919. 16,
  126920. };
  126921. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126922. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126923. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126924. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126925. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126926. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126927. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126928. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126929. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126930. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126931. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126932. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126933. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126934. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126935. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126936. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126937. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126938. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126939. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126940. 9,
  126941. };
  126942. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126943. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126944. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126945. };
  126946. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126947. 15, 13, 11, 9, 7, 5, 3, 1,
  126948. 0, 2, 4, 6, 8, 10, 12, 14,
  126949. 16,
  126950. };
  126951. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126952. _vq_quantthresh__44cn1_s_p8_2,
  126953. _vq_quantmap__44cn1_s_p8_2,
  126954. 17,
  126955. 17
  126956. };
  126957. static static_codebook _44cn1_s_p8_2 = {
  126958. 2, 289,
  126959. _vq_lengthlist__44cn1_s_p8_2,
  126960. 1, -529530880, 1611661312, 5, 0,
  126961. _vq_quantlist__44cn1_s_p8_2,
  126962. NULL,
  126963. &_vq_auxt__44cn1_s_p8_2,
  126964. NULL,
  126965. 0
  126966. };
  126967. static long _huff_lengthlist__44cn1_s_short[] = {
  126968. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126969. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126970. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126971. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126972. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126973. 10,
  126974. };
  126975. static static_codebook _huff_book__44cn1_s_short = {
  126976. 2, 81,
  126977. _huff_lengthlist__44cn1_s_short,
  126978. 0, 0, 0, 0, 0,
  126979. NULL,
  126980. NULL,
  126981. NULL,
  126982. NULL,
  126983. 0
  126984. };
  126985. static long _huff_lengthlist__44cn1_sm_long[] = {
  126986. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126987. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126988. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126989. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126990. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126991. 17,
  126992. };
  126993. static static_codebook _huff_book__44cn1_sm_long = {
  126994. 2, 81,
  126995. _huff_lengthlist__44cn1_sm_long,
  126996. 0, 0, 0, 0, 0,
  126997. NULL,
  126998. NULL,
  126999. NULL,
  127000. NULL,
  127001. 0
  127002. };
  127003. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  127004. 1,
  127005. 0,
  127006. 2,
  127007. };
  127008. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  127009. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  127010. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127014. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  127015. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127019. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  127020. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  127055. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  127060. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  127065. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  127066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127100. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127101. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127105. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127106. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  127107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127110. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  127111. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  127112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127419. 0,
  127420. };
  127421. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127422. -0.5, 0.5,
  127423. };
  127424. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127425. 1, 0, 2,
  127426. };
  127427. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127428. _vq_quantthresh__44cn1_sm_p1_0,
  127429. _vq_quantmap__44cn1_sm_p1_0,
  127430. 3,
  127431. 3
  127432. };
  127433. static static_codebook _44cn1_sm_p1_0 = {
  127434. 8, 6561,
  127435. _vq_lengthlist__44cn1_sm_p1_0,
  127436. 1, -535822336, 1611661312, 2, 0,
  127437. _vq_quantlist__44cn1_sm_p1_0,
  127438. NULL,
  127439. &_vq_auxt__44cn1_sm_p1_0,
  127440. NULL,
  127441. 0
  127442. };
  127443. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127444. 2,
  127445. 1,
  127446. 3,
  127447. 0,
  127448. 4,
  127449. };
  127450. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127451. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127454. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127457. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127490. 0,
  127491. };
  127492. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127493. -1.5, -0.5, 0.5, 1.5,
  127494. };
  127495. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127496. 3, 1, 0, 2, 4,
  127497. };
  127498. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127499. _vq_quantthresh__44cn1_sm_p2_0,
  127500. _vq_quantmap__44cn1_sm_p2_0,
  127501. 5,
  127502. 5
  127503. };
  127504. static static_codebook _44cn1_sm_p2_0 = {
  127505. 4, 625,
  127506. _vq_lengthlist__44cn1_sm_p2_0,
  127507. 1, -533725184, 1611661312, 3, 0,
  127508. _vq_quantlist__44cn1_sm_p2_0,
  127509. NULL,
  127510. &_vq_auxt__44cn1_sm_p2_0,
  127511. NULL,
  127512. 0
  127513. };
  127514. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127515. 4,
  127516. 3,
  127517. 5,
  127518. 2,
  127519. 6,
  127520. 1,
  127521. 7,
  127522. 0,
  127523. 8,
  127524. };
  127525. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127526. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127527. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127528. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127529. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127530. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127531. 0,
  127532. };
  127533. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127534. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127535. };
  127536. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127537. 7, 5, 3, 1, 0, 2, 4, 6,
  127538. 8,
  127539. };
  127540. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127541. _vq_quantthresh__44cn1_sm_p3_0,
  127542. _vq_quantmap__44cn1_sm_p3_0,
  127543. 9,
  127544. 9
  127545. };
  127546. static static_codebook _44cn1_sm_p3_0 = {
  127547. 2, 81,
  127548. _vq_lengthlist__44cn1_sm_p3_0,
  127549. 1, -531628032, 1611661312, 4, 0,
  127550. _vq_quantlist__44cn1_sm_p3_0,
  127551. NULL,
  127552. &_vq_auxt__44cn1_sm_p3_0,
  127553. NULL,
  127554. 0
  127555. };
  127556. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127557. 4,
  127558. 3,
  127559. 5,
  127560. 2,
  127561. 6,
  127562. 1,
  127563. 7,
  127564. 0,
  127565. 8,
  127566. };
  127567. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127568. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127569. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127570. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127571. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127572. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127573. 11,
  127574. };
  127575. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127576. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127577. };
  127578. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127579. 7, 5, 3, 1, 0, 2, 4, 6,
  127580. 8,
  127581. };
  127582. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127583. _vq_quantthresh__44cn1_sm_p4_0,
  127584. _vq_quantmap__44cn1_sm_p4_0,
  127585. 9,
  127586. 9
  127587. };
  127588. static static_codebook _44cn1_sm_p4_0 = {
  127589. 2, 81,
  127590. _vq_lengthlist__44cn1_sm_p4_0,
  127591. 1, -531628032, 1611661312, 4, 0,
  127592. _vq_quantlist__44cn1_sm_p4_0,
  127593. NULL,
  127594. &_vq_auxt__44cn1_sm_p4_0,
  127595. NULL,
  127596. 0
  127597. };
  127598. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127599. 8,
  127600. 7,
  127601. 9,
  127602. 6,
  127603. 10,
  127604. 5,
  127605. 11,
  127606. 4,
  127607. 12,
  127608. 3,
  127609. 13,
  127610. 2,
  127611. 14,
  127612. 1,
  127613. 15,
  127614. 0,
  127615. 16,
  127616. };
  127617. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127618. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127619. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127620. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127621. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127622. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127623. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127624. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127625. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127626. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127627. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127628. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127629. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127630. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127631. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127632. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127633. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127634. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127635. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127636. 14,
  127637. };
  127638. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127639. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127640. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127641. };
  127642. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127643. 15, 13, 11, 9, 7, 5, 3, 1,
  127644. 0, 2, 4, 6, 8, 10, 12, 14,
  127645. 16,
  127646. };
  127647. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127648. _vq_quantthresh__44cn1_sm_p5_0,
  127649. _vq_quantmap__44cn1_sm_p5_0,
  127650. 17,
  127651. 17
  127652. };
  127653. static static_codebook _44cn1_sm_p5_0 = {
  127654. 2, 289,
  127655. _vq_lengthlist__44cn1_sm_p5_0,
  127656. 1, -529530880, 1611661312, 5, 0,
  127657. _vq_quantlist__44cn1_sm_p5_0,
  127658. NULL,
  127659. &_vq_auxt__44cn1_sm_p5_0,
  127660. NULL,
  127661. 0
  127662. };
  127663. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127664. 1,
  127665. 0,
  127666. 2,
  127667. };
  127668. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127669. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127670. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127671. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127672. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127673. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127674. 10,
  127675. };
  127676. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127677. -5.5, 5.5,
  127678. };
  127679. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127680. 1, 0, 2,
  127681. };
  127682. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127683. _vq_quantthresh__44cn1_sm_p6_0,
  127684. _vq_quantmap__44cn1_sm_p6_0,
  127685. 3,
  127686. 3
  127687. };
  127688. static static_codebook _44cn1_sm_p6_0 = {
  127689. 4, 81,
  127690. _vq_lengthlist__44cn1_sm_p6_0,
  127691. 1, -529137664, 1618345984, 2, 0,
  127692. _vq_quantlist__44cn1_sm_p6_0,
  127693. NULL,
  127694. &_vq_auxt__44cn1_sm_p6_0,
  127695. NULL,
  127696. 0
  127697. };
  127698. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127699. 5,
  127700. 4,
  127701. 6,
  127702. 3,
  127703. 7,
  127704. 2,
  127705. 8,
  127706. 1,
  127707. 9,
  127708. 0,
  127709. 10,
  127710. };
  127711. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127712. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127713. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127714. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127715. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127716. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127717. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127718. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127719. 10,10,10, 8, 9, 8, 8, 9, 8,
  127720. };
  127721. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127722. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127723. 3.5, 4.5,
  127724. };
  127725. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127726. 9, 7, 5, 3, 1, 0, 2, 4,
  127727. 6, 8, 10,
  127728. };
  127729. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127730. _vq_quantthresh__44cn1_sm_p6_1,
  127731. _vq_quantmap__44cn1_sm_p6_1,
  127732. 11,
  127733. 11
  127734. };
  127735. static static_codebook _44cn1_sm_p6_1 = {
  127736. 2, 121,
  127737. _vq_lengthlist__44cn1_sm_p6_1,
  127738. 1, -531365888, 1611661312, 4, 0,
  127739. _vq_quantlist__44cn1_sm_p6_1,
  127740. NULL,
  127741. &_vq_auxt__44cn1_sm_p6_1,
  127742. NULL,
  127743. 0
  127744. };
  127745. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127746. 6,
  127747. 5,
  127748. 7,
  127749. 4,
  127750. 8,
  127751. 3,
  127752. 9,
  127753. 2,
  127754. 10,
  127755. 1,
  127756. 11,
  127757. 0,
  127758. 12,
  127759. };
  127760. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127761. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127762. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127763. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127764. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127765. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127766. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127767. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127768. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127769. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127770. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127771. 0,13,12,12,12,13,13,13,14,
  127772. };
  127773. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127774. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127775. 12.5, 17.5, 22.5, 27.5,
  127776. };
  127777. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127778. 11, 9, 7, 5, 3, 1, 0, 2,
  127779. 4, 6, 8, 10, 12,
  127780. };
  127781. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127782. _vq_quantthresh__44cn1_sm_p7_0,
  127783. _vq_quantmap__44cn1_sm_p7_0,
  127784. 13,
  127785. 13
  127786. };
  127787. static static_codebook _44cn1_sm_p7_0 = {
  127788. 2, 169,
  127789. _vq_lengthlist__44cn1_sm_p7_0,
  127790. 1, -526516224, 1616117760, 4, 0,
  127791. _vq_quantlist__44cn1_sm_p7_0,
  127792. NULL,
  127793. &_vq_auxt__44cn1_sm_p7_0,
  127794. NULL,
  127795. 0
  127796. };
  127797. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127798. 2,
  127799. 1,
  127800. 3,
  127801. 0,
  127802. 4,
  127803. };
  127804. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127805. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127806. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127807. };
  127808. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127809. -1.5, -0.5, 0.5, 1.5,
  127810. };
  127811. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127812. 3, 1, 0, 2, 4,
  127813. };
  127814. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127815. _vq_quantthresh__44cn1_sm_p7_1,
  127816. _vq_quantmap__44cn1_sm_p7_1,
  127817. 5,
  127818. 5
  127819. };
  127820. static static_codebook _44cn1_sm_p7_1 = {
  127821. 2, 25,
  127822. _vq_lengthlist__44cn1_sm_p7_1,
  127823. 1, -533725184, 1611661312, 3, 0,
  127824. _vq_quantlist__44cn1_sm_p7_1,
  127825. NULL,
  127826. &_vq_auxt__44cn1_sm_p7_1,
  127827. NULL,
  127828. 0
  127829. };
  127830. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127831. 4,
  127832. 3,
  127833. 5,
  127834. 2,
  127835. 6,
  127836. 1,
  127837. 7,
  127838. 0,
  127839. 8,
  127840. };
  127841. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127842. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127843. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127844. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127845. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127846. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127847. 14,
  127848. };
  127849. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127850. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127851. };
  127852. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127853. 7, 5, 3, 1, 0, 2, 4, 6,
  127854. 8,
  127855. };
  127856. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127857. _vq_quantthresh__44cn1_sm_p8_0,
  127858. _vq_quantmap__44cn1_sm_p8_0,
  127859. 9,
  127860. 9
  127861. };
  127862. static static_codebook _44cn1_sm_p8_0 = {
  127863. 2, 81,
  127864. _vq_lengthlist__44cn1_sm_p8_0,
  127865. 1, -516186112, 1627103232, 4, 0,
  127866. _vq_quantlist__44cn1_sm_p8_0,
  127867. NULL,
  127868. &_vq_auxt__44cn1_sm_p8_0,
  127869. NULL,
  127870. 0
  127871. };
  127872. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127873. 6,
  127874. 5,
  127875. 7,
  127876. 4,
  127877. 8,
  127878. 3,
  127879. 9,
  127880. 2,
  127881. 10,
  127882. 1,
  127883. 11,
  127884. 0,
  127885. 12,
  127886. };
  127887. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127888. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127889. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127890. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127891. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127892. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127893. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127894. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127895. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127896. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127897. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127898. 17,12,12,11,10,13,11,13,13,
  127899. };
  127900. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127901. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127902. 42.5, 59.5, 76.5, 93.5,
  127903. };
  127904. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127905. 11, 9, 7, 5, 3, 1, 0, 2,
  127906. 4, 6, 8, 10, 12,
  127907. };
  127908. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127909. _vq_quantthresh__44cn1_sm_p8_1,
  127910. _vq_quantmap__44cn1_sm_p8_1,
  127911. 13,
  127912. 13
  127913. };
  127914. static static_codebook _44cn1_sm_p8_1 = {
  127915. 2, 169,
  127916. _vq_lengthlist__44cn1_sm_p8_1,
  127917. 1, -522616832, 1620115456, 4, 0,
  127918. _vq_quantlist__44cn1_sm_p8_1,
  127919. NULL,
  127920. &_vq_auxt__44cn1_sm_p8_1,
  127921. NULL,
  127922. 0
  127923. };
  127924. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127925. 8,
  127926. 7,
  127927. 9,
  127928. 6,
  127929. 10,
  127930. 5,
  127931. 11,
  127932. 4,
  127933. 12,
  127934. 3,
  127935. 13,
  127936. 2,
  127937. 14,
  127938. 1,
  127939. 15,
  127940. 0,
  127941. 16,
  127942. };
  127943. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127944. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127945. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127946. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127947. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127948. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127949. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127950. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127951. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127952. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127953. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127954. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127955. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127956. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127957. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127958. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127959. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127960. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127961. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127962. 9,
  127963. };
  127964. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127965. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127966. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127967. };
  127968. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127969. 15, 13, 11, 9, 7, 5, 3, 1,
  127970. 0, 2, 4, 6, 8, 10, 12, 14,
  127971. 16,
  127972. };
  127973. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127974. _vq_quantthresh__44cn1_sm_p8_2,
  127975. _vq_quantmap__44cn1_sm_p8_2,
  127976. 17,
  127977. 17
  127978. };
  127979. static static_codebook _44cn1_sm_p8_2 = {
  127980. 2, 289,
  127981. _vq_lengthlist__44cn1_sm_p8_2,
  127982. 1, -529530880, 1611661312, 5, 0,
  127983. _vq_quantlist__44cn1_sm_p8_2,
  127984. NULL,
  127985. &_vq_auxt__44cn1_sm_p8_2,
  127986. NULL,
  127987. 0
  127988. };
  127989. static long _huff_lengthlist__44cn1_sm_short[] = {
  127990. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127991. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127992. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127993. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127994. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127995. 9,
  127996. };
  127997. static static_codebook _huff_book__44cn1_sm_short = {
  127998. 2, 81,
  127999. _huff_lengthlist__44cn1_sm_short,
  128000. 0, 0, 0, 0, 0,
  128001. NULL,
  128002. NULL,
  128003. NULL,
  128004. NULL,
  128005. 0
  128006. };
  128007. /*** End of inlined file: res_books_stereo.h ***/
  128008. static vorbis_info_residue0 _residue_44_low={
  128009. 0,-1, -1, 9,-1,
  128010. {0},
  128011. {-1},
  128012. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128013. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  128014. };
  128015. static vorbis_info_residue0 _residue_44_mid={
  128016. 0,-1, -1, 10,-1,
  128017. {0},
  128018. {-1},
  128019. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128020. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  128021. };
  128022. static vorbis_info_residue0 _residue_44_high={
  128023. 0,-1, -1, 10,-1,
  128024. {0},
  128025. {-1},
  128026. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  128027. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  128028. };
  128029. static static_bookblock _resbook_44s_n1={
  128030. {
  128031. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  128032. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  128033. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  128034. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  128035. }
  128036. };
  128037. static static_bookblock _resbook_44sm_n1={
  128038. {
  128039. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  128040. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  128041. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  128042. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  128043. }
  128044. };
  128045. static static_bookblock _resbook_44s_0={
  128046. {
  128047. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  128048. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  128049. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  128050. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  128051. }
  128052. };
  128053. static static_bookblock _resbook_44sm_0={
  128054. {
  128055. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  128056. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  128057. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  128058. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  128059. }
  128060. };
  128061. static static_bookblock _resbook_44s_1={
  128062. {
  128063. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  128064. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  128065. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  128066. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  128067. }
  128068. };
  128069. static static_bookblock _resbook_44sm_1={
  128070. {
  128071. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  128072. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  128073. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  128074. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  128075. }
  128076. };
  128077. static static_bookblock _resbook_44s_2={
  128078. {
  128079. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  128080. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  128081. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  128082. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  128083. }
  128084. };
  128085. static static_bookblock _resbook_44s_3={
  128086. {
  128087. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  128088. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  128089. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  128090. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  128091. }
  128092. };
  128093. static static_bookblock _resbook_44s_4={
  128094. {
  128095. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  128096. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  128097. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  128098. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  128099. }
  128100. };
  128101. static static_bookblock _resbook_44s_5={
  128102. {
  128103. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  128104. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  128105. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  128106. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  128107. }
  128108. };
  128109. static static_bookblock _resbook_44s_6={
  128110. {
  128111. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  128112. {0,0,&_44c6_s_p4_0},
  128113. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  128114. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  128115. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  128116. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  128117. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  128118. }
  128119. };
  128120. static static_bookblock _resbook_44s_7={
  128121. {
  128122. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  128123. {0,0,&_44c7_s_p4_0},
  128124. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  128125. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  128126. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  128127. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  128128. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  128129. }
  128130. };
  128131. static static_bookblock _resbook_44s_8={
  128132. {
  128133. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  128134. {0,0,&_44c8_s_p4_0},
  128135. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  128136. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  128137. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  128138. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  128139. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  128140. }
  128141. };
  128142. static static_bookblock _resbook_44s_9={
  128143. {
  128144. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  128145. {0,0,&_44c9_s_p4_0},
  128146. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  128147. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  128148. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  128149. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  128150. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  128151. }
  128152. };
  128153. static vorbis_residue_template _res_44s_n1[]={
  128154. {2,0, &_residue_44_low,
  128155. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  128156. &_resbook_44s_n1,&_resbook_44sm_n1},
  128157. {2,0, &_residue_44_low,
  128158. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  128159. &_resbook_44s_n1,&_resbook_44sm_n1}
  128160. };
  128161. static vorbis_residue_template _res_44s_0[]={
  128162. {2,0, &_residue_44_low,
  128163. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  128164. &_resbook_44s_0,&_resbook_44sm_0},
  128165. {2,0, &_residue_44_low,
  128166. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  128167. &_resbook_44s_0,&_resbook_44sm_0}
  128168. };
  128169. static vorbis_residue_template _res_44s_1[]={
  128170. {2,0, &_residue_44_low,
  128171. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  128172. &_resbook_44s_1,&_resbook_44sm_1},
  128173. {2,0, &_residue_44_low,
  128174. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  128175. &_resbook_44s_1,&_resbook_44sm_1}
  128176. };
  128177. static vorbis_residue_template _res_44s_2[]={
  128178. {2,0, &_residue_44_mid,
  128179. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  128180. &_resbook_44s_2,&_resbook_44s_2},
  128181. {2,0, &_residue_44_mid,
  128182. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  128183. &_resbook_44s_2,&_resbook_44s_2}
  128184. };
  128185. static vorbis_residue_template _res_44s_3[]={
  128186. {2,0, &_residue_44_mid,
  128187. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  128188. &_resbook_44s_3,&_resbook_44s_3},
  128189. {2,0, &_residue_44_mid,
  128190. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  128191. &_resbook_44s_3,&_resbook_44s_3}
  128192. };
  128193. static vorbis_residue_template _res_44s_4[]={
  128194. {2,0, &_residue_44_mid,
  128195. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  128196. &_resbook_44s_4,&_resbook_44s_4},
  128197. {2,0, &_residue_44_mid,
  128198. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  128199. &_resbook_44s_4,&_resbook_44s_4}
  128200. };
  128201. static vorbis_residue_template _res_44s_5[]={
  128202. {2,0, &_residue_44_mid,
  128203. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  128204. &_resbook_44s_5,&_resbook_44s_5},
  128205. {2,0, &_residue_44_mid,
  128206. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  128207. &_resbook_44s_5,&_resbook_44s_5}
  128208. };
  128209. static vorbis_residue_template _res_44s_6[]={
  128210. {2,0, &_residue_44_high,
  128211. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  128212. &_resbook_44s_6,&_resbook_44s_6},
  128213. {2,0, &_residue_44_high,
  128214. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  128215. &_resbook_44s_6,&_resbook_44s_6}
  128216. };
  128217. static vorbis_residue_template _res_44s_7[]={
  128218. {2,0, &_residue_44_high,
  128219. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  128220. &_resbook_44s_7,&_resbook_44s_7},
  128221. {2,0, &_residue_44_high,
  128222. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  128223. &_resbook_44s_7,&_resbook_44s_7}
  128224. };
  128225. static vorbis_residue_template _res_44s_8[]={
  128226. {2,0, &_residue_44_high,
  128227. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  128228. &_resbook_44s_8,&_resbook_44s_8},
  128229. {2,0, &_residue_44_high,
  128230. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  128231. &_resbook_44s_8,&_resbook_44s_8}
  128232. };
  128233. static vorbis_residue_template _res_44s_9[]={
  128234. {2,0, &_residue_44_high,
  128235. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  128236. &_resbook_44s_9,&_resbook_44s_9},
  128237. {2,0, &_residue_44_high,
  128238. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  128239. &_resbook_44s_9,&_resbook_44s_9}
  128240. };
  128241. static vorbis_mapping_template _mapres_template_44_stereo[]={
  128242. { _map_nominal, _res_44s_n1 }, /* -1 */
  128243. { _map_nominal, _res_44s_0 }, /* 0 */
  128244. { _map_nominal, _res_44s_1 }, /* 1 */
  128245. { _map_nominal, _res_44s_2 }, /* 2 */
  128246. { _map_nominal, _res_44s_3 }, /* 3 */
  128247. { _map_nominal, _res_44s_4 }, /* 4 */
  128248. { _map_nominal, _res_44s_5 }, /* 5 */
  128249. { _map_nominal, _res_44s_6 }, /* 6 */
  128250. { _map_nominal, _res_44s_7 }, /* 7 */
  128251. { _map_nominal, _res_44s_8 }, /* 8 */
  128252. { _map_nominal, _res_44s_9 }, /* 9 */
  128253. };
  128254. /*** End of inlined file: residue_44.h ***/
  128255. /*** Start of inlined file: psych_44.h ***/
  128256. static vorbis_info_psy_global _psy_global_44[5]={
  128257. {8, /* lines per eighth octave */
  128258. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  128259. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  128260. -6.f,
  128261. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128262. },
  128263. {8, /* lines per eighth octave */
  128264. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128265. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  128266. -6.f,
  128267. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128268. },
  128269. {8, /* lines per eighth octave */
  128270. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128271. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  128272. -6.f,
  128273. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128274. },
  128275. {8, /* lines per eighth octave */
  128276. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  128277. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  128278. -6.f,
  128279. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128280. },
  128281. {8, /* lines per eighth octave */
  128282. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  128283. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  128284. -6.f,
  128285. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128286. },
  128287. };
  128288. static compandblock _psy_compand_44[6]={
  128289. {{
  128290. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128291. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128292. 16,17,18,19,20,21,22, 23, /* 23dB */
  128293. 24,25,26,27,28,29,30, 31, /* 31dB */
  128294. 32,33,34,35,36,37,38, 39, /* 39dB */
  128295. }},
  128296. {{
  128297. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  128298. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  128299. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  128300. 15,16,17,17,17,18,18, 19, /* 31dB */
  128301. 19,19,20,21,22,23,24, 25, /* 39dB */
  128302. }},
  128303. {{
  128304. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  128305. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128306. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128307. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128308. 11,12,13,14,15,16,17, 18, /* 39dB */
  128309. }},
  128310. {{
  128311. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128312. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128313. 16,17,18,19,20,21,22, 23, /* 23dB */
  128314. 24,25,26,27,28,29,30, 31, /* 31dB */
  128315. 32,33,34,35,36,37,38, 39, /* 39dB */
  128316. }},
  128317. {{
  128318. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128319. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128320. 13,14,14,14,15,15,15, 15, /* 23dB */
  128321. 16,16,17,17,17,18,18, 19, /* 31dB */
  128322. 19,19,20,21,22,23,24, 25, /* 39dB */
  128323. }},
  128324. {{
  128325. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128326. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128327. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128328. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128329. 11,12,13,14,15,16,17, 18, /* 39dB */
  128330. }}
  128331. };
  128332. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128333. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128334. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128335. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128336. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128337. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128338. /* 4 */
  128339. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128340. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128341. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128342. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128343. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128344. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128345. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128346. };
  128347. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128348. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128349. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128350. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128351. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128352. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128353. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128354. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128355. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128356. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128357. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128358. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128359. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128360. };
  128361. static noise3 _psy_noisebias_trans[12]={
  128362. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128363. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128364. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128365. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128366. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128367. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128368. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128369. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128370. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128371. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128372. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128373. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128374. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128375. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128376. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128377. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128378. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128379. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128380. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128381. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128382. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128383. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128384. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128385. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128386. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128387. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128388. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128389. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128390. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128391. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128392. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128393. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128394. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128395. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128396. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128397. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128398. };
  128399. static noise3 _psy_noisebias_long[12]={
  128400. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128401. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128402. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128403. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128404. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128405. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128406. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128407. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128408. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128409. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128410. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128411. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128412. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128413. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128414. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128415. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128416. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128417. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128418. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128419. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128420. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128421. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128422. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128423. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128424. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128425. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128426. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128427. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128428. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128429. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128430. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128431. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128432. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128433. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128434. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128435. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128436. };
  128437. static noise3 _psy_noisebias_impulse[12]={
  128438. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128439. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128440. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128441. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128442. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128443. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128444. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128445. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128446. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128447. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128448. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128449. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128450. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128451. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128452. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128453. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128454. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128455. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128456. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128457. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128458. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128459. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128460. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128461. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128462. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128463. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128464. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128465. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128466. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128467. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128468. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128469. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128470. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128471. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128472. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128473. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128474. };
  128475. static noise3 _psy_noisebias_padding[12]={
  128476. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128477. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128478. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128479. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128480. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128481. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128482. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128483. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128484. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128485. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128486. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128487. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128488. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128489. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128490. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128491. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128492. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128493. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128494. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128495. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128496. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128497. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128498. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128499. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128500. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128501. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128502. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128503. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128504. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128505. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128506. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128507. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128508. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128509. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128510. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128511. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128512. };
  128513. static noiseguard _psy_noiseguards_44[4]={
  128514. {3,3,15},
  128515. {3,3,15},
  128516. {10,10,100},
  128517. {10,10,100},
  128518. };
  128519. static int _psy_tone_suppress[12]={
  128520. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128521. };
  128522. static int _psy_tone_0dB[12]={
  128523. 90,90,95,95,95,95,105,105,105,105,105,105,
  128524. };
  128525. static int _psy_noise_suppress[12]={
  128526. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128527. };
  128528. static vorbis_info_psy _psy_info_template={
  128529. -1,
  128530. -140.,-140.,
  128531. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128532. 1, -0.f, .5f, .5f, 0,0,0,
  128533. {{-1},{-1},{-1}},{-1},105.f,
  128534. 0,0,-1,-1,0.,
  128535. };
  128536. static int _psy_ath_floater[12]={
  128537. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128538. };
  128539. static int _psy_ath_abs[12]={
  128540. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128541. };
  128542. static adj_stereo _psy_stereo_modes_44[12]={
  128543. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128544. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128545. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128546. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128547. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128548. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128549. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128550. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128551. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128552. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128553. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128554. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128555. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128556. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128557. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128558. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128559. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128560. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128561. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128562. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128563. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128564. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128565. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128566. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128567. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128568. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128569. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128570. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128571. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128572. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128573. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128574. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128575. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128576. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128577. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128578. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128579. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128580. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128581. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128582. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128583. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128584. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128585. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128586. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128587. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128588. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128589. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128590. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128591. };
  128592. static att3 _psy_tone_masteratt_44[12]={
  128593. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128594. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128595. /* 1 */
  128596. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128597. /* 2 */
  128598. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128599. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128600. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128601. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128602. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128603. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128604. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128605. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128606. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128607. };
  128608. static double _psy_lowpass_44[12]={
  128609. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128610. };
  128611. static int _noise_start_short_44[11]={
  128612. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128613. };
  128614. static int _noise_start_long_44[11]={
  128615. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128616. };
  128617. static int _noise_part_short_44[11]={
  128618. 8,8,8,8,8,8,8,8,8,8,8
  128619. };
  128620. static int _noise_part_long_44[11]={
  128621. 32,32,32,32,32,32,32,32,32,32,32
  128622. };
  128623. static double _noise_thresh_44[11]={
  128624. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128625. };
  128626. static double _noise_thresh_5only[2]={
  128627. .5,.5,
  128628. };
  128629. /*** End of inlined file: psych_44.h ***/
  128630. static double rate_mapping_44_stereo[12]={
  128631. 22500.,32000.,40000.,48000.,56000.,64000.,
  128632. 80000.,96000.,112000.,128000.,160000.,250001.
  128633. };
  128634. static double quality_mapping_44[12]={
  128635. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128636. };
  128637. static int blocksize_short_44[11]={
  128638. 512,256,256,256,256,256,256,256,256,256,256
  128639. };
  128640. static int blocksize_long_44[11]={
  128641. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128642. };
  128643. static double _psy_compand_short_mapping[12]={
  128644. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128645. };
  128646. static double _psy_compand_long_mapping[12]={
  128647. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128648. };
  128649. static double _global_mapping_44[12]={
  128650. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128651. };
  128652. static int _floor_short_mapping_44[11]={
  128653. 1,0,0,2,2,4,5,5,5,5,5
  128654. };
  128655. static int _floor_long_mapping_44[11]={
  128656. 8,7,7,7,7,7,7,7,7,7,7
  128657. };
  128658. ve_setup_data_template ve_setup_44_stereo={
  128659. 11,
  128660. rate_mapping_44_stereo,
  128661. quality_mapping_44,
  128662. 2,
  128663. 40000,
  128664. 50000,
  128665. blocksize_short_44,
  128666. blocksize_long_44,
  128667. _psy_tone_masteratt_44,
  128668. _psy_tone_0dB,
  128669. _psy_tone_suppress,
  128670. _vp_tonemask_adj_otherblock,
  128671. _vp_tonemask_adj_longblock,
  128672. _vp_tonemask_adj_otherblock,
  128673. _psy_noiseguards_44,
  128674. _psy_noisebias_impulse,
  128675. _psy_noisebias_padding,
  128676. _psy_noisebias_trans,
  128677. _psy_noisebias_long,
  128678. _psy_noise_suppress,
  128679. _psy_compand_44,
  128680. _psy_compand_short_mapping,
  128681. _psy_compand_long_mapping,
  128682. {_noise_start_short_44,_noise_start_long_44},
  128683. {_noise_part_short_44,_noise_part_long_44},
  128684. _noise_thresh_44,
  128685. _psy_ath_floater,
  128686. _psy_ath_abs,
  128687. _psy_lowpass_44,
  128688. _psy_global_44,
  128689. _global_mapping_44,
  128690. _psy_stereo_modes_44,
  128691. _floor_books,
  128692. _floor,
  128693. _floor_short_mapping_44,
  128694. _floor_long_mapping_44,
  128695. _mapres_template_44_stereo
  128696. };
  128697. /*** End of inlined file: setup_44.h ***/
  128698. /*** Start of inlined file: setup_44u.h ***/
  128699. /*** Start of inlined file: residue_44u.h ***/
  128700. /*** Start of inlined file: res_books_uncoupled.h ***/
  128701. static long _vq_quantlist__16u0__p1_0[] = {
  128702. 1,
  128703. 0,
  128704. 2,
  128705. };
  128706. static long _vq_lengthlist__16u0__p1_0[] = {
  128707. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128708. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128709. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128710. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128711. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128712. 12,
  128713. };
  128714. static float _vq_quantthresh__16u0__p1_0[] = {
  128715. -0.5, 0.5,
  128716. };
  128717. static long _vq_quantmap__16u0__p1_0[] = {
  128718. 1, 0, 2,
  128719. };
  128720. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128721. _vq_quantthresh__16u0__p1_0,
  128722. _vq_quantmap__16u0__p1_0,
  128723. 3,
  128724. 3
  128725. };
  128726. static static_codebook _16u0__p1_0 = {
  128727. 4, 81,
  128728. _vq_lengthlist__16u0__p1_0,
  128729. 1, -535822336, 1611661312, 2, 0,
  128730. _vq_quantlist__16u0__p1_0,
  128731. NULL,
  128732. &_vq_auxt__16u0__p1_0,
  128733. NULL,
  128734. 0
  128735. };
  128736. static long _vq_quantlist__16u0__p2_0[] = {
  128737. 1,
  128738. 0,
  128739. 2,
  128740. };
  128741. static long _vq_lengthlist__16u0__p2_0[] = {
  128742. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128743. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128744. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128745. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128746. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128747. 8,
  128748. };
  128749. static float _vq_quantthresh__16u0__p2_0[] = {
  128750. -0.5, 0.5,
  128751. };
  128752. static long _vq_quantmap__16u0__p2_0[] = {
  128753. 1, 0, 2,
  128754. };
  128755. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128756. _vq_quantthresh__16u0__p2_0,
  128757. _vq_quantmap__16u0__p2_0,
  128758. 3,
  128759. 3
  128760. };
  128761. static static_codebook _16u0__p2_0 = {
  128762. 4, 81,
  128763. _vq_lengthlist__16u0__p2_0,
  128764. 1, -535822336, 1611661312, 2, 0,
  128765. _vq_quantlist__16u0__p2_0,
  128766. NULL,
  128767. &_vq_auxt__16u0__p2_0,
  128768. NULL,
  128769. 0
  128770. };
  128771. static long _vq_quantlist__16u0__p3_0[] = {
  128772. 2,
  128773. 1,
  128774. 3,
  128775. 0,
  128776. 4,
  128777. };
  128778. static long _vq_lengthlist__16u0__p3_0[] = {
  128779. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128780. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128781. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128782. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128783. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128784. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128785. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128786. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128787. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128788. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128789. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128790. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128791. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128792. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128793. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128794. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128795. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128796. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128797. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128798. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128799. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128800. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128801. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128802. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128803. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128804. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128805. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128806. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128807. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128808. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128809. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128810. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128811. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128812. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128813. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128814. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128815. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128816. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128817. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128818. 18,
  128819. };
  128820. static float _vq_quantthresh__16u0__p3_0[] = {
  128821. -1.5, -0.5, 0.5, 1.5,
  128822. };
  128823. static long _vq_quantmap__16u0__p3_0[] = {
  128824. 3, 1, 0, 2, 4,
  128825. };
  128826. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128827. _vq_quantthresh__16u0__p3_0,
  128828. _vq_quantmap__16u0__p3_0,
  128829. 5,
  128830. 5
  128831. };
  128832. static static_codebook _16u0__p3_0 = {
  128833. 4, 625,
  128834. _vq_lengthlist__16u0__p3_0,
  128835. 1, -533725184, 1611661312, 3, 0,
  128836. _vq_quantlist__16u0__p3_0,
  128837. NULL,
  128838. &_vq_auxt__16u0__p3_0,
  128839. NULL,
  128840. 0
  128841. };
  128842. static long _vq_quantlist__16u0__p4_0[] = {
  128843. 2,
  128844. 1,
  128845. 3,
  128846. 0,
  128847. 4,
  128848. };
  128849. static long _vq_lengthlist__16u0__p4_0[] = {
  128850. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128851. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128852. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128853. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128854. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128855. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128856. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128857. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128858. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128859. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128860. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128861. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128862. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128863. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128864. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128865. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128866. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128867. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128868. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128869. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128870. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128871. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128872. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128873. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128874. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128875. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128876. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128877. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128878. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128879. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128880. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128881. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128882. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128883. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128884. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128885. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128886. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128887. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128888. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128889. 11,
  128890. };
  128891. static float _vq_quantthresh__16u0__p4_0[] = {
  128892. -1.5, -0.5, 0.5, 1.5,
  128893. };
  128894. static long _vq_quantmap__16u0__p4_0[] = {
  128895. 3, 1, 0, 2, 4,
  128896. };
  128897. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128898. _vq_quantthresh__16u0__p4_0,
  128899. _vq_quantmap__16u0__p4_0,
  128900. 5,
  128901. 5
  128902. };
  128903. static static_codebook _16u0__p4_0 = {
  128904. 4, 625,
  128905. _vq_lengthlist__16u0__p4_0,
  128906. 1, -533725184, 1611661312, 3, 0,
  128907. _vq_quantlist__16u0__p4_0,
  128908. NULL,
  128909. &_vq_auxt__16u0__p4_0,
  128910. NULL,
  128911. 0
  128912. };
  128913. static long _vq_quantlist__16u0__p5_0[] = {
  128914. 4,
  128915. 3,
  128916. 5,
  128917. 2,
  128918. 6,
  128919. 1,
  128920. 7,
  128921. 0,
  128922. 8,
  128923. };
  128924. static long _vq_lengthlist__16u0__p5_0[] = {
  128925. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128926. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128927. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128928. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128929. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128930. 12,
  128931. };
  128932. static float _vq_quantthresh__16u0__p5_0[] = {
  128933. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128934. };
  128935. static long _vq_quantmap__16u0__p5_0[] = {
  128936. 7, 5, 3, 1, 0, 2, 4, 6,
  128937. 8,
  128938. };
  128939. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128940. _vq_quantthresh__16u0__p5_0,
  128941. _vq_quantmap__16u0__p5_0,
  128942. 9,
  128943. 9
  128944. };
  128945. static static_codebook _16u0__p5_0 = {
  128946. 2, 81,
  128947. _vq_lengthlist__16u0__p5_0,
  128948. 1, -531628032, 1611661312, 4, 0,
  128949. _vq_quantlist__16u0__p5_0,
  128950. NULL,
  128951. &_vq_auxt__16u0__p5_0,
  128952. NULL,
  128953. 0
  128954. };
  128955. static long _vq_quantlist__16u0__p6_0[] = {
  128956. 6,
  128957. 5,
  128958. 7,
  128959. 4,
  128960. 8,
  128961. 3,
  128962. 9,
  128963. 2,
  128964. 10,
  128965. 1,
  128966. 11,
  128967. 0,
  128968. 12,
  128969. };
  128970. static long _vq_lengthlist__16u0__p6_0[] = {
  128971. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128972. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128973. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128974. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128975. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128976. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128977. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128978. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128979. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128980. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128981. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128982. };
  128983. static float _vq_quantthresh__16u0__p6_0[] = {
  128984. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128985. 12.5, 17.5, 22.5, 27.5,
  128986. };
  128987. static long _vq_quantmap__16u0__p6_0[] = {
  128988. 11, 9, 7, 5, 3, 1, 0, 2,
  128989. 4, 6, 8, 10, 12,
  128990. };
  128991. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128992. _vq_quantthresh__16u0__p6_0,
  128993. _vq_quantmap__16u0__p6_0,
  128994. 13,
  128995. 13
  128996. };
  128997. static static_codebook _16u0__p6_0 = {
  128998. 2, 169,
  128999. _vq_lengthlist__16u0__p6_0,
  129000. 1, -526516224, 1616117760, 4, 0,
  129001. _vq_quantlist__16u0__p6_0,
  129002. NULL,
  129003. &_vq_auxt__16u0__p6_0,
  129004. NULL,
  129005. 0
  129006. };
  129007. static long _vq_quantlist__16u0__p6_1[] = {
  129008. 2,
  129009. 1,
  129010. 3,
  129011. 0,
  129012. 4,
  129013. };
  129014. static long _vq_lengthlist__16u0__p6_1[] = {
  129015. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  129016. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  129017. };
  129018. static float _vq_quantthresh__16u0__p6_1[] = {
  129019. -1.5, -0.5, 0.5, 1.5,
  129020. };
  129021. static long _vq_quantmap__16u0__p6_1[] = {
  129022. 3, 1, 0, 2, 4,
  129023. };
  129024. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  129025. _vq_quantthresh__16u0__p6_1,
  129026. _vq_quantmap__16u0__p6_1,
  129027. 5,
  129028. 5
  129029. };
  129030. static static_codebook _16u0__p6_1 = {
  129031. 2, 25,
  129032. _vq_lengthlist__16u0__p6_1,
  129033. 1, -533725184, 1611661312, 3, 0,
  129034. _vq_quantlist__16u0__p6_1,
  129035. NULL,
  129036. &_vq_auxt__16u0__p6_1,
  129037. NULL,
  129038. 0
  129039. };
  129040. static long _vq_quantlist__16u0__p7_0[] = {
  129041. 1,
  129042. 0,
  129043. 2,
  129044. };
  129045. static long _vq_lengthlist__16u0__p7_0[] = {
  129046. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129047. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129048. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129049. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129050. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129051. 7,
  129052. };
  129053. static float _vq_quantthresh__16u0__p7_0[] = {
  129054. -157.5, 157.5,
  129055. };
  129056. static long _vq_quantmap__16u0__p7_0[] = {
  129057. 1, 0, 2,
  129058. };
  129059. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  129060. _vq_quantthresh__16u0__p7_0,
  129061. _vq_quantmap__16u0__p7_0,
  129062. 3,
  129063. 3
  129064. };
  129065. static static_codebook _16u0__p7_0 = {
  129066. 4, 81,
  129067. _vq_lengthlist__16u0__p7_0,
  129068. 1, -518803456, 1628680192, 2, 0,
  129069. _vq_quantlist__16u0__p7_0,
  129070. NULL,
  129071. &_vq_auxt__16u0__p7_0,
  129072. NULL,
  129073. 0
  129074. };
  129075. static long _vq_quantlist__16u0__p7_1[] = {
  129076. 7,
  129077. 6,
  129078. 8,
  129079. 5,
  129080. 9,
  129081. 4,
  129082. 10,
  129083. 3,
  129084. 11,
  129085. 2,
  129086. 12,
  129087. 1,
  129088. 13,
  129089. 0,
  129090. 14,
  129091. };
  129092. static long _vq_lengthlist__16u0__p7_1[] = {
  129093. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  129094. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  129095. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  129096. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  129097. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  129098. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  129099. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129100. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129101. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129102. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129103. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129104. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129105. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129106. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129107. 10,
  129108. };
  129109. static float _vq_quantthresh__16u0__p7_1[] = {
  129110. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129111. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129112. };
  129113. static long _vq_quantmap__16u0__p7_1[] = {
  129114. 13, 11, 9, 7, 5, 3, 1, 0,
  129115. 2, 4, 6, 8, 10, 12, 14,
  129116. };
  129117. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  129118. _vq_quantthresh__16u0__p7_1,
  129119. _vq_quantmap__16u0__p7_1,
  129120. 15,
  129121. 15
  129122. };
  129123. static static_codebook _16u0__p7_1 = {
  129124. 2, 225,
  129125. _vq_lengthlist__16u0__p7_1,
  129126. 1, -520986624, 1620377600, 4, 0,
  129127. _vq_quantlist__16u0__p7_1,
  129128. NULL,
  129129. &_vq_auxt__16u0__p7_1,
  129130. NULL,
  129131. 0
  129132. };
  129133. static long _vq_quantlist__16u0__p7_2[] = {
  129134. 10,
  129135. 9,
  129136. 11,
  129137. 8,
  129138. 12,
  129139. 7,
  129140. 13,
  129141. 6,
  129142. 14,
  129143. 5,
  129144. 15,
  129145. 4,
  129146. 16,
  129147. 3,
  129148. 17,
  129149. 2,
  129150. 18,
  129151. 1,
  129152. 19,
  129153. 0,
  129154. 20,
  129155. };
  129156. static long _vq_lengthlist__16u0__p7_2[] = {
  129157. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  129158. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  129159. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  129160. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  129161. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  129162. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  129163. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  129164. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  129165. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  129166. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  129167. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  129168. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  129169. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  129170. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  129171. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  129172. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  129173. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  129174. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  129175. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  129176. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  129177. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  129178. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  129179. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  129180. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  129181. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  129182. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  129183. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  129184. 10,10,12,11,10,11,11,11,10,
  129185. };
  129186. static float _vq_quantthresh__16u0__p7_2[] = {
  129187. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129188. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129189. 6.5, 7.5, 8.5, 9.5,
  129190. };
  129191. static long _vq_quantmap__16u0__p7_2[] = {
  129192. 19, 17, 15, 13, 11, 9, 7, 5,
  129193. 3, 1, 0, 2, 4, 6, 8, 10,
  129194. 12, 14, 16, 18, 20,
  129195. };
  129196. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  129197. _vq_quantthresh__16u0__p7_2,
  129198. _vq_quantmap__16u0__p7_2,
  129199. 21,
  129200. 21
  129201. };
  129202. static static_codebook _16u0__p7_2 = {
  129203. 2, 441,
  129204. _vq_lengthlist__16u0__p7_2,
  129205. 1, -529268736, 1611661312, 5, 0,
  129206. _vq_quantlist__16u0__p7_2,
  129207. NULL,
  129208. &_vq_auxt__16u0__p7_2,
  129209. NULL,
  129210. 0
  129211. };
  129212. static long _huff_lengthlist__16u0__single[] = {
  129213. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  129214. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  129215. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  129216. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  129217. };
  129218. static static_codebook _huff_book__16u0__single = {
  129219. 2, 64,
  129220. _huff_lengthlist__16u0__single,
  129221. 0, 0, 0, 0, 0,
  129222. NULL,
  129223. NULL,
  129224. NULL,
  129225. NULL,
  129226. 0
  129227. };
  129228. static long _huff_lengthlist__16u1__long[] = {
  129229. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  129230. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  129231. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  129232. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  129233. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  129234. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  129235. 16,13,16,18,
  129236. };
  129237. static static_codebook _huff_book__16u1__long = {
  129238. 2, 100,
  129239. _huff_lengthlist__16u1__long,
  129240. 0, 0, 0, 0, 0,
  129241. NULL,
  129242. NULL,
  129243. NULL,
  129244. NULL,
  129245. 0
  129246. };
  129247. static long _vq_quantlist__16u1__p1_0[] = {
  129248. 1,
  129249. 0,
  129250. 2,
  129251. };
  129252. static long _vq_lengthlist__16u1__p1_0[] = {
  129253. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  129254. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  129255. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  129256. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  129257. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  129258. 11,
  129259. };
  129260. static float _vq_quantthresh__16u1__p1_0[] = {
  129261. -0.5, 0.5,
  129262. };
  129263. static long _vq_quantmap__16u1__p1_0[] = {
  129264. 1, 0, 2,
  129265. };
  129266. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  129267. _vq_quantthresh__16u1__p1_0,
  129268. _vq_quantmap__16u1__p1_0,
  129269. 3,
  129270. 3
  129271. };
  129272. static static_codebook _16u1__p1_0 = {
  129273. 4, 81,
  129274. _vq_lengthlist__16u1__p1_0,
  129275. 1, -535822336, 1611661312, 2, 0,
  129276. _vq_quantlist__16u1__p1_0,
  129277. NULL,
  129278. &_vq_auxt__16u1__p1_0,
  129279. NULL,
  129280. 0
  129281. };
  129282. static long _vq_quantlist__16u1__p2_0[] = {
  129283. 1,
  129284. 0,
  129285. 2,
  129286. };
  129287. static long _vq_lengthlist__16u1__p2_0[] = {
  129288. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  129289. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  129290. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  129291. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  129292. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  129293. 8,
  129294. };
  129295. static float _vq_quantthresh__16u1__p2_0[] = {
  129296. -0.5, 0.5,
  129297. };
  129298. static long _vq_quantmap__16u1__p2_0[] = {
  129299. 1, 0, 2,
  129300. };
  129301. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  129302. _vq_quantthresh__16u1__p2_0,
  129303. _vq_quantmap__16u1__p2_0,
  129304. 3,
  129305. 3
  129306. };
  129307. static static_codebook _16u1__p2_0 = {
  129308. 4, 81,
  129309. _vq_lengthlist__16u1__p2_0,
  129310. 1, -535822336, 1611661312, 2, 0,
  129311. _vq_quantlist__16u1__p2_0,
  129312. NULL,
  129313. &_vq_auxt__16u1__p2_0,
  129314. NULL,
  129315. 0
  129316. };
  129317. static long _vq_quantlist__16u1__p3_0[] = {
  129318. 2,
  129319. 1,
  129320. 3,
  129321. 0,
  129322. 4,
  129323. };
  129324. static long _vq_lengthlist__16u1__p3_0[] = {
  129325. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129326. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129327. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129328. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129329. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129330. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129331. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129332. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129333. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129334. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129335. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129336. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129337. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129338. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129339. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129340. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129341. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129342. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129343. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129344. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129345. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129346. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129347. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129348. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129349. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129350. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129351. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129352. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129353. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129354. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129355. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129356. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129357. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129358. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129359. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129360. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129361. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129362. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129363. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129364. 16,
  129365. };
  129366. static float _vq_quantthresh__16u1__p3_0[] = {
  129367. -1.5, -0.5, 0.5, 1.5,
  129368. };
  129369. static long _vq_quantmap__16u1__p3_0[] = {
  129370. 3, 1, 0, 2, 4,
  129371. };
  129372. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129373. _vq_quantthresh__16u1__p3_0,
  129374. _vq_quantmap__16u1__p3_0,
  129375. 5,
  129376. 5
  129377. };
  129378. static static_codebook _16u1__p3_0 = {
  129379. 4, 625,
  129380. _vq_lengthlist__16u1__p3_0,
  129381. 1, -533725184, 1611661312, 3, 0,
  129382. _vq_quantlist__16u1__p3_0,
  129383. NULL,
  129384. &_vq_auxt__16u1__p3_0,
  129385. NULL,
  129386. 0
  129387. };
  129388. static long _vq_quantlist__16u1__p4_0[] = {
  129389. 2,
  129390. 1,
  129391. 3,
  129392. 0,
  129393. 4,
  129394. };
  129395. static long _vq_lengthlist__16u1__p4_0[] = {
  129396. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129397. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129398. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129399. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129400. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129401. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129402. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129403. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129404. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129405. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129406. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129407. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129408. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129409. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129410. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129411. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129412. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129413. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129414. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129415. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129416. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129417. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129418. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129419. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129420. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129421. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129422. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129423. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129424. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129425. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129426. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129427. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129428. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129429. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129430. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129431. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129432. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129433. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129434. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129435. 11,
  129436. };
  129437. static float _vq_quantthresh__16u1__p4_0[] = {
  129438. -1.5, -0.5, 0.5, 1.5,
  129439. };
  129440. static long _vq_quantmap__16u1__p4_0[] = {
  129441. 3, 1, 0, 2, 4,
  129442. };
  129443. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129444. _vq_quantthresh__16u1__p4_0,
  129445. _vq_quantmap__16u1__p4_0,
  129446. 5,
  129447. 5
  129448. };
  129449. static static_codebook _16u1__p4_0 = {
  129450. 4, 625,
  129451. _vq_lengthlist__16u1__p4_0,
  129452. 1, -533725184, 1611661312, 3, 0,
  129453. _vq_quantlist__16u1__p4_0,
  129454. NULL,
  129455. &_vq_auxt__16u1__p4_0,
  129456. NULL,
  129457. 0
  129458. };
  129459. static long _vq_quantlist__16u1__p5_0[] = {
  129460. 4,
  129461. 3,
  129462. 5,
  129463. 2,
  129464. 6,
  129465. 1,
  129466. 7,
  129467. 0,
  129468. 8,
  129469. };
  129470. static long _vq_lengthlist__16u1__p5_0[] = {
  129471. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129472. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129473. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129474. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129475. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129476. 13,
  129477. };
  129478. static float _vq_quantthresh__16u1__p5_0[] = {
  129479. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129480. };
  129481. static long _vq_quantmap__16u1__p5_0[] = {
  129482. 7, 5, 3, 1, 0, 2, 4, 6,
  129483. 8,
  129484. };
  129485. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129486. _vq_quantthresh__16u1__p5_0,
  129487. _vq_quantmap__16u1__p5_0,
  129488. 9,
  129489. 9
  129490. };
  129491. static static_codebook _16u1__p5_0 = {
  129492. 2, 81,
  129493. _vq_lengthlist__16u1__p5_0,
  129494. 1, -531628032, 1611661312, 4, 0,
  129495. _vq_quantlist__16u1__p5_0,
  129496. NULL,
  129497. &_vq_auxt__16u1__p5_0,
  129498. NULL,
  129499. 0
  129500. };
  129501. static long _vq_quantlist__16u1__p6_0[] = {
  129502. 4,
  129503. 3,
  129504. 5,
  129505. 2,
  129506. 6,
  129507. 1,
  129508. 7,
  129509. 0,
  129510. 8,
  129511. };
  129512. static long _vq_lengthlist__16u1__p6_0[] = {
  129513. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129514. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129515. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129516. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129517. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129518. 11,
  129519. };
  129520. static float _vq_quantthresh__16u1__p6_0[] = {
  129521. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129522. };
  129523. static long _vq_quantmap__16u1__p6_0[] = {
  129524. 7, 5, 3, 1, 0, 2, 4, 6,
  129525. 8,
  129526. };
  129527. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129528. _vq_quantthresh__16u1__p6_0,
  129529. _vq_quantmap__16u1__p6_0,
  129530. 9,
  129531. 9
  129532. };
  129533. static static_codebook _16u1__p6_0 = {
  129534. 2, 81,
  129535. _vq_lengthlist__16u1__p6_0,
  129536. 1, -531628032, 1611661312, 4, 0,
  129537. _vq_quantlist__16u1__p6_0,
  129538. NULL,
  129539. &_vq_auxt__16u1__p6_0,
  129540. NULL,
  129541. 0
  129542. };
  129543. static long _vq_quantlist__16u1__p7_0[] = {
  129544. 1,
  129545. 0,
  129546. 2,
  129547. };
  129548. static long _vq_lengthlist__16u1__p7_0[] = {
  129549. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129550. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129551. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129552. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129553. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129554. 13,
  129555. };
  129556. static float _vq_quantthresh__16u1__p7_0[] = {
  129557. -5.5, 5.5,
  129558. };
  129559. static long _vq_quantmap__16u1__p7_0[] = {
  129560. 1, 0, 2,
  129561. };
  129562. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129563. _vq_quantthresh__16u1__p7_0,
  129564. _vq_quantmap__16u1__p7_0,
  129565. 3,
  129566. 3
  129567. };
  129568. static static_codebook _16u1__p7_0 = {
  129569. 4, 81,
  129570. _vq_lengthlist__16u1__p7_0,
  129571. 1, -529137664, 1618345984, 2, 0,
  129572. _vq_quantlist__16u1__p7_0,
  129573. NULL,
  129574. &_vq_auxt__16u1__p7_0,
  129575. NULL,
  129576. 0
  129577. };
  129578. static long _vq_quantlist__16u1__p7_1[] = {
  129579. 5,
  129580. 4,
  129581. 6,
  129582. 3,
  129583. 7,
  129584. 2,
  129585. 8,
  129586. 1,
  129587. 9,
  129588. 0,
  129589. 10,
  129590. };
  129591. static long _vq_lengthlist__16u1__p7_1[] = {
  129592. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129593. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129594. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129595. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129596. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129597. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129598. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129599. 8, 9, 9,10,10,10,10,10,10,
  129600. };
  129601. static float _vq_quantthresh__16u1__p7_1[] = {
  129602. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129603. 3.5, 4.5,
  129604. };
  129605. static long _vq_quantmap__16u1__p7_1[] = {
  129606. 9, 7, 5, 3, 1, 0, 2, 4,
  129607. 6, 8, 10,
  129608. };
  129609. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129610. _vq_quantthresh__16u1__p7_1,
  129611. _vq_quantmap__16u1__p7_1,
  129612. 11,
  129613. 11
  129614. };
  129615. static static_codebook _16u1__p7_1 = {
  129616. 2, 121,
  129617. _vq_lengthlist__16u1__p7_1,
  129618. 1, -531365888, 1611661312, 4, 0,
  129619. _vq_quantlist__16u1__p7_1,
  129620. NULL,
  129621. &_vq_auxt__16u1__p7_1,
  129622. NULL,
  129623. 0
  129624. };
  129625. static long _vq_quantlist__16u1__p8_0[] = {
  129626. 5,
  129627. 4,
  129628. 6,
  129629. 3,
  129630. 7,
  129631. 2,
  129632. 8,
  129633. 1,
  129634. 9,
  129635. 0,
  129636. 10,
  129637. };
  129638. static long _vq_lengthlist__16u1__p8_0[] = {
  129639. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129640. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129641. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129642. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129643. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129644. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129645. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129646. 13,14,14,15,15,16,16,15,16,
  129647. };
  129648. static float _vq_quantthresh__16u1__p8_0[] = {
  129649. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129650. 38.5, 49.5,
  129651. };
  129652. static long _vq_quantmap__16u1__p8_0[] = {
  129653. 9, 7, 5, 3, 1, 0, 2, 4,
  129654. 6, 8, 10,
  129655. };
  129656. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129657. _vq_quantthresh__16u1__p8_0,
  129658. _vq_quantmap__16u1__p8_0,
  129659. 11,
  129660. 11
  129661. };
  129662. static static_codebook _16u1__p8_0 = {
  129663. 2, 121,
  129664. _vq_lengthlist__16u1__p8_0,
  129665. 1, -524582912, 1618345984, 4, 0,
  129666. _vq_quantlist__16u1__p8_0,
  129667. NULL,
  129668. &_vq_auxt__16u1__p8_0,
  129669. NULL,
  129670. 0
  129671. };
  129672. static long _vq_quantlist__16u1__p8_1[] = {
  129673. 5,
  129674. 4,
  129675. 6,
  129676. 3,
  129677. 7,
  129678. 2,
  129679. 8,
  129680. 1,
  129681. 9,
  129682. 0,
  129683. 10,
  129684. };
  129685. static long _vq_lengthlist__16u1__p8_1[] = {
  129686. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129687. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129688. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129689. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129690. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129691. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129692. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129693. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129694. };
  129695. static float _vq_quantthresh__16u1__p8_1[] = {
  129696. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129697. 3.5, 4.5,
  129698. };
  129699. static long _vq_quantmap__16u1__p8_1[] = {
  129700. 9, 7, 5, 3, 1, 0, 2, 4,
  129701. 6, 8, 10,
  129702. };
  129703. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129704. _vq_quantthresh__16u1__p8_1,
  129705. _vq_quantmap__16u1__p8_1,
  129706. 11,
  129707. 11
  129708. };
  129709. static static_codebook _16u1__p8_1 = {
  129710. 2, 121,
  129711. _vq_lengthlist__16u1__p8_1,
  129712. 1, -531365888, 1611661312, 4, 0,
  129713. _vq_quantlist__16u1__p8_1,
  129714. NULL,
  129715. &_vq_auxt__16u1__p8_1,
  129716. NULL,
  129717. 0
  129718. };
  129719. static long _vq_quantlist__16u1__p9_0[] = {
  129720. 7,
  129721. 6,
  129722. 8,
  129723. 5,
  129724. 9,
  129725. 4,
  129726. 10,
  129727. 3,
  129728. 11,
  129729. 2,
  129730. 12,
  129731. 1,
  129732. 13,
  129733. 0,
  129734. 14,
  129735. };
  129736. static long _vq_lengthlist__16u1__p9_0[] = {
  129737. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129738. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129739. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129740. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129741. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129742. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129743. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129744. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129745. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129746. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129747. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129748. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129749. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129750. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129751. 8,
  129752. };
  129753. static float _vq_quantthresh__16u1__p9_0[] = {
  129754. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129755. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129756. };
  129757. static long _vq_quantmap__16u1__p9_0[] = {
  129758. 13, 11, 9, 7, 5, 3, 1, 0,
  129759. 2, 4, 6, 8, 10, 12, 14,
  129760. };
  129761. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129762. _vq_quantthresh__16u1__p9_0,
  129763. _vq_quantmap__16u1__p9_0,
  129764. 15,
  129765. 15
  129766. };
  129767. static static_codebook _16u1__p9_0 = {
  129768. 2, 225,
  129769. _vq_lengthlist__16u1__p9_0,
  129770. 1, -514071552, 1627381760, 4, 0,
  129771. _vq_quantlist__16u1__p9_0,
  129772. NULL,
  129773. &_vq_auxt__16u1__p9_0,
  129774. NULL,
  129775. 0
  129776. };
  129777. static long _vq_quantlist__16u1__p9_1[] = {
  129778. 7,
  129779. 6,
  129780. 8,
  129781. 5,
  129782. 9,
  129783. 4,
  129784. 10,
  129785. 3,
  129786. 11,
  129787. 2,
  129788. 12,
  129789. 1,
  129790. 13,
  129791. 0,
  129792. 14,
  129793. };
  129794. static long _vq_lengthlist__16u1__p9_1[] = {
  129795. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129796. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129797. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129798. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129799. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129800. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129801. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129802. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129803. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129804. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129805. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129806. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129807. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129808. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129809. 9,
  129810. };
  129811. static float _vq_quantthresh__16u1__p9_1[] = {
  129812. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129813. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129814. };
  129815. static long _vq_quantmap__16u1__p9_1[] = {
  129816. 13, 11, 9, 7, 5, 3, 1, 0,
  129817. 2, 4, 6, 8, 10, 12, 14,
  129818. };
  129819. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129820. _vq_quantthresh__16u1__p9_1,
  129821. _vq_quantmap__16u1__p9_1,
  129822. 15,
  129823. 15
  129824. };
  129825. static static_codebook _16u1__p9_1 = {
  129826. 2, 225,
  129827. _vq_lengthlist__16u1__p9_1,
  129828. 1, -522338304, 1620115456, 4, 0,
  129829. _vq_quantlist__16u1__p9_1,
  129830. NULL,
  129831. &_vq_auxt__16u1__p9_1,
  129832. NULL,
  129833. 0
  129834. };
  129835. static long _vq_quantlist__16u1__p9_2[] = {
  129836. 8,
  129837. 7,
  129838. 9,
  129839. 6,
  129840. 10,
  129841. 5,
  129842. 11,
  129843. 4,
  129844. 12,
  129845. 3,
  129846. 13,
  129847. 2,
  129848. 14,
  129849. 1,
  129850. 15,
  129851. 0,
  129852. 16,
  129853. };
  129854. static long _vq_lengthlist__16u1__p9_2[] = {
  129855. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129856. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129857. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129858. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129859. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129860. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129861. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129862. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129863. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129864. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129865. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129866. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129867. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129868. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129869. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129870. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129871. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129872. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129873. 10,
  129874. };
  129875. static float _vq_quantthresh__16u1__p9_2[] = {
  129876. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129877. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129878. };
  129879. static long _vq_quantmap__16u1__p9_2[] = {
  129880. 15, 13, 11, 9, 7, 5, 3, 1,
  129881. 0, 2, 4, 6, 8, 10, 12, 14,
  129882. 16,
  129883. };
  129884. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129885. _vq_quantthresh__16u1__p9_2,
  129886. _vq_quantmap__16u1__p9_2,
  129887. 17,
  129888. 17
  129889. };
  129890. static static_codebook _16u1__p9_2 = {
  129891. 2, 289,
  129892. _vq_lengthlist__16u1__p9_2,
  129893. 1, -529530880, 1611661312, 5, 0,
  129894. _vq_quantlist__16u1__p9_2,
  129895. NULL,
  129896. &_vq_auxt__16u1__p9_2,
  129897. NULL,
  129898. 0
  129899. };
  129900. static long _huff_lengthlist__16u1__short[] = {
  129901. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129902. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129903. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129904. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129905. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129906. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129907. 16,16,16,16,
  129908. };
  129909. static static_codebook _huff_book__16u1__short = {
  129910. 2, 100,
  129911. _huff_lengthlist__16u1__short,
  129912. 0, 0, 0, 0, 0,
  129913. NULL,
  129914. NULL,
  129915. NULL,
  129916. NULL,
  129917. 0
  129918. };
  129919. static long _huff_lengthlist__16u2__long[] = {
  129920. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129921. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129922. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129923. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129924. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129925. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129926. 13,14,18,18,
  129927. };
  129928. static static_codebook _huff_book__16u2__long = {
  129929. 2, 100,
  129930. _huff_lengthlist__16u2__long,
  129931. 0, 0, 0, 0, 0,
  129932. NULL,
  129933. NULL,
  129934. NULL,
  129935. NULL,
  129936. 0
  129937. };
  129938. static long _huff_lengthlist__16u2__short[] = {
  129939. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129940. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129941. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129942. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129943. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129944. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129945. 16,16,16,16,
  129946. };
  129947. static static_codebook _huff_book__16u2__short = {
  129948. 2, 100,
  129949. _huff_lengthlist__16u2__short,
  129950. 0, 0, 0, 0, 0,
  129951. NULL,
  129952. NULL,
  129953. NULL,
  129954. NULL,
  129955. 0
  129956. };
  129957. static long _vq_quantlist__16u2_p1_0[] = {
  129958. 1,
  129959. 0,
  129960. 2,
  129961. };
  129962. static long _vq_lengthlist__16u2_p1_0[] = {
  129963. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129964. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129965. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129966. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129967. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129968. 10,
  129969. };
  129970. static float _vq_quantthresh__16u2_p1_0[] = {
  129971. -0.5, 0.5,
  129972. };
  129973. static long _vq_quantmap__16u2_p1_0[] = {
  129974. 1, 0, 2,
  129975. };
  129976. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129977. _vq_quantthresh__16u2_p1_0,
  129978. _vq_quantmap__16u2_p1_0,
  129979. 3,
  129980. 3
  129981. };
  129982. static static_codebook _16u2_p1_0 = {
  129983. 4, 81,
  129984. _vq_lengthlist__16u2_p1_0,
  129985. 1, -535822336, 1611661312, 2, 0,
  129986. _vq_quantlist__16u2_p1_0,
  129987. NULL,
  129988. &_vq_auxt__16u2_p1_0,
  129989. NULL,
  129990. 0
  129991. };
  129992. static long _vq_quantlist__16u2_p2_0[] = {
  129993. 2,
  129994. 1,
  129995. 3,
  129996. 0,
  129997. 4,
  129998. };
  129999. static long _vq_lengthlist__16u2_p2_0[] = {
  130000. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  130001. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  130002. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  130003. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  130004. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  130005. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  130006. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  130007. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  130008. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  130009. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  130010. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  130011. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  130012. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  130013. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  130014. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  130015. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  130016. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  130017. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  130018. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  130019. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  130020. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  130021. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  130022. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  130023. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  130024. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  130025. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  130026. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  130027. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  130028. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  130029. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  130030. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  130031. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  130032. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  130033. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  130034. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  130035. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  130036. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  130037. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  130038. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  130039. 13,
  130040. };
  130041. static float _vq_quantthresh__16u2_p2_0[] = {
  130042. -1.5, -0.5, 0.5, 1.5,
  130043. };
  130044. static long _vq_quantmap__16u2_p2_0[] = {
  130045. 3, 1, 0, 2, 4,
  130046. };
  130047. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  130048. _vq_quantthresh__16u2_p2_0,
  130049. _vq_quantmap__16u2_p2_0,
  130050. 5,
  130051. 5
  130052. };
  130053. static static_codebook _16u2_p2_0 = {
  130054. 4, 625,
  130055. _vq_lengthlist__16u2_p2_0,
  130056. 1, -533725184, 1611661312, 3, 0,
  130057. _vq_quantlist__16u2_p2_0,
  130058. NULL,
  130059. &_vq_auxt__16u2_p2_0,
  130060. NULL,
  130061. 0
  130062. };
  130063. static long _vq_quantlist__16u2_p3_0[] = {
  130064. 4,
  130065. 3,
  130066. 5,
  130067. 2,
  130068. 6,
  130069. 1,
  130070. 7,
  130071. 0,
  130072. 8,
  130073. };
  130074. static long _vq_lengthlist__16u2_p3_0[] = {
  130075. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  130076. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  130077. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  130078. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  130079. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  130080. 11,
  130081. };
  130082. static float _vq_quantthresh__16u2_p3_0[] = {
  130083. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130084. };
  130085. static long _vq_quantmap__16u2_p3_0[] = {
  130086. 7, 5, 3, 1, 0, 2, 4, 6,
  130087. 8,
  130088. };
  130089. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  130090. _vq_quantthresh__16u2_p3_0,
  130091. _vq_quantmap__16u2_p3_0,
  130092. 9,
  130093. 9
  130094. };
  130095. static static_codebook _16u2_p3_0 = {
  130096. 2, 81,
  130097. _vq_lengthlist__16u2_p3_0,
  130098. 1, -531628032, 1611661312, 4, 0,
  130099. _vq_quantlist__16u2_p3_0,
  130100. NULL,
  130101. &_vq_auxt__16u2_p3_0,
  130102. NULL,
  130103. 0
  130104. };
  130105. static long _vq_quantlist__16u2_p4_0[] = {
  130106. 8,
  130107. 7,
  130108. 9,
  130109. 6,
  130110. 10,
  130111. 5,
  130112. 11,
  130113. 4,
  130114. 12,
  130115. 3,
  130116. 13,
  130117. 2,
  130118. 14,
  130119. 1,
  130120. 15,
  130121. 0,
  130122. 16,
  130123. };
  130124. static long _vq_lengthlist__16u2_p4_0[] = {
  130125. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  130126. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  130127. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  130128. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  130129. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  130130. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  130131. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  130132. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  130133. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  130134. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  130135. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  130136. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  130137. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  130138. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  130139. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  130140. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  130141. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  130142. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  130143. 14,
  130144. };
  130145. static float _vq_quantthresh__16u2_p4_0[] = {
  130146. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130147. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130148. };
  130149. static long _vq_quantmap__16u2_p4_0[] = {
  130150. 15, 13, 11, 9, 7, 5, 3, 1,
  130151. 0, 2, 4, 6, 8, 10, 12, 14,
  130152. 16,
  130153. };
  130154. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  130155. _vq_quantthresh__16u2_p4_0,
  130156. _vq_quantmap__16u2_p4_0,
  130157. 17,
  130158. 17
  130159. };
  130160. static static_codebook _16u2_p4_0 = {
  130161. 2, 289,
  130162. _vq_lengthlist__16u2_p4_0,
  130163. 1, -529530880, 1611661312, 5, 0,
  130164. _vq_quantlist__16u2_p4_0,
  130165. NULL,
  130166. &_vq_auxt__16u2_p4_0,
  130167. NULL,
  130168. 0
  130169. };
  130170. static long _vq_quantlist__16u2_p5_0[] = {
  130171. 1,
  130172. 0,
  130173. 2,
  130174. };
  130175. static long _vq_lengthlist__16u2_p5_0[] = {
  130176. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  130177. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  130178. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  130179. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  130180. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  130181. 10,
  130182. };
  130183. static float _vq_quantthresh__16u2_p5_0[] = {
  130184. -5.5, 5.5,
  130185. };
  130186. static long _vq_quantmap__16u2_p5_0[] = {
  130187. 1, 0, 2,
  130188. };
  130189. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  130190. _vq_quantthresh__16u2_p5_0,
  130191. _vq_quantmap__16u2_p5_0,
  130192. 3,
  130193. 3
  130194. };
  130195. static static_codebook _16u2_p5_0 = {
  130196. 4, 81,
  130197. _vq_lengthlist__16u2_p5_0,
  130198. 1, -529137664, 1618345984, 2, 0,
  130199. _vq_quantlist__16u2_p5_0,
  130200. NULL,
  130201. &_vq_auxt__16u2_p5_0,
  130202. NULL,
  130203. 0
  130204. };
  130205. static long _vq_quantlist__16u2_p5_1[] = {
  130206. 5,
  130207. 4,
  130208. 6,
  130209. 3,
  130210. 7,
  130211. 2,
  130212. 8,
  130213. 1,
  130214. 9,
  130215. 0,
  130216. 10,
  130217. };
  130218. static long _vq_lengthlist__16u2_p5_1[] = {
  130219. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  130220. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  130221. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  130222. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130223. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130224. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130225. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130226. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  130227. };
  130228. static float _vq_quantthresh__16u2_p5_1[] = {
  130229. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130230. 3.5, 4.5,
  130231. };
  130232. static long _vq_quantmap__16u2_p5_1[] = {
  130233. 9, 7, 5, 3, 1, 0, 2, 4,
  130234. 6, 8, 10,
  130235. };
  130236. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  130237. _vq_quantthresh__16u2_p5_1,
  130238. _vq_quantmap__16u2_p5_1,
  130239. 11,
  130240. 11
  130241. };
  130242. static static_codebook _16u2_p5_1 = {
  130243. 2, 121,
  130244. _vq_lengthlist__16u2_p5_1,
  130245. 1, -531365888, 1611661312, 4, 0,
  130246. _vq_quantlist__16u2_p5_1,
  130247. NULL,
  130248. &_vq_auxt__16u2_p5_1,
  130249. NULL,
  130250. 0
  130251. };
  130252. static long _vq_quantlist__16u2_p6_0[] = {
  130253. 6,
  130254. 5,
  130255. 7,
  130256. 4,
  130257. 8,
  130258. 3,
  130259. 9,
  130260. 2,
  130261. 10,
  130262. 1,
  130263. 11,
  130264. 0,
  130265. 12,
  130266. };
  130267. static long _vq_lengthlist__16u2_p6_0[] = {
  130268. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  130269. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  130270. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  130271. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  130272. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  130273. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  130274. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  130275. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  130276. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  130277. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  130278. 12,13,13,14,14,14,14,15,15,
  130279. };
  130280. static float _vq_quantthresh__16u2_p6_0[] = {
  130281. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130282. 12.5, 17.5, 22.5, 27.5,
  130283. };
  130284. static long _vq_quantmap__16u2_p6_0[] = {
  130285. 11, 9, 7, 5, 3, 1, 0, 2,
  130286. 4, 6, 8, 10, 12,
  130287. };
  130288. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  130289. _vq_quantthresh__16u2_p6_0,
  130290. _vq_quantmap__16u2_p6_0,
  130291. 13,
  130292. 13
  130293. };
  130294. static static_codebook _16u2_p6_0 = {
  130295. 2, 169,
  130296. _vq_lengthlist__16u2_p6_0,
  130297. 1, -526516224, 1616117760, 4, 0,
  130298. _vq_quantlist__16u2_p6_0,
  130299. NULL,
  130300. &_vq_auxt__16u2_p6_0,
  130301. NULL,
  130302. 0
  130303. };
  130304. static long _vq_quantlist__16u2_p6_1[] = {
  130305. 2,
  130306. 1,
  130307. 3,
  130308. 0,
  130309. 4,
  130310. };
  130311. static long _vq_lengthlist__16u2_p6_1[] = {
  130312. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130313. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130314. };
  130315. static float _vq_quantthresh__16u2_p6_1[] = {
  130316. -1.5, -0.5, 0.5, 1.5,
  130317. };
  130318. static long _vq_quantmap__16u2_p6_1[] = {
  130319. 3, 1, 0, 2, 4,
  130320. };
  130321. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130322. _vq_quantthresh__16u2_p6_1,
  130323. _vq_quantmap__16u2_p6_1,
  130324. 5,
  130325. 5
  130326. };
  130327. static static_codebook _16u2_p6_1 = {
  130328. 2, 25,
  130329. _vq_lengthlist__16u2_p6_1,
  130330. 1, -533725184, 1611661312, 3, 0,
  130331. _vq_quantlist__16u2_p6_1,
  130332. NULL,
  130333. &_vq_auxt__16u2_p6_1,
  130334. NULL,
  130335. 0
  130336. };
  130337. static long _vq_quantlist__16u2_p7_0[] = {
  130338. 6,
  130339. 5,
  130340. 7,
  130341. 4,
  130342. 8,
  130343. 3,
  130344. 9,
  130345. 2,
  130346. 10,
  130347. 1,
  130348. 11,
  130349. 0,
  130350. 12,
  130351. };
  130352. static long _vq_lengthlist__16u2_p7_0[] = {
  130353. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130354. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130355. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130356. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130357. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130358. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130359. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130360. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130361. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130362. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130363. 12,13,13,13,14,14,14,15,14,
  130364. };
  130365. static float _vq_quantthresh__16u2_p7_0[] = {
  130366. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130367. 27.5, 38.5, 49.5, 60.5,
  130368. };
  130369. static long _vq_quantmap__16u2_p7_0[] = {
  130370. 11, 9, 7, 5, 3, 1, 0, 2,
  130371. 4, 6, 8, 10, 12,
  130372. };
  130373. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130374. _vq_quantthresh__16u2_p7_0,
  130375. _vq_quantmap__16u2_p7_0,
  130376. 13,
  130377. 13
  130378. };
  130379. static static_codebook _16u2_p7_0 = {
  130380. 2, 169,
  130381. _vq_lengthlist__16u2_p7_0,
  130382. 1, -523206656, 1618345984, 4, 0,
  130383. _vq_quantlist__16u2_p7_0,
  130384. NULL,
  130385. &_vq_auxt__16u2_p7_0,
  130386. NULL,
  130387. 0
  130388. };
  130389. static long _vq_quantlist__16u2_p7_1[] = {
  130390. 5,
  130391. 4,
  130392. 6,
  130393. 3,
  130394. 7,
  130395. 2,
  130396. 8,
  130397. 1,
  130398. 9,
  130399. 0,
  130400. 10,
  130401. };
  130402. static long _vq_lengthlist__16u2_p7_1[] = {
  130403. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130404. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130405. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130406. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130407. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130408. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130409. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130410. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130411. };
  130412. static float _vq_quantthresh__16u2_p7_1[] = {
  130413. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130414. 3.5, 4.5,
  130415. };
  130416. static long _vq_quantmap__16u2_p7_1[] = {
  130417. 9, 7, 5, 3, 1, 0, 2, 4,
  130418. 6, 8, 10,
  130419. };
  130420. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130421. _vq_quantthresh__16u2_p7_1,
  130422. _vq_quantmap__16u2_p7_1,
  130423. 11,
  130424. 11
  130425. };
  130426. static static_codebook _16u2_p7_1 = {
  130427. 2, 121,
  130428. _vq_lengthlist__16u2_p7_1,
  130429. 1, -531365888, 1611661312, 4, 0,
  130430. _vq_quantlist__16u2_p7_1,
  130431. NULL,
  130432. &_vq_auxt__16u2_p7_1,
  130433. NULL,
  130434. 0
  130435. };
  130436. static long _vq_quantlist__16u2_p8_0[] = {
  130437. 7,
  130438. 6,
  130439. 8,
  130440. 5,
  130441. 9,
  130442. 4,
  130443. 10,
  130444. 3,
  130445. 11,
  130446. 2,
  130447. 12,
  130448. 1,
  130449. 13,
  130450. 0,
  130451. 14,
  130452. };
  130453. static long _vq_lengthlist__16u2_p8_0[] = {
  130454. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130455. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130456. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130457. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130458. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130459. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130460. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130461. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130462. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130463. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130464. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130465. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130466. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130467. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130468. 14,
  130469. };
  130470. static float _vq_quantthresh__16u2_p8_0[] = {
  130471. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130472. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130473. };
  130474. static long _vq_quantmap__16u2_p8_0[] = {
  130475. 13, 11, 9, 7, 5, 3, 1, 0,
  130476. 2, 4, 6, 8, 10, 12, 14,
  130477. };
  130478. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130479. _vq_quantthresh__16u2_p8_0,
  130480. _vq_quantmap__16u2_p8_0,
  130481. 15,
  130482. 15
  130483. };
  130484. static static_codebook _16u2_p8_0 = {
  130485. 2, 225,
  130486. _vq_lengthlist__16u2_p8_0,
  130487. 1, -520986624, 1620377600, 4, 0,
  130488. _vq_quantlist__16u2_p8_0,
  130489. NULL,
  130490. &_vq_auxt__16u2_p8_0,
  130491. NULL,
  130492. 0
  130493. };
  130494. static long _vq_quantlist__16u2_p8_1[] = {
  130495. 10,
  130496. 9,
  130497. 11,
  130498. 8,
  130499. 12,
  130500. 7,
  130501. 13,
  130502. 6,
  130503. 14,
  130504. 5,
  130505. 15,
  130506. 4,
  130507. 16,
  130508. 3,
  130509. 17,
  130510. 2,
  130511. 18,
  130512. 1,
  130513. 19,
  130514. 0,
  130515. 20,
  130516. };
  130517. static long _vq_lengthlist__16u2_p8_1[] = {
  130518. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130519. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130520. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130521. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130522. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130523. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130524. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130525. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130526. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130527. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130528. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130529. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130530. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130531. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130532. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130533. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130534. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130535. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130536. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130537. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130538. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130539. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130540. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130541. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130542. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130543. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130544. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130545. 11,11,10,11,11,11,10,11,11,
  130546. };
  130547. static float _vq_quantthresh__16u2_p8_1[] = {
  130548. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130549. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130550. 6.5, 7.5, 8.5, 9.5,
  130551. };
  130552. static long _vq_quantmap__16u2_p8_1[] = {
  130553. 19, 17, 15, 13, 11, 9, 7, 5,
  130554. 3, 1, 0, 2, 4, 6, 8, 10,
  130555. 12, 14, 16, 18, 20,
  130556. };
  130557. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130558. _vq_quantthresh__16u2_p8_1,
  130559. _vq_quantmap__16u2_p8_1,
  130560. 21,
  130561. 21
  130562. };
  130563. static static_codebook _16u2_p8_1 = {
  130564. 2, 441,
  130565. _vq_lengthlist__16u2_p8_1,
  130566. 1, -529268736, 1611661312, 5, 0,
  130567. _vq_quantlist__16u2_p8_1,
  130568. NULL,
  130569. &_vq_auxt__16u2_p8_1,
  130570. NULL,
  130571. 0
  130572. };
  130573. static long _vq_quantlist__16u2_p9_0[] = {
  130574. 5586,
  130575. 4655,
  130576. 6517,
  130577. 3724,
  130578. 7448,
  130579. 2793,
  130580. 8379,
  130581. 1862,
  130582. 9310,
  130583. 931,
  130584. 10241,
  130585. 0,
  130586. 11172,
  130587. 5521,
  130588. 5651,
  130589. };
  130590. static long _vq_lengthlist__16u2_p9_0[] = {
  130591. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130592. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130593. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130594. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130595. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130596. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130597. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130598. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130599. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130600. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130601. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130602. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130603. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130604. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130605. 5,
  130606. };
  130607. static float _vq_quantthresh__16u2_p9_0[] = {
  130608. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130609. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130610. };
  130611. static long _vq_quantmap__16u2_p9_0[] = {
  130612. 11, 9, 7, 5, 3, 1, 13, 0,
  130613. 14, 2, 4, 6, 8, 10, 12,
  130614. };
  130615. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130616. _vq_quantthresh__16u2_p9_0,
  130617. _vq_quantmap__16u2_p9_0,
  130618. 15,
  130619. 15
  130620. };
  130621. static static_codebook _16u2_p9_0 = {
  130622. 2, 225,
  130623. _vq_lengthlist__16u2_p9_0,
  130624. 1, -510275072, 1611661312, 14, 0,
  130625. _vq_quantlist__16u2_p9_0,
  130626. NULL,
  130627. &_vq_auxt__16u2_p9_0,
  130628. NULL,
  130629. 0
  130630. };
  130631. static long _vq_quantlist__16u2_p9_1[] = {
  130632. 392,
  130633. 343,
  130634. 441,
  130635. 294,
  130636. 490,
  130637. 245,
  130638. 539,
  130639. 196,
  130640. 588,
  130641. 147,
  130642. 637,
  130643. 98,
  130644. 686,
  130645. 49,
  130646. 735,
  130647. 0,
  130648. 784,
  130649. 388,
  130650. 396,
  130651. };
  130652. static long _vq_lengthlist__16u2_p9_1[] = {
  130653. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130654. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130655. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130656. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130657. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130658. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130659. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130660. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130661. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130662. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130663. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130664. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130665. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130666. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130667. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130668. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130669. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130670. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130671. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130672. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130673. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130674. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130675. 11,11,11,11,11,11,11, 5, 4,
  130676. };
  130677. static float _vq_quantthresh__16u2_p9_1[] = {
  130678. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130679. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130680. 318.5, 367.5,
  130681. };
  130682. static long _vq_quantmap__16u2_p9_1[] = {
  130683. 15, 13, 11, 9, 7, 5, 3, 1,
  130684. 17, 0, 18, 2, 4, 6, 8, 10,
  130685. 12, 14, 16,
  130686. };
  130687. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130688. _vq_quantthresh__16u2_p9_1,
  130689. _vq_quantmap__16u2_p9_1,
  130690. 19,
  130691. 19
  130692. };
  130693. static static_codebook _16u2_p9_1 = {
  130694. 2, 361,
  130695. _vq_lengthlist__16u2_p9_1,
  130696. 1, -518488064, 1611661312, 10, 0,
  130697. _vq_quantlist__16u2_p9_1,
  130698. NULL,
  130699. &_vq_auxt__16u2_p9_1,
  130700. NULL,
  130701. 0
  130702. };
  130703. static long _vq_quantlist__16u2_p9_2[] = {
  130704. 24,
  130705. 23,
  130706. 25,
  130707. 22,
  130708. 26,
  130709. 21,
  130710. 27,
  130711. 20,
  130712. 28,
  130713. 19,
  130714. 29,
  130715. 18,
  130716. 30,
  130717. 17,
  130718. 31,
  130719. 16,
  130720. 32,
  130721. 15,
  130722. 33,
  130723. 14,
  130724. 34,
  130725. 13,
  130726. 35,
  130727. 12,
  130728. 36,
  130729. 11,
  130730. 37,
  130731. 10,
  130732. 38,
  130733. 9,
  130734. 39,
  130735. 8,
  130736. 40,
  130737. 7,
  130738. 41,
  130739. 6,
  130740. 42,
  130741. 5,
  130742. 43,
  130743. 4,
  130744. 44,
  130745. 3,
  130746. 45,
  130747. 2,
  130748. 46,
  130749. 1,
  130750. 47,
  130751. 0,
  130752. 48,
  130753. };
  130754. static long _vq_lengthlist__16u2_p9_2[] = {
  130755. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130756. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130757. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130758. 11,
  130759. };
  130760. static float _vq_quantthresh__16u2_p9_2[] = {
  130761. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130762. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130763. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130764. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130765. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130766. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130767. };
  130768. static long _vq_quantmap__16u2_p9_2[] = {
  130769. 47, 45, 43, 41, 39, 37, 35, 33,
  130770. 31, 29, 27, 25, 23, 21, 19, 17,
  130771. 15, 13, 11, 9, 7, 5, 3, 1,
  130772. 0, 2, 4, 6, 8, 10, 12, 14,
  130773. 16, 18, 20, 22, 24, 26, 28, 30,
  130774. 32, 34, 36, 38, 40, 42, 44, 46,
  130775. 48,
  130776. };
  130777. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130778. _vq_quantthresh__16u2_p9_2,
  130779. _vq_quantmap__16u2_p9_2,
  130780. 49,
  130781. 49
  130782. };
  130783. static static_codebook _16u2_p9_2 = {
  130784. 1, 49,
  130785. _vq_lengthlist__16u2_p9_2,
  130786. 1, -526909440, 1611661312, 6, 0,
  130787. _vq_quantlist__16u2_p9_2,
  130788. NULL,
  130789. &_vq_auxt__16u2_p9_2,
  130790. NULL,
  130791. 0
  130792. };
  130793. static long _vq_quantlist__8u0__p1_0[] = {
  130794. 1,
  130795. 0,
  130796. 2,
  130797. };
  130798. static long _vq_lengthlist__8u0__p1_0[] = {
  130799. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130800. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130801. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130802. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130803. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130804. 11,
  130805. };
  130806. static float _vq_quantthresh__8u0__p1_0[] = {
  130807. -0.5, 0.5,
  130808. };
  130809. static long _vq_quantmap__8u0__p1_0[] = {
  130810. 1, 0, 2,
  130811. };
  130812. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130813. _vq_quantthresh__8u0__p1_0,
  130814. _vq_quantmap__8u0__p1_0,
  130815. 3,
  130816. 3
  130817. };
  130818. static static_codebook _8u0__p1_0 = {
  130819. 4, 81,
  130820. _vq_lengthlist__8u0__p1_0,
  130821. 1, -535822336, 1611661312, 2, 0,
  130822. _vq_quantlist__8u0__p1_0,
  130823. NULL,
  130824. &_vq_auxt__8u0__p1_0,
  130825. NULL,
  130826. 0
  130827. };
  130828. static long _vq_quantlist__8u0__p2_0[] = {
  130829. 1,
  130830. 0,
  130831. 2,
  130832. };
  130833. static long _vq_lengthlist__8u0__p2_0[] = {
  130834. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130835. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130836. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130837. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130838. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130839. 8,
  130840. };
  130841. static float _vq_quantthresh__8u0__p2_0[] = {
  130842. -0.5, 0.5,
  130843. };
  130844. static long _vq_quantmap__8u0__p2_0[] = {
  130845. 1, 0, 2,
  130846. };
  130847. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130848. _vq_quantthresh__8u0__p2_0,
  130849. _vq_quantmap__8u0__p2_0,
  130850. 3,
  130851. 3
  130852. };
  130853. static static_codebook _8u0__p2_0 = {
  130854. 4, 81,
  130855. _vq_lengthlist__8u0__p2_0,
  130856. 1, -535822336, 1611661312, 2, 0,
  130857. _vq_quantlist__8u0__p2_0,
  130858. NULL,
  130859. &_vq_auxt__8u0__p2_0,
  130860. NULL,
  130861. 0
  130862. };
  130863. static long _vq_quantlist__8u0__p3_0[] = {
  130864. 2,
  130865. 1,
  130866. 3,
  130867. 0,
  130868. 4,
  130869. };
  130870. static long _vq_lengthlist__8u0__p3_0[] = {
  130871. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130872. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130873. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130874. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130875. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130876. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130877. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130878. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130879. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130880. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130881. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130882. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130883. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130884. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130885. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130886. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130887. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130888. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130889. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130890. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130891. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130892. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130893. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130894. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130895. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130896. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130897. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130898. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130899. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130900. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130901. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130902. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130903. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130904. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130905. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130906. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130907. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130908. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130909. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130910. 16,
  130911. };
  130912. static float _vq_quantthresh__8u0__p3_0[] = {
  130913. -1.5, -0.5, 0.5, 1.5,
  130914. };
  130915. static long _vq_quantmap__8u0__p3_0[] = {
  130916. 3, 1, 0, 2, 4,
  130917. };
  130918. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130919. _vq_quantthresh__8u0__p3_0,
  130920. _vq_quantmap__8u0__p3_0,
  130921. 5,
  130922. 5
  130923. };
  130924. static static_codebook _8u0__p3_0 = {
  130925. 4, 625,
  130926. _vq_lengthlist__8u0__p3_0,
  130927. 1, -533725184, 1611661312, 3, 0,
  130928. _vq_quantlist__8u0__p3_0,
  130929. NULL,
  130930. &_vq_auxt__8u0__p3_0,
  130931. NULL,
  130932. 0
  130933. };
  130934. static long _vq_quantlist__8u0__p4_0[] = {
  130935. 2,
  130936. 1,
  130937. 3,
  130938. 0,
  130939. 4,
  130940. };
  130941. static long _vq_lengthlist__8u0__p4_0[] = {
  130942. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130943. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130944. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130945. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130946. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130947. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130948. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130949. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130950. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130951. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130952. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130953. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130954. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130955. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130956. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130957. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130958. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130959. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130960. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130961. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130962. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130963. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130964. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130965. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130966. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130967. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130968. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130969. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130970. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130971. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130972. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130973. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130974. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130975. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130976. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130977. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130978. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130979. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130980. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130981. 12,
  130982. };
  130983. static float _vq_quantthresh__8u0__p4_0[] = {
  130984. -1.5, -0.5, 0.5, 1.5,
  130985. };
  130986. static long _vq_quantmap__8u0__p4_0[] = {
  130987. 3, 1, 0, 2, 4,
  130988. };
  130989. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130990. _vq_quantthresh__8u0__p4_0,
  130991. _vq_quantmap__8u0__p4_0,
  130992. 5,
  130993. 5
  130994. };
  130995. static static_codebook _8u0__p4_0 = {
  130996. 4, 625,
  130997. _vq_lengthlist__8u0__p4_0,
  130998. 1, -533725184, 1611661312, 3, 0,
  130999. _vq_quantlist__8u0__p4_0,
  131000. NULL,
  131001. &_vq_auxt__8u0__p4_0,
  131002. NULL,
  131003. 0
  131004. };
  131005. static long _vq_quantlist__8u0__p5_0[] = {
  131006. 4,
  131007. 3,
  131008. 5,
  131009. 2,
  131010. 6,
  131011. 1,
  131012. 7,
  131013. 0,
  131014. 8,
  131015. };
  131016. static long _vq_lengthlist__8u0__p5_0[] = {
  131017. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  131018. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  131019. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  131020. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131021. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  131022. 12,
  131023. };
  131024. static float _vq_quantthresh__8u0__p5_0[] = {
  131025. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131026. };
  131027. static long _vq_quantmap__8u0__p5_0[] = {
  131028. 7, 5, 3, 1, 0, 2, 4, 6,
  131029. 8,
  131030. };
  131031. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  131032. _vq_quantthresh__8u0__p5_0,
  131033. _vq_quantmap__8u0__p5_0,
  131034. 9,
  131035. 9
  131036. };
  131037. static static_codebook _8u0__p5_0 = {
  131038. 2, 81,
  131039. _vq_lengthlist__8u0__p5_0,
  131040. 1, -531628032, 1611661312, 4, 0,
  131041. _vq_quantlist__8u0__p5_0,
  131042. NULL,
  131043. &_vq_auxt__8u0__p5_0,
  131044. NULL,
  131045. 0
  131046. };
  131047. static long _vq_quantlist__8u0__p6_0[] = {
  131048. 6,
  131049. 5,
  131050. 7,
  131051. 4,
  131052. 8,
  131053. 3,
  131054. 9,
  131055. 2,
  131056. 10,
  131057. 1,
  131058. 11,
  131059. 0,
  131060. 12,
  131061. };
  131062. static long _vq_lengthlist__8u0__p6_0[] = {
  131063. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  131064. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  131065. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  131066. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  131067. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  131068. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  131069. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  131070. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  131071. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  131072. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  131073. 16, 0,15, 0,17, 0, 0, 0, 0,
  131074. };
  131075. static float _vq_quantthresh__8u0__p6_0[] = {
  131076. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131077. 12.5, 17.5, 22.5, 27.5,
  131078. };
  131079. static long _vq_quantmap__8u0__p6_0[] = {
  131080. 11, 9, 7, 5, 3, 1, 0, 2,
  131081. 4, 6, 8, 10, 12,
  131082. };
  131083. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  131084. _vq_quantthresh__8u0__p6_0,
  131085. _vq_quantmap__8u0__p6_0,
  131086. 13,
  131087. 13
  131088. };
  131089. static static_codebook _8u0__p6_0 = {
  131090. 2, 169,
  131091. _vq_lengthlist__8u0__p6_0,
  131092. 1, -526516224, 1616117760, 4, 0,
  131093. _vq_quantlist__8u0__p6_0,
  131094. NULL,
  131095. &_vq_auxt__8u0__p6_0,
  131096. NULL,
  131097. 0
  131098. };
  131099. static long _vq_quantlist__8u0__p6_1[] = {
  131100. 2,
  131101. 1,
  131102. 3,
  131103. 0,
  131104. 4,
  131105. };
  131106. static long _vq_lengthlist__8u0__p6_1[] = {
  131107. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  131108. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  131109. };
  131110. static float _vq_quantthresh__8u0__p6_1[] = {
  131111. -1.5, -0.5, 0.5, 1.5,
  131112. };
  131113. static long _vq_quantmap__8u0__p6_1[] = {
  131114. 3, 1, 0, 2, 4,
  131115. };
  131116. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  131117. _vq_quantthresh__8u0__p6_1,
  131118. _vq_quantmap__8u0__p6_1,
  131119. 5,
  131120. 5
  131121. };
  131122. static static_codebook _8u0__p6_1 = {
  131123. 2, 25,
  131124. _vq_lengthlist__8u0__p6_1,
  131125. 1, -533725184, 1611661312, 3, 0,
  131126. _vq_quantlist__8u0__p6_1,
  131127. NULL,
  131128. &_vq_auxt__8u0__p6_1,
  131129. NULL,
  131130. 0
  131131. };
  131132. static long _vq_quantlist__8u0__p7_0[] = {
  131133. 1,
  131134. 0,
  131135. 2,
  131136. };
  131137. static long _vq_lengthlist__8u0__p7_0[] = {
  131138. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131139. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131140. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131141. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131142. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131143. 7,
  131144. };
  131145. static float _vq_quantthresh__8u0__p7_0[] = {
  131146. -157.5, 157.5,
  131147. };
  131148. static long _vq_quantmap__8u0__p7_0[] = {
  131149. 1, 0, 2,
  131150. };
  131151. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  131152. _vq_quantthresh__8u0__p7_0,
  131153. _vq_quantmap__8u0__p7_0,
  131154. 3,
  131155. 3
  131156. };
  131157. static static_codebook _8u0__p7_0 = {
  131158. 4, 81,
  131159. _vq_lengthlist__8u0__p7_0,
  131160. 1, -518803456, 1628680192, 2, 0,
  131161. _vq_quantlist__8u0__p7_0,
  131162. NULL,
  131163. &_vq_auxt__8u0__p7_0,
  131164. NULL,
  131165. 0
  131166. };
  131167. static long _vq_quantlist__8u0__p7_1[] = {
  131168. 7,
  131169. 6,
  131170. 8,
  131171. 5,
  131172. 9,
  131173. 4,
  131174. 10,
  131175. 3,
  131176. 11,
  131177. 2,
  131178. 12,
  131179. 1,
  131180. 13,
  131181. 0,
  131182. 14,
  131183. };
  131184. static long _vq_lengthlist__8u0__p7_1[] = {
  131185. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  131186. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  131187. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  131188. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  131189. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  131190. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  131191. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131192. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131193. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131194. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131195. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131196. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131197. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  131198. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131199. 10,
  131200. };
  131201. static float _vq_quantthresh__8u0__p7_1[] = {
  131202. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  131203. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  131204. };
  131205. static long _vq_quantmap__8u0__p7_1[] = {
  131206. 13, 11, 9, 7, 5, 3, 1, 0,
  131207. 2, 4, 6, 8, 10, 12, 14,
  131208. };
  131209. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  131210. _vq_quantthresh__8u0__p7_1,
  131211. _vq_quantmap__8u0__p7_1,
  131212. 15,
  131213. 15
  131214. };
  131215. static static_codebook _8u0__p7_1 = {
  131216. 2, 225,
  131217. _vq_lengthlist__8u0__p7_1,
  131218. 1, -520986624, 1620377600, 4, 0,
  131219. _vq_quantlist__8u0__p7_1,
  131220. NULL,
  131221. &_vq_auxt__8u0__p7_1,
  131222. NULL,
  131223. 0
  131224. };
  131225. static long _vq_quantlist__8u0__p7_2[] = {
  131226. 10,
  131227. 9,
  131228. 11,
  131229. 8,
  131230. 12,
  131231. 7,
  131232. 13,
  131233. 6,
  131234. 14,
  131235. 5,
  131236. 15,
  131237. 4,
  131238. 16,
  131239. 3,
  131240. 17,
  131241. 2,
  131242. 18,
  131243. 1,
  131244. 19,
  131245. 0,
  131246. 20,
  131247. };
  131248. static long _vq_lengthlist__8u0__p7_2[] = {
  131249. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  131250. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  131251. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  131252. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  131253. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  131254. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  131255. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  131256. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  131257. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  131258. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  131259. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  131260. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  131261. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  131262. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  131263. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  131264. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  131265. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  131266. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  131267. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  131268. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  131269. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  131270. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  131271. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  131272. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  131273. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  131274. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  131275. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  131276. 11,12,11,11,11,10,10,11,11,
  131277. };
  131278. static float _vq_quantthresh__8u0__p7_2[] = {
  131279. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  131280. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  131281. 6.5, 7.5, 8.5, 9.5,
  131282. };
  131283. static long _vq_quantmap__8u0__p7_2[] = {
  131284. 19, 17, 15, 13, 11, 9, 7, 5,
  131285. 3, 1, 0, 2, 4, 6, 8, 10,
  131286. 12, 14, 16, 18, 20,
  131287. };
  131288. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  131289. _vq_quantthresh__8u0__p7_2,
  131290. _vq_quantmap__8u0__p7_2,
  131291. 21,
  131292. 21
  131293. };
  131294. static static_codebook _8u0__p7_2 = {
  131295. 2, 441,
  131296. _vq_lengthlist__8u0__p7_2,
  131297. 1, -529268736, 1611661312, 5, 0,
  131298. _vq_quantlist__8u0__p7_2,
  131299. NULL,
  131300. &_vq_auxt__8u0__p7_2,
  131301. NULL,
  131302. 0
  131303. };
  131304. static long _huff_lengthlist__8u0__single[] = {
  131305. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131306. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131307. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131308. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131309. };
  131310. static static_codebook _huff_book__8u0__single = {
  131311. 2, 64,
  131312. _huff_lengthlist__8u0__single,
  131313. 0, 0, 0, 0, 0,
  131314. NULL,
  131315. NULL,
  131316. NULL,
  131317. NULL,
  131318. 0
  131319. };
  131320. static long _vq_quantlist__8u1__p1_0[] = {
  131321. 1,
  131322. 0,
  131323. 2,
  131324. };
  131325. static long _vq_lengthlist__8u1__p1_0[] = {
  131326. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131327. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131328. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131329. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131330. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131331. 10,
  131332. };
  131333. static float _vq_quantthresh__8u1__p1_0[] = {
  131334. -0.5, 0.5,
  131335. };
  131336. static long _vq_quantmap__8u1__p1_0[] = {
  131337. 1, 0, 2,
  131338. };
  131339. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131340. _vq_quantthresh__8u1__p1_0,
  131341. _vq_quantmap__8u1__p1_0,
  131342. 3,
  131343. 3
  131344. };
  131345. static static_codebook _8u1__p1_0 = {
  131346. 4, 81,
  131347. _vq_lengthlist__8u1__p1_0,
  131348. 1, -535822336, 1611661312, 2, 0,
  131349. _vq_quantlist__8u1__p1_0,
  131350. NULL,
  131351. &_vq_auxt__8u1__p1_0,
  131352. NULL,
  131353. 0
  131354. };
  131355. static long _vq_quantlist__8u1__p2_0[] = {
  131356. 1,
  131357. 0,
  131358. 2,
  131359. };
  131360. static long _vq_lengthlist__8u1__p2_0[] = {
  131361. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131362. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131363. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131364. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131365. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131366. 7,
  131367. };
  131368. static float _vq_quantthresh__8u1__p2_0[] = {
  131369. -0.5, 0.5,
  131370. };
  131371. static long _vq_quantmap__8u1__p2_0[] = {
  131372. 1, 0, 2,
  131373. };
  131374. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131375. _vq_quantthresh__8u1__p2_0,
  131376. _vq_quantmap__8u1__p2_0,
  131377. 3,
  131378. 3
  131379. };
  131380. static static_codebook _8u1__p2_0 = {
  131381. 4, 81,
  131382. _vq_lengthlist__8u1__p2_0,
  131383. 1, -535822336, 1611661312, 2, 0,
  131384. _vq_quantlist__8u1__p2_0,
  131385. NULL,
  131386. &_vq_auxt__8u1__p2_0,
  131387. NULL,
  131388. 0
  131389. };
  131390. static long _vq_quantlist__8u1__p3_0[] = {
  131391. 2,
  131392. 1,
  131393. 3,
  131394. 0,
  131395. 4,
  131396. };
  131397. static long _vq_lengthlist__8u1__p3_0[] = {
  131398. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131399. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131400. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131401. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131402. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131403. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131404. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131405. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131406. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131407. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131408. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131409. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131410. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131411. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131412. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131413. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131414. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131415. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131416. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131417. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131418. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131419. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131420. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131421. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131422. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131423. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131424. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131425. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131426. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131427. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131428. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131429. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131430. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131431. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131432. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131433. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131434. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131435. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131436. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131437. 16,
  131438. };
  131439. static float _vq_quantthresh__8u1__p3_0[] = {
  131440. -1.5, -0.5, 0.5, 1.5,
  131441. };
  131442. static long _vq_quantmap__8u1__p3_0[] = {
  131443. 3, 1, 0, 2, 4,
  131444. };
  131445. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131446. _vq_quantthresh__8u1__p3_0,
  131447. _vq_quantmap__8u1__p3_0,
  131448. 5,
  131449. 5
  131450. };
  131451. static static_codebook _8u1__p3_0 = {
  131452. 4, 625,
  131453. _vq_lengthlist__8u1__p3_0,
  131454. 1, -533725184, 1611661312, 3, 0,
  131455. _vq_quantlist__8u1__p3_0,
  131456. NULL,
  131457. &_vq_auxt__8u1__p3_0,
  131458. NULL,
  131459. 0
  131460. };
  131461. static long _vq_quantlist__8u1__p4_0[] = {
  131462. 2,
  131463. 1,
  131464. 3,
  131465. 0,
  131466. 4,
  131467. };
  131468. static long _vq_lengthlist__8u1__p4_0[] = {
  131469. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131470. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131471. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131472. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131473. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131474. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131475. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131476. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131477. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131478. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131479. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131480. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131481. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131482. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131483. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131484. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131485. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131486. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131487. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131488. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131489. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131490. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131491. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131492. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131493. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131494. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131495. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131496. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131497. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131498. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131499. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131500. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131501. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131502. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131503. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131504. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131505. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131506. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131507. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131508. 10,
  131509. };
  131510. static float _vq_quantthresh__8u1__p4_0[] = {
  131511. -1.5, -0.5, 0.5, 1.5,
  131512. };
  131513. static long _vq_quantmap__8u1__p4_0[] = {
  131514. 3, 1, 0, 2, 4,
  131515. };
  131516. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131517. _vq_quantthresh__8u1__p4_0,
  131518. _vq_quantmap__8u1__p4_0,
  131519. 5,
  131520. 5
  131521. };
  131522. static static_codebook _8u1__p4_0 = {
  131523. 4, 625,
  131524. _vq_lengthlist__8u1__p4_0,
  131525. 1, -533725184, 1611661312, 3, 0,
  131526. _vq_quantlist__8u1__p4_0,
  131527. NULL,
  131528. &_vq_auxt__8u1__p4_0,
  131529. NULL,
  131530. 0
  131531. };
  131532. static long _vq_quantlist__8u1__p5_0[] = {
  131533. 4,
  131534. 3,
  131535. 5,
  131536. 2,
  131537. 6,
  131538. 1,
  131539. 7,
  131540. 0,
  131541. 8,
  131542. };
  131543. static long _vq_lengthlist__8u1__p5_0[] = {
  131544. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131545. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131546. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131547. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131548. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131549. 13,
  131550. };
  131551. static float _vq_quantthresh__8u1__p5_0[] = {
  131552. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131553. };
  131554. static long _vq_quantmap__8u1__p5_0[] = {
  131555. 7, 5, 3, 1, 0, 2, 4, 6,
  131556. 8,
  131557. };
  131558. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131559. _vq_quantthresh__8u1__p5_0,
  131560. _vq_quantmap__8u1__p5_0,
  131561. 9,
  131562. 9
  131563. };
  131564. static static_codebook _8u1__p5_0 = {
  131565. 2, 81,
  131566. _vq_lengthlist__8u1__p5_0,
  131567. 1, -531628032, 1611661312, 4, 0,
  131568. _vq_quantlist__8u1__p5_0,
  131569. NULL,
  131570. &_vq_auxt__8u1__p5_0,
  131571. NULL,
  131572. 0
  131573. };
  131574. static long _vq_quantlist__8u1__p6_0[] = {
  131575. 4,
  131576. 3,
  131577. 5,
  131578. 2,
  131579. 6,
  131580. 1,
  131581. 7,
  131582. 0,
  131583. 8,
  131584. };
  131585. static long _vq_lengthlist__8u1__p6_0[] = {
  131586. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131587. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131588. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131589. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131590. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131591. 10,
  131592. };
  131593. static float _vq_quantthresh__8u1__p6_0[] = {
  131594. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131595. };
  131596. static long _vq_quantmap__8u1__p6_0[] = {
  131597. 7, 5, 3, 1, 0, 2, 4, 6,
  131598. 8,
  131599. };
  131600. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131601. _vq_quantthresh__8u1__p6_0,
  131602. _vq_quantmap__8u1__p6_0,
  131603. 9,
  131604. 9
  131605. };
  131606. static static_codebook _8u1__p6_0 = {
  131607. 2, 81,
  131608. _vq_lengthlist__8u1__p6_0,
  131609. 1, -531628032, 1611661312, 4, 0,
  131610. _vq_quantlist__8u1__p6_0,
  131611. NULL,
  131612. &_vq_auxt__8u1__p6_0,
  131613. NULL,
  131614. 0
  131615. };
  131616. static long _vq_quantlist__8u1__p7_0[] = {
  131617. 1,
  131618. 0,
  131619. 2,
  131620. };
  131621. static long _vq_lengthlist__8u1__p7_0[] = {
  131622. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131623. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131624. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131625. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131626. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131627. 11,
  131628. };
  131629. static float _vq_quantthresh__8u1__p7_0[] = {
  131630. -5.5, 5.5,
  131631. };
  131632. static long _vq_quantmap__8u1__p7_0[] = {
  131633. 1, 0, 2,
  131634. };
  131635. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131636. _vq_quantthresh__8u1__p7_0,
  131637. _vq_quantmap__8u1__p7_0,
  131638. 3,
  131639. 3
  131640. };
  131641. static static_codebook _8u1__p7_0 = {
  131642. 4, 81,
  131643. _vq_lengthlist__8u1__p7_0,
  131644. 1, -529137664, 1618345984, 2, 0,
  131645. _vq_quantlist__8u1__p7_0,
  131646. NULL,
  131647. &_vq_auxt__8u1__p7_0,
  131648. NULL,
  131649. 0
  131650. };
  131651. static long _vq_quantlist__8u1__p7_1[] = {
  131652. 5,
  131653. 4,
  131654. 6,
  131655. 3,
  131656. 7,
  131657. 2,
  131658. 8,
  131659. 1,
  131660. 9,
  131661. 0,
  131662. 10,
  131663. };
  131664. static long _vq_lengthlist__8u1__p7_1[] = {
  131665. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131666. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131667. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131668. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131669. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131670. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131671. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131672. 9, 9, 9, 9, 9,10,10,10,10,
  131673. };
  131674. static float _vq_quantthresh__8u1__p7_1[] = {
  131675. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131676. 3.5, 4.5,
  131677. };
  131678. static long _vq_quantmap__8u1__p7_1[] = {
  131679. 9, 7, 5, 3, 1, 0, 2, 4,
  131680. 6, 8, 10,
  131681. };
  131682. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131683. _vq_quantthresh__8u1__p7_1,
  131684. _vq_quantmap__8u1__p7_1,
  131685. 11,
  131686. 11
  131687. };
  131688. static static_codebook _8u1__p7_1 = {
  131689. 2, 121,
  131690. _vq_lengthlist__8u1__p7_1,
  131691. 1, -531365888, 1611661312, 4, 0,
  131692. _vq_quantlist__8u1__p7_1,
  131693. NULL,
  131694. &_vq_auxt__8u1__p7_1,
  131695. NULL,
  131696. 0
  131697. };
  131698. static long _vq_quantlist__8u1__p8_0[] = {
  131699. 5,
  131700. 4,
  131701. 6,
  131702. 3,
  131703. 7,
  131704. 2,
  131705. 8,
  131706. 1,
  131707. 9,
  131708. 0,
  131709. 10,
  131710. };
  131711. static long _vq_lengthlist__8u1__p8_0[] = {
  131712. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131713. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131714. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131715. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131716. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131717. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131718. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131719. 12,13,13,14,14,15,15,15,15,
  131720. };
  131721. static float _vq_quantthresh__8u1__p8_0[] = {
  131722. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131723. 38.5, 49.5,
  131724. };
  131725. static long _vq_quantmap__8u1__p8_0[] = {
  131726. 9, 7, 5, 3, 1, 0, 2, 4,
  131727. 6, 8, 10,
  131728. };
  131729. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131730. _vq_quantthresh__8u1__p8_0,
  131731. _vq_quantmap__8u1__p8_0,
  131732. 11,
  131733. 11
  131734. };
  131735. static static_codebook _8u1__p8_0 = {
  131736. 2, 121,
  131737. _vq_lengthlist__8u1__p8_0,
  131738. 1, -524582912, 1618345984, 4, 0,
  131739. _vq_quantlist__8u1__p8_0,
  131740. NULL,
  131741. &_vq_auxt__8u1__p8_0,
  131742. NULL,
  131743. 0
  131744. };
  131745. static long _vq_quantlist__8u1__p8_1[] = {
  131746. 5,
  131747. 4,
  131748. 6,
  131749. 3,
  131750. 7,
  131751. 2,
  131752. 8,
  131753. 1,
  131754. 9,
  131755. 0,
  131756. 10,
  131757. };
  131758. static long _vq_lengthlist__8u1__p8_1[] = {
  131759. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131760. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131761. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131762. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131763. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131764. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131765. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131766. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131767. };
  131768. static float _vq_quantthresh__8u1__p8_1[] = {
  131769. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131770. 3.5, 4.5,
  131771. };
  131772. static long _vq_quantmap__8u1__p8_1[] = {
  131773. 9, 7, 5, 3, 1, 0, 2, 4,
  131774. 6, 8, 10,
  131775. };
  131776. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131777. _vq_quantthresh__8u1__p8_1,
  131778. _vq_quantmap__8u1__p8_1,
  131779. 11,
  131780. 11
  131781. };
  131782. static static_codebook _8u1__p8_1 = {
  131783. 2, 121,
  131784. _vq_lengthlist__8u1__p8_1,
  131785. 1, -531365888, 1611661312, 4, 0,
  131786. _vq_quantlist__8u1__p8_1,
  131787. NULL,
  131788. &_vq_auxt__8u1__p8_1,
  131789. NULL,
  131790. 0
  131791. };
  131792. static long _vq_quantlist__8u1__p9_0[] = {
  131793. 7,
  131794. 6,
  131795. 8,
  131796. 5,
  131797. 9,
  131798. 4,
  131799. 10,
  131800. 3,
  131801. 11,
  131802. 2,
  131803. 12,
  131804. 1,
  131805. 13,
  131806. 0,
  131807. 14,
  131808. };
  131809. static long _vq_lengthlist__8u1__p9_0[] = {
  131810. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131811. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131812. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131813. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131814. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131815. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131816. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131817. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131818. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131819. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131820. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131821. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131822. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131823. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131824. 10,
  131825. };
  131826. static float _vq_quantthresh__8u1__p9_0[] = {
  131827. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131828. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131829. };
  131830. static long _vq_quantmap__8u1__p9_0[] = {
  131831. 13, 11, 9, 7, 5, 3, 1, 0,
  131832. 2, 4, 6, 8, 10, 12, 14,
  131833. };
  131834. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131835. _vq_quantthresh__8u1__p9_0,
  131836. _vq_quantmap__8u1__p9_0,
  131837. 15,
  131838. 15
  131839. };
  131840. static static_codebook _8u1__p9_0 = {
  131841. 2, 225,
  131842. _vq_lengthlist__8u1__p9_0,
  131843. 1, -514071552, 1627381760, 4, 0,
  131844. _vq_quantlist__8u1__p9_0,
  131845. NULL,
  131846. &_vq_auxt__8u1__p9_0,
  131847. NULL,
  131848. 0
  131849. };
  131850. static long _vq_quantlist__8u1__p9_1[] = {
  131851. 7,
  131852. 6,
  131853. 8,
  131854. 5,
  131855. 9,
  131856. 4,
  131857. 10,
  131858. 3,
  131859. 11,
  131860. 2,
  131861. 12,
  131862. 1,
  131863. 13,
  131864. 0,
  131865. 14,
  131866. };
  131867. static long _vq_lengthlist__8u1__p9_1[] = {
  131868. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131869. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131870. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131871. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131872. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131873. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131874. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131875. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131876. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131877. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131878. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131879. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131880. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131881. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131882. 13,
  131883. };
  131884. static float _vq_quantthresh__8u1__p9_1[] = {
  131885. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131886. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131887. };
  131888. static long _vq_quantmap__8u1__p9_1[] = {
  131889. 13, 11, 9, 7, 5, 3, 1, 0,
  131890. 2, 4, 6, 8, 10, 12, 14,
  131891. };
  131892. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131893. _vq_quantthresh__8u1__p9_1,
  131894. _vq_quantmap__8u1__p9_1,
  131895. 15,
  131896. 15
  131897. };
  131898. static static_codebook _8u1__p9_1 = {
  131899. 2, 225,
  131900. _vq_lengthlist__8u1__p9_1,
  131901. 1, -522338304, 1620115456, 4, 0,
  131902. _vq_quantlist__8u1__p9_1,
  131903. NULL,
  131904. &_vq_auxt__8u1__p9_1,
  131905. NULL,
  131906. 0
  131907. };
  131908. static long _vq_quantlist__8u1__p9_2[] = {
  131909. 8,
  131910. 7,
  131911. 9,
  131912. 6,
  131913. 10,
  131914. 5,
  131915. 11,
  131916. 4,
  131917. 12,
  131918. 3,
  131919. 13,
  131920. 2,
  131921. 14,
  131922. 1,
  131923. 15,
  131924. 0,
  131925. 16,
  131926. };
  131927. static long _vq_lengthlist__8u1__p9_2[] = {
  131928. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131929. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131930. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131931. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131932. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131933. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131934. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131935. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131936. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131937. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131938. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131939. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131940. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131941. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131942. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131943. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131944. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131945. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131946. 10,
  131947. };
  131948. static float _vq_quantthresh__8u1__p9_2[] = {
  131949. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131950. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131951. };
  131952. static long _vq_quantmap__8u1__p9_2[] = {
  131953. 15, 13, 11, 9, 7, 5, 3, 1,
  131954. 0, 2, 4, 6, 8, 10, 12, 14,
  131955. 16,
  131956. };
  131957. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131958. _vq_quantthresh__8u1__p9_2,
  131959. _vq_quantmap__8u1__p9_2,
  131960. 17,
  131961. 17
  131962. };
  131963. static static_codebook _8u1__p9_2 = {
  131964. 2, 289,
  131965. _vq_lengthlist__8u1__p9_2,
  131966. 1, -529530880, 1611661312, 5, 0,
  131967. _vq_quantlist__8u1__p9_2,
  131968. NULL,
  131969. &_vq_auxt__8u1__p9_2,
  131970. NULL,
  131971. 0
  131972. };
  131973. static long _huff_lengthlist__8u1__single[] = {
  131974. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131975. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131976. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131977. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131978. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131979. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131980. 13, 8, 8,15,
  131981. };
  131982. static static_codebook _huff_book__8u1__single = {
  131983. 2, 100,
  131984. _huff_lengthlist__8u1__single,
  131985. 0, 0, 0, 0, 0,
  131986. NULL,
  131987. NULL,
  131988. NULL,
  131989. NULL,
  131990. 0
  131991. };
  131992. static long _huff_lengthlist__44u0__long[] = {
  131993. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131994. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131995. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131996. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131997. };
  131998. static static_codebook _huff_book__44u0__long = {
  131999. 2, 64,
  132000. _huff_lengthlist__44u0__long,
  132001. 0, 0, 0, 0, 0,
  132002. NULL,
  132003. NULL,
  132004. NULL,
  132005. NULL,
  132006. 0
  132007. };
  132008. static long _vq_quantlist__44u0__p1_0[] = {
  132009. 1,
  132010. 0,
  132011. 2,
  132012. };
  132013. static long _vq_lengthlist__44u0__p1_0[] = {
  132014. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132015. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132016. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132017. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132018. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132019. 13,
  132020. };
  132021. static float _vq_quantthresh__44u0__p1_0[] = {
  132022. -0.5, 0.5,
  132023. };
  132024. static long _vq_quantmap__44u0__p1_0[] = {
  132025. 1, 0, 2,
  132026. };
  132027. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  132028. _vq_quantthresh__44u0__p1_0,
  132029. _vq_quantmap__44u0__p1_0,
  132030. 3,
  132031. 3
  132032. };
  132033. static static_codebook _44u0__p1_0 = {
  132034. 4, 81,
  132035. _vq_lengthlist__44u0__p1_0,
  132036. 1, -535822336, 1611661312, 2, 0,
  132037. _vq_quantlist__44u0__p1_0,
  132038. NULL,
  132039. &_vq_auxt__44u0__p1_0,
  132040. NULL,
  132041. 0
  132042. };
  132043. static long _vq_quantlist__44u0__p2_0[] = {
  132044. 1,
  132045. 0,
  132046. 2,
  132047. };
  132048. static long _vq_lengthlist__44u0__p2_0[] = {
  132049. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132050. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132051. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132052. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132053. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132054. 9,
  132055. };
  132056. static float _vq_quantthresh__44u0__p2_0[] = {
  132057. -0.5, 0.5,
  132058. };
  132059. static long _vq_quantmap__44u0__p2_0[] = {
  132060. 1, 0, 2,
  132061. };
  132062. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  132063. _vq_quantthresh__44u0__p2_0,
  132064. _vq_quantmap__44u0__p2_0,
  132065. 3,
  132066. 3
  132067. };
  132068. static static_codebook _44u0__p2_0 = {
  132069. 4, 81,
  132070. _vq_lengthlist__44u0__p2_0,
  132071. 1, -535822336, 1611661312, 2, 0,
  132072. _vq_quantlist__44u0__p2_0,
  132073. NULL,
  132074. &_vq_auxt__44u0__p2_0,
  132075. NULL,
  132076. 0
  132077. };
  132078. static long _vq_quantlist__44u0__p3_0[] = {
  132079. 2,
  132080. 1,
  132081. 3,
  132082. 0,
  132083. 4,
  132084. };
  132085. static long _vq_lengthlist__44u0__p3_0[] = {
  132086. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132087. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132088. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132089. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132090. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132091. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132092. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132093. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132094. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132095. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132096. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132097. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132098. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132099. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132100. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132101. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132102. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132103. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132104. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132105. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132106. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132107. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132108. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132109. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132110. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132111. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132112. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132113. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132114. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132115. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132116. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132117. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132118. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132119. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132120. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132121. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132122. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132123. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132124. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132125. 19,
  132126. };
  132127. static float _vq_quantthresh__44u0__p3_0[] = {
  132128. -1.5, -0.5, 0.5, 1.5,
  132129. };
  132130. static long _vq_quantmap__44u0__p3_0[] = {
  132131. 3, 1, 0, 2, 4,
  132132. };
  132133. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  132134. _vq_quantthresh__44u0__p3_0,
  132135. _vq_quantmap__44u0__p3_0,
  132136. 5,
  132137. 5
  132138. };
  132139. static static_codebook _44u0__p3_0 = {
  132140. 4, 625,
  132141. _vq_lengthlist__44u0__p3_0,
  132142. 1, -533725184, 1611661312, 3, 0,
  132143. _vq_quantlist__44u0__p3_0,
  132144. NULL,
  132145. &_vq_auxt__44u0__p3_0,
  132146. NULL,
  132147. 0
  132148. };
  132149. static long _vq_quantlist__44u0__p4_0[] = {
  132150. 2,
  132151. 1,
  132152. 3,
  132153. 0,
  132154. 4,
  132155. };
  132156. static long _vq_lengthlist__44u0__p4_0[] = {
  132157. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132158. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132159. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132160. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132161. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132162. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132163. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132164. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132165. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132166. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132167. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132168. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132169. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132170. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132171. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132172. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132173. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132174. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132175. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132176. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132177. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132178. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132179. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132180. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132181. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132182. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132183. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132184. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132185. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132186. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132187. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132188. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132189. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132190. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132191. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132192. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132193. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132194. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132195. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132196. 12,
  132197. };
  132198. static float _vq_quantthresh__44u0__p4_0[] = {
  132199. -1.5, -0.5, 0.5, 1.5,
  132200. };
  132201. static long _vq_quantmap__44u0__p4_0[] = {
  132202. 3, 1, 0, 2, 4,
  132203. };
  132204. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  132205. _vq_quantthresh__44u0__p4_0,
  132206. _vq_quantmap__44u0__p4_0,
  132207. 5,
  132208. 5
  132209. };
  132210. static static_codebook _44u0__p4_0 = {
  132211. 4, 625,
  132212. _vq_lengthlist__44u0__p4_0,
  132213. 1, -533725184, 1611661312, 3, 0,
  132214. _vq_quantlist__44u0__p4_0,
  132215. NULL,
  132216. &_vq_auxt__44u0__p4_0,
  132217. NULL,
  132218. 0
  132219. };
  132220. static long _vq_quantlist__44u0__p5_0[] = {
  132221. 4,
  132222. 3,
  132223. 5,
  132224. 2,
  132225. 6,
  132226. 1,
  132227. 7,
  132228. 0,
  132229. 8,
  132230. };
  132231. static long _vq_lengthlist__44u0__p5_0[] = {
  132232. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132233. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132234. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132235. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132236. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132237. 12,
  132238. };
  132239. static float _vq_quantthresh__44u0__p5_0[] = {
  132240. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132241. };
  132242. static long _vq_quantmap__44u0__p5_0[] = {
  132243. 7, 5, 3, 1, 0, 2, 4, 6,
  132244. 8,
  132245. };
  132246. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  132247. _vq_quantthresh__44u0__p5_0,
  132248. _vq_quantmap__44u0__p5_0,
  132249. 9,
  132250. 9
  132251. };
  132252. static static_codebook _44u0__p5_0 = {
  132253. 2, 81,
  132254. _vq_lengthlist__44u0__p5_0,
  132255. 1, -531628032, 1611661312, 4, 0,
  132256. _vq_quantlist__44u0__p5_0,
  132257. NULL,
  132258. &_vq_auxt__44u0__p5_0,
  132259. NULL,
  132260. 0
  132261. };
  132262. static long _vq_quantlist__44u0__p6_0[] = {
  132263. 6,
  132264. 5,
  132265. 7,
  132266. 4,
  132267. 8,
  132268. 3,
  132269. 9,
  132270. 2,
  132271. 10,
  132272. 1,
  132273. 11,
  132274. 0,
  132275. 12,
  132276. };
  132277. static long _vq_lengthlist__44u0__p6_0[] = {
  132278. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132279. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132280. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132281. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132282. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132283. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132284. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132285. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132286. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132287. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132288. 15,17,16,17,18,17,17,18, 0,
  132289. };
  132290. static float _vq_quantthresh__44u0__p6_0[] = {
  132291. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132292. 12.5, 17.5, 22.5, 27.5,
  132293. };
  132294. static long _vq_quantmap__44u0__p6_0[] = {
  132295. 11, 9, 7, 5, 3, 1, 0, 2,
  132296. 4, 6, 8, 10, 12,
  132297. };
  132298. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  132299. _vq_quantthresh__44u0__p6_0,
  132300. _vq_quantmap__44u0__p6_0,
  132301. 13,
  132302. 13
  132303. };
  132304. static static_codebook _44u0__p6_0 = {
  132305. 2, 169,
  132306. _vq_lengthlist__44u0__p6_0,
  132307. 1, -526516224, 1616117760, 4, 0,
  132308. _vq_quantlist__44u0__p6_0,
  132309. NULL,
  132310. &_vq_auxt__44u0__p6_0,
  132311. NULL,
  132312. 0
  132313. };
  132314. static long _vq_quantlist__44u0__p6_1[] = {
  132315. 2,
  132316. 1,
  132317. 3,
  132318. 0,
  132319. 4,
  132320. };
  132321. static long _vq_lengthlist__44u0__p6_1[] = {
  132322. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132323. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132324. };
  132325. static float _vq_quantthresh__44u0__p6_1[] = {
  132326. -1.5, -0.5, 0.5, 1.5,
  132327. };
  132328. static long _vq_quantmap__44u0__p6_1[] = {
  132329. 3, 1, 0, 2, 4,
  132330. };
  132331. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132332. _vq_quantthresh__44u0__p6_1,
  132333. _vq_quantmap__44u0__p6_1,
  132334. 5,
  132335. 5
  132336. };
  132337. static static_codebook _44u0__p6_1 = {
  132338. 2, 25,
  132339. _vq_lengthlist__44u0__p6_1,
  132340. 1, -533725184, 1611661312, 3, 0,
  132341. _vq_quantlist__44u0__p6_1,
  132342. NULL,
  132343. &_vq_auxt__44u0__p6_1,
  132344. NULL,
  132345. 0
  132346. };
  132347. static long _vq_quantlist__44u0__p7_0[] = {
  132348. 2,
  132349. 1,
  132350. 3,
  132351. 0,
  132352. 4,
  132353. };
  132354. static long _vq_lengthlist__44u0__p7_0[] = {
  132355. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132356. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132357. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132358. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132359. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132360. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132361. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132362. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132363. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132364. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132365. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132366. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132367. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132368. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132369. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132370. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132371. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132372. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132373. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132374. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132375. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132376. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132377. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132378. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132379. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132380. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132381. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132382. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132383. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132384. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132385. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132386. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132387. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132388. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132389. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132390. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132391. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132392. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132393. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132394. 10,
  132395. };
  132396. static float _vq_quantthresh__44u0__p7_0[] = {
  132397. -253.5, -84.5, 84.5, 253.5,
  132398. };
  132399. static long _vq_quantmap__44u0__p7_0[] = {
  132400. 3, 1, 0, 2, 4,
  132401. };
  132402. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132403. _vq_quantthresh__44u0__p7_0,
  132404. _vq_quantmap__44u0__p7_0,
  132405. 5,
  132406. 5
  132407. };
  132408. static static_codebook _44u0__p7_0 = {
  132409. 4, 625,
  132410. _vq_lengthlist__44u0__p7_0,
  132411. 1, -518709248, 1626677248, 3, 0,
  132412. _vq_quantlist__44u0__p7_0,
  132413. NULL,
  132414. &_vq_auxt__44u0__p7_0,
  132415. NULL,
  132416. 0
  132417. };
  132418. static long _vq_quantlist__44u0__p7_1[] = {
  132419. 6,
  132420. 5,
  132421. 7,
  132422. 4,
  132423. 8,
  132424. 3,
  132425. 9,
  132426. 2,
  132427. 10,
  132428. 1,
  132429. 11,
  132430. 0,
  132431. 12,
  132432. };
  132433. static long _vq_lengthlist__44u0__p7_1[] = {
  132434. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132435. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132436. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132437. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132438. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132439. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132440. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132441. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132442. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132443. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132444. 15,15,15,15,15,15,15,15,15,
  132445. };
  132446. static float _vq_quantthresh__44u0__p7_1[] = {
  132447. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132448. 32.5, 45.5, 58.5, 71.5,
  132449. };
  132450. static long _vq_quantmap__44u0__p7_1[] = {
  132451. 11, 9, 7, 5, 3, 1, 0, 2,
  132452. 4, 6, 8, 10, 12,
  132453. };
  132454. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132455. _vq_quantthresh__44u0__p7_1,
  132456. _vq_quantmap__44u0__p7_1,
  132457. 13,
  132458. 13
  132459. };
  132460. static static_codebook _44u0__p7_1 = {
  132461. 2, 169,
  132462. _vq_lengthlist__44u0__p7_1,
  132463. 1, -523010048, 1618608128, 4, 0,
  132464. _vq_quantlist__44u0__p7_1,
  132465. NULL,
  132466. &_vq_auxt__44u0__p7_1,
  132467. NULL,
  132468. 0
  132469. };
  132470. static long _vq_quantlist__44u0__p7_2[] = {
  132471. 6,
  132472. 5,
  132473. 7,
  132474. 4,
  132475. 8,
  132476. 3,
  132477. 9,
  132478. 2,
  132479. 10,
  132480. 1,
  132481. 11,
  132482. 0,
  132483. 12,
  132484. };
  132485. static long _vq_lengthlist__44u0__p7_2[] = {
  132486. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132487. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132488. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132489. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132490. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132491. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132492. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132493. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132494. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132495. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132496. 9, 9, 9,10, 9, 9,10,10, 9,
  132497. };
  132498. static float _vq_quantthresh__44u0__p7_2[] = {
  132499. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132500. 2.5, 3.5, 4.5, 5.5,
  132501. };
  132502. static long _vq_quantmap__44u0__p7_2[] = {
  132503. 11, 9, 7, 5, 3, 1, 0, 2,
  132504. 4, 6, 8, 10, 12,
  132505. };
  132506. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132507. _vq_quantthresh__44u0__p7_2,
  132508. _vq_quantmap__44u0__p7_2,
  132509. 13,
  132510. 13
  132511. };
  132512. static static_codebook _44u0__p7_2 = {
  132513. 2, 169,
  132514. _vq_lengthlist__44u0__p7_2,
  132515. 1, -531103744, 1611661312, 4, 0,
  132516. _vq_quantlist__44u0__p7_2,
  132517. NULL,
  132518. &_vq_auxt__44u0__p7_2,
  132519. NULL,
  132520. 0
  132521. };
  132522. static long _huff_lengthlist__44u0__short[] = {
  132523. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132524. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132525. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132526. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132527. };
  132528. static static_codebook _huff_book__44u0__short = {
  132529. 2, 64,
  132530. _huff_lengthlist__44u0__short,
  132531. 0, 0, 0, 0, 0,
  132532. NULL,
  132533. NULL,
  132534. NULL,
  132535. NULL,
  132536. 0
  132537. };
  132538. static long _huff_lengthlist__44u1__long[] = {
  132539. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132540. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132541. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132542. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132543. };
  132544. static static_codebook _huff_book__44u1__long = {
  132545. 2, 64,
  132546. _huff_lengthlist__44u1__long,
  132547. 0, 0, 0, 0, 0,
  132548. NULL,
  132549. NULL,
  132550. NULL,
  132551. NULL,
  132552. 0
  132553. };
  132554. static long _vq_quantlist__44u1__p1_0[] = {
  132555. 1,
  132556. 0,
  132557. 2,
  132558. };
  132559. static long _vq_lengthlist__44u1__p1_0[] = {
  132560. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132561. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132562. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132563. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132564. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132565. 13,
  132566. };
  132567. static float _vq_quantthresh__44u1__p1_0[] = {
  132568. -0.5, 0.5,
  132569. };
  132570. static long _vq_quantmap__44u1__p1_0[] = {
  132571. 1, 0, 2,
  132572. };
  132573. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132574. _vq_quantthresh__44u1__p1_0,
  132575. _vq_quantmap__44u1__p1_0,
  132576. 3,
  132577. 3
  132578. };
  132579. static static_codebook _44u1__p1_0 = {
  132580. 4, 81,
  132581. _vq_lengthlist__44u1__p1_0,
  132582. 1, -535822336, 1611661312, 2, 0,
  132583. _vq_quantlist__44u1__p1_0,
  132584. NULL,
  132585. &_vq_auxt__44u1__p1_0,
  132586. NULL,
  132587. 0
  132588. };
  132589. static long _vq_quantlist__44u1__p2_0[] = {
  132590. 1,
  132591. 0,
  132592. 2,
  132593. };
  132594. static long _vq_lengthlist__44u1__p2_0[] = {
  132595. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132596. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132597. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132598. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132599. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132600. 9,
  132601. };
  132602. static float _vq_quantthresh__44u1__p2_0[] = {
  132603. -0.5, 0.5,
  132604. };
  132605. static long _vq_quantmap__44u1__p2_0[] = {
  132606. 1, 0, 2,
  132607. };
  132608. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132609. _vq_quantthresh__44u1__p2_0,
  132610. _vq_quantmap__44u1__p2_0,
  132611. 3,
  132612. 3
  132613. };
  132614. static static_codebook _44u1__p2_0 = {
  132615. 4, 81,
  132616. _vq_lengthlist__44u1__p2_0,
  132617. 1, -535822336, 1611661312, 2, 0,
  132618. _vq_quantlist__44u1__p2_0,
  132619. NULL,
  132620. &_vq_auxt__44u1__p2_0,
  132621. NULL,
  132622. 0
  132623. };
  132624. static long _vq_quantlist__44u1__p3_0[] = {
  132625. 2,
  132626. 1,
  132627. 3,
  132628. 0,
  132629. 4,
  132630. };
  132631. static long _vq_lengthlist__44u1__p3_0[] = {
  132632. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132633. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132634. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132635. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132636. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132637. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132638. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132639. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132640. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132641. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132642. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132643. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132644. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132645. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132646. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132647. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132648. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132649. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132650. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132651. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132652. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132653. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132654. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132655. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132656. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132657. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132658. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132659. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132660. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132661. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132662. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132663. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132664. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132665. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132666. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132667. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132668. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132669. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132670. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132671. 19,
  132672. };
  132673. static float _vq_quantthresh__44u1__p3_0[] = {
  132674. -1.5, -0.5, 0.5, 1.5,
  132675. };
  132676. static long _vq_quantmap__44u1__p3_0[] = {
  132677. 3, 1, 0, 2, 4,
  132678. };
  132679. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132680. _vq_quantthresh__44u1__p3_0,
  132681. _vq_quantmap__44u1__p3_0,
  132682. 5,
  132683. 5
  132684. };
  132685. static static_codebook _44u1__p3_0 = {
  132686. 4, 625,
  132687. _vq_lengthlist__44u1__p3_0,
  132688. 1, -533725184, 1611661312, 3, 0,
  132689. _vq_quantlist__44u1__p3_0,
  132690. NULL,
  132691. &_vq_auxt__44u1__p3_0,
  132692. NULL,
  132693. 0
  132694. };
  132695. static long _vq_quantlist__44u1__p4_0[] = {
  132696. 2,
  132697. 1,
  132698. 3,
  132699. 0,
  132700. 4,
  132701. };
  132702. static long _vq_lengthlist__44u1__p4_0[] = {
  132703. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132704. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132705. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132706. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132707. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132708. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132709. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132710. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132711. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132712. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132713. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132714. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132715. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132716. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132717. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132718. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132719. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132720. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132721. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132722. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132723. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132724. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132725. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132726. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132727. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132728. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132729. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132730. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132731. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132732. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132733. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132734. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132735. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132736. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132737. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132738. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132739. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132740. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132741. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132742. 12,
  132743. };
  132744. static float _vq_quantthresh__44u1__p4_0[] = {
  132745. -1.5, -0.5, 0.5, 1.5,
  132746. };
  132747. static long _vq_quantmap__44u1__p4_0[] = {
  132748. 3, 1, 0, 2, 4,
  132749. };
  132750. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132751. _vq_quantthresh__44u1__p4_0,
  132752. _vq_quantmap__44u1__p4_0,
  132753. 5,
  132754. 5
  132755. };
  132756. static static_codebook _44u1__p4_0 = {
  132757. 4, 625,
  132758. _vq_lengthlist__44u1__p4_0,
  132759. 1, -533725184, 1611661312, 3, 0,
  132760. _vq_quantlist__44u1__p4_0,
  132761. NULL,
  132762. &_vq_auxt__44u1__p4_0,
  132763. NULL,
  132764. 0
  132765. };
  132766. static long _vq_quantlist__44u1__p5_0[] = {
  132767. 4,
  132768. 3,
  132769. 5,
  132770. 2,
  132771. 6,
  132772. 1,
  132773. 7,
  132774. 0,
  132775. 8,
  132776. };
  132777. static long _vq_lengthlist__44u1__p5_0[] = {
  132778. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132779. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132780. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132781. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132782. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132783. 12,
  132784. };
  132785. static float _vq_quantthresh__44u1__p5_0[] = {
  132786. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132787. };
  132788. static long _vq_quantmap__44u1__p5_0[] = {
  132789. 7, 5, 3, 1, 0, 2, 4, 6,
  132790. 8,
  132791. };
  132792. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132793. _vq_quantthresh__44u1__p5_0,
  132794. _vq_quantmap__44u1__p5_0,
  132795. 9,
  132796. 9
  132797. };
  132798. static static_codebook _44u1__p5_0 = {
  132799. 2, 81,
  132800. _vq_lengthlist__44u1__p5_0,
  132801. 1, -531628032, 1611661312, 4, 0,
  132802. _vq_quantlist__44u1__p5_0,
  132803. NULL,
  132804. &_vq_auxt__44u1__p5_0,
  132805. NULL,
  132806. 0
  132807. };
  132808. static long _vq_quantlist__44u1__p6_0[] = {
  132809. 6,
  132810. 5,
  132811. 7,
  132812. 4,
  132813. 8,
  132814. 3,
  132815. 9,
  132816. 2,
  132817. 10,
  132818. 1,
  132819. 11,
  132820. 0,
  132821. 12,
  132822. };
  132823. static long _vq_lengthlist__44u1__p6_0[] = {
  132824. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132825. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132826. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132827. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132828. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132829. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132830. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132831. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132832. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132833. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132834. 15,17,16,17,18,17,17,18, 0,
  132835. };
  132836. static float _vq_quantthresh__44u1__p6_0[] = {
  132837. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132838. 12.5, 17.5, 22.5, 27.5,
  132839. };
  132840. static long _vq_quantmap__44u1__p6_0[] = {
  132841. 11, 9, 7, 5, 3, 1, 0, 2,
  132842. 4, 6, 8, 10, 12,
  132843. };
  132844. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132845. _vq_quantthresh__44u1__p6_0,
  132846. _vq_quantmap__44u1__p6_0,
  132847. 13,
  132848. 13
  132849. };
  132850. static static_codebook _44u1__p6_0 = {
  132851. 2, 169,
  132852. _vq_lengthlist__44u1__p6_0,
  132853. 1, -526516224, 1616117760, 4, 0,
  132854. _vq_quantlist__44u1__p6_0,
  132855. NULL,
  132856. &_vq_auxt__44u1__p6_0,
  132857. NULL,
  132858. 0
  132859. };
  132860. static long _vq_quantlist__44u1__p6_1[] = {
  132861. 2,
  132862. 1,
  132863. 3,
  132864. 0,
  132865. 4,
  132866. };
  132867. static long _vq_lengthlist__44u1__p6_1[] = {
  132868. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132869. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132870. };
  132871. static float _vq_quantthresh__44u1__p6_1[] = {
  132872. -1.5, -0.5, 0.5, 1.5,
  132873. };
  132874. static long _vq_quantmap__44u1__p6_1[] = {
  132875. 3, 1, 0, 2, 4,
  132876. };
  132877. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132878. _vq_quantthresh__44u1__p6_1,
  132879. _vq_quantmap__44u1__p6_1,
  132880. 5,
  132881. 5
  132882. };
  132883. static static_codebook _44u1__p6_1 = {
  132884. 2, 25,
  132885. _vq_lengthlist__44u1__p6_1,
  132886. 1, -533725184, 1611661312, 3, 0,
  132887. _vq_quantlist__44u1__p6_1,
  132888. NULL,
  132889. &_vq_auxt__44u1__p6_1,
  132890. NULL,
  132891. 0
  132892. };
  132893. static long _vq_quantlist__44u1__p7_0[] = {
  132894. 3,
  132895. 2,
  132896. 4,
  132897. 1,
  132898. 5,
  132899. 0,
  132900. 6,
  132901. };
  132902. static long _vq_lengthlist__44u1__p7_0[] = {
  132903. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132904. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132905. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132906. 8,
  132907. };
  132908. static float _vq_quantthresh__44u1__p7_0[] = {
  132909. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132910. };
  132911. static long _vq_quantmap__44u1__p7_0[] = {
  132912. 5, 3, 1, 0, 2, 4, 6,
  132913. };
  132914. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132915. _vq_quantthresh__44u1__p7_0,
  132916. _vq_quantmap__44u1__p7_0,
  132917. 7,
  132918. 7
  132919. };
  132920. static static_codebook _44u1__p7_0 = {
  132921. 2, 49,
  132922. _vq_lengthlist__44u1__p7_0,
  132923. 1, -518017024, 1626677248, 3, 0,
  132924. _vq_quantlist__44u1__p7_0,
  132925. NULL,
  132926. &_vq_auxt__44u1__p7_0,
  132927. NULL,
  132928. 0
  132929. };
  132930. static long _vq_quantlist__44u1__p7_1[] = {
  132931. 6,
  132932. 5,
  132933. 7,
  132934. 4,
  132935. 8,
  132936. 3,
  132937. 9,
  132938. 2,
  132939. 10,
  132940. 1,
  132941. 11,
  132942. 0,
  132943. 12,
  132944. };
  132945. static long _vq_lengthlist__44u1__p7_1[] = {
  132946. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132947. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132948. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132949. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132950. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132951. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132952. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132953. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132954. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132955. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132956. 15,15,15,15,15,15,15,15,15,
  132957. };
  132958. static float _vq_quantthresh__44u1__p7_1[] = {
  132959. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132960. 32.5, 45.5, 58.5, 71.5,
  132961. };
  132962. static long _vq_quantmap__44u1__p7_1[] = {
  132963. 11, 9, 7, 5, 3, 1, 0, 2,
  132964. 4, 6, 8, 10, 12,
  132965. };
  132966. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132967. _vq_quantthresh__44u1__p7_1,
  132968. _vq_quantmap__44u1__p7_1,
  132969. 13,
  132970. 13
  132971. };
  132972. static static_codebook _44u1__p7_1 = {
  132973. 2, 169,
  132974. _vq_lengthlist__44u1__p7_1,
  132975. 1, -523010048, 1618608128, 4, 0,
  132976. _vq_quantlist__44u1__p7_1,
  132977. NULL,
  132978. &_vq_auxt__44u1__p7_1,
  132979. NULL,
  132980. 0
  132981. };
  132982. static long _vq_quantlist__44u1__p7_2[] = {
  132983. 6,
  132984. 5,
  132985. 7,
  132986. 4,
  132987. 8,
  132988. 3,
  132989. 9,
  132990. 2,
  132991. 10,
  132992. 1,
  132993. 11,
  132994. 0,
  132995. 12,
  132996. };
  132997. static long _vq_lengthlist__44u1__p7_2[] = {
  132998. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132999. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  133000. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  133001. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133002. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  133003. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  133004. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  133005. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133006. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133007. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  133008. 9, 9, 9,10, 9, 9,10,10, 9,
  133009. };
  133010. static float _vq_quantthresh__44u1__p7_2[] = {
  133011. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133012. 2.5, 3.5, 4.5, 5.5,
  133013. };
  133014. static long _vq_quantmap__44u1__p7_2[] = {
  133015. 11, 9, 7, 5, 3, 1, 0, 2,
  133016. 4, 6, 8, 10, 12,
  133017. };
  133018. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  133019. _vq_quantthresh__44u1__p7_2,
  133020. _vq_quantmap__44u1__p7_2,
  133021. 13,
  133022. 13
  133023. };
  133024. static static_codebook _44u1__p7_2 = {
  133025. 2, 169,
  133026. _vq_lengthlist__44u1__p7_2,
  133027. 1, -531103744, 1611661312, 4, 0,
  133028. _vq_quantlist__44u1__p7_2,
  133029. NULL,
  133030. &_vq_auxt__44u1__p7_2,
  133031. NULL,
  133032. 0
  133033. };
  133034. static long _huff_lengthlist__44u1__short[] = {
  133035. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  133036. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  133037. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  133038. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  133039. };
  133040. static static_codebook _huff_book__44u1__short = {
  133041. 2, 64,
  133042. _huff_lengthlist__44u1__short,
  133043. 0, 0, 0, 0, 0,
  133044. NULL,
  133045. NULL,
  133046. NULL,
  133047. NULL,
  133048. 0
  133049. };
  133050. static long _huff_lengthlist__44u2__long[] = {
  133051. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  133052. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  133053. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  133054. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  133055. };
  133056. static static_codebook _huff_book__44u2__long = {
  133057. 2, 64,
  133058. _huff_lengthlist__44u2__long,
  133059. 0, 0, 0, 0, 0,
  133060. NULL,
  133061. NULL,
  133062. NULL,
  133063. NULL,
  133064. 0
  133065. };
  133066. static long _vq_quantlist__44u2__p1_0[] = {
  133067. 1,
  133068. 0,
  133069. 2,
  133070. };
  133071. static long _vq_lengthlist__44u2__p1_0[] = {
  133072. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  133073. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133074. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  133075. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  133076. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  133077. 13,
  133078. };
  133079. static float _vq_quantthresh__44u2__p1_0[] = {
  133080. -0.5, 0.5,
  133081. };
  133082. static long _vq_quantmap__44u2__p1_0[] = {
  133083. 1, 0, 2,
  133084. };
  133085. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  133086. _vq_quantthresh__44u2__p1_0,
  133087. _vq_quantmap__44u2__p1_0,
  133088. 3,
  133089. 3
  133090. };
  133091. static static_codebook _44u2__p1_0 = {
  133092. 4, 81,
  133093. _vq_lengthlist__44u2__p1_0,
  133094. 1, -535822336, 1611661312, 2, 0,
  133095. _vq_quantlist__44u2__p1_0,
  133096. NULL,
  133097. &_vq_auxt__44u2__p1_0,
  133098. NULL,
  133099. 0
  133100. };
  133101. static long _vq_quantlist__44u2__p2_0[] = {
  133102. 1,
  133103. 0,
  133104. 2,
  133105. };
  133106. static long _vq_lengthlist__44u2__p2_0[] = {
  133107. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133108. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  133109. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133110. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133111. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133112. 9,
  133113. };
  133114. static float _vq_quantthresh__44u2__p2_0[] = {
  133115. -0.5, 0.5,
  133116. };
  133117. static long _vq_quantmap__44u2__p2_0[] = {
  133118. 1, 0, 2,
  133119. };
  133120. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  133121. _vq_quantthresh__44u2__p2_0,
  133122. _vq_quantmap__44u2__p2_0,
  133123. 3,
  133124. 3
  133125. };
  133126. static static_codebook _44u2__p2_0 = {
  133127. 4, 81,
  133128. _vq_lengthlist__44u2__p2_0,
  133129. 1, -535822336, 1611661312, 2, 0,
  133130. _vq_quantlist__44u2__p2_0,
  133131. NULL,
  133132. &_vq_auxt__44u2__p2_0,
  133133. NULL,
  133134. 0
  133135. };
  133136. static long _vq_quantlist__44u2__p3_0[] = {
  133137. 2,
  133138. 1,
  133139. 3,
  133140. 0,
  133141. 4,
  133142. };
  133143. static long _vq_lengthlist__44u2__p3_0[] = {
  133144. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133145. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133146. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133147. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133148. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  133149. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  133150. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  133151. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  133152. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133153. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133154. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  133155. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133156. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  133157. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  133158. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  133159. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  133160. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  133161. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  133162. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  133163. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  133164. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  133165. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  133166. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  133167. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  133168. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  133169. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  133170. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  133171. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  133172. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  133173. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  133174. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  133175. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  133176. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  133177. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  133178. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  133179. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  133180. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  133181. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  133182. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  133183. 0,
  133184. };
  133185. static float _vq_quantthresh__44u2__p3_0[] = {
  133186. -1.5, -0.5, 0.5, 1.5,
  133187. };
  133188. static long _vq_quantmap__44u2__p3_0[] = {
  133189. 3, 1, 0, 2, 4,
  133190. };
  133191. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  133192. _vq_quantthresh__44u2__p3_0,
  133193. _vq_quantmap__44u2__p3_0,
  133194. 5,
  133195. 5
  133196. };
  133197. static static_codebook _44u2__p3_0 = {
  133198. 4, 625,
  133199. _vq_lengthlist__44u2__p3_0,
  133200. 1, -533725184, 1611661312, 3, 0,
  133201. _vq_quantlist__44u2__p3_0,
  133202. NULL,
  133203. &_vq_auxt__44u2__p3_0,
  133204. NULL,
  133205. 0
  133206. };
  133207. static long _vq_quantlist__44u2__p4_0[] = {
  133208. 2,
  133209. 1,
  133210. 3,
  133211. 0,
  133212. 4,
  133213. };
  133214. static long _vq_lengthlist__44u2__p4_0[] = {
  133215. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133216. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133217. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  133218. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  133219. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  133220. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133221. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  133222. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  133223. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133224. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133225. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  133226. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133227. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  133228. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  133229. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  133230. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  133231. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  133232. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133233. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133234. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133235. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133236. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  133237. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133238. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133239. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133240. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  133241. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  133242. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  133243. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133244. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  133245. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  133246. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  133247. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  133248. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133249. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133250. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  133251. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133252. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  133253. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  133254. 13,
  133255. };
  133256. static float _vq_quantthresh__44u2__p4_0[] = {
  133257. -1.5, -0.5, 0.5, 1.5,
  133258. };
  133259. static long _vq_quantmap__44u2__p4_0[] = {
  133260. 3, 1, 0, 2, 4,
  133261. };
  133262. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  133263. _vq_quantthresh__44u2__p4_0,
  133264. _vq_quantmap__44u2__p4_0,
  133265. 5,
  133266. 5
  133267. };
  133268. static static_codebook _44u2__p4_0 = {
  133269. 4, 625,
  133270. _vq_lengthlist__44u2__p4_0,
  133271. 1, -533725184, 1611661312, 3, 0,
  133272. _vq_quantlist__44u2__p4_0,
  133273. NULL,
  133274. &_vq_auxt__44u2__p4_0,
  133275. NULL,
  133276. 0
  133277. };
  133278. static long _vq_quantlist__44u2__p5_0[] = {
  133279. 4,
  133280. 3,
  133281. 5,
  133282. 2,
  133283. 6,
  133284. 1,
  133285. 7,
  133286. 0,
  133287. 8,
  133288. };
  133289. static long _vq_lengthlist__44u2__p5_0[] = {
  133290. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  133291. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  133292. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  133293. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  133294. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  133295. 13,
  133296. };
  133297. static float _vq_quantthresh__44u2__p5_0[] = {
  133298. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133299. };
  133300. static long _vq_quantmap__44u2__p5_0[] = {
  133301. 7, 5, 3, 1, 0, 2, 4, 6,
  133302. 8,
  133303. };
  133304. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  133305. _vq_quantthresh__44u2__p5_0,
  133306. _vq_quantmap__44u2__p5_0,
  133307. 9,
  133308. 9
  133309. };
  133310. static static_codebook _44u2__p5_0 = {
  133311. 2, 81,
  133312. _vq_lengthlist__44u2__p5_0,
  133313. 1, -531628032, 1611661312, 4, 0,
  133314. _vq_quantlist__44u2__p5_0,
  133315. NULL,
  133316. &_vq_auxt__44u2__p5_0,
  133317. NULL,
  133318. 0
  133319. };
  133320. static long _vq_quantlist__44u2__p6_0[] = {
  133321. 6,
  133322. 5,
  133323. 7,
  133324. 4,
  133325. 8,
  133326. 3,
  133327. 9,
  133328. 2,
  133329. 10,
  133330. 1,
  133331. 11,
  133332. 0,
  133333. 12,
  133334. };
  133335. static long _vq_lengthlist__44u2__p6_0[] = {
  133336. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133337. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133338. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133339. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133340. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133341. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133342. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133343. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133344. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133345. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133346. 15,17,17,16,18,17,18, 0, 0,
  133347. };
  133348. static float _vq_quantthresh__44u2__p6_0[] = {
  133349. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133350. 12.5, 17.5, 22.5, 27.5,
  133351. };
  133352. static long _vq_quantmap__44u2__p6_0[] = {
  133353. 11, 9, 7, 5, 3, 1, 0, 2,
  133354. 4, 6, 8, 10, 12,
  133355. };
  133356. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133357. _vq_quantthresh__44u2__p6_0,
  133358. _vq_quantmap__44u2__p6_0,
  133359. 13,
  133360. 13
  133361. };
  133362. static static_codebook _44u2__p6_0 = {
  133363. 2, 169,
  133364. _vq_lengthlist__44u2__p6_0,
  133365. 1, -526516224, 1616117760, 4, 0,
  133366. _vq_quantlist__44u2__p6_0,
  133367. NULL,
  133368. &_vq_auxt__44u2__p6_0,
  133369. NULL,
  133370. 0
  133371. };
  133372. static long _vq_quantlist__44u2__p6_1[] = {
  133373. 2,
  133374. 1,
  133375. 3,
  133376. 0,
  133377. 4,
  133378. };
  133379. static long _vq_lengthlist__44u2__p6_1[] = {
  133380. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133381. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133382. };
  133383. static float _vq_quantthresh__44u2__p6_1[] = {
  133384. -1.5, -0.5, 0.5, 1.5,
  133385. };
  133386. static long _vq_quantmap__44u2__p6_1[] = {
  133387. 3, 1, 0, 2, 4,
  133388. };
  133389. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133390. _vq_quantthresh__44u2__p6_1,
  133391. _vq_quantmap__44u2__p6_1,
  133392. 5,
  133393. 5
  133394. };
  133395. static static_codebook _44u2__p6_1 = {
  133396. 2, 25,
  133397. _vq_lengthlist__44u2__p6_1,
  133398. 1, -533725184, 1611661312, 3, 0,
  133399. _vq_quantlist__44u2__p6_1,
  133400. NULL,
  133401. &_vq_auxt__44u2__p6_1,
  133402. NULL,
  133403. 0
  133404. };
  133405. static long _vq_quantlist__44u2__p7_0[] = {
  133406. 4,
  133407. 3,
  133408. 5,
  133409. 2,
  133410. 6,
  133411. 1,
  133412. 7,
  133413. 0,
  133414. 8,
  133415. };
  133416. static long _vq_lengthlist__44u2__p7_0[] = {
  133417. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133418. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133419. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133420. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133421. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133422. 11,
  133423. };
  133424. static float _vq_quantthresh__44u2__p7_0[] = {
  133425. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133426. };
  133427. static long _vq_quantmap__44u2__p7_0[] = {
  133428. 7, 5, 3, 1, 0, 2, 4, 6,
  133429. 8,
  133430. };
  133431. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133432. _vq_quantthresh__44u2__p7_0,
  133433. _vq_quantmap__44u2__p7_0,
  133434. 9,
  133435. 9
  133436. };
  133437. static static_codebook _44u2__p7_0 = {
  133438. 2, 81,
  133439. _vq_lengthlist__44u2__p7_0,
  133440. 1, -516612096, 1626677248, 4, 0,
  133441. _vq_quantlist__44u2__p7_0,
  133442. NULL,
  133443. &_vq_auxt__44u2__p7_0,
  133444. NULL,
  133445. 0
  133446. };
  133447. static long _vq_quantlist__44u2__p7_1[] = {
  133448. 6,
  133449. 5,
  133450. 7,
  133451. 4,
  133452. 8,
  133453. 3,
  133454. 9,
  133455. 2,
  133456. 10,
  133457. 1,
  133458. 11,
  133459. 0,
  133460. 12,
  133461. };
  133462. static long _vq_lengthlist__44u2__p7_1[] = {
  133463. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133464. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133465. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133466. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133467. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133468. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133469. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133470. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133471. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133472. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133473. 14,14,14,17,15,17,17,17,17,
  133474. };
  133475. static float _vq_quantthresh__44u2__p7_1[] = {
  133476. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133477. 32.5, 45.5, 58.5, 71.5,
  133478. };
  133479. static long _vq_quantmap__44u2__p7_1[] = {
  133480. 11, 9, 7, 5, 3, 1, 0, 2,
  133481. 4, 6, 8, 10, 12,
  133482. };
  133483. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133484. _vq_quantthresh__44u2__p7_1,
  133485. _vq_quantmap__44u2__p7_1,
  133486. 13,
  133487. 13
  133488. };
  133489. static static_codebook _44u2__p7_1 = {
  133490. 2, 169,
  133491. _vq_lengthlist__44u2__p7_1,
  133492. 1, -523010048, 1618608128, 4, 0,
  133493. _vq_quantlist__44u2__p7_1,
  133494. NULL,
  133495. &_vq_auxt__44u2__p7_1,
  133496. NULL,
  133497. 0
  133498. };
  133499. static long _vq_quantlist__44u2__p7_2[] = {
  133500. 6,
  133501. 5,
  133502. 7,
  133503. 4,
  133504. 8,
  133505. 3,
  133506. 9,
  133507. 2,
  133508. 10,
  133509. 1,
  133510. 11,
  133511. 0,
  133512. 12,
  133513. };
  133514. static long _vq_lengthlist__44u2__p7_2[] = {
  133515. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133516. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133517. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133518. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133519. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133520. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133521. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133522. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133523. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133524. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133525. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133526. };
  133527. static float _vq_quantthresh__44u2__p7_2[] = {
  133528. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133529. 2.5, 3.5, 4.5, 5.5,
  133530. };
  133531. static long _vq_quantmap__44u2__p7_2[] = {
  133532. 11, 9, 7, 5, 3, 1, 0, 2,
  133533. 4, 6, 8, 10, 12,
  133534. };
  133535. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133536. _vq_quantthresh__44u2__p7_2,
  133537. _vq_quantmap__44u2__p7_2,
  133538. 13,
  133539. 13
  133540. };
  133541. static static_codebook _44u2__p7_2 = {
  133542. 2, 169,
  133543. _vq_lengthlist__44u2__p7_2,
  133544. 1, -531103744, 1611661312, 4, 0,
  133545. _vq_quantlist__44u2__p7_2,
  133546. NULL,
  133547. &_vq_auxt__44u2__p7_2,
  133548. NULL,
  133549. 0
  133550. };
  133551. static long _huff_lengthlist__44u2__short[] = {
  133552. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133553. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133554. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133555. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133556. };
  133557. static static_codebook _huff_book__44u2__short = {
  133558. 2, 64,
  133559. _huff_lengthlist__44u2__short,
  133560. 0, 0, 0, 0, 0,
  133561. NULL,
  133562. NULL,
  133563. NULL,
  133564. NULL,
  133565. 0
  133566. };
  133567. static long _huff_lengthlist__44u3__long[] = {
  133568. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133569. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133570. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133571. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133572. };
  133573. static static_codebook _huff_book__44u3__long = {
  133574. 2, 64,
  133575. _huff_lengthlist__44u3__long,
  133576. 0, 0, 0, 0, 0,
  133577. NULL,
  133578. NULL,
  133579. NULL,
  133580. NULL,
  133581. 0
  133582. };
  133583. static long _vq_quantlist__44u3__p1_0[] = {
  133584. 1,
  133585. 0,
  133586. 2,
  133587. };
  133588. static long _vq_lengthlist__44u3__p1_0[] = {
  133589. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133590. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133591. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133592. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133593. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133594. 13,
  133595. };
  133596. static float _vq_quantthresh__44u3__p1_0[] = {
  133597. -0.5, 0.5,
  133598. };
  133599. static long _vq_quantmap__44u3__p1_0[] = {
  133600. 1, 0, 2,
  133601. };
  133602. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133603. _vq_quantthresh__44u3__p1_0,
  133604. _vq_quantmap__44u3__p1_0,
  133605. 3,
  133606. 3
  133607. };
  133608. static static_codebook _44u3__p1_0 = {
  133609. 4, 81,
  133610. _vq_lengthlist__44u3__p1_0,
  133611. 1, -535822336, 1611661312, 2, 0,
  133612. _vq_quantlist__44u3__p1_0,
  133613. NULL,
  133614. &_vq_auxt__44u3__p1_0,
  133615. NULL,
  133616. 0
  133617. };
  133618. static long _vq_quantlist__44u3__p2_0[] = {
  133619. 1,
  133620. 0,
  133621. 2,
  133622. };
  133623. static long _vq_lengthlist__44u3__p2_0[] = {
  133624. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133625. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133626. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133627. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133628. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133629. 9,
  133630. };
  133631. static float _vq_quantthresh__44u3__p2_0[] = {
  133632. -0.5, 0.5,
  133633. };
  133634. static long _vq_quantmap__44u3__p2_0[] = {
  133635. 1, 0, 2,
  133636. };
  133637. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133638. _vq_quantthresh__44u3__p2_0,
  133639. _vq_quantmap__44u3__p2_0,
  133640. 3,
  133641. 3
  133642. };
  133643. static static_codebook _44u3__p2_0 = {
  133644. 4, 81,
  133645. _vq_lengthlist__44u3__p2_0,
  133646. 1, -535822336, 1611661312, 2, 0,
  133647. _vq_quantlist__44u3__p2_0,
  133648. NULL,
  133649. &_vq_auxt__44u3__p2_0,
  133650. NULL,
  133651. 0
  133652. };
  133653. static long _vq_quantlist__44u3__p3_0[] = {
  133654. 2,
  133655. 1,
  133656. 3,
  133657. 0,
  133658. 4,
  133659. };
  133660. static long _vq_lengthlist__44u3__p3_0[] = {
  133661. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133662. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133663. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133664. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133665. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133666. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133667. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133668. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133669. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133670. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133671. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133672. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133673. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133674. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133675. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133676. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133677. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133678. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133679. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133680. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133681. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133682. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133683. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133684. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133685. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133686. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133687. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133688. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133689. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133690. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133691. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133692. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133693. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133694. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133695. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133696. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133697. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133698. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133699. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133700. 0,
  133701. };
  133702. static float _vq_quantthresh__44u3__p3_0[] = {
  133703. -1.5, -0.5, 0.5, 1.5,
  133704. };
  133705. static long _vq_quantmap__44u3__p3_0[] = {
  133706. 3, 1, 0, 2, 4,
  133707. };
  133708. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133709. _vq_quantthresh__44u3__p3_0,
  133710. _vq_quantmap__44u3__p3_0,
  133711. 5,
  133712. 5
  133713. };
  133714. static static_codebook _44u3__p3_0 = {
  133715. 4, 625,
  133716. _vq_lengthlist__44u3__p3_0,
  133717. 1, -533725184, 1611661312, 3, 0,
  133718. _vq_quantlist__44u3__p3_0,
  133719. NULL,
  133720. &_vq_auxt__44u3__p3_0,
  133721. NULL,
  133722. 0
  133723. };
  133724. static long _vq_quantlist__44u3__p4_0[] = {
  133725. 2,
  133726. 1,
  133727. 3,
  133728. 0,
  133729. 4,
  133730. };
  133731. static long _vq_lengthlist__44u3__p4_0[] = {
  133732. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133733. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133734. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133735. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133736. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133737. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133738. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133739. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133740. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133741. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133742. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133743. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133744. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133745. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133746. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133747. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133748. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133749. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133750. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133751. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133752. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133753. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133754. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133755. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133756. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133757. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133758. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133759. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133760. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133761. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133762. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133763. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133764. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133765. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133766. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133767. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133768. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133769. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133770. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133771. 13,
  133772. };
  133773. static float _vq_quantthresh__44u3__p4_0[] = {
  133774. -1.5, -0.5, 0.5, 1.5,
  133775. };
  133776. static long _vq_quantmap__44u3__p4_0[] = {
  133777. 3, 1, 0, 2, 4,
  133778. };
  133779. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133780. _vq_quantthresh__44u3__p4_0,
  133781. _vq_quantmap__44u3__p4_0,
  133782. 5,
  133783. 5
  133784. };
  133785. static static_codebook _44u3__p4_0 = {
  133786. 4, 625,
  133787. _vq_lengthlist__44u3__p4_0,
  133788. 1, -533725184, 1611661312, 3, 0,
  133789. _vq_quantlist__44u3__p4_0,
  133790. NULL,
  133791. &_vq_auxt__44u3__p4_0,
  133792. NULL,
  133793. 0
  133794. };
  133795. static long _vq_quantlist__44u3__p5_0[] = {
  133796. 4,
  133797. 3,
  133798. 5,
  133799. 2,
  133800. 6,
  133801. 1,
  133802. 7,
  133803. 0,
  133804. 8,
  133805. };
  133806. static long _vq_lengthlist__44u3__p5_0[] = {
  133807. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133808. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133809. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133810. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133811. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133812. 12,
  133813. };
  133814. static float _vq_quantthresh__44u3__p5_0[] = {
  133815. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133816. };
  133817. static long _vq_quantmap__44u3__p5_0[] = {
  133818. 7, 5, 3, 1, 0, 2, 4, 6,
  133819. 8,
  133820. };
  133821. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133822. _vq_quantthresh__44u3__p5_0,
  133823. _vq_quantmap__44u3__p5_0,
  133824. 9,
  133825. 9
  133826. };
  133827. static static_codebook _44u3__p5_0 = {
  133828. 2, 81,
  133829. _vq_lengthlist__44u3__p5_0,
  133830. 1, -531628032, 1611661312, 4, 0,
  133831. _vq_quantlist__44u3__p5_0,
  133832. NULL,
  133833. &_vq_auxt__44u3__p5_0,
  133834. NULL,
  133835. 0
  133836. };
  133837. static long _vq_quantlist__44u3__p6_0[] = {
  133838. 6,
  133839. 5,
  133840. 7,
  133841. 4,
  133842. 8,
  133843. 3,
  133844. 9,
  133845. 2,
  133846. 10,
  133847. 1,
  133848. 11,
  133849. 0,
  133850. 12,
  133851. };
  133852. static long _vq_lengthlist__44u3__p6_0[] = {
  133853. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133854. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133855. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133856. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133857. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133858. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133859. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133860. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133861. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133862. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133863. 15,16,16,16,17,18,16,20,18,
  133864. };
  133865. static float _vq_quantthresh__44u3__p6_0[] = {
  133866. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133867. 12.5, 17.5, 22.5, 27.5,
  133868. };
  133869. static long _vq_quantmap__44u3__p6_0[] = {
  133870. 11, 9, 7, 5, 3, 1, 0, 2,
  133871. 4, 6, 8, 10, 12,
  133872. };
  133873. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133874. _vq_quantthresh__44u3__p6_0,
  133875. _vq_quantmap__44u3__p6_0,
  133876. 13,
  133877. 13
  133878. };
  133879. static static_codebook _44u3__p6_0 = {
  133880. 2, 169,
  133881. _vq_lengthlist__44u3__p6_0,
  133882. 1, -526516224, 1616117760, 4, 0,
  133883. _vq_quantlist__44u3__p6_0,
  133884. NULL,
  133885. &_vq_auxt__44u3__p6_0,
  133886. NULL,
  133887. 0
  133888. };
  133889. static long _vq_quantlist__44u3__p6_1[] = {
  133890. 2,
  133891. 1,
  133892. 3,
  133893. 0,
  133894. 4,
  133895. };
  133896. static long _vq_lengthlist__44u3__p6_1[] = {
  133897. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133898. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133899. };
  133900. static float _vq_quantthresh__44u3__p6_1[] = {
  133901. -1.5, -0.5, 0.5, 1.5,
  133902. };
  133903. static long _vq_quantmap__44u3__p6_1[] = {
  133904. 3, 1, 0, 2, 4,
  133905. };
  133906. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133907. _vq_quantthresh__44u3__p6_1,
  133908. _vq_quantmap__44u3__p6_1,
  133909. 5,
  133910. 5
  133911. };
  133912. static static_codebook _44u3__p6_1 = {
  133913. 2, 25,
  133914. _vq_lengthlist__44u3__p6_1,
  133915. 1, -533725184, 1611661312, 3, 0,
  133916. _vq_quantlist__44u3__p6_1,
  133917. NULL,
  133918. &_vq_auxt__44u3__p6_1,
  133919. NULL,
  133920. 0
  133921. };
  133922. static long _vq_quantlist__44u3__p7_0[] = {
  133923. 4,
  133924. 3,
  133925. 5,
  133926. 2,
  133927. 6,
  133928. 1,
  133929. 7,
  133930. 0,
  133931. 8,
  133932. };
  133933. static long _vq_lengthlist__44u3__p7_0[] = {
  133934. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133935. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133936. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133937. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133938. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133939. 9,
  133940. };
  133941. static float _vq_quantthresh__44u3__p7_0[] = {
  133942. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133943. };
  133944. static long _vq_quantmap__44u3__p7_0[] = {
  133945. 7, 5, 3, 1, 0, 2, 4, 6,
  133946. 8,
  133947. };
  133948. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133949. _vq_quantthresh__44u3__p7_0,
  133950. _vq_quantmap__44u3__p7_0,
  133951. 9,
  133952. 9
  133953. };
  133954. static static_codebook _44u3__p7_0 = {
  133955. 2, 81,
  133956. _vq_lengthlist__44u3__p7_0,
  133957. 1, -515907584, 1627381760, 4, 0,
  133958. _vq_quantlist__44u3__p7_0,
  133959. NULL,
  133960. &_vq_auxt__44u3__p7_0,
  133961. NULL,
  133962. 0
  133963. };
  133964. static long _vq_quantlist__44u3__p7_1[] = {
  133965. 7,
  133966. 6,
  133967. 8,
  133968. 5,
  133969. 9,
  133970. 4,
  133971. 10,
  133972. 3,
  133973. 11,
  133974. 2,
  133975. 12,
  133976. 1,
  133977. 13,
  133978. 0,
  133979. 14,
  133980. };
  133981. static long _vq_lengthlist__44u3__p7_1[] = {
  133982. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133983. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133984. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133985. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133986. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133987. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133988. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133989. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133990. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133991. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133992. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133993. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133994. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133995. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133996. 17,
  133997. };
  133998. static float _vq_quantthresh__44u3__p7_1[] = {
  133999. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134000. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134001. };
  134002. static long _vq_quantmap__44u3__p7_1[] = {
  134003. 13, 11, 9, 7, 5, 3, 1, 0,
  134004. 2, 4, 6, 8, 10, 12, 14,
  134005. };
  134006. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  134007. _vq_quantthresh__44u3__p7_1,
  134008. _vq_quantmap__44u3__p7_1,
  134009. 15,
  134010. 15
  134011. };
  134012. static static_codebook _44u3__p7_1 = {
  134013. 2, 225,
  134014. _vq_lengthlist__44u3__p7_1,
  134015. 1, -522338304, 1620115456, 4, 0,
  134016. _vq_quantlist__44u3__p7_1,
  134017. NULL,
  134018. &_vq_auxt__44u3__p7_1,
  134019. NULL,
  134020. 0
  134021. };
  134022. static long _vq_quantlist__44u3__p7_2[] = {
  134023. 8,
  134024. 7,
  134025. 9,
  134026. 6,
  134027. 10,
  134028. 5,
  134029. 11,
  134030. 4,
  134031. 12,
  134032. 3,
  134033. 13,
  134034. 2,
  134035. 14,
  134036. 1,
  134037. 15,
  134038. 0,
  134039. 16,
  134040. };
  134041. static long _vq_lengthlist__44u3__p7_2[] = {
  134042. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134043. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134044. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  134045. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134046. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134047. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134048. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  134049. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134050. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  134051. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  134052. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134053. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  134054. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  134055. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134056. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  134057. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  134058. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134059. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  134060. 11,
  134061. };
  134062. static float _vq_quantthresh__44u3__p7_2[] = {
  134063. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134064. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134065. };
  134066. static long _vq_quantmap__44u3__p7_2[] = {
  134067. 15, 13, 11, 9, 7, 5, 3, 1,
  134068. 0, 2, 4, 6, 8, 10, 12, 14,
  134069. 16,
  134070. };
  134071. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  134072. _vq_quantthresh__44u3__p7_2,
  134073. _vq_quantmap__44u3__p7_2,
  134074. 17,
  134075. 17
  134076. };
  134077. static static_codebook _44u3__p7_2 = {
  134078. 2, 289,
  134079. _vq_lengthlist__44u3__p7_2,
  134080. 1, -529530880, 1611661312, 5, 0,
  134081. _vq_quantlist__44u3__p7_2,
  134082. NULL,
  134083. &_vq_auxt__44u3__p7_2,
  134084. NULL,
  134085. 0
  134086. };
  134087. static long _huff_lengthlist__44u3__short[] = {
  134088. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  134089. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  134090. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  134091. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  134092. };
  134093. static static_codebook _huff_book__44u3__short = {
  134094. 2, 64,
  134095. _huff_lengthlist__44u3__short,
  134096. 0, 0, 0, 0, 0,
  134097. NULL,
  134098. NULL,
  134099. NULL,
  134100. NULL,
  134101. 0
  134102. };
  134103. static long _huff_lengthlist__44u4__long[] = {
  134104. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  134105. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  134106. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  134107. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  134108. };
  134109. static static_codebook _huff_book__44u4__long = {
  134110. 2, 64,
  134111. _huff_lengthlist__44u4__long,
  134112. 0, 0, 0, 0, 0,
  134113. NULL,
  134114. NULL,
  134115. NULL,
  134116. NULL,
  134117. 0
  134118. };
  134119. static long _vq_quantlist__44u4__p1_0[] = {
  134120. 1,
  134121. 0,
  134122. 2,
  134123. };
  134124. static long _vq_lengthlist__44u4__p1_0[] = {
  134125. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  134126. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  134127. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  134128. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  134129. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  134130. 13,
  134131. };
  134132. static float _vq_quantthresh__44u4__p1_0[] = {
  134133. -0.5, 0.5,
  134134. };
  134135. static long _vq_quantmap__44u4__p1_0[] = {
  134136. 1, 0, 2,
  134137. };
  134138. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  134139. _vq_quantthresh__44u4__p1_0,
  134140. _vq_quantmap__44u4__p1_0,
  134141. 3,
  134142. 3
  134143. };
  134144. static static_codebook _44u4__p1_0 = {
  134145. 4, 81,
  134146. _vq_lengthlist__44u4__p1_0,
  134147. 1, -535822336, 1611661312, 2, 0,
  134148. _vq_quantlist__44u4__p1_0,
  134149. NULL,
  134150. &_vq_auxt__44u4__p1_0,
  134151. NULL,
  134152. 0
  134153. };
  134154. static long _vq_quantlist__44u4__p2_0[] = {
  134155. 1,
  134156. 0,
  134157. 2,
  134158. };
  134159. static long _vq_lengthlist__44u4__p2_0[] = {
  134160. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134161. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  134162. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134163. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  134164. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  134165. 9,
  134166. };
  134167. static float _vq_quantthresh__44u4__p2_0[] = {
  134168. -0.5, 0.5,
  134169. };
  134170. static long _vq_quantmap__44u4__p2_0[] = {
  134171. 1, 0, 2,
  134172. };
  134173. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  134174. _vq_quantthresh__44u4__p2_0,
  134175. _vq_quantmap__44u4__p2_0,
  134176. 3,
  134177. 3
  134178. };
  134179. static static_codebook _44u4__p2_0 = {
  134180. 4, 81,
  134181. _vq_lengthlist__44u4__p2_0,
  134182. 1, -535822336, 1611661312, 2, 0,
  134183. _vq_quantlist__44u4__p2_0,
  134184. NULL,
  134185. &_vq_auxt__44u4__p2_0,
  134186. NULL,
  134187. 0
  134188. };
  134189. static long _vq_quantlist__44u4__p3_0[] = {
  134190. 2,
  134191. 1,
  134192. 3,
  134193. 0,
  134194. 4,
  134195. };
  134196. static long _vq_lengthlist__44u4__p3_0[] = {
  134197. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134198. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134199. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  134200. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  134201. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  134202. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  134203. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  134204. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  134205. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  134206. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  134207. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  134208. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  134209. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  134210. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  134211. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  134212. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  134213. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  134214. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  134215. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  134216. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  134217. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  134218. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  134219. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  134220. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  134221. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  134222. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  134223. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  134224. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  134225. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  134226. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  134227. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  134228. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  134229. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  134230. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  134231. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  134232. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  134233. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  134234. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  134235. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  134236. 0,
  134237. };
  134238. static float _vq_quantthresh__44u4__p3_0[] = {
  134239. -1.5, -0.5, 0.5, 1.5,
  134240. };
  134241. static long _vq_quantmap__44u4__p3_0[] = {
  134242. 3, 1, 0, 2, 4,
  134243. };
  134244. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  134245. _vq_quantthresh__44u4__p3_0,
  134246. _vq_quantmap__44u4__p3_0,
  134247. 5,
  134248. 5
  134249. };
  134250. static static_codebook _44u4__p3_0 = {
  134251. 4, 625,
  134252. _vq_lengthlist__44u4__p3_0,
  134253. 1, -533725184, 1611661312, 3, 0,
  134254. _vq_quantlist__44u4__p3_0,
  134255. NULL,
  134256. &_vq_auxt__44u4__p3_0,
  134257. NULL,
  134258. 0
  134259. };
  134260. static long _vq_quantlist__44u4__p4_0[] = {
  134261. 2,
  134262. 1,
  134263. 3,
  134264. 0,
  134265. 4,
  134266. };
  134267. static long _vq_lengthlist__44u4__p4_0[] = {
  134268. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134269. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134270. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134271. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134272. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134273. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  134274. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  134275. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  134276. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134277. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134278. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134279. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134280. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134281. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  134282. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134283. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134284. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134285. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134286. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134287. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  134288. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134289. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134290. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  134291. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134292. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  134293. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  134294. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  134295. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  134296. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  134297. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  134298. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  134299. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134300. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134301. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  134302. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  134303. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  134304. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  134305. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134306. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134307. 13,
  134308. };
  134309. static float _vq_quantthresh__44u4__p4_0[] = {
  134310. -1.5, -0.5, 0.5, 1.5,
  134311. };
  134312. static long _vq_quantmap__44u4__p4_0[] = {
  134313. 3, 1, 0, 2, 4,
  134314. };
  134315. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134316. _vq_quantthresh__44u4__p4_0,
  134317. _vq_quantmap__44u4__p4_0,
  134318. 5,
  134319. 5
  134320. };
  134321. static static_codebook _44u4__p4_0 = {
  134322. 4, 625,
  134323. _vq_lengthlist__44u4__p4_0,
  134324. 1, -533725184, 1611661312, 3, 0,
  134325. _vq_quantlist__44u4__p4_0,
  134326. NULL,
  134327. &_vq_auxt__44u4__p4_0,
  134328. NULL,
  134329. 0
  134330. };
  134331. static long _vq_quantlist__44u4__p5_0[] = {
  134332. 4,
  134333. 3,
  134334. 5,
  134335. 2,
  134336. 6,
  134337. 1,
  134338. 7,
  134339. 0,
  134340. 8,
  134341. };
  134342. static long _vq_lengthlist__44u4__p5_0[] = {
  134343. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134344. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134345. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134346. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134347. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134348. 12,
  134349. };
  134350. static float _vq_quantthresh__44u4__p5_0[] = {
  134351. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134352. };
  134353. static long _vq_quantmap__44u4__p5_0[] = {
  134354. 7, 5, 3, 1, 0, 2, 4, 6,
  134355. 8,
  134356. };
  134357. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134358. _vq_quantthresh__44u4__p5_0,
  134359. _vq_quantmap__44u4__p5_0,
  134360. 9,
  134361. 9
  134362. };
  134363. static static_codebook _44u4__p5_0 = {
  134364. 2, 81,
  134365. _vq_lengthlist__44u4__p5_0,
  134366. 1, -531628032, 1611661312, 4, 0,
  134367. _vq_quantlist__44u4__p5_0,
  134368. NULL,
  134369. &_vq_auxt__44u4__p5_0,
  134370. NULL,
  134371. 0
  134372. };
  134373. static long _vq_quantlist__44u4__p6_0[] = {
  134374. 6,
  134375. 5,
  134376. 7,
  134377. 4,
  134378. 8,
  134379. 3,
  134380. 9,
  134381. 2,
  134382. 10,
  134383. 1,
  134384. 11,
  134385. 0,
  134386. 12,
  134387. };
  134388. static long _vq_lengthlist__44u4__p6_0[] = {
  134389. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134390. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134391. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134392. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134393. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134394. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134395. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134396. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134397. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134398. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134399. 16,16,16,17,17,18,17,20,21,
  134400. };
  134401. static float _vq_quantthresh__44u4__p6_0[] = {
  134402. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134403. 12.5, 17.5, 22.5, 27.5,
  134404. };
  134405. static long _vq_quantmap__44u4__p6_0[] = {
  134406. 11, 9, 7, 5, 3, 1, 0, 2,
  134407. 4, 6, 8, 10, 12,
  134408. };
  134409. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134410. _vq_quantthresh__44u4__p6_0,
  134411. _vq_quantmap__44u4__p6_0,
  134412. 13,
  134413. 13
  134414. };
  134415. static static_codebook _44u4__p6_0 = {
  134416. 2, 169,
  134417. _vq_lengthlist__44u4__p6_0,
  134418. 1, -526516224, 1616117760, 4, 0,
  134419. _vq_quantlist__44u4__p6_0,
  134420. NULL,
  134421. &_vq_auxt__44u4__p6_0,
  134422. NULL,
  134423. 0
  134424. };
  134425. static long _vq_quantlist__44u4__p6_1[] = {
  134426. 2,
  134427. 1,
  134428. 3,
  134429. 0,
  134430. 4,
  134431. };
  134432. static long _vq_lengthlist__44u4__p6_1[] = {
  134433. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134434. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134435. };
  134436. static float _vq_quantthresh__44u4__p6_1[] = {
  134437. -1.5, -0.5, 0.5, 1.5,
  134438. };
  134439. static long _vq_quantmap__44u4__p6_1[] = {
  134440. 3, 1, 0, 2, 4,
  134441. };
  134442. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134443. _vq_quantthresh__44u4__p6_1,
  134444. _vq_quantmap__44u4__p6_1,
  134445. 5,
  134446. 5
  134447. };
  134448. static static_codebook _44u4__p6_1 = {
  134449. 2, 25,
  134450. _vq_lengthlist__44u4__p6_1,
  134451. 1, -533725184, 1611661312, 3, 0,
  134452. _vq_quantlist__44u4__p6_1,
  134453. NULL,
  134454. &_vq_auxt__44u4__p6_1,
  134455. NULL,
  134456. 0
  134457. };
  134458. static long _vq_quantlist__44u4__p7_0[] = {
  134459. 6,
  134460. 5,
  134461. 7,
  134462. 4,
  134463. 8,
  134464. 3,
  134465. 9,
  134466. 2,
  134467. 10,
  134468. 1,
  134469. 11,
  134470. 0,
  134471. 12,
  134472. };
  134473. static long _vq_lengthlist__44u4__p7_0[] = {
  134474. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134475. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134476. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134477. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134478. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134479. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134480. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134481. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134482. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134483. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134484. 11,11,11,11,11,11,11,11,11,
  134485. };
  134486. static float _vq_quantthresh__44u4__p7_0[] = {
  134487. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134488. 637.5, 892.5, 1147.5, 1402.5,
  134489. };
  134490. static long _vq_quantmap__44u4__p7_0[] = {
  134491. 11, 9, 7, 5, 3, 1, 0, 2,
  134492. 4, 6, 8, 10, 12,
  134493. };
  134494. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134495. _vq_quantthresh__44u4__p7_0,
  134496. _vq_quantmap__44u4__p7_0,
  134497. 13,
  134498. 13
  134499. };
  134500. static static_codebook _44u4__p7_0 = {
  134501. 2, 169,
  134502. _vq_lengthlist__44u4__p7_0,
  134503. 1, -514332672, 1627381760, 4, 0,
  134504. _vq_quantlist__44u4__p7_0,
  134505. NULL,
  134506. &_vq_auxt__44u4__p7_0,
  134507. NULL,
  134508. 0
  134509. };
  134510. static long _vq_quantlist__44u4__p7_1[] = {
  134511. 7,
  134512. 6,
  134513. 8,
  134514. 5,
  134515. 9,
  134516. 4,
  134517. 10,
  134518. 3,
  134519. 11,
  134520. 2,
  134521. 12,
  134522. 1,
  134523. 13,
  134524. 0,
  134525. 14,
  134526. };
  134527. static long _vq_lengthlist__44u4__p7_1[] = {
  134528. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134529. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134530. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134531. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134532. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134533. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134534. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134535. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134536. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134537. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134538. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134539. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134540. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134541. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134542. 16,
  134543. };
  134544. static float _vq_quantthresh__44u4__p7_1[] = {
  134545. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134546. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134547. };
  134548. static long _vq_quantmap__44u4__p7_1[] = {
  134549. 13, 11, 9, 7, 5, 3, 1, 0,
  134550. 2, 4, 6, 8, 10, 12, 14,
  134551. };
  134552. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134553. _vq_quantthresh__44u4__p7_1,
  134554. _vq_quantmap__44u4__p7_1,
  134555. 15,
  134556. 15
  134557. };
  134558. static static_codebook _44u4__p7_1 = {
  134559. 2, 225,
  134560. _vq_lengthlist__44u4__p7_1,
  134561. 1, -522338304, 1620115456, 4, 0,
  134562. _vq_quantlist__44u4__p7_1,
  134563. NULL,
  134564. &_vq_auxt__44u4__p7_1,
  134565. NULL,
  134566. 0
  134567. };
  134568. static long _vq_quantlist__44u4__p7_2[] = {
  134569. 8,
  134570. 7,
  134571. 9,
  134572. 6,
  134573. 10,
  134574. 5,
  134575. 11,
  134576. 4,
  134577. 12,
  134578. 3,
  134579. 13,
  134580. 2,
  134581. 14,
  134582. 1,
  134583. 15,
  134584. 0,
  134585. 16,
  134586. };
  134587. static long _vq_lengthlist__44u4__p7_2[] = {
  134588. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134589. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134590. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134591. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134592. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134593. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134594. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134595. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134596. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134597. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134598. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134599. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134600. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134601. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134602. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134603. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134604. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134605. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134606. 10,
  134607. };
  134608. static float _vq_quantthresh__44u4__p7_2[] = {
  134609. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134610. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134611. };
  134612. static long _vq_quantmap__44u4__p7_2[] = {
  134613. 15, 13, 11, 9, 7, 5, 3, 1,
  134614. 0, 2, 4, 6, 8, 10, 12, 14,
  134615. 16,
  134616. };
  134617. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134618. _vq_quantthresh__44u4__p7_2,
  134619. _vq_quantmap__44u4__p7_2,
  134620. 17,
  134621. 17
  134622. };
  134623. static static_codebook _44u4__p7_2 = {
  134624. 2, 289,
  134625. _vq_lengthlist__44u4__p7_2,
  134626. 1, -529530880, 1611661312, 5, 0,
  134627. _vq_quantlist__44u4__p7_2,
  134628. NULL,
  134629. &_vq_auxt__44u4__p7_2,
  134630. NULL,
  134631. 0
  134632. };
  134633. static long _huff_lengthlist__44u4__short[] = {
  134634. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134635. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134636. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134637. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134638. };
  134639. static static_codebook _huff_book__44u4__short = {
  134640. 2, 64,
  134641. _huff_lengthlist__44u4__short,
  134642. 0, 0, 0, 0, 0,
  134643. NULL,
  134644. NULL,
  134645. NULL,
  134646. NULL,
  134647. 0
  134648. };
  134649. static long _huff_lengthlist__44u5__long[] = {
  134650. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134651. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134652. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134653. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134654. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134655. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134656. 14, 8, 7, 8,
  134657. };
  134658. static static_codebook _huff_book__44u5__long = {
  134659. 2, 100,
  134660. _huff_lengthlist__44u5__long,
  134661. 0, 0, 0, 0, 0,
  134662. NULL,
  134663. NULL,
  134664. NULL,
  134665. NULL,
  134666. 0
  134667. };
  134668. static long _vq_quantlist__44u5__p1_0[] = {
  134669. 1,
  134670. 0,
  134671. 2,
  134672. };
  134673. static long _vq_lengthlist__44u5__p1_0[] = {
  134674. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134675. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134676. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134677. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134678. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134679. 12,
  134680. };
  134681. static float _vq_quantthresh__44u5__p1_0[] = {
  134682. -0.5, 0.5,
  134683. };
  134684. static long _vq_quantmap__44u5__p1_0[] = {
  134685. 1, 0, 2,
  134686. };
  134687. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134688. _vq_quantthresh__44u5__p1_0,
  134689. _vq_quantmap__44u5__p1_0,
  134690. 3,
  134691. 3
  134692. };
  134693. static static_codebook _44u5__p1_0 = {
  134694. 4, 81,
  134695. _vq_lengthlist__44u5__p1_0,
  134696. 1, -535822336, 1611661312, 2, 0,
  134697. _vq_quantlist__44u5__p1_0,
  134698. NULL,
  134699. &_vq_auxt__44u5__p1_0,
  134700. NULL,
  134701. 0
  134702. };
  134703. static long _vq_quantlist__44u5__p2_0[] = {
  134704. 1,
  134705. 0,
  134706. 2,
  134707. };
  134708. static long _vq_lengthlist__44u5__p2_0[] = {
  134709. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134710. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134711. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134712. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134713. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134714. 9,
  134715. };
  134716. static float _vq_quantthresh__44u5__p2_0[] = {
  134717. -0.5, 0.5,
  134718. };
  134719. static long _vq_quantmap__44u5__p2_0[] = {
  134720. 1, 0, 2,
  134721. };
  134722. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134723. _vq_quantthresh__44u5__p2_0,
  134724. _vq_quantmap__44u5__p2_0,
  134725. 3,
  134726. 3
  134727. };
  134728. static static_codebook _44u5__p2_0 = {
  134729. 4, 81,
  134730. _vq_lengthlist__44u5__p2_0,
  134731. 1, -535822336, 1611661312, 2, 0,
  134732. _vq_quantlist__44u5__p2_0,
  134733. NULL,
  134734. &_vq_auxt__44u5__p2_0,
  134735. NULL,
  134736. 0
  134737. };
  134738. static long _vq_quantlist__44u5__p3_0[] = {
  134739. 2,
  134740. 1,
  134741. 3,
  134742. 0,
  134743. 4,
  134744. };
  134745. static long _vq_lengthlist__44u5__p3_0[] = {
  134746. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134747. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134748. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134749. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134750. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134751. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134752. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134753. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134754. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134755. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134756. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134757. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134758. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134759. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134760. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134761. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134762. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134763. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134764. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134765. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134766. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134767. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134768. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134769. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134770. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134771. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134772. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134773. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134774. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134775. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134776. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134777. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134778. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134779. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134780. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134781. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134782. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134783. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134784. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134785. 0,
  134786. };
  134787. static float _vq_quantthresh__44u5__p3_0[] = {
  134788. -1.5, -0.5, 0.5, 1.5,
  134789. };
  134790. static long _vq_quantmap__44u5__p3_0[] = {
  134791. 3, 1, 0, 2, 4,
  134792. };
  134793. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134794. _vq_quantthresh__44u5__p3_0,
  134795. _vq_quantmap__44u5__p3_0,
  134796. 5,
  134797. 5
  134798. };
  134799. static static_codebook _44u5__p3_0 = {
  134800. 4, 625,
  134801. _vq_lengthlist__44u5__p3_0,
  134802. 1, -533725184, 1611661312, 3, 0,
  134803. _vq_quantlist__44u5__p3_0,
  134804. NULL,
  134805. &_vq_auxt__44u5__p3_0,
  134806. NULL,
  134807. 0
  134808. };
  134809. static long _vq_quantlist__44u5__p4_0[] = {
  134810. 2,
  134811. 1,
  134812. 3,
  134813. 0,
  134814. 4,
  134815. };
  134816. static long _vq_lengthlist__44u5__p4_0[] = {
  134817. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134818. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134819. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134820. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134821. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134822. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134823. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134824. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134825. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134826. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134827. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134828. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134829. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134830. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134831. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134832. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134833. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134834. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134835. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134836. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134837. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134838. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134839. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134840. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134841. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134842. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134843. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134844. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134845. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134846. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134847. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134848. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134849. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134850. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134851. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134852. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134853. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134854. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134855. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134856. 12,
  134857. };
  134858. static float _vq_quantthresh__44u5__p4_0[] = {
  134859. -1.5, -0.5, 0.5, 1.5,
  134860. };
  134861. static long _vq_quantmap__44u5__p4_0[] = {
  134862. 3, 1, 0, 2, 4,
  134863. };
  134864. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134865. _vq_quantthresh__44u5__p4_0,
  134866. _vq_quantmap__44u5__p4_0,
  134867. 5,
  134868. 5
  134869. };
  134870. static static_codebook _44u5__p4_0 = {
  134871. 4, 625,
  134872. _vq_lengthlist__44u5__p4_0,
  134873. 1, -533725184, 1611661312, 3, 0,
  134874. _vq_quantlist__44u5__p4_0,
  134875. NULL,
  134876. &_vq_auxt__44u5__p4_0,
  134877. NULL,
  134878. 0
  134879. };
  134880. static long _vq_quantlist__44u5__p5_0[] = {
  134881. 4,
  134882. 3,
  134883. 5,
  134884. 2,
  134885. 6,
  134886. 1,
  134887. 7,
  134888. 0,
  134889. 8,
  134890. };
  134891. static long _vq_lengthlist__44u5__p5_0[] = {
  134892. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134893. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134894. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134895. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134896. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134897. 14,
  134898. };
  134899. static float _vq_quantthresh__44u5__p5_0[] = {
  134900. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134901. };
  134902. static long _vq_quantmap__44u5__p5_0[] = {
  134903. 7, 5, 3, 1, 0, 2, 4, 6,
  134904. 8,
  134905. };
  134906. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134907. _vq_quantthresh__44u5__p5_0,
  134908. _vq_quantmap__44u5__p5_0,
  134909. 9,
  134910. 9
  134911. };
  134912. static static_codebook _44u5__p5_0 = {
  134913. 2, 81,
  134914. _vq_lengthlist__44u5__p5_0,
  134915. 1, -531628032, 1611661312, 4, 0,
  134916. _vq_quantlist__44u5__p5_0,
  134917. NULL,
  134918. &_vq_auxt__44u5__p5_0,
  134919. NULL,
  134920. 0
  134921. };
  134922. static long _vq_quantlist__44u5__p6_0[] = {
  134923. 4,
  134924. 3,
  134925. 5,
  134926. 2,
  134927. 6,
  134928. 1,
  134929. 7,
  134930. 0,
  134931. 8,
  134932. };
  134933. static long _vq_lengthlist__44u5__p6_0[] = {
  134934. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134935. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134936. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134937. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134938. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134939. 11,
  134940. };
  134941. static float _vq_quantthresh__44u5__p6_0[] = {
  134942. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134943. };
  134944. static long _vq_quantmap__44u5__p6_0[] = {
  134945. 7, 5, 3, 1, 0, 2, 4, 6,
  134946. 8,
  134947. };
  134948. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134949. _vq_quantthresh__44u5__p6_0,
  134950. _vq_quantmap__44u5__p6_0,
  134951. 9,
  134952. 9
  134953. };
  134954. static static_codebook _44u5__p6_0 = {
  134955. 2, 81,
  134956. _vq_lengthlist__44u5__p6_0,
  134957. 1, -531628032, 1611661312, 4, 0,
  134958. _vq_quantlist__44u5__p6_0,
  134959. NULL,
  134960. &_vq_auxt__44u5__p6_0,
  134961. NULL,
  134962. 0
  134963. };
  134964. static long _vq_quantlist__44u5__p7_0[] = {
  134965. 1,
  134966. 0,
  134967. 2,
  134968. };
  134969. static long _vq_lengthlist__44u5__p7_0[] = {
  134970. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134971. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134972. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134973. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134974. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134975. 12,
  134976. };
  134977. static float _vq_quantthresh__44u5__p7_0[] = {
  134978. -5.5, 5.5,
  134979. };
  134980. static long _vq_quantmap__44u5__p7_0[] = {
  134981. 1, 0, 2,
  134982. };
  134983. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134984. _vq_quantthresh__44u5__p7_0,
  134985. _vq_quantmap__44u5__p7_0,
  134986. 3,
  134987. 3
  134988. };
  134989. static static_codebook _44u5__p7_0 = {
  134990. 4, 81,
  134991. _vq_lengthlist__44u5__p7_0,
  134992. 1, -529137664, 1618345984, 2, 0,
  134993. _vq_quantlist__44u5__p7_0,
  134994. NULL,
  134995. &_vq_auxt__44u5__p7_0,
  134996. NULL,
  134997. 0
  134998. };
  134999. static long _vq_quantlist__44u5__p7_1[] = {
  135000. 5,
  135001. 4,
  135002. 6,
  135003. 3,
  135004. 7,
  135005. 2,
  135006. 8,
  135007. 1,
  135008. 9,
  135009. 0,
  135010. 10,
  135011. };
  135012. static long _vq_lengthlist__44u5__p7_1[] = {
  135013. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  135014. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  135015. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  135016. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  135017. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  135018. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135019. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  135020. 9, 9, 9, 9, 9,10,10,10,10,
  135021. };
  135022. static float _vq_quantthresh__44u5__p7_1[] = {
  135023. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135024. 3.5, 4.5,
  135025. };
  135026. static long _vq_quantmap__44u5__p7_1[] = {
  135027. 9, 7, 5, 3, 1, 0, 2, 4,
  135028. 6, 8, 10,
  135029. };
  135030. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  135031. _vq_quantthresh__44u5__p7_1,
  135032. _vq_quantmap__44u5__p7_1,
  135033. 11,
  135034. 11
  135035. };
  135036. static static_codebook _44u5__p7_1 = {
  135037. 2, 121,
  135038. _vq_lengthlist__44u5__p7_1,
  135039. 1, -531365888, 1611661312, 4, 0,
  135040. _vq_quantlist__44u5__p7_1,
  135041. NULL,
  135042. &_vq_auxt__44u5__p7_1,
  135043. NULL,
  135044. 0
  135045. };
  135046. static long _vq_quantlist__44u5__p8_0[] = {
  135047. 5,
  135048. 4,
  135049. 6,
  135050. 3,
  135051. 7,
  135052. 2,
  135053. 8,
  135054. 1,
  135055. 9,
  135056. 0,
  135057. 10,
  135058. };
  135059. static long _vq_lengthlist__44u5__p8_0[] = {
  135060. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135061. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135062. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  135063. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  135064. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  135065. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  135066. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  135067. 12,13,13,14,14,14,14,15,15,
  135068. };
  135069. static float _vq_quantthresh__44u5__p8_0[] = {
  135070. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135071. 38.5, 49.5,
  135072. };
  135073. static long _vq_quantmap__44u5__p8_0[] = {
  135074. 9, 7, 5, 3, 1, 0, 2, 4,
  135075. 6, 8, 10,
  135076. };
  135077. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  135078. _vq_quantthresh__44u5__p8_0,
  135079. _vq_quantmap__44u5__p8_0,
  135080. 11,
  135081. 11
  135082. };
  135083. static static_codebook _44u5__p8_0 = {
  135084. 2, 121,
  135085. _vq_lengthlist__44u5__p8_0,
  135086. 1, -524582912, 1618345984, 4, 0,
  135087. _vq_quantlist__44u5__p8_0,
  135088. NULL,
  135089. &_vq_auxt__44u5__p8_0,
  135090. NULL,
  135091. 0
  135092. };
  135093. static long _vq_quantlist__44u5__p8_1[] = {
  135094. 5,
  135095. 4,
  135096. 6,
  135097. 3,
  135098. 7,
  135099. 2,
  135100. 8,
  135101. 1,
  135102. 9,
  135103. 0,
  135104. 10,
  135105. };
  135106. static long _vq_lengthlist__44u5__p8_1[] = {
  135107. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  135108. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  135109. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  135110. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135111. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  135112. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135113. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135114. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135115. };
  135116. static float _vq_quantthresh__44u5__p8_1[] = {
  135117. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135118. 3.5, 4.5,
  135119. };
  135120. static long _vq_quantmap__44u5__p8_1[] = {
  135121. 9, 7, 5, 3, 1, 0, 2, 4,
  135122. 6, 8, 10,
  135123. };
  135124. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  135125. _vq_quantthresh__44u5__p8_1,
  135126. _vq_quantmap__44u5__p8_1,
  135127. 11,
  135128. 11
  135129. };
  135130. static static_codebook _44u5__p8_1 = {
  135131. 2, 121,
  135132. _vq_lengthlist__44u5__p8_1,
  135133. 1, -531365888, 1611661312, 4, 0,
  135134. _vq_quantlist__44u5__p8_1,
  135135. NULL,
  135136. &_vq_auxt__44u5__p8_1,
  135137. NULL,
  135138. 0
  135139. };
  135140. static long _vq_quantlist__44u5__p9_0[] = {
  135141. 6,
  135142. 5,
  135143. 7,
  135144. 4,
  135145. 8,
  135146. 3,
  135147. 9,
  135148. 2,
  135149. 10,
  135150. 1,
  135151. 11,
  135152. 0,
  135153. 12,
  135154. };
  135155. static long _vq_lengthlist__44u5__p9_0[] = {
  135156. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  135157. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  135158. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  135159. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  135160. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135161. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135162. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135163. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135164. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  135165. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  135166. 12,12,12,12,12,12,12,12,12,
  135167. };
  135168. static float _vq_quantthresh__44u5__p9_0[] = {
  135169. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  135170. 637.5, 892.5, 1147.5, 1402.5,
  135171. };
  135172. static long _vq_quantmap__44u5__p9_0[] = {
  135173. 11, 9, 7, 5, 3, 1, 0, 2,
  135174. 4, 6, 8, 10, 12,
  135175. };
  135176. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  135177. _vq_quantthresh__44u5__p9_0,
  135178. _vq_quantmap__44u5__p9_0,
  135179. 13,
  135180. 13
  135181. };
  135182. static static_codebook _44u5__p9_0 = {
  135183. 2, 169,
  135184. _vq_lengthlist__44u5__p9_0,
  135185. 1, -514332672, 1627381760, 4, 0,
  135186. _vq_quantlist__44u5__p9_0,
  135187. NULL,
  135188. &_vq_auxt__44u5__p9_0,
  135189. NULL,
  135190. 0
  135191. };
  135192. static long _vq_quantlist__44u5__p9_1[] = {
  135193. 7,
  135194. 6,
  135195. 8,
  135196. 5,
  135197. 9,
  135198. 4,
  135199. 10,
  135200. 3,
  135201. 11,
  135202. 2,
  135203. 12,
  135204. 1,
  135205. 13,
  135206. 0,
  135207. 14,
  135208. };
  135209. static long _vq_lengthlist__44u5__p9_1[] = {
  135210. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  135211. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  135212. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  135213. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  135214. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  135215. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  135216. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  135217. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  135218. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  135219. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  135220. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  135221. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  135222. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  135223. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  135224. 14,
  135225. };
  135226. static float _vq_quantthresh__44u5__p9_1[] = {
  135227. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135228. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135229. };
  135230. static long _vq_quantmap__44u5__p9_1[] = {
  135231. 13, 11, 9, 7, 5, 3, 1, 0,
  135232. 2, 4, 6, 8, 10, 12, 14,
  135233. };
  135234. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  135235. _vq_quantthresh__44u5__p9_1,
  135236. _vq_quantmap__44u5__p9_1,
  135237. 15,
  135238. 15
  135239. };
  135240. static static_codebook _44u5__p9_1 = {
  135241. 2, 225,
  135242. _vq_lengthlist__44u5__p9_1,
  135243. 1, -522338304, 1620115456, 4, 0,
  135244. _vq_quantlist__44u5__p9_1,
  135245. NULL,
  135246. &_vq_auxt__44u5__p9_1,
  135247. NULL,
  135248. 0
  135249. };
  135250. static long _vq_quantlist__44u5__p9_2[] = {
  135251. 8,
  135252. 7,
  135253. 9,
  135254. 6,
  135255. 10,
  135256. 5,
  135257. 11,
  135258. 4,
  135259. 12,
  135260. 3,
  135261. 13,
  135262. 2,
  135263. 14,
  135264. 1,
  135265. 15,
  135266. 0,
  135267. 16,
  135268. };
  135269. static long _vq_lengthlist__44u5__p9_2[] = {
  135270. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135271. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135272. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135273. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135274. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135275. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  135276. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135277. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  135278. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135279. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  135280. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  135281. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  135282. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135283. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135284. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135285. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135286. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  135287. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  135288. 10,
  135289. };
  135290. static float _vq_quantthresh__44u5__p9_2[] = {
  135291. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135292. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135293. };
  135294. static long _vq_quantmap__44u5__p9_2[] = {
  135295. 15, 13, 11, 9, 7, 5, 3, 1,
  135296. 0, 2, 4, 6, 8, 10, 12, 14,
  135297. 16,
  135298. };
  135299. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  135300. _vq_quantthresh__44u5__p9_2,
  135301. _vq_quantmap__44u5__p9_2,
  135302. 17,
  135303. 17
  135304. };
  135305. static static_codebook _44u5__p9_2 = {
  135306. 2, 289,
  135307. _vq_lengthlist__44u5__p9_2,
  135308. 1, -529530880, 1611661312, 5, 0,
  135309. _vq_quantlist__44u5__p9_2,
  135310. NULL,
  135311. &_vq_auxt__44u5__p9_2,
  135312. NULL,
  135313. 0
  135314. };
  135315. static long _huff_lengthlist__44u5__short[] = {
  135316. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135317. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135318. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135319. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135320. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135321. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135322. 6, 8,15,17,
  135323. };
  135324. static static_codebook _huff_book__44u5__short = {
  135325. 2, 100,
  135326. _huff_lengthlist__44u5__short,
  135327. 0, 0, 0, 0, 0,
  135328. NULL,
  135329. NULL,
  135330. NULL,
  135331. NULL,
  135332. 0
  135333. };
  135334. static long _huff_lengthlist__44u6__long[] = {
  135335. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135336. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135337. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135338. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135339. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135340. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135341. 13, 8, 7, 7,
  135342. };
  135343. static static_codebook _huff_book__44u6__long = {
  135344. 2, 100,
  135345. _huff_lengthlist__44u6__long,
  135346. 0, 0, 0, 0, 0,
  135347. NULL,
  135348. NULL,
  135349. NULL,
  135350. NULL,
  135351. 0
  135352. };
  135353. static long _vq_quantlist__44u6__p1_0[] = {
  135354. 1,
  135355. 0,
  135356. 2,
  135357. };
  135358. static long _vq_lengthlist__44u6__p1_0[] = {
  135359. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135360. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135361. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135362. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135363. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135364. 12,
  135365. };
  135366. static float _vq_quantthresh__44u6__p1_0[] = {
  135367. -0.5, 0.5,
  135368. };
  135369. static long _vq_quantmap__44u6__p1_0[] = {
  135370. 1, 0, 2,
  135371. };
  135372. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135373. _vq_quantthresh__44u6__p1_0,
  135374. _vq_quantmap__44u6__p1_0,
  135375. 3,
  135376. 3
  135377. };
  135378. static static_codebook _44u6__p1_0 = {
  135379. 4, 81,
  135380. _vq_lengthlist__44u6__p1_0,
  135381. 1, -535822336, 1611661312, 2, 0,
  135382. _vq_quantlist__44u6__p1_0,
  135383. NULL,
  135384. &_vq_auxt__44u6__p1_0,
  135385. NULL,
  135386. 0
  135387. };
  135388. static long _vq_quantlist__44u6__p2_0[] = {
  135389. 1,
  135390. 0,
  135391. 2,
  135392. };
  135393. static long _vq_lengthlist__44u6__p2_0[] = {
  135394. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135395. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135396. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135397. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135398. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135399. 9,
  135400. };
  135401. static float _vq_quantthresh__44u6__p2_0[] = {
  135402. -0.5, 0.5,
  135403. };
  135404. static long _vq_quantmap__44u6__p2_0[] = {
  135405. 1, 0, 2,
  135406. };
  135407. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135408. _vq_quantthresh__44u6__p2_0,
  135409. _vq_quantmap__44u6__p2_0,
  135410. 3,
  135411. 3
  135412. };
  135413. static static_codebook _44u6__p2_0 = {
  135414. 4, 81,
  135415. _vq_lengthlist__44u6__p2_0,
  135416. 1, -535822336, 1611661312, 2, 0,
  135417. _vq_quantlist__44u6__p2_0,
  135418. NULL,
  135419. &_vq_auxt__44u6__p2_0,
  135420. NULL,
  135421. 0
  135422. };
  135423. static long _vq_quantlist__44u6__p3_0[] = {
  135424. 2,
  135425. 1,
  135426. 3,
  135427. 0,
  135428. 4,
  135429. };
  135430. static long _vq_lengthlist__44u6__p3_0[] = {
  135431. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135432. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135433. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135434. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135435. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135436. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135437. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135438. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135439. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135440. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135441. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135442. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135443. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135444. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135445. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135446. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135447. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135448. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135449. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135450. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135451. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135452. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135453. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135454. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135455. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135456. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135457. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135458. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135459. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135460. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135461. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135462. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135463. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135464. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135465. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135466. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135467. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135468. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135469. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135470. 19,
  135471. };
  135472. static float _vq_quantthresh__44u6__p3_0[] = {
  135473. -1.5, -0.5, 0.5, 1.5,
  135474. };
  135475. static long _vq_quantmap__44u6__p3_0[] = {
  135476. 3, 1, 0, 2, 4,
  135477. };
  135478. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135479. _vq_quantthresh__44u6__p3_0,
  135480. _vq_quantmap__44u6__p3_0,
  135481. 5,
  135482. 5
  135483. };
  135484. static static_codebook _44u6__p3_0 = {
  135485. 4, 625,
  135486. _vq_lengthlist__44u6__p3_0,
  135487. 1, -533725184, 1611661312, 3, 0,
  135488. _vq_quantlist__44u6__p3_0,
  135489. NULL,
  135490. &_vq_auxt__44u6__p3_0,
  135491. NULL,
  135492. 0
  135493. };
  135494. static long _vq_quantlist__44u6__p4_0[] = {
  135495. 2,
  135496. 1,
  135497. 3,
  135498. 0,
  135499. 4,
  135500. };
  135501. static long _vq_lengthlist__44u6__p4_0[] = {
  135502. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135503. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135504. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135505. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135506. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135507. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135508. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135509. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135510. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135511. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135512. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135513. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135514. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135515. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135516. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135517. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135518. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135519. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135520. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135521. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135522. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135523. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135524. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135525. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135526. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135527. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135528. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135529. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135530. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135531. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135532. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135533. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135534. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135535. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135536. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135537. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135538. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135539. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135540. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135541. 13,
  135542. };
  135543. static float _vq_quantthresh__44u6__p4_0[] = {
  135544. -1.5, -0.5, 0.5, 1.5,
  135545. };
  135546. static long _vq_quantmap__44u6__p4_0[] = {
  135547. 3, 1, 0, 2, 4,
  135548. };
  135549. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135550. _vq_quantthresh__44u6__p4_0,
  135551. _vq_quantmap__44u6__p4_0,
  135552. 5,
  135553. 5
  135554. };
  135555. static static_codebook _44u6__p4_0 = {
  135556. 4, 625,
  135557. _vq_lengthlist__44u6__p4_0,
  135558. 1, -533725184, 1611661312, 3, 0,
  135559. _vq_quantlist__44u6__p4_0,
  135560. NULL,
  135561. &_vq_auxt__44u6__p4_0,
  135562. NULL,
  135563. 0
  135564. };
  135565. static long _vq_quantlist__44u6__p5_0[] = {
  135566. 4,
  135567. 3,
  135568. 5,
  135569. 2,
  135570. 6,
  135571. 1,
  135572. 7,
  135573. 0,
  135574. 8,
  135575. };
  135576. static long _vq_lengthlist__44u6__p5_0[] = {
  135577. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135578. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135579. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135580. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135581. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135582. 14,
  135583. };
  135584. static float _vq_quantthresh__44u6__p5_0[] = {
  135585. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135586. };
  135587. static long _vq_quantmap__44u6__p5_0[] = {
  135588. 7, 5, 3, 1, 0, 2, 4, 6,
  135589. 8,
  135590. };
  135591. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135592. _vq_quantthresh__44u6__p5_0,
  135593. _vq_quantmap__44u6__p5_0,
  135594. 9,
  135595. 9
  135596. };
  135597. static static_codebook _44u6__p5_0 = {
  135598. 2, 81,
  135599. _vq_lengthlist__44u6__p5_0,
  135600. 1, -531628032, 1611661312, 4, 0,
  135601. _vq_quantlist__44u6__p5_0,
  135602. NULL,
  135603. &_vq_auxt__44u6__p5_0,
  135604. NULL,
  135605. 0
  135606. };
  135607. static long _vq_quantlist__44u6__p6_0[] = {
  135608. 4,
  135609. 3,
  135610. 5,
  135611. 2,
  135612. 6,
  135613. 1,
  135614. 7,
  135615. 0,
  135616. 8,
  135617. };
  135618. static long _vq_lengthlist__44u6__p6_0[] = {
  135619. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135620. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135621. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135622. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135623. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135624. 12,
  135625. };
  135626. static float _vq_quantthresh__44u6__p6_0[] = {
  135627. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135628. };
  135629. static long _vq_quantmap__44u6__p6_0[] = {
  135630. 7, 5, 3, 1, 0, 2, 4, 6,
  135631. 8,
  135632. };
  135633. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135634. _vq_quantthresh__44u6__p6_0,
  135635. _vq_quantmap__44u6__p6_0,
  135636. 9,
  135637. 9
  135638. };
  135639. static static_codebook _44u6__p6_0 = {
  135640. 2, 81,
  135641. _vq_lengthlist__44u6__p6_0,
  135642. 1, -531628032, 1611661312, 4, 0,
  135643. _vq_quantlist__44u6__p6_0,
  135644. NULL,
  135645. &_vq_auxt__44u6__p6_0,
  135646. NULL,
  135647. 0
  135648. };
  135649. static long _vq_quantlist__44u6__p7_0[] = {
  135650. 1,
  135651. 0,
  135652. 2,
  135653. };
  135654. static long _vq_lengthlist__44u6__p7_0[] = {
  135655. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135656. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135657. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135658. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135659. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135660. 10,
  135661. };
  135662. static float _vq_quantthresh__44u6__p7_0[] = {
  135663. -5.5, 5.5,
  135664. };
  135665. static long _vq_quantmap__44u6__p7_0[] = {
  135666. 1, 0, 2,
  135667. };
  135668. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135669. _vq_quantthresh__44u6__p7_0,
  135670. _vq_quantmap__44u6__p7_0,
  135671. 3,
  135672. 3
  135673. };
  135674. static static_codebook _44u6__p7_0 = {
  135675. 4, 81,
  135676. _vq_lengthlist__44u6__p7_0,
  135677. 1, -529137664, 1618345984, 2, 0,
  135678. _vq_quantlist__44u6__p7_0,
  135679. NULL,
  135680. &_vq_auxt__44u6__p7_0,
  135681. NULL,
  135682. 0
  135683. };
  135684. static long _vq_quantlist__44u6__p7_1[] = {
  135685. 5,
  135686. 4,
  135687. 6,
  135688. 3,
  135689. 7,
  135690. 2,
  135691. 8,
  135692. 1,
  135693. 9,
  135694. 0,
  135695. 10,
  135696. };
  135697. static long _vq_lengthlist__44u6__p7_1[] = {
  135698. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135699. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135700. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135701. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135702. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135703. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135704. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135705. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135706. };
  135707. static float _vq_quantthresh__44u6__p7_1[] = {
  135708. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135709. 3.5, 4.5,
  135710. };
  135711. static long _vq_quantmap__44u6__p7_1[] = {
  135712. 9, 7, 5, 3, 1, 0, 2, 4,
  135713. 6, 8, 10,
  135714. };
  135715. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135716. _vq_quantthresh__44u6__p7_1,
  135717. _vq_quantmap__44u6__p7_1,
  135718. 11,
  135719. 11
  135720. };
  135721. static static_codebook _44u6__p7_1 = {
  135722. 2, 121,
  135723. _vq_lengthlist__44u6__p7_1,
  135724. 1, -531365888, 1611661312, 4, 0,
  135725. _vq_quantlist__44u6__p7_1,
  135726. NULL,
  135727. &_vq_auxt__44u6__p7_1,
  135728. NULL,
  135729. 0
  135730. };
  135731. static long _vq_quantlist__44u6__p8_0[] = {
  135732. 5,
  135733. 4,
  135734. 6,
  135735. 3,
  135736. 7,
  135737. 2,
  135738. 8,
  135739. 1,
  135740. 9,
  135741. 0,
  135742. 10,
  135743. };
  135744. static long _vq_lengthlist__44u6__p8_0[] = {
  135745. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135746. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135747. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135748. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135749. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135750. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135751. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135752. 12,13,13,14,14,14,15,15,15,
  135753. };
  135754. static float _vq_quantthresh__44u6__p8_0[] = {
  135755. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135756. 38.5, 49.5,
  135757. };
  135758. static long _vq_quantmap__44u6__p8_0[] = {
  135759. 9, 7, 5, 3, 1, 0, 2, 4,
  135760. 6, 8, 10,
  135761. };
  135762. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135763. _vq_quantthresh__44u6__p8_0,
  135764. _vq_quantmap__44u6__p8_0,
  135765. 11,
  135766. 11
  135767. };
  135768. static static_codebook _44u6__p8_0 = {
  135769. 2, 121,
  135770. _vq_lengthlist__44u6__p8_0,
  135771. 1, -524582912, 1618345984, 4, 0,
  135772. _vq_quantlist__44u6__p8_0,
  135773. NULL,
  135774. &_vq_auxt__44u6__p8_0,
  135775. NULL,
  135776. 0
  135777. };
  135778. static long _vq_quantlist__44u6__p8_1[] = {
  135779. 5,
  135780. 4,
  135781. 6,
  135782. 3,
  135783. 7,
  135784. 2,
  135785. 8,
  135786. 1,
  135787. 9,
  135788. 0,
  135789. 10,
  135790. };
  135791. static long _vq_lengthlist__44u6__p8_1[] = {
  135792. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135793. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135794. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135795. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135796. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135797. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135798. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135799. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135800. };
  135801. static float _vq_quantthresh__44u6__p8_1[] = {
  135802. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135803. 3.5, 4.5,
  135804. };
  135805. static long _vq_quantmap__44u6__p8_1[] = {
  135806. 9, 7, 5, 3, 1, 0, 2, 4,
  135807. 6, 8, 10,
  135808. };
  135809. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135810. _vq_quantthresh__44u6__p8_1,
  135811. _vq_quantmap__44u6__p8_1,
  135812. 11,
  135813. 11
  135814. };
  135815. static static_codebook _44u6__p8_1 = {
  135816. 2, 121,
  135817. _vq_lengthlist__44u6__p8_1,
  135818. 1, -531365888, 1611661312, 4, 0,
  135819. _vq_quantlist__44u6__p8_1,
  135820. NULL,
  135821. &_vq_auxt__44u6__p8_1,
  135822. NULL,
  135823. 0
  135824. };
  135825. static long _vq_quantlist__44u6__p9_0[] = {
  135826. 7,
  135827. 6,
  135828. 8,
  135829. 5,
  135830. 9,
  135831. 4,
  135832. 10,
  135833. 3,
  135834. 11,
  135835. 2,
  135836. 12,
  135837. 1,
  135838. 13,
  135839. 0,
  135840. 14,
  135841. };
  135842. static long _vq_lengthlist__44u6__p9_0[] = {
  135843. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135844. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135845. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135846. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135847. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135848. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135849. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135850. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135851. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135852. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135853. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135854. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135855. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135856. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135857. 14,
  135858. };
  135859. static float _vq_quantthresh__44u6__p9_0[] = {
  135860. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135861. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135862. };
  135863. static long _vq_quantmap__44u6__p9_0[] = {
  135864. 13, 11, 9, 7, 5, 3, 1, 0,
  135865. 2, 4, 6, 8, 10, 12, 14,
  135866. };
  135867. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135868. _vq_quantthresh__44u6__p9_0,
  135869. _vq_quantmap__44u6__p9_0,
  135870. 15,
  135871. 15
  135872. };
  135873. static static_codebook _44u6__p9_0 = {
  135874. 2, 225,
  135875. _vq_lengthlist__44u6__p9_0,
  135876. 1, -514071552, 1627381760, 4, 0,
  135877. _vq_quantlist__44u6__p9_0,
  135878. NULL,
  135879. &_vq_auxt__44u6__p9_0,
  135880. NULL,
  135881. 0
  135882. };
  135883. static long _vq_quantlist__44u6__p9_1[] = {
  135884. 7,
  135885. 6,
  135886. 8,
  135887. 5,
  135888. 9,
  135889. 4,
  135890. 10,
  135891. 3,
  135892. 11,
  135893. 2,
  135894. 12,
  135895. 1,
  135896. 13,
  135897. 0,
  135898. 14,
  135899. };
  135900. static long _vq_lengthlist__44u6__p9_1[] = {
  135901. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135902. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135903. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135904. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135905. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135906. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135907. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135908. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135909. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135910. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135911. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135912. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135913. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135914. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135915. 13,
  135916. };
  135917. static float _vq_quantthresh__44u6__p9_1[] = {
  135918. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135919. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135920. };
  135921. static long _vq_quantmap__44u6__p9_1[] = {
  135922. 13, 11, 9, 7, 5, 3, 1, 0,
  135923. 2, 4, 6, 8, 10, 12, 14,
  135924. };
  135925. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135926. _vq_quantthresh__44u6__p9_1,
  135927. _vq_quantmap__44u6__p9_1,
  135928. 15,
  135929. 15
  135930. };
  135931. static static_codebook _44u6__p9_1 = {
  135932. 2, 225,
  135933. _vq_lengthlist__44u6__p9_1,
  135934. 1, -522338304, 1620115456, 4, 0,
  135935. _vq_quantlist__44u6__p9_1,
  135936. NULL,
  135937. &_vq_auxt__44u6__p9_1,
  135938. NULL,
  135939. 0
  135940. };
  135941. static long _vq_quantlist__44u6__p9_2[] = {
  135942. 8,
  135943. 7,
  135944. 9,
  135945. 6,
  135946. 10,
  135947. 5,
  135948. 11,
  135949. 4,
  135950. 12,
  135951. 3,
  135952. 13,
  135953. 2,
  135954. 14,
  135955. 1,
  135956. 15,
  135957. 0,
  135958. 16,
  135959. };
  135960. static long _vq_lengthlist__44u6__p9_2[] = {
  135961. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135962. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135963. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135964. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135965. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135966. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135967. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135968. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135969. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135970. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135971. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135972. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135973. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135974. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135975. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135976. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135977. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135978. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135979. 10,
  135980. };
  135981. static float _vq_quantthresh__44u6__p9_2[] = {
  135982. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135983. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135984. };
  135985. static long _vq_quantmap__44u6__p9_2[] = {
  135986. 15, 13, 11, 9, 7, 5, 3, 1,
  135987. 0, 2, 4, 6, 8, 10, 12, 14,
  135988. 16,
  135989. };
  135990. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135991. _vq_quantthresh__44u6__p9_2,
  135992. _vq_quantmap__44u6__p9_2,
  135993. 17,
  135994. 17
  135995. };
  135996. static static_codebook _44u6__p9_2 = {
  135997. 2, 289,
  135998. _vq_lengthlist__44u6__p9_2,
  135999. 1, -529530880, 1611661312, 5, 0,
  136000. _vq_quantlist__44u6__p9_2,
  136001. NULL,
  136002. &_vq_auxt__44u6__p9_2,
  136003. NULL,
  136004. 0
  136005. };
  136006. static long _huff_lengthlist__44u6__short[] = {
  136007. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  136008. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  136009. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  136010. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  136011. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  136012. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  136013. 7, 6, 9,16,
  136014. };
  136015. static static_codebook _huff_book__44u6__short = {
  136016. 2, 100,
  136017. _huff_lengthlist__44u6__short,
  136018. 0, 0, 0, 0, 0,
  136019. NULL,
  136020. NULL,
  136021. NULL,
  136022. NULL,
  136023. 0
  136024. };
  136025. static long _huff_lengthlist__44u7__long[] = {
  136026. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  136027. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  136028. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  136029. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  136030. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  136031. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  136032. 12, 8, 6, 7,
  136033. };
  136034. static static_codebook _huff_book__44u7__long = {
  136035. 2, 100,
  136036. _huff_lengthlist__44u7__long,
  136037. 0, 0, 0, 0, 0,
  136038. NULL,
  136039. NULL,
  136040. NULL,
  136041. NULL,
  136042. 0
  136043. };
  136044. static long _vq_quantlist__44u7__p1_0[] = {
  136045. 1,
  136046. 0,
  136047. 2,
  136048. };
  136049. static long _vq_lengthlist__44u7__p1_0[] = {
  136050. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  136051. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  136052. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  136053. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  136054. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  136055. 12,
  136056. };
  136057. static float _vq_quantthresh__44u7__p1_0[] = {
  136058. -0.5, 0.5,
  136059. };
  136060. static long _vq_quantmap__44u7__p1_0[] = {
  136061. 1, 0, 2,
  136062. };
  136063. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  136064. _vq_quantthresh__44u7__p1_0,
  136065. _vq_quantmap__44u7__p1_0,
  136066. 3,
  136067. 3
  136068. };
  136069. static static_codebook _44u7__p1_0 = {
  136070. 4, 81,
  136071. _vq_lengthlist__44u7__p1_0,
  136072. 1, -535822336, 1611661312, 2, 0,
  136073. _vq_quantlist__44u7__p1_0,
  136074. NULL,
  136075. &_vq_auxt__44u7__p1_0,
  136076. NULL,
  136077. 0
  136078. };
  136079. static long _vq_quantlist__44u7__p2_0[] = {
  136080. 1,
  136081. 0,
  136082. 2,
  136083. };
  136084. static long _vq_lengthlist__44u7__p2_0[] = {
  136085. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  136086. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  136087. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  136088. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  136089. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  136090. 9,
  136091. };
  136092. static float _vq_quantthresh__44u7__p2_0[] = {
  136093. -0.5, 0.5,
  136094. };
  136095. static long _vq_quantmap__44u7__p2_0[] = {
  136096. 1, 0, 2,
  136097. };
  136098. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  136099. _vq_quantthresh__44u7__p2_0,
  136100. _vq_quantmap__44u7__p2_0,
  136101. 3,
  136102. 3
  136103. };
  136104. static static_codebook _44u7__p2_0 = {
  136105. 4, 81,
  136106. _vq_lengthlist__44u7__p2_0,
  136107. 1, -535822336, 1611661312, 2, 0,
  136108. _vq_quantlist__44u7__p2_0,
  136109. NULL,
  136110. &_vq_auxt__44u7__p2_0,
  136111. NULL,
  136112. 0
  136113. };
  136114. static long _vq_quantlist__44u7__p3_0[] = {
  136115. 2,
  136116. 1,
  136117. 3,
  136118. 0,
  136119. 4,
  136120. };
  136121. static long _vq_lengthlist__44u7__p3_0[] = {
  136122. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136123. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  136124. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  136125. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  136126. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  136127. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  136128. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  136129. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  136130. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  136131. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  136132. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  136133. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  136134. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  136135. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  136136. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  136137. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  136138. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  136139. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  136140. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  136141. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  136142. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  136143. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  136144. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  136145. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  136146. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  136147. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  136148. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  136149. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  136150. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  136151. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  136152. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  136153. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  136154. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  136155. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  136156. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  136157. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  136158. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  136159. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  136160. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  136161. 0,
  136162. };
  136163. static float _vq_quantthresh__44u7__p3_0[] = {
  136164. -1.5, -0.5, 0.5, 1.5,
  136165. };
  136166. static long _vq_quantmap__44u7__p3_0[] = {
  136167. 3, 1, 0, 2, 4,
  136168. };
  136169. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  136170. _vq_quantthresh__44u7__p3_0,
  136171. _vq_quantmap__44u7__p3_0,
  136172. 5,
  136173. 5
  136174. };
  136175. static static_codebook _44u7__p3_0 = {
  136176. 4, 625,
  136177. _vq_lengthlist__44u7__p3_0,
  136178. 1, -533725184, 1611661312, 3, 0,
  136179. _vq_quantlist__44u7__p3_0,
  136180. NULL,
  136181. &_vq_auxt__44u7__p3_0,
  136182. NULL,
  136183. 0
  136184. };
  136185. static long _vq_quantlist__44u7__p4_0[] = {
  136186. 2,
  136187. 1,
  136188. 3,
  136189. 0,
  136190. 4,
  136191. };
  136192. static long _vq_lengthlist__44u7__p4_0[] = {
  136193. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  136194. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  136195. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  136196. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  136197. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  136198. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  136199. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  136200. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  136201. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  136202. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  136203. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  136204. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  136205. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  136206. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  136207. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  136208. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  136209. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  136210. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  136211. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  136212. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  136213. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  136214. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  136215. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  136216. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136217. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  136218. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  136219. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  136220. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  136221. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  136222. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  136223. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  136224. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136225. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  136226. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  136227. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  136228. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  136229. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  136230. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  136231. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  136232. 14,
  136233. };
  136234. static float _vq_quantthresh__44u7__p4_0[] = {
  136235. -1.5, -0.5, 0.5, 1.5,
  136236. };
  136237. static long _vq_quantmap__44u7__p4_0[] = {
  136238. 3, 1, 0, 2, 4,
  136239. };
  136240. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  136241. _vq_quantthresh__44u7__p4_0,
  136242. _vq_quantmap__44u7__p4_0,
  136243. 5,
  136244. 5
  136245. };
  136246. static static_codebook _44u7__p4_0 = {
  136247. 4, 625,
  136248. _vq_lengthlist__44u7__p4_0,
  136249. 1, -533725184, 1611661312, 3, 0,
  136250. _vq_quantlist__44u7__p4_0,
  136251. NULL,
  136252. &_vq_auxt__44u7__p4_0,
  136253. NULL,
  136254. 0
  136255. };
  136256. static long _vq_quantlist__44u7__p5_0[] = {
  136257. 4,
  136258. 3,
  136259. 5,
  136260. 2,
  136261. 6,
  136262. 1,
  136263. 7,
  136264. 0,
  136265. 8,
  136266. };
  136267. static long _vq_lengthlist__44u7__p5_0[] = {
  136268. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136269. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  136270. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  136271. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  136272. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  136273. 14,
  136274. };
  136275. static float _vq_quantthresh__44u7__p5_0[] = {
  136276. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136277. };
  136278. static long _vq_quantmap__44u7__p5_0[] = {
  136279. 7, 5, 3, 1, 0, 2, 4, 6,
  136280. 8,
  136281. };
  136282. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  136283. _vq_quantthresh__44u7__p5_0,
  136284. _vq_quantmap__44u7__p5_0,
  136285. 9,
  136286. 9
  136287. };
  136288. static static_codebook _44u7__p5_0 = {
  136289. 2, 81,
  136290. _vq_lengthlist__44u7__p5_0,
  136291. 1, -531628032, 1611661312, 4, 0,
  136292. _vq_quantlist__44u7__p5_0,
  136293. NULL,
  136294. &_vq_auxt__44u7__p5_0,
  136295. NULL,
  136296. 0
  136297. };
  136298. static long _vq_quantlist__44u7__p6_0[] = {
  136299. 4,
  136300. 3,
  136301. 5,
  136302. 2,
  136303. 6,
  136304. 1,
  136305. 7,
  136306. 0,
  136307. 8,
  136308. };
  136309. static long _vq_lengthlist__44u7__p6_0[] = {
  136310. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136311. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136312. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136313. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136314. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136315. 12,
  136316. };
  136317. static float _vq_quantthresh__44u7__p6_0[] = {
  136318. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136319. };
  136320. static long _vq_quantmap__44u7__p6_0[] = {
  136321. 7, 5, 3, 1, 0, 2, 4, 6,
  136322. 8,
  136323. };
  136324. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136325. _vq_quantthresh__44u7__p6_0,
  136326. _vq_quantmap__44u7__p6_0,
  136327. 9,
  136328. 9
  136329. };
  136330. static static_codebook _44u7__p6_0 = {
  136331. 2, 81,
  136332. _vq_lengthlist__44u7__p6_0,
  136333. 1, -531628032, 1611661312, 4, 0,
  136334. _vq_quantlist__44u7__p6_0,
  136335. NULL,
  136336. &_vq_auxt__44u7__p6_0,
  136337. NULL,
  136338. 0
  136339. };
  136340. static long _vq_quantlist__44u7__p7_0[] = {
  136341. 1,
  136342. 0,
  136343. 2,
  136344. };
  136345. static long _vq_lengthlist__44u7__p7_0[] = {
  136346. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136347. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136348. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136349. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136350. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136351. 10,
  136352. };
  136353. static float _vq_quantthresh__44u7__p7_0[] = {
  136354. -5.5, 5.5,
  136355. };
  136356. static long _vq_quantmap__44u7__p7_0[] = {
  136357. 1, 0, 2,
  136358. };
  136359. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136360. _vq_quantthresh__44u7__p7_0,
  136361. _vq_quantmap__44u7__p7_0,
  136362. 3,
  136363. 3
  136364. };
  136365. static static_codebook _44u7__p7_0 = {
  136366. 4, 81,
  136367. _vq_lengthlist__44u7__p7_0,
  136368. 1, -529137664, 1618345984, 2, 0,
  136369. _vq_quantlist__44u7__p7_0,
  136370. NULL,
  136371. &_vq_auxt__44u7__p7_0,
  136372. NULL,
  136373. 0
  136374. };
  136375. static long _vq_quantlist__44u7__p7_1[] = {
  136376. 5,
  136377. 4,
  136378. 6,
  136379. 3,
  136380. 7,
  136381. 2,
  136382. 8,
  136383. 1,
  136384. 9,
  136385. 0,
  136386. 10,
  136387. };
  136388. static long _vq_lengthlist__44u7__p7_1[] = {
  136389. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136390. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136391. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136392. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136393. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136394. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136395. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136396. 8, 9, 9, 9, 9, 9,10,10,10,
  136397. };
  136398. static float _vq_quantthresh__44u7__p7_1[] = {
  136399. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136400. 3.5, 4.5,
  136401. };
  136402. static long _vq_quantmap__44u7__p7_1[] = {
  136403. 9, 7, 5, 3, 1, 0, 2, 4,
  136404. 6, 8, 10,
  136405. };
  136406. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136407. _vq_quantthresh__44u7__p7_1,
  136408. _vq_quantmap__44u7__p7_1,
  136409. 11,
  136410. 11
  136411. };
  136412. static static_codebook _44u7__p7_1 = {
  136413. 2, 121,
  136414. _vq_lengthlist__44u7__p7_1,
  136415. 1, -531365888, 1611661312, 4, 0,
  136416. _vq_quantlist__44u7__p7_1,
  136417. NULL,
  136418. &_vq_auxt__44u7__p7_1,
  136419. NULL,
  136420. 0
  136421. };
  136422. static long _vq_quantlist__44u7__p8_0[] = {
  136423. 5,
  136424. 4,
  136425. 6,
  136426. 3,
  136427. 7,
  136428. 2,
  136429. 8,
  136430. 1,
  136431. 9,
  136432. 0,
  136433. 10,
  136434. };
  136435. static long _vq_lengthlist__44u7__p8_0[] = {
  136436. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136437. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136438. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136439. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136440. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136441. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136442. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136443. 12,13,13,14,14,15,15,15,16,
  136444. };
  136445. static float _vq_quantthresh__44u7__p8_0[] = {
  136446. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136447. 38.5, 49.5,
  136448. };
  136449. static long _vq_quantmap__44u7__p8_0[] = {
  136450. 9, 7, 5, 3, 1, 0, 2, 4,
  136451. 6, 8, 10,
  136452. };
  136453. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136454. _vq_quantthresh__44u7__p8_0,
  136455. _vq_quantmap__44u7__p8_0,
  136456. 11,
  136457. 11
  136458. };
  136459. static static_codebook _44u7__p8_0 = {
  136460. 2, 121,
  136461. _vq_lengthlist__44u7__p8_0,
  136462. 1, -524582912, 1618345984, 4, 0,
  136463. _vq_quantlist__44u7__p8_0,
  136464. NULL,
  136465. &_vq_auxt__44u7__p8_0,
  136466. NULL,
  136467. 0
  136468. };
  136469. static long _vq_quantlist__44u7__p8_1[] = {
  136470. 5,
  136471. 4,
  136472. 6,
  136473. 3,
  136474. 7,
  136475. 2,
  136476. 8,
  136477. 1,
  136478. 9,
  136479. 0,
  136480. 10,
  136481. };
  136482. static long _vq_lengthlist__44u7__p8_1[] = {
  136483. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136484. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136485. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136486. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136487. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136488. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136489. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136490. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136491. };
  136492. static float _vq_quantthresh__44u7__p8_1[] = {
  136493. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136494. 3.5, 4.5,
  136495. };
  136496. static long _vq_quantmap__44u7__p8_1[] = {
  136497. 9, 7, 5, 3, 1, 0, 2, 4,
  136498. 6, 8, 10,
  136499. };
  136500. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136501. _vq_quantthresh__44u7__p8_1,
  136502. _vq_quantmap__44u7__p8_1,
  136503. 11,
  136504. 11
  136505. };
  136506. static static_codebook _44u7__p8_1 = {
  136507. 2, 121,
  136508. _vq_lengthlist__44u7__p8_1,
  136509. 1, -531365888, 1611661312, 4, 0,
  136510. _vq_quantlist__44u7__p8_1,
  136511. NULL,
  136512. &_vq_auxt__44u7__p8_1,
  136513. NULL,
  136514. 0
  136515. };
  136516. static long _vq_quantlist__44u7__p9_0[] = {
  136517. 5,
  136518. 4,
  136519. 6,
  136520. 3,
  136521. 7,
  136522. 2,
  136523. 8,
  136524. 1,
  136525. 9,
  136526. 0,
  136527. 10,
  136528. };
  136529. static long _vq_lengthlist__44u7__p9_0[] = {
  136530. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136531. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136532. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136533. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136534. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136535. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136536. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136537. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136538. };
  136539. static float _vq_quantthresh__44u7__p9_0[] = {
  136540. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136541. 2229.5, 2866.5,
  136542. };
  136543. static long _vq_quantmap__44u7__p9_0[] = {
  136544. 9, 7, 5, 3, 1, 0, 2, 4,
  136545. 6, 8, 10,
  136546. };
  136547. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136548. _vq_quantthresh__44u7__p9_0,
  136549. _vq_quantmap__44u7__p9_0,
  136550. 11,
  136551. 11
  136552. };
  136553. static static_codebook _44u7__p9_0 = {
  136554. 2, 121,
  136555. _vq_lengthlist__44u7__p9_0,
  136556. 1, -512171520, 1630791680, 4, 0,
  136557. _vq_quantlist__44u7__p9_0,
  136558. NULL,
  136559. &_vq_auxt__44u7__p9_0,
  136560. NULL,
  136561. 0
  136562. };
  136563. static long _vq_quantlist__44u7__p9_1[] = {
  136564. 6,
  136565. 5,
  136566. 7,
  136567. 4,
  136568. 8,
  136569. 3,
  136570. 9,
  136571. 2,
  136572. 10,
  136573. 1,
  136574. 11,
  136575. 0,
  136576. 12,
  136577. };
  136578. static long _vq_lengthlist__44u7__p9_1[] = {
  136579. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136580. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136581. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136582. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136583. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136584. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136585. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136586. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136587. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136588. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136589. 15,15,15,15,17,17,16,17,16,
  136590. };
  136591. static float _vq_quantthresh__44u7__p9_1[] = {
  136592. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136593. 122.5, 171.5, 220.5, 269.5,
  136594. };
  136595. static long _vq_quantmap__44u7__p9_1[] = {
  136596. 11, 9, 7, 5, 3, 1, 0, 2,
  136597. 4, 6, 8, 10, 12,
  136598. };
  136599. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136600. _vq_quantthresh__44u7__p9_1,
  136601. _vq_quantmap__44u7__p9_1,
  136602. 13,
  136603. 13
  136604. };
  136605. static static_codebook _44u7__p9_1 = {
  136606. 2, 169,
  136607. _vq_lengthlist__44u7__p9_1,
  136608. 1, -518889472, 1622704128, 4, 0,
  136609. _vq_quantlist__44u7__p9_1,
  136610. NULL,
  136611. &_vq_auxt__44u7__p9_1,
  136612. NULL,
  136613. 0
  136614. };
  136615. static long _vq_quantlist__44u7__p9_2[] = {
  136616. 24,
  136617. 23,
  136618. 25,
  136619. 22,
  136620. 26,
  136621. 21,
  136622. 27,
  136623. 20,
  136624. 28,
  136625. 19,
  136626. 29,
  136627. 18,
  136628. 30,
  136629. 17,
  136630. 31,
  136631. 16,
  136632. 32,
  136633. 15,
  136634. 33,
  136635. 14,
  136636. 34,
  136637. 13,
  136638. 35,
  136639. 12,
  136640. 36,
  136641. 11,
  136642. 37,
  136643. 10,
  136644. 38,
  136645. 9,
  136646. 39,
  136647. 8,
  136648. 40,
  136649. 7,
  136650. 41,
  136651. 6,
  136652. 42,
  136653. 5,
  136654. 43,
  136655. 4,
  136656. 44,
  136657. 3,
  136658. 45,
  136659. 2,
  136660. 46,
  136661. 1,
  136662. 47,
  136663. 0,
  136664. 48,
  136665. };
  136666. static long _vq_lengthlist__44u7__p9_2[] = {
  136667. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136668. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136669. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136670. 8,
  136671. };
  136672. static float _vq_quantthresh__44u7__p9_2[] = {
  136673. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136674. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136675. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136676. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136677. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136678. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136679. };
  136680. static long _vq_quantmap__44u7__p9_2[] = {
  136681. 47, 45, 43, 41, 39, 37, 35, 33,
  136682. 31, 29, 27, 25, 23, 21, 19, 17,
  136683. 15, 13, 11, 9, 7, 5, 3, 1,
  136684. 0, 2, 4, 6, 8, 10, 12, 14,
  136685. 16, 18, 20, 22, 24, 26, 28, 30,
  136686. 32, 34, 36, 38, 40, 42, 44, 46,
  136687. 48,
  136688. };
  136689. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136690. _vq_quantthresh__44u7__p9_2,
  136691. _vq_quantmap__44u7__p9_2,
  136692. 49,
  136693. 49
  136694. };
  136695. static static_codebook _44u7__p9_2 = {
  136696. 1, 49,
  136697. _vq_lengthlist__44u7__p9_2,
  136698. 1, -526909440, 1611661312, 6, 0,
  136699. _vq_quantlist__44u7__p9_2,
  136700. NULL,
  136701. &_vq_auxt__44u7__p9_2,
  136702. NULL,
  136703. 0
  136704. };
  136705. static long _huff_lengthlist__44u7__short[] = {
  136706. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136707. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136708. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136709. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136710. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136711. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136712. 6, 8, 5, 9,
  136713. };
  136714. static static_codebook _huff_book__44u7__short = {
  136715. 2, 100,
  136716. _huff_lengthlist__44u7__short,
  136717. 0, 0, 0, 0, 0,
  136718. NULL,
  136719. NULL,
  136720. NULL,
  136721. NULL,
  136722. 0
  136723. };
  136724. static long _huff_lengthlist__44u8__long[] = {
  136725. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136726. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136727. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136728. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136729. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136730. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136731. 10, 8, 8, 9,
  136732. };
  136733. static static_codebook _huff_book__44u8__long = {
  136734. 2, 100,
  136735. _huff_lengthlist__44u8__long,
  136736. 0, 0, 0, 0, 0,
  136737. NULL,
  136738. NULL,
  136739. NULL,
  136740. NULL,
  136741. 0
  136742. };
  136743. static long _huff_lengthlist__44u8__short[] = {
  136744. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136745. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136746. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136747. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136748. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136749. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136750. 10,10,15,17,
  136751. };
  136752. static static_codebook _huff_book__44u8__short = {
  136753. 2, 100,
  136754. _huff_lengthlist__44u8__short,
  136755. 0, 0, 0, 0, 0,
  136756. NULL,
  136757. NULL,
  136758. NULL,
  136759. NULL,
  136760. 0
  136761. };
  136762. static long _vq_quantlist__44u8_p1_0[] = {
  136763. 1,
  136764. 0,
  136765. 2,
  136766. };
  136767. static long _vq_lengthlist__44u8_p1_0[] = {
  136768. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136769. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136770. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136771. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136772. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136773. 10,
  136774. };
  136775. static float _vq_quantthresh__44u8_p1_0[] = {
  136776. -0.5, 0.5,
  136777. };
  136778. static long _vq_quantmap__44u8_p1_0[] = {
  136779. 1, 0, 2,
  136780. };
  136781. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136782. _vq_quantthresh__44u8_p1_0,
  136783. _vq_quantmap__44u8_p1_0,
  136784. 3,
  136785. 3
  136786. };
  136787. static static_codebook _44u8_p1_0 = {
  136788. 4, 81,
  136789. _vq_lengthlist__44u8_p1_0,
  136790. 1, -535822336, 1611661312, 2, 0,
  136791. _vq_quantlist__44u8_p1_0,
  136792. NULL,
  136793. &_vq_auxt__44u8_p1_0,
  136794. NULL,
  136795. 0
  136796. };
  136797. static long _vq_quantlist__44u8_p2_0[] = {
  136798. 2,
  136799. 1,
  136800. 3,
  136801. 0,
  136802. 4,
  136803. };
  136804. static long _vq_lengthlist__44u8_p2_0[] = {
  136805. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136806. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136807. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136808. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136809. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136810. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136811. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136812. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136813. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136814. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136815. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136816. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136817. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136818. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136819. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136820. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136821. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136822. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136823. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136824. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136825. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136826. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136827. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136828. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136829. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136830. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136831. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136832. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136833. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136834. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136835. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136836. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136837. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136838. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136839. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136840. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136841. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136842. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136843. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136844. 14,
  136845. };
  136846. static float _vq_quantthresh__44u8_p2_0[] = {
  136847. -1.5, -0.5, 0.5, 1.5,
  136848. };
  136849. static long _vq_quantmap__44u8_p2_0[] = {
  136850. 3, 1, 0, 2, 4,
  136851. };
  136852. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136853. _vq_quantthresh__44u8_p2_0,
  136854. _vq_quantmap__44u8_p2_0,
  136855. 5,
  136856. 5
  136857. };
  136858. static static_codebook _44u8_p2_0 = {
  136859. 4, 625,
  136860. _vq_lengthlist__44u8_p2_0,
  136861. 1, -533725184, 1611661312, 3, 0,
  136862. _vq_quantlist__44u8_p2_0,
  136863. NULL,
  136864. &_vq_auxt__44u8_p2_0,
  136865. NULL,
  136866. 0
  136867. };
  136868. static long _vq_quantlist__44u8_p3_0[] = {
  136869. 4,
  136870. 3,
  136871. 5,
  136872. 2,
  136873. 6,
  136874. 1,
  136875. 7,
  136876. 0,
  136877. 8,
  136878. };
  136879. static long _vq_lengthlist__44u8_p3_0[] = {
  136880. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136881. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136882. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136883. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136884. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136885. 12,
  136886. };
  136887. static float _vq_quantthresh__44u8_p3_0[] = {
  136888. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136889. };
  136890. static long _vq_quantmap__44u8_p3_0[] = {
  136891. 7, 5, 3, 1, 0, 2, 4, 6,
  136892. 8,
  136893. };
  136894. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136895. _vq_quantthresh__44u8_p3_0,
  136896. _vq_quantmap__44u8_p3_0,
  136897. 9,
  136898. 9
  136899. };
  136900. static static_codebook _44u8_p3_0 = {
  136901. 2, 81,
  136902. _vq_lengthlist__44u8_p3_0,
  136903. 1, -531628032, 1611661312, 4, 0,
  136904. _vq_quantlist__44u8_p3_0,
  136905. NULL,
  136906. &_vq_auxt__44u8_p3_0,
  136907. NULL,
  136908. 0
  136909. };
  136910. static long _vq_quantlist__44u8_p4_0[] = {
  136911. 8,
  136912. 7,
  136913. 9,
  136914. 6,
  136915. 10,
  136916. 5,
  136917. 11,
  136918. 4,
  136919. 12,
  136920. 3,
  136921. 13,
  136922. 2,
  136923. 14,
  136924. 1,
  136925. 15,
  136926. 0,
  136927. 16,
  136928. };
  136929. static long _vq_lengthlist__44u8_p4_0[] = {
  136930. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136931. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136932. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136933. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136934. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136935. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136936. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136937. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136938. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136939. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136940. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136941. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136942. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136943. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136944. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136945. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136946. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136947. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136948. 14,
  136949. };
  136950. static float _vq_quantthresh__44u8_p4_0[] = {
  136951. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136952. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136953. };
  136954. static long _vq_quantmap__44u8_p4_0[] = {
  136955. 15, 13, 11, 9, 7, 5, 3, 1,
  136956. 0, 2, 4, 6, 8, 10, 12, 14,
  136957. 16,
  136958. };
  136959. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136960. _vq_quantthresh__44u8_p4_0,
  136961. _vq_quantmap__44u8_p4_0,
  136962. 17,
  136963. 17
  136964. };
  136965. static static_codebook _44u8_p4_0 = {
  136966. 2, 289,
  136967. _vq_lengthlist__44u8_p4_0,
  136968. 1, -529530880, 1611661312, 5, 0,
  136969. _vq_quantlist__44u8_p4_0,
  136970. NULL,
  136971. &_vq_auxt__44u8_p4_0,
  136972. NULL,
  136973. 0
  136974. };
  136975. static long _vq_quantlist__44u8_p5_0[] = {
  136976. 1,
  136977. 0,
  136978. 2,
  136979. };
  136980. static long _vq_lengthlist__44u8_p5_0[] = {
  136981. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136982. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136983. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136984. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136985. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136986. 10,
  136987. };
  136988. static float _vq_quantthresh__44u8_p5_0[] = {
  136989. -5.5, 5.5,
  136990. };
  136991. static long _vq_quantmap__44u8_p5_0[] = {
  136992. 1, 0, 2,
  136993. };
  136994. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136995. _vq_quantthresh__44u8_p5_0,
  136996. _vq_quantmap__44u8_p5_0,
  136997. 3,
  136998. 3
  136999. };
  137000. static static_codebook _44u8_p5_0 = {
  137001. 4, 81,
  137002. _vq_lengthlist__44u8_p5_0,
  137003. 1, -529137664, 1618345984, 2, 0,
  137004. _vq_quantlist__44u8_p5_0,
  137005. NULL,
  137006. &_vq_auxt__44u8_p5_0,
  137007. NULL,
  137008. 0
  137009. };
  137010. static long _vq_quantlist__44u8_p5_1[] = {
  137011. 5,
  137012. 4,
  137013. 6,
  137014. 3,
  137015. 7,
  137016. 2,
  137017. 8,
  137018. 1,
  137019. 9,
  137020. 0,
  137021. 10,
  137022. };
  137023. static long _vq_lengthlist__44u8_p5_1[] = {
  137024. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  137025. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  137026. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  137027. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137028. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  137029. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  137030. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  137031. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  137032. };
  137033. static float _vq_quantthresh__44u8_p5_1[] = {
  137034. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137035. 3.5, 4.5,
  137036. };
  137037. static long _vq_quantmap__44u8_p5_1[] = {
  137038. 9, 7, 5, 3, 1, 0, 2, 4,
  137039. 6, 8, 10,
  137040. };
  137041. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  137042. _vq_quantthresh__44u8_p5_1,
  137043. _vq_quantmap__44u8_p5_1,
  137044. 11,
  137045. 11
  137046. };
  137047. static static_codebook _44u8_p5_1 = {
  137048. 2, 121,
  137049. _vq_lengthlist__44u8_p5_1,
  137050. 1, -531365888, 1611661312, 4, 0,
  137051. _vq_quantlist__44u8_p5_1,
  137052. NULL,
  137053. &_vq_auxt__44u8_p5_1,
  137054. NULL,
  137055. 0
  137056. };
  137057. static long _vq_quantlist__44u8_p6_0[] = {
  137058. 6,
  137059. 5,
  137060. 7,
  137061. 4,
  137062. 8,
  137063. 3,
  137064. 9,
  137065. 2,
  137066. 10,
  137067. 1,
  137068. 11,
  137069. 0,
  137070. 12,
  137071. };
  137072. static long _vq_lengthlist__44u8_p6_0[] = {
  137073. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137074. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  137075. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  137076. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  137077. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  137078. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137079. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137080. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  137081. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  137082. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137083. 11,11,11,11,11,12,11,12,12,
  137084. };
  137085. static float _vq_quantthresh__44u8_p6_0[] = {
  137086. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137087. 12.5, 17.5, 22.5, 27.5,
  137088. };
  137089. static long _vq_quantmap__44u8_p6_0[] = {
  137090. 11, 9, 7, 5, 3, 1, 0, 2,
  137091. 4, 6, 8, 10, 12,
  137092. };
  137093. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  137094. _vq_quantthresh__44u8_p6_0,
  137095. _vq_quantmap__44u8_p6_0,
  137096. 13,
  137097. 13
  137098. };
  137099. static static_codebook _44u8_p6_0 = {
  137100. 2, 169,
  137101. _vq_lengthlist__44u8_p6_0,
  137102. 1, -526516224, 1616117760, 4, 0,
  137103. _vq_quantlist__44u8_p6_0,
  137104. NULL,
  137105. &_vq_auxt__44u8_p6_0,
  137106. NULL,
  137107. 0
  137108. };
  137109. static long _vq_quantlist__44u8_p6_1[] = {
  137110. 2,
  137111. 1,
  137112. 3,
  137113. 0,
  137114. 4,
  137115. };
  137116. static long _vq_lengthlist__44u8_p6_1[] = {
  137117. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  137118. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137119. };
  137120. static float _vq_quantthresh__44u8_p6_1[] = {
  137121. -1.5, -0.5, 0.5, 1.5,
  137122. };
  137123. static long _vq_quantmap__44u8_p6_1[] = {
  137124. 3, 1, 0, 2, 4,
  137125. };
  137126. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  137127. _vq_quantthresh__44u8_p6_1,
  137128. _vq_quantmap__44u8_p6_1,
  137129. 5,
  137130. 5
  137131. };
  137132. static static_codebook _44u8_p6_1 = {
  137133. 2, 25,
  137134. _vq_lengthlist__44u8_p6_1,
  137135. 1, -533725184, 1611661312, 3, 0,
  137136. _vq_quantlist__44u8_p6_1,
  137137. NULL,
  137138. &_vq_auxt__44u8_p6_1,
  137139. NULL,
  137140. 0
  137141. };
  137142. static long _vq_quantlist__44u8_p7_0[] = {
  137143. 6,
  137144. 5,
  137145. 7,
  137146. 4,
  137147. 8,
  137148. 3,
  137149. 9,
  137150. 2,
  137151. 10,
  137152. 1,
  137153. 11,
  137154. 0,
  137155. 12,
  137156. };
  137157. static long _vq_lengthlist__44u8_p7_0[] = {
  137158. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  137159. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  137160. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  137161. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  137162. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137163. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137164. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  137165. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  137166. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  137167. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  137168. 13,13,14,14,14,15,15,15,16,
  137169. };
  137170. static float _vq_quantthresh__44u8_p7_0[] = {
  137171. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137172. 27.5, 38.5, 49.5, 60.5,
  137173. };
  137174. static long _vq_quantmap__44u8_p7_0[] = {
  137175. 11, 9, 7, 5, 3, 1, 0, 2,
  137176. 4, 6, 8, 10, 12,
  137177. };
  137178. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  137179. _vq_quantthresh__44u8_p7_0,
  137180. _vq_quantmap__44u8_p7_0,
  137181. 13,
  137182. 13
  137183. };
  137184. static static_codebook _44u8_p7_0 = {
  137185. 2, 169,
  137186. _vq_lengthlist__44u8_p7_0,
  137187. 1, -523206656, 1618345984, 4, 0,
  137188. _vq_quantlist__44u8_p7_0,
  137189. NULL,
  137190. &_vq_auxt__44u8_p7_0,
  137191. NULL,
  137192. 0
  137193. };
  137194. static long _vq_quantlist__44u8_p7_1[] = {
  137195. 5,
  137196. 4,
  137197. 6,
  137198. 3,
  137199. 7,
  137200. 2,
  137201. 8,
  137202. 1,
  137203. 9,
  137204. 0,
  137205. 10,
  137206. };
  137207. static long _vq_lengthlist__44u8_p7_1[] = {
  137208. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  137209. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137210. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  137211. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  137212. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  137213. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  137214. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  137215. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  137216. };
  137217. static float _vq_quantthresh__44u8_p7_1[] = {
  137218. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137219. 3.5, 4.5,
  137220. };
  137221. static long _vq_quantmap__44u8_p7_1[] = {
  137222. 9, 7, 5, 3, 1, 0, 2, 4,
  137223. 6, 8, 10,
  137224. };
  137225. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  137226. _vq_quantthresh__44u8_p7_1,
  137227. _vq_quantmap__44u8_p7_1,
  137228. 11,
  137229. 11
  137230. };
  137231. static static_codebook _44u8_p7_1 = {
  137232. 2, 121,
  137233. _vq_lengthlist__44u8_p7_1,
  137234. 1, -531365888, 1611661312, 4, 0,
  137235. _vq_quantlist__44u8_p7_1,
  137236. NULL,
  137237. &_vq_auxt__44u8_p7_1,
  137238. NULL,
  137239. 0
  137240. };
  137241. static long _vq_quantlist__44u8_p8_0[] = {
  137242. 7,
  137243. 6,
  137244. 8,
  137245. 5,
  137246. 9,
  137247. 4,
  137248. 10,
  137249. 3,
  137250. 11,
  137251. 2,
  137252. 12,
  137253. 1,
  137254. 13,
  137255. 0,
  137256. 14,
  137257. };
  137258. static long _vq_lengthlist__44u8_p8_0[] = {
  137259. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  137260. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137261. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  137262. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  137263. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  137264. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  137265. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  137266. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  137267. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  137268. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  137269. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  137270. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  137271. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  137272. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  137273. 17,
  137274. };
  137275. static float _vq_quantthresh__44u8_p8_0[] = {
  137276. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137277. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137278. };
  137279. static long _vq_quantmap__44u8_p8_0[] = {
  137280. 13, 11, 9, 7, 5, 3, 1, 0,
  137281. 2, 4, 6, 8, 10, 12, 14,
  137282. };
  137283. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  137284. _vq_quantthresh__44u8_p8_0,
  137285. _vq_quantmap__44u8_p8_0,
  137286. 15,
  137287. 15
  137288. };
  137289. static static_codebook _44u8_p8_0 = {
  137290. 2, 225,
  137291. _vq_lengthlist__44u8_p8_0,
  137292. 1, -520986624, 1620377600, 4, 0,
  137293. _vq_quantlist__44u8_p8_0,
  137294. NULL,
  137295. &_vq_auxt__44u8_p8_0,
  137296. NULL,
  137297. 0
  137298. };
  137299. static long _vq_quantlist__44u8_p8_1[] = {
  137300. 10,
  137301. 9,
  137302. 11,
  137303. 8,
  137304. 12,
  137305. 7,
  137306. 13,
  137307. 6,
  137308. 14,
  137309. 5,
  137310. 15,
  137311. 4,
  137312. 16,
  137313. 3,
  137314. 17,
  137315. 2,
  137316. 18,
  137317. 1,
  137318. 19,
  137319. 0,
  137320. 20,
  137321. };
  137322. static long _vq_lengthlist__44u8_p8_1[] = {
  137323. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137324. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137325. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137326. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137327. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137328. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137329. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137330. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137331. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137332. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137333. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137334. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137335. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137336. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137337. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137338. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137339. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137340. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137341. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137342. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137343. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137344. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137345. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137346. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137347. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137348. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137349. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137350. 10,10,10,10,10,10,10,10,10,
  137351. };
  137352. static float _vq_quantthresh__44u8_p8_1[] = {
  137353. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137354. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137355. 6.5, 7.5, 8.5, 9.5,
  137356. };
  137357. static long _vq_quantmap__44u8_p8_1[] = {
  137358. 19, 17, 15, 13, 11, 9, 7, 5,
  137359. 3, 1, 0, 2, 4, 6, 8, 10,
  137360. 12, 14, 16, 18, 20,
  137361. };
  137362. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137363. _vq_quantthresh__44u8_p8_1,
  137364. _vq_quantmap__44u8_p8_1,
  137365. 21,
  137366. 21
  137367. };
  137368. static static_codebook _44u8_p8_1 = {
  137369. 2, 441,
  137370. _vq_lengthlist__44u8_p8_1,
  137371. 1, -529268736, 1611661312, 5, 0,
  137372. _vq_quantlist__44u8_p8_1,
  137373. NULL,
  137374. &_vq_auxt__44u8_p8_1,
  137375. NULL,
  137376. 0
  137377. };
  137378. static long _vq_quantlist__44u8_p9_0[] = {
  137379. 4,
  137380. 3,
  137381. 5,
  137382. 2,
  137383. 6,
  137384. 1,
  137385. 7,
  137386. 0,
  137387. 8,
  137388. };
  137389. static long _vq_lengthlist__44u8_p9_0[] = {
  137390. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137391. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137392. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137393. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137394. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137395. 8,
  137396. };
  137397. static float _vq_quantthresh__44u8_p9_0[] = {
  137398. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137399. };
  137400. static long _vq_quantmap__44u8_p9_0[] = {
  137401. 7, 5, 3, 1, 0, 2, 4, 6,
  137402. 8,
  137403. };
  137404. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137405. _vq_quantthresh__44u8_p9_0,
  137406. _vq_quantmap__44u8_p9_0,
  137407. 9,
  137408. 9
  137409. };
  137410. static static_codebook _44u8_p9_0 = {
  137411. 2, 81,
  137412. _vq_lengthlist__44u8_p9_0,
  137413. 1, -511895552, 1631393792, 4, 0,
  137414. _vq_quantlist__44u8_p9_0,
  137415. NULL,
  137416. &_vq_auxt__44u8_p9_0,
  137417. NULL,
  137418. 0
  137419. };
  137420. static long _vq_quantlist__44u8_p9_1[] = {
  137421. 9,
  137422. 8,
  137423. 10,
  137424. 7,
  137425. 11,
  137426. 6,
  137427. 12,
  137428. 5,
  137429. 13,
  137430. 4,
  137431. 14,
  137432. 3,
  137433. 15,
  137434. 2,
  137435. 16,
  137436. 1,
  137437. 17,
  137438. 0,
  137439. 18,
  137440. };
  137441. static long _vq_lengthlist__44u8_p9_1[] = {
  137442. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137443. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137444. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137445. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137446. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137447. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137448. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137449. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137450. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137451. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137452. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137453. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137454. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137455. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137456. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137457. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137458. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137459. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137460. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137461. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137462. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137463. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137464. 16,15,16,16,16,16,16,16,16,
  137465. };
  137466. static float _vq_quantthresh__44u8_p9_1[] = {
  137467. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137468. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137469. 367.5, 416.5,
  137470. };
  137471. static long _vq_quantmap__44u8_p9_1[] = {
  137472. 17, 15, 13, 11, 9, 7, 5, 3,
  137473. 1, 0, 2, 4, 6, 8, 10, 12,
  137474. 14, 16, 18,
  137475. };
  137476. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137477. _vq_quantthresh__44u8_p9_1,
  137478. _vq_quantmap__44u8_p9_1,
  137479. 19,
  137480. 19
  137481. };
  137482. static static_codebook _44u8_p9_1 = {
  137483. 2, 361,
  137484. _vq_lengthlist__44u8_p9_1,
  137485. 1, -518287360, 1622704128, 5, 0,
  137486. _vq_quantlist__44u8_p9_1,
  137487. NULL,
  137488. &_vq_auxt__44u8_p9_1,
  137489. NULL,
  137490. 0
  137491. };
  137492. static long _vq_quantlist__44u8_p9_2[] = {
  137493. 24,
  137494. 23,
  137495. 25,
  137496. 22,
  137497. 26,
  137498. 21,
  137499. 27,
  137500. 20,
  137501. 28,
  137502. 19,
  137503. 29,
  137504. 18,
  137505. 30,
  137506. 17,
  137507. 31,
  137508. 16,
  137509. 32,
  137510. 15,
  137511. 33,
  137512. 14,
  137513. 34,
  137514. 13,
  137515. 35,
  137516. 12,
  137517. 36,
  137518. 11,
  137519. 37,
  137520. 10,
  137521. 38,
  137522. 9,
  137523. 39,
  137524. 8,
  137525. 40,
  137526. 7,
  137527. 41,
  137528. 6,
  137529. 42,
  137530. 5,
  137531. 43,
  137532. 4,
  137533. 44,
  137534. 3,
  137535. 45,
  137536. 2,
  137537. 46,
  137538. 1,
  137539. 47,
  137540. 0,
  137541. 48,
  137542. };
  137543. static long _vq_lengthlist__44u8_p9_2[] = {
  137544. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137545. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137546. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137547. 7,
  137548. };
  137549. static float _vq_quantthresh__44u8_p9_2[] = {
  137550. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137551. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137552. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137553. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137554. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137555. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137556. };
  137557. static long _vq_quantmap__44u8_p9_2[] = {
  137558. 47, 45, 43, 41, 39, 37, 35, 33,
  137559. 31, 29, 27, 25, 23, 21, 19, 17,
  137560. 15, 13, 11, 9, 7, 5, 3, 1,
  137561. 0, 2, 4, 6, 8, 10, 12, 14,
  137562. 16, 18, 20, 22, 24, 26, 28, 30,
  137563. 32, 34, 36, 38, 40, 42, 44, 46,
  137564. 48,
  137565. };
  137566. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137567. _vq_quantthresh__44u8_p9_2,
  137568. _vq_quantmap__44u8_p9_2,
  137569. 49,
  137570. 49
  137571. };
  137572. static static_codebook _44u8_p9_2 = {
  137573. 1, 49,
  137574. _vq_lengthlist__44u8_p9_2,
  137575. 1, -526909440, 1611661312, 6, 0,
  137576. _vq_quantlist__44u8_p9_2,
  137577. NULL,
  137578. &_vq_auxt__44u8_p9_2,
  137579. NULL,
  137580. 0
  137581. };
  137582. static long _huff_lengthlist__44u9__long[] = {
  137583. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137584. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137585. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137586. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137587. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137588. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137589. 10, 8, 8, 9,
  137590. };
  137591. static static_codebook _huff_book__44u9__long = {
  137592. 2, 100,
  137593. _huff_lengthlist__44u9__long,
  137594. 0, 0, 0, 0, 0,
  137595. NULL,
  137596. NULL,
  137597. NULL,
  137598. NULL,
  137599. 0
  137600. };
  137601. static long _huff_lengthlist__44u9__short[] = {
  137602. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137603. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137604. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137605. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137606. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137607. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137608. 9, 9,12,15,
  137609. };
  137610. static static_codebook _huff_book__44u9__short = {
  137611. 2, 100,
  137612. _huff_lengthlist__44u9__short,
  137613. 0, 0, 0, 0, 0,
  137614. NULL,
  137615. NULL,
  137616. NULL,
  137617. NULL,
  137618. 0
  137619. };
  137620. static long _vq_quantlist__44u9_p1_0[] = {
  137621. 1,
  137622. 0,
  137623. 2,
  137624. };
  137625. static long _vq_lengthlist__44u9_p1_0[] = {
  137626. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137627. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137628. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137629. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137630. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137631. 10,
  137632. };
  137633. static float _vq_quantthresh__44u9_p1_0[] = {
  137634. -0.5, 0.5,
  137635. };
  137636. static long _vq_quantmap__44u9_p1_0[] = {
  137637. 1, 0, 2,
  137638. };
  137639. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137640. _vq_quantthresh__44u9_p1_0,
  137641. _vq_quantmap__44u9_p1_0,
  137642. 3,
  137643. 3
  137644. };
  137645. static static_codebook _44u9_p1_0 = {
  137646. 4, 81,
  137647. _vq_lengthlist__44u9_p1_0,
  137648. 1, -535822336, 1611661312, 2, 0,
  137649. _vq_quantlist__44u9_p1_0,
  137650. NULL,
  137651. &_vq_auxt__44u9_p1_0,
  137652. NULL,
  137653. 0
  137654. };
  137655. static long _vq_quantlist__44u9_p2_0[] = {
  137656. 2,
  137657. 1,
  137658. 3,
  137659. 0,
  137660. 4,
  137661. };
  137662. static long _vq_lengthlist__44u9_p2_0[] = {
  137663. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137664. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137665. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137666. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137667. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137668. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137669. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137670. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137671. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137672. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137673. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137674. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137675. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137676. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137677. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137678. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137679. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137680. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137681. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137682. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137683. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137684. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137685. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137686. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137687. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137688. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137689. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137690. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137691. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137692. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137693. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137694. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137695. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137696. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137697. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137698. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137699. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137700. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137701. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137702. 14,
  137703. };
  137704. static float _vq_quantthresh__44u9_p2_0[] = {
  137705. -1.5, -0.5, 0.5, 1.5,
  137706. };
  137707. static long _vq_quantmap__44u9_p2_0[] = {
  137708. 3, 1, 0, 2, 4,
  137709. };
  137710. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137711. _vq_quantthresh__44u9_p2_0,
  137712. _vq_quantmap__44u9_p2_0,
  137713. 5,
  137714. 5
  137715. };
  137716. static static_codebook _44u9_p2_0 = {
  137717. 4, 625,
  137718. _vq_lengthlist__44u9_p2_0,
  137719. 1, -533725184, 1611661312, 3, 0,
  137720. _vq_quantlist__44u9_p2_0,
  137721. NULL,
  137722. &_vq_auxt__44u9_p2_0,
  137723. NULL,
  137724. 0
  137725. };
  137726. static long _vq_quantlist__44u9_p3_0[] = {
  137727. 4,
  137728. 3,
  137729. 5,
  137730. 2,
  137731. 6,
  137732. 1,
  137733. 7,
  137734. 0,
  137735. 8,
  137736. };
  137737. static long _vq_lengthlist__44u9_p3_0[] = {
  137738. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137739. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137740. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137741. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137742. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137743. 11,
  137744. };
  137745. static float _vq_quantthresh__44u9_p3_0[] = {
  137746. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137747. };
  137748. static long _vq_quantmap__44u9_p3_0[] = {
  137749. 7, 5, 3, 1, 0, 2, 4, 6,
  137750. 8,
  137751. };
  137752. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137753. _vq_quantthresh__44u9_p3_0,
  137754. _vq_quantmap__44u9_p3_0,
  137755. 9,
  137756. 9
  137757. };
  137758. static static_codebook _44u9_p3_0 = {
  137759. 2, 81,
  137760. _vq_lengthlist__44u9_p3_0,
  137761. 1, -531628032, 1611661312, 4, 0,
  137762. _vq_quantlist__44u9_p3_0,
  137763. NULL,
  137764. &_vq_auxt__44u9_p3_0,
  137765. NULL,
  137766. 0
  137767. };
  137768. static long _vq_quantlist__44u9_p4_0[] = {
  137769. 8,
  137770. 7,
  137771. 9,
  137772. 6,
  137773. 10,
  137774. 5,
  137775. 11,
  137776. 4,
  137777. 12,
  137778. 3,
  137779. 13,
  137780. 2,
  137781. 14,
  137782. 1,
  137783. 15,
  137784. 0,
  137785. 16,
  137786. };
  137787. static long _vq_lengthlist__44u9_p4_0[] = {
  137788. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137789. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137790. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137791. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137792. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137793. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137794. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137795. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137796. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137797. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137798. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137799. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137800. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137801. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137802. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137803. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137804. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137805. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137806. 14,
  137807. };
  137808. static float _vq_quantthresh__44u9_p4_0[] = {
  137809. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137810. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137811. };
  137812. static long _vq_quantmap__44u9_p4_0[] = {
  137813. 15, 13, 11, 9, 7, 5, 3, 1,
  137814. 0, 2, 4, 6, 8, 10, 12, 14,
  137815. 16,
  137816. };
  137817. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137818. _vq_quantthresh__44u9_p4_0,
  137819. _vq_quantmap__44u9_p4_0,
  137820. 17,
  137821. 17
  137822. };
  137823. static static_codebook _44u9_p4_0 = {
  137824. 2, 289,
  137825. _vq_lengthlist__44u9_p4_0,
  137826. 1, -529530880, 1611661312, 5, 0,
  137827. _vq_quantlist__44u9_p4_0,
  137828. NULL,
  137829. &_vq_auxt__44u9_p4_0,
  137830. NULL,
  137831. 0
  137832. };
  137833. static long _vq_quantlist__44u9_p5_0[] = {
  137834. 1,
  137835. 0,
  137836. 2,
  137837. };
  137838. static long _vq_lengthlist__44u9_p5_0[] = {
  137839. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137840. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137841. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137842. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137843. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137844. 10,
  137845. };
  137846. static float _vq_quantthresh__44u9_p5_0[] = {
  137847. -5.5, 5.5,
  137848. };
  137849. static long _vq_quantmap__44u9_p5_0[] = {
  137850. 1, 0, 2,
  137851. };
  137852. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137853. _vq_quantthresh__44u9_p5_0,
  137854. _vq_quantmap__44u9_p5_0,
  137855. 3,
  137856. 3
  137857. };
  137858. static static_codebook _44u9_p5_0 = {
  137859. 4, 81,
  137860. _vq_lengthlist__44u9_p5_0,
  137861. 1, -529137664, 1618345984, 2, 0,
  137862. _vq_quantlist__44u9_p5_0,
  137863. NULL,
  137864. &_vq_auxt__44u9_p5_0,
  137865. NULL,
  137866. 0
  137867. };
  137868. static long _vq_quantlist__44u9_p5_1[] = {
  137869. 5,
  137870. 4,
  137871. 6,
  137872. 3,
  137873. 7,
  137874. 2,
  137875. 8,
  137876. 1,
  137877. 9,
  137878. 0,
  137879. 10,
  137880. };
  137881. static long _vq_lengthlist__44u9_p5_1[] = {
  137882. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137883. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137884. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137885. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137886. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137887. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137888. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137889. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137890. };
  137891. static float _vq_quantthresh__44u9_p5_1[] = {
  137892. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137893. 3.5, 4.5,
  137894. };
  137895. static long _vq_quantmap__44u9_p5_1[] = {
  137896. 9, 7, 5, 3, 1, 0, 2, 4,
  137897. 6, 8, 10,
  137898. };
  137899. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137900. _vq_quantthresh__44u9_p5_1,
  137901. _vq_quantmap__44u9_p5_1,
  137902. 11,
  137903. 11
  137904. };
  137905. static static_codebook _44u9_p5_1 = {
  137906. 2, 121,
  137907. _vq_lengthlist__44u9_p5_1,
  137908. 1, -531365888, 1611661312, 4, 0,
  137909. _vq_quantlist__44u9_p5_1,
  137910. NULL,
  137911. &_vq_auxt__44u9_p5_1,
  137912. NULL,
  137913. 0
  137914. };
  137915. static long _vq_quantlist__44u9_p6_0[] = {
  137916. 6,
  137917. 5,
  137918. 7,
  137919. 4,
  137920. 8,
  137921. 3,
  137922. 9,
  137923. 2,
  137924. 10,
  137925. 1,
  137926. 11,
  137927. 0,
  137928. 12,
  137929. };
  137930. static long _vq_lengthlist__44u9_p6_0[] = {
  137931. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137932. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137933. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137934. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137935. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137936. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137937. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137938. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137939. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137940. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137941. 10,11,11,11,11,12,11,12,12,
  137942. };
  137943. static float _vq_quantthresh__44u9_p6_0[] = {
  137944. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137945. 12.5, 17.5, 22.5, 27.5,
  137946. };
  137947. static long _vq_quantmap__44u9_p6_0[] = {
  137948. 11, 9, 7, 5, 3, 1, 0, 2,
  137949. 4, 6, 8, 10, 12,
  137950. };
  137951. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137952. _vq_quantthresh__44u9_p6_0,
  137953. _vq_quantmap__44u9_p6_0,
  137954. 13,
  137955. 13
  137956. };
  137957. static static_codebook _44u9_p6_0 = {
  137958. 2, 169,
  137959. _vq_lengthlist__44u9_p6_0,
  137960. 1, -526516224, 1616117760, 4, 0,
  137961. _vq_quantlist__44u9_p6_0,
  137962. NULL,
  137963. &_vq_auxt__44u9_p6_0,
  137964. NULL,
  137965. 0
  137966. };
  137967. static long _vq_quantlist__44u9_p6_1[] = {
  137968. 2,
  137969. 1,
  137970. 3,
  137971. 0,
  137972. 4,
  137973. };
  137974. static long _vq_lengthlist__44u9_p6_1[] = {
  137975. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137976. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137977. };
  137978. static float _vq_quantthresh__44u9_p6_1[] = {
  137979. -1.5, -0.5, 0.5, 1.5,
  137980. };
  137981. static long _vq_quantmap__44u9_p6_1[] = {
  137982. 3, 1, 0, 2, 4,
  137983. };
  137984. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137985. _vq_quantthresh__44u9_p6_1,
  137986. _vq_quantmap__44u9_p6_1,
  137987. 5,
  137988. 5
  137989. };
  137990. static static_codebook _44u9_p6_1 = {
  137991. 2, 25,
  137992. _vq_lengthlist__44u9_p6_1,
  137993. 1, -533725184, 1611661312, 3, 0,
  137994. _vq_quantlist__44u9_p6_1,
  137995. NULL,
  137996. &_vq_auxt__44u9_p6_1,
  137997. NULL,
  137998. 0
  137999. };
  138000. static long _vq_quantlist__44u9_p7_0[] = {
  138001. 6,
  138002. 5,
  138003. 7,
  138004. 4,
  138005. 8,
  138006. 3,
  138007. 9,
  138008. 2,
  138009. 10,
  138010. 1,
  138011. 11,
  138012. 0,
  138013. 12,
  138014. };
  138015. static long _vq_lengthlist__44u9_p7_0[] = {
  138016. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  138017. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  138018. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  138019. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  138020. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  138021. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  138022. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  138023. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  138024. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  138025. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  138026. 12,13,13,14,14,14,15,15,15,
  138027. };
  138028. static float _vq_quantthresh__44u9_p7_0[] = {
  138029. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  138030. 27.5, 38.5, 49.5, 60.5,
  138031. };
  138032. static long _vq_quantmap__44u9_p7_0[] = {
  138033. 11, 9, 7, 5, 3, 1, 0, 2,
  138034. 4, 6, 8, 10, 12,
  138035. };
  138036. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  138037. _vq_quantthresh__44u9_p7_0,
  138038. _vq_quantmap__44u9_p7_0,
  138039. 13,
  138040. 13
  138041. };
  138042. static static_codebook _44u9_p7_0 = {
  138043. 2, 169,
  138044. _vq_lengthlist__44u9_p7_0,
  138045. 1, -523206656, 1618345984, 4, 0,
  138046. _vq_quantlist__44u9_p7_0,
  138047. NULL,
  138048. &_vq_auxt__44u9_p7_0,
  138049. NULL,
  138050. 0
  138051. };
  138052. static long _vq_quantlist__44u9_p7_1[] = {
  138053. 5,
  138054. 4,
  138055. 6,
  138056. 3,
  138057. 7,
  138058. 2,
  138059. 8,
  138060. 1,
  138061. 9,
  138062. 0,
  138063. 10,
  138064. };
  138065. static long _vq_lengthlist__44u9_p7_1[] = {
  138066. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  138067. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  138068. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  138069. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138070. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138071. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138072. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  138073. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  138074. };
  138075. static float _vq_quantthresh__44u9_p7_1[] = {
  138076. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138077. 3.5, 4.5,
  138078. };
  138079. static long _vq_quantmap__44u9_p7_1[] = {
  138080. 9, 7, 5, 3, 1, 0, 2, 4,
  138081. 6, 8, 10,
  138082. };
  138083. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  138084. _vq_quantthresh__44u9_p7_1,
  138085. _vq_quantmap__44u9_p7_1,
  138086. 11,
  138087. 11
  138088. };
  138089. static static_codebook _44u9_p7_1 = {
  138090. 2, 121,
  138091. _vq_lengthlist__44u9_p7_1,
  138092. 1, -531365888, 1611661312, 4, 0,
  138093. _vq_quantlist__44u9_p7_1,
  138094. NULL,
  138095. &_vq_auxt__44u9_p7_1,
  138096. NULL,
  138097. 0
  138098. };
  138099. static long _vq_quantlist__44u9_p8_0[] = {
  138100. 7,
  138101. 6,
  138102. 8,
  138103. 5,
  138104. 9,
  138105. 4,
  138106. 10,
  138107. 3,
  138108. 11,
  138109. 2,
  138110. 12,
  138111. 1,
  138112. 13,
  138113. 0,
  138114. 14,
  138115. };
  138116. static long _vq_lengthlist__44u9_p8_0[] = {
  138117. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  138118. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  138119. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  138120. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  138121. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  138122. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  138123. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  138124. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  138125. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  138126. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  138127. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  138128. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  138129. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  138130. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  138131. 15,
  138132. };
  138133. static float _vq_quantthresh__44u9_p8_0[] = {
  138134. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  138135. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  138136. };
  138137. static long _vq_quantmap__44u9_p8_0[] = {
  138138. 13, 11, 9, 7, 5, 3, 1, 0,
  138139. 2, 4, 6, 8, 10, 12, 14,
  138140. };
  138141. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  138142. _vq_quantthresh__44u9_p8_0,
  138143. _vq_quantmap__44u9_p8_0,
  138144. 15,
  138145. 15
  138146. };
  138147. static static_codebook _44u9_p8_0 = {
  138148. 2, 225,
  138149. _vq_lengthlist__44u9_p8_0,
  138150. 1, -520986624, 1620377600, 4, 0,
  138151. _vq_quantlist__44u9_p8_0,
  138152. NULL,
  138153. &_vq_auxt__44u9_p8_0,
  138154. NULL,
  138155. 0
  138156. };
  138157. static long _vq_quantlist__44u9_p8_1[] = {
  138158. 10,
  138159. 9,
  138160. 11,
  138161. 8,
  138162. 12,
  138163. 7,
  138164. 13,
  138165. 6,
  138166. 14,
  138167. 5,
  138168. 15,
  138169. 4,
  138170. 16,
  138171. 3,
  138172. 17,
  138173. 2,
  138174. 18,
  138175. 1,
  138176. 19,
  138177. 0,
  138178. 20,
  138179. };
  138180. static long _vq_lengthlist__44u9_p8_1[] = {
  138181. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  138182. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138183. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  138184. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  138185. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  138186. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  138187. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  138188. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  138189. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138190. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138191. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  138192. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  138193. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138194. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  138195. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138196. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  138197. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138198. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138199. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  138200. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  138201. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138202. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  138203. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  138204. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  138205. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  138206. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  138207. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138208. 10,10,10,10,10,10,10,10,10,
  138209. };
  138210. static float _vq_quantthresh__44u9_p8_1[] = {
  138211. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  138212. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  138213. 6.5, 7.5, 8.5, 9.5,
  138214. };
  138215. static long _vq_quantmap__44u9_p8_1[] = {
  138216. 19, 17, 15, 13, 11, 9, 7, 5,
  138217. 3, 1, 0, 2, 4, 6, 8, 10,
  138218. 12, 14, 16, 18, 20,
  138219. };
  138220. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  138221. _vq_quantthresh__44u9_p8_1,
  138222. _vq_quantmap__44u9_p8_1,
  138223. 21,
  138224. 21
  138225. };
  138226. static static_codebook _44u9_p8_1 = {
  138227. 2, 441,
  138228. _vq_lengthlist__44u9_p8_1,
  138229. 1, -529268736, 1611661312, 5, 0,
  138230. _vq_quantlist__44u9_p8_1,
  138231. NULL,
  138232. &_vq_auxt__44u9_p8_1,
  138233. NULL,
  138234. 0
  138235. };
  138236. static long _vq_quantlist__44u9_p9_0[] = {
  138237. 7,
  138238. 6,
  138239. 8,
  138240. 5,
  138241. 9,
  138242. 4,
  138243. 10,
  138244. 3,
  138245. 11,
  138246. 2,
  138247. 12,
  138248. 1,
  138249. 13,
  138250. 0,
  138251. 14,
  138252. };
  138253. static long _vq_lengthlist__44u9_p9_0[] = {
  138254. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  138255. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  138256. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138257. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138258. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138259. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138260. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138261. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138262. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138263. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138264. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138265. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138266. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138267. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138268. 10,
  138269. };
  138270. static float _vq_quantthresh__44u9_p9_0[] = {
  138271. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  138272. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  138273. };
  138274. static long _vq_quantmap__44u9_p9_0[] = {
  138275. 13, 11, 9, 7, 5, 3, 1, 0,
  138276. 2, 4, 6, 8, 10, 12, 14,
  138277. };
  138278. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  138279. _vq_quantthresh__44u9_p9_0,
  138280. _vq_quantmap__44u9_p9_0,
  138281. 15,
  138282. 15
  138283. };
  138284. static static_codebook _44u9_p9_0 = {
  138285. 2, 225,
  138286. _vq_lengthlist__44u9_p9_0,
  138287. 1, -510036736, 1631393792, 4, 0,
  138288. _vq_quantlist__44u9_p9_0,
  138289. NULL,
  138290. &_vq_auxt__44u9_p9_0,
  138291. NULL,
  138292. 0
  138293. };
  138294. static long _vq_quantlist__44u9_p9_1[] = {
  138295. 9,
  138296. 8,
  138297. 10,
  138298. 7,
  138299. 11,
  138300. 6,
  138301. 12,
  138302. 5,
  138303. 13,
  138304. 4,
  138305. 14,
  138306. 3,
  138307. 15,
  138308. 2,
  138309. 16,
  138310. 1,
  138311. 17,
  138312. 0,
  138313. 18,
  138314. };
  138315. static long _vq_lengthlist__44u9_p9_1[] = {
  138316. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138317. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138318. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138319. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138320. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138321. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138322. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138323. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138324. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138325. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138326. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138327. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138328. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138329. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138330. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138331. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138332. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138333. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138334. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138335. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138336. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138337. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138338. 17,17,15,17,15,17,16,16,17,
  138339. };
  138340. static float _vq_quantthresh__44u9_p9_1[] = {
  138341. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138342. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138343. 367.5, 416.5,
  138344. };
  138345. static long _vq_quantmap__44u9_p9_1[] = {
  138346. 17, 15, 13, 11, 9, 7, 5, 3,
  138347. 1, 0, 2, 4, 6, 8, 10, 12,
  138348. 14, 16, 18,
  138349. };
  138350. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138351. _vq_quantthresh__44u9_p9_1,
  138352. _vq_quantmap__44u9_p9_1,
  138353. 19,
  138354. 19
  138355. };
  138356. static static_codebook _44u9_p9_1 = {
  138357. 2, 361,
  138358. _vq_lengthlist__44u9_p9_1,
  138359. 1, -518287360, 1622704128, 5, 0,
  138360. _vq_quantlist__44u9_p9_1,
  138361. NULL,
  138362. &_vq_auxt__44u9_p9_1,
  138363. NULL,
  138364. 0
  138365. };
  138366. static long _vq_quantlist__44u9_p9_2[] = {
  138367. 24,
  138368. 23,
  138369. 25,
  138370. 22,
  138371. 26,
  138372. 21,
  138373. 27,
  138374. 20,
  138375. 28,
  138376. 19,
  138377. 29,
  138378. 18,
  138379. 30,
  138380. 17,
  138381. 31,
  138382. 16,
  138383. 32,
  138384. 15,
  138385. 33,
  138386. 14,
  138387. 34,
  138388. 13,
  138389. 35,
  138390. 12,
  138391. 36,
  138392. 11,
  138393. 37,
  138394. 10,
  138395. 38,
  138396. 9,
  138397. 39,
  138398. 8,
  138399. 40,
  138400. 7,
  138401. 41,
  138402. 6,
  138403. 42,
  138404. 5,
  138405. 43,
  138406. 4,
  138407. 44,
  138408. 3,
  138409. 45,
  138410. 2,
  138411. 46,
  138412. 1,
  138413. 47,
  138414. 0,
  138415. 48,
  138416. };
  138417. static long _vq_lengthlist__44u9_p9_2[] = {
  138418. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138419. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138420. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138421. 7,
  138422. };
  138423. static float _vq_quantthresh__44u9_p9_2[] = {
  138424. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138425. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138426. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138427. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138428. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138429. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138430. };
  138431. static long _vq_quantmap__44u9_p9_2[] = {
  138432. 47, 45, 43, 41, 39, 37, 35, 33,
  138433. 31, 29, 27, 25, 23, 21, 19, 17,
  138434. 15, 13, 11, 9, 7, 5, 3, 1,
  138435. 0, 2, 4, 6, 8, 10, 12, 14,
  138436. 16, 18, 20, 22, 24, 26, 28, 30,
  138437. 32, 34, 36, 38, 40, 42, 44, 46,
  138438. 48,
  138439. };
  138440. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138441. _vq_quantthresh__44u9_p9_2,
  138442. _vq_quantmap__44u9_p9_2,
  138443. 49,
  138444. 49
  138445. };
  138446. static static_codebook _44u9_p9_2 = {
  138447. 1, 49,
  138448. _vq_lengthlist__44u9_p9_2,
  138449. 1, -526909440, 1611661312, 6, 0,
  138450. _vq_quantlist__44u9_p9_2,
  138451. NULL,
  138452. &_vq_auxt__44u9_p9_2,
  138453. NULL,
  138454. 0
  138455. };
  138456. static long _huff_lengthlist__44un1__long[] = {
  138457. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138458. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138459. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138460. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138461. };
  138462. static static_codebook _huff_book__44un1__long = {
  138463. 2, 64,
  138464. _huff_lengthlist__44un1__long,
  138465. 0, 0, 0, 0, 0,
  138466. NULL,
  138467. NULL,
  138468. NULL,
  138469. NULL,
  138470. 0
  138471. };
  138472. static long _vq_quantlist__44un1__p1_0[] = {
  138473. 1,
  138474. 0,
  138475. 2,
  138476. };
  138477. static long _vq_lengthlist__44un1__p1_0[] = {
  138478. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138479. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138480. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138481. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138482. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138483. 12,
  138484. };
  138485. static float _vq_quantthresh__44un1__p1_0[] = {
  138486. -0.5, 0.5,
  138487. };
  138488. static long _vq_quantmap__44un1__p1_0[] = {
  138489. 1, 0, 2,
  138490. };
  138491. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138492. _vq_quantthresh__44un1__p1_0,
  138493. _vq_quantmap__44un1__p1_0,
  138494. 3,
  138495. 3
  138496. };
  138497. static static_codebook _44un1__p1_0 = {
  138498. 4, 81,
  138499. _vq_lengthlist__44un1__p1_0,
  138500. 1, -535822336, 1611661312, 2, 0,
  138501. _vq_quantlist__44un1__p1_0,
  138502. NULL,
  138503. &_vq_auxt__44un1__p1_0,
  138504. NULL,
  138505. 0
  138506. };
  138507. static long _vq_quantlist__44un1__p2_0[] = {
  138508. 1,
  138509. 0,
  138510. 2,
  138511. };
  138512. static long _vq_lengthlist__44un1__p2_0[] = {
  138513. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138514. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138515. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138516. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138517. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138518. 8,
  138519. };
  138520. static float _vq_quantthresh__44un1__p2_0[] = {
  138521. -0.5, 0.5,
  138522. };
  138523. static long _vq_quantmap__44un1__p2_0[] = {
  138524. 1, 0, 2,
  138525. };
  138526. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138527. _vq_quantthresh__44un1__p2_0,
  138528. _vq_quantmap__44un1__p2_0,
  138529. 3,
  138530. 3
  138531. };
  138532. static static_codebook _44un1__p2_0 = {
  138533. 4, 81,
  138534. _vq_lengthlist__44un1__p2_0,
  138535. 1, -535822336, 1611661312, 2, 0,
  138536. _vq_quantlist__44un1__p2_0,
  138537. NULL,
  138538. &_vq_auxt__44un1__p2_0,
  138539. NULL,
  138540. 0
  138541. };
  138542. static long _vq_quantlist__44un1__p3_0[] = {
  138543. 2,
  138544. 1,
  138545. 3,
  138546. 0,
  138547. 4,
  138548. };
  138549. static long _vq_lengthlist__44un1__p3_0[] = {
  138550. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138551. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138552. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138553. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138554. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138555. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138556. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138557. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138558. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138559. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138560. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138561. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138562. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138563. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138564. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138565. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138566. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138567. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138568. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138569. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138570. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138571. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138572. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138573. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138574. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138575. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138576. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138577. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138578. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138579. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138580. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138581. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138582. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138583. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138584. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138585. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138586. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138587. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138588. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138589. 17,
  138590. };
  138591. static float _vq_quantthresh__44un1__p3_0[] = {
  138592. -1.5, -0.5, 0.5, 1.5,
  138593. };
  138594. static long _vq_quantmap__44un1__p3_0[] = {
  138595. 3, 1, 0, 2, 4,
  138596. };
  138597. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138598. _vq_quantthresh__44un1__p3_0,
  138599. _vq_quantmap__44un1__p3_0,
  138600. 5,
  138601. 5
  138602. };
  138603. static static_codebook _44un1__p3_0 = {
  138604. 4, 625,
  138605. _vq_lengthlist__44un1__p3_0,
  138606. 1, -533725184, 1611661312, 3, 0,
  138607. _vq_quantlist__44un1__p3_0,
  138608. NULL,
  138609. &_vq_auxt__44un1__p3_0,
  138610. NULL,
  138611. 0
  138612. };
  138613. static long _vq_quantlist__44un1__p4_0[] = {
  138614. 2,
  138615. 1,
  138616. 3,
  138617. 0,
  138618. 4,
  138619. };
  138620. static long _vq_lengthlist__44un1__p4_0[] = {
  138621. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138622. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138623. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138624. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138625. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138626. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138627. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138628. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138629. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138630. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138631. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138632. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138633. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138634. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138635. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138636. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138637. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138638. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138639. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138640. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138641. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138642. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138643. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138644. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138645. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138646. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138647. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138648. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138649. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138650. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138651. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138652. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138653. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138654. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138655. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138656. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138657. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138658. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138659. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138660. 12,
  138661. };
  138662. static float _vq_quantthresh__44un1__p4_0[] = {
  138663. -1.5, -0.5, 0.5, 1.5,
  138664. };
  138665. static long _vq_quantmap__44un1__p4_0[] = {
  138666. 3, 1, 0, 2, 4,
  138667. };
  138668. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138669. _vq_quantthresh__44un1__p4_0,
  138670. _vq_quantmap__44un1__p4_0,
  138671. 5,
  138672. 5
  138673. };
  138674. static static_codebook _44un1__p4_0 = {
  138675. 4, 625,
  138676. _vq_lengthlist__44un1__p4_0,
  138677. 1, -533725184, 1611661312, 3, 0,
  138678. _vq_quantlist__44un1__p4_0,
  138679. NULL,
  138680. &_vq_auxt__44un1__p4_0,
  138681. NULL,
  138682. 0
  138683. };
  138684. static long _vq_quantlist__44un1__p5_0[] = {
  138685. 4,
  138686. 3,
  138687. 5,
  138688. 2,
  138689. 6,
  138690. 1,
  138691. 7,
  138692. 0,
  138693. 8,
  138694. };
  138695. static long _vq_lengthlist__44un1__p5_0[] = {
  138696. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138697. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138698. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138699. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138700. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138701. 12,
  138702. };
  138703. static float _vq_quantthresh__44un1__p5_0[] = {
  138704. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138705. };
  138706. static long _vq_quantmap__44un1__p5_0[] = {
  138707. 7, 5, 3, 1, 0, 2, 4, 6,
  138708. 8,
  138709. };
  138710. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138711. _vq_quantthresh__44un1__p5_0,
  138712. _vq_quantmap__44un1__p5_0,
  138713. 9,
  138714. 9
  138715. };
  138716. static static_codebook _44un1__p5_0 = {
  138717. 2, 81,
  138718. _vq_lengthlist__44un1__p5_0,
  138719. 1, -531628032, 1611661312, 4, 0,
  138720. _vq_quantlist__44un1__p5_0,
  138721. NULL,
  138722. &_vq_auxt__44un1__p5_0,
  138723. NULL,
  138724. 0
  138725. };
  138726. static long _vq_quantlist__44un1__p6_0[] = {
  138727. 6,
  138728. 5,
  138729. 7,
  138730. 4,
  138731. 8,
  138732. 3,
  138733. 9,
  138734. 2,
  138735. 10,
  138736. 1,
  138737. 11,
  138738. 0,
  138739. 12,
  138740. };
  138741. static long _vq_lengthlist__44un1__p6_0[] = {
  138742. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138743. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138744. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138745. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138746. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138747. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138748. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138749. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138750. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138751. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138752. 16, 0,15,18,18, 0,16, 0, 0,
  138753. };
  138754. static float _vq_quantthresh__44un1__p6_0[] = {
  138755. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138756. 12.5, 17.5, 22.5, 27.5,
  138757. };
  138758. static long _vq_quantmap__44un1__p6_0[] = {
  138759. 11, 9, 7, 5, 3, 1, 0, 2,
  138760. 4, 6, 8, 10, 12,
  138761. };
  138762. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138763. _vq_quantthresh__44un1__p6_0,
  138764. _vq_quantmap__44un1__p6_0,
  138765. 13,
  138766. 13
  138767. };
  138768. static static_codebook _44un1__p6_0 = {
  138769. 2, 169,
  138770. _vq_lengthlist__44un1__p6_0,
  138771. 1, -526516224, 1616117760, 4, 0,
  138772. _vq_quantlist__44un1__p6_0,
  138773. NULL,
  138774. &_vq_auxt__44un1__p6_0,
  138775. NULL,
  138776. 0
  138777. };
  138778. static long _vq_quantlist__44un1__p6_1[] = {
  138779. 2,
  138780. 1,
  138781. 3,
  138782. 0,
  138783. 4,
  138784. };
  138785. static long _vq_lengthlist__44un1__p6_1[] = {
  138786. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138787. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138788. };
  138789. static float _vq_quantthresh__44un1__p6_1[] = {
  138790. -1.5, -0.5, 0.5, 1.5,
  138791. };
  138792. static long _vq_quantmap__44un1__p6_1[] = {
  138793. 3, 1, 0, 2, 4,
  138794. };
  138795. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138796. _vq_quantthresh__44un1__p6_1,
  138797. _vq_quantmap__44un1__p6_1,
  138798. 5,
  138799. 5
  138800. };
  138801. static static_codebook _44un1__p6_1 = {
  138802. 2, 25,
  138803. _vq_lengthlist__44un1__p6_1,
  138804. 1, -533725184, 1611661312, 3, 0,
  138805. _vq_quantlist__44un1__p6_1,
  138806. NULL,
  138807. &_vq_auxt__44un1__p6_1,
  138808. NULL,
  138809. 0
  138810. };
  138811. static long _vq_quantlist__44un1__p7_0[] = {
  138812. 2,
  138813. 1,
  138814. 3,
  138815. 0,
  138816. 4,
  138817. };
  138818. static long _vq_lengthlist__44un1__p7_0[] = {
  138819. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138820. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138821. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138822. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138823. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138824. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138825. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138826. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138827. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138828. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138829. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138830. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138831. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138832. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138833. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138834. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138835. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138836. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138837. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138838. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138839. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138840. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138841. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138842. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138843. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138844. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138845. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138846. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138847. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138848. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138849. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138850. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138851. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138852. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138853. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138854. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138855. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138856. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138857. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138858. 10,
  138859. };
  138860. static float _vq_quantthresh__44un1__p7_0[] = {
  138861. -253.5, -84.5, 84.5, 253.5,
  138862. };
  138863. static long _vq_quantmap__44un1__p7_0[] = {
  138864. 3, 1, 0, 2, 4,
  138865. };
  138866. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138867. _vq_quantthresh__44un1__p7_0,
  138868. _vq_quantmap__44un1__p7_0,
  138869. 5,
  138870. 5
  138871. };
  138872. static static_codebook _44un1__p7_0 = {
  138873. 4, 625,
  138874. _vq_lengthlist__44un1__p7_0,
  138875. 1, -518709248, 1626677248, 3, 0,
  138876. _vq_quantlist__44un1__p7_0,
  138877. NULL,
  138878. &_vq_auxt__44un1__p7_0,
  138879. NULL,
  138880. 0
  138881. };
  138882. static long _vq_quantlist__44un1__p7_1[] = {
  138883. 6,
  138884. 5,
  138885. 7,
  138886. 4,
  138887. 8,
  138888. 3,
  138889. 9,
  138890. 2,
  138891. 10,
  138892. 1,
  138893. 11,
  138894. 0,
  138895. 12,
  138896. };
  138897. static long _vq_lengthlist__44un1__p7_1[] = {
  138898. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138899. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138900. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138901. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138902. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138903. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138904. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138905. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138906. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138907. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138908. 12,13,13,12,13,13,14,14,14,
  138909. };
  138910. static float _vq_quantthresh__44un1__p7_1[] = {
  138911. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138912. 32.5, 45.5, 58.5, 71.5,
  138913. };
  138914. static long _vq_quantmap__44un1__p7_1[] = {
  138915. 11, 9, 7, 5, 3, 1, 0, 2,
  138916. 4, 6, 8, 10, 12,
  138917. };
  138918. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138919. _vq_quantthresh__44un1__p7_1,
  138920. _vq_quantmap__44un1__p7_1,
  138921. 13,
  138922. 13
  138923. };
  138924. static static_codebook _44un1__p7_1 = {
  138925. 2, 169,
  138926. _vq_lengthlist__44un1__p7_1,
  138927. 1, -523010048, 1618608128, 4, 0,
  138928. _vq_quantlist__44un1__p7_1,
  138929. NULL,
  138930. &_vq_auxt__44un1__p7_1,
  138931. NULL,
  138932. 0
  138933. };
  138934. static long _vq_quantlist__44un1__p7_2[] = {
  138935. 6,
  138936. 5,
  138937. 7,
  138938. 4,
  138939. 8,
  138940. 3,
  138941. 9,
  138942. 2,
  138943. 10,
  138944. 1,
  138945. 11,
  138946. 0,
  138947. 12,
  138948. };
  138949. static long _vq_lengthlist__44un1__p7_2[] = {
  138950. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138951. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138952. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138953. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138954. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138955. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138956. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138957. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138958. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138959. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138960. 9, 9, 9,10,10,10,10,10,10,
  138961. };
  138962. static float _vq_quantthresh__44un1__p7_2[] = {
  138963. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138964. 2.5, 3.5, 4.5, 5.5,
  138965. };
  138966. static long _vq_quantmap__44un1__p7_2[] = {
  138967. 11, 9, 7, 5, 3, 1, 0, 2,
  138968. 4, 6, 8, 10, 12,
  138969. };
  138970. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138971. _vq_quantthresh__44un1__p7_2,
  138972. _vq_quantmap__44un1__p7_2,
  138973. 13,
  138974. 13
  138975. };
  138976. static static_codebook _44un1__p7_2 = {
  138977. 2, 169,
  138978. _vq_lengthlist__44un1__p7_2,
  138979. 1, -531103744, 1611661312, 4, 0,
  138980. _vq_quantlist__44un1__p7_2,
  138981. NULL,
  138982. &_vq_auxt__44un1__p7_2,
  138983. NULL,
  138984. 0
  138985. };
  138986. static long _huff_lengthlist__44un1__short[] = {
  138987. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138988. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138989. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138990. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138991. };
  138992. static static_codebook _huff_book__44un1__short = {
  138993. 2, 64,
  138994. _huff_lengthlist__44un1__short,
  138995. 0, 0, 0, 0, 0,
  138996. NULL,
  138997. NULL,
  138998. NULL,
  138999. NULL,
  139000. 0
  139001. };
  139002. /*** End of inlined file: res_books_uncoupled.h ***/
  139003. static vorbis_info_residue0 _residue_44_low_un={
  139004. 0,-1, -1, 8,-1,
  139005. {0},
  139006. {-1},
  139007. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  139008. { -1, 25, -1, 45, -1, -1, -1}
  139009. };
  139010. static vorbis_info_residue0 _residue_44_mid_un={
  139011. 0,-1, -1, 10,-1,
  139012. {0},
  139013. {-1},
  139014. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  139015. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  139016. };
  139017. static vorbis_info_residue0 _residue_44_hi_un={
  139018. 0,-1, -1, 10,-1,
  139019. {0},
  139020. {-1},
  139021. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  139022. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  139023. };
  139024. static vorbis_info_mapping0 _map_nominal_u[2]={
  139025. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  139026. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  139027. };
  139028. static static_bookblock _resbook_44u_n1={
  139029. {
  139030. {0},
  139031. {0,0,&_44un1__p1_0},
  139032. {0,0,&_44un1__p2_0},
  139033. {0,0,&_44un1__p3_0},
  139034. {0,0,&_44un1__p4_0},
  139035. {0,0,&_44un1__p5_0},
  139036. {&_44un1__p6_0,&_44un1__p6_1},
  139037. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  139038. }
  139039. };
  139040. static static_bookblock _resbook_44u_0={
  139041. {
  139042. {0},
  139043. {0,0,&_44u0__p1_0},
  139044. {0,0,&_44u0__p2_0},
  139045. {0,0,&_44u0__p3_0},
  139046. {0,0,&_44u0__p4_0},
  139047. {0,0,&_44u0__p5_0},
  139048. {&_44u0__p6_0,&_44u0__p6_1},
  139049. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  139050. }
  139051. };
  139052. static static_bookblock _resbook_44u_1={
  139053. {
  139054. {0},
  139055. {0,0,&_44u1__p1_0},
  139056. {0,0,&_44u1__p2_0},
  139057. {0,0,&_44u1__p3_0},
  139058. {0,0,&_44u1__p4_0},
  139059. {0,0,&_44u1__p5_0},
  139060. {&_44u1__p6_0,&_44u1__p6_1},
  139061. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  139062. }
  139063. };
  139064. static static_bookblock _resbook_44u_2={
  139065. {
  139066. {0},
  139067. {0,0,&_44u2__p1_0},
  139068. {0,0,&_44u2__p2_0},
  139069. {0,0,&_44u2__p3_0},
  139070. {0,0,&_44u2__p4_0},
  139071. {0,0,&_44u2__p5_0},
  139072. {&_44u2__p6_0,&_44u2__p6_1},
  139073. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  139074. }
  139075. };
  139076. static static_bookblock _resbook_44u_3={
  139077. {
  139078. {0},
  139079. {0,0,&_44u3__p1_0},
  139080. {0,0,&_44u3__p2_0},
  139081. {0,0,&_44u3__p3_0},
  139082. {0,0,&_44u3__p4_0},
  139083. {0,0,&_44u3__p5_0},
  139084. {&_44u3__p6_0,&_44u3__p6_1},
  139085. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  139086. }
  139087. };
  139088. static static_bookblock _resbook_44u_4={
  139089. {
  139090. {0},
  139091. {0,0,&_44u4__p1_0},
  139092. {0,0,&_44u4__p2_0},
  139093. {0,0,&_44u4__p3_0},
  139094. {0,0,&_44u4__p4_0},
  139095. {0,0,&_44u4__p5_0},
  139096. {&_44u4__p6_0,&_44u4__p6_1},
  139097. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  139098. }
  139099. };
  139100. static static_bookblock _resbook_44u_5={
  139101. {
  139102. {0},
  139103. {0,0,&_44u5__p1_0},
  139104. {0,0,&_44u5__p2_0},
  139105. {0,0,&_44u5__p3_0},
  139106. {0,0,&_44u5__p4_0},
  139107. {0,0,&_44u5__p5_0},
  139108. {0,0,&_44u5__p6_0},
  139109. {&_44u5__p7_0,&_44u5__p7_1},
  139110. {&_44u5__p8_0,&_44u5__p8_1},
  139111. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  139112. }
  139113. };
  139114. static static_bookblock _resbook_44u_6={
  139115. {
  139116. {0},
  139117. {0,0,&_44u6__p1_0},
  139118. {0,0,&_44u6__p2_0},
  139119. {0,0,&_44u6__p3_0},
  139120. {0,0,&_44u6__p4_0},
  139121. {0,0,&_44u6__p5_0},
  139122. {0,0,&_44u6__p6_0},
  139123. {&_44u6__p7_0,&_44u6__p7_1},
  139124. {&_44u6__p8_0,&_44u6__p8_1},
  139125. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  139126. }
  139127. };
  139128. static static_bookblock _resbook_44u_7={
  139129. {
  139130. {0},
  139131. {0,0,&_44u7__p1_0},
  139132. {0,0,&_44u7__p2_0},
  139133. {0,0,&_44u7__p3_0},
  139134. {0,0,&_44u7__p4_0},
  139135. {0,0,&_44u7__p5_0},
  139136. {0,0,&_44u7__p6_0},
  139137. {&_44u7__p7_0,&_44u7__p7_1},
  139138. {&_44u7__p8_0,&_44u7__p8_1},
  139139. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  139140. }
  139141. };
  139142. static static_bookblock _resbook_44u_8={
  139143. {
  139144. {0},
  139145. {0,0,&_44u8_p1_0},
  139146. {0,0,&_44u8_p2_0},
  139147. {0,0,&_44u8_p3_0},
  139148. {0,0,&_44u8_p4_0},
  139149. {&_44u8_p5_0,&_44u8_p5_1},
  139150. {&_44u8_p6_0,&_44u8_p6_1},
  139151. {&_44u8_p7_0,&_44u8_p7_1},
  139152. {&_44u8_p8_0,&_44u8_p8_1},
  139153. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  139154. }
  139155. };
  139156. static static_bookblock _resbook_44u_9={
  139157. {
  139158. {0},
  139159. {0,0,&_44u9_p1_0},
  139160. {0,0,&_44u9_p2_0},
  139161. {0,0,&_44u9_p3_0},
  139162. {0,0,&_44u9_p4_0},
  139163. {&_44u9_p5_0,&_44u9_p5_1},
  139164. {&_44u9_p6_0,&_44u9_p6_1},
  139165. {&_44u9_p7_0,&_44u9_p7_1},
  139166. {&_44u9_p8_0,&_44u9_p8_1},
  139167. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  139168. }
  139169. };
  139170. static vorbis_residue_template _res_44u_n1[]={
  139171. {1,0, &_residue_44_low_un,
  139172. &_huff_book__44un1__short,&_huff_book__44un1__short,
  139173. &_resbook_44u_n1,&_resbook_44u_n1},
  139174. {1,0, &_residue_44_low_un,
  139175. &_huff_book__44un1__long,&_huff_book__44un1__long,
  139176. &_resbook_44u_n1,&_resbook_44u_n1}
  139177. };
  139178. static vorbis_residue_template _res_44u_0[]={
  139179. {1,0, &_residue_44_low_un,
  139180. &_huff_book__44u0__short,&_huff_book__44u0__short,
  139181. &_resbook_44u_0,&_resbook_44u_0},
  139182. {1,0, &_residue_44_low_un,
  139183. &_huff_book__44u0__long,&_huff_book__44u0__long,
  139184. &_resbook_44u_0,&_resbook_44u_0}
  139185. };
  139186. static vorbis_residue_template _res_44u_1[]={
  139187. {1,0, &_residue_44_low_un,
  139188. &_huff_book__44u1__short,&_huff_book__44u1__short,
  139189. &_resbook_44u_1,&_resbook_44u_1},
  139190. {1,0, &_residue_44_low_un,
  139191. &_huff_book__44u1__long,&_huff_book__44u1__long,
  139192. &_resbook_44u_1,&_resbook_44u_1}
  139193. };
  139194. static vorbis_residue_template _res_44u_2[]={
  139195. {1,0, &_residue_44_low_un,
  139196. &_huff_book__44u2__short,&_huff_book__44u2__short,
  139197. &_resbook_44u_2,&_resbook_44u_2},
  139198. {1,0, &_residue_44_low_un,
  139199. &_huff_book__44u2__long,&_huff_book__44u2__long,
  139200. &_resbook_44u_2,&_resbook_44u_2}
  139201. };
  139202. static vorbis_residue_template _res_44u_3[]={
  139203. {1,0, &_residue_44_low_un,
  139204. &_huff_book__44u3__short,&_huff_book__44u3__short,
  139205. &_resbook_44u_3,&_resbook_44u_3},
  139206. {1,0, &_residue_44_low_un,
  139207. &_huff_book__44u3__long,&_huff_book__44u3__long,
  139208. &_resbook_44u_3,&_resbook_44u_3}
  139209. };
  139210. static vorbis_residue_template _res_44u_4[]={
  139211. {1,0, &_residue_44_low_un,
  139212. &_huff_book__44u4__short,&_huff_book__44u4__short,
  139213. &_resbook_44u_4,&_resbook_44u_4},
  139214. {1,0, &_residue_44_low_un,
  139215. &_huff_book__44u4__long,&_huff_book__44u4__long,
  139216. &_resbook_44u_4,&_resbook_44u_4}
  139217. };
  139218. static vorbis_residue_template _res_44u_5[]={
  139219. {1,0, &_residue_44_mid_un,
  139220. &_huff_book__44u5__short,&_huff_book__44u5__short,
  139221. &_resbook_44u_5,&_resbook_44u_5},
  139222. {1,0, &_residue_44_mid_un,
  139223. &_huff_book__44u5__long,&_huff_book__44u5__long,
  139224. &_resbook_44u_5,&_resbook_44u_5}
  139225. };
  139226. static vorbis_residue_template _res_44u_6[]={
  139227. {1,0, &_residue_44_mid_un,
  139228. &_huff_book__44u6__short,&_huff_book__44u6__short,
  139229. &_resbook_44u_6,&_resbook_44u_6},
  139230. {1,0, &_residue_44_mid_un,
  139231. &_huff_book__44u6__long,&_huff_book__44u6__long,
  139232. &_resbook_44u_6,&_resbook_44u_6}
  139233. };
  139234. static vorbis_residue_template _res_44u_7[]={
  139235. {1,0, &_residue_44_mid_un,
  139236. &_huff_book__44u7__short,&_huff_book__44u7__short,
  139237. &_resbook_44u_7,&_resbook_44u_7},
  139238. {1,0, &_residue_44_mid_un,
  139239. &_huff_book__44u7__long,&_huff_book__44u7__long,
  139240. &_resbook_44u_7,&_resbook_44u_7}
  139241. };
  139242. static vorbis_residue_template _res_44u_8[]={
  139243. {1,0, &_residue_44_hi_un,
  139244. &_huff_book__44u8__short,&_huff_book__44u8__short,
  139245. &_resbook_44u_8,&_resbook_44u_8},
  139246. {1,0, &_residue_44_hi_un,
  139247. &_huff_book__44u8__long,&_huff_book__44u8__long,
  139248. &_resbook_44u_8,&_resbook_44u_8}
  139249. };
  139250. static vorbis_residue_template _res_44u_9[]={
  139251. {1,0, &_residue_44_hi_un,
  139252. &_huff_book__44u9__short,&_huff_book__44u9__short,
  139253. &_resbook_44u_9,&_resbook_44u_9},
  139254. {1,0, &_residue_44_hi_un,
  139255. &_huff_book__44u9__long,&_huff_book__44u9__long,
  139256. &_resbook_44u_9,&_resbook_44u_9}
  139257. };
  139258. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  139259. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  139260. { _map_nominal_u, _res_44u_0 }, /* 0 */
  139261. { _map_nominal_u, _res_44u_1 }, /* 1 */
  139262. { _map_nominal_u, _res_44u_2 }, /* 2 */
  139263. { _map_nominal_u, _res_44u_3 }, /* 3 */
  139264. { _map_nominal_u, _res_44u_4 }, /* 4 */
  139265. { _map_nominal_u, _res_44u_5 }, /* 5 */
  139266. { _map_nominal_u, _res_44u_6 }, /* 6 */
  139267. { _map_nominal_u, _res_44u_7 }, /* 7 */
  139268. { _map_nominal_u, _res_44u_8 }, /* 8 */
  139269. { _map_nominal_u, _res_44u_9 }, /* 9 */
  139270. };
  139271. /*** End of inlined file: residue_44u.h ***/
  139272. static double rate_mapping_44_un[12]={
  139273. 32000.,48000.,60000.,70000.,80000.,86000.,
  139274. 96000.,110000.,120000.,140000.,160000.,240001.
  139275. };
  139276. ve_setup_data_template ve_setup_44_uncoupled={
  139277. 11,
  139278. rate_mapping_44_un,
  139279. quality_mapping_44,
  139280. -1,
  139281. 40000,
  139282. 50000,
  139283. blocksize_short_44,
  139284. blocksize_long_44,
  139285. _psy_tone_masteratt_44,
  139286. _psy_tone_0dB,
  139287. _psy_tone_suppress,
  139288. _vp_tonemask_adj_otherblock,
  139289. _vp_tonemask_adj_longblock,
  139290. _vp_tonemask_adj_otherblock,
  139291. _psy_noiseguards_44,
  139292. _psy_noisebias_impulse,
  139293. _psy_noisebias_padding,
  139294. _psy_noisebias_trans,
  139295. _psy_noisebias_long,
  139296. _psy_noise_suppress,
  139297. _psy_compand_44,
  139298. _psy_compand_short_mapping,
  139299. _psy_compand_long_mapping,
  139300. {_noise_start_short_44,_noise_start_long_44},
  139301. {_noise_part_short_44,_noise_part_long_44},
  139302. _noise_thresh_44,
  139303. _psy_ath_floater,
  139304. _psy_ath_abs,
  139305. _psy_lowpass_44,
  139306. _psy_global_44,
  139307. _global_mapping_44,
  139308. NULL,
  139309. _floor_books,
  139310. _floor,
  139311. _floor_short_mapping_44,
  139312. _floor_long_mapping_44,
  139313. _mapres_template_44_uncoupled
  139314. };
  139315. /*** End of inlined file: setup_44u.h ***/
  139316. /*** Start of inlined file: setup_32.h ***/
  139317. static double rate_mapping_32[12]={
  139318. 18000.,28000.,35000.,45000.,56000.,60000.,
  139319. 75000.,90000.,100000.,115000.,150000.,190000.,
  139320. };
  139321. static double rate_mapping_32_un[12]={
  139322. 30000.,42000.,52000.,64000.,72000.,78000.,
  139323. 86000.,92000.,110000.,120000.,140000.,190000.,
  139324. };
  139325. static double _psy_lowpass_32[12]={
  139326. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139327. };
  139328. ve_setup_data_template ve_setup_32_stereo={
  139329. 11,
  139330. rate_mapping_32,
  139331. quality_mapping_44,
  139332. 2,
  139333. 26000,
  139334. 40000,
  139335. blocksize_short_44,
  139336. blocksize_long_44,
  139337. _psy_tone_masteratt_44,
  139338. _psy_tone_0dB,
  139339. _psy_tone_suppress,
  139340. _vp_tonemask_adj_otherblock,
  139341. _vp_tonemask_adj_longblock,
  139342. _vp_tonemask_adj_otherblock,
  139343. _psy_noiseguards_44,
  139344. _psy_noisebias_impulse,
  139345. _psy_noisebias_padding,
  139346. _psy_noisebias_trans,
  139347. _psy_noisebias_long,
  139348. _psy_noise_suppress,
  139349. _psy_compand_44,
  139350. _psy_compand_short_mapping,
  139351. _psy_compand_long_mapping,
  139352. {_noise_start_short_44,_noise_start_long_44},
  139353. {_noise_part_short_44,_noise_part_long_44},
  139354. _noise_thresh_44,
  139355. _psy_ath_floater,
  139356. _psy_ath_abs,
  139357. _psy_lowpass_32,
  139358. _psy_global_44,
  139359. _global_mapping_44,
  139360. _psy_stereo_modes_44,
  139361. _floor_books,
  139362. _floor,
  139363. _floor_short_mapping_44,
  139364. _floor_long_mapping_44,
  139365. _mapres_template_44_stereo
  139366. };
  139367. ve_setup_data_template ve_setup_32_uncoupled={
  139368. 11,
  139369. rate_mapping_32_un,
  139370. quality_mapping_44,
  139371. -1,
  139372. 26000,
  139373. 40000,
  139374. blocksize_short_44,
  139375. blocksize_long_44,
  139376. _psy_tone_masteratt_44,
  139377. _psy_tone_0dB,
  139378. _psy_tone_suppress,
  139379. _vp_tonemask_adj_otherblock,
  139380. _vp_tonemask_adj_longblock,
  139381. _vp_tonemask_adj_otherblock,
  139382. _psy_noiseguards_44,
  139383. _psy_noisebias_impulse,
  139384. _psy_noisebias_padding,
  139385. _psy_noisebias_trans,
  139386. _psy_noisebias_long,
  139387. _psy_noise_suppress,
  139388. _psy_compand_44,
  139389. _psy_compand_short_mapping,
  139390. _psy_compand_long_mapping,
  139391. {_noise_start_short_44,_noise_start_long_44},
  139392. {_noise_part_short_44,_noise_part_long_44},
  139393. _noise_thresh_44,
  139394. _psy_ath_floater,
  139395. _psy_ath_abs,
  139396. _psy_lowpass_32,
  139397. _psy_global_44,
  139398. _global_mapping_44,
  139399. NULL,
  139400. _floor_books,
  139401. _floor,
  139402. _floor_short_mapping_44,
  139403. _floor_long_mapping_44,
  139404. _mapres_template_44_uncoupled
  139405. };
  139406. /*** End of inlined file: setup_32.h ***/
  139407. /*** Start of inlined file: setup_8.h ***/
  139408. /*** Start of inlined file: psych_8.h ***/
  139409. static att3 _psy_tone_masteratt_8[3]={
  139410. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139411. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139412. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139413. };
  139414. static vp_adjblock _vp_tonemask_adj_8[3]={
  139415. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139416. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139417. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139418. };
  139419. static noise3 _psy_noisebias_8[3]={
  139420. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139421. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139422. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139423. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139424. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139425. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139426. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139427. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139428. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139429. };
  139430. static adj_stereo _psy_stereo_modes_8[3]={
  139431. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139432. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139433. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139434. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139435. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139436. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139437. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139438. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139439. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139440. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139441. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139442. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139443. };
  139444. static noiseguard _psy_noiseguards_8[2]={
  139445. {10,10,-1},
  139446. {10,10,-1},
  139447. };
  139448. static compandblock _psy_compand_8[2]={
  139449. {{
  139450. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139451. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139452. 12,12,13,13,14,14,15, 15, /* 23dB */
  139453. 16,16,17,17,17,18,18, 19, /* 31dB */
  139454. 19,19,20,21,22,23,24, 25, /* 39dB */
  139455. }},
  139456. {{
  139457. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139458. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139459. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139460. 9,10,11,12,13,14,15, 16, /* 31dB */
  139461. 17,18,19,20,21,22,23, 24, /* 39dB */
  139462. }},
  139463. };
  139464. static double _psy_lowpass_8[3]={3.,4.,4.};
  139465. static int _noise_start_8[2]={
  139466. 64,64,
  139467. };
  139468. static int _noise_part_8[2]={
  139469. 8,8,
  139470. };
  139471. static int _psy_ath_floater_8[3]={
  139472. -100,-100,-105,
  139473. };
  139474. static int _psy_ath_abs_8[3]={
  139475. -130,-130,-140,
  139476. };
  139477. /*** End of inlined file: psych_8.h ***/
  139478. /*** Start of inlined file: residue_8.h ***/
  139479. static static_bookblock _resbook_8s_0={
  139480. {
  139481. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139482. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139483. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139484. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139485. }
  139486. };
  139487. static static_bookblock _resbook_8s_1={
  139488. {
  139489. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139490. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139491. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139492. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139493. }
  139494. };
  139495. static vorbis_residue_template _res_8s_0[]={
  139496. {2,0, &_residue_44_mid,
  139497. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139498. &_resbook_8s_0,&_resbook_8s_0},
  139499. };
  139500. static vorbis_residue_template _res_8s_1[]={
  139501. {2,0, &_residue_44_mid,
  139502. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139503. &_resbook_8s_1,&_resbook_8s_1},
  139504. };
  139505. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139506. { _map_nominal, _res_8s_0 }, /* 0 */
  139507. { _map_nominal, _res_8s_1 }, /* 1 */
  139508. };
  139509. static static_bookblock _resbook_8u_0={
  139510. {
  139511. {0},
  139512. {0,0,&_8u0__p1_0},
  139513. {0,0,&_8u0__p2_0},
  139514. {0,0,&_8u0__p3_0},
  139515. {0,0,&_8u0__p4_0},
  139516. {0,0,&_8u0__p5_0},
  139517. {&_8u0__p6_0,&_8u0__p6_1},
  139518. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139519. }
  139520. };
  139521. static static_bookblock _resbook_8u_1={
  139522. {
  139523. {0},
  139524. {0,0,&_8u1__p1_0},
  139525. {0,0,&_8u1__p2_0},
  139526. {0,0,&_8u1__p3_0},
  139527. {0,0,&_8u1__p4_0},
  139528. {0,0,&_8u1__p5_0},
  139529. {0,0,&_8u1__p6_0},
  139530. {&_8u1__p7_0,&_8u1__p7_1},
  139531. {&_8u1__p8_0,&_8u1__p8_1},
  139532. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139533. }
  139534. };
  139535. static vorbis_residue_template _res_8u_0[]={
  139536. {1,0, &_residue_44_low_un,
  139537. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139538. &_resbook_8u_0,&_resbook_8u_0},
  139539. };
  139540. static vorbis_residue_template _res_8u_1[]={
  139541. {1,0, &_residue_44_mid_un,
  139542. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139543. &_resbook_8u_1,&_resbook_8u_1},
  139544. };
  139545. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139546. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139547. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139548. };
  139549. /*** End of inlined file: residue_8.h ***/
  139550. static int blocksize_8[2]={
  139551. 512,512
  139552. };
  139553. static int _floor_mapping_8[2]={
  139554. 6,6,
  139555. };
  139556. static double rate_mapping_8[3]={
  139557. 6000.,9000.,32000.,
  139558. };
  139559. static double rate_mapping_8_uncoupled[3]={
  139560. 8000.,14000.,42000.,
  139561. };
  139562. static double quality_mapping_8[3]={
  139563. -.1,.0,1.
  139564. };
  139565. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139566. static double _global_mapping_8[3]={ 1., 2., 3. };
  139567. ve_setup_data_template ve_setup_8_stereo={
  139568. 2,
  139569. rate_mapping_8,
  139570. quality_mapping_8,
  139571. 2,
  139572. 8000,
  139573. 9000,
  139574. blocksize_8,
  139575. blocksize_8,
  139576. _psy_tone_masteratt_8,
  139577. _psy_tone_0dB,
  139578. _psy_tone_suppress,
  139579. _vp_tonemask_adj_8,
  139580. NULL,
  139581. _vp_tonemask_adj_8,
  139582. _psy_noiseguards_8,
  139583. _psy_noisebias_8,
  139584. _psy_noisebias_8,
  139585. NULL,
  139586. NULL,
  139587. _psy_noise_suppress,
  139588. _psy_compand_8,
  139589. _psy_compand_8_mapping,
  139590. NULL,
  139591. {_noise_start_8,_noise_start_8},
  139592. {_noise_part_8,_noise_part_8},
  139593. _noise_thresh_5only,
  139594. _psy_ath_floater_8,
  139595. _psy_ath_abs_8,
  139596. _psy_lowpass_8,
  139597. _psy_global_44,
  139598. _global_mapping_8,
  139599. _psy_stereo_modes_8,
  139600. _floor_books,
  139601. _floor,
  139602. _floor_mapping_8,
  139603. NULL,
  139604. _mapres_template_8_stereo
  139605. };
  139606. ve_setup_data_template ve_setup_8_uncoupled={
  139607. 2,
  139608. rate_mapping_8_uncoupled,
  139609. quality_mapping_8,
  139610. -1,
  139611. 8000,
  139612. 9000,
  139613. blocksize_8,
  139614. blocksize_8,
  139615. _psy_tone_masteratt_8,
  139616. _psy_tone_0dB,
  139617. _psy_tone_suppress,
  139618. _vp_tonemask_adj_8,
  139619. NULL,
  139620. _vp_tonemask_adj_8,
  139621. _psy_noiseguards_8,
  139622. _psy_noisebias_8,
  139623. _psy_noisebias_8,
  139624. NULL,
  139625. NULL,
  139626. _psy_noise_suppress,
  139627. _psy_compand_8,
  139628. _psy_compand_8_mapping,
  139629. NULL,
  139630. {_noise_start_8,_noise_start_8},
  139631. {_noise_part_8,_noise_part_8},
  139632. _noise_thresh_5only,
  139633. _psy_ath_floater_8,
  139634. _psy_ath_abs_8,
  139635. _psy_lowpass_8,
  139636. _psy_global_44,
  139637. _global_mapping_8,
  139638. _psy_stereo_modes_8,
  139639. _floor_books,
  139640. _floor,
  139641. _floor_mapping_8,
  139642. NULL,
  139643. _mapres_template_8_uncoupled
  139644. };
  139645. /*** End of inlined file: setup_8.h ***/
  139646. /*** Start of inlined file: setup_11.h ***/
  139647. /*** Start of inlined file: psych_11.h ***/
  139648. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139649. static att3 _psy_tone_masteratt_11[3]={
  139650. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139651. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139652. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139653. };
  139654. static vp_adjblock _vp_tonemask_adj_11[3]={
  139655. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139656. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139657. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139658. };
  139659. static noise3 _psy_noisebias_11[3]={
  139660. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139661. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139662. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139663. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139664. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139665. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139666. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139667. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139668. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139669. };
  139670. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139671. /*** End of inlined file: psych_11.h ***/
  139672. static int blocksize_11[2]={
  139673. 512,512
  139674. };
  139675. static int _floor_mapping_11[2]={
  139676. 6,6,
  139677. };
  139678. static double rate_mapping_11[3]={
  139679. 8000.,13000.,44000.,
  139680. };
  139681. static double rate_mapping_11_uncoupled[3]={
  139682. 12000.,20000.,50000.,
  139683. };
  139684. static double quality_mapping_11[3]={
  139685. -.1,.0,1.
  139686. };
  139687. ve_setup_data_template ve_setup_11_stereo={
  139688. 2,
  139689. rate_mapping_11,
  139690. quality_mapping_11,
  139691. 2,
  139692. 9000,
  139693. 15000,
  139694. blocksize_11,
  139695. blocksize_11,
  139696. _psy_tone_masteratt_11,
  139697. _psy_tone_0dB,
  139698. _psy_tone_suppress,
  139699. _vp_tonemask_adj_11,
  139700. NULL,
  139701. _vp_tonemask_adj_11,
  139702. _psy_noiseguards_8,
  139703. _psy_noisebias_11,
  139704. _psy_noisebias_11,
  139705. NULL,
  139706. NULL,
  139707. _psy_noise_suppress,
  139708. _psy_compand_8,
  139709. _psy_compand_8_mapping,
  139710. NULL,
  139711. {_noise_start_8,_noise_start_8},
  139712. {_noise_part_8,_noise_part_8},
  139713. _noise_thresh_11,
  139714. _psy_ath_floater_8,
  139715. _psy_ath_abs_8,
  139716. _psy_lowpass_11,
  139717. _psy_global_44,
  139718. _global_mapping_8,
  139719. _psy_stereo_modes_8,
  139720. _floor_books,
  139721. _floor,
  139722. _floor_mapping_11,
  139723. NULL,
  139724. _mapres_template_8_stereo
  139725. };
  139726. ve_setup_data_template ve_setup_11_uncoupled={
  139727. 2,
  139728. rate_mapping_11_uncoupled,
  139729. quality_mapping_11,
  139730. -1,
  139731. 9000,
  139732. 15000,
  139733. blocksize_11,
  139734. blocksize_11,
  139735. _psy_tone_masteratt_11,
  139736. _psy_tone_0dB,
  139737. _psy_tone_suppress,
  139738. _vp_tonemask_adj_11,
  139739. NULL,
  139740. _vp_tonemask_adj_11,
  139741. _psy_noiseguards_8,
  139742. _psy_noisebias_11,
  139743. _psy_noisebias_11,
  139744. NULL,
  139745. NULL,
  139746. _psy_noise_suppress,
  139747. _psy_compand_8,
  139748. _psy_compand_8_mapping,
  139749. NULL,
  139750. {_noise_start_8,_noise_start_8},
  139751. {_noise_part_8,_noise_part_8},
  139752. _noise_thresh_11,
  139753. _psy_ath_floater_8,
  139754. _psy_ath_abs_8,
  139755. _psy_lowpass_11,
  139756. _psy_global_44,
  139757. _global_mapping_8,
  139758. _psy_stereo_modes_8,
  139759. _floor_books,
  139760. _floor,
  139761. _floor_mapping_11,
  139762. NULL,
  139763. _mapres_template_8_uncoupled
  139764. };
  139765. /*** End of inlined file: setup_11.h ***/
  139766. /*** Start of inlined file: setup_16.h ***/
  139767. /*** Start of inlined file: psych_16.h ***/
  139768. static adj_stereo _psy_stereo_modes_16[4]={
  139769. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139770. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139771. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139772. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139773. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139774. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139775. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139776. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139777. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139778. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139779. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139780. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139781. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139782. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139783. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139784. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139785. };
  139786. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139787. static att3 _psy_tone_masteratt_16[4]={
  139788. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139789. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139790. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139791. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139792. };
  139793. static vp_adjblock _vp_tonemask_adj_16[4]={
  139794. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139795. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139796. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139797. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139798. };
  139799. static noise3 _psy_noisebias_16_short[4]={
  139800. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139801. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139802. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139803. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139804. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139805. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139806. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139807. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139808. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139809. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139810. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139811. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139812. };
  139813. static noise3 _psy_noisebias_16_impulse[4]={
  139814. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139815. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139816. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139817. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139818. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139819. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139820. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139821. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139822. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139823. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139824. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139825. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139826. };
  139827. static noise3 _psy_noisebias_16[4]={
  139828. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139829. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139830. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139831. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139832. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139833. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139834. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139835. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139836. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139837. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139838. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139839. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139840. };
  139841. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139842. static int _noise_start_16[3]={ 256,256,9999 };
  139843. static int _noise_part_16[4]={ 8,8,8,8 };
  139844. static int _psy_ath_floater_16[4]={
  139845. -100,-100,-100,-105,
  139846. };
  139847. static int _psy_ath_abs_16[4]={
  139848. -130,-130,-130,-140,
  139849. };
  139850. /*** End of inlined file: psych_16.h ***/
  139851. /*** Start of inlined file: residue_16.h ***/
  139852. static static_bookblock _resbook_16s_0={
  139853. {
  139854. {0},
  139855. {0,0,&_16c0_s_p1_0},
  139856. {0,0,&_16c0_s_p2_0},
  139857. {0,0,&_16c0_s_p3_0},
  139858. {0,0,&_16c0_s_p4_0},
  139859. {0,0,&_16c0_s_p5_0},
  139860. {0,0,&_16c0_s_p6_0},
  139861. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139862. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139863. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139864. }
  139865. };
  139866. static static_bookblock _resbook_16s_1={
  139867. {
  139868. {0},
  139869. {0,0,&_16c1_s_p1_0},
  139870. {0,0,&_16c1_s_p2_0},
  139871. {0,0,&_16c1_s_p3_0},
  139872. {0,0,&_16c1_s_p4_0},
  139873. {0,0,&_16c1_s_p5_0},
  139874. {0,0,&_16c1_s_p6_0},
  139875. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139876. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139877. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139878. }
  139879. };
  139880. static static_bookblock _resbook_16s_2={
  139881. {
  139882. {0},
  139883. {0,0,&_16c2_s_p1_0},
  139884. {0,0,&_16c2_s_p2_0},
  139885. {0,0,&_16c2_s_p3_0},
  139886. {0,0,&_16c2_s_p4_0},
  139887. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139888. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139889. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139890. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139891. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139892. }
  139893. };
  139894. static vorbis_residue_template _res_16s_0[]={
  139895. {2,0, &_residue_44_mid,
  139896. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139897. &_resbook_16s_0,&_resbook_16s_0},
  139898. };
  139899. static vorbis_residue_template _res_16s_1[]={
  139900. {2,0, &_residue_44_mid,
  139901. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139902. &_resbook_16s_1,&_resbook_16s_1},
  139903. {2,0, &_residue_44_mid,
  139904. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139905. &_resbook_16s_1,&_resbook_16s_1}
  139906. };
  139907. static vorbis_residue_template _res_16s_2[]={
  139908. {2,0, &_residue_44_high,
  139909. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139910. &_resbook_16s_2,&_resbook_16s_2},
  139911. {2,0, &_residue_44_high,
  139912. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139913. &_resbook_16s_2,&_resbook_16s_2}
  139914. };
  139915. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139916. { _map_nominal, _res_16s_0 }, /* 0 */
  139917. { _map_nominal, _res_16s_1 }, /* 1 */
  139918. { _map_nominal, _res_16s_2 }, /* 2 */
  139919. };
  139920. static static_bookblock _resbook_16u_0={
  139921. {
  139922. {0},
  139923. {0,0,&_16u0__p1_0},
  139924. {0,0,&_16u0__p2_0},
  139925. {0,0,&_16u0__p3_0},
  139926. {0,0,&_16u0__p4_0},
  139927. {0,0,&_16u0__p5_0},
  139928. {&_16u0__p6_0,&_16u0__p6_1},
  139929. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139930. }
  139931. };
  139932. static static_bookblock _resbook_16u_1={
  139933. {
  139934. {0},
  139935. {0,0,&_16u1__p1_0},
  139936. {0,0,&_16u1__p2_0},
  139937. {0,0,&_16u1__p3_0},
  139938. {0,0,&_16u1__p4_0},
  139939. {0,0,&_16u1__p5_0},
  139940. {0,0,&_16u1__p6_0},
  139941. {&_16u1__p7_0,&_16u1__p7_1},
  139942. {&_16u1__p8_0,&_16u1__p8_1},
  139943. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139944. }
  139945. };
  139946. static static_bookblock _resbook_16u_2={
  139947. {
  139948. {0},
  139949. {0,0,&_16u2_p1_0},
  139950. {0,0,&_16u2_p2_0},
  139951. {0,0,&_16u2_p3_0},
  139952. {0,0,&_16u2_p4_0},
  139953. {&_16u2_p5_0,&_16u2_p5_1},
  139954. {&_16u2_p6_0,&_16u2_p6_1},
  139955. {&_16u2_p7_0,&_16u2_p7_1},
  139956. {&_16u2_p8_0,&_16u2_p8_1},
  139957. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139958. }
  139959. };
  139960. static vorbis_residue_template _res_16u_0[]={
  139961. {1,0, &_residue_44_low_un,
  139962. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139963. &_resbook_16u_0,&_resbook_16u_0},
  139964. };
  139965. static vorbis_residue_template _res_16u_1[]={
  139966. {1,0, &_residue_44_mid_un,
  139967. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139968. &_resbook_16u_1,&_resbook_16u_1},
  139969. {1,0, &_residue_44_mid_un,
  139970. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139971. &_resbook_16u_1,&_resbook_16u_1}
  139972. };
  139973. static vorbis_residue_template _res_16u_2[]={
  139974. {1,0, &_residue_44_hi_un,
  139975. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139976. &_resbook_16u_2,&_resbook_16u_2},
  139977. {1,0, &_residue_44_hi_un,
  139978. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139979. &_resbook_16u_2,&_resbook_16u_2}
  139980. };
  139981. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139982. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139983. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139984. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139985. };
  139986. /*** End of inlined file: residue_16.h ***/
  139987. static int blocksize_16_short[3]={
  139988. 1024,512,512
  139989. };
  139990. static int blocksize_16_long[3]={
  139991. 1024,1024,1024
  139992. };
  139993. static int _floor_mapping_16_short[3]={
  139994. 9,3,3
  139995. };
  139996. static int _floor_mapping_16[3]={
  139997. 9,9,9
  139998. };
  139999. static double rate_mapping_16[4]={
  140000. 12000.,20000.,44000.,86000.
  140001. };
  140002. static double rate_mapping_16_uncoupled[4]={
  140003. 16000.,28000.,64000.,100000.
  140004. };
  140005. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  140006. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  140007. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  140008. ve_setup_data_template ve_setup_16_stereo={
  140009. 3,
  140010. rate_mapping_16,
  140011. quality_mapping_16,
  140012. 2,
  140013. 15000,
  140014. 19000,
  140015. blocksize_16_short,
  140016. blocksize_16_long,
  140017. _psy_tone_masteratt_16,
  140018. _psy_tone_0dB,
  140019. _psy_tone_suppress,
  140020. _vp_tonemask_adj_16,
  140021. _vp_tonemask_adj_16,
  140022. _vp_tonemask_adj_16,
  140023. _psy_noiseguards_8,
  140024. _psy_noisebias_16_impulse,
  140025. _psy_noisebias_16_short,
  140026. _psy_noisebias_16_short,
  140027. _psy_noisebias_16,
  140028. _psy_noise_suppress,
  140029. _psy_compand_8,
  140030. _psy_compand_16_mapping,
  140031. _psy_compand_16_mapping,
  140032. {_noise_start_16,_noise_start_16},
  140033. { _noise_part_16, _noise_part_16},
  140034. _noise_thresh_16,
  140035. _psy_ath_floater_16,
  140036. _psy_ath_abs_16,
  140037. _psy_lowpass_16,
  140038. _psy_global_44,
  140039. _global_mapping_16,
  140040. _psy_stereo_modes_16,
  140041. _floor_books,
  140042. _floor,
  140043. _floor_mapping_16_short,
  140044. _floor_mapping_16,
  140045. _mapres_template_16_stereo
  140046. };
  140047. ve_setup_data_template ve_setup_16_uncoupled={
  140048. 3,
  140049. rate_mapping_16_uncoupled,
  140050. quality_mapping_16,
  140051. -1,
  140052. 15000,
  140053. 19000,
  140054. blocksize_16_short,
  140055. blocksize_16_long,
  140056. _psy_tone_masteratt_16,
  140057. _psy_tone_0dB,
  140058. _psy_tone_suppress,
  140059. _vp_tonemask_adj_16,
  140060. _vp_tonemask_adj_16,
  140061. _vp_tonemask_adj_16,
  140062. _psy_noiseguards_8,
  140063. _psy_noisebias_16_impulse,
  140064. _psy_noisebias_16_short,
  140065. _psy_noisebias_16_short,
  140066. _psy_noisebias_16,
  140067. _psy_noise_suppress,
  140068. _psy_compand_8,
  140069. _psy_compand_16_mapping,
  140070. _psy_compand_16_mapping,
  140071. {_noise_start_16,_noise_start_16},
  140072. { _noise_part_16, _noise_part_16},
  140073. _noise_thresh_16,
  140074. _psy_ath_floater_16,
  140075. _psy_ath_abs_16,
  140076. _psy_lowpass_16,
  140077. _psy_global_44,
  140078. _global_mapping_16,
  140079. _psy_stereo_modes_16,
  140080. _floor_books,
  140081. _floor,
  140082. _floor_mapping_16_short,
  140083. _floor_mapping_16,
  140084. _mapres_template_16_uncoupled
  140085. };
  140086. /*** End of inlined file: setup_16.h ***/
  140087. /*** Start of inlined file: setup_22.h ***/
  140088. static double rate_mapping_22[4]={
  140089. 15000.,20000.,44000.,86000.
  140090. };
  140091. static double rate_mapping_22_uncoupled[4]={
  140092. 16000.,28000.,50000.,90000.
  140093. };
  140094. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  140095. ve_setup_data_template ve_setup_22_stereo={
  140096. 3,
  140097. rate_mapping_22,
  140098. quality_mapping_16,
  140099. 2,
  140100. 19000,
  140101. 26000,
  140102. blocksize_16_short,
  140103. blocksize_16_long,
  140104. _psy_tone_masteratt_16,
  140105. _psy_tone_0dB,
  140106. _psy_tone_suppress,
  140107. _vp_tonemask_adj_16,
  140108. _vp_tonemask_adj_16,
  140109. _vp_tonemask_adj_16,
  140110. _psy_noiseguards_8,
  140111. _psy_noisebias_16_impulse,
  140112. _psy_noisebias_16_short,
  140113. _psy_noisebias_16_short,
  140114. _psy_noisebias_16,
  140115. _psy_noise_suppress,
  140116. _psy_compand_8,
  140117. _psy_compand_8_mapping,
  140118. _psy_compand_8_mapping,
  140119. {_noise_start_16,_noise_start_16},
  140120. { _noise_part_16, _noise_part_16},
  140121. _noise_thresh_16,
  140122. _psy_ath_floater_16,
  140123. _psy_ath_abs_16,
  140124. _psy_lowpass_22,
  140125. _psy_global_44,
  140126. _global_mapping_16,
  140127. _psy_stereo_modes_16,
  140128. _floor_books,
  140129. _floor,
  140130. _floor_mapping_16_short,
  140131. _floor_mapping_16,
  140132. _mapres_template_16_stereo
  140133. };
  140134. ve_setup_data_template ve_setup_22_uncoupled={
  140135. 3,
  140136. rate_mapping_22_uncoupled,
  140137. quality_mapping_16,
  140138. -1,
  140139. 19000,
  140140. 26000,
  140141. blocksize_16_short,
  140142. blocksize_16_long,
  140143. _psy_tone_masteratt_16,
  140144. _psy_tone_0dB,
  140145. _psy_tone_suppress,
  140146. _vp_tonemask_adj_16,
  140147. _vp_tonemask_adj_16,
  140148. _vp_tonemask_adj_16,
  140149. _psy_noiseguards_8,
  140150. _psy_noisebias_16_impulse,
  140151. _psy_noisebias_16_short,
  140152. _psy_noisebias_16_short,
  140153. _psy_noisebias_16,
  140154. _psy_noise_suppress,
  140155. _psy_compand_8,
  140156. _psy_compand_8_mapping,
  140157. _psy_compand_8_mapping,
  140158. {_noise_start_16,_noise_start_16},
  140159. { _noise_part_16, _noise_part_16},
  140160. _noise_thresh_16,
  140161. _psy_ath_floater_16,
  140162. _psy_ath_abs_16,
  140163. _psy_lowpass_22,
  140164. _psy_global_44,
  140165. _global_mapping_16,
  140166. _psy_stereo_modes_16,
  140167. _floor_books,
  140168. _floor,
  140169. _floor_mapping_16_short,
  140170. _floor_mapping_16,
  140171. _mapres_template_16_uncoupled
  140172. };
  140173. /*** End of inlined file: setup_22.h ***/
  140174. /*** Start of inlined file: setup_X.h ***/
  140175. static double rate_mapping_X[12]={
  140176. -1.,-1.,-1.,-1.,-1.,-1.,
  140177. -1.,-1.,-1.,-1.,-1.,-1.
  140178. };
  140179. ve_setup_data_template ve_setup_X_stereo={
  140180. 11,
  140181. rate_mapping_X,
  140182. quality_mapping_44,
  140183. 2,
  140184. 50000,
  140185. 200000,
  140186. blocksize_short_44,
  140187. blocksize_long_44,
  140188. _psy_tone_masteratt_44,
  140189. _psy_tone_0dB,
  140190. _psy_tone_suppress,
  140191. _vp_tonemask_adj_otherblock,
  140192. _vp_tonemask_adj_longblock,
  140193. _vp_tonemask_adj_otherblock,
  140194. _psy_noiseguards_44,
  140195. _psy_noisebias_impulse,
  140196. _psy_noisebias_padding,
  140197. _psy_noisebias_trans,
  140198. _psy_noisebias_long,
  140199. _psy_noise_suppress,
  140200. _psy_compand_44,
  140201. _psy_compand_short_mapping,
  140202. _psy_compand_long_mapping,
  140203. {_noise_start_short_44,_noise_start_long_44},
  140204. {_noise_part_short_44,_noise_part_long_44},
  140205. _noise_thresh_44,
  140206. _psy_ath_floater,
  140207. _psy_ath_abs,
  140208. _psy_lowpass_44,
  140209. _psy_global_44,
  140210. _global_mapping_44,
  140211. _psy_stereo_modes_44,
  140212. _floor_books,
  140213. _floor,
  140214. _floor_short_mapping_44,
  140215. _floor_long_mapping_44,
  140216. _mapres_template_44_stereo
  140217. };
  140218. ve_setup_data_template ve_setup_X_uncoupled={
  140219. 11,
  140220. rate_mapping_X,
  140221. quality_mapping_44,
  140222. -1,
  140223. 50000,
  140224. 200000,
  140225. blocksize_short_44,
  140226. blocksize_long_44,
  140227. _psy_tone_masteratt_44,
  140228. _psy_tone_0dB,
  140229. _psy_tone_suppress,
  140230. _vp_tonemask_adj_otherblock,
  140231. _vp_tonemask_adj_longblock,
  140232. _vp_tonemask_adj_otherblock,
  140233. _psy_noiseguards_44,
  140234. _psy_noisebias_impulse,
  140235. _psy_noisebias_padding,
  140236. _psy_noisebias_trans,
  140237. _psy_noisebias_long,
  140238. _psy_noise_suppress,
  140239. _psy_compand_44,
  140240. _psy_compand_short_mapping,
  140241. _psy_compand_long_mapping,
  140242. {_noise_start_short_44,_noise_start_long_44},
  140243. {_noise_part_short_44,_noise_part_long_44},
  140244. _noise_thresh_44,
  140245. _psy_ath_floater,
  140246. _psy_ath_abs,
  140247. _psy_lowpass_44,
  140248. _psy_global_44,
  140249. _global_mapping_44,
  140250. NULL,
  140251. _floor_books,
  140252. _floor,
  140253. _floor_short_mapping_44,
  140254. _floor_long_mapping_44,
  140255. _mapres_template_44_uncoupled
  140256. };
  140257. ve_setup_data_template ve_setup_XX_stereo={
  140258. 2,
  140259. rate_mapping_X,
  140260. quality_mapping_8,
  140261. 2,
  140262. 0,
  140263. 8000,
  140264. blocksize_8,
  140265. blocksize_8,
  140266. _psy_tone_masteratt_8,
  140267. _psy_tone_0dB,
  140268. _psy_tone_suppress,
  140269. _vp_tonemask_adj_8,
  140270. NULL,
  140271. _vp_tonemask_adj_8,
  140272. _psy_noiseguards_8,
  140273. _psy_noisebias_8,
  140274. _psy_noisebias_8,
  140275. NULL,
  140276. NULL,
  140277. _psy_noise_suppress,
  140278. _psy_compand_8,
  140279. _psy_compand_8_mapping,
  140280. NULL,
  140281. {_noise_start_8,_noise_start_8},
  140282. {_noise_part_8,_noise_part_8},
  140283. _noise_thresh_5only,
  140284. _psy_ath_floater_8,
  140285. _psy_ath_abs_8,
  140286. _psy_lowpass_8,
  140287. _psy_global_44,
  140288. _global_mapping_8,
  140289. _psy_stereo_modes_8,
  140290. _floor_books,
  140291. _floor,
  140292. _floor_mapping_8,
  140293. NULL,
  140294. _mapres_template_8_stereo
  140295. };
  140296. ve_setup_data_template ve_setup_XX_uncoupled={
  140297. 2,
  140298. rate_mapping_X,
  140299. quality_mapping_8,
  140300. -1,
  140301. 0,
  140302. 8000,
  140303. blocksize_8,
  140304. blocksize_8,
  140305. _psy_tone_masteratt_8,
  140306. _psy_tone_0dB,
  140307. _psy_tone_suppress,
  140308. _vp_tonemask_adj_8,
  140309. NULL,
  140310. _vp_tonemask_adj_8,
  140311. _psy_noiseguards_8,
  140312. _psy_noisebias_8,
  140313. _psy_noisebias_8,
  140314. NULL,
  140315. NULL,
  140316. _psy_noise_suppress,
  140317. _psy_compand_8,
  140318. _psy_compand_8_mapping,
  140319. NULL,
  140320. {_noise_start_8,_noise_start_8},
  140321. {_noise_part_8,_noise_part_8},
  140322. _noise_thresh_5only,
  140323. _psy_ath_floater_8,
  140324. _psy_ath_abs_8,
  140325. _psy_lowpass_8,
  140326. _psy_global_44,
  140327. _global_mapping_8,
  140328. _psy_stereo_modes_8,
  140329. _floor_books,
  140330. _floor,
  140331. _floor_mapping_8,
  140332. NULL,
  140333. _mapres_template_8_uncoupled
  140334. };
  140335. /*** End of inlined file: setup_X.h ***/
  140336. static ve_setup_data_template *setup_list[]={
  140337. &ve_setup_44_stereo,
  140338. &ve_setup_44_uncoupled,
  140339. &ve_setup_32_stereo,
  140340. &ve_setup_32_uncoupled,
  140341. &ve_setup_22_stereo,
  140342. &ve_setup_22_uncoupled,
  140343. &ve_setup_16_stereo,
  140344. &ve_setup_16_uncoupled,
  140345. &ve_setup_11_stereo,
  140346. &ve_setup_11_uncoupled,
  140347. &ve_setup_8_stereo,
  140348. &ve_setup_8_uncoupled,
  140349. &ve_setup_X_stereo,
  140350. &ve_setup_X_uncoupled,
  140351. &ve_setup_XX_stereo,
  140352. &ve_setup_XX_uncoupled,
  140353. 0
  140354. };
  140355. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140356. if(vi && vi->codec_setup){
  140357. vi->version=0;
  140358. vi->channels=ch;
  140359. vi->rate=rate;
  140360. return(0);
  140361. }
  140362. return(OV_EINVAL);
  140363. }
  140364. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140365. static_codebook ***books,
  140366. vorbis_info_floor1 *in,
  140367. int *x){
  140368. int i,k,is=s;
  140369. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140370. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140371. memcpy(f,in+x[is],sizeof(*f));
  140372. f->n=ci->blocksizes[block]>>1;
  140373. {
  140374. int partitions=f->partitions;
  140375. int maxclass=-1;
  140376. int maxbook=-1;
  140377. for(i=0;i<partitions;i++)
  140378. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140379. for(i=0;i<=maxclass;i++){
  140380. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140381. f->class_book[i]+=ci->books;
  140382. for(k=0;k<(1<<f->class_subs[i]);k++){
  140383. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140384. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140385. }
  140386. }
  140387. for(i=0;i<=maxbook;i++)
  140388. ci->book_param[ci->books++]=books[x[is]][i];
  140389. }
  140390. ci->floor_type[ci->floors]=1;
  140391. ci->floor_param[ci->floors]=f;
  140392. ci->floors++;
  140393. return;
  140394. }
  140395. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140396. vorbis_info_psy_global *in,
  140397. double *x){
  140398. int i,is=s;
  140399. double ds=s-is;
  140400. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140401. vorbis_info_psy_global *g=&ci->psy_g_param;
  140402. memcpy(g,in+(int)x[is],sizeof(*g));
  140403. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140404. is=(int)ds;
  140405. ds-=is;
  140406. if(ds==0 && is>0){
  140407. is--;
  140408. ds=1.;
  140409. }
  140410. for(i=0;i<4;i++){
  140411. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140412. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140413. }
  140414. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140415. return;
  140416. }
  140417. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140418. highlevel_encode_setup *hi,
  140419. adj_stereo *p){
  140420. float s=hi->stereo_point_setting;
  140421. int i,is=s;
  140422. double ds=s-is;
  140423. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140424. vorbis_info_psy_global *g=&ci->psy_g_param;
  140425. if(p){
  140426. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140427. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140428. if(hi->managed){
  140429. for(i=0;i<PACKETBLOBS;i++){
  140430. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140431. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140432. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140433. g->coupling_pkHz[i]=kHz;
  140434. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140435. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140436. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140437. }
  140438. }else{
  140439. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140440. for(i=0;i<PACKETBLOBS;i++){
  140441. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140442. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140443. g->coupling_pkHz[i]=kHz;
  140444. }
  140445. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140446. for(i=0;i<PACKETBLOBS;i++){
  140447. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140448. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140449. }
  140450. }
  140451. }else{
  140452. for(i=0;i<PACKETBLOBS;i++){
  140453. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140454. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140455. }
  140456. }
  140457. return;
  140458. }
  140459. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140460. int *nn_start,
  140461. int *nn_partition,
  140462. double *nn_thresh,
  140463. int block){
  140464. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140465. vorbis_info_psy *p=ci->psy_param[block];
  140466. highlevel_encode_setup *hi=&ci->hi;
  140467. int is=s;
  140468. if(block>=ci->psys)
  140469. ci->psys=block+1;
  140470. if(!p){
  140471. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140472. ci->psy_param[block]=p;
  140473. }
  140474. memcpy(p,&_psy_info_template,sizeof(*p));
  140475. p->blockflag=block>>1;
  140476. if(hi->noise_normalize_p){
  140477. p->normal_channel_p=1;
  140478. p->normal_point_p=1;
  140479. p->normal_start=nn_start[is];
  140480. p->normal_partition=nn_partition[is];
  140481. p->normal_thresh=nn_thresh[is];
  140482. }
  140483. return;
  140484. }
  140485. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140486. att3 *att,
  140487. int *max,
  140488. vp_adjblock *in){
  140489. int i,is=s;
  140490. double ds=s-is;
  140491. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140492. vorbis_info_psy *p=ci->psy_param[block];
  140493. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140494. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140495. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140496. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140497. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140498. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140499. for(i=0;i<P_BANDS;i++)
  140500. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140501. return;
  140502. }
  140503. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140504. compandblock *in, double *x){
  140505. int i,is=s;
  140506. double ds=s-is;
  140507. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140508. vorbis_info_psy *p=ci->psy_param[block];
  140509. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140510. is=(int)ds;
  140511. ds-=is;
  140512. if(ds==0 && is>0){
  140513. is--;
  140514. ds=1.;
  140515. }
  140516. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140517. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140518. return;
  140519. }
  140520. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140521. int *suppress){
  140522. int is=s;
  140523. double ds=s-is;
  140524. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140525. vorbis_info_psy *p=ci->psy_param[block];
  140526. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140527. return;
  140528. }
  140529. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140530. int *suppress,
  140531. noise3 *in,
  140532. noiseguard *guard,
  140533. double userbias){
  140534. int i,is=s,j;
  140535. double ds=s-is;
  140536. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140537. vorbis_info_psy *p=ci->psy_param[block];
  140538. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140539. p->noisewindowlomin=guard[block].lo;
  140540. p->noisewindowhimin=guard[block].hi;
  140541. p->noisewindowfixed=guard[block].fixed;
  140542. for(j=0;j<P_NOISECURVES;j++)
  140543. for(i=0;i<P_BANDS;i++)
  140544. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140545. for(j=0;j<P_NOISECURVES;j++){
  140546. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140547. for(i=0;i<P_BANDS;i++){
  140548. p->noiseoff[j][i]+=userbias;
  140549. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140550. }
  140551. }
  140552. return;
  140553. }
  140554. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140555. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140556. vorbis_info_psy *p=ci->psy_param[block];
  140557. p->ath_adjatt=ci->hi.ath_floating_dB;
  140558. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140559. return;
  140560. }
  140561. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140562. int i;
  140563. for(i=0;i<ci->books;i++)
  140564. if(ci->book_param[i]==book)return(i);
  140565. return(ci->books++);
  140566. }
  140567. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140568. int *shortb,int *longb){
  140569. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140570. int is=s;
  140571. int blockshort=shortb[is];
  140572. int blocklong=longb[is];
  140573. ci->blocksizes[0]=blockshort;
  140574. ci->blocksizes[1]=blocklong;
  140575. }
  140576. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140577. int number, int block,
  140578. vorbis_residue_template *res){
  140579. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140580. int i,n;
  140581. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140582. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140583. memcpy(r,res->res,sizeof(*r));
  140584. if(ci->residues<=number)ci->residues=number+1;
  140585. switch(ci->blocksizes[block]){
  140586. case 64:case 128:case 256:
  140587. r->grouping=16;
  140588. break;
  140589. default:
  140590. r->grouping=32;
  140591. break;
  140592. }
  140593. ci->residue_type[number]=res->res_type;
  140594. n=r->end=ci->blocksizes[block]>>1;
  140595. if(res->res_type==2)
  140596. n=r->end*=vi->channels;
  140597. {
  140598. int booklist=0,k;
  140599. if(ci->hi.managed){
  140600. for(i=0;i<r->partitions;i++)
  140601. for(k=0;k<3;k++)
  140602. if(res->books_base_managed->books[i][k])
  140603. r->secondstages[i]|=(1<<k);
  140604. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140605. ci->book_param[r->groupbook]=res->book_aux_managed;
  140606. for(i=0;i<r->partitions;i++){
  140607. for(k=0;k<3;k++){
  140608. if(res->books_base_managed->books[i][k]){
  140609. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140610. r->booklist[booklist++]=bookid;
  140611. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140612. }
  140613. }
  140614. }
  140615. }else{
  140616. for(i=0;i<r->partitions;i++)
  140617. for(k=0;k<3;k++)
  140618. if(res->books_base->books[i][k])
  140619. r->secondstages[i]|=(1<<k);
  140620. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140621. ci->book_param[r->groupbook]=res->book_aux;
  140622. for(i=0;i<r->partitions;i++){
  140623. for(k=0;k<3;k++){
  140624. if(res->books_base->books[i][k]){
  140625. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140626. r->booklist[booklist++]=bookid;
  140627. ci->book_param[bookid]=res->books_base->books[i][k];
  140628. }
  140629. }
  140630. }
  140631. }
  140632. }
  140633. {
  140634. double freq=ci->hi.lowpass_kHz*1000.;
  140635. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140636. double nyq=vi->rate/2.;
  140637. long blocksize=ci->blocksizes[block]>>1;
  140638. if(freq>nyq)freq=nyq;
  140639. f->n=freq/nyq*blocksize;
  140640. if(res->limit_type){
  140641. if(ci->hi.managed)
  140642. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140643. else
  140644. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140645. if(freq>nyq)freq=nyq;
  140646. }
  140647. if(ci->residue_type[block]==2)
  140648. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140649. r->grouping;
  140650. else
  140651. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140652. r->grouping;
  140653. }
  140654. }
  140655. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140656. vorbis_mapping_template *maps){
  140657. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140658. int i,j,is=s,modes=2;
  140659. vorbis_info_mapping0 *map=maps[is].map;
  140660. vorbis_info_mode *mode=_mode_template;
  140661. vorbis_residue_template *res=maps[is].res;
  140662. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140663. for(i=0;i<modes;i++){
  140664. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140665. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140666. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140667. if(i>=ci->modes)ci->modes=i+1;
  140668. ci->map_type[i]=0;
  140669. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140670. if(i>=ci->maps)ci->maps=i+1;
  140671. for(j=0;j<map[i].submaps;j++)
  140672. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140673. ,res+map[i].residuesubmap[j]);
  140674. }
  140675. }
  140676. static double setting_to_approx_bitrate(vorbis_info *vi){
  140677. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140678. highlevel_encode_setup *hi=&ci->hi;
  140679. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140680. int is=hi->base_setting;
  140681. double ds=hi->base_setting-is;
  140682. int ch=vi->channels;
  140683. double *r=setup->rate_mapping;
  140684. if(r==NULL)
  140685. return(-1);
  140686. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140687. }
  140688. static void get_setup_template(vorbis_info *vi,
  140689. long ch,long srate,
  140690. double req,int q_or_bitrate){
  140691. int i=0,j;
  140692. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140693. highlevel_encode_setup *hi=&ci->hi;
  140694. if(q_or_bitrate)req/=ch;
  140695. while(setup_list[i]){
  140696. if(setup_list[i]->coupling_restriction==-1 ||
  140697. setup_list[i]->coupling_restriction==ch){
  140698. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140699. srate<=setup_list[i]->samplerate_max_restriction){
  140700. int mappings=setup_list[i]->mappings;
  140701. double *map=(q_or_bitrate?
  140702. setup_list[i]->rate_mapping:
  140703. setup_list[i]->quality_mapping);
  140704. if(req<map[0]){++i;continue;}
  140705. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140706. for(j=0;j<mappings;j++)
  140707. if(req>=map[j] && req<map[j+1])break;
  140708. hi->setup=setup_list[i];
  140709. if(j==mappings)
  140710. hi->base_setting=j-.001;
  140711. else{
  140712. float low=map[j];
  140713. float high=map[j+1];
  140714. float del=(req-low)/(high-low);
  140715. hi->base_setting=j+del;
  140716. }
  140717. return;
  140718. }
  140719. }
  140720. i++;
  140721. }
  140722. hi->setup=NULL;
  140723. }
  140724. int vorbis_encode_setup_init(vorbis_info *vi){
  140725. int i0=0,singleblock=0;
  140726. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140727. ve_setup_data_template *setup=NULL;
  140728. highlevel_encode_setup *hi=&ci->hi;
  140729. if(ci==NULL)return(OV_EINVAL);
  140730. if(!hi->impulse_block_p)i0=1;
  140731. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140732. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140733. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140734. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140735. setup=(ve_setup_data_template *)hi->setup;
  140736. if(setup==NULL)return(OV_EINVAL);
  140737. hi->set_in_stone=1;
  140738. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140739. setup->blocksize_short,
  140740. setup->blocksize_long);
  140741. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140742. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140743. setup->floor_books,
  140744. setup->floor_params,
  140745. setup->floor_short_mapping);
  140746. if(!singleblock)
  140747. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140748. setup->floor_books,
  140749. setup->floor_params,
  140750. setup->floor_long_mapping);
  140751. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140752. setup->global_params,
  140753. setup->global_mapping);
  140754. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140755. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140756. setup->psy_noise_normal_start[0],
  140757. setup->psy_noise_normal_partition[0],
  140758. setup->psy_noise_normal_thresh,
  140759. 0);
  140760. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140761. setup->psy_noise_normal_start[0],
  140762. setup->psy_noise_normal_partition[0],
  140763. setup->psy_noise_normal_thresh,
  140764. 1);
  140765. if(!singleblock){
  140766. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140767. setup->psy_noise_normal_start[1],
  140768. setup->psy_noise_normal_partition[1],
  140769. setup->psy_noise_normal_thresh,
  140770. 2);
  140771. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140772. setup->psy_noise_normal_start[1],
  140773. setup->psy_noise_normal_partition[1],
  140774. setup->psy_noise_normal_thresh,
  140775. 3);
  140776. }
  140777. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140778. setup->psy_tone_masteratt,
  140779. setup->psy_tone_0dB,
  140780. setup->psy_tone_adj_impulse);
  140781. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140782. setup->psy_tone_masteratt,
  140783. setup->psy_tone_0dB,
  140784. setup->psy_tone_adj_other);
  140785. if(!singleblock){
  140786. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140787. setup->psy_tone_masteratt,
  140788. setup->psy_tone_0dB,
  140789. setup->psy_tone_adj_other);
  140790. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140791. setup->psy_tone_masteratt,
  140792. setup->psy_tone_0dB,
  140793. setup->psy_tone_adj_long);
  140794. }
  140795. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140796. setup->psy_noise_compand,
  140797. setup->psy_noise_compand_short_mapping);
  140798. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140799. setup->psy_noise_compand,
  140800. setup->psy_noise_compand_short_mapping);
  140801. if(!singleblock){
  140802. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140803. setup->psy_noise_compand,
  140804. setup->psy_noise_compand_long_mapping);
  140805. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140806. setup->psy_noise_compand,
  140807. setup->psy_noise_compand_long_mapping);
  140808. }
  140809. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140810. setup->psy_tone_dBsuppress);
  140811. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140812. setup->psy_tone_dBsuppress);
  140813. if(!singleblock){
  140814. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140815. setup->psy_tone_dBsuppress);
  140816. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140817. setup->psy_tone_dBsuppress);
  140818. }
  140819. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140820. setup->psy_noise_dBsuppress,
  140821. setup->psy_noise_bias_impulse,
  140822. setup->psy_noiseguards,
  140823. (i0==0?hi->impulse_noisetune:0.));
  140824. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140825. setup->psy_noise_dBsuppress,
  140826. setup->psy_noise_bias_padding,
  140827. setup->psy_noiseguards,0.);
  140828. if(!singleblock){
  140829. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140830. setup->psy_noise_dBsuppress,
  140831. setup->psy_noise_bias_trans,
  140832. setup->psy_noiseguards,0.);
  140833. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140834. setup->psy_noise_dBsuppress,
  140835. setup->psy_noise_bias_long,
  140836. setup->psy_noiseguards,0.);
  140837. }
  140838. vorbis_encode_ath_setup(vi,0);
  140839. vorbis_encode_ath_setup(vi,1);
  140840. if(!singleblock){
  140841. vorbis_encode_ath_setup(vi,2);
  140842. vorbis_encode_ath_setup(vi,3);
  140843. }
  140844. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140845. if(hi->bitrate_av>0)
  140846. vi->bitrate_nominal=hi->bitrate_av;
  140847. else{
  140848. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140849. }
  140850. vi->bitrate_lower=hi->bitrate_min;
  140851. vi->bitrate_upper=hi->bitrate_max;
  140852. if(hi->bitrate_av)
  140853. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140854. else
  140855. vi->bitrate_window=0.;
  140856. if(hi->managed){
  140857. ci->bi.avg_rate=hi->bitrate_av;
  140858. ci->bi.min_rate=hi->bitrate_min;
  140859. ci->bi.max_rate=hi->bitrate_max;
  140860. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140861. ci->bi.reservoir_bias=
  140862. hi->bitrate_reservoir_bias;
  140863. ci->bi.slew_damp=hi->bitrate_av_damp;
  140864. }
  140865. return(0);
  140866. }
  140867. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140868. long channels,
  140869. long rate){
  140870. int ret=0,i,is;
  140871. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140872. highlevel_encode_setup *hi=&ci->hi;
  140873. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140874. double ds;
  140875. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140876. if(ret)return(ret);
  140877. is=hi->base_setting;
  140878. ds=hi->base_setting-is;
  140879. hi->short_setting=hi->base_setting;
  140880. hi->long_setting=hi->base_setting;
  140881. hi->managed=0;
  140882. hi->impulse_block_p=1;
  140883. hi->noise_normalize_p=1;
  140884. hi->stereo_point_setting=hi->base_setting;
  140885. hi->lowpass_kHz=
  140886. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140887. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140888. setup->psy_ath_float[is+1]*ds;
  140889. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140890. setup->psy_ath_abs[is+1]*ds;
  140891. hi->amplitude_track_dBpersec=-6.;
  140892. hi->trigger_setting=hi->base_setting;
  140893. for(i=0;i<4;i++){
  140894. hi->block[i].tone_mask_setting=hi->base_setting;
  140895. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140896. hi->block[i].noise_bias_setting=hi->base_setting;
  140897. hi->block[i].noise_compand_setting=hi->base_setting;
  140898. }
  140899. return(ret);
  140900. }
  140901. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140902. long channels,
  140903. long rate,
  140904. float quality){
  140905. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140906. highlevel_encode_setup *hi=&ci->hi;
  140907. quality+=.0000001;
  140908. if(quality>=1.)quality=.9999;
  140909. get_setup_template(vi,channels,rate,quality,0);
  140910. if(!hi->setup)return OV_EIMPL;
  140911. return vorbis_encode_setup_setting(vi,channels,rate);
  140912. }
  140913. int vorbis_encode_init_vbr(vorbis_info *vi,
  140914. long channels,
  140915. long rate,
  140916. float base_quality /* 0. to 1. */
  140917. ){
  140918. int ret=0;
  140919. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140920. if(ret){
  140921. vorbis_info_clear(vi);
  140922. return ret;
  140923. }
  140924. ret=vorbis_encode_setup_init(vi);
  140925. if(ret)
  140926. vorbis_info_clear(vi);
  140927. return(ret);
  140928. }
  140929. int vorbis_encode_setup_managed(vorbis_info *vi,
  140930. long channels,
  140931. long rate,
  140932. long max_bitrate,
  140933. long nominal_bitrate,
  140934. long min_bitrate){
  140935. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140936. highlevel_encode_setup *hi=&ci->hi;
  140937. double tnominal=nominal_bitrate;
  140938. int ret=0;
  140939. if(nominal_bitrate<=0.){
  140940. if(max_bitrate>0.){
  140941. if(min_bitrate>0.)
  140942. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140943. else
  140944. nominal_bitrate=max_bitrate*.875;
  140945. }else{
  140946. if(min_bitrate>0.){
  140947. nominal_bitrate=min_bitrate;
  140948. }else{
  140949. return(OV_EINVAL);
  140950. }
  140951. }
  140952. }
  140953. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140954. if(!hi->setup)return OV_EIMPL;
  140955. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140956. if(ret){
  140957. vorbis_info_clear(vi);
  140958. return ret;
  140959. }
  140960. hi->managed=1;
  140961. hi->bitrate_min=min_bitrate;
  140962. hi->bitrate_max=max_bitrate;
  140963. hi->bitrate_av=tnominal;
  140964. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140965. hi->bitrate_reservoir=nominal_bitrate*2;
  140966. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140967. return(ret);
  140968. }
  140969. int vorbis_encode_init(vorbis_info *vi,
  140970. long channels,
  140971. long rate,
  140972. long max_bitrate,
  140973. long nominal_bitrate,
  140974. long min_bitrate){
  140975. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140976. max_bitrate,
  140977. nominal_bitrate,
  140978. min_bitrate);
  140979. if(ret){
  140980. vorbis_info_clear(vi);
  140981. return(ret);
  140982. }
  140983. ret=vorbis_encode_setup_init(vi);
  140984. if(ret)
  140985. vorbis_info_clear(vi);
  140986. return(ret);
  140987. }
  140988. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140989. if(vi){
  140990. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140991. highlevel_encode_setup *hi=&ci->hi;
  140992. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140993. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140994. switch(number){
  140995. case OV_ECTL_RATEMANAGE_GET:
  140996. {
  140997. struct ovectl_ratemanage_arg *ai=
  140998. (struct ovectl_ratemanage_arg *)arg;
  140999. ai->management_active=hi->managed;
  141000. ai->bitrate_hard_window=ai->bitrate_av_window=
  141001. (double)hi->bitrate_reservoir/vi->rate;
  141002. ai->bitrate_av_window_center=1.;
  141003. ai->bitrate_hard_min=hi->bitrate_min;
  141004. ai->bitrate_hard_max=hi->bitrate_max;
  141005. ai->bitrate_av_lo=hi->bitrate_av;
  141006. ai->bitrate_av_hi=hi->bitrate_av;
  141007. }
  141008. return(0);
  141009. case OV_ECTL_RATEMANAGE_SET:
  141010. {
  141011. struct ovectl_ratemanage_arg *ai=
  141012. (struct ovectl_ratemanage_arg *)arg;
  141013. if(ai==NULL){
  141014. hi->managed=0;
  141015. }else{
  141016. hi->managed=ai->management_active;
  141017. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  141018. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  141019. }
  141020. }
  141021. return 0;
  141022. case OV_ECTL_RATEMANAGE_AVG:
  141023. {
  141024. struct ovectl_ratemanage_arg *ai=
  141025. (struct ovectl_ratemanage_arg *)arg;
  141026. if(ai==NULL){
  141027. hi->bitrate_av=0;
  141028. }else{
  141029. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  141030. }
  141031. }
  141032. return(0);
  141033. case OV_ECTL_RATEMANAGE_HARD:
  141034. {
  141035. struct ovectl_ratemanage_arg *ai=
  141036. (struct ovectl_ratemanage_arg *)arg;
  141037. if(ai==NULL){
  141038. hi->bitrate_min=0;
  141039. hi->bitrate_max=0;
  141040. }else{
  141041. hi->bitrate_min=ai->bitrate_hard_min;
  141042. hi->bitrate_max=ai->bitrate_hard_max;
  141043. hi->bitrate_reservoir=ai->bitrate_hard_window*
  141044. (hi->bitrate_max+hi->bitrate_min)*.5;
  141045. }
  141046. if(hi->bitrate_reservoir<128.)
  141047. hi->bitrate_reservoir=128.;
  141048. }
  141049. return(0);
  141050. case OV_ECTL_RATEMANAGE2_GET:
  141051. {
  141052. struct ovectl_ratemanage2_arg *ai=
  141053. (struct ovectl_ratemanage2_arg *)arg;
  141054. if(ai==NULL)return OV_EINVAL;
  141055. ai->management_active=hi->managed;
  141056. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  141057. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  141058. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  141059. ai->bitrate_average_damping=hi->bitrate_av_damp;
  141060. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  141061. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  141062. }
  141063. return (0);
  141064. case OV_ECTL_RATEMANAGE2_SET:
  141065. {
  141066. struct ovectl_ratemanage2_arg *ai=
  141067. (struct ovectl_ratemanage2_arg *)arg;
  141068. if(ai==NULL){
  141069. hi->managed=0;
  141070. }else{
  141071. if(ai->bitrate_limit_min_kbps>0 &&
  141072. ai->bitrate_average_kbps>0 &&
  141073. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  141074. return OV_EINVAL;
  141075. if(ai->bitrate_limit_max_kbps>0 &&
  141076. ai->bitrate_average_kbps>0 &&
  141077. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  141078. return OV_EINVAL;
  141079. if(ai->bitrate_limit_min_kbps>0 &&
  141080. ai->bitrate_limit_max_kbps>0 &&
  141081. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  141082. return OV_EINVAL;
  141083. if(ai->bitrate_average_damping <= 0.)
  141084. return OV_EINVAL;
  141085. if(ai->bitrate_limit_reservoir_bits < 0)
  141086. return OV_EINVAL;
  141087. if(ai->bitrate_limit_reservoir_bias < 0.)
  141088. return OV_EINVAL;
  141089. if(ai->bitrate_limit_reservoir_bias > 1.)
  141090. return OV_EINVAL;
  141091. hi->managed=ai->management_active;
  141092. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  141093. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  141094. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  141095. hi->bitrate_av_damp=ai->bitrate_average_damping;
  141096. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  141097. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  141098. }
  141099. }
  141100. return 0;
  141101. case OV_ECTL_LOWPASS_GET:
  141102. {
  141103. double *farg=(double *)arg;
  141104. *farg=hi->lowpass_kHz;
  141105. }
  141106. return(0);
  141107. case OV_ECTL_LOWPASS_SET:
  141108. {
  141109. double *farg=(double *)arg;
  141110. hi->lowpass_kHz=*farg;
  141111. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  141112. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  141113. }
  141114. return(0);
  141115. case OV_ECTL_IBLOCK_GET:
  141116. {
  141117. double *farg=(double *)arg;
  141118. *farg=hi->impulse_noisetune;
  141119. }
  141120. return(0);
  141121. case OV_ECTL_IBLOCK_SET:
  141122. {
  141123. double *farg=(double *)arg;
  141124. hi->impulse_noisetune=*farg;
  141125. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  141126. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  141127. }
  141128. return(0);
  141129. }
  141130. return(OV_EIMPL);
  141131. }
  141132. return(OV_EINVAL);
  141133. }
  141134. #endif
  141135. /*** End of inlined file: vorbisenc.c ***/
  141136. /*** Start of inlined file: vorbisfile.c ***/
  141137. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141138. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141139. // tasks..
  141140. #if JUCE_MSVC
  141141. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141142. #endif
  141143. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141144. #if JUCE_USE_OGGVORBIS
  141145. #include <stdlib.h>
  141146. #include <stdio.h>
  141147. #include <errno.h>
  141148. #include <string.h>
  141149. #include <math.h>
  141150. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  141151. over 8k gets what they deserve */
  141152. static long _get_data(OggVorbis_File *vf){
  141153. errno=0;
  141154. if(vf->datasource){
  141155. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  141156. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  141157. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  141158. if(bytes==0 && errno)return(-1);
  141159. return(bytes);
  141160. }else
  141161. return(0);
  141162. }
  141163. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  141164. if(vf->datasource){
  141165. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  141166. vf->offset=offset;
  141167. ogg_sync_reset(&vf->oy);
  141168. }else{
  141169. return;
  141170. }
  141171. }
  141172. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  141173. ogg_int64_t boundary){
  141174. if(boundary>0)boundary+=vf->offset;
  141175. while(1){
  141176. long more;
  141177. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  141178. more=ogg_sync_pageseek(&vf->oy,og);
  141179. if(more<0){
  141180. vf->offset-=more;
  141181. }else{
  141182. if(more==0){
  141183. if(!boundary)return(OV_FALSE);
  141184. {
  141185. long ret=_get_data(vf);
  141186. if(ret==0)return(OV_EOF);
  141187. if(ret<0)return(OV_EREAD);
  141188. }
  141189. }else{
  141190. ogg_int64_t ret=vf->offset;
  141191. vf->offset+=more;
  141192. return(ret);
  141193. }
  141194. }
  141195. }
  141196. }
  141197. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  141198. ogg_int64_t begin=vf->offset;
  141199. ogg_int64_t end=begin;
  141200. ogg_int64_t ret;
  141201. ogg_int64_t offset=-1;
  141202. while(offset==-1){
  141203. begin-=CHUNKSIZE;
  141204. if(begin<0)
  141205. begin=0;
  141206. _seek_helper(vf,begin);
  141207. while(vf->offset<end){
  141208. ret=_get_next_page(vf,og,end-vf->offset);
  141209. if(ret==OV_EREAD)return(OV_EREAD);
  141210. if(ret<0){
  141211. break;
  141212. }else{
  141213. offset=ret;
  141214. }
  141215. }
  141216. }
  141217. _seek_helper(vf,offset);
  141218. ret=_get_next_page(vf,og,CHUNKSIZE);
  141219. if(ret<0)
  141220. return(OV_EFAULT);
  141221. return(offset);
  141222. }
  141223. static int _bisect_forward_serialno(OggVorbis_File *vf,
  141224. ogg_int64_t begin,
  141225. ogg_int64_t searched,
  141226. ogg_int64_t end,
  141227. long currentno,
  141228. long m){
  141229. ogg_int64_t endsearched=end;
  141230. ogg_int64_t next=end;
  141231. ogg_page og;
  141232. ogg_int64_t ret;
  141233. while(searched<endsearched){
  141234. ogg_int64_t bisect;
  141235. if(endsearched-searched<CHUNKSIZE){
  141236. bisect=searched;
  141237. }else{
  141238. bisect=(searched+endsearched)/2;
  141239. }
  141240. _seek_helper(vf,bisect);
  141241. ret=_get_next_page(vf,&og,-1);
  141242. if(ret==OV_EREAD)return(OV_EREAD);
  141243. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  141244. endsearched=bisect;
  141245. if(ret>=0)next=ret;
  141246. }else{
  141247. searched=ret+og.header_len+og.body_len;
  141248. }
  141249. }
  141250. _seek_helper(vf,next);
  141251. ret=_get_next_page(vf,&og,-1);
  141252. if(ret==OV_EREAD)return(OV_EREAD);
  141253. if(searched>=end || ret<0){
  141254. vf->links=m+1;
  141255. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  141256. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  141257. vf->offsets[m+1]=searched;
  141258. }else{
  141259. ret=_bisect_forward_serialno(vf,next,vf->offset,
  141260. end,ogg_page_serialno(&og),m+1);
  141261. if(ret==OV_EREAD)return(OV_EREAD);
  141262. }
  141263. vf->offsets[m]=begin;
  141264. vf->serialnos[m]=currentno;
  141265. return(0);
  141266. }
  141267. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  141268. long *serialno,ogg_page *og_ptr){
  141269. ogg_page og;
  141270. ogg_packet op;
  141271. int i,ret;
  141272. if(!og_ptr){
  141273. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  141274. if(llret==OV_EREAD)return(OV_EREAD);
  141275. if(llret<0)return OV_ENOTVORBIS;
  141276. og_ptr=&og;
  141277. }
  141278. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  141279. if(serialno)*serialno=vf->os.serialno;
  141280. vf->ready_state=STREAMSET;
  141281. vorbis_info_init(vi);
  141282. vorbis_comment_init(vc);
  141283. i=0;
  141284. while(i<3){
  141285. ogg_stream_pagein(&vf->os,og_ptr);
  141286. while(i<3){
  141287. int result=ogg_stream_packetout(&vf->os,&op);
  141288. if(result==0)break;
  141289. if(result==-1){
  141290. ret=OV_EBADHEADER;
  141291. goto bail_header;
  141292. }
  141293. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  141294. goto bail_header;
  141295. }
  141296. i++;
  141297. }
  141298. if(i<3)
  141299. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  141300. ret=OV_EBADHEADER;
  141301. goto bail_header;
  141302. }
  141303. }
  141304. return 0;
  141305. bail_header:
  141306. vorbis_info_clear(vi);
  141307. vorbis_comment_clear(vc);
  141308. vf->ready_state=OPENED;
  141309. return ret;
  141310. }
  141311. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141312. ogg_page og;
  141313. int i;
  141314. ogg_int64_t ret;
  141315. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141316. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141317. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141318. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141319. for(i=0;i<vf->links;i++){
  141320. if(i==0){
  141321. vf->dataoffsets[i]=dataoffset;
  141322. _seek_helper(vf,dataoffset);
  141323. }else{
  141324. _seek_helper(vf,vf->offsets[i]);
  141325. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141326. vf->dataoffsets[i]=-1;
  141327. }else{
  141328. vf->dataoffsets[i]=vf->offset;
  141329. }
  141330. }
  141331. if(vf->dataoffsets[i]!=-1){
  141332. ogg_int64_t accumulated=0;
  141333. long lastblock=-1;
  141334. int result;
  141335. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141336. while(1){
  141337. ogg_packet op;
  141338. ret=_get_next_page(vf,&og,-1);
  141339. if(ret<0)
  141340. break;
  141341. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141342. break;
  141343. ogg_stream_pagein(&vf->os,&og);
  141344. while((result=ogg_stream_packetout(&vf->os,&op))){
  141345. if(result>0){ /* ignore holes */
  141346. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141347. if(lastblock!=-1)
  141348. accumulated+=(lastblock+thisblock)>>2;
  141349. lastblock=thisblock;
  141350. }
  141351. }
  141352. if(ogg_page_granulepos(&og)!=-1){
  141353. accumulated= ogg_page_granulepos(&og)-accumulated;
  141354. break;
  141355. }
  141356. }
  141357. if(accumulated<0)accumulated=0;
  141358. vf->pcmlengths[i*2]=accumulated;
  141359. }
  141360. {
  141361. ogg_int64_t end=vf->offsets[i+1];
  141362. _seek_helper(vf,end);
  141363. while(1){
  141364. ret=_get_prev_page(vf,&og);
  141365. if(ret<0){
  141366. vorbis_info_clear(vf->vi+i);
  141367. vorbis_comment_clear(vf->vc+i);
  141368. break;
  141369. }
  141370. if(ogg_page_granulepos(&og)!=-1){
  141371. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141372. break;
  141373. }
  141374. vf->offset=ret;
  141375. }
  141376. }
  141377. }
  141378. }
  141379. static int _make_decode_ready(OggVorbis_File *vf){
  141380. if(vf->ready_state>STREAMSET)return 0;
  141381. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141382. if(vf->seekable){
  141383. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141384. return OV_EBADLINK;
  141385. }else{
  141386. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141387. return OV_EBADLINK;
  141388. }
  141389. vorbis_block_init(&vf->vd,&vf->vb);
  141390. vf->ready_state=INITSET;
  141391. vf->bittrack=0.f;
  141392. vf->samptrack=0.f;
  141393. return 0;
  141394. }
  141395. static int _open_seekable2(OggVorbis_File *vf){
  141396. long serialno=vf->current_serialno;
  141397. ogg_int64_t dataoffset=vf->offset, end;
  141398. ogg_page og;
  141399. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141400. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141401. end=_get_prev_page(vf,&og);
  141402. if(end<0)return(end);
  141403. if(ogg_page_serialno(&og)!=serialno){
  141404. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141405. }else{
  141406. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141407. }
  141408. _prefetch_all_headers(vf,dataoffset);
  141409. return(ov_raw_seek(vf,0));
  141410. }
  141411. static void _decode_clear(OggVorbis_File *vf){
  141412. vorbis_dsp_clear(&vf->vd);
  141413. vorbis_block_clear(&vf->vb);
  141414. vf->ready_state=OPENED;
  141415. }
  141416. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141417. ogg_packet *op_in,
  141418. int readp,
  141419. int spanp){
  141420. ogg_page og;
  141421. while(1){
  141422. if(vf->ready_state==INITSET){
  141423. while(1) {
  141424. ogg_packet op;
  141425. ogg_packet *op_ptr=(op_in?op_in:&op);
  141426. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141427. ogg_int64_t granulepos;
  141428. op_in=NULL;
  141429. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141430. if(result>0){
  141431. granulepos=op_ptr->granulepos;
  141432. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141433. header handling. The
  141434. header packets aren't
  141435. audio, so if/when we
  141436. submit them,
  141437. vorbis_synthesis will
  141438. reject them */
  141439. {
  141440. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141441. if(oldsamples)return(OV_EFAULT);
  141442. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141443. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141444. vf->bittrack+=op_ptr->bytes*8;
  141445. }
  141446. if(granulepos!=-1 && !op_ptr->e_o_s){
  141447. int link=(vf->seekable?vf->current_link:0);
  141448. int i,samples;
  141449. if(vf->seekable && link>0)
  141450. granulepos-=vf->pcmlengths[link*2];
  141451. if(granulepos<0)granulepos=0; /* actually, this
  141452. shouldn't be possible
  141453. here unless the stream
  141454. is very broken */
  141455. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141456. granulepos-=samples;
  141457. for(i=0;i<link;i++)
  141458. granulepos+=vf->pcmlengths[i*2+1];
  141459. vf->pcm_offset=granulepos;
  141460. }
  141461. return(1);
  141462. }
  141463. }
  141464. else
  141465. break;
  141466. }
  141467. }
  141468. if(vf->ready_state>=OPENED){
  141469. ogg_int64_t ret;
  141470. if(!readp)return(0);
  141471. if((ret=_get_next_page(vf,&og,-1))<0){
  141472. return(OV_EOF); /* eof.
  141473. leave unitialized */
  141474. }
  141475. vf->bittrack+=og.header_len*8;
  141476. if(vf->ready_state==INITSET){
  141477. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141478. if(!spanp)
  141479. return(OV_EOF);
  141480. _decode_clear(vf);
  141481. if(!vf->seekable){
  141482. vorbis_info_clear(vf->vi);
  141483. vorbis_comment_clear(vf->vc);
  141484. }
  141485. }
  141486. }
  141487. }
  141488. if(vf->ready_state!=INITSET){
  141489. int link;
  141490. if(vf->ready_state<STREAMSET){
  141491. if(vf->seekable){
  141492. vf->current_serialno=ogg_page_serialno(&og);
  141493. for(link=0;link<vf->links;link++)
  141494. if(vf->serialnos[link]==vf->current_serialno)break;
  141495. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141496. stream. error out,
  141497. leave machine
  141498. uninitialized */
  141499. vf->current_link=link;
  141500. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141501. vf->ready_state=STREAMSET;
  141502. }else{
  141503. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141504. if(ret)return(ret);
  141505. vf->current_link++;
  141506. link=0;
  141507. }
  141508. }
  141509. {
  141510. int ret=_make_decode_ready(vf);
  141511. if(ret<0)return ret;
  141512. }
  141513. }
  141514. ogg_stream_pagein(&vf->os,&og);
  141515. }
  141516. }
  141517. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141518. if(f==NULL)return(-1);
  141519. return fseek(f,off,whence);
  141520. }
  141521. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141522. long ibytes, ov_callbacks callbacks){
  141523. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141524. int ret;
  141525. memset(vf,0,sizeof(*vf));
  141526. vf->datasource=f;
  141527. vf->callbacks = callbacks;
  141528. ogg_sync_init(&vf->oy);
  141529. if(initial){
  141530. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141531. memcpy(buffer,initial,ibytes);
  141532. ogg_sync_wrote(&vf->oy,ibytes);
  141533. }
  141534. if(offsettest!=-1)vf->seekable=1;
  141535. vf->links=1;
  141536. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141537. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141538. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141539. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141540. vf->datasource=NULL;
  141541. ov_clear(vf);
  141542. }else
  141543. vf->ready_state=PARTOPEN;
  141544. return(ret);
  141545. }
  141546. static int _ov_open2(OggVorbis_File *vf){
  141547. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141548. vf->ready_state=OPENED;
  141549. if(vf->seekable){
  141550. int ret=_open_seekable2(vf);
  141551. if(ret){
  141552. vf->datasource=NULL;
  141553. ov_clear(vf);
  141554. }
  141555. return(ret);
  141556. }else
  141557. vf->ready_state=STREAMSET;
  141558. return 0;
  141559. }
  141560. int ov_clear(OggVorbis_File *vf){
  141561. if(vf){
  141562. vorbis_block_clear(&vf->vb);
  141563. vorbis_dsp_clear(&vf->vd);
  141564. ogg_stream_clear(&vf->os);
  141565. if(vf->vi && vf->links){
  141566. int i;
  141567. for(i=0;i<vf->links;i++){
  141568. vorbis_info_clear(vf->vi+i);
  141569. vorbis_comment_clear(vf->vc+i);
  141570. }
  141571. _ogg_free(vf->vi);
  141572. _ogg_free(vf->vc);
  141573. }
  141574. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141575. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141576. if(vf->serialnos)_ogg_free(vf->serialnos);
  141577. if(vf->offsets)_ogg_free(vf->offsets);
  141578. ogg_sync_clear(&vf->oy);
  141579. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141580. memset(vf,0,sizeof(*vf));
  141581. }
  141582. #ifdef DEBUG_LEAKS
  141583. _VDBG_dump();
  141584. #endif
  141585. return(0);
  141586. }
  141587. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141588. ov_callbacks callbacks){
  141589. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141590. if(ret)return ret;
  141591. return _ov_open2(vf);
  141592. }
  141593. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141594. ov_callbacks callbacks = {
  141595. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141596. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141597. (int (*)(void *)) fclose,
  141598. (long (*)(void *)) ftell
  141599. };
  141600. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141601. }
  141602. int ov_halfrate(OggVorbis_File *vf,int flag){
  141603. int i;
  141604. if(vf->vi==NULL)return OV_EINVAL;
  141605. if(!vf->seekable)return OV_EINVAL;
  141606. if(vf->ready_state>=STREAMSET)
  141607. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141608. will be able to swap this on the fly, but
  141609. for now dumping the decode machine is needed
  141610. to reinit the MDCT lookups. 1.1 libvorbis
  141611. is planned to be able to switch on the fly */
  141612. for(i=0;i<vf->links;i++){
  141613. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141614. ov_halfrate(vf,0);
  141615. return OV_EINVAL;
  141616. }
  141617. }
  141618. return 0;
  141619. }
  141620. int ov_halfrate_p(OggVorbis_File *vf){
  141621. if(vf->vi==NULL)return OV_EINVAL;
  141622. return vorbis_synthesis_halfrate_p(vf->vi);
  141623. }
  141624. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141625. ov_callbacks callbacks)
  141626. {
  141627. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141628. }
  141629. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141630. ov_callbacks callbacks = {
  141631. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141632. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141633. (int (*)(void *)) fclose,
  141634. (long (*)(void *)) ftell
  141635. };
  141636. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141637. }
  141638. int ov_test_open(OggVorbis_File *vf){
  141639. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141640. return _ov_open2(vf);
  141641. }
  141642. long ov_streams(OggVorbis_File *vf){
  141643. return vf->links;
  141644. }
  141645. long ov_seekable(OggVorbis_File *vf){
  141646. return vf->seekable;
  141647. }
  141648. long ov_bitrate(OggVorbis_File *vf,int i){
  141649. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141650. if(i>=vf->links)return(OV_EINVAL);
  141651. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141652. if(i<0){
  141653. ogg_int64_t bits=0;
  141654. int i;
  141655. float br;
  141656. for(i=0;i<vf->links;i++)
  141657. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141658. br = bits/ov_time_total(vf,-1);
  141659. return(rint(br));
  141660. }else{
  141661. if(vf->seekable){
  141662. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141663. }else{
  141664. if(vf->vi[i].bitrate_nominal>0){
  141665. return vf->vi[i].bitrate_nominal;
  141666. }else{
  141667. if(vf->vi[i].bitrate_upper>0){
  141668. if(vf->vi[i].bitrate_lower>0){
  141669. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141670. }else{
  141671. return vf->vi[i].bitrate_upper;
  141672. }
  141673. }
  141674. return(OV_FALSE);
  141675. }
  141676. }
  141677. }
  141678. }
  141679. long ov_bitrate_instant(OggVorbis_File *vf){
  141680. int link=(vf->seekable?vf->current_link:0);
  141681. long ret;
  141682. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141683. if(vf->samptrack==0)return(OV_FALSE);
  141684. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141685. vf->bittrack=0.f;
  141686. vf->samptrack=0.f;
  141687. return(ret);
  141688. }
  141689. long ov_serialnumber(OggVorbis_File *vf,int i){
  141690. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141691. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141692. if(i<0){
  141693. return(vf->current_serialno);
  141694. }else{
  141695. return(vf->serialnos[i]);
  141696. }
  141697. }
  141698. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141699. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141700. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141701. if(i<0){
  141702. ogg_int64_t acc=0;
  141703. int i;
  141704. for(i=0;i<vf->links;i++)
  141705. acc+=ov_raw_total(vf,i);
  141706. return(acc);
  141707. }else{
  141708. return(vf->offsets[i+1]-vf->offsets[i]);
  141709. }
  141710. }
  141711. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141712. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141713. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141714. if(i<0){
  141715. ogg_int64_t acc=0;
  141716. int i;
  141717. for(i=0;i<vf->links;i++)
  141718. acc+=ov_pcm_total(vf,i);
  141719. return(acc);
  141720. }else{
  141721. return(vf->pcmlengths[i*2+1]);
  141722. }
  141723. }
  141724. double ov_time_total(OggVorbis_File *vf,int i){
  141725. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141726. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141727. if(i<0){
  141728. double acc=0;
  141729. int i;
  141730. for(i=0;i<vf->links;i++)
  141731. acc+=ov_time_total(vf,i);
  141732. return(acc);
  141733. }else{
  141734. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141735. }
  141736. }
  141737. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141738. ogg_stream_state work_os;
  141739. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141740. if(!vf->seekable)
  141741. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141742. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141743. vf->pcm_offset=-1;
  141744. ogg_stream_reset_serialno(&vf->os,
  141745. vf->current_serialno); /* must set serialno */
  141746. vorbis_synthesis_restart(&vf->vd);
  141747. _seek_helper(vf,pos);
  141748. {
  141749. ogg_page og;
  141750. ogg_packet op;
  141751. int lastblock=0;
  141752. int accblock=0;
  141753. int thisblock;
  141754. int eosflag;
  141755. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141756. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141757. return from not necessarily
  141758. starting from the beginning */
  141759. while(1){
  141760. if(vf->ready_state>=STREAMSET){
  141761. int result=ogg_stream_packetout(&work_os,&op);
  141762. if(result>0){
  141763. if(vf->vi[vf->current_link].codec_setup){
  141764. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141765. if(thisblock<0){
  141766. ogg_stream_packetout(&vf->os,NULL);
  141767. thisblock=0;
  141768. }else{
  141769. if(eosflag)
  141770. ogg_stream_packetout(&vf->os,NULL);
  141771. else
  141772. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141773. }
  141774. if(op.granulepos!=-1){
  141775. int i,link=vf->current_link;
  141776. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141777. if(granulepos<0)granulepos=0;
  141778. for(i=0;i<link;i++)
  141779. granulepos+=vf->pcmlengths[i*2+1];
  141780. vf->pcm_offset=granulepos-accblock;
  141781. break;
  141782. }
  141783. lastblock=thisblock;
  141784. continue;
  141785. }else
  141786. ogg_stream_packetout(&vf->os,NULL);
  141787. }
  141788. }
  141789. if(!lastblock){
  141790. if(_get_next_page(vf,&og,-1)<0){
  141791. vf->pcm_offset=ov_pcm_total(vf,-1);
  141792. break;
  141793. }
  141794. }else{
  141795. vf->pcm_offset=-1;
  141796. break;
  141797. }
  141798. if(vf->ready_state>=STREAMSET)
  141799. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141800. _decode_clear(vf); /* clear out stream state */
  141801. ogg_stream_clear(&work_os);
  141802. }
  141803. if(vf->ready_state<STREAMSET){
  141804. int link;
  141805. vf->current_serialno=ogg_page_serialno(&og);
  141806. for(link=0;link<vf->links;link++)
  141807. if(vf->serialnos[link]==vf->current_serialno)break;
  141808. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141809. error out, leave
  141810. machine uninitialized */
  141811. vf->current_link=link;
  141812. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141813. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141814. vf->ready_state=STREAMSET;
  141815. }
  141816. ogg_stream_pagein(&vf->os,&og);
  141817. ogg_stream_pagein(&work_os,&og);
  141818. eosflag=ogg_page_eos(&og);
  141819. }
  141820. }
  141821. ogg_stream_clear(&work_os);
  141822. vf->bittrack=0.f;
  141823. vf->samptrack=0.f;
  141824. return(0);
  141825. seek_error:
  141826. vf->pcm_offset=-1;
  141827. ogg_stream_clear(&work_os);
  141828. _decode_clear(vf);
  141829. return OV_EBADLINK;
  141830. }
  141831. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141832. int link=-1;
  141833. ogg_int64_t result=0;
  141834. ogg_int64_t total=ov_pcm_total(vf,-1);
  141835. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141836. if(!vf->seekable)return(OV_ENOSEEK);
  141837. if(pos<0 || pos>total)return(OV_EINVAL);
  141838. for(link=vf->links-1;link>=0;link--){
  141839. total-=vf->pcmlengths[link*2+1];
  141840. if(pos>=total)break;
  141841. }
  141842. {
  141843. ogg_int64_t end=vf->offsets[link+1];
  141844. ogg_int64_t begin=vf->offsets[link];
  141845. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141846. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141847. ogg_int64_t target=pos-total+begintime;
  141848. ogg_int64_t best=begin;
  141849. ogg_page og;
  141850. while(begin<end){
  141851. ogg_int64_t bisect;
  141852. if(end-begin<CHUNKSIZE){
  141853. bisect=begin;
  141854. }else{
  141855. bisect=begin +
  141856. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141857. if(bisect<=begin)
  141858. bisect=begin+1;
  141859. }
  141860. _seek_helper(vf,bisect);
  141861. while(begin<end){
  141862. result=_get_next_page(vf,&og,end-vf->offset);
  141863. if(result==OV_EREAD) goto seek_error;
  141864. if(result<0){
  141865. if(bisect<=begin+1)
  141866. end=begin; /* found it */
  141867. else{
  141868. if(bisect==0) goto seek_error;
  141869. bisect-=CHUNKSIZE;
  141870. if(bisect<=begin)bisect=begin+1;
  141871. _seek_helper(vf,bisect);
  141872. }
  141873. }else{
  141874. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141875. if(granulepos==-1)continue;
  141876. if(granulepos<target){
  141877. best=result; /* raw offset of packet with granulepos */
  141878. begin=vf->offset; /* raw offset of next page */
  141879. begintime=granulepos;
  141880. if(target-begintime>44100)break;
  141881. bisect=begin; /* *not* begin + 1 */
  141882. }else{
  141883. if(bisect<=begin+1)
  141884. end=begin; /* found it */
  141885. else{
  141886. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141887. end=result;
  141888. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141889. if(bisect<=begin)bisect=begin+1;
  141890. _seek_helper(vf,bisect);
  141891. }else{
  141892. end=result;
  141893. endtime=granulepos;
  141894. break;
  141895. }
  141896. }
  141897. }
  141898. }
  141899. }
  141900. }
  141901. {
  141902. ogg_page og;
  141903. ogg_packet op;
  141904. _seek_helper(vf,best);
  141905. vf->pcm_offset=-1;
  141906. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141907. if(link!=vf->current_link){
  141908. _decode_clear(vf);
  141909. vf->current_link=link;
  141910. vf->current_serialno=ogg_page_serialno(&og);
  141911. vf->ready_state=STREAMSET;
  141912. }else{
  141913. vorbis_synthesis_restart(&vf->vd);
  141914. }
  141915. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141916. ogg_stream_pagein(&vf->os,&og);
  141917. while(1){
  141918. result=ogg_stream_packetpeek(&vf->os,&op);
  141919. if(result==0){
  141920. _seek_helper(vf,best);
  141921. while(1){
  141922. result=_get_prev_page(vf,&og);
  141923. if(result<0) goto seek_error;
  141924. if(ogg_page_granulepos(&og)>-1 ||
  141925. !ogg_page_continued(&og)){
  141926. return ov_raw_seek(vf,result);
  141927. }
  141928. vf->offset=result;
  141929. }
  141930. }
  141931. if(result<0){
  141932. result = OV_EBADPACKET;
  141933. goto seek_error;
  141934. }
  141935. if(op.granulepos!=-1){
  141936. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141937. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141938. vf->pcm_offset+=total;
  141939. break;
  141940. }else
  141941. result=ogg_stream_packetout(&vf->os,NULL);
  141942. }
  141943. }
  141944. }
  141945. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141946. result=OV_EFAULT;
  141947. goto seek_error;
  141948. }
  141949. vf->bittrack=0.f;
  141950. vf->samptrack=0.f;
  141951. return(0);
  141952. seek_error:
  141953. vf->pcm_offset=-1;
  141954. _decode_clear(vf);
  141955. return (int)result;
  141956. }
  141957. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141958. int thisblock,lastblock=0;
  141959. int ret=ov_pcm_seek_page(vf,pos);
  141960. if(ret<0)return(ret);
  141961. if((ret=_make_decode_ready(vf)))return ret;
  141962. while(1){
  141963. ogg_packet op;
  141964. ogg_page og;
  141965. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141966. if(ret>0){
  141967. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141968. if(thisblock<0){
  141969. ogg_stream_packetout(&vf->os,NULL);
  141970. continue; /* non audio packet */
  141971. }
  141972. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141973. if(vf->pcm_offset+((thisblock+
  141974. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141975. ogg_stream_packetout(&vf->os,NULL);
  141976. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141977. only tracking, no
  141978. pcm_decode */
  141979. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141980. if(op.granulepos>-1){
  141981. int i;
  141982. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141983. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141984. for(i=0;i<vf->current_link;i++)
  141985. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141986. }
  141987. lastblock=thisblock;
  141988. }else{
  141989. if(ret<0 && ret!=OV_HOLE)break;
  141990. if(_get_next_page(vf,&og,-1)<0)break;
  141991. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141992. if(vf->ready_state<STREAMSET){
  141993. int link;
  141994. vf->current_serialno=ogg_page_serialno(&og);
  141995. for(link=0;link<vf->links;link++)
  141996. if(vf->serialnos[link]==vf->current_serialno)break;
  141997. if(link==vf->links)return(OV_EBADLINK);
  141998. vf->current_link=link;
  141999. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142000. vf->ready_state=STREAMSET;
  142001. ret=_make_decode_ready(vf);
  142002. if(ret)return ret;
  142003. lastblock=0;
  142004. }
  142005. ogg_stream_pagein(&vf->os,&og);
  142006. }
  142007. }
  142008. vf->bittrack=0.f;
  142009. vf->samptrack=0.f;
  142010. while(vf->pcm_offset<pos){
  142011. ogg_int64_t target=pos-vf->pcm_offset;
  142012. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  142013. if(samples>target)samples=target;
  142014. vorbis_synthesis_read(&vf->vd,samples);
  142015. vf->pcm_offset+=samples;
  142016. if(samples<target)
  142017. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  142018. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  142019. }
  142020. return 0;
  142021. }
  142022. int ov_time_seek(OggVorbis_File *vf,double seconds){
  142023. int link=-1;
  142024. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142025. double time_total=ov_time_total(vf,-1);
  142026. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142027. if(!vf->seekable)return(OV_ENOSEEK);
  142028. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142029. for(link=vf->links-1;link>=0;link--){
  142030. pcm_total-=vf->pcmlengths[link*2+1];
  142031. time_total-=ov_time_total(vf,link);
  142032. if(seconds>=time_total)break;
  142033. }
  142034. {
  142035. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142036. return(ov_pcm_seek(vf,target));
  142037. }
  142038. }
  142039. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  142040. int link=-1;
  142041. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142042. double time_total=ov_time_total(vf,-1);
  142043. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142044. if(!vf->seekable)return(OV_ENOSEEK);
  142045. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142046. for(link=vf->links-1;link>=0;link--){
  142047. pcm_total-=vf->pcmlengths[link*2+1];
  142048. time_total-=ov_time_total(vf,link);
  142049. if(seconds>=time_total)break;
  142050. }
  142051. {
  142052. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142053. return(ov_pcm_seek_page(vf,target));
  142054. }
  142055. }
  142056. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  142057. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142058. return(vf->offset);
  142059. }
  142060. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  142061. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142062. return(vf->pcm_offset);
  142063. }
  142064. double ov_time_tell(OggVorbis_File *vf){
  142065. int link=0;
  142066. ogg_int64_t pcm_total=0;
  142067. double time_total=0.f;
  142068. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142069. if(vf->seekable){
  142070. pcm_total=ov_pcm_total(vf,-1);
  142071. time_total=ov_time_total(vf,-1);
  142072. for(link=vf->links-1;link>=0;link--){
  142073. pcm_total-=vf->pcmlengths[link*2+1];
  142074. time_total-=ov_time_total(vf,link);
  142075. if(vf->pcm_offset>=pcm_total)break;
  142076. }
  142077. }
  142078. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  142079. }
  142080. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  142081. if(vf->seekable){
  142082. if(link<0)
  142083. if(vf->ready_state>=STREAMSET)
  142084. return vf->vi+vf->current_link;
  142085. else
  142086. return vf->vi;
  142087. else
  142088. if(link>=vf->links)
  142089. return NULL;
  142090. else
  142091. return vf->vi+link;
  142092. }else{
  142093. return vf->vi;
  142094. }
  142095. }
  142096. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  142097. if(vf->seekable){
  142098. if(link<0)
  142099. if(vf->ready_state>=STREAMSET)
  142100. return vf->vc+vf->current_link;
  142101. else
  142102. return vf->vc;
  142103. else
  142104. if(link>=vf->links)
  142105. return NULL;
  142106. else
  142107. return vf->vc+link;
  142108. }else{
  142109. return vf->vc;
  142110. }
  142111. }
  142112. static int host_is_big_endian() {
  142113. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  142114. unsigned char *bytewise = (unsigned char *)&pattern;
  142115. if (bytewise[0] == 0xfe) return 1;
  142116. return 0;
  142117. }
  142118. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  142119. int bigendianp,int word,int sgned,int *bitstream){
  142120. int i,j;
  142121. int host_endian = host_is_big_endian();
  142122. float **pcm;
  142123. long samples;
  142124. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142125. while(1){
  142126. if(vf->ready_state==INITSET){
  142127. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142128. if(samples)break;
  142129. }
  142130. {
  142131. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142132. if(ret==OV_EOF)
  142133. return(0);
  142134. if(ret<=0)
  142135. return(ret);
  142136. }
  142137. }
  142138. if(samples>0){
  142139. long channels=ov_info(vf,-1)->channels;
  142140. long bytespersample=word * channels;
  142141. vorbis_fpu_control fpu;
  142142. (void) fpu; // (to avoid a warning about it being unused)
  142143. if(samples>length/bytespersample)samples=length/bytespersample;
  142144. if(samples <= 0)
  142145. return OV_EINVAL;
  142146. {
  142147. int val;
  142148. if(word==1){
  142149. int off=(sgned?0:128);
  142150. vorbis_fpu_setround(&fpu);
  142151. for(j=0;j<samples;j++)
  142152. for(i=0;i<channels;i++){
  142153. val=vorbis_ftoi(pcm[i][j]*128.f);
  142154. if(val>127)val=127;
  142155. else if(val<-128)val=-128;
  142156. *buffer++=val+off;
  142157. }
  142158. vorbis_fpu_restore(fpu);
  142159. }else{
  142160. int off=(sgned?0:32768);
  142161. if(host_endian==bigendianp){
  142162. if(sgned){
  142163. vorbis_fpu_setround(&fpu);
  142164. for(i=0;i<channels;i++) { /* It's faster in this order */
  142165. float *src=pcm[i];
  142166. short *dest=((short *)buffer)+i;
  142167. for(j=0;j<samples;j++) {
  142168. val=vorbis_ftoi(src[j]*32768.f);
  142169. if(val>32767)val=32767;
  142170. else if(val<-32768)val=-32768;
  142171. *dest=val;
  142172. dest+=channels;
  142173. }
  142174. }
  142175. vorbis_fpu_restore(fpu);
  142176. }else{
  142177. vorbis_fpu_setround(&fpu);
  142178. for(i=0;i<channels;i++) {
  142179. float *src=pcm[i];
  142180. short *dest=((short *)buffer)+i;
  142181. for(j=0;j<samples;j++) {
  142182. val=vorbis_ftoi(src[j]*32768.f);
  142183. if(val>32767)val=32767;
  142184. else if(val<-32768)val=-32768;
  142185. *dest=val+off;
  142186. dest+=channels;
  142187. }
  142188. }
  142189. vorbis_fpu_restore(fpu);
  142190. }
  142191. }else if(bigendianp){
  142192. vorbis_fpu_setround(&fpu);
  142193. for(j=0;j<samples;j++)
  142194. for(i=0;i<channels;i++){
  142195. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142196. if(val>32767)val=32767;
  142197. else if(val<-32768)val=-32768;
  142198. val+=off;
  142199. *buffer++=(val>>8);
  142200. *buffer++=(val&0xff);
  142201. }
  142202. vorbis_fpu_restore(fpu);
  142203. }else{
  142204. int val;
  142205. vorbis_fpu_setround(&fpu);
  142206. for(j=0;j<samples;j++)
  142207. for(i=0;i<channels;i++){
  142208. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142209. if(val>32767)val=32767;
  142210. else if(val<-32768)val=-32768;
  142211. val+=off;
  142212. *buffer++=(val&0xff);
  142213. *buffer++=(val>>8);
  142214. }
  142215. vorbis_fpu_restore(fpu);
  142216. }
  142217. }
  142218. }
  142219. vorbis_synthesis_read(&vf->vd,samples);
  142220. vf->pcm_offset+=samples;
  142221. if(bitstream)*bitstream=vf->current_link;
  142222. return(samples*bytespersample);
  142223. }else{
  142224. return(samples);
  142225. }
  142226. }
  142227. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  142228. int *bitstream){
  142229. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142230. while(1){
  142231. if(vf->ready_state==INITSET){
  142232. float **pcm;
  142233. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142234. if(samples){
  142235. if(pcm_channels)*pcm_channels=pcm;
  142236. if(samples>length)samples=length;
  142237. vorbis_synthesis_read(&vf->vd,samples);
  142238. vf->pcm_offset+=samples;
  142239. if(bitstream)*bitstream=vf->current_link;
  142240. return samples;
  142241. }
  142242. }
  142243. {
  142244. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142245. if(ret==OV_EOF)return(0);
  142246. if(ret<=0)return(ret);
  142247. }
  142248. }
  142249. }
  142250. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  142251. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  142252. ogg_int64_t off);
  142253. static void _ov_splice(float **pcm,float **lappcm,
  142254. int n1, int n2,
  142255. int ch1, int ch2,
  142256. float *w1, float *w2){
  142257. int i,j;
  142258. float *w=w1;
  142259. int n=n1;
  142260. if(n1>n2){
  142261. n=n2;
  142262. w=w2;
  142263. }
  142264. for(j=0;j<ch1 && j<ch2;j++){
  142265. float *s=lappcm[j];
  142266. float *d=pcm[j];
  142267. for(i=0;i<n;i++){
  142268. float wd=w[i]*w[i];
  142269. float ws=1.-wd;
  142270. d[i]=d[i]*wd + s[i]*ws;
  142271. }
  142272. }
  142273. for(;j<ch2;j++){
  142274. float *d=pcm[j];
  142275. for(i=0;i<n;i++){
  142276. float wd=w[i]*w[i];
  142277. d[i]=d[i]*wd;
  142278. }
  142279. }
  142280. }
  142281. static int _ov_initset(OggVorbis_File *vf){
  142282. while(1){
  142283. if(vf->ready_state==INITSET)break;
  142284. {
  142285. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142286. if(ret<0 && ret!=OV_HOLE)return(ret);
  142287. }
  142288. }
  142289. return 0;
  142290. }
  142291. static int _ov_initprime(OggVorbis_File *vf){
  142292. vorbis_dsp_state *vd=&vf->vd;
  142293. while(1){
  142294. if(vf->ready_state==INITSET)
  142295. if(vorbis_synthesis_pcmout(vd,NULL))break;
  142296. {
  142297. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142298. if(ret<0 && ret!=OV_HOLE)return(ret);
  142299. }
  142300. }
  142301. return 0;
  142302. }
  142303. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  142304. float **lappcm,int lapsize){
  142305. int lapcount=0,i;
  142306. float **pcm;
  142307. while(lapcount<lapsize){
  142308. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142309. if(samples){
  142310. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142311. for(i=0;i<vi->channels;i++)
  142312. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142313. lapcount+=samples;
  142314. vorbis_synthesis_read(vd,samples);
  142315. }else{
  142316. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142317. if(ret==OV_EOF)break;
  142318. }
  142319. }
  142320. if(lapcount<lapsize){
  142321. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142322. if(samples==0){
  142323. for(i=0;i<vi->channels;i++)
  142324. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142325. lapcount=lapsize;
  142326. }else{
  142327. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142328. for(i=0;i<vi->channels;i++)
  142329. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142330. lapcount+=samples;
  142331. }
  142332. }
  142333. }
  142334. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142335. vorbis_info *vi1,*vi2;
  142336. float **lappcm;
  142337. float **pcm;
  142338. float *w1,*w2;
  142339. int n1,n2,i,ret,hs1,hs2;
  142340. if(vf1==vf2)return(0); /* degenerate case */
  142341. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142342. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142343. ret=_ov_initset(vf1);
  142344. if(ret)return(ret);
  142345. ret=_ov_initprime(vf2);
  142346. if(ret)return(ret);
  142347. vi1=ov_info(vf1,-1);
  142348. vi2=ov_info(vf2,-1);
  142349. hs1=ov_halfrate_p(vf1);
  142350. hs2=ov_halfrate_p(vf2);
  142351. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142352. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142353. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142354. w1=vorbis_window(&vf1->vd,0);
  142355. w2=vorbis_window(&vf2->vd,0);
  142356. for(i=0;i<vi1->channels;i++)
  142357. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142358. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142359. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142360. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142361. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142362. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142363. return(0);
  142364. }
  142365. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142366. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142367. vorbis_info *vi;
  142368. float **lappcm;
  142369. float **pcm;
  142370. float *w1,*w2;
  142371. int n1,n2,ch1,ch2,hs;
  142372. int i,ret;
  142373. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142374. ret=_ov_initset(vf);
  142375. if(ret)return(ret);
  142376. vi=ov_info(vf,-1);
  142377. hs=ov_halfrate_p(vf);
  142378. ch1=vi->channels;
  142379. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142380. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142381. persistent; even if the decode state
  142382. from this link gets dumped, this
  142383. window array continues to exist */
  142384. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142385. for(i=0;i<ch1;i++)
  142386. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142387. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142388. ret=localseek(vf,pos);
  142389. if(ret)return ret;
  142390. ret=_ov_initprime(vf);
  142391. if(ret)return(ret);
  142392. vi=ov_info(vf,-1);
  142393. ch2=vi->channels;
  142394. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142395. w2=vorbis_window(&vf->vd,0);
  142396. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142397. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142398. return(0);
  142399. }
  142400. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142401. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142402. }
  142403. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142404. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142405. }
  142406. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142407. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142408. }
  142409. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142410. int (*localseek)(OggVorbis_File *,double)){
  142411. vorbis_info *vi;
  142412. float **lappcm;
  142413. float **pcm;
  142414. float *w1,*w2;
  142415. int n1,n2,ch1,ch2,hs;
  142416. int i,ret;
  142417. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142418. ret=_ov_initset(vf);
  142419. if(ret)return(ret);
  142420. vi=ov_info(vf,-1);
  142421. hs=ov_halfrate_p(vf);
  142422. ch1=vi->channels;
  142423. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142424. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142425. persistent; even if the decode state
  142426. from this link gets dumped, this
  142427. window array continues to exist */
  142428. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142429. for(i=0;i<ch1;i++)
  142430. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142431. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142432. ret=localseek(vf,pos);
  142433. if(ret)return ret;
  142434. ret=_ov_initprime(vf);
  142435. if(ret)return(ret);
  142436. vi=ov_info(vf,-1);
  142437. ch2=vi->channels;
  142438. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142439. w2=vorbis_window(&vf->vd,0);
  142440. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142441. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142442. return(0);
  142443. }
  142444. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142445. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142446. }
  142447. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142448. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142449. }
  142450. #endif
  142451. /*** End of inlined file: vorbisfile.c ***/
  142452. /*** Start of inlined file: window.c ***/
  142453. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142454. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142455. // tasks..
  142456. #if JUCE_MSVC
  142457. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142458. #endif
  142459. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142460. #if JUCE_USE_OGGVORBIS
  142461. #include <stdlib.h>
  142462. #include <math.h>
  142463. static float vwin64[32] = {
  142464. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142465. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142466. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142467. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142468. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142469. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142470. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142471. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142472. };
  142473. static float vwin128[64] = {
  142474. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142475. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142476. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142477. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142478. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142479. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142480. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142481. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142482. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142483. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142484. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142485. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142486. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142487. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142488. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142489. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142490. };
  142491. static float vwin256[128] = {
  142492. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142493. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142494. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142495. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142496. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142497. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142498. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142499. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142500. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142501. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142502. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142503. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142504. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142505. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142506. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142507. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142508. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142509. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142510. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142511. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142512. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142513. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142514. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142515. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142516. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142517. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142518. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142519. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142520. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142521. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142522. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142523. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142524. };
  142525. static float vwin512[256] = {
  142526. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142527. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142528. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142529. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142530. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142531. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142532. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142533. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142534. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142535. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142536. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142537. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142538. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142539. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142540. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142541. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142542. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142543. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142544. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142545. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142546. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142547. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142548. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142549. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142550. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142551. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142552. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142553. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142554. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142555. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142556. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142557. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142558. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142559. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142560. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142561. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142562. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142563. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142564. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142565. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142566. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142567. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142568. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142569. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142570. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142571. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142572. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142573. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142574. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142575. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142576. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142577. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142578. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142579. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142580. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142581. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142582. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142583. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142584. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142585. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142586. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142587. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142588. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142589. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142590. };
  142591. static float vwin1024[512] = {
  142592. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142593. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142594. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142595. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142596. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142597. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142598. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142599. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142600. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142601. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142602. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142603. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142604. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142605. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142606. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142607. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142608. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142609. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142610. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142611. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142612. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142613. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142614. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142615. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142616. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142617. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142618. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142619. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142620. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142621. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142622. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142623. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142624. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142625. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142626. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142627. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142628. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142629. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142630. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142631. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142632. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142633. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142634. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142635. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142636. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142637. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142638. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142639. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142640. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142641. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142642. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142643. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142644. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142645. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142646. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142647. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142648. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142649. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142650. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142651. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142652. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142653. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142654. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142655. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142656. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142657. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142658. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142659. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142660. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142661. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142662. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142663. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142664. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142665. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142666. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142667. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142668. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142669. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142670. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142671. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142672. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142673. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142674. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142675. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142676. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142677. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142678. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142679. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142680. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142681. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142682. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142683. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142684. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142685. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142686. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142687. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142688. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142689. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142690. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142691. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142692. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142693. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142694. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142695. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142696. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142697. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142698. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142699. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142700. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142701. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142702. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142703. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142704. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142705. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142706. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142707. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142708. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142709. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142710. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142711. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142712. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142713. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142714. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142715. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142716. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142717. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142718. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142719. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142720. };
  142721. static float vwin2048[1024] = {
  142722. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142723. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142724. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142725. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142726. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142727. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142728. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142729. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142730. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142731. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142732. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142733. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142734. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142735. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142736. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142737. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142738. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142739. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142740. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142741. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142742. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142743. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142744. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142745. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142746. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142747. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142748. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142749. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142750. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142751. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142752. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142753. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142754. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142755. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142756. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142757. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142758. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142759. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142760. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142761. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142762. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142763. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142764. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142765. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142766. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142767. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142768. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142769. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142770. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142771. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142772. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142773. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142774. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142775. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142776. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142777. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142778. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142779. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142780. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142781. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142782. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142783. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142784. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142785. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142786. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142787. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142788. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142789. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142790. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142791. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142792. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142793. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142794. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142795. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142796. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142797. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142798. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142799. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142800. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142801. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142802. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142803. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142804. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142805. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142806. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142807. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142808. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142809. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142810. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142811. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142812. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142813. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142814. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142815. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142816. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142817. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142818. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142819. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142820. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142821. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142822. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142823. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142824. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142825. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142826. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142827. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142828. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142829. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142830. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142831. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142832. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142833. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142834. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142835. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142836. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142837. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142838. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142839. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142840. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142841. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142842. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142843. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142844. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142845. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142846. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142847. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142848. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142849. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142850. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142851. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142852. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142853. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142854. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142855. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142856. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142857. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142858. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142859. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142860. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142861. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142862. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142863. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142864. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142865. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142866. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142867. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142868. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142869. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142870. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142871. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142872. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142873. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142874. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142875. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142876. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142877. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142878. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142879. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142880. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142881. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142882. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142883. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142884. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142885. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142886. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142887. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142888. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142889. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142890. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142891. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142892. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142893. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142894. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142895. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142896. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142897. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142898. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142899. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142900. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142901. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142902. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142903. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142904. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142905. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142906. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142907. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142908. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142909. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142910. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142911. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142912. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142913. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142914. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142915. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142916. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142917. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142918. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142919. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142920. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142921. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142922. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142923. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142924. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142925. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142926. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142927. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142928. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142929. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142930. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142931. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142932. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142933. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142934. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142935. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142936. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142937. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142938. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142939. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142940. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142941. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142942. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142943. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142944. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142945. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142946. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142947. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142948. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142949. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142950. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142951. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142952. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142953. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142954. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142955. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142956. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142957. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142958. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142959. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142960. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142961. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142962. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142963. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142964. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142965. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142966. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142967. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142968. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142969. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142970. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142971. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142972. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142973. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142974. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142975. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142976. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142977. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142978. };
  142979. static float vwin4096[2048] = {
  142980. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142981. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142982. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142983. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142984. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142985. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142986. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142987. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142988. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142989. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142990. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142991. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142992. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142993. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142994. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142995. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142996. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142997. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142998. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142999. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  143000. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  143001. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  143002. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  143003. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  143004. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  143005. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  143006. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  143007. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  143008. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  143009. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  143010. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  143011. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  143012. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  143013. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  143014. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  143015. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  143016. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  143017. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  143018. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  143019. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  143020. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  143021. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  143022. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  143023. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  143024. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  143025. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  143026. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  143027. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  143028. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  143029. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  143030. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  143031. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  143032. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  143033. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  143034. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  143035. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  143036. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  143037. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  143038. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  143039. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  143040. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  143041. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  143042. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  143043. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  143044. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  143045. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  143046. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  143047. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  143048. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  143049. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  143050. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  143051. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  143052. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  143053. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  143054. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  143055. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  143056. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  143057. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  143058. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  143059. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  143060. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  143061. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  143062. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  143063. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  143064. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  143065. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  143066. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  143067. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  143068. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  143069. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  143070. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  143071. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  143072. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  143073. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  143074. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  143075. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  143076. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  143077. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  143078. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  143079. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  143080. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  143081. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  143082. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  143083. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  143084. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  143085. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  143086. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  143087. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  143088. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  143089. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  143090. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  143091. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  143092. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  143093. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  143094. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  143095. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  143096. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  143097. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  143098. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  143099. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  143100. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  143101. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  143102. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  143103. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  143104. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  143105. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  143106. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  143107. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  143108. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  143109. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  143110. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  143111. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  143112. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  143113. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  143114. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  143115. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  143116. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  143117. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  143118. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  143119. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  143120. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  143121. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  143122. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  143123. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  143124. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  143125. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  143126. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  143127. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  143128. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  143129. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  143130. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  143131. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  143132. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  143133. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  143134. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  143135. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  143136. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  143137. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  143138. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  143139. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  143140. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  143141. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  143142. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  143143. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  143144. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  143145. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  143146. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  143147. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  143148. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  143149. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  143150. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  143151. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  143152. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  143153. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  143154. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  143155. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  143156. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  143157. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  143158. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  143159. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  143160. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  143161. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  143162. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  143163. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  143164. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  143165. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  143166. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  143167. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  143168. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  143169. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  143170. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  143171. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  143172. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  143173. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  143174. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  143175. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  143176. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  143177. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  143178. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  143179. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  143180. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  143181. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  143182. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  143183. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  143184. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  143185. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  143186. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  143187. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  143188. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  143189. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  143190. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  143191. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  143192. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  143193. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  143194. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  143195. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  143196. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  143197. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  143198. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  143199. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  143200. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  143201. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  143202. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  143203. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  143204. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  143205. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  143206. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  143207. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  143208. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  143209. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  143210. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  143211. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  143212. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  143213. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  143214. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  143215. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  143216. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  143217. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  143218. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  143219. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  143220. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  143221. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  143222. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  143223. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  143224. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  143225. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  143226. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  143227. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  143228. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  143229. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  143230. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  143231. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  143232. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  143233. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  143234. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  143235. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  143236. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  143237. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  143238. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  143239. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  143240. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  143241. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  143242. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  143243. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  143244. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  143245. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  143246. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  143247. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  143248. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  143249. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  143250. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  143251. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  143252. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  143253. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  143254. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  143255. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  143256. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  143257. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  143258. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  143259. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  143260. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  143261. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  143262. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  143263. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  143264. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  143265. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  143266. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  143267. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  143268. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  143269. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  143270. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  143271. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  143272. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  143273. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  143274. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  143275. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  143276. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  143277. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  143278. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  143279. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  143280. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  143281. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  143282. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  143283. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  143284. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  143285. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  143286. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  143287. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  143288. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  143289. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  143290. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  143291. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  143292. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  143293. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  143294. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  143295. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  143296. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  143297. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  143298. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  143299. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  143300. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  143301. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  143302. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  143303. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  143304. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  143305. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143306. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143307. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143308. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143309. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143310. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143311. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143312. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143313. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143314. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143315. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143316. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143317. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143318. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143319. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143320. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143321. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143322. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143323. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143324. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143325. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143326. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143327. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143328. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143329. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143330. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143331. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143332. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143333. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143334. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143335. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143336. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143337. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143338. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143339. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143340. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143341. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143342. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143343. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143344. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143345. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143346. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143347. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143348. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143349. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143350. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143351. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143352. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143353. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143354. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143355. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143356. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143357. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143358. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143359. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143360. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143361. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143362. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143363. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143364. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143365. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143366. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143367. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143368. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143369. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143370. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143371. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143372. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143373. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143374. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143375. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143376. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143377. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143378. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143379. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143380. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143381. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143382. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143383. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143384. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143385. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143386. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143387. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143388. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143389. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143390. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143391. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143392. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143393. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143394. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143395. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143396. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143397. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143398. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143399. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143400. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143401. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143402. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143403. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143404. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143405. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143406. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143407. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143408. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143409. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143410. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143411. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143412. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143413. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143414. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143415. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143416. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143417. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143418. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143419. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143420. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143421. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143422. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143423. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143424. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143425. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143426. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143427. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143428. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143429. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143430. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143431. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143432. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143433. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143434. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143435. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143436. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143437. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143438. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143439. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143440. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143441. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143442. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143443. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143444. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143445. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143446. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143447. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143448. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143449. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143450. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143451. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143452. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143453. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143454. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143455. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143456. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143457. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143458. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143459. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143460. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143461. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143462. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143463. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143464. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143465. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143466. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143467. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143468. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143469. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143470. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143471. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143472. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143473. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143474. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143475. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143476. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143477. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143478. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143479. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143480. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143481. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143482. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143483. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143484. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143485. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143486. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143487. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143488. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143489. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143490. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143491. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143492. };
  143493. static float vwin8192[4096] = {
  143494. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143495. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143496. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143497. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143498. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143499. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143500. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143501. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143502. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143503. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143504. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143505. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143506. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143507. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143508. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143509. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143510. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143511. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143512. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143513. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143514. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143515. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143516. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143517. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143518. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143519. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143520. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143521. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143522. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143523. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143524. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143525. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143526. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143527. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143528. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143529. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143530. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143531. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143532. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143533. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143534. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143535. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143536. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143537. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143538. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143539. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143540. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143541. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143542. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143543. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143544. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143545. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143546. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143547. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143548. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143549. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143550. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143551. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143552. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143553. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143554. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143555. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143556. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143557. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143558. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143559. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143560. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143561. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143562. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143563. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143564. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143565. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143566. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143567. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143568. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143569. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143570. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143571. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143572. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143573. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143574. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143575. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143576. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143577. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143578. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143579. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143580. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143581. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143582. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143583. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143584. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143585. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143586. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143587. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143588. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143589. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143590. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143591. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143592. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143593. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143594. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143595. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143596. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143597. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143598. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143599. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143600. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143601. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143602. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143603. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143604. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143605. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143606. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143607. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143608. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143609. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143610. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143611. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143612. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143613. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143614. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143615. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143616. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143617. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143618. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143619. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143620. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143621. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143622. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143623. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143624. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143625. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143626. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143627. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143628. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143629. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143630. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143631. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143632. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143633. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143634. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143635. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143636. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143637. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143638. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143639. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143640. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143641. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143642. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143643. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143644. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143645. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143646. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143647. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143648. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143649. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143650. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143651. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143652. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143653. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143654. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143655. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143656. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143657. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143658. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143659. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143660. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143661. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143662. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143663. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143664. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143665. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143666. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143667. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143668. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143669. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143670. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143671. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143672. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143673. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143674. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143675. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143676. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143677. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143678. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143679. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143680. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143681. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143682. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143683. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143684. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143685. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143686. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143687. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143688. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143689. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143690. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143691. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143692. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143693. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143694. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143695. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143696. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143697. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143698. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143699. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143700. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143701. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143702. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143703. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143704. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143705. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143706. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143707. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143708. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143709. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143710. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143711. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143712. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143713. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143714. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143715. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143716. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143717. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143718. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143719. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143720. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143721. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143722. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143723. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143724. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143725. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143726. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143727. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143728. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143729. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143730. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143731. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143732. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143733. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143734. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143735. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143736. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143737. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143738. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143739. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143740. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143741. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143742. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143743. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143744. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143745. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143746. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143747. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143748. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143749. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143750. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143751. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143752. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143753. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143754. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143755. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143756. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143757. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143758. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143759. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143760. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143761. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143762. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143763. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143764. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143765. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143766. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143767. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143768. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143769. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143770. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143771. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143772. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143773. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143774. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143775. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143776. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143777. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143778. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143779. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143780. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143781. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143782. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143783. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143784. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143785. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143786. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143787. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143788. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143789. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143790. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143791. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143792. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143793. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143794. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143795. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143796. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143797. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143798. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143799. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143800. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143801. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143802. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143803. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143804. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143805. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143806. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143807. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143808. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143809. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143810. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143811. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143812. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143813. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143814. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143815. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143816. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143817. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143818. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143819. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143820. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143821. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143822. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143823. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143824. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143825. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143826. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143827. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143828. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143829. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143830. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143831. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143832. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143833. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143834. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143835. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143836. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143837. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143838. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143839. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143840. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143841. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143842. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143843. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143844. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143845. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143846. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143847. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143848. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143849. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143850. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143851. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143852. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143853. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143854. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143855. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143856. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143857. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143858. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143859. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143860. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143861. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143862. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143863. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143864. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143865. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143866. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143867. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143868. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143869. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143870. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143871. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143872. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143873. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143874. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143875. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143876. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143877. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143878. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143879. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143880. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143881. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143882. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143883. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143884. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143885. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143886. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143887. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143888. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143889. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143890. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143891. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143892. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143893. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143894. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143895. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143896. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143897. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143898. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143899. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143900. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143901. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143902. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143903. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143904. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143905. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143906. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143907. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143908. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143909. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143910. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143911. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143912. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143913. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143914. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143915. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143916. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143917. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143918. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143919. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143920. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143921. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143922. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143923. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143924. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143925. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143926. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143927. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143928. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143929. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143930. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143931. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143932. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143933. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143934. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143935. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143936. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143937. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143938. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143939. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143940. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143941. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143942. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143943. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143944. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143945. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143946. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143947. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143948. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143949. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143950. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143951. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143952. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143953. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143954. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143955. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143956. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143957. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143958. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143959. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143960. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143961. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143962. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143963. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143964. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143965. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143966. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143967. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143968. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143969. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143970. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143971. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143972. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143973. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143974. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143975. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143976. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143977. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143978. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143979. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143980. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143981. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143982. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143983. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143984. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143985. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143986. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143987. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143988. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143989. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143990. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143991. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143992. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143993. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143994. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143995. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143996. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143997. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143998. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143999. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  144000. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  144001. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  144002. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  144003. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  144004. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  144005. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  144006. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  144007. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  144008. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  144009. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  144010. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  144011. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  144012. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  144013. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  144014. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  144015. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  144016. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  144017. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  144018. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  144019. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  144020. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  144021. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  144022. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  144023. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  144024. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  144025. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  144026. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  144027. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  144028. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  144029. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  144030. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  144031. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  144032. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  144033. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  144034. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  144035. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  144036. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  144037. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  144038. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  144039. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  144040. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  144041. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  144042. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  144043. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  144044. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  144045. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  144046. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  144047. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  144048. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  144049. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  144050. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  144051. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  144052. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  144053. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  144054. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  144055. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  144056. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  144057. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  144058. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  144059. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  144060. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  144061. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  144062. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  144063. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  144064. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  144065. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  144066. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  144067. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  144068. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  144069. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  144070. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  144071. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  144072. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  144073. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  144074. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  144075. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  144076. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  144077. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  144078. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  144079. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  144080. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  144081. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  144082. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  144083. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  144084. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  144085. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  144086. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  144087. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  144088. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  144089. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  144090. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  144091. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  144092. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  144093. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  144094. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  144095. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  144096. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  144097. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  144098. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  144099. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  144100. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  144101. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  144102. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  144103. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  144104. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  144105. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  144106. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  144107. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  144108. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  144109. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  144110. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  144111. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  144112. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  144113. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  144114. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  144115. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  144116. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  144117. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  144118. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  144119. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  144120. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  144121. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  144122. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  144123. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  144124. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  144125. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  144126. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  144127. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  144128. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  144129. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  144130. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  144131. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  144132. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  144133. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  144134. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  144135. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  144136. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  144137. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  144138. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  144139. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  144140. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  144141. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  144142. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  144143. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  144144. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  144145. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  144146. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  144147. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  144148. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  144149. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  144150. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  144151. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  144152. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  144153. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  144154. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  144155. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  144156. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  144157. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  144158. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  144159. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  144160. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  144161. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  144162. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  144163. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  144164. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  144165. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  144166. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  144167. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  144168. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  144169. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  144170. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  144171. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  144172. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  144173. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  144174. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  144175. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  144176. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  144177. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  144178. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  144179. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  144180. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  144181. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  144182. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  144183. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  144184. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  144185. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  144186. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  144187. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  144188. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  144189. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  144190. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  144191. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  144192. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  144193. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  144194. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  144195. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  144196. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  144197. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  144198. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  144199. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  144200. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  144201. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  144202. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  144203. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  144204. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  144205. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  144206. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  144207. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  144208. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  144209. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  144210. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  144211. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  144212. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  144213. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  144214. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  144215. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  144216. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  144217. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  144218. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  144219. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  144220. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  144221. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  144222. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  144223. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  144224. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  144225. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  144226. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  144227. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  144228. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  144229. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  144230. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  144231. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  144232. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  144233. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  144234. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  144235. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  144236. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  144237. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  144238. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  144239. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  144240. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  144241. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  144242. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  144243. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  144244. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  144245. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  144246. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  144247. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  144248. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  144249. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  144250. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  144251. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  144252. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  144253. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  144254. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  144255. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  144256. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  144257. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  144258. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  144259. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  144260. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  144261. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  144262. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  144263. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  144264. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  144265. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  144266. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  144267. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  144268. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  144269. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  144270. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  144271. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  144272. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  144273. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  144274. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  144275. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  144276. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  144277. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  144278. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  144279. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  144280. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  144281. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  144282. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  144283. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  144284. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  144285. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  144286. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  144287. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  144288. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  144289. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  144290. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  144291. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  144292. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  144293. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  144294. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  144295. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  144296. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  144297. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  144298. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  144299. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  144300. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  144301. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  144302. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  144303. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  144304. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  144305. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144306. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144307. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144308. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144309. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144310. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144311. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144312. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144313. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144314. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144315. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144316. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144317. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144318. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144319. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144320. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144321. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144322. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144323. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144324. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144325. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144326. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144327. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144328. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144329. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144330. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144331. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144332. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144333. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144334. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144335. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144336. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144337. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144338. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144339. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144340. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144341. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144342. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144343. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144344. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144345. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144346. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144347. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144348. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144349. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144350. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144351. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144352. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144353. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144354. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144355. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144356. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144357. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144358. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144359. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144360. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144361. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144362. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144363. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144364. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144365. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144366. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144367. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144368. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144369. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144370. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144371. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144372. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144373. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144374. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144375. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144376. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144377. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144378. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144379. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144380. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144381. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144382. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144383. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144384. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144385. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144386. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144387. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144388. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144389. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144390. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144391. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144392. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144393. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144394. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144395. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144396. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144397. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144398. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144399. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144400. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144401. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144402. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144403. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144404. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144405. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144406. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144407. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144408. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144409. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144410. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144411. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144412. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144413. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144414. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144415. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144416. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144417. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144418. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144419. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144420. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144421. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144422. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144423. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144424. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144425. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144426. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144427. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144428. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144429. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144430. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144431. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144432. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144433. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144434. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144435. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144436. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144437. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144438. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144439. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144440. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144441. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144442. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144443. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144444. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144445. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144446. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144447. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144448. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144449. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144450. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144451. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144452. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144453. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144454. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144455. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144456. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144457. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144458. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144459. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144460. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144461. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144462. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144463. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144464. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144465. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144466. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144467. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144468. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144469. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144470. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144471. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144472. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144473. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144474. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144475. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144476. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144477. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144478. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144479. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144480. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144481. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144482. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144483. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144484. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144485. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144486. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144487. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144488. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144489. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144490. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144491. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144492. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144493. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144494. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144495. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144496. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144497. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144498. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144499. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144500. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144501. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144502. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144503. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144504. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144505. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144506. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144507. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144508. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144509. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144510. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144511. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144512. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144513. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144514. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144515. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144516. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144517. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144518. };
  144519. static float *vwin[8] = {
  144520. vwin64,
  144521. vwin128,
  144522. vwin256,
  144523. vwin512,
  144524. vwin1024,
  144525. vwin2048,
  144526. vwin4096,
  144527. vwin8192,
  144528. };
  144529. float *_vorbis_window_get(int n){
  144530. return vwin[n];
  144531. }
  144532. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144533. int lW,int W,int nW){
  144534. lW=(W?lW:0);
  144535. nW=(W?nW:0);
  144536. {
  144537. float *windowLW=vwin[winno[lW]];
  144538. float *windowNW=vwin[winno[nW]];
  144539. long n=blocksizes[W];
  144540. long ln=blocksizes[lW];
  144541. long rn=blocksizes[nW];
  144542. long leftbegin=n/4-ln/4;
  144543. long leftend=leftbegin+ln/2;
  144544. long rightbegin=n/2+n/4-rn/4;
  144545. long rightend=rightbegin+rn/2;
  144546. int i,p;
  144547. for(i=0;i<leftbegin;i++)
  144548. d[i]=0.f;
  144549. for(p=0;i<leftend;i++,p++)
  144550. d[i]*=windowLW[p];
  144551. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144552. d[i]*=windowNW[p];
  144553. for(;i<n;i++)
  144554. d[i]=0.f;
  144555. }
  144556. }
  144557. #endif
  144558. /*** End of inlined file: window.c ***/
  144559. #else
  144560. #include <vorbis/vorbisenc.h>
  144561. #include <vorbis/codec.h>
  144562. #include <vorbis/vorbisfile.h>
  144563. #endif
  144564. }
  144565. BEGIN_JUCE_NAMESPACE
  144566. using namespace OggVorbisNamespace;
  144567. static const char* const oggFormatName = "Ogg-Vorbis file";
  144568. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144569. class OggReader : public AudioFormatReader
  144570. {
  144571. OggVorbis_File ovFile;
  144572. ov_callbacks callbacks;
  144573. AudioSampleBuffer reservoir;
  144574. int reservoirStart, samplesInReservoir;
  144575. public:
  144576. OggReader (InputStream* const inp)
  144577. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144578. reservoir (2, 4096),
  144579. reservoirStart (0),
  144580. samplesInReservoir (0)
  144581. {
  144582. sampleRate = 0;
  144583. usesFloatingPointData = true;
  144584. callbacks.read_func = &oggReadCallback;
  144585. callbacks.seek_func = &oggSeekCallback;
  144586. callbacks.close_func = &oggCloseCallback;
  144587. callbacks.tell_func = &oggTellCallback;
  144588. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144589. if (err == 0)
  144590. {
  144591. vorbis_info* info = ov_info (&ovFile, -1);
  144592. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144593. numChannels = info->channels;
  144594. bitsPerSample = 16;
  144595. sampleRate = info->rate;
  144596. reservoir.setSize (numChannels,
  144597. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144598. }
  144599. }
  144600. ~OggReader()
  144601. {
  144602. ov_clear (&ovFile);
  144603. }
  144604. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144605. int64 startSampleInFile, int numSamples)
  144606. {
  144607. while (numSamples > 0)
  144608. {
  144609. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144610. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144611. {
  144612. // got a few samples overlapping, so use them before seeking..
  144613. const int numToUse = jmin (numSamples, numAvailable);
  144614. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144615. if (destSamples[i] != 0)
  144616. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144617. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144618. sizeof (float) * numToUse);
  144619. startSampleInFile += numToUse;
  144620. numSamples -= numToUse;
  144621. startOffsetInDestBuffer += numToUse;
  144622. if (numSamples == 0)
  144623. break;
  144624. }
  144625. if (startSampleInFile < reservoirStart
  144626. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144627. {
  144628. // buffer miss, so refill the reservoir
  144629. int bitStream = 0;
  144630. reservoirStart = jmax (0, (int) startSampleInFile);
  144631. samplesInReservoir = reservoir.getNumSamples();
  144632. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  144633. ov_pcm_seek (&ovFile, reservoirStart);
  144634. int offset = 0;
  144635. int numToRead = samplesInReservoir;
  144636. while (numToRead > 0)
  144637. {
  144638. float** dataIn = 0;
  144639. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144640. if (samps <= 0)
  144641. break;
  144642. jassert (samps <= numToRead);
  144643. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144644. {
  144645. memcpy (reservoir.getSampleData (i, offset),
  144646. dataIn[i],
  144647. sizeof (float) * samps);
  144648. }
  144649. numToRead -= samps;
  144650. offset += samps;
  144651. }
  144652. if (numToRead > 0)
  144653. reservoir.clear (offset, numToRead);
  144654. }
  144655. }
  144656. if (numSamples > 0)
  144657. {
  144658. for (int i = numDestChannels; --i >= 0;)
  144659. if (destSamples[i] != 0)
  144660. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144661. sizeof (int) * numSamples);
  144662. }
  144663. return true;
  144664. }
  144665. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144666. {
  144667. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144668. }
  144669. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  144670. {
  144671. InputStream* const in = (InputStream*) datasource;
  144672. if (whence == SEEK_CUR)
  144673. offset += in->getPosition();
  144674. else if (whence == SEEK_END)
  144675. offset += in->getTotalLength();
  144676. in->setPosition (offset);
  144677. return 0;
  144678. }
  144679. static int oggCloseCallback (void*)
  144680. {
  144681. return 0;
  144682. }
  144683. static long oggTellCallback (void* datasource)
  144684. {
  144685. return (long) ((InputStream*) datasource)->getPosition();
  144686. }
  144687. juce_UseDebuggingNewOperator
  144688. };
  144689. class OggWriter : public AudioFormatWriter
  144690. {
  144691. ogg_stream_state os;
  144692. ogg_page og;
  144693. ogg_packet op;
  144694. vorbis_info vi;
  144695. vorbis_comment vc;
  144696. vorbis_dsp_state vd;
  144697. vorbis_block vb;
  144698. public:
  144699. bool ok;
  144700. OggWriter (OutputStream* const out,
  144701. const double sampleRate,
  144702. const int numChannels,
  144703. const int bitsPerSample,
  144704. const int qualityIndex)
  144705. : AudioFormatWriter (out, TRANS (oggFormatName),
  144706. sampleRate,
  144707. numChannels,
  144708. bitsPerSample)
  144709. {
  144710. ok = false;
  144711. vorbis_info_init (&vi);
  144712. if (vorbis_encode_init_vbr (&vi,
  144713. numChannels,
  144714. (int) sampleRate,
  144715. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144716. {
  144717. vorbis_comment_init (&vc);
  144718. if (JUCEApplication::getInstance() != 0)
  144719. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144720. vorbis_analysis_init (&vd, &vi);
  144721. vorbis_block_init (&vd, &vb);
  144722. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144723. ogg_packet header;
  144724. ogg_packet header_comm;
  144725. ogg_packet header_code;
  144726. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144727. ogg_stream_packetin (&os, &header);
  144728. ogg_stream_packetin (&os, &header_comm);
  144729. ogg_stream_packetin (&os, &header_code);
  144730. for (;;)
  144731. {
  144732. if (ogg_stream_flush (&os, &og) == 0)
  144733. break;
  144734. output->write (og.header, og.header_len);
  144735. output->write (og.body, og.body_len);
  144736. }
  144737. ok = true;
  144738. }
  144739. }
  144740. ~OggWriter()
  144741. {
  144742. if (ok)
  144743. {
  144744. // write a zero-length packet to show ogg that we're finished..
  144745. write (0, 0);
  144746. ogg_stream_clear (&os);
  144747. vorbis_block_clear (&vb);
  144748. vorbis_dsp_clear (&vd);
  144749. vorbis_comment_clear (&vc);
  144750. vorbis_info_clear (&vi);
  144751. output->flush();
  144752. }
  144753. else
  144754. {
  144755. vorbis_info_clear (&vi);
  144756. output = 0; // to stop the base class deleting this, as it needs to be returned
  144757. // to the caller of createWriter()
  144758. }
  144759. }
  144760. bool write (const int** samplesToWrite, int numSamples)
  144761. {
  144762. if (! ok)
  144763. return false;
  144764. if (numSamples > 0)
  144765. {
  144766. const double gain = 1.0 / 0x80000000u;
  144767. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144768. for (int i = numChannels; --i >= 0;)
  144769. {
  144770. float* const dst = vorbisBuffer[i];
  144771. const int* const src = samplesToWrite [i];
  144772. if (src != 0 && dst != 0)
  144773. {
  144774. for (int j = 0; j < numSamples; ++j)
  144775. dst[j] = (float) (src[j] * gain);
  144776. }
  144777. }
  144778. }
  144779. vorbis_analysis_wrote (&vd, numSamples);
  144780. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144781. {
  144782. vorbis_analysis (&vb, 0);
  144783. vorbis_bitrate_addblock (&vb);
  144784. while (vorbis_bitrate_flushpacket (&vd, &op))
  144785. {
  144786. ogg_stream_packetin (&os, &op);
  144787. for (;;)
  144788. {
  144789. if (ogg_stream_pageout (&os, &og) == 0)
  144790. break;
  144791. output->write (og.header, og.header_len);
  144792. output->write (og.body, og.body_len);
  144793. if (ogg_page_eos (&og))
  144794. break;
  144795. }
  144796. }
  144797. }
  144798. return true;
  144799. }
  144800. juce_UseDebuggingNewOperator
  144801. };
  144802. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144803. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144804. {
  144805. }
  144806. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144807. {
  144808. }
  144809. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144810. {
  144811. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144812. return Array <int> (rates);
  144813. }
  144814. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144815. {
  144816. Array <int> depths;
  144817. depths.add (32);
  144818. return depths;
  144819. }
  144820. bool OggVorbisAudioFormat::canDoStereo()
  144821. {
  144822. return true;
  144823. }
  144824. bool OggVorbisAudioFormat::canDoMono()
  144825. {
  144826. return true;
  144827. }
  144828. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144829. const bool deleteStreamIfOpeningFails)
  144830. {
  144831. ScopedPointer <OggReader> r (new OggReader (in));
  144832. if (r->sampleRate != 0)
  144833. return r.release();
  144834. if (! deleteStreamIfOpeningFails)
  144835. r->input = 0;
  144836. return 0;
  144837. }
  144838. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144839. double sampleRate,
  144840. unsigned int numChannels,
  144841. int bitsPerSample,
  144842. const StringPairArray& /*metadataValues*/,
  144843. int qualityOptionIndex)
  144844. {
  144845. ScopedPointer <OggWriter> w (new OggWriter (out,
  144846. sampleRate,
  144847. numChannels,
  144848. bitsPerSample,
  144849. qualityOptionIndex));
  144850. return w->ok ? w.release() : 0;
  144851. }
  144852. bool OggVorbisAudioFormat::isCompressed()
  144853. {
  144854. return true;
  144855. }
  144856. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144857. {
  144858. StringArray s;
  144859. s.add ("Low Quality");
  144860. s.add ("Medium Quality");
  144861. s.add ("High Quality");
  144862. return s;
  144863. }
  144864. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144865. {
  144866. FileInputStream* const in = source.createInputStream();
  144867. if (in != 0)
  144868. {
  144869. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144870. if (r != 0)
  144871. {
  144872. const int64 numSamps = r->lengthInSamples;
  144873. r = 0;
  144874. const int64 fileNumSamps = source.getSize() / 4;
  144875. const double ratio = numSamps / (double) fileNumSamps;
  144876. if (ratio > 12.0)
  144877. return 0;
  144878. else if (ratio > 6.0)
  144879. return 1;
  144880. else
  144881. return 2;
  144882. }
  144883. }
  144884. return 1;
  144885. }
  144886. END_JUCE_NAMESPACE
  144887. #endif
  144888. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144889. #endif
  144890. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144891. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144892. #if JUCE_MSVC
  144893. #pragma warning (push)
  144894. #endif
  144895. namespace jpeglibNamespace
  144896. {
  144897. #if JUCE_INCLUDE_JPEGLIB_CODE
  144898. #if JUCE_MINGW
  144899. typedef unsigned char boolean;
  144900. #endif
  144901. extern "C"
  144902. {
  144903. #define JPEG_INTERNALS
  144904. #undef FAR
  144905. /*** Start of inlined file: jpeglib.h ***/
  144906. #ifndef JPEGLIB_H
  144907. #define JPEGLIB_H
  144908. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144909. /*** Start of inlined file: jconfig.h ***/
  144910. // disable all the warnings under MSVC
  144911. #ifdef _MSC_VER
  144912. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144913. #endif
  144914. #ifdef __BORLANDC__
  144915. #pragma warn -8057
  144916. #pragma warn -8019
  144917. #pragma warn -8004
  144918. #pragma warn -8008
  144919. #endif
  144920. #define HAVE_PROTOTYPES
  144921. #define HAVE_UNSIGNED_CHAR
  144922. #define HAVE_UNSIGNED_SHORT
  144923. #undef CHAR_IS_UNSIGNED
  144924. #define HAVE_STDDEF_H
  144925. #define HAVE_STDLIB_H
  144926. #undef NEED_BSD_STRINGS
  144927. #undef NEED_SYS_TYPES_H
  144928. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144929. #undef NEED_SHORT_EXTERNAL_NAMES
  144930. #undef INCOMPLETE_TYPES_BROKEN
  144931. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144932. typedef unsigned char boolean;
  144933. #endif
  144934. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144935. #ifdef JPEG_INTERNALS
  144936. #undef RIGHT_SHIFT_IS_UNSIGNED
  144937. #endif /* JPEG_INTERNALS */
  144938. #ifdef JPEG_CJPEG_DJPEG
  144939. #define BMP_SUPPORTED /* BMP image file format */
  144940. #define GIF_SUPPORTED /* GIF image file format */
  144941. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144942. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144943. #define TARGA_SUPPORTED /* Targa image file format */
  144944. #define TWO_FILE_COMMANDLINE /* optional */
  144945. #define USE_SETMODE /* Microsoft has setmode() */
  144946. #undef NEED_SIGNAL_CATCHER
  144947. #undef DONT_USE_B_MODE
  144948. #undef PROGRESS_REPORT /* optional */
  144949. #endif /* JPEG_CJPEG_DJPEG */
  144950. /*** End of inlined file: jconfig.h ***/
  144951. /* widely used configuration options */
  144952. #endif
  144953. /*** Start of inlined file: jmorecfg.h ***/
  144954. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144955. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144956. #if BITS_IN_JSAMPLE == 8
  144957. #ifdef HAVE_UNSIGNED_CHAR
  144958. typedef unsigned char JSAMPLE;
  144959. #define GETJSAMPLE(value) ((int) (value))
  144960. #else /* not HAVE_UNSIGNED_CHAR */
  144961. typedef char JSAMPLE;
  144962. #ifdef CHAR_IS_UNSIGNED
  144963. #define GETJSAMPLE(value) ((int) (value))
  144964. #else
  144965. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144966. #endif /* CHAR_IS_UNSIGNED */
  144967. #endif /* HAVE_UNSIGNED_CHAR */
  144968. #define MAXJSAMPLE 255
  144969. #define CENTERJSAMPLE 128
  144970. #endif /* BITS_IN_JSAMPLE == 8 */
  144971. #if BITS_IN_JSAMPLE == 12
  144972. typedef short JSAMPLE;
  144973. #define GETJSAMPLE(value) ((int) (value))
  144974. #define MAXJSAMPLE 4095
  144975. #define CENTERJSAMPLE 2048
  144976. #endif /* BITS_IN_JSAMPLE == 12 */
  144977. typedef short JCOEF;
  144978. #ifdef HAVE_UNSIGNED_CHAR
  144979. typedef unsigned char JOCTET;
  144980. #define GETJOCTET(value) (value)
  144981. #else /* not HAVE_UNSIGNED_CHAR */
  144982. typedef char JOCTET;
  144983. #ifdef CHAR_IS_UNSIGNED
  144984. #define GETJOCTET(value) (value)
  144985. #else
  144986. #define GETJOCTET(value) ((value) & 0xFF)
  144987. #endif /* CHAR_IS_UNSIGNED */
  144988. #endif /* HAVE_UNSIGNED_CHAR */
  144989. #ifdef HAVE_UNSIGNED_CHAR
  144990. typedef unsigned char UINT8;
  144991. #else /* not HAVE_UNSIGNED_CHAR */
  144992. #ifdef CHAR_IS_UNSIGNED
  144993. typedef char UINT8;
  144994. #else /* not CHAR_IS_UNSIGNED */
  144995. typedef short UINT8;
  144996. #endif /* CHAR_IS_UNSIGNED */
  144997. #endif /* HAVE_UNSIGNED_CHAR */
  144998. #ifdef HAVE_UNSIGNED_SHORT
  144999. typedef unsigned short UINT16;
  145000. #else /* not HAVE_UNSIGNED_SHORT */
  145001. typedef unsigned int UINT16;
  145002. #endif /* HAVE_UNSIGNED_SHORT */
  145003. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  145004. typedef short INT16;
  145005. #endif
  145006. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  145007. typedef long INT32;
  145008. #endif
  145009. typedef unsigned int JDIMENSION;
  145010. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  145011. #define METHODDEF(type) static type
  145012. #define LOCAL(type) static type
  145013. #define GLOBAL(type) type
  145014. #define EXTERN(type) extern type
  145015. #ifdef HAVE_PROTOTYPES
  145016. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  145017. #else
  145018. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  145019. #endif
  145020. #ifdef NEED_FAR_POINTERS
  145021. #define FAR far
  145022. #else
  145023. #define FAR
  145024. #endif
  145025. #ifndef HAVE_BOOLEAN
  145026. typedef int boolean;
  145027. #endif
  145028. #ifndef FALSE /* in case these macros already exist */
  145029. #define FALSE 0 /* values of boolean */
  145030. #endif
  145031. #ifndef TRUE
  145032. #define TRUE 1
  145033. #endif
  145034. #ifdef JPEG_INTERNALS
  145035. #define JPEG_INTERNAL_OPTIONS
  145036. #endif
  145037. #ifdef JPEG_INTERNAL_OPTIONS
  145038. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  145039. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  145040. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  145041. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145042. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145043. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145044. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  145045. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  145046. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145047. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145048. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145049. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  145050. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  145051. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  145052. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  145053. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  145054. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  145055. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  145056. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  145057. #define RGB_GREEN 1 /* Offset of Green */
  145058. #define RGB_BLUE 2 /* Offset of Blue */
  145059. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  145060. #ifndef INLINE
  145061. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  145062. #define INLINE __inline__
  145063. #endif
  145064. #ifndef INLINE
  145065. #define INLINE /* default is to define it as empty */
  145066. #endif
  145067. #endif
  145068. #ifndef MULTIPLIER
  145069. #define MULTIPLIER int /* type for fastest integer multiply */
  145070. #endif
  145071. #ifndef FAST_FLOAT
  145072. #ifdef HAVE_PROTOTYPES
  145073. #define FAST_FLOAT float
  145074. #else
  145075. #define FAST_FLOAT double
  145076. #endif
  145077. #endif
  145078. #endif /* JPEG_INTERNAL_OPTIONS */
  145079. /*** End of inlined file: jmorecfg.h ***/
  145080. /* seldom changed options */
  145081. #define JPEG_LIB_VERSION 62 /* Version 6b */
  145082. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  145083. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  145084. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  145085. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  145086. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  145087. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  145088. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  145089. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  145090. #ifndef D_MAX_BLOCKS_IN_MCU
  145091. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  145092. #endif
  145093. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  145094. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  145095. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  145096. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  145097. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  145098. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  145099. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  145100. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  145101. typedef struct {
  145102. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  145103. boolean sent_table; /* TRUE when table has been output */
  145104. } JQUANT_TBL;
  145105. typedef struct {
  145106. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  145107. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  145108. boolean sent_table; /* TRUE when table has been output */
  145109. } JHUFF_TBL;
  145110. typedef struct {
  145111. int component_id; /* identifier for this component (0..255) */
  145112. int component_index; /* its index in SOF or cinfo->comp_info[] */
  145113. int h_samp_factor; /* horizontal sampling factor (1..4) */
  145114. int v_samp_factor; /* vertical sampling factor (1..4) */
  145115. int quant_tbl_no; /* quantization table selector (0..3) */
  145116. int dc_tbl_no; /* DC entropy table selector (0..3) */
  145117. int ac_tbl_no; /* AC entropy table selector (0..3) */
  145118. JDIMENSION width_in_blocks;
  145119. JDIMENSION height_in_blocks;
  145120. int DCT_scaled_size;
  145121. JDIMENSION downsampled_width; /* actual width in samples */
  145122. JDIMENSION downsampled_height; /* actual height in samples */
  145123. boolean component_needed; /* do we need the value of this component? */
  145124. int MCU_width; /* number of blocks per MCU, horizontally */
  145125. int MCU_height; /* number of blocks per MCU, vertically */
  145126. int MCU_blocks; /* MCU_width * MCU_height */
  145127. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  145128. int last_col_width; /* # of non-dummy blocks across in last MCU */
  145129. int last_row_height; /* # of non-dummy blocks down in last MCU */
  145130. JQUANT_TBL * quant_table;
  145131. void * dct_table;
  145132. } jpeg_component_info;
  145133. typedef struct {
  145134. int comps_in_scan; /* number of components encoded in this scan */
  145135. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  145136. int Ss, Se; /* progressive JPEG spectral selection parms */
  145137. int Ah, Al; /* progressive JPEG successive approx. parms */
  145138. } jpeg_scan_info;
  145139. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  145140. struct jpeg_marker_struct {
  145141. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  145142. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  145143. unsigned int original_length; /* # bytes of data in the file */
  145144. unsigned int data_length; /* # bytes of data saved at data[] */
  145145. JOCTET FAR * data; /* the data contained in the marker */
  145146. };
  145147. typedef enum {
  145148. JCS_UNKNOWN, /* error/unspecified */
  145149. JCS_GRAYSCALE, /* monochrome */
  145150. JCS_RGB, /* red/green/blue */
  145151. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  145152. JCS_CMYK, /* C/M/Y/K */
  145153. JCS_YCCK /* Y/Cb/Cr/K */
  145154. } J_COLOR_SPACE;
  145155. typedef enum {
  145156. JDCT_ISLOW, /* slow but accurate integer algorithm */
  145157. JDCT_IFAST, /* faster, less accurate integer method */
  145158. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  145159. } J_DCT_METHOD;
  145160. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  145161. #define JDCT_DEFAULT JDCT_ISLOW
  145162. #endif
  145163. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  145164. #define JDCT_FASTEST JDCT_IFAST
  145165. #endif
  145166. typedef enum {
  145167. JDITHER_NONE, /* no dithering */
  145168. JDITHER_ORDERED, /* simple ordered dither */
  145169. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  145170. } J_DITHER_MODE;
  145171. #define jpeg_common_fields \
  145172. struct jpeg_error_mgr * err; /* Error handler module */\
  145173. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  145174. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  145175. void * client_data; /* Available for use by application */\
  145176. boolean is_decompressor; /* So common code can tell which is which */\
  145177. int global_state /* For checking call sequence validity */
  145178. struct jpeg_common_struct {
  145179. jpeg_common_fields; /* Fields common to both master struct types */
  145180. };
  145181. typedef struct jpeg_common_struct * j_common_ptr;
  145182. typedef struct jpeg_compress_struct * j_compress_ptr;
  145183. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  145184. struct jpeg_compress_struct {
  145185. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  145186. struct jpeg_destination_mgr * dest;
  145187. JDIMENSION image_width; /* input image width */
  145188. JDIMENSION image_height; /* input image height */
  145189. int input_components; /* # of color components in input image */
  145190. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  145191. double input_gamma; /* image gamma of input image */
  145192. int data_precision; /* bits of precision in image data */
  145193. int num_components; /* # of color components in JPEG image */
  145194. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145195. jpeg_component_info * comp_info;
  145196. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145197. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145198. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145199. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145200. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145201. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145202. int num_scans; /* # of entries in scan_info array */
  145203. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  145204. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  145205. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145206. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  145207. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145208. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  145209. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  145210. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  145211. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  145212. boolean write_JFIF_header; /* should a JFIF marker be written? */
  145213. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  145214. UINT8 JFIF_minor_version;
  145215. UINT8 density_unit; /* JFIF code for pixel size units */
  145216. UINT16 X_density; /* Horizontal pixel density */
  145217. UINT16 Y_density; /* Vertical pixel density */
  145218. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  145219. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  145220. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  145221. int max_h_samp_factor; /* largest h_samp_factor */
  145222. int max_v_samp_factor; /* largest v_samp_factor */
  145223. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  145224. int comps_in_scan; /* # of JPEG components in this scan */
  145225. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145226. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145227. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145228. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145229. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  145230. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145231. struct jpeg_comp_master * master;
  145232. struct jpeg_c_main_controller * main;
  145233. struct jpeg_c_prep_controller * prep;
  145234. struct jpeg_c_coef_controller * coef;
  145235. struct jpeg_marker_writer * marker;
  145236. struct jpeg_color_converter * cconvert;
  145237. struct jpeg_downsampler * downsample;
  145238. struct jpeg_forward_dct * fdct;
  145239. struct jpeg_entropy_encoder * entropy;
  145240. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  145241. int script_space_size;
  145242. };
  145243. struct jpeg_decompress_struct {
  145244. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  145245. struct jpeg_source_mgr * src;
  145246. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  145247. JDIMENSION image_height; /* nominal image height */
  145248. int num_components; /* # of color components in JPEG image */
  145249. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145250. J_COLOR_SPACE out_color_space; /* colorspace for output */
  145251. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  145252. double output_gamma; /* image gamma wanted in output */
  145253. boolean buffered_image; /* TRUE=multiple output passes */
  145254. boolean raw_data_out; /* TRUE=downsampled data wanted */
  145255. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  145256. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  145257. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  145258. boolean quantize_colors; /* TRUE=colormapped output wanted */
  145259. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  145260. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  145261. int desired_number_of_colors; /* max # colors to use in created colormap */
  145262. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  145263. boolean enable_external_quant;/* enable future use of external colormap */
  145264. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  145265. JDIMENSION output_width; /* scaled image width */
  145266. JDIMENSION output_height; /* scaled image height */
  145267. int out_color_components; /* # of color components in out_color_space */
  145268. int output_components; /* # of color components returned */
  145269. int rec_outbuf_height; /* min recommended height of scanline buffer */
  145270. int actual_number_of_colors; /* number of entries in use */
  145271. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  145272. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  145273. int input_scan_number; /* Number of SOS markers seen so far */
  145274. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  145275. int output_scan_number; /* Nominal scan number being displayed */
  145276. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  145277. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  145278. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145279. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145280. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145281. int data_precision; /* bits of precision in image data */
  145282. jpeg_component_info * comp_info;
  145283. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  145284. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145285. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145286. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145287. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145288. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  145289. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  145290. UINT8 JFIF_major_version; /* JFIF version number */
  145291. UINT8 JFIF_minor_version;
  145292. UINT8 density_unit; /* JFIF code for pixel size units */
  145293. UINT16 X_density; /* Horizontal pixel density */
  145294. UINT16 Y_density; /* Vertical pixel density */
  145295. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  145296. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  145297. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145298. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  145299. int max_h_samp_factor; /* largest h_samp_factor */
  145300. int max_v_samp_factor; /* largest v_samp_factor */
  145301. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  145302. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  145303. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  145304. int comps_in_scan; /* # of JPEG components in this scan */
  145305. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145306. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145307. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145308. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145309. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145310. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145311. int unread_marker;
  145312. struct jpeg_decomp_master * master;
  145313. struct jpeg_d_main_controller * main;
  145314. struct jpeg_d_coef_controller * coef;
  145315. struct jpeg_d_post_controller * post;
  145316. struct jpeg_input_controller * inputctl;
  145317. struct jpeg_marker_reader * marker;
  145318. struct jpeg_entropy_decoder * entropy;
  145319. struct jpeg_inverse_dct * idct;
  145320. struct jpeg_upsampler * upsample;
  145321. struct jpeg_color_deconverter * cconvert;
  145322. struct jpeg_color_quantizer * cquantize;
  145323. };
  145324. struct jpeg_error_mgr {
  145325. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145326. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145327. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145328. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145329. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145330. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145331. int msg_code;
  145332. #define JMSG_STR_PARM_MAX 80
  145333. union {
  145334. int i[8];
  145335. char s[JMSG_STR_PARM_MAX];
  145336. } msg_parm;
  145337. int trace_level; /* max msg_level that will be displayed */
  145338. long num_warnings; /* number of corrupt-data warnings */
  145339. const char * const * jpeg_message_table; /* Library errors */
  145340. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145341. const char * const * addon_message_table; /* Non-library errors */
  145342. int first_addon_message; /* code for first string in addon table */
  145343. int last_addon_message; /* code for last string in addon table */
  145344. };
  145345. struct jpeg_progress_mgr {
  145346. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145347. long pass_counter; /* work units completed in this pass */
  145348. long pass_limit; /* total number of work units in this pass */
  145349. int completed_passes; /* passes completed so far */
  145350. int total_passes; /* total number of passes expected */
  145351. };
  145352. struct jpeg_destination_mgr {
  145353. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145354. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145355. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145356. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145357. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145358. };
  145359. struct jpeg_source_mgr {
  145360. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145361. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145362. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145363. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145364. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145365. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145366. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145367. };
  145368. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145369. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145370. #define JPOOL_NUMPOOLS 2
  145371. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145372. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145373. struct jpeg_memory_mgr {
  145374. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145375. size_t sizeofobject));
  145376. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145377. size_t sizeofobject));
  145378. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145379. JDIMENSION samplesperrow,
  145380. JDIMENSION numrows));
  145381. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145382. JDIMENSION blocksperrow,
  145383. JDIMENSION numrows));
  145384. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145385. int pool_id,
  145386. boolean pre_zero,
  145387. JDIMENSION samplesperrow,
  145388. JDIMENSION numrows,
  145389. JDIMENSION maxaccess));
  145390. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145391. int pool_id,
  145392. boolean pre_zero,
  145393. JDIMENSION blocksperrow,
  145394. JDIMENSION numrows,
  145395. JDIMENSION maxaccess));
  145396. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145397. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145398. jvirt_sarray_ptr ptr,
  145399. JDIMENSION start_row,
  145400. JDIMENSION num_rows,
  145401. boolean writable));
  145402. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145403. jvirt_barray_ptr ptr,
  145404. JDIMENSION start_row,
  145405. JDIMENSION num_rows,
  145406. boolean writable));
  145407. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145408. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145409. long max_memory_to_use;
  145410. long max_alloc_chunk;
  145411. };
  145412. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145413. #ifdef HAVE_PROTOTYPES
  145414. #define JPP(arglist) arglist
  145415. #else
  145416. #define JPP(arglist) ()
  145417. #endif
  145418. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145419. #define jpeg_std_error jStdError
  145420. #define jpeg_CreateCompress jCreaCompress
  145421. #define jpeg_CreateDecompress jCreaDecompress
  145422. #define jpeg_destroy_compress jDestCompress
  145423. #define jpeg_destroy_decompress jDestDecompress
  145424. #define jpeg_stdio_dest jStdDest
  145425. #define jpeg_stdio_src jStdSrc
  145426. #define jpeg_set_defaults jSetDefaults
  145427. #define jpeg_set_colorspace jSetColorspace
  145428. #define jpeg_default_colorspace jDefColorspace
  145429. #define jpeg_set_quality jSetQuality
  145430. #define jpeg_set_linear_quality jSetLQuality
  145431. #define jpeg_add_quant_table jAddQuantTable
  145432. #define jpeg_quality_scaling jQualityScaling
  145433. #define jpeg_simple_progression jSimProgress
  145434. #define jpeg_suppress_tables jSuppressTables
  145435. #define jpeg_alloc_quant_table jAlcQTable
  145436. #define jpeg_alloc_huff_table jAlcHTable
  145437. #define jpeg_start_compress jStrtCompress
  145438. #define jpeg_write_scanlines jWrtScanlines
  145439. #define jpeg_finish_compress jFinCompress
  145440. #define jpeg_write_raw_data jWrtRawData
  145441. #define jpeg_write_marker jWrtMarker
  145442. #define jpeg_write_m_header jWrtMHeader
  145443. #define jpeg_write_m_byte jWrtMByte
  145444. #define jpeg_write_tables jWrtTables
  145445. #define jpeg_read_header jReadHeader
  145446. #define jpeg_start_decompress jStrtDecompress
  145447. #define jpeg_read_scanlines jReadScanlines
  145448. #define jpeg_finish_decompress jFinDecompress
  145449. #define jpeg_read_raw_data jReadRawData
  145450. #define jpeg_has_multiple_scans jHasMultScn
  145451. #define jpeg_start_output jStrtOutput
  145452. #define jpeg_finish_output jFinOutput
  145453. #define jpeg_input_complete jInComplete
  145454. #define jpeg_new_colormap jNewCMap
  145455. #define jpeg_consume_input jConsumeInput
  145456. #define jpeg_calc_output_dimensions jCalcDimensions
  145457. #define jpeg_save_markers jSaveMarkers
  145458. #define jpeg_set_marker_processor jSetMarker
  145459. #define jpeg_read_coefficients jReadCoefs
  145460. #define jpeg_write_coefficients jWrtCoefs
  145461. #define jpeg_copy_critical_parameters jCopyCrit
  145462. #define jpeg_abort_compress jAbrtCompress
  145463. #define jpeg_abort_decompress jAbrtDecompress
  145464. #define jpeg_abort jAbort
  145465. #define jpeg_destroy jDestroy
  145466. #define jpeg_resync_to_restart jResyncRestart
  145467. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145468. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145469. JPP((struct jpeg_error_mgr * err));
  145470. #define jpeg_create_compress(cinfo) \
  145471. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145472. (size_t) sizeof(struct jpeg_compress_struct))
  145473. #define jpeg_create_decompress(cinfo) \
  145474. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145475. (size_t) sizeof(struct jpeg_decompress_struct))
  145476. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145477. int version, size_t structsize));
  145478. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145479. int version, size_t structsize));
  145480. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145481. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145482. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145483. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145484. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145485. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145486. J_COLOR_SPACE colorspace));
  145487. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145488. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145489. boolean force_baseline));
  145490. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145491. int scale_factor,
  145492. boolean force_baseline));
  145493. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145494. const unsigned int *basic_table,
  145495. int scale_factor,
  145496. boolean force_baseline));
  145497. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145498. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145499. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145500. boolean suppress));
  145501. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145502. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145503. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145504. boolean write_all_tables));
  145505. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145506. JSAMPARRAY scanlines,
  145507. JDIMENSION num_lines));
  145508. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145509. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145510. JSAMPIMAGE data,
  145511. JDIMENSION num_lines));
  145512. EXTERN(void) jpeg_write_marker
  145513. JPP((j_compress_ptr cinfo, int marker,
  145514. const JOCTET * dataptr, unsigned int datalen));
  145515. EXTERN(void) jpeg_write_m_header
  145516. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145517. EXTERN(void) jpeg_write_m_byte
  145518. JPP((j_compress_ptr cinfo, int val));
  145519. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145520. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145521. boolean require_image));
  145522. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145523. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145524. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145525. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145526. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145527. JSAMPARRAY scanlines,
  145528. JDIMENSION max_lines));
  145529. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145530. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145531. JSAMPIMAGE data,
  145532. JDIMENSION max_lines));
  145533. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145534. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145535. int scan_number));
  145536. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145537. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145538. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145539. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145540. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145541. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145542. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145543. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145544. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145545. EXTERN(void) jpeg_save_markers
  145546. JPP((j_decompress_ptr cinfo, int marker_code,
  145547. unsigned int length_limit));
  145548. EXTERN(void) jpeg_set_marker_processor
  145549. JPP((j_decompress_ptr cinfo, int marker_code,
  145550. jpeg_marker_parser_method routine));
  145551. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145552. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145553. jvirt_barray_ptr * coef_arrays));
  145554. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145555. j_compress_ptr dstinfo));
  145556. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145557. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145558. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145559. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145560. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145561. int desired));
  145562. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145563. #define JPEG_EOI 0xD9 /* EOI marker code */
  145564. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145565. #define JPEG_COM 0xFE /* COM marker code */
  145566. #ifdef INCOMPLETE_TYPES_BROKEN
  145567. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145568. struct jvirt_sarray_control { long dummy; };
  145569. struct jvirt_barray_control { long dummy; };
  145570. struct jpeg_comp_master { long dummy; };
  145571. struct jpeg_c_main_controller { long dummy; };
  145572. struct jpeg_c_prep_controller { long dummy; };
  145573. struct jpeg_c_coef_controller { long dummy; };
  145574. struct jpeg_marker_writer { long dummy; };
  145575. struct jpeg_color_converter { long dummy; };
  145576. struct jpeg_downsampler { long dummy; };
  145577. struct jpeg_forward_dct { long dummy; };
  145578. struct jpeg_entropy_encoder { long dummy; };
  145579. struct jpeg_decomp_master { long dummy; };
  145580. struct jpeg_d_main_controller { long dummy; };
  145581. struct jpeg_d_coef_controller { long dummy; };
  145582. struct jpeg_d_post_controller { long dummy; };
  145583. struct jpeg_input_controller { long dummy; };
  145584. struct jpeg_marker_reader { long dummy; };
  145585. struct jpeg_entropy_decoder { long dummy; };
  145586. struct jpeg_inverse_dct { long dummy; };
  145587. struct jpeg_upsampler { long dummy; };
  145588. struct jpeg_color_deconverter { long dummy; };
  145589. struct jpeg_color_quantizer { long dummy; };
  145590. #endif /* JPEG_INTERNALS */
  145591. #endif /* INCOMPLETE_TYPES_BROKEN */
  145592. #ifdef JPEG_INTERNALS
  145593. /*** Start of inlined file: jpegint.h ***/
  145594. typedef enum { /* Operating modes for buffer controllers */
  145595. JBUF_PASS_THRU, /* Plain stripwise operation */
  145596. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145597. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145598. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145599. } J_BUF_MODE;
  145600. #define CSTATE_START 100 /* after create_compress */
  145601. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145602. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145603. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145604. #define DSTATE_START 200 /* after create_decompress */
  145605. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145606. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145607. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145608. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145609. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145610. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145611. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145612. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145613. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145614. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145615. struct jpeg_comp_master {
  145616. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145617. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145618. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145619. boolean call_pass_startup; /* True if pass_startup must be called */
  145620. boolean is_last_pass; /* True during last pass */
  145621. };
  145622. struct jpeg_c_main_controller {
  145623. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145624. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145625. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145626. JDIMENSION in_rows_avail));
  145627. };
  145628. struct jpeg_c_prep_controller {
  145629. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145630. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145631. JSAMPARRAY input_buf,
  145632. JDIMENSION *in_row_ctr,
  145633. JDIMENSION in_rows_avail,
  145634. JSAMPIMAGE output_buf,
  145635. JDIMENSION *out_row_group_ctr,
  145636. JDIMENSION out_row_groups_avail));
  145637. };
  145638. struct jpeg_c_coef_controller {
  145639. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145640. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145641. JSAMPIMAGE input_buf));
  145642. };
  145643. struct jpeg_color_converter {
  145644. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145645. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145646. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145647. JDIMENSION output_row, int num_rows));
  145648. };
  145649. struct jpeg_downsampler {
  145650. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145651. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145652. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145653. JSAMPIMAGE output_buf,
  145654. JDIMENSION out_row_group_index));
  145655. boolean need_context_rows; /* TRUE if need rows above & below */
  145656. };
  145657. struct jpeg_forward_dct {
  145658. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145659. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145660. jpeg_component_info * compptr,
  145661. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145662. JDIMENSION start_row, JDIMENSION start_col,
  145663. JDIMENSION num_blocks));
  145664. };
  145665. struct jpeg_entropy_encoder {
  145666. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145667. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145668. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145669. };
  145670. struct jpeg_marker_writer {
  145671. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145672. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145673. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145674. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145675. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145676. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145677. unsigned int datalen));
  145678. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145679. };
  145680. struct jpeg_decomp_master {
  145681. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145682. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145683. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145684. };
  145685. struct jpeg_input_controller {
  145686. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145687. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145688. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145689. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145690. boolean has_multiple_scans; /* True if file has multiple scans */
  145691. boolean eoi_reached; /* True when EOI has been consumed */
  145692. };
  145693. struct jpeg_d_main_controller {
  145694. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145695. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145696. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145697. JDIMENSION out_rows_avail));
  145698. };
  145699. struct jpeg_d_coef_controller {
  145700. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145701. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145702. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145703. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145704. JSAMPIMAGE output_buf));
  145705. jvirt_barray_ptr *coef_arrays;
  145706. };
  145707. struct jpeg_d_post_controller {
  145708. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145709. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145710. JSAMPIMAGE input_buf,
  145711. JDIMENSION *in_row_group_ctr,
  145712. JDIMENSION in_row_groups_avail,
  145713. JSAMPARRAY output_buf,
  145714. JDIMENSION *out_row_ctr,
  145715. JDIMENSION out_rows_avail));
  145716. };
  145717. struct jpeg_marker_reader {
  145718. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145719. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145720. jpeg_marker_parser_method read_restart_marker;
  145721. boolean saw_SOI; /* found SOI? */
  145722. boolean saw_SOF; /* found SOF? */
  145723. int next_restart_num; /* next restart number expected (0-7) */
  145724. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145725. };
  145726. struct jpeg_entropy_decoder {
  145727. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145728. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145729. JBLOCKROW *MCU_data));
  145730. boolean insufficient_data; /* set TRUE after emitting warning */
  145731. };
  145732. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145733. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145734. JCOEFPTR coef_block,
  145735. JSAMPARRAY output_buf, JDIMENSION output_col));
  145736. struct jpeg_inverse_dct {
  145737. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145738. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145739. };
  145740. struct jpeg_upsampler {
  145741. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145742. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145743. JSAMPIMAGE input_buf,
  145744. JDIMENSION *in_row_group_ctr,
  145745. JDIMENSION in_row_groups_avail,
  145746. JSAMPARRAY output_buf,
  145747. JDIMENSION *out_row_ctr,
  145748. JDIMENSION out_rows_avail));
  145749. boolean need_context_rows; /* TRUE if need rows above & below */
  145750. };
  145751. struct jpeg_color_deconverter {
  145752. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145753. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145754. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145755. JSAMPARRAY output_buf, int num_rows));
  145756. };
  145757. struct jpeg_color_quantizer {
  145758. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145759. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145760. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145761. int num_rows));
  145762. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145763. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145764. };
  145765. #undef MAX
  145766. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145767. #undef MIN
  145768. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145769. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145770. #define SHIFT_TEMPS INT32 shift_temp;
  145771. #define RIGHT_SHIFT(x,shft) \
  145772. ((shift_temp = (x)) < 0 ? \
  145773. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145774. (shift_temp >> (shft)))
  145775. #else
  145776. #define SHIFT_TEMPS
  145777. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145778. #endif
  145779. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145780. #define jinit_compress_master jICompress
  145781. #define jinit_c_master_control jICMaster
  145782. #define jinit_c_main_controller jICMainC
  145783. #define jinit_c_prep_controller jICPrepC
  145784. #define jinit_c_coef_controller jICCoefC
  145785. #define jinit_color_converter jICColor
  145786. #define jinit_downsampler jIDownsampler
  145787. #define jinit_forward_dct jIFDCT
  145788. #define jinit_huff_encoder jIHEncoder
  145789. #define jinit_phuff_encoder jIPHEncoder
  145790. #define jinit_marker_writer jIMWriter
  145791. #define jinit_master_decompress jIDMaster
  145792. #define jinit_d_main_controller jIDMainC
  145793. #define jinit_d_coef_controller jIDCoefC
  145794. #define jinit_d_post_controller jIDPostC
  145795. #define jinit_input_controller jIInCtlr
  145796. #define jinit_marker_reader jIMReader
  145797. #define jinit_huff_decoder jIHDecoder
  145798. #define jinit_phuff_decoder jIPHDecoder
  145799. #define jinit_inverse_dct jIIDCT
  145800. #define jinit_upsampler jIUpsampler
  145801. #define jinit_color_deconverter jIDColor
  145802. #define jinit_1pass_quantizer jI1Quant
  145803. #define jinit_2pass_quantizer jI2Quant
  145804. #define jinit_merged_upsampler jIMUpsampler
  145805. #define jinit_memory_mgr jIMemMgr
  145806. #define jdiv_round_up jDivRound
  145807. #define jround_up jRound
  145808. #define jcopy_sample_rows jCopySamples
  145809. #define jcopy_block_row jCopyBlocks
  145810. #define jzero_far jZeroFar
  145811. #define jpeg_zigzag_order jZIGTable
  145812. #define jpeg_natural_order jZAGTable
  145813. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145814. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145815. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145816. boolean transcode_only));
  145817. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145818. boolean need_full_buffer));
  145819. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145820. boolean need_full_buffer));
  145821. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145822. boolean need_full_buffer));
  145823. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145824. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145825. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145826. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145827. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145828. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145829. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145830. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145831. boolean need_full_buffer));
  145832. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145833. boolean need_full_buffer));
  145834. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145835. boolean need_full_buffer));
  145836. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145837. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145838. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145839. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145840. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145841. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145842. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145843. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145844. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145845. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145846. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145847. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145848. EXTERN(long) jround_up JPP((long a, long b));
  145849. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145850. JSAMPARRAY output_array, int dest_row,
  145851. int num_rows, JDIMENSION num_cols));
  145852. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145853. JDIMENSION num_blocks));
  145854. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145855. #if 0 /* This table is not actually needed in v6a */
  145856. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145857. #endif
  145858. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145859. #ifdef INCOMPLETE_TYPES_BROKEN
  145860. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145861. struct jvirt_sarray_control { long dummy; };
  145862. struct jvirt_barray_control { long dummy; };
  145863. #endif
  145864. #endif /* INCOMPLETE_TYPES_BROKEN */
  145865. /*** End of inlined file: jpegint.h ***/
  145866. /* fetch private declarations */
  145867. /*** Start of inlined file: jerror.h ***/
  145868. #ifndef JMESSAGE
  145869. #ifndef JERROR_H
  145870. #define JMAKE_ENUM_LIST
  145871. #else
  145872. #define JMESSAGE(code,string)
  145873. #endif /* JERROR_H */
  145874. #endif /* JMESSAGE */
  145875. #ifdef JMAKE_ENUM_LIST
  145876. typedef enum {
  145877. #define JMESSAGE(code,string) code ,
  145878. #endif /* JMAKE_ENUM_LIST */
  145879. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145880. JMESSAGE(JERR_ARITH_NOTIMPL,
  145881. "Sorry, there are legal restrictions on arithmetic coding")
  145882. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145883. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145884. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145885. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145886. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145887. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145888. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145889. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145890. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145891. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145892. JMESSAGE(JERR_BAD_LIB_VERSION,
  145893. "Wrong JPEG library version: library is %d, caller expects %d")
  145894. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145895. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145896. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145897. JMESSAGE(JERR_BAD_PROGRESSION,
  145898. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145899. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145900. "Invalid progressive parameters at scan script entry %d")
  145901. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145902. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145903. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145904. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145905. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145906. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145907. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145908. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145909. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145910. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145911. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145912. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145913. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145914. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145915. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145916. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145917. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145918. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145919. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145920. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145921. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145922. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145923. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145924. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145925. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145926. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145927. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145928. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145929. "Cannot transcode due to multiple use of quantization table %d")
  145930. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145931. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145932. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145933. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145934. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145935. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145936. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145937. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145938. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145939. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145940. JMESSAGE(JERR_QUANT_COMPONENTS,
  145941. "Cannot quantize more than %d color components")
  145942. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145943. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145944. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145945. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145946. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145947. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145948. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145949. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145950. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145951. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145952. JMESSAGE(JERR_TFILE_WRITE,
  145953. "Write failed on temporary file --- out of disk space?")
  145954. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145955. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145956. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145957. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145958. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145959. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145960. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145961. JMESSAGE(JMSG_VERSION, JVERSION)
  145962. JMESSAGE(JTRC_16BIT_TABLES,
  145963. "Caution: quantization tables are too coarse for baseline JPEG")
  145964. JMESSAGE(JTRC_ADOBE,
  145965. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145966. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145967. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145968. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145969. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145970. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145971. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145972. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145973. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145974. JMESSAGE(JTRC_EOI, "End Of Image")
  145975. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145976. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145977. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145978. "Warning: thumbnail image size does not match data length %u")
  145979. JMESSAGE(JTRC_JFIF_EXTENSION,
  145980. "JFIF extension marker: type 0x%02x, length %u")
  145981. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145982. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145983. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145984. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145985. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145986. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145987. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145988. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145989. JMESSAGE(JTRC_RST, "RST%d")
  145990. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145991. "Smoothing not supported with nonstandard sampling ratios")
  145992. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145993. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145994. JMESSAGE(JTRC_SOI, "Start of Image")
  145995. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145996. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145997. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145998. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145999. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  146000. JMESSAGE(JTRC_THUMB_JPEG,
  146001. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  146002. JMESSAGE(JTRC_THUMB_PALETTE,
  146003. "JFIF extension marker: palette thumbnail image, length %u")
  146004. JMESSAGE(JTRC_THUMB_RGB,
  146005. "JFIF extension marker: RGB thumbnail image, length %u")
  146006. JMESSAGE(JTRC_UNKNOWN_IDS,
  146007. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  146008. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  146009. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  146010. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  146011. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  146012. "Inconsistent progression sequence for component %d coefficient %d")
  146013. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  146014. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  146015. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  146016. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  146017. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  146018. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  146019. JMESSAGE(JWRN_MUST_RESYNC,
  146020. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  146021. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  146022. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  146023. #ifdef JMAKE_ENUM_LIST
  146024. JMSG_LASTMSGCODE
  146025. } J_MESSAGE_CODE;
  146026. #undef JMAKE_ENUM_LIST
  146027. #endif /* JMAKE_ENUM_LIST */
  146028. #undef JMESSAGE
  146029. #ifndef JERROR_H
  146030. #define JERROR_H
  146031. #define ERREXIT(cinfo,code) \
  146032. ((cinfo)->err->msg_code = (code), \
  146033. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146034. #define ERREXIT1(cinfo,code,p1) \
  146035. ((cinfo)->err->msg_code = (code), \
  146036. (cinfo)->err->msg_parm.i[0] = (p1), \
  146037. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146038. #define ERREXIT2(cinfo,code,p1,p2) \
  146039. ((cinfo)->err->msg_code = (code), \
  146040. (cinfo)->err->msg_parm.i[0] = (p1), \
  146041. (cinfo)->err->msg_parm.i[1] = (p2), \
  146042. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146043. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  146044. ((cinfo)->err->msg_code = (code), \
  146045. (cinfo)->err->msg_parm.i[0] = (p1), \
  146046. (cinfo)->err->msg_parm.i[1] = (p2), \
  146047. (cinfo)->err->msg_parm.i[2] = (p3), \
  146048. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146049. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  146050. ((cinfo)->err->msg_code = (code), \
  146051. (cinfo)->err->msg_parm.i[0] = (p1), \
  146052. (cinfo)->err->msg_parm.i[1] = (p2), \
  146053. (cinfo)->err->msg_parm.i[2] = (p3), \
  146054. (cinfo)->err->msg_parm.i[3] = (p4), \
  146055. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146056. #define ERREXITS(cinfo,code,str) \
  146057. ((cinfo)->err->msg_code = (code), \
  146058. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146059. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146060. #define MAKESTMT(stuff) do { stuff } while (0)
  146061. #define WARNMS(cinfo,code) \
  146062. ((cinfo)->err->msg_code = (code), \
  146063. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146064. #define WARNMS1(cinfo,code,p1) \
  146065. ((cinfo)->err->msg_code = (code), \
  146066. (cinfo)->err->msg_parm.i[0] = (p1), \
  146067. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146068. #define WARNMS2(cinfo,code,p1,p2) \
  146069. ((cinfo)->err->msg_code = (code), \
  146070. (cinfo)->err->msg_parm.i[0] = (p1), \
  146071. (cinfo)->err->msg_parm.i[1] = (p2), \
  146072. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146073. #define TRACEMS(cinfo,lvl,code) \
  146074. ((cinfo)->err->msg_code = (code), \
  146075. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146076. #define TRACEMS1(cinfo,lvl,code,p1) \
  146077. ((cinfo)->err->msg_code = (code), \
  146078. (cinfo)->err->msg_parm.i[0] = (p1), \
  146079. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146080. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  146081. ((cinfo)->err->msg_code = (code), \
  146082. (cinfo)->err->msg_parm.i[0] = (p1), \
  146083. (cinfo)->err->msg_parm.i[1] = (p2), \
  146084. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146085. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  146086. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146087. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  146088. (cinfo)->err->msg_code = (code); \
  146089. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146090. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  146091. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146092. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146093. (cinfo)->err->msg_code = (code); \
  146094. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146095. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  146096. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146097. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146098. _mp[4] = (p5); \
  146099. (cinfo)->err->msg_code = (code); \
  146100. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146101. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  146102. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146103. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146104. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  146105. (cinfo)->err->msg_code = (code); \
  146106. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146107. #define TRACEMSS(cinfo,lvl,code,str) \
  146108. ((cinfo)->err->msg_code = (code), \
  146109. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146110. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146111. #endif /* JERROR_H */
  146112. /*** End of inlined file: jerror.h ***/
  146113. /* fetch error codes too */
  146114. #endif
  146115. #endif /* JPEGLIB_H */
  146116. /*** End of inlined file: jpeglib.h ***/
  146117. /*** Start of inlined file: jcapimin.c ***/
  146118. #define JPEG_INTERNALS
  146119. /*** Start of inlined file: jinclude.h ***/
  146120. #ifndef __jinclude_h__
  146121. #define __jinclude_h__
  146122. /*** Start of inlined file: jconfig.h ***/
  146123. // disable all the warnings under MSVC
  146124. #ifdef _MSC_VER
  146125. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  146126. #endif
  146127. #ifdef __BORLANDC__
  146128. #pragma warn -8057
  146129. #pragma warn -8019
  146130. #pragma warn -8004
  146131. #pragma warn -8008
  146132. #endif
  146133. #define HAVE_PROTOTYPES
  146134. #define HAVE_UNSIGNED_CHAR
  146135. #define HAVE_UNSIGNED_SHORT
  146136. #undef CHAR_IS_UNSIGNED
  146137. #define HAVE_STDDEF_H
  146138. #define HAVE_STDLIB_H
  146139. #undef NEED_BSD_STRINGS
  146140. #undef NEED_SYS_TYPES_H
  146141. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  146142. #undef NEED_SHORT_EXTERNAL_NAMES
  146143. #undef INCOMPLETE_TYPES_BROKEN
  146144. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  146145. typedef unsigned char boolean;
  146146. #endif
  146147. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  146148. #ifdef JPEG_INTERNALS
  146149. #undef RIGHT_SHIFT_IS_UNSIGNED
  146150. #endif /* JPEG_INTERNALS */
  146151. #ifdef JPEG_CJPEG_DJPEG
  146152. #define BMP_SUPPORTED /* BMP image file format */
  146153. #define GIF_SUPPORTED /* GIF image file format */
  146154. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  146155. #undef RLE_SUPPORTED /* Utah RLE image file format */
  146156. #define TARGA_SUPPORTED /* Targa image file format */
  146157. #define TWO_FILE_COMMANDLINE /* optional */
  146158. #define USE_SETMODE /* Microsoft has setmode() */
  146159. #undef NEED_SIGNAL_CATCHER
  146160. #undef DONT_USE_B_MODE
  146161. #undef PROGRESS_REPORT /* optional */
  146162. #endif /* JPEG_CJPEG_DJPEG */
  146163. /*** End of inlined file: jconfig.h ***/
  146164. /* auto configuration options */
  146165. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  146166. #ifdef HAVE_STDDEF_H
  146167. #include <stddef.h>
  146168. #endif
  146169. #ifdef HAVE_STDLIB_H
  146170. #include <stdlib.h>
  146171. #endif
  146172. #ifdef NEED_SYS_TYPES_H
  146173. #include <sys/types.h>
  146174. #endif
  146175. #include <stdio.h>
  146176. #ifdef NEED_BSD_STRINGS
  146177. #include <strings.h>
  146178. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  146179. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  146180. #else /* not BSD, assume ANSI/SysV string lib */
  146181. #include <string.h>
  146182. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  146183. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  146184. #endif
  146185. #define SIZEOF(object) ((size_t) sizeof(object))
  146186. #define JFREAD(file,buf,sizeofbuf) \
  146187. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146188. #define JFWRITE(file,buf,sizeofbuf) \
  146189. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146190. typedef enum { /* JPEG marker codes */
  146191. M_SOF0 = 0xc0,
  146192. M_SOF1 = 0xc1,
  146193. M_SOF2 = 0xc2,
  146194. M_SOF3 = 0xc3,
  146195. M_SOF5 = 0xc5,
  146196. M_SOF6 = 0xc6,
  146197. M_SOF7 = 0xc7,
  146198. M_JPG = 0xc8,
  146199. M_SOF9 = 0xc9,
  146200. M_SOF10 = 0xca,
  146201. M_SOF11 = 0xcb,
  146202. M_SOF13 = 0xcd,
  146203. M_SOF14 = 0xce,
  146204. M_SOF15 = 0xcf,
  146205. M_DHT = 0xc4,
  146206. M_DAC = 0xcc,
  146207. M_RST0 = 0xd0,
  146208. M_RST1 = 0xd1,
  146209. M_RST2 = 0xd2,
  146210. M_RST3 = 0xd3,
  146211. M_RST4 = 0xd4,
  146212. M_RST5 = 0xd5,
  146213. M_RST6 = 0xd6,
  146214. M_RST7 = 0xd7,
  146215. M_SOI = 0xd8,
  146216. M_EOI = 0xd9,
  146217. M_SOS = 0xda,
  146218. M_DQT = 0xdb,
  146219. M_DNL = 0xdc,
  146220. M_DRI = 0xdd,
  146221. M_DHP = 0xde,
  146222. M_EXP = 0xdf,
  146223. M_APP0 = 0xe0,
  146224. M_APP1 = 0xe1,
  146225. M_APP2 = 0xe2,
  146226. M_APP3 = 0xe3,
  146227. M_APP4 = 0xe4,
  146228. M_APP5 = 0xe5,
  146229. M_APP6 = 0xe6,
  146230. M_APP7 = 0xe7,
  146231. M_APP8 = 0xe8,
  146232. M_APP9 = 0xe9,
  146233. M_APP10 = 0xea,
  146234. M_APP11 = 0xeb,
  146235. M_APP12 = 0xec,
  146236. M_APP13 = 0xed,
  146237. M_APP14 = 0xee,
  146238. M_APP15 = 0xef,
  146239. M_JPG0 = 0xf0,
  146240. M_JPG13 = 0xfd,
  146241. M_COM = 0xfe,
  146242. M_TEM = 0x01,
  146243. M_ERROR = 0x100
  146244. } JPEG_MARKER;
  146245. #ifdef AVOID_TABLES
  146246. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  146247. #else
  146248. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  146249. static const int extend_test[16] = /* entry n is 2**(n-1) */
  146250. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  146251. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  146252. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  146253. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  146254. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  146255. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  146256. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  146257. #endif /* AVOID_TABLES */
  146258. #endif
  146259. /*** End of inlined file: jinclude.h ***/
  146260. GLOBAL(void)
  146261. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  146262. {
  146263. int i;
  146264. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  146265. if (version != JPEG_LIB_VERSION)
  146266. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  146267. if (structsize != SIZEOF(struct jpeg_compress_struct))
  146268. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  146269. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  146270. {
  146271. struct jpeg_error_mgr * err = cinfo->err;
  146272. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  146273. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  146274. cinfo->err = err;
  146275. cinfo->client_data = client_data;
  146276. }
  146277. cinfo->is_decompressor = FALSE;
  146278. jinit_memory_mgr((j_common_ptr) cinfo);
  146279. cinfo->progress = NULL;
  146280. cinfo->dest = NULL;
  146281. cinfo->comp_info = NULL;
  146282. for (i = 0; i < NUM_QUANT_TBLS; i++)
  146283. cinfo->quant_tbl_ptrs[i] = NULL;
  146284. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146285. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  146286. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  146287. }
  146288. cinfo->script_space = NULL;
  146289. cinfo->input_gamma = 1.0; /* in case application forgets */
  146290. cinfo->global_state = CSTATE_START;
  146291. }
  146292. GLOBAL(void)
  146293. jpeg_destroy_compress (j_compress_ptr cinfo)
  146294. {
  146295. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  146296. }
  146297. GLOBAL(void)
  146298. jpeg_abort_compress (j_compress_ptr cinfo)
  146299. {
  146300. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  146301. }
  146302. GLOBAL(void)
  146303. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  146304. {
  146305. int i;
  146306. JQUANT_TBL * qtbl;
  146307. JHUFF_TBL * htbl;
  146308. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146309. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146310. qtbl->sent_table = suppress;
  146311. }
  146312. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146313. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146314. htbl->sent_table = suppress;
  146315. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146316. htbl->sent_table = suppress;
  146317. }
  146318. }
  146319. GLOBAL(void)
  146320. jpeg_finish_compress (j_compress_ptr cinfo)
  146321. {
  146322. JDIMENSION iMCU_row;
  146323. if (cinfo->global_state == CSTATE_SCANNING ||
  146324. cinfo->global_state == CSTATE_RAW_OK) {
  146325. if (cinfo->next_scanline < cinfo->image_height)
  146326. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146327. (*cinfo->master->finish_pass) (cinfo);
  146328. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146329. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146330. while (! cinfo->master->is_last_pass) {
  146331. (*cinfo->master->prepare_for_pass) (cinfo);
  146332. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146333. if (cinfo->progress != NULL) {
  146334. cinfo->progress->pass_counter = (long) iMCU_row;
  146335. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146336. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146337. }
  146338. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146339. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146340. }
  146341. (*cinfo->master->finish_pass) (cinfo);
  146342. }
  146343. (*cinfo->marker->write_file_trailer) (cinfo);
  146344. (*cinfo->dest->term_destination) (cinfo);
  146345. jpeg_abort((j_common_ptr) cinfo);
  146346. }
  146347. GLOBAL(void)
  146348. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146349. const JOCTET *dataptr, unsigned int datalen)
  146350. {
  146351. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146352. if (cinfo->next_scanline != 0 ||
  146353. (cinfo->global_state != CSTATE_SCANNING &&
  146354. cinfo->global_state != CSTATE_RAW_OK &&
  146355. cinfo->global_state != CSTATE_WRCOEFS))
  146356. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146357. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146358. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146359. while (datalen--) {
  146360. (*write_marker_byte) (cinfo, *dataptr);
  146361. dataptr++;
  146362. }
  146363. }
  146364. GLOBAL(void)
  146365. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146366. {
  146367. if (cinfo->next_scanline != 0 ||
  146368. (cinfo->global_state != CSTATE_SCANNING &&
  146369. cinfo->global_state != CSTATE_RAW_OK &&
  146370. cinfo->global_state != CSTATE_WRCOEFS))
  146371. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146372. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146373. }
  146374. GLOBAL(void)
  146375. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146376. {
  146377. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146378. }
  146379. GLOBAL(void)
  146380. jpeg_write_tables (j_compress_ptr cinfo)
  146381. {
  146382. if (cinfo->global_state != CSTATE_START)
  146383. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146384. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146385. (*cinfo->dest->init_destination) (cinfo);
  146386. jinit_marker_writer(cinfo);
  146387. (*cinfo->marker->write_tables_only) (cinfo);
  146388. (*cinfo->dest->term_destination) (cinfo);
  146389. }
  146390. /*** End of inlined file: jcapimin.c ***/
  146391. /*** Start of inlined file: jcapistd.c ***/
  146392. #define JPEG_INTERNALS
  146393. GLOBAL(void)
  146394. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146395. {
  146396. if (cinfo->global_state != CSTATE_START)
  146397. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146398. if (write_all_tables)
  146399. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146400. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146401. (*cinfo->dest->init_destination) (cinfo);
  146402. jinit_compress_master(cinfo);
  146403. (*cinfo->master->prepare_for_pass) (cinfo);
  146404. cinfo->next_scanline = 0;
  146405. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146406. }
  146407. GLOBAL(JDIMENSION)
  146408. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146409. JDIMENSION num_lines)
  146410. {
  146411. JDIMENSION row_ctr, rows_left;
  146412. if (cinfo->global_state != CSTATE_SCANNING)
  146413. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146414. if (cinfo->next_scanline >= cinfo->image_height)
  146415. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146416. if (cinfo->progress != NULL) {
  146417. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146418. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146419. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146420. }
  146421. if (cinfo->master->call_pass_startup)
  146422. (*cinfo->master->pass_startup) (cinfo);
  146423. rows_left = cinfo->image_height - cinfo->next_scanline;
  146424. if (num_lines > rows_left)
  146425. num_lines = rows_left;
  146426. row_ctr = 0;
  146427. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146428. cinfo->next_scanline += row_ctr;
  146429. return row_ctr;
  146430. }
  146431. GLOBAL(JDIMENSION)
  146432. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146433. JDIMENSION num_lines)
  146434. {
  146435. JDIMENSION lines_per_iMCU_row;
  146436. if (cinfo->global_state != CSTATE_RAW_OK)
  146437. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146438. if (cinfo->next_scanline >= cinfo->image_height) {
  146439. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146440. return 0;
  146441. }
  146442. if (cinfo->progress != NULL) {
  146443. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146444. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146445. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146446. }
  146447. if (cinfo->master->call_pass_startup)
  146448. (*cinfo->master->pass_startup) (cinfo);
  146449. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146450. if (num_lines < lines_per_iMCU_row)
  146451. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146452. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146453. return 0;
  146454. }
  146455. cinfo->next_scanline += lines_per_iMCU_row;
  146456. return lines_per_iMCU_row;
  146457. }
  146458. /*** End of inlined file: jcapistd.c ***/
  146459. /*** Start of inlined file: jccoefct.c ***/
  146460. #define JPEG_INTERNALS
  146461. #ifdef ENTROPY_OPT_SUPPORTED
  146462. #define FULL_COEF_BUFFER_SUPPORTED
  146463. #else
  146464. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146465. #define FULL_COEF_BUFFER_SUPPORTED
  146466. #endif
  146467. #endif
  146468. typedef struct {
  146469. struct jpeg_c_coef_controller pub; /* public fields */
  146470. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146471. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146472. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146473. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146474. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146475. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146476. } my_coef_controller;
  146477. typedef my_coef_controller * my_coef_ptr;
  146478. METHODDEF(boolean) compress_data
  146479. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146480. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146481. METHODDEF(boolean) compress_first_pass
  146482. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146483. METHODDEF(boolean) compress_output
  146484. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146485. #endif
  146486. LOCAL(void)
  146487. start_iMCU_row (j_compress_ptr cinfo)
  146488. {
  146489. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146490. if (cinfo->comps_in_scan > 1) {
  146491. coef->MCU_rows_per_iMCU_row = 1;
  146492. } else {
  146493. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146494. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146495. else
  146496. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146497. }
  146498. coef->mcu_ctr = 0;
  146499. coef->MCU_vert_offset = 0;
  146500. }
  146501. METHODDEF(void)
  146502. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146503. {
  146504. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146505. coef->iMCU_row_num = 0;
  146506. start_iMCU_row(cinfo);
  146507. switch (pass_mode) {
  146508. case JBUF_PASS_THRU:
  146509. if (coef->whole_image[0] != NULL)
  146510. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146511. coef->pub.compress_data = compress_data;
  146512. break;
  146513. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146514. case JBUF_SAVE_AND_PASS:
  146515. if (coef->whole_image[0] == NULL)
  146516. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146517. coef->pub.compress_data = compress_first_pass;
  146518. break;
  146519. case JBUF_CRANK_DEST:
  146520. if (coef->whole_image[0] == NULL)
  146521. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146522. coef->pub.compress_data = compress_output;
  146523. break;
  146524. #endif
  146525. default:
  146526. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146527. break;
  146528. }
  146529. }
  146530. METHODDEF(boolean)
  146531. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146532. {
  146533. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146534. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146535. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146536. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146537. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146538. JDIMENSION ypos, xpos;
  146539. jpeg_component_info *compptr;
  146540. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146541. yoffset++) {
  146542. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146543. MCU_col_num++) {
  146544. blkn = 0;
  146545. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146546. compptr = cinfo->cur_comp_info[ci];
  146547. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146548. : compptr->last_col_width;
  146549. xpos = MCU_col_num * compptr->MCU_sample_width;
  146550. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146551. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146552. if (coef->iMCU_row_num < last_iMCU_row ||
  146553. yoffset+yindex < compptr->last_row_height) {
  146554. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146555. input_buf[compptr->component_index],
  146556. coef->MCU_buffer[blkn],
  146557. ypos, xpos, (JDIMENSION) blockcnt);
  146558. if (blockcnt < compptr->MCU_width) {
  146559. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146560. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146561. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146562. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146563. }
  146564. }
  146565. } else {
  146566. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146567. compptr->MCU_width * SIZEOF(JBLOCK));
  146568. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146569. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146570. }
  146571. }
  146572. blkn += compptr->MCU_width;
  146573. ypos += DCTSIZE;
  146574. }
  146575. }
  146576. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146577. coef->MCU_vert_offset = yoffset;
  146578. coef->mcu_ctr = MCU_col_num;
  146579. return FALSE;
  146580. }
  146581. }
  146582. coef->mcu_ctr = 0;
  146583. }
  146584. coef->iMCU_row_num++;
  146585. start_iMCU_row(cinfo);
  146586. return TRUE;
  146587. }
  146588. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146589. METHODDEF(boolean)
  146590. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146591. {
  146592. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146593. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146594. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146595. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146596. JCOEF lastDC;
  146597. jpeg_component_info *compptr;
  146598. JBLOCKARRAY buffer;
  146599. JBLOCKROW thisblockrow, lastblockrow;
  146600. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146601. ci++, compptr++) {
  146602. buffer = (*cinfo->mem->access_virt_barray)
  146603. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146604. coef->iMCU_row_num * compptr->v_samp_factor,
  146605. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146606. if (coef->iMCU_row_num < last_iMCU_row)
  146607. block_rows = compptr->v_samp_factor;
  146608. else {
  146609. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146610. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146611. }
  146612. blocks_across = compptr->width_in_blocks;
  146613. h_samp_factor = compptr->h_samp_factor;
  146614. ndummy = (int) (blocks_across % h_samp_factor);
  146615. if (ndummy > 0)
  146616. ndummy = h_samp_factor - ndummy;
  146617. for (block_row = 0; block_row < block_rows; block_row++) {
  146618. thisblockrow = buffer[block_row];
  146619. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146620. input_buf[ci], thisblockrow,
  146621. (JDIMENSION) (block_row * DCTSIZE),
  146622. (JDIMENSION) 0, blocks_across);
  146623. if (ndummy > 0) {
  146624. thisblockrow += blocks_across; /* => first dummy block */
  146625. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146626. lastDC = thisblockrow[-1][0];
  146627. for (bi = 0; bi < ndummy; bi++) {
  146628. thisblockrow[bi][0] = lastDC;
  146629. }
  146630. }
  146631. }
  146632. if (coef->iMCU_row_num == last_iMCU_row) {
  146633. blocks_across += ndummy; /* include lower right corner */
  146634. MCUs_across = blocks_across / h_samp_factor;
  146635. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146636. block_row++) {
  146637. thisblockrow = buffer[block_row];
  146638. lastblockrow = buffer[block_row-1];
  146639. jzero_far((void FAR *) thisblockrow,
  146640. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146641. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146642. lastDC = lastblockrow[h_samp_factor-1][0];
  146643. for (bi = 0; bi < h_samp_factor; bi++) {
  146644. thisblockrow[bi][0] = lastDC;
  146645. }
  146646. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146647. lastblockrow += h_samp_factor;
  146648. }
  146649. }
  146650. }
  146651. }
  146652. return compress_output(cinfo, input_buf);
  146653. }
  146654. METHODDEF(boolean)
  146655. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146656. {
  146657. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146658. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146659. int blkn, ci, xindex, yindex, yoffset;
  146660. JDIMENSION start_col;
  146661. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146662. JBLOCKROW buffer_ptr;
  146663. jpeg_component_info *compptr;
  146664. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146665. compptr = cinfo->cur_comp_info[ci];
  146666. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146667. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146668. coef->iMCU_row_num * compptr->v_samp_factor,
  146669. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146670. }
  146671. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146672. yoffset++) {
  146673. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146674. MCU_col_num++) {
  146675. blkn = 0; /* index of current DCT block within MCU */
  146676. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146677. compptr = cinfo->cur_comp_info[ci];
  146678. start_col = MCU_col_num * compptr->MCU_width;
  146679. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146680. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146681. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146682. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146683. }
  146684. }
  146685. }
  146686. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146687. coef->MCU_vert_offset = yoffset;
  146688. coef->mcu_ctr = MCU_col_num;
  146689. return FALSE;
  146690. }
  146691. }
  146692. coef->mcu_ctr = 0;
  146693. }
  146694. coef->iMCU_row_num++;
  146695. start_iMCU_row(cinfo);
  146696. return TRUE;
  146697. }
  146698. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146699. GLOBAL(void)
  146700. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146701. {
  146702. my_coef_ptr coef;
  146703. coef = (my_coef_ptr)
  146704. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146705. SIZEOF(my_coef_controller));
  146706. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146707. coef->pub.start_pass = start_pass_coef;
  146708. if (need_full_buffer) {
  146709. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146710. int ci;
  146711. jpeg_component_info *compptr;
  146712. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146713. ci++, compptr++) {
  146714. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146715. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146716. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146717. (long) compptr->h_samp_factor),
  146718. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146719. (long) compptr->v_samp_factor),
  146720. (JDIMENSION) compptr->v_samp_factor);
  146721. }
  146722. #else
  146723. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146724. #endif
  146725. } else {
  146726. JBLOCKROW buffer;
  146727. int i;
  146728. buffer = (JBLOCKROW)
  146729. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146730. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146731. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146732. coef->MCU_buffer[i] = buffer + i;
  146733. }
  146734. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146735. }
  146736. }
  146737. /*** End of inlined file: jccoefct.c ***/
  146738. /*** Start of inlined file: jccolor.c ***/
  146739. #define JPEG_INTERNALS
  146740. typedef struct {
  146741. struct jpeg_color_converter pub; /* public fields */
  146742. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146743. } my_color_converter;
  146744. typedef my_color_converter * my_cconvert_ptr;
  146745. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146746. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146747. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146748. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146749. #define R_Y_OFF 0 /* offset to R => Y section */
  146750. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146751. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146752. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146753. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146754. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146755. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146756. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146757. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146758. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146759. METHODDEF(void)
  146760. rgb_ycc_start (j_compress_ptr cinfo)
  146761. {
  146762. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146763. INT32 * rgb_ycc_tab;
  146764. INT32 i;
  146765. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146766. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146767. (TABLE_SIZE * SIZEOF(INT32)));
  146768. for (i = 0; i <= MAXJSAMPLE; i++) {
  146769. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146770. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146771. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146772. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146773. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146774. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146775. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146776. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146777. }
  146778. }
  146779. METHODDEF(void)
  146780. rgb_ycc_convert (j_compress_ptr cinfo,
  146781. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146782. JDIMENSION output_row, int num_rows)
  146783. {
  146784. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146785. register int r, g, b;
  146786. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146787. register JSAMPROW inptr;
  146788. register JSAMPROW outptr0, outptr1, outptr2;
  146789. register JDIMENSION col;
  146790. JDIMENSION num_cols = cinfo->image_width;
  146791. while (--num_rows >= 0) {
  146792. inptr = *input_buf++;
  146793. outptr0 = output_buf[0][output_row];
  146794. outptr1 = output_buf[1][output_row];
  146795. outptr2 = output_buf[2][output_row];
  146796. output_row++;
  146797. for (col = 0; col < num_cols; col++) {
  146798. r = GETJSAMPLE(inptr[RGB_RED]);
  146799. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146800. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146801. inptr += RGB_PIXELSIZE;
  146802. outptr0[col] = (JSAMPLE)
  146803. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146804. >> SCALEBITS);
  146805. outptr1[col] = (JSAMPLE)
  146806. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146807. >> SCALEBITS);
  146808. outptr2[col] = (JSAMPLE)
  146809. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146810. >> SCALEBITS);
  146811. }
  146812. }
  146813. }
  146814. METHODDEF(void)
  146815. rgb_gray_convert (j_compress_ptr cinfo,
  146816. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146817. JDIMENSION output_row, int num_rows)
  146818. {
  146819. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146820. register int r, g, b;
  146821. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146822. register JSAMPROW inptr;
  146823. register JSAMPROW outptr;
  146824. register JDIMENSION col;
  146825. JDIMENSION num_cols = cinfo->image_width;
  146826. while (--num_rows >= 0) {
  146827. inptr = *input_buf++;
  146828. outptr = output_buf[0][output_row];
  146829. output_row++;
  146830. for (col = 0; col < num_cols; col++) {
  146831. r = GETJSAMPLE(inptr[RGB_RED]);
  146832. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146833. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146834. inptr += RGB_PIXELSIZE;
  146835. outptr[col] = (JSAMPLE)
  146836. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146837. >> SCALEBITS);
  146838. }
  146839. }
  146840. }
  146841. METHODDEF(void)
  146842. cmyk_ycck_convert (j_compress_ptr cinfo,
  146843. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146844. JDIMENSION output_row, int num_rows)
  146845. {
  146846. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146847. register int r, g, b;
  146848. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146849. register JSAMPROW inptr;
  146850. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146851. register JDIMENSION col;
  146852. JDIMENSION num_cols = cinfo->image_width;
  146853. while (--num_rows >= 0) {
  146854. inptr = *input_buf++;
  146855. outptr0 = output_buf[0][output_row];
  146856. outptr1 = output_buf[1][output_row];
  146857. outptr2 = output_buf[2][output_row];
  146858. outptr3 = output_buf[3][output_row];
  146859. output_row++;
  146860. for (col = 0; col < num_cols; col++) {
  146861. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146862. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146863. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146864. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146865. inptr += 4;
  146866. outptr0[col] = (JSAMPLE)
  146867. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146868. >> SCALEBITS);
  146869. outptr1[col] = (JSAMPLE)
  146870. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146871. >> SCALEBITS);
  146872. outptr2[col] = (JSAMPLE)
  146873. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146874. >> SCALEBITS);
  146875. }
  146876. }
  146877. }
  146878. METHODDEF(void)
  146879. grayscale_convert (j_compress_ptr cinfo,
  146880. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146881. JDIMENSION output_row, int num_rows)
  146882. {
  146883. register JSAMPROW inptr;
  146884. register JSAMPROW outptr;
  146885. register JDIMENSION col;
  146886. JDIMENSION num_cols = cinfo->image_width;
  146887. int instride = cinfo->input_components;
  146888. while (--num_rows >= 0) {
  146889. inptr = *input_buf++;
  146890. outptr = output_buf[0][output_row];
  146891. output_row++;
  146892. for (col = 0; col < num_cols; col++) {
  146893. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146894. inptr += instride;
  146895. }
  146896. }
  146897. }
  146898. METHODDEF(void)
  146899. null_convert (j_compress_ptr cinfo,
  146900. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146901. JDIMENSION output_row, int num_rows)
  146902. {
  146903. register JSAMPROW inptr;
  146904. register JSAMPROW outptr;
  146905. register JDIMENSION col;
  146906. register int ci;
  146907. int nc = cinfo->num_components;
  146908. JDIMENSION num_cols = cinfo->image_width;
  146909. while (--num_rows >= 0) {
  146910. for (ci = 0; ci < nc; ci++) {
  146911. inptr = *input_buf;
  146912. outptr = output_buf[ci][output_row];
  146913. for (col = 0; col < num_cols; col++) {
  146914. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146915. inptr += nc;
  146916. }
  146917. }
  146918. input_buf++;
  146919. output_row++;
  146920. }
  146921. }
  146922. METHODDEF(void)
  146923. null_method (j_compress_ptr cinfo)
  146924. {
  146925. }
  146926. GLOBAL(void)
  146927. jinit_color_converter (j_compress_ptr cinfo)
  146928. {
  146929. my_cconvert_ptr cconvert;
  146930. cconvert = (my_cconvert_ptr)
  146931. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146932. SIZEOF(my_color_converter));
  146933. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146934. cconvert->pub.start_pass = null_method;
  146935. switch (cinfo->in_color_space) {
  146936. case JCS_GRAYSCALE:
  146937. if (cinfo->input_components != 1)
  146938. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146939. break;
  146940. case JCS_RGB:
  146941. #if RGB_PIXELSIZE != 3
  146942. if (cinfo->input_components != RGB_PIXELSIZE)
  146943. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146944. break;
  146945. #endif /* else share code with YCbCr */
  146946. case JCS_YCbCr:
  146947. if (cinfo->input_components != 3)
  146948. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146949. break;
  146950. case JCS_CMYK:
  146951. case JCS_YCCK:
  146952. if (cinfo->input_components != 4)
  146953. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146954. break;
  146955. default: /* JCS_UNKNOWN can be anything */
  146956. if (cinfo->input_components < 1)
  146957. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146958. break;
  146959. }
  146960. switch (cinfo->jpeg_color_space) {
  146961. case JCS_GRAYSCALE:
  146962. if (cinfo->num_components != 1)
  146963. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146964. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146965. cconvert->pub.color_convert = grayscale_convert;
  146966. else if (cinfo->in_color_space == JCS_RGB) {
  146967. cconvert->pub.start_pass = rgb_ycc_start;
  146968. cconvert->pub.color_convert = rgb_gray_convert;
  146969. } else if (cinfo->in_color_space == JCS_YCbCr)
  146970. cconvert->pub.color_convert = grayscale_convert;
  146971. else
  146972. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146973. break;
  146974. case JCS_RGB:
  146975. if (cinfo->num_components != 3)
  146976. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146977. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146978. cconvert->pub.color_convert = null_convert;
  146979. else
  146980. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146981. break;
  146982. case JCS_YCbCr:
  146983. if (cinfo->num_components != 3)
  146984. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146985. if (cinfo->in_color_space == JCS_RGB) {
  146986. cconvert->pub.start_pass = rgb_ycc_start;
  146987. cconvert->pub.color_convert = rgb_ycc_convert;
  146988. } else if (cinfo->in_color_space == JCS_YCbCr)
  146989. cconvert->pub.color_convert = null_convert;
  146990. else
  146991. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146992. break;
  146993. case JCS_CMYK:
  146994. if (cinfo->num_components != 4)
  146995. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146996. if (cinfo->in_color_space == JCS_CMYK)
  146997. cconvert->pub.color_convert = null_convert;
  146998. else
  146999. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147000. break;
  147001. case JCS_YCCK:
  147002. if (cinfo->num_components != 4)
  147003. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147004. if (cinfo->in_color_space == JCS_CMYK) {
  147005. cconvert->pub.start_pass = rgb_ycc_start;
  147006. cconvert->pub.color_convert = cmyk_ycck_convert;
  147007. } else if (cinfo->in_color_space == JCS_YCCK)
  147008. cconvert->pub.color_convert = null_convert;
  147009. else
  147010. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147011. break;
  147012. default: /* allow null conversion of JCS_UNKNOWN */
  147013. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  147014. cinfo->num_components != cinfo->input_components)
  147015. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147016. cconvert->pub.color_convert = null_convert;
  147017. break;
  147018. }
  147019. }
  147020. /*** End of inlined file: jccolor.c ***/
  147021. #undef FIX
  147022. /*** Start of inlined file: jcdctmgr.c ***/
  147023. #define JPEG_INTERNALS
  147024. /*** Start of inlined file: jdct.h ***/
  147025. #ifndef __jdct_h__
  147026. #define __jdct_h__
  147027. #if BITS_IN_JSAMPLE == 8
  147028. typedef int DCTELEM; /* 16 or 32 bits is fine */
  147029. #else
  147030. typedef INT32 DCTELEM; /* must have 32 bits */
  147031. #endif
  147032. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  147033. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  147034. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  147035. #if BITS_IN_JSAMPLE == 8
  147036. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  147037. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  147038. #else
  147039. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  147040. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  147041. #endif
  147042. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  147043. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  147044. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  147045. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147046. #define jpeg_fdct_islow jFDislow
  147047. #define jpeg_fdct_ifast jFDifast
  147048. #define jpeg_fdct_float jFDfloat
  147049. #define jpeg_idct_islow jRDislow
  147050. #define jpeg_idct_ifast jRDifast
  147051. #define jpeg_idct_float jRDfloat
  147052. #define jpeg_idct_4x4 jRD4x4
  147053. #define jpeg_idct_2x2 jRD2x2
  147054. #define jpeg_idct_1x1 jRD1x1
  147055. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147056. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  147057. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  147058. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  147059. EXTERN(void) jpeg_idct_islow
  147060. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147061. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147062. EXTERN(void) jpeg_idct_ifast
  147063. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147064. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147065. EXTERN(void) jpeg_idct_float
  147066. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147067. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147068. EXTERN(void) jpeg_idct_4x4
  147069. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147070. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147071. EXTERN(void) jpeg_idct_2x2
  147072. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147073. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147074. EXTERN(void) jpeg_idct_1x1
  147075. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147076. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147077. #define ONE ((INT32) 1)
  147078. #define CONST_SCALE (ONE << CONST_BITS)
  147079. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  147080. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  147081. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147082. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  147083. #endif
  147084. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  147085. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  147086. #endif
  147087. #ifndef MULTIPLY16C16 /* default definition */
  147088. #define MULTIPLY16C16(var,const) ((var) * (const))
  147089. #endif
  147090. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147091. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  147092. #endif
  147093. #ifndef MULTIPLY16V16 /* default definition */
  147094. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  147095. #endif
  147096. #endif
  147097. /*** End of inlined file: jdct.h ***/
  147098. /* Private declarations for DCT subsystem */
  147099. typedef struct {
  147100. struct jpeg_forward_dct pub; /* public fields */
  147101. forward_DCT_method_ptr do_dct;
  147102. DCTELEM * divisors[NUM_QUANT_TBLS];
  147103. #ifdef DCT_FLOAT_SUPPORTED
  147104. float_DCT_method_ptr do_float_dct;
  147105. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  147106. #endif
  147107. } my_fdct_controller;
  147108. typedef my_fdct_controller * my_fdct_ptr;
  147109. METHODDEF(void)
  147110. start_pass_fdctmgr (j_compress_ptr cinfo)
  147111. {
  147112. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147113. int ci, qtblno, i;
  147114. jpeg_component_info *compptr;
  147115. JQUANT_TBL * qtbl;
  147116. DCTELEM * dtbl;
  147117. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147118. ci++, compptr++) {
  147119. qtblno = compptr->quant_tbl_no;
  147120. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  147121. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  147122. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  147123. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  147124. switch (cinfo->dct_method) {
  147125. #ifdef DCT_ISLOW_SUPPORTED
  147126. case JDCT_ISLOW:
  147127. if (fdct->divisors[qtblno] == NULL) {
  147128. fdct->divisors[qtblno] = (DCTELEM *)
  147129. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147130. DCTSIZE2 * SIZEOF(DCTELEM));
  147131. }
  147132. dtbl = fdct->divisors[qtblno];
  147133. for (i = 0; i < DCTSIZE2; i++) {
  147134. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  147135. }
  147136. break;
  147137. #endif
  147138. #ifdef DCT_IFAST_SUPPORTED
  147139. case JDCT_IFAST:
  147140. {
  147141. #define CONST_BITS 14
  147142. static const INT16 aanscales[DCTSIZE2] = {
  147143. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147144. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  147145. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  147146. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  147147. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147148. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  147149. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  147150. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  147151. };
  147152. SHIFT_TEMPS
  147153. if (fdct->divisors[qtblno] == NULL) {
  147154. fdct->divisors[qtblno] = (DCTELEM *)
  147155. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147156. DCTSIZE2 * SIZEOF(DCTELEM));
  147157. }
  147158. dtbl = fdct->divisors[qtblno];
  147159. for (i = 0; i < DCTSIZE2; i++) {
  147160. dtbl[i] = (DCTELEM)
  147161. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  147162. (INT32) aanscales[i]),
  147163. CONST_BITS-3);
  147164. }
  147165. }
  147166. break;
  147167. #endif
  147168. #ifdef DCT_FLOAT_SUPPORTED
  147169. case JDCT_FLOAT:
  147170. {
  147171. FAST_FLOAT * fdtbl;
  147172. int row, col;
  147173. static const double aanscalefactor[DCTSIZE] = {
  147174. 1.0, 1.387039845, 1.306562965, 1.175875602,
  147175. 1.0, 0.785694958, 0.541196100, 0.275899379
  147176. };
  147177. if (fdct->float_divisors[qtblno] == NULL) {
  147178. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  147179. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147180. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  147181. }
  147182. fdtbl = fdct->float_divisors[qtblno];
  147183. i = 0;
  147184. for (row = 0; row < DCTSIZE; row++) {
  147185. for (col = 0; col < DCTSIZE; col++) {
  147186. fdtbl[i] = (FAST_FLOAT)
  147187. (1.0 / (((double) qtbl->quantval[i] *
  147188. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  147189. i++;
  147190. }
  147191. }
  147192. }
  147193. break;
  147194. #endif
  147195. default:
  147196. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147197. break;
  147198. }
  147199. }
  147200. }
  147201. METHODDEF(void)
  147202. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147203. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147204. JDIMENSION start_row, JDIMENSION start_col,
  147205. JDIMENSION num_blocks)
  147206. {
  147207. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147208. forward_DCT_method_ptr do_dct = fdct->do_dct;
  147209. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  147210. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147211. JDIMENSION bi;
  147212. sample_data += start_row; /* fold in the vertical offset once */
  147213. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147214. { register DCTELEM *workspaceptr;
  147215. register JSAMPROW elemptr;
  147216. register int elemr;
  147217. workspaceptr = workspace;
  147218. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147219. elemptr = sample_data[elemr] + start_col;
  147220. #if DCTSIZE == 8 /* unroll the inner loop */
  147221. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147222. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147223. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147224. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147225. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147226. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147227. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147228. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147229. #else
  147230. { register int elemc;
  147231. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147232. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147233. }
  147234. }
  147235. #endif
  147236. }
  147237. }
  147238. (*do_dct) (workspace);
  147239. { register DCTELEM temp, qval;
  147240. register int i;
  147241. register JCOEFPTR output_ptr = coef_blocks[bi];
  147242. for (i = 0; i < DCTSIZE2; i++) {
  147243. qval = divisors[i];
  147244. temp = workspace[i];
  147245. #ifdef FAST_DIVIDE
  147246. #define DIVIDE_BY(a,b) a /= b
  147247. #else
  147248. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  147249. #endif
  147250. if (temp < 0) {
  147251. temp = -temp;
  147252. temp += qval>>1; /* for rounding */
  147253. DIVIDE_BY(temp, qval);
  147254. temp = -temp;
  147255. } else {
  147256. temp += qval>>1; /* for rounding */
  147257. DIVIDE_BY(temp, qval);
  147258. }
  147259. output_ptr[i] = (JCOEF) temp;
  147260. }
  147261. }
  147262. }
  147263. }
  147264. #ifdef DCT_FLOAT_SUPPORTED
  147265. METHODDEF(void)
  147266. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147267. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147268. JDIMENSION start_row, JDIMENSION start_col,
  147269. JDIMENSION num_blocks)
  147270. {
  147271. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147272. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  147273. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  147274. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147275. JDIMENSION bi;
  147276. sample_data += start_row; /* fold in the vertical offset once */
  147277. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147278. { register FAST_FLOAT *workspaceptr;
  147279. register JSAMPROW elemptr;
  147280. register int elemr;
  147281. workspaceptr = workspace;
  147282. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147283. elemptr = sample_data[elemr] + start_col;
  147284. #if DCTSIZE == 8 /* unroll the inner loop */
  147285. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147286. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147287. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147288. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147289. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147290. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147291. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147292. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147293. #else
  147294. { register int elemc;
  147295. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147296. *workspaceptr++ = (FAST_FLOAT)
  147297. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147298. }
  147299. }
  147300. #endif
  147301. }
  147302. }
  147303. (*do_dct) (workspace);
  147304. { register FAST_FLOAT temp;
  147305. register int i;
  147306. register JCOEFPTR output_ptr = coef_blocks[bi];
  147307. for (i = 0; i < DCTSIZE2; i++) {
  147308. temp = workspace[i] * divisors[i];
  147309. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147310. }
  147311. }
  147312. }
  147313. }
  147314. #endif /* DCT_FLOAT_SUPPORTED */
  147315. GLOBAL(void)
  147316. jinit_forward_dct (j_compress_ptr cinfo)
  147317. {
  147318. my_fdct_ptr fdct;
  147319. int i;
  147320. fdct = (my_fdct_ptr)
  147321. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147322. SIZEOF(my_fdct_controller));
  147323. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147324. fdct->pub.start_pass = start_pass_fdctmgr;
  147325. switch (cinfo->dct_method) {
  147326. #ifdef DCT_ISLOW_SUPPORTED
  147327. case JDCT_ISLOW:
  147328. fdct->pub.forward_DCT = forward_DCT;
  147329. fdct->do_dct = jpeg_fdct_islow;
  147330. break;
  147331. #endif
  147332. #ifdef DCT_IFAST_SUPPORTED
  147333. case JDCT_IFAST:
  147334. fdct->pub.forward_DCT = forward_DCT;
  147335. fdct->do_dct = jpeg_fdct_ifast;
  147336. break;
  147337. #endif
  147338. #ifdef DCT_FLOAT_SUPPORTED
  147339. case JDCT_FLOAT:
  147340. fdct->pub.forward_DCT = forward_DCT_float;
  147341. fdct->do_float_dct = jpeg_fdct_float;
  147342. break;
  147343. #endif
  147344. default:
  147345. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147346. break;
  147347. }
  147348. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147349. fdct->divisors[i] = NULL;
  147350. #ifdef DCT_FLOAT_SUPPORTED
  147351. fdct->float_divisors[i] = NULL;
  147352. #endif
  147353. }
  147354. }
  147355. /*** End of inlined file: jcdctmgr.c ***/
  147356. #undef CONST_BITS
  147357. /*** Start of inlined file: jchuff.c ***/
  147358. #define JPEG_INTERNALS
  147359. /*** Start of inlined file: jchuff.h ***/
  147360. #ifndef _jchuff_h_
  147361. #define _jchuff_h_
  147362. #if BITS_IN_JSAMPLE == 8
  147363. #define MAX_COEF_BITS 10
  147364. #else
  147365. #define MAX_COEF_BITS 14
  147366. #endif
  147367. typedef struct {
  147368. unsigned int ehufco[256]; /* code for each symbol */
  147369. char ehufsi[256]; /* length of code for each symbol */
  147370. } c_derived_tbl;
  147371. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147372. #define jpeg_make_c_derived_tbl jMkCDerived
  147373. #define jpeg_gen_optimal_table jGenOptTbl
  147374. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147375. EXTERN(void) jpeg_make_c_derived_tbl
  147376. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147377. c_derived_tbl ** pdtbl));
  147378. EXTERN(void) jpeg_gen_optimal_table
  147379. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147380. #endif
  147381. /*** End of inlined file: jchuff.h ***/
  147382. /* Declarations shared with jcphuff.c */
  147383. typedef struct {
  147384. INT32 put_buffer; /* current bit-accumulation buffer */
  147385. int put_bits; /* # of bits now in it */
  147386. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147387. } savable_state;
  147388. #ifndef NO_STRUCT_ASSIGN
  147389. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147390. #else
  147391. #if MAX_COMPS_IN_SCAN == 4
  147392. #define ASSIGN_STATE(dest,src) \
  147393. ((dest).put_buffer = (src).put_buffer, \
  147394. (dest).put_bits = (src).put_bits, \
  147395. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147396. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147397. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147398. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147399. #endif
  147400. #endif
  147401. typedef struct {
  147402. struct jpeg_entropy_encoder pub; /* public fields */
  147403. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147404. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147405. int next_restart_num; /* next restart number to write (0-7) */
  147406. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147407. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147408. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147409. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147410. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147411. #endif
  147412. } huff_entropy_encoder;
  147413. typedef huff_entropy_encoder * huff_entropy_ptr;
  147414. typedef struct {
  147415. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147416. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147417. savable_state cur; /* Current bit buffer & DC state */
  147418. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147419. } working_state;
  147420. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147421. JBLOCKROW *MCU_data));
  147422. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147423. #ifdef ENTROPY_OPT_SUPPORTED
  147424. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147425. JBLOCKROW *MCU_data));
  147426. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147427. #endif
  147428. METHODDEF(void)
  147429. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147430. {
  147431. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147432. int ci, dctbl, actbl;
  147433. jpeg_component_info * compptr;
  147434. if (gather_statistics) {
  147435. #ifdef ENTROPY_OPT_SUPPORTED
  147436. entropy->pub.encode_mcu = encode_mcu_gather;
  147437. entropy->pub.finish_pass = finish_pass_gather;
  147438. #else
  147439. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147440. #endif
  147441. } else {
  147442. entropy->pub.encode_mcu = encode_mcu_huff;
  147443. entropy->pub.finish_pass = finish_pass_huff;
  147444. }
  147445. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147446. compptr = cinfo->cur_comp_info[ci];
  147447. dctbl = compptr->dc_tbl_no;
  147448. actbl = compptr->ac_tbl_no;
  147449. if (gather_statistics) {
  147450. #ifdef ENTROPY_OPT_SUPPORTED
  147451. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147452. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147453. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147454. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147455. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147456. entropy->dc_count_ptrs[dctbl] = (long *)
  147457. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147458. 257 * SIZEOF(long));
  147459. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147460. if (entropy->ac_count_ptrs[actbl] == NULL)
  147461. entropy->ac_count_ptrs[actbl] = (long *)
  147462. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147463. 257 * SIZEOF(long));
  147464. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147465. #endif
  147466. } else {
  147467. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147468. & entropy->dc_derived_tbls[dctbl]);
  147469. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147470. & entropy->ac_derived_tbls[actbl]);
  147471. }
  147472. entropy->saved.last_dc_val[ci] = 0;
  147473. }
  147474. entropy->saved.put_buffer = 0;
  147475. entropy->saved.put_bits = 0;
  147476. entropy->restarts_to_go = cinfo->restart_interval;
  147477. entropy->next_restart_num = 0;
  147478. }
  147479. GLOBAL(void)
  147480. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147481. c_derived_tbl ** pdtbl)
  147482. {
  147483. JHUFF_TBL *htbl;
  147484. c_derived_tbl *dtbl;
  147485. int p, i, l, lastp, si, maxsymbol;
  147486. char huffsize[257];
  147487. unsigned int huffcode[257];
  147488. unsigned int code;
  147489. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147490. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147491. htbl =
  147492. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147493. if (htbl == NULL)
  147494. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147495. if (*pdtbl == NULL)
  147496. *pdtbl = (c_derived_tbl *)
  147497. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147498. SIZEOF(c_derived_tbl));
  147499. dtbl = *pdtbl;
  147500. p = 0;
  147501. for (l = 1; l <= 16; l++) {
  147502. i = (int) htbl->bits[l];
  147503. if (i < 0 || p + i > 256) /* protect against table overrun */
  147504. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147505. while (i--)
  147506. huffsize[p++] = (char) l;
  147507. }
  147508. huffsize[p] = 0;
  147509. lastp = p;
  147510. code = 0;
  147511. si = huffsize[0];
  147512. p = 0;
  147513. while (huffsize[p]) {
  147514. while (((int) huffsize[p]) == si) {
  147515. huffcode[p++] = code;
  147516. code++;
  147517. }
  147518. if (((INT32) code) >= (((INT32) 1) << si))
  147519. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147520. code <<= 1;
  147521. si++;
  147522. }
  147523. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147524. maxsymbol = isDC ? 15 : 255;
  147525. for (p = 0; p < lastp; p++) {
  147526. i = htbl->huffval[p];
  147527. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147528. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147529. dtbl->ehufco[i] = huffcode[p];
  147530. dtbl->ehufsi[i] = huffsize[p];
  147531. }
  147532. }
  147533. #define emit_byte(state,val,action) \
  147534. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147535. if (--(state)->free_in_buffer == 0) \
  147536. if (! dump_buffer(state)) \
  147537. { action; } }
  147538. LOCAL(boolean)
  147539. dump_buffer (working_state * state)
  147540. {
  147541. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147542. if (! (*dest->empty_output_buffer) (state->cinfo))
  147543. return FALSE;
  147544. state->next_output_byte = dest->next_output_byte;
  147545. state->free_in_buffer = dest->free_in_buffer;
  147546. return TRUE;
  147547. }
  147548. INLINE
  147549. LOCAL(boolean)
  147550. emit_bits (working_state * state, unsigned int code, int size)
  147551. {
  147552. register INT32 put_buffer = (INT32) code;
  147553. register int put_bits = state->cur.put_bits;
  147554. if (size == 0)
  147555. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147556. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147557. put_bits += size; /* new number of bits in buffer */
  147558. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147559. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147560. while (put_bits >= 8) {
  147561. int c = (int) ((put_buffer >> 16) & 0xFF);
  147562. emit_byte(state, c, return FALSE);
  147563. if (c == 0xFF) { /* need to stuff a zero byte? */
  147564. emit_byte(state, 0, return FALSE);
  147565. }
  147566. put_buffer <<= 8;
  147567. put_bits -= 8;
  147568. }
  147569. state->cur.put_buffer = put_buffer; /* update state variables */
  147570. state->cur.put_bits = put_bits;
  147571. return TRUE;
  147572. }
  147573. LOCAL(boolean)
  147574. flush_bits (working_state * state)
  147575. {
  147576. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147577. return FALSE;
  147578. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147579. state->cur.put_bits = 0;
  147580. return TRUE;
  147581. }
  147582. LOCAL(boolean)
  147583. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147584. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147585. {
  147586. register int temp, temp2;
  147587. register int nbits;
  147588. register int k, r, i;
  147589. temp = temp2 = block[0] - last_dc_val;
  147590. if (temp < 0) {
  147591. temp = -temp; /* temp is abs value of input */
  147592. temp2--;
  147593. }
  147594. nbits = 0;
  147595. while (temp) {
  147596. nbits++;
  147597. temp >>= 1;
  147598. }
  147599. if (nbits > MAX_COEF_BITS+1)
  147600. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147601. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147602. return FALSE;
  147603. if (nbits) /* emit_bits rejects calls with size 0 */
  147604. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147605. return FALSE;
  147606. r = 0; /* r = run length of zeros */
  147607. for (k = 1; k < DCTSIZE2; k++) {
  147608. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147609. r++;
  147610. } else {
  147611. while (r > 15) {
  147612. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147613. return FALSE;
  147614. r -= 16;
  147615. }
  147616. temp2 = temp;
  147617. if (temp < 0) {
  147618. temp = -temp; /* temp is abs value of input */
  147619. temp2--;
  147620. }
  147621. nbits = 1; /* there must be at least one 1 bit */
  147622. while ((temp >>= 1))
  147623. nbits++;
  147624. if (nbits > MAX_COEF_BITS)
  147625. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147626. i = (r << 4) + nbits;
  147627. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147628. return FALSE;
  147629. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147630. return FALSE;
  147631. r = 0;
  147632. }
  147633. }
  147634. if (r > 0)
  147635. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147636. return FALSE;
  147637. return TRUE;
  147638. }
  147639. LOCAL(boolean)
  147640. emit_restart (working_state * state, int restart_num)
  147641. {
  147642. int ci;
  147643. if (! flush_bits(state))
  147644. return FALSE;
  147645. emit_byte(state, 0xFF, return FALSE);
  147646. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147647. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147648. state->cur.last_dc_val[ci] = 0;
  147649. return TRUE;
  147650. }
  147651. METHODDEF(boolean)
  147652. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147653. {
  147654. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147655. working_state state;
  147656. int blkn, ci;
  147657. jpeg_component_info * compptr;
  147658. state.next_output_byte = cinfo->dest->next_output_byte;
  147659. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147660. ASSIGN_STATE(state.cur, entropy->saved);
  147661. state.cinfo = cinfo;
  147662. if (cinfo->restart_interval) {
  147663. if (entropy->restarts_to_go == 0)
  147664. if (! emit_restart(&state, entropy->next_restart_num))
  147665. return FALSE;
  147666. }
  147667. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147668. ci = cinfo->MCU_membership[blkn];
  147669. compptr = cinfo->cur_comp_info[ci];
  147670. if (! encode_one_block(&state,
  147671. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147672. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147673. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147674. return FALSE;
  147675. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147676. }
  147677. cinfo->dest->next_output_byte = state.next_output_byte;
  147678. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147679. ASSIGN_STATE(entropy->saved, state.cur);
  147680. if (cinfo->restart_interval) {
  147681. if (entropy->restarts_to_go == 0) {
  147682. entropy->restarts_to_go = cinfo->restart_interval;
  147683. entropy->next_restart_num++;
  147684. entropy->next_restart_num &= 7;
  147685. }
  147686. entropy->restarts_to_go--;
  147687. }
  147688. return TRUE;
  147689. }
  147690. METHODDEF(void)
  147691. finish_pass_huff (j_compress_ptr cinfo)
  147692. {
  147693. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147694. working_state state;
  147695. state.next_output_byte = cinfo->dest->next_output_byte;
  147696. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147697. ASSIGN_STATE(state.cur, entropy->saved);
  147698. state.cinfo = cinfo;
  147699. if (! flush_bits(&state))
  147700. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147701. cinfo->dest->next_output_byte = state.next_output_byte;
  147702. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147703. ASSIGN_STATE(entropy->saved, state.cur);
  147704. }
  147705. #ifdef ENTROPY_OPT_SUPPORTED
  147706. LOCAL(void)
  147707. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147708. long dc_counts[], long ac_counts[])
  147709. {
  147710. register int temp;
  147711. register int nbits;
  147712. register int k, r;
  147713. temp = block[0] - last_dc_val;
  147714. if (temp < 0)
  147715. temp = -temp;
  147716. nbits = 0;
  147717. while (temp) {
  147718. nbits++;
  147719. temp >>= 1;
  147720. }
  147721. if (nbits > MAX_COEF_BITS+1)
  147722. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147723. dc_counts[nbits]++;
  147724. r = 0; /* r = run length of zeros */
  147725. for (k = 1; k < DCTSIZE2; k++) {
  147726. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147727. r++;
  147728. } else {
  147729. while (r > 15) {
  147730. ac_counts[0xF0]++;
  147731. r -= 16;
  147732. }
  147733. if (temp < 0)
  147734. temp = -temp;
  147735. nbits = 1; /* there must be at least one 1 bit */
  147736. while ((temp >>= 1))
  147737. nbits++;
  147738. if (nbits > MAX_COEF_BITS)
  147739. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147740. ac_counts[(r << 4) + nbits]++;
  147741. r = 0;
  147742. }
  147743. }
  147744. if (r > 0)
  147745. ac_counts[0]++;
  147746. }
  147747. METHODDEF(boolean)
  147748. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147749. {
  147750. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147751. int blkn, ci;
  147752. jpeg_component_info * compptr;
  147753. if (cinfo->restart_interval) {
  147754. if (entropy->restarts_to_go == 0) {
  147755. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147756. entropy->saved.last_dc_val[ci] = 0;
  147757. entropy->restarts_to_go = cinfo->restart_interval;
  147758. }
  147759. entropy->restarts_to_go--;
  147760. }
  147761. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147762. ci = cinfo->MCU_membership[blkn];
  147763. compptr = cinfo->cur_comp_info[ci];
  147764. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147765. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147766. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147767. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147768. }
  147769. return TRUE;
  147770. }
  147771. GLOBAL(void)
  147772. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147773. {
  147774. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147775. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147776. int codesize[257]; /* codesize[k] = code length of symbol k */
  147777. int others[257]; /* next symbol in current branch of tree */
  147778. int c1, c2;
  147779. int p, i, j;
  147780. long v;
  147781. MEMZERO(bits, SIZEOF(bits));
  147782. MEMZERO(codesize, SIZEOF(codesize));
  147783. for (i = 0; i < 257; i++)
  147784. others[i] = -1; /* init links to empty */
  147785. freq[256] = 1; /* make sure 256 has a nonzero count */
  147786. for (;;) {
  147787. c1 = -1;
  147788. v = 1000000000L;
  147789. for (i = 0; i <= 256; i++) {
  147790. if (freq[i] && freq[i] <= v) {
  147791. v = freq[i];
  147792. c1 = i;
  147793. }
  147794. }
  147795. c2 = -1;
  147796. v = 1000000000L;
  147797. for (i = 0; i <= 256; i++) {
  147798. if (freq[i] && freq[i] <= v && i != c1) {
  147799. v = freq[i];
  147800. c2 = i;
  147801. }
  147802. }
  147803. if (c2 < 0)
  147804. break;
  147805. freq[c1] += freq[c2];
  147806. freq[c2] = 0;
  147807. codesize[c1]++;
  147808. while (others[c1] >= 0) {
  147809. c1 = others[c1];
  147810. codesize[c1]++;
  147811. }
  147812. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147813. codesize[c2]++;
  147814. while (others[c2] >= 0) {
  147815. c2 = others[c2];
  147816. codesize[c2]++;
  147817. }
  147818. }
  147819. for (i = 0; i <= 256; i++) {
  147820. if (codesize[i]) {
  147821. if (codesize[i] > MAX_CLEN)
  147822. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147823. bits[codesize[i]]++;
  147824. }
  147825. }
  147826. for (i = MAX_CLEN; i > 16; i--) {
  147827. while (bits[i] > 0) {
  147828. j = i - 2; /* find length of new prefix to be used */
  147829. while (bits[j] == 0)
  147830. j--;
  147831. bits[i] -= 2; /* remove two symbols */
  147832. bits[i-1]++; /* one goes in this length */
  147833. bits[j+1] += 2; /* two new symbols in this length */
  147834. bits[j]--; /* symbol of this length is now a prefix */
  147835. }
  147836. }
  147837. while (bits[i] == 0) /* find largest codelength still in use */
  147838. i--;
  147839. bits[i]--;
  147840. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147841. p = 0;
  147842. for (i = 1; i <= MAX_CLEN; i++) {
  147843. for (j = 0; j <= 255; j++) {
  147844. if (codesize[j] == i) {
  147845. htbl->huffval[p] = (UINT8) j;
  147846. p++;
  147847. }
  147848. }
  147849. }
  147850. htbl->sent_table = FALSE;
  147851. }
  147852. METHODDEF(void)
  147853. finish_pass_gather (j_compress_ptr cinfo)
  147854. {
  147855. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147856. int ci, dctbl, actbl;
  147857. jpeg_component_info * compptr;
  147858. JHUFF_TBL **htblptr;
  147859. boolean did_dc[NUM_HUFF_TBLS];
  147860. boolean did_ac[NUM_HUFF_TBLS];
  147861. MEMZERO(did_dc, SIZEOF(did_dc));
  147862. MEMZERO(did_ac, SIZEOF(did_ac));
  147863. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147864. compptr = cinfo->cur_comp_info[ci];
  147865. dctbl = compptr->dc_tbl_no;
  147866. actbl = compptr->ac_tbl_no;
  147867. if (! did_dc[dctbl]) {
  147868. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147869. if (*htblptr == NULL)
  147870. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147871. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147872. did_dc[dctbl] = TRUE;
  147873. }
  147874. if (! did_ac[actbl]) {
  147875. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147876. if (*htblptr == NULL)
  147877. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147878. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147879. did_ac[actbl] = TRUE;
  147880. }
  147881. }
  147882. }
  147883. #endif /* ENTROPY_OPT_SUPPORTED */
  147884. GLOBAL(void)
  147885. jinit_huff_encoder (j_compress_ptr cinfo)
  147886. {
  147887. huff_entropy_ptr entropy;
  147888. int i;
  147889. entropy = (huff_entropy_ptr)
  147890. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147891. SIZEOF(huff_entropy_encoder));
  147892. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147893. entropy->pub.start_pass = start_pass_huff;
  147894. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147895. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147896. #ifdef ENTROPY_OPT_SUPPORTED
  147897. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147898. #endif
  147899. }
  147900. }
  147901. /*** End of inlined file: jchuff.c ***/
  147902. #undef emit_byte
  147903. /*** Start of inlined file: jcinit.c ***/
  147904. #define JPEG_INTERNALS
  147905. GLOBAL(void)
  147906. jinit_compress_master (j_compress_ptr cinfo)
  147907. {
  147908. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147909. if (! cinfo->raw_data_in) {
  147910. jinit_color_converter(cinfo);
  147911. jinit_downsampler(cinfo);
  147912. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147913. }
  147914. jinit_forward_dct(cinfo);
  147915. if (cinfo->arith_code) {
  147916. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147917. } else {
  147918. if (cinfo->progressive_mode) {
  147919. #ifdef C_PROGRESSIVE_SUPPORTED
  147920. jinit_phuff_encoder(cinfo);
  147921. #else
  147922. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147923. #endif
  147924. } else
  147925. jinit_huff_encoder(cinfo);
  147926. }
  147927. jinit_c_coef_controller(cinfo,
  147928. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147929. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147930. jinit_marker_writer(cinfo);
  147931. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147932. (*cinfo->marker->write_file_header) (cinfo);
  147933. }
  147934. /*** End of inlined file: jcinit.c ***/
  147935. /*** Start of inlined file: jcmainct.c ***/
  147936. #define JPEG_INTERNALS
  147937. #undef FULL_MAIN_BUFFER_SUPPORTED
  147938. typedef struct {
  147939. struct jpeg_c_main_controller pub; /* public fields */
  147940. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147941. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147942. boolean suspended; /* remember if we suspended output */
  147943. J_BUF_MODE pass_mode; /* current operating mode */
  147944. JSAMPARRAY buffer[MAX_COMPONENTS];
  147945. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147946. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147947. #endif
  147948. } my_main_controller;
  147949. typedef my_main_controller * my_main_ptr;
  147950. METHODDEF(void) process_data_simple_main
  147951. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147952. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147953. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147954. METHODDEF(void) process_data_buffer_main
  147955. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147956. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147957. #endif
  147958. METHODDEF(void)
  147959. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147960. {
  147961. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147962. if (cinfo->raw_data_in)
  147963. return;
  147964. main_->cur_iMCU_row = 0; /* initialize counters */
  147965. main_->rowgroup_ctr = 0;
  147966. main_->suspended = FALSE;
  147967. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147968. switch (pass_mode) {
  147969. case JBUF_PASS_THRU:
  147970. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147971. if (main_->whole_image[0] != NULL)
  147972. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147973. #endif
  147974. main_->pub.process_data = process_data_simple_main;
  147975. break;
  147976. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147977. case JBUF_SAVE_SOURCE:
  147978. case JBUF_CRANK_DEST:
  147979. case JBUF_SAVE_AND_PASS:
  147980. if (main_->whole_image[0] == NULL)
  147981. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147982. main_->pub.process_data = process_data_buffer_main;
  147983. break;
  147984. #endif
  147985. default:
  147986. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147987. break;
  147988. }
  147989. }
  147990. METHODDEF(void)
  147991. process_data_simple_main (j_compress_ptr cinfo,
  147992. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147993. JDIMENSION in_rows_avail)
  147994. {
  147995. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147996. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147997. if (main_->rowgroup_ctr < DCTSIZE)
  147998. (*cinfo->prep->pre_process_data) (cinfo,
  147999. input_buf, in_row_ctr, in_rows_avail,
  148000. main_->buffer, &main_->rowgroup_ctr,
  148001. (JDIMENSION) DCTSIZE);
  148002. if (main_->rowgroup_ctr != DCTSIZE)
  148003. return;
  148004. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  148005. if (! main_->suspended) {
  148006. (*in_row_ctr)--;
  148007. main_->suspended = TRUE;
  148008. }
  148009. return;
  148010. }
  148011. if (main_->suspended) {
  148012. (*in_row_ctr)++;
  148013. main_->suspended = FALSE;
  148014. }
  148015. main_->rowgroup_ctr = 0;
  148016. main_->cur_iMCU_row++;
  148017. }
  148018. }
  148019. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148020. METHODDEF(void)
  148021. process_data_buffer_main (j_compress_ptr cinfo,
  148022. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148023. JDIMENSION in_rows_avail)
  148024. {
  148025. my_main_ptr main = (my_main_ptr) cinfo->main;
  148026. int ci;
  148027. jpeg_component_info *compptr;
  148028. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  148029. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148030. if (main->rowgroup_ctr == 0) {
  148031. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148032. ci++, compptr++) {
  148033. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  148034. ((j_common_ptr) cinfo, main->whole_image[ci],
  148035. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  148036. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  148037. }
  148038. if (! writing) {
  148039. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  148040. main->rowgroup_ctr = DCTSIZE;
  148041. }
  148042. }
  148043. if (writing) {
  148044. (*cinfo->prep->pre_process_data) (cinfo,
  148045. input_buf, in_row_ctr, in_rows_avail,
  148046. main->buffer, &main->rowgroup_ctr,
  148047. (JDIMENSION) DCTSIZE);
  148048. if (main->rowgroup_ctr < DCTSIZE)
  148049. return;
  148050. }
  148051. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  148052. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  148053. if (! main->suspended) {
  148054. (*in_row_ctr)--;
  148055. main->suspended = TRUE;
  148056. }
  148057. return;
  148058. }
  148059. if (main->suspended) {
  148060. (*in_row_ctr)++;
  148061. main->suspended = FALSE;
  148062. }
  148063. }
  148064. main->rowgroup_ctr = 0;
  148065. main->cur_iMCU_row++;
  148066. }
  148067. }
  148068. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  148069. GLOBAL(void)
  148070. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  148071. {
  148072. my_main_ptr main_;
  148073. int ci;
  148074. jpeg_component_info *compptr;
  148075. main_ = (my_main_ptr)
  148076. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148077. SIZEOF(my_main_controller));
  148078. cinfo->main = (struct jpeg_c_main_controller *) main_;
  148079. main_->pub.start_pass = start_pass_main;
  148080. if (cinfo->raw_data_in)
  148081. return;
  148082. if (need_full_buffer) {
  148083. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148084. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148085. ci++, compptr++) {
  148086. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  148087. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  148088. compptr->width_in_blocks * DCTSIZE,
  148089. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  148090. (long) compptr->v_samp_factor) * DCTSIZE,
  148091. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148092. }
  148093. #else
  148094. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148095. #endif
  148096. } else {
  148097. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148098. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  148099. #endif
  148100. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148101. ci++, compptr++) {
  148102. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  148103. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148104. compptr->width_in_blocks * DCTSIZE,
  148105. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148106. }
  148107. }
  148108. }
  148109. /*** End of inlined file: jcmainct.c ***/
  148110. /*** Start of inlined file: jcmarker.c ***/
  148111. #define JPEG_INTERNALS
  148112. typedef struct {
  148113. struct jpeg_marker_writer pub; /* public fields */
  148114. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  148115. } my_marker_writer;
  148116. typedef my_marker_writer * my_marker_ptr;
  148117. LOCAL(void)
  148118. emit_byte (j_compress_ptr cinfo, int val)
  148119. {
  148120. struct jpeg_destination_mgr * dest = cinfo->dest;
  148121. *(dest->next_output_byte)++ = (JOCTET) val;
  148122. if (--dest->free_in_buffer == 0) {
  148123. if (! (*dest->empty_output_buffer) (cinfo))
  148124. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148125. }
  148126. }
  148127. LOCAL(void)
  148128. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  148129. {
  148130. emit_byte(cinfo, 0xFF);
  148131. emit_byte(cinfo, (int) mark);
  148132. }
  148133. LOCAL(void)
  148134. emit_2bytes (j_compress_ptr cinfo, int value)
  148135. {
  148136. emit_byte(cinfo, (value >> 8) & 0xFF);
  148137. emit_byte(cinfo, value & 0xFF);
  148138. }
  148139. LOCAL(int)
  148140. emit_dqt (j_compress_ptr cinfo, int index)
  148141. {
  148142. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  148143. int prec;
  148144. int i;
  148145. if (qtbl == NULL)
  148146. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  148147. prec = 0;
  148148. for (i = 0; i < DCTSIZE2; i++) {
  148149. if (qtbl->quantval[i] > 255)
  148150. prec = 1;
  148151. }
  148152. if (! qtbl->sent_table) {
  148153. emit_marker(cinfo, M_DQT);
  148154. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  148155. emit_byte(cinfo, index + (prec<<4));
  148156. for (i = 0; i < DCTSIZE2; i++) {
  148157. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  148158. if (prec)
  148159. emit_byte(cinfo, (int) (qval >> 8));
  148160. emit_byte(cinfo, (int) (qval & 0xFF));
  148161. }
  148162. qtbl->sent_table = TRUE;
  148163. }
  148164. return prec;
  148165. }
  148166. LOCAL(void)
  148167. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  148168. {
  148169. JHUFF_TBL * htbl;
  148170. int length, i;
  148171. if (is_ac) {
  148172. htbl = cinfo->ac_huff_tbl_ptrs[index];
  148173. index += 0x10; /* output index has AC bit set */
  148174. } else {
  148175. htbl = cinfo->dc_huff_tbl_ptrs[index];
  148176. }
  148177. if (htbl == NULL)
  148178. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  148179. if (! htbl->sent_table) {
  148180. emit_marker(cinfo, M_DHT);
  148181. length = 0;
  148182. for (i = 1; i <= 16; i++)
  148183. length += htbl->bits[i];
  148184. emit_2bytes(cinfo, length + 2 + 1 + 16);
  148185. emit_byte(cinfo, index);
  148186. for (i = 1; i <= 16; i++)
  148187. emit_byte(cinfo, htbl->bits[i]);
  148188. for (i = 0; i < length; i++)
  148189. emit_byte(cinfo, htbl->huffval[i]);
  148190. htbl->sent_table = TRUE;
  148191. }
  148192. }
  148193. LOCAL(void)
  148194. emit_dac (j_compress_ptr cinfo)
  148195. {
  148196. #ifdef C_ARITH_CODING_SUPPORTED
  148197. char dc_in_use[NUM_ARITH_TBLS];
  148198. char ac_in_use[NUM_ARITH_TBLS];
  148199. int length, i;
  148200. jpeg_component_info *compptr;
  148201. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148202. dc_in_use[i] = ac_in_use[i] = 0;
  148203. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148204. compptr = cinfo->cur_comp_info[i];
  148205. dc_in_use[compptr->dc_tbl_no] = 1;
  148206. ac_in_use[compptr->ac_tbl_no] = 1;
  148207. }
  148208. length = 0;
  148209. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148210. length += dc_in_use[i] + ac_in_use[i];
  148211. emit_marker(cinfo, M_DAC);
  148212. emit_2bytes(cinfo, length*2 + 2);
  148213. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148214. if (dc_in_use[i]) {
  148215. emit_byte(cinfo, i);
  148216. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  148217. }
  148218. if (ac_in_use[i]) {
  148219. emit_byte(cinfo, i + 0x10);
  148220. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  148221. }
  148222. }
  148223. #endif /* C_ARITH_CODING_SUPPORTED */
  148224. }
  148225. LOCAL(void)
  148226. emit_dri (j_compress_ptr cinfo)
  148227. {
  148228. emit_marker(cinfo, M_DRI);
  148229. emit_2bytes(cinfo, 4); /* fixed length */
  148230. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  148231. }
  148232. LOCAL(void)
  148233. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  148234. {
  148235. int ci;
  148236. jpeg_component_info *compptr;
  148237. emit_marker(cinfo, code);
  148238. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  148239. if ((long) cinfo->image_height > 65535L ||
  148240. (long) cinfo->image_width > 65535L)
  148241. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  148242. emit_byte(cinfo, cinfo->data_precision);
  148243. emit_2bytes(cinfo, (int) cinfo->image_height);
  148244. emit_2bytes(cinfo, (int) cinfo->image_width);
  148245. emit_byte(cinfo, cinfo->num_components);
  148246. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148247. ci++, compptr++) {
  148248. emit_byte(cinfo, compptr->component_id);
  148249. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  148250. emit_byte(cinfo, compptr->quant_tbl_no);
  148251. }
  148252. }
  148253. LOCAL(void)
  148254. emit_sos (j_compress_ptr cinfo)
  148255. {
  148256. int i, td, ta;
  148257. jpeg_component_info *compptr;
  148258. emit_marker(cinfo, M_SOS);
  148259. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  148260. emit_byte(cinfo, cinfo->comps_in_scan);
  148261. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148262. compptr = cinfo->cur_comp_info[i];
  148263. emit_byte(cinfo, compptr->component_id);
  148264. td = compptr->dc_tbl_no;
  148265. ta = compptr->ac_tbl_no;
  148266. if (cinfo->progressive_mode) {
  148267. if (cinfo->Ss == 0) {
  148268. ta = 0; /* DC scan */
  148269. if (cinfo->Ah != 0 && !cinfo->arith_code)
  148270. td = 0; /* no DC table either */
  148271. } else {
  148272. td = 0; /* AC scan */
  148273. }
  148274. }
  148275. emit_byte(cinfo, (td << 4) + ta);
  148276. }
  148277. emit_byte(cinfo, cinfo->Ss);
  148278. emit_byte(cinfo, cinfo->Se);
  148279. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  148280. }
  148281. LOCAL(void)
  148282. emit_jfif_app0 (j_compress_ptr cinfo)
  148283. {
  148284. emit_marker(cinfo, M_APP0);
  148285. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  148286. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  148287. emit_byte(cinfo, 0x46);
  148288. emit_byte(cinfo, 0x49);
  148289. emit_byte(cinfo, 0x46);
  148290. emit_byte(cinfo, 0);
  148291. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  148292. emit_byte(cinfo, cinfo->JFIF_minor_version);
  148293. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  148294. emit_2bytes(cinfo, (int) cinfo->X_density);
  148295. emit_2bytes(cinfo, (int) cinfo->Y_density);
  148296. emit_byte(cinfo, 0); /* No thumbnail image */
  148297. emit_byte(cinfo, 0);
  148298. }
  148299. LOCAL(void)
  148300. emit_adobe_app14 (j_compress_ptr cinfo)
  148301. {
  148302. emit_marker(cinfo, M_APP14);
  148303. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  148304. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148305. emit_byte(cinfo, 0x64);
  148306. emit_byte(cinfo, 0x6F);
  148307. emit_byte(cinfo, 0x62);
  148308. emit_byte(cinfo, 0x65);
  148309. emit_2bytes(cinfo, 100); /* Version */
  148310. emit_2bytes(cinfo, 0); /* Flags0 */
  148311. emit_2bytes(cinfo, 0); /* Flags1 */
  148312. switch (cinfo->jpeg_color_space) {
  148313. case JCS_YCbCr:
  148314. emit_byte(cinfo, 1); /* Color transform = 1 */
  148315. break;
  148316. case JCS_YCCK:
  148317. emit_byte(cinfo, 2); /* Color transform = 2 */
  148318. break;
  148319. default:
  148320. emit_byte(cinfo, 0); /* Color transform = 0 */
  148321. break;
  148322. }
  148323. }
  148324. METHODDEF(void)
  148325. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148326. {
  148327. if (datalen > (unsigned int) 65533) /* safety check */
  148328. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148329. emit_marker(cinfo, (JPEG_MARKER) marker);
  148330. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148331. }
  148332. METHODDEF(void)
  148333. write_marker_byte (j_compress_ptr cinfo, int val)
  148334. {
  148335. emit_byte(cinfo, val);
  148336. }
  148337. METHODDEF(void)
  148338. write_file_header (j_compress_ptr cinfo)
  148339. {
  148340. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148341. emit_marker(cinfo, M_SOI); /* first the SOI */
  148342. marker->last_restart_interval = 0;
  148343. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148344. emit_jfif_app0(cinfo);
  148345. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148346. emit_adobe_app14(cinfo);
  148347. }
  148348. METHODDEF(void)
  148349. write_frame_header (j_compress_ptr cinfo)
  148350. {
  148351. int ci, prec;
  148352. boolean is_baseline;
  148353. jpeg_component_info *compptr;
  148354. prec = 0;
  148355. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148356. ci++, compptr++) {
  148357. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148358. }
  148359. if (cinfo->arith_code || cinfo->progressive_mode ||
  148360. cinfo->data_precision != 8) {
  148361. is_baseline = FALSE;
  148362. } else {
  148363. is_baseline = TRUE;
  148364. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148365. ci++, compptr++) {
  148366. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148367. is_baseline = FALSE;
  148368. }
  148369. if (prec && is_baseline) {
  148370. is_baseline = FALSE;
  148371. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148372. }
  148373. }
  148374. if (cinfo->arith_code) {
  148375. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148376. } else {
  148377. if (cinfo->progressive_mode)
  148378. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148379. else if (is_baseline)
  148380. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148381. else
  148382. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148383. }
  148384. }
  148385. METHODDEF(void)
  148386. write_scan_header (j_compress_ptr cinfo)
  148387. {
  148388. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148389. int i;
  148390. jpeg_component_info *compptr;
  148391. if (cinfo->arith_code) {
  148392. emit_dac(cinfo);
  148393. } else {
  148394. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148395. compptr = cinfo->cur_comp_info[i];
  148396. if (cinfo->progressive_mode) {
  148397. if (cinfo->Ss == 0) {
  148398. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148399. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148400. } else {
  148401. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148402. }
  148403. } else {
  148404. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148405. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148406. }
  148407. }
  148408. }
  148409. if (cinfo->restart_interval != marker->last_restart_interval) {
  148410. emit_dri(cinfo);
  148411. marker->last_restart_interval = cinfo->restart_interval;
  148412. }
  148413. emit_sos(cinfo);
  148414. }
  148415. METHODDEF(void)
  148416. write_file_trailer (j_compress_ptr cinfo)
  148417. {
  148418. emit_marker(cinfo, M_EOI);
  148419. }
  148420. METHODDEF(void)
  148421. write_tables_only (j_compress_ptr cinfo)
  148422. {
  148423. int i;
  148424. emit_marker(cinfo, M_SOI);
  148425. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148426. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148427. (void) emit_dqt(cinfo, i);
  148428. }
  148429. if (! cinfo->arith_code) {
  148430. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148431. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148432. emit_dht(cinfo, i, FALSE);
  148433. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148434. emit_dht(cinfo, i, TRUE);
  148435. }
  148436. }
  148437. emit_marker(cinfo, M_EOI);
  148438. }
  148439. GLOBAL(void)
  148440. jinit_marker_writer (j_compress_ptr cinfo)
  148441. {
  148442. my_marker_ptr marker;
  148443. marker = (my_marker_ptr)
  148444. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148445. SIZEOF(my_marker_writer));
  148446. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148447. marker->pub.write_file_header = write_file_header;
  148448. marker->pub.write_frame_header = write_frame_header;
  148449. marker->pub.write_scan_header = write_scan_header;
  148450. marker->pub.write_file_trailer = write_file_trailer;
  148451. marker->pub.write_tables_only = write_tables_only;
  148452. marker->pub.write_marker_header = write_marker_header;
  148453. marker->pub.write_marker_byte = write_marker_byte;
  148454. marker->last_restart_interval = 0;
  148455. }
  148456. /*** End of inlined file: jcmarker.c ***/
  148457. /*** Start of inlined file: jcmaster.c ***/
  148458. #define JPEG_INTERNALS
  148459. typedef enum {
  148460. main_pass, /* input data, also do first output step */
  148461. huff_opt_pass, /* Huffman code optimization pass */
  148462. output_pass /* data output pass */
  148463. } c_pass_type;
  148464. typedef struct {
  148465. struct jpeg_comp_master pub; /* public fields */
  148466. c_pass_type pass_type; /* the type of the current pass */
  148467. int pass_number; /* # of passes completed */
  148468. int total_passes; /* total # of passes needed */
  148469. int scan_number; /* current index in scan_info[] */
  148470. } my_comp_master;
  148471. typedef my_comp_master * my_master_ptr;
  148472. LOCAL(void)
  148473. initial_setup (j_compress_ptr cinfo)
  148474. {
  148475. int ci;
  148476. jpeg_component_info *compptr;
  148477. long samplesperrow;
  148478. JDIMENSION jd_samplesperrow;
  148479. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148480. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148481. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148482. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148483. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148484. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148485. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148486. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148487. if ((long) jd_samplesperrow != samplesperrow)
  148488. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148489. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148490. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148491. if (cinfo->num_components > MAX_COMPONENTS)
  148492. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148493. MAX_COMPONENTS);
  148494. cinfo->max_h_samp_factor = 1;
  148495. cinfo->max_v_samp_factor = 1;
  148496. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148497. ci++, compptr++) {
  148498. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148499. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148500. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148501. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148502. compptr->h_samp_factor);
  148503. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148504. compptr->v_samp_factor);
  148505. }
  148506. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148507. ci++, compptr++) {
  148508. compptr->component_index = ci;
  148509. compptr->DCT_scaled_size = DCTSIZE;
  148510. compptr->width_in_blocks = (JDIMENSION)
  148511. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148512. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148513. compptr->height_in_blocks = (JDIMENSION)
  148514. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148515. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148516. compptr->downsampled_width = (JDIMENSION)
  148517. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148518. (long) cinfo->max_h_samp_factor);
  148519. compptr->downsampled_height = (JDIMENSION)
  148520. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148521. (long) cinfo->max_v_samp_factor);
  148522. compptr->component_needed = TRUE;
  148523. }
  148524. cinfo->total_iMCU_rows = (JDIMENSION)
  148525. jdiv_round_up((long) cinfo->image_height,
  148526. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148527. }
  148528. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148529. LOCAL(void)
  148530. validate_script (j_compress_ptr cinfo)
  148531. {
  148532. const jpeg_scan_info * scanptr;
  148533. int scanno, ncomps, ci, coefi, thisi;
  148534. int Ss, Se, Ah, Al;
  148535. boolean component_sent[MAX_COMPONENTS];
  148536. #ifdef C_PROGRESSIVE_SUPPORTED
  148537. int * last_bitpos_ptr;
  148538. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148539. #endif
  148540. if (cinfo->num_scans <= 0)
  148541. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148542. scanptr = cinfo->scan_info;
  148543. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148544. #ifdef C_PROGRESSIVE_SUPPORTED
  148545. cinfo->progressive_mode = TRUE;
  148546. last_bitpos_ptr = & last_bitpos[0][0];
  148547. for (ci = 0; ci < cinfo->num_components; ci++)
  148548. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148549. *last_bitpos_ptr++ = -1;
  148550. #else
  148551. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148552. #endif
  148553. } else {
  148554. cinfo->progressive_mode = FALSE;
  148555. for (ci = 0; ci < cinfo->num_components; ci++)
  148556. component_sent[ci] = FALSE;
  148557. }
  148558. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148559. ncomps = scanptr->comps_in_scan;
  148560. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148561. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148562. for (ci = 0; ci < ncomps; ci++) {
  148563. thisi = scanptr->component_index[ci];
  148564. if (thisi < 0 || thisi >= cinfo->num_components)
  148565. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148566. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148567. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148568. }
  148569. Ss = scanptr->Ss;
  148570. Se = scanptr->Se;
  148571. Ah = scanptr->Ah;
  148572. Al = scanptr->Al;
  148573. if (cinfo->progressive_mode) {
  148574. #ifdef C_PROGRESSIVE_SUPPORTED
  148575. #if BITS_IN_JSAMPLE == 8
  148576. #define MAX_AH_AL 10
  148577. #else
  148578. #define MAX_AH_AL 13
  148579. #endif
  148580. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148581. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148582. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148583. if (Ss == 0) {
  148584. if (Se != 0) /* DC and AC together not OK */
  148585. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148586. } else {
  148587. if (ncomps != 1) /* AC scans must be for only one component */
  148588. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148589. }
  148590. for (ci = 0; ci < ncomps; ci++) {
  148591. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148592. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148593. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148594. for (coefi = Ss; coefi <= Se; coefi++) {
  148595. if (last_bitpos_ptr[coefi] < 0) {
  148596. if (Ah != 0)
  148597. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148598. } else {
  148599. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148600. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148601. }
  148602. last_bitpos_ptr[coefi] = Al;
  148603. }
  148604. }
  148605. #endif
  148606. } else {
  148607. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148608. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148609. for (ci = 0; ci < ncomps; ci++) {
  148610. thisi = scanptr->component_index[ci];
  148611. if (component_sent[thisi])
  148612. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148613. component_sent[thisi] = TRUE;
  148614. }
  148615. }
  148616. }
  148617. if (cinfo->progressive_mode) {
  148618. #ifdef C_PROGRESSIVE_SUPPORTED
  148619. for (ci = 0; ci < cinfo->num_components; ci++) {
  148620. if (last_bitpos[ci][0] < 0)
  148621. ERREXIT(cinfo, JERR_MISSING_DATA);
  148622. }
  148623. #endif
  148624. } else {
  148625. for (ci = 0; ci < cinfo->num_components; ci++) {
  148626. if (! component_sent[ci])
  148627. ERREXIT(cinfo, JERR_MISSING_DATA);
  148628. }
  148629. }
  148630. }
  148631. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148632. LOCAL(void)
  148633. select_scan_parameters (j_compress_ptr cinfo)
  148634. {
  148635. int ci;
  148636. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148637. if (cinfo->scan_info != NULL) {
  148638. my_master_ptr master = (my_master_ptr) cinfo->master;
  148639. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148640. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148641. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148642. cinfo->cur_comp_info[ci] =
  148643. &cinfo->comp_info[scanptr->component_index[ci]];
  148644. }
  148645. cinfo->Ss = scanptr->Ss;
  148646. cinfo->Se = scanptr->Se;
  148647. cinfo->Ah = scanptr->Ah;
  148648. cinfo->Al = scanptr->Al;
  148649. }
  148650. else
  148651. #endif
  148652. {
  148653. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148654. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148655. MAX_COMPS_IN_SCAN);
  148656. cinfo->comps_in_scan = cinfo->num_components;
  148657. for (ci = 0; ci < cinfo->num_components; ci++) {
  148658. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148659. }
  148660. cinfo->Ss = 0;
  148661. cinfo->Se = DCTSIZE2-1;
  148662. cinfo->Ah = 0;
  148663. cinfo->Al = 0;
  148664. }
  148665. }
  148666. LOCAL(void)
  148667. per_scan_setup (j_compress_ptr cinfo)
  148668. {
  148669. int ci, mcublks, tmp;
  148670. jpeg_component_info *compptr;
  148671. if (cinfo->comps_in_scan == 1) {
  148672. compptr = cinfo->cur_comp_info[0];
  148673. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148674. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148675. compptr->MCU_width = 1;
  148676. compptr->MCU_height = 1;
  148677. compptr->MCU_blocks = 1;
  148678. compptr->MCU_sample_width = DCTSIZE;
  148679. compptr->last_col_width = 1;
  148680. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148681. if (tmp == 0) tmp = compptr->v_samp_factor;
  148682. compptr->last_row_height = tmp;
  148683. cinfo->blocks_in_MCU = 1;
  148684. cinfo->MCU_membership[0] = 0;
  148685. } else {
  148686. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148687. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148688. MAX_COMPS_IN_SCAN);
  148689. cinfo->MCUs_per_row = (JDIMENSION)
  148690. jdiv_round_up((long) cinfo->image_width,
  148691. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148692. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148693. jdiv_round_up((long) cinfo->image_height,
  148694. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148695. cinfo->blocks_in_MCU = 0;
  148696. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148697. compptr = cinfo->cur_comp_info[ci];
  148698. compptr->MCU_width = compptr->h_samp_factor;
  148699. compptr->MCU_height = compptr->v_samp_factor;
  148700. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148701. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148702. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148703. if (tmp == 0) tmp = compptr->MCU_width;
  148704. compptr->last_col_width = tmp;
  148705. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148706. if (tmp == 0) tmp = compptr->MCU_height;
  148707. compptr->last_row_height = tmp;
  148708. mcublks = compptr->MCU_blocks;
  148709. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148710. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148711. while (mcublks-- > 0) {
  148712. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148713. }
  148714. }
  148715. }
  148716. if (cinfo->restart_in_rows > 0) {
  148717. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148718. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148719. }
  148720. }
  148721. METHODDEF(void)
  148722. prepare_for_pass (j_compress_ptr cinfo)
  148723. {
  148724. my_master_ptr master = (my_master_ptr) cinfo->master;
  148725. switch (master->pass_type) {
  148726. case main_pass:
  148727. select_scan_parameters(cinfo);
  148728. per_scan_setup(cinfo);
  148729. if (! cinfo->raw_data_in) {
  148730. (*cinfo->cconvert->start_pass) (cinfo);
  148731. (*cinfo->downsample->start_pass) (cinfo);
  148732. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148733. }
  148734. (*cinfo->fdct->start_pass) (cinfo);
  148735. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148736. (*cinfo->coef->start_pass) (cinfo,
  148737. (master->total_passes > 1 ?
  148738. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148739. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148740. if (cinfo->optimize_coding) {
  148741. master->pub.call_pass_startup = FALSE;
  148742. } else {
  148743. master->pub.call_pass_startup = TRUE;
  148744. }
  148745. break;
  148746. #ifdef ENTROPY_OPT_SUPPORTED
  148747. case huff_opt_pass:
  148748. select_scan_parameters(cinfo);
  148749. per_scan_setup(cinfo);
  148750. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148751. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148752. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148753. master->pub.call_pass_startup = FALSE;
  148754. break;
  148755. }
  148756. master->pass_type = output_pass;
  148757. master->pass_number++;
  148758. #endif
  148759. case output_pass:
  148760. if (! cinfo->optimize_coding) {
  148761. select_scan_parameters(cinfo);
  148762. per_scan_setup(cinfo);
  148763. }
  148764. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148765. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148766. if (master->scan_number == 0)
  148767. (*cinfo->marker->write_frame_header) (cinfo);
  148768. (*cinfo->marker->write_scan_header) (cinfo);
  148769. master->pub.call_pass_startup = FALSE;
  148770. break;
  148771. default:
  148772. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148773. }
  148774. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148775. if (cinfo->progress != NULL) {
  148776. cinfo->progress->completed_passes = master->pass_number;
  148777. cinfo->progress->total_passes = master->total_passes;
  148778. }
  148779. }
  148780. METHODDEF(void)
  148781. pass_startup (j_compress_ptr cinfo)
  148782. {
  148783. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148784. (*cinfo->marker->write_frame_header) (cinfo);
  148785. (*cinfo->marker->write_scan_header) (cinfo);
  148786. }
  148787. METHODDEF(void)
  148788. finish_pass_master (j_compress_ptr cinfo)
  148789. {
  148790. my_master_ptr master = (my_master_ptr) cinfo->master;
  148791. (*cinfo->entropy->finish_pass) (cinfo);
  148792. switch (master->pass_type) {
  148793. case main_pass:
  148794. master->pass_type = output_pass;
  148795. if (! cinfo->optimize_coding)
  148796. master->scan_number++;
  148797. break;
  148798. case huff_opt_pass:
  148799. master->pass_type = output_pass;
  148800. break;
  148801. case output_pass:
  148802. if (cinfo->optimize_coding)
  148803. master->pass_type = huff_opt_pass;
  148804. master->scan_number++;
  148805. break;
  148806. }
  148807. master->pass_number++;
  148808. }
  148809. GLOBAL(void)
  148810. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148811. {
  148812. my_master_ptr master;
  148813. master = (my_master_ptr)
  148814. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148815. SIZEOF(my_comp_master));
  148816. cinfo->master = (struct jpeg_comp_master *) master;
  148817. master->pub.prepare_for_pass = prepare_for_pass;
  148818. master->pub.pass_startup = pass_startup;
  148819. master->pub.finish_pass = finish_pass_master;
  148820. master->pub.is_last_pass = FALSE;
  148821. initial_setup(cinfo);
  148822. if (cinfo->scan_info != NULL) {
  148823. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148824. validate_script(cinfo);
  148825. #else
  148826. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148827. #endif
  148828. } else {
  148829. cinfo->progressive_mode = FALSE;
  148830. cinfo->num_scans = 1;
  148831. }
  148832. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148833. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148834. if (transcode_only) {
  148835. if (cinfo->optimize_coding)
  148836. master->pass_type = huff_opt_pass;
  148837. else
  148838. master->pass_type = output_pass;
  148839. } else {
  148840. master->pass_type = main_pass;
  148841. }
  148842. master->scan_number = 0;
  148843. master->pass_number = 0;
  148844. if (cinfo->optimize_coding)
  148845. master->total_passes = cinfo->num_scans * 2;
  148846. else
  148847. master->total_passes = cinfo->num_scans;
  148848. }
  148849. /*** End of inlined file: jcmaster.c ***/
  148850. /*** Start of inlined file: jcomapi.c ***/
  148851. #define JPEG_INTERNALS
  148852. GLOBAL(void)
  148853. jpeg_abort (j_common_ptr cinfo)
  148854. {
  148855. int pool;
  148856. if (cinfo->mem == NULL)
  148857. return;
  148858. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148859. (*cinfo->mem->free_pool) (cinfo, pool);
  148860. }
  148861. if (cinfo->is_decompressor) {
  148862. cinfo->global_state = DSTATE_START;
  148863. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148864. } else {
  148865. cinfo->global_state = CSTATE_START;
  148866. }
  148867. }
  148868. GLOBAL(void)
  148869. jpeg_destroy (j_common_ptr cinfo)
  148870. {
  148871. if (cinfo->mem != NULL)
  148872. (*cinfo->mem->self_destruct) (cinfo);
  148873. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148874. cinfo->global_state = 0; /* mark it destroyed */
  148875. }
  148876. GLOBAL(JQUANT_TBL *)
  148877. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148878. {
  148879. JQUANT_TBL *tbl;
  148880. tbl = (JQUANT_TBL *)
  148881. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148882. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148883. return tbl;
  148884. }
  148885. GLOBAL(JHUFF_TBL *)
  148886. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148887. {
  148888. JHUFF_TBL *tbl;
  148889. tbl = (JHUFF_TBL *)
  148890. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148891. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148892. return tbl;
  148893. }
  148894. /*** End of inlined file: jcomapi.c ***/
  148895. /*** Start of inlined file: jcparam.c ***/
  148896. #define JPEG_INTERNALS
  148897. GLOBAL(void)
  148898. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148899. const unsigned int *basic_table,
  148900. int scale_factor, boolean force_baseline)
  148901. {
  148902. JQUANT_TBL ** qtblptr;
  148903. int i;
  148904. long temp;
  148905. if (cinfo->global_state != CSTATE_START)
  148906. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148907. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148908. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148909. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148910. if (*qtblptr == NULL)
  148911. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148912. for (i = 0; i < DCTSIZE2; i++) {
  148913. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148914. if (temp <= 0L) temp = 1L;
  148915. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148916. if (force_baseline && temp > 255L)
  148917. temp = 255L; /* limit to baseline range if requested */
  148918. (*qtblptr)->quantval[i] = (UINT16) temp;
  148919. }
  148920. (*qtblptr)->sent_table = FALSE;
  148921. }
  148922. GLOBAL(void)
  148923. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148924. boolean force_baseline)
  148925. {
  148926. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148927. 16, 11, 10, 16, 24, 40, 51, 61,
  148928. 12, 12, 14, 19, 26, 58, 60, 55,
  148929. 14, 13, 16, 24, 40, 57, 69, 56,
  148930. 14, 17, 22, 29, 51, 87, 80, 62,
  148931. 18, 22, 37, 56, 68, 109, 103, 77,
  148932. 24, 35, 55, 64, 81, 104, 113, 92,
  148933. 49, 64, 78, 87, 103, 121, 120, 101,
  148934. 72, 92, 95, 98, 112, 100, 103, 99
  148935. };
  148936. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148937. 17, 18, 24, 47, 99, 99, 99, 99,
  148938. 18, 21, 26, 66, 99, 99, 99, 99,
  148939. 24, 26, 56, 99, 99, 99, 99, 99,
  148940. 47, 66, 99, 99, 99, 99, 99, 99,
  148941. 99, 99, 99, 99, 99, 99, 99, 99,
  148942. 99, 99, 99, 99, 99, 99, 99, 99,
  148943. 99, 99, 99, 99, 99, 99, 99, 99,
  148944. 99, 99, 99, 99, 99, 99, 99, 99
  148945. };
  148946. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148947. scale_factor, force_baseline);
  148948. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148949. scale_factor, force_baseline);
  148950. }
  148951. GLOBAL(int)
  148952. jpeg_quality_scaling (int quality)
  148953. {
  148954. if (quality <= 0) quality = 1;
  148955. if (quality > 100) quality = 100;
  148956. if (quality < 50)
  148957. quality = 5000 / quality;
  148958. else
  148959. quality = 200 - quality*2;
  148960. return quality;
  148961. }
  148962. GLOBAL(void)
  148963. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148964. {
  148965. quality = jpeg_quality_scaling(quality);
  148966. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148967. }
  148968. LOCAL(void)
  148969. add_huff_table (j_compress_ptr cinfo,
  148970. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148971. {
  148972. int nsymbols, len;
  148973. if (*htblptr == NULL)
  148974. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148975. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148976. nsymbols = 0;
  148977. for (len = 1; len <= 16; len++)
  148978. nsymbols += bits[len];
  148979. if (nsymbols < 1 || nsymbols > 256)
  148980. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148981. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148982. (*htblptr)->sent_table = FALSE;
  148983. }
  148984. LOCAL(void)
  148985. std_huff_tables (j_compress_ptr cinfo)
  148986. {
  148987. static const UINT8 bits_dc_luminance[17] =
  148988. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148989. static const UINT8 val_dc_luminance[] =
  148990. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148991. static const UINT8 bits_dc_chrominance[17] =
  148992. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148993. static const UINT8 val_dc_chrominance[] =
  148994. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148995. static const UINT8 bits_ac_luminance[17] =
  148996. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148997. static const UINT8 val_ac_luminance[] =
  148998. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148999. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  149000. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  149001. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  149002. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  149003. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  149004. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  149005. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  149006. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  149007. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  149008. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  149009. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  149010. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  149011. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  149012. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  149013. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  149014. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  149015. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  149016. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  149017. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149018. 0xf9, 0xfa };
  149019. static const UINT8 bits_ac_chrominance[17] =
  149020. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  149021. static const UINT8 val_ac_chrominance[] =
  149022. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  149023. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  149024. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  149025. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  149026. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  149027. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  149028. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  149029. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  149030. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  149031. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  149032. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  149033. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  149034. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  149035. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  149036. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  149037. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  149038. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  149039. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  149040. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  149041. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149042. 0xf9, 0xfa };
  149043. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  149044. bits_dc_luminance, val_dc_luminance);
  149045. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  149046. bits_ac_luminance, val_ac_luminance);
  149047. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  149048. bits_dc_chrominance, val_dc_chrominance);
  149049. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  149050. bits_ac_chrominance, val_ac_chrominance);
  149051. }
  149052. GLOBAL(void)
  149053. jpeg_set_defaults (j_compress_ptr cinfo)
  149054. {
  149055. int i;
  149056. if (cinfo->global_state != CSTATE_START)
  149057. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149058. if (cinfo->comp_info == NULL)
  149059. cinfo->comp_info = (jpeg_component_info *)
  149060. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149061. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  149062. cinfo->data_precision = BITS_IN_JSAMPLE;
  149063. jpeg_set_quality(cinfo, 75, TRUE);
  149064. std_huff_tables(cinfo);
  149065. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  149066. cinfo->arith_dc_L[i] = 0;
  149067. cinfo->arith_dc_U[i] = 1;
  149068. cinfo->arith_ac_K[i] = 5;
  149069. }
  149070. cinfo->scan_info = NULL;
  149071. cinfo->num_scans = 0;
  149072. cinfo->raw_data_in = FALSE;
  149073. cinfo->arith_code = FALSE;
  149074. cinfo->optimize_coding = FALSE;
  149075. if (cinfo->data_precision > 8)
  149076. cinfo->optimize_coding = TRUE;
  149077. cinfo->CCIR601_sampling = FALSE;
  149078. cinfo->smoothing_factor = 0;
  149079. cinfo->dct_method = JDCT_DEFAULT;
  149080. cinfo->restart_interval = 0;
  149081. cinfo->restart_in_rows = 0;
  149082. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  149083. cinfo->JFIF_minor_version = 1;
  149084. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  149085. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  149086. cinfo->Y_density = 1;
  149087. jpeg_default_colorspace(cinfo);
  149088. }
  149089. GLOBAL(void)
  149090. jpeg_default_colorspace (j_compress_ptr cinfo)
  149091. {
  149092. switch (cinfo->in_color_space) {
  149093. case JCS_GRAYSCALE:
  149094. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  149095. break;
  149096. case JCS_RGB:
  149097. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149098. break;
  149099. case JCS_YCbCr:
  149100. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149101. break;
  149102. case JCS_CMYK:
  149103. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  149104. break;
  149105. case JCS_YCCK:
  149106. jpeg_set_colorspace(cinfo, JCS_YCCK);
  149107. break;
  149108. case JCS_UNKNOWN:
  149109. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  149110. break;
  149111. default:
  149112. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  149113. }
  149114. }
  149115. GLOBAL(void)
  149116. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  149117. {
  149118. jpeg_component_info * compptr;
  149119. int ci;
  149120. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  149121. (compptr = &cinfo->comp_info[index], \
  149122. compptr->component_id = (id), \
  149123. compptr->h_samp_factor = (hsamp), \
  149124. compptr->v_samp_factor = (vsamp), \
  149125. compptr->quant_tbl_no = (quant), \
  149126. compptr->dc_tbl_no = (dctbl), \
  149127. compptr->ac_tbl_no = (actbl) )
  149128. if (cinfo->global_state != CSTATE_START)
  149129. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149130. cinfo->jpeg_color_space = colorspace;
  149131. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  149132. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  149133. switch (colorspace) {
  149134. case JCS_GRAYSCALE:
  149135. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149136. cinfo->num_components = 1;
  149137. SET_COMP(0, 1, 1,1, 0, 0,0);
  149138. break;
  149139. case JCS_RGB:
  149140. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  149141. cinfo->num_components = 3;
  149142. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  149143. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  149144. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  149145. break;
  149146. case JCS_YCbCr:
  149147. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149148. cinfo->num_components = 3;
  149149. SET_COMP(0, 1, 2,2, 0, 0,0);
  149150. SET_COMP(1, 2, 1,1, 1, 1,1);
  149151. SET_COMP(2, 3, 1,1, 1, 1,1);
  149152. break;
  149153. case JCS_CMYK:
  149154. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  149155. cinfo->num_components = 4;
  149156. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  149157. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  149158. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  149159. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  149160. break;
  149161. case JCS_YCCK:
  149162. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  149163. cinfo->num_components = 4;
  149164. SET_COMP(0, 1, 2,2, 0, 0,0);
  149165. SET_COMP(1, 2, 1,1, 1, 1,1);
  149166. SET_COMP(2, 3, 1,1, 1, 1,1);
  149167. SET_COMP(3, 4, 2,2, 0, 0,0);
  149168. break;
  149169. case JCS_UNKNOWN:
  149170. cinfo->num_components = cinfo->input_components;
  149171. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  149172. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149173. MAX_COMPONENTS);
  149174. for (ci = 0; ci < cinfo->num_components; ci++) {
  149175. SET_COMP(ci, ci, 1,1, 0, 0,0);
  149176. }
  149177. break;
  149178. default:
  149179. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  149180. }
  149181. }
  149182. #ifdef C_PROGRESSIVE_SUPPORTED
  149183. LOCAL(jpeg_scan_info *)
  149184. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  149185. int Ss, int Se, int Ah, int Al)
  149186. {
  149187. scanptr->comps_in_scan = 1;
  149188. scanptr->component_index[0] = ci;
  149189. scanptr->Ss = Ss;
  149190. scanptr->Se = Se;
  149191. scanptr->Ah = Ah;
  149192. scanptr->Al = Al;
  149193. scanptr++;
  149194. return scanptr;
  149195. }
  149196. LOCAL(jpeg_scan_info *)
  149197. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  149198. int Ss, int Se, int Ah, int Al)
  149199. {
  149200. int ci;
  149201. for (ci = 0; ci < ncomps; ci++) {
  149202. scanptr->comps_in_scan = 1;
  149203. scanptr->component_index[0] = ci;
  149204. scanptr->Ss = Ss;
  149205. scanptr->Se = Se;
  149206. scanptr->Ah = Ah;
  149207. scanptr->Al = Al;
  149208. scanptr++;
  149209. }
  149210. return scanptr;
  149211. }
  149212. LOCAL(jpeg_scan_info *)
  149213. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  149214. {
  149215. int ci;
  149216. if (ncomps <= MAX_COMPS_IN_SCAN) {
  149217. scanptr->comps_in_scan = ncomps;
  149218. for (ci = 0; ci < ncomps; ci++)
  149219. scanptr->component_index[ci] = ci;
  149220. scanptr->Ss = scanptr->Se = 0;
  149221. scanptr->Ah = Ah;
  149222. scanptr->Al = Al;
  149223. scanptr++;
  149224. } else {
  149225. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  149226. }
  149227. return scanptr;
  149228. }
  149229. GLOBAL(void)
  149230. jpeg_simple_progression (j_compress_ptr cinfo)
  149231. {
  149232. int ncomps = cinfo->num_components;
  149233. int nscans;
  149234. jpeg_scan_info * scanptr;
  149235. if (cinfo->global_state != CSTATE_START)
  149236. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149237. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149238. nscans = 10;
  149239. } else {
  149240. if (ncomps > MAX_COMPS_IN_SCAN)
  149241. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  149242. else
  149243. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  149244. }
  149245. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  149246. cinfo->script_space_size = MAX(nscans, 10);
  149247. cinfo->script_space = (jpeg_scan_info *)
  149248. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149249. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  149250. }
  149251. scanptr = cinfo->script_space;
  149252. cinfo->scan_info = scanptr;
  149253. cinfo->num_scans = nscans;
  149254. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149255. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149256. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  149257. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  149258. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  149259. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  149260. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  149261. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149262. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  149263. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  149264. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  149265. } else {
  149266. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149267. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  149268. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  149269. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  149270. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149271. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  149272. }
  149273. }
  149274. #endif /* C_PROGRESSIVE_SUPPORTED */
  149275. /*** End of inlined file: jcparam.c ***/
  149276. /*** Start of inlined file: jcphuff.c ***/
  149277. #define JPEG_INTERNALS
  149278. #ifdef C_PROGRESSIVE_SUPPORTED
  149279. typedef struct {
  149280. struct jpeg_entropy_encoder pub; /* public fields */
  149281. boolean gather_statistics;
  149282. JOCTET * next_output_byte; /* => next byte to write in buffer */
  149283. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  149284. INT32 put_buffer; /* current bit-accumulation buffer */
  149285. int put_bits; /* # of bits now in it */
  149286. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  149287. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  149288. int ac_tbl_no; /* the table number of the single component */
  149289. unsigned int EOBRUN; /* run length of EOBs */
  149290. unsigned int BE; /* # of buffered correction bits before MCU */
  149291. char * bit_buffer; /* buffer for correction bits (1 per char) */
  149292. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  149293. int next_restart_num; /* next restart number to write (0-7) */
  149294. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  149295. long * count_ptrs[NUM_HUFF_TBLS];
  149296. } phuff_entropy_encoder;
  149297. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  149298. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  149299. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  149300. #define ISHIFT_TEMPS int ishift_temp;
  149301. #define IRIGHT_SHIFT(x,shft) \
  149302. ((ishift_temp = (x)) < 0 ? \
  149303. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  149304. (ishift_temp >> (shft)))
  149305. #else
  149306. #define ISHIFT_TEMPS
  149307. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149308. #endif
  149309. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149310. JBLOCKROW *MCU_data));
  149311. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149312. JBLOCKROW *MCU_data));
  149313. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149314. JBLOCKROW *MCU_data));
  149315. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149316. JBLOCKROW *MCU_data));
  149317. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149318. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149319. METHODDEF(void)
  149320. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149321. {
  149322. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149323. boolean is_DC_band;
  149324. int ci, tbl;
  149325. jpeg_component_info * compptr;
  149326. entropy->cinfo = cinfo;
  149327. entropy->gather_statistics = gather_statistics;
  149328. is_DC_band = (cinfo->Ss == 0);
  149329. if (cinfo->Ah == 0) {
  149330. if (is_DC_band)
  149331. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149332. else
  149333. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149334. } else {
  149335. if (is_DC_band)
  149336. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149337. else {
  149338. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149339. if (entropy->bit_buffer == NULL)
  149340. entropy->bit_buffer = (char *)
  149341. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149342. MAX_CORR_BITS * SIZEOF(char));
  149343. }
  149344. }
  149345. if (gather_statistics)
  149346. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149347. else
  149348. entropy->pub.finish_pass = finish_pass_phuff;
  149349. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149350. compptr = cinfo->cur_comp_info[ci];
  149351. entropy->last_dc_val[ci] = 0;
  149352. if (is_DC_band) {
  149353. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149354. continue;
  149355. tbl = compptr->dc_tbl_no;
  149356. } else {
  149357. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149358. }
  149359. if (gather_statistics) {
  149360. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149361. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149362. if (entropy->count_ptrs[tbl] == NULL)
  149363. entropy->count_ptrs[tbl] = (long *)
  149364. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149365. 257 * SIZEOF(long));
  149366. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149367. } else {
  149368. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149369. & entropy->derived_tbls[tbl]);
  149370. }
  149371. }
  149372. entropy->EOBRUN = 0;
  149373. entropy->BE = 0;
  149374. entropy->put_buffer = 0;
  149375. entropy->put_bits = 0;
  149376. entropy->restarts_to_go = cinfo->restart_interval;
  149377. entropy->next_restart_num = 0;
  149378. }
  149379. #define emit_byte(entropy,val) \
  149380. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149381. if (--(entropy)->free_in_buffer == 0) \
  149382. dump_buffer_p(entropy); }
  149383. LOCAL(void)
  149384. dump_buffer_p (phuff_entropy_ptr entropy)
  149385. {
  149386. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149387. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149388. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149389. entropy->next_output_byte = dest->next_output_byte;
  149390. entropy->free_in_buffer = dest->free_in_buffer;
  149391. }
  149392. INLINE
  149393. LOCAL(void)
  149394. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149395. {
  149396. register INT32 put_buffer = (INT32) code;
  149397. register int put_bits = entropy->put_bits;
  149398. if (size == 0)
  149399. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149400. if (entropy->gather_statistics)
  149401. return; /* do nothing if we're only getting stats */
  149402. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149403. put_bits += size; /* new number of bits in buffer */
  149404. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149405. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149406. while (put_bits >= 8) {
  149407. int c = (int) ((put_buffer >> 16) & 0xFF);
  149408. emit_byte(entropy, c);
  149409. if (c == 0xFF) { /* need to stuff a zero byte? */
  149410. emit_byte(entropy, 0);
  149411. }
  149412. put_buffer <<= 8;
  149413. put_bits -= 8;
  149414. }
  149415. entropy->put_buffer = put_buffer; /* update variables */
  149416. entropy->put_bits = put_bits;
  149417. }
  149418. LOCAL(void)
  149419. flush_bits_p (phuff_entropy_ptr entropy)
  149420. {
  149421. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149422. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149423. entropy->put_bits = 0;
  149424. }
  149425. INLINE
  149426. LOCAL(void)
  149427. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149428. {
  149429. if (entropy->gather_statistics)
  149430. entropy->count_ptrs[tbl_no][symbol]++;
  149431. else {
  149432. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149433. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149434. }
  149435. }
  149436. LOCAL(void)
  149437. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149438. unsigned int nbits)
  149439. {
  149440. if (entropy->gather_statistics)
  149441. return; /* no real work */
  149442. while (nbits > 0) {
  149443. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149444. bufstart++;
  149445. nbits--;
  149446. }
  149447. }
  149448. LOCAL(void)
  149449. emit_eobrun (phuff_entropy_ptr entropy)
  149450. {
  149451. register int temp, nbits;
  149452. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149453. temp = entropy->EOBRUN;
  149454. nbits = 0;
  149455. while ((temp >>= 1))
  149456. nbits++;
  149457. if (nbits > 14)
  149458. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149459. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149460. if (nbits)
  149461. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149462. entropy->EOBRUN = 0;
  149463. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149464. entropy->BE = 0;
  149465. }
  149466. }
  149467. LOCAL(void)
  149468. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149469. {
  149470. int ci;
  149471. emit_eobrun(entropy);
  149472. if (! entropy->gather_statistics) {
  149473. flush_bits_p(entropy);
  149474. emit_byte(entropy, 0xFF);
  149475. emit_byte(entropy, JPEG_RST0 + restart_num);
  149476. }
  149477. if (entropy->cinfo->Ss == 0) {
  149478. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149479. entropy->last_dc_val[ci] = 0;
  149480. } else {
  149481. entropy->EOBRUN = 0;
  149482. entropy->BE = 0;
  149483. }
  149484. }
  149485. METHODDEF(boolean)
  149486. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149487. {
  149488. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149489. register int temp, temp2;
  149490. register int nbits;
  149491. int blkn, ci;
  149492. int Al = cinfo->Al;
  149493. JBLOCKROW block;
  149494. jpeg_component_info * compptr;
  149495. ISHIFT_TEMPS
  149496. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149497. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149498. if (cinfo->restart_interval)
  149499. if (entropy->restarts_to_go == 0)
  149500. emit_restart_p(entropy, entropy->next_restart_num);
  149501. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149502. block = MCU_data[blkn];
  149503. ci = cinfo->MCU_membership[blkn];
  149504. compptr = cinfo->cur_comp_info[ci];
  149505. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149506. temp = temp2 - entropy->last_dc_val[ci];
  149507. entropy->last_dc_val[ci] = temp2;
  149508. temp2 = temp;
  149509. if (temp < 0) {
  149510. temp = -temp; /* temp is abs value of input */
  149511. temp2--;
  149512. }
  149513. nbits = 0;
  149514. while (temp) {
  149515. nbits++;
  149516. temp >>= 1;
  149517. }
  149518. if (nbits > MAX_COEF_BITS+1)
  149519. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149520. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149521. if (nbits) /* emit_bits rejects calls with size 0 */
  149522. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149523. }
  149524. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149525. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149526. if (cinfo->restart_interval) {
  149527. if (entropy->restarts_to_go == 0) {
  149528. entropy->restarts_to_go = cinfo->restart_interval;
  149529. entropy->next_restart_num++;
  149530. entropy->next_restart_num &= 7;
  149531. }
  149532. entropy->restarts_to_go--;
  149533. }
  149534. return TRUE;
  149535. }
  149536. METHODDEF(boolean)
  149537. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149538. {
  149539. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149540. register int temp, temp2;
  149541. register int nbits;
  149542. register int r, k;
  149543. int Se = cinfo->Se;
  149544. int Al = cinfo->Al;
  149545. JBLOCKROW block;
  149546. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149547. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149548. if (cinfo->restart_interval)
  149549. if (entropy->restarts_to_go == 0)
  149550. emit_restart_p(entropy, entropy->next_restart_num);
  149551. block = MCU_data[0];
  149552. r = 0; /* r = run length of zeros */
  149553. for (k = cinfo->Ss; k <= Se; k++) {
  149554. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149555. r++;
  149556. continue;
  149557. }
  149558. if (temp < 0) {
  149559. temp = -temp; /* temp is abs value of input */
  149560. temp >>= Al; /* apply the point transform */
  149561. temp2 = ~temp;
  149562. } else {
  149563. temp >>= Al; /* apply the point transform */
  149564. temp2 = temp;
  149565. }
  149566. if (temp == 0) {
  149567. r++;
  149568. continue;
  149569. }
  149570. if (entropy->EOBRUN > 0)
  149571. emit_eobrun(entropy);
  149572. while (r > 15) {
  149573. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149574. r -= 16;
  149575. }
  149576. nbits = 1; /* there must be at least one 1 bit */
  149577. while ((temp >>= 1))
  149578. nbits++;
  149579. if (nbits > MAX_COEF_BITS)
  149580. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149581. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149582. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149583. r = 0; /* reset zero run length */
  149584. }
  149585. if (r > 0) { /* If there are trailing zeroes, */
  149586. entropy->EOBRUN++; /* count an EOB */
  149587. if (entropy->EOBRUN == 0x7FFF)
  149588. emit_eobrun(entropy); /* force it out to avoid overflow */
  149589. }
  149590. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149591. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149592. if (cinfo->restart_interval) {
  149593. if (entropy->restarts_to_go == 0) {
  149594. entropy->restarts_to_go = cinfo->restart_interval;
  149595. entropy->next_restart_num++;
  149596. entropy->next_restart_num &= 7;
  149597. }
  149598. entropy->restarts_to_go--;
  149599. }
  149600. return TRUE;
  149601. }
  149602. METHODDEF(boolean)
  149603. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149604. {
  149605. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149606. register int temp;
  149607. int blkn;
  149608. int Al = cinfo->Al;
  149609. JBLOCKROW block;
  149610. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149611. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149612. if (cinfo->restart_interval)
  149613. if (entropy->restarts_to_go == 0)
  149614. emit_restart_p(entropy, entropy->next_restart_num);
  149615. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149616. block = MCU_data[blkn];
  149617. temp = (*block)[0];
  149618. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149619. }
  149620. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149621. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149622. if (cinfo->restart_interval) {
  149623. if (entropy->restarts_to_go == 0) {
  149624. entropy->restarts_to_go = cinfo->restart_interval;
  149625. entropy->next_restart_num++;
  149626. entropy->next_restart_num &= 7;
  149627. }
  149628. entropy->restarts_to_go--;
  149629. }
  149630. return TRUE;
  149631. }
  149632. METHODDEF(boolean)
  149633. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149634. {
  149635. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149636. register int temp;
  149637. register int r, k;
  149638. int EOB;
  149639. char *BR_buffer;
  149640. unsigned int BR;
  149641. int Se = cinfo->Se;
  149642. int Al = cinfo->Al;
  149643. JBLOCKROW block;
  149644. int absvalues[DCTSIZE2];
  149645. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149646. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149647. if (cinfo->restart_interval)
  149648. if (entropy->restarts_to_go == 0)
  149649. emit_restart_p(entropy, entropy->next_restart_num);
  149650. block = MCU_data[0];
  149651. EOB = 0;
  149652. for (k = cinfo->Ss; k <= Se; k++) {
  149653. temp = (*block)[jpeg_natural_order[k]];
  149654. if (temp < 0)
  149655. temp = -temp; /* temp is abs value of input */
  149656. temp >>= Al; /* apply the point transform */
  149657. absvalues[k] = temp; /* save abs value for main pass */
  149658. if (temp == 1)
  149659. EOB = k; /* EOB = index of last newly-nonzero coef */
  149660. }
  149661. r = 0; /* r = run length of zeros */
  149662. BR = 0; /* BR = count of buffered bits added now */
  149663. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149664. for (k = cinfo->Ss; k <= Se; k++) {
  149665. if ((temp = absvalues[k]) == 0) {
  149666. r++;
  149667. continue;
  149668. }
  149669. while (r > 15 && k <= EOB) {
  149670. emit_eobrun(entropy);
  149671. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149672. r -= 16;
  149673. emit_buffered_bits(entropy, BR_buffer, BR);
  149674. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149675. BR = 0;
  149676. }
  149677. if (temp > 1) {
  149678. BR_buffer[BR++] = (char) (temp & 1);
  149679. continue;
  149680. }
  149681. emit_eobrun(entropy);
  149682. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149683. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149684. emit_bits_p(entropy, (unsigned int) temp, 1);
  149685. emit_buffered_bits(entropy, BR_buffer, BR);
  149686. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149687. BR = 0;
  149688. r = 0; /* reset zero run length */
  149689. }
  149690. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149691. entropy->EOBRUN++; /* count an EOB */
  149692. entropy->BE += BR; /* concat my correction bits to older ones */
  149693. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149694. emit_eobrun(entropy);
  149695. }
  149696. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149697. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149698. if (cinfo->restart_interval) {
  149699. if (entropy->restarts_to_go == 0) {
  149700. entropy->restarts_to_go = cinfo->restart_interval;
  149701. entropy->next_restart_num++;
  149702. entropy->next_restart_num &= 7;
  149703. }
  149704. entropy->restarts_to_go--;
  149705. }
  149706. return TRUE;
  149707. }
  149708. METHODDEF(void)
  149709. finish_pass_phuff (j_compress_ptr cinfo)
  149710. {
  149711. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149712. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149713. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149714. emit_eobrun(entropy);
  149715. flush_bits_p(entropy);
  149716. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149717. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149718. }
  149719. METHODDEF(void)
  149720. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149721. {
  149722. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149723. boolean is_DC_band;
  149724. int ci, tbl;
  149725. jpeg_component_info * compptr;
  149726. JHUFF_TBL **htblptr;
  149727. boolean did[NUM_HUFF_TBLS];
  149728. emit_eobrun(entropy);
  149729. is_DC_band = (cinfo->Ss == 0);
  149730. MEMZERO(did, SIZEOF(did));
  149731. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149732. compptr = cinfo->cur_comp_info[ci];
  149733. if (is_DC_band) {
  149734. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149735. continue;
  149736. tbl = compptr->dc_tbl_no;
  149737. } else {
  149738. tbl = compptr->ac_tbl_no;
  149739. }
  149740. if (! did[tbl]) {
  149741. if (is_DC_band)
  149742. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149743. else
  149744. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149745. if (*htblptr == NULL)
  149746. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149747. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149748. did[tbl] = TRUE;
  149749. }
  149750. }
  149751. }
  149752. GLOBAL(void)
  149753. jinit_phuff_encoder (j_compress_ptr cinfo)
  149754. {
  149755. phuff_entropy_ptr entropy;
  149756. int i;
  149757. entropy = (phuff_entropy_ptr)
  149758. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149759. SIZEOF(phuff_entropy_encoder));
  149760. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149761. entropy->pub.start_pass = start_pass_phuff;
  149762. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149763. entropy->derived_tbls[i] = NULL;
  149764. entropy->count_ptrs[i] = NULL;
  149765. }
  149766. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149767. }
  149768. #endif /* C_PROGRESSIVE_SUPPORTED */
  149769. /*** End of inlined file: jcphuff.c ***/
  149770. /*** Start of inlined file: jcprepct.c ***/
  149771. #define JPEG_INTERNALS
  149772. #ifdef INPUT_SMOOTHING_SUPPORTED
  149773. #define CONTEXT_ROWS_SUPPORTED
  149774. #endif
  149775. typedef struct {
  149776. struct jpeg_c_prep_controller pub; /* public fields */
  149777. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149778. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149779. int next_buf_row; /* index of next row to store in color_buf */
  149780. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149781. int this_row_group; /* starting row index of group to process */
  149782. int next_buf_stop; /* downsample when we reach this index */
  149783. #endif
  149784. } my_prep_controller;
  149785. typedef my_prep_controller * my_prep_ptr;
  149786. METHODDEF(void)
  149787. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149788. {
  149789. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149790. if (pass_mode != JBUF_PASS_THRU)
  149791. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149792. prep->rows_to_go = cinfo->image_height;
  149793. prep->next_buf_row = 0;
  149794. #ifdef CONTEXT_ROWS_SUPPORTED
  149795. prep->this_row_group = 0;
  149796. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149797. #endif
  149798. }
  149799. LOCAL(void)
  149800. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149801. int input_rows, int output_rows)
  149802. {
  149803. register int row;
  149804. for (row = input_rows; row < output_rows; row++) {
  149805. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149806. 1, num_cols);
  149807. }
  149808. }
  149809. METHODDEF(void)
  149810. pre_process_data (j_compress_ptr cinfo,
  149811. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149812. JDIMENSION in_rows_avail,
  149813. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149814. JDIMENSION out_row_groups_avail)
  149815. {
  149816. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149817. int numrows, ci;
  149818. JDIMENSION inrows;
  149819. jpeg_component_info * compptr;
  149820. while (*in_row_ctr < in_rows_avail &&
  149821. *out_row_group_ctr < out_row_groups_avail) {
  149822. inrows = in_rows_avail - *in_row_ctr;
  149823. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149824. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149825. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149826. prep->color_buf,
  149827. (JDIMENSION) prep->next_buf_row,
  149828. numrows);
  149829. *in_row_ctr += numrows;
  149830. prep->next_buf_row += numrows;
  149831. prep->rows_to_go -= numrows;
  149832. if (prep->rows_to_go == 0 &&
  149833. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149834. for (ci = 0; ci < cinfo->num_components; ci++) {
  149835. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149836. prep->next_buf_row, cinfo->max_v_samp_factor);
  149837. }
  149838. prep->next_buf_row = cinfo->max_v_samp_factor;
  149839. }
  149840. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149841. (*cinfo->downsample->downsample) (cinfo,
  149842. prep->color_buf, (JDIMENSION) 0,
  149843. output_buf, *out_row_group_ctr);
  149844. prep->next_buf_row = 0;
  149845. (*out_row_group_ctr)++;
  149846. }
  149847. if (prep->rows_to_go == 0 &&
  149848. *out_row_group_ctr < out_row_groups_avail) {
  149849. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149850. ci++, compptr++) {
  149851. expand_bottom_edge(output_buf[ci],
  149852. compptr->width_in_blocks * DCTSIZE,
  149853. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149854. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149855. }
  149856. *out_row_group_ctr = out_row_groups_avail;
  149857. break; /* can exit outer loop without test */
  149858. }
  149859. }
  149860. }
  149861. #ifdef CONTEXT_ROWS_SUPPORTED
  149862. METHODDEF(void)
  149863. pre_process_context (j_compress_ptr cinfo,
  149864. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149865. JDIMENSION in_rows_avail,
  149866. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149867. JDIMENSION out_row_groups_avail)
  149868. {
  149869. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149870. int numrows, ci;
  149871. int buf_height = cinfo->max_v_samp_factor * 3;
  149872. JDIMENSION inrows;
  149873. while (*out_row_group_ctr < out_row_groups_avail) {
  149874. if (*in_row_ctr < in_rows_avail) {
  149875. inrows = in_rows_avail - *in_row_ctr;
  149876. numrows = prep->next_buf_stop - prep->next_buf_row;
  149877. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149878. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149879. prep->color_buf,
  149880. (JDIMENSION) prep->next_buf_row,
  149881. numrows);
  149882. if (prep->rows_to_go == cinfo->image_height) {
  149883. for (ci = 0; ci < cinfo->num_components; ci++) {
  149884. int row;
  149885. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149886. jcopy_sample_rows(prep->color_buf[ci], 0,
  149887. prep->color_buf[ci], -row,
  149888. 1, cinfo->image_width);
  149889. }
  149890. }
  149891. }
  149892. *in_row_ctr += numrows;
  149893. prep->next_buf_row += numrows;
  149894. prep->rows_to_go -= numrows;
  149895. } else {
  149896. if (prep->rows_to_go != 0)
  149897. break;
  149898. if (prep->next_buf_row < prep->next_buf_stop) {
  149899. for (ci = 0; ci < cinfo->num_components; ci++) {
  149900. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149901. prep->next_buf_row, prep->next_buf_stop);
  149902. }
  149903. prep->next_buf_row = prep->next_buf_stop;
  149904. }
  149905. }
  149906. if (prep->next_buf_row == prep->next_buf_stop) {
  149907. (*cinfo->downsample->downsample) (cinfo,
  149908. prep->color_buf,
  149909. (JDIMENSION) prep->this_row_group,
  149910. output_buf, *out_row_group_ctr);
  149911. (*out_row_group_ctr)++;
  149912. prep->this_row_group += cinfo->max_v_samp_factor;
  149913. if (prep->this_row_group >= buf_height)
  149914. prep->this_row_group = 0;
  149915. if (prep->next_buf_row >= buf_height)
  149916. prep->next_buf_row = 0;
  149917. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149918. }
  149919. }
  149920. }
  149921. LOCAL(void)
  149922. create_context_buffer (j_compress_ptr cinfo)
  149923. {
  149924. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149925. int rgroup_height = cinfo->max_v_samp_factor;
  149926. int ci, i;
  149927. jpeg_component_info * compptr;
  149928. JSAMPARRAY true_buffer, fake_buffer;
  149929. fake_buffer = (JSAMPARRAY)
  149930. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149931. (cinfo->num_components * 5 * rgroup_height) *
  149932. SIZEOF(JSAMPROW));
  149933. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149934. ci++, compptr++) {
  149935. true_buffer = (*cinfo->mem->alloc_sarray)
  149936. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149937. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149938. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149939. (JDIMENSION) (3 * rgroup_height));
  149940. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149941. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149942. for (i = 0; i < rgroup_height; i++) {
  149943. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149944. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149945. }
  149946. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149947. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149948. }
  149949. }
  149950. #endif /* CONTEXT_ROWS_SUPPORTED */
  149951. GLOBAL(void)
  149952. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149953. {
  149954. my_prep_ptr prep;
  149955. int ci;
  149956. jpeg_component_info * compptr;
  149957. if (need_full_buffer) /* safety check */
  149958. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149959. prep = (my_prep_ptr)
  149960. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149961. SIZEOF(my_prep_controller));
  149962. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149963. prep->pub.start_pass = start_pass_prep;
  149964. if (cinfo->downsample->need_context_rows) {
  149965. #ifdef CONTEXT_ROWS_SUPPORTED
  149966. prep->pub.pre_process_data = pre_process_context;
  149967. create_context_buffer(cinfo);
  149968. #else
  149969. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149970. #endif
  149971. } else {
  149972. prep->pub.pre_process_data = pre_process_data;
  149973. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149974. ci++, compptr++) {
  149975. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149976. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149977. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149978. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149979. (JDIMENSION) cinfo->max_v_samp_factor);
  149980. }
  149981. }
  149982. }
  149983. /*** End of inlined file: jcprepct.c ***/
  149984. /*** Start of inlined file: jcsample.c ***/
  149985. #define JPEG_INTERNALS
  149986. typedef JMETHOD(void, downsample1_ptr,
  149987. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149988. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149989. typedef struct {
  149990. struct jpeg_downsampler pub; /* public fields */
  149991. downsample1_ptr methods[MAX_COMPONENTS];
  149992. } my_downsampler;
  149993. typedef my_downsampler * my_downsample_ptr;
  149994. METHODDEF(void)
  149995. start_pass_downsample (j_compress_ptr cinfo)
  149996. {
  149997. }
  149998. LOCAL(void)
  149999. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  150000. JDIMENSION input_cols, JDIMENSION output_cols)
  150001. {
  150002. register JSAMPROW ptr;
  150003. register JSAMPLE pixval;
  150004. register int count;
  150005. int row;
  150006. int numcols = (int) (output_cols - input_cols);
  150007. if (numcols > 0) {
  150008. for (row = 0; row < num_rows; row++) {
  150009. ptr = image_data[row] + input_cols;
  150010. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  150011. for (count = numcols; count > 0; count--)
  150012. *ptr++ = pixval;
  150013. }
  150014. }
  150015. }
  150016. METHODDEF(void)
  150017. sep_downsample (j_compress_ptr cinfo,
  150018. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  150019. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  150020. {
  150021. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  150022. int ci;
  150023. jpeg_component_info * compptr;
  150024. JSAMPARRAY in_ptr, out_ptr;
  150025. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150026. ci++, compptr++) {
  150027. in_ptr = input_buf[ci] + in_row_index;
  150028. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  150029. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  150030. }
  150031. }
  150032. METHODDEF(void)
  150033. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150034. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150035. {
  150036. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  150037. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  150038. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150039. JSAMPROW inptr, outptr;
  150040. INT32 outvalue;
  150041. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  150042. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  150043. numpix = h_expand * v_expand;
  150044. numpix2 = numpix/2;
  150045. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150046. cinfo->image_width, output_cols * h_expand);
  150047. inrow = 0;
  150048. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150049. outptr = output_data[outrow];
  150050. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  150051. outcol++, outcol_h += h_expand) {
  150052. outvalue = 0;
  150053. for (v = 0; v < v_expand; v++) {
  150054. inptr = input_data[inrow+v] + outcol_h;
  150055. for (h = 0; h < h_expand; h++) {
  150056. outvalue += (INT32) GETJSAMPLE(*inptr++);
  150057. }
  150058. }
  150059. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  150060. }
  150061. inrow += v_expand;
  150062. }
  150063. }
  150064. METHODDEF(void)
  150065. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150066. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150067. {
  150068. jcopy_sample_rows(input_data, 0, output_data, 0,
  150069. cinfo->max_v_samp_factor, cinfo->image_width);
  150070. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  150071. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  150072. }
  150073. METHODDEF(void)
  150074. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150075. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150076. {
  150077. int outrow;
  150078. JDIMENSION outcol;
  150079. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150080. register JSAMPROW inptr, outptr;
  150081. register int bias;
  150082. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150083. cinfo->image_width, output_cols * 2);
  150084. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150085. outptr = output_data[outrow];
  150086. inptr = input_data[outrow];
  150087. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  150088. for (outcol = 0; outcol < output_cols; outcol++) {
  150089. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  150090. + bias) >> 1);
  150091. bias ^= 1; /* 0=>1, 1=>0 */
  150092. inptr += 2;
  150093. }
  150094. }
  150095. }
  150096. METHODDEF(void)
  150097. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150098. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150099. {
  150100. int inrow, outrow;
  150101. JDIMENSION outcol;
  150102. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150103. register JSAMPROW inptr0, inptr1, outptr;
  150104. register int bias;
  150105. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150106. cinfo->image_width, output_cols * 2);
  150107. inrow = 0;
  150108. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150109. outptr = output_data[outrow];
  150110. inptr0 = input_data[inrow];
  150111. inptr1 = input_data[inrow+1];
  150112. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  150113. for (outcol = 0; outcol < output_cols; outcol++) {
  150114. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150115. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  150116. + bias) >> 2);
  150117. bias ^= 3; /* 1=>2, 2=>1 */
  150118. inptr0 += 2; inptr1 += 2;
  150119. }
  150120. inrow += 2;
  150121. }
  150122. }
  150123. #ifdef INPUT_SMOOTHING_SUPPORTED
  150124. METHODDEF(void)
  150125. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150126. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150127. {
  150128. int inrow, outrow;
  150129. JDIMENSION colctr;
  150130. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150131. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  150132. INT32 membersum, neighsum, memberscale, neighscale;
  150133. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150134. cinfo->image_width, output_cols * 2);
  150135. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  150136. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  150137. inrow = 0;
  150138. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150139. outptr = output_data[outrow];
  150140. inptr0 = input_data[inrow];
  150141. inptr1 = input_data[inrow+1];
  150142. above_ptr = input_data[inrow-1];
  150143. below_ptr = input_data[inrow+2];
  150144. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150145. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150146. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150147. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150148. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  150149. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  150150. neighsum += neighsum;
  150151. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  150152. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  150153. membersum = membersum * memberscale + neighsum * neighscale;
  150154. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150155. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150156. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150157. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150158. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150159. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150160. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150161. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  150162. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  150163. neighsum += neighsum;
  150164. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  150165. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  150166. membersum = membersum * memberscale + neighsum * neighscale;
  150167. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150168. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150169. }
  150170. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150171. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150172. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150173. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150174. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  150175. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  150176. neighsum += neighsum;
  150177. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  150178. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  150179. membersum = membersum * memberscale + neighsum * neighscale;
  150180. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150181. inrow += 2;
  150182. }
  150183. }
  150184. METHODDEF(void)
  150185. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  150186. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150187. {
  150188. int outrow;
  150189. JDIMENSION colctr;
  150190. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150191. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  150192. INT32 membersum, neighsum, memberscale, neighscale;
  150193. int colsum, lastcolsum, nextcolsum;
  150194. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150195. cinfo->image_width, output_cols);
  150196. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  150197. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  150198. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150199. outptr = output_data[outrow];
  150200. inptr = input_data[outrow];
  150201. above_ptr = input_data[outrow-1];
  150202. below_ptr = input_data[outrow+1];
  150203. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  150204. GETJSAMPLE(*inptr);
  150205. membersum = GETJSAMPLE(*inptr++);
  150206. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150207. GETJSAMPLE(*inptr);
  150208. neighsum = colsum + (colsum - membersum) + nextcolsum;
  150209. membersum = membersum * memberscale + neighsum * neighscale;
  150210. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150211. lastcolsum = colsum; colsum = nextcolsum;
  150212. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150213. membersum = GETJSAMPLE(*inptr++);
  150214. above_ptr++; below_ptr++;
  150215. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150216. GETJSAMPLE(*inptr);
  150217. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  150218. membersum = membersum * memberscale + neighsum * neighscale;
  150219. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150220. lastcolsum = colsum; colsum = nextcolsum;
  150221. }
  150222. membersum = GETJSAMPLE(*inptr);
  150223. neighsum = lastcolsum + (colsum - membersum) + colsum;
  150224. membersum = membersum * memberscale + neighsum * neighscale;
  150225. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150226. }
  150227. }
  150228. #endif /* INPUT_SMOOTHING_SUPPORTED */
  150229. GLOBAL(void)
  150230. jinit_downsampler (j_compress_ptr cinfo)
  150231. {
  150232. my_downsample_ptr downsample;
  150233. int ci;
  150234. jpeg_component_info * compptr;
  150235. boolean smoothok = TRUE;
  150236. downsample = (my_downsample_ptr)
  150237. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150238. SIZEOF(my_downsampler));
  150239. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  150240. downsample->pub.start_pass = start_pass_downsample;
  150241. downsample->pub.downsample = sep_downsample;
  150242. downsample->pub.need_context_rows = FALSE;
  150243. if (cinfo->CCIR601_sampling)
  150244. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  150245. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150246. ci++, compptr++) {
  150247. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  150248. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150249. #ifdef INPUT_SMOOTHING_SUPPORTED
  150250. if (cinfo->smoothing_factor) {
  150251. downsample->methods[ci] = fullsize_smooth_downsample;
  150252. downsample->pub.need_context_rows = TRUE;
  150253. } else
  150254. #endif
  150255. downsample->methods[ci] = fullsize_downsample;
  150256. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150257. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150258. smoothok = FALSE;
  150259. downsample->methods[ci] = h2v1_downsample;
  150260. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150261. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  150262. #ifdef INPUT_SMOOTHING_SUPPORTED
  150263. if (cinfo->smoothing_factor) {
  150264. downsample->methods[ci] = h2v2_smooth_downsample;
  150265. downsample->pub.need_context_rows = TRUE;
  150266. } else
  150267. #endif
  150268. downsample->methods[ci] = h2v2_downsample;
  150269. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  150270. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  150271. smoothok = FALSE;
  150272. downsample->methods[ci] = int_downsample;
  150273. } else
  150274. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  150275. }
  150276. #ifdef INPUT_SMOOTHING_SUPPORTED
  150277. if (cinfo->smoothing_factor && !smoothok)
  150278. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  150279. #endif
  150280. }
  150281. /*** End of inlined file: jcsample.c ***/
  150282. /*** Start of inlined file: jctrans.c ***/
  150283. #define JPEG_INTERNALS
  150284. LOCAL(void) transencode_master_selection
  150285. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150286. LOCAL(void) transencode_coef_controller
  150287. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150288. GLOBAL(void)
  150289. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  150290. {
  150291. if (cinfo->global_state != CSTATE_START)
  150292. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150293. jpeg_suppress_tables(cinfo, FALSE);
  150294. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  150295. (*cinfo->dest->init_destination) (cinfo);
  150296. transencode_master_selection(cinfo, coef_arrays);
  150297. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  150298. cinfo->global_state = CSTATE_WRCOEFS;
  150299. }
  150300. GLOBAL(void)
  150301. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  150302. j_compress_ptr dstinfo)
  150303. {
  150304. JQUANT_TBL ** qtblptr;
  150305. jpeg_component_info *incomp, *outcomp;
  150306. JQUANT_TBL *c_quant, *slot_quant;
  150307. int tblno, ci, coefi;
  150308. if (dstinfo->global_state != CSTATE_START)
  150309. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150310. dstinfo->image_width = srcinfo->image_width;
  150311. dstinfo->image_height = srcinfo->image_height;
  150312. dstinfo->input_components = srcinfo->num_components;
  150313. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150314. jpeg_set_defaults(dstinfo);
  150315. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150316. dstinfo->data_precision = srcinfo->data_precision;
  150317. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150318. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150319. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150320. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150321. if (*qtblptr == NULL)
  150322. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150323. MEMCOPY((*qtblptr)->quantval,
  150324. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150325. SIZEOF((*qtblptr)->quantval));
  150326. (*qtblptr)->sent_table = FALSE;
  150327. }
  150328. }
  150329. dstinfo->num_components = srcinfo->num_components;
  150330. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150331. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150332. MAX_COMPONENTS);
  150333. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150334. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150335. outcomp->component_id = incomp->component_id;
  150336. outcomp->h_samp_factor = incomp->h_samp_factor;
  150337. outcomp->v_samp_factor = incomp->v_samp_factor;
  150338. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150339. tblno = outcomp->quant_tbl_no;
  150340. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150341. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150342. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150343. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150344. c_quant = incomp->quant_table;
  150345. if (c_quant != NULL) {
  150346. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150347. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150348. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150349. }
  150350. }
  150351. }
  150352. if (srcinfo->saw_JFIF_marker) {
  150353. if (srcinfo->JFIF_major_version == 1) {
  150354. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150355. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150356. }
  150357. dstinfo->density_unit = srcinfo->density_unit;
  150358. dstinfo->X_density = srcinfo->X_density;
  150359. dstinfo->Y_density = srcinfo->Y_density;
  150360. }
  150361. }
  150362. LOCAL(void)
  150363. transencode_master_selection (j_compress_ptr cinfo,
  150364. jvirt_barray_ptr * coef_arrays)
  150365. {
  150366. cinfo->input_components = 1;
  150367. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150368. if (cinfo->arith_code) {
  150369. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150370. } else {
  150371. if (cinfo->progressive_mode) {
  150372. #ifdef C_PROGRESSIVE_SUPPORTED
  150373. jinit_phuff_encoder(cinfo);
  150374. #else
  150375. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150376. #endif
  150377. } else
  150378. jinit_huff_encoder(cinfo);
  150379. }
  150380. transencode_coef_controller(cinfo, coef_arrays);
  150381. jinit_marker_writer(cinfo);
  150382. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150383. (*cinfo->marker->write_file_header) (cinfo);
  150384. }
  150385. typedef struct {
  150386. struct jpeg_c_coef_controller pub; /* public fields */
  150387. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150388. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150389. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150390. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150391. jvirt_barray_ptr * whole_image;
  150392. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150393. } my_coef_controller2;
  150394. typedef my_coef_controller2 * my_coef_ptr2;
  150395. LOCAL(void)
  150396. start_iMCU_row2 (j_compress_ptr cinfo)
  150397. {
  150398. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150399. if (cinfo->comps_in_scan > 1) {
  150400. coef->MCU_rows_per_iMCU_row = 1;
  150401. } else {
  150402. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150403. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150404. else
  150405. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150406. }
  150407. coef->mcu_ctr = 0;
  150408. coef->MCU_vert_offset = 0;
  150409. }
  150410. METHODDEF(void)
  150411. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150412. {
  150413. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150414. if (pass_mode != JBUF_CRANK_DEST)
  150415. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150416. coef->iMCU_row_num = 0;
  150417. start_iMCU_row2(cinfo);
  150418. }
  150419. METHODDEF(boolean)
  150420. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150421. {
  150422. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150423. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150424. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150425. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150426. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150427. JDIMENSION start_col;
  150428. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150429. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150430. JBLOCKROW buffer_ptr;
  150431. jpeg_component_info *compptr;
  150432. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150433. compptr = cinfo->cur_comp_info[ci];
  150434. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150435. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150436. coef->iMCU_row_num * compptr->v_samp_factor,
  150437. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150438. }
  150439. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150440. yoffset++) {
  150441. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150442. MCU_col_num++) {
  150443. blkn = 0; /* index of current DCT block within MCU */
  150444. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150445. compptr = cinfo->cur_comp_info[ci];
  150446. start_col = MCU_col_num * compptr->MCU_width;
  150447. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150448. : compptr->last_col_width;
  150449. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150450. if (coef->iMCU_row_num < last_iMCU_row ||
  150451. yindex+yoffset < compptr->last_row_height) {
  150452. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150453. for (xindex = 0; xindex < blockcnt; xindex++)
  150454. MCU_buffer[blkn++] = buffer_ptr++;
  150455. } else {
  150456. xindex = 0;
  150457. }
  150458. for (; xindex < compptr->MCU_width; xindex++) {
  150459. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150460. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150461. blkn++;
  150462. }
  150463. }
  150464. }
  150465. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150466. coef->MCU_vert_offset = yoffset;
  150467. coef->mcu_ctr = MCU_col_num;
  150468. return FALSE;
  150469. }
  150470. }
  150471. coef->mcu_ctr = 0;
  150472. }
  150473. coef->iMCU_row_num++;
  150474. start_iMCU_row2(cinfo);
  150475. return TRUE;
  150476. }
  150477. LOCAL(void)
  150478. transencode_coef_controller (j_compress_ptr cinfo,
  150479. jvirt_barray_ptr * coef_arrays)
  150480. {
  150481. my_coef_ptr2 coef;
  150482. JBLOCKROW buffer;
  150483. int i;
  150484. coef = (my_coef_ptr2)
  150485. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150486. SIZEOF(my_coef_controller2));
  150487. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150488. coef->pub.start_pass = start_pass_coef2;
  150489. coef->pub.compress_data = compress_output2;
  150490. coef->whole_image = coef_arrays;
  150491. buffer = (JBLOCKROW)
  150492. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150493. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150494. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150495. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150496. coef->dummy_buffer[i] = buffer + i;
  150497. }
  150498. }
  150499. /*** End of inlined file: jctrans.c ***/
  150500. /*** Start of inlined file: jdapistd.c ***/
  150501. #define JPEG_INTERNALS
  150502. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150503. GLOBAL(boolean)
  150504. jpeg_start_decompress (j_decompress_ptr cinfo)
  150505. {
  150506. if (cinfo->global_state == DSTATE_READY) {
  150507. jinit_master_decompress(cinfo);
  150508. if (cinfo->buffered_image) {
  150509. cinfo->global_state = DSTATE_BUFIMAGE;
  150510. return TRUE;
  150511. }
  150512. cinfo->global_state = DSTATE_PRELOAD;
  150513. }
  150514. if (cinfo->global_state == DSTATE_PRELOAD) {
  150515. if (cinfo->inputctl->has_multiple_scans) {
  150516. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150517. for (;;) {
  150518. int retcode;
  150519. if (cinfo->progress != NULL)
  150520. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150521. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150522. if (retcode == JPEG_SUSPENDED)
  150523. return FALSE;
  150524. if (retcode == JPEG_REACHED_EOI)
  150525. break;
  150526. if (cinfo->progress != NULL &&
  150527. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150528. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150529. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150530. }
  150531. }
  150532. }
  150533. #else
  150534. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150535. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150536. }
  150537. cinfo->output_scan_number = cinfo->input_scan_number;
  150538. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150539. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150540. return output_pass_setup(cinfo);
  150541. }
  150542. LOCAL(boolean)
  150543. output_pass_setup (j_decompress_ptr cinfo)
  150544. {
  150545. if (cinfo->global_state != DSTATE_PRESCAN) {
  150546. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150547. cinfo->output_scanline = 0;
  150548. cinfo->global_state = DSTATE_PRESCAN;
  150549. }
  150550. while (cinfo->master->is_dummy_pass) {
  150551. #ifdef QUANT_2PASS_SUPPORTED
  150552. while (cinfo->output_scanline < cinfo->output_height) {
  150553. JDIMENSION last_scanline;
  150554. if (cinfo->progress != NULL) {
  150555. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150556. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150557. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150558. }
  150559. last_scanline = cinfo->output_scanline;
  150560. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150561. &cinfo->output_scanline, (JDIMENSION) 0);
  150562. if (cinfo->output_scanline == last_scanline)
  150563. return FALSE; /* No progress made, must suspend */
  150564. }
  150565. (*cinfo->master->finish_output_pass) (cinfo);
  150566. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150567. cinfo->output_scanline = 0;
  150568. #else
  150569. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150570. #endif /* QUANT_2PASS_SUPPORTED */
  150571. }
  150572. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150573. return TRUE;
  150574. }
  150575. GLOBAL(JDIMENSION)
  150576. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150577. JDIMENSION max_lines)
  150578. {
  150579. JDIMENSION row_ctr;
  150580. if (cinfo->global_state != DSTATE_SCANNING)
  150581. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150582. if (cinfo->output_scanline >= cinfo->output_height) {
  150583. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150584. return 0;
  150585. }
  150586. if (cinfo->progress != NULL) {
  150587. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150588. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150589. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150590. }
  150591. row_ctr = 0;
  150592. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150593. cinfo->output_scanline += row_ctr;
  150594. return row_ctr;
  150595. }
  150596. GLOBAL(JDIMENSION)
  150597. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150598. JDIMENSION max_lines)
  150599. {
  150600. JDIMENSION lines_per_iMCU_row;
  150601. if (cinfo->global_state != DSTATE_RAW_OK)
  150602. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150603. if (cinfo->output_scanline >= cinfo->output_height) {
  150604. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150605. return 0;
  150606. }
  150607. if (cinfo->progress != NULL) {
  150608. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150609. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150610. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150611. }
  150612. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150613. if (max_lines < lines_per_iMCU_row)
  150614. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150615. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150616. return 0; /* suspension forced, can do nothing more */
  150617. cinfo->output_scanline += lines_per_iMCU_row;
  150618. return lines_per_iMCU_row;
  150619. }
  150620. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150621. GLOBAL(boolean)
  150622. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150623. {
  150624. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150625. cinfo->global_state != DSTATE_PRESCAN)
  150626. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150627. if (scan_number <= 0)
  150628. scan_number = 1;
  150629. if (cinfo->inputctl->eoi_reached &&
  150630. scan_number > cinfo->input_scan_number)
  150631. scan_number = cinfo->input_scan_number;
  150632. cinfo->output_scan_number = scan_number;
  150633. return output_pass_setup(cinfo);
  150634. }
  150635. GLOBAL(boolean)
  150636. jpeg_finish_output (j_decompress_ptr cinfo)
  150637. {
  150638. if ((cinfo->global_state == DSTATE_SCANNING ||
  150639. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150640. (*cinfo->master->finish_output_pass) (cinfo);
  150641. cinfo->global_state = DSTATE_BUFPOST;
  150642. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150643. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150644. }
  150645. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150646. ! cinfo->inputctl->eoi_reached) {
  150647. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150648. return FALSE; /* Suspend, come back later */
  150649. }
  150650. cinfo->global_state = DSTATE_BUFIMAGE;
  150651. return TRUE;
  150652. }
  150653. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150654. /*** End of inlined file: jdapistd.c ***/
  150655. /*** Start of inlined file: jdapimin.c ***/
  150656. #define JPEG_INTERNALS
  150657. GLOBAL(void)
  150658. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150659. {
  150660. int i;
  150661. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150662. if (version != JPEG_LIB_VERSION)
  150663. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150664. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150665. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150666. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150667. {
  150668. struct jpeg_error_mgr * err = cinfo->err;
  150669. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150670. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150671. cinfo->err = err;
  150672. cinfo->client_data = client_data;
  150673. }
  150674. cinfo->is_decompressor = TRUE;
  150675. jinit_memory_mgr((j_common_ptr) cinfo);
  150676. cinfo->progress = NULL;
  150677. cinfo->src = NULL;
  150678. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150679. cinfo->quant_tbl_ptrs[i] = NULL;
  150680. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150681. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150682. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150683. }
  150684. cinfo->marker_list = NULL;
  150685. jinit_marker_reader(cinfo);
  150686. jinit_input_controller(cinfo);
  150687. cinfo->global_state = DSTATE_START;
  150688. }
  150689. GLOBAL(void)
  150690. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150691. {
  150692. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150693. }
  150694. GLOBAL(void)
  150695. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150696. {
  150697. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150698. }
  150699. LOCAL(void)
  150700. default_decompress_parms (j_decompress_ptr cinfo)
  150701. {
  150702. switch (cinfo->num_components) {
  150703. case 1:
  150704. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150705. cinfo->out_color_space = JCS_GRAYSCALE;
  150706. break;
  150707. case 3:
  150708. if (cinfo->saw_JFIF_marker) {
  150709. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150710. } else if (cinfo->saw_Adobe_marker) {
  150711. switch (cinfo->Adobe_transform) {
  150712. case 0:
  150713. cinfo->jpeg_color_space = JCS_RGB;
  150714. break;
  150715. case 1:
  150716. cinfo->jpeg_color_space = JCS_YCbCr;
  150717. break;
  150718. default:
  150719. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150720. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150721. break;
  150722. }
  150723. } else {
  150724. int cid0 = cinfo->comp_info[0].component_id;
  150725. int cid1 = cinfo->comp_info[1].component_id;
  150726. int cid2 = cinfo->comp_info[2].component_id;
  150727. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150728. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150729. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150730. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150731. else {
  150732. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150733. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150734. }
  150735. }
  150736. cinfo->out_color_space = JCS_RGB;
  150737. break;
  150738. case 4:
  150739. if (cinfo->saw_Adobe_marker) {
  150740. switch (cinfo->Adobe_transform) {
  150741. case 0:
  150742. cinfo->jpeg_color_space = JCS_CMYK;
  150743. break;
  150744. case 2:
  150745. cinfo->jpeg_color_space = JCS_YCCK;
  150746. break;
  150747. default:
  150748. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150749. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150750. break;
  150751. }
  150752. } else {
  150753. cinfo->jpeg_color_space = JCS_CMYK;
  150754. }
  150755. cinfo->out_color_space = JCS_CMYK;
  150756. break;
  150757. default:
  150758. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150759. cinfo->out_color_space = JCS_UNKNOWN;
  150760. break;
  150761. }
  150762. cinfo->scale_num = 1; /* 1:1 scaling */
  150763. cinfo->scale_denom = 1;
  150764. cinfo->output_gamma = 1.0;
  150765. cinfo->buffered_image = FALSE;
  150766. cinfo->raw_data_out = FALSE;
  150767. cinfo->dct_method = JDCT_DEFAULT;
  150768. cinfo->do_fancy_upsampling = TRUE;
  150769. cinfo->do_block_smoothing = TRUE;
  150770. cinfo->quantize_colors = FALSE;
  150771. cinfo->dither_mode = JDITHER_FS;
  150772. #ifdef QUANT_2PASS_SUPPORTED
  150773. cinfo->two_pass_quantize = TRUE;
  150774. #else
  150775. cinfo->two_pass_quantize = FALSE;
  150776. #endif
  150777. cinfo->desired_number_of_colors = 256;
  150778. cinfo->colormap = NULL;
  150779. cinfo->enable_1pass_quant = FALSE;
  150780. cinfo->enable_external_quant = FALSE;
  150781. cinfo->enable_2pass_quant = FALSE;
  150782. }
  150783. GLOBAL(int)
  150784. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150785. {
  150786. int retcode;
  150787. if (cinfo->global_state != DSTATE_START &&
  150788. cinfo->global_state != DSTATE_INHEADER)
  150789. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150790. retcode = jpeg_consume_input(cinfo);
  150791. switch (retcode) {
  150792. case JPEG_REACHED_SOS:
  150793. retcode = JPEG_HEADER_OK;
  150794. break;
  150795. case JPEG_REACHED_EOI:
  150796. if (require_image) /* Complain if application wanted an image */
  150797. ERREXIT(cinfo, JERR_NO_IMAGE);
  150798. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150799. retcode = JPEG_HEADER_TABLES_ONLY;
  150800. break;
  150801. case JPEG_SUSPENDED:
  150802. break;
  150803. }
  150804. return retcode;
  150805. }
  150806. GLOBAL(int)
  150807. jpeg_consume_input (j_decompress_ptr cinfo)
  150808. {
  150809. int retcode = JPEG_SUSPENDED;
  150810. switch (cinfo->global_state) {
  150811. case DSTATE_START:
  150812. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150813. (*cinfo->src->init_source) (cinfo);
  150814. cinfo->global_state = DSTATE_INHEADER;
  150815. case DSTATE_INHEADER:
  150816. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150817. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150818. default_decompress_parms(cinfo);
  150819. cinfo->global_state = DSTATE_READY;
  150820. }
  150821. break;
  150822. case DSTATE_READY:
  150823. retcode = JPEG_REACHED_SOS;
  150824. break;
  150825. case DSTATE_PRELOAD:
  150826. case DSTATE_PRESCAN:
  150827. case DSTATE_SCANNING:
  150828. case DSTATE_RAW_OK:
  150829. case DSTATE_BUFIMAGE:
  150830. case DSTATE_BUFPOST:
  150831. case DSTATE_STOPPING:
  150832. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150833. break;
  150834. default:
  150835. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150836. }
  150837. return retcode;
  150838. }
  150839. GLOBAL(boolean)
  150840. jpeg_input_complete (j_decompress_ptr cinfo)
  150841. {
  150842. if (cinfo->global_state < DSTATE_START ||
  150843. cinfo->global_state > DSTATE_STOPPING)
  150844. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150845. return cinfo->inputctl->eoi_reached;
  150846. }
  150847. GLOBAL(boolean)
  150848. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150849. {
  150850. if (cinfo->global_state < DSTATE_READY ||
  150851. cinfo->global_state > DSTATE_STOPPING)
  150852. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150853. return cinfo->inputctl->has_multiple_scans;
  150854. }
  150855. GLOBAL(boolean)
  150856. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150857. {
  150858. if ((cinfo->global_state == DSTATE_SCANNING ||
  150859. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150860. if (cinfo->output_scanline < cinfo->output_height)
  150861. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150862. (*cinfo->master->finish_output_pass) (cinfo);
  150863. cinfo->global_state = DSTATE_STOPPING;
  150864. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150865. cinfo->global_state = DSTATE_STOPPING;
  150866. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150867. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150868. }
  150869. while (! cinfo->inputctl->eoi_reached) {
  150870. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150871. return FALSE; /* Suspend, come back later */
  150872. }
  150873. (*cinfo->src->term_source) (cinfo);
  150874. jpeg_abort((j_common_ptr) cinfo);
  150875. return TRUE;
  150876. }
  150877. /*** End of inlined file: jdapimin.c ***/
  150878. /*** Start of inlined file: jdatasrc.c ***/
  150879. /*** Start of inlined file: jerror.h ***/
  150880. #ifndef JMESSAGE
  150881. #ifndef JERROR_H
  150882. #define JMAKE_ENUM_LIST
  150883. #else
  150884. #define JMESSAGE(code,string)
  150885. #endif /* JERROR_H */
  150886. #endif /* JMESSAGE */
  150887. #ifdef JMAKE_ENUM_LIST
  150888. typedef enum {
  150889. #define JMESSAGE(code,string) code ,
  150890. #endif /* JMAKE_ENUM_LIST */
  150891. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150892. JMESSAGE(JERR_ARITH_NOTIMPL,
  150893. "Sorry, there are legal restrictions on arithmetic coding")
  150894. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150895. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150896. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150897. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150898. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150899. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150900. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150901. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150902. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150903. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150904. JMESSAGE(JERR_BAD_LIB_VERSION,
  150905. "Wrong JPEG library version: library is %d, caller expects %d")
  150906. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150907. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150908. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150909. JMESSAGE(JERR_BAD_PROGRESSION,
  150910. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150911. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150912. "Invalid progressive parameters at scan script entry %d")
  150913. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150914. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150915. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150916. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150917. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150918. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150919. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150920. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150921. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150922. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150923. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150924. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150925. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150926. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150927. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150928. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150929. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150930. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150931. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150932. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150933. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150934. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150935. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150936. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150937. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150938. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150939. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150940. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150941. "Cannot transcode due to multiple use of quantization table %d")
  150942. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150943. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150944. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150945. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150946. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150947. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150948. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150949. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150950. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150951. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150952. JMESSAGE(JERR_QUANT_COMPONENTS,
  150953. "Cannot quantize more than %d color components")
  150954. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150955. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150956. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150957. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150958. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150959. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150960. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150961. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150962. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150963. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150964. JMESSAGE(JERR_TFILE_WRITE,
  150965. "Write failed on temporary file --- out of disk space?")
  150966. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150967. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150968. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150969. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150970. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150971. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150972. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150973. JMESSAGE(JMSG_VERSION, JVERSION)
  150974. JMESSAGE(JTRC_16BIT_TABLES,
  150975. "Caution: quantization tables are too coarse for baseline JPEG")
  150976. JMESSAGE(JTRC_ADOBE,
  150977. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150978. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150979. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150980. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150981. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150982. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150983. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150984. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150985. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150986. JMESSAGE(JTRC_EOI, "End Of Image")
  150987. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150988. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150989. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150990. "Warning: thumbnail image size does not match data length %u")
  150991. JMESSAGE(JTRC_JFIF_EXTENSION,
  150992. "JFIF extension marker: type 0x%02x, length %u")
  150993. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150994. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150995. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150996. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150997. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150998. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150999. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  151000. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  151001. JMESSAGE(JTRC_RST, "RST%d")
  151002. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  151003. "Smoothing not supported with nonstandard sampling ratios")
  151004. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  151005. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  151006. JMESSAGE(JTRC_SOI, "Start of Image")
  151007. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  151008. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  151009. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  151010. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  151011. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  151012. JMESSAGE(JTRC_THUMB_JPEG,
  151013. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  151014. JMESSAGE(JTRC_THUMB_PALETTE,
  151015. "JFIF extension marker: palette thumbnail image, length %u")
  151016. JMESSAGE(JTRC_THUMB_RGB,
  151017. "JFIF extension marker: RGB thumbnail image, length %u")
  151018. JMESSAGE(JTRC_UNKNOWN_IDS,
  151019. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  151020. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  151021. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  151022. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  151023. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  151024. "Inconsistent progression sequence for component %d coefficient %d")
  151025. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  151026. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  151027. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  151028. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  151029. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  151030. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  151031. JMESSAGE(JWRN_MUST_RESYNC,
  151032. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  151033. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  151034. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  151035. #ifdef JMAKE_ENUM_LIST
  151036. JMSG_LASTMSGCODE
  151037. } J_MESSAGE_CODE;
  151038. #undef JMAKE_ENUM_LIST
  151039. #endif /* JMAKE_ENUM_LIST */
  151040. #undef JMESSAGE
  151041. #ifndef JERROR_H
  151042. #define JERROR_H
  151043. #define ERREXIT(cinfo,code) \
  151044. ((cinfo)->err->msg_code = (code), \
  151045. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151046. #define ERREXIT1(cinfo,code,p1) \
  151047. ((cinfo)->err->msg_code = (code), \
  151048. (cinfo)->err->msg_parm.i[0] = (p1), \
  151049. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151050. #define ERREXIT2(cinfo,code,p1,p2) \
  151051. ((cinfo)->err->msg_code = (code), \
  151052. (cinfo)->err->msg_parm.i[0] = (p1), \
  151053. (cinfo)->err->msg_parm.i[1] = (p2), \
  151054. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151055. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  151056. ((cinfo)->err->msg_code = (code), \
  151057. (cinfo)->err->msg_parm.i[0] = (p1), \
  151058. (cinfo)->err->msg_parm.i[1] = (p2), \
  151059. (cinfo)->err->msg_parm.i[2] = (p3), \
  151060. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151061. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  151062. ((cinfo)->err->msg_code = (code), \
  151063. (cinfo)->err->msg_parm.i[0] = (p1), \
  151064. (cinfo)->err->msg_parm.i[1] = (p2), \
  151065. (cinfo)->err->msg_parm.i[2] = (p3), \
  151066. (cinfo)->err->msg_parm.i[3] = (p4), \
  151067. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151068. #define ERREXITS(cinfo,code,str) \
  151069. ((cinfo)->err->msg_code = (code), \
  151070. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151071. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151072. #define MAKESTMT(stuff) do { stuff } while (0)
  151073. #define WARNMS(cinfo,code) \
  151074. ((cinfo)->err->msg_code = (code), \
  151075. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151076. #define WARNMS1(cinfo,code,p1) \
  151077. ((cinfo)->err->msg_code = (code), \
  151078. (cinfo)->err->msg_parm.i[0] = (p1), \
  151079. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151080. #define WARNMS2(cinfo,code,p1,p2) \
  151081. ((cinfo)->err->msg_code = (code), \
  151082. (cinfo)->err->msg_parm.i[0] = (p1), \
  151083. (cinfo)->err->msg_parm.i[1] = (p2), \
  151084. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151085. #define TRACEMS(cinfo,lvl,code) \
  151086. ((cinfo)->err->msg_code = (code), \
  151087. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151088. #define TRACEMS1(cinfo,lvl,code,p1) \
  151089. ((cinfo)->err->msg_code = (code), \
  151090. (cinfo)->err->msg_parm.i[0] = (p1), \
  151091. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151092. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  151093. ((cinfo)->err->msg_code = (code), \
  151094. (cinfo)->err->msg_parm.i[0] = (p1), \
  151095. (cinfo)->err->msg_parm.i[1] = (p2), \
  151096. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151097. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  151098. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151099. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  151100. (cinfo)->err->msg_code = (code); \
  151101. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151102. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  151103. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151104. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151105. (cinfo)->err->msg_code = (code); \
  151106. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151107. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  151108. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151109. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151110. _mp[4] = (p5); \
  151111. (cinfo)->err->msg_code = (code); \
  151112. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151113. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  151114. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151115. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151116. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  151117. (cinfo)->err->msg_code = (code); \
  151118. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151119. #define TRACEMSS(cinfo,lvl,code,str) \
  151120. ((cinfo)->err->msg_code = (code), \
  151121. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151122. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151123. #endif /* JERROR_H */
  151124. /*** End of inlined file: jerror.h ***/
  151125. typedef struct {
  151126. struct jpeg_source_mgr pub; /* public fields */
  151127. FILE * infile; /* source stream */
  151128. JOCTET * buffer; /* start of buffer */
  151129. boolean start_of_file; /* have we gotten any data yet? */
  151130. } my_source_mgr;
  151131. typedef my_source_mgr * my_src_ptr;
  151132. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  151133. METHODDEF(void)
  151134. init_source (j_decompress_ptr cinfo)
  151135. {
  151136. my_src_ptr src = (my_src_ptr) cinfo->src;
  151137. src->start_of_file = TRUE;
  151138. }
  151139. METHODDEF(boolean)
  151140. fill_input_buffer (j_decompress_ptr cinfo)
  151141. {
  151142. my_src_ptr src = (my_src_ptr) cinfo->src;
  151143. size_t nbytes;
  151144. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  151145. if (nbytes <= 0) {
  151146. if (src->start_of_file) /* Treat empty input file as fatal error */
  151147. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  151148. WARNMS(cinfo, JWRN_JPEG_EOF);
  151149. src->buffer[0] = (JOCTET) 0xFF;
  151150. src->buffer[1] = (JOCTET) JPEG_EOI;
  151151. nbytes = 2;
  151152. }
  151153. src->pub.next_input_byte = src->buffer;
  151154. src->pub.bytes_in_buffer = nbytes;
  151155. src->start_of_file = FALSE;
  151156. return TRUE;
  151157. }
  151158. METHODDEF(void)
  151159. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  151160. {
  151161. my_src_ptr src = (my_src_ptr) cinfo->src;
  151162. if (num_bytes > 0) {
  151163. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  151164. num_bytes -= (long) src->pub.bytes_in_buffer;
  151165. (void) fill_input_buffer(cinfo);
  151166. }
  151167. src->pub.next_input_byte += (size_t) num_bytes;
  151168. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  151169. }
  151170. }
  151171. METHODDEF(void)
  151172. term_source (j_decompress_ptr cinfo)
  151173. {
  151174. }
  151175. GLOBAL(void)
  151176. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  151177. {
  151178. my_src_ptr src;
  151179. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  151180. cinfo->src = (struct jpeg_source_mgr *)
  151181. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151182. SIZEOF(my_source_mgr));
  151183. src = (my_src_ptr) cinfo->src;
  151184. src->buffer = (JOCTET *)
  151185. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151186. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  151187. }
  151188. src = (my_src_ptr) cinfo->src;
  151189. src->pub.init_source = init_source;
  151190. src->pub.fill_input_buffer = fill_input_buffer;
  151191. src->pub.skip_input_data = skip_input_data;
  151192. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  151193. src->pub.term_source = term_source;
  151194. src->infile = infile;
  151195. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  151196. src->pub.next_input_byte = NULL; /* until buffer loaded */
  151197. }
  151198. /*** End of inlined file: jdatasrc.c ***/
  151199. /*** Start of inlined file: jdcoefct.c ***/
  151200. #define JPEG_INTERNALS
  151201. #ifndef D_PROGRESSIVE_SUPPORTED
  151202. #undef BLOCK_SMOOTHING_SUPPORTED
  151203. #endif
  151204. typedef struct {
  151205. struct jpeg_d_coef_controller pub; /* public fields */
  151206. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  151207. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  151208. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  151209. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  151210. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151211. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  151212. #endif
  151213. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151214. int * coef_bits_latch;
  151215. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  151216. #endif
  151217. } my_coef_controller3;
  151218. typedef my_coef_controller3 * my_coef_ptr3;
  151219. METHODDEF(int) decompress_onepass
  151220. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151221. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151222. METHODDEF(int) decompress_data
  151223. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151224. #endif
  151225. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151226. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  151227. METHODDEF(int) decompress_smooth_data
  151228. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151229. #endif
  151230. LOCAL(void)
  151231. start_iMCU_row3 (j_decompress_ptr cinfo)
  151232. {
  151233. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151234. if (cinfo->comps_in_scan > 1) {
  151235. coef->MCU_rows_per_iMCU_row = 1;
  151236. } else {
  151237. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  151238. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  151239. else
  151240. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  151241. }
  151242. coef->MCU_ctr = 0;
  151243. coef->MCU_vert_offset = 0;
  151244. }
  151245. METHODDEF(void)
  151246. start_input_pass (j_decompress_ptr cinfo)
  151247. {
  151248. cinfo->input_iMCU_row = 0;
  151249. start_iMCU_row3(cinfo);
  151250. }
  151251. METHODDEF(void)
  151252. start_output_pass (j_decompress_ptr cinfo)
  151253. {
  151254. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151255. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151256. if (coef->pub.coef_arrays != NULL) {
  151257. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  151258. coef->pub.decompress_data = decompress_smooth_data;
  151259. else
  151260. coef->pub.decompress_data = decompress_data;
  151261. }
  151262. #endif
  151263. cinfo->output_iMCU_row = 0;
  151264. }
  151265. METHODDEF(int)
  151266. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151267. {
  151268. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151269. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151270. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  151271. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151272. int blkn, ci, xindex, yindex, yoffset, useful_width;
  151273. JSAMPARRAY output_ptr;
  151274. JDIMENSION start_col, output_col;
  151275. jpeg_component_info *compptr;
  151276. inverse_DCT_method_ptr inverse_DCT;
  151277. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151278. yoffset++) {
  151279. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  151280. MCU_col_num++) {
  151281. jzero_far((void FAR *) coef->MCU_buffer[0],
  151282. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  151283. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151284. coef->MCU_vert_offset = yoffset;
  151285. coef->MCU_ctr = MCU_col_num;
  151286. return JPEG_SUSPENDED;
  151287. }
  151288. blkn = 0; /* index of current DCT block within MCU */
  151289. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151290. compptr = cinfo->cur_comp_info[ci];
  151291. if (! compptr->component_needed) {
  151292. blkn += compptr->MCU_blocks;
  151293. continue;
  151294. }
  151295. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  151296. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  151297. : compptr->last_col_width;
  151298. output_ptr = output_buf[compptr->component_index] +
  151299. yoffset * compptr->DCT_scaled_size;
  151300. start_col = MCU_col_num * compptr->MCU_sample_width;
  151301. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151302. if (cinfo->input_iMCU_row < last_iMCU_row ||
  151303. yoffset+yindex < compptr->last_row_height) {
  151304. output_col = start_col;
  151305. for (xindex = 0; xindex < useful_width; xindex++) {
  151306. (*inverse_DCT) (cinfo, compptr,
  151307. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151308. output_ptr, output_col);
  151309. output_col += compptr->DCT_scaled_size;
  151310. }
  151311. }
  151312. blkn += compptr->MCU_width;
  151313. output_ptr += compptr->DCT_scaled_size;
  151314. }
  151315. }
  151316. }
  151317. coef->MCU_ctr = 0;
  151318. }
  151319. cinfo->output_iMCU_row++;
  151320. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151321. start_iMCU_row3(cinfo);
  151322. return JPEG_ROW_COMPLETED;
  151323. }
  151324. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151325. return JPEG_SCAN_COMPLETED;
  151326. }
  151327. METHODDEF(int)
  151328. dummy_consume_data (j_decompress_ptr cinfo)
  151329. {
  151330. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151331. }
  151332. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151333. METHODDEF(int)
  151334. consume_data (j_decompress_ptr cinfo)
  151335. {
  151336. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151337. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151338. int blkn, ci, xindex, yindex, yoffset;
  151339. JDIMENSION start_col;
  151340. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151341. JBLOCKROW buffer_ptr;
  151342. jpeg_component_info *compptr;
  151343. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151344. compptr = cinfo->cur_comp_info[ci];
  151345. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151346. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151347. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151348. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151349. }
  151350. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151351. yoffset++) {
  151352. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151353. MCU_col_num++) {
  151354. blkn = 0; /* index of current DCT block within MCU */
  151355. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151356. compptr = cinfo->cur_comp_info[ci];
  151357. start_col = MCU_col_num * compptr->MCU_width;
  151358. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151359. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151360. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151361. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151362. }
  151363. }
  151364. }
  151365. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151366. coef->MCU_vert_offset = yoffset;
  151367. coef->MCU_ctr = MCU_col_num;
  151368. return JPEG_SUSPENDED;
  151369. }
  151370. }
  151371. coef->MCU_ctr = 0;
  151372. }
  151373. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151374. start_iMCU_row3(cinfo);
  151375. return JPEG_ROW_COMPLETED;
  151376. }
  151377. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151378. return JPEG_SCAN_COMPLETED;
  151379. }
  151380. METHODDEF(int)
  151381. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151382. {
  151383. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151384. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151385. JDIMENSION block_num;
  151386. int ci, block_row, block_rows;
  151387. JBLOCKARRAY buffer;
  151388. JBLOCKROW buffer_ptr;
  151389. JSAMPARRAY output_ptr;
  151390. JDIMENSION output_col;
  151391. jpeg_component_info *compptr;
  151392. inverse_DCT_method_ptr inverse_DCT;
  151393. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151394. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151395. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151396. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151397. return JPEG_SUSPENDED;
  151398. }
  151399. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151400. ci++, compptr++) {
  151401. if (! compptr->component_needed)
  151402. continue;
  151403. buffer = (*cinfo->mem->access_virt_barray)
  151404. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151405. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151406. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151407. if (cinfo->output_iMCU_row < last_iMCU_row)
  151408. block_rows = compptr->v_samp_factor;
  151409. else {
  151410. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151411. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151412. }
  151413. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151414. output_ptr = output_buf[ci];
  151415. for (block_row = 0; block_row < block_rows; block_row++) {
  151416. buffer_ptr = buffer[block_row];
  151417. output_col = 0;
  151418. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151419. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151420. output_ptr, output_col);
  151421. buffer_ptr++;
  151422. output_col += compptr->DCT_scaled_size;
  151423. }
  151424. output_ptr += compptr->DCT_scaled_size;
  151425. }
  151426. }
  151427. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151428. return JPEG_ROW_COMPLETED;
  151429. return JPEG_SCAN_COMPLETED;
  151430. }
  151431. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151432. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151433. #define Q01_POS 1
  151434. #define Q10_POS 8
  151435. #define Q20_POS 16
  151436. #define Q11_POS 9
  151437. #define Q02_POS 2
  151438. LOCAL(boolean)
  151439. smoothing_ok (j_decompress_ptr cinfo)
  151440. {
  151441. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151442. boolean smoothing_useful = FALSE;
  151443. int ci, coefi;
  151444. jpeg_component_info *compptr;
  151445. JQUANT_TBL * qtable;
  151446. int * coef_bits;
  151447. int * coef_bits_latch;
  151448. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151449. return FALSE;
  151450. if (coef->coef_bits_latch == NULL)
  151451. coef->coef_bits_latch = (int *)
  151452. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151453. cinfo->num_components *
  151454. (SAVED_COEFS * SIZEOF(int)));
  151455. coef_bits_latch = coef->coef_bits_latch;
  151456. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151457. ci++, compptr++) {
  151458. if ((qtable = compptr->quant_table) == NULL)
  151459. return FALSE;
  151460. if (qtable->quantval[0] == 0 ||
  151461. qtable->quantval[Q01_POS] == 0 ||
  151462. qtable->quantval[Q10_POS] == 0 ||
  151463. qtable->quantval[Q20_POS] == 0 ||
  151464. qtable->quantval[Q11_POS] == 0 ||
  151465. qtable->quantval[Q02_POS] == 0)
  151466. return FALSE;
  151467. coef_bits = cinfo->coef_bits[ci];
  151468. if (coef_bits[0] < 0)
  151469. return FALSE;
  151470. for (coefi = 1; coefi <= 5; coefi++) {
  151471. coef_bits_latch[coefi] = coef_bits[coefi];
  151472. if (coef_bits[coefi] != 0)
  151473. smoothing_useful = TRUE;
  151474. }
  151475. coef_bits_latch += SAVED_COEFS;
  151476. }
  151477. return smoothing_useful;
  151478. }
  151479. METHODDEF(int)
  151480. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151481. {
  151482. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151483. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151484. JDIMENSION block_num, last_block_column;
  151485. int ci, block_row, block_rows, access_rows;
  151486. JBLOCKARRAY buffer;
  151487. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151488. JSAMPARRAY output_ptr;
  151489. JDIMENSION output_col;
  151490. jpeg_component_info *compptr;
  151491. inverse_DCT_method_ptr inverse_DCT;
  151492. boolean first_row, last_row;
  151493. JBLOCK workspace;
  151494. int *coef_bits;
  151495. JQUANT_TBL *quanttbl;
  151496. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151497. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151498. int Al, pred;
  151499. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151500. ! cinfo->inputctl->eoi_reached) {
  151501. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151502. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151503. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151504. break;
  151505. }
  151506. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151507. return JPEG_SUSPENDED;
  151508. }
  151509. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151510. ci++, compptr++) {
  151511. if (! compptr->component_needed)
  151512. continue;
  151513. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151514. block_rows = compptr->v_samp_factor;
  151515. access_rows = block_rows * 2; /* this and next iMCU row */
  151516. last_row = FALSE;
  151517. } else {
  151518. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151519. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151520. access_rows = block_rows; /* this iMCU row only */
  151521. last_row = TRUE;
  151522. }
  151523. if (cinfo->output_iMCU_row > 0) {
  151524. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151525. buffer = (*cinfo->mem->access_virt_barray)
  151526. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151527. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151528. (JDIMENSION) access_rows, FALSE);
  151529. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151530. first_row = FALSE;
  151531. } else {
  151532. buffer = (*cinfo->mem->access_virt_barray)
  151533. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151534. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151535. first_row = TRUE;
  151536. }
  151537. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151538. quanttbl = compptr->quant_table;
  151539. Q00 = quanttbl->quantval[0];
  151540. Q01 = quanttbl->quantval[Q01_POS];
  151541. Q10 = quanttbl->quantval[Q10_POS];
  151542. Q20 = quanttbl->quantval[Q20_POS];
  151543. Q11 = quanttbl->quantval[Q11_POS];
  151544. Q02 = quanttbl->quantval[Q02_POS];
  151545. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151546. output_ptr = output_buf[ci];
  151547. for (block_row = 0; block_row < block_rows; block_row++) {
  151548. buffer_ptr = buffer[block_row];
  151549. if (first_row && block_row == 0)
  151550. prev_block_row = buffer_ptr;
  151551. else
  151552. prev_block_row = buffer[block_row-1];
  151553. if (last_row && block_row == block_rows-1)
  151554. next_block_row = buffer_ptr;
  151555. else
  151556. next_block_row = buffer[block_row+1];
  151557. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151558. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151559. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151560. output_col = 0;
  151561. last_block_column = compptr->width_in_blocks - 1;
  151562. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151563. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151564. if (block_num < last_block_column) {
  151565. DC3 = (int) prev_block_row[1][0];
  151566. DC6 = (int) buffer_ptr[1][0];
  151567. DC9 = (int) next_block_row[1][0];
  151568. }
  151569. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151570. num = 36 * Q00 * (DC4 - DC6);
  151571. if (num >= 0) {
  151572. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151573. if (Al > 0 && pred >= (1<<Al))
  151574. pred = (1<<Al)-1;
  151575. } else {
  151576. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151577. if (Al > 0 && pred >= (1<<Al))
  151578. pred = (1<<Al)-1;
  151579. pred = -pred;
  151580. }
  151581. workspace[1] = (JCOEF) pred;
  151582. }
  151583. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151584. num = 36 * Q00 * (DC2 - DC8);
  151585. if (num >= 0) {
  151586. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151587. if (Al > 0 && pred >= (1<<Al))
  151588. pred = (1<<Al)-1;
  151589. } else {
  151590. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151591. if (Al > 0 && pred >= (1<<Al))
  151592. pred = (1<<Al)-1;
  151593. pred = -pred;
  151594. }
  151595. workspace[8] = (JCOEF) pred;
  151596. }
  151597. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151598. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151599. if (num >= 0) {
  151600. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151601. if (Al > 0 && pred >= (1<<Al))
  151602. pred = (1<<Al)-1;
  151603. } else {
  151604. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151605. if (Al > 0 && pred >= (1<<Al))
  151606. pred = (1<<Al)-1;
  151607. pred = -pred;
  151608. }
  151609. workspace[16] = (JCOEF) pred;
  151610. }
  151611. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151612. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151613. if (num >= 0) {
  151614. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151615. if (Al > 0 && pred >= (1<<Al))
  151616. pred = (1<<Al)-1;
  151617. } else {
  151618. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151619. if (Al > 0 && pred >= (1<<Al))
  151620. pred = (1<<Al)-1;
  151621. pred = -pred;
  151622. }
  151623. workspace[9] = (JCOEF) pred;
  151624. }
  151625. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151626. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151627. if (num >= 0) {
  151628. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151629. if (Al > 0 && pred >= (1<<Al))
  151630. pred = (1<<Al)-1;
  151631. } else {
  151632. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151633. if (Al > 0 && pred >= (1<<Al))
  151634. pred = (1<<Al)-1;
  151635. pred = -pred;
  151636. }
  151637. workspace[2] = (JCOEF) pred;
  151638. }
  151639. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151640. output_ptr, output_col);
  151641. DC1 = DC2; DC2 = DC3;
  151642. DC4 = DC5; DC5 = DC6;
  151643. DC7 = DC8; DC8 = DC9;
  151644. buffer_ptr++, prev_block_row++, next_block_row++;
  151645. output_col += compptr->DCT_scaled_size;
  151646. }
  151647. output_ptr += compptr->DCT_scaled_size;
  151648. }
  151649. }
  151650. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151651. return JPEG_ROW_COMPLETED;
  151652. return JPEG_SCAN_COMPLETED;
  151653. }
  151654. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151655. GLOBAL(void)
  151656. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151657. {
  151658. my_coef_ptr3 coef;
  151659. coef = (my_coef_ptr3)
  151660. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151661. SIZEOF(my_coef_controller3));
  151662. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151663. coef->pub.start_input_pass = start_input_pass;
  151664. coef->pub.start_output_pass = start_output_pass;
  151665. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151666. coef->coef_bits_latch = NULL;
  151667. #endif
  151668. if (need_full_buffer) {
  151669. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151670. int ci, access_rows;
  151671. jpeg_component_info *compptr;
  151672. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151673. ci++, compptr++) {
  151674. access_rows = compptr->v_samp_factor;
  151675. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151676. if (cinfo->progressive_mode)
  151677. access_rows *= 3;
  151678. #endif
  151679. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151680. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151681. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151682. (long) compptr->h_samp_factor),
  151683. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151684. (long) compptr->v_samp_factor),
  151685. (JDIMENSION) access_rows);
  151686. }
  151687. coef->pub.consume_data = consume_data;
  151688. coef->pub.decompress_data = decompress_data;
  151689. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151690. #else
  151691. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151692. #endif
  151693. } else {
  151694. JBLOCKROW buffer;
  151695. int i;
  151696. buffer = (JBLOCKROW)
  151697. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151698. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151699. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151700. coef->MCU_buffer[i] = buffer + i;
  151701. }
  151702. coef->pub.consume_data = dummy_consume_data;
  151703. coef->pub.decompress_data = decompress_onepass;
  151704. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151705. }
  151706. }
  151707. /*** End of inlined file: jdcoefct.c ***/
  151708. #undef FIX
  151709. /*** Start of inlined file: jdcolor.c ***/
  151710. #define JPEG_INTERNALS
  151711. typedef struct {
  151712. struct jpeg_color_deconverter pub; /* public fields */
  151713. int * Cr_r_tab; /* => table for Cr to R conversion */
  151714. int * Cb_b_tab; /* => table for Cb to B conversion */
  151715. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151716. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151717. } my_color_deconverter2;
  151718. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151719. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151720. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151721. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151722. LOCAL(void)
  151723. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151724. {
  151725. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151726. int i;
  151727. INT32 x;
  151728. SHIFT_TEMPS
  151729. cconvert->Cr_r_tab = (int *)
  151730. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151731. (MAXJSAMPLE+1) * SIZEOF(int));
  151732. cconvert->Cb_b_tab = (int *)
  151733. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151734. (MAXJSAMPLE+1) * SIZEOF(int));
  151735. cconvert->Cr_g_tab = (INT32 *)
  151736. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151737. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151738. cconvert->Cb_g_tab = (INT32 *)
  151739. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151740. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151741. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151742. cconvert->Cr_r_tab[i] = (int)
  151743. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151744. cconvert->Cb_b_tab[i] = (int)
  151745. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151746. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151747. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151748. }
  151749. }
  151750. METHODDEF(void)
  151751. ycc_rgb_convert (j_decompress_ptr cinfo,
  151752. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151753. JSAMPARRAY output_buf, int num_rows)
  151754. {
  151755. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151756. register int y, cb, cr;
  151757. register JSAMPROW outptr;
  151758. register JSAMPROW inptr0, inptr1, inptr2;
  151759. register JDIMENSION col;
  151760. JDIMENSION num_cols = cinfo->output_width;
  151761. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151762. register int * Crrtab = cconvert->Cr_r_tab;
  151763. register int * Cbbtab = cconvert->Cb_b_tab;
  151764. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151765. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151766. SHIFT_TEMPS
  151767. while (--num_rows >= 0) {
  151768. inptr0 = input_buf[0][input_row];
  151769. inptr1 = input_buf[1][input_row];
  151770. inptr2 = input_buf[2][input_row];
  151771. input_row++;
  151772. outptr = *output_buf++;
  151773. for (col = 0; col < num_cols; col++) {
  151774. y = GETJSAMPLE(inptr0[col]);
  151775. cb = GETJSAMPLE(inptr1[col]);
  151776. cr = GETJSAMPLE(inptr2[col]);
  151777. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151778. outptr[RGB_GREEN] = range_limit[y +
  151779. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151780. SCALEBITS))];
  151781. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151782. outptr += RGB_PIXELSIZE;
  151783. }
  151784. }
  151785. }
  151786. METHODDEF(void)
  151787. null_convert2 (j_decompress_ptr cinfo,
  151788. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151789. JSAMPARRAY output_buf, int num_rows)
  151790. {
  151791. register JSAMPROW inptr, outptr;
  151792. register JDIMENSION count;
  151793. register int num_components = cinfo->num_components;
  151794. JDIMENSION num_cols = cinfo->output_width;
  151795. int ci;
  151796. while (--num_rows >= 0) {
  151797. for (ci = 0; ci < num_components; ci++) {
  151798. inptr = input_buf[ci][input_row];
  151799. outptr = output_buf[0] + ci;
  151800. for (count = num_cols; count > 0; count--) {
  151801. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151802. outptr += num_components;
  151803. }
  151804. }
  151805. input_row++;
  151806. output_buf++;
  151807. }
  151808. }
  151809. METHODDEF(void)
  151810. grayscale_convert2 (j_decompress_ptr cinfo,
  151811. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151812. JSAMPARRAY output_buf, int num_rows)
  151813. {
  151814. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151815. num_rows, cinfo->output_width);
  151816. }
  151817. METHODDEF(void)
  151818. gray_rgb_convert (j_decompress_ptr cinfo,
  151819. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151820. JSAMPARRAY output_buf, int num_rows)
  151821. {
  151822. register JSAMPROW inptr, outptr;
  151823. register JDIMENSION col;
  151824. JDIMENSION num_cols = cinfo->output_width;
  151825. while (--num_rows >= 0) {
  151826. inptr = input_buf[0][input_row++];
  151827. outptr = *output_buf++;
  151828. for (col = 0; col < num_cols; col++) {
  151829. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151830. outptr += RGB_PIXELSIZE;
  151831. }
  151832. }
  151833. }
  151834. METHODDEF(void)
  151835. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151836. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151837. JSAMPARRAY output_buf, int num_rows)
  151838. {
  151839. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151840. register int y, cb, cr;
  151841. register JSAMPROW outptr;
  151842. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151843. register JDIMENSION col;
  151844. JDIMENSION num_cols = cinfo->output_width;
  151845. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151846. register int * Crrtab = cconvert->Cr_r_tab;
  151847. register int * Cbbtab = cconvert->Cb_b_tab;
  151848. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151849. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151850. SHIFT_TEMPS
  151851. while (--num_rows >= 0) {
  151852. inptr0 = input_buf[0][input_row];
  151853. inptr1 = input_buf[1][input_row];
  151854. inptr2 = input_buf[2][input_row];
  151855. inptr3 = input_buf[3][input_row];
  151856. input_row++;
  151857. outptr = *output_buf++;
  151858. for (col = 0; col < num_cols; col++) {
  151859. y = GETJSAMPLE(inptr0[col]);
  151860. cb = GETJSAMPLE(inptr1[col]);
  151861. cr = GETJSAMPLE(inptr2[col]);
  151862. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151863. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151864. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151865. SCALEBITS)))];
  151866. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151867. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151868. outptr += 4;
  151869. }
  151870. }
  151871. }
  151872. METHODDEF(void)
  151873. start_pass_dcolor (j_decompress_ptr cinfo)
  151874. {
  151875. }
  151876. GLOBAL(void)
  151877. jinit_color_deconverter (j_decompress_ptr cinfo)
  151878. {
  151879. my_cconvert_ptr2 cconvert;
  151880. int ci;
  151881. cconvert = (my_cconvert_ptr2)
  151882. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151883. SIZEOF(my_color_deconverter2));
  151884. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151885. cconvert->pub.start_pass = start_pass_dcolor;
  151886. switch (cinfo->jpeg_color_space) {
  151887. case JCS_GRAYSCALE:
  151888. if (cinfo->num_components != 1)
  151889. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151890. break;
  151891. case JCS_RGB:
  151892. case JCS_YCbCr:
  151893. if (cinfo->num_components != 3)
  151894. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151895. break;
  151896. case JCS_CMYK:
  151897. case JCS_YCCK:
  151898. if (cinfo->num_components != 4)
  151899. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151900. break;
  151901. default: /* JCS_UNKNOWN can be anything */
  151902. if (cinfo->num_components < 1)
  151903. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151904. break;
  151905. }
  151906. switch (cinfo->out_color_space) {
  151907. case JCS_GRAYSCALE:
  151908. cinfo->out_color_components = 1;
  151909. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151910. cinfo->jpeg_color_space == JCS_YCbCr) {
  151911. cconvert->pub.color_convert = grayscale_convert2;
  151912. for (ci = 1; ci < cinfo->num_components; ci++)
  151913. cinfo->comp_info[ci].component_needed = FALSE;
  151914. } else
  151915. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151916. break;
  151917. case JCS_RGB:
  151918. cinfo->out_color_components = RGB_PIXELSIZE;
  151919. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151920. cconvert->pub.color_convert = ycc_rgb_convert;
  151921. build_ycc_rgb_table(cinfo);
  151922. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151923. cconvert->pub.color_convert = gray_rgb_convert;
  151924. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151925. cconvert->pub.color_convert = null_convert2;
  151926. } else
  151927. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151928. break;
  151929. case JCS_CMYK:
  151930. cinfo->out_color_components = 4;
  151931. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151932. cconvert->pub.color_convert = ycck_cmyk_convert;
  151933. build_ycc_rgb_table(cinfo);
  151934. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151935. cconvert->pub.color_convert = null_convert2;
  151936. } else
  151937. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151938. break;
  151939. default:
  151940. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151941. cinfo->out_color_components = cinfo->num_components;
  151942. cconvert->pub.color_convert = null_convert2;
  151943. } else /* unsupported non-null conversion */
  151944. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151945. break;
  151946. }
  151947. if (cinfo->quantize_colors)
  151948. cinfo->output_components = 1; /* single colormapped output component */
  151949. else
  151950. cinfo->output_components = cinfo->out_color_components;
  151951. }
  151952. /*** End of inlined file: jdcolor.c ***/
  151953. #undef FIX
  151954. /*** Start of inlined file: jddctmgr.c ***/
  151955. #define JPEG_INTERNALS
  151956. typedef struct {
  151957. struct jpeg_inverse_dct pub; /* public fields */
  151958. int cur_method[MAX_COMPONENTS];
  151959. } my_idct_controller;
  151960. typedef my_idct_controller * my_idct_ptr;
  151961. typedef union {
  151962. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151963. #ifdef DCT_IFAST_SUPPORTED
  151964. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151965. #endif
  151966. #ifdef DCT_FLOAT_SUPPORTED
  151967. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151968. #endif
  151969. } multiplier_table;
  151970. #ifdef DCT_ISLOW_SUPPORTED
  151971. #define PROVIDE_ISLOW_TABLES
  151972. #else
  151973. #ifdef IDCT_SCALING_SUPPORTED
  151974. #define PROVIDE_ISLOW_TABLES
  151975. #endif
  151976. #endif
  151977. METHODDEF(void)
  151978. start_pass (j_decompress_ptr cinfo)
  151979. {
  151980. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151981. int ci, i;
  151982. jpeg_component_info *compptr;
  151983. int method = 0;
  151984. inverse_DCT_method_ptr method_ptr = NULL;
  151985. JQUANT_TBL * qtbl;
  151986. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151987. ci++, compptr++) {
  151988. switch (compptr->DCT_scaled_size) {
  151989. #ifdef IDCT_SCALING_SUPPORTED
  151990. case 1:
  151991. method_ptr = jpeg_idct_1x1;
  151992. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151993. break;
  151994. case 2:
  151995. method_ptr = jpeg_idct_2x2;
  151996. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151997. break;
  151998. case 4:
  151999. method_ptr = jpeg_idct_4x4;
  152000. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152001. break;
  152002. #endif
  152003. case DCTSIZE:
  152004. switch (cinfo->dct_method) {
  152005. #ifdef DCT_ISLOW_SUPPORTED
  152006. case JDCT_ISLOW:
  152007. method_ptr = jpeg_idct_islow;
  152008. method = JDCT_ISLOW;
  152009. break;
  152010. #endif
  152011. #ifdef DCT_IFAST_SUPPORTED
  152012. case JDCT_IFAST:
  152013. method_ptr = jpeg_idct_ifast;
  152014. method = JDCT_IFAST;
  152015. break;
  152016. #endif
  152017. #ifdef DCT_FLOAT_SUPPORTED
  152018. case JDCT_FLOAT:
  152019. method_ptr = jpeg_idct_float;
  152020. method = JDCT_FLOAT;
  152021. break;
  152022. #endif
  152023. default:
  152024. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152025. break;
  152026. }
  152027. break;
  152028. default:
  152029. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  152030. break;
  152031. }
  152032. idct->pub.inverse_DCT[ci] = method_ptr;
  152033. if (! compptr->component_needed || idct->cur_method[ci] == method)
  152034. continue;
  152035. qtbl = compptr->quant_table;
  152036. if (qtbl == NULL) /* happens if no data yet for component */
  152037. continue;
  152038. idct->cur_method[ci] = method;
  152039. switch (method) {
  152040. #ifdef PROVIDE_ISLOW_TABLES
  152041. case JDCT_ISLOW:
  152042. {
  152043. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  152044. for (i = 0; i < DCTSIZE2; i++) {
  152045. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  152046. }
  152047. }
  152048. break;
  152049. #endif
  152050. #ifdef DCT_IFAST_SUPPORTED
  152051. case JDCT_IFAST:
  152052. {
  152053. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  152054. #define CONST_BITS 14
  152055. static const INT16 aanscales[DCTSIZE2] = {
  152056. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152057. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  152058. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  152059. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  152060. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152061. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  152062. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  152063. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  152064. };
  152065. SHIFT_TEMPS
  152066. for (i = 0; i < DCTSIZE2; i++) {
  152067. ifmtbl[i] = (IFAST_MULT_TYPE)
  152068. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  152069. (INT32) aanscales[i]),
  152070. CONST_BITS-IFAST_SCALE_BITS);
  152071. }
  152072. }
  152073. break;
  152074. #endif
  152075. #ifdef DCT_FLOAT_SUPPORTED
  152076. case JDCT_FLOAT:
  152077. {
  152078. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  152079. int row, col;
  152080. static const double aanscalefactor[DCTSIZE] = {
  152081. 1.0, 1.387039845, 1.306562965, 1.175875602,
  152082. 1.0, 0.785694958, 0.541196100, 0.275899379
  152083. };
  152084. i = 0;
  152085. for (row = 0; row < DCTSIZE; row++) {
  152086. for (col = 0; col < DCTSIZE; col++) {
  152087. fmtbl[i] = (FLOAT_MULT_TYPE)
  152088. ((double) qtbl->quantval[i] *
  152089. aanscalefactor[row] * aanscalefactor[col]);
  152090. i++;
  152091. }
  152092. }
  152093. }
  152094. break;
  152095. #endif
  152096. default:
  152097. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152098. break;
  152099. }
  152100. }
  152101. }
  152102. GLOBAL(void)
  152103. jinit_inverse_dct (j_decompress_ptr cinfo)
  152104. {
  152105. my_idct_ptr idct;
  152106. int ci;
  152107. jpeg_component_info *compptr;
  152108. idct = (my_idct_ptr)
  152109. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152110. SIZEOF(my_idct_controller));
  152111. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  152112. idct->pub.start_pass = start_pass;
  152113. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152114. ci++, compptr++) {
  152115. compptr->dct_table =
  152116. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152117. SIZEOF(multiplier_table));
  152118. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  152119. idct->cur_method[ci] = -1;
  152120. }
  152121. }
  152122. /*** End of inlined file: jddctmgr.c ***/
  152123. #undef CONST_BITS
  152124. #undef ASSIGN_STATE
  152125. /*** Start of inlined file: jdhuff.c ***/
  152126. #define JPEG_INTERNALS
  152127. /*** Start of inlined file: jdhuff.h ***/
  152128. #ifndef __jdhuff_h__
  152129. #define __jdhuff_h__
  152130. #ifdef NEED_SHORT_EXTERNAL_NAMES
  152131. #define jpeg_make_d_derived_tbl jMkDDerived
  152132. #define jpeg_fill_bit_buffer jFilBitBuf
  152133. #define jpeg_huff_decode jHufDecode
  152134. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  152135. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  152136. typedef struct {
  152137. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  152138. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  152139. JHUFF_TBL *pub;
  152140. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  152141. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  152142. } d_derived_tbl;
  152143. EXTERN(void) jpeg_make_d_derived_tbl
  152144. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  152145. d_derived_tbl ** pdtbl));
  152146. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  152147. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  152148. typedef struct { /* Bitreading state saved across MCUs */
  152149. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152150. int bits_left; /* # of unused bits in it */
  152151. } bitread_perm_state;
  152152. typedef struct { /* Bitreading working state within an MCU */
  152153. const JOCTET * next_input_byte; /* => next byte to read from source */
  152154. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  152155. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152156. int bits_left; /* # of unused bits in it */
  152157. j_decompress_ptr cinfo; /* back link to decompress master record */
  152158. } bitread_working_state;
  152159. #define BITREAD_STATE_VARS \
  152160. register bit_buf_type get_buffer; \
  152161. register int bits_left; \
  152162. bitread_working_state br_state
  152163. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  152164. br_state.cinfo = cinfop; \
  152165. br_state.next_input_byte = cinfop->src->next_input_byte; \
  152166. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  152167. get_buffer = permstate.get_buffer; \
  152168. bits_left = permstate.bits_left;
  152169. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  152170. cinfop->src->next_input_byte = br_state.next_input_byte; \
  152171. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  152172. permstate.get_buffer = get_buffer; \
  152173. permstate.bits_left = bits_left
  152174. #define CHECK_BIT_BUFFER(state,nbits,action) \
  152175. { if (bits_left < (nbits)) { \
  152176. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  152177. { action; } \
  152178. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  152179. #define GET_BITS(nbits) \
  152180. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  152181. #define PEEK_BITS(nbits) \
  152182. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  152183. #define DROP_BITS(nbits) \
  152184. (bits_left -= (nbits))
  152185. EXTERN(boolean) jpeg_fill_bit_buffer
  152186. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152187. register int bits_left, int nbits));
  152188. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  152189. { register int nb, look; \
  152190. if (bits_left < HUFF_LOOKAHEAD) { \
  152191. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  152192. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152193. if (bits_left < HUFF_LOOKAHEAD) { \
  152194. nb = 1; goto slowlabel; \
  152195. } \
  152196. } \
  152197. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  152198. if ((nb = htbl->look_nbits[look]) != 0) { \
  152199. DROP_BITS(nb); \
  152200. result = htbl->look_sym[look]; \
  152201. } else { \
  152202. nb = HUFF_LOOKAHEAD+1; \
  152203. slowlabel: \
  152204. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  152205. { failaction; } \
  152206. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152207. } \
  152208. }
  152209. EXTERN(int) jpeg_huff_decode
  152210. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152211. register int bits_left, d_derived_tbl * htbl, int min_bits));
  152212. #endif
  152213. /*** End of inlined file: jdhuff.h ***/
  152214. /* Declarations shared with jdphuff.c */
  152215. typedef struct {
  152216. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  152217. } savable_state2;
  152218. #ifndef NO_STRUCT_ASSIGN
  152219. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  152220. #else
  152221. #if MAX_COMPS_IN_SCAN == 4
  152222. #define ASSIGN_STATE(dest,src) \
  152223. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  152224. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  152225. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  152226. (dest).last_dc_val[3] = (src).last_dc_val[3])
  152227. #endif
  152228. #endif
  152229. typedef struct {
  152230. struct jpeg_entropy_decoder pub; /* public fields */
  152231. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  152232. savable_state2 saved; /* Other state at start of MCU */
  152233. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  152234. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  152235. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  152236. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152237. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152238. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  152239. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  152240. } huff_entropy_decoder2;
  152241. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  152242. METHODDEF(void)
  152243. start_pass_huff_decoder (j_decompress_ptr cinfo)
  152244. {
  152245. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152246. int ci, blkn, dctbl, actbl;
  152247. jpeg_component_info * compptr;
  152248. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  152249. cinfo->Ah != 0 || cinfo->Al != 0)
  152250. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  152251. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152252. compptr = cinfo->cur_comp_info[ci];
  152253. dctbl = compptr->dc_tbl_no;
  152254. actbl = compptr->ac_tbl_no;
  152255. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  152256. & entropy->dc_derived_tbls[dctbl]);
  152257. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  152258. & entropy->ac_derived_tbls[actbl]);
  152259. entropy->saved.last_dc_val[ci] = 0;
  152260. }
  152261. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152262. ci = cinfo->MCU_membership[blkn];
  152263. compptr = cinfo->cur_comp_info[ci];
  152264. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  152265. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  152266. if (compptr->component_needed) {
  152267. entropy->dc_needed[blkn] = TRUE;
  152268. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  152269. } else {
  152270. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  152271. }
  152272. }
  152273. entropy->bitstate.bits_left = 0;
  152274. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  152275. entropy->pub.insufficient_data = FALSE;
  152276. entropy->restarts_to_go = cinfo->restart_interval;
  152277. }
  152278. GLOBAL(void)
  152279. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  152280. d_derived_tbl ** pdtbl)
  152281. {
  152282. JHUFF_TBL *htbl;
  152283. d_derived_tbl *dtbl;
  152284. int p, i, l, si, numsymbols;
  152285. int lookbits, ctr;
  152286. char huffsize[257];
  152287. unsigned int huffcode[257];
  152288. unsigned int code;
  152289. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  152290. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152291. htbl =
  152292. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  152293. if (htbl == NULL)
  152294. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152295. if (*pdtbl == NULL)
  152296. *pdtbl = (d_derived_tbl *)
  152297. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152298. SIZEOF(d_derived_tbl));
  152299. dtbl = *pdtbl;
  152300. dtbl->pub = htbl; /* fill in back link */
  152301. p = 0;
  152302. for (l = 1; l <= 16; l++) {
  152303. i = (int) htbl->bits[l];
  152304. if (i < 0 || p + i > 256) /* protect against table overrun */
  152305. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152306. while (i--)
  152307. huffsize[p++] = (char) l;
  152308. }
  152309. huffsize[p] = 0;
  152310. numsymbols = p;
  152311. code = 0;
  152312. si = huffsize[0];
  152313. p = 0;
  152314. while (huffsize[p]) {
  152315. while (((int) huffsize[p]) == si) {
  152316. huffcode[p++] = code;
  152317. code++;
  152318. }
  152319. if (((INT32) code) >= (((INT32) 1) << si))
  152320. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152321. code <<= 1;
  152322. si++;
  152323. }
  152324. p = 0;
  152325. for (l = 1; l <= 16; l++) {
  152326. if (htbl->bits[l]) {
  152327. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152328. p += htbl->bits[l];
  152329. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152330. } else {
  152331. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152332. }
  152333. }
  152334. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152335. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152336. p = 0;
  152337. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152338. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152339. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152340. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152341. dtbl->look_nbits[lookbits] = l;
  152342. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152343. lookbits++;
  152344. }
  152345. }
  152346. }
  152347. if (isDC) {
  152348. for (i = 0; i < numsymbols; i++) {
  152349. int sym = htbl->huffval[i];
  152350. if (sym < 0 || sym > 15)
  152351. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152352. }
  152353. }
  152354. }
  152355. #ifdef SLOW_SHIFT_32
  152356. #define MIN_GET_BITS 15 /* minimum allowable value */
  152357. #else
  152358. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152359. #endif
  152360. GLOBAL(boolean)
  152361. jpeg_fill_bit_buffer (bitread_working_state * state,
  152362. register bit_buf_type get_buffer, register int bits_left,
  152363. int nbits)
  152364. {
  152365. register const JOCTET * next_input_byte = state->next_input_byte;
  152366. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152367. j_decompress_ptr cinfo = state->cinfo;
  152368. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152369. while (bits_left < MIN_GET_BITS) {
  152370. register int c;
  152371. if (bytes_in_buffer == 0) {
  152372. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152373. return FALSE;
  152374. next_input_byte = cinfo->src->next_input_byte;
  152375. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152376. }
  152377. bytes_in_buffer--;
  152378. c = GETJOCTET(*next_input_byte++);
  152379. if (c == 0xFF) {
  152380. do {
  152381. if (bytes_in_buffer == 0) {
  152382. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152383. return FALSE;
  152384. next_input_byte = cinfo->src->next_input_byte;
  152385. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152386. }
  152387. bytes_in_buffer--;
  152388. c = GETJOCTET(*next_input_byte++);
  152389. } while (c == 0xFF);
  152390. if (c == 0) {
  152391. c = 0xFF;
  152392. } else {
  152393. cinfo->unread_marker = c;
  152394. goto no_more_bytes;
  152395. }
  152396. }
  152397. get_buffer = (get_buffer << 8) | c;
  152398. bits_left += 8;
  152399. } /* end while */
  152400. } else {
  152401. no_more_bytes:
  152402. if (nbits > bits_left) {
  152403. if (! cinfo->entropy->insufficient_data) {
  152404. WARNMS(cinfo, JWRN_HIT_MARKER);
  152405. cinfo->entropy->insufficient_data = TRUE;
  152406. }
  152407. get_buffer <<= MIN_GET_BITS - bits_left;
  152408. bits_left = MIN_GET_BITS;
  152409. }
  152410. }
  152411. state->next_input_byte = next_input_byte;
  152412. state->bytes_in_buffer = bytes_in_buffer;
  152413. state->get_buffer = get_buffer;
  152414. state->bits_left = bits_left;
  152415. return TRUE;
  152416. }
  152417. GLOBAL(int)
  152418. jpeg_huff_decode (bitread_working_state * state,
  152419. register bit_buf_type get_buffer, register int bits_left,
  152420. d_derived_tbl * htbl, int min_bits)
  152421. {
  152422. register int l = min_bits;
  152423. register INT32 code;
  152424. CHECK_BIT_BUFFER(*state, l, return -1);
  152425. code = GET_BITS(l);
  152426. while (code > htbl->maxcode[l]) {
  152427. code <<= 1;
  152428. CHECK_BIT_BUFFER(*state, 1, return -1);
  152429. code |= GET_BITS(1);
  152430. l++;
  152431. }
  152432. state->get_buffer = get_buffer;
  152433. state->bits_left = bits_left;
  152434. if (l > 16) {
  152435. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152436. return 0; /* fake a zero as the safest result */
  152437. }
  152438. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152439. }
  152440. LOCAL(boolean)
  152441. process_restart (j_decompress_ptr cinfo)
  152442. {
  152443. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152444. int ci;
  152445. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152446. entropy->bitstate.bits_left = 0;
  152447. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152448. return FALSE;
  152449. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152450. entropy->saved.last_dc_val[ci] = 0;
  152451. entropy->restarts_to_go = cinfo->restart_interval;
  152452. if (cinfo->unread_marker == 0)
  152453. entropy->pub.insufficient_data = FALSE;
  152454. return TRUE;
  152455. }
  152456. METHODDEF(boolean)
  152457. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152458. {
  152459. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152460. int blkn;
  152461. BITREAD_STATE_VARS;
  152462. savable_state2 state;
  152463. if (cinfo->restart_interval) {
  152464. if (entropy->restarts_to_go == 0)
  152465. if (! process_restart(cinfo))
  152466. return FALSE;
  152467. }
  152468. if (! entropy->pub.insufficient_data) {
  152469. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152470. ASSIGN_STATE(state, entropy->saved);
  152471. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152472. JBLOCKROW block = MCU_data[blkn];
  152473. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152474. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152475. register int s, k, r;
  152476. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152477. if (s) {
  152478. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152479. r = GET_BITS(s);
  152480. s = HUFF_EXTEND(r, s);
  152481. }
  152482. if (entropy->dc_needed[blkn]) {
  152483. int ci = cinfo->MCU_membership[blkn];
  152484. s += state.last_dc_val[ci];
  152485. state.last_dc_val[ci] = s;
  152486. (*block)[0] = (JCOEF) s;
  152487. }
  152488. if (entropy->ac_needed[blkn]) {
  152489. for (k = 1; k < DCTSIZE2; k++) {
  152490. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152491. r = s >> 4;
  152492. s &= 15;
  152493. if (s) {
  152494. k += r;
  152495. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152496. r = GET_BITS(s);
  152497. s = HUFF_EXTEND(r, s);
  152498. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152499. } else {
  152500. if (r != 15)
  152501. break;
  152502. k += 15;
  152503. }
  152504. }
  152505. } else {
  152506. for (k = 1; k < DCTSIZE2; k++) {
  152507. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152508. r = s >> 4;
  152509. s &= 15;
  152510. if (s) {
  152511. k += r;
  152512. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152513. DROP_BITS(s);
  152514. } else {
  152515. if (r != 15)
  152516. break;
  152517. k += 15;
  152518. }
  152519. }
  152520. }
  152521. }
  152522. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152523. ASSIGN_STATE(entropy->saved, state);
  152524. }
  152525. entropy->restarts_to_go--;
  152526. return TRUE;
  152527. }
  152528. GLOBAL(void)
  152529. jinit_huff_decoder (j_decompress_ptr cinfo)
  152530. {
  152531. huff_entropy_ptr2 entropy;
  152532. int i;
  152533. entropy = (huff_entropy_ptr2)
  152534. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152535. SIZEOF(huff_entropy_decoder2));
  152536. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152537. entropy->pub.start_pass = start_pass_huff_decoder;
  152538. entropy->pub.decode_mcu = decode_mcu;
  152539. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152540. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152541. }
  152542. }
  152543. /*** End of inlined file: jdhuff.c ***/
  152544. /*** Start of inlined file: jdinput.c ***/
  152545. #define JPEG_INTERNALS
  152546. typedef struct {
  152547. struct jpeg_input_controller pub; /* public fields */
  152548. boolean inheaders; /* TRUE until first SOS is reached */
  152549. } my_input_controller;
  152550. typedef my_input_controller * my_inputctl_ptr;
  152551. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152552. LOCAL(void)
  152553. initial_setup2 (j_decompress_ptr cinfo)
  152554. {
  152555. int ci;
  152556. jpeg_component_info *compptr;
  152557. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152558. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152559. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152560. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152561. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152562. if (cinfo->num_components > MAX_COMPONENTS)
  152563. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152564. MAX_COMPONENTS);
  152565. cinfo->max_h_samp_factor = 1;
  152566. cinfo->max_v_samp_factor = 1;
  152567. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152568. ci++, compptr++) {
  152569. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152570. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152571. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152572. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152573. compptr->h_samp_factor);
  152574. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152575. compptr->v_samp_factor);
  152576. }
  152577. cinfo->min_DCT_scaled_size = DCTSIZE;
  152578. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152579. ci++, compptr++) {
  152580. compptr->DCT_scaled_size = DCTSIZE;
  152581. compptr->width_in_blocks = (JDIMENSION)
  152582. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152583. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152584. compptr->height_in_blocks = (JDIMENSION)
  152585. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152586. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152587. compptr->downsampled_width = (JDIMENSION)
  152588. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152589. (long) cinfo->max_h_samp_factor);
  152590. compptr->downsampled_height = (JDIMENSION)
  152591. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152592. (long) cinfo->max_v_samp_factor);
  152593. compptr->component_needed = TRUE;
  152594. compptr->quant_table = NULL;
  152595. }
  152596. cinfo->total_iMCU_rows = (JDIMENSION)
  152597. jdiv_round_up((long) cinfo->image_height,
  152598. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152599. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152600. cinfo->inputctl->has_multiple_scans = TRUE;
  152601. else
  152602. cinfo->inputctl->has_multiple_scans = FALSE;
  152603. }
  152604. LOCAL(void)
  152605. per_scan_setup2 (j_decompress_ptr cinfo)
  152606. {
  152607. int ci, mcublks, tmp;
  152608. jpeg_component_info *compptr;
  152609. if (cinfo->comps_in_scan == 1) {
  152610. compptr = cinfo->cur_comp_info[0];
  152611. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152612. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152613. compptr->MCU_width = 1;
  152614. compptr->MCU_height = 1;
  152615. compptr->MCU_blocks = 1;
  152616. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152617. compptr->last_col_width = 1;
  152618. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152619. if (tmp == 0) tmp = compptr->v_samp_factor;
  152620. compptr->last_row_height = tmp;
  152621. cinfo->blocks_in_MCU = 1;
  152622. cinfo->MCU_membership[0] = 0;
  152623. } else {
  152624. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152625. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152626. MAX_COMPS_IN_SCAN);
  152627. cinfo->MCUs_per_row = (JDIMENSION)
  152628. jdiv_round_up((long) cinfo->image_width,
  152629. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152630. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152631. jdiv_round_up((long) cinfo->image_height,
  152632. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152633. cinfo->blocks_in_MCU = 0;
  152634. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152635. compptr = cinfo->cur_comp_info[ci];
  152636. compptr->MCU_width = compptr->h_samp_factor;
  152637. compptr->MCU_height = compptr->v_samp_factor;
  152638. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152639. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152640. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152641. if (tmp == 0) tmp = compptr->MCU_width;
  152642. compptr->last_col_width = tmp;
  152643. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152644. if (tmp == 0) tmp = compptr->MCU_height;
  152645. compptr->last_row_height = tmp;
  152646. mcublks = compptr->MCU_blocks;
  152647. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152648. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152649. while (mcublks-- > 0) {
  152650. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152651. }
  152652. }
  152653. }
  152654. }
  152655. LOCAL(void)
  152656. latch_quant_tables (j_decompress_ptr cinfo)
  152657. {
  152658. int ci, qtblno;
  152659. jpeg_component_info *compptr;
  152660. JQUANT_TBL * qtbl;
  152661. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152662. compptr = cinfo->cur_comp_info[ci];
  152663. if (compptr->quant_table != NULL)
  152664. continue;
  152665. qtblno = compptr->quant_tbl_no;
  152666. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152667. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152668. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152669. qtbl = (JQUANT_TBL *)
  152670. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152671. SIZEOF(JQUANT_TBL));
  152672. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152673. compptr->quant_table = qtbl;
  152674. }
  152675. }
  152676. METHODDEF(void)
  152677. start_input_pass2 (j_decompress_ptr cinfo)
  152678. {
  152679. per_scan_setup2(cinfo);
  152680. latch_quant_tables(cinfo);
  152681. (*cinfo->entropy->start_pass) (cinfo);
  152682. (*cinfo->coef->start_input_pass) (cinfo);
  152683. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152684. }
  152685. METHODDEF(void)
  152686. finish_input_pass (j_decompress_ptr cinfo)
  152687. {
  152688. cinfo->inputctl->consume_input = consume_markers;
  152689. }
  152690. METHODDEF(int)
  152691. consume_markers (j_decompress_ptr cinfo)
  152692. {
  152693. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152694. int val;
  152695. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152696. return JPEG_REACHED_EOI;
  152697. val = (*cinfo->marker->read_markers) (cinfo);
  152698. switch (val) {
  152699. case JPEG_REACHED_SOS: /* Found SOS */
  152700. if (inputctl->inheaders) { /* 1st SOS */
  152701. initial_setup2(cinfo);
  152702. inputctl->inheaders = FALSE;
  152703. } else { /* 2nd or later SOS marker */
  152704. if (! inputctl->pub.has_multiple_scans)
  152705. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152706. start_input_pass2(cinfo);
  152707. }
  152708. break;
  152709. case JPEG_REACHED_EOI: /* Found EOI */
  152710. inputctl->pub.eoi_reached = TRUE;
  152711. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152712. if (cinfo->marker->saw_SOF)
  152713. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152714. } else {
  152715. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152716. cinfo->output_scan_number = cinfo->input_scan_number;
  152717. }
  152718. break;
  152719. case JPEG_SUSPENDED:
  152720. break;
  152721. }
  152722. return val;
  152723. }
  152724. METHODDEF(void)
  152725. reset_input_controller (j_decompress_ptr cinfo)
  152726. {
  152727. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152728. inputctl->pub.consume_input = consume_markers;
  152729. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152730. inputctl->pub.eoi_reached = FALSE;
  152731. inputctl->inheaders = TRUE;
  152732. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152733. (*cinfo->marker->reset_marker_reader) (cinfo);
  152734. cinfo->coef_bits = NULL;
  152735. }
  152736. GLOBAL(void)
  152737. jinit_input_controller (j_decompress_ptr cinfo)
  152738. {
  152739. my_inputctl_ptr inputctl;
  152740. inputctl = (my_inputctl_ptr)
  152741. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152742. SIZEOF(my_input_controller));
  152743. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152744. inputctl->pub.consume_input = consume_markers;
  152745. inputctl->pub.reset_input_controller = reset_input_controller;
  152746. inputctl->pub.start_input_pass = start_input_pass2;
  152747. inputctl->pub.finish_input_pass = finish_input_pass;
  152748. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152749. inputctl->pub.eoi_reached = FALSE;
  152750. inputctl->inheaders = TRUE;
  152751. }
  152752. /*** End of inlined file: jdinput.c ***/
  152753. /*** Start of inlined file: jdmainct.c ***/
  152754. #define JPEG_INTERNALS
  152755. typedef struct {
  152756. struct jpeg_d_main_controller pub; /* public fields */
  152757. JSAMPARRAY buffer[MAX_COMPONENTS];
  152758. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152759. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152760. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152761. int whichptr; /* indicates which pointer set is now in use */
  152762. int context_state; /* process_data state machine status */
  152763. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152764. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152765. } my_main_controller4;
  152766. typedef my_main_controller4 * my_main_ptr4;
  152767. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152768. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152769. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152770. METHODDEF(void) process_data_simple_main2
  152771. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152772. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152773. METHODDEF(void) process_data_context_main
  152774. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152775. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152776. #ifdef QUANT_2PASS_SUPPORTED
  152777. METHODDEF(void) process_data_crank_post
  152778. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152779. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152780. #endif
  152781. LOCAL(void)
  152782. alloc_funny_pointers (j_decompress_ptr cinfo)
  152783. {
  152784. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152785. int ci, rgroup;
  152786. int M = cinfo->min_DCT_scaled_size;
  152787. jpeg_component_info *compptr;
  152788. JSAMPARRAY xbuf;
  152789. main_->xbuffer[0] = (JSAMPIMAGE)
  152790. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152791. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152792. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152793. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152794. ci++, compptr++) {
  152795. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152796. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152797. xbuf = (JSAMPARRAY)
  152798. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152799. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152800. xbuf += rgroup; /* want one row group at negative offsets */
  152801. main_->xbuffer[0][ci] = xbuf;
  152802. xbuf += rgroup * (M + 4);
  152803. main_->xbuffer[1][ci] = xbuf;
  152804. }
  152805. }
  152806. LOCAL(void)
  152807. make_funny_pointers (j_decompress_ptr cinfo)
  152808. {
  152809. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152810. int ci, i, rgroup;
  152811. int M = cinfo->min_DCT_scaled_size;
  152812. jpeg_component_info *compptr;
  152813. JSAMPARRAY buf, xbuf0, xbuf1;
  152814. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152815. ci++, compptr++) {
  152816. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152817. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152818. xbuf0 = main_->xbuffer[0][ci];
  152819. xbuf1 = main_->xbuffer[1][ci];
  152820. buf = main_->buffer[ci];
  152821. for (i = 0; i < rgroup * (M + 2); i++) {
  152822. xbuf0[i] = xbuf1[i] = buf[i];
  152823. }
  152824. for (i = 0; i < rgroup * 2; i++) {
  152825. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152826. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152827. }
  152828. for (i = 0; i < rgroup; i++) {
  152829. xbuf0[i - rgroup] = xbuf0[0];
  152830. }
  152831. }
  152832. }
  152833. LOCAL(void)
  152834. set_wraparound_pointers (j_decompress_ptr cinfo)
  152835. {
  152836. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152837. int ci, i, rgroup;
  152838. int M = cinfo->min_DCT_scaled_size;
  152839. jpeg_component_info *compptr;
  152840. JSAMPARRAY xbuf0, xbuf1;
  152841. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152842. ci++, compptr++) {
  152843. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152844. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152845. xbuf0 = main_->xbuffer[0][ci];
  152846. xbuf1 = main_->xbuffer[1][ci];
  152847. for (i = 0; i < rgroup; i++) {
  152848. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152849. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152850. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152851. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152852. }
  152853. }
  152854. }
  152855. LOCAL(void)
  152856. set_bottom_pointers (j_decompress_ptr cinfo)
  152857. {
  152858. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152859. int ci, i, rgroup, iMCUheight, rows_left;
  152860. jpeg_component_info *compptr;
  152861. JSAMPARRAY xbuf;
  152862. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152863. ci++, compptr++) {
  152864. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152865. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152866. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152867. if (rows_left == 0) rows_left = iMCUheight;
  152868. if (ci == 0) {
  152869. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152870. }
  152871. xbuf = main_->xbuffer[main_->whichptr][ci];
  152872. for (i = 0; i < rgroup * 2; i++) {
  152873. xbuf[rows_left + i] = xbuf[rows_left-1];
  152874. }
  152875. }
  152876. }
  152877. METHODDEF(void)
  152878. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152879. {
  152880. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152881. switch (pass_mode) {
  152882. case JBUF_PASS_THRU:
  152883. if (cinfo->upsample->need_context_rows) {
  152884. main_->pub.process_data = process_data_context_main;
  152885. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152886. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152887. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152888. main_->iMCU_row_ctr = 0;
  152889. } else {
  152890. main_->pub.process_data = process_data_simple_main2;
  152891. }
  152892. main_->buffer_full = FALSE; /* Mark buffer empty */
  152893. main_->rowgroup_ctr = 0;
  152894. break;
  152895. #ifdef QUANT_2PASS_SUPPORTED
  152896. case JBUF_CRANK_DEST:
  152897. main_->pub.process_data = process_data_crank_post;
  152898. break;
  152899. #endif
  152900. default:
  152901. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152902. break;
  152903. }
  152904. }
  152905. METHODDEF(void)
  152906. process_data_simple_main2 (j_decompress_ptr cinfo,
  152907. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152908. JDIMENSION out_rows_avail)
  152909. {
  152910. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152911. JDIMENSION rowgroups_avail;
  152912. if (! main_->buffer_full) {
  152913. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152914. return; /* suspension forced, can do nothing more */
  152915. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152916. }
  152917. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152918. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152919. &main_->rowgroup_ctr, rowgroups_avail,
  152920. output_buf, out_row_ctr, out_rows_avail);
  152921. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152922. main_->buffer_full = FALSE;
  152923. main_->rowgroup_ctr = 0;
  152924. }
  152925. }
  152926. METHODDEF(void)
  152927. process_data_context_main (j_decompress_ptr cinfo,
  152928. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152929. JDIMENSION out_rows_avail)
  152930. {
  152931. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152932. if (! main_->buffer_full) {
  152933. if (! (*cinfo->coef->decompress_data) (cinfo,
  152934. main_->xbuffer[main_->whichptr]))
  152935. return; /* suspension forced, can do nothing more */
  152936. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152937. main_->iMCU_row_ctr++; /* count rows received */
  152938. }
  152939. switch (main_->context_state) {
  152940. case CTX_POSTPONED_ROW:
  152941. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152942. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152943. output_buf, out_row_ctr, out_rows_avail);
  152944. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152945. return; /* Need to suspend */
  152946. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152947. if (*out_row_ctr >= out_rows_avail)
  152948. return; /* Postprocessor exactly filled output buf */
  152949. case CTX_PREPARE_FOR_IMCU:
  152950. main_->rowgroup_ctr = 0;
  152951. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152952. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152953. set_bottom_pointers(cinfo);
  152954. main_->context_state = CTX_PROCESS_IMCU;
  152955. case CTX_PROCESS_IMCU:
  152956. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152957. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152958. output_buf, out_row_ctr, out_rows_avail);
  152959. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152960. return; /* Need to suspend */
  152961. if (main_->iMCU_row_ctr == 1)
  152962. set_wraparound_pointers(cinfo);
  152963. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152964. main_->buffer_full = FALSE;
  152965. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152966. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152967. main_->context_state = CTX_POSTPONED_ROW;
  152968. }
  152969. }
  152970. #ifdef QUANT_2PASS_SUPPORTED
  152971. METHODDEF(void)
  152972. process_data_crank_post (j_decompress_ptr cinfo,
  152973. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152974. JDIMENSION out_rows_avail)
  152975. {
  152976. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152977. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152978. output_buf, out_row_ctr, out_rows_avail);
  152979. }
  152980. #endif /* QUANT_2PASS_SUPPORTED */
  152981. GLOBAL(void)
  152982. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152983. {
  152984. my_main_ptr4 main_;
  152985. int ci, rgroup, ngroups;
  152986. jpeg_component_info *compptr;
  152987. main_ = (my_main_ptr4)
  152988. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152989. SIZEOF(my_main_controller4));
  152990. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152991. main_->pub.start_pass = start_pass_main2;
  152992. if (need_full_buffer) /* shouldn't happen */
  152993. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152994. if (cinfo->upsample->need_context_rows) {
  152995. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152996. ERREXIT(cinfo, JERR_NOTIMPL);
  152997. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152998. ngroups = cinfo->min_DCT_scaled_size + 2;
  152999. } else {
  153000. ngroups = cinfo->min_DCT_scaled_size;
  153001. }
  153002. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153003. ci++, compptr++) {
  153004. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153005. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153006. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  153007. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153008. compptr->width_in_blocks * compptr->DCT_scaled_size,
  153009. (JDIMENSION) (rgroup * ngroups));
  153010. }
  153011. }
  153012. /*** End of inlined file: jdmainct.c ***/
  153013. /*** Start of inlined file: jdmarker.c ***/
  153014. #define JPEG_INTERNALS
  153015. typedef struct {
  153016. struct jpeg_marker_reader pub; /* public fields */
  153017. jpeg_marker_parser_method process_COM;
  153018. jpeg_marker_parser_method process_APPn[16];
  153019. unsigned int length_limit_COM;
  153020. unsigned int length_limit_APPn[16];
  153021. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  153022. unsigned int bytes_read; /* data bytes read so far in marker */
  153023. } my_marker_reader;
  153024. typedef my_marker_reader * my_marker_ptr2;
  153025. #define INPUT_VARS(cinfo) \
  153026. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  153027. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  153028. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  153029. #define INPUT_SYNC(cinfo) \
  153030. ( datasrc->next_input_byte = next_input_byte, \
  153031. datasrc->bytes_in_buffer = bytes_in_buffer )
  153032. #define INPUT_RELOAD(cinfo) \
  153033. ( next_input_byte = datasrc->next_input_byte, \
  153034. bytes_in_buffer = datasrc->bytes_in_buffer )
  153035. #define MAKE_BYTE_AVAIL(cinfo,action) \
  153036. if (bytes_in_buffer == 0) { \
  153037. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  153038. { action; } \
  153039. INPUT_RELOAD(cinfo); \
  153040. }
  153041. #define INPUT_BYTE(cinfo,V,action) \
  153042. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153043. bytes_in_buffer--; \
  153044. V = GETJOCTET(*next_input_byte++); )
  153045. #define INPUT_2BYTES(cinfo,V,action) \
  153046. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153047. bytes_in_buffer--; \
  153048. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  153049. MAKE_BYTE_AVAIL(cinfo,action); \
  153050. bytes_in_buffer--; \
  153051. V += GETJOCTET(*next_input_byte++); )
  153052. LOCAL(boolean)
  153053. get_soi (j_decompress_ptr cinfo)
  153054. {
  153055. int i;
  153056. TRACEMS(cinfo, 1, JTRC_SOI);
  153057. if (cinfo->marker->saw_SOI)
  153058. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  153059. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  153060. cinfo->arith_dc_L[i] = 0;
  153061. cinfo->arith_dc_U[i] = 1;
  153062. cinfo->arith_ac_K[i] = 5;
  153063. }
  153064. cinfo->restart_interval = 0;
  153065. cinfo->jpeg_color_space = JCS_UNKNOWN;
  153066. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  153067. cinfo->saw_JFIF_marker = FALSE;
  153068. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  153069. cinfo->JFIF_minor_version = 1;
  153070. cinfo->density_unit = 0;
  153071. cinfo->X_density = 1;
  153072. cinfo->Y_density = 1;
  153073. cinfo->saw_Adobe_marker = FALSE;
  153074. cinfo->Adobe_transform = 0;
  153075. cinfo->marker->saw_SOI = TRUE;
  153076. return TRUE;
  153077. }
  153078. LOCAL(boolean)
  153079. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  153080. {
  153081. INT32 length;
  153082. int c, ci;
  153083. jpeg_component_info * compptr;
  153084. INPUT_VARS(cinfo);
  153085. cinfo->progressive_mode = is_prog;
  153086. cinfo->arith_code = is_arith;
  153087. INPUT_2BYTES(cinfo, length, return FALSE);
  153088. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  153089. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  153090. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  153091. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  153092. length -= 8;
  153093. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  153094. (int) cinfo->image_width, (int) cinfo->image_height,
  153095. cinfo->num_components);
  153096. if (cinfo->marker->saw_SOF)
  153097. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  153098. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  153099. || cinfo->num_components <= 0)
  153100. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  153101. if (length != (cinfo->num_components * 3))
  153102. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153103. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  153104. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  153105. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153106. cinfo->num_components * SIZEOF(jpeg_component_info));
  153107. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153108. ci++, compptr++) {
  153109. compptr->component_index = ci;
  153110. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  153111. INPUT_BYTE(cinfo, c, return FALSE);
  153112. compptr->h_samp_factor = (c >> 4) & 15;
  153113. compptr->v_samp_factor = (c ) & 15;
  153114. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  153115. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  153116. compptr->component_id, compptr->h_samp_factor,
  153117. compptr->v_samp_factor, compptr->quant_tbl_no);
  153118. }
  153119. cinfo->marker->saw_SOF = TRUE;
  153120. INPUT_SYNC(cinfo);
  153121. return TRUE;
  153122. }
  153123. LOCAL(boolean)
  153124. get_sos (j_decompress_ptr cinfo)
  153125. {
  153126. INT32 length;
  153127. int i, ci, n, c, cc;
  153128. jpeg_component_info * compptr;
  153129. INPUT_VARS(cinfo);
  153130. if (! cinfo->marker->saw_SOF)
  153131. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  153132. INPUT_2BYTES(cinfo, length, return FALSE);
  153133. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  153134. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  153135. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  153136. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153137. cinfo->comps_in_scan = n;
  153138. for (i = 0; i < n; i++) {
  153139. INPUT_BYTE(cinfo, cc, return FALSE);
  153140. INPUT_BYTE(cinfo, c, return FALSE);
  153141. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153142. ci++, compptr++) {
  153143. if (cc == compptr->component_id)
  153144. goto id_found;
  153145. }
  153146. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  153147. id_found:
  153148. cinfo->cur_comp_info[i] = compptr;
  153149. compptr->dc_tbl_no = (c >> 4) & 15;
  153150. compptr->ac_tbl_no = (c ) & 15;
  153151. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  153152. compptr->dc_tbl_no, compptr->ac_tbl_no);
  153153. }
  153154. INPUT_BYTE(cinfo, c, return FALSE);
  153155. cinfo->Ss = c;
  153156. INPUT_BYTE(cinfo, c, return FALSE);
  153157. cinfo->Se = c;
  153158. INPUT_BYTE(cinfo, c, return FALSE);
  153159. cinfo->Ah = (c >> 4) & 15;
  153160. cinfo->Al = (c ) & 15;
  153161. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  153162. cinfo->Ah, cinfo->Al);
  153163. cinfo->marker->next_restart_num = 0;
  153164. cinfo->input_scan_number++;
  153165. INPUT_SYNC(cinfo);
  153166. return TRUE;
  153167. }
  153168. #ifdef D_ARITH_CODING_SUPPORTED
  153169. LOCAL(boolean)
  153170. get_dac (j_decompress_ptr cinfo)
  153171. {
  153172. INT32 length;
  153173. int index, val;
  153174. INPUT_VARS(cinfo);
  153175. INPUT_2BYTES(cinfo, length, return FALSE);
  153176. length -= 2;
  153177. while (length > 0) {
  153178. INPUT_BYTE(cinfo, index, return FALSE);
  153179. INPUT_BYTE(cinfo, val, return FALSE);
  153180. length -= 2;
  153181. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  153182. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  153183. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  153184. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  153185. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  153186. } else { /* define DC table */
  153187. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  153188. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  153189. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  153190. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  153191. }
  153192. }
  153193. if (length != 0)
  153194. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153195. INPUT_SYNC(cinfo);
  153196. return TRUE;
  153197. }
  153198. #else /* ! D_ARITH_CODING_SUPPORTED */
  153199. #define get_dac(cinfo) skip_variable(cinfo)
  153200. #endif /* D_ARITH_CODING_SUPPORTED */
  153201. LOCAL(boolean)
  153202. get_dht (j_decompress_ptr cinfo)
  153203. {
  153204. INT32 length;
  153205. UINT8 bits[17];
  153206. UINT8 huffval[256];
  153207. int i, index, count;
  153208. JHUFF_TBL **htblptr;
  153209. INPUT_VARS(cinfo);
  153210. INPUT_2BYTES(cinfo, length, return FALSE);
  153211. length -= 2;
  153212. while (length > 16) {
  153213. INPUT_BYTE(cinfo, index, return FALSE);
  153214. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  153215. bits[0] = 0;
  153216. count = 0;
  153217. for (i = 1; i <= 16; i++) {
  153218. INPUT_BYTE(cinfo, bits[i], return FALSE);
  153219. count += bits[i];
  153220. }
  153221. length -= 1 + 16;
  153222. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153223. bits[1], bits[2], bits[3], bits[4],
  153224. bits[5], bits[6], bits[7], bits[8]);
  153225. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153226. bits[9], bits[10], bits[11], bits[12],
  153227. bits[13], bits[14], bits[15], bits[16]);
  153228. if (count > 256 || ((INT32) count) > length)
  153229. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  153230. for (i = 0; i < count; i++)
  153231. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  153232. length -= count;
  153233. if (index & 0x10) { /* AC table definition */
  153234. index -= 0x10;
  153235. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  153236. } else { /* DC table definition */
  153237. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  153238. }
  153239. if (index < 0 || index >= NUM_HUFF_TBLS)
  153240. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  153241. if (*htblptr == NULL)
  153242. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  153243. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  153244. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  153245. }
  153246. if (length != 0)
  153247. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153248. INPUT_SYNC(cinfo);
  153249. return TRUE;
  153250. }
  153251. LOCAL(boolean)
  153252. get_dqt (j_decompress_ptr cinfo)
  153253. {
  153254. INT32 length;
  153255. int n, i, prec;
  153256. unsigned int tmp;
  153257. JQUANT_TBL *quant_ptr;
  153258. INPUT_VARS(cinfo);
  153259. INPUT_2BYTES(cinfo, length, return FALSE);
  153260. length -= 2;
  153261. while (length > 0) {
  153262. INPUT_BYTE(cinfo, n, return FALSE);
  153263. prec = n >> 4;
  153264. n &= 0x0F;
  153265. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  153266. if (n >= NUM_QUANT_TBLS)
  153267. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  153268. if (cinfo->quant_tbl_ptrs[n] == NULL)
  153269. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  153270. quant_ptr = cinfo->quant_tbl_ptrs[n];
  153271. for (i = 0; i < DCTSIZE2; i++) {
  153272. if (prec)
  153273. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153274. else
  153275. INPUT_BYTE(cinfo, tmp, return FALSE);
  153276. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  153277. }
  153278. if (cinfo->err->trace_level >= 2) {
  153279. for (i = 0; i < DCTSIZE2; i += 8) {
  153280. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  153281. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  153282. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  153283. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  153284. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  153285. }
  153286. }
  153287. length -= DCTSIZE2+1;
  153288. if (prec) length -= DCTSIZE2;
  153289. }
  153290. if (length != 0)
  153291. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153292. INPUT_SYNC(cinfo);
  153293. return TRUE;
  153294. }
  153295. LOCAL(boolean)
  153296. get_dri (j_decompress_ptr cinfo)
  153297. {
  153298. INT32 length;
  153299. unsigned int tmp;
  153300. INPUT_VARS(cinfo);
  153301. INPUT_2BYTES(cinfo, length, return FALSE);
  153302. if (length != 4)
  153303. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153304. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153305. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153306. cinfo->restart_interval = tmp;
  153307. INPUT_SYNC(cinfo);
  153308. return TRUE;
  153309. }
  153310. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153311. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153312. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153313. LOCAL(void)
  153314. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153315. unsigned int datalen, INT32 remaining)
  153316. {
  153317. INT32 totallen = (INT32) datalen + remaining;
  153318. if (datalen >= APP0_DATA_LEN &&
  153319. GETJOCTET(data[0]) == 0x4A &&
  153320. GETJOCTET(data[1]) == 0x46 &&
  153321. GETJOCTET(data[2]) == 0x49 &&
  153322. GETJOCTET(data[3]) == 0x46 &&
  153323. GETJOCTET(data[4]) == 0) {
  153324. cinfo->saw_JFIF_marker = TRUE;
  153325. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153326. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153327. cinfo->density_unit = GETJOCTET(data[7]);
  153328. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153329. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153330. if (cinfo->JFIF_major_version != 1)
  153331. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153332. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153333. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153334. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153335. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153336. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153337. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153338. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153339. totallen -= APP0_DATA_LEN;
  153340. if (totallen !=
  153341. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153342. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153343. } else if (datalen >= 6 &&
  153344. GETJOCTET(data[0]) == 0x4A &&
  153345. GETJOCTET(data[1]) == 0x46 &&
  153346. GETJOCTET(data[2]) == 0x58 &&
  153347. GETJOCTET(data[3]) == 0x58 &&
  153348. GETJOCTET(data[4]) == 0) {
  153349. switch (GETJOCTET(data[5])) {
  153350. case 0x10:
  153351. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153352. break;
  153353. case 0x11:
  153354. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153355. break;
  153356. case 0x13:
  153357. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153358. break;
  153359. default:
  153360. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153361. GETJOCTET(data[5]), (int) totallen);
  153362. break;
  153363. }
  153364. } else {
  153365. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153366. }
  153367. }
  153368. LOCAL(void)
  153369. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153370. unsigned int datalen, INT32 remaining)
  153371. {
  153372. unsigned int version, flags0, flags1, transform;
  153373. if (datalen >= APP14_DATA_LEN &&
  153374. GETJOCTET(data[0]) == 0x41 &&
  153375. GETJOCTET(data[1]) == 0x64 &&
  153376. GETJOCTET(data[2]) == 0x6F &&
  153377. GETJOCTET(data[3]) == 0x62 &&
  153378. GETJOCTET(data[4]) == 0x65) {
  153379. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153380. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153381. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153382. transform = GETJOCTET(data[11]);
  153383. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153384. cinfo->saw_Adobe_marker = TRUE;
  153385. cinfo->Adobe_transform = (UINT8) transform;
  153386. } else {
  153387. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153388. }
  153389. }
  153390. METHODDEF(boolean)
  153391. get_interesting_appn (j_decompress_ptr cinfo)
  153392. {
  153393. INT32 length;
  153394. JOCTET b[APPN_DATA_LEN];
  153395. unsigned int i, numtoread;
  153396. INPUT_VARS(cinfo);
  153397. INPUT_2BYTES(cinfo, length, return FALSE);
  153398. length -= 2;
  153399. if (length >= APPN_DATA_LEN)
  153400. numtoread = APPN_DATA_LEN;
  153401. else if (length > 0)
  153402. numtoread = (unsigned int) length;
  153403. else
  153404. numtoread = 0;
  153405. for (i = 0; i < numtoread; i++)
  153406. INPUT_BYTE(cinfo, b[i], return FALSE);
  153407. length -= numtoread;
  153408. switch (cinfo->unread_marker) {
  153409. case M_APP0:
  153410. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153411. break;
  153412. case M_APP14:
  153413. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153414. break;
  153415. default:
  153416. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153417. break;
  153418. }
  153419. INPUT_SYNC(cinfo);
  153420. if (length > 0)
  153421. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153422. return TRUE;
  153423. }
  153424. #ifdef SAVE_MARKERS_SUPPORTED
  153425. METHODDEF(boolean)
  153426. save_marker (j_decompress_ptr cinfo)
  153427. {
  153428. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153429. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153430. unsigned int bytes_read, data_length;
  153431. JOCTET FAR * data;
  153432. INT32 length = 0;
  153433. INPUT_VARS(cinfo);
  153434. if (cur_marker == NULL) {
  153435. INPUT_2BYTES(cinfo, length, return FALSE);
  153436. length -= 2;
  153437. if (length >= 0) { /* watch out for bogus length word */
  153438. unsigned int limit;
  153439. if (cinfo->unread_marker == (int) M_COM)
  153440. limit = marker->length_limit_COM;
  153441. else
  153442. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153443. if ((unsigned int) length < limit)
  153444. limit = (unsigned int) length;
  153445. cur_marker = (jpeg_saved_marker_ptr)
  153446. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153447. SIZEOF(struct jpeg_marker_struct) + limit);
  153448. cur_marker->next = NULL;
  153449. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153450. cur_marker->original_length = (unsigned int) length;
  153451. cur_marker->data_length = limit;
  153452. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153453. marker->cur_marker = cur_marker;
  153454. marker->bytes_read = 0;
  153455. bytes_read = 0;
  153456. data_length = limit;
  153457. } else {
  153458. bytes_read = data_length = 0;
  153459. data = NULL;
  153460. }
  153461. } else {
  153462. bytes_read = marker->bytes_read;
  153463. data_length = cur_marker->data_length;
  153464. data = cur_marker->data + bytes_read;
  153465. }
  153466. while (bytes_read < data_length) {
  153467. INPUT_SYNC(cinfo); /* move the restart point to here */
  153468. marker->bytes_read = bytes_read;
  153469. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153470. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153471. *data++ = *next_input_byte++;
  153472. bytes_in_buffer--;
  153473. bytes_read++;
  153474. }
  153475. }
  153476. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153477. if (cinfo->marker_list == NULL) {
  153478. cinfo->marker_list = cur_marker;
  153479. } else {
  153480. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153481. while (prev->next != NULL)
  153482. prev = prev->next;
  153483. prev->next = cur_marker;
  153484. }
  153485. data = cur_marker->data;
  153486. length = cur_marker->original_length - data_length;
  153487. }
  153488. marker->cur_marker = NULL;
  153489. switch (cinfo->unread_marker) {
  153490. case M_APP0:
  153491. examine_app0(cinfo, data, data_length, length);
  153492. break;
  153493. case M_APP14:
  153494. examine_app14(cinfo, data, data_length, length);
  153495. break;
  153496. default:
  153497. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153498. (int) (data_length + length));
  153499. break;
  153500. }
  153501. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153502. if (length > 0)
  153503. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153504. return TRUE;
  153505. }
  153506. #endif /* SAVE_MARKERS_SUPPORTED */
  153507. METHODDEF(boolean)
  153508. skip_variable (j_decompress_ptr cinfo)
  153509. {
  153510. INT32 length;
  153511. INPUT_VARS(cinfo);
  153512. INPUT_2BYTES(cinfo, length, return FALSE);
  153513. length -= 2;
  153514. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153515. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153516. if (length > 0)
  153517. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153518. return TRUE;
  153519. }
  153520. LOCAL(boolean)
  153521. next_marker (j_decompress_ptr cinfo)
  153522. {
  153523. int c;
  153524. INPUT_VARS(cinfo);
  153525. for (;;) {
  153526. INPUT_BYTE(cinfo, c, return FALSE);
  153527. while (c != 0xFF) {
  153528. cinfo->marker->discarded_bytes++;
  153529. INPUT_SYNC(cinfo);
  153530. INPUT_BYTE(cinfo, c, return FALSE);
  153531. }
  153532. do {
  153533. INPUT_BYTE(cinfo, c, return FALSE);
  153534. } while (c == 0xFF);
  153535. if (c != 0)
  153536. break; /* found a valid marker, exit loop */
  153537. cinfo->marker->discarded_bytes += 2;
  153538. INPUT_SYNC(cinfo);
  153539. }
  153540. if (cinfo->marker->discarded_bytes != 0) {
  153541. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153542. cinfo->marker->discarded_bytes = 0;
  153543. }
  153544. cinfo->unread_marker = c;
  153545. INPUT_SYNC(cinfo);
  153546. return TRUE;
  153547. }
  153548. LOCAL(boolean)
  153549. first_marker (j_decompress_ptr cinfo)
  153550. {
  153551. int c, c2;
  153552. INPUT_VARS(cinfo);
  153553. INPUT_BYTE(cinfo, c, return FALSE);
  153554. INPUT_BYTE(cinfo, c2, return FALSE);
  153555. if (c != 0xFF || c2 != (int) M_SOI)
  153556. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153557. cinfo->unread_marker = c2;
  153558. INPUT_SYNC(cinfo);
  153559. return TRUE;
  153560. }
  153561. METHODDEF(int)
  153562. read_markers (j_decompress_ptr cinfo)
  153563. {
  153564. for (;;) {
  153565. if (cinfo->unread_marker == 0) {
  153566. if (! cinfo->marker->saw_SOI) {
  153567. if (! first_marker(cinfo))
  153568. return JPEG_SUSPENDED;
  153569. } else {
  153570. if (! next_marker(cinfo))
  153571. return JPEG_SUSPENDED;
  153572. }
  153573. }
  153574. switch (cinfo->unread_marker) {
  153575. case M_SOI:
  153576. if (! get_soi(cinfo))
  153577. return JPEG_SUSPENDED;
  153578. break;
  153579. case M_SOF0: /* Baseline */
  153580. case M_SOF1: /* Extended sequential, Huffman */
  153581. if (! get_sof(cinfo, FALSE, FALSE))
  153582. return JPEG_SUSPENDED;
  153583. break;
  153584. case M_SOF2: /* Progressive, Huffman */
  153585. if (! get_sof(cinfo, TRUE, FALSE))
  153586. return JPEG_SUSPENDED;
  153587. break;
  153588. case M_SOF9: /* Extended sequential, arithmetic */
  153589. if (! get_sof(cinfo, FALSE, TRUE))
  153590. return JPEG_SUSPENDED;
  153591. break;
  153592. case M_SOF10: /* Progressive, arithmetic */
  153593. if (! get_sof(cinfo, TRUE, TRUE))
  153594. return JPEG_SUSPENDED;
  153595. break;
  153596. case M_SOF3: /* Lossless, Huffman */
  153597. case M_SOF5: /* Differential sequential, Huffman */
  153598. case M_SOF6: /* Differential progressive, Huffman */
  153599. case M_SOF7: /* Differential lossless, Huffman */
  153600. case M_JPG: /* Reserved for JPEG extensions */
  153601. case M_SOF11: /* Lossless, arithmetic */
  153602. case M_SOF13: /* Differential sequential, arithmetic */
  153603. case M_SOF14: /* Differential progressive, arithmetic */
  153604. case M_SOF15: /* Differential lossless, arithmetic */
  153605. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153606. break;
  153607. case M_SOS:
  153608. if (! get_sos(cinfo))
  153609. return JPEG_SUSPENDED;
  153610. cinfo->unread_marker = 0; /* processed the marker */
  153611. return JPEG_REACHED_SOS;
  153612. case M_EOI:
  153613. TRACEMS(cinfo, 1, JTRC_EOI);
  153614. cinfo->unread_marker = 0; /* processed the marker */
  153615. return JPEG_REACHED_EOI;
  153616. case M_DAC:
  153617. if (! get_dac(cinfo))
  153618. return JPEG_SUSPENDED;
  153619. break;
  153620. case M_DHT:
  153621. if (! get_dht(cinfo))
  153622. return JPEG_SUSPENDED;
  153623. break;
  153624. case M_DQT:
  153625. if (! get_dqt(cinfo))
  153626. return JPEG_SUSPENDED;
  153627. break;
  153628. case M_DRI:
  153629. if (! get_dri(cinfo))
  153630. return JPEG_SUSPENDED;
  153631. break;
  153632. case M_APP0:
  153633. case M_APP1:
  153634. case M_APP2:
  153635. case M_APP3:
  153636. case M_APP4:
  153637. case M_APP5:
  153638. case M_APP6:
  153639. case M_APP7:
  153640. case M_APP8:
  153641. case M_APP9:
  153642. case M_APP10:
  153643. case M_APP11:
  153644. case M_APP12:
  153645. case M_APP13:
  153646. case M_APP14:
  153647. case M_APP15:
  153648. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153649. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153650. return JPEG_SUSPENDED;
  153651. break;
  153652. case M_COM:
  153653. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153654. return JPEG_SUSPENDED;
  153655. break;
  153656. case M_RST0: /* these are all parameterless */
  153657. case M_RST1:
  153658. case M_RST2:
  153659. case M_RST3:
  153660. case M_RST4:
  153661. case M_RST5:
  153662. case M_RST6:
  153663. case M_RST7:
  153664. case M_TEM:
  153665. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153666. break;
  153667. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153668. if (! skip_variable(cinfo))
  153669. return JPEG_SUSPENDED;
  153670. break;
  153671. default: /* must be DHP, EXP, JPGn, or RESn */
  153672. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153673. break;
  153674. }
  153675. cinfo->unread_marker = 0;
  153676. } /* end loop */
  153677. }
  153678. METHODDEF(boolean)
  153679. read_restart_marker (j_decompress_ptr cinfo)
  153680. {
  153681. if (cinfo->unread_marker == 0) {
  153682. if (! next_marker(cinfo))
  153683. return FALSE;
  153684. }
  153685. if (cinfo->unread_marker ==
  153686. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153687. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153688. cinfo->unread_marker = 0;
  153689. } else {
  153690. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153691. cinfo->marker->next_restart_num))
  153692. return FALSE;
  153693. }
  153694. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153695. return TRUE;
  153696. }
  153697. GLOBAL(boolean)
  153698. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153699. {
  153700. int marker = cinfo->unread_marker;
  153701. int action = 1;
  153702. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153703. for (;;) {
  153704. if (marker < (int) M_SOF0)
  153705. action = 2; /* invalid marker */
  153706. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153707. action = 3; /* valid non-restart marker */
  153708. else {
  153709. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153710. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153711. action = 3; /* one of the next two expected restarts */
  153712. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153713. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153714. action = 2; /* a prior restart, so advance */
  153715. else
  153716. action = 1; /* desired restart or too far away */
  153717. }
  153718. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153719. switch (action) {
  153720. case 1:
  153721. cinfo->unread_marker = 0;
  153722. return TRUE;
  153723. case 2:
  153724. if (! next_marker(cinfo))
  153725. return FALSE;
  153726. marker = cinfo->unread_marker;
  153727. break;
  153728. case 3:
  153729. return TRUE;
  153730. }
  153731. } /* end loop */
  153732. }
  153733. METHODDEF(void)
  153734. reset_marker_reader (j_decompress_ptr cinfo)
  153735. {
  153736. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153737. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153738. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153739. cinfo->unread_marker = 0; /* no pending marker */
  153740. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153741. marker->pub.saw_SOF = FALSE;
  153742. marker->pub.discarded_bytes = 0;
  153743. marker->cur_marker = NULL;
  153744. }
  153745. GLOBAL(void)
  153746. jinit_marker_reader (j_decompress_ptr cinfo)
  153747. {
  153748. my_marker_ptr2 marker;
  153749. int i;
  153750. marker = (my_marker_ptr2)
  153751. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153752. SIZEOF(my_marker_reader));
  153753. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153754. marker->pub.reset_marker_reader = reset_marker_reader;
  153755. marker->pub.read_markers = read_markers;
  153756. marker->pub.read_restart_marker = read_restart_marker;
  153757. marker->process_COM = skip_variable;
  153758. marker->length_limit_COM = 0;
  153759. for (i = 0; i < 16; i++) {
  153760. marker->process_APPn[i] = skip_variable;
  153761. marker->length_limit_APPn[i] = 0;
  153762. }
  153763. marker->process_APPn[0] = get_interesting_appn;
  153764. marker->process_APPn[14] = get_interesting_appn;
  153765. reset_marker_reader(cinfo);
  153766. }
  153767. #ifdef SAVE_MARKERS_SUPPORTED
  153768. GLOBAL(void)
  153769. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153770. unsigned int length_limit)
  153771. {
  153772. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153773. long maxlength;
  153774. jpeg_marker_parser_method processor;
  153775. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153776. if (((long) length_limit) > maxlength)
  153777. length_limit = (unsigned int) maxlength;
  153778. if (length_limit) {
  153779. processor = save_marker;
  153780. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153781. length_limit = APP0_DATA_LEN;
  153782. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153783. length_limit = APP14_DATA_LEN;
  153784. } else {
  153785. processor = skip_variable;
  153786. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153787. processor = get_interesting_appn;
  153788. }
  153789. if (marker_code == (int) M_COM) {
  153790. marker->process_COM = processor;
  153791. marker->length_limit_COM = length_limit;
  153792. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153793. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153794. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153795. } else
  153796. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153797. }
  153798. #endif /* SAVE_MARKERS_SUPPORTED */
  153799. GLOBAL(void)
  153800. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153801. jpeg_marker_parser_method routine)
  153802. {
  153803. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153804. if (marker_code == (int) M_COM)
  153805. marker->process_COM = routine;
  153806. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153807. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153808. else
  153809. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153810. }
  153811. /*** End of inlined file: jdmarker.c ***/
  153812. /*** Start of inlined file: jdmaster.c ***/
  153813. #define JPEG_INTERNALS
  153814. typedef struct {
  153815. struct jpeg_decomp_master pub; /* public fields */
  153816. int pass_number; /* # of passes completed */
  153817. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153818. struct jpeg_color_quantizer * quantizer_1pass;
  153819. struct jpeg_color_quantizer * quantizer_2pass;
  153820. } my_decomp_master;
  153821. typedef my_decomp_master * my_master_ptr6;
  153822. LOCAL(boolean)
  153823. use_merged_upsample (j_decompress_ptr cinfo)
  153824. {
  153825. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153826. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153827. return FALSE;
  153828. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153829. cinfo->out_color_space != JCS_RGB ||
  153830. cinfo->out_color_components != RGB_PIXELSIZE)
  153831. return FALSE;
  153832. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153833. cinfo->comp_info[1].h_samp_factor != 1 ||
  153834. cinfo->comp_info[2].h_samp_factor != 1 ||
  153835. cinfo->comp_info[0].v_samp_factor > 2 ||
  153836. cinfo->comp_info[1].v_samp_factor != 1 ||
  153837. cinfo->comp_info[2].v_samp_factor != 1)
  153838. return FALSE;
  153839. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153840. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153841. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153842. return FALSE;
  153843. return TRUE; /* by golly, it'll work... */
  153844. #else
  153845. return FALSE;
  153846. #endif
  153847. }
  153848. GLOBAL(void)
  153849. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153850. {
  153851. #ifdef IDCT_SCALING_SUPPORTED
  153852. int ci;
  153853. jpeg_component_info *compptr;
  153854. #endif
  153855. if (cinfo->global_state != DSTATE_READY)
  153856. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153857. #ifdef IDCT_SCALING_SUPPORTED
  153858. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153859. cinfo->output_width = (JDIMENSION)
  153860. jdiv_round_up((long) cinfo->image_width, 8L);
  153861. cinfo->output_height = (JDIMENSION)
  153862. jdiv_round_up((long) cinfo->image_height, 8L);
  153863. cinfo->min_DCT_scaled_size = 1;
  153864. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153865. cinfo->output_width = (JDIMENSION)
  153866. jdiv_round_up((long) cinfo->image_width, 4L);
  153867. cinfo->output_height = (JDIMENSION)
  153868. jdiv_round_up((long) cinfo->image_height, 4L);
  153869. cinfo->min_DCT_scaled_size = 2;
  153870. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153871. cinfo->output_width = (JDIMENSION)
  153872. jdiv_round_up((long) cinfo->image_width, 2L);
  153873. cinfo->output_height = (JDIMENSION)
  153874. jdiv_round_up((long) cinfo->image_height, 2L);
  153875. cinfo->min_DCT_scaled_size = 4;
  153876. } else {
  153877. cinfo->output_width = cinfo->image_width;
  153878. cinfo->output_height = cinfo->image_height;
  153879. cinfo->min_DCT_scaled_size = DCTSIZE;
  153880. }
  153881. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153882. ci++, compptr++) {
  153883. int ssize = cinfo->min_DCT_scaled_size;
  153884. while (ssize < DCTSIZE &&
  153885. (compptr->h_samp_factor * ssize * 2 <=
  153886. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153887. (compptr->v_samp_factor * ssize * 2 <=
  153888. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153889. ssize = ssize * 2;
  153890. }
  153891. compptr->DCT_scaled_size = ssize;
  153892. }
  153893. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153894. ci++, compptr++) {
  153895. compptr->downsampled_width = (JDIMENSION)
  153896. jdiv_round_up((long) cinfo->image_width *
  153897. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153898. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153899. compptr->downsampled_height = (JDIMENSION)
  153900. jdiv_round_up((long) cinfo->image_height *
  153901. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153902. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153903. }
  153904. #else /* !IDCT_SCALING_SUPPORTED */
  153905. cinfo->output_width = cinfo->image_width;
  153906. cinfo->output_height = cinfo->image_height;
  153907. #endif /* IDCT_SCALING_SUPPORTED */
  153908. switch (cinfo->out_color_space) {
  153909. case JCS_GRAYSCALE:
  153910. cinfo->out_color_components = 1;
  153911. break;
  153912. case JCS_RGB:
  153913. #if RGB_PIXELSIZE != 3
  153914. cinfo->out_color_components = RGB_PIXELSIZE;
  153915. break;
  153916. #endif /* else share code with YCbCr */
  153917. case JCS_YCbCr:
  153918. cinfo->out_color_components = 3;
  153919. break;
  153920. case JCS_CMYK:
  153921. case JCS_YCCK:
  153922. cinfo->out_color_components = 4;
  153923. break;
  153924. default: /* else must be same colorspace as in file */
  153925. cinfo->out_color_components = cinfo->num_components;
  153926. break;
  153927. }
  153928. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153929. cinfo->out_color_components);
  153930. if (use_merged_upsample(cinfo))
  153931. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153932. else
  153933. cinfo->rec_outbuf_height = 1;
  153934. }
  153935. LOCAL(void)
  153936. prepare_range_limit_table (j_decompress_ptr cinfo)
  153937. {
  153938. JSAMPLE * table;
  153939. int i;
  153940. table = (JSAMPLE *)
  153941. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153942. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153943. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153944. cinfo->sample_range_limit = table;
  153945. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153946. for (i = 0; i <= MAXJSAMPLE; i++)
  153947. table[i] = (JSAMPLE) i;
  153948. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153949. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153950. table[i] = MAXJSAMPLE;
  153951. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153952. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153953. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153954. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153955. }
  153956. LOCAL(void)
  153957. master_selection (j_decompress_ptr cinfo)
  153958. {
  153959. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153960. boolean use_c_buffer;
  153961. long samplesperrow;
  153962. JDIMENSION jd_samplesperrow;
  153963. jpeg_calc_output_dimensions(cinfo);
  153964. prepare_range_limit_table(cinfo);
  153965. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153966. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153967. if ((long) jd_samplesperrow != samplesperrow)
  153968. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153969. master->pass_number = 0;
  153970. master->using_merged_upsample = use_merged_upsample(cinfo);
  153971. master->quantizer_1pass = NULL;
  153972. master->quantizer_2pass = NULL;
  153973. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153974. cinfo->enable_1pass_quant = FALSE;
  153975. cinfo->enable_external_quant = FALSE;
  153976. cinfo->enable_2pass_quant = FALSE;
  153977. }
  153978. if (cinfo->quantize_colors) {
  153979. if (cinfo->raw_data_out)
  153980. ERREXIT(cinfo, JERR_NOTIMPL);
  153981. if (cinfo->out_color_components != 3) {
  153982. cinfo->enable_1pass_quant = TRUE;
  153983. cinfo->enable_external_quant = FALSE;
  153984. cinfo->enable_2pass_quant = FALSE;
  153985. cinfo->colormap = NULL;
  153986. } else if (cinfo->colormap != NULL) {
  153987. cinfo->enable_external_quant = TRUE;
  153988. } else if (cinfo->two_pass_quantize) {
  153989. cinfo->enable_2pass_quant = TRUE;
  153990. } else {
  153991. cinfo->enable_1pass_quant = TRUE;
  153992. }
  153993. if (cinfo->enable_1pass_quant) {
  153994. #ifdef QUANT_1PASS_SUPPORTED
  153995. jinit_1pass_quantizer(cinfo);
  153996. master->quantizer_1pass = cinfo->cquantize;
  153997. #else
  153998. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153999. #endif
  154000. }
  154001. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  154002. #ifdef QUANT_2PASS_SUPPORTED
  154003. jinit_2pass_quantizer(cinfo);
  154004. master->quantizer_2pass = cinfo->cquantize;
  154005. #else
  154006. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154007. #endif
  154008. }
  154009. }
  154010. if (! cinfo->raw_data_out) {
  154011. if (master->using_merged_upsample) {
  154012. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154013. jinit_merged_upsampler(cinfo); /* does color conversion too */
  154014. #else
  154015. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154016. #endif
  154017. } else {
  154018. jinit_color_deconverter(cinfo);
  154019. jinit_upsampler(cinfo);
  154020. }
  154021. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  154022. }
  154023. jinit_inverse_dct(cinfo);
  154024. if (cinfo->arith_code) {
  154025. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154026. } else {
  154027. if (cinfo->progressive_mode) {
  154028. #ifdef D_PROGRESSIVE_SUPPORTED
  154029. jinit_phuff_decoder(cinfo);
  154030. #else
  154031. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154032. #endif
  154033. } else
  154034. jinit_huff_decoder(cinfo);
  154035. }
  154036. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  154037. jinit_d_coef_controller(cinfo, use_c_buffer);
  154038. if (! cinfo->raw_data_out)
  154039. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  154040. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154041. (*cinfo->inputctl->start_input_pass) (cinfo);
  154042. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154043. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  154044. cinfo->inputctl->has_multiple_scans) {
  154045. int nscans;
  154046. if (cinfo->progressive_mode) {
  154047. nscans = 2 + 3 * cinfo->num_components;
  154048. } else {
  154049. nscans = cinfo->num_components;
  154050. }
  154051. cinfo->progress->pass_counter = 0L;
  154052. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154053. cinfo->progress->completed_passes = 0;
  154054. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  154055. master->pass_number++;
  154056. }
  154057. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154058. }
  154059. METHODDEF(void)
  154060. prepare_for_output_pass (j_decompress_ptr cinfo)
  154061. {
  154062. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154063. if (master->pub.is_dummy_pass) {
  154064. #ifdef QUANT_2PASS_SUPPORTED
  154065. master->pub.is_dummy_pass = FALSE;
  154066. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  154067. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  154068. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  154069. #else
  154070. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154071. #endif /* QUANT_2PASS_SUPPORTED */
  154072. } else {
  154073. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  154074. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  154075. cinfo->cquantize = master->quantizer_2pass;
  154076. master->pub.is_dummy_pass = TRUE;
  154077. } else if (cinfo->enable_1pass_quant) {
  154078. cinfo->cquantize = master->quantizer_1pass;
  154079. } else {
  154080. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154081. }
  154082. }
  154083. (*cinfo->idct->start_pass) (cinfo);
  154084. (*cinfo->coef->start_output_pass) (cinfo);
  154085. if (! cinfo->raw_data_out) {
  154086. if (! master->using_merged_upsample)
  154087. (*cinfo->cconvert->start_pass) (cinfo);
  154088. (*cinfo->upsample->start_pass) (cinfo);
  154089. if (cinfo->quantize_colors)
  154090. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  154091. (*cinfo->post->start_pass) (cinfo,
  154092. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  154093. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  154094. }
  154095. }
  154096. if (cinfo->progress != NULL) {
  154097. cinfo->progress->completed_passes = master->pass_number;
  154098. cinfo->progress->total_passes = master->pass_number +
  154099. (master->pub.is_dummy_pass ? 2 : 1);
  154100. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  154101. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  154102. }
  154103. }
  154104. }
  154105. METHODDEF(void)
  154106. finish_output_pass (j_decompress_ptr cinfo)
  154107. {
  154108. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154109. if (cinfo->quantize_colors)
  154110. (*cinfo->cquantize->finish_pass) (cinfo);
  154111. master->pass_number++;
  154112. }
  154113. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154114. GLOBAL(void)
  154115. jpeg_new_colormap (j_decompress_ptr cinfo)
  154116. {
  154117. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154118. if (cinfo->global_state != DSTATE_BUFIMAGE)
  154119. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154120. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  154121. cinfo->colormap != NULL) {
  154122. cinfo->cquantize = master->quantizer_2pass;
  154123. (*cinfo->cquantize->new_color_map) (cinfo);
  154124. master->pub.is_dummy_pass = FALSE; /* just in case */
  154125. } else
  154126. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154127. }
  154128. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154129. GLOBAL(void)
  154130. jinit_master_decompress (j_decompress_ptr cinfo)
  154131. {
  154132. my_master_ptr6 master;
  154133. master = (my_master_ptr6)
  154134. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154135. SIZEOF(my_decomp_master));
  154136. cinfo->master = (struct jpeg_decomp_master *) master;
  154137. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  154138. master->pub.finish_output_pass = finish_output_pass;
  154139. master->pub.is_dummy_pass = FALSE;
  154140. master_selection(cinfo);
  154141. }
  154142. /*** End of inlined file: jdmaster.c ***/
  154143. #undef FIX
  154144. /*** Start of inlined file: jdmerge.c ***/
  154145. #define JPEG_INTERNALS
  154146. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154147. typedef struct {
  154148. struct jpeg_upsampler pub; /* public fields */
  154149. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  154150. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154151. JSAMPARRAY output_buf));
  154152. int * Cr_r_tab; /* => table for Cr to R conversion */
  154153. int * Cb_b_tab; /* => table for Cb to B conversion */
  154154. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  154155. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  154156. JSAMPROW spare_row;
  154157. boolean spare_full; /* T if spare buffer is occupied */
  154158. JDIMENSION out_row_width; /* samples per output row */
  154159. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154160. } my_upsampler;
  154161. typedef my_upsampler * my_upsample_ptr;
  154162. #define SCALEBITS 16 /* speediest right-shift on some machines */
  154163. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  154164. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  154165. LOCAL(void)
  154166. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  154167. {
  154168. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154169. int i;
  154170. INT32 x;
  154171. SHIFT_TEMPS
  154172. upsample->Cr_r_tab = (int *)
  154173. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154174. (MAXJSAMPLE+1) * SIZEOF(int));
  154175. upsample->Cb_b_tab = (int *)
  154176. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154177. (MAXJSAMPLE+1) * SIZEOF(int));
  154178. upsample->Cr_g_tab = (INT32 *)
  154179. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154180. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154181. upsample->Cb_g_tab = (INT32 *)
  154182. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154183. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154184. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  154185. upsample->Cr_r_tab[i] = (int)
  154186. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  154187. upsample->Cb_b_tab[i] = (int)
  154188. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  154189. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  154190. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  154191. }
  154192. }
  154193. METHODDEF(void)
  154194. start_pass_merged_upsample (j_decompress_ptr cinfo)
  154195. {
  154196. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154197. upsample->spare_full = FALSE;
  154198. upsample->rows_to_go = cinfo->output_height;
  154199. }
  154200. METHODDEF(void)
  154201. merged_2v_upsample (j_decompress_ptr cinfo,
  154202. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154203. JDIMENSION in_row_groups_avail,
  154204. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154205. JDIMENSION out_rows_avail)
  154206. {
  154207. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154208. JSAMPROW work_ptrs[2];
  154209. JDIMENSION num_rows; /* number of rows returned to caller */
  154210. if (upsample->spare_full) {
  154211. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  154212. 1, upsample->out_row_width);
  154213. num_rows = 1;
  154214. upsample->spare_full = FALSE;
  154215. } else {
  154216. num_rows = 2;
  154217. if (num_rows > upsample->rows_to_go)
  154218. num_rows = upsample->rows_to_go;
  154219. out_rows_avail -= *out_row_ctr;
  154220. if (num_rows > out_rows_avail)
  154221. num_rows = out_rows_avail;
  154222. work_ptrs[0] = output_buf[*out_row_ctr];
  154223. if (num_rows > 1) {
  154224. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  154225. } else {
  154226. work_ptrs[1] = upsample->spare_row;
  154227. upsample->spare_full = TRUE;
  154228. }
  154229. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  154230. }
  154231. *out_row_ctr += num_rows;
  154232. upsample->rows_to_go -= num_rows;
  154233. if (! upsample->spare_full)
  154234. (*in_row_group_ctr)++;
  154235. }
  154236. METHODDEF(void)
  154237. merged_1v_upsample (j_decompress_ptr cinfo,
  154238. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154239. JDIMENSION in_row_groups_avail,
  154240. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154241. JDIMENSION out_rows_avail)
  154242. {
  154243. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154244. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  154245. output_buf + *out_row_ctr);
  154246. (*out_row_ctr)++;
  154247. (*in_row_group_ctr)++;
  154248. }
  154249. METHODDEF(void)
  154250. h2v1_merged_upsample (j_decompress_ptr cinfo,
  154251. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154252. JSAMPARRAY output_buf)
  154253. {
  154254. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154255. register int y, cred, cgreen, cblue;
  154256. int cb, cr;
  154257. register JSAMPROW outptr;
  154258. JSAMPROW inptr0, inptr1, inptr2;
  154259. JDIMENSION col;
  154260. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154261. int * Crrtab = upsample->Cr_r_tab;
  154262. int * Cbbtab = upsample->Cb_b_tab;
  154263. INT32 * Crgtab = upsample->Cr_g_tab;
  154264. INT32 * Cbgtab = upsample->Cb_g_tab;
  154265. SHIFT_TEMPS
  154266. inptr0 = input_buf[0][in_row_group_ctr];
  154267. inptr1 = input_buf[1][in_row_group_ctr];
  154268. inptr2 = input_buf[2][in_row_group_ctr];
  154269. outptr = output_buf[0];
  154270. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154271. cb = GETJSAMPLE(*inptr1++);
  154272. cr = GETJSAMPLE(*inptr2++);
  154273. cred = Crrtab[cr];
  154274. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154275. cblue = Cbbtab[cb];
  154276. y = GETJSAMPLE(*inptr0++);
  154277. outptr[RGB_RED] = range_limit[y + cred];
  154278. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154279. outptr[RGB_BLUE] = range_limit[y + cblue];
  154280. outptr += RGB_PIXELSIZE;
  154281. y = GETJSAMPLE(*inptr0++);
  154282. outptr[RGB_RED] = range_limit[y + cred];
  154283. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154284. outptr[RGB_BLUE] = range_limit[y + cblue];
  154285. outptr += RGB_PIXELSIZE;
  154286. }
  154287. if (cinfo->output_width & 1) {
  154288. cb = GETJSAMPLE(*inptr1);
  154289. cr = GETJSAMPLE(*inptr2);
  154290. cred = Crrtab[cr];
  154291. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154292. cblue = Cbbtab[cb];
  154293. y = GETJSAMPLE(*inptr0);
  154294. outptr[RGB_RED] = range_limit[y + cred];
  154295. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154296. outptr[RGB_BLUE] = range_limit[y + cblue];
  154297. }
  154298. }
  154299. METHODDEF(void)
  154300. h2v2_merged_upsample (j_decompress_ptr cinfo,
  154301. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154302. JSAMPARRAY output_buf)
  154303. {
  154304. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154305. register int y, cred, cgreen, cblue;
  154306. int cb, cr;
  154307. register JSAMPROW outptr0, outptr1;
  154308. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154309. JDIMENSION col;
  154310. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154311. int * Crrtab = upsample->Cr_r_tab;
  154312. int * Cbbtab = upsample->Cb_b_tab;
  154313. INT32 * Crgtab = upsample->Cr_g_tab;
  154314. INT32 * Cbgtab = upsample->Cb_g_tab;
  154315. SHIFT_TEMPS
  154316. inptr00 = input_buf[0][in_row_group_ctr*2];
  154317. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154318. inptr1 = input_buf[1][in_row_group_ctr];
  154319. inptr2 = input_buf[2][in_row_group_ctr];
  154320. outptr0 = output_buf[0];
  154321. outptr1 = output_buf[1];
  154322. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154323. cb = GETJSAMPLE(*inptr1++);
  154324. cr = GETJSAMPLE(*inptr2++);
  154325. cred = Crrtab[cr];
  154326. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154327. cblue = Cbbtab[cb];
  154328. y = GETJSAMPLE(*inptr00++);
  154329. outptr0[RGB_RED] = range_limit[y + cred];
  154330. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154331. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154332. outptr0 += RGB_PIXELSIZE;
  154333. y = GETJSAMPLE(*inptr00++);
  154334. outptr0[RGB_RED] = range_limit[y + cred];
  154335. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154336. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154337. outptr0 += RGB_PIXELSIZE;
  154338. y = GETJSAMPLE(*inptr01++);
  154339. outptr1[RGB_RED] = range_limit[y + cred];
  154340. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154341. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154342. outptr1 += RGB_PIXELSIZE;
  154343. y = GETJSAMPLE(*inptr01++);
  154344. outptr1[RGB_RED] = range_limit[y + cred];
  154345. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154346. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154347. outptr1 += RGB_PIXELSIZE;
  154348. }
  154349. if (cinfo->output_width & 1) {
  154350. cb = GETJSAMPLE(*inptr1);
  154351. cr = GETJSAMPLE(*inptr2);
  154352. cred = Crrtab[cr];
  154353. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154354. cblue = Cbbtab[cb];
  154355. y = GETJSAMPLE(*inptr00);
  154356. outptr0[RGB_RED] = range_limit[y + cred];
  154357. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154358. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154359. y = GETJSAMPLE(*inptr01);
  154360. outptr1[RGB_RED] = range_limit[y + cred];
  154361. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154362. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154363. }
  154364. }
  154365. GLOBAL(void)
  154366. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154367. {
  154368. my_upsample_ptr upsample;
  154369. upsample = (my_upsample_ptr)
  154370. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154371. SIZEOF(my_upsampler));
  154372. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154373. upsample->pub.start_pass = start_pass_merged_upsample;
  154374. upsample->pub.need_context_rows = FALSE;
  154375. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154376. if (cinfo->max_v_samp_factor == 2) {
  154377. upsample->pub.upsample = merged_2v_upsample;
  154378. upsample->upmethod = h2v2_merged_upsample;
  154379. upsample->spare_row = (JSAMPROW)
  154380. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154381. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154382. } else {
  154383. upsample->pub.upsample = merged_1v_upsample;
  154384. upsample->upmethod = h2v1_merged_upsample;
  154385. upsample->spare_row = NULL;
  154386. }
  154387. build_ycc_rgb_table2(cinfo);
  154388. }
  154389. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154390. /*** End of inlined file: jdmerge.c ***/
  154391. #undef ASSIGN_STATE
  154392. /*** Start of inlined file: jdphuff.c ***/
  154393. #define JPEG_INTERNALS
  154394. #ifdef D_PROGRESSIVE_SUPPORTED
  154395. typedef struct {
  154396. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154397. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154398. } savable_state3;
  154399. #ifndef NO_STRUCT_ASSIGN
  154400. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154401. #else
  154402. #if MAX_COMPS_IN_SCAN == 4
  154403. #define ASSIGN_STATE(dest,src) \
  154404. ((dest).EOBRUN = (src).EOBRUN, \
  154405. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154406. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154407. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154408. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154409. #endif
  154410. #endif
  154411. typedef struct {
  154412. struct jpeg_entropy_decoder pub; /* public fields */
  154413. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154414. savable_state3 saved; /* Other state at start of MCU */
  154415. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154416. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154417. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154418. } phuff_entropy_decoder;
  154419. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154420. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154421. JBLOCKROW *MCU_data));
  154422. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154423. JBLOCKROW *MCU_data));
  154424. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154425. JBLOCKROW *MCU_data));
  154426. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154427. JBLOCKROW *MCU_data));
  154428. METHODDEF(void)
  154429. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154430. {
  154431. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154432. boolean is_DC_band, bad;
  154433. int ci, coefi, tbl;
  154434. int *coef_bit_ptr;
  154435. jpeg_component_info * compptr;
  154436. is_DC_band = (cinfo->Ss == 0);
  154437. bad = FALSE;
  154438. if (is_DC_band) {
  154439. if (cinfo->Se != 0)
  154440. bad = TRUE;
  154441. } else {
  154442. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154443. bad = TRUE;
  154444. if (cinfo->comps_in_scan != 1)
  154445. bad = TRUE;
  154446. }
  154447. if (cinfo->Ah != 0) {
  154448. if (cinfo->Al != cinfo->Ah-1)
  154449. bad = TRUE;
  154450. }
  154451. if (cinfo->Al > 13) /* need not check for < 0 */
  154452. bad = TRUE;
  154453. if (bad)
  154454. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154455. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154456. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154457. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154458. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154459. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154460. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154461. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154462. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154463. if (cinfo->Ah != expected)
  154464. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154465. coef_bit_ptr[coefi] = cinfo->Al;
  154466. }
  154467. }
  154468. if (cinfo->Ah == 0) {
  154469. if (is_DC_band)
  154470. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154471. else
  154472. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154473. } else {
  154474. if (is_DC_band)
  154475. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154476. else
  154477. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154478. }
  154479. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154480. compptr = cinfo->cur_comp_info[ci];
  154481. if (is_DC_band) {
  154482. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154483. tbl = compptr->dc_tbl_no;
  154484. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154485. & entropy->derived_tbls[tbl]);
  154486. }
  154487. } else {
  154488. tbl = compptr->ac_tbl_no;
  154489. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154490. & entropy->derived_tbls[tbl]);
  154491. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154492. }
  154493. entropy->saved.last_dc_val[ci] = 0;
  154494. }
  154495. entropy->bitstate.bits_left = 0;
  154496. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154497. entropy->pub.insufficient_data = FALSE;
  154498. entropy->saved.EOBRUN = 0;
  154499. entropy->restarts_to_go = cinfo->restart_interval;
  154500. }
  154501. LOCAL(boolean)
  154502. process_restartp (j_decompress_ptr cinfo)
  154503. {
  154504. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154505. int ci;
  154506. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154507. entropy->bitstate.bits_left = 0;
  154508. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154509. return FALSE;
  154510. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154511. entropy->saved.last_dc_val[ci] = 0;
  154512. entropy->saved.EOBRUN = 0;
  154513. entropy->restarts_to_go = cinfo->restart_interval;
  154514. if (cinfo->unread_marker == 0)
  154515. entropy->pub.insufficient_data = FALSE;
  154516. return TRUE;
  154517. }
  154518. METHODDEF(boolean)
  154519. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154520. {
  154521. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154522. int Al = cinfo->Al;
  154523. register int s, r;
  154524. int blkn, ci;
  154525. JBLOCKROW block;
  154526. BITREAD_STATE_VARS;
  154527. savable_state3 state;
  154528. d_derived_tbl * tbl;
  154529. jpeg_component_info * compptr;
  154530. if (cinfo->restart_interval) {
  154531. if (entropy->restarts_to_go == 0)
  154532. if (! process_restartp(cinfo))
  154533. return FALSE;
  154534. }
  154535. if (! entropy->pub.insufficient_data) {
  154536. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154537. ASSIGN_STATE(state, entropy->saved);
  154538. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154539. block = MCU_data[blkn];
  154540. ci = cinfo->MCU_membership[blkn];
  154541. compptr = cinfo->cur_comp_info[ci];
  154542. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154543. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154544. if (s) {
  154545. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154546. r = GET_BITS(s);
  154547. s = HUFF_EXTEND(r, s);
  154548. }
  154549. s += state.last_dc_val[ci];
  154550. state.last_dc_val[ci] = s;
  154551. (*block)[0] = (JCOEF) (s << Al);
  154552. }
  154553. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154554. ASSIGN_STATE(entropy->saved, state);
  154555. }
  154556. entropy->restarts_to_go--;
  154557. return TRUE;
  154558. }
  154559. METHODDEF(boolean)
  154560. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154561. {
  154562. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154563. int Se = cinfo->Se;
  154564. int Al = cinfo->Al;
  154565. register int s, k, r;
  154566. unsigned int EOBRUN;
  154567. JBLOCKROW block;
  154568. BITREAD_STATE_VARS;
  154569. d_derived_tbl * tbl;
  154570. if (cinfo->restart_interval) {
  154571. if (entropy->restarts_to_go == 0)
  154572. if (! process_restartp(cinfo))
  154573. return FALSE;
  154574. }
  154575. if (! entropy->pub.insufficient_data) {
  154576. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154577. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154578. EOBRUN--; /* ...process it now (we do nothing) */
  154579. else {
  154580. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154581. block = MCU_data[0];
  154582. tbl = entropy->ac_derived_tbl;
  154583. for (k = cinfo->Ss; k <= Se; k++) {
  154584. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154585. r = s >> 4;
  154586. s &= 15;
  154587. if (s) {
  154588. k += r;
  154589. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154590. r = GET_BITS(s);
  154591. s = HUFF_EXTEND(r, s);
  154592. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154593. } else {
  154594. if (r == 15) { /* ZRL */
  154595. k += 15; /* skip 15 zeroes in band */
  154596. } else { /* EOBr, run length is 2^r + appended bits */
  154597. EOBRUN = 1 << r;
  154598. if (r) { /* EOBr, r > 0 */
  154599. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154600. r = GET_BITS(r);
  154601. EOBRUN += r;
  154602. }
  154603. EOBRUN--; /* this band is processed at this moment */
  154604. break; /* force end-of-band */
  154605. }
  154606. }
  154607. }
  154608. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154609. }
  154610. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154611. }
  154612. entropy->restarts_to_go--;
  154613. return TRUE;
  154614. }
  154615. METHODDEF(boolean)
  154616. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154617. {
  154618. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154619. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154620. int blkn;
  154621. JBLOCKROW block;
  154622. BITREAD_STATE_VARS;
  154623. if (cinfo->restart_interval) {
  154624. if (entropy->restarts_to_go == 0)
  154625. if (! process_restartp(cinfo))
  154626. return FALSE;
  154627. }
  154628. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154629. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154630. block = MCU_data[blkn];
  154631. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154632. if (GET_BITS(1))
  154633. (*block)[0] |= p1;
  154634. }
  154635. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154636. entropy->restarts_to_go--;
  154637. return TRUE;
  154638. }
  154639. METHODDEF(boolean)
  154640. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154641. {
  154642. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154643. int Se = cinfo->Se;
  154644. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154645. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154646. register int s, k, r;
  154647. unsigned int EOBRUN;
  154648. JBLOCKROW block;
  154649. JCOEFPTR thiscoef;
  154650. BITREAD_STATE_VARS;
  154651. d_derived_tbl * tbl;
  154652. int num_newnz;
  154653. int newnz_pos[DCTSIZE2];
  154654. if (cinfo->restart_interval) {
  154655. if (entropy->restarts_to_go == 0)
  154656. if (! process_restartp(cinfo))
  154657. return FALSE;
  154658. }
  154659. if (! entropy->pub.insufficient_data) {
  154660. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154661. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154662. block = MCU_data[0];
  154663. tbl = entropy->ac_derived_tbl;
  154664. num_newnz = 0;
  154665. k = cinfo->Ss;
  154666. if (EOBRUN == 0) {
  154667. for (; k <= Se; k++) {
  154668. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154669. r = s >> 4;
  154670. s &= 15;
  154671. if (s) {
  154672. if (s != 1) /* size of new coef should always be 1 */
  154673. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154674. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154675. if (GET_BITS(1))
  154676. s = p1; /* newly nonzero coef is positive */
  154677. else
  154678. s = m1; /* newly nonzero coef is negative */
  154679. } else {
  154680. if (r != 15) {
  154681. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154682. if (r) {
  154683. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154684. r = GET_BITS(r);
  154685. EOBRUN += r;
  154686. }
  154687. break; /* rest of block is handled by EOB logic */
  154688. }
  154689. }
  154690. do {
  154691. thiscoef = *block + jpeg_natural_order[k];
  154692. if (*thiscoef != 0) {
  154693. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154694. if (GET_BITS(1)) {
  154695. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154696. if (*thiscoef >= 0)
  154697. *thiscoef += p1;
  154698. else
  154699. *thiscoef += m1;
  154700. }
  154701. }
  154702. } else {
  154703. if (--r < 0)
  154704. break; /* reached target zero coefficient */
  154705. }
  154706. k++;
  154707. } while (k <= Se);
  154708. if (s) {
  154709. int pos = jpeg_natural_order[k];
  154710. (*block)[pos] = (JCOEF) s;
  154711. newnz_pos[num_newnz++] = pos;
  154712. }
  154713. }
  154714. }
  154715. if (EOBRUN > 0) {
  154716. for (; k <= Se; k++) {
  154717. thiscoef = *block + jpeg_natural_order[k];
  154718. if (*thiscoef != 0) {
  154719. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154720. if (GET_BITS(1)) {
  154721. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154722. if (*thiscoef >= 0)
  154723. *thiscoef += p1;
  154724. else
  154725. *thiscoef += m1;
  154726. }
  154727. }
  154728. }
  154729. }
  154730. EOBRUN--;
  154731. }
  154732. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154733. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154734. }
  154735. entropy->restarts_to_go--;
  154736. return TRUE;
  154737. undoit:
  154738. while (num_newnz > 0)
  154739. (*block)[newnz_pos[--num_newnz]] = 0;
  154740. return FALSE;
  154741. }
  154742. GLOBAL(void)
  154743. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154744. {
  154745. phuff_entropy_ptr2 entropy;
  154746. int *coef_bit_ptr;
  154747. int ci, i;
  154748. entropy = (phuff_entropy_ptr2)
  154749. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154750. SIZEOF(phuff_entropy_decoder));
  154751. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154752. entropy->pub.start_pass = start_pass_phuff_decoder;
  154753. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154754. entropy->derived_tbls[i] = NULL;
  154755. }
  154756. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154757. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154758. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154759. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154760. for (ci = 0; ci < cinfo->num_components; ci++)
  154761. for (i = 0; i < DCTSIZE2; i++)
  154762. *coef_bit_ptr++ = -1;
  154763. }
  154764. #endif /* D_PROGRESSIVE_SUPPORTED */
  154765. /*** End of inlined file: jdphuff.c ***/
  154766. /*** Start of inlined file: jdpostct.c ***/
  154767. #define JPEG_INTERNALS
  154768. typedef struct {
  154769. struct jpeg_d_post_controller pub; /* public fields */
  154770. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154771. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154772. JDIMENSION strip_height; /* buffer size in rows */
  154773. JDIMENSION starting_row; /* row # of first row in current strip */
  154774. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154775. } my_post_controller;
  154776. typedef my_post_controller * my_post_ptr;
  154777. METHODDEF(void) post_process_1pass
  154778. JPP((j_decompress_ptr cinfo,
  154779. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154780. JDIMENSION in_row_groups_avail,
  154781. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154782. JDIMENSION out_rows_avail));
  154783. #ifdef QUANT_2PASS_SUPPORTED
  154784. METHODDEF(void) post_process_prepass
  154785. JPP((j_decompress_ptr cinfo,
  154786. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154787. JDIMENSION in_row_groups_avail,
  154788. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154789. JDIMENSION out_rows_avail));
  154790. METHODDEF(void) post_process_2pass
  154791. JPP((j_decompress_ptr cinfo,
  154792. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154793. JDIMENSION in_row_groups_avail,
  154794. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154795. JDIMENSION out_rows_avail));
  154796. #endif
  154797. METHODDEF(void)
  154798. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154799. {
  154800. my_post_ptr post = (my_post_ptr) cinfo->post;
  154801. switch (pass_mode) {
  154802. case JBUF_PASS_THRU:
  154803. if (cinfo->quantize_colors) {
  154804. post->pub.post_process_data = post_process_1pass;
  154805. if (post->buffer == NULL) {
  154806. post->buffer = (*cinfo->mem->access_virt_sarray)
  154807. ((j_common_ptr) cinfo, post->whole_image,
  154808. (JDIMENSION) 0, post->strip_height, TRUE);
  154809. }
  154810. } else {
  154811. post->pub.post_process_data = cinfo->upsample->upsample;
  154812. }
  154813. break;
  154814. #ifdef QUANT_2PASS_SUPPORTED
  154815. case JBUF_SAVE_AND_PASS:
  154816. if (post->whole_image == NULL)
  154817. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154818. post->pub.post_process_data = post_process_prepass;
  154819. break;
  154820. case JBUF_CRANK_DEST:
  154821. if (post->whole_image == NULL)
  154822. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154823. post->pub.post_process_data = post_process_2pass;
  154824. break;
  154825. #endif /* QUANT_2PASS_SUPPORTED */
  154826. default:
  154827. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154828. break;
  154829. }
  154830. post->starting_row = post->next_row = 0;
  154831. }
  154832. METHODDEF(void)
  154833. post_process_1pass (j_decompress_ptr cinfo,
  154834. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154835. JDIMENSION in_row_groups_avail,
  154836. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154837. JDIMENSION out_rows_avail)
  154838. {
  154839. my_post_ptr post = (my_post_ptr) cinfo->post;
  154840. JDIMENSION num_rows, max_rows;
  154841. max_rows = out_rows_avail - *out_row_ctr;
  154842. if (max_rows > post->strip_height)
  154843. max_rows = post->strip_height;
  154844. num_rows = 0;
  154845. (*cinfo->upsample->upsample) (cinfo,
  154846. input_buf, in_row_group_ctr, in_row_groups_avail,
  154847. post->buffer, &num_rows, max_rows);
  154848. (*cinfo->cquantize->color_quantize) (cinfo,
  154849. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154850. *out_row_ctr += num_rows;
  154851. }
  154852. #ifdef QUANT_2PASS_SUPPORTED
  154853. METHODDEF(void)
  154854. post_process_prepass (j_decompress_ptr cinfo,
  154855. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154856. JDIMENSION in_row_groups_avail,
  154857. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154858. JDIMENSION out_rows_avail)
  154859. {
  154860. my_post_ptr post = (my_post_ptr) cinfo->post;
  154861. JDIMENSION old_next_row, num_rows;
  154862. if (post->next_row == 0) {
  154863. post->buffer = (*cinfo->mem->access_virt_sarray)
  154864. ((j_common_ptr) cinfo, post->whole_image,
  154865. post->starting_row, post->strip_height, TRUE);
  154866. }
  154867. old_next_row = post->next_row;
  154868. (*cinfo->upsample->upsample) (cinfo,
  154869. input_buf, in_row_group_ctr, in_row_groups_avail,
  154870. post->buffer, &post->next_row, post->strip_height);
  154871. if (post->next_row > old_next_row) {
  154872. num_rows = post->next_row - old_next_row;
  154873. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154874. (JSAMPARRAY) NULL, (int) num_rows);
  154875. *out_row_ctr += num_rows;
  154876. }
  154877. if (post->next_row >= post->strip_height) {
  154878. post->starting_row += post->strip_height;
  154879. post->next_row = 0;
  154880. }
  154881. }
  154882. METHODDEF(void)
  154883. post_process_2pass (j_decompress_ptr cinfo,
  154884. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154885. JDIMENSION in_row_groups_avail,
  154886. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154887. JDIMENSION out_rows_avail)
  154888. {
  154889. my_post_ptr post = (my_post_ptr) cinfo->post;
  154890. JDIMENSION num_rows, max_rows;
  154891. if (post->next_row == 0) {
  154892. post->buffer = (*cinfo->mem->access_virt_sarray)
  154893. ((j_common_ptr) cinfo, post->whole_image,
  154894. post->starting_row, post->strip_height, FALSE);
  154895. }
  154896. num_rows = post->strip_height - post->next_row; /* available in strip */
  154897. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154898. if (num_rows > max_rows)
  154899. num_rows = max_rows;
  154900. max_rows = cinfo->output_height - post->starting_row;
  154901. if (num_rows > max_rows)
  154902. num_rows = max_rows;
  154903. (*cinfo->cquantize->color_quantize) (cinfo,
  154904. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154905. (int) num_rows);
  154906. *out_row_ctr += num_rows;
  154907. post->next_row += num_rows;
  154908. if (post->next_row >= post->strip_height) {
  154909. post->starting_row += post->strip_height;
  154910. post->next_row = 0;
  154911. }
  154912. }
  154913. #endif /* QUANT_2PASS_SUPPORTED */
  154914. GLOBAL(void)
  154915. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154916. {
  154917. my_post_ptr post;
  154918. post = (my_post_ptr)
  154919. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154920. SIZEOF(my_post_controller));
  154921. cinfo->post = (struct jpeg_d_post_controller *) post;
  154922. post->pub.start_pass = start_pass_dpost;
  154923. post->whole_image = NULL; /* flag for no virtual arrays */
  154924. post->buffer = NULL; /* flag for no strip buffer */
  154925. if (cinfo->quantize_colors) {
  154926. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154927. if (need_full_buffer) {
  154928. #ifdef QUANT_2PASS_SUPPORTED
  154929. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154930. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154931. cinfo->output_width * cinfo->out_color_components,
  154932. (JDIMENSION) jround_up((long) cinfo->output_height,
  154933. (long) post->strip_height),
  154934. post->strip_height);
  154935. #else
  154936. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154937. #endif /* QUANT_2PASS_SUPPORTED */
  154938. } else {
  154939. post->buffer = (*cinfo->mem->alloc_sarray)
  154940. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154941. cinfo->output_width * cinfo->out_color_components,
  154942. post->strip_height);
  154943. }
  154944. }
  154945. }
  154946. /*** End of inlined file: jdpostct.c ***/
  154947. #undef FIX
  154948. /*** Start of inlined file: jdsample.c ***/
  154949. #define JPEG_INTERNALS
  154950. typedef JMETHOD(void, upsample1_ptr,
  154951. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154952. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154953. typedef struct {
  154954. struct jpeg_upsampler pub; /* public fields */
  154955. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154956. upsample1_ptr methods[MAX_COMPONENTS];
  154957. int next_row_out; /* counts rows emitted from color_buf */
  154958. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154959. int rowgroup_height[MAX_COMPONENTS];
  154960. UINT8 h_expand[MAX_COMPONENTS];
  154961. UINT8 v_expand[MAX_COMPONENTS];
  154962. } my_upsampler2;
  154963. typedef my_upsampler2 * my_upsample_ptr2;
  154964. METHODDEF(void)
  154965. start_pass_upsample (j_decompress_ptr cinfo)
  154966. {
  154967. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154968. upsample->next_row_out = cinfo->max_v_samp_factor;
  154969. upsample->rows_to_go = cinfo->output_height;
  154970. }
  154971. METHODDEF(void)
  154972. sep_upsample (j_decompress_ptr cinfo,
  154973. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154974. JDIMENSION in_row_groups_avail,
  154975. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154976. JDIMENSION out_rows_avail)
  154977. {
  154978. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154979. int ci;
  154980. jpeg_component_info * compptr;
  154981. JDIMENSION num_rows;
  154982. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154983. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154984. ci++, compptr++) {
  154985. (*upsample->methods[ci]) (cinfo, compptr,
  154986. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154987. upsample->color_buf + ci);
  154988. }
  154989. upsample->next_row_out = 0;
  154990. }
  154991. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154992. if (num_rows > upsample->rows_to_go)
  154993. num_rows = upsample->rows_to_go;
  154994. out_rows_avail -= *out_row_ctr;
  154995. if (num_rows > out_rows_avail)
  154996. num_rows = out_rows_avail;
  154997. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154998. (JDIMENSION) upsample->next_row_out,
  154999. output_buf + *out_row_ctr,
  155000. (int) num_rows);
  155001. *out_row_ctr += num_rows;
  155002. upsample->rows_to_go -= num_rows;
  155003. upsample->next_row_out += num_rows;
  155004. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  155005. (*in_row_group_ctr)++;
  155006. }
  155007. METHODDEF(void)
  155008. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155009. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155010. {
  155011. *output_data_ptr = input_data;
  155012. }
  155013. METHODDEF(void)
  155014. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155015. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155016. {
  155017. *output_data_ptr = NULL; /* safety check */
  155018. }
  155019. METHODDEF(void)
  155020. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155021. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155022. {
  155023. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155024. JSAMPARRAY output_data = *output_data_ptr;
  155025. register JSAMPROW inptr, outptr;
  155026. register JSAMPLE invalue;
  155027. register int h;
  155028. JSAMPROW outend;
  155029. int h_expand, v_expand;
  155030. int inrow, outrow;
  155031. h_expand = upsample->h_expand[compptr->component_index];
  155032. v_expand = upsample->v_expand[compptr->component_index];
  155033. inrow = outrow = 0;
  155034. while (outrow < cinfo->max_v_samp_factor) {
  155035. inptr = input_data[inrow];
  155036. outptr = output_data[outrow];
  155037. outend = outptr + cinfo->output_width;
  155038. while (outptr < outend) {
  155039. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155040. for (h = h_expand; h > 0; h--) {
  155041. *outptr++ = invalue;
  155042. }
  155043. }
  155044. if (v_expand > 1) {
  155045. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155046. v_expand-1, cinfo->output_width);
  155047. }
  155048. inrow++;
  155049. outrow += v_expand;
  155050. }
  155051. }
  155052. METHODDEF(void)
  155053. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155054. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155055. {
  155056. JSAMPARRAY output_data = *output_data_ptr;
  155057. register JSAMPROW inptr, outptr;
  155058. register JSAMPLE invalue;
  155059. JSAMPROW outend;
  155060. int inrow;
  155061. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155062. inptr = input_data[inrow];
  155063. outptr = output_data[inrow];
  155064. outend = outptr + cinfo->output_width;
  155065. while (outptr < outend) {
  155066. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155067. *outptr++ = invalue;
  155068. *outptr++ = invalue;
  155069. }
  155070. }
  155071. }
  155072. METHODDEF(void)
  155073. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155074. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155075. {
  155076. JSAMPARRAY output_data = *output_data_ptr;
  155077. register JSAMPROW inptr, outptr;
  155078. register JSAMPLE invalue;
  155079. JSAMPROW outend;
  155080. int inrow, outrow;
  155081. inrow = outrow = 0;
  155082. while (outrow < cinfo->max_v_samp_factor) {
  155083. inptr = input_data[inrow];
  155084. outptr = output_data[outrow];
  155085. outend = outptr + cinfo->output_width;
  155086. while (outptr < outend) {
  155087. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155088. *outptr++ = invalue;
  155089. *outptr++ = invalue;
  155090. }
  155091. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155092. 1, cinfo->output_width);
  155093. inrow++;
  155094. outrow += 2;
  155095. }
  155096. }
  155097. METHODDEF(void)
  155098. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155099. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155100. {
  155101. JSAMPARRAY output_data = *output_data_ptr;
  155102. register JSAMPROW inptr, outptr;
  155103. register int invalue;
  155104. register JDIMENSION colctr;
  155105. int inrow;
  155106. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155107. inptr = input_data[inrow];
  155108. outptr = output_data[inrow];
  155109. invalue = GETJSAMPLE(*inptr++);
  155110. *outptr++ = (JSAMPLE) invalue;
  155111. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  155112. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155113. invalue = GETJSAMPLE(*inptr++) * 3;
  155114. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  155115. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  155116. }
  155117. invalue = GETJSAMPLE(*inptr);
  155118. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  155119. *outptr++ = (JSAMPLE) invalue;
  155120. }
  155121. }
  155122. METHODDEF(void)
  155123. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155124. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155125. {
  155126. JSAMPARRAY output_data = *output_data_ptr;
  155127. register JSAMPROW inptr0, inptr1, outptr;
  155128. #if BITS_IN_JSAMPLE == 8
  155129. register int thiscolsum, lastcolsum, nextcolsum;
  155130. #else
  155131. register INT32 thiscolsum, lastcolsum, nextcolsum;
  155132. #endif
  155133. register JDIMENSION colctr;
  155134. int inrow, outrow, v;
  155135. inrow = outrow = 0;
  155136. while (outrow < cinfo->max_v_samp_factor) {
  155137. for (v = 0; v < 2; v++) {
  155138. inptr0 = input_data[inrow];
  155139. if (v == 0) /* next nearest is row above */
  155140. inptr1 = input_data[inrow-1];
  155141. else /* next nearest is row below */
  155142. inptr1 = input_data[inrow+1];
  155143. outptr = output_data[outrow++];
  155144. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155145. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155146. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  155147. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155148. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155149. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155150. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155151. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155152. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155153. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155154. }
  155155. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155156. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  155157. }
  155158. inrow++;
  155159. }
  155160. }
  155161. GLOBAL(void)
  155162. jinit_upsampler (j_decompress_ptr cinfo)
  155163. {
  155164. my_upsample_ptr2 upsample;
  155165. int ci;
  155166. jpeg_component_info * compptr;
  155167. boolean need_buffer, do_fancy;
  155168. int h_in_group, v_in_group, h_out_group, v_out_group;
  155169. upsample = (my_upsample_ptr2)
  155170. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155171. SIZEOF(my_upsampler2));
  155172. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  155173. upsample->pub.start_pass = start_pass_upsample;
  155174. upsample->pub.upsample = sep_upsample;
  155175. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  155176. if (cinfo->CCIR601_sampling) /* this isn't supported */
  155177. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  155178. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  155179. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155180. ci++, compptr++) {
  155181. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  155182. cinfo->min_DCT_scaled_size;
  155183. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  155184. cinfo->min_DCT_scaled_size;
  155185. h_out_group = cinfo->max_h_samp_factor;
  155186. v_out_group = cinfo->max_v_samp_factor;
  155187. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  155188. need_buffer = TRUE;
  155189. if (! compptr->component_needed) {
  155190. upsample->methods[ci] = noop_upsample;
  155191. need_buffer = FALSE;
  155192. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  155193. upsample->methods[ci] = fullsize_upsample;
  155194. need_buffer = FALSE;
  155195. } else if (h_in_group * 2 == h_out_group &&
  155196. v_in_group == v_out_group) {
  155197. if (do_fancy && compptr->downsampled_width > 2)
  155198. upsample->methods[ci] = h2v1_fancy_upsample;
  155199. else
  155200. upsample->methods[ci] = h2v1_upsample;
  155201. } else if (h_in_group * 2 == h_out_group &&
  155202. v_in_group * 2 == v_out_group) {
  155203. if (do_fancy && compptr->downsampled_width > 2) {
  155204. upsample->methods[ci] = h2v2_fancy_upsample;
  155205. upsample->pub.need_context_rows = TRUE;
  155206. } else
  155207. upsample->methods[ci] = h2v2_upsample;
  155208. } else if ((h_out_group % h_in_group) == 0 &&
  155209. (v_out_group % v_in_group) == 0) {
  155210. upsample->methods[ci] = int_upsample;
  155211. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  155212. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  155213. } else
  155214. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  155215. if (need_buffer) {
  155216. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  155217. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155218. (JDIMENSION) jround_up((long) cinfo->output_width,
  155219. (long) cinfo->max_h_samp_factor),
  155220. (JDIMENSION) cinfo->max_v_samp_factor);
  155221. }
  155222. }
  155223. }
  155224. /*** End of inlined file: jdsample.c ***/
  155225. /*** Start of inlined file: jdtrans.c ***/
  155226. #define JPEG_INTERNALS
  155227. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  155228. GLOBAL(jvirt_barray_ptr *)
  155229. jpeg_read_coefficients (j_decompress_ptr cinfo)
  155230. {
  155231. if (cinfo->global_state == DSTATE_READY) {
  155232. transdecode_master_selection(cinfo);
  155233. cinfo->global_state = DSTATE_RDCOEFS;
  155234. }
  155235. if (cinfo->global_state == DSTATE_RDCOEFS) {
  155236. for (;;) {
  155237. int retcode;
  155238. if (cinfo->progress != NULL)
  155239. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  155240. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  155241. if (retcode == JPEG_SUSPENDED)
  155242. return NULL;
  155243. if (retcode == JPEG_REACHED_EOI)
  155244. break;
  155245. if (cinfo->progress != NULL &&
  155246. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  155247. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  155248. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  155249. }
  155250. }
  155251. }
  155252. cinfo->global_state = DSTATE_STOPPING;
  155253. }
  155254. if ((cinfo->global_state == DSTATE_STOPPING ||
  155255. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  155256. return cinfo->coef->coef_arrays;
  155257. }
  155258. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  155259. return NULL; /* keep compiler happy */
  155260. }
  155261. LOCAL(void)
  155262. transdecode_master_selection (j_decompress_ptr cinfo)
  155263. {
  155264. cinfo->buffered_image = TRUE;
  155265. if (cinfo->arith_code) {
  155266. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  155267. } else {
  155268. if (cinfo->progressive_mode) {
  155269. #ifdef D_PROGRESSIVE_SUPPORTED
  155270. jinit_phuff_decoder(cinfo);
  155271. #else
  155272. ERREXIT(cinfo, JERR_NOT_COMPILED);
  155273. #endif
  155274. } else
  155275. jinit_huff_decoder(cinfo);
  155276. }
  155277. jinit_d_coef_controller(cinfo, TRUE);
  155278. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  155279. (*cinfo->inputctl->start_input_pass) (cinfo);
  155280. if (cinfo->progress != NULL) {
  155281. int nscans;
  155282. if (cinfo->progressive_mode) {
  155283. nscans = 2 + 3 * cinfo->num_components;
  155284. } else if (cinfo->inputctl->has_multiple_scans) {
  155285. nscans = cinfo->num_components;
  155286. } else {
  155287. nscans = 1;
  155288. }
  155289. cinfo->progress->pass_counter = 0L;
  155290. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  155291. cinfo->progress->completed_passes = 0;
  155292. cinfo->progress->total_passes = 1;
  155293. }
  155294. }
  155295. /*** End of inlined file: jdtrans.c ***/
  155296. /*** Start of inlined file: jfdctflt.c ***/
  155297. #define JPEG_INTERNALS
  155298. #ifdef DCT_FLOAT_SUPPORTED
  155299. #if DCTSIZE != 8
  155300. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155301. #endif
  155302. GLOBAL(void)
  155303. jpeg_fdct_float (FAST_FLOAT * data)
  155304. {
  155305. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155306. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155307. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155308. FAST_FLOAT *dataptr;
  155309. int ctr;
  155310. dataptr = data;
  155311. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155312. tmp0 = dataptr[0] + dataptr[7];
  155313. tmp7 = dataptr[0] - dataptr[7];
  155314. tmp1 = dataptr[1] + dataptr[6];
  155315. tmp6 = dataptr[1] - dataptr[6];
  155316. tmp2 = dataptr[2] + dataptr[5];
  155317. tmp5 = dataptr[2] - dataptr[5];
  155318. tmp3 = dataptr[3] + dataptr[4];
  155319. tmp4 = dataptr[3] - dataptr[4];
  155320. tmp10 = tmp0 + tmp3; /* phase 2 */
  155321. tmp13 = tmp0 - tmp3;
  155322. tmp11 = tmp1 + tmp2;
  155323. tmp12 = tmp1 - tmp2;
  155324. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155325. dataptr[4] = tmp10 - tmp11;
  155326. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155327. dataptr[2] = tmp13 + z1; /* phase 5 */
  155328. dataptr[6] = tmp13 - z1;
  155329. tmp10 = tmp4 + tmp5; /* phase 2 */
  155330. tmp11 = tmp5 + tmp6;
  155331. tmp12 = tmp6 + tmp7;
  155332. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155333. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155334. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155335. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155336. z11 = tmp7 + z3; /* phase 5 */
  155337. z13 = tmp7 - z3;
  155338. dataptr[5] = z13 + z2; /* phase 6 */
  155339. dataptr[3] = z13 - z2;
  155340. dataptr[1] = z11 + z4;
  155341. dataptr[7] = z11 - z4;
  155342. dataptr += DCTSIZE; /* advance pointer to next row */
  155343. }
  155344. dataptr = data;
  155345. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155346. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155347. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155348. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155349. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155350. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155351. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155352. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155353. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155354. tmp10 = tmp0 + tmp3; /* phase 2 */
  155355. tmp13 = tmp0 - tmp3;
  155356. tmp11 = tmp1 + tmp2;
  155357. tmp12 = tmp1 - tmp2;
  155358. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155359. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155360. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155361. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155362. dataptr[DCTSIZE*6] = tmp13 - z1;
  155363. tmp10 = tmp4 + tmp5; /* phase 2 */
  155364. tmp11 = tmp5 + tmp6;
  155365. tmp12 = tmp6 + tmp7;
  155366. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155367. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155368. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155369. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155370. z11 = tmp7 + z3; /* phase 5 */
  155371. z13 = tmp7 - z3;
  155372. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155373. dataptr[DCTSIZE*3] = z13 - z2;
  155374. dataptr[DCTSIZE*1] = z11 + z4;
  155375. dataptr[DCTSIZE*7] = z11 - z4;
  155376. dataptr++; /* advance pointer to next column */
  155377. }
  155378. }
  155379. #endif /* DCT_FLOAT_SUPPORTED */
  155380. /*** End of inlined file: jfdctflt.c ***/
  155381. /*** Start of inlined file: jfdctint.c ***/
  155382. #define JPEG_INTERNALS
  155383. #ifdef DCT_ISLOW_SUPPORTED
  155384. #if DCTSIZE != 8
  155385. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155386. #endif
  155387. #if BITS_IN_JSAMPLE == 8
  155388. #define CONST_BITS 13
  155389. #define PASS1_BITS 2
  155390. #else
  155391. #define CONST_BITS 13
  155392. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155393. #endif
  155394. #if CONST_BITS == 13
  155395. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155396. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155397. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155398. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155399. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155400. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155401. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155402. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155403. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155404. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155405. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155406. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155407. #else
  155408. #define FIX_0_298631336 FIX(0.298631336)
  155409. #define FIX_0_390180644 FIX(0.390180644)
  155410. #define FIX_0_541196100 FIX(0.541196100)
  155411. #define FIX_0_765366865 FIX(0.765366865)
  155412. #define FIX_0_899976223 FIX(0.899976223)
  155413. #define FIX_1_175875602 FIX(1.175875602)
  155414. #define FIX_1_501321110 FIX(1.501321110)
  155415. #define FIX_1_847759065 FIX(1.847759065)
  155416. #define FIX_1_961570560 FIX(1.961570560)
  155417. #define FIX_2_053119869 FIX(2.053119869)
  155418. #define FIX_2_562915447 FIX(2.562915447)
  155419. #define FIX_3_072711026 FIX(3.072711026)
  155420. #endif
  155421. #if BITS_IN_JSAMPLE == 8
  155422. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155423. #else
  155424. #define MULTIPLY(var,const) ((var) * (const))
  155425. #endif
  155426. GLOBAL(void)
  155427. jpeg_fdct_islow (DCTELEM * data)
  155428. {
  155429. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155430. INT32 tmp10, tmp11, tmp12, tmp13;
  155431. INT32 z1, z2, z3, z4, z5;
  155432. DCTELEM *dataptr;
  155433. int ctr;
  155434. SHIFT_TEMPS
  155435. dataptr = data;
  155436. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155437. tmp0 = dataptr[0] + dataptr[7];
  155438. tmp7 = dataptr[0] - dataptr[7];
  155439. tmp1 = dataptr[1] + dataptr[6];
  155440. tmp6 = dataptr[1] - dataptr[6];
  155441. tmp2 = dataptr[2] + dataptr[5];
  155442. tmp5 = dataptr[2] - dataptr[5];
  155443. tmp3 = dataptr[3] + dataptr[4];
  155444. tmp4 = dataptr[3] - dataptr[4];
  155445. tmp10 = tmp0 + tmp3;
  155446. tmp13 = tmp0 - tmp3;
  155447. tmp11 = tmp1 + tmp2;
  155448. tmp12 = tmp1 - tmp2;
  155449. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155450. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155451. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155452. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155453. CONST_BITS-PASS1_BITS);
  155454. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155455. CONST_BITS-PASS1_BITS);
  155456. z1 = tmp4 + tmp7;
  155457. z2 = tmp5 + tmp6;
  155458. z3 = tmp4 + tmp6;
  155459. z4 = tmp5 + tmp7;
  155460. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155461. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155462. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155463. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155464. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155465. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155466. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155467. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155468. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155469. z3 += z5;
  155470. z4 += z5;
  155471. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155472. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155473. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155474. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155475. dataptr += DCTSIZE; /* advance pointer to next row */
  155476. }
  155477. dataptr = data;
  155478. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155479. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155480. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155481. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155482. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155483. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155484. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155485. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155486. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155487. tmp10 = tmp0 + tmp3;
  155488. tmp13 = tmp0 - tmp3;
  155489. tmp11 = tmp1 + tmp2;
  155490. tmp12 = tmp1 - tmp2;
  155491. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155492. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155493. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155494. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155495. CONST_BITS+PASS1_BITS);
  155496. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155497. CONST_BITS+PASS1_BITS);
  155498. z1 = tmp4 + tmp7;
  155499. z2 = tmp5 + tmp6;
  155500. z3 = tmp4 + tmp6;
  155501. z4 = tmp5 + tmp7;
  155502. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155503. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155504. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155505. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155506. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155507. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155508. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155509. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155510. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155511. z3 += z5;
  155512. z4 += z5;
  155513. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155514. CONST_BITS+PASS1_BITS);
  155515. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155516. CONST_BITS+PASS1_BITS);
  155517. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155518. CONST_BITS+PASS1_BITS);
  155519. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155520. CONST_BITS+PASS1_BITS);
  155521. dataptr++; /* advance pointer to next column */
  155522. }
  155523. }
  155524. #endif /* DCT_ISLOW_SUPPORTED */
  155525. /*** End of inlined file: jfdctint.c ***/
  155526. #undef CONST_BITS
  155527. #undef MULTIPLY
  155528. #undef FIX_0_541196100
  155529. /*** Start of inlined file: jfdctfst.c ***/
  155530. #define JPEG_INTERNALS
  155531. #ifdef DCT_IFAST_SUPPORTED
  155532. #if DCTSIZE != 8
  155533. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155534. #endif
  155535. #define CONST_BITS 8
  155536. #if CONST_BITS == 8
  155537. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155538. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155539. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155540. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155541. #else
  155542. #define FIX_0_382683433 FIX(0.382683433)
  155543. #define FIX_0_541196100 FIX(0.541196100)
  155544. #define FIX_0_707106781 FIX(0.707106781)
  155545. #define FIX_1_306562965 FIX(1.306562965)
  155546. #endif
  155547. #ifndef USE_ACCURATE_ROUNDING
  155548. #undef DESCALE
  155549. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155550. #endif
  155551. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155552. GLOBAL(void)
  155553. jpeg_fdct_ifast (DCTELEM * data)
  155554. {
  155555. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155556. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155557. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155558. DCTELEM *dataptr;
  155559. int ctr;
  155560. SHIFT_TEMPS
  155561. dataptr = data;
  155562. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155563. tmp0 = dataptr[0] + dataptr[7];
  155564. tmp7 = dataptr[0] - dataptr[7];
  155565. tmp1 = dataptr[1] + dataptr[6];
  155566. tmp6 = dataptr[1] - dataptr[6];
  155567. tmp2 = dataptr[2] + dataptr[5];
  155568. tmp5 = dataptr[2] - dataptr[5];
  155569. tmp3 = dataptr[3] + dataptr[4];
  155570. tmp4 = dataptr[3] - dataptr[4];
  155571. tmp10 = tmp0 + tmp3; /* phase 2 */
  155572. tmp13 = tmp0 - tmp3;
  155573. tmp11 = tmp1 + tmp2;
  155574. tmp12 = tmp1 - tmp2;
  155575. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155576. dataptr[4] = tmp10 - tmp11;
  155577. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155578. dataptr[2] = tmp13 + z1; /* phase 5 */
  155579. dataptr[6] = tmp13 - z1;
  155580. tmp10 = tmp4 + tmp5; /* phase 2 */
  155581. tmp11 = tmp5 + tmp6;
  155582. tmp12 = tmp6 + tmp7;
  155583. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155584. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155585. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155586. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155587. z11 = tmp7 + z3; /* phase 5 */
  155588. z13 = tmp7 - z3;
  155589. dataptr[5] = z13 + z2; /* phase 6 */
  155590. dataptr[3] = z13 - z2;
  155591. dataptr[1] = z11 + z4;
  155592. dataptr[7] = z11 - z4;
  155593. dataptr += DCTSIZE; /* advance pointer to next row */
  155594. }
  155595. dataptr = data;
  155596. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155597. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155598. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155599. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155600. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155601. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155602. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155603. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155604. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155605. tmp10 = tmp0 + tmp3; /* phase 2 */
  155606. tmp13 = tmp0 - tmp3;
  155607. tmp11 = tmp1 + tmp2;
  155608. tmp12 = tmp1 - tmp2;
  155609. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155610. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155611. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155612. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155613. dataptr[DCTSIZE*6] = tmp13 - z1;
  155614. tmp10 = tmp4 + tmp5; /* phase 2 */
  155615. tmp11 = tmp5 + tmp6;
  155616. tmp12 = tmp6 + tmp7;
  155617. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155618. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155619. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155620. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155621. z11 = tmp7 + z3; /* phase 5 */
  155622. z13 = tmp7 - z3;
  155623. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155624. dataptr[DCTSIZE*3] = z13 - z2;
  155625. dataptr[DCTSIZE*1] = z11 + z4;
  155626. dataptr[DCTSIZE*7] = z11 - z4;
  155627. dataptr++; /* advance pointer to next column */
  155628. }
  155629. }
  155630. #endif /* DCT_IFAST_SUPPORTED */
  155631. /*** End of inlined file: jfdctfst.c ***/
  155632. #undef FIX_0_541196100
  155633. /*** Start of inlined file: jidctflt.c ***/
  155634. #define JPEG_INTERNALS
  155635. #ifdef DCT_FLOAT_SUPPORTED
  155636. #if DCTSIZE != 8
  155637. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155638. #endif
  155639. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155640. GLOBAL(void)
  155641. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155642. JCOEFPTR coef_block,
  155643. JSAMPARRAY output_buf, JDIMENSION output_col)
  155644. {
  155645. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155646. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155647. FAST_FLOAT z5, z10, z11, z12, z13;
  155648. JCOEFPTR inptr;
  155649. FLOAT_MULT_TYPE * quantptr;
  155650. FAST_FLOAT * wsptr;
  155651. JSAMPROW outptr;
  155652. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155653. int ctr;
  155654. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155655. SHIFT_TEMPS
  155656. inptr = coef_block;
  155657. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155658. wsptr = workspace;
  155659. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155660. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155661. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155662. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155663. inptr[DCTSIZE*7] == 0) {
  155664. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155665. wsptr[DCTSIZE*0] = dcval;
  155666. wsptr[DCTSIZE*1] = dcval;
  155667. wsptr[DCTSIZE*2] = dcval;
  155668. wsptr[DCTSIZE*3] = dcval;
  155669. wsptr[DCTSIZE*4] = dcval;
  155670. wsptr[DCTSIZE*5] = dcval;
  155671. wsptr[DCTSIZE*6] = dcval;
  155672. wsptr[DCTSIZE*7] = dcval;
  155673. inptr++; /* advance pointers to next column */
  155674. quantptr++;
  155675. wsptr++;
  155676. continue;
  155677. }
  155678. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155679. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155680. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155681. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155682. tmp10 = tmp0 + tmp2; /* phase 3 */
  155683. tmp11 = tmp0 - tmp2;
  155684. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155685. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155686. tmp0 = tmp10 + tmp13; /* phase 2 */
  155687. tmp3 = tmp10 - tmp13;
  155688. tmp1 = tmp11 + tmp12;
  155689. tmp2 = tmp11 - tmp12;
  155690. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155691. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155692. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155693. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155694. z13 = tmp6 + tmp5; /* phase 6 */
  155695. z10 = tmp6 - tmp5;
  155696. z11 = tmp4 + tmp7;
  155697. z12 = tmp4 - tmp7;
  155698. tmp7 = z11 + z13; /* phase 5 */
  155699. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155700. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155701. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155702. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155703. tmp6 = tmp12 - tmp7; /* phase 2 */
  155704. tmp5 = tmp11 - tmp6;
  155705. tmp4 = tmp10 + tmp5;
  155706. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155707. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155708. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155709. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155710. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155711. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155712. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155713. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155714. inptr++; /* advance pointers to next column */
  155715. quantptr++;
  155716. wsptr++;
  155717. }
  155718. wsptr = workspace;
  155719. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155720. outptr = output_buf[ctr] + output_col;
  155721. tmp10 = wsptr[0] + wsptr[4];
  155722. tmp11 = wsptr[0] - wsptr[4];
  155723. tmp13 = wsptr[2] + wsptr[6];
  155724. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155725. tmp0 = tmp10 + tmp13;
  155726. tmp3 = tmp10 - tmp13;
  155727. tmp1 = tmp11 + tmp12;
  155728. tmp2 = tmp11 - tmp12;
  155729. z13 = wsptr[5] + wsptr[3];
  155730. z10 = wsptr[5] - wsptr[3];
  155731. z11 = wsptr[1] + wsptr[7];
  155732. z12 = wsptr[1] - wsptr[7];
  155733. tmp7 = z11 + z13;
  155734. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155735. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155736. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155737. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155738. tmp6 = tmp12 - tmp7;
  155739. tmp5 = tmp11 - tmp6;
  155740. tmp4 = tmp10 + tmp5;
  155741. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155742. & RANGE_MASK];
  155743. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155744. & RANGE_MASK];
  155745. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155746. & RANGE_MASK];
  155747. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155748. & RANGE_MASK];
  155749. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155750. & RANGE_MASK];
  155751. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155752. & RANGE_MASK];
  155753. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155754. & RANGE_MASK];
  155755. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155756. & RANGE_MASK];
  155757. wsptr += DCTSIZE; /* advance pointer to next row */
  155758. }
  155759. }
  155760. #endif /* DCT_FLOAT_SUPPORTED */
  155761. /*** End of inlined file: jidctflt.c ***/
  155762. #undef CONST_BITS
  155763. #undef FIX_1_847759065
  155764. #undef MULTIPLY
  155765. #undef DEQUANTIZE
  155766. #undef DESCALE
  155767. /*** Start of inlined file: jidctfst.c ***/
  155768. #define JPEG_INTERNALS
  155769. #ifdef DCT_IFAST_SUPPORTED
  155770. #if DCTSIZE != 8
  155771. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155772. #endif
  155773. #if BITS_IN_JSAMPLE == 8
  155774. #define CONST_BITS 8
  155775. #define PASS1_BITS 2
  155776. #else
  155777. #define CONST_BITS 8
  155778. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155779. #endif
  155780. #if CONST_BITS == 8
  155781. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155782. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155783. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155784. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155785. #else
  155786. #define FIX_1_082392200 FIX(1.082392200)
  155787. #define FIX_1_414213562 FIX(1.414213562)
  155788. #define FIX_1_847759065 FIX(1.847759065)
  155789. #define FIX_2_613125930 FIX(2.613125930)
  155790. #endif
  155791. #ifndef USE_ACCURATE_ROUNDING
  155792. #undef DESCALE
  155793. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155794. #endif
  155795. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155796. #if BITS_IN_JSAMPLE == 8
  155797. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155798. #else
  155799. #define DEQUANTIZE(coef,quantval) \
  155800. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155801. #endif
  155802. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155803. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155804. #if BITS_IN_JSAMPLE == 8
  155805. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155806. #else
  155807. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155808. #endif
  155809. #define IRIGHT_SHIFT(x,shft) \
  155810. ((ishift_temp = (x)) < 0 ? \
  155811. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155812. (ishift_temp >> (shft)))
  155813. #else
  155814. #define ISHIFT_TEMPS
  155815. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155816. #endif
  155817. #ifdef USE_ACCURATE_ROUNDING
  155818. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155819. #else
  155820. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155821. #endif
  155822. GLOBAL(void)
  155823. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155824. JCOEFPTR coef_block,
  155825. JSAMPARRAY output_buf, JDIMENSION output_col)
  155826. {
  155827. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155828. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155829. DCTELEM z5, z10, z11, z12, z13;
  155830. JCOEFPTR inptr;
  155831. IFAST_MULT_TYPE * quantptr;
  155832. int * wsptr;
  155833. JSAMPROW outptr;
  155834. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155835. int ctr;
  155836. int workspace[DCTSIZE2]; /* buffers data between passes */
  155837. SHIFT_TEMPS /* for DESCALE */
  155838. ISHIFT_TEMPS /* for IDESCALE */
  155839. inptr = coef_block;
  155840. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155841. wsptr = workspace;
  155842. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155843. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155844. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155845. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155846. inptr[DCTSIZE*7] == 0) {
  155847. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155848. wsptr[DCTSIZE*0] = dcval;
  155849. wsptr[DCTSIZE*1] = dcval;
  155850. wsptr[DCTSIZE*2] = dcval;
  155851. wsptr[DCTSIZE*3] = dcval;
  155852. wsptr[DCTSIZE*4] = dcval;
  155853. wsptr[DCTSIZE*5] = dcval;
  155854. wsptr[DCTSIZE*6] = dcval;
  155855. wsptr[DCTSIZE*7] = dcval;
  155856. inptr++; /* advance pointers to next column */
  155857. quantptr++;
  155858. wsptr++;
  155859. continue;
  155860. }
  155861. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155862. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155863. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155864. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155865. tmp10 = tmp0 + tmp2; /* phase 3 */
  155866. tmp11 = tmp0 - tmp2;
  155867. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155868. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155869. tmp0 = tmp10 + tmp13; /* phase 2 */
  155870. tmp3 = tmp10 - tmp13;
  155871. tmp1 = tmp11 + tmp12;
  155872. tmp2 = tmp11 - tmp12;
  155873. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155874. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155875. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155876. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155877. z13 = tmp6 + tmp5; /* phase 6 */
  155878. z10 = tmp6 - tmp5;
  155879. z11 = tmp4 + tmp7;
  155880. z12 = tmp4 - tmp7;
  155881. tmp7 = z11 + z13; /* phase 5 */
  155882. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155883. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155884. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155885. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155886. tmp6 = tmp12 - tmp7; /* phase 2 */
  155887. tmp5 = tmp11 - tmp6;
  155888. tmp4 = tmp10 + tmp5;
  155889. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155890. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155891. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155892. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155893. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155894. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155895. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155896. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155897. inptr++; /* advance pointers to next column */
  155898. quantptr++;
  155899. wsptr++;
  155900. }
  155901. wsptr = workspace;
  155902. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155903. outptr = output_buf[ctr] + output_col;
  155904. #ifndef NO_ZERO_ROW_TEST
  155905. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155906. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155907. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155908. & RANGE_MASK];
  155909. outptr[0] = dcval;
  155910. outptr[1] = dcval;
  155911. outptr[2] = dcval;
  155912. outptr[3] = dcval;
  155913. outptr[4] = dcval;
  155914. outptr[5] = dcval;
  155915. outptr[6] = dcval;
  155916. outptr[7] = dcval;
  155917. wsptr += DCTSIZE; /* advance pointer to next row */
  155918. continue;
  155919. }
  155920. #endif
  155921. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155922. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155923. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155924. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155925. - tmp13;
  155926. tmp0 = tmp10 + tmp13;
  155927. tmp3 = tmp10 - tmp13;
  155928. tmp1 = tmp11 + tmp12;
  155929. tmp2 = tmp11 - tmp12;
  155930. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155931. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155932. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155933. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155934. tmp7 = z11 + z13; /* phase 5 */
  155935. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155936. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155937. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155938. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155939. tmp6 = tmp12 - tmp7; /* phase 2 */
  155940. tmp5 = tmp11 - tmp6;
  155941. tmp4 = tmp10 + tmp5;
  155942. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155943. & RANGE_MASK];
  155944. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155945. & RANGE_MASK];
  155946. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155947. & RANGE_MASK];
  155948. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155949. & RANGE_MASK];
  155950. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155951. & RANGE_MASK];
  155952. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155953. & RANGE_MASK];
  155954. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155955. & RANGE_MASK];
  155956. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155957. & RANGE_MASK];
  155958. wsptr += DCTSIZE; /* advance pointer to next row */
  155959. }
  155960. }
  155961. #endif /* DCT_IFAST_SUPPORTED */
  155962. /*** End of inlined file: jidctfst.c ***/
  155963. #undef CONST_BITS
  155964. #undef FIX_1_847759065
  155965. #undef MULTIPLY
  155966. #undef DEQUANTIZE
  155967. /*** Start of inlined file: jidctint.c ***/
  155968. #define JPEG_INTERNALS
  155969. #ifdef DCT_ISLOW_SUPPORTED
  155970. #if DCTSIZE != 8
  155971. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155972. #endif
  155973. #if BITS_IN_JSAMPLE == 8
  155974. #define CONST_BITS 13
  155975. #define PASS1_BITS 2
  155976. #else
  155977. #define CONST_BITS 13
  155978. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155979. #endif
  155980. #if CONST_BITS == 13
  155981. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155982. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155983. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155984. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155985. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155986. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155987. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155988. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155989. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155990. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155991. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155992. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155993. #else
  155994. #define FIX_0_298631336 FIX(0.298631336)
  155995. #define FIX_0_390180644 FIX(0.390180644)
  155996. #define FIX_0_541196100 FIX(0.541196100)
  155997. #define FIX_0_765366865 FIX(0.765366865)
  155998. #define FIX_0_899976223 FIX(0.899976223)
  155999. #define FIX_1_175875602 FIX(1.175875602)
  156000. #define FIX_1_501321110 FIX(1.501321110)
  156001. #define FIX_1_847759065 FIX(1.847759065)
  156002. #define FIX_1_961570560 FIX(1.961570560)
  156003. #define FIX_2_053119869 FIX(2.053119869)
  156004. #define FIX_2_562915447 FIX(2.562915447)
  156005. #define FIX_3_072711026 FIX(3.072711026)
  156006. #endif
  156007. #if BITS_IN_JSAMPLE == 8
  156008. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156009. #else
  156010. #define MULTIPLY(var,const) ((var) * (const))
  156011. #endif
  156012. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156013. GLOBAL(void)
  156014. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156015. JCOEFPTR coef_block,
  156016. JSAMPARRAY output_buf, JDIMENSION output_col)
  156017. {
  156018. INT32 tmp0, tmp1, tmp2, tmp3;
  156019. INT32 tmp10, tmp11, tmp12, tmp13;
  156020. INT32 z1, z2, z3, z4, z5;
  156021. JCOEFPTR inptr;
  156022. ISLOW_MULT_TYPE * quantptr;
  156023. int * wsptr;
  156024. JSAMPROW outptr;
  156025. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156026. int ctr;
  156027. int workspace[DCTSIZE2]; /* buffers data between passes */
  156028. SHIFT_TEMPS
  156029. inptr = coef_block;
  156030. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156031. wsptr = workspace;
  156032. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156033. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156034. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156035. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156036. inptr[DCTSIZE*7] == 0) {
  156037. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156038. wsptr[DCTSIZE*0] = dcval;
  156039. wsptr[DCTSIZE*1] = dcval;
  156040. wsptr[DCTSIZE*2] = dcval;
  156041. wsptr[DCTSIZE*3] = dcval;
  156042. wsptr[DCTSIZE*4] = dcval;
  156043. wsptr[DCTSIZE*5] = dcval;
  156044. wsptr[DCTSIZE*6] = dcval;
  156045. wsptr[DCTSIZE*7] = dcval;
  156046. inptr++; /* advance pointers to next column */
  156047. quantptr++;
  156048. wsptr++;
  156049. continue;
  156050. }
  156051. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156052. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156053. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156054. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156055. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156056. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156057. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156058. tmp0 = (z2 + z3) << CONST_BITS;
  156059. tmp1 = (z2 - z3) << CONST_BITS;
  156060. tmp10 = tmp0 + tmp3;
  156061. tmp13 = tmp0 - tmp3;
  156062. tmp11 = tmp1 + tmp2;
  156063. tmp12 = tmp1 - tmp2;
  156064. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156065. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156066. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156067. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156068. z1 = tmp0 + tmp3;
  156069. z2 = tmp1 + tmp2;
  156070. z3 = tmp0 + tmp2;
  156071. z4 = tmp1 + tmp3;
  156072. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156073. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156074. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156075. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156076. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156077. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156078. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156079. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156080. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156081. z3 += z5;
  156082. z4 += z5;
  156083. tmp0 += z1 + z3;
  156084. tmp1 += z2 + z4;
  156085. tmp2 += z2 + z3;
  156086. tmp3 += z1 + z4;
  156087. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  156088. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  156089. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  156090. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  156091. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  156092. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  156093. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  156094. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  156095. inptr++; /* advance pointers to next column */
  156096. quantptr++;
  156097. wsptr++;
  156098. }
  156099. wsptr = workspace;
  156100. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156101. outptr = output_buf[ctr] + output_col;
  156102. #ifndef NO_ZERO_ROW_TEST
  156103. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156104. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156105. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156106. & RANGE_MASK];
  156107. outptr[0] = dcval;
  156108. outptr[1] = dcval;
  156109. outptr[2] = dcval;
  156110. outptr[3] = dcval;
  156111. outptr[4] = dcval;
  156112. outptr[5] = dcval;
  156113. outptr[6] = dcval;
  156114. outptr[7] = dcval;
  156115. wsptr += DCTSIZE; /* advance pointer to next row */
  156116. continue;
  156117. }
  156118. #endif
  156119. z2 = (INT32) wsptr[2];
  156120. z3 = (INT32) wsptr[6];
  156121. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156122. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156123. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156124. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  156125. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  156126. tmp10 = tmp0 + tmp3;
  156127. tmp13 = tmp0 - tmp3;
  156128. tmp11 = tmp1 + tmp2;
  156129. tmp12 = tmp1 - tmp2;
  156130. tmp0 = (INT32) wsptr[7];
  156131. tmp1 = (INT32) wsptr[5];
  156132. tmp2 = (INT32) wsptr[3];
  156133. tmp3 = (INT32) wsptr[1];
  156134. z1 = tmp0 + tmp3;
  156135. z2 = tmp1 + tmp2;
  156136. z3 = tmp0 + tmp2;
  156137. z4 = tmp1 + tmp3;
  156138. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156139. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156140. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156141. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156142. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156143. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156144. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156145. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156146. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156147. z3 += z5;
  156148. z4 += z5;
  156149. tmp0 += z1 + z3;
  156150. tmp1 += z2 + z4;
  156151. tmp2 += z2 + z3;
  156152. tmp3 += z1 + z4;
  156153. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  156154. CONST_BITS+PASS1_BITS+3)
  156155. & RANGE_MASK];
  156156. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  156157. CONST_BITS+PASS1_BITS+3)
  156158. & RANGE_MASK];
  156159. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  156160. CONST_BITS+PASS1_BITS+3)
  156161. & RANGE_MASK];
  156162. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  156163. CONST_BITS+PASS1_BITS+3)
  156164. & RANGE_MASK];
  156165. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  156166. CONST_BITS+PASS1_BITS+3)
  156167. & RANGE_MASK];
  156168. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  156169. CONST_BITS+PASS1_BITS+3)
  156170. & RANGE_MASK];
  156171. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  156172. CONST_BITS+PASS1_BITS+3)
  156173. & RANGE_MASK];
  156174. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  156175. CONST_BITS+PASS1_BITS+3)
  156176. & RANGE_MASK];
  156177. wsptr += DCTSIZE; /* advance pointer to next row */
  156178. }
  156179. }
  156180. #endif /* DCT_ISLOW_SUPPORTED */
  156181. /*** End of inlined file: jidctint.c ***/
  156182. /*** Start of inlined file: jidctred.c ***/
  156183. #define JPEG_INTERNALS
  156184. #ifdef IDCT_SCALING_SUPPORTED
  156185. #if DCTSIZE != 8
  156186. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156187. #endif
  156188. #if BITS_IN_JSAMPLE == 8
  156189. #define CONST_BITS 13
  156190. #define PASS1_BITS 2
  156191. #else
  156192. #define CONST_BITS 13
  156193. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156194. #endif
  156195. #if CONST_BITS == 13
  156196. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  156197. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  156198. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  156199. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  156200. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156201. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  156202. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156203. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  156204. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  156205. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  156206. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156207. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  156208. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156209. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  156210. #else
  156211. #define FIX_0_211164243 FIX(0.211164243)
  156212. #define FIX_0_509795579 FIX(0.509795579)
  156213. #define FIX_0_601344887 FIX(0.601344887)
  156214. #define FIX_0_720959822 FIX(0.720959822)
  156215. #define FIX_0_765366865 FIX(0.765366865)
  156216. #define FIX_0_850430095 FIX(0.850430095)
  156217. #define FIX_0_899976223 FIX(0.899976223)
  156218. #define FIX_1_061594337 FIX(1.061594337)
  156219. #define FIX_1_272758580 FIX(1.272758580)
  156220. #define FIX_1_451774981 FIX(1.451774981)
  156221. #define FIX_1_847759065 FIX(1.847759065)
  156222. #define FIX_2_172734803 FIX(2.172734803)
  156223. #define FIX_2_562915447 FIX(2.562915447)
  156224. #define FIX_3_624509785 FIX(3.624509785)
  156225. #endif
  156226. #if BITS_IN_JSAMPLE == 8
  156227. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156228. #else
  156229. #define MULTIPLY(var,const) ((var) * (const))
  156230. #endif
  156231. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156232. GLOBAL(void)
  156233. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156234. JCOEFPTR coef_block,
  156235. JSAMPARRAY output_buf, JDIMENSION output_col)
  156236. {
  156237. INT32 tmp0, tmp2, tmp10, tmp12;
  156238. INT32 z1, z2, z3, z4;
  156239. JCOEFPTR inptr;
  156240. ISLOW_MULT_TYPE * quantptr;
  156241. int * wsptr;
  156242. JSAMPROW outptr;
  156243. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156244. int ctr;
  156245. int workspace[DCTSIZE*4]; /* buffers data between passes */
  156246. SHIFT_TEMPS
  156247. inptr = coef_block;
  156248. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156249. wsptr = workspace;
  156250. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156251. if (ctr == DCTSIZE-4)
  156252. continue;
  156253. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156254. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  156255. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  156256. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156257. wsptr[DCTSIZE*0] = dcval;
  156258. wsptr[DCTSIZE*1] = dcval;
  156259. wsptr[DCTSIZE*2] = dcval;
  156260. wsptr[DCTSIZE*3] = dcval;
  156261. continue;
  156262. }
  156263. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156264. tmp0 <<= (CONST_BITS+1);
  156265. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156266. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156267. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  156268. tmp10 = tmp0 + tmp2;
  156269. tmp12 = tmp0 - tmp2;
  156270. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156271. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156272. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156273. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156274. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156275. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156276. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156277. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156278. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156279. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156280. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156281. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156282. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  156283. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  156284. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  156285. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  156286. }
  156287. wsptr = workspace;
  156288. for (ctr = 0; ctr < 4; ctr++) {
  156289. outptr = output_buf[ctr] + output_col;
  156290. #ifndef NO_ZERO_ROW_TEST
  156291. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  156292. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156293. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156294. & RANGE_MASK];
  156295. outptr[0] = dcval;
  156296. outptr[1] = dcval;
  156297. outptr[2] = dcval;
  156298. outptr[3] = dcval;
  156299. wsptr += DCTSIZE; /* advance pointer to next row */
  156300. continue;
  156301. }
  156302. #endif
  156303. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  156304. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156305. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156306. tmp10 = tmp0 + tmp2;
  156307. tmp12 = tmp0 - tmp2;
  156308. z1 = (INT32) wsptr[7];
  156309. z2 = (INT32) wsptr[5];
  156310. z3 = (INT32) wsptr[3];
  156311. z4 = (INT32) wsptr[1];
  156312. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156313. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156314. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156315. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156316. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156317. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156318. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156319. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156320. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156321. CONST_BITS+PASS1_BITS+3+1)
  156322. & RANGE_MASK];
  156323. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156324. CONST_BITS+PASS1_BITS+3+1)
  156325. & RANGE_MASK];
  156326. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156327. CONST_BITS+PASS1_BITS+3+1)
  156328. & RANGE_MASK];
  156329. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156330. CONST_BITS+PASS1_BITS+3+1)
  156331. & RANGE_MASK];
  156332. wsptr += DCTSIZE; /* advance pointer to next row */
  156333. }
  156334. }
  156335. GLOBAL(void)
  156336. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156337. JCOEFPTR coef_block,
  156338. JSAMPARRAY output_buf, JDIMENSION output_col)
  156339. {
  156340. INT32 tmp0, tmp10, z1;
  156341. JCOEFPTR inptr;
  156342. ISLOW_MULT_TYPE * quantptr;
  156343. int * wsptr;
  156344. JSAMPROW outptr;
  156345. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156346. int ctr;
  156347. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156348. SHIFT_TEMPS
  156349. inptr = coef_block;
  156350. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156351. wsptr = workspace;
  156352. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156353. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156354. continue;
  156355. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156356. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156357. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156358. wsptr[DCTSIZE*0] = dcval;
  156359. wsptr[DCTSIZE*1] = dcval;
  156360. continue;
  156361. }
  156362. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156363. tmp10 = z1 << (CONST_BITS+2);
  156364. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156365. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156366. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156367. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156368. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156369. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156370. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156371. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156372. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156373. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156374. }
  156375. wsptr = workspace;
  156376. for (ctr = 0; ctr < 2; ctr++) {
  156377. outptr = output_buf[ctr] + output_col;
  156378. #ifndef NO_ZERO_ROW_TEST
  156379. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156380. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156381. & RANGE_MASK];
  156382. outptr[0] = dcval;
  156383. outptr[1] = dcval;
  156384. wsptr += DCTSIZE; /* advance pointer to next row */
  156385. continue;
  156386. }
  156387. #endif
  156388. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156389. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156390. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156391. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156392. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156393. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156394. CONST_BITS+PASS1_BITS+3+2)
  156395. & RANGE_MASK];
  156396. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156397. CONST_BITS+PASS1_BITS+3+2)
  156398. & RANGE_MASK];
  156399. wsptr += DCTSIZE; /* advance pointer to next row */
  156400. }
  156401. }
  156402. GLOBAL(void)
  156403. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156404. JCOEFPTR coef_block,
  156405. JSAMPARRAY output_buf, JDIMENSION output_col)
  156406. {
  156407. int dcval;
  156408. ISLOW_MULT_TYPE * quantptr;
  156409. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156410. SHIFT_TEMPS
  156411. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156412. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156413. dcval = (int) DESCALE((INT32) dcval, 3);
  156414. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156415. }
  156416. #endif /* IDCT_SCALING_SUPPORTED */
  156417. /*** End of inlined file: jidctred.c ***/
  156418. /*** Start of inlined file: jmemmgr.c ***/
  156419. #define JPEG_INTERNALS
  156420. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156421. /*** Start of inlined file: jmemsys.h ***/
  156422. #ifndef __jmemsys_h__
  156423. #define __jmemsys_h__
  156424. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156425. #define jpeg_get_small jGetSmall
  156426. #define jpeg_free_small jFreeSmall
  156427. #define jpeg_get_large jGetLarge
  156428. #define jpeg_free_large jFreeLarge
  156429. #define jpeg_mem_available jMemAvail
  156430. #define jpeg_open_backing_store jOpenBackStore
  156431. #define jpeg_mem_init jMemInit
  156432. #define jpeg_mem_term jMemTerm
  156433. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156434. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156435. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156436. size_t sizeofobject));
  156437. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156438. size_t sizeofobject));
  156439. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156440. size_t sizeofobject));
  156441. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156442. #define MAX_ALLOC_CHUNK 1000000000L
  156443. #endif
  156444. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156445. long min_bytes_needed,
  156446. long max_bytes_needed,
  156447. long already_allocated));
  156448. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156449. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156450. typedef unsigned short XMSH; /* type of extended-memory handles */
  156451. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156452. typedef union {
  156453. short file_handle; /* DOS file handle if it's a temp file */
  156454. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156455. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156456. } handle_union;
  156457. #endif /* USE_MSDOS_MEMMGR */
  156458. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156459. #include <Files.h>
  156460. #endif /* USE_MAC_MEMMGR */
  156461. //typedef struct backing_store_struct * backing_store_ptr;
  156462. typedef struct backing_store_struct {
  156463. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156464. struct backing_store_struct *info,
  156465. void FAR * buffer_address,
  156466. long file_offset, long byte_count));
  156467. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156468. struct backing_store_struct *info,
  156469. void FAR * buffer_address,
  156470. long file_offset, long byte_count));
  156471. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156472. struct backing_store_struct *info));
  156473. #ifdef USE_MSDOS_MEMMGR
  156474. handle_union handle; /* reference to backing-store storage object */
  156475. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156476. #else
  156477. #ifdef USE_MAC_MEMMGR
  156478. short temp_file; /* file reference number to temp file */
  156479. FSSpec tempSpec; /* the FSSpec for the temp file */
  156480. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156481. #else
  156482. FILE * temp_file; /* stdio reference to temp file */
  156483. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156484. #endif
  156485. #endif
  156486. } backing_store_info;
  156487. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156488. struct backing_store_struct *info,
  156489. long total_bytes_needed));
  156490. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156491. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156492. #endif
  156493. /*** End of inlined file: jmemsys.h ***/
  156494. /* import the system-dependent declarations */
  156495. #ifndef NO_GETENV
  156496. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156497. extern char * getenv JPP((const char * name));
  156498. #endif
  156499. #endif
  156500. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156501. #define ALIGN_TYPE double
  156502. #endif
  156503. typedef union small_pool_struct * small_pool_ptr;
  156504. typedef union small_pool_struct {
  156505. struct {
  156506. small_pool_ptr next; /* next in list of pools */
  156507. size_t bytes_used; /* how many bytes already used within pool */
  156508. size_t bytes_left; /* bytes still available in this pool */
  156509. } hdr;
  156510. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156511. } small_pool_hdr;
  156512. typedef union large_pool_struct FAR * large_pool_ptr;
  156513. typedef union large_pool_struct {
  156514. struct {
  156515. large_pool_ptr next; /* next in list of pools */
  156516. size_t bytes_used; /* how many bytes already used within pool */
  156517. size_t bytes_left; /* bytes still available in this pool */
  156518. } hdr;
  156519. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156520. } large_pool_hdr;
  156521. typedef struct {
  156522. struct jpeg_memory_mgr pub; /* public fields */
  156523. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156524. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156525. jvirt_sarray_ptr virt_sarray_list;
  156526. jvirt_barray_ptr virt_barray_list;
  156527. long total_space_allocated;
  156528. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156529. } my_memory_mgr;
  156530. typedef my_memory_mgr * my_mem_ptr;
  156531. struct jvirt_sarray_control {
  156532. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156533. JDIMENSION rows_in_array; /* total virtual array height */
  156534. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156535. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156536. JDIMENSION rows_in_mem; /* height of memory buffer */
  156537. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156538. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156539. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156540. boolean pre_zero; /* pre-zero mode requested? */
  156541. boolean dirty; /* do current buffer contents need written? */
  156542. boolean b_s_open; /* is backing-store data valid? */
  156543. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156544. backing_store_info b_s_info; /* System-dependent control info */
  156545. };
  156546. struct jvirt_barray_control {
  156547. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156548. JDIMENSION rows_in_array; /* total virtual array height */
  156549. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156550. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156551. JDIMENSION rows_in_mem; /* height of memory buffer */
  156552. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156553. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156554. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156555. boolean pre_zero; /* pre-zero mode requested? */
  156556. boolean dirty; /* do current buffer contents need written? */
  156557. boolean b_s_open; /* is backing-store data valid? */
  156558. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156559. backing_store_info b_s_info; /* System-dependent control info */
  156560. };
  156561. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156562. LOCAL(void)
  156563. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156564. {
  156565. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156566. small_pool_ptr shdr_ptr;
  156567. large_pool_ptr lhdr_ptr;
  156568. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156569. pool_id, mem->total_space_allocated);
  156570. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156571. lhdr_ptr = lhdr_ptr->hdr.next) {
  156572. fprintf(stderr, " Large chunk used %ld\n",
  156573. (long) lhdr_ptr->hdr.bytes_used);
  156574. }
  156575. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156576. shdr_ptr = shdr_ptr->hdr.next) {
  156577. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156578. (long) shdr_ptr->hdr.bytes_used,
  156579. (long) shdr_ptr->hdr.bytes_left);
  156580. }
  156581. }
  156582. #endif /* MEM_STATS */
  156583. LOCAL(void)
  156584. out_of_memory (j_common_ptr cinfo, int which)
  156585. {
  156586. #ifdef MEM_STATS
  156587. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156588. #endif
  156589. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156590. }
  156591. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156592. {
  156593. 1600, /* first PERMANENT pool */
  156594. 16000 /* first IMAGE pool */
  156595. };
  156596. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156597. {
  156598. 0, /* additional PERMANENT pools */
  156599. 5000 /* additional IMAGE pools */
  156600. };
  156601. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156602. METHODDEF(void *)
  156603. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156604. {
  156605. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156606. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156607. char * data_ptr;
  156608. size_t odd_bytes, min_request, slop;
  156609. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156610. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156611. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156612. if (odd_bytes > 0)
  156613. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156614. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156615. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156616. prev_hdr_ptr = NULL;
  156617. hdr_ptr = mem->small_list[pool_id];
  156618. while (hdr_ptr != NULL) {
  156619. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156620. break; /* found pool with enough space */
  156621. prev_hdr_ptr = hdr_ptr;
  156622. hdr_ptr = hdr_ptr->hdr.next;
  156623. }
  156624. if (hdr_ptr == NULL) {
  156625. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156626. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156627. slop = first_pool_slop[pool_id];
  156628. else
  156629. slop = extra_pool_slop[pool_id];
  156630. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156631. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156632. for (;;) {
  156633. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156634. if (hdr_ptr != NULL)
  156635. break;
  156636. slop /= 2;
  156637. if (slop < MIN_SLOP) /* give up when it gets real small */
  156638. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156639. }
  156640. mem->total_space_allocated += min_request + slop;
  156641. hdr_ptr->hdr.next = NULL;
  156642. hdr_ptr->hdr.bytes_used = 0;
  156643. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156644. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156645. mem->small_list[pool_id] = hdr_ptr;
  156646. else
  156647. prev_hdr_ptr->hdr.next = hdr_ptr;
  156648. }
  156649. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156650. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156651. hdr_ptr->hdr.bytes_used += sizeofobject;
  156652. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156653. return (void *) data_ptr;
  156654. }
  156655. METHODDEF(void FAR *)
  156656. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156657. {
  156658. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156659. large_pool_ptr hdr_ptr;
  156660. size_t odd_bytes;
  156661. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156662. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156663. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156664. if (odd_bytes > 0)
  156665. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156666. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156667. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156668. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156669. SIZEOF(large_pool_hdr));
  156670. if (hdr_ptr == NULL)
  156671. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156672. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156673. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156674. hdr_ptr->hdr.bytes_used = sizeofobject;
  156675. hdr_ptr->hdr.bytes_left = 0;
  156676. mem->large_list[pool_id] = hdr_ptr;
  156677. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156678. }
  156679. METHODDEF(JSAMPARRAY)
  156680. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156681. JDIMENSION samplesperrow, JDIMENSION numrows)
  156682. {
  156683. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156684. JSAMPARRAY result;
  156685. JSAMPROW workspace;
  156686. JDIMENSION rowsperchunk, currow, i;
  156687. long ltemp;
  156688. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156689. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156690. if (ltemp <= 0)
  156691. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156692. if (ltemp < (long) numrows)
  156693. rowsperchunk = (JDIMENSION) ltemp;
  156694. else
  156695. rowsperchunk = numrows;
  156696. mem->last_rowsperchunk = rowsperchunk;
  156697. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156698. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156699. currow = 0;
  156700. while (currow < numrows) {
  156701. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156702. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156703. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156704. * SIZEOF(JSAMPLE)));
  156705. for (i = rowsperchunk; i > 0; i--) {
  156706. result[currow++] = workspace;
  156707. workspace += samplesperrow;
  156708. }
  156709. }
  156710. return result;
  156711. }
  156712. METHODDEF(JBLOCKARRAY)
  156713. alloc_barray (j_common_ptr cinfo, int pool_id,
  156714. JDIMENSION blocksperrow, JDIMENSION numrows)
  156715. {
  156716. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156717. JBLOCKARRAY result;
  156718. JBLOCKROW workspace;
  156719. JDIMENSION rowsperchunk, currow, i;
  156720. long ltemp;
  156721. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156722. ((long) blocksperrow * SIZEOF(JBLOCK));
  156723. if (ltemp <= 0)
  156724. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156725. if (ltemp < (long) numrows)
  156726. rowsperchunk = (JDIMENSION) ltemp;
  156727. else
  156728. rowsperchunk = numrows;
  156729. mem->last_rowsperchunk = rowsperchunk;
  156730. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156731. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156732. currow = 0;
  156733. while (currow < numrows) {
  156734. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156735. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156736. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156737. * SIZEOF(JBLOCK)));
  156738. for (i = rowsperchunk; i > 0; i--) {
  156739. result[currow++] = workspace;
  156740. workspace += blocksperrow;
  156741. }
  156742. }
  156743. return result;
  156744. }
  156745. METHODDEF(jvirt_sarray_ptr)
  156746. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156747. JDIMENSION samplesperrow, JDIMENSION numrows,
  156748. JDIMENSION maxaccess)
  156749. {
  156750. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156751. jvirt_sarray_ptr result;
  156752. if (pool_id != JPOOL_IMAGE)
  156753. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156754. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156755. SIZEOF(struct jvirt_sarray_control));
  156756. result->mem_buffer = NULL; /* marks array not yet realized */
  156757. result->rows_in_array = numrows;
  156758. result->samplesperrow = samplesperrow;
  156759. result->maxaccess = maxaccess;
  156760. result->pre_zero = pre_zero;
  156761. result->b_s_open = FALSE; /* no associated backing-store object */
  156762. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156763. mem->virt_sarray_list = result;
  156764. return result;
  156765. }
  156766. METHODDEF(jvirt_barray_ptr)
  156767. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156768. JDIMENSION blocksperrow, JDIMENSION numrows,
  156769. JDIMENSION maxaccess)
  156770. {
  156771. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156772. jvirt_barray_ptr result;
  156773. if (pool_id != JPOOL_IMAGE)
  156774. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156775. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156776. SIZEOF(struct jvirt_barray_control));
  156777. result->mem_buffer = NULL; /* marks array not yet realized */
  156778. result->rows_in_array = numrows;
  156779. result->blocksperrow = blocksperrow;
  156780. result->maxaccess = maxaccess;
  156781. result->pre_zero = pre_zero;
  156782. result->b_s_open = FALSE; /* no associated backing-store object */
  156783. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156784. mem->virt_barray_list = result;
  156785. return result;
  156786. }
  156787. METHODDEF(void)
  156788. realize_virt_arrays (j_common_ptr cinfo)
  156789. {
  156790. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156791. long space_per_minheight, maximum_space, avail_mem;
  156792. long minheights, max_minheights;
  156793. jvirt_sarray_ptr sptr;
  156794. jvirt_barray_ptr bptr;
  156795. space_per_minheight = 0;
  156796. maximum_space = 0;
  156797. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156798. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156799. space_per_minheight += (long) sptr->maxaccess *
  156800. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156801. maximum_space += (long) sptr->rows_in_array *
  156802. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156803. }
  156804. }
  156805. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156806. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156807. space_per_minheight += (long) bptr->maxaccess *
  156808. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156809. maximum_space += (long) bptr->rows_in_array *
  156810. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156811. }
  156812. }
  156813. if (space_per_minheight <= 0)
  156814. return; /* no unrealized arrays, no work */
  156815. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156816. mem->total_space_allocated);
  156817. if (avail_mem >= maximum_space)
  156818. max_minheights = 1000000000L;
  156819. else {
  156820. max_minheights = avail_mem / space_per_minheight;
  156821. if (max_minheights <= 0)
  156822. max_minheights = 1;
  156823. }
  156824. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156825. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156826. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156827. if (minheights <= max_minheights) {
  156828. sptr->rows_in_mem = sptr->rows_in_array;
  156829. } else {
  156830. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156831. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156832. (long) sptr->rows_in_array *
  156833. (long) sptr->samplesperrow *
  156834. (long) SIZEOF(JSAMPLE));
  156835. sptr->b_s_open = TRUE;
  156836. }
  156837. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156838. sptr->samplesperrow, sptr->rows_in_mem);
  156839. sptr->rowsperchunk = mem->last_rowsperchunk;
  156840. sptr->cur_start_row = 0;
  156841. sptr->first_undef_row = 0;
  156842. sptr->dirty = FALSE;
  156843. }
  156844. }
  156845. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156846. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156847. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156848. if (minheights <= max_minheights) {
  156849. bptr->rows_in_mem = bptr->rows_in_array;
  156850. } else {
  156851. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156852. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156853. (long) bptr->rows_in_array *
  156854. (long) bptr->blocksperrow *
  156855. (long) SIZEOF(JBLOCK));
  156856. bptr->b_s_open = TRUE;
  156857. }
  156858. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156859. bptr->blocksperrow, bptr->rows_in_mem);
  156860. bptr->rowsperchunk = mem->last_rowsperchunk;
  156861. bptr->cur_start_row = 0;
  156862. bptr->first_undef_row = 0;
  156863. bptr->dirty = FALSE;
  156864. }
  156865. }
  156866. }
  156867. LOCAL(void)
  156868. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156869. {
  156870. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156871. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156872. file_offset = ptr->cur_start_row * bytesperrow;
  156873. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156874. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156875. thisrow = (long) ptr->cur_start_row + i;
  156876. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156877. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156878. if (rows <= 0) /* this chunk might be past end of file! */
  156879. break;
  156880. byte_count = rows * bytesperrow;
  156881. if (writing)
  156882. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156883. (void FAR *) ptr->mem_buffer[i],
  156884. file_offset, byte_count);
  156885. else
  156886. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156887. (void FAR *) ptr->mem_buffer[i],
  156888. file_offset, byte_count);
  156889. file_offset += byte_count;
  156890. }
  156891. }
  156892. LOCAL(void)
  156893. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156894. {
  156895. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156896. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156897. file_offset = ptr->cur_start_row * bytesperrow;
  156898. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156899. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156900. thisrow = (long) ptr->cur_start_row + i;
  156901. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156902. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156903. if (rows <= 0) /* this chunk might be past end of file! */
  156904. break;
  156905. byte_count = rows * bytesperrow;
  156906. if (writing)
  156907. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156908. (void FAR *) ptr->mem_buffer[i],
  156909. file_offset, byte_count);
  156910. else
  156911. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156912. (void FAR *) ptr->mem_buffer[i],
  156913. file_offset, byte_count);
  156914. file_offset += byte_count;
  156915. }
  156916. }
  156917. METHODDEF(JSAMPARRAY)
  156918. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156919. JDIMENSION start_row, JDIMENSION num_rows,
  156920. boolean writable)
  156921. {
  156922. JDIMENSION end_row = start_row + num_rows;
  156923. JDIMENSION undef_row;
  156924. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156925. ptr->mem_buffer == NULL)
  156926. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156927. if (start_row < ptr->cur_start_row ||
  156928. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156929. if (! ptr->b_s_open)
  156930. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156931. if (ptr->dirty) {
  156932. do_sarray_io(cinfo, ptr, TRUE);
  156933. ptr->dirty = FALSE;
  156934. }
  156935. if (start_row > ptr->cur_start_row) {
  156936. ptr->cur_start_row = start_row;
  156937. } else {
  156938. long ltemp;
  156939. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156940. if (ltemp < 0)
  156941. ltemp = 0; /* don't fall off front end of file */
  156942. ptr->cur_start_row = (JDIMENSION) ltemp;
  156943. }
  156944. do_sarray_io(cinfo, ptr, FALSE);
  156945. }
  156946. if (ptr->first_undef_row < end_row) {
  156947. if (ptr->first_undef_row < start_row) {
  156948. if (writable) /* writer skipped over a section of array */
  156949. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156950. undef_row = start_row; /* but reader is allowed to read ahead */
  156951. } else {
  156952. undef_row = ptr->first_undef_row;
  156953. }
  156954. if (writable)
  156955. ptr->first_undef_row = end_row;
  156956. if (ptr->pre_zero) {
  156957. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156958. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156959. end_row -= ptr->cur_start_row;
  156960. while (undef_row < end_row) {
  156961. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156962. undef_row++;
  156963. }
  156964. } else {
  156965. if (! writable) /* reader looking at undefined data */
  156966. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156967. }
  156968. }
  156969. if (writable)
  156970. ptr->dirty = TRUE;
  156971. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156972. }
  156973. METHODDEF(JBLOCKARRAY)
  156974. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156975. JDIMENSION start_row, JDIMENSION num_rows,
  156976. boolean writable)
  156977. {
  156978. JDIMENSION end_row = start_row + num_rows;
  156979. JDIMENSION undef_row;
  156980. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156981. ptr->mem_buffer == NULL)
  156982. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156983. if (start_row < ptr->cur_start_row ||
  156984. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156985. if (! ptr->b_s_open)
  156986. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156987. if (ptr->dirty) {
  156988. do_barray_io(cinfo, ptr, TRUE);
  156989. ptr->dirty = FALSE;
  156990. }
  156991. if (start_row > ptr->cur_start_row) {
  156992. ptr->cur_start_row = start_row;
  156993. } else {
  156994. long ltemp;
  156995. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156996. if (ltemp < 0)
  156997. ltemp = 0; /* don't fall off front end of file */
  156998. ptr->cur_start_row = (JDIMENSION) ltemp;
  156999. }
  157000. do_barray_io(cinfo, ptr, FALSE);
  157001. }
  157002. if (ptr->first_undef_row < end_row) {
  157003. if (ptr->first_undef_row < start_row) {
  157004. if (writable) /* writer skipped over a section of array */
  157005. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157006. undef_row = start_row; /* but reader is allowed to read ahead */
  157007. } else {
  157008. undef_row = ptr->first_undef_row;
  157009. }
  157010. if (writable)
  157011. ptr->first_undef_row = end_row;
  157012. if (ptr->pre_zero) {
  157013. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  157014. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157015. end_row -= ptr->cur_start_row;
  157016. while (undef_row < end_row) {
  157017. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157018. undef_row++;
  157019. }
  157020. } else {
  157021. if (! writable) /* reader looking at undefined data */
  157022. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157023. }
  157024. }
  157025. if (writable)
  157026. ptr->dirty = TRUE;
  157027. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157028. }
  157029. METHODDEF(void)
  157030. free_pool (j_common_ptr cinfo, int pool_id)
  157031. {
  157032. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157033. small_pool_ptr shdr_ptr;
  157034. large_pool_ptr lhdr_ptr;
  157035. size_t space_freed;
  157036. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157037. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157038. #ifdef MEM_STATS
  157039. if (cinfo->err->trace_level > 1)
  157040. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  157041. #endif
  157042. if (pool_id == JPOOL_IMAGE) {
  157043. jvirt_sarray_ptr sptr;
  157044. jvirt_barray_ptr bptr;
  157045. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157046. if (sptr->b_s_open) { /* there may be no backing store */
  157047. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  157048. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  157049. }
  157050. }
  157051. mem->virt_sarray_list = NULL;
  157052. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157053. if (bptr->b_s_open) { /* there may be no backing store */
  157054. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  157055. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  157056. }
  157057. }
  157058. mem->virt_barray_list = NULL;
  157059. }
  157060. lhdr_ptr = mem->large_list[pool_id];
  157061. mem->large_list[pool_id] = NULL;
  157062. while (lhdr_ptr != NULL) {
  157063. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  157064. space_freed = lhdr_ptr->hdr.bytes_used +
  157065. lhdr_ptr->hdr.bytes_left +
  157066. SIZEOF(large_pool_hdr);
  157067. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  157068. mem->total_space_allocated -= space_freed;
  157069. lhdr_ptr = next_lhdr_ptr;
  157070. }
  157071. shdr_ptr = mem->small_list[pool_id];
  157072. mem->small_list[pool_id] = NULL;
  157073. while (shdr_ptr != NULL) {
  157074. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  157075. space_freed = shdr_ptr->hdr.bytes_used +
  157076. shdr_ptr->hdr.bytes_left +
  157077. SIZEOF(small_pool_hdr);
  157078. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  157079. mem->total_space_allocated -= space_freed;
  157080. shdr_ptr = next_shdr_ptr;
  157081. }
  157082. }
  157083. METHODDEF(void)
  157084. self_destruct (j_common_ptr cinfo)
  157085. {
  157086. int pool;
  157087. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157088. free_pool(cinfo, pool);
  157089. }
  157090. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  157091. cinfo->mem = NULL; /* ensures I will be called only once */
  157092. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157093. }
  157094. GLOBAL(void)
  157095. jinit_memory_mgr (j_common_ptr cinfo)
  157096. {
  157097. my_mem_ptr mem;
  157098. long max_to_use;
  157099. int pool;
  157100. size_t test_mac;
  157101. cinfo->mem = NULL; /* for safety if init fails */
  157102. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  157103. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  157104. test_mac = (size_t) MAX_ALLOC_CHUNK;
  157105. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  157106. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  157107. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  157108. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  157109. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  157110. if (mem == NULL) {
  157111. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157112. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  157113. }
  157114. mem->pub.alloc_small = alloc_small;
  157115. mem->pub.alloc_large = alloc_large;
  157116. mem->pub.alloc_sarray = alloc_sarray;
  157117. mem->pub.alloc_barray = alloc_barray;
  157118. mem->pub.request_virt_sarray = request_virt_sarray;
  157119. mem->pub.request_virt_barray = request_virt_barray;
  157120. mem->pub.realize_virt_arrays = realize_virt_arrays;
  157121. mem->pub.access_virt_sarray = access_virt_sarray;
  157122. mem->pub.access_virt_barray = access_virt_barray;
  157123. mem->pub.free_pool = free_pool;
  157124. mem->pub.self_destruct = self_destruct;
  157125. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  157126. mem->pub.max_memory_to_use = max_to_use;
  157127. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157128. mem->small_list[pool] = NULL;
  157129. mem->large_list[pool] = NULL;
  157130. }
  157131. mem->virt_sarray_list = NULL;
  157132. mem->virt_barray_list = NULL;
  157133. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  157134. cinfo->mem = & mem->pub;
  157135. #ifndef NO_GETENV
  157136. { char * memenv;
  157137. if ((memenv = getenv("JPEGMEM")) != NULL) {
  157138. char ch = 'x';
  157139. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  157140. if (ch == 'm' || ch == 'M')
  157141. max_to_use *= 1000L;
  157142. mem->pub.max_memory_to_use = max_to_use * 1000L;
  157143. }
  157144. }
  157145. }
  157146. #endif
  157147. }
  157148. /*** End of inlined file: jmemmgr.c ***/
  157149. /*** Start of inlined file: jmemnobs.c ***/
  157150. #define JPEG_INTERNALS
  157151. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  157152. extern void * malloc JPP((size_t size));
  157153. extern void free JPP((void *ptr));
  157154. #endif
  157155. GLOBAL(void *)
  157156. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  157157. {
  157158. return (void *) malloc(sizeofobject);
  157159. }
  157160. GLOBAL(void)
  157161. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  157162. {
  157163. free(object);
  157164. }
  157165. GLOBAL(void FAR *)
  157166. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  157167. {
  157168. return (void FAR *) malloc(sizeofobject);
  157169. }
  157170. GLOBAL(void)
  157171. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  157172. {
  157173. free(object);
  157174. }
  157175. GLOBAL(long)
  157176. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  157177. long max_bytes_needed, long already_allocated)
  157178. {
  157179. return max_bytes_needed;
  157180. }
  157181. GLOBAL(void)
  157182. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  157183. long total_bytes_needed)
  157184. {
  157185. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  157186. }
  157187. GLOBAL(long)
  157188. jpeg_mem_init (j_common_ptr cinfo)
  157189. {
  157190. return 0; /* just set max_memory_to_use to 0 */
  157191. }
  157192. GLOBAL(void)
  157193. jpeg_mem_term (j_common_ptr cinfo)
  157194. {
  157195. }
  157196. /*** End of inlined file: jmemnobs.c ***/
  157197. /*** Start of inlined file: jquant1.c ***/
  157198. #define JPEG_INTERNALS
  157199. #ifdef QUANT_1PASS_SUPPORTED
  157200. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  157201. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  157202. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  157203. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  157204. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  157205. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  157206. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  157207. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  157208. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  157209. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  157210. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  157211. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  157212. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  157213. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  157214. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  157215. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  157216. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  157217. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  157218. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  157219. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  157220. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  157221. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  157222. };
  157223. #if BITS_IN_JSAMPLE == 8
  157224. typedef INT16 FSERROR; /* 16 bits should be enough */
  157225. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157226. #else
  157227. typedef INT32 FSERROR; /* may need more than 16 bits */
  157228. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157229. #endif
  157230. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157231. #define MAX_Q_COMPS 4 /* max components I can handle */
  157232. typedef struct {
  157233. struct jpeg_color_quantizer pub; /* public fields */
  157234. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  157235. int sv_actual; /* number of entries in use */
  157236. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  157237. boolean is_padded; /* is the colorindex padded for odither? */
  157238. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  157239. int row_index; /* cur row's vertical index in dither matrix */
  157240. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  157241. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  157242. boolean on_odd_row; /* flag to remember which row we are on */
  157243. } my_cquantizer;
  157244. typedef my_cquantizer * my_cquantize_ptr;
  157245. LOCAL(int)
  157246. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  157247. {
  157248. int nc = cinfo->out_color_components; /* number of color components */
  157249. int max_colors = cinfo->desired_number_of_colors;
  157250. int total_colors, iroot, i, j;
  157251. boolean changed;
  157252. long temp;
  157253. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  157254. iroot = 1;
  157255. do {
  157256. iroot++;
  157257. temp = iroot; /* set temp = iroot ** nc */
  157258. for (i = 1; i < nc; i++)
  157259. temp *= iroot;
  157260. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  157261. iroot--; /* now iroot = floor(root) */
  157262. if (iroot < 2)
  157263. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  157264. total_colors = 1;
  157265. for (i = 0; i < nc; i++) {
  157266. Ncolors[i] = iroot;
  157267. total_colors *= iroot;
  157268. }
  157269. do {
  157270. changed = FALSE;
  157271. for (i = 0; i < nc; i++) {
  157272. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  157273. temp = total_colors / Ncolors[j];
  157274. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  157275. if (temp > (long) max_colors)
  157276. break; /* won't fit, done with this pass */
  157277. Ncolors[j]++; /* OK, apply the increment */
  157278. total_colors = (int) temp;
  157279. changed = TRUE;
  157280. }
  157281. } while (changed);
  157282. return total_colors;
  157283. }
  157284. LOCAL(int)
  157285. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157286. {
  157287. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  157288. }
  157289. LOCAL(int)
  157290. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157291. {
  157292. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  157293. }
  157294. LOCAL(void)
  157295. create_colormap (j_decompress_ptr cinfo)
  157296. {
  157297. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157298. JSAMPARRAY colormap; /* Created colormap */
  157299. int total_colors; /* Number of distinct output colors */
  157300. int i,j,k, nci, blksize, blkdist, ptr, val;
  157301. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  157302. if (cinfo->out_color_components == 3)
  157303. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  157304. total_colors, cquantize->Ncolors[0],
  157305. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157306. else
  157307. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157308. colormap = (*cinfo->mem->alloc_sarray)
  157309. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157310. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157311. blkdist = total_colors;
  157312. for (i = 0; i < cinfo->out_color_components; i++) {
  157313. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157314. blksize = blkdist / nci;
  157315. for (j = 0; j < nci; j++) {
  157316. val = output_value(cinfo, i, j, nci-1);
  157317. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157318. for (k = 0; k < blksize; k++)
  157319. colormap[i][ptr+k] = (JSAMPLE) val;
  157320. }
  157321. }
  157322. blkdist = blksize; /* blksize of this color is blkdist of next */
  157323. }
  157324. cquantize->sv_colormap = colormap;
  157325. cquantize->sv_actual = total_colors;
  157326. }
  157327. LOCAL(void)
  157328. create_colorindex (j_decompress_ptr cinfo)
  157329. {
  157330. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157331. JSAMPROW indexptr;
  157332. int i,j,k, nci, blksize, val, pad;
  157333. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157334. pad = MAXJSAMPLE*2;
  157335. cquantize->is_padded = TRUE;
  157336. } else {
  157337. pad = 0;
  157338. cquantize->is_padded = FALSE;
  157339. }
  157340. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157341. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157342. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157343. (JDIMENSION) cinfo->out_color_components);
  157344. blksize = cquantize->sv_actual;
  157345. for (i = 0; i < cinfo->out_color_components; i++) {
  157346. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157347. blksize = blksize / nci;
  157348. if (pad)
  157349. cquantize->colorindex[i] += MAXJSAMPLE;
  157350. indexptr = cquantize->colorindex[i];
  157351. val = 0;
  157352. k = largest_input_value(cinfo, i, 0, nci-1);
  157353. for (j = 0; j <= MAXJSAMPLE; j++) {
  157354. while (j > k) /* advance val if past boundary */
  157355. k = largest_input_value(cinfo, i, ++val, nci-1);
  157356. indexptr[j] = (JSAMPLE) (val * blksize);
  157357. }
  157358. if (pad)
  157359. for (j = 1; j <= MAXJSAMPLE; j++) {
  157360. indexptr[-j] = indexptr[0];
  157361. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157362. }
  157363. }
  157364. }
  157365. LOCAL(ODITHER_MATRIX_PTR)
  157366. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157367. {
  157368. ODITHER_MATRIX_PTR odither;
  157369. int j,k;
  157370. INT32 num,den;
  157371. odither = (ODITHER_MATRIX_PTR)
  157372. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157373. SIZEOF(ODITHER_MATRIX));
  157374. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157375. for (j = 0; j < ODITHER_SIZE; j++) {
  157376. for (k = 0; k < ODITHER_SIZE; k++) {
  157377. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157378. * MAXJSAMPLE;
  157379. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157380. }
  157381. }
  157382. return odither;
  157383. }
  157384. LOCAL(void)
  157385. create_odither_tables (j_decompress_ptr cinfo)
  157386. {
  157387. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157388. ODITHER_MATRIX_PTR odither;
  157389. int i, j, nci;
  157390. for (i = 0; i < cinfo->out_color_components; i++) {
  157391. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157392. odither = NULL; /* search for matching prior component */
  157393. for (j = 0; j < i; j++) {
  157394. if (nci == cquantize->Ncolors[j]) {
  157395. odither = cquantize->odither[j];
  157396. break;
  157397. }
  157398. }
  157399. if (odither == NULL) /* need a new table? */
  157400. odither = make_odither_array(cinfo, nci);
  157401. cquantize->odither[i] = odither;
  157402. }
  157403. }
  157404. METHODDEF(void)
  157405. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157406. JSAMPARRAY output_buf, int num_rows)
  157407. {
  157408. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157409. JSAMPARRAY colorindex = cquantize->colorindex;
  157410. register int pixcode, ci;
  157411. register JSAMPROW ptrin, ptrout;
  157412. int row;
  157413. JDIMENSION col;
  157414. JDIMENSION width = cinfo->output_width;
  157415. register int nc = cinfo->out_color_components;
  157416. for (row = 0; row < num_rows; row++) {
  157417. ptrin = input_buf[row];
  157418. ptrout = output_buf[row];
  157419. for (col = width; col > 0; col--) {
  157420. pixcode = 0;
  157421. for (ci = 0; ci < nc; ci++) {
  157422. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157423. }
  157424. *ptrout++ = (JSAMPLE) pixcode;
  157425. }
  157426. }
  157427. }
  157428. METHODDEF(void)
  157429. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157430. JSAMPARRAY output_buf, int num_rows)
  157431. {
  157432. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157433. register int pixcode;
  157434. register JSAMPROW ptrin, ptrout;
  157435. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157436. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157437. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157438. int row;
  157439. JDIMENSION col;
  157440. JDIMENSION width = cinfo->output_width;
  157441. for (row = 0; row < num_rows; row++) {
  157442. ptrin = input_buf[row];
  157443. ptrout = output_buf[row];
  157444. for (col = width; col > 0; col--) {
  157445. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157446. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157447. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157448. *ptrout++ = (JSAMPLE) pixcode;
  157449. }
  157450. }
  157451. }
  157452. METHODDEF(void)
  157453. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157454. JSAMPARRAY output_buf, int num_rows)
  157455. {
  157456. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157457. register JSAMPROW input_ptr;
  157458. register JSAMPROW output_ptr;
  157459. JSAMPROW colorindex_ci;
  157460. int * dither; /* points to active row of dither matrix */
  157461. int row_index, col_index; /* current indexes into dither matrix */
  157462. int nc = cinfo->out_color_components;
  157463. int ci;
  157464. int row;
  157465. JDIMENSION col;
  157466. JDIMENSION width = cinfo->output_width;
  157467. for (row = 0; row < num_rows; row++) {
  157468. jzero_far((void FAR *) output_buf[row],
  157469. (size_t) (width * SIZEOF(JSAMPLE)));
  157470. row_index = cquantize->row_index;
  157471. for (ci = 0; ci < nc; ci++) {
  157472. input_ptr = input_buf[row] + ci;
  157473. output_ptr = output_buf[row];
  157474. colorindex_ci = cquantize->colorindex[ci];
  157475. dither = cquantize->odither[ci][row_index];
  157476. col_index = 0;
  157477. for (col = width; col > 0; col--) {
  157478. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157479. input_ptr += nc;
  157480. output_ptr++;
  157481. col_index = (col_index + 1) & ODITHER_MASK;
  157482. }
  157483. }
  157484. row_index = (row_index + 1) & ODITHER_MASK;
  157485. cquantize->row_index = row_index;
  157486. }
  157487. }
  157488. METHODDEF(void)
  157489. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157490. JSAMPARRAY output_buf, int num_rows)
  157491. {
  157492. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157493. register int pixcode;
  157494. register JSAMPROW input_ptr;
  157495. register JSAMPROW output_ptr;
  157496. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157497. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157498. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157499. int * dither0; /* points to active row of dither matrix */
  157500. int * dither1;
  157501. int * dither2;
  157502. int row_index, col_index; /* current indexes into dither matrix */
  157503. int row;
  157504. JDIMENSION col;
  157505. JDIMENSION width = cinfo->output_width;
  157506. for (row = 0; row < num_rows; row++) {
  157507. row_index = cquantize->row_index;
  157508. input_ptr = input_buf[row];
  157509. output_ptr = output_buf[row];
  157510. dither0 = cquantize->odither[0][row_index];
  157511. dither1 = cquantize->odither[1][row_index];
  157512. dither2 = cquantize->odither[2][row_index];
  157513. col_index = 0;
  157514. for (col = width; col > 0; col--) {
  157515. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157516. dither0[col_index]]);
  157517. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157518. dither1[col_index]]);
  157519. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157520. dither2[col_index]]);
  157521. *output_ptr++ = (JSAMPLE) pixcode;
  157522. col_index = (col_index + 1) & ODITHER_MASK;
  157523. }
  157524. row_index = (row_index + 1) & ODITHER_MASK;
  157525. cquantize->row_index = row_index;
  157526. }
  157527. }
  157528. METHODDEF(void)
  157529. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157530. JSAMPARRAY output_buf, int num_rows)
  157531. {
  157532. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157533. register LOCFSERROR cur; /* current error or pixel value */
  157534. LOCFSERROR belowerr; /* error for pixel below cur */
  157535. LOCFSERROR bpreverr; /* error for below/prev col */
  157536. LOCFSERROR bnexterr; /* error for below/next col */
  157537. LOCFSERROR delta;
  157538. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157539. register JSAMPROW input_ptr;
  157540. register JSAMPROW output_ptr;
  157541. JSAMPROW colorindex_ci;
  157542. JSAMPROW colormap_ci;
  157543. int pixcode;
  157544. int nc = cinfo->out_color_components;
  157545. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157546. int dirnc; /* dir * nc */
  157547. int ci;
  157548. int row;
  157549. JDIMENSION col;
  157550. JDIMENSION width = cinfo->output_width;
  157551. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157552. SHIFT_TEMPS
  157553. for (row = 0; row < num_rows; row++) {
  157554. jzero_far((void FAR *) output_buf[row],
  157555. (size_t) (width * SIZEOF(JSAMPLE)));
  157556. for (ci = 0; ci < nc; ci++) {
  157557. input_ptr = input_buf[row] + ci;
  157558. output_ptr = output_buf[row];
  157559. if (cquantize->on_odd_row) {
  157560. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157561. output_ptr += width-1;
  157562. dir = -1;
  157563. dirnc = -nc;
  157564. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157565. } else {
  157566. dir = 1;
  157567. dirnc = nc;
  157568. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157569. }
  157570. colorindex_ci = cquantize->colorindex[ci];
  157571. colormap_ci = cquantize->sv_colormap[ci];
  157572. cur = 0;
  157573. belowerr = bpreverr = 0;
  157574. for (col = width; col > 0; col--) {
  157575. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157576. cur += GETJSAMPLE(*input_ptr);
  157577. cur = GETJSAMPLE(range_limit[cur]);
  157578. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157579. *output_ptr += (JSAMPLE) pixcode;
  157580. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157581. bnexterr = cur;
  157582. delta = cur * 2;
  157583. cur += delta; /* form error * 3 */
  157584. errorptr[0] = (FSERROR) (bpreverr + cur);
  157585. cur += delta; /* form error * 5 */
  157586. bpreverr = belowerr + cur;
  157587. belowerr = bnexterr;
  157588. cur += delta; /* form error * 7 */
  157589. input_ptr += dirnc; /* advance input ptr to next column */
  157590. output_ptr += dir; /* advance output ptr to next column */
  157591. errorptr += dir; /* advance errorptr to current column */
  157592. }
  157593. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157594. }
  157595. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157596. }
  157597. }
  157598. LOCAL(void)
  157599. alloc_fs_workspace (j_decompress_ptr cinfo)
  157600. {
  157601. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157602. size_t arraysize;
  157603. int i;
  157604. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157605. for (i = 0; i < cinfo->out_color_components; i++) {
  157606. cquantize->fserrors[i] = (FSERRPTR)
  157607. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157608. }
  157609. }
  157610. METHODDEF(void)
  157611. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157612. {
  157613. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157614. size_t arraysize;
  157615. int i;
  157616. cinfo->colormap = cquantize->sv_colormap;
  157617. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157618. switch (cinfo->dither_mode) {
  157619. case JDITHER_NONE:
  157620. if (cinfo->out_color_components == 3)
  157621. cquantize->pub.color_quantize = color_quantize3;
  157622. else
  157623. cquantize->pub.color_quantize = color_quantize;
  157624. break;
  157625. case JDITHER_ORDERED:
  157626. if (cinfo->out_color_components == 3)
  157627. cquantize->pub.color_quantize = quantize3_ord_dither;
  157628. else
  157629. cquantize->pub.color_quantize = quantize_ord_dither;
  157630. cquantize->row_index = 0; /* initialize state for ordered dither */
  157631. if (! cquantize->is_padded)
  157632. create_colorindex(cinfo);
  157633. if (cquantize->odither[0] == NULL)
  157634. create_odither_tables(cinfo);
  157635. break;
  157636. case JDITHER_FS:
  157637. cquantize->pub.color_quantize = quantize_fs_dither;
  157638. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157639. if (cquantize->fserrors[0] == NULL)
  157640. alloc_fs_workspace(cinfo);
  157641. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157642. for (i = 0; i < cinfo->out_color_components; i++)
  157643. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157644. break;
  157645. default:
  157646. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157647. break;
  157648. }
  157649. }
  157650. METHODDEF(void)
  157651. finish_pass_1_quant (j_decompress_ptr cinfo)
  157652. {
  157653. }
  157654. METHODDEF(void)
  157655. new_color_map_1_quant (j_decompress_ptr cinfo)
  157656. {
  157657. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157658. }
  157659. GLOBAL(void)
  157660. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157661. {
  157662. my_cquantize_ptr cquantize;
  157663. cquantize = (my_cquantize_ptr)
  157664. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157665. SIZEOF(my_cquantizer));
  157666. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157667. cquantize->pub.start_pass = start_pass_1_quant;
  157668. cquantize->pub.finish_pass = finish_pass_1_quant;
  157669. cquantize->pub.new_color_map = new_color_map_1_quant;
  157670. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157671. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157672. if (cinfo->out_color_components > MAX_Q_COMPS)
  157673. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157674. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157675. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157676. create_colormap(cinfo);
  157677. create_colorindex(cinfo);
  157678. if (cinfo->dither_mode == JDITHER_FS)
  157679. alloc_fs_workspace(cinfo);
  157680. }
  157681. #endif /* QUANT_1PASS_SUPPORTED */
  157682. /*** End of inlined file: jquant1.c ***/
  157683. /*** Start of inlined file: jquant2.c ***/
  157684. #define JPEG_INTERNALS
  157685. #ifdef QUANT_2PASS_SUPPORTED
  157686. #define R_SCALE 2 /* scale R distances by this much */
  157687. #define G_SCALE 3 /* scale G distances by this much */
  157688. #define B_SCALE 1 /* and B by this much */
  157689. #if RGB_RED == 0
  157690. #define C0_SCALE R_SCALE
  157691. #endif
  157692. #if RGB_BLUE == 0
  157693. #define C0_SCALE B_SCALE
  157694. #endif
  157695. #if RGB_GREEN == 1
  157696. #define C1_SCALE G_SCALE
  157697. #endif
  157698. #if RGB_RED == 2
  157699. #define C2_SCALE R_SCALE
  157700. #endif
  157701. #if RGB_BLUE == 2
  157702. #define C2_SCALE B_SCALE
  157703. #endif
  157704. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157705. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157706. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157707. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157708. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157709. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157710. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157711. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157712. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157713. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157714. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157715. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157716. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157717. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157718. typedef hist2d * hist3d; /* type for top-level pointer */
  157719. #if BITS_IN_JSAMPLE == 8
  157720. typedef INT16 FSERROR; /* 16 bits should be enough */
  157721. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157722. #else
  157723. typedef INT32 FSERROR; /* may need more than 16 bits */
  157724. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157725. #endif
  157726. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157727. typedef struct {
  157728. struct jpeg_color_quantizer pub; /* public fields */
  157729. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157730. int desired; /* desired # of colors = size of colormap */
  157731. hist3d histogram; /* pointer to the histogram */
  157732. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157733. FSERRPTR fserrors; /* accumulated errors */
  157734. boolean on_odd_row; /* flag to remember which row we are on */
  157735. int * error_limiter; /* table for clamping the applied error */
  157736. } my_cquantizer2;
  157737. typedef my_cquantizer2 * my_cquantize_ptr2;
  157738. METHODDEF(void)
  157739. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157740. JSAMPARRAY output_buf, int num_rows)
  157741. {
  157742. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157743. register JSAMPROW ptr;
  157744. register histptr histp;
  157745. register hist3d histogram = cquantize->histogram;
  157746. int row;
  157747. JDIMENSION col;
  157748. JDIMENSION width = cinfo->output_width;
  157749. for (row = 0; row < num_rows; row++) {
  157750. ptr = input_buf[row];
  157751. for (col = width; col > 0; col--) {
  157752. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157753. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157754. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157755. if (++(*histp) <= 0)
  157756. (*histp)--;
  157757. ptr += 3;
  157758. }
  157759. }
  157760. }
  157761. typedef struct {
  157762. int c0min, c0max;
  157763. int c1min, c1max;
  157764. int c2min, c2max;
  157765. INT32 volume;
  157766. long colorcount;
  157767. } box;
  157768. typedef box * boxptr;
  157769. LOCAL(boxptr)
  157770. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157771. {
  157772. register boxptr boxp;
  157773. register int i;
  157774. register long maxc = 0;
  157775. boxptr which = NULL;
  157776. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157777. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157778. which = boxp;
  157779. maxc = boxp->colorcount;
  157780. }
  157781. }
  157782. return which;
  157783. }
  157784. LOCAL(boxptr)
  157785. find_biggest_volume (boxptr boxlist, int numboxes)
  157786. {
  157787. register boxptr boxp;
  157788. register int i;
  157789. register INT32 maxv = 0;
  157790. boxptr which = NULL;
  157791. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157792. if (boxp->volume > maxv) {
  157793. which = boxp;
  157794. maxv = boxp->volume;
  157795. }
  157796. }
  157797. return which;
  157798. }
  157799. LOCAL(void)
  157800. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157801. {
  157802. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157803. hist3d histogram = cquantize->histogram;
  157804. histptr histp;
  157805. int c0,c1,c2;
  157806. int c0min,c0max,c1min,c1max,c2min,c2max;
  157807. INT32 dist0,dist1,dist2;
  157808. long ccount;
  157809. c0min = boxp->c0min; c0max = boxp->c0max;
  157810. c1min = boxp->c1min; c1max = boxp->c1max;
  157811. c2min = boxp->c2min; c2max = boxp->c2max;
  157812. if (c0max > c0min)
  157813. for (c0 = c0min; c0 <= c0max; c0++)
  157814. for (c1 = c1min; c1 <= c1max; c1++) {
  157815. histp = & histogram[c0][c1][c2min];
  157816. for (c2 = c2min; c2 <= c2max; c2++)
  157817. if (*histp++ != 0) {
  157818. boxp->c0min = c0min = c0;
  157819. goto have_c0min;
  157820. }
  157821. }
  157822. have_c0min:
  157823. if (c0max > c0min)
  157824. for (c0 = c0max; c0 >= c0min; c0--)
  157825. for (c1 = c1min; c1 <= c1max; c1++) {
  157826. histp = & histogram[c0][c1][c2min];
  157827. for (c2 = c2min; c2 <= c2max; c2++)
  157828. if (*histp++ != 0) {
  157829. boxp->c0max = c0max = c0;
  157830. goto have_c0max;
  157831. }
  157832. }
  157833. have_c0max:
  157834. if (c1max > c1min)
  157835. for (c1 = c1min; c1 <= c1max; c1++)
  157836. for (c0 = c0min; c0 <= c0max; c0++) {
  157837. histp = & histogram[c0][c1][c2min];
  157838. for (c2 = c2min; c2 <= c2max; c2++)
  157839. if (*histp++ != 0) {
  157840. boxp->c1min = c1min = c1;
  157841. goto have_c1min;
  157842. }
  157843. }
  157844. have_c1min:
  157845. if (c1max > c1min)
  157846. for (c1 = c1max; c1 >= c1min; c1--)
  157847. for (c0 = c0min; c0 <= c0max; c0++) {
  157848. histp = & histogram[c0][c1][c2min];
  157849. for (c2 = c2min; c2 <= c2max; c2++)
  157850. if (*histp++ != 0) {
  157851. boxp->c1max = c1max = c1;
  157852. goto have_c1max;
  157853. }
  157854. }
  157855. have_c1max:
  157856. if (c2max > c2min)
  157857. for (c2 = c2min; c2 <= c2max; c2++)
  157858. for (c0 = c0min; c0 <= c0max; c0++) {
  157859. histp = & histogram[c0][c1min][c2];
  157860. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157861. if (*histp != 0) {
  157862. boxp->c2min = c2min = c2;
  157863. goto have_c2min;
  157864. }
  157865. }
  157866. have_c2min:
  157867. if (c2max > c2min)
  157868. for (c2 = c2max; c2 >= c2min; c2--)
  157869. for (c0 = c0min; c0 <= c0max; c0++) {
  157870. histp = & histogram[c0][c1min][c2];
  157871. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157872. if (*histp != 0) {
  157873. boxp->c2max = c2max = c2;
  157874. goto have_c2max;
  157875. }
  157876. }
  157877. have_c2max:
  157878. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157879. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157880. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157881. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157882. ccount = 0;
  157883. for (c0 = c0min; c0 <= c0max; c0++)
  157884. for (c1 = c1min; c1 <= c1max; c1++) {
  157885. histp = & histogram[c0][c1][c2min];
  157886. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157887. if (*histp != 0) {
  157888. ccount++;
  157889. }
  157890. }
  157891. boxp->colorcount = ccount;
  157892. }
  157893. LOCAL(int)
  157894. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157895. int desired_colors)
  157896. {
  157897. int n,lb;
  157898. int c0,c1,c2,cmax;
  157899. register boxptr b1,b2;
  157900. while (numboxes < desired_colors) {
  157901. if (numboxes*2 <= desired_colors) {
  157902. b1 = find_biggest_color_pop(boxlist, numboxes);
  157903. } else {
  157904. b1 = find_biggest_volume(boxlist, numboxes);
  157905. }
  157906. if (b1 == NULL) /* no splittable boxes left! */
  157907. break;
  157908. b2 = &boxlist[numboxes]; /* where new box will go */
  157909. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157910. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157911. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157912. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157913. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157914. #if RGB_RED == 0
  157915. cmax = c1; n = 1;
  157916. if (c0 > cmax) { cmax = c0; n = 0; }
  157917. if (c2 > cmax) { n = 2; }
  157918. #else
  157919. cmax = c1; n = 1;
  157920. if (c2 > cmax) { cmax = c2; n = 2; }
  157921. if (c0 > cmax) { n = 0; }
  157922. #endif
  157923. switch (n) {
  157924. case 0:
  157925. lb = (b1->c0max + b1->c0min) / 2;
  157926. b1->c0max = lb;
  157927. b2->c0min = lb+1;
  157928. break;
  157929. case 1:
  157930. lb = (b1->c1max + b1->c1min) / 2;
  157931. b1->c1max = lb;
  157932. b2->c1min = lb+1;
  157933. break;
  157934. case 2:
  157935. lb = (b1->c2max + b1->c2min) / 2;
  157936. b1->c2max = lb;
  157937. b2->c2min = lb+1;
  157938. break;
  157939. }
  157940. update_box(cinfo, b1);
  157941. update_box(cinfo, b2);
  157942. numboxes++;
  157943. }
  157944. return numboxes;
  157945. }
  157946. LOCAL(void)
  157947. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157948. {
  157949. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157950. hist3d histogram = cquantize->histogram;
  157951. histptr histp;
  157952. int c0,c1,c2;
  157953. int c0min,c0max,c1min,c1max,c2min,c2max;
  157954. long count;
  157955. long total = 0;
  157956. long c0total = 0;
  157957. long c1total = 0;
  157958. long c2total = 0;
  157959. c0min = boxp->c0min; c0max = boxp->c0max;
  157960. c1min = boxp->c1min; c1max = boxp->c1max;
  157961. c2min = boxp->c2min; c2max = boxp->c2max;
  157962. for (c0 = c0min; c0 <= c0max; c0++)
  157963. for (c1 = c1min; c1 <= c1max; c1++) {
  157964. histp = & histogram[c0][c1][c2min];
  157965. for (c2 = c2min; c2 <= c2max; c2++) {
  157966. if ((count = *histp++) != 0) {
  157967. total += count;
  157968. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157969. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157970. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157971. }
  157972. }
  157973. }
  157974. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157975. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157976. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157977. }
  157978. LOCAL(void)
  157979. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157980. {
  157981. boxptr boxlist;
  157982. int numboxes;
  157983. int i;
  157984. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157985. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157986. numboxes = 1;
  157987. boxlist[0].c0min = 0;
  157988. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157989. boxlist[0].c1min = 0;
  157990. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157991. boxlist[0].c2min = 0;
  157992. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157993. update_box(cinfo, & boxlist[0]);
  157994. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157995. for (i = 0; i < numboxes; i++)
  157996. compute_color(cinfo, & boxlist[i], i);
  157997. cinfo->actual_number_of_colors = numboxes;
  157998. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157999. }
  158000. #define BOX_C0_LOG (HIST_C0_BITS-3)
  158001. #define BOX_C1_LOG (HIST_C1_BITS-3)
  158002. #define BOX_C2_LOG (HIST_C2_BITS-3)
  158003. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  158004. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  158005. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  158006. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  158007. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  158008. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  158009. LOCAL(int)
  158010. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158011. JSAMPLE colorlist[])
  158012. {
  158013. int numcolors = cinfo->actual_number_of_colors;
  158014. int maxc0, maxc1, maxc2;
  158015. int centerc0, centerc1, centerc2;
  158016. int i, x, ncolors;
  158017. INT32 minmaxdist, min_dist, max_dist, tdist;
  158018. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  158019. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  158020. centerc0 = (minc0 + maxc0) >> 1;
  158021. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  158022. centerc1 = (minc1 + maxc1) >> 1;
  158023. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  158024. centerc2 = (minc2 + maxc2) >> 1;
  158025. minmaxdist = 0x7FFFFFFFL;
  158026. for (i = 0; i < numcolors; i++) {
  158027. x = GETJSAMPLE(cinfo->colormap[0][i]);
  158028. if (x < minc0) {
  158029. tdist = (x - minc0) * C0_SCALE;
  158030. min_dist = tdist*tdist;
  158031. tdist = (x - maxc0) * C0_SCALE;
  158032. max_dist = tdist*tdist;
  158033. } else if (x > maxc0) {
  158034. tdist = (x - maxc0) * C0_SCALE;
  158035. min_dist = tdist*tdist;
  158036. tdist = (x - minc0) * C0_SCALE;
  158037. max_dist = tdist*tdist;
  158038. } else {
  158039. min_dist = 0;
  158040. if (x <= centerc0) {
  158041. tdist = (x - maxc0) * C0_SCALE;
  158042. max_dist = tdist*tdist;
  158043. } else {
  158044. tdist = (x - minc0) * C0_SCALE;
  158045. max_dist = tdist*tdist;
  158046. }
  158047. }
  158048. x = GETJSAMPLE(cinfo->colormap[1][i]);
  158049. if (x < minc1) {
  158050. tdist = (x - minc1) * C1_SCALE;
  158051. min_dist += tdist*tdist;
  158052. tdist = (x - maxc1) * C1_SCALE;
  158053. max_dist += tdist*tdist;
  158054. } else if (x > maxc1) {
  158055. tdist = (x - maxc1) * C1_SCALE;
  158056. min_dist += tdist*tdist;
  158057. tdist = (x - minc1) * C1_SCALE;
  158058. max_dist += tdist*tdist;
  158059. } else {
  158060. if (x <= centerc1) {
  158061. tdist = (x - maxc1) * C1_SCALE;
  158062. max_dist += tdist*tdist;
  158063. } else {
  158064. tdist = (x - minc1) * C1_SCALE;
  158065. max_dist += tdist*tdist;
  158066. }
  158067. }
  158068. x = GETJSAMPLE(cinfo->colormap[2][i]);
  158069. if (x < minc2) {
  158070. tdist = (x - minc2) * C2_SCALE;
  158071. min_dist += tdist*tdist;
  158072. tdist = (x - maxc2) * C2_SCALE;
  158073. max_dist += tdist*tdist;
  158074. } else if (x > maxc2) {
  158075. tdist = (x - maxc2) * C2_SCALE;
  158076. min_dist += tdist*tdist;
  158077. tdist = (x - minc2) * C2_SCALE;
  158078. max_dist += tdist*tdist;
  158079. } else {
  158080. if (x <= centerc2) {
  158081. tdist = (x - maxc2) * C2_SCALE;
  158082. max_dist += tdist*tdist;
  158083. } else {
  158084. tdist = (x - minc2) * C2_SCALE;
  158085. max_dist += tdist*tdist;
  158086. }
  158087. }
  158088. mindist[i] = min_dist; /* save away the results */
  158089. if (max_dist < minmaxdist)
  158090. minmaxdist = max_dist;
  158091. }
  158092. ncolors = 0;
  158093. for (i = 0; i < numcolors; i++) {
  158094. if (mindist[i] <= minmaxdist)
  158095. colorlist[ncolors++] = (JSAMPLE) i;
  158096. }
  158097. return ncolors;
  158098. }
  158099. LOCAL(void)
  158100. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158101. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  158102. {
  158103. int ic0, ic1, ic2;
  158104. int i, icolor;
  158105. register INT32 * bptr; /* pointer into bestdist[] array */
  158106. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158107. INT32 dist0, dist1; /* initial distance values */
  158108. register INT32 dist2; /* current distance in inner loop */
  158109. INT32 xx0, xx1; /* distance increments */
  158110. register INT32 xx2;
  158111. INT32 inc0, inc1, inc2; /* initial values for increments */
  158112. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158113. bptr = bestdist;
  158114. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  158115. *bptr++ = 0x7FFFFFFFL;
  158116. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  158117. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  158118. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  158119. for (i = 0; i < numcolors; i++) {
  158120. icolor = GETJSAMPLE(colorlist[i]);
  158121. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  158122. dist0 = inc0*inc0;
  158123. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  158124. dist0 += inc1*inc1;
  158125. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  158126. dist0 += inc2*inc2;
  158127. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  158128. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  158129. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  158130. bptr = bestdist;
  158131. cptr = bestcolor;
  158132. xx0 = inc0;
  158133. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  158134. dist1 = dist0;
  158135. xx1 = inc1;
  158136. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  158137. dist2 = dist1;
  158138. xx2 = inc2;
  158139. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  158140. if (dist2 < *bptr) {
  158141. *bptr = dist2;
  158142. *cptr = (JSAMPLE) icolor;
  158143. }
  158144. dist2 += xx2;
  158145. xx2 += 2 * STEP_C2 * STEP_C2;
  158146. bptr++;
  158147. cptr++;
  158148. }
  158149. dist1 += xx1;
  158150. xx1 += 2 * STEP_C1 * STEP_C1;
  158151. }
  158152. dist0 += xx0;
  158153. xx0 += 2 * STEP_C0 * STEP_C0;
  158154. }
  158155. }
  158156. }
  158157. LOCAL(void)
  158158. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  158159. {
  158160. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158161. hist3d histogram = cquantize->histogram;
  158162. int minc0, minc1, minc2; /* lower left corner of update box */
  158163. int ic0, ic1, ic2;
  158164. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158165. register histptr cachep; /* pointer into main cache array */
  158166. JSAMPLE colorlist[MAXNUMCOLORS];
  158167. int numcolors; /* number of candidate colors */
  158168. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158169. c0 >>= BOX_C0_LOG;
  158170. c1 >>= BOX_C1_LOG;
  158171. c2 >>= BOX_C2_LOG;
  158172. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  158173. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  158174. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  158175. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  158176. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  158177. bestcolor);
  158178. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  158179. c1 <<= BOX_C1_LOG;
  158180. c2 <<= BOX_C2_LOG;
  158181. cptr = bestcolor;
  158182. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  158183. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  158184. cachep = & histogram[c0+ic0][c1+ic1][c2];
  158185. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  158186. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  158187. }
  158188. }
  158189. }
  158190. }
  158191. METHODDEF(void)
  158192. pass2_no_dither (j_decompress_ptr cinfo,
  158193. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158194. {
  158195. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158196. hist3d histogram = cquantize->histogram;
  158197. register JSAMPROW inptr, outptr;
  158198. register histptr cachep;
  158199. register int c0, c1, c2;
  158200. int row;
  158201. JDIMENSION col;
  158202. JDIMENSION width = cinfo->output_width;
  158203. for (row = 0; row < num_rows; row++) {
  158204. inptr = input_buf[row];
  158205. outptr = output_buf[row];
  158206. for (col = width; col > 0; col--) {
  158207. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  158208. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  158209. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  158210. cachep = & histogram[c0][c1][c2];
  158211. if (*cachep == 0)
  158212. fill_inverse_cmap(cinfo, c0,c1,c2);
  158213. *outptr++ = (JSAMPLE) (*cachep - 1);
  158214. }
  158215. }
  158216. }
  158217. METHODDEF(void)
  158218. pass2_fs_dither (j_decompress_ptr cinfo,
  158219. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158220. {
  158221. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158222. hist3d histogram = cquantize->histogram;
  158223. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  158224. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  158225. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  158226. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  158227. JSAMPROW inptr; /* => current input pixel */
  158228. JSAMPROW outptr; /* => current output pixel */
  158229. histptr cachep;
  158230. int dir; /* +1 or -1 depending on direction */
  158231. int dir3; /* 3*dir, for advancing inptr & errorptr */
  158232. int row;
  158233. JDIMENSION col;
  158234. JDIMENSION width = cinfo->output_width;
  158235. JSAMPLE *range_limit = cinfo->sample_range_limit;
  158236. int *error_limit = cquantize->error_limiter;
  158237. JSAMPROW colormap0 = cinfo->colormap[0];
  158238. JSAMPROW colormap1 = cinfo->colormap[1];
  158239. JSAMPROW colormap2 = cinfo->colormap[2];
  158240. SHIFT_TEMPS
  158241. for (row = 0; row < num_rows; row++) {
  158242. inptr = input_buf[row];
  158243. outptr = output_buf[row];
  158244. if (cquantize->on_odd_row) {
  158245. inptr += (width-1) * 3; /* so point to rightmost pixel */
  158246. outptr += width-1;
  158247. dir = -1;
  158248. dir3 = -3;
  158249. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  158250. cquantize->on_odd_row = FALSE; /* flip for next time */
  158251. } else {
  158252. dir = 1;
  158253. dir3 = 3;
  158254. errorptr = cquantize->fserrors; /* => entry before first real column */
  158255. cquantize->on_odd_row = TRUE; /* flip for next time */
  158256. }
  158257. cur0 = cur1 = cur2 = 0;
  158258. belowerr0 = belowerr1 = belowerr2 = 0;
  158259. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  158260. for (col = width; col > 0; col--) {
  158261. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  158262. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  158263. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  158264. cur0 = error_limit[cur0];
  158265. cur1 = error_limit[cur1];
  158266. cur2 = error_limit[cur2];
  158267. cur0 += GETJSAMPLE(inptr[0]);
  158268. cur1 += GETJSAMPLE(inptr[1]);
  158269. cur2 += GETJSAMPLE(inptr[2]);
  158270. cur0 = GETJSAMPLE(range_limit[cur0]);
  158271. cur1 = GETJSAMPLE(range_limit[cur1]);
  158272. cur2 = GETJSAMPLE(range_limit[cur2]);
  158273. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  158274. if (*cachep == 0)
  158275. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  158276. { register int pixcode = *cachep - 1;
  158277. *outptr = (JSAMPLE) pixcode;
  158278. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  158279. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  158280. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  158281. }
  158282. { register LOCFSERROR bnexterr, delta;
  158283. bnexterr = cur0; /* Process component 0 */
  158284. delta = cur0 * 2;
  158285. cur0 += delta; /* form error * 3 */
  158286. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  158287. cur0 += delta; /* form error * 5 */
  158288. bpreverr0 = belowerr0 + cur0;
  158289. belowerr0 = bnexterr;
  158290. cur0 += delta; /* form error * 7 */
  158291. bnexterr = cur1; /* Process component 1 */
  158292. delta = cur1 * 2;
  158293. cur1 += delta; /* form error * 3 */
  158294. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  158295. cur1 += delta; /* form error * 5 */
  158296. bpreverr1 = belowerr1 + cur1;
  158297. belowerr1 = bnexterr;
  158298. cur1 += delta; /* form error * 7 */
  158299. bnexterr = cur2; /* Process component 2 */
  158300. delta = cur2 * 2;
  158301. cur2 += delta; /* form error * 3 */
  158302. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  158303. cur2 += delta; /* form error * 5 */
  158304. bpreverr2 = belowerr2 + cur2;
  158305. belowerr2 = bnexterr;
  158306. cur2 += delta; /* form error * 7 */
  158307. }
  158308. inptr += dir3; /* Advance pixel pointers to next column */
  158309. outptr += dir;
  158310. errorptr += dir3; /* advance errorptr to current column */
  158311. }
  158312. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158313. errorptr[1] = (FSERROR) bpreverr1;
  158314. errorptr[2] = (FSERROR) bpreverr2;
  158315. }
  158316. }
  158317. LOCAL(void)
  158318. init_error_limit (j_decompress_ptr cinfo)
  158319. {
  158320. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158321. int * table;
  158322. int in, out;
  158323. table = (int *) (*cinfo->mem->alloc_small)
  158324. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158325. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158326. cquantize->error_limiter = table;
  158327. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158328. out = 0;
  158329. for (in = 0; in < STEPSIZE; in++, out++) {
  158330. table[in] = out; table[-in] = -out;
  158331. }
  158332. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158333. table[in] = out; table[-in] = -out;
  158334. }
  158335. for (; in <= MAXJSAMPLE; in++) {
  158336. table[in] = out; table[-in] = -out;
  158337. }
  158338. #undef STEPSIZE
  158339. }
  158340. METHODDEF(void)
  158341. finish_pass1 (j_decompress_ptr cinfo)
  158342. {
  158343. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158344. cinfo->colormap = cquantize->sv_colormap;
  158345. select_colors(cinfo, cquantize->desired);
  158346. cquantize->needs_zeroed = TRUE;
  158347. }
  158348. METHODDEF(void)
  158349. finish_pass2 (j_decompress_ptr cinfo)
  158350. {
  158351. }
  158352. METHODDEF(void)
  158353. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158354. {
  158355. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158356. hist3d histogram = cquantize->histogram;
  158357. int i;
  158358. if (cinfo->dither_mode != JDITHER_NONE)
  158359. cinfo->dither_mode = JDITHER_FS;
  158360. if (is_pre_scan) {
  158361. cquantize->pub.color_quantize = prescan_quantize;
  158362. cquantize->pub.finish_pass = finish_pass1;
  158363. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158364. } else {
  158365. if (cinfo->dither_mode == JDITHER_FS)
  158366. cquantize->pub.color_quantize = pass2_fs_dither;
  158367. else
  158368. cquantize->pub.color_quantize = pass2_no_dither;
  158369. cquantize->pub.finish_pass = finish_pass2;
  158370. i = cinfo->actual_number_of_colors;
  158371. if (i < 1)
  158372. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158373. if (i > MAXNUMCOLORS)
  158374. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158375. if (cinfo->dither_mode == JDITHER_FS) {
  158376. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158377. (3 * SIZEOF(FSERROR)));
  158378. if (cquantize->fserrors == NULL)
  158379. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158380. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158381. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158382. if (cquantize->error_limiter == NULL)
  158383. init_error_limit(cinfo);
  158384. cquantize->on_odd_row = FALSE;
  158385. }
  158386. }
  158387. if (cquantize->needs_zeroed) {
  158388. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158389. jzero_far((void FAR *) histogram[i],
  158390. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158391. }
  158392. cquantize->needs_zeroed = FALSE;
  158393. }
  158394. }
  158395. METHODDEF(void)
  158396. new_color_map_2_quant (j_decompress_ptr cinfo)
  158397. {
  158398. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158399. cquantize->needs_zeroed = TRUE;
  158400. }
  158401. GLOBAL(void)
  158402. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158403. {
  158404. my_cquantize_ptr2 cquantize;
  158405. int i;
  158406. cquantize = (my_cquantize_ptr2)
  158407. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158408. SIZEOF(my_cquantizer2));
  158409. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158410. cquantize->pub.start_pass = start_pass_2_quant;
  158411. cquantize->pub.new_color_map = new_color_map_2_quant;
  158412. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158413. cquantize->error_limiter = NULL;
  158414. if (cinfo->out_color_components != 3)
  158415. ERREXIT(cinfo, JERR_NOTIMPL);
  158416. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158417. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158418. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158419. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158420. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158421. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158422. }
  158423. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158424. if (cinfo->enable_2pass_quant) {
  158425. int desired = cinfo->desired_number_of_colors;
  158426. if (desired < 8)
  158427. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158428. if (desired > MAXNUMCOLORS)
  158429. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158430. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158431. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158432. cquantize->desired = desired;
  158433. } else
  158434. cquantize->sv_colormap = NULL;
  158435. if (cinfo->dither_mode != JDITHER_NONE)
  158436. cinfo->dither_mode = JDITHER_FS;
  158437. if (cinfo->dither_mode == JDITHER_FS) {
  158438. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158439. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158440. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158441. init_error_limit(cinfo);
  158442. }
  158443. }
  158444. #endif /* QUANT_2PASS_SUPPORTED */
  158445. /*** End of inlined file: jquant2.c ***/
  158446. /*** Start of inlined file: jutils.c ***/
  158447. #define JPEG_INTERNALS
  158448. #if 0 /* This table is not actually needed in v6a */
  158449. const int jpeg_zigzag_order[DCTSIZE2] = {
  158450. 0, 1, 5, 6, 14, 15, 27, 28,
  158451. 2, 4, 7, 13, 16, 26, 29, 42,
  158452. 3, 8, 12, 17, 25, 30, 41, 43,
  158453. 9, 11, 18, 24, 31, 40, 44, 53,
  158454. 10, 19, 23, 32, 39, 45, 52, 54,
  158455. 20, 22, 33, 38, 46, 51, 55, 60,
  158456. 21, 34, 37, 47, 50, 56, 59, 61,
  158457. 35, 36, 48, 49, 57, 58, 62, 63
  158458. };
  158459. #endif
  158460. const int jpeg_natural_order[DCTSIZE2+16] = {
  158461. 0, 1, 8, 16, 9, 2, 3, 10,
  158462. 17, 24, 32, 25, 18, 11, 4, 5,
  158463. 12, 19, 26, 33, 40, 48, 41, 34,
  158464. 27, 20, 13, 6, 7, 14, 21, 28,
  158465. 35, 42, 49, 56, 57, 50, 43, 36,
  158466. 29, 22, 15, 23, 30, 37, 44, 51,
  158467. 58, 59, 52, 45, 38, 31, 39, 46,
  158468. 53, 60, 61, 54, 47, 55, 62, 63,
  158469. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158470. 63, 63, 63, 63, 63, 63, 63, 63
  158471. };
  158472. GLOBAL(long)
  158473. jdiv_round_up (long a, long b)
  158474. {
  158475. return (a + b - 1L) / b;
  158476. }
  158477. GLOBAL(long)
  158478. jround_up (long a, long b)
  158479. {
  158480. a += b - 1L;
  158481. return a - (a % b);
  158482. }
  158483. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158484. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158485. #define FMEMZERO(target,size) MEMZERO(target,size)
  158486. #else /* 80x86 case, define if we can */
  158487. #ifdef USE_FMEM
  158488. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158489. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158490. #endif
  158491. #endif
  158492. GLOBAL(void)
  158493. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158494. JSAMPARRAY output_array, int dest_row,
  158495. int num_rows, JDIMENSION num_cols)
  158496. {
  158497. register JSAMPROW inptr, outptr;
  158498. #ifdef FMEMCOPY
  158499. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158500. #else
  158501. register JDIMENSION count;
  158502. #endif
  158503. register int row;
  158504. input_array += source_row;
  158505. output_array += dest_row;
  158506. for (row = num_rows; row > 0; row--) {
  158507. inptr = *input_array++;
  158508. outptr = *output_array++;
  158509. #ifdef FMEMCOPY
  158510. FMEMCOPY(outptr, inptr, count);
  158511. #else
  158512. for (count = num_cols; count > 0; count--)
  158513. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158514. #endif
  158515. }
  158516. }
  158517. GLOBAL(void)
  158518. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158519. JDIMENSION num_blocks)
  158520. {
  158521. #ifdef FMEMCOPY
  158522. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158523. #else
  158524. register JCOEFPTR inptr, outptr;
  158525. register long count;
  158526. inptr = (JCOEFPTR) input_row;
  158527. outptr = (JCOEFPTR) output_row;
  158528. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158529. *outptr++ = *inptr++;
  158530. }
  158531. #endif
  158532. }
  158533. GLOBAL(void)
  158534. jzero_far (void FAR * target, size_t bytestozero)
  158535. {
  158536. #ifdef FMEMZERO
  158537. FMEMZERO(target, bytestozero);
  158538. #else
  158539. register char FAR * ptr = (char FAR *) target;
  158540. register size_t count;
  158541. for (count = bytestozero; count > 0; count--) {
  158542. *ptr++ = 0;
  158543. }
  158544. #endif
  158545. }
  158546. /*** End of inlined file: jutils.c ***/
  158547. /*** Start of inlined file: transupp.c ***/
  158548. #define JPEG_INTERNALS
  158549. /*** Start of inlined file: transupp.h ***/
  158550. #ifndef TRANSFORMS_SUPPORTED
  158551. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158552. #endif
  158553. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158554. #define jtransform_request_workspace jTrRequest
  158555. #define jtransform_adjust_parameters jTrAdjust
  158556. #define jtransform_execute_transformation jTrExec
  158557. #define jcopy_markers_setup jCMrkSetup
  158558. #define jcopy_markers_execute jCMrkExec
  158559. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158560. typedef enum {
  158561. JXFORM_NONE, /* no transformation */
  158562. JXFORM_FLIP_H, /* horizontal flip */
  158563. JXFORM_FLIP_V, /* vertical flip */
  158564. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158565. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158566. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158567. JXFORM_ROT_180, /* 180-degree rotation */
  158568. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158569. } JXFORM_CODE;
  158570. typedef struct {
  158571. JXFORM_CODE transform; /* image transform operator */
  158572. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158573. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158574. int num_components; /* # of components in workspace */
  158575. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158576. } jpeg_transform_info;
  158577. #if TRANSFORMS_SUPPORTED
  158578. EXTERN(void) jtransform_request_workspace
  158579. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158580. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158581. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158582. jvirt_barray_ptr *src_coef_arrays,
  158583. jpeg_transform_info *info));
  158584. EXTERN(void) jtransform_execute_transformation
  158585. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158586. jvirt_barray_ptr *src_coef_arrays,
  158587. jpeg_transform_info *info));
  158588. #endif /* TRANSFORMS_SUPPORTED */
  158589. typedef enum {
  158590. JCOPYOPT_NONE, /* copy no optional markers */
  158591. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158592. JCOPYOPT_ALL /* copy all optional markers */
  158593. } JCOPY_OPTION;
  158594. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158595. EXTERN(void) jcopy_markers_setup
  158596. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158597. EXTERN(void) jcopy_markers_execute
  158598. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158599. JCOPY_OPTION option));
  158600. /*** End of inlined file: transupp.h ***/
  158601. /* My own external interface */
  158602. #if TRANSFORMS_SUPPORTED
  158603. LOCAL(void)
  158604. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158605. jvirt_barray_ptr *src_coef_arrays)
  158606. {
  158607. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158608. int ci, k, offset_y;
  158609. JBLOCKARRAY buffer;
  158610. JCOEFPTR ptr1, ptr2;
  158611. JCOEF temp1, temp2;
  158612. jpeg_component_info *compptr;
  158613. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158614. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158615. compptr = dstinfo->comp_info + ci;
  158616. comp_width = MCU_cols * compptr->h_samp_factor;
  158617. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158618. blk_y += compptr->v_samp_factor) {
  158619. buffer = (*srcinfo->mem->access_virt_barray)
  158620. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158621. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158622. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158623. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158624. ptr1 = buffer[offset_y][blk_x];
  158625. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158626. for (k = 0; k < DCTSIZE2; k += 2) {
  158627. temp1 = *ptr1; /* swap even column */
  158628. temp2 = *ptr2;
  158629. *ptr1++ = temp2;
  158630. *ptr2++ = temp1;
  158631. temp1 = *ptr1; /* swap odd column with sign change */
  158632. temp2 = *ptr2;
  158633. *ptr1++ = -temp2;
  158634. *ptr2++ = -temp1;
  158635. }
  158636. }
  158637. }
  158638. }
  158639. }
  158640. }
  158641. LOCAL(void)
  158642. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158643. jvirt_barray_ptr *src_coef_arrays,
  158644. jvirt_barray_ptr *dst_coef_arrays)
  158645. {
  158646. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158647. int ci, i, j, offset_y;
  158648. JBLOCKARRAY src_buffer, dst_buffer;
  158649. JBLOCKROW src_row_ptr, dst_row_ptr;
  158650. JCOEFPTR src_ptr, dst_ptr;
  158651. jpeg_component_info *compptr;
  158652. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158653. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158654. compptr = dstinfo->comp_info + ci;
  158655. comp_height = MCU_rows * compptr->v_samp_factor;
  158656. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158657. dst_blk_y += compptr->v_samp_factor) {
  158658. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158659. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158660. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158661. if (dst_blk_y < comp_height) {
  158662. src_buffer = (*srcinfo->mem->access_virt_barray)
  158663. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158664. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158665. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158666. } else {
  158667. src_buffer = (*srcinfo->mem->access_virt_barray)
  158668. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158669. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158670. }
  158671. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158672. if (dst_blk_y < comp_height) {
  158673. dst_row_ptr = dst_buffer[offset_y];
  158674. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158675. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158676. dst_blk_x++) {
  158677. dst_ptr = dst_row_ptr[dst_blk_x];
  158678. src_ptr = src_row_ptr[dst_blk_x];
  158679. for (i = 0; i < DCTSIZE; i += 2) {
  158680. for (j = 0; j < DCTSIZE; j++)
  158681. *dst_ptr++ = *src_ptr++;
  158682. for (j = 0; j < DCTSIZE; j++)
  158683. *dst_ptr++ = - *src_ptr++;
  158684. }
  158685. }
  158686. } else {
  158687. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158688. compptr->width_in_blocks);
  158689. }
  158690. }
  158691. }
  158692. }
  158693. }
  158694. LOCAL(void)
  158695. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158696. jvirt_barray_ptr *src_coef_arrays,
  158697. jvirt_barray_ptr *dst_coef_arrays)
  158698. {
  158699. JDIMENSION dst_blk_x, dst_blk_y;
  158700. int ci, i, j, offset_x, offset_y;
  158701. JBLOCKARRAY src_buffer, dst_buffer;
  158702. JCOEFPTR src_ptr, dst_ptr;
  158703. jpeg_component_info *compptr;
  158704. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158705. compptr = dstinfo->comp_info + ci;
  158706. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158707. dst_blk_y += compptr->v_samp_factor) {
  158708. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158709. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158710. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158711. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158712. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158713. dst_blk_x += compptr->h_samp_factor) {
  158714. src_buffer = (*srcinfo->mem->access_virt_barray)
  158715. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158716. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158717. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158718. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158719. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158720. for (i = 0; i < DCTSIZE; i++)
  158721. for (j = 0; j < DCTSIZE; j++)
  158722. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158723. }
  158724. }
  158725. }
  158726. }
  158727. }
  158728. }
  158729. LOCAL(void)
  158730. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158731. jvirt_barray_ptr *src_coef_arrays,
  158732. jvirt_barray_ptr *dst_coef_arrays)
  158733. {
  158734. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158735. int ci, i, j, offset_x, offset_y;
  158736. JBLOCKARRAY src_buffer, dst_buffer;
  158737. JCOEFPTR src_ptr, dst_ptr;
  158738. jpeg_component_info *compptr;
  158739. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158740. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158741. compptr = dstinfo->comp_info + ci;
  158742. comp_width = MCU_cols * compptr->h_samp_factor;
  158743. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158744. dst_blk_y += compptr->v_samp_factor) {
  158745. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158746. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158747. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158748. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158749. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158750. dst_blk_x += compptr->h_samp_factor) {
  158751. src_buffer = (*srcinfo->mem->access_virt_barray)
  158752. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158753. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158754. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158755. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158756. if (dst_blk_x < comp_width) {
  158757. dst_ptr = dst_buffer[offset_y]
  158758. [comp_width - dst_blk_x - offset_x - 1];
  158759. for (i = 0; i < DCTSIZE; i++) {
  158760. for (j = 0; j < DCTSIZE; j++)
  158761. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158762. i++;
  158763. for (j = 0; j < DCTSIZE; j++)
  158764. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158765. }
  158766. } else {
  158767. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158768. for (i = 0; i < DCTSIZE; i++)
  158769. for (j = 0; j < DCTSIZE; j++)
  158770. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158771. }
  158772. }
  158773. }
  158774. }
  158775. }
  158776. }
  158777. }
  158778. LOCAL(void)
  158779. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158780. jvirt_barray_ptr *src_coef_arrays,
  158781. jvirt_barray_ptr *dst_coef_arrays)
  158782. {
  158783. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158784. int ci, i, j, offset_x, offset_y;
  158785. JBLOCKARRAY src_buffer, dst_buffer;
  158786. JCOEFPTR src_ptr, dst_ptr;
  158787. jpeg_component_info *compptr;
  158788. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158789. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158790. compptr = dstinfo->comp_info + ci;
  158791. comp_height = MCU_rows * compptr->v_samp_factor;
  158792. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158793. dst_blk_y += compptr->v_samp_factor) {
  158794. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158795. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158796. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158797. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158798. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158799. dst_blk_x += compptr->h_samp_factor) {
  158800. src_buffer = (*srcinfo->mem->access_virt_barray)
  158801. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158802. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158803. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158804. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158805. if (dst_blk_y < comp_height) {
  158806. src_ptr = src_buffer[offset_x]
  158807. [comp_height - dst_blk_y - offset_y - 1];
  158808. for (i = 0; i < DCTSIZE; i++) {
  158809. for (j = 0; j < DCTSIZE; j++) {
  158810. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158811. j++;
  158812. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158813. }
  158814. }
  158815. } else {
  158816. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158817. for (i = 0; i < DCTSIZE; i++)
  158818. for (j = 0; j < DCTSIZE; j++)
  158819. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158820. }
  158821. }
  158822. }
  158823. }
  158824. }
  158825. }
  158826. }
  158827. LOCAL(void)
  158828. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158829. jvirt_barray_ptr *src_coef_arrays,
  158830. jvirt_barray_ptr *dst_coef_arrays)
  158831. {
  158832. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158833. int ci, i, j, offset_y;
  158834. JBLOCKARRAY src_buffer, dst_buffer;
  158835. JBLOCKROW src_row_ptr, dst_row_ptr;
  158836. JCOEFPTR src_ptr, dst_ptr;
  158837. jpeg_component_info *compptr;
  158838. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158839. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158840. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158841. compptr = dstinfo->comp_info + ci;
  158842. comp_width = MCU_cols * compptr->h_samp_factor;
  158843. comp_height = MCU_rows * compptr->v_samp_factor;
  158844. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158845. dst_blk_y += compptr->v_samp_factor) {
  158846. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158847. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158848. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158849. if (dst_blk_y < comp_height) {
  158850. src_buffer = (*srcinfo->mem->access_virt_barray)
  158851. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158852. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158853. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158854. } else {
  158855. src_buffer = (*srcinfo->mem->access_virt_barray)
  158856. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158857. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158858. }
  158859. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158860. if (dst_blk_y < comp_height) {
  158861. dst_row_ptr = dst_buffer[offset_y];
  158862. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158863. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158864. dst_ptr = dst_row_ptr[dst_blk_x];
  158865. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158866. for (i = 0; i < DCTSIZE; i += 2) {
  158867. for (j = 0; j < DCTSIZE; j += 2) {
  158868. *dst_ptr++ = *src_ptr++;
  158869. *dst_ptr++ = - *src_ptr++;
  158870. }
  158871. for (j = 0; j < DCTSIZE; j += 2) {
  158872. *dst_ptr++ = - *src_ptr++;
  158873. *dst_ptr++ = *src_ptr++;
  158874. }
  158875. }
  158876. }
  158877. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158878. dst_ptr = dst_row_ptr[dst_blk_x];
  158879. src_ptr = src_row_ptr[dst_blk_x];
  158880. for (i = 0; i < DCTSIZE; i += 2) {
  158881. for (j = 0; j < DCTSIZE; j++)
  158882. *dst_ptr++ = *src_ptr++;
  158883. for (j = 0; j < DCTSIZE; j++)
  158884. *dst_ptr++ = - *src_ptr++;
  158885. }
  158886. }
  158887. } else {
  158888. dst_row_ptr = dst_buffer[offset_y];
  158889. src_row_ptr = src_buffer[offset_y];
  158890. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158891. dst_ptr = dst_row_ptr[dst_blk_x];
  158892. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158893. for (i = 0; i < DCTSIZE2; i += 2) {
  158894. *dst_ptr++ = *src_ptr++;
  158895. *dst_ptr++ = - *src_ptr++;
  158896. }
  158897. }
  158898. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158899. dst_ptr = dst_row_ptr[dst_blk_x];
  158900. src_ptr = src_row_ptr[dst_blk_x];
  158901. for (i = 0; i < DCTSIZE2; i++)
  158902. *dst_ptr++ = *src_ptr++;
  158903. }
  158904. }
  158905. }
  158906. }
  158907. }
  158908. }
  158909. LOCAL(void)
  158910. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158911. jvirt_barray_ptr *src_coef_arrays,
  158912. jvirt_barray_ptr *dst_coef_arrays)
  158913. {
  158914. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158915. int ci, i, j, offset_x, offset_y;
  158916. JBLOCKARRAY src_buffer, dst_buffer;
  158917. JCOEFPTR src_ptr, dst_ptr;
  158918. jpeg_component_info *compptr;
  158919. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158920. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158921. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158922. compptr = dstinfo->comp_info + ci;
  158923. comp_width = MCU_cols * compptr->h_samp_factor;
  158924. comp_height = MCU_rows * compptr->v_samp_factor;
  158925. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158926. dst_blk_y += compptr->v_samp_factor) {
  158927. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158928. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158929. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158930. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158931. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158932. dst_blk_x += compptr->h_samp_factor) {
  158933. src_buffer = (*srcinfo->mem->access_virt_barray)
  158934. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158935. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158936. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158937. if (dst_blk_y < comp_height) {
  158938. src_ptr = src_buffer[offset_x]
  158939. [comp_height - dst_blk_y - offset_y - 1];
  158940. if (dst_blk_x < comp_width) {
  158941. dst_ptr = dst_buffer[offset_y]
  158942. [comp_width - dst_blk_x - offset_x - 1];
  158943. for (i = 0; i < DCTSIZE; i++) {
  158944. for (j = 0; j < DCTSIZE; j++) {
  158945. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158946. j++;
  158947. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158948. }
  158949. i++;
  158950. for (j = 0; j < DCTSIZE; j++) {
  158951. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158952. j++;
  158953. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158954. }
  158955. }
  158956. } else {
  158957. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158958. for (i = 0; i < DCTSIZE; i++) {
  158959. for (j = 0; j < DCTSIZE; j++) {
  158960. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158961. j++;
  158962. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158963. }
  158964. }
  158965. }
  158966. } else {
  158967. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158968. if (dst_blk_x < comp_width) {
  158969. dst_ptr = dst_buffer[offset_y]
  158970. [comp_width - dst_blk_x - offset_x - 1];
  158971. for (i = 0; i < DCTSIZE; i++) {
  158972. for (j = 0; j < DCTSIZE; j++)
  158973. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158974. i++;
  158975. for (j = 0; j < DCTSIZE; j++)
  158976. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158977. }
  158978. } else {
  158979. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158980. for (i = 0; i < DCTSIZE; i++)
  158981. for (j = 0; j < DCTSIZE; j++)
  158982. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158983. }
  158984. }
  158985. }
  158986. }
  158987. }
  158988. }
  158989. }
  158990. }
  158991. GLOBAL(void)
  158992. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158993. jpeg_transform_info *info)
  158994. {
  158995. jvirt_barray_ptr *coef_arrays = NULL;
  158996. jpeg_component_info *compptr;
  158997. int ci;
  158998. if (info->force_grayscale &&
  158999. srcinfo->jpeg_color_space == JCS_YCbCr &&
  159000. srcinfo->num_components == 3) {
  159001. info->num_components = 1;
  159002. } else {
  159003. info->num_components = srcinfo->num_components;
  159004. }
  159005. switch (info->transform) {
  159006. case JXFORM_NONE:
  159007. case JXFORM_FLIP_H:
  159008. break;
  159009. case JXFORM_FLIP_V:
  159010. case JXFORM_ROT_180:
  159011. coef_arrays = (jvirt_barray_ptr *)
  159012. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159013. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159014. for (ci = 0; ci < info->num_components; ci++) {
  159015. compptr = srcinfo->comp_info + ci;
  159016. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159017. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159018. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159019. (long) compptr->h_samp_factor),
  159020. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159021. (long) compptr->v_samp_factor),
  159022. (JDIMENSION) compptr->v_samp_factor);
  159023. }
  159024. break;
  159025. case JXFORM_TRANSPOSE:
  159026. case JXFORM_TRANSVERSE:
  159027. case JXFORM_ROT_90:
  159028. case JXFORM_ROT_270:
  159029. coef_arrays = (jvirt_barray_ptr *)
  159030. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159031. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159032. for (ci = 0; ci < info->num_components; ci++) {
  159033. compptr = srcinfo->comp_info + ci;
  159034. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159035. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159036. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159037. (long) compptr->v_samp_factor),
  159038. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159039. (long) compptr->h_samp_factor),
  159040. (JDIMENSION) compptr->h_samp_factor);
  159041. }
  159042. break;
  159043. }
  159044. info->workspace_coef_arrays = coef_arrays;
  159045. }
  159046. LOCAL(void)
  159047. transpose_critical_parameters (j_compress_ptr dstinfo)
  159048. {
  159049. int tblno, i, j, ci, itemp;
  159050. jpeg_component_info *compptr;
  159051. JQUANT_TBL *qtblptr;
  159052. JDIMENSION dtemp;
  159053. UINT16 qtemp;
  159054. dtemp = dstinfo->image_width;
  159055. dstinfo->image_width = dstinfo->image_height;
  159056. dstinfo->image_height = dtemp;
  159057. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159058. compptr = dstinfo->comp_info + ci;
  159059. itemp = compptr->h_samp_factor;
  159060. compptr->h_samp_factor = compptr->v_samp_factor;
  159061. compptr->v_samp_factor = itemp;
  159062. }
  159063. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  159064. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  159065. if (qtblptr != NULL) {
  159066. for (i = 0; i < DCTSIZE; i++) {
  159067. for (j = 0; j < i; j++) {
  159068. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  159069. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  159070. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  159071. }
  159072. }
  159073. }
  159074. }
  159075. }
  159076. LOCAL(void)
  159077. trim_right_edge (j_compress_ptr dstinfo)
  159078. {
  159079. int ci, max_h_samp_factor;
  159080. JDIMENSION MCU_cols;
  159081. max_h_samp_factor = 1;
  159082. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159083. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  159084. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  159085. }
  159086. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  159087. if (MCU_cols > 0) /* can't trim to 0 pixels */
  159088. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  159089. }
  159090. LOCAL(void)
  159091. trim_bottom_edge (j_compress_ptr dstinfo)
  159092. {
  159093. int ci, max_v_samp_factor;
  159094. JDIMENSION MCU_rows;
  159095. max_v_samp_factor = 1;
  159096. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159097. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  159098. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  159099. }
  159100. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  159101. if (MCU_rows > 0) /* can't trim to 0 pixels */
  159102. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  159103. }
  159104. GLOBAL(jvirt_barray_ptr *)
  159105. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  159106. j_compress_ptr dstinfo,
  159107. jvirt_barray_ptr *src_coef_arrays,
  159108. jpeg_transform_info *info)
  159109. {
  159110. if (info->force_grayscale) {
  159111. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  159112. dstinfo->num_components == 3) ||
  159113. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  159114. dstinfo->num_components == 1)) {
  159115. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  159116. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  159117. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  159118. } else {
  159119. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  159120. }
  159121. }
  159122. switch (info->transform) {
  159123. case JXFORM_NONE:
  159124. break;
  159125. case JXFORM_FLIP_H:
  159126. if (info->trim)
  159127. trim_right_edge(dstinfo);
  159128. break;
  159129. case JXFORM_FLIP_V:
  159130. if (info->trim)
  159131. trim_bottom_edge(dstinfo);
  159132. break;
  159133. case JXFORM_TRANSPOSE:
  159134. transpose_critical_parameters(dstinfo);
  159135. break;
  159136. case JXFORM_TRANSVERSE:
  159137. transpose_critical_parameters(dstinfo);
  159138. if (info->trim) {
  159139. trim_right_edge(dstinfo);
  159140. trim_bottom_edge(dstinfo);
  159141. }
  159142. break;
  159143. case JXFORM_ROT_90:
  159144. transpose_critical_parameters(dstinfo);
  159145. if (info->trim)
  159146. trim_right_edge(dstinfo);
  159147. break;
  159148. case JXFORM_ROT_180:
  159149. if (info->trim) {
  159150. trim_right_edge(dstinfo);
  159151. trim_bottom_edge(dstinfo);
  159152. }
  159153. break;
  159154. case JXFORM_ROT_270:
  159155. transpose_critical_parameters(dstinfo);
  159156. if (info->trim)
  159157. trim_bottom_edge(dstinfo);
  159158. break;
  159159. }
  159160. if (info->workspace_coef_arrays != NULL)
  159161. return info->workspace_coef_arrays;
  159162. return src_coef_arrays;
  159163. }
  159164. GLOBAL(void)
  159165. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  159166. j_compress_ptr dstinfo,
  159167. jvirt_barray_ptr *src_coef_arrays,
  159168. jpeg_transform_info *info)
  159169. {
  159170. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  159171. switch (info->transform) {
  159172. case JXFORM_NONE:
  159173. break;
  159174. case JXFORM_FLIP_H:
  159175. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  159176. break;
  159177. case JXFORM_FLIP_V:
  159178. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159179. break;
  159180. case JXFORM_TRANSPOSE:
  159181. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159182. break;
  159183. case JXFORM_TRANSVERSE:
  159184. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159185. break;
  159186. case JXFORM_ROT_90:
  159187. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159188. break;
  159189. case JXFORM_ROT_180:
  159190. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159191. break;
  159192. case JXFORM_ROT_270:
  159193. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159194. break;
  159195. }
  159196. }
  159197. #endif /* TRANSFORMS_SUPPORTED */
  159198. GLOBAL(void)
  159199. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  159200. {
  159201. #ifdef SAVE_MARKERS_SUPPORTED
  159202. int m;
  159203. if (option != JCOPYOPT_NONE) {
  159204. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  159205. }
  159206. if (option == JCOPYOPT_ALL) {
  159207. for (m = 0; m < 16; m++)
  159208. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  159209. }
  159210. #endif /* SAVE_MARKERS_SUPPORTED */
  159211. }
  159212. GLOBAL(void)
  159213. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159214. JCOPY_OPTION option)
  159215. {
  159216. jpeg_saved_marker_ptr marker;
  159217. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  159218. if (dstinfo->write_JFIF_header &&
  159219. marker->marker == JPEG_APP0 &&
  159220. marker->data_length >= 5 &&
  159221. GETJOCTET(marker->data[0]) == 0x4A &&
  159222. GETJOCTET(marker->data[1]) == 0x46 &&
  159223. GETJOCTET(marker->data[2]) == 0x49 &&
  159224. GETJOCTET(marker->data[3]) == 0x46 &&
  159225. GETJOCTET(marker->data[4]) == 0)
  159226. continue; /* reject duplicate JFIF */
  159227. if (dstinfo->write_Adobe_marker &&
  159228. marker->marker == JPEG_APP0+14 &&
  159229. marker->data_length >= 5 &&
  159230. GETJOCTET(marker->data[0]) == 0x41 &&
  159231. GETJOCTET(marker->data[1]) == 0x64 &&
  159232. GETJOCTET(marker->data[2]) == 0x6F &&
  159233. GETJOCTET(marker->data[3]) == 0x62 &&
  159234. GETJOCTET(marker->data[4]) == 0x65)
  159235. continue; /* reject duplicate Adobe */
  159236. #ifdef NEED_FAR_POINTERS
  159237. {
  159238. unsigned int i;
  159239. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  159240. for (i = 0; i < marker->data_length; i++)
  159241. jpeg_write_m_byte(dstinfo, marker->data[i]);
  159242. }
  159243. #else
  159244. jpeg_write_marker(dstinfo, marker->marker,
  159245. marker->data, marker->data_length);
  159246. #endif
  159247. }
  159248. }
  159249. /*** End of inlined file: transupp.c ***/
  159250. }
  159251. #else
  159252. #define JPEG_INTERNALS
  159253. #undef FAR
  159254. #include <jpeglib.h>
  159255. #endif
  159256. }
  159257. #if JUCE_MSVC
  159258. #pragma warning (pop)
  159259. #endif
  159260. BEGIN_JUCE_NAMESPACE
  159261. using namespace jpeglibNamespace;
  159262. #if ! JUCE_MSVC
  159263. using jpeglibNamespace::boolean;
  159264. #endif
  159265. struct JPEGDecodingFailure {};
  159266. static void fatalErrorHandler (j_common_ptr)
  159267. {
  159268. throw JPEGDecodingFailure();
  159269. }
  159270. static void silentErrorCallback1 (j_common_ptr) {}
  159271. static void silentErrorCallback2 (j_common_ptr, int) {}
  159272. static void silentErrorCallback3 (j_common_ptr, char*) {}
  159273. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  159274. {
  159275. zerostruct (err);
  159276. err.error_exit = fatalErrorHandler;
  159277. err.emit_message = silentErrorCallback2;
  159278. err.output_message = silentErrorCallback1;
  159279. err.format_message = silentErrorCallback3;
  159280. err.reset_error_mgr = silentErrorCallback1;
  159281. }
  159282. static void dummyCallback1 (j_decompress_ptr)
  159283. {
  159284. }
  159285. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  159286. {
  159287. decompStruct->src->next_input_byte += num;
  159288. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  159289. decompStruct->src->bytes_in_buffer -= num;
  159290. }
  159291. static boolean jpegFill (j_decompress_ptr)
  159292. {
  159293. return 0;
  159294. }
  159295. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159296. {
  159297. MemoryBlock mb;
  159298. in.readIntoMemoryBlock (mb);
  159299. Image* image = 0;
  159300. if (mb.getSize() > 16)
  159301. {
  159302. struct jpeg_decompress_struct jpegDecompStruct;
  159303. struct jpeg_error_mgr jerr;
  159304. setupSilentErrorHandler (jerr);
  159305. jpegDecompStruct.err = &jerr;
  159306. jpeg_create_decompress (&jpegDecompStruct);
  159307. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159308. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159309. jpegDecompStruct.src->init_source = dummyCallback1;
  159310. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159311. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159312. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159313. jpegDecompStruct.src->term_source = dummyCallback1;
  159314. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159315. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159316. try
  159317. {
  159318. jpeg_read_header (&jpegDecompStruct, TRUE);
  159319. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159320. const int width = jpegDecompStruct.output_width;
  159321. const int height = jpegDecompStruct.output_height;
  159322. jpegDecompStruct.out_color_space = JCS_RGB;
  159323. JSAMPARRAY buffer
  159324. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159325. JPOOL_IMAGE,
  159326. width * 3, 1);
  159327. if (jpeg_start_decompress (&jpegDecompStruct))
  159328. {
  159329. image = Image::createNativeImage (Image::RGB, width, height, false);
  159330. const bool hasAlphaChan = image->hasAlphaChannel();
  159331. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159332. for (int y = 0; y < height; ++y)
  159333. {
  159334. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159335. const uint8* src = *buffer;
  159336. uint8* dest = destData.getLinePointer (y);
  159337. if (hasAlphaChan)
  159338. {
  159339. for (int i = width; --i >= 0;)
  159340. {
  159341. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159342. ((PixelARGB*) dest)->premultiply();
  159343. dest += destData.pixelStride;
  159344. src += 3;
  159345. }
  159346. }
  159347. else
  159348. {
  159349. for (int i = width; --i >= 0;)
  159350. {
  159351. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159352. dest += destData.pixelStride;
  159353. src += 3;
  159354. }
  159355. }
  159356. }
  159357. jpeg_finish_decompress (&jpegDecompStruct);
  159358. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159359. }
  159360. jpeg_destroy_decompress (&jpegDecompStruct);
  159361. }
  159362. catch (...)
  159363. {}
  159364. }
  159365. return image;
  159366. }
  159367. static const int jpegBufferSize = 512;
  159368. struct JuceJpegDest : public jpeg_destination_mgr
  159369. {
  159370. OutputStream* output;
  159371. char* buffer;
  159372. };
  159373. static void jpegWriteInit (j_compress_ptr)
  159374. {
  159375. }
  159376. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159377. {
  159378. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159379. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159380. dest->output->write (dest->buffer, (int) numToWrite);
  159381. }
  159382. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159383. {
  159384. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159385. const int numToWrite = jpegBufferSize;
  159386. dest->next_output_byte = (JOCTET*) dest->buffer;
  159387. dest->free_in_buffer = jpegBufferSize;
  159388. return dest->output->write (dest->buffer, numToWrite);
  159389. }
  159390. bool juce_writeJPEGImageToStream (const Image& image,
  159391. OutputStream& out,
  159392. float quality)
  159393. {
  159394. if (image.hasAlphaChannel())
  159395. {
  159396. // this method could fill the background in white and still save the image..
  159397. jassertfalse
  159398. return true;
  159399. }
  159400. struct jpeg_compress_struct jpegCompStruct;
  159401. struct jpeg_error_mgr jerr;
  159402. setupSilentErrorHandler (jerr);
  159403. jpegCompStruct.err = &jerr;
  159404. jpeg_create_compress (&jpegCompStruct);
  159405. JuceJpegDest dest;
  159406. jpegCompStruct.dest = &dest;
  159407. dest.output = &out;
  159408. HeapBlock <char> tempBuffer (jpegBufferSize);
  159409. dest.buffer = (char*) tempBuffer;
  159410. dest.next_output_byte = (JOCTET*) dest.buffer;
  159411. dest.free_in_buffer = jpegBufferSize;
  159412. dest.init_destination = jpegWriteInit;
  159413. dest.empty_output_buffer = jpegWriteFlush;
  159414. dest.term_destination = jpegWriteTerminate;
  159415. jpegCompStruct.image_width = image.getWidth();
  159416. jpegCompStruct.image_height = image.getHeight();
  159417. jpegCompStruct.input_components = 3;
  159418. jpegCompStruct.in_color_space = JCS_RGB;
  159419. jpegCompStruct.write_JFIF_header = 1;
  159420. jpegCompStruct.X_density = 72;
  159421. jpegCompStruct.Y_density = 72;
  159422. jpeg_set_defaults (&jpegCompStruct);
  159423. jpegCompStruct.dct_method = JDCT_FLOAT;
  159424. jpegCompStruct.optimize_coding = 1;
  159425. // jpegCompStruct.smoothing_factor = 10;
  159426. if (quality < 0.0f)
  159427. quality = 0.85f;
  159428. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159429. jpeg_start_compress (&jpegCompStruct, TRUE);
  159430. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159431. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159432. JPOOL_IMAGE,
  159433. strideBytes, 1);
  159434. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159435. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159436. {
  159437. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159438. uint8* dst = *buffer;
  159439. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159440. {
  159441. *dst++ = ((const PixelRGB*) src)->getRed();
  159442. *dst++ = ((const PixelRGB*) src)->getGreen();
  159443. *dst++ = ((const PixelRGB*) src)->getBlue();
  159444. src += srcData.pixelStride;
  159445. }
  159446. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159447. }
  159448. jpeg_finish_compress (&jpegCompStruct);
  159449. jpeg_destroy_compress (&jpegCompStruct);
  159450. out.flush();
  159451. return true;
  159452. }
  159453. END_JUCE_NAMESPACE
  159454. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159455. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159456. #ifdef _MSC_VER
  159457. #pragma warning (push)
  159458. #pragma warning (disable: 4390 4611)
  159459. #endif
  159460. namespace zlibNamespace
  159461. {
  159462. #if JUCE_INCLUDE_ZLIB_CODE
  159463. #undef OS_CODE
  159464. #undef fdopen
  159465. #undef OS_CODE
  159466. #else
  159467. #include <zlib.h>
  159468. #endif
  159469. }
  159470. namespace pnglibNamespace
  159471. {
  159472. using namespace zlibNamespace;
  159473. #if JUCE_INCLUDE_PNGLIB_CODE
  159474. #if _MSC_VER != 1310
  159475. using ::calloc; // (causes conflict in VS.NET 2003)
  159476. using ::malloc;
  159477. using ::free;
  159478. #endif
  159479. extern "C"
  159480. {
  159481. using ::abs;
  159482. #define PNG_INTERNAL
  159483. #define NO_DUMMY_DECL
  159484. #define PNG_SETJMP_NOT_SUPPORTED
  159485. /*** Start of inlined file: png.h ***/
  159486. #ifndef PNG_H
  159487. #define PNG_H
  159488. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159489. #define PNG_HEADER_VERSION_STRING \
  159490. " libpng version 1.2.21 - October 4, 2007\n"
  159491. #define PNG_LIBPNG_VER_SONUM 0
  159492. #define PNG_LIBPNG_VER_DLLNUM 13
  159493. #define PNG_LIBPNG_VER_MAJOR 1
  159494. #define PNG_LIBPNG_VER_MINOR 2
  159495. #define PNG_LIBPNG_VER_RELEASE 21
  159496. #define PNG_LIBPNG_VER_BUILD 0
  159497. #define PNG_LIBPNG_BUILD_ALPHA 1
  159498. #define PNG_LIBPNG_BUILD_BETA 2
  159499. #define PNG_LIBPNG_BUILD_RC 3
  159500. #define PNG_LIBPNG_BUILD_STABLE 4
  159501. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159502. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159503. PNG_LIBPNG_BUILD_STABLE only */
  159504. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159505. PNG_LIBPNG_BUILD_SPECIAL */
  159506. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159507. PNG_LIBPNG_BUILD_PRIVATE */
  159508. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159509. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159510. #ifndef PNG_VERSION_INFO_ONLY
  159511. #endif
  159512. /*** Start of inlined file: pngconf.h ***/
  159513. #ifndef PNGCONF_H
  159514. #define PNGCONF_H
  159515. #define PNG_1_2_X
  159516. // These are some Juce config settings that should remove any unnecessary code bloat..
  159517. #define PNG_NO_STDIO 1
  159518. #define PNG_DEBUG 0
  159519. #define PNG_NO_WARNINGS 1
  159520. #define PNG_NO_ERROR_TEXT 1
  159521. #define PNG_NO_ERROR_NUMBERS 1
  159522. #define PNG_NO_USER_MEM 1
  159523. #define PNG_NO_READ_iCCP 1
  159524. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159525. #define PNG_NO_READ_USER_CHUNKS 1
  159526. #define PNG_NO_READ_iTXt 1
  159527. #define PNG_NO_READ_sCAL 1
  159528. #define PNG_NO_READ_sPLT 1
  159529. #define png_error(a, b) png_err(a)
  159530. #define png_warning(a, b)
  159531. #define png_chunk_error(a, b) png_err(a)
  159532. #define png_chunk_warning(a, b)
  159533. #ifdef PNG_USER_CONFIG
  159534. # ifndef PNG_USER_PRIVATEBUILD
  159535. # define PNG_USER_PRIVATEBUILD
  159536. # endif
  159537. #include "pngusr.h"
  159538. #endif
  159539. #ifdef PNG_CONFIGURE_LIBPNG
  159540. #ifdef HAVE_CONFIG_H
  159541. #include "config.h"
  159542. #endif
  159543. #endif
  159544. #ifdef __STDC__
  159545. #ifdef SPECIALBUILD
  159546. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159547. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159548. #endif
  159549. #ifdef PRIVATEBUILD
  159550. # pragma message("PRIVATEBUILD is deprecated.\
  159551. Use PNG_USER_PRIVATEBUILD instead.")
  159552. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159553. #endif
  159554. #endif /* __STDC__ */
  159555. #ifndef PNG_VERSION_INFO_ONLY
  159556. # define PNG_WARN_UNINITIALIZED_ROW 1
  159557. #ifndef PNG_ZBUF_SIZE
  159558. # define PNG_ZBUF_SIZE 8192
  159559. #endif
  159560. #ifndef PNG_NO_READ_SUPPORTED
  159561. # define PNG_READ_SUPPORTED
  159562. #endif
  159563. #ifndef PNG_NO_WRITE_SUPPORTED
  159564. # define PNG_WRITE_SUPPORTED
  159565. #endif
  159566. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159567. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159568. # define PNG_MNG_FEATURES_SUPPORTED
  159569. # endif
  159570. #endif
  159571. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159572. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159573. # define PNG_FLOATING_POINT_SUPPORTED
  159574. # endif
  159575. #endif
  159576. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159577. # define PNG_MAX_MALLOC_64K
  159578. #endif
  159579. #if defined(__CYGWIN__)
  159580. # if defined(ALL_STATIC)
  159581. # if defined(PNG_BUILD_DLL)
  159582. # undef PNG_BUILD_DLL
  159583. # endif
  159584. # if defined(PNG_USE_DLL)
  159585. # undef PNG_USE_DLL
  159586. # endif
  159587. # if defined(PNG_DLL)
  159588. # undef PNG_DLL
  159589. # endif
  159590. # if !defined(PNG_STATIC)
  159591. # define PNG_STATIC
  159592. # endif
  159593. # else
  159594. # if defined (PNG_BUILD_DLL)
  159595. # if defined(PNG_STATIC)
  159596. # undef PNG_STATIC
  159597. # endif
  159598. # if defined(PNG_USE_DLL)
  159599. # undef PNG_USE_DLL
  159600. # endif
  159601. # if !defined(PNG_DLL)
  159602. # define PNG_DLL
  159603. # endif
  159604. # else
  159605. # if defined(PNG_STATIC)
  159606. # if defined(PNG_USE_DLL)
  159607. # undef PNG_USE_DLL
  159608. # endif
  159609. # if defined(PNG_DLL)
  159610. # undef PNG_DLL
  159611. # endif
  159612. # else
  159613. # if !defined(PNG_USE_DLL)
  159614. # define PNG_USE_DLL
  159615. # endif
  159616. # if !defined(PNG_DLL)
  159617. # define PNG_DLL
  159618. # endif
  159619. # endif
  159620. # endif
  159621. # endif
  159622. #endif
  159623. #if defined(_WIN32_WCE)
  159624. # include <windows.h>
  159625. # define PNG_NO_CONSOLE_IO
  159626. # ifdef PNG_DEBUG
  159627. # undef PNG_DEBUG
  159628. # endif
  159629. #endif
  159630. #ifdef PNG_BUILD_DLL
  159631. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159632. # ifndef PNG_NO_CONSOLE_IO
  159633. # define PNG_NO_CONSOLE_IO
  159634. # endif
  159635. # endif
  159636. #endif
  159637. # ifdef PNG_NO_STDIO
  159638. # ifndef PNG_NO_CONSOLE_IO
  159639. # define PNG_NO_CONSOLE_IO
  159640. # endif
  159641. # ifdef PNG_DEBUG
  159642. # if (PNG_DEBUG > 0)
  159643. # include <stdio.h>
  159644. # endif
  159645. # endif
  159646. # else
  159647. # if !defined(_WIN32_WCE)
  159648. # include <stdio.h>
  159649. # endif
  159650. # endif
  159651. #ifndef PNGARG
  159652. #ifdef OF /* zlib prototype munger */
  159653. # define PNGARG(arglist) OF(arglist)
  159654. #else
  159655. #ifdef _NO_PROTO
  159656. # define PNGARG(arglist) ()
  159657. # ifndef PNG_TYPECAST_NULL
  159658. # define PNG_TYPECAST_NULL
  159659. # endif
  159660. #else
  159661. # define PNGARG(arglist) arglist
  159662. #endif /* _NO_PROTO */
  159663. #endif /* OF */
  159664. #endif /* PNGARG */
  159665. #ifndef MACOS
  159666. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159667. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159668. # define MACOS
  159669. # endif
  159670. #endif
  159671. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159672. # include <sys/types.h>
  159673. #endif
  159674. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159675. # define PNG_SETJMP_SUPPORTED
  159676. #endif
  159677. #ifdef PNG_SETJMP_SUPPORTED
  159678. # ifdef __linux__
  159679. # ifdef _BSD_SOURCE
  159680. # define PNG_SAVE_BSD_SOURCE
  159681. # undef _BSD_SOURCE
  159682. # endif
  159683. # ifdef _SETJMP_H
  159684. __png.h__ already includes setjmp.h;
  159685. __dont__ include it again.;
  159686. # endif
  159687. # endif /* __linux__ */
  159688. # include <setjmp.h>
  159689. # ifdef __linux__
  159690. # ifdef PNG_SAVE_BSD_SOURCE
  159691. # define _BSD_SOURCE
  159692. # undef PNG_SAVE_BSD_SOURCE
  159693. # endif
  159694. # endif /* __linux__ */
  159695. #endif /* PNG_SETJMP_SUPPORTED */
  159696. #ifdef BSD
  159697. #if ! JUCE_MAC
  159698. # include <strings.h>
  159699. #endif
  159700. #else
  159701. # include <string.h>
  159702. #endif
  159703. #ifdef PNG_INTERNAL
  159704. #include <stdlib.h>
  159705. #define PNG_EXTERN
  159706. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159707. # if defined(MACOS)
  159708. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159709. # include <fp.h>
  159710. # endif
  159711. # else
  159712. # include <math.h>
  159713. # endif
  159714. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159715. # include <m68881.h>
  159716. # endif
  159717. #endif
  159718. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159719. # define PNG_ALWAYS_EXTERN
  159720. #endif
  159721. #if defined(__TURBOC__) && defined(__MSDOS__)
  159722. # include <mem.h>
  159723. # include <alloc.h>
  159724. #endif
  159725. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159726. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159727. # include <malloc.h>
  159728. #endif
  159729. #ifndef PNG_DITHER_RED_BITS
  159730. # define PNG_DITHER_RED_BITS 5
  159731. #endif
  159732. #ifndef PNG_DITHER_GREEN_BITS
  159733. # define PNG_DITHER_GREEN_BITS 5
  159734. #endif
  159735. #ifndef PNG_DITHER_BLUE_BITS
  159736. # define PNG_DITHER_BLUE_BITS 5
  159737. #endif
  159738. #ifndef PNG_MAX_GAMMA_8
  159739. # define PNG_MAX_GAMMA_8 11
  159740. #endif
  159741. #ifndef PNG_GAMMA_THRESHOLD
  159742. # define PNG_GAMMA_THRESHOLD 0.05
  159743. #endif
  159744. #endif /* PNG_INTERNAL */
  159745. #ifndef PNG_NO_CONST
  159746. # define PNG_CONST const
  159747. #else
  159748. # define PNG_CONST
  159749. #endif
  159750. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159751. # ifndef PNG_NO_iTXt_SUPPORTED
  159752. # define PNG_NO_iTXt_SUPPORTED
  159753. # endif
  159754. # ifndef PNG_NO_READ_iTXt
  159755. # define PNG_NO_READ_iTXt
  159756. # endif
  159757. # ifndef PNG_NO_WRITE_iTXt
  159758. # define PNG_NO_WRITE_iTXt
  159759. # endif
  159760. #endif
  159761. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159762. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159763. # define PNG_READ_iTXt
  159764. # endif
  159765. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159766. # define PNG_WRITE_iTXt
  159767. # endif
  159768. #endif
  159769. #ifdef PNG_LEGACY_SUPPORTED
  159770. # define PNG_NO_FREE_ME
  159771. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159772. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159773. # define PNG_NO_READ_USER_CHUNKS
  159774. # define PNG_NO_READ_iCCP
  159775. # define PNG_NO_WRITE_iCCP
  159776. # define PNG_NO_READ_iTXt
  159777. # define PNG_NO_WRITE_iTXt
  159778. # define PNG_NO_READ_sCAL
  159779. # define PNG_NO_WRITE_sCAL
  159780. # define PNG_NO_READ_sPLT
  159781. # define PNG_NO_WRITE_sPLT
  159782. # define PNG_NO_INFO_IMAGE
  159783. # define PNG_NO_READ_RGB_TO_GRAY
  159784. # define PNG_NO_READ_USER_TRANSFORM
  159785. # define PNG_NO_WRITE_USER_TRANSFORM
  159786. # define PNG_NO_USER_MEM
  159787. # define PNG_NO_READ_EMPTY_PLTE
  159788. # define PNG_NO_MNG_FEATURES
  159789. # define PNG_NO_FIXED_POINT_SUPPORTED
  159790. #endif
  159791. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159792. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159793. # define PNG_FIXED_POINT_SUPPORTED
  159794. #endif
  159795. #ifndef PNG_NO_FREE_ME
  159796. # define PNG_FREE_ME_SUPPORTED
  159797. #endif
  159798. #if defined(PNG_READ_SUPPORTED)
  159799. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159800. !defined(PNG_NO_READ_TRANSFORMS)
  159801. # define PNG_READ_TRANSFORMS_SUPPORTED
  159802. #endif
  159803. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159804. # ifndef PNG_NO_READ_EXPAND
  159805. # define PNG_READ_EXPAND_SUPPORTED
  159806. # endif
  159807. # ifndef PNG_NO_READ_SHIFT
  159808. # define PNG_READ_SHIFT_SUPPORTED
  159809. # endif
  159810. # ifndef PNG_NO_READ_PACK
  159811. # define PNG_READ_PACK_SUPPORTED
  159812. # endif
  159813. # ifndef PNG_NO_READ_BGR
  159814. # define PNG_READ_BGR_SUPPORTED
  159815. # endif
  159816. # ifndef PNG_NO_READ_SWAP
  159817. # define PNG_READ_SWAP_SUPPORTED
  159818. # endif
  159819. # ifndef PNG_NO_READ_PACKSWAP
  159820. # define PNG_READ_PACKSWAP_SUPPORTED
  159821. # endif
  159822. # ifndef PNG_NO_READ_INVERT
  159823. # define PNG_READ_INVERT_SUPPORTED
  159824. # endif
  159825. # ifndef PNG_NO_READ_DITHER
  159826. # define PNG_READ_DITHER_SUPPORTED
  159827. # endif
  159828. # ifndef PNG_NO_READ_BACKGROUND
  159829. # define PNG_READ_BACKGROUND_SUPPORTED
  159830. # endif
  159831. # ifndef PNG_NO_READ_16_TO_8
  159832. # define PNG_READ_16_TO_8_SUPPORTED
  159833. # endif
  159834. # ifndef PNG_NO_READ_FILLER
  159835. # define PNG_READ_FILLER_SUPPORTED
  159836. # endif
  159837. # ifndef PNG_NO_READ_GAMMA
  159838. # define PNG_READ_GAMMA_SUPPORTED
  159839. # endif
  159840. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159841. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159842. # endif
  159843. # ifndef PNG_NO_READ_SWAP_ALPHA
  159844. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159845. # endif
  159846. # ifndef PNG_NO_READ_INVERT_ALPHA
  159847. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159848. # endif
  159849. # ifndef PNG_NO_READ_STRIP_ALPHA
  159850. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159851. # endif
  159852. # ifndef PNG_NO_READ_USER_TRANSFORM
  159853. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159854. # endif
  159855. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159856. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159857. # endif
  159858. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159859. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159860. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159861. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159862. #endif /* about interlacing capability! You'll */
  159863. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159864. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159865. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159866. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159867. # endif
  159868. #endif
  159869. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159870. #ifndef PNG_NO_READ_EMPTY_PLTE
  159871. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159872. #endif
  159873. #endif
  159874. #endif /* PNG_READ_SUPPORTED */
  159875. #if defined(PNG_WRITE_SUPPORTED)
  159876. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159877. !defined(PNG_NO_WRITE_TRANSFORMS)
  159878. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159879. #endif
  159880. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159881. # ifndef PNG_NO_WRITE_SHIFT
  159882. # define PNG_WRITE_SHIFT_SUPPORTED
  159883. # endif
  159884. # ifndef PNG_NO_WRITE_PACK
  159885. # define PNG_WRITE_PACK_SUPPORTED
  159886. # endif
  159887. # ifndef PNG_NO_WRITE_BGR
  159888. # define PNG_WRITE_BGR_SUPPORTED
  159889. # endif
  159890. # ifndef PNG_NO_WRITE_SWAP
  159891. # define PNG_WRITE_SWAP_SUPPORTED
  159892. # endif
  159893. # ifndef PNG_NO_WRITE_PACKSWAP
  159894. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159895. # endif
  159896. # ifndef PNG_NO_WRITE_INVERT
  159897. # define PNG_WRITE_INVERT_SUPPORTED
  159898. # endif
  159899. # ifndef PNG_NO_WRITE_FILLER
  159900. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159901. # endif
  159902. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159903. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159904. # endif
  159905. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159906. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159907. # endif
  159908. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159909. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159910. # endif
  159911. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159912. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159913. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159914. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159915. encoders, but can cause trouble
  159916. if left undefined */
  159917. #endif
  159918. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159919. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159920. defined(PNG_FLOATING_POINT_SUPPORTED)
  159921. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159922. #endif
  159923. #ifndef PNG_NO_WRITE_FLUSH
  159924. # define PNG_WRITE_FLUSH_SUPPORTED
  159925. #endif
  159926. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159927. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159928. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159929. #endif
  159930. #endif
  159931. #endif /* PNG_WRITE_SUPPORTED */
  159932. #ifndef PNG_1_0_X
  159933. # ifndef PNG_NO_ERROR_NUMBERS
  159934. # define PNG_ERROR_NUMBERS_SUPPORTED
  159935. # endif
  159936. #endif /* PNG_1_0_X */
  159937. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159938. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159939. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159940. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159941. # endif
  159942. #endif
  159943. #ifndef PNG_NO_STDIO
  159944. # define PNG_TIME_RFC1123_SUPPORTED
  159945. #endif
  159946. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159947. # define PNG_EASY_ACCESS_SUPPORTED
  159948. #endif
  159949. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159950. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159951. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159952. # endif
  159953. #endif
  159954. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159955. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159956. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159957. # endif
  159958. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159959. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159960. # define PNG_NO_MMX_CODE
  159961. # endif
  159962. # endif
  159963. # if defined(__APPLE__)
  159964. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159965. # define PNG_NO_MMX_CODE
  159966. # endif
  159967. # endif
  159968. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159969. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159970. # define PNG_NO_MMX_CODE
  159971. # endif
  159972. # endif
  159973. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159974. # define PNG_MMX_CODE_SUPPORTED
  159975. # endif
  159976. #endif
  159977. #if !defined(PNG_1_0_X)
  159978. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159979. # define PNG_USER_MEM_SUPPORTED
  159980. #endif
  159981. #endif /* PNG_1_0_X */
  159982. #if !defined(PNG_1_0_X)
  159983. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159984. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159985. # define PNG_SET_USER_LIMITS_SUPPORTED
  159986. #endif
  159987. #endif
  159988. #endif /* PNG_1_0_X */
  159989. #ifndef PNG_USER_WIDTH_MAX
  159990. # define PNG_USER_WIDTH_MAX 1000000L
  159991. #endif
  159992. #ifndef PNG_USER_HEIGHT_MAX
  159993. # define PNG_USER_HEIGHT_MAX 1000000L
  159994. #endif
  159995. #if defined(PNG_READ_SUPPORTED) && \
  159996. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159997. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159998. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159999. #endif
  160000. #if defined(PNG_WRITE_SUPPORTED) && \
  160001. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160002. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  160003. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160004. #endif
  160005. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160006. #ifdef PNG_NO_READ_TEXT
  160007. # define PNG_NO_READ_iTXt
  160008. # define PNG_NO_READ_tEXt
  160009. # define PNG_NO_READ_zTXt
  160010. #endif
  160011. #ifndef PNG_NO_READ_bKGD
  160012. # define PNG_READ_bKGD_SUPPORTED
  160013. # define PNG_bKGD_SUPPORTED
  160014. #endif
  160015. #ifndef PNG_NO_READ_cHRM
  160016. # define PNG_READ_cHRM_SUPPORTED
  160017. # define PNG_cHRM_SUPPORTED
  160018. #endif
  160019. #ifndef PNG_NO_READ_gAMA
  160020. # define PNG_READ_gAMA_SUPPORTED
  160021. # define PNG_gAMA_SUPPORTED
  160022. #endif
  160023. #ifndef PNG_NO_READ_hIST
  160024. # define PNG_READ_hIST_SUPPORTED
  160025. # define PNG_hIST_SUPPORTED
  160026. #endif
  160027. #ifndef PNG_NO_READ_iCCP
  160028. # define PNG_READ_iCCP_SUPPORTED
  160029. # define PNG_iCCP_SUPPORTED
  160030. #endif
  160031. #ifndef PNG_NO_READ_iTXt
  160032. # ifndef PNG_READ_iTXt_SUPPORTED
  160033. # define PNG_READ_iTXt_SUPPORTED
  160034. # endif
  160035. # ifndef PNG_iTXt_SUPPORTED
  160036. # define PNG_iTXt_SUPPORTED
  160037. # endif
  160038. #endif
  160039. #ifndef PNG_NO_READ_oFFs
  160040. # define PNG_READ_oFFs_SUPPORTED
  160041. # define PNG_oFFs_SUPPORTED
  160042. #endif
  160043. #ifndef PNG_NO_READ_pCAL
  160044. # define PNG_READ_pCAL_SUPPORTED
  160045. # define PNG_pCAL_SUPPORTED
  160046. #endif
  160047. #ifndef PNG_NO_READ_sCAL
  160048. # define PNG_READ_sCAL_SUPPORTED
  160049. # define PNG_sCAL_SUPPORTED
  160050. #endif
  160051. #ifndef PNG_NO_READ_pHYs
  160052. # define PNG_READ_pHYs_SUPPORTED
  160053. # define PNG_pHYs_SUPPORTED
  160054. #endif
  160055. #ifndef PNG_NO_READ_sBIT
  160056. # define PNG_READ_sBIT_SUPPORTED
  160057. # define PNG_sBIT_SUPPORTED
  160058. #endif
  160059. #ifndef PNG_NO_READ_sPLT
  160060. # define PNG_READ_sPLT_SUPPORTED
  160061. # define PNG_sPLT_SUPPORTED
  160062. #endif
  160063. #ifndef PNG_NO_READ_sRGB
  160064. # define PNG_READ_sRGB_SUPPORTED
  160065. # define PNG_sRGB_SUPPORTED
  160066. #endif
  160067. #ifndef PNG_NO_READ_tEXt
  160068. # define PNG_READ_tEXt_SUPPORTED
  160069. # define PNG_tEXt_SUPPORTED
  160070. #endif
  160071. #ifndef PNG_NO_READ_tIME
  160072. # define PNG_READ_tIME_SUPPORTED
  160073. # define PNG_tIME_SUPPORTED
  160074. #endif
  160075. #ifndef PNG_NO_READ_tRNS
  160076. # define PNG_READ_tRNS_SUPPORTED
  160077. # define PNG_tRNS_SUPPORTED
  160078. #endif
  160079. #ifndef PNG_NO_READ_zTXt
  160080. # define PNG_READ_zTXt_SUPPORTED
  160081. # define PNG_zTXt_SUPPORTED
  160082. #endif
  160083. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  160084. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  160085. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160086. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160087. # endif
  160088. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160089. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160090. # endif
  160091. #endif
  160092. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  160093. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  160094. # define PNG_READ_USER_CHUNKS_SUPPORTED
  160095. # define PNG_USER_CHUNKS_SUPPORTED
  160096. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  160097. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  160098. # endif
  160099. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  160100. # undef PNG_NO_HANDLE_AS_UNKNOWN
  160101. # endif
  160102. #endif
  160103. #ifndef PNG_NO_READ_OPT_PLTE
  160104. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  160105. #endif /* optional PLTE chunk in RGB and RGBA images */
  160106. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  160107. defined(PNG_READ_zTXt_SUPPORTED)
  160108. # define PNG_READ_TEXT_SUPPORTED
  160109. # define PNG_TEXT_SUPPORTED
  160110. #endif
  160111. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  160112. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160113. #ifdef PNG_NO_WRITE_TEXT
  160114. # define PNG_NO_WRITE_iTXt
  160115. # define PNG_NO_WRITE_tEXt
  160116. # define PNG_NO_WRITE_zTXt
  160117. #endif
  160118. #ifndef PNG_NO_WRITE_bKGD
  160119. # define PNG_WRITE_bKGD_SUPPORTED
  160120. # ifndef PNG_bKGD_SUPPORTED
  160121. # define PNG_bKGD_SUPPORTED
  160122. # endif
  160123. #endif
  160124. #ifndef PNG_NO_WRITE_cHRM
  160125. # define PNG_WRITE_cHRM_SUPPORTED
  160126. # ifndef PNG_cHRM_SUPPORTED
  160127. # define PNG_cHRM_SUPPORTED
  160128. # endif
  160129. #endif
  160130. #ifndef PNG_NO_WRITE_gAMA
  160131. # define PNG_WRITE_gAMA_SUPPORTED
  160132. # ifndef PNG_gAMA_SUPPORTED
  160133. # define PNG_gAMA_SUPPORTED
  160134. # endif
  160135. #endif
  160136. #ifndef PNG_NO_WRITE_hIST
  160137. # define PNG_WRITE_hIST_SUPPORTED
  160138. # ifndef PNG_hIST_SUPPORTED
  160139. # define PNG_hIST_SUPPORTED
  160140. # endif
  160141. #endif
  160142. #ifndef PNG_NO_WRITE_iCCP
  160143. # define PNG_WRITE_iCCP_SUPPORTED
  160144. # ifndef PNG_iCCP_SUPPORTED
  160145. # define PNG_iCCP_SUPPORTED
  160146. # endif
  160147. #endif
  160148. #ifndef PNG_NO_WRITE_iTXt
  160149. # ifndef PNG_WRITE_iTXt_SUPPORTED
  160150. # define PNG_WRITE_iTXt_SUPPORTED
  160151. # endif
  160152. # ifndef PNG_iTXt_SUPPORTED
  160153. # define PNG_iTXt_SUPPORTED
  160154. # endif
  160155. #endif
  160156. #ifndef PNG_NO_WRITE_oFFs
  160157. # define PNG_WRITE_oFFs_SUPPORTED
  160158. # ifndef PNG_oFFs_SUPPORTED
  160159. # define PNG_oFFs_SUPPORTED
  160160. # endif
  160161. #endif
  160162. #ifndef PNG_NO_WRITE_pCAL
  160163. # define PNG_WRITE_pCAL_SUPPORTED
  160164. # ifndef PNG_pCAL_SUPPORTED
  160165. # define PNG_pCAL_SUPPORTED
  160166. # endif
  160167. #endif
  160168. #ifndef PNG_NO_WRITE_sCAL
  160169. # define PNG_WRITE_sCAL_SUPPORTED
  160170. # ifndef PNG_sCAL_SUPPORTED
  160171. # define PNG_sCAL_SUPPORTED
  160172. # endif
  160173. #endif
  160174. #ifndef PNG_NO_WRITE_pHYs
  160175. # define PNG_WRITE_pHYs_SUPPORTED
  160176. # ifndef PNG_pHYs_SUPPORTED
  160177. # define PNG_pHYs_SUPPORTED
  160178. # endif
  160179. #endif
  160180. #ifndef PNG_NO_WRITE_sBIT
  160181. # define PNG_WRITE_sBIT_SUPPORTED
  160182. # ifndef PNG_sBIT_SUPPORTED
  160183. # define PNG_sBIT_SUPPORTED
  160184. # endif
  160185. #endif
  160186. #ifndef PNG_NO_WRITE_sPLT
  160187. # define PNG_WRITE_sPLT_SUPPORTED
  160188. # ifndef PNG_sPLT_SUPPORTED
  160189. # define PNG_sPLT_SUPPORTED
  160190. # endif
  160191. #endif
  160192. #ifndef PNG_NO_WRITE_sRGB
  160193. # define PNG_WRITE_sRGB_SUPPORTED
  160194. # ifndef PNG_sRGB_SUPPORTED
  160195. # define PNG_sRGB_SUPPORTED
  160196. # endif
  160197. #endif
  160198. #ifndef PNG_NO_WRITE_tEXt
  160199. # define PNG_WRITE_tEXt_SUPPORTED
  160200. # ifndef PNG_tEXt_SUPPORTED
  160201. # define PNG_tEXt_SUPPORTED
  160202. # endif
  160203. #endif
  160204. #ifndef PNG_NO_WRITE_tIME
  160205. # define PNG_WRITE_tIME_SUPPORTED
  160206. # ifndef PNG_tIME_SUPPORTED
  160207. # define PNG_tIME_SUPPORTED
  160208. # endif
  160209. #endif
  160210. #ifndef PNG_NO_WRITE_tRNS
  160211. # define PNG_WRITE_tRNS_SUPPORTED
  160212. # ifndef PNG_tRNS_SUPPORTED
  160213. # define PNG_tRNS_SUPPORTED
  160214. # endif
  160215. #endif
  160216. #ifndef PNG_NO_WRITE_zTXt
  160217. # define PNG_WRITE_zTXt_SUPPORTED
  160218. # ifndef PNG_zTXt_SUPPORTED
  160219. # define PNG_zTXt_SUPPORTED
  160220. # endif
  160221. #endif
  160222. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  160223. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  160224. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160225. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160226. # endif
  160227. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160228. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160229. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160230. # endif
  160231. # endif
  160232. #endif
  160233. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  160234. defined(PNG_WRITE_zTXt_SUPPORTED)
  160235. # define PNG_WRITE_TEXT_SUPPORTED
  160236. # ifndef PNG_TEXT_SUPPORTED
  160237. # define PNG_TEXT_SUPPORTED
  160238. # endif
  160239. #endif
  160240. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  160241. #ifndef PNG_NO_INFO_IMAGE
  160242. # define PNG_INFO_IMAGE_SUPPORTED
  160243. #endif
  160244. #if defined(PNG_tIME_SUPPORTED)
  160245. # if !defined(_WIN32_WCE)
  160246. # include <time.h>
  160247. # endif
  160248. #endif
  160249. typedef unsigned long png_uint_32;
  160250. typedef long png_int_32;
  160251. typedef unsigned short png_uint_16;
  160252. typedef short png_int_16;
  160253. typedef unsigned char png_byte;
  160254. #ifdef PNG_SIZE_T
  160255. typedef PNG_SIZE_T png_size_t;
  160256. # define png_sizeof(x) png_convert_size(sizeof (x))
  160257. #else
  160258. typedef size_t png_size_t;
  160259. # define png_sizeof(x) sizeof (x)
  160260. #endif
  160261. #ifdef __BORLANDC__
  160262. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  160263. # define LDATA 1
  160264. # else
  160265. # define LDATA 0
  160266. # endif
  160267. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  160268. # define PNG_MAX_MALLOC_64K
  160269. # if (LDATA != 1)
  160270. # ifndef FAR
  160271. # define FAR __far
  160272. # endif
  160273. # define USE_FAR_KEYWORD
  160274. # endif /* LDATA != 1 */
  160275. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  160276. #endif /* __BORLANDC__ */
  160277. #if defined(FAR)
  160278. # if defined(M_I86MM)
  160279. # define USE_FAR_KEYWORD
  160280. # define FARDATA FAR
  160281. # include <dos.h>
  160282. # endif
  160283. #endif
  160284. #ifndef FAR
  160285. # define FAR
  160286. #endif
  160287. #ifndef FARDATA
  160288. # define FARDATA
  160289. #endif
  160290. typedef png_int_32 png_fixed_point;
  160291. typedef void FAR * png_voidp;
  160292. typedef png_byte FAR * png_bytep;
  160293. typedef png_uint_32 FAR * png_uint_32p;
  160294. typedef png_int_32 FAR * png_int_32p;
  160295. typedef png_uint_16 FAR * png_uint_16p;
  160296. typedef png_int_16 FAR * png_int_16p;
  160297. typedef PNG_CONST char FAR * png_const_charp;
  160298. typedef char FAR * png_charp;
  160299. typedef png_fixed_point FAR * png_fixed_point_p;
  160300. #ifndef PNG_NO_STDIO
  160301. #if defined(_WIN32_WCE)
  160302. typedef HANDLE png_FILE_p;
  160303. #else
  160304. typedef FILE * png_FILE_p;
  160305. #endif
  160306. #endif
  160307. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160308. typedef double FAR * png_doublep;
  160309. #endif
  160310. typedef png_byte FAR * FAR * png_bytepp;
  160311. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160312. typedef png_int_32 FAR * FAR * png_int_32pp;
  160313. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160314. typedef png_int_16 FAR * FAR * png_int_16pp;
  160315. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160316. typedef char FAR * FAR * png_charpp;
  160317. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160318. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160319. typedef double FAR * FAR * png_doublepp;
  160320. #endif
  160321. typedef char FAR * FAR * FAR * png_charppp;
  160322. #if 0
  160323. typedef charf * png_zcharp;
  160324. typedef charf * FAR * png_zcharpp;
  160325. typedef z_stream FAR * png_zstreamp;
  160326. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160327. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160328. # define PNG_DLL
  160329. #endif
  160330. #if defined(__CYGWIN__)
  160331. # if !defined(PNG_STATIC)
  160332. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160333. # undef PNG_USE_GLOBAL_ARRAYS
  160334. # endif
  160335. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160336. # define PNG_USE_LOCAL_ARRAYS
  160337. # endif
  160338. # else
  160339. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160340. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160341. # undef PNG_USE_GLOBAL_ARRAYS
  160342. # endif
  160343. # endif
  160344. # endif
  160345. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160346. # define PNG_USE_LOCAL_ARRAYS
  160347. # endif
  160348. #endif
  160349. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160350. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160351. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160352. # define PNG_USE_LOCAL_ARRAYS
  160353. # else
  160354. # define PNG_USE_GLOBAL_ARRAYS
  160355. # endif
  160356. #endif
  160357. #if defined(__CYGWIN__)
  160358. # undef PNGAPI
  160359. # define PNGAPI __cdecl
  160360. # undef PNG_IMPEXP
  160361. # define PNG_IMPEXP
  160362. #endif
  160363. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160364. # ifndef PNG_NO_MODULEDEF
  160365. # define PNG_NO_MODULEDEF
  160366. # endif
  160367. #endif
  160368. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160369. # define PNG_IMPEXP
  160370. #endif
  160371. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160372. (( defined(_Windows) || defined(_WINDOWS) || \
  160373. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160374. # ifndef PNGAPI
  160375. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160376. # define PNGAPI __cdecl
  160377. # else
  160378. # define PNGAPI _cdecl
  160379. # endif
  160380. # endif
  160381. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160382. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160383. # define PNG_IMPEXP
  160384. # endif
  160385. # if !defined(PNG_IMPEXP)
  160386. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160387. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160388. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160389. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160390. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160391. # else
  160392. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160393. # if defined(PNG_BUILD_DLL)
  160394. # define PNG_IMPEXP __export
  160395. # else
  160396. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160397. VC++ */
  160398. # endif /* Exists in Borland C++ for
  160399. C++ classes (== huge) */
  160400. # endif
  160401. # endif
  160402. # if !defined(PNG_IMPEXP)
  160403. # if defined(PNG_BUILD_DLL)
  160404. # define PNG_IMPEXP __declspec(dllexport)
  160405. # else
  160406. # define PNG_IMPEXP __declspec(dllimport)
  160407. # endif
  160408. # endif
  160409. # endif /* PNG_IMPEXP */
  160410. #else /* !(DLL || non-cygwin WINDOWS) */
  160411. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160412. # ifndef PNGAPI
  160413. # define PNGAPI _System
  160414. # endif
  160415. # else
  160416. # if 0 /* ... other platforms, with other meanings */
  160417. # endif
  160418. # endif
  160419. #endif
  160420. #ifndef PNGAPI
  160421. # define PNGAPI
  160422. #endif
  160423. #ifndef PNG_IMPEXP
  160424. # define PNG_IMPEXP
  160425. #endif
  160426. #ifdef PNG_BUILDSYMS
  160427. # ifndef PNG_EXPORT
  160428. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160429. # endif
  160430. # ifdef PNG_USE_GLOBAL_ARRAYS
  160431. # ifndef PNG_EXPORT_VAR
  160432. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160433. # endif
  160434. # endif
  160435. #endif
  160436. #ifndef PNG_EXPORT
  160437. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160438. #endif
  160439. #ifdef PNG_USE_GLOBAL_ARRAYS
  160440. # ifndef PNG_EXPORT_VAR
  160441. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160442. # endif
  160443. #endif
  160444. #ifndef PNG_ABORT
  160445. # define PNG_ABORT() abort()
  160446. #endif
  160447. #ifdef PNG_SETJMP_SUPPORTED
  160448. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160449. #else
  160450. # define png_jmpbuf(png_ptr) \
  160451. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160452. #endif
  160453. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160454. # define CHECK 1
  160455. # define NOCHECK 0
  160456. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160457. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160458. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160459. # define png_strcpy _fstrcpy
  160460. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160461. # define png_strlen _fstrlen
  160462. # define png_memcmp _fmemcmp /* SJT: added */
  160463. # define png_memcpy _fmemcpy
  160464. # define png_memset _fmemset
  160465. #else /* use the usual functions */
  160466. # define CVT_PTR(ptr) (ptr)
  160467. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160468. # ifndef PNG_NO_SNPRINTF
  160469. # ifdef _MSC_VER
  160470. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160471. # define png_snprintf2 _snprintf
  160472. # define png_snprintf6 _snprintf
  160473. # else
  160474. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160475. # define png_snprintf2 snprintf
  160476. # define png_snprintf6 snprintf
  160477. # endif
  160478. # else
  160479. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160480. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160481. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160482. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160483. # endif
  160484. # define png_strcpy strcpy
  160485. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160486. # define png_strlen strlen
  160487. # define png_memcmp memcmp /* SJT: added */
  160488. # define png_memcpy memcpy
  160489. # define png_memset memset
  160490. #endif
  160491. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160492. # undef PNG_ZBUF_SIZE
  160493. # define PNG_ZBUF_SIZE 65536L
  160494. #endif
  160495. #endif /* PNG_VERSION_INFO_ONLY */
  160496. #endif /* PNGCONF_H */
  160497. /*** End of inlined file: pngconf.h ***/
  160498. #ifdef _MSC_VER
  160499. #pragma warning (disable: 4996 4100)
  160500. #endif
  160501. #if defined(PNG_USER_PRIVATEBUILD)
  160502. # define PNG_LIBPNG_BUILD_TYPE \
  160503. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160504. #else
  160505. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160506. # define PNG_LIBPNG_BUILD_TYPE \
  160507. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160508. # else
  160509. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160510. # endif
  160511. #endif
  160512. #ifndef PNG_VERSION_INFO_ONLY
  160513. #ifdef __cplusplus
  160514. extern "C" {
  160515. #endif /* __cplusplus */
  160516. #ifndef PNG_NO_TYPECAST_NULL
  160517. #define int_p_NULL (int *)NULL
  160518. #define png_bytep_NULL (png_bytep)NULL
  160519. #define png_bytepp_NULL (png_bytepp)NULL
  160520. #define png_doublep_NULL (png_doublep)NULL
  160521. #define png_error_ptr_NULL (png_error_ptr)NULL
  160522. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160523. #define png_free_ptr_NULL (png_free_ptr)NULL
  160524. #define png_infopp_NULL (png_infopp)NULL
  160525. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160526. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160527. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160528. #define png_structp_NULL (png_structp)NULL
  160529. #define png_uint_16p_NULL (png_uint_16p)NULL
  160530. #define png_voidp_NULL (png_voidp)NULL
  160531. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160532. #else
  160533. #define int_p_NULL NULL
  160534. #define png_bytep_NULL NULL
  160535. #define png_bytepp_NULL NULL
  160536. #define png_doublep_NULL NULL
  160537. #define png_error_ptr_NULL NULL
  160538. #define png_flush_ptr_NULL NULL
  160539. #define png_free_ptr_NULL NULL
  160540. #define png_infopp_NULL NULL
  160541. #define png_malloc_ptr_NULL NULL
  160542. #define png_read_status_ptr_NULL NULL
  160543. #define png_rw_ptr_NULL NULL
  160544. #define png_structp_NULL NULL
  160545. #define png_uint_16p_NULL NULL
  160546. #define png_voidp_NULL NULL
  160547. #define png_write_status_ptr_NULL NULL
  160548. #endif
  160549. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160550. #ifdef PNG_USE_GLOBAL_ARRAYS
  160551. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160552. #else
  160553. #define png_libpng_ver png_get_header_ver(NULL)
  160554. #endif
  160555. #ifdef PNG_USE_GLOBAL_ARRAYS
  160556. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160557. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160558. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160559. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160560. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160561. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160562. #endif
  160563. #endif /* PNG_NO_EXTERN */
  160564. typedef struct png_color_struct
  160565. {
  160566. png_byte red;
  160567. png_byte green;
  160568. png_byte blue;
  160569. } png_color;
  160570. typedef png_color FAR * png_colorp;
  160571. typedef png_color FAR * FAR * png_colorpp;
  160572. typedef struct png_color_16_struct
  160573. {
  160574. png_byte index; /* used for palette files */
  160575. png_uint_16 red; /* for use in red green blue files */
  160576. png_uint_16 green;
  160577. png_uint_16 blue;
  160578. png_uint_16 gray; /* for use in grayscale files */
  160579. } png_color_16;
  160580. typedef png_color_16 FAR * png_color_16p;
  160581. typedef png_color_16 FAR * FAR * png_color_16pp;
  160582. typedef struct png_color_8_struct
  160583. {
  160584. png_byte red; /* for use in red green blue files */
  160585. png_byte green;
  160586. png_byte blue;
  160587. png_byte gray; /* for use in grayscale files */
  160588. png_byte alpha; /* for alpha channel files */
  160589. } png_color_8;
  160590. typedef png_color_8 FAR * png_color_8p;
  160591. typedef png_color_8 FAR * FAR * png_color_8pp;
  160592. typedef struct png_sPLT_entry_struct
  160593. {
  160594. png_uint_16 red;
  160595. png_uint_16 green;
  160596. png_uint_16 blue;
  160597. png_uint_16 alpha;
  160598. png_uint_16 frequency;
  160599. } png_sPLT_entry;
  160600. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160601. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160602. typedef struct png_sPLT_struct
  160603. {
  160604. png_charp name; /* palette name */
  160605. png_byte depth; /* depth of palette samples */
  160606. png_sPLT_entryp entries; /* palette entries */
  160607. png_int_32 nentries; /* number of palette entries */
  160608. } png_sPLT_t;
  160609. typedef png_sPLT_t FAR * png_sPLT_tp;
  160610. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160611. #ifdef PNG_TEXT_SUPPORTED
  160612. typedef struct png_text_struct
  160613. {
  160614. int compression; /* compression value:
  160615. -1: tEXt, none
  160616. 0: zTXt, deflate
  160617. 1: iTXt, none
  160618. 2: iTXt, deflate */
  160619. png_charp key; /* keyword, 1-79 character description of "text" */
  160620. png_charp text; /* comment, may be an empty string (ie "")
  160621. or a NULL pointer */
  160622. png_size_t text_length; /* length of the text string */
  160623. #ifdef PNG_iTXt_SUPPORTED
  160624. png_size_t itxt_length; /* length of the itxt string */
  160625. png_charp lang; /* language code, 0-79 characters
  160626. or a NULL pointer */
  160627. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160628. chars or a NULL pointer */
  160629. #endif
  160630. } png_text;
  160631. typedef png_text FAR * png_textp;
  160632. typedef png_text FAR * FAR * png_textpp;
  160633. #endif
  160634. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160635. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160636. #define PNG_TEXT_COMPRESSION_NONE -1
  160637. #define PNG_TEXT_COMPRESSION_zTXt 0
  160638. #define PNG_ITXT_COMPRESSION_NONE 1
  160639. #define PNG_ITXT_COMPRESSION_zTXt 2
  160640. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160641. typedef struct png_time_struct
  160642. {
  160643. png_uint_16 year; /* full year, as in, 1995 */
  160644. png_byte month; /* month of year, 1 - 12 */
  160645. png_byte day; /* day of month, 1 - 31 */
  160646. png_byte hour; /* hour of day, 0 - 23 */
  160647. png_byte minute; /* minute of hour, 0 - 59 */
  160648. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160649. } png_time;
  160650. typedef png_time FAR * png_timep;
  160651. typedef png_time FAR * FAR * png_timepp;
  160652. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160653. typedef struct png_unknown_chunk_t
  160654. {
  160655. png_byte name[5];
  160656. png_byte *data;
  160657. png_size_t size;
  160658. png_byte location; /* mode of operation at read time */
  160659. }
  160660. png_unknown_chunk;
  160661. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160662. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160663. #endif
  160664. typedef struct png_info_struct
  160665. {
  160666. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160667. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160668. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160669. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160670. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160671. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160672. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160673. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160674. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160675. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160676. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160677. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160678. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160679. png_byte pixel_depth; /* number of bits per pixel */
  160680. png_byte spare_byte; /* to align the data, and for future use */
  160681. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160682. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160683. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160684. #endif
  160685. #if defined(PNG_sRGB_SUPPORTED)
  160686. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160687. #endif
  160688. #if defined(PNG_TEXT_SUPPORTED)
  160689. int num_text; /* number of comments read/to write */
  160690. int max_text; /* current size of text array */
  160691. png_textp text; /* array of comments read/to write */
  160692. #endif /* PNG_TEXT_SUPPORTED */
  160693. #if defined(PNG_tIME_SUPPORTED)
  160694. png_time mod_time;
  160695. #endif
  160696. #if defined(PNG_sBIT_SUPPORTED)
  160697. png_color_8 sig_bit; /* significant bits in color channels */
  160698. #endif
  160699. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160700. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160701. png_bytep trans; /* transparent values for paletted image */
  160702. png_color_16 trans_values; /* transparent color for non-palette image */
  160703. #endif
  160704. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160705. png_color_16 background;
  160706. #endif
  160707. #if defined(PNG_oFFs_SUPPORTED)
  160708. png_int_32 x_offset; /* x offset on page */
  160709. png_int_32 y_offset; /* y offset on page */
  160710. png_byte offset_unit_type; /* offset units type */
  160711. #endif
  160712. #if defined(PNG_pHYs_SUPPORTED)
  160713. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160714. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160715. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160716. #endif
  160717. #if defined(PNG_hIST_SUPPORTED)
  160718. png_uint_16p hist;
  160719. #endif
  160720. #ifdef PNG_cHRM_SUPPORTED
  160721. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160722. float x_white;
  160723. float y_white;
  160724. float x_red;
  160725. float y_red;
  160726. float x_green;
  160727. float y_green;
  160728. float x_blue;
  160729. float y_blue;
  160730. #endif
  160731. #endif
  160732. #if defined(PNG_pCAL_SUPPORTED)
  160733. png_charp pcal_purpose; /* pCAL chunk description string */
  160734. png_int_32 pcal_X0; /* minimum value */
  160735. png_int_32 pcal_X1; /* maximum value */
  160736. png_charp pcal_units; /* Latin-1 string giving physical units */
  160737. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160738. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160739. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160740. #endif
  160741. #ifdef PNG_FREE_ME_SUPPORTED
  160742. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160743. #endif
  160744. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160745. png_unknown_chunkp unknown_chunks;
  160746. png_size_t unknown_chunks_num;
  160747. #endif
  160748. #if defined(PNG_iCCP_SUPPORTED)
  160749. png_charp iccp_name; /* profile name */
  160750. png_charp iccp_profile; /* International Color Consortium profile data */
  160751. png_uint_32 iccp_proflen; /* ICC profile data length */
  160752. png_byte iccp_compression; /* Always zero */
  160753. #endif
  160754. #if defined(PNG_sPLT_SUPPORTED)
  160755. png_sPLT_tp splt_palettes;
  160756. png_uint_32 splt_palettes_num;
  160757. #endif
  160758. #if defined(PNG_sCAL_SUPPORTED)
  160759. png_byte scal_unit; /* unit of physical scale */
  160760. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160761. double scal_pixel_width; /* width of one pixel */
  160762. double scal_pixel_height; /* height of one pixel */
  160763. #endif
  160764. #ifdef PNG_FIXED_POINT_SUPPORTED
  160765. png_charp scal_s_width; /* string containing height */
  160766. png_charp scal_s_height; /* string containing width */
  160767. #endif
  160768. #endif
  160769. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160770. png_bytepp row_pointers; /* the image bits */
  160771. #endif
  160772. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160773. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160774. #endif
  160775. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160776. png_fixed_point int_x_white;
  160777. png_fixed_point int_y_white;
  160778. png_fixed_point int_x_red;
  160779. png_fixed_point int_y_red;
  160780. png_fixed_point int_x_green;
  160781. png_fixed_point int_y_green;
  160782. png_fixed_point int_x_blue;
  160783. png_fixed_point int_y_blue;
  160784. #endif
  160785. } png_info;
  160786. typedef png_info FAR * png_infop;
  160787. typedef png_info FAR * FAR * png_infopp;
  160788. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160789. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160790. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160791. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160792. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160793. #endif
  160794. #define PNG_COLOR_MASK_PALETTE 1
  160795. #define PNG_COLOR_MASK_COLOR 2
  160796. #define PNG_COLOR_MASK_ALPHA 4
  160797. #define PNG_COLOR_TYPE_GRAY 0
  160798. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160799. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160800. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160801. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160802. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160803. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160804. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160805. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160806. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160807. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160808. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160809. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160810. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160811. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160812. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160813. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160814. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160815. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160816. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160817. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160818. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160819. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160820. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160821. #define PNG_SCALE_METER 1 /* meters per pixel */
  160822. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160823. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160824. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160825. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160826. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160827. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160828. #define PNG_sRGB_INTENT_RELATIVE 1
  160829. #define PNG_sRGB_INTENT_SATURATION 2
  160830. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160831. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160832. #define PNG_KEYWORD_MAX_LENGTH 79
  160833. #define PNG_MAX_PALETTE_LENGTH 256
  160834. #define PNG_INFO_gAMA 0x0001
  160835. #define PNG_INFO_sBIT 0x0002
  160836. #define PNG_INFO_cHRM 0x0004
  160837. #define PNG_INFO_PLTE 0x0008
  160838. #define PNG_INFO_tRNS 0x0010
  160839. #define PNG_INFO_bKGD 0x0020
  160840. #define PNG_INFO_hIST 0x0040
  160841. #define PNG_INFO_pHYs 0x0080
  160842. #define PNG_INFO_oFFs 0x0100
  160843. #define PNG_INFO_tIME 0x0200
  160844. #define PNG_INFO_pCAL 0x0400
  160845. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160846. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160847. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160848. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160849. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160850. typedef struct png_row_info_struct
  160851. {
  160852. png_uint_32 width; /* width of row */
  160853. png_uint_32 rowbytes; /* number of bytes in row */
  160854. png_byte color_type; /* color type of row */
  160855. png_byte bit_depth; /* bit depth of row */
  160856. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160857. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160858. } png_row_info;
  160859. typedef png_row_info FAR * png_row_infop;
  160860. typedef png_row_info FAR * FAR * png_row_infopp;
  160861. typedef struct png_struct_def png_struct;
  160862. typedef png_struct FAR * png_structp;
  160863. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160864. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160865. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160866. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160867. int));
  160868. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160869. int));
  160870. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160871. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160872. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160873. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160874. png_uint_32, int));
  160875. #endif
  160876. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160877. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160878. defined(PNG_LEGACY_SUPPORTED)
  160879. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160880. png_row_infop, png_bytep));
  160881. #endif
  160882. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160883. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160884. #endif
  160885. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160886. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160887. #endif
  160888. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160889. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160890. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160891. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160892. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160893. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160894. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160895. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160896. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160897. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160898. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160899. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160900. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160901. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160902. #define PNG_FLAG_MNG_FILTER_64 0x04
  160903. #define PNG_ALL_MNG_FEATURES 0x05
  160904. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160905. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160906. struct png_struct_def
  160907. {
  160908. #ifdef PNG_SETJMP_SUPPORTED
  160909. jmp_buf jmpbuf; /* used in png_error */
  160910. #endif
  160911. png_error_ptr error_fn; /* function for printing errors and aborting */
  160912. png_error_ptr warning_fn; /* function for printing warnings */
  160913. png_voidp error_ptr; /* user supplied struct for error functions */
  160914. png_rw_ptr write_data_fn; /* function for writing output data */
  160915. png_rw_ptr read_data_fn; /* function for reading input data */
  160916. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160917. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160918. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160919. #endif
  160920. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160921. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160922. #endif
  160923. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160924. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160925. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160926. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160927. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160928. png_byte user_transform_channels; /* channels in user transformed pixels */
  160929. #endif
  160930. #endif
  160931. png_uint_32 mode; /* tells us where we are in the PNG file */
  160932. png_uint_32 flags; /* flags indicating various things to libpng */
  160933. png_uint_32 transformations; /* which transformations to perform */
  160934. z_stream zstream; /* pointer to decompression structure (below) */
  160935. png_bytep zbuf; /* buffer for zlib */
  160936. png_size_t zbuf_size; /* size of zbuf */
  160937. int zlib_level; /* holds zlib compression level */
  160938. int zlib_method; /* holds zlib compression method */
  160939. int zlib_window_bits; /* holds zlib compression window bits */
  160940. int zlib_mem_level; /* holds zlib compression memory level */
  160941. int zlib_strategy; /* holds zlib compression strategy */
  160942. png_uint_32 width; /* width of image in pixels */
  160943. png_uint_32 height; /* height of image in pixels */
  160944. png_uint_32 num_rows; /* number of rows in current pass */
  160945. png_uint_32 usr_width; /* width of row at start of write */
  160946. png_uint_32 rowbytes; /* size of row in bytes */
  160947. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160948. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160949. png_uint_32 row_number; /* current row in interlace pass */
  160950. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160951. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160952. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160953. png_bytep up_row; /* buffer to save "up" row when filtering */
  160954. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160955. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160956. png_row_info row_info; /* used for transformation routines */
  160957. png_uint_32 idat_size; /* current IDAT size for read */
  160958. png_uint_32 crc; /* current chunk CRC value */
  160959. png_colorp palette; /* palette from the input file */
  160960. png_uint_16 num_palette; /* number of color entries in palette */
  160961. png_uint_16 num_trans; /* number of transparency values */
  160962. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160963. png_byte compression; /* file compression type (always 0) */
  160964. png_byte filter; /* file filter type (always 0) */
  160965. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160966. png_byte pass; /* current interlace pass (0 - 6) */
  160967. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160968. png_byte color_type; /* color type of file */
  160969. png_byte bit_depth; /* bit depth of file */
  160970. png_byte usr_bit_depth; /* bit depth of users row */
  160971. png_byte pixel_depth; /* number of bits per pixel */
  160972. png_byte channels; /* number of channels in file */
  160973. png_byte usr_channels; /* channels at start of write */
  160974. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160975. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160976. #ifdef PNG_LEGACY_SUPPORTED
  160977. png_byte filler; /* filler byte for pixel expansion */
  160978. #else
  160979. png_uint_16 filler; /* filler bytes for pixel expansion */
  160980. #endif
  160981. #endif
  160982. #if defined(PNG_bKGD_SUPPORTED)
  160983. png_byte background_gamma_type;
  160984. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160985. float background_gamma;
  160986. # endif
  160987. png_color_16 background; /* background color in screen gamma space */
  160988. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160989. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160990. #endif
  160991. #endif /* PNG_bKGD_SUPPORTED */
  160992. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160993. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160994. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160995. png_uint_32 flush_rows; /* number of rows written since last flush */
  160996. #endif
  160997. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160998. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160999. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161000. float gamma; /* file gamma value */
  161001. float screen_gamma; /* screen gamma value (display_exponent) */
  161002. #endif
  161003. #endif
  161004. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161005. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  161006. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  161007. png_bytep gamma_to_1; /* converts from file to 1.0 */
  161008. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  161009. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  161010. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  161011. #endif
  161012. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  161013. png_color_8 sig_bit; /* significant bits in each available channel */
  161014. #endif
  161015. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161016. png_color_8 shift; /* shift for significant bit tranformation */
  161017. #endif
  161018. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  161019. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161020. png_bytep trans; /* transparency values for paletted files */
  161021. png_color_16 trans_values; /* transparency values for non-paletted files */
  161022. #endif
  161023. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  161024. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  161025. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161026. png_progressive_info_ptr info_fn; /* called after header data fully read */
  161027. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  161028. png_progressive_end_ptr end_fn; /* called after image is complete */
  161029. png_bytep save_buffer_ptr; /* current location in save_buffer */
  161030. png_bytep save_buffer; /* buffer for previously read data */
  161031. png_bytep current_buffer_ptr; /* current location in current_buffer */
  161032. png_bytep current_buffer; /* buffer for recently used data */
  161033. png_uint_32 push_length; /* size of current input chunk */
  161034. png_uint_32 skip_length; /* bytes to skip in input data */
  161035. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  161036. png_size_t save_buffer_max; /* total size of save_buffer */
  161037. png_size_t buffer_size; /* total amount of available input data */
  161038. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  161039. int process_mode; /* what push library is currently doing */
  161040. int cur_palette; /* current push library palette index */
  161041. # if defined(PNG_TEXT_SUPPORTED)
  161042. png_size_t current_text_size; /* current size of text input data */
  161043. png_size_t current_text_left; /* how much text left to read in input */
  161044. png_charp current_text; /* current text chunk buffer */
  161045. png_charp current_text_ptr; /* current location in current_text */
  161046. # endif /* PNG_TEXT_SUPPORTED */
  161047. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161048. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  161049. png_bytepp offset_table_ptr;
  161050. png_bytep offset_table;
  161051. png_uint_16 offset_table_number;
  161052. png_uint_16 offset_table_count;
  161053. png_uint_16 offset_table_count_free;
  161054. #endif
  161055. #if defined(PNG_READ_DITHER_SUPPORTED)
  161056. png_bytep palette_lookup; /* lookup table for dithering */
  161057. png_bytep dither_index; /* index translation for palette files */
  161058. #endif
  161059. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  161060. png_uint_16p hist; /* histogram */
  161061. #endif
  161062. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  161063. png_byte heuristic_method; /* heuristic for row filter selection */
  161064. png_byte num_prev_filters; /* number of weights for previous rows */
  161065. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  161066. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  161067. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  161068. png_uint_16p filter_costs; /* relative filter calculation cost */
  161069. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  161070. #endif
  161071. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161072. png_charp time_buffer; /* String to hold RFC 1123 time text */
  161073. #endif
  161074. #ifdef PNG_FREE_ME_SUPPORTED
  161075. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161076. #endif
  161077. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161078. png_voidp user_chunk_ptr;
  161079. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  161080. #endif
  161081. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161082. int num_chunk_list;
  161083. png_bytep chunk_list;
  161084. #endif
  161085. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161086. png_byte rgb_to_gray_status;
  161087. png_uint_16 rgb_to_gray_red_coeff;
  161088. png_uint_16 rgb_to_gray_green_coeff;
  161089. png_uint_16 rgb_to_gray_blue_coeff;
  161090. #endif
  161091. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  161092. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161093. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161094. #ifdef PNG_1_0_X
  161095. png_byte mng_features_permitted;
  161096. #else
  161097. png_uint_32 mng_features_permitted;
  161098. #endif /* PNG_1_0_X */
  161099. #endif
  161100. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161101. png_fixed_point int_gamma;
  161102. #endif
  161103. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  161104. png_byte filter_type;
  161105. #endif
  161106. #if defined(PNG_1_0_X)
  161107. png_uint_32 row_buf_size;
  161108. #endif
  161109. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161110. # if !defined(PNG_1_0_X)
  161111. # if defined(PNG_MMX_CODE_SUPPORTED)
  161112. png_byte mmx_bitdepth_threshold;
  161113. png_uint_32 mmx_rowbytes_threshold;
  161114. # endif
  161115. png_uint_32 asm_flags;
  161116. # endif
  161117. #endif
  161118. #ifdef PNG_USER_MEM_SUPPORTED
  161119. png_voidp mem_ptr; /* user supplied struct for mem functions */
  161120. png_malloc_ptr malloc_fn; /* function for allocating memory */
  161121. png_free_ptr free_fn; /* function for freeing memory */
  161122. #endif
  161123. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  161124. #if defined(PNG_READ_DITHER_SUPPORTED)
  161125. png_bytep dither_sort; /* working sort array */
  161126. png_bytep index_to_palette; /* where the original index currently is */
  161127. png_bytep palette_to_index; /* which original index points to this */
  161128. #endif
  161129. png_byte compression_type;
  161130. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161131. png_uint_32 user_width_max;
  161132. png_uint_32 user_height_max;
  161133. #endif
  161134. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161135. png_unknown_chunk unknown_chunk;
  161136. #endif
  161137. };
  161138. typedef png_structp version_1_2_21;
  161139. typedef png_struct FAR * FAR * png_structpp;
  161140. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  161141. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  161142. int num_bytes));
  161143. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  161144. png_size_t num_to_check));
  161145. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  161146. extern PNG_EXPORT(png_structp,png_create_read_struct)
  161147. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161148. png_error_ptr error_fn, png_error_ptr warn_fn));
  161149. extern PNG_EXPORT(png_structp,png_create_write_struct)
  161150. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161151. png_error_ptr error_fn, png_error_ptr warn_fn));
  161152. #ifdef PNG_WRITE_SUPPORTED
  161153. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  161154. PNGARG((png_structp png_ptr));
  161155. #endif
  161156. #ifdef PNG_WRITE_SUPPORTED
  161157. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  161158. PNGARG((png_structp png_ptr, png_uint_32 size));
  161159. #endif
  161160. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  161161. #ifdef PNG_USER_MEM_SUPPORTED
  161162. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  161163. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161164. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161165. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161166. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  161167. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161168. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161169. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161170. #endif
  161171. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  161172. png_bytep chunk_name, png_bytep data, png_size_t length));
  161173. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  161174. png_bytep chunk_name, png_uint_32 length));
  161175. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  161176. png_bytep data, png_size_t length));
  161177. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  161178. extern PNG_EXPORT(png_infop,png_create_info_struct)
  161179. PNGARG((png_structp png_ptr));
  161180. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161181. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  161182. #undef png_info_init
  161183. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  161184. png_sizeof(png_info));
  161185. #endif
  161186. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  161187. png_size_t png_info_struct_size));
  161188. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  161189. png_infop info_ptr));
  161190. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  161191. png_infop info_ptr));
  161192. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161193. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  161194. png_infop info_ptr));
  161195. #endif
  161196. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161197. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  161198. PNGARG((png_structp png_ptr, png_timep ptime));
  161199. #endif
  161200. #if !defined(_WIN32_WCE)
  161201. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161202. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  161203. struct tm FAR * ttime));
  161204. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  161205. time_t ttime));
  161206. #endif /* PNG_WRITE_tIME_SUPPORTED */
  161207. #endif /* _WIN32_WCE */
  161208. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161209. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  161210. #if !defined(PNG_1_0_X)
  161211. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  161212. png_ptr));
  161213. #endif
  161214. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  161215. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  161216. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161217. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  161218. #endif
  161219. #endif
  161220. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161221. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  161222. #endif
  161223. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161224. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  161225. #endif
  161226. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161227. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161228. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  161229. int error_action, double red, double green ));
  161230. #endif
  161231. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  161232. int error_action, png_fixed_point red, png_fixed_point green ));
  161233. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  161234. png_ptr));
  161235. #endif
  161236. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  161237. png_colorp palette));
  161238. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161239. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  161240. #endif
  161241. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  161242. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161243. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  161244. #endif
  161245. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  161246. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161247. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  161248. #endif
  161249. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161250. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  161251. png_uint_32 filler, int flags));
  161252. #define PNG_FILLER_BEFORE 0
  161253. #define PNG_FILLER_AFTER 1
  161254. #if !defined(PNG_1_0_X)
  161255. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  161256. png_uint_32 filler, int flags));
  161257. #endif
  161258. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  161259. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161260. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  161261. #endif
  161262. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  161263. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  161264. #endif
  161265. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161266. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  161267. #endif
  161268. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161269. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  161270. png_color_8p true_bits));
  161271. #endif
  161272. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  161273. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161274. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  161275. #endif
  161276. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161277. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  161278. #endif
  161279. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161280. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161281. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  161282. png_color_16p background_color, int background_gamma_code,
  161283. int need_expand, double background_gamma));
  161284. #endif
  161285. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  161286. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  161287. #define PNG_BACKGROUND_GAMMA_FILE 2
  161288. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  161289. #endif
  161290. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161291. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  161292. #endif
  161293. #if defined(PNG_READ_DITHER_SUPPORTED)
  161294. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  161295. png_colorp palette, int num_palette, int maximum_colors,
  161296. png_uint_16p histogram, int full_dither));
  161297. #endif
  161298. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161299. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161300. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161301. double screen_gamma, double default_file_gamma));
  161302. #endif
  161303. #endif
  161304. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161305. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161306. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161307. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161308. int empty_plte_permitted));
  161309. #endif
  161310. #endif
  161311. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161312. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161313. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161314. #endif
  161315. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161316. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161317. png_infop info_ptr));
  161318. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161319. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161320. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161321. #endif
  161322. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161323. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161324. png_bytep row,
  161325. png_bytep display_row));
  161326. #endif
  161327. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161328. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161329. png_bytepp image));
  161330. #endif
  161331. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161332. png_bytep row));
  161333. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161334. png_bytepp row, png_uint_32 num_rows));
  161335. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161336. png_bytepp image));
  161337. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161338. png_infop info_ptr));
  161339. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161340. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161341. png_infop info_ptr));
  161342. #endif
  161343. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161344. png_infopp info_ptr_ptr));
  161345. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161346. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161347. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161348. png_infop end_info_ptr));
  161349. extern PNG_EXPORT(void,png_destroy_write_struct)
  161350. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161351. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161352. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161353. int crit_action, int ancil_action));
  161354. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161355. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161356. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161357. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161358. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161359. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161360. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161361. int filters));
  161362. #define PNG_NO_FILTERS 0x00
  161363. #define PNG_FILTER_NONE 0x08
  161364. #define PNG_FILTER_SUB 0x10
  161365. #define PNG_FILTER_UP 0x20
  161366. #define PNG_FILTER_AVG 0x40
  161367. #define PNG_FILTER_PAETH 0x80
  161368. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161369. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161370. #define PNG_FILTER_VALUE_NONE 0
  161371. #define PNG_FILTER_VALUE_SUB 1
  161372. #define PNG_FILTER_VALUE_UP 2
  161373. #define PNG_FILTER_VALUE_AVG 3
  161374. #define PNG_FILTER_VALUE_PAETH 4
  161375. #define PNG_FILTER_VALUE_LAST 5
  161376. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161377. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161378. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161379. int heuristic_method, int num_weights, png_doublep filter_weights,
  161380. png_doublep filter_costs));
  161381. #endif
  161382. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161383. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161384. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161385. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161386. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161387. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161388. int level));
  161389. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161390. PNGARG((png_structp png_ptr, int mem_level));
  161391. extern PNG_EXPORT(void,png_set_compression_strategy)
  161392. PNGARG((png_structp png_ptr, int strategy));
  161393. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161394. PNGARG((png_structp png_ptr, int window_bits));
  161395. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161396. int method));
  161397. #if !defined(PNG_NO_STDIO)
  161398. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161399. #endif
  161400. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161401. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161402. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161403. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161404. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161405. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161406. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161407. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161408. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161409. png_read_status_ptr read_row_fn));
  161410. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161411. png_write_status_ptr write_row_fn));
  161412. #ifdef PNG_USER_MEM_SUPPORTED
  161413. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161414. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161415. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161416. #endif
  161417. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161418. defined(PNG_LEGACY_SUPPORTED)
  161419. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161420. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161421. #endif
  161422. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161423. defined(PNG_LEGACY_SUPPORTED)
  161424. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161425. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161426. #endif
  161427. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161428. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161429. defined(PNG_LEGACY_SUPPORTED)
  161430. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161431. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161432. int user_transform_channels));
  161433. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161434. PNGARG((png_structp png_ptr));
  161435. #endif
  161436. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161437. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161438. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161439. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161440. png_ptr));
  161441. #endif
  161442. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161443. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161444. png_voidp progressive_ptr,
  161445. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161446. png_progressive_end_ptr end_fn));
  161447. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161448. PNGARG((png_structp png_ptr));
  161449. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161450. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161451. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161452. png_bytep old_row, png_bytep new_row));
  161453. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161454. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161455. png_uint_32 size));
  161456. #if defined(PNG_1_0_X)
  161457. # define png_malloc_warn png_malloc
  161458. #else
  161459. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161460. png_uint_32 size));
  161461. #endif
  161462. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161463. #if defined(PNG_1_0_X)
  161464. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161465. uInt size));
  161466. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161467. #endif
  161468. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161469. png_infop info_ptr, png_uint_32 free_me, int num));
  161470. #ifdef PNG_FREE_ME_SUPPORTED
  161471. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161472. png_infop info_ptr, int freer, png_uint_32 mask));
  161473. #endif
  161474. #define PNG_DESTROY_WILL_FREE_DATA 1
  161475. #define PNG_SET_WILL_FREE_DATA 1
  161476. #define PNG_USER_WILL_FREE_DATA 2
  161477. #define PNG_FREE_HIST 0x0008
  161478. #define PNG_FREE_ICCP 0x0010
  161479. #define PNG_FREE_SPLT 0x0020
  161480. #define PNG_FREE_ROWS 0x0040
  161481. #define PNG_FREE_PCAL 0x0080
  161482. #define PNG_FREE_SCAL 0x0100
  161483. #define PNG_FREE_UNKN 0x0200
  161484. #define PNG_FREE_LIST 0x0400
  161485. #define PNG_FREE_PLTE 0x1000
  161486. #define PNG_FREE_TRNS 0x2000
  161487. #define PNG_FREE_TEXT 0x4000
  161488. #define PNG_FREE_ALL 0x7fff
  161489. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161490. #ifdef PNG_USER_MEM_SUPPORTED
  161491. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161492. png_uint_32 size));
  161493. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161494. png_voidp ptr));
  161495. #endif
  161496. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161497. png_voidp s1, png_voidp s2, png_uint_32 size));
  161498. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161499. png_voidp s1, int value, png_uint_32 size));
  161500. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161501. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161502. int check));
  161503. #endif /* USE_FAR_KEYWORD */
  161504. #ifndef PNG_NO_ERROR_TEXT
  161505. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161506. png_const_charp error_message));
  161507. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161508. png_const_charp error_message));
  161509. #else
  161510. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161511. #endif
  161512. #ifndef PNG_NO_WARNINGS
  161513. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161514. png_const_charp warning_message));
  161515. #ifdef PNG_READ_SUPPORTED
  161516. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161517. png_const_charp warning_message));
  161518. #endif /* PNG_READ_SUPPORTED */
  161519. #endif /* PNG_NO_WARNINGS */
  161520. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161521. png_infop info_ptr, png_uint_32 flag));
  161522. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161523. png_infop info_ptr));
  161524. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161525. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161526. png_infop info_ptr));
  161527. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161528. png_infop info_ptr, png_bytepp row_pointers));
  161529. #endif
  161530. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161531. png_infop info_ptr));
  161532. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161533. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161534. png_ptr, png_infop info_ptr));
  161535. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161536. png_ptr, png_infop info_ptr));
  161537. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161538. png_ptr, png_infop info_ptr));
  161539. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161540. png_ptr, png_infop info_ptr));
  161541. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161542. png_ptr, png_infop info_ptr));
  161543. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161544. png_ptr, png_infop info_ptr));
  161545. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161546. png_ptr, png_infop info_ptr));
  161547. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161548. png_ptr, png_infop info_ptr));
  161549. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161550. png_ptr, png_infop info_ptr));
  161551. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161552. png_ptr, png_infop info_ptr));
  161553. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161554. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161555. png_ptr, png_infop info_ptr));
  161556. #endif
  161557. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161558. png_ptr, png_infop info_ptr));
  161559. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161560. png_ptr, png_infop info_ptr));
  161561. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161562. png_ptr, png_infop info_ptr));
  161563. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161564. png_ptr, png_infop info_ptr));
  161565. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161566. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161567. png_infop info_ptr));
  161568. #if defined(PNG_bKGD_SUPPORTED)
  161569. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161570. png_infop info_ptr, png_color_16p *background));
  161571. #endif
  161572. #if defined(PNG_bKGD_SUPPORTED)
  161573. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161574. png_infop info_ptr, png_color_16p background));
  161575. #endif
  161576. #if defined(PNG_cHRM_SUPPORTED)
  161577. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161578. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161579. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161580. double *red_y, double *green_x, double *green_y, double *blue_x,
  161581. double *blue_y));
  161582. #endif
  161583. #ifdef PNG_FIXED_POINT_SUPPORTED
  161584. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161585. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161586. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161587. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161588. *int_blue_x, png_fixed_point *int_blue_y));
  161589. #endif
  161590. #endif
  161591. #if defined(PNG_cHRM_SUPPORTED)
  161592. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161593. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161594. png_infop info_ptr, double white_x, double white_y, double red_x,
  161595. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161596. #endif
  161597. #ifdef PNG_FIXED_POINT_SUPPORTED
  161598. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161599. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161600. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161601. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161602. png_fixed_point int_blue_y));
  161603. #endif
  161604. #endif
  161605. #if defined(PNG_gAMA_SUPPORTED)
  161606. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161607. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161608. png_infop info_ptr, double *file_gamma));
  161609. #endif
  161610. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161611. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161612. #endif
  161613. #if defined(PNG_gAMA_SUPPORTED)
  161614. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161615. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161616. png_infop info_ptr, double file_gamma));
  161617. #endif
  161618. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161619. png_infop info_ptr, png_fixed_point int_file_gamma));
  161620. #endif
  161621. #if defined(PNG_hIST_SUPPORTED)
  161622. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161623. png_infop info_ptr, png_uint_16p *hist));
  161624. #endif
  161625. #if defined(PNG_hIST_SUPPORTED)
  161626. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161627. png_infop info_ptr, png_uint_16p hist));
  161628. #endif
  161629. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161630. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161631. int *bit_depth, int *color_type, int *interlace_method,
  161632. int *compression_method, int *filter_method));
  161633. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161634. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161635. int color_type, int interlace_method, int compression_method,
  161636. int filter_method));
  161637. #if defined(PNG_oFFs_SUPPORTED)
  161638. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161639. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161640. int *unit_type));
  161641. #endif
  161642. #if defined(PNG_oFFs_SUPPORTED)
  161643. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161644. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161645. int unit_type));
  161646. #endif
  161647. #if defined(PNG_pCAL_SUPPORTED)
  161648. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161649. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161650. int *type, int *nparams, png_charp *units, png_charpp *params));
  161651. #endif
  161652. #if defined(PNG_pCAL_SUPPORTED)
  161653. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161654. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161655. int type, int nparams, png_charp units, png_charpp params));
  161656. #endif
  161657. #if defined(PNG_pHYs_SUPPORTED)
  161658. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161659. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161660. #endif
  161661. #if defined(PNG_pHYs_SUPPORTED)
  161662. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161663. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161664. #endif
  161665. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161666. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161667. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161668. png_infop info_ptr, png_colorp palette, int num_palette));
  161669. #if defined(PNG_sBIT_SUPPORTED)
  161670. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161671. png_infop info_ptr, png_color_8p *sig_bit));
  161672. #endif
  161673. #if defined(PNG_sBIT_SUPPORTED)
  161674. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161675. png_infop info_ptr, png_color_8p sig_bit));
  161676. #endif
  161677. #if defined(PNG_sRGB_SUPPORTED)
  161678. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161679. png_infop info_ptr, int *intent));
  161680. #endif
  161681. #if defined(PNG_sRGB_SUPPORTED)
  161682. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161683. png_infop info_ptr, int intent));
  161684. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161685. png_infop info_ptr, int intent));
  161686. #endif
  161687. #if defined(PNG_iCCP_SUPPORTED)
  161688. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161689. png_infop info_ptr, png_charpp name, int *compression_type,
  161690. png_charpp profile, png_uint_32 *proflen));
  161691. #endif
  161692. #if defined(PNG_iCCP_SUPPORTED)
  161693. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161694. png_infop info_ptr, png_charp name, int compression_type,
  161695. png_charp profile, png_uint_32 proflen));
  161696. #endif
  161697. #if defined(PNG_sPLT_SUPPORTED)
  161698. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161699. png_infop info_ptr, png_sPLT_tpp entries));
  161700. #endif
  161701. #if defined(PNG_sPLT_SUPPORTED)
  161702. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161703. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161704. #endif
  161705. #if defined(PNG_TEXT_SUPPORTED)
  161706. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161707. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161708. #endif
  161709. #if defined(PNG_TEXT_SUPPORTED)
  161710. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161711. png_infop info_ptr, png_textp text_ptr, int num_text));
  161712. #endif
  161713. #if defined(PNG_tIME_SUPPORTED)
  161714. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161715. png_infop info_ptr, png_timep *mod_time));
  161716. #endif
  161717. #if defined(PNG_tIME_SUPPORTED)
  161718. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161719. png_infop info_ptr, png_timep mod_time));
  161720. #endif
  161721. #if defined(PNG_tRNS_SUPPORTED)
  161722. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161723. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161724. png_color_16p *trans_values));
  161725. #endif
  161726. #if defined(PNG_tRNS_SUPPORTED)
  161727. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161728. png_infop info_ptr, png_bytep trans, int num_trans,
  161729. png_color_16p trans_values));
  161730. #endif
  161731. #if defined(PNG_tRNS_SUPPORTED)
  161732. #endif
  161733. #if defined(PNG_sCAL_SUPPORTED)
  161734. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161735. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161736. png_infop info_ptr, int *unit, double *width, double *height));
  161737. #else
  161738. #ifdef PNG_FIXED_POINT_SUPPORTED
  161739. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161740. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161741. #endif
  161742. #endif
  161743. #endif /* PNG_sCAL_SUPPORTED */
  161744. #if defined(PNG_sCAL_SUPPORTED)
  161745. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161746. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161747. png_infop info_ptr, int unit, double width, double height));
  161748. #else
  161749. #ifdef PNG_FIXED_POINT_SUPPORTED
  161750. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161751. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161752. #endif
  161753. #endif
  161754. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161755. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161756. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161757. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161758. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161759. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161760. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161761. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161762. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161763. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161764. #endif
  161765. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161766. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161767. chunk_name));
  161768. #endif
  161769. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161770. png_infop info_ptr, int mask));
  161771. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161772. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161773. png_infop info_ptr,
  161774. int transforms,
  161775. png_voidp params));
  161776. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161777. png_infop info_ptr,
  161778. int transforms,
  161779. png_voidp params));
  161780. #endif
  161781. #ifdef PNG_DEBUG
  161782. #if (PNG_DEBUG > 0)
  161783. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161784. #include <crtdbg.h>
  161785. #if (PNG_DEBUG > 1)
  161786. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161787. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161788. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161789. #endif
  161790. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161791. #ifndef PNG_DEBUG_FILE
  161792. #define PNG_DEBUG_FILE stderr
  161793. #endif /* PNG_DEBUG_FILE */
  161794. #if (PNG_DEBUG > 1)
  161795. #define png_debug(l,m) \
  161796. { \
  161797. int num_tabs=l; \
  161798. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161799. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161800. }
  161801. #define png_debug1(l,m,p1) \
  161802. { \
  161803. int num_tabs=l; \
  161804. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161805. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161806. }
  161807. #define png_debug2(l,m,p1,p2) \
  161808. { \
  161809. int num_tabs=l; \
  161810. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161811. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161812. }
  161813. #endif /* (PNG_DEBUG > 1) */
  161814. #endif /* _MSC_VER */
  161815. #endif /* (PNG_DEBUG > 0) */
  161816. #endif /* PNG_DEBUG */
  161817. #ifndef png_debug
  161818. #define png_debug(l, m)
  161819. #endif
  161820. #ifndef png_debug1
  161821. #define png_debug1(l, m, p1)
  161822. #endif
  161823. #ifndef png_debug2
  161824. #define png_debug2(l, m, p1, p2)
  161825. #endif
  161826. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161827. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161828. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161829. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161830. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161831. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161832. png_ptr, png_uint_32 mng_features_permitted));
  161833. #endif
  161834. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161835. #define PNG_HANDLE_CHUNK_NEVER 1
  161836. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161837. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161838. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161839. #if defined(PNG_MMX_CODE_SUPPORTED)
  161840. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161841. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161842. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161843. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161844. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161845. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161846. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161847. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161848. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161849. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161850. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161851. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161852. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161853. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161854. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161855. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161856. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161857. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161858. | PNG_MMX_READ_FLAGS \
  161859. | PNG_MMX_WRITE_FLAGS )
  161860. #define PNG_SELECT_READ 1
  161861. #define PNG_SELECT_WRITE 2
  161862. #endif /* PNG_MMX_CODE_SUPPORTED */
  161863. #if !defined(PNG_1_0_X)
  161864. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161865. PNGARG((int flag_select, int *compilerID));
  161866. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161867. PNGARG((int flag_select));
  161868. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161869. PNGARG((png_structp png_ptr));
  161870. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161871. PNGARG((png_structp png_ptr));
  161872. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161873. PNGARG((png_structp png_ptr));
  161874. extern PNG_EXPORT(void,png_set_asm_flags)
  161875. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161876. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161877. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161878. png_uint_32 mmx_rowbytes_threshold));
  161879. #endif /* PNG_1_0_X */
  161880. #if !defined(PNG_1_0_X)
  161881. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161882. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161883. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161884. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161885. png_ptr, png_uint_32 strip_mode));
  161886. #endif
  161887. #endif /* PNG_1_0_X */
  161888. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161889. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161890. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161891. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161892. png_ptr));
  161893. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161894. png_ptr));
  161895. #endif
  161896. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161897. # define png_composite(composite, fg, alpha, bg) \
  161898. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161899. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161900. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161901. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161902. # define png_composite_16(composite, fg, alpha, bg) \
  161903. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161904. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161905. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161906. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161907. #else /* standard method using integer division */
  161908. # define png_composite(composite, fg, alpha, bg) \
  161909. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161910. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161911. (png_uint_16)127) / 255)
  161912. # define png_composite_16(composite, fg, alpha, bg) \
  161913. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161914. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161915. (png_uint_32)32767) / (png_uint_32)65535L)
  161916. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161917. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161918. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161919. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161920. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161921. #else
  161922. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161923. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161924. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161925. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161926. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161927. PNGARG((png_structp png_ptr, png_bytep buf));
  161928. extern PNG_EXPORT(void,png_save_uint_32)
  161929. PNGARG((png_bytep buf, png_uint_32 i));
  161930. extern PNG_EXPORT(void,png_save_int_32)
  161931. PNGARG((png_bytep buf, png_int_32 i));
  161932. extern PNG_EXPORT(void,png_save_uint_16)
  161933. PNGARG((png_bytep buf, unsigned int i));
  161934. #define PNG_HAVE_IHDR 0x01
  161935. #define PNG_HAVE_PLTE 0x02
  161936. #define PNG_HAVE_IDAT 0x04
  161937. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161938. #define PNG_HAVE_IEND 0x10
  161939. #if defined(PNG_INTERNAL)
  161940. #define PNG_HAVE_gAMA 0x20
  161941. #define PNG_HAVE_cHRM 0x40
  161942. #define PNG_HAVE_sRGB 0x80
  161943. #define PNG_HAVE_CHUNK_HEADER 0x100
  161944. #define PNG_WROTE_tIME 0x200
  161945. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161946. #define PNG_BACKGROUND_IS_GRAY 0x800
  161947. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161948. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161949. #define PNG_BGR 0x0001
  161950. #define PNG_INTERLACE 0x0002
  161951. #define PNG_PACK 0x0004
  161952. #define PNG_SHIFT 0x0008
  161953. #define PNG_SWAP_BYTES 0x0010
  161954. #define PNG_INVERT_MONO 0x0020
  161955. #define PNG_DITHER 0x0040
  161956. #define PNG_BACKGROUND 0x0080
  161957. #define PNG_BACKGROUND_EXPAND 0x0100
  161958. #define PNG_16_TO_8 0x0400
  161959. #define PNG_RGBA 0x0800
  161960. #define PNG_EXPAND 0x1000
  161961. #define PNG_GAMMA 0x2000
  161962. #define PNG_GRAY_TO_RGB 0x4000
  161963. #define PNG_FILLER 0x8000L
  161964. #define PNG_PACKSWAP 0x10000L
  161965. #define PNG_SWAP_ALPHA 0x20000L
  161966. #define PNG_STRIP_ALPHA 0x40000L
  161967. #define PNG_INVERT_ALPHA 0x80000L
  161968. #define PNG_USER_TRANSFORM 0x100000L
  161969. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161970. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161971. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161972. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161973. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161974. #define PNG_STRUCT_PNG 0x0001
  161975. #define PNG_STRUCT_INFO 0x0002
  161976. #define PNG_WEIGHT_SHIFT 8
  161977. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161978. #define PNG_COST_SHIFT 3
  161979. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161980. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161981. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161982. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161983. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161984. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161985. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161986. #define PNG_FLAG_ROW_INIT 0x0040
  161987. #define PNG_FLAG_FILLER_AFTER 0x0080
  161988. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161989. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161990. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161991. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161992. #define PNG_FLAG_FREE_PLTE 0x1000
  161993. #define PNG_FLAG_FREE_TRNS 0x2000
  161994. #define PNG_FLAG_FREE_HIST 0x4000
  161995. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161996. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161997. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161998. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161999. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  162000. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  162001. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  162002. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  162003. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  162004. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  162005. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  162006. PNG_FLAG_CRC_CRITICAL_IGNORE)
  162007. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  162008. PNG_FLAG_CRC_CRITICAL_MASK)
  162009. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  162010. abs((int)((c1).green) - (int)((c2).green)) + \
  162011. abs((int)((c1).blue) - (int)((c2).blue)))
  162012. #define PNG_ROWBYTES(pixel_bits, width) \
  162013. ((pixel_bits) >= 8 ? \
  162014. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  162015. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  162016. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  162017. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  162018. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  162019. #ifdef PNG_USE_GLOBAL_ARRAYS
  162020. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  162021. #else
  162022. #endif
  162023. #endif /* PNG_NO_EXTERN */
  162024. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  162025. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  162026. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  162027. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  162028. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  162029. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  162030. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  162031. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  162032. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  162033. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  162034. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  162035. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  162036. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  162037. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  162038. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  162039. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  162040. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  162041. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  162042. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  162043. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  162044. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  162045. #ifdef PNG_USE_GLOBAL_ARRAYS
  162046. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  162047. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  162048. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  162049. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  162050. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  162051. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  162052. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  162053. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  162054. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  162055. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  162056. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  162057. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  162058. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  162059. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  162060. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  162061. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  162062. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  162063. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  162064. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  162065. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  162066. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  162067. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162068. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162069. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  162070. #undef png_read_init
  162071. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  162072. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162073. #endif
  162074. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  162075. png_const_charp user_png_ver, png_size_t png_struct_size));
  162076. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162077. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  162078. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162079. png_info_size));
  162080. #endif
  162081. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162082. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  162083. #undef png_write_init
  162084. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  162085. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162086. #endif
  162087. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  162088. png_const_charp user_png_ver, png_size_t png_struct_size));
  162089. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  162090. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162091. png_info_size));
  162092. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  162093. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  162094. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  162095. malloc_fn, png_voidp mem_ptr));
  162096. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  162097. png_free_ptr free_fn, png_voidp mem_ptr));
  162098. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  162099. png_infop info_ptr));
  162100. #ifndef PNG_1_0_X
  162101. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  162102. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  162103. #ifdef PNG_SIZE_T
  162104. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162105. #endif
  162106. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  162107. png_bytep data, png_size_t length));
  162108. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162109. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  162110. png_bytep buffer, png_size_t length));
  162111. #endif
  162112. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  162113. png_bytep data, png_size_t length));
  162114. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162115. #if !defined(PNG_NO_STDIO)
  162116. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  162117. #endif
  162118. #endif
  162119. #else /* PNG_1_0_X */
  162120. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162121. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  162122. png_bytep buffer, png_size_t length));
  162123. #endif
  162124. #endif /* PNG_1_0_X */
  162125. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  162126. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  162127. png_size_t length));
  162128. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  162129. png_size_t length));
  162130. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  162131. png_size_t length));
  162132. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  162133. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  162134. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  162135. int comp_type, png_charp chunkdata, png_size_t chunklength,
  162136. png_size_t prefix_length, png_size_t *data_length));
  162137. #endif
  162138. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  162139. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  162140. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  162141. png_size_t length));
  162142. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162143. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  162144. #endif
  162145. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  162146. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  162147. png_uint_32 height,
  162148. int bit_depth, int color_type, int compression_method, int filter_method,
  162149. int interlace_method));
  162150. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  162151. png_uint_32 num_pal));
  162152. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  162153. png_size_t length));
  162154. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  162155. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  162156. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162157. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  162158. #endif
  162159. #ifdef PNG_FIXED_POINT_SUPPORTED
  162160. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  162161. file_gamma));
  162162. #endif
  162163. #endif
  162164. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  162165. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  162166. int color_type));
  162167. #endif
  162168. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  162169. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162170. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  162171. double white_x, double white_y,
  162172. double red_x, double red_y, double green_x, double green_y,
  162173. double blue_x, double blue_y));
  162174. #endif
  162175. #ifdef PNG_FIXED_POINT_SUPPORTED
  162176. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  162177. png_fixed_point int_white_x, png_fixed_point int_white_y,
  162178. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  162179. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  162180. png_fixed_point int_blue_y));
  162181. #endif
  162182. #endif
  162183. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  162184. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  162185. int intent));
  162186. #endif
  162187. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  162188. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  162189. png_charp name, int compression_type,
  162190. png_charp profile, int proflen));
  162191. #endif
  162192. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  162193. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  162194. png_sPLT_tp palette));
  162195. #endif
  162196. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  162197. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  162198. png_color_16p values, int number, int color_type));
  162199. #endif
  162200. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  162201. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  162202. png_color_16p values, int color_type));
  162203. #endif
  162204. #if defined(PNG_WRITE_hIST_SUPPORTED)
  162205. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  162206. int num_hist));
  162207. #endif
  162208. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  162209. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  162210. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  162211. png_charp key, png_charpp new_key));
  162212. #endif
  162213. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  162214. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  162215. png_charp text, png_size_t text_len));
  162216. #endif
  162217. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  162218. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  162219. png_charp text, png_size_t text_len, int compression));
  162220. #endif
  162221. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  162222. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  162223. int compression, png_charp key, png_charp lang, png_charp lang_key,
  162224. png_charp text));
  162225. #endif
  162226. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  162227. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  162228. png_infop info_ptr, png_textp text_ptr, int num_text));
  162229. #endif
  162230. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  162231. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  162232. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  162233. #endif
  162234. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  162235. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  162236. png_int_32 X0, png_int_32 X1, int type, int nparams,
  162237. png_charp units, png_charpp params));
  162238. #endif
  162239. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  162240. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  162241. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  162242. int unit_type));
  162243. #endif
  162244. #if defined(PNG_WRITE_tIME_SUPPORTED)
  162245. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  162246. png_timep mod_time));
  162247. #endif
  162248. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  162249. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  162250. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  162251. int unit, double width, double height));
  162252. #else
  162253. #ifdef PNG_FIXED_POINT_SUPPORTED
  162254. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  162255. int unit, png_charp width, png_charp height));
  162256. #endif
  162257. #endif
  162258. #endif
  162259. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  162260. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  162261. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162262. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  162263. #endif
  162264. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  162265. int mask));
  162266. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  162267. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  162268. #endif
  162269. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  162270. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  162271. png_bytep row, int pass));
  162272. #endif
  162273. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  162274. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  162275. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  162276. png_row_infop row_info));
  162277. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  162278. png_bytep filtered_row));
  162279. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  162280. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  162281. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  162282. png_infop info_ptr));
  162283. #if defined(PNG_READ_FILLER_SUPPORTED)
  162284. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  162285. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  162286. #endif
  162287. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  162288. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  162289. png_bytep row));
  162290. #endif
  162291. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  162292. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  162293. png_bytep row));
  162294. #endif
  162295. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  162296. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  162297. png_bytep row));
  162298. #endif
  162299. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162300. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162301. png_bytep row));
  162302. #endif
  162303. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162304. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162305. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162306. png_bytep row, png_uint_32 flags));
  162307. #endif
  162308. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162309. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162310. #endif
  162311. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162312. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162313. #endif
  162314. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162315. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162316. row_info, png_bytep row));
  162317. #endif
  162318. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162319. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162320. png_bytep row));
  162321. #endif
  162322. #if defined(PNG_READ_PACK_SUPPORTED)
  162323. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162324. #endif
  162325. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162326. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162327. png_color_8p sig_bits));
  162328. #endif
  162329. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162330. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162331. #endif
  162332. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162333. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162334. #endif
  162335. #if defined(PNG_READ_DITHER_SUPPORTED)
  162336. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162337. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162338. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162339. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162340. png_colorp palette, int num_palette));
  162341. # endif
  162342. #endif
  162343. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162344. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162345. #endif
  162346. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162347. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162348. png_bytep row, png_uint_32 bit_depth));
  162349. #endif
  162350. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162351. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162352. png_color_8p bit_depth));
  162353. #endif
  162354. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162355. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162356. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162357. png_color_16p trans_values, png_color_16p background,
  162358. png_color_16p background_1,
  162359. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162360. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162361. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162362. #else
  162363. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162364. png_color_16p trans_values, png_color_16p background));
  162365. #endif
  162366. #endif
  162367. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162368. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162369. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162370. int gamma_shift));
  162371. #endif
  162372. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162373. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162374. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162375. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162376. png_bytep row, png_color_16p trans_value));
  162377. #endif
  162378. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162379. png_uint_32 length));
  162380. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162381. png_uint_32 length));
  162382. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162383. png_uint_32 length));
  162384. #if defined(PNG_READ_bKGD_SUPPORTED)
  162385. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162386. png_uint_32 length));
  162387. #endif
  162388. #if defined(PNG_READ_cHRM_SUPPORTED)
  162389. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162390. png_uint_32 length));
  162391. #endif
  162392. #if defined(PNG_READ_gAMA_SUPPORTED)
  162393. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162394. png_uint_32 length));
  162395. #endif
  162396. #if defined(PNG_READ_hIST_SUPPORTED)
  162397. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162398. png_uint_32 length));
  162399. #endif
  162400. #if defined(PNG_READ_iCCP_SUPPORTED)
  162401. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162402. png_uint_32 length));
  162403. #endif /* PNG_READ_iCCP_SUPPORTED */
  162404. #if defined(PNG_READ_iTXt_SUPPORTED)
  162405. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162406. png_uint_32 length));
  162407. #endif
  162408. #if defined(PNG_READ_oFFs_SUPPORTED)
  162409. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162410. png_uint_32 length));
  162411. #endif
  162412. #if defined(PNG_READ_pCAL_SUPPORTED)
  162413. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162414. png_uint_32 length));
  162415. #endif
  162416. #if defined(PNG_READ_pHYs_SUPPORTED)
  162417. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162418. png_uint_32 length));
  162419. #endif
  162420. #if defined(PNG_READ_sBIT_SUPPORTED)
  162421. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162422. png_uint_32 length));
  162423. #endif
  162424. #if defined(PNG_READ_sCAL_SUPPORTED)
  162425. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162426. png_uint_32 length));
  162427. #endif
  162428. #if defined(PNG_READ_sPLT_SUPPORTED)
  162429. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162430. png_uint_32 length));
  162431. #endif /* PNG_READ_sPLT_SUPPORTED */
  162432. #if defined(PNG_READ_sRGB_SUPPORTED)
  162433. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162434. png_uint_32 length));
  162435. #endif
  162436. #if defined(PNG_READ_tEXt_SUPPORTED)
  162437. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162438. png_uint_32 length));
  162439. #endif
  162440. #if defined(PNG_READ_tIME_SUPPORTED)
  162441. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162442. png_uint_32 length));
  162443. #endif
  162444. #if defined(PNG_READ_tRNS_SUPPORTED)
  162445. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162446. png_uint_32 length));
  162447. #endif
  162448. #if defined(PNG_READ_zTXt_SUPPORTED)
  162449. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162450. png_uint_32 length));
  162451. #endif
  162452. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162453. png_infop info_ptr, png_uint_32 length));
  162454. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162455. png_bytep chunk_name));
  162456. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162457. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162458. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162459. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162460. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162461. png_infop info_ptr));
  162462. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162463. png_infop info_ptr));
  162464. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162465. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162466. png_uint_32 length));
  162467. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162468. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162469. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162470. png_bytep buffer, png_size_t buffer_length));
  162471. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162472. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162473. png_bytep buffer, png_size_t buffer_length));
  162474. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162475. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162476. png_infop info_ptr, png_uint_32 length));
  162477. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162478. png_infop info_ptr));
  162479. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162480. png_infop info_ptr));
  162481. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162482. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162483. png_infop info_ptr));
  162484. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162485. png_infop info_ptr));
  162486. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162487. #if defined(PNG_READ_tEXt_SUPPORTED)
  162488. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162489. png_infop info_ptr, png_uint_32 length));
  162490. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162491. png_infop info_ptr));
  162492. #endif
  162493. #if defined(PNG_READ_zTXt_SUPPORTED)
  162494. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162495. png_infop info_ptr, png_uint_32 length));
  162496. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162497. png_infop info_ptr));
  162498. #endif
  162499. #if defined(PNG_READ_iTXt_SUPPORTED)
  162500. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162501. png_infop info_ptr, png_uint_32 length));
  162502. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162503. png_infop info_ptr));
  162504. #endif
  162505. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162506. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162507. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162508. png_bytep row));
  162509. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162510. png_bytep row));
  162511. #endif
  162512. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162513. #if defined(PNG_MMX_CODE_SUPPORTED)
  162514. /* PRIVATE */
  162515. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162516. #endif
  162517. #endif
  162518. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162519. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162520. png_infop info_ptr));
  162521. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162522. png_infop info_ptr));
  162523. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162524. png_infop info_ptr));
  162525. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162526. png_infop info_ptr));
  162527. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162528. png_infop info_ptr));
  162529. #if defined(PNG_pHYs_SUPPORTED)
  162530. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162531. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162532. #endif /* PNG_pHYs_SUPPORTED */
  162533. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162534. #endif /* PNG_INTERNAL */
  162535. #ifdef __cplusplus
  162536. }
  162537. #endif
  162538. #endif /* PNG_VERSION_INFO_ONLY */
  162539. #endif /* PNG_H */
  162540. /*** End of inlined file: png.h ***/
  162541. #define PNG_NO_EXTERN
  162542. /*** Start of inlined file: png.c ***/
  162543. #define PNG_INTERNAL
  162544. #define PNG_NO_EXTERN
  162545. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162546. #ifdef PNG_USE_GLOBAL_ARRAYS
  162547. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162548. #ifdef PNG_READ_SUPPORTED
  162549. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162550. #endif /* PNG_READ_SUPPORTED */
  162551. PNG_IHDR;
  162552. PNG_IDAT;
  162553. PNG_IEND;
  162554. PNG_PLTE;
  162555. PNG_bKGD;
  162556. PNG_cHRM;
  162557. PNG_gAMA;
  162558. PNG_hIST;
  162559. PNG_iCCP;
  162560. PNG_iTXt;
  162561. PNG_oFFs;
  162562. PNG_pCAL;
  162563. PNG_sCAL;
  162564. PNG_pHYs;
  162565. PNG_sBIT;
  162566. PNG_sPLT;
  162567. PNG_sRGB;
  162568. PNG_tEXt;
  162569. PNG_tIME;
  162570. PNG_tRNS;
  162571. PNG_zTXt;
  162572. #ifdef PNG_READ_SUPPORTED
  162573. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162574. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162575. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162576. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162577. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162578. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162579. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162580. #endif /* PNG_READ_SUPPORTED */
  162581. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162582. #ifdef PNG_READ_SUPPORTED
  162583. void PNGAPI
  162584. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162585. {
  162586. if(png_ptr == NULL) return;
  162587. png_debug(1, "in png_set_sig_bytes\n");
  162588. if (num_bytes > 8)
  162589. png_error(png_ptr, "Too many bytes for PNG signature.");
  162590. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162591. }
  162592. int PNGAPI
  162593. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162594. {
  162595. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162596. if (num_to_check > 8)
  162597. num_to_check = 8;
  162598. else if (num_to_check < 1)
  162599. return (-1);
  162600. if (start > 7)
  162601. return (-1);
  162602. if (start + num_to_check > 8)
  162603. num_to_check = 8 - start;
  162604. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162605. }
  162606. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162607. int PNGAPI
  162608. png_check_sig(png_bytep sig, int num)
  162609. {
  162610. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162611. }
  162612. #endif
  162613. #endif /* PNG_READ_SUPPORTED */
  162614. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162615. #ifdef PNG_1_0_X
  162616. voidpf PNGAPI
  162617. #else
  162618. voidpf /* private */
  162619. #endif
  162620. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162621. {
  162622. png_voidp ptr;
  162623. png_structp p=(png_structp)png_ptr;
  162624. png_uint_32 save_flags=p->flags;
  162625. png_uint_32 num_bytes;
  162626. if(png_ptr == NULL) return (NULL);
  162627. if (items > PNG_UINT_32_MAX/size)
  162628. {
  162629. png_warning (p, "Potential overflow in png_zalloc()");
  162630. return (NULL);
  162631. }
  162632. num_bytes = (png_uint_32)items * size;
  162633. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162634. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162635. p->flags=save_flags;
  162636. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162637. if (ptr == NULL)
  162638. return ((voidpf)ptr);
  162639. if (num_bytes > (png_uint_32)0x8000L)
  162640. {
  162641. png_memset(ptr, 0, (png_size_t)0x8000L);
  162642. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162643. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162644. }
  162645. else
  162646. {
  162647. png_memset(ptr, 0, (png_size_t)num_bytes);
  162648. }
  162649. #endif
  162650. return ((voidpf)ptr);
  162651. }
  162652. #ifdef PNG_1_0_X
  162653. void PNGAPI
  162654. #else
  162655. void /* private */
  162656. #endif
  162657. png_zfree(voidpf png_ptr, voidpf ptr)
  162658. {
  162659. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162660. }
  162661. void /* PRIVATE */
  162662. png_reset_crc(png_structp png_ptr)
  162663. {
  162664. png_ptr->crc = crc32(0, Z_NULL, 0);
  162665. }
  162666. void /* PRIVATE */
  162667. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162668. {
  162669. int need_crc = 1;
  162670. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162671. {
  162672. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162673. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162674. need_crc = 0;
  162675. }
  162676. else /* critical */
  162677. {
  162678. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162679. need_crc = 0;
  162680. }
  162681. if (need_crc)
  162682. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162683. }
  162684. png_infop PNGAPI
  162685. png_create_info_struct(png_structp png_ptr)
  162686. {
  162687. png_infop info_ptr;
  162688. png_debug(1, "in png_create_info_struct\n");
  162689. if(png_ptr == NULL) return (NULL);
  162690. #ifdef PNG_USER_MEM_SUPPORTED
  162691. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162692. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162693. #else
  162694. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162695. #endif
  162696. if (info_ptr != NULL)
  162697. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162698. return (info_ptr);
  162699. }
  162700. void PNGAPI
  162701. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162702. {
  162703. png_infop info_ptr = NULL;
  162704. if(png_ptr == NULL) return;
  162705. png_debug(1, "in png_destroy_info_struct\n");
  162706. if (info_ptr_ptr != NULL)
  162707. info_ptr = *info_ptr_ptr;
  162708. if (info_ptr != NULL)
  162709. {
  162710. png_info_destroy(png_ptr, info_ptr);
  162711. #ifdef PNG_USER_MEM_SUPPORTED
  162712. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162713. png_ptr->mem_ptr);
  162714. #else
  162715. png_destroy_struct((png_voidp)info_ptr);
  162716. #endif
  162717. *info_ptr_ptr = NULL;
  162718. }
  162719. }
  162720. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162721. #undef png_info_init
  162722. void PNGAPI
  162723. png_info_init(png_infop info_ptr)
  162724. {
  162725. png_info_init_3(&info_ptr, 0);
  162726. }
  162727. #endif
  162728. void PNGAPI
  162729. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162730. {
  162731. png_infop info_ptr = *ptr_ptr;
  162732. if(info_ptr == NULL) return;
  162733. png_debug(1, "in png_info_init_3\n");
  162734. if(png_sizeof(png_info) > png_info_struct_size)
  162735. {
  162736. png_destroy_struct(info_ptr);
  162737. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162738. *ptr_ptr = info_ptr;
  162739. }
  162740. png_memset(info_ptr, 0, png_sizeof (png_info));
  162741. }
  162742. #ifdef PNG_FREE_ME_SUPPORTED
  162743. void PNGAPI
  162744. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162745. int freer, png_uint_32 mask)
  162746. {
  162747. png_debug(1, "in png_data_freer\n");
  162748. if (png_ptr == NULL || info_ptr == NULL)
  162749. return;
  162750. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162751. info_ptr->free_me |= mask;
  162752. else if(freer == PNG_USER_WILL_FREE_DATA)
  162753. info_ptr->free_me &= ~mask;
  162754. else
  162755. png_warning(png_ptr,
  162756. "Unknown freer parameter in png_data_freer.");
  162757. }
  162758. #endif
  162759. void PNGAPI
  162760. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162761. int num)
  162762. {
  162763. png_debug(1, "in png_free_data\n");
  162764. if (png_ptr == NULL || info_ptr == NULL)
  162765. return;
  162766. #if defined(PNG_TEXT_SUPPORTED)
  162767. #ifdef PNG_FREE_ME_SUPPORTED
  162768. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162769. #else
  162770. if (mask & PNG_FREE_TEXT)
  162771. #endif
  162772. {
  162773. if (num != -1)
  162774. {
  162775. if (info_ptr->text && info_ptr->text[num].key)
  162776. {
  162777. png_free(png_ptr, info_ptr->text[num].key);
  162778. info_ptr->text[num].key = NULL;
  162779. }
  162780. }
  162781. else
  162782. {
  162783. int i;
  162784. for (i = 0; i < info_ptr->num_text; i++)
  162785. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162786. png_free(png_ptr, info_ptr->text);
  162787. info_ptr->text = NULL;
  162788. info_ptr->num_text=0;
  162789. }
  162790. }
  162791. #endif
  162792. #if defined(PNG_tRNS_SUPPORTED)
  162793. #ifdef PNG_FREE_ME_SUPPORTED
  162794. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162795. #else
  162796. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162797. #endif
  162798. {
  162799. png_free(png_ptr, info_ptr->trans);
  162800. info_ptr->valid &= ~PNG_INFO_tRNS;
  162801. #ifndef PNG_FREE_ME_SUPPORTED
  162802. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162803. #endif
  162804. info_ptr->trans = NULL;
  162805. }
  162806. #endif
  162807. #if defined(PNG_sCAL_SUPPORTED)
  162808. #ifdef PNG_FREE_ME_SUPPORTED
  162809. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162810. #else
  162811. if (mask & PNG_FREE_SCAL)
  162812. #endif
  162813. {
  162814. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162815. png_free(png_ptr, info_ptr->scal_s_width);
  162816. png_free(png_ptr, info_ptr->scal_s_height);
  162817. info_ptr->scal_s_width = NULL;
  162818. info_ptr->scal_s_height = NULL;
  162819. #endif
  162820. info_ptr->valid &= ~PNG_INFO_sCAL;
  162821. }
  162822. #endif
  162823. #if defined(PNG_pCAL_SUPPORTED)
  162824. #ifdef PNG_FREE_ME_SUPPORTED
  162825. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162826. #else
  162827. if (mask & PNG_FREE_PCAL)
  162828. #endif
  162829. {
  162830. png_free(png_ptr, info_ptr->pcal_purpose);
  162831. png_free(png_ptr, info_ptr->pcal_units);
  162832. info_ptr->pcal_purpose = NULL;
  162833. info_ptr->pcal_units = NULL;
  162834. if (info_ptr->pcal_params != NULL)
  162835. {
  162836. int i;
  162837. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162838. {
  162839. png_free(png_ptr, info_ptr->pcal_params[i]);
  162840. info_ptr->pcal_params[i]=NULL;
  162841. }
  162842. png_free(png_ptr, info_ptr->pcal_params);
  162843. info_ptr->pcal_params = NULL;
  162844. }
  162845. info_ptr->valid &= ~PNG_INFO_pCAL;
  162846. }
  162847. #endif
  162848. #if defined(PNG_iCCP_SUPPORTED)
  162849. #ifdef PNG_FREE_ME_SUPPORTED
  162850. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162851. #else
  162852. if (mask & PNG_FREE_ICCP)
  162853. #endif
  162854. {
  162855. png_free(png_ptr, info_ptr->iccp_name);
  162856. png_free(png_ptr, info_ptr->iccp_profile);
  162857. info_ptr->iccp_name = NULL;
  162858. info_ptr->iccp_profile = NULL;
  162859. info_ptr->valid &= ~PNG_INFO_iCCP;
  162860. }
  162861. #endif
  162862. #if defined(PNG_sPLT_SUPPORTED)
  162863. #ifdef PNG_FREE_ME_SUPPORTED
  162864. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162865. #else
  162866. if (mask & PNG_FREE_SPLT)
  162867. #endif
  162868. {
  162869. if (num != -1)
  162870. {
  162871. if(info_ptr->splt_palettes)
  162872. {
  162873. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162874. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162875. info_ptr->splt_palettes[num].name = NULL;
  162876. info_ptr->splt_palettes[num].entries = NULL;
  162877. }
  162878. }
  162879. else
  162880. {
  162881. if(info_ptr->splt_palettes_num)
  162882. {
  162883. int i;
  162884. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162885. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162886. png_free(png_ptr, info_ptr->splt_palettes);
  162887. info_ptr->splt_palettes = NULL;
  162888. info_ptr->splt_palettes_num = 0;
  162889. }
  162890. info_ptr->valid &= ~PNG_INFO_sPLT;
  162891. }
  162892. }
  162893. #endif
  162894. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162895. if(png_ptr->unknown_chunk.data)
  162896. {
  162897. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162898. png_ptr->unknown_chunk.data = NULL;
  162899. }
  162900. #ifdef PNG_FREE_ME_SUPPORTED
  162901. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162902. #else
  162903. if (mask & PNG_FREE_UNKN)
  162904. #endif
  162905. {
  162906. if (num != -1)
  162907. {
  162908. if(info_ptr->unknown_chunks)
  162909. {
  162910. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162911. info_ptr->unknown_chunks[num].data = NULL;
  162912. }
  162913. }
  162914. else
  162915. {
  162916. int i;
  162917. if(info_ptr->unknown_chunks_num)
  162918. {
  162919. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162920. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162921. png_free(png_ptr, info_ptr->unknown_chunks);
  162922. info_ptr->unknown_chunks = NULL;
  162923. info_ptr->unknown_chunks_num = 0;
  162924. }
  162925. }
  162926. }
  162927. #endif
  162928. #if defined(PNG_hIST_SUPPORTED)
  162929. #ifdef PNG_FREE_ME_SUPPORTED
  162930. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162931. #else
  162932. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162933. #endif
  162934. {
  162935. png_free(png_ptr, info_ptr->hist);
  162936. info_ptr->hist = NULL;
  162937. info_ptr->valid &= ~PNG_INFO_hIST;
  162938. #ifndef PNG_FREE_ME_SUPPORTED
  162939. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162940. #endif
  162941. }
  162942. #endif
  162943. #ifdef PNG_FREE_ME_SUPPORTED
  162944. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162945. #else
  162946. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162947. #endif
  162948. {
  162949. png_zfree(png_ptr, info_ptr->palette);
  162950. info_ptr->palette = NULL;
  162951. info_ptr->valid &= ~PNG_INFO_PLTE;
  162952. #ifndef PNG_FREE_ME_SUPPORTED
  162953. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162954. #endif
  162955. info_ptr->num_palette = 0;
  162956. }
  162957. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162958. #ifdef PNG_FREE_ME_SUPPORTED
  162959. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162960. #else
  162961. if (mask & PNG_FREE_ROWS)
  162962. #endif
  162963. {
  162964. if(info_ptr->row_pointers)
  162965. {
  162966. int row;
  162967. for (row = 0; row < (int)info_ptr->height; row++)
  162968. {
  162969. png_free(png_ptr, info_ptr->row_pointers[row]);
  162970. info_ptr->row_pointers[row]=NULL;
  162971. }
  162972. png_free(png_ptr, info_ptr->row_pointers);
  162973. info_ptr->row_pointers=NULL;
  162974. }
  162975. info_ptr->valid &= ~PNG_INFO_IDAT;
  162976. }
  162977. #endif
  162978. #ifdef PNG_FREE_ME_SUPPORTED
  162979. if(num == -1)
  162980. info_ptr->free_me &= ~mask;
  162981. else
  162982. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162983. #endif
  162984. }
  162985. void /* PRIVATE */
  162986. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162987. {
  162988. png_debug(1, "in png_info_destroy\n");
  162989. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162990. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162991. if (png_ptr->num_chunk_list)
  162992. {
  162993. png_free(png_ptr, png_ptr->chunk_list);
  162994. png_ptr->chunk_list=NULL;
  162995. png_ptr->num_chunk_list=0;
  162996. }
  162997. #endif
  162998. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162999. }
  163000. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163001. png_voidp PNGAPI
  163002. png_get_io_ptr(png_structp png_ptr)
  163003. {
  163004. if(png_ptr == NULL) return (NULL);
  163005. return (png_ptr->io_ptr);
  163006. }
  163007. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163008. #if !defined(PNG_NO_STDIO)
  163009. void PNGAPI
  163010. png_init_io(png_structp png_ptr, png_FILE_p fp)
  163011. {
  163012. png_debug(1, "in png_init_io\n");
  163013. if(png_ptr == NULL) return;
  163014. png_ptr->io_ptr = (png_voidp)fp;
  163015. }
  163016. #endif
  163017. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  163018. png_charp PNGAPI
  163019. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  163020. {
  163021. static PNG_CONST char short_months[12][4] =
  163022. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  163023. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  163024. if(png_ptr == NULL) return (NULL);
  163025. if (png_ptr->time_buffer == NULL)
  163026. {
  163027. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  163028. png_sizeof(char)));
  163029. }
  163030. #if defined(_WIN32_WCE)
  163031. {
  163032. wchar_t time_buf[29];
  163033. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  163034. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163035. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163036. ptime->second % 61);
  163037. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  163038. NULL, NULL);
  163039. }
  163040. #else
  163041. #ifdef USE_FAR_KEYWORD
  163042. {
  163043. char near_time_buf[29];
  163044. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  163045. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163046. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163047. ptime->second % 61);
  163048. png_memcpy(png_ptr->time_buffer, near_time_buf,
  163049. 29*png_sizeof(char));
  163050. }
  163051. #else
  163052. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  163053. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163054. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163055. ptime->second % 61);
  163056. #endif
  163057. #endif /* _WIN32_WCE */
  163058. return ((png_charp)png_ptr->time_buffer);
  163059. }
  163060. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  163061. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163062. png_charp PNGAPI
  163063. png_get_copyright(png_structp png_ptr)
  163064. {
  163065. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163066. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  163067. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  163068. Copyright (c) 1996-1997 Andreas Dilger\n\
  163069. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  163070. }
  163071. png_charp PNGAPI
  163072. png_get_libpng_ver(png_structp png_ptr)
  163073. {
  163074. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163075. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163076. }
  163077. png_charp PNGAPI
  163078. png_get_header_ver(png_structp png_ptr)
  163079. {
  163080. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163081. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163082. }
  163083. png_charp PNGAPI
  163084. png_get_header_version(png_structp png_ptr)
  163085. {
  163086. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163087. return ((png_charp) PNG_HEADER_VERSION_STRING
  163088. #ifndef PNG_READ_SUPPORTED
  163089. " (NO READ SUPPORT)"
  163090. #endif
  163091. "\n");
  163092. }
  163093. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163094. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  163095. int PNGAPI
  163096. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  163097. {
  163098. int i;
  163099. png_bytep p;
  163100. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  163101. return 0;
  163102. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  163103. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  163104. if (!png_memcmp(chunk_name, p, 4))
  163105. return ((int)*(p+4));
  163106. return 0;
  163107. }
  163108. #endif
  163109. int PNGAPI
  163110. png_reset_zstream(png_structp png_ptr)
  163111. {
  163112. if (png_ptr == NULL) return Z_STREAM_ERROR;
  163113. return (inflateReset(&png_ptr->zstream));
  163114. }
  163115. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163116. png_uint_32 PNGAPI
  163117. png_access_version_number(void)
  163118. {
  163119. return((png_uint_32) PNG_LIBPNG_VER);
  163120. }
  163121. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  163122. #if !defined(PNG_1_0_X)
  163123. int PNGAPI
  163124. png_mmx_support(void)
  163125. {
  163126. return -1;
  163127. }
  163128. #endif /* PNG_1_0_X */
  163129. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  163130. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163131. #ifdef PNG_SIZE_T
  163132. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  163133. png_size_t PNGAPI
  163134. png_convert_size(size_t size)
  163135. {
  163136. if (size > (png_size_t)-1)
  163137. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  163138. return ((png_size_t)size);
  163139. }
  163140. #endif /* PNG_SIZE_T */
  163141. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163142. /*** End of inlined file: png.c ***/
  163143. /*** Start of inlined file: pngerror.c ***/
  163144. #define PNG_INTERNAL
  163145. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163146. static void /* PRIVATE */
  163147. png_default_error PNGARG((png_structp png_ptr,
  163148. png_const_charp error_message));
  163149. #ifndef PNG_NO_WARNINGS
  163150. static void /* PRIVATE */
  163151. png_default_warning PNGARG((png_structp png_ptr,
  163152. png_const_charp warning_message));
  163153. #endif /* PNG_NO_WARNINGS */
  163154. #ifndef PNG_NO_ERROR_TEXT
  163155. void PNGAPI
  163156. png_error(png_structp png_ptr, png_const_charp error_message)
  163157. {
  163158. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163159. char msg[16];
  163160. if (png_ptr != NULL)
  163161. {
  163162. if (png_ptr->flags&
  163163. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163164. {
  163165. if (*error_message == '#')
  163166. {
  163167. int offset;
  163168. for (offset=1; offset<15; offset++)
  163169. if (*(error_message+offset) == ' ')
  163170. break;
  163171. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163172. {
  163173. int i;
  163174. for (i=0; i<offset-1; i++)
  163175. msg[i]=error_message[i+1];
  163176. msg[i]='\0';
  163177. error_message=msg;
  163178. }
  163179. else
  163180. error_message+=offset;
  163181. }
  163182. else
  163183. {
  163184. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163185. {
  163186. msg[0]='0';
  163187. msg[1]='\0';
  163188. error_message=msg;
  163189. }
  163190. }
  163191. }
  163192. }
  163193. #endif
  163194. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163195. (*(png_ptr->error_fn))(png_ptr, error_message);
  163196. png_default_error(png_ptr, error_message);
  163197. }
  163198. #else
  163199. void PNGAPI
  163200. png_err(png_structp png_ptr)
  163201. {
  163202. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163203. (*(png_ptr->error_fn))(png_ptr, '\0');
  163204. png_default_error(png_ptr, '\0');
  163205. }
  163206. #endif /* PNG_NO_ERROR_TEXT */
  163207. #ifndef PNG_NO_WARNINGS
  163208. void PNGAPI
  163209. png_warning(png_structp png_ptr, png_const_charp warning_message)
  163210. {
  163211. int offset = 0;
  163212. if (png_ptr != NULL)
  163213. {
  163214. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163215. if (png_ptr->flags&
  163216. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163217. #endif
  163218. {
  163219. if (*warning_message == '#')
  163220. {
  163221. for (offset=1; offset<15; offset++)
  163222. if (*(warning_message+offset) == ' ')
  163223. break;
  163224. }
  163225. }
  163226. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  163227. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  163228. }
  163229. else
  163230. png_default_warning(png_ptr, warning_message+offset);
  163231. }
  163232. #endif /* PNG_NO_WARNINGS */
  163233. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  163234. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  163235. static void /* PRIVATE */
  163236. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  163237. error_message)
  163238. {
  163239. int iout = 0, iin = 0;
  163240. while (iin < 4)
  163241. {
  163242. int c = png_ptr->chunk_name[iin++];
  163243. if (isnonalpha(c))
  163244. {
  163245. buffer[iout++] = '[';
  163246. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  163247. buffer[iout++] = png_digit[c & 0x0f];
  163248. buffer[iout++] = ']';
  163249. }
  163250. else
  163251. {
  163252. buffer[iout++] = (png_byte)c;
  163253. }
  163254. }
  163255. if (error_message == NULL)
  163256. buffer[iout] = 0;
  163257. else
  163258. {
  163259. buffer[iout++] = ':';
  163260. buffer[iout++] = ' ';
  163261. png_strncpy(buffer+iout, error_message, 63);
  163262. buffer[iout+63] = 0;
  163263. }
  163264. }
  163265. #ifdef PNG_READ_SUPPORTED
  163266. void PNGAPI
  163267. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  163268. {
  163269. char msg[18+64];
  163270. if (png_ptr == NULL)
  163271. png_error(png_ptr, error_message);
  163272. else
  163273. {
  163274. png_format_buffer(png_ptr, msg, error_message);
  163275. png_error(png_ptr, msg);
  163276. }
  163277. }
  163278. #endif /* PNG_READ_SUPPORTED */
  163279. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  163280. #ifndef PNG_NO_WARNINGS
  163281. void PNGAPI
  163282. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  163283. {
  163284. char msg[18+64];
  163285. if (png_ptr == NULL)
  163286. png_warning(png_ptr, warning_message);
  163287. else
  163288. {
  163289. png_format_buffer(png_ptr, msg, warning_message);
  163290. png_warning(png_ptr, msg);
  163291. }
  163292. }
  163293. #endif /* PNG_NO_WARNINGS */
  163294. static void /* PRIVATE */
  163295. png_default_error(png_structp png_ptr, png_const_charp error_message)
  163296. {
  163297. #ifndef PNG_NO_CONSOLE_IO
  163298. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163299. if (*error_message == '#')
  163300. {
  163301. int offset;
  163302. char error_number[16];
  163303. for (offset=0; offset<15; offset++)
  163304. {
  163305. error_number[offset] = *(error_message+offset+1);
  163306. if (*(error_message+offset) == ' ')
  163307. break;
  163308. }
  163309. if((offset > 1) && (offset < 15))
  163310. {
  163311. error_number[offset-1]='\0';
  163312. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163313. error_message+offset);
  163314. }
  163315. else
  163316. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163317. }
  163318. else
  163319. #endif
  163320. fprintf(stderr, "libpng error: %s\n", error_message);
  163321. #endif
  163322. #ifdef PNG_SETJMP_SUPPORTED
  163323. if (png_ptr)
  163324. {
  163325. # ifdef USE_FAR_KEYWORD
  163326. {
  163327. jmp_buf jmpbuf;
  163328. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163329. longjmp(jmpbuf, 1);
  163330. }
  163331. # else
  163332. longjmp(png_ptr->jmpbuf, 1);
  163333. # endif
  163334. }
  163335. #else
  163336. PNG_ABORT();
  163337. #endif
  163338. #ifdef PNG_NO_CONSOLE_IO
  163339. error_message = error_message; /* make compiler happy */
  163340. #endif
  163341. }
  163342. #ifndef PNG_NO_WARNINGS
  163343. static void /* PRIVATE */
  163344. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163345. {
  163346. #ifndef PNG_NO_CONSOLE_IO
  163347. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163348. if (*warning_message == '#')
  163349. {
  163350. int offset;
  163351. char warning_number[16];
  163352. for (offset=0; offset<15; offset++)
  163353. {
  163354. warning_number[offset]=*(warning_message+offset+1);
  163355. if (*(warning_message+offset) == ' ')
  163356. break;
  163357. }
  163358. if((offset > 1) && (offset < 15))
  163359. {
  163360. warning_number[offset-1]='\0';
  163361. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163362. warning_message+offset);
  163363. }
  163364. else
  163365. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163366. }
  163367. else
  163368. # endif
  163369. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163370. #else
  163371. warning_message = warning_message; /* make compiler happy */
  163372. #endif
  163373. png_ptr = png_ptr; /* make compiler happy */
  163374. }
  163375. #endif /* PNG_NO_WARNINGS */
  163376. void PNGAPI
  163377. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163378. png_error_ptr error_fn, png_error_ptr warning_fn)
  163379. {
  163380. if (png_ptr == NULL)
  163381. return;
  163382. png_ptr->error_ptr = error_ptr;
  163383. png_ptr->error_fn = error_fn;
  163384. png_ptr->warning_fn = warning_fn;
  163385. }
  163386. png_voidp PNGAPI
  163387. png_get_error_ptr(png_structp png_ptr)
  163388. {
  163389. if (png_ptr == NULL)
  163390. return NULL;
  163391. return ((png_voidp)png_ptr->error_ptr);
  163392. }
  163393. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163394. void PNGAPI
  163395. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163396. {
  163397. if(png_ptr != NULL)
  163398. {
  163399. png_ptr->flags &=
  163400. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163401. }
  163402. }
  163403. #endif
  163404. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163405. /*** End of inlined file: pngerror.c ***/
  163406. /*** Start of inlined file: pngget.c ***/
  163407. #define PNG_INTERNAL
  163408. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163409. png_uint_32 PNGAPI
  163410. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163411. {
  163412. if (png_ptr != NULL && info_ptr != NULL)
  163413. return(info_ptr->valid & flag);
  163414. else
  163415. return(0);
  163416. }
  163417. png_uint_32 PNGAPI
  163418. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163419. {
  163420. if (png_ptr != NULL && info_ptr != NULL)
  163421. return(info_ptr->rowbytes);
  163422. else
  163423. return(0);
  163424. }
  163425. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163426. png_bytepp PNGAPI
  163427. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163428. {
  163429. if (png_ptr != NULL && info_ptr != NULL)
  163430. return(info_ptr->row_pointers);
  163431. else
  163432. return(0);
  163433. }
  163434. #endif
  163435. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163436. png_uint_32 PNGAPI
  163437. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163438. {
  163439. if (png_ptr != NULL && info_ptr != NULL)
  163440. {
  163441. return info_ptr->width;
  163442. }
  163443. return (0);
  163444. }
  163445. png_uint_32 PNGAPI
  163446. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163447. {
  163448. if (png_ptr != NULL && info_ptr != NULL)
  163449. {
  163450. return info_ptr->height;
  163451. }
  163452. return (0);
  163453. }
  163454. png_byte PNGAPI
  163455. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163456. {
  163457. if (png_ptr != NULL && info_ptr != NULL)
  163458. {
  163459. return info_ptr->bit_depth;
  163460. }
  163461. return (0);
  163462. }
  163463. png_byte PNGAPI
  163464. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163465. {
  163466. if (png_ptr != NULL && info_ptr != NULL)
  163467. {
  163468. return info_ptr->color_type;
  163469. }
  163470. return (0);
  163471. }
  163472. png_byte PNGAPI
  163473. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163474. {
  163475. if (png_ptr != NULL && info_ptr != NULL)
  163476. {
  163477. return info_ptr->filter_type;
  163478. }
  163479. return (0);
  163480. }
  163481. png_byte PNGAPI
  163482. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163483. {
  163484. if (png_ptr != NULL && info_ptr != NULL)
  163485. {
  163486. return info_ptr->interlace_type;
  163487. }
  163488. return (0);
  163489. }
  163490. png_byte PNGAPI
  163491. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163492. {
  163493. if (png_ptr != NULL && info_ptr != NULL)
  163494. {
  163495. return info_ptr->compression_type;
  163496. }
  163497. return (0);
  163498. }
  163499. png_uint_32 PNGAPI
  163500. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163501. {
  163502. if (png_ptr != NULL && info_ptr != NULL)
  163503. #if defined(PNG_pHYs_SUPPORTED)
  163504. if (info_ptr->valid & PNG_INFO_pHYs)
  163505. {
  163506. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163507. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163508. return (0);
  163509. else return (info_ptr->x_pixels_per_unit);
  163510. }
  163511. #else
  163512. return (0);
  163513. #endif
  163514. return (0);
  163515. }
  163516. png_uint_32 PNGAPI
  163517. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163518. {
  163519. if (png_ptr != NULL && info_ptr != NULL)
  163520. #if defined(PNG_pHYs_SUPPORTED)
  163521. if (info_ptr->valid & PNG_INFO_pHYs)
  163522. {
  163523. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163524. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163525. return (0);
  163526. else return (info_ptr->y_pixels_per_unit);
  163527. }
  163528. #else
  163529. return (0);
  163530. #endif
  163531. return (0);
  163532. }
  163533. png_uint_32 PNGAPI
  163534. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163535. {
  163536. if (png_ptr != NULL && info_ptr != NULL)
  163537. #if defined(PNG_pHYs_SUPPORTED)
  163538. if (info_ptr->valid & PNG_INFO_pHYs)
  163539. {
  163540. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163541. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163542. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163543. return (0);
  163544. else return (info_ptr->x_pixels_per_unit);
  163545. }
  163546. #else
  163547. return (0);
  163548. #endif
  163549. return (0);
  163550. }
  163551. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163552. float PNGAPI
  163553. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163554. {
  163555. if (png_ptr != NULL && info_ptr != NULL)
  163556. #if defined(PNG_pHYs_SUPPORTED)
  163557. if (info_ptr->valid & PNG_INFO_pHYs)
  163558. {
  163559. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163560. if (info_ptr->x_pixels_per_unit == 0)
  163561. return ((float)0.0);
  163562. else
  163563. return ((float)((float)info_ptr->y_pixels_per_unit
  163564. /(float)info_ptr->x_pixels_per_unit));
  163565. }
  163566. #else
  163567. return (0.0);
  163568. #endif
  163569. return ((float)0.0);
  163570. }
  163571. #endif
  163572. png_int_32 PNGAPI
  163573. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163574. {
  163575. if (png_ptr != NULL && info_ptr != NULL)
  163576. #if defined(PNG_oFFs_SUPPORTED)
  163577. if (info_ptr->valid & PNG_INFO_oFFs)
  163578. {
  163579. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163580. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163581. return (0);
  163582. else return (info_ptr->x_offset);
  163583. }
  163584. #else
  163585. return (0);
  163586. #endif
  163587. return (0);
  163588. }
  163589. png_int_32 PNGAPI
  163590. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163591. {
  163592. if (png_ptr != NULL && info_ptr != NULL)
  163593. #if defined(PNG_oFFs_SUPPORTED)
  163594. if (info_ptr->valid & PNG_INFO_oFFs)
  163595. {
  163596. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163597. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163598. return (0);
  163599. else return (info_ptr->y_offset);
  163600. }
  163601. #else
  163602. return (0);
  163603. #endif
  163604. return (0);
  163605. }
  163606. png_int_32 PNGAPI
  163607. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163608. {
  163609. if (png_ptr != NULL && info_ptr != NULL)
  163610. #if defined(PNG_oFFs_SUPPORTED)
  163611. if (info_ptr->valid & PNG_INFO_oFFs)
  163612. {
  163613. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163614. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163615. return (0);
  163616. else return (info_ptr->x_offset);
  163617. }
  163618. #else
  163619. return (0);
  163620. #endif
  163621. return (0);
  163622. }
  163623. png_int_32 PNGAPI
  163624. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163625. {
  163626. if (png_ptr != NULL && info_ptr != NULL)
  163627. #if defined(PNG_oFFs_SUPPORTED)
  163628. if (info_ptr->valid & PNG_INFO_oFFs)
  163629. {
  163630. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163631. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163632. return (0);
  163633. else return (info_ptr->y_offset);
  163634. }
  163635. #else
  163636. return (0);
  163637. #endif
  163638. return (0);
  163639. }
  163640. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163641. png_uint_32 PNGAPI
  163642. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163643. {
  163644. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163645. *.0254 +.5));
  163646. }
  163647. png_uint_32 PNGAPI
  163648. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163649. {
  163650. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163651. *.0254 +.5));
  163652. }
  163653. png_uint_32 PNGAPI
  163654. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163655. {
  163656. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163657. *.0254 +.5));
  163658. }
  163659. float PNGAPI
  163660. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163661. {
  163662. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163663. *.00003937);
  163664. }
  163665. float PNGAPI
  163666. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163667. {
  163668. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163669. *.00003937);
  163670. }
  163671. #if defined(PNG_pHYs_SUPPORTED)
  163672. png_uint_32 PNGAPI
  163673. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163674. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163675. {
  163676. png_uint_32 retval = 0;
  163677. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163678. {
  163679. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163680. if (res_x != NULL)
  163681. {
  163682. *res_x = info_ptr->x_pixels_per_unit;
  163683. retval |= PNG_INFO_pHYs;
  163684. }
  163685. if (res_y != NULL)
  163686. {
  163687. *res_y = info_ptr->y_pixels_per_unit;
  163688. retval |= PNG_INFO_pHYs;
  163689. }
  163690. if (unit_type != NULL)
  163691. {
  163692. *unit_type = (int)info_ptr->phys_unit_type;
  163693. retval |= PNG_INFO_pHYs;
  163694. if(*unit_type == 1)
  163695. {
  163696. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163697. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163698. }
  163699. }
  163700. }
  163701. return (retval);
  163702. }
  163703. #endif /* PNG_pHYs_SUPPORTED */
  163704. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163705. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163706. png_byte PNGAPI
  163707. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163708. {
  163709. if (png_ptr != NULL && info_ptr != NULL)
  163710. return(info_ptr->channels);
  163711. else
  163712. return (0);
  163713. }
  163714. png_bytep PNGAPI
  163715. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163716. {
  163717. if (png_ptr != NULL && info_ptr != NULL)
  163718. return(info_ptr->signature);
  163719. else
  163720. return (NULL);
  163721. }
  163722. #if defined(PNG_bKGD_SUPPORTED)
  163723. png_uint_32 PNGAPI
  163724. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163725. png_color_16p *background)
  163726. {
  163727. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163728. && background != NULL)
  163729. {
  163730. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163731. *background = &(info_ptr->background);
  163732. return (PNG_INFO_bKGD);
  163733. }
  163734. return (0);
  163735. }
  163736. #endif
  163737. #if defined(PNG_cHRM_SUPPORTED)
  163738. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163739. png_uint_32 PNGAPI
  163740. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163741. double *white_x, double *white_y, double *red_x, double *red_y,
  163742. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163743. {
  163744. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163745. {
  163746. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163747. if (white_x != NULL)
  163748. *white_x = (double)info_ptr->x_white;
  163749. if (white_y != NULL)
  163750. *white_y = (double)info_ptr->y_white;
  163751. if (red_x != NULL)
  163752. *red_x = (double)info_ptr->x_red;
  163753. if (red_y != NULL)
  163754. *red_y = (double)info_ptr->y_red;
  163755. if (green_x != NULL)
  163756. *green_x = (double)info_ptr->x_green;
  163757. if (green_y != NULL)
  163758. *green_y = (double)info_ptr->y_green;
  163759. if (blue_x != NULL)
  163760. *blue_x = (double)info_ptr->x_blue;
  163761. if (blue_y != NULL)
  163762. *blue_y = (double)info_ptr->y_blue;
  163763. return (PNG_INFO_cHRM);
  163764. }
  163765. return (0);
  163766. }
  163767. #endif
  163768. #ifdef PNG_FIXED_POINT_SUPPORTED
  163769. png_uint_32 PNGAPI
  163770. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163771. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163772. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163773. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163774. {
  163775. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163776. {
  163777. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163778. if (white_x != NULL)
  163779. *white_x = info_ptr->int_x_white;
  163780. if (white_y != NULL)
  163781. *white_y = info_ptr->int_y_white;
  163782. if (red_x != NULL)
  163783. *red_x = info_ptr->int_x_red;
  163784. if (red_y != NULL)
  163785. *red_y = info_ptr->int_y_red;
  163786. if (green_x != NULL)
  163787. *green_x = info_ptr->int_x_green;
  163788. if (green_y != NULL)
  163789. *green_y = info_ptr->int_y_green;
  163790. if (blue_x != NULL)
  163791. *blue_x = info_ptr->int_x_blue;
  163792. if (blue_y != NULL)
  163793. *blue_y = info_ptr->int_y_blue;
  163794. return (PNG_INFO_cHRM);
  163795. }
  163796. return (0);
  163797. }
  163798. #endif
  163799. #endif
  163800. #if defined(PNG_gAMA_SUPPORTED)
  163801. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163802. png_uint_32 PNGAPI
  163803. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163804. {
  163805. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163806. && file_gamma != NULL)
  163807. {
  163808. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163809. *file_gamma = (double)info_ptr->gamma;
  163810. return (PNG_INFO_gAMA);
  163811. }
  163812. return (0);
  163813. }
  163814. #endif
  163815. #ifdef PNG_FIXED_POINT_SUPPORTED
  163816. png_uint_32 PNGAPI
  163817. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163818. png_fixed_point *int_file_gamma)
  163819. {
  163820. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163821. && int_file_gamma != NULL)
  163822. {
  163823. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163824. *int_file_gamma = info_ptr->int_gamma;
  163825. return (PNG_INFO_gAMA);
  163826. }
  163827. return (0);
  163828. }
  163829. #endif
  163830. #endif
  163831. #if defined(PNG_sRGB_SUPPORTED)
  163832. png_uint_32 PNGAPI
  163833. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163834. {
  163835. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163836. && file_srgb_intent != NULL)
  163837. {
  163838. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163839. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163840. return (PNG_INFO_sRGB);
  163841. }
  163842. return (0);
  163843. }
  163844. #endif
  163845. #if defined(PNG_iCCP_SUPPORTED)
  163846. png_uint_32 PNGAPI
  163847. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163848. png_charpp name, int *compression_type,
  163849. png_charpp profile, png_uint_32 *proflen)
  163850. {
  163851. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163852. && name != NULL && profile != NULL && proflen != NULL)
  163853. {
  163854. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163855. *name = info_ptr->iccp_name;
  163856. *profile = info_ptr->iccp_profile;
  163857. *proflen = (int)info_ptr->iccp_proflen;
  163858. *compression_type = (int)info_ptr->iccp_compression;
  163859. return (PNG_INFO_iCCP);
  163860. }
  163861. return (0);
  163862. }
  163863. #endif
  163864. #if defined(PNG_sPLT_SUPPORTED)
  163865. png_uint_32 PNGAPI
  163866. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163867. png_sPLT_tpp spalettes)
  163868. {
  163869. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163870. {
  163871. *spalettes = info_ptr->splt_palettes;
  163872. return ((png_uint_32)info_ptr->splt_palettes_num);
  163873. }
  163874. return (0);
  163875. }
  163876. #endif
  163877. #if defined(PNG_hIST_SUPPORTED)
  163878. png_uint_32 PNGAPI
  163879. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163880. {
  163881. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163882. && hist != NULL)
  163883. {
  163884. png_debug1(1, "in %s retrieval function\n", "hIST");
  163885. *hist = info_ptr->hist;
  163886. return (PNG_INFO_hIST);
  163887. }
  163888. return (0);
  163889. }
  163890. #endif
  163891. png_uint_32 PNGAPI
  163892. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163893. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163894. int *color_type, int *interlace_type, int *compression_type,
  163895. int *filter_type)
  163896. {
  163897. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163898. bit_depth != NULL && color_type != NULL)
  163899. {
  163900. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163901. *width = info_ptr->width;
  163902. *height = info_ptr->height;
  163903. *bit_depth = info_ptr->bit_depth;
  163904. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163905. png_error(png_ptr, "Invalid bit depth");
  163906. *color_type = info_ptr->color_type;
  163907. if (info_ptr->color_type > 6)
  163908. png_error(png_ptr, "Invalid color type");
  163909. if (compression_type != NULL)
  163910. *compression_type = info_ptr->compression_type;
  163911. if (filter_type != NULL)
  163912. *filter_type = info_ptr->filter_type;
  163913. if (interlace_type != NULL)
  163914. *interlace_type = info_ptr->interlace_type;
  163915. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163916. png_error(png_ptr, "Invalid image width");
  163917. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163918. png_error(png_ptr, "Invalid image height");
  163919. if (info_ptr->width > (PNG_UINT_32_MAX
  163920. >> 3) /* 8-byte RGBA pixels */
  163921. - 64 /* bigrowbuf hack */
  163922. - 1 /* filter byte */
  163923. - 7*8 /* rounding of width to multiple of 8 pixels */
  163924. - 8) /* extra max_pixel_depth pad */
  163925. {
  163926. png_warning(png_ptr,
  163927. "Width too large for libpng to process image data.");
  163928. }
  163929. return (1);
  163930. }
  163931. return (0);
  163932. }
  163933. #if defined(PNG_oFFs_SUPPORTED)
  163934. png_uint_32 PNGAPI
  163935. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163936. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163937. {
  163938. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163939. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163940. {
  163941. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163942. *offset_x = info_ptr->x_offset;
  163943. *offset_y = info_ptr->y_offset;
  163944. *unit_type = (int)info_ptr->offset_unit_type;
  163945. return (PNG_INFO_oFFs);
  163946. }
  163947. return (0);
  163948. }
  163949. #endif
  163950. #if defined(PNG_pCAL_SUPPORTED)
  163951. png_uint_32 PNGAPI
  163952. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163953. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163954. png_charp *units, png_charpp *params)
  163955. {
  163956. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163957. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163958. nparams != NULL && units != NULL && params != NULL)
  163959. {
  163960. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163961. *purpose = info_ptr->pcal_purpose;
  163962. *X0 = info_ptr->pcal_X0;
  163963. *X1 = info_ptr->pcal_X1;
  163964. *type = (int)info_ptr->pcal_type;
  163965. *nparams = (int)info_ptr->pcal_nparams;
  163966. *units = info_ptr->pcal_units;
  163967. *params = info_ptr->pcal_params;
  163968. return (PNG_INFO_pCAL);
  163969. }
  163970. return (0);
  163971. }
  163972. #endif
  163973. #if defined(PNG_sCAL_SUPPORTED)
  163974. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163975. png_uint_32 PNGAPI
  163976. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163977. int *unit, double *width, double *height)
  163978. {
  163979. if (png_ptr != NULL && info_ptr != NULL &&
  163980. (info_ptr->valid & PNG_INFO_sCAL))
  163981. {
  163982. *unit = info_ptr->scal_unit;
  163983. *width = info_ptr->scal_pixel_width;
  163984. *height = info_ptr->scal_pixel_height;
  163985. return (PNG_INFO_sCAL);
  163986. }
  163987. return(0);
  163988. }
  163989. #else
  163990. #ifdef PNG_FIXED_POINT_SUPPORTED
  163991. png_uint_32 PNGAPI
  163992. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163993. int *unit, png_charpp width, png_charpp height)
  163994. {
  163995. if (png_ptr != NULL && info_ptr != NULL &&
  163996. (info_ptr->valid & PNG_INFO_sCAL))
  163997. {
  163998. *unit = info_ptr->scal_unit;
  163999. *width = info_ptr->scal_s_width;
  164000. *height = info_ptr->scal_s_height;
  164001. return (PNG_INFO_sCAL);
  164002. }
  164003. return(0);
  164004. }
  164005. #endif
  164006. #endif
  164007. #endif
  164008. #if defined(PNG_pHYs_SUPPORTED)
  164009. png_uint_32 PNGAPI
  164010. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  164011. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  164012. {
  164013. png_uint_32 retval = 0;
  164014. if (png_ptr != NULL && info_ptr != NULL &&
  164015. (info_ptr->valid & PNG_INFO_pHYs))
  164016. {
  164017. png_debug1(1, "in %s retrieval function\n", "pHYs");
  164018. if (res_x != NULL)
  164019. {
  164020. *res_x = info_ptr->x_pixels_per_unit;
  164021. retval |= PNG_INFO_pHYs;
  164022. }
  164023. if (res_y != NULL)
  164024. {
  164025. *res_y = info_ptr->y_pixels_per_unit;
  164026. retval |= PNG_INFO_pHYs;
  164027. }
  164028. if (unit_type != NULL)
  164029. {
  164030. *unit_type = (int)info_ptr->phys_unit_type;
  164031. retval |= PNG_INFO_pHYs;
  164032. }
  164033. }
  164034. return (retval);
  164035. }
  164036. #endif
  164037. png_uint_32 PNGAPI
  164038. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  164039. int *num_palette)
  164040. {
  164041. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  164042. && palette != NULL)
  164043. {
  164044. png_debug1(1, "in %s retrieval function\n", "PLTE");
  164045. *palette = info_ptr->palette;
  164046. *num_palette = info_ptr->num_palette;
  164047. png_debug1(3, "num_palette = %d\n", *num_palette);
  164048. return (PNG_INFO_PLTE);
  164049. }
  164050. return (0);
  164051. }
  164052. #if defined(PNG_sBIT_SUPPORTED)
  164053. png_uint_32 PNGAPI
  164054. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  164055. {
  164056. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  164057. && sig_bit != NULL)
  164058. {
  164059. png_debug1(1, "in %s retrieval function\n", "sBIT");
  164060. *sig_bit = &(info_ptr->sig_bit);
  164061. return (PNG_INFO_sBIT);
  164062. }
  164063. return (0);
  164064. }
  164065. #endif
  164066. #if defined(PNG_TEXT_SUPPORTED)
  164067. png_uint_32 PNGAPI
  164068. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  164069. int *num_text)
  164070. {
  164071. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  164072. {
  164073. png_debug1(1, "in %s retrieval function\n",
  164074. (png_ptr->chunk_name[0] == '\0' ? "text"
  164075. : (png_const_charp)png_ptr->chunk_name));
  164076. if (text_ptr != NULL)
  164077. *text_ptr = info_ptr->text;
  164078. if (num_text != NULL)
  164079. *num_text = info_ptr->num_text;
  164080. return ((png_uint_32)info_ptr->num_text);
  164081. }
  164082. if (num_text != NULL)
  164083. *num_text = 0;
  164084. return(0);
  164085. }
  164086. #endif
  164087. #if defined(PNG_tIME_SUPPORTED)
  164088. png_uint_32 PNGAPI
  164089. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  164090. {
  164091. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  164092. && mod_time != NULL)
  164093. {
  164094. png_debug1(1, "in %s retrieval function\n", "tIME");
  164095. *mod_time = &(info_ptr->mod_time);
  164096. return (PNG_INFO_tIME);
  164097. }
  164098. return (0);
  164099. }
  164100. #endif
  164101. #if defined(PNG_tRNS_SUPPORTED)
  164102. png_uint_32 PNGAPI
  164103. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  164104. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  164105. {
  164106. png_uint_32 retval = 0;
  164107. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  164108. {
  164109. png_debug1(1, "in %s retrieval function\n", "tRNS");
  164110. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  164111. {
  164112. if (trans != NULL)
  164113. {
  164114. *trans = info_ptr->trans;
  164115. retval |= PNG_INFO_tRNS;
  164116. }
  164117. if (trans_values != NULL)
  164118. *trans_values = &(info_ptr->trans_values);
  164119. }
  164120. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  164121. {
  164122. if (trans_values != NULL)
  164123. {
  164124. *trans_values = &(info_ptr->trans_values);
  164125. retval |= PNG_INFO_tRNS;
  164126. }
  164127. if(trans != NULL)
  164128. *trans = NULL;
  164129. }
  164130. if(num_trans != NULL)
  164131. {
  164132. *num_trans = info_ptr->num_trans;
  164133. retval |= PNG_INFO_tRNS;
  164134. }
  164135. }
  164136. return (retval);
  164137. }
  164138. #endif
  164139. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  164140. png_uint_32 PNGAPI
  164141. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  164142. png_unknown_chunkpp unknowns)
  164143. {
  164144. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  164145. {
  164146. *unknowns = info_ptr->unknown_chunks;
  164147. return ((png_uint_32)info_ptr->unknown_chunks_num);
  164148. }
  164149. return (0);
  164150. }
  164151. #endif
  164152. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  164153. png_byte PNGAPI
  164154. png_get_rgb_to_gray_status (png_structp png_ptr)
  164155. {
  164156. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  164157. }
  164158. #endif
  164159. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  164160. png_voidp PNGAPI
  164161. png_get_user_chunk_ptr(png_structp png_ptr)
  164162. {
  164163. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  164164. }
  164165. #endif
  164166. #ifdef PNG_WRITE_SUPPORTED
  164167. png_uint_32 PNGAPI
  164168. png_get_compression_buffer_size(png_structp png_ptr)
  164169. {
  164170. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  164171. }
  164172. #endif
  164173. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  164174. #ifndef PNG_1_0_X
  164175. png_uint_32 PNGAPI
  164176. png_get_asm_flags (png_structp png_ptr)
  164177. {
  164178. return (png_ptr? 0L: 0L);
  164179. }
  164180. png_uint_32 PNGAPI
  164181. png_get_asm_flagmask (int flag_select)
  164182. {
  164183. flag_select=flag_select;
  164184. return 0L;
  164185. }
  164186. png_uint_32 PNGAPI
  164187. png_get_mmx_flagmask (int flag_select, int *compilerID)
  164188. {
  164189. flag_select=flag_select;
  164190. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  164191. return 0L;
  164192. }
  164193. png_byte PNGAPI
  164194. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  164195. {
  164196. return (png_ptr? 0: 0);
  164197. }
  164198. png_uint_32 PNGAPI
  164199. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  164200. {
  164201. return (png_ptr? 0L: 0L);
  164202. }
  164203. #endif /* ?PNG_1_0_X */
  164204. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  164205. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164206. png_uint_32 PNGAPI
  164207. png_get_user_width_max (png_structp png_ptr)
  164208. {
  164209. return (png_ptr? png_ptr->user_width_max : 0);
  164210. }
  164211. png_uint_32 PNGAPI
  164212. png_get_user_height_max (png_structp png_ptr)
  164213. {
  164214. return (png_ptr? png_ptr->user_height_max : 0);
  164215. }
  164216. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  164217. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164218. /*** End of inlined file: pngget.c ***/
  164219. /*** Start of inlined file: pngmem.c ***/
  164220. #define PNG_INTERNAL
  164221. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  164222. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  164223. png_voidp /* PRIVATE */
  164224. png_create_struct(int type)
  164225. {
  164226. #ifdef PNG_USER_MEM_SUPPORTED
  164227. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164228. }
  164229. png_voidp /* PRIVATE */
  164230. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164231. {
  164232. #endif /* PNG_USER_MEM_SUPPORTED */
  164233. png_size_t size;
  164234. png_voidp struct_ptr;
  164235. if (type == PNG_STRUCT_INFO)
  164236. size = png_sizeof(png_info);
  164237. else if (type == PNG_STRUCT_PNG)
  164238. size = png_sizeof(png_struct);
  164239. else
  164240. return (png_get_copyright(NULL));
  164241. #ifdef PNG_USER_MEM_SUPPORTED
  164242. if(malloc_fn != NULL)
  164243. {
  164244. png_struct dummy_struct;
  164245. png_structp png_ptr = &dummy_struct;
  164246. png_ptr->mem_ptr=mem_ptr;
  164247. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  164248. }
  164249. else
  164250. #endif /* PNG_USER_MEM_SUPPORTED */
  164251. struct_ptr = (png_voidp)farmalloc(size);
  164252. if (struct_ptr != NULL)
  164253. png_memset(struct_ptr, 0, size);
  164254. return (struct_ptr);
  164255. }
  164256. void /* PRIVATE */
  164257. png_destroy_struct(png_voidp struct_ptr)
  164258. {
  164259. #ifdef PNG_USER_MEM_SUPPORTED
  164260. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164261. }
  164262. void /* PRIVATE */
  164263. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164264. png_voidp mem_ptr)
  164265. {
  164266. #endif
  164267. if (struct_ptr != NULL)
  164268. {
  164269. #ifdef PNG_USER_MEM_SUPPORTED
  164270. if(free_fn != NULL)
  164271. {
  164272. png_struct dummy_struct;
  164273. png_structp png_ptr = &dummy_struct;
  164274. png_ptr->mem_ptr=mem_ptr;
  164275. (*(free_fn))(png_ptr, struct_ptr);
  164276. return;
  164277. }
  164278. #endif /* PNG_USER_MEM_SUPPORTED */
  164279. farfree (struct_ptr);
  164280. }
  164281. }
  164282. png_voidp PNGAPI
  164283. png_malloc(png_structp png_ptr, png_uint_32 size)
  164284. {
  164285. png_voidp ret;
  164286. if (png_ptr == NULL || size == 0)
  164287. return (NULL);
  164288. #ifdef PNG_USER_MEM_SUPPORTED
  164289. if(png_ptr->malloc_fn != NULL)
  164290. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164291. else
  164292. ret = (png_malloc_default(png_ptr, size));
  164293. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164294. png_error(png_ptr, "Out of memory!");
  164295. return (ret);
  164296. }
  164297. png_voidp PNGAPI
  164298. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164299. {
  164300. png_voidp ret;
  164301. #endif /* PNG_USER_MEM_SUPPORTED */
  164302. if (png_ptr == NULL || size == 0)
  164303. return (NULL);
  164304. #ifdef PNG_MAX_MALLOC_64K
  164305. if (size > (png_uint_32)65536L)
  164306. {
  164307. png_warning(png_ptr, "Cannot Allocate > 64K");
  164308. ret = NULL;
  164309. }
  164310. else
  164311. #endif
  164312. if (size != (size_t)size)
  164313. ret = NULL;
  164314. else if (size == (png_uint_32)65536L)
  164315. {
  164316. if (png_ptr->offset_table == NULL)
  164317. {
  164318. ret = farmalloc(size);
  164319. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164320. {
  164321. int num_blocks;
  164322. png_uint_32 total_size;
  164323. png_bytep table;
  164324. int i;
  164325. png_byte huge * hptr;
  164326. if (ret != NULL)
  164327. {
  164328. farfree(ret);
  164329. ret = NULL;
  164330. }
  164331. if(png_ptr->zlib_window_bits > 14)
  164332. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164333. else
  164334. num_blocks = 1;
  164335. if (png_ptr->zlib_mem_level >= 7)
  164336. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164337. else
  164338. num_blocks++;
  164339. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164340. table = farmalloc(total_size);
  164341. if (table == NULL)
  164342. {
  164343. #ifndef PNG_USER_MEM_SUPPORTED
  164344. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164345. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164346. else
  164347. png_warning(png_ptr, "Out Of Memory.");
  164348. #endif
  164349. return (NULL);
  164350. }
  164351. if ((png_size_t)table & 0xfff0)
  164352. {
  164353. #ifndef PNG_USER_MEM_SUPPORTED
  164354. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164355. png_error(png_ptr,
  164356. "Farmalloc didn't return normalized pointer");
  164357. else
  164358. png_warning(png_ptr,
  164359. "Farmalloc didn't return normalized pointer");
  164360. #endif
  164361. return (NULL);
  164362. }
  164363. png_ptr->offset_table = table;
  164364. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164365. png_sizeof (png_bytep));
  164366. if (png_ptr->offset_table_ptr == NULL)
  164367. {
  164368. #ifndef PNG_USER_MEM_SUPPORTED
  164369. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164370. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164371. else
  164372. png_warning(png_ptr, "Out Of memory.");
  164373. #endif
  164374. return (NULL);
  164375. }
  164376. hptr = (png_byte huge *)table;
  164377. if ((png_size_t)hptr & 0xf)
  164378. {
  164379. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164380. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164381. }
  164382. for (i = 0; i < num_blocks; i++)
  164383. {
  164384. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164385. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164386. }
  164387. png_ptr->offset_table_number = num_blocks;
  164388. png_ptr->offset_table_count = 0;
  164389. png_ptr->offset_table_count_free = 0;
  164390. }
  164391. }
  164392. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164393. {
  164394. #ifndef PNG_USER_MEM_SUPPORTED
  164395. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164396. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164397. else
  164398. png_warning(png_ptr, "Out of Memory.");
  164399. #endif
  164400. return (NULL);
  164401. }
  164402. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164403. }
  164404. else
  164405. ret = farmalloc(size);
  164406. #ifndef PNG_USER_MEM_SUPPORTED
  164407. if (ret == NULL)
  164408. {
  164409. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164410. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164411. else
  164412. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164413. }
  164414. #endif
  164415. return (ret);
  164416. }
  164417. void PNGAPI
  164418. png_free(png_structp png_ptr, png_voidp ptr)
  164419. {
  164420. if (png_ptr == NULL || ptr == NULL)
  164421. return;
  164422. #ifdef PNG_USER_MEM_SUPPORTED
  164423. if (png_ptr->free_fn != NULL)
  164424. {
  164425. (*(png_ptr->free_fn))(png_ptr, ptr);
  164426. return;
  164427. }
  164428. else png_free_default(png_ptr, ptr);
  164429. }
  164430. void PNGAPI
  164431. png_free_default(png_structp png_ptr, png_voidp ptr)
  164432. {
  164433. #endif /* PNG_USER_MEM_SUPPORTED */
  164434. if(png_ptr == NULL) return;
  164435. if (png_ptr->offset_table != NULL)
  164436. {
  164437. int i;
  164438. for (i = 0; i < png_ptr->offset_table_count; i++)
  164439. {
  164440. if (ptr == png_ptr->offset_table_ptr[i])
  164441. {
  164442. ptr = NULL;
  164443. png_ptr->offset_table_count_free++;
  164444. break;
  164445. }
  164446. }
  164447. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164448. {
  164449. farfree(png_ptr->offset_table);
  164450. farfree(png_ptr->offset_table_ptr);
  164451. png_ptr->offset_table = NULL;
  164452. png_ptr->offset_table_ptr = NULL;
  164453. }
  164454. }
  164455. if (ptr != NULL)
  164456. {
  164457. farfree(ptr);
  164458. }
  164459. }
  164460. #else /* Not the Borland DOS special memory handler */
  164461. png_voidp /* PRIVATE */
  164462. png_create_struct(int type)
  164463. {
  164464. #ifdef PNG_USER_MEM_SUPPORTED
  164465. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164466. }
  164467. png_voidp /* PRIVATE */
  164468. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164469. {
  164470. #endif /* PNG_USER_MEM_SUPPORTED */
  164471. png_size_t size;
  164472. png_voidp struct_ptr;
  164473. if (type == PNG_STRUCT_INFO)
  164474. size = png_sizeof(png_info);
  164475. else if (type == PNG_STRUCT_PNG)
  164476. size = png_sizeof(png_struct);
  164477. else
  164478. return (NULL);
  164479. #ifdef PNG_USER_MEM_SUPPORTED
  164480. if(malloc_fn != NULL)
  164481. {
  164482. png_struct dummy_struct;
  164483. png_structp png_ptr = &dummy_struct;
  164484. png_ptr->mem_ptr=mem_ptr;
  164485. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164486. if (struct_ptr != NULL)
  164487. png_memset(struct_ptr, 0, size);
  164488. return (struct_ptr);
  164489. }
  164490. #endif /* PNG_USER_MEM_SUPPORTED */
  164491. #if defined(__TURBOC__) && !defined(__FLAT__)
  164492. struct_ptr = (png_voidp)farmalloc(size);
  164493. #else
  164494. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164495. struct_ptr = (png_voidp)halloc(size,1);
  164496. # else
  164497. struct_ptr = (png_voidp)malloc(size);
  164498. # endif
  164499. #endif
  164500. if (struct_ptr != NULL)
  164501. png_memset(struct_ptr, 0, size);
  164502. return (struct_ptr);
  164503. }
  164504. void /* PRIVATE */
  164505. png_destroy_struct(png_voidp struct_ptr)
  164506. {
  164507. #ifdef PNG_USER_MEM_SUPPORTED
  164508. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164509. }
  164510. void /* PRIVATE */
  164511. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164512. png_voidp mem_ptr)
  164513. {
  164514. #endif /* PNG_USER_MEM_SUPPORTED */
  164515. if (struct_ptr != NULL)
  164516. {
  164517. #ifdef PNG_USER_MEM_SUPPORTED
  164518. if(free_fn != NULL)
  164519. {
  164520. png_struct dummy_struct;
  164521. png_structp png_ptr = &dummy_struct;
  164522. png_ptr->mem_ptr=mem_ptr;
  164523. (*(free_fn))(png_ptr, struct_ptr);
  164524. return;
  164525. }
  164526. #endif /* PNG_USER_MEM_SUPPORTED */
  164527. #if defined(__TURBOC__) && !defined(__FLAT__)
  164528. farfree(struct_ptr);
  164529. #else
  164530. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164531. hfree(struct_ptr);
  164532. # else
  164533. free(struct_ptr);
  164534. # endif
  164535. #endif
  164536. }
  164537. }
  164538. png_voidp PNGAPI
  164539. png_malloc(png_structp png_ptr, png_uint_32 size)
  164540. {
  164541. png_voidp ret;
  164542. #ifdef PNG_USER_MEM_SUPPORTED
  164543. if (png_ptr == NULL || size == 0)
  164544. return (NULL);
  164545. if(png_ptr->malloc_fn != NULL)
  164546. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164547. else
  164548. ret = (png_malloc_default(png_ptr, size));
  164549. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164550. png_error(png_ptr, "Out of Memory!");
  164551. return (ret);
  164552. }
  164553. png_voidp PNGAPI
  164554. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164555. {
  164556. png_voidp ret;
  164557. #endif /* PNG_USER_MEM_SUPPORTED */
  164558. if (png_ptr == NULL || size == 0)
  164559. return (NULL);
  164560. #ifdef PNG_MAX_MALLOC_64K
  164561. if (size > (png_uint_32)65536L)
  164562. {
  164563. #ifndef PNG_USER_MEM_SUPPORTED
  164564. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164565. png_error(png_ptr, "Cannot Allocate > 64K");
  164566. else
  164567. #endif
  164568. return NULL;
  164569. }
  164570. #endif
  164571. #if defined(__TURBOC__) && !defined(__FLAT__)
  164572. if (size != (unsigned long)size)
  164573. ret = NULL;
  164574. else
  164575. ret = farmalloc(size);
  164576. #else
  164577. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164578. if (size != (unsigned long)size)
  164579. ret = NULL;
  164580. else
  164581. ret = halloc(size, 1);
  164582. # else
  164583. if (size != (size_t)size)
  164584. ret = NULL;
  164585. else
  164586. ret = malloc((size_t)size);
  164587. # endif
  164588. #endif
  164589. #ifndef PNG_USER_MEM_SUPPORTED
  164590. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164591. png_error(png_ptr, "Out of Memory");
  164592. #endif
  164593. return (ret);
  164594. }
  164595. void PNGAPI
  164596. png_free(png_structp png_ptr, png_voidp ptr)
  164597. {
  164598. if (png_ptr == NULL || ptr == NULL)
  164599. return;
  164600. #ifdef PNG_USER_MEM_SUPPORTED
  164601. if (png_ptr->free_fn != NULL)
  164602. {
  164603. (*(png_ptr->free_fn))(png_ptr, ptr);
  164604. return;
  164605. }
  164606. else png_free_default(png_ptr, ptr);
  164607. }
  164608. void PNGAPI
  164609. png_free_default(png_structp png_ptr, png_voidp ptr)
  164610. {
  164611. if (png_ptr == NULL || ptr == NULL)
  164612. return;
  164613. #endif /* PNG_USER_MEM_SUPPORTED */
  164614. #if defined(__TURBOC__) && !defined(__FLAT__)
  164615. farfree(ptr);
  164616. #else
  164617. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164618. hfree(ptr);
  164619. # else
  164620. free(ptr);
  164621. # endif
  164622. #endif
  164623. }
  164624. #endif /* Not Borland DOS special memory handler */
  164625. #if defined(PNG_1_0_X)
  164626. # define png_malloc_warn png_malloc
  164627. #else
  164628. png_voidp PNGAPI
  164629. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164630. {
  164631. png_voidp ptr;
  164632. png_uint_32 save_flags;
  164633. if(png_ptr == NULL) return (NULL);
  164634. save_flags=png_ptr->flags;
  164635. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164636. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164637. png_ptr->flags=save_flags;
  164638. return(ptr);
  164639. }
  164640. #endif
  164641. png_voidp PNGAPI
  164642. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164643. png_uint_32 length)
  164644. {
  164645. png_size_t size;
  164646. size = (png_size_t)length;
  164647. if ((png_uint_32)size != length)
  164648. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164649. return(png_memcpy (s1, s2, size));
  164650. }
  164651. png_voidp PNGAPI
  164652. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164653. png_uint_32 length)
  164654. {
  164655. png_size_t size;
  164656. size = (png_size_t)length;
  164657. if ((png_uint_32)size != length)
  164658. png_error(png_ptr,"Overflow in png_memset_check.");
  164659. return (png_memset (s1, value, size));
  164660. }
  164661. #ifdef PNG_USER_MEM_SUPPORTED
  164662. void PNGAPI
  164663. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164664. malloc_fn, png_free_ptr free_fn)
  164665. {
  164666. if(png_ptr != NULL) {
  164667. png_ptr->mem_ptr = mem_ptr;
  164668. png_ptr->malloc_fn = malloc_fn;
  164669. png_ptr->free_fn = free_fn;
  164670. }
  164671. }
  164672. png_voidp PNGAPI
  164673. png_get_mem_ptr(png_structp png_ptr)
  164674. {
  164675. if(png_ptr == NULL) return (NULL);
  164676. return ((png_voidp)png_ptr->mem_ptr);
  164677. }
  164678. #endif /* PNG_USER_MEM_SUPPORTED */
  164679. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164680. /*** End of inlined file: pngmem.c ***/
  164681. /*** Start of inlined file: pngread.c ***/
  164682. #define PNG_INTERNAL
  164683. #if defined(PNG_READ_SUPPORTED)
  164684. png_structp PNGAPI
  164685. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164686. png_error_ptr error_fn, png_error_ptr warn_fn)
  164687. {
  164688. #ifdef PNG_USER_MEM_SUPPORTED
  164689. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164690. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164691. }
  164692. png_structp PNGAPI
  164693. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164694. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164695. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164696. {
  164697. #endif /* PNG_USER_MEM_SUPPORTED */
  164698. png_structp png_ptr;
  164699. #ifdef PNG_SETJMP_SUPPORTED
  164700. #ifdef USE_FAR_KEYWORD
  164701. jmp_buf jmpbuf;
  164702. #endif
  164703. #endif
  164704. int i;
  164705. png_debug(1, "in png_create_read_struct\n");
  164706. #ifdef PNG_USER_MEM_SUPPORTED
  164707. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164708. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164709. #else
  164710. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164711. #endif
  164712. if (png_ptr == NULL)
  164713. return (NULL);
  164714. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164715. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164716. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164717. #endif
  164718. #ifdef PNG_SETJMP_SUPPORTED
  164719. #ifdef USE_FAR_KEYWORD
  164720. if (setjmp(jmpbuf))
  164721. #else
  164722. if (setjmp(png_ptr->jmpbuf))
  164723. #endif
  164724. {
  164725. png_free(png_ptr, png_ptr->zbuf);
  164726. png_ptr->zbuf=NULL;
  164727. #ifdef PNG_USER_MEM_SUPPORTED
  164728. png_destroy_struct_2((png_voidp)png_ptr,
  164729. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164730. #else
  164731. png_destroy_struct((png_voidp)png_ptr);
  164732. #endif
  164733. return (NULL);
  164734. }
  164735. #ifdef USE_FAR_KEYWORD
  164736. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164737. #endif
  164738. #endif
  164739. #ifdef PNG_USER_MEM_SUPPORTED
  164740. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164741. #endif
  164742. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164743. i=0;
  164744. do
  164745. {
  164746. if(user_png_ver[i] != png_libpng_ver[i])
  164747. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164748. } while (png_libpng_ver[i++]);
  164749. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164750. {
  164751. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164752. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164753. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164754. {
  164755. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164756. char msg[80];
  164757. if (user_png_ver)
  164758. {
  164759. png_snprintf(msg, 80,
  164760. "Application was compiled with png.h from libpng-%.20s",
  164761. user_png_ver);
  164762. png_warning(png_ptr, msg);
  164763. }
  164764. png_snprintf(msg, 80,
  164765. "Application is running with png.c from libpng-%.20s",
  164766. png_libpng_ver);
  164767. png_warning(png_ptr, msg);
  164768. #endif
  164769. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164770. png_ptr->flags=0;
  164771. #endif
  164772. png_error(png_ptr,
  164773. "Incompatible libpng version in application and library");
  164774. }
  164775. }
  164776. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164777. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164778. (png_uint_32)png_ptr->zbuf_size);
  164779. png_ptr->zstream.zalloc = png_zalloc;
  164780. png_ptr->zstream.zfree = png_zfree;
  164781. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164782. switch (inflateInit(&png_ptr->zstream))
  164783. {
  164784. case Z_OK: /* Do nothing */ break;
  164785. case Z_MEM_ERROR:
  164786. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164787. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164788. default: png_error(png_ptr, "Unknown zlib error");
  164789. }
  164790. png_ptr->zstream.next_out = png_ptr->zbuf;
  164791. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164792. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164793. #ifdef PNG_SETJMP_SUPPORTED
  164794. #ifdef USE_FAR_KEYWORD
  164795. if (setjmp(jmpbuf))
  164796. PNG_ABORT();
  164797. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164798. #else
  164799. if (setjmp(png_ptr->jmpbuf))
  164800. PNG_ABORT();
  164801. #endif
  164802. #endif
  164803. return (png_ptr);
  164804. }
  164805. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164806. #undef png_read_init
  164807. void PNGAPI
  164808. png_read_init(png_structp png_ptr)
  164809. {
  164810. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164811. }
  164812. void PNGAPI
  164813. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164814. png_size_t png_struct_size, png_size_t png_info_size)
  164815. {
  164816. if(png_ptr == NULL) return;
  164817. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164818. if(png_sizeof(png_struct) > png_struct_size ||
  164819. png_sizeof(png_info) > png_info_size)
  164820. {
  164821. char msg[80];
  164822. png_ptr->warning_fn=NULL;
  164823. if (user_png_ver)
  164824. {
  164825. png_snprintf(msg, 80,
  164826. "Application was compiled with png.h from libpng-%.20s",
  164827. user_png_ver);
  164828. png_warning(png_ptr, msg);
  164829. }
  164830. png_snprintf(msg, 80,
  164831. "Application is running with png.c from libpng-%.20s",
  164832. png_libpng_ver);
  164833. png_warning(png_ptr, msg);
  164834. }
  164835. #endif
  164836. if(png_sizeof(png_struct) > png_struct_size)
  164837. {
  164838. png_ptr->error_fn=NULL;
  164839. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164840. png_ptr->flags=0;
  164841. #endif
  164842. png_error(png_ptr,
  164843. "The png struct allocated by the application for reading is too small.");
  164844. }
  164845. if(png_sizeof(png_info) > png_info_size)
  164846. {
  164847. png_ptr->error_fn=NULL;
  164848. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164849. png_ptr->flags=0;
  164850. #endif
  164851. png_error(png_ptr,
  164852. "The info struct allocated by application for reading is too small.");
  164853. }
  164854. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164855. }
  164856. #endif /* PNG_1_0_X || PNG_1_2_X */
  164857. void PNGAPI
  164858. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164859. png_size_t png_struct_size)
  164860. {
  164861. #ifdef PNG_SETJMP_SUPPORTED
  164862. jmp_buf tmp_jmp; /* to save current jump buffer */
  164863. #endif
  164864. int i=0;
  164865. png_structp png_ptr=*ptr_ptr;
  164866. if(png_ptr == NULL) return;
  164867. do
  164868. {
  164869. if(user_png_ver[i] != png_libpng_ver[i])
  164870. {
  164871. #ifdef PNG_LEGACY_SUPPORTED
  164872. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164873. #else
  164874. png_ptr->warning_fn=NULL;
  164875. png_warning(png_ptr,
  164876. "Application uses deprecated png_read_init() and should be recompiled.");
  164877. break;
  164878. #endif
  164879. }
  164880. } while (png_libpng_ver[i++]);
  164881. png_debug(1, "in png_read_init_3\n");
  164882. #ifdef PNG_SETJMP_SUPPORTED
  164883. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164884. #endif
  164885. if(png_sizeof(png_struct) > png_struct_size)
  164886. {
  164887. png_destroy_struct(png_ptr);
  164888. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164889. png_ptr = *ptr_ptr;
  164890. }
  164891. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164892. #ifdef PNG_SETJMP_SUPPORTED
  164893. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164894. #endif
  164895. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164896. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164897. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164898. #endif
  164899. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164900. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164901. (png_uint_32)png_ptr->zbuf_size);
  164902. png_ptr->zstream.zalloc = png_zalloc;
  164903. png_ptr->zstream.zfree = png_zfree;
  164904. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164905. switch (inflateInit(&png_ptr->zstream))
  164906. {
  164907. case Z_OK: /* Do nothing */ break;
  164908. case Z_MEM_ERROR:
  164909. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164910. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164911. default: png_error(png_ptr, "Unknown zlib error");
  164912. }
  164913. png_ptr->zstream.next_out = png_ptr->zbuf;
  164914. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164915. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164916. }
  164917. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164918. void PNGAPI
  164919. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164920. {
  164921. if(png_ptr == NULL) return;
  164922. png_debug(1, "in png_read_info\n");
  164923. if (png_ptr->sig_bytes < 8)
  164924. {
  164925. png_size_t num_checked = png_ptr->sig_bytes,
  164926. num_to_check = 8 - num_checked;
  164927. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164928. png_ptr->sig_bytes = 8;
  164929. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164930. {
  164931. if (num_checked < 4 &&
  164932. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164933. png_error(png_ptr, "Not a PNG file");
  164934. else
  164935. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164936. }
  164937. if (num_checked < 3)
  164938. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164939. }
  164940. for(;;)
  164941. {
  164942. #ifdef PNG_USE_LOCAL_ARRAYS
  164943. PNG_CONST PNG_IHDR;
  164944. PNG_CONST PNG_IDAT;
  164945. PNG_CONST PNG_IEND;
  164946. PNG_CONST PNG_PLTE;
  164947. #if defined(PNG_READ_bKGD_SUPPORTED)
  164948. PNG_CONST PNG_bKGD;
  164949. #endif
  164950. #if defined(PNG_READ_cHRM_SUPPORTED)
  164951. PNG_CONST PNG_cHRM;
  164952. #endif
  164953. #if defined(PNG_READ_gAMA_SUPPORTED)
  164954. PNG_CONST PNG_gAMA;
  164955. #endif
  164956. #if defined(PNG_READ_hIST_SUPPORTED)
  164957. PNG_CONST PNG_hIST;
  164958. #endif
  164959. #if defined(PNG_READ_iCCP_SUPPORTED)
  164960. PNG_CONST PNG_iCCP;
  164961. #endif
  164962. #if defined(PNG_READ_iTXt_SUPPORTED)
  164963. PNG_CONST PNG_iTXt;
  164964. #endif
  164965. #if defined(PNG_READ_oFFs_SUPPORTED)
  164966. PNG_CONST PNG_oFFs;
  164967. #endif
  164968. #if defined(PNG_READ_pCAL_SUPPORTED)
  164969. PNG_CONST PNG_pCAL;
  164970. #endif
  164971. #if defined(PNG_READ_pHYs_SUPPORTED)
  164972. PNG_CONST PNG_pHYs;
  164973. #endif
  164974. #if defined(PNG_READ_sBIT_SUPPORTED)
  164975. PNG_CONST PNG_sBIT;
  164976. #endif
  164977. #if defined(PNG_READ_sCAL_SUPPORTED)
  164978. PNG_CONST PNG_sCAL;
  164979. #endif
  164980. #if defined(PNG_READ_sPLT_SUPPORTED)
  164981. PNG_CONST PNG_sPLT;
  164982. #endif
  164983. #if defined(PNG_READ_sRGB_SUPPORTED)
  164984. PNG_CONST PNG_sRGB;
  164985. #endif
  164986. #if defined(PNG_READ_tEXt_SUPPORTED)
  164987. PNG_CONST PNG_tEXt;
  164988. #endif
  164989. #if defined(PNG_READ_tIME_SUPPORTED)
  164990. PNG_CONST PNG_tIME;
  164991. #endif
  164992. #if defined(PNG_READ_tRNS_SUPPORTED)
  164993. PNG_CONST PNG_tRNS;
  164994. #endif
  164995. #if defined(PNG_READ_zTXt_SUPPORTED)
  164996. PNG_CONST PNG_zTXt;
  164997. #endif
  164998. #endif /* PNG_USE_LOCAL_ARRAYS */
  164999. png_byte chunk_length[4];
  165000. png_uint_32 length;
  165001. png_read_data(png_ptr, chunk_length, 4);
  165002. length = png_get_uint_31(png_ptr,chunk_length);
  165003. png_reset_crc(png_ptr);
  165004. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165005. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  165006. length);
  165007. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165008. if(png_ptr->mode & PNG_AFTER_IDAT)
  165009. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165010. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165011. png_handle_IHDR(png_ptr, info_ptr, length);
  165012. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165013. png_handle_IEND(png_ptr, info_ptr, length);
  165014. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165015. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165016. {
  165017. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165018. png_ptr->mode |= PNG_HAVE_IDAT;
  165019. png_handle_unknown(png_ptr, info_ptr, length);
  165020. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165021. png_ptr->mode |= PNG_HAVE_PLTE;
  165022. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165023. {
  165024. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165025. png_error(png_ptr, "Missing IHDR before IDAT");
  165026. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165027. !(png_ptr->mode & PNG_HAVE_PLTE))
  165028. png_error(png_ptr, "Missing PLTE before IDAT");
  165029. break;
  165030. }
  165031. }
  165032. #endif
  165033. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165034. png_handle_PLTE(png_ptr, info_ptr, length);
  165035. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165036. {
  165037. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165038. png_error(png_ptr, "Missing IHDR before IDAT");
  165039. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165040. !(png_ptr->mode & PNG_HAVE_PLTE))
  165041. png_error(png_ptr, "Missing PLTE before IDAT");
  165042. png_ptr->idat_size = length;
  165043. png_ptr->mode |= PNG_HAVE_IDAT;
  165044. break;
  165045. }
  165046. #if defined(PNG_READ_bKGD_SUPPORTED)
  165047. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165048. png_handle_bKGD(png_ptr, info_ptr, length);
  165049. #endif
  165050. #if defined(PNG_READ_cHRM_SUPPORTED)
  165051. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165052. png_handle_cHRM(png_ptr, info_ptr, length);
  165053. #endif
  165054. #if defined(PNG_READ_gAMA_SUPPORTED)
  165055. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165056. png_handle_gAMA(png_ptr, info_ptr, length);
  165057. #endif
  165058. #if defined(PNG_READ_hIST_SUPPORTED)
  165059. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165060. png_handle_hIST(png_ptr, info_ptr, length);
  165061. #endif
  165062. #if defined(PNG_READ_oFFs_SUPPORTED)
  165063. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165064. png_handle_oFFs(png_ptr, info_ptr, length);
  165065. #endif
  165066. #if defined(PNG_READ_pCAL_SUPPORTED)
  165067. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165068. png_handle_pCAL(png_ptr, info_ptr, length);
  165069. #endif
  165070. #if defined(PNG_READ_sCAL_SUPPORTED)
  165071. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165072. png_handle_sCAL(png_ptr, info_ptr, length);
  165073. #endif
  165074. #if defined(PNG_READ_pHYs_SUPPORTED)
  165075. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165076. png_handle_pHYs(png_ptr, info_ptr, length);
  165077. #endif
  165078. #if defined(PNG_READ_sBIT_SUPPORTED)
  165079. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165080. png_handle_sBIT(png_ptr, info_ptr, length);
  165081. #endif
  165082. #if defined(PNG_READ_sRGB_SUPPORTED)
  165083. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165084. png_handle_sRGB(png_ptr, info_ptr, length);
  165085. #endif
  165086. #if defined(PNG_READ_iCCP_SUPPORTED)
  165087. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165088. png_handle_iCCP(png_ptr, info_ptr, length);
  165089. #endif
  165090. #if defined(PNG_READ_sPLT_SUPPORTED)
  165091. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165092. png_handle_sPLT(png_ptr, info_ptr, length);
  165093. #endif
  165094. #if defined(PNG_READ_tEXt_SUPPORTED)
  165095. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165096. png_handle_tEXt(png_ptr, info_ptr, length);
  165097. #endif
  165098. #if defined(PNG_READ_tIME_SUPPORTED)
  165099. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165100. png_handle_tIME(png_ptr, info_ptr, length);
  165101. #endif
  165102. #if defined(PNG_READ_tRNS_SUPPORTED)
  165103. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165104. png_handle_tRNS(png_ptr, info_ptr, length);
  165105. #endif
  165106. #if defined(PNG_READ_zTXt_SUPPORTED)
  165107. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165108. png_handle_zTXt(png_ptr, info_ptr, length);
  165109. #endif
  165110. #if defined(PNG_READ_iTXt_SUPPORTED)
  165111. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165112. png_handle_iTXt(png_ptr, info_ptr, length);
  165113. #endif
  165114. else
  165115. png_handle_unknown(png_ptr, info_ptr, length);
  165116. }
  165117. }
  165118. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165119. void PNGAPI
  165120. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  165121. {
  165122. png_debug(1, "in png_read_update_info\n");
  165123. if(png_ptr == NULL) return;
  165124. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165125. png_read_start_row(png_ptr);
  165126. else
  165127. png_warning(png_ptr,
  165128. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  165129. png_read_transform_info(png_ptr, info_ptr);
  165130. }
  165131. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165132. void PNGAPI
  165133. png_start_read_image(png_structp png_ptr)
  165134. {
  165135. png_debug(1, "in png_start_read_image\n");
  165136. if(png_ptr == NULL) return;
  165137. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165138. png_read_start_row(png_ptr);
  165139. }
  165140. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165141. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165142. void PNGAPI
  165143. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  165144. {
  165145. #ifdef PNG_USE_LOCAL_ARRAYS
  165146. PNG_CONST PNG_IDAT;
  165147. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  165148. 0xff};
  165149. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  165150. #endif
  165151. int ret;
  165152. if(png_ptr == NULL) return;
  165153. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  165154. png_ptr->row_number, png_ptr->pass);
  165155. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165156. png_read_start_row(png_ptr);
  165157. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  165158. {
  165159. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  165160. if (png_ptr->transformations & PNG_INVERT_MONO)
  165161. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  165162. #endif
  165163. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  165164. if (png_ptr->transformations & PNG_FILLER)
  165165. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  165166. #endif
  165167. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  165168. if (png_ptr->transformations & PNG_PACKSWAP)
  165169. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  165170. #endif
  165171. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  165172. if (png_ptr->transformations & PNG_PACK)
  165173. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  165174. #endif
  165175. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  165176. if (png_ptr->transformations & PNG_SHIFT)
  165177. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  165178. #endif
  165179. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  165180. if (png_ptr->transformations & PNG_BGR)
  165181. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  165182. #endif
  165183. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  165184. if (png_ptr->transformations & PNG_SWAP_BYTES)
  165185. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  165186. #endif
  165187. }
  165188. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165189. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  165190. {
  165191. switch (png_ptr->pass)
  165192. {
  165193. case 0:
  165194. if (png_ptr->row_number & 0x07)
  165195. {
  165196. if (dsp_row != NULL)
  165197. png_combine_row(png_ptr, dsp_row,
  165198. png_pass_dsp_mask[png_ptr->pass]);
  165199. png_read_finish_row(png_ptr);
  165200. return;
  165201. }
  165202. break;
  165203. case 1:
  165204. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  165205. {
  165206. if (dsp_row != NULL)
  165207. png_combine_row(png_ptr, dsp_row,
  165208. png_pass_dsp_mask[png_ptr->pass]);
  165209. png_read_finish_row(png_ptr);
  165210. return;
  165211. }
  165212. break;
  165213. case 2:
  165214. if ((png_ptr->row_number & 0x07) != 4)
  165215. {
  165216. if (dsp_row != NULL && (png_ptr->row_number & 4))
  165217. png_combine_row(png_ptr, dsp_row,
  165218. png_pass_dsp_mask[png_ptr->pass]);
  165219. png_read_finish_row(png_ptr);
  165220. return;
  165221. }
  165222. break;
  165223. case 3:
  165224. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  165225. {
  165226. if (dsp_row != NULL)
  165227. png_combine_row(png_ptr, dsp_row,
  165228. png_pass_dsp_mask[png_ptr->pass]);
  165229. png_read_finish_row(png_ptr);
  165230. return;
  165231. }
  165232. break;
  165233. case 4:
  165234. if ((png_ptr->row_number & 3) != 2)
  165235. {
  165236. if (dsp_row != NULL && (png_ptr->row_number & 2))
  165237. png_combine_row(png_ptr, dsp_row,
  165238. png_pass_dsp_mask[png_ptr->pass]);
  165239. png_read_finish_row(png_ptr);
  165240. return;
  165241. }
  165242. break;
  165243. case 5:
  165244. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  165245. {
  165246. if (dsp_row != NULL)
  165247. png_combine_row(png_ptr, dsp_row,
  165248. png_pass_dsp_mask[png_ptr->pass]);
  165249. png_read_finish_row(png_ptr);
  165250. return;
  165251. }
  165252. break;
  165253. case 6:
  165254. if (!(png_ptr->row_number & 1))
  165255. {
  165256. png_read_finish_row(png_ptr);
  165257. return;
  165258. }
  165259. break;
  165260. }
  165261. }
  165262. #endif
  165263. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  165264. png_error(png_ptr, "Invalid attempt to read row data");
  165265. png_ptr->zstream.next_out = png_ptr->row_buf;
  165266. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165267. do
  165268. {
  165269. if (!(png_ptr->zstream.avail_in))
  165270. {
  165271. while (!png_ptr->idat_size)
  165272. {
  165273. png_byte chunk_length[4];
  165274. png_crc_finish(png_ptr, 0);
  165275. png_read_data(png_ptr, chunk_length, 4);
  165276. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  165277. png_reset_crc(png_ptr);
  165278. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165279. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165280. png_error(png_ptr, "Not enough image data");
  165281. }
  165282. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  165283. png_ptr->zstream.next_in = png_ptr->zbuf;
  165284. if (png_ptr->zbuf_size > png_ptr->idat_size)
  165285. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  165286. png_crc_read(png_ptr, png_ptr->zbuf,
  165287. (png_size_t)png_ptr->zstream.avail_in);
  165288. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  165289. }
  165290. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165291. if (ret == Z_STREAM_END)
  165292. {
  165293. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  165294. png_ptr->idat_size)
  165295. png_error(png_ptr, "Extra compressed data");
  165296. png_ptr->mode |= PNG_AFTER_IDAT;
  165297. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165298. break;
  165299. }
  165300. if (ret != Z_OK)
  165301. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165302. "Decompression error");
  165303. } while (png_ptr->zstream.avail_out);
  165304. png_ptr->row_info.color_type = png_ptr->color_type;
  165305. png_ptr->row_info.width = png_ptr->iwidth;
  165306. png_ptr->row_info.channels = png_ptr->channels;
  165307. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165308. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165309. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165310. png_ptr->row_info.width);
  165311. if(png_ptr->row_buf[0])
  165312. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165313. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165314. (int)(png_ptr->row_buf[0]));
  165315. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165316. png_ptr->rowbytes + 1);
  165317. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165318. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165319. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165320. {
  165321. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165322. }
  165323. #endif
  165324. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165325. png_do_read_transformations(png_ptr);
  165326. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165327. if (png_ptr->interlaced &&
  165328. (png_ptr->transformations & PNG_INTERLACE))
  165329. {
  165330. if (png_ptr->pass < 6)
  165331. png_do_read_interlace(png_ptr);
  165332. if (dsp_row != NULL)
  165333. png_combine_row(png_ptr, dsp_row,
  165334. png_pass_dsp_mask[png_ptr->pass]);
  165335. if (row != NULL)
  165336. png_combine_row(png_ptr, row,
  165337. png_pass_mask[png_ptr->pass]);
  165338. }
  165339. else
  165340. #endif
  165341. {
  165342. if (row != NULL)
  165343. png_combine_row(png_ptr, row, 0xff);
  165344. if (dsp_row != NULL)
  165345. png_combine_row(png_ptr, dsp_row, 0xff);
  165346. }
  165347. png_read_finish_row(png_ptr);
  165348. if (png_ptr->read_row_fn != NULL)
  165349. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165350. }
  165351. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165352. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165353. void PNGAPI
  165354. png_read_rows(png_structp png_ptr, png_bytepp row,
  165355. png_bytepp display_row, png_uint_32 num_rows)
  165356. {
  165357. png_uint_32 i;
  165358. png_bytepp rp;
  165359. png_bytepp dp;
  165360. png_debug(1, "in png_read_rows\n");
  165361. if(png_ptr == NULL) return;
  165362. rp = row;
  165363. dp = display_row;
  165364. if (rp != NULL && dp != NULL)
  165365. for (i = 0; i < num_rows; i++)
  165366. {
  165367. png_bytep rptr = *rp++;
  165368. png_bytep dptr = *dp++;
  165369. png_read_row(png_ptr, rptr, dptr);
  165370. }
  165371. else if(rp != NULL)
  165372. for (i = 0; i < num_rows; i++)
  165373. {
  165374. png_bytep rptr = *rp;
  165375. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165376. rp++;
  165377. }
  165378. else if(dp != NULL)
  165379. for (i = 0; i < num_rows; i++)
  165380. {
  165381. png_bytep dptr = *dp;
  165382. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165383. dp++;
  165384. }
  165385. }
  165386. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165387. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165388. void PNGAPI
  165389. png_read_image(png_structp png_ptr, png_bytepp image)
  165390. {
  165391. png_uint_32 i,image_height;
  165392. int pass, j;
  165393. png_bytepp rp;
  165394. png_debug(1, "in png_read_image\n");
  165395. if(png_ptr == NULL) return;
  165396. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165397. pass = png_set_interlace_handling(png_ptr);
  165398. #else
  165399. if (png_ptr->interlaced)
  165400. png_error(png_ptr,
  165401. "Cannot read interlaced image -- interlace handler disabled.");
  165402. pass = 1;
  165403. #endif
  165404. image_height=png_ptr->height;
  165405. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165406. for (j = 0; j < pass; j++)
  165407. {
  165408. rp = image;
  165409. for (i = 0; i < image_height; i++)
  165410. {
  165411. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165412. rp++;
  165413. }
  165414. }
  165415. }
  165416. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165417. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165418. void PNGAPI
  165419. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165420. {
  165421. png_byte chunk_length[4];
  165422. png_uint_32 length;
  165423. png_debug(1, "in png_read_end\n");
  165424. if(png_ptr == NULL) return;
  165425. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165426. do
  165427. {
  165428. #ifdef PNG_USE_LOCAL_ARRAYS
  165429. PNG_CONST PNG_IHDR;
  165430. PNG_CONST PNG_IDAT;
  165431. PNG_CONST PNG_IEND;
  165432. PNG_CONST PNG_PLTE;
  165433. #if defined(PNG_READ_bKGD_SUPPORTED)
  165434. PNG_CONST PNG_bKGD;
  165435. #endif
  165436. #if defined(PNG_READ_cHRM_SUPPORTED)
  165437. PNG_CONST PNG_cHRM;
  165438. #endif
  165439. #if defined(PNG_READ_gAMA_SUPPORTED)
  165440. PNG_CONST PNG_gAMA;
  165441. #endif
  165442. #if defined(PNG_READ_hIST_SUPPORTED)
  165443. PNG_CONST PNG_hIST;
  165444. #endif
  165445. #if defined(PNG_READ_iCCP_SUPPORTED)
  165446. PNG_CONST PNG_iCCP;
  165447. #endif
  165448. #if defined(PNG_READ_iTXt_SUPPORTED)
  165449. PNG_CONST PNG_iTXt;
  165450. #endif
  165451. #if defined(PNG_READ_oFFs_SUPPORTED)
  165452. PNG_CONST PNG_oFFs;
  165453. #endif
  165454. #if defined(PNG_READ_pCAL_SUPPORTED)
  165455. PNG_CONST PNG_pCAL;
  165456. #endif
  165457. #if defined(PNG_READ_pHYs_SUPPORTED)
  165458. PNG_CONST PNG_pHYs;
  165459. #endif
  165460. #if defined(PNG_READ_sBIT_SUPPORTED)
  165461. PNG_CONST PNG_sBIT;
  165462. #endif
  165463. #if defined(PNG_READ_sCAL_SUPPORTED)
  165464. PNG_CONST PNG_sCAL;
  165465. #endif
  165466. #if defined(PNG_READ_sPLT_SUPPORTED)
  165467. PNG_CONST PNG_sPLT;
  165468. #endif
  165469. #if defined(PNG_READ_sRGB_SUPPORTED)
  165470. PNG_CONST PNG_sRGB;
  165471. #endif
  165472. #if defined(PNG_READ_tEXt_SUPPORTED)
  165473. PNG_CONST PNG_tEXt;
  165474. #endif
  165475. #if defined(PNG_READ_tIME_SUPPORTED)
  165476. PNG_CONST PNG_tIME;
  165477. #endif
  165478. #if defined(PNG_READ_tRNS_SUPPORTED)
  165479. PNG_CONST PNG_tRNS;
  165480. #endif
  165481. #if defined(PNG_READ_zTXt_SUPPORTED)
  165482. PNG_CONST PNG_zTXt;
  165483. #endif
  165484. #endif /* PNG_USE_LOCAL_ARRAYS */
  165485. png_read_data(png_ptr, chunk_length, 4);
  165486. length = png_get_uint_31(png_ptr,chunk_length);
  165487. png_reset_crc(png_ptr);
  165488. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165489. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165490. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165491. png_handle_IHDR(png_ptr, info_ptr, length);
  165492. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165493. png_handle_IEND(png_ptr, info_ptr, length);
  165494. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165495. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165496. {
  165497. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165498. {
  165499. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165500. png_error(png_ptr, "Too many IDAT's found");
  165501. }
  165502. png_handle_unknown(png_ptr, info_ptr, length);
  165503. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165504. png_ptr->mode |= PNG_HAVE_PLTE;
  165505. }
  165506. #endif
  165507. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165508. {
  165509. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165510. png_error(png_ptr, "Too many IDAT's found");
  165511. png_crc_finish(png_ptr, length);
  165512. }
  165513. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165514. png_handle_PLTE(png_ptr, info_ptr, length);
  165515. #if defined(PNG_READ_bKGD_SUPPORTED)
  165516. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165517. png_handle_bKGD(png_ptr, info_ptr, length);
  165518. #endif
  165519. #if defined(PNG_READ_cHRM_SUPPORTED)
  165520. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165521. png_handle_cHRM(png_ptr, info_ptr, length);
  165522. #endif
  165523. #if defined(PNG_READ_gAMA_SUPPORTED)
  165524. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165525. png_handle_gAMA(png_ptr, info_ptr, length);
  165526. #endif
  165527. #if defined(PNG_READ_hIST_SUPPORTED)
  165528. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165529. png_handle_hIST(png_ptr, info_ptr, length);
  165530. #endif
  165531. #if defined(PNG_READ_oFFs_SUPPORTED)
  165532. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165533. png_handle_oFFs(png_ptr, info_ptr, length);
  165534. #endif
  165535. #if defined(PNG_READ_pCAL_SUPPORTED)
  165536. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165537. png_handle_pCAL(png_ptr, info_ptr, length);
  165538. #endif
  165539. #if defined(PNG_READ_sCAL_SUPPORTED)
  165540. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165541. png_handle_sCAL(png_ptr, info_ptr, length);
  165542. #endif
  165543. #if defined(PNG_READ_pHYs_SUPPORTED)
  165544. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165545. png_handle_pHYs(png_ptr, info_ptr, length);
  165546. #endif
  165547. #if defined(PNG_READ_sBIT_SUPPORTED)
  165548. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165549. png_handle_sBIT(png_ptr, info_ptr, length);
  165550. #endif
  165551. #if defined(PNG_READ_sRGB_SUPPORTED)
  165552. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165553. png_handle_sRGB(png_ptr, info_ptr, length);
  165554. #endif
  165555. #if defined(PNG_READ_iCCP_SUPPORTED)
  165556. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165557. png_handle_iCCP(png_ptr, info_ptr, length);
  165558. #endif
  165559. #if defined(PNG_READ_sPLT_SUPPORTED)
  165560. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165561. png_handle_sPLT(png_ptr, info_ptr, length);
  165562. #endif
  165563. #if defined(PNG_READ_tEXt_SUPPORTED)
  165564. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165565. png_handle_tEXt(png_ptr, info_ptr, length);
  165566. #endif
  165567. #if defined(PNG_READ_tIME_SUPPORTED)
  165568. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165569. png_handle_tIME(png_ptr, info_ptr, length);
  165570. #endif
  165571. #if defined(PNG_READ_tRNS_SUPPORTED)
  165572. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165573. png_handle_tRNS(png_ptr, info_ptr, length);
  165574. #endif
  165575. #if defined(PNG_READ_zTXt_SUPPORTED)
  165576. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165577. png_handle_zTXt(png_ptr, info_ptr, length);
  165578. #endif
  165579. #if defined(PNG_READ_iTXt_SUPPORTED)
  165580. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165581. png_handle_iTXt(png_ptr, info_ptr, length);
  165582. #endif
  165583. else
  165584. png_handle_unknown(png_ptr, info_ptr, length);
  165585. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165586. }
  165587. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165588. void PNGAPI
  165589. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165590. png_infopp end_info_ptr_ptr)
  165591. {
  165592. png_structp png_ptr = NULL;
  165593. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165594. #ifdef PNG_USER_MEM_SUPPORTED
  165595. png_free_ptr free_fn;
  165596. png_voidp mem_ptr;
  165597. #endif
  165598. png_debug(1, "in png_destroy_read_struct\n");
  165599. if (png_ptr_ptr != NULL)
  165600. png_ptr = *png_ptr_ptr;
  165601. if (info_ptr_ptr != NULL)
  165602. info_ptr = *info_ptr_ptr;
  165603. if (end_info_ptr_ptr != NULL)
  165604. end_info_ptr = *end_info_ptr_ptr;
  165605. #ifdef PNG_USER_MEM_SUPPORTED
  165606. free_fn = png_ptr->free_fn;
  165607. mem_ptr = png_ptr->mem_ptr;
  165608. #endif
  165609. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165610. if (info_ptr != NULL)
  165611. {
  165612. #if defined(PNG_TEXT_SUPPORTED)
  165613. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165614. #endif
  165615. #ifdef PNG_USER_MEM_SUPPORTED
  165616. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165617. (png_voidp)mem_ptr);
  165618. #else
  165619. png_destroy_struct((png_voidp)info_ptr);
  165620. #endif
  165621. *info_ptr_ptr = NULL;
  165622. }
  165623. if (end_info_ptr != NULL)
  165624. {
  165625. #if defined(PNG_READ_TEXT_SUPPORTED)
  165626. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165627. #endif
  165628. #ifdef PNG_USER_MEM_SUPPORTED
  165629. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165630. (png_voidp)mem_ptr);
  165631. #else
  165632. png_destroy_struct((png_voidp)end_info_ptr);
  165633. #endif
  165634. *end_info_ptr_ptr = NULL;
  165635. }
  165636. if (png_ptr != NULL)
  165637. {
  165638. #ifdef PNG_USER_MEM_SUPPORTED
  165639. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165640. (png_voidp)mem_ptr);
  165641. #else
  165642. png_destroy_struct((png_voidp)png_ptr);
  165643. #endif
  165644. *png_ptr_ptr = NULL;
  165645. }
  165646. }
  165647. void /* PRIVATE */
  165648. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165649. {
  165650. #ifdef PNG_SETJMP_SUPPORTED
  165651. jmp_buf tmp_jmp;
  165652. #endif
  165653. png_error_ptr error_fn;
  165654. png_error_ptr warning_fn;
  165655. png_voidp error_ptr;
  165656. #ifdef PNG_USER_MEM_SUPPORTED
  165657. png_free_ptr free_fn;
  165658. #endif
  165659. png_debug(1, "in png_read_destroy\n");
  165660. if (info_ptr != NULL)
  165661. png_info_destroy(png_ptr, info_ptr);
  165662. if (end_info_ptr != NULL)
  165663. png_info_destroy(png_ptr, end_info_ptr);
  165664. png_free(png_ptr, png_ptr->zbuf);
  165665. png_free(png_ptr, png_ptr->big_row_buf);
  165666. png_free(png_ptr, png_ptr->prev_row);
  165667. #if defined(PNG_READ_DITHER_SUPPORTED)
  165668. png_free(png_ptr, png_ptr->palette_lookup);
  165669. png_free(png_ptr, png_ptr->dither_index);
  165670. #endif
  165671. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165672. png_free(png_ptr, png_ptr->gamma_table);
  165673. #endif
  165674. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165675. png_free(png_ptr, png_ptr->gamma_from_1);
  165676. png_free(png_ptr, png_ptr->gamma_to_1);
  165677. #endif
  165678. #ifdef PNG_FREE_ME_SUPPORTED
  165679. if (png_ptr->free_me & PNG_FREE_PLTE)
  165680. png_zfree(png_ptr, png_ptr->palette);
  165681. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165682. #else
  165683. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165684. png_zfree(png_ptr, png_ptr->palette);
  165685. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165686. #endif
  165687. #if defined(PNG_tRNS_SUPPORTED) || \
  165688. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165689. #ifdef PNG_FREE_ME_SUPPORTED
  165690. if (png_ptr->free_me & PNG_FREE_TRNS)
  165691. png_free(png_ptr, png_ptr->trans);
  165692. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165693. #else
  165694. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165695. png_free(png_ptr, png_ptr->trans);
  165696. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165697. #endif
  165698. #endif
  165699. #if defined(PNG_READ_hIST_SUPPORTED)
  165700. #ifdef PNG_FREE_ME_SUPPORTED
  165701. if (png_ptr->free_me & PNG_FREE_HIST)
  165702. png_free(png_ptr, png_ptr->hist);
  165703. png_ptr->free_me &= ~PNG_FREE_HIST;
  165704. #else
  165705. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165706. png_free(png_ptr, png_ptr->hist);
  165707. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165708. #endif
  165709. #endif
  165710. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165711. if (png_ptr->gamma_16_table != NULL)
  165712. {
  165713. int i;
  165714. int istop = (1 << (8 - png_ptr->gamma_shift));
  165715. for (i = 0; i < istop; i++)
  165716. {
  165717. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165718. }
  165719. png_free(png_ptr, png_ptr->gamma_16_table);
  165720. }
  165721. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165722. if (png_ptr->gamma_16_from_1 != NULL)
  165723. {
  165724. int i;
  165725. int istop = (1 << (8 - png_ptr->gamma_shift));
  165726. for (i = 0; i < istop; i++)
  165727. {
  165728. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165729. }
  165730. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165731. }
  165732. if (png_ptr->gamma_16_to_1 != NULL)
  165733. {
  165734. int i;
  165735. int istop = (1 << (8 - png_ptr->gamma_shift));
  165736. for (i = 0; i < istop; i++)
  165737. {
  165738. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165739. }
  165740. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165741. }
  165742. #endif
  165743. #endif
  165744. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165745. png_free(png_ptr, png_ptr->time_buffer);
  165746. #endif
  165747. inflateEnd(&png_ptr->zstream);
  165748. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165749. png_free(png_ptr, png_ptr->save_buffer);
  165750. #endif
  165751. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165752. #ifdef PNG_TEXT_SUPPORTED
  165753. png_free(png_ptr, png_ptr->current_text);
  165754. #endif /* PNG_TEXT_SUPPORTED */
  165755. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165756. #ifdef PNG_SETJMP_SUPPORTED
  165757. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165758. #endif
  165759. error_fn = png_ptr->error_fn;
  165760. warning_fn = png_ptr->warning_fn;
  165761. error_ptr = png_ptr->error_ptr;
  165762. #ifdef PNG_USER_MEM_SUPPORTED
  165763. free_fn = png_ptr->free_fn;
  165764. #endif
  165765. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165766. png_ptr->error_fn = error_fn;
  165767. png_ptr->warning_fn = warning_fn;
  165768. png_ptr->error_ptr = error_ptr;
  165769. #ifdef PNG_USER_MEM_SUPPORTED
  165770. png_ptr->free_fn = free_fn;
  165771. #endif
  165772. #ifdef PNG_SETJMP_SUPPORTED
  165773. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165774. #endif
  165775. }
  165776. void PNGAPI
  165777. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165778. {
  165779. if(png_ptr == NULL) return;
  165780. png_ptr->read_row_fn = read_row_fn;
  165781. }
  165782. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165783. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165784. void PNGAPI
  165785. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165786. int transforms,
  165787. voidp params)
  165788. {
  165789. int row;
  165790. if(png_ptr == NULL) return;
  165791. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165792. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165793. png_set_invert_alpha(png_ptr);
  165794. #endif
  165795. png_read_info(png_ptr, info_ptr);
  165796. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165797. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165798. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165799. if (transforms & PNG_TRANSFORM_STRIP_16)
  165800. png_set_strip_16(png_ptr);
  165801. #endif
  165802. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165803. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165804. png_set_strip_alpha(png_ptr);
  165805. #endif
  165806. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165807. if (transforms & PNG_TRANSFORM_PACKING)
  165808. png_set_packing(png_ptr);
  165809. #endif
  165810. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165811. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165812. png_set_packswap(png_ptr);
  165813. #endif
  165814. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165815. if (transforms & PNG_TRANSFORM_EXPAND)
  165816. if ((png_ptr->bit_depth < 8) ||
  165817. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165818. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165819. png_set_expand(png_ptr);
  165820. #endif
  165821. #if defined(PNG_READ_INVERT_SUPPORTED)
  165822. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165823. png_set_invert_mono(png_ptr);
  165824. #endif
  165825. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165826. if ((transforms & PNG_TRANSFORM_SHIFT)
  165827. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165828. {
  165829. png_color_8p sig_bit;
  165830. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165831. png_set_shift(png_ptr, sig_bit);
  165832. }
  165833. #endif
  165834. #if defined(PNG_READ_BGR_SUPPORTED)
  165835. if (transforms & PNG_TRANSFORM_BGR)
  165836. png_set_bgr(png_ptr);
  165837. #endif
  165838. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165839. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165840. png_set_swap_alpha(png_ptr);
  165841. #endif
  165842. #if defined(PNG_READ_SWAP_SUPPORTED)
  165843. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165844. png_set_swap(png_ptr);
  165845. #endif
  165846. png_read_update_info(png_ptr, info_ptr);
  165847. #ifdef PNG_FREE_ME_SUPPORTED
  165848. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165849. #endif
  165850. if(info_ptr->row_pointers == NULL)
  165851. {
  165852. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165853. info_ptr->height * png_sizeof(png_bytep));
  165854. #ifdef PNG_FREE_ME_SUPPORTED
  165855. info_ptr->free_me |= PNG_FREE_ROWS;
  165856. #endif
  165857. for (row = 0; row < (int)info_ptr->height; row++)
  165858. {
  165859. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165860. png_get_rowbytes(png_ptr, info_ptr));
  165861. }
  165862. }
  165863. png_read_image(png_ptr, info_ptr->row_pointers);
  165864. info_ptr->valid |= PNG_INFO_IDAT;
  165865. png_read_end(png_ptr, info_ptr);
  165866. transforms = transforms; /* quiet compiler warnings */
  165867. params = params;
  165868. }
  165869. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165870. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165871. #endif /* PNG_READ_SUPPORTED */
  165872. /*** End of inlined file: pngread.c ***/
  165873. /*** Start of inlined file: pngpread.c ***/
  165874. #define PNG_INTERNAL
  165875. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165876. #define PNG_READ_SIG_MODE 0
  165877. #define PNG_READ_CHUNK_MODE 1
  165878. #define PNG_READ_IDAT_MODE 2
  165879. #define PNG_SKIP_MODE 3
  165880. #define PNG_READ_tEXt_MODE 4
  165881. #define PNG_READ_zTXt_MODE 5
  165882. #define PNG_READ_DONE_MODE 6
  165883. #define PNG_READ_iTXt_MODE 7
  165884. #define PNG_ERROR_MODE 8
  165885. void PNGAPI
  165886. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165887. png_bytep buffer, png_size_t buffer_size)
  165888. {
  165889. if(png_ptr == NULL) return;
  165890. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165891. while (png_ptr->buffer_size)
  165892. {
  165893. png_process_some_data(png_ptr, info_ptr);
  165894. }
  165895. }
  165896. void /* PRIVATE */
  165897. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165898. {
  165899. if(png_ptr == NULL) return;
  165900. switch (png_ptr->process_mode)
  165901. {
  165902. case PNG_READ_SIG_MODE:
  165903. {
  165904. png_push_read_sig(png_ptr, info_ptr);
  165905. break;
  165906. }
  165907. case PNG_READ_CHUNK_MODE:
  165908. {
  165909. png_push_read_chunk(png_ptr, info_ptr);
  165910. break;
  165911. }
  165912. case PNG_READ_IDAT_MODE:
  165913. {
  165914. png_push_read_IDAT(png_ptr);
  165915. break;
  165916. }
  165917. #if defined(PNG_READ_tEXt_SUPPORTED)
  165918. case PNG_READ_tEXt_MODE:
  165919. {
  165920. png_push_read_tEXt(png_ptr, info_ptr);
  165921. break;
  165922. }
  165923. #endif
  165924. #if defined(PNG_READ_zTXt_SUPPORTED)
  165925. case PNG_READ_zTXt_MODE:
  165926. {
  165927. png_push_read_zTXt(png_ptr, info_ptr);
  165928. break;
  165929. }
  165930. #endif
  165931. #if defined(PNG_READ_iTXt_SUPPORTED)
  165932. case PNG_READ_iTXt_MODE:
  165933. {
  165934. png_push_read_iTXt(png_ptr, info_ptr);
  165935. break;
  165936. }
  165937. #endif
  165938. case PNG_SKIP_MODE:
  165939. {
  165940. png_push_crc_finish(png_ptr);
  165941. break;
  165942. }
  165943. default:
  165944. {
  165945. png_ptr->buffer_size = 0;
  165946. break;
  165947. }
  165948. }
  165949. }
  165950. void /* PRIVATE */
  165951. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165952. {
  165953. png_size_t num_checked = png_ptr->sig_bytes,
  165954. num_to_check = 8 - num_checked;
  165955. if (png_ptr->buffer_size < num_to_check)
  165956. {
  165957. num_to_check = png_ptr->buffer_size;
  165958. }
  165959. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165960. num_to_check);
  165961. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165962. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165963. {
  165964. if (num_checked < 4 &&
  165965. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165966. png_error(png_ptr, "Not a PNG file");
  165967. else
  165968. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165969. }
  165970. else
  165971. {
  165972. if (png_ptr->sig_bytes >= 8)
  165973. {
  165974. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165975. }
  165976. }
  165977. }
  165978. void /* PRIVATE */
  165979. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165980. {
  165981. #ifdef PNG_USE_LOCAL_ARRAYS
  165982. PNG_CONST PNG_IHDR;
  165983. PNG_CONST PNG_IDAT;
  165984. PNG_CONST PNG_IEND;
  165985. PNG_CONST PNG_PLTE;
  165986. #if defined(PNG_READ_bKGD_SUPPORTED)
  165987. PNG_CONST PNG_bKGD;
  165988. #endif
  165989. #if defined(PNG_READ_cHRM_SUPPORTED)
  165990. PNG_CONST PNG_cHRM;
  165991. #endif
  165992. #if defined(PNG_READ_gAMA_SUPPORTED)
  165993. PNG_CONST PNG_gAMA;
  165994. #endif
  165995. #if defined(PNG_READ_hIST_SUPPORTED)
  165996. PNG_CONST PNG_hIST;
  165997. #endif
  165998. #if defined(PNG_READ_iCCP_SUPPORTED)
  165999. PNG_CONST PNG_iCCP;
  166000. #endif
  166001. #if defined(PNG_READ_iTXt_SUPPORTED)
  166002. PNG_CONST PNG_iTXt;
  166003. #endif
  166004. #if defined(PNG_READ_oFFs_SUPPORTED)
  166005. PNG_CONST PNG_oFFs;
  166006. #endif
  166007. #if defined(PNG_READ_pCAL_SUPPORTED)
  166008. PNG_CONST PNG_pCAL;
  166009. #endif
  166010. #if defined(PNG_READ_pHYs_SUPPORTED)
  166011. PNG_CONST PNG_pHYs;
  166012. #endif
  166013. #if defined(PNG_READ_sBIT_SUPPORTED)
  166014. PNG_CONST PNG_sBIT;
  166015. #endif
  166016. #if defined(PNG_READ_sCAL_SUPPORTED)
  166017. PNG_CONST PNG_sCAL;
  166018. #endif
  166019. #if defined(PNG_READ_sRGB_SUPPORTED)
  166020. PNG_CONST PNG_sRGB;
  166021. #endif
  166022. #if defined(PNG_READ_sPLT_SUPPORTED)
  166023. PNG_CONST PNG_sPLT;
  166024. #endif
  166025. #if defined(PNG_READ_tEXt_SUPPORTED)
  166026. PNG_CONST PNG_tEXt;
  166027. #endif
  166028. #if defined(PNG_READ_tIME_SUPPORTED)
  166029. PNG_CONST PNG_tIME;
  166030. #endif
  166031. #if defined(PNG_READ_tRNS_SUPPORTED)
  166032. PNG_CONST PNG_tRNS;
  166033. #endif
  166034. #if defined(PNG_READ_zTXt_SUPPORTED)
  166035. PNG_CONST PNG_zTXt;
  166036. #endif
  166037. #endif /* PNG_USE_LOCAL_ARRAYS */
  166038. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166039. {
  166040. png_byte chunk_length[4];
  166041. if (png_ptr->buffer_size < 8)
  166042. {
  166043. png_push_save_buffer(png_ptr);
  166044. return;
  166045. }
  166046. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166047. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166048. png_reset_crc(png_ptr);
  166049. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166050. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166051. }
  166052. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166053. if(png_ptr->mode & PNG_AFTER_IDAT)
  166054. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  166055. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  166056. {
  166057. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166058. {
  166059. png_push_save_buffer(png_ptr);
  166060. return;
  166061. }
  166062. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  166063. }
  166064. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  166065. {
  166066. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166067. {
  166068. png_push_save_buffer(png_ptr);
  166069. return;
  166070. }
  166071. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  166072. png_ptr->process_mode = PNG_READ_DONE_MODE;
  166073. png_push_have_end(png_ptr, info_ptr);
  166074. }
  166075. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  166076. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  166077. {
  166078. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166079. {
  166080. png_push_save_buffer(png_ptr);
  166081. return;
  166082. }
  166083. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166084. png_ptr->mode |= PNG_HAVE_IDAT;
  166085. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166086. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166087. png_ptr->mode |= PNG_HAVE_PLTE;
  166088. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166089. {
  166090. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166091. png_error(png_ptr, "Missing IHDR before IDAT");
  166092. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166093. !(png_ptr->mode & PNG_HAVE_PLTE))
  166094. png_error(png_ptr, "Missing PLTE before IDAT");
  166095. }
  166096. }
  166097. #endif
  166098. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166099. {
  166100. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166101. {
  166102. png_push_save_buffer(png_ptr);
  166103. return;
  166104. }
  166105. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  166106. }
  166107. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166108. {
  166109. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166110. png_error(png_ptr, "Missing IHDR before IDAT");
  166111. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166112. !(png_ptr->mode & PNG_HAVE_PLTE))
  166113. png_error(png_ptr, "Missing PLTE before IDAT");
  166114. if (png_ptr->mode & PNG_HAVE_IDAT)
  166115. {
  166116. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  166117. if (png_ptr->push_length == 0)
  166118. return;
  166119. if (png_ptr->mode & PNG_AFTER_IDAT)
  166120. png_error(png_ptr, "Too many IDAT's found");
  166121. }
  166122. png_ptr->idat_size = png_ptr->push_length;
  166123. png_ptr->mode |= PNG_HAVE_IDAT;
  166124. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  166125. png_push_have_info(png_ptr, info_ptr);
  166126. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166127. png_ptr->zstream.next_out = png_ptr->row_buf;
  166128. return;
  166129. }
  166130. #if defined(PNG_READ_gAMA_SUPPORTED)
  166131. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  166132. {
  166133. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166134. {
  166135. png_push_save_buffer(png_ptr);
  166136. return;
  166137. }
  166138. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  166139. }
  166140. #endif
  166141. #if defined(PNG_READ_sBIT_SUPPORTED)
  166142. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  166143. {
  166144. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166145. {
  166146. png_push_save_buffer(png_ptr);
  166147. return;
  166148. }
  166149. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  166150. }
  166151. #endif
  166152. #if defined(PNG_READ_cHRM_SUPPORTED)
  166153. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  166154. {
  166155. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166156. {
  166157. png_push_save_buffer(png_ptr);
  166158. return;
  166159. }
  166160. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  166161. }
  166162. #endif
  166163. #if defined(PNG_READ_sRGB_SUPPORTED)
  166164. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  166165. {
  166166. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166167. {
  166168. png_push_save_buffer(png_ptr);
  166169. return;
  166170. }
  166171. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  166172. }
  166173. #endif
  166174. #if defined(PNG_READ_iCCP_SUPPORTED)
  166175. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  166176. {
  166177. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166178. {
  166179. png_push_save_buffer(png_ptr);
  166180. return;
  166181. }
  166182. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  166183. }
  166184. #endif
  166185. #if defined(PNG_READ_sPLT_SUPPORTED)
  166186. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  166187. {
  166188. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166189. {
  166190. png_push_save_buffer(png_ptr);
  166191. return;
  166192. }
  166193. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  166194. }
  166195. #endif
  166196. #if defined(PNG_READ_tRNS_SUPPORTED)
  166197. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  166198. {
  166199. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166200. {
  166201. png_push_save_buffer(png_ptr);
  166202. return;
  166203. }
  166204. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  166205. }
  166206. #endif
  166207. #if defined(PNG_READ_bKGD_SUPPORTED)
  166208. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  166209. {
  166210. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166211. {
  166212. png_push_save_buffer(png_ptr);
  166213. return;
  166214. }
  166215. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  166216. }
  166217. #endif
  166218. #if defined(PNG_READ_hIST_SUPPORTED)
  166219. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  166220. {
  166221. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166222. {
  166223. png_push_save_buffer(png_ptr);
  166224. return;
  166225. }
  166226. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  166227. }
  166228. #endif
  166229. #if defined(PNG_READ_pHYs_SUPPORTED)
  166230. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  166231. {
  166232. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166233. {
  166234. png_push_save_buffer(png_ptr);
  166235. return;
  166236. }
  166237. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  166238. }
  166239. #endif
  166240. #if defined(PNG_READ_oFFs_SUPPORTED)
  166241. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  166242. {
  166243. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166244. {
  166245. png_push_save_buffer(png_ptr);
  166246. return;
  166247. }
  166248. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  166249. }
  166250. #endif
  166251. #if defined(PNG_READ_pCAL_SUPPORTED)
  166252. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  166253. {
  166254. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166255. {
  166256. png_push_save_buffer(png_ptr);
  166257. return;
  166258. }
  166259. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  166260. }
  166261. #endif
  166262. #if defined(PNG_READ_sCAL_SUPPORTED)
  166263. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  166264. {
  166265. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166266. {
  166267. png_push_save_buffer(png_ptr);
  166268. return;
  166269. }
  166270. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  166271. }
  166272. #endif
  166273. #if defined(PNG_READ_tIME_SUPPORTED)
  166274. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  166275. {
  166276. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166277. {
  166278. png_push_save_buffer(png_ptr);
  166279. return;
  166280. }
  166281. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  166282. }
  166283. #endif
  166284. #if defined(PNG_READ_tEXt_SUPPORTED)
  166285. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  166286. {
  166287. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166288. {
  166289. png_push_save_buffer(png_ptr);
  166290. return;
  166291. }
  166292. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  166293. }
  166294. #endif
  166295. #if defined(PNG_READ_zTXt_SUPPORTED)
  166296. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  166297. {
  166298. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166299. {
  166300. png_push_save_buffer(png_ptr);
  166301. return;
  166302. }
  166303. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166304. }
  166305. #endif
  166306. #if defined(PNG_READ_iTXt_SUPPORTED)
  166307. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  166308. {
  166309. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166310. {
  166311. png_push_save_buffer(png_ptr);
  166312. return;
  166313. }
  166314. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166315. }
  166316. #endif
  166317. else
  166318. {
  166319. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166320. {
  166321. png_push_save_buffer(png_ptr);
  166322. return;
  166323. }
  166324. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166325. }
  166326. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166327. }
  166328. void /* PRIVATE */
  166329. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166330. {
  166331. png_ptr->process_mode = PNG_SKIP_MODE;
  166332. png_ptr->skip_length = skip;
  166333. }
  166334. void /* PRIVATE */
  166335. png_push_crc_finish(png_structp png_ptr)
  166336. {
  166337. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166338. {
  166339. png_size_t save_size;
  166340. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166341. save_size = (png_size_t)png_ptr->skip_length;
  166342. else
  166343. save_size = png_ptr->save_buffer_size;
  166344. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166345. png_ptr->skip_length -= save_size;
  166346. png_ptr->buffer_size -= save_size;
  166347. png_ptr->save_buffer_size -= save_size;
  166348. png_ptr->save_buffer_ptr += save_size;
  166349. }
  166350. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166351. {
  166352. png_size_t save_size;
  166353. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166354. save_size = (png_size_t)png_ptr->skip_length;
  166355. else
  166356. save_size = png_ptr->current_buffer_size;
  166357. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166358. png_ptr->skip_length -= save_size;
  166359. png_ptr->buffer_size -= save_size;
  166360. png_ptr->current_buffer_size -= save_size;
  166361. png_ptr->current_buffer_ptr += save_size;
  166362. }
  166363. if (!png_ptr->skip_length)
  166364. {
  166365. if (png_ptr->buffer_size < 4)
  166366. {
  166367. png_push_save_buffer(png_ptr);
  166368. return;
  166369. }
  166370. png_crc_finish(png_ptr, 0);
  166371. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166372. }
  166373. }
  166374. void PNGAPI
  166375. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166376. {
  166377. png_bytep ptr;
  166378. if(png_ptr == NULL) return;
  166379. ptr = buffer;
  166380. if (png_ptr->save_buffer_size)
  166381. {
  166382. png_size_t save_size;
  166383. if (length < png_ptr->save_buffer_size)
  166384. save_size = length;
  166385. else
  166386. save_size = png_ptr->save_buffer_size;
  166387. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166388. length -= save_size;
  166389. ptr += save_size;
  166390. png_ptr->buffer_size -= save_size;
  166391. png_ptr->save_buffer_size -= save_size;
  166392. png_ptr->save_buffer_ptr += save_size;
  166393. }
  166394. if (length && png_ptr->current_buffer_size)
  166395. {
  166396. png_size_t save_size;
  166397. if (length < png_ptr->current_buffer_size)
  166398. save_size = length;
  166399. else
  166400. save_size = png_ptr->current_buffer_size;
  166401. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166402. png_ptr->buffer_size -= save_size;
  166403. png_ptr->current_buffer_size -= save_size;
  166404. png_ptr->current_buffer_ptr += save_size;
  166405. }
  166406. }
  166407. void /* PRIVATE */
  166408. png_push_save_buffer(png_structp png_ptr)
  166409. {
  166410. if (png_ptr->save_buffer_size)
  166411. {
  166412. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166413. {
  166414. png_size_t i,istop;
  166415. png_bytep sp;
  166416. png_bytep dp;
  166417. istop = png_ptr->save_buffer_size;
  166418. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166419. i < istop; i++, sp++, dp++)
  166420. {
  166421. *dp = *sp;
  166422. }
  166423. }
  166424. }
  166425. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166426. png_ptr->save_buffer_max)
  166427. {
  166428. png_size_t new_max;
  166429. png_bytep old_buffer;
  166430. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166431. (png_ptr->current_buffer_size + 256))
  166432. {
  166433. png_error(png_ptr, "Potential overflow of save_buffer");
  166434. }
  166435. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166436. old_buffer = png_ptr->save_buffer;
  166437. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166438. (png_uint_32)new_max);
  166439. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166440. png_free(png_ptr, old_buffer);
  166441. png_ptr->save_buffer_max = new_max;
  166442. }
  166443. if (png_ptr->current_buffer_size)
  166444. {
  166445. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166446. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166447. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166448. png_ptr->current_buffer_size = 0;
  166449. }
  166450. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166451. png_ptr->buffer_size = 0;
  166452. }
  166453. void /* PRIVATE */
  166454. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166455. png_size_t buffer_length)
  166456. {
  166457. png_ptr->current_buffer = buffer;
  166458. png_ptr->current_buffer_size = buffer_length;
  166459. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166460. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166461. }
  166462. void /* PRIVATE */
  166463. png_push_read_IDAT(png_structp png_ptr)
  166464. {
  166465. #ifdef PNG_USE_LOCAL_ARRAYS
  166466. PNG_CONST PNG_IDAT;
  166467. #endif
  166468. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166469. {
  166470. png_byte chunk_length[4];
  166471. if (png_ptr->buffer_size < 8)
  166472. {
  166473. png_push_save_buffer(png_ptr);
  166474. return;
  166475. }
  166476. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166477. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166478. png_reset_crc(png_ptr);
  166479. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166480. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166481. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166482. {
  166483. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166484. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166485. png_error(png_ptr, "Not enough compressed data");
  166486. return;
  166487. }
  166488. png_ptr->idat_size = png_ptr->push_length;
  166489. }
  166490. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166491. {
  166492. png_size_t save_size;
  166493. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166494. {
  166495. save_size = (png_size_t)png_ptr->idat_size;
  166496. if((png_uint_32)save_size != png_ptr->idat_size)
  166497. png_error(png_ptr, "save_size overflowed in pngpread");
  166498. }
  166499. else
  166500. save_size = png_ptr->save_buffer_size;
  166501. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166502. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166503. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166504. png_ptr->idat_size -= save_size;
  166505. png_ptr->buffer_size -= save_size;
  166506. png_ptr->save_buffer_size -= save_size;
  166507. png_ptr->save_buffer_ptr += save_size;
  166508. }
  166509. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166510. {
  166511. png_size_t save_size;
  166512. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166513. {
  166514. save_size = (png_size_t)png_ptr->idat_size;
  166515. if((png_uint_32)save_size != png_ptr->idat_size)
  166516. png_error(png_ptr, "save_size overflowed in pngpread");
  166517. }
  166518. else
  166519. save_size = png_ptr->current_buffer_size;
  166520. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166521. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166522. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166523. png_ptr->idat_size -= save_size;
  166524. png_ptr->buffer_size -= save_size;
  166525. png_ptr->current_buffer_size -= save_size;
  166526. png_ptr->current_buffer_ptr += save_size;
  166527. }
  166528. if (!png_ptr->idat_size)
  166529. {
  166530. if (png_ptr->buffer_size < 4)
  166531. {
  166532. png_push_save_buffer(png_ptr);
  166533. return;
  166534. }
  166535. png_crc_finish(png_ptr, 0);
  166536. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166537. png_ptr->mode |= PNG_AFTER_IDAT;
  166538. }
  166539. }
  166540. void /* PRIVATE */
  166541. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166542. png_size_t buffer_length)
  166543. {
  166544. int ret;
  166545. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166546. png_error(png_ptr, "Extra compression data");
  166547. png_ptr->zstream.next_in = buffer;
  166548. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166549. for(;;)
  166550. {
  166551. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166552. if (ret != Z_OK)
  166553. {
  166554. if (ret == Z_STREAM_END)
  166555. {
  166556. if (png_ptr->zstream.avail_in)
  166557. png_error(png_ptr, "Extra compressed data");
  166558. if (!(png_ptr->zstream.avail_out))
  166559. {
  166560. png_push_process_row(png_ptr);
  166561. }
  166562. png_ptr->mode |= PNG_AFTER_IDAT;
  166563. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166564. break;
  166565. }
  166566. else if (ret == Z_BUF_ERROR)
  166567. break;
  166568. else
  166569. png_error(png_ptr, "Decompression Error");
  166570. }
  166571. if (!(png_ptr->zstream.avail_out))
  166572. {
  166573. if ((
  166574. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166575. png_ptr->interlaced && png_ptr->pass > 6) ||
  166576. (!png_ptr->interlaced &&
  166577. #endif
  166578. png_ptr->row_number == png_ptr->num_rows))
  166579. {
  166580. if (png_ptr->zstream.avail_in)
  166581. {
  166582. png_warning(png_ptr, "Too much data in IDAT chunks");
  166583. }
  166584. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166585. break;
  166586. }
  166587. png_push_process_row(png_ptr);
  166588. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166589. png_ptr->zstream.next_out = png_ptr->row_buf;
  166590. }
  166591. else
  166592. break;
  166593. }
  166594. }
  166595. void /* PRIVATE */
  166596. png_push_process_row(png_structp png_ptr)
  166597. {
  166598. png_ptr->row_info.color_type = png_ptr->color_type;
  166599. png_ptr->row_info.width = png_ptr->iwidth;
  166600. png_ptr->row_info.channels = png_ptr->channels;
  166601. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166602. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166603. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166604. png_ptr->row_info.width);
  166605. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166606. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166607. (int)(png_ptr->row_buf[0]));
  166608. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166609. png_ptr->rowbytes + 1);
  166610. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166611. png_do_read_transformations(png_ptr);
  166612. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166613. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166614. {
  166615. if (png_ptr->pass < 6)
  166616. png_do_read_interlace(png_ptr);
  166617. switch (png_ptr->pass)
  166618. {
  166619. case 0:
  166620. {
  166621. int i;
  166622. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166623. {
  166624. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166625. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166626. }
  166627. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166628. {
  166629. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166630. {
  166631. png_push_have_row(png_ptr, png_bytep_NULL);
  166632. png_read_push_finish_row(png_ptr);
  166633. }
  166634. }
  166635. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166636. {
  166637. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166638. {
  166639. png_push_have_row(png_ptr, png_bytep_NULL);
  166640. png_read_push_finish_row(png_ptr);
  166641. }
  166642. }
  166643. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166644. {
  166645. png_push_have_row(png_ptr, png_bytep_NULL);
  166646. png_read_push_finish_row(png_ptr);
  166647. }
  166648. break;
  166649. }
  166650. case 1:
  166651. {
  166652. int i;
  166653. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166654. {
  166655. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166656. png_read_push_finish_row(png_ptr);
  166657. }
  166658. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166659. {
  166660. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166661. {
  166662. png_push_have_row(png_ptr, png_bytep_NULL);
  166663. png_read_push_finish_row(png_ptr);
  166664. }
  166665. }
  166666. break;
  166667. }
  166668. case 2:
  166669. {
  166670. int i;
  166671. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166672. {
  166673. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166674. png_read_push_finish_row(png_ptr);
  166675. }
  166676. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166677. {
  166678. png_push_have_row(png_ptr, png_bytep_NULL);
  166679. png_read_push_finish_row(png_ptr);
  166680. }
  166681. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166682. {
  166683. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166684. {
  166685. png_push_have_row(png_ptr, png_bytep_NULL);
  166686. png_read_push_finish_row(png_ptr);
  166687. }
  166688. }
  166689. break;
  166690. }
  166691. case 3:
  166692. {
  166693. int i;
  166694. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166695. {
  166696. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166697. png_read_push_finish_row(png_ptr);
  166698. }
  166699. if (png_ptr->pass == 4) /* skip top two generated rows */
  166700. {
  166701. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166702. {
  166703. png_push_have_row(png_ptr, png_bytep_NULL);
  166704. png_read_push_finish_row(png_ptr);
  166705. }
  166706. }
  166707. break;
  166708. }
  166709. case 4:
  166710. {
  166711. int i;
  166712. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166713. {
  166714. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166715. png_read_push_finish_row(png_ptr);
  166716. }
  166717. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166718. {
  166719. png_push_have_row(png_ptr, png_bytep_NULL);
  166720. png_read_push_finish_row(png_ptr);
  166721. }
  166722. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166723. {
  166724. png_push_have_row(png_ptr, png_bytep_NULL);
  166725. png_read_push_finish_row(png_ptr);
  166726. }
  166727. break;
  166728. }
  166729. case 5:
  166730. {
  166731. int i;
  166732. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166733. {
  166734. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166735. png_read_push_finish_row(png_ptr);
  166736. }
  166737. if (png_ptr->pass == 6) /* skip top generated row */
  166738. {
  166739. png_push_have_row(png_ptr, png_bytep_NULL);
  166740. png_read_push_finish_row(png_ptr);
  166741. }
  166742. break;
  166743. }
  166744. case 6:
  166745. {
  166746. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166747. png_read_push_finish_row(png_ptr);
  166748. if (png_ptr->pass != 6)
  166749. break;
  166750. png_push_have_row(png_ptr, png_bytep_NULL);
  166751. png_read_push_finish_row(png_ptr);
  166752. }
  166753. }
  166754. }
  166755. else
  166756. #endif
  166757. {
  166758. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166759. png_read_push_finish_row(png_ptr);
  166760. }
  166761. }
  166762. void /* PRIVATE */
  166763. png_read_push_finish_row(png_structp png_ptr)
  166764. {
  166765. #ifdef PNG_USE_LOCAL_ARRAYS
  166766. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166767. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166768. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166769. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166770. #endif
  166771. png_ptr->row_number++;
  166772. if (png_ptr->row_number < png_ptr->num_rows)
  166773. return;
  166774. if (png_ptr->interlaced)
  166775. {
  166776. png_ptr->row_number = 0;
  166777. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166778. png_ptr->rowbytes + 1);
  166779. do
  166780. {
  166781. png_ptr->pass++;
  166782. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166783. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166784. (png_ptr->pass == 5 && png_ptr->width < 2))
  166785. png_ptr->pass++;
  166786. if (png_ptr->pass > 7)
  166787. png_ptr->pass--;
  166788. if (png_ptr->pass >= 7)
  166789. break;
  166790. png_ptr->iwidth = (png_ptr->width +
  166791. png_pass_inc[png_ptr->pass] - 1 -
  166792. png_pass_start[png_ptr->pass]) /
  166793. png_pass_inc[png_ptr->pass];
  166794. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166795. png_ptr->iwidth) + 1;
  166796. if (png_ptr->transformations & PNG_INTERLACE)
  166797. break;
  166798. png_ptr->num_rows = (png_ptr->height +
  166799. png_pass_yinc[png_ptr->pass] - 1 -
  166800. png_pass_ystart[png_ptr->pass]) /
  166801. png_pass_yinc[png_ptr->pass];
  166802. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166803. }
  166804. }
  166805. #if defined(PNG_READ_tEXt_SUPPORTED)
  166806. void /* PRIVATE */
  166807. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166808. length)
  166809. {
  166810. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166811. {
  166812. png_error(png_ptr, "Out of place tEXt");
  166813. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166814. }
  166815. #ifdef PNG_MAX_MALLOC_64K
  166816. png_ptr->skip_length = 0; /* This may not be necessary */
  166817. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166818. {
  166819. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166820. png_ptr->skip_length = length - (png_uint_32)65535L;
  166821. length = (png_uint_32)65535L;
  166822. }
  166823. #endif
  166824. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166825. (png_uint_32)(length+1));
  166826. png_ptr->current_text[length] = '\0';
  166827. png_ptr->current_text_ptr = png_ptr->current_text;
  166828. png_ptr->current_text_size = (png_size_t)length;
  166829. png_ptr->current_text_left = (png_size_t)length;
  166830. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166831. }
  166832. void /* PRIVATE */
  166833. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166834. {
  166835. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166836. {
  166837. png_size_t text_size;
  166838. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166839. text_size = png_ptr->buffer_size;
  166840. else
  166841. text_size = png_ptr->current_text_left;
  166842. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166843. png_ptr->current_text_left -= text_size;
  166844. png_ptr->current_text_ptr += text_size;
  166845. }
  166846. if (!(png_ptr->current_text_left))
  166847. {
  166848. png_textp text_ptr;
  166849. png_charp text;
  166850. png_charp key;
  166851. int ret;
  166852. if (png_ptr->buffer_size < 4)
  166853. {
  166854. png_push_save_buffer(png_ptr);
  166855. return;
  166856. }
  166857. png_push_crc_finish(png_ptr);
  166858. #if defined(PNG_MAX_MALLOC_64K)
  166859. if (png_ptr->skip_length)
  166860. return;
  166861. #endif
  166862. key = png_ptr->current_text;
  166863. for (text = key; *text; text++)
  166864. ;
  166865. if (text < key + png_ptr->current_text_size)
  166866. text++;
  166867. text_ptr = (png_textp)png_malloc(png_ptr,
  166868. (png_uint_32)png_sizeof(png_text));
  166869. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166870. text_ptr->key = key;
  166871. #ifdef PNG_iTXt_SUPPORTED
  166872. text_ptr->lang = NULL;
  166873. text_ptr->lang_key = NULL;
  166874. #endif
  166875. text_ptr->text = text;
  166876. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166877. png_free(png_ptr, key);
  166878. png_free(png_ptr, text_ptr);
  166879. png_ptr->current_text = NULL;
  166880. if (ret)
  166881. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166882. }
  166883. }
  166884. #endif
  166885. #if defined(PNG_READ_zTXt_SUPPORTED)
  166886. void /* PRIVATE */
  166887. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166888. length)
  166889. {
  166890. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166891. {
  166892. png_error(png_ptr, "Out of place zTXt");
  166893. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166894. }
  166895. #ifdef PNG_MAX_MALLOC_64K
  166896. if (length > (png_uint_32)65535L)
  166897. {
  166898. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166899. png_push_crc_skip(png_ptr, length);
  166900. return;
  166901. }
  166902. #endif
  166903. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166904. (png_uint_32)(length+1));
  166905. png_ptr->current_text[length] = '\0';
  166906. png_ptr->current_text_ptr = png_ptr->current_text;
  166907. png_ptr->current_text_size = (png_size_t)length;
  166908. png_ptr->current_text_left = (png_size_t)length;
  166909. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166910. }
  166911. void /* PRIVATE */
  166912. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166913. {
  166914. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166915. {
  166916. png_size_t text_size;
  166917. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166918. text_size = png_ptr->buffer_size;
  166919. else
  166920. text_size = png_ptr->current_text_left;
  166921. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166922. png_ptr->current_text_left -= text_size;
  166923. png_ptr->current_text_ptr += text_size;
  166924. }
  166925. if (!(png_ptr->current_text_left))
  166926. {
  166927. png_textp text_ptr;
  166928. png_charp text;
  166929. png_charp key;
  166930. int ret;
  166931. png_size_t text_size, key_size;
  166932. if (png_ptr->buffer_size < 4)
  166933. {
  166934. png_push_save_buffer(png_ptr);
  166935. return;
  166936. }
  166937. png_push_crc_finish(png_ptr);
  166938. key = png_ptr->current_text;
  166939. for (text = key; *text; text++)
  166940. ;
  166941. if (text >= key + png_ptr->current_text_size)
  166942. {
  166943. png_ptr->current_text = NULL;
  166944. png_free(png_ptr, key);
  166945. return;
  166946. }
  166947. text++;
  166948. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166949. {
  166950. png_ptr->current_text = NULL;
  166951. png_free(png_ptr, key);
  166952. return;
  166953. }
  166954. text++;
  166955. png_ptr->zstream.next_in = (png_bytep )text;
  166956. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166957. (text - key));
  166958. png_ptr->zstream.next_out = png_ptr->zbuf;
  166959. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166960. key_size = text - key;
  166961. text_size = 0;
  166962. text = NULL;
  166963. ret = Z_STREAM_END;
  166964. while (png_ptr->zstream.avail_in)
  166965. {
  166966. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166967. if (ret != Z_OK && ret != Z_STREAM_END)
  166968. {
  166969. inflateReset(&png_ptr->zstream);
  166970. png_ptr->zstream.avail_in = 0;
  166971. png_ptr->current_text = NULL;
  166972. png_free(png_ptr, key);
  166973. png_free(png_ptr, text);
  166974. return;
  166975. }
  166976. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166977. {
  166978. if (text == NULL)
  166979. {
  166980. text = (png_charp)png_malloc(png_ptr,
  166981. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166982. + key_size + 1));
  166983. png_memcpy(text + key_size, png_ptr->zbuf,
  166984. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166985. png_memcpy(text, key, key_size);
  166986. text_size = key_size + png_ptr->zbuf_size -
  166987. png_ptr->zstream.avail_out;
  166988. *(text + text_size) = '\0';
  166989. }
  166990. else
  166991. {
  166992. png_charp tmp;
  166993. tmp = text;
  166994. text = (png_charp)png_malloc(png_ptr, text_size +
  166995. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166996. + 1));
  166997. png_memcpy(text, tmp, text_size);
  166998. png_free(png_ptr, tmp);
  166999. png_memcpy(text + text_size, png_ptr->zbuf,
  167000. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167001. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  167002. *(text + text_size) = '\0';
  167003. }
  167004. if (ret != Z_STREAM_END)
  167005. {
  167006. png_ptr->zstream.next_out = png_ptr->zbuf;
  167007. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167008. }
  167009. }
  167010. else
  167011. {
  167012. break;
  167013. }
  167014. if (ret == Z_STREAM_END)
  167015. break;
  167016. }
  167017. inflateReset(&png_ptr->zstream);
  167018. png_ptr->zstream.avail_in = 0;
  167019. if (ret != Z_STREAM_END)
  167020. {
  167021. png_ptr->current_text = NULL;
  167022. png_free(png_ptr, key);
  167023. png_free(png_ptr, text);
  167024. return;
  167025. }
  167026. png_ptr->current_text = NULL;
  167027. png_free(png_ptr, key);
  167028. key = text;
  167029. text += key_size;
  167030. text_ptr = (png_textp)png_malloc(png_ptr,
  167031. (png_uint_32)png_sizeof(png_text));
  167032. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  167033. text_ptr->key = key;
  167034. #ifdef PNG_iTXt_SUPPORTED
  167035. text_ptr->lang = NULL;
  167036. text_ptr->lang_key = NULL;
  167037. #endif
  167038. text_ptr->text = text;
  167039. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167040. png_free(png_ptr, key);
  167041. png_free(png_ptr, text_ptr);
  167042. if (ret)
  167043. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  167044. }
  167045. }
  167046. #endif
  167047. #if defined(PNG_READ_iTXt_SUPPORTED)
  167048. void /* PRIVATE */
  167049. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167050. length)
  167051. {
  167052. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167053. {
  167054. png_error(png_ptr, "Out of place iTXt");
  167055. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167056. }
  167057. #ifdef PNG_MAX_MALLOC_64K
  167058. png_ptr->skip_length = 0; /* This may not be necessary */
  167059. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167060. {
  167061. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  167062. png_ptr->skip_length = length - (png_uint_32)65535L;
  167063. length = (png_uint_32)65535L;
  167064. }
  167065. #endif
  167066. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167067. (png_uint_32)(length+1));
  167068. png_ptr->current_text[length] = '\0';
  167069. png_ptr->current_text_ptr = png_ptr->current_text;
  167070. png_ptr->current_text_size = (png_size_t)length;
  167071. png_ptr->current_text_left = (png_size_t)length;
  167072. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  167073. }
  167074. void /* PRIVATE */
  167075. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  167076. {
  167077. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167078. {
  167079. png_size_t text_size;
  167080. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167081. text_size = png_ptr->buffer_size;
  167082. else
  167083. text_size = png_ptr->current_text_left;
  167084. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167085. png_ptr->current_text_left -= text_size;
  167086. png_ptr->current_text_ptr += text_size;
  167087. }
  167088. if (!(png_ptr->current_text_left))
  167089. {
  167090. png_textp text_ptr;
  167091. png_charp key;
  167092. int comp_flag;
  167093. png_charp lang;
  167094. png_charp lang_key;
  167095. png_charp text;
  167096. int ret;
  167097. if (png_ptr->buffer_size < 4)
  167098. {
  167099. png_push_save_buffer(png_ptr);
  167100. return;
  167101. }
  167102. png_push_crc_finish(png_ptr);
  167103. #if defined(PNG_MAX_MALLOC_64K)
  167104. if (png_ptr->skip_length)
  167105. return;
  167106. #endif
  167107. key = png_ptr->current_text;
  167108. for (lang = key; *lang; lang++)
  167109. ;
  167110. if (lang < key + png_ptr->current_text_size - 3)
  167111. lang++;
  167112. comp_flag = *lang++;
  167113. lang++; /* skip comp_type, always zero */
  167114. for (lang_key = lang; *lang_key; lang_key++)
  167115. ;
  167116. lang_key++; /* skip NUL separator */
  167117. text=lang_key;
  167118. if (lang_key < key + png_ptr->current_text_size - 1)
  167119. {
  167120. for (; *text; text++)
  167121. ;
  167122. }
  167123. if (text < key + png_ptr->current_text_size)
  167124. text++;
  167125. text_ptr = (png_textp)png_malloc(png_ptr,
  167126. (png_uint_32)png_sizeof(png_text));
  167127. text_ptr->compression = comp_flag + 2;
  167128. text_ptr->key = key;
  167129. text_ptr->lang = lang;
  167130. text_ptr->lang_key = lang_key;
  167131. text_ptr->text = text;
  167132. text_ptr->text_length = 0;
  167133. text_ptr->itxt_length = png_strlen(text);
  167134. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167135. png_ptr->current_text = NULL;
  167136. png_free(png_ptr, text_ptr);
  167137. if (ret)
  167138. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  167139. }
  167140. }
  167141. #endif
  167142. void /* PRIVATE */
  167143. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167144. length)
  167145. {
  167146. png_uint_32 skip=0;
  167147. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  167148. if (!(png_ptr->chunk_name[0] & 0x20))
  167149. {
  167150. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167151. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167152. PNG_HANDLE_CHUNK_ALWAYS
  167153. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167154. && png_ptr->read_user_chunk_fn == NULL
  167155. #endif
  167156. )
  167157. #endif
  167158. png_chunk_error(png_ptr, "unknown critical chunk");
  167159. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167160. }
  167161. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167162. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  167163. {
  167164. #ifdef PNG_MAX_MALLOC_64K
  167165. if (length > (png_uint_32)65535L)
  167166. {
  167167. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  167168. skip = length - (png_uint_32)65535L;
  167169. length = (png_uint_32)65535L;
  167170. }
  167171. #endif
  167172. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  167173. (png_charp)png_ptr->chunk_name, 5);
  167174. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  167175. png_ptr->unknown_chunk.size = (png_size_t)length;
  167176. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  167177. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167178. if(png_ptr->read_user_chunk_fn != NULL)
  167179. {
  167180. int ret;
  167181. ret = (*(png_ptr->read_user_chunk_fn))
  167182. (png_ptr, &png_ptr->unknown_chunk);
  167183. if (ret < 0)
  167184. png_chunk_error(png_ptr, "error in user chunk");
  167185. if (ret == 0)
  167186. {
  167187. if (!(png_ptr->chunk_name[0] & 0x20))
  167188. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167189. PNG_HANDLE_CHUNK_ALWAYS)
  167190. png_chunk_error(png_ptr, "unknown critical chunk");
  167191. png_set_unknown_chunks(png_ptr, info_ptr,
  167192. &png_ptr->unknown_chunk, 1);
  167193. }
  167194. }
  167195. #else
  167196. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  167197. #endif
  167198. png_free(png_ptr, png_ptr->unknown_chunk.data);
  167199. png_ptr->unknown_chunk.data = NULL;
  167200. }
  167201. else
  167202. #endif
  167203. skip=length;
  167204. png_push_crc_skip(png_ptr, skip);
  167205. }
  167206. void /* PRIVATE */
  167207. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  167208. {
  167209. if (png_ptr->info_fn != NULL)
  167210. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  167211. }
  167212. void /* PRIVATE */
  167213. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  167214. {
  167215. if (png_ptr->end_fn != NULL)
  167216. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  167217. }
  167218. void /* PRIVATE */
  167219. png_push_have_row(png_structp png_ptr, png_bytep row)
  167220. {
  167221. if (png_ptr->row_fn != NULL)
  167222. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  167223. (int)png_ptr->pass);
  167224. }
  167225. void PNGAPI
  167226. png_progressive_combine_row (png_structp png_ptr,
  167227. png_bytep old_row, png_bytep new_row)
  167228. {
  167229. #ifdef PNG_USE_LOCAL_ARRAYS
  167230. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  167231. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  167232. #endif
  167233. if(png_ptr == NULL) return;
  167234. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  167235. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  167236. }
  167237. void PNGAPI
  167238. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  167239. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  167240. png_progressive_end_ptr end_fn)
  167241. {
  167242. if(png_ptr == NULL) return;
  167243. png_ptr->info_fn = info_fn;
  167244. png_ptr->row_fn = row_fn;
  167245. png_ptr->end_fn = end_fn;
  167246. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  167247. }
  167248. png_voidp PNGAPI
  167249. png_get_progressive_ptr(png_structp png_ptr)
  167250. {
  167251. if(png_ptr == NULL) return (NULL);
  167252. return png_ptr->io_ptr;
  167253. }
  167254. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  167255. /*** End of inlined file: pngpread.c ***/
  167256. /*** Start of inlined file: pngrio.c ***/
  167257. #define PNG_INTERNAL
  167258. #if defined(PNG_READ_SUPPORTED)
  167259. void /* PRIVATE */
  167260. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167261. {
  167262. png_debug1(4,"reading %d bytes\n", (int)length);
  167263. if (png_ptr->read_data_fn != NULL)
  167264. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  167265. else
  167266. png_error(png_ptr, "Call to NULL read function");
  167267. }
  167268. #if !defined(PNG_NO_STDIO)
  167269. #ifndef USE_FAR_KEYWORD
  167270. void PNGAPI
  167271. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167272. {
  167273. png_size_t check;
  167274. if(png_ptr == NULL) return;
  167275. #if defined(_WIN32_WCE)
  167276. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167277. check = 0;
  167278. #else
  167279. check = (png_size_t)fread(data, (png_size_t)1, length,
  167280. (png_FILE_p)png_ptr->io_ptr);
  167281. #endif
  167282. if (check != length)
  167283. png_error(png_ptr, "Read Error");
  167284. }
  167285. #else
  167286. #define NEAR_BUF_SIZE 1024
  167287. #define MIN(a,b) (a <= b ? a : b)
  167288. static void PNGAPI
  167289. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167290. {
  167291. int check;
  167292. png_byte *n_data;
  167293. png_FILE_p io_ptr;
  167294. if(png_ptr == NULL) return;
  167295. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  167296. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  167297. if ((png_bytep)n_data == data)
  167298. {
  167299. #if defined(_WIN32_WCE)
  167300. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167301. check = 0;
  167302. #else
  167303. check = fread(n_data, 1, length, io_ptr);
  167304. #endif
  167305. }
  167306. else
  167307. {
  167308. png_byte buf[NEAR_BUF_SIZE];
  167309. png_size_t read, remaining, err;
  167310. check = 0;
  167311. remaining = length;
  167312. do
  167313. {
  167314. read = MIN(NEAR_BUF_SIZE, remaining);
  167315. #if defined(_WIN32_WCE)
  167316. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167317. err = 0;
  167318. #else
  167319. err = fread(buf, (png_size_t)1, read, io_ptr);
  167320. #endif
  167321. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167322. if(err != read)
  167323. break;
  167324. else
  167325. check += err;
  167326. data += read;
  167327. remaining -= read;
  167328. }
  167329. while (remaining != 0);
  167330. }
  167331. if ((png_uint_32)check != (png_uint_32)length)
  167332. png_error(png_ptr, "read Error");
  167333. }
  167334. #endif
  167335. #endif
  167336. void PNGAPI
  167337. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167338. png_rw_ptr read_data_fn)
  167339. {
  167340. if(png_ptr == NULL) return;
  167341. png_ptr->io_ptr = io_ptr;
  167342. #if !defined(PNG_NO_STDIO)
  167343. if (read_data_fn != NULL)
  167344. png_ptr->read_data_fn = read_data_fn;
  167345. else
  167346. png_ptr->read_data_fn = png_default_read_data;
  167347. #else
  167348. png_ptr->read_data_fn = read_data_fn;
  167349. #endif
  167350. if (png_ptr->write_data_fn != NULL)
  167351. {
  167352. png_ptr->write_data_fn = NULL;
  167353. png_warning(png_ptr,
  167354. "It's an error to set both read_data_fn and write_data_fn in the ");
  167355. png_warning(png_ptr,
  167356. "same structure. Resetting write_data_fn to NULL.");
  167357. }
  167358. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167359. png_ptr->output_flush_fn = NULL;
  167360. #endif
  167361. }
  167362. #endif /* PNG_READ_SUPPORTED */
  167363. /*** End of inlined file: pngrio.c ***/
  167364. /*** Start of inlined file: pngrtran.c ***/
  167365. #define PNG_INTERNAL
  167366. #if defined(PNG_READ_SUPPORTED)
  167367. void PNGAPI
  167368. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167369. {
  167370. png_debug(1, "in png_set_crc_action\n");
  167371. if(png_ptr == NULL) return;
  167372. switch (crit_action)
  167373. {
  167374. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167375. break;
  167376. case PNG_CRC_WARN_USE: /* warn/use data */
  167377. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167378. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167379. break;
  167380. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167381. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167382. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167383. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167384. break;
  167385. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167386. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167387. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167388. case PNG_CRC_DEFAULT:
  167389. default:
  167390. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167391. break;
  167392. }
  167393. switch (ancil_action)
  167394. {
  167395. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167396. break;
  167397. case PNG_CRC_WARN_USE: /* warn/use data */
  167398. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167399. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167400. break;
  167401. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167402. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167403. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167404. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167405. break;
  167406. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167407. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167408. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167409. break;
  167410. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167411. case PNG_CRC_DEFAULT:
  167412. default:
  167413. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167414. break;
  167415. }
  167416. }
  167417. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167418. defined(PNG_FLOATING_POINT_SUPPORTED)
  167419. void PNGAPI
  167420. png_set_background(png_structp png_ptr,
  167421. png_color_16p background_color, int background_gamma_code,
  167422. int need_expand, double background_gamma)
  167423. {
  167424. png_debug(1, "in png_set_background\n");
  167425. if(png_ptr == NULL) return;
  167426. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167427. {
  167428. png_warning(png_ptr, "Application must supply a known background gamma");
  167429. return;
  167430. }
  167431. png_ptr->transformations |= PNG_BACKGROUND;
  167432. png_memcpy(&(png_ptr->background), background_color,
  167433. png_sizeof(png_color_16));
  167434. png_ptr->background_gamma = (float)background_gamma;
  167435. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167436. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167437. }
  167438. #endif
  167439. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167440. void PNGAPI
  167441. png_set_strip_16(png_structp png_ptr)
  167442. {
  167443. png_debug(1, "in png_set_strip_16\n");
  167444. if(png_ptr == NULL) return;
  167445. png_ptr->transformations |= PNG_16_TO_8;
  167446. }
  167447. #endif
  167448. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167449. void PNGAPI
  167450. png_set_strip_alpha(png_structp png_ptr)
  167451. {
  167452. png_debug(1, "in png_set_strip_alpha\n");
  167453. if(png_ptr == NULL) return;
  167454. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167455. }
  167456. #endif
  167457. #if defined(PNG_READ_DITHER_SUPPORTED)
  167458. typedef struct png_dsort_struct
  167459. {
  167460. struct png_dsort_struct FAR * next;
  167461. png_byte left;
  167462. png_byte right;
  167463. } png_dsort;
  167464. typedef png_dsort FAR * png_dsortp;
  167465. typedef png_dsort FAR * FAR * png_dsortpp;
  167466. void PNGAPI
  167467. png_set_dither(png_structp png_ptr, png_colorp palette,
  167468. int num_palette, int maximum_colors, png_uint_16p histogram,
  167469. int full_dither)
  167470. {
  167471. png_debug(1, "in png_set_dither\n");
  167472. if(png_ptr == NULL) return;
  167473. png_ptr->transformations |= PNG_DITHER;
  167474. if (!full_dither)
  167475. {
  167476. int i;
  167477. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167478. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167479. for (i = 0; i < num_palette; i++)
  167480. png_ptr->dither_index[i] = (png_byte)i;
  167481. }
  167482. if (num_palette > maximum_colors)
  167483. {
  167484. if (histogram != NULL)
  167485. {
  167486. int i;
  167487. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167488. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167489. for (i = 0; i < num_palette; i++)
  167490. png_ptr->dither_sort[i] = (png_byte)i;
  167491. for (i = num_palette - 1; i >= maximum_colors; i--)
  167492. {
  167493. int done; /* to stop early if the list is pre-sorted */
  167494. int j;
  167495. done = 1;
  167496. for (j = 0; j < i; j++)
  167497. {
  167498. if (histogram[png_ptr->dither_sort[j]]
  167499. < histogram[png_ptr->dither_sort[j + 1]])
  167500. {
  167501. png_byte t;
  167502. t = png_ptr->dither_sort[j];
  167503. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167504. png_ptr->dither_sort[j + 1] = t;
  167505. done = 0;
  167506. }
  167507. }
  167508. if (done)
  167509. break;
  167510. }
  167511. if (full_dither)
  167512. {
  167513. int j = num_palette;
  167514. for (i = 0; i < maximum_colors; i++)
  167515. {
  167516. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167517. {
  167518. do
  167519. j--;
  167520. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167521. palette[i] = palette[j];
  167522. }
  167523. }
  167524. }
  167525. else
  167526. {
  167527. int j = num_palette;
  167528. for (i = 0; i < maximum_colors; i++)
  167529. {
  167530. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167531. {
  167532. png_color tmp_color;
  167533. do
  167534. j--;
  167535. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167536. tmp_color = palette[j];
  167537. palette[j] = palette[i];
  167538. palette[i] = tmp_color;
  167539. png_ptr->dither_index[j] = (png_byte)i;
  167540. png_ptr->dither_index[i] = (png_byte)j;
  167541. }
  167542. }
  167543. for (i = 0; i < num_palette; i++)
  167544. {
  167545. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167546. {
  167547. int min_d, k, min_k, d_index;
  167548. d_index = png_ptr->dither_index[i];
  167549. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167550. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167551. {
  167552. int d;
  167553. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167554. if (d < min_d)
  167555. {
  167556. min_d = d;
  167557. min_k = k;
  167558. }
  167559. }
  167560. png_ptr->dither_index[i] = (png_byte)min_k;
  167561. }
  167562. }
  167563. }
  167564. png_free(png_ptr, png_ptr->dither_sort);
  167565. png_ptr->dither_sort=NULL;
  167566. }
  167567. else
  167568. {
  167569. int i;
  167570. int max_d;
  167571. int num_new_palette;
  167572. png_dsortp t;
  167573. png_dsortpp hash;
  167574. t=NULL;
  167575. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167576. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167577. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167578. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167579. for (i = 0; i < num_palette; i++)
  167580. {
  167581. png_ptr->index_to_palette[i] = (png_byte)i;
  167582. png_ptr->palette_to_index[i] = (png_byte)i;
  167583. }
  167584. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167585. png_sizeof (png_dsortp)));
  167586. for (i = 0; i < 769; i++)
  167587. hash[i] = NULL;
  167588. num_new_palette = num_palette;
  167589. max_d = 96;
  167590. while (num_new_palette > maximum_colors)
  167591. {
  167592. for (i = 0; i < num_new_palette - 1; i++)
  167593. {
  167594. int j;
  167595. for (j = i + 1; j < num_new_palette; j++)
  167596. {
  167597. int d;
  167598. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167599. if (d <= max_d)
  167600. {
  167601. t = (png_dsortp)png_malloc_warn(png_ptr,
  167602. (png_uint_32)(png_sizeof(png_dsort)));
  167603. if (t == NULL)
  167604. break;
  167605. t->next = hash[d];
  167606. t->left = (png_byte)i;
  167607. t->right = (png_byte)j;
  167608. hash[d] = t;
  167609. }
  167610. }
  167611. if (t == NULL)
  167612. break;
  167613. }
  167614. if (t != NULL)
  167615. for (i = 0; i <= max_d; i++)
  167616. {
  167617. if (hash[i] != NULL)
  167618. {
  167619. png_dsortp p;
  167620. for (p = hash[i]; p; p = p->next)
  167621. {
  167622. if ((int)png_ptr->index_to_palette[p->left]
  167623. < num_new_palette &&
  167624. (int)png_ptr->index_to_palette[p->right]
  167625. < num_new_palette)
  167626. {
  167627. int j, next_j;
  167628. if (num_new_palette & 0x01)
  167629. {
  167630. j = p->left;
  167631. next_j = p->right;
  167632. }
  167633. else
  167634. {
  167635. j = p->right;
  167636. next_j = p->left;
  167637. }
  167638. num_new_palette--;
  167639. palette[png_ptr->index_to_palette[j]]
  167640. = palette[num_new_palette];
  167641. if (!full_dither)
  167642. {
  167643. int k;
  167644. for (k = 0; k < num_palette; k++)
  167645. {
  167646. if (png_ptr->dither_index[k] ==
  167647. png_ptr->index_to_palette[j])
  167648. png_ptr->dither_index[k] =
  167649. png_ptr->index_to_palette[next_j];
  167650. if ((int)png_ptr->dither_index[k] ==
  167651. num_new_palette)
  167652. png_ptr->dither_index[k] =
  167653. png_ptr->index_to_palette[j];
  167654. }
  167655. }
  167656. png_ptr->index_to_palette[png_ptr->palette_to_index
  167657. [num_new_palette]] = png_ptr->index_to_palette[j];
  167658. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167659. = png_ptr->palette_to_index[num_new_palette];
  167660. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167661. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167662. }
  167663. if (num_new_palette <= maximum_colors)
  167664. break;
  167665. }
  167666. if (num_new_palette <= maximum_colors)
  167667. break;
  167668. }
  167669. }
  167670. for (i = 0; i < 769; i++)
  167671. {
  167672. if (hash[i] != NULL)
  167673. {
  167674. png_dsortp p = hash[i];
  167675. while (p)
  167676. {
  167677. t = p->next;
  167678. png_free(png_ptr, p);
  167679. p = t;
  167680. }
  167681. }
  167682. hash[i] = 0;
  167683. }
  167684. max_d += 96;
  167685. }
  167686. png_free(png_ptr, hash);
  167687. png_free(png_ptr, png_ptr->palette_to_index);
  167688. png_free(png_ptr, png_ptr->index_to_palette);
  167689. png_ptr->palette_to_index=NULL;
  167690. png_ptr->index_to_palette=NULL;
  167691. }
  167692. num_palette = maximum_colors;
  167693. }
  167694. if (png_ptr->palette == NULL)
  167695. {
  167696. png_ptr->palette = palette;
  167697. }
  167698. png_ptr->num_palette = (png_uint_16)num_palette;
  167699. if (full_dither)
  167700. {
  167701. int i;
  167702. png_bytep distance;
  167703. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167704. PNG_DITHER_BLUE_BITS;
  167705. int num_red = (1 << PNG_DITHER_RED_BITS);
  167706. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167707. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167708. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167709. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167710. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167711. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167712. png_sizeof (png_byte));
  167713. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167714. png_sizeof(png_byte)));
  167715. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167716. for (i = 0; i < num_palette; i++)
  167717. {
  167718. int ir, ig, ib;
  167719. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167720. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167721. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167722. for (ir = 0; ir < num_red; ir++)
  167723. {
  167724. int dr = ((ir > r) ? ir - r : r - ir);
  167725. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167726. for (ig = 0; ig < num_green; ig++)
  167727. {
  167728. int dg = ((ig > g) ? ig - g : g - ig);
  167729. int dt = dr + dg;
  167730. int dm = ((dr > dg) ? dr : dg);
  167731. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167732. for (ib = 0; ib < num_blue; ib++)
  167733. {
  167734. int d_index = index_g | ib;
  167735. int db = ((ib > b) ? ib - b : b - ib);
  167736. int dmax = ((dm > db) ? dm : db);
  167737. int d = dmax + dt + db;
  167738. if (d < (int)distance[d_index])
  167739. {
  167740. distance[d_index] = (png_byte)d;
  167741. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167742. }
  167743. }
  167744. }
  167745. }
  167746. }
  167747. png_free(png_ptr, distance);
  167748. }
  167749. }
  167750. #endif
  167751. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167752. void PNGAPI
  167753. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167754. {
  167755. png_debug(1, "in png_set_gamma\n");
  167756. if(png_ptr == NULL) return;
  167757. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167758. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167759. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167760. png_ptr->transformations |= PNG_GAMMA;
  167761. png_ptr->gamma = (float)file_gamma;
  167762. png_ptr->screen_gamma = (float)scrn_gamma;
  167763. }
  167764. #endif
  167765. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167766. void PNGAPI
  167767. png_set_expand(png_structp png_ptr)
  167768. {
  167769. png_debug(1, "in png_set_expand\n");
  167770. if(png_ptr == NULL) return;
  167771. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167772. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167773. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167774. #endif
  167775. }
  167776. void PNGAPI
  167777. png_set_palette_to_rgb(png_structp png_ptr)
  167778. {
  167779. png_debug(1, "in png_set_palette_to_rgb\n");
  167780. if(png_ptr == NULL) return;
  167781. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167782. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167783. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167784. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167785. #endif
  167786. }
  167787. #if !defined(PNG_1_0_X)
  167788. void PNGAPI
  167789. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167790. {
  167791. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167792. if(png_ptr == NULL) return;
  167793. png_ptr->transformations |= PNG_EXPAND;
  167794. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167795. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167796. #endif
  167797. }
  167798. #endif
  167799. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167800. void PNGAPI
  167801. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167802. {
  167803. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167804. if(png_ptr == NULL) return;
  167805. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167806. }
  167807. #endif
  167808. void PNGAPI
  167809. png_set_tRNS_to_alpha(png_structp png_ptr)
  167810. {
  167811. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167812. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167813. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167814. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167815. #endif
  167816. }
  167817. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167818. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167819. void PNGAPI
  167820. png_set_gray_to_rgb(png_structp png_ptr)
  167821. {
  167822. png_debug(1, "in png_set_gray_to_rgb\n");
  167823. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167824. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167825. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167826. #endif
  167827. }
  167828. #endif
  167829. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167830. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167831. void PNGAPI
  167832. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167833. double green)
  167834. {
  167835. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167836. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167837. if(png_ptr == NULL) return;
  167838. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167839. }
  167840. #endif
  167841. void PNGAPI
  167842. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167843. png_fixed_point red, png_fixed_point green)
  167844. {
  167845. png_debug(1, "in png_set_rgb_to_gray\n");
  167846. if(png_ptr == NULL) return;
  167847. switch(error_action)
  167848. {
  167849. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167850. break;
  167851. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167852. break;
  167853. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167854. }
  167855. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167856. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167857. png_ptr->transformations |= PNG_EXPAND;
  167858. #else
  167859. {
  167860. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167861. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167862. }
  167863. #endif
  167864. {
  167865. png_uint_16 red_int, green_int;
  167866. if(red < 0 || green < 0)
  167867. {
  167868. red_int = 6968; /* .212671 * 32768 + .5 */
  167869. green_int = 23434; /* .715160 * 32768 + .5 */
  167870. }
  167871. else if(red + green < 100000L)
  167872. {
  167873. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167874. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167875. }
  167876. else
  167877. {
  167878. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167879. red_int = 6968;
  167880. green_int = 23434;
  167881. }
  167882. png_ptr->rgb_to_gray_red_coeff = red_int;
  167883. png_ptr->rgb_to_gray_green_coeff = green_int;
  167884. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167885. }
  167886. }
  167887. #endif
  167888. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167889. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167890. defined(PNG_LEGACY_SUPPORTED)
  167891. void PNGAPI
  167892. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167893. read_user_transform_fn)
  167894. {
  167895. png_debug(1, "in png_set_read_user_transform_fn\n");
  167896. if(png_ptr == NULL) return;
  167897. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167898. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167899. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167900. #endif
  167901. #ifdef PNG_LEGACY_SUPPORTED
  167902. if(read_user_transform_fn)
  167903. png_warning(png_ptr,
  167904. "This version of libpng does not support user transforms");
  167905. #endif
  167906. }
  167907. #endif
  167908. void /* PRIVATE */
  167909. png_init_read_transformations(png_structp png_ptr)
  167910. {
  167911. png_debug(1, "in png_init_read_transformations\n");
  167912. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167913. if(png_ptr != NULL)
  167914. #endif
  167915. {
  167916. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167917. || defined(PNG_READ_GAMMA_SUPPORTED)
  167918. int color_type = png_ptr->color_type;
  167919. #endif
  167920. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167921. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167922. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167923. !(color_type & PNG_COLOR_MASK_COLOR))
  167924. {
  167925. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167926. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167927. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167928. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167929. png_ptr->background.red == png_ptr->background.green &&
  167930. png_ptr->background.red == png_ptr->background.blue)
  167931. {
  167932. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167933. png_ptr->background.gray = png_ptr->background.red;
  167934. }
  167935. #endif
  167936. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167937. (png_ptr->transformations & PNG_EXPAND))
  167938. {
  167939. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167940. {
  167941. switch (png_ptr->bit_depth)
  167942. {
  167943. case 1:
  167944. png_ptr->background.gray *= (png_uint_16)0xff;
  167945. png_ptr->background.red = png_ptr->background.green
  167946. = png_ptr->background.blue = png_ptr->background.gray;
  167947. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167948. {
  167949. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167950. png_ptr->trans_values.red = png_ptr->trans_values.green
  167951. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167952. }
  167953. break;
  167954. case 2:
  167955. png_ptr->background.gray *= (png_uint_16)0x55;
  167956. png_ptr->background.red = png_ptr->background.green
  167957. = png_ptr->background.blue = png_ptr->background.gray;
  167958. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167959. {
  167960. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167961. png_ptr->trans_values.red = png_ptr->trans_values.green
  167962. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167963. }
  167964. break;
  167965. case 4:
  167966. png_ptr->background.gray *= (png_uint_16)0x11;
  167967. png_ptr->background.red = png_ptr->background.green
  167968. = png_ptr->background.blue = png_ptr->background.gray;
  167969. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167970. {
  167971. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167972. png_ptr->trans_values.red = png_ptr->trans_values.green
  167973. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167974. }
  167975. break;
  167976. case 8:
  167977. case 16:
  167978. png_ptr->background.red = png_ptr->background.green
  167979. = png_ptr->background.blue = png_ptr->background.gray;
  167980. break;
  167981. }
  167982. }
  167983. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167984. {
  167985. png_ptr->background.red =
  167986. png_ptr->palette[png_ptr->background.index].red;
  167987. png_ptr->background.green =
  167988. png_ptr->palette[png_ptr->background.index].green;
  167989. png_ptr->background.blue =
  167990. png_ptr->palette[png_ptr->background.index].blue;
  167991. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167992. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167993. {
  167994. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167995. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167996. #endif
  167997. {
  167998. int i,istop;
  167999. istop=(int)png_ptr->num_trans;
  168000. for (i=0; i<istop; i++)
  168001. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  168002. }
  168003. }
  168004. #endif
  168005. }
  168006. }
  168007. #endif
  168008. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  168009. png_ptr->background_1 = png_ptr->background;
  168010. #endif
  168011. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168012. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  168013. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  168014. < PNG_GAMMA_THRESHOLD))
  168015. {
  168016. int i,k;
  168017. k=0;
  168018. for (i=0; i<png_ptr->num_trans; i++)
  168019. {
  168020. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  168021. k=1; /* partial transparency is present */
  168022. }
  168023. if (k == 0)
  168024. png_ptr->transformations &= (~PNG_GAMMA);
  168025. }
  168026. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  168027. png_ptr->gamma != 0.0)
  168028. {
  168029. png_build_gamma_table(png_ptr);
  168030. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168031. if (png_ptr->transformations & PNG_BACKGROUND)
  168032. {
  168033. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168034. {
  168035. png_color back, back_1;
  168036. png_colorp palette = png_ptr->palette;
  168037. int num_palette = png_ptr->num_palette;
  168038. int i;
  168039. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168040. {
  168041. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168042. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168043. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168044. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168045. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168046. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168047. }
  168048. else
  168049. {
  168050. double g, gs;
  168051. switch (png_ptr->background_gamma_type)
  168052. {
  168053. case PNG_BACKGROUND_GAMMA_SCREEN:
  168054. g = (png_ptr->screen_gamma);
  168055. gs = 1.0;
  168056. break;
  168057. case PNG_BACKGROUND_GAMMA_FILE:
  168058. g = 1.0 / (png_ptr->gamma);
  168059. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168060. break;
  168061. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168062. g = 1.0 / (png_ptr->background_gamma);
  168063. gs = 1.0 / (png_ptr->background_gamma *
  168064. png_ptr->screen_gamma);
  168065. break;
  168066. default:
  168067. g = 1.0; /* back_1 */
  168068. gs = 1.0; /* back */
  168069. }
  168070. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  168071. {
  168072. back.red = (png_byte)png_ptr->background.red;
  168073. back.green = (png_byte)png_ptr->background.green;
  168074. back.blue = (png_byte)png_ptr->background.blue;
  168075. }
  168076. else
  168077. {
  168078. back.red = (png_byte)(pow(
  168079. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  168080. back.green = (png_byte)(pow(
  168081. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  168082. back.blue = (png_byte)(pow(
  168083. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  168084. }
  168085. back_1.red = (png_byte)(pow(
  168086. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  168087. back_1.green = (png_byte)(pow(
  168088. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  168089. back_1.blue = (png_byte)(pow(
  168090. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  168091. }
  168092. for (i = 0; i < num_palette; i++)
  168093. {
  168094. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168095. {
  168096. if (png_ptr->trans[i] == 0)
  168097. {
  168098. palette[i] = back;
  168099. }
  168100. else /* if (png_ptr->trans[i] != 0xff) */
  168101. {
  168102. png_byte v, w;
  168103. v = png_ptr->gamma_to_1[palette[i].red];
  168104. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168105. palette[i].red = png_ptr->gamma_from_1[w];
  168106. v = png_ptr->gamma_to_1[palette[i].green];
  168107. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168108. palette[i].green = png_ptr->gamma_from_1[w];
  168109. v = png_ptr->gamma_to_1[palette[i].blue];
  168110. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168111. palette[i].blue = png_ptr->gamma_from_1[w];
  168112. }
  168113. }
  168114. else
  168115. {
  168116. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168117. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168118. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168119. }
  168120. }
  168121. }
  168122. else
  168123. {
  168124. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  168125. double g = 1.0;
  168126. double gs = 1.0;
  168127. switch (png_ptr->background_gamma_type)
  168128. {
  168129. case PNG_BACKGROUND_GAMMA_SCREEN:
  168130. g = (png_ptr->screen_gamma);
  168131. gs = 1.0;
  168132. break;
  168133. case PNG_BACKGROUND_GAMMA_FILE:
  168134. g = 1.0 / (png_ptr->gamma);
  168135. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168136. break;
  168137. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168138. g = 1.0 / (png_ptr->background_gamma);
  168139. gs = 1.0 / (png_ptr->background_gamma *
  168140. png_ptr->screen_gamma);
  168141. break;
  168142. }
  168143. png_ptr->background_1.gray = (png_uint_16)(pow(
  168144. (double)png_ptr->background.gray / m, g) * m + .5);
  168145. png_ptr->background.gray = (png_uint_16)(pow(
  168146. (double)png_ptr->background.gray / m, gs) * m + .5);
  168147. if ((png_ptr->background.red != png_ptr->background.green) ||
  168148. (png_ptr->background.red != png_ptr->background.blue) ||
  168149. (png_ptr->background.red != png_ptr->background.gray))
  168150. {
  168151. png_ptr->background_1.red = (png_uint_16)(pow(
  168152. (double)png_ptr->background.red / m, g) * m + .5);
  168153. png_ptr->background_1.green = (png_uint_16)(pow(
  168154. (double)png_ptr->background.green / m, g) * m + .5);
  168155. png_ptr->background_1.blue = (png_uint_16)(pow(
  168156. (double)png_ptr->background.blue / m, g) * m + .5);
  168157. png_ptr->background.red = (png_uint_16)(pow(
  168158. (double)png_ptr->background.red / m, gs) * m + .5);
  168159. png_ptr->background.green = (png_uint_16)(pow(
  168160. (double)png_ptr->background.green / m, gs) * m + .5);
  168161. png_ptr->background.blue = (png_uint_16)(pow(
  168162. (double)png_ptr->background.blue / m, gs) * m + .5);
  168163. }
  168164. else
  168165. {
  168166. png_ptr->background_1.red = png_ptr->background_1.green
  168167. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  168168. png_ptr->background.red = png_ptr->background.green
  168169. = png_ptr->background.blue = png_ptr->background.gray;
  168170. }
  168171. }
  168172. }
  168173. else
  168174. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168175. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168176. {
  168177. png_colorp palette = png_ptr->palette;
  168178. int num_palette = png_ptr->num_palette;
  168179. int i;
  168180. for (i = 0; i < num_palette; i++)
  168181. {
  168182. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168183. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168184. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168185. }
  168186. }
  168187. }
  168188. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168189. else
  168190. #endif
  168191. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  168192. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168193. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168194. (color_type == PNG_COLOR_TYPE_PALETTE))
  168195. {
  168196. int i;
  168197. int istop = (int)png_ptr->num_trans;
  168198. png_color back;
  168199. png_colorp palette = png_ptr->palette;
  168200. back.red = (png_byte)png_ptr->background.red;
  168201. back.green = (png_byte)png_ptr->background.green;
  168202. back.blue = (png_byte)png_ptr->background.blue;
  168203. for (i = 0; i < istop; i++)
  168204. {
  168205. if (png_ptr->trans[i] == 0)
  168206. {
  168207. palette[i] = back;
  168208. }
  168209. else if (png_ptr->trans[i] != 0xff)
  168210. {
  168211. png_composite(palette[i].red, palette[i].red,
  168212. png_ptr->trans[i], back.red);
  168213. png_composite(palette[i].green, palette[i].green,
  168214. png_ptr->trans[i], back.green);
  168215. png_composite(palette[i].blue, palette[i].blue,
  168216. png_ptr->trans[i], back.blue);
  168217. }
  168218. }
  168219. }
  168220. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168221. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168222. if ((png_ptr->transformations & PNG_SHIFT) &&
  168223. (color_type == PNG_COLOR_TYPE_PALETTE))
  168224. {
  168225. png_uint_16 i;
  168226. png_uint_16 istop = png_ptr->num_palette;
  168227. int sr = 8 - png_ptr->sig_bit.red;
  168228. int sg = 8 - png_ptr->sig_bit.green;
  168229. int sb = 8 - png_ptr->sig_bit.blue;
  168230. if (sr < 0 || sr > 8)
  168231. sr = 0;
  168232. if (sg < 0 || sg > 8)
  168233. sg = 0;
  168234. if (sb < 0 || sb > 8)
  168235. sb = 0;
  168236. for (i = 0; i < istop; i++)
  168237. {
  168238. png_ptr->palette[i].red >>= sr;
  168239. png_ptr->palette[i].green >>= sg;
  168240. png_ptr->palette[i].blue >>= sb;
  168241. }
  168242. }
  168243. #endif /* PNG_READ_SHIFT_SUPPORTED */
  168244. }
  168245. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  168246. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  168247. if(png_ptr)
  168248. return;
  168249. #endif
  168250. }
  168251. void /* PRIVATE */
  168252. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  168253. {
  168254. png_debug(1, "in png_read_transform_info\n");
  168255. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168256. if (png_ptr->transformations & PNG_EXPAND)
  168257. {
  168258. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168259. {
  168260. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  168261. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  168262. else
  168263. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  168264. info_ptr->bit_depth = 8;
  168265. info_ptr->num_trans = 0;
  168266. }
  168267. else
  168268. {
  168269. if (png_ptr->num_trans)
  168270. {
  168271. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  168272. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168273. else
  168274. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168275. }
  168276. if (info_ptr->bit_depth < 8)
  168277. info_ptr->bit_depth = 8;
  168278. info_ptr->num_trans = 0;
  168279. }
  168280. }
  168281. #endif
  168282. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168283. if (png_ptr->transformations & PNG_BACKGROUND)
  168284. {
  168285. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168286. info_ptr->num_trans = 0;
  168287. info_ptr->background = png_ptr->background;
  168288. }
  168289. #endif
  168290. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168291. if (png_ptr->transformations & PNG_GAMMA)
  168292. {
  168293. #ifdef PNG_FLOATING_POINT_SUPPORTED
  168294. info_ptr->gamma = png_ptr->gamma;
  168295. #endif
  168296. #ifdef PNG_FIXED_POINT_SUPPORTED
  168297. info_ptr->int_gamma = png_ptr->int_gamma;
  168298. #endif
  168299. }
  168300. #endif
  168301. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168302. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168303. info_ptr->bit_depth = 8;
  168304. #endif
  168305. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168306. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168307. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168308. #endif
  168309. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168310. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168311. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168312. #endif
  168313. #if defined(PNG_READ_DITHER_SUPPORTED)
  168314. if (png_ptr->transformations & PNG_DITHER)
  168315. {
  168316. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168317. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168318. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168319. {
  168320. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168321. }
  168322. }
  168323. #endif
  168324. #if defined(PNG_READ_PACK_SUPPORTED)
  168325. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168326. info_ptr->bit_depth = 8;
  168327. #endif
  168328. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168329. info_ptr->channels = 1;
  168330. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168331. info_ptr->channels = 3;
  168332. else
  168333. info_ptr->channels = 1;
  168334. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168335. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168336. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168337. #endif
  168338. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168339. info_ptr->channels++;
  168340. #if defined(PNG_READ_FILLER_SUPPORTED)
  168341. if ((png_ptr->transformations & PNG_FILLER) &&
  168342. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168343. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168344. {
  168345. info_ptr->channels++;
  168346. #if !defined(PNG_1_0_X)
  168347. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168348. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168349. #endif
  168350. }
  168351. #endif
  168352. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168353. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168354. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168355. {
  168356. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168357. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168358. if(info_ptr->channels < png_ptr->user_transform_channels)
  168359. info_ptr->channels = png_ptr->user_transform_channels;
  168360. }
  168361. #endif
  168362. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168363. info_ptr->bit_depth);
  168364. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168365. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168366. if(png_ptr)
  168367. return;
  168368. #endif
  168369. }
  168370. void /* PRIVATE */
  168371. png_do_read_transformations(png_structp png_ptr)
  168372. {
  168373. png_debug(1, "in png_do_read_transformations\n");
  168374. if (png_ptr->row_buf == NULL)
  168375. {
  168376. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168377. char msg[50];
  168378. png_snprintf2(msg, 50,
  168379. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168380. png_ptr->pass);
  168381. png_error(png_ptr, msg);
  168382. #else
  168383. png_error(png_ptr, "NULL row buffer");
  168384. #endif
  168385. }
  168386. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168387. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168388. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168389. png_error(png_ptr, "Uninitialized row");
  168390. #else
  168391. png_warning(png_ptr, "Uninitialized row");
  168392. #endif
  168393. #endif
  168394. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168395. if (png_ptr->transformations & PNG_EXPAND)
  168396. {
  168397. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168398. {
  168399. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168400. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168401. }
  168402. else
  168403. {
  168404. if (png_ptr->num_trans &&
  168405. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168406. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168407. &(png_ptr->trans_values));
  168408. else
  168409. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168410. NULL);
  168411. }
  168412. }
  168413. #endif
  168414. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168415. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168416. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168417. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168418. #endif
  168419. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168420. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168421. {
  168422. int rgb_error =
  168423. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168424. if(rgb_error)
  168425. {
  168426. png_ptr->rgb_to_gray_status=1;
  168427. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168428. PNG_RGB_TO_GRAY_WARN)
  168429. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168430. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168431. PNG_RGB_TO_GRAY_ERR)
  168432. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168433. }
  168434. }
  168435. #endif
  168436. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168437. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168438. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168439. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168440. #endif
  168441. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168442. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168443. ((png_ptr->num_trans != 0 ) ||
  168444. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168445. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168446. &(png_ptr->trans_values), &(png_ptr->background)
  168447. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168448. , &(png_ptr->background_1),
  168449. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168450. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168451. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168452. png_ptr->gamma_shift
  168453. #endif
  168454. );
  168455. #endif
  168456. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168457. if ((png_ptr->transformations & PNG_GAMMA) &&
  168458. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168459. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168460. ((png_ptr->num_trans != 0) ||
  168461. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168462. #endif
  168463. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168464. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168465. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168466. png_ptr->gamma_shift);
  168467. #endif
  168468. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168469. if (png_ptr->transformations & PNG_16_TO_8)
  168470. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168471. #endif
  168472. #if defined(PNG_READ_DITHER_SUPPORTED)
  168473. if (png_ptr->transformations & PNG_DITHER)
  168474. {
  168475. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168476. png_ptr->palette_lookup, png_ptr->dither_index);
  168477. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168478. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168479. }
  168480. #endif
  168481. #if defined(PNG_READ_INVERT_SUPPORTED)
  168482. if (png_ptr->transformations & PNG_INVERT_MONO)
  168483. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168484. #endif
  168485. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168486. if (png_ptr->transformations & PNG_SHIFT)
  168487. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168488. &(png_ptr->shift));
  168489. #endif
  168490. #if defined(PNG_READ_PACK_SUPPORTED)
  168491. if (png_ptr->transformations & PNG_PACK)
  168492. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168493. #endif
  168494. #if defined(PNG_READ_BGR_SUPPORTED)
  168495. if (png_ptr->transformations & PNG_BGR)
  168496. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168497. #endif
  168498. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168499. if (png_ptr->transformations & PNG_PACKSWAP)
  168500. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168501. #endif
  168502. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168503. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168504. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168505. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168506. #endif
  168507. #if defined(PNG_READ_FILLER_SUPPORTED)
  168508. if (png_ptr->transformations & PNG_FILLER)
  168509. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168510. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168511. #endif
  168512. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168513. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168514. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168515. #endif
  168516. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168517. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168518. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168519. #endif
  168520. #if defined(PNG_READ_SWAP_SUPPORTED)
  168521. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168522. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168523. #endif
  168524. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168525. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168526. {
  168527. if(png_ptr->read_user_transform_fn != NULL)
  168528. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168529. (png_ptr, /* png_ptr */
  168530. &(png_ptr->row_info), /* row_info: */
  168531. png_ptr->row_buf + 1); /* start of pixel data for row */
  168532. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168533. if(png_ptr->user_transform_depth)
  168534. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168535. if(png_ptr->user_transform_channels)
  168536. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168537. #endif
  168538. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168539. png_ptr->row_info.channels);
  168540. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168541. png_ptr->row_info.width);
  168542. }
  168543. #endif
  168544. }
  168545. #if defined(PNG_READ_PACK_SUPPORTED)
  168546. void /* PRIVATE */
  168547. png_do_unpack(png_row_infop row_info, png_bytep row)
  168548. {
  168549. png_debug(1, "in png_do_unpack\n");
  168550. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168551. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168552. #else
  168553. if (row_info->bit_depth < 8)
  168554. #endif
  168555. {
  168556. png_uint_32 i;
  168557. png_uint_32 row_width=row_info->width;
  168558. switch (row_info->bit_depth)
  168559. {
  168560. case 1:
  168561. {
  168562. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168563. png_bytep dp = row + (png_size_t)row_width - 1;
  168564. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168565. for (i = 0; i < row_width; i++)
  168566. {
  168567. *dp = (png_byte)((*sp >> shift) & 0x01);
  168568. if (shift == 7)
  168569. {
  168570. shift = 0;
  168571. sp--;
  168572. }
  168573. else
  168574. shift++;
  168575. dp--;
  168576. }
  168577. break;
  168578. }
  168579. case 2:
  168580. {
  168581. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168582. png_bytep dp = row + (png_size_t)row_width - 1;
  168583. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168584. for (i = 0; i < row_width; i++)
  168585. {
  168586. *dp = (png_byte)((*sp >> shift) & 0x03);
  168587. if (shift == 6)
  168588. {
  168589. shift = 0;
  168590. sp--;
  168591. }
  168592. else
  168593. shift += 2;
  168594. dp--;
  168595. }
  168596. break;
  168597. }
  168598. case 4:
  168599. {
  168600. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168601. png_bytep dp = row + (png_size_t)row_width - 1;
  168602. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168603. for (i = 0; i < row_width; i++)
  168604. {
  168605. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168606. if (shift == 4)
  168607. {
  168608. shift = 0;
  168609. sp--;
  168610. }
  168611. else
  168612. shift = 4;
  168613. dp--;
  168614. }
  168615. break;
  168616. }
  168617. }
  168618. row_info->bit_depth = 8;
  168619. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168620. row_info->rowbytes = row_width * row_info->channels;
  168621. }
  168622. }
  168623. #endif
  168624. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168625. void /* PRIVATE */
  168626. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168627. {
  168628. png_debug(1, "in png_do_unshift\n");
  168629. if (
  168630. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168631. row != NULL && row_info != NULL && sig_bits != NULL &&
  168632. #endif
  168633. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168634. {
  168635. int shift[4];
  168636. int channels = 0;
  168637. int c;
  168638. png_uint_16 value = 0;
  168639. png_uint_32 row_width = row_info->width;
  168640. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168641. {
  168642. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168643. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168644. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168645. }
  168646. else
  168647. {
  168648. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168649. }
  168650. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168651. {
  168652. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168653. }
  168654. for (c = 0; c < channels; c++)
  168655. {
  168656. if (shift[c] <= 0)
  168657. shift[c] = 0;
  168658. else
  168659. value = 1;
  168660. }
  168661. if (!value)
  168662. return;
  168663. switch (row_info->bit_depth)
  168664. {
  168665. case 2:
  168666. {
  168667. png_bytep bp;
  168668. png_uint_32 i;
  168669. png_uint_32 istop = row_info->rowbytes;
  168670. for (bp = row, i = 0; i < istop; i++)
  168671. {
  168672. *bp >>= 1;
  168673. *bp++ &= 0x55;
  168674. }
  168675. break;
  168676. }
  168677. case 4:
  168678. {
  168679. png_bytep bp = row;
  168680. png_uint_32 i;
  168681. png_uint_32 istop = row_info->rowbytes;
  168682. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168683. (png_byte)((int)0xf >> shift[0]));
  168684. for (i = 0; i < istop; i++)
  168685. {
  168686. *bp >>= shift[0];
  168687. *bp++ &= mask;
  168688. }
  168689. break;
  168690. }
  168691. case 8:
  168692. {
  168693. png_bytep bp = row;
  168694. png_uint_32 i;
  168695. png_uint_32 istop = row_width * channels;
  168696. for (i = 0; i < istop; i++)
  168697. {
  168698. *bp++ >>= shift[i%channels];
  168699. }
  168700. break;
  168701. }
  168702. case 16:
  168703. {
  168704. png_bytep bp = row;
  168705. png_uint_32 i;
  168706. png_uint_32 istop = channels * row_width;
  168707. for (i = 0; i < istop; i++)
  168708. {
  168709. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168710. value >>= shift[i%channels];
  168711. *bp++ = (png_byte)(value >> 8);
  168712. *bp++ = (png_byte)(value & 0xff);
  168713. }
  168714. break;
  168715. }
  168716. }
  168717. }
  168718. }
  168719. #endif
  168720. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168721. void /* PRIVATE */
  168722. png_do_chop(png_row_infop row_info, png_bytep row)
  168723. {
  168724. png_debug(1, "in png_do_chop\n");
  168725. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168726. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168727. #else
  168728. if (row_info->bit_depth == 16)
  168729. #endif
  168730. {
  168731. png_bytep sp = row;
  168732. png_bytep dp = row;
  168733. png_uint_32 i;
  168734. png_uint_32 istop = row_info->width * row_info->channels;
  168735. for (i = 0; i<istop; i++, sp += 2, dp++)
  168736. {
  168737. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168738. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168739. #else
  168740. *dp = *sp;
  168741. #endif
  168742. }
  168743. row_info->bit_depth = 8;
  168744. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168745. row_info->rowbytes = row_info->width * row_info->channels;
  168746. }
  168747. }
  168748. #endif
  168749. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168750. void /* PRIVATE */
  168751. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168752. {
  168753. png_debug(1, "in png_do_read_swap_alpha\n");
  168754. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168755. if (row != NULL && row_info != NULL)
  168756. #endif
  168757. {
  168758. png_uint_32 row_width = row_info->width;
  168759. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168760. {
  168761. if (row_info->bit_depth == 8)
  168762. {
  168763. png_bytep sp = row + row_info->rowbytes;
  168764. png_bytep dp = sp;
  168765. png_byte save;
  168766. png_uint_32 i;
  168767. for (i = 0; i < row_width; i++)
  168768. {
  168769. save = *(--sp);
  168770. *(--dp) = *(--sp);
  168771. *(--dp) = *(--sp);
  168772. *(--dp) = *(--sp);
  168773. *(--dp) = save;
  168774. }
  168775. }
  168776. else
  168777. {
  168778. png_bytep sp = row + row_info->rowbytes;
  168779. png_bytep dp = sp;
  168780. png_byte save[2];
  168781. png_uint_32 i;
  168782. for (i = 0; i < row_width; i++)
  168783. {
  168784. save[0] = *(--sp);
  168785. save[1] = *(--sp);
  168786. *(--dp) = *(--sp);
  168787. *(--dp) = *(--sp);
  168788. *(--dp) = *(--sp);
  168789. *(--dp) = *(--sp);
  168790. *(--dp) = *(--sp);
  168791. *(--dp) = *(--sp);
  168792. *(--dp) = save[0];
  168793. *(--dp) = save[1];
  168794. }
  168795. }
  168796. }
  168797. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168798. {
  168799. if (row_info->bit_depth == 8)
  168800. {
  168801. png_bytep sp = row + row_info->rowbytes;
  168802. png_bytep dp = sp;
  168803. png_byte save;
  168804. png_uint_32 i;
  168805. for (i = 0; i < row_width; i++)
  168806. {
  168807. save = *(--sp);
  168808. *(--dp) = *(--sp);
  168809. *(--dp) = save;
  168810. }
  168811. }
  168812. else
  168813. {
  168814. png_bytep sp = row + row_info->rowbytes;
  168815. png_bytep dp = sp;
  168816. png_byte save[2];
  168817. png_uint_32 i;
  168818. for (i = 0; i < row_width; i++)
  168819. {
  168820. save[0] = *(--sp);
  168821. save[1] = *(--sp);
  168822. *(--dp) = *(--sp);
  168823. *(--dp) = *(--sp);
  168824. *(--dp) = save[0];
  168825. *(--dp) = save[1];
  168826. }
  168827. }
  168828. }
  168829. }
  168830. }
  168831. #endif
  168832. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168833. void /* PRIVATE */
  168834. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168835. {
  168836. png_debug(1, "in png_do_read_invert_alpha\n");
  168837. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168838. if (row != NULL && row_info != NULL)
  168839. #endif
  168840. {
  168841. png_uint_32 row_width = row_info->width;
  168842. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168843. {
  168844. if (row_info->bit_depth == 8)
  168845. {
  168846. png_bytep sp = row + row_info->rowbytes;
  168847. png_bytep dp = sp;
  168848. png_uint_32 i;
  168849. for (i = 0; i < row_width; i++)
  168850. {
  168851. *(--dp) = (png_byte)(255 - *(--sp));
  168852. sp-=3;
  168853. dp=sp;
  168854. }
  168855. }
  168856. else
  168857. {
  168858. png_bytep sp = row + row_info->rowbytes;
  168859. png_bytep dp = sp;
  168860. png_uint_32 i;
  168861. for (i = 0; i < row_width; i++)
  168862. {
  168863. *(--dp) = (png_byte)(255 - *(--sp));
  168864. *(--dp) = (png_byte)(255 - *(--sp));
  168865. sp-=6;
  168866. dp=sp;
  168867. }
  168868. }
  168869. }
  168870. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168871. {
  168872. if (row_info->bit_depth == 8)
  168873. {
  168874. png_bytep sp = row + row_info->rowbytes;
  168875. png_bytep dp = sp;
  168876. png_uint_32 i;
  168877. for (i = 0; i < row_width; i++)
  168878. {
  168879. *(--dp) = (png_byte)(255 - *(--sp));
  168880. *(--dp) = *(--sp);
  168881. }
  168882. }
  168883. else
  168884. {
  168885. png_bytep sp = row + row_info->rowbytes;
  168886. png_bytep dp = sp;
  168887. png_uint_32 i;
  168888. for (i = 0; i < row_width; i++)
  168889. {
  168890. *(--dp) = (png_byte)(255 - *(--sp));
  168891. *(--dp) = (png_byte)(255 - *(--sp));
  168892. sp-=2;
  168893. dp=sp;
  168894. }
  168895. }
  168896. }
  168897. }
  168898. }
  168899. #endif
  168900. #if defined(PNG_READ_FILLER_SUPPORTED)
  168901. void /* PRIVATE */
  168902. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168903. png_uint_32 filler, png_uint_32 flags)
  168904. {
  168905. png_uint_32 i;
  168906. png_uint_32 row_width = row_info->width;
  168907. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168908. png_byte lo_filler = (png_byte)(filler & 0xff);
  168909. png_debug(1, "in png_do_read_filler\n");
  168910. if (
  168911. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168912. row != NULL && row_info != NULL &&
  168913. #endif
  168914. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168915. {
  168916. if(row_info->bit_depth == 8)
  168917. {
  168918. if (flags & PNG_FLAG_FILLER_AFTER)
  168919. {
  168920. png_bytep sp = row + (png_size_t)row_width;
  168921. png_bytep dp = sp + (png_size_t)row_width;
  168922. for (i = 1; i < row_width; i++)
  168923. {
  168924. *(--dp) = lo_filler;
  168925. *(--dp) = *(--sp);
  168926. }
  168927. *(--dp) = lo_filler;
  168928. row_info->channels = 2;
  168929. row_info->pixel_depth = 16;
  168930. row_info->rowbytes = row_width * 2;
  168931. }
  168932. else
  168933. {
  168934. png_bytep sp = row + (png_size_t)row_width;
  168935. png_bytep dp = sp + (png_size_t)row_width;
  168936. for (i = 0; i < row_width; i++)
  168937. {
  168938. *(--dp) = *(--sp);
  168939. *(--dp) = lo_filler;
  168940. }
  168941. row_info->channels = 2;
  168942. row_info->pixel_depth = 16;
  168943. row_info->rowbytes = row_width * 2;
  168944. }
  168945. }
  168946. else if(row_info->bit_depth == 16)
  168947. {
  168948. if (flags & PNG_FLAG_FILLER_AFTER)
  168949. {
  168950. png_bytep sp = row + (png_size_t)row_width * 2;
  168951. png_bytep dp = sp + (png_size_t)row_width * 2;
  168952. for (i = 1; i < row_width; i++)
  168953. {
  168954. *(--dp) = hi_filler;
  168955. *(--dp) = lo_filler;
  168956. *(--dp) = *(--sp);
  168957. *(--dp) = *(--sp);
  168958. }
  168959. *(--dp) = hi_filler;
  168960. *(--dp) = lo_filler;
  168961. row_info->channels = 2;
  168962. row_info->pixel_depth = 32;
  168963. row_info->rowbytes = row_width * 4;
  168964. }
  168965. else
  168966. {
  168967. png_bytep sp = row + (png_size_t)row_width * 2;
  168968. png_bytep dp = sp + (png_size_t)row_width * 2;
  168969. for (i = 0; i < row_width; i++)
  168970. {
  168971. *(--dp) = *(--sp);
  168972. *(--dp) = *(--sp);
  168973. *(--dp) = hi_filler;
  168974. *(--dp) = lo_filler;
  168975. }
  168976. row_info->channels = 2;
  168977. row_info->pixel_depth = 32;
  168978. row_info->rowbytes = row_width * 4;
  168979. }
  168980. }
  168981. } /* COLOR_TYPE == GRAY */
  168982. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168983. {
  168984. if(row_info->bit_depth == 8)
  168985. {
  168986. if (flags & PNG_FLAG_FILLER_AFTER)
  168987. {
  168988. png_bytep sp = row + (png_size_t)row_width * 3;
  168989. png_bytep dp = sp + (png_size_t)row_width;
  168990. for (i = 1; i < row_width; i++)
  168991. {
  168992. *(--dp) = lo_filler;
  168993. *(--dp) = *(--sp);
  168994. *(--dp) = *(--sp);
  168995. *(--dp) = *(--sp);
  168996. }
  168997. *(--dp) = lo_filler;
  168998. row_info->channels = 4;
  168999. row_info->pixel_depth = 32;
  169000. row_info->rowbytes = row_width * 4;
  169001. }
  169002. else
  169003. {
  169004. png_bytep sp = row + (png_size_t)row_width * 3;
  169005. png_bytep dp = sp + (png_size_t)row_width;
  169006. for (i = 0; i < row_width; i++)
  169007. {
  169008. *(--dp) = *(--sp);
  169009. *(--dp) = *(--sp);
  169010. *(--dp) = *(--sp);
  169011. *(--dp) = lo_filler;
  169012. }
  169013. row_info->channels = 4;
  169014. row_info->pixel_depth = 32;
  169015. row_info->rowbytes = row_width * 4;
  169016. }
  169017. }
  169018. else if(row_info->bit_depth == 16)
  169019. {
  169020. if (flags & PNG_FLAG_FILLER_AFTER)
  169021. {
  169022. png_bytep sp = row + (png_size_t)row_width * 6;
  169023. png_bytep dp = sp + (png_size_t)row_width * 2;
  169024. for (i = 1; i < row_width; i++)
  169025. {
  169026. *(--dp) = hi_filler;
  169027. *(--dp) = lo_filler;
  169028. *(--dp) = *(--sp);
  169029. *(--dp) = *(--sp);
  169030. *(--dp) = *(--sp);
  169031. *(--dp) = *(--sp);
  169032. *(--dp) = *(--sp);
  169033. *(--dp) = *(--sp);
  169034. }
  169035. *(--dp) = hi_filler;
  169036. *(--dp) = lo_filler;
  169037. row_info->channels = 4;
  169038. row_info->pixel_depth = 64;
  169039. row_info->rowbytes = row_width * 8;
  169040. }
  169041. else
  169042. {
  169043. png_bytep sp = row + (png_size_t)row_width * 6;
  169044. png_bytep dp = sp + (png_size_t)row_width * 2;
  169045. for (i = 0; i < row_width; i++)
  169046. {
  169047. *(--dp) = *(--sp);
  169048. *(--dp) = *(--sp);
  169049. *(--dp) = *(--sp);
  169050. *(--dp) = *(--sp);
  169051. *(--dp) = *(--sp);
  169052. *(--dp) = *(--sp);
  169053. *(--dp) = hi_filler;
  169054. *(--dp) = lo_filler;
  169055. }
  169056. row_info->channels = 4;
  169057. row_info->pixel_depth = 64;
  169058. row_info->rowbytes = row_width * 8;
  169059. }
  169060. }
  169061. } /* COLOR_TYPE == RGB */
  169062. }
  169063. #endif
  169064. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  169065. void /* PRIVATE */
  169066. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  169067. {
  169068. png_uint_32 i;
  169069. png_uint_32 row_width = row_info->width;
  169070. png_debug(1, "in png_do_gray_to_rgb\n");
  169071. if (row_info->bit_depth >= 8 &&
  169072. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169073. row != NULL && row_info != NULL &&
  169074. #endif
  169075. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  169076. {
  169077. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169078. {
  169079. if (row_info->bit_depth == 8)
  169080. {
  169081. png_bytep sp = row + (png_size_t)row_width - 1;
  169082. png_bytep dp = sp + (png_size_t)row_width * 2;
  169083. for (i = 0; i < row_width; i++)
  169084. {
  169085. *(dp--) = *sp;
  169086. *(dp--) = *sp;
  169087. *(dp--) = *(sp--);
  169088. }
  169089. }
  169090. else
  169091. {
  169092. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169093. png_bytep dp = sp + (png_size_t)row_width * 4;
  169094. for (i = 0; i < row_width; i++)
  169095. {
  169096. *(dp--) = *sp;
  169097. *(dp--) = *(sp - 1);
  169098. *(dp--) = *sp;
  169099. *(dp--) = *(sp - 1);
  169100. *(dp--) = *(sp--);
  169101. *(dp--) = *(sp--);
  169102. }
  169103. }
  169104. }
  169105. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169106. {
  169107. if (row_info->bit_depth == 8)
  169108. {
  169109. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169110. png_bytep dp = sp + (png_size_t)row_width * 2;
  169111. for (i = 0; i < row_width; i++)
  169112. {
  169113. *(dp--) = *(sp--);
  169114. *(dp--) = *sp;
  169115. *(dp--) = *sp;
  169116. *(dp--) = *(sp--);
  169117. }
  169118. }
  169119. else
  169120. {
  169121. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  169122. png_bytep dp = sp + (png_size_t)row_width * 4;
  169123. for (i = 0; i < row_width; i++)
  169124. {
  169125. *(dp--) = *(sp--);
  169126. *(dp--) = *(sp--);
  169127. *(dp--) = *sp;
  169128. *(dp--) = *(sp - 1);
  169129. *(dp--) = *sp;
  169130. *(dp--) = *(sp - 1);
  169131. *(dp--) = *(sp--);
  169132. *(dp--) = *(sp--);
  169133. }
  169134. }
  169135. }
  169136. row_info->channels += (png_byte)2;
  169137. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  169138. row_info->pixel_depth = (png_byte)(row_info->channels *
  169139. row_info->bit_depth);
  169140. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169141. }
  169142. }
  169143. #endif
  169144. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  169145. int /* PRIVATE */
  169146. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  169147. {
  169148. png_uint_32 i;
  169149. png_uint_32 row_width = row_info->width;
  169150. int rgb_error = 0;
  169151. png_debug(1, "in png_do_rgb_to_gray\n");
  169152. if (
  169153. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169154. row != NULL && row_info != NULL &&
  169155. #endif
  169156. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  169157. {
  169158. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  169159. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  169160. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  169161. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169162. {
  169163. if (row_info->bit_depth == 8)
  169164. {
  169165. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169166. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169167. {
  169168. png_bytep sp = row;
  169169. png_bytep dp = row;
  169170. for (i = 0; i < row_width; i++)
  169171. {
  169172. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169173. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169174. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169175. if(red != green || red != blue)
  169176. {
  169177. rgb_error |= 1;
  169178. *(dp++) = png_ptr->gamma_from_1[
  169179. (rc*red+gc*green+bc*blue)>>15];
  169180. }
  169181. else
  169182. *(dp++) = *(sp-1);
  169183. }
  169184. }
  169185. else
  169186. #endif
  169187. {
  169188. png_bytep sp = row;
  169189. png_bytep dp = row;
  169190. for (i = 0; i < row_width; i++)
  169191. {
  169192. png_byte red = *(sp++);
  169193. png_byte green = *(sp++);
  169194. png_byte blue = *(sp++);
  169195. if(red != green || red != blue)
  169196. {
  169197. rgb_error |= 1;
  169198. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  169199. }
  169200. else
  169201. *(dp++) = *(sp-1);
  169202. }
  169203. }
  169204. }
  169205. else /* RGB bit_depth == 16 */
  169206. {
  169207. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169208. if (png_ptr->gamma_16_to_1 != NULL &&
  169209. png_ptr->gamma_16_from_1 != NULL)
  169210. {
  169211. png_bytep sp = row;
  169212. png_bytep dp = row;
  169213. for (i = 0; i < row_width; i++)
  169214. {
  169215. png_uint_16 red, green, blue, w;
  169216. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169217. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169218. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169219. if(red == green && red == blue)
  169220. w = red;
  169221. else
  169222. {
  169223. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169224. png_ptr->gamma_shift][red>>8];
  169225. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169226. png_ptr->gamma_shift][green>>8];
  169227. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169228. png_ptr->gamma_shift][blue>>8];
  169229. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  169230. + bc*blue_1)>>15);
  169231. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169232. png_ptr->gamma_shift][gray16 >> 8];
  169233. rgb_error |= 1;
  169234. }
  169235. *(dp++) = (png_byte)((w>>8) & 0xff);
  169236. *(dp++) = (png_byte)(w & 0xff);
  169237. }
  169238. }
  169239. else
  169240. #endif
  169241. {
  169242. png_bytep sp = row;
  169243. png_bytep dp = row;
  169244. for (i = 0; i < row_width; i++)
  169245. {
  169246. png_uint_16 red, green, blue, gray16;
  169247. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169248. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169249. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169250. if(red != green || red != blue)
  169251. rgb_error |= 1;
  169252. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169253. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169254. *(dp++) = (png_byte)(gray16 & 0xff);
  169255. }
  169256. }
  169257. }
  169258. }
  169259. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169260. {
  169261. if (row_info->bit_depth == 8)
  169262. {
  169263. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169264. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169265. {
  169266. png_bytep sp = row;
  169267. png_bytep dp = row;
  169268. for (i = 0; i < row_width; i++)
  169269. {
  169270. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169271. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169272. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169273. if(red != green || red != blue)
  169274. rgb_error |= 1;
  169275. *(dp++) = png_ptr->gamma_from_1
  169276. [(rc*red + gc*green + bc*blue)>>15];
  169277. *(dp++) = *(sp++); /* alpha */
  169278. }
  169279. }
  169280. else
  169281. #endif
  169282. {
  169283. png_bytep sp = row;
  169284. png_bytep dp = row;
  169285. for (i = 0; i < row_width; i++)
  169286. {
  169287. png_byte red = *(sp++);
  169288. png_byte green = *(sp++);
  169289. png_byte blue = *(sp++);
  169290. if(red != green || red != blue)
  169291. rgb_error |= 1;
  169292. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  169293. *(dp++) = *(sp++); /* alpha */
  169294. }
  169295. }
  169296. }
  169297. else /* RGBA bit_depth == 16 */
  169298. {
  169299. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169300. if (png_ptr->gamma_16_to_1 != NULL &&
  169301. png_ptr->gamma_16_from_1 != NULL)
  169302. {
  169303. png_bytep sp = row;
  169304. png_bytep dp = row;
  169305. for (i = 0; i < row_width; i++)
  169306. {
  169307. png_uint_16 red, green, blue, w;
  169308. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169309. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169310. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169311. if(red == green && red == blue)
  169312. w = red;
  169313. else
  169314. {
  169315. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169316. png_ptr->gamma_shift][red>>8];
  169317. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169318. png_ptr->gamma_shift][green>>8];
  169319. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169320. png_ptr->gamma_shift][blue>>8];
  169321. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169322. + gc * green_1 + bc * blue_1)>>15);
  169323. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169324. png_ptr->gamma_shift][gray16 >> 8];
  169325. rgb_error |= 1;
  169326. }
  169327. *(dp++) = (png_byte)((w>>8) & 0xff);
  169328. *(dp++) = (png_byte)(w & 0xff);
  169329. *(dp++) = *(sp++); /* alpha */
  169330. *(dp++) = *(sp++);
  169331. }
  169332. }
  169333. else
  169334. #endif
  169335. {
  169336. png_bytep sp = row;
  169337. png_bytep dp = row;
  169338. for (i = 0; i < row_width; i++)
  169339. {
  169340. png_uint_16 red, green, blue, gray16;
  169341. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169342. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169343. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169344. if(red != green || red != blue)
  169345. rgb_error |= 1;
  169346. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169347. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169348. *(dp++) = (png_byte)(gray16 & 0xff);
  169349. *(dp++) = *(sp++); /* alpha */
  169350. *(dp++) = *(sp++);
  169351. }
  169352. }
  169353. }
  169354. }
  169355. row_info->channels -= (png_byte)2;
  169356. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169357. row_info->pixel_depth = (png_byte)(row_info->channels *
  169358. row_info->bit_depth);
  169359. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169360. }
  169361. return rgb_error;
  169362. }
  169363. #endif
  169364. void PNGAPI
  169365. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169366. {
  169367. int num_palette;
  169368. int color_inc;
  169369. int i;
  169370. int v;
  169371. png_debug(1, "in png_do_build_grayscale_palette\n");
  169372. if (palette == NULL)
  169373. return;
  169374. switch (bit_depth)
  169375. {
  169376. case 1:
  169377. num_palette = 2;
  169378. color_inc = 0xff;
  169379. break;
  169380. case 2:
  169381. num_palette = 4;
  169382. color_inc = 0x55;
  169383. break;
  169384. case 4:
  169385. num_palette = 16;
  169386. color_inc = 0x11;
  169387. break;
  169388. case 8:
  169389. num_palette = 256;
  169390. color_inc = 1;
  169391. break;
  169392. default:
  169393. num_palette = 0;
  169394. color_inc = 0;
  169395. break;
  169396. }
  169397. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169398. {
  169399. palette[i].red = (png_byte)v;
  169400. palette[i].green = (png_byte)v;
  169401. palette[i].blue = (png_byte)v;
  169402. }
  169403. }
  169404. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169405. void /* PRIVATE */
  169406. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169407. int num_palette)
  169408. {
  169409. png_debug(1, "in png_correct_palette\n");
  169410. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169411. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169412. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169413. {
  169414. png_color back, back_1;
  169415. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169416. {
  169417. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169418. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169419. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169420. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169421. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169422. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169423. }
  169424. else
  169425. {
  169426. double g;
  169427. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169428. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169429. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169430. {
  169431. back.red = png_ptr->background.red;
  169432. back.green = png_ptr->background.green;
  169433. back.blue = png_ptr->background.blue;
  169434. }
  169435. else
  169436. {
  169437. back.red =
  169438. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169439. 255.0 + 0.5);
  169440. back.green =
  169441. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169442. 255.0 + 0.5);
  169443. back.blue =
  169444. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169445. 255.0 + 0.5);
  169446. }
  169447. g = 1.0 / png_ptr->background_gamma;
  169448. back_1.red =
  169449. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169450. 255.0 + 0.5);
  169451. back_1.green =
  169452. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169453. 255.0 + 0.5);
  169454. back_1.blue =
  169455. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169456. 255.0 + 0.5);
  169457. }
  169458. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169459. {
  169460. png_uint_32 i;
  169461. for (i = 0; i < (png_uint_32)num_palette; i++)
  169462. {
  169463. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169464. {
  169465. palette[i] = back;
  169466. }
  169467. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169468. {
  169469. png_byte v, w;
  169470. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169471. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169472. palette[i].red = png_ptr->gamma_from_1[w];
  169473. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169474. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169475. palette[i].green = png_ptr->gamma_from_1[w];
  169476. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169477. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169478. palette[i].blue = png_ptr->gamma_from_1[w];
  169479. }
  169480. else
  169481. {
  169482. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169483. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169484. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169485. }
  169486. }
  169487. }
  169488. else
  169489. {
  169490. int i;
  169491. for (i = 0; i < num_palette; i++)
  169492. {
  169493. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169494. {
  169495. palette[i] = back;
  169496. }
  169497. else
  169498. {
  169499. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169500. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169501. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169502. }
  169503. }
  169504. }
  169505. }
  169506. else
  169507. #endif
  169508. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169509. if (png_ptr->transformations & PNG_GAMMA)
  169510. {
  169511. int i;
  169512. for (i = 0; i < num_palette; i++)
  169513. {
  169514. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169515. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169516. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169517. }
  169518. }
  169519. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169520. else
  169521. #endif
  169522. #endif
  169523. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169524. if (png_ptr->transformations & PNG_BACKGROUND)
  169525. {
  169526. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169527. {
  169528. png_color back;
  169529. back.red = (png_byte)png_ptr->background.red;
  169530. back.green = (png_byte)png_ptr->background.green;
  169531. back.blue = (png_byte)png_ptr->background.blue;
  169532. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169533. {
  169534. if (png_ptr->trans[i] == 0)
  169535. {
  169536. palette[i].red = back.red;
  169537. palette[i].green = back.green;
  169538. palette[i].blue = back.blue;
  169539. }
  169540. else if (png_ptr->trans[i] != 0xff)
  169541. {
  169542. png_composite(palette[i].red, png_ptr->palette[i].red,
  169543. png_ptr->trans[i], back.red);
  169544. png_composite(palette[i].green, png_ptr->palette[i].green,
  169545. png_ptr->trans[i], back.green);
  169546. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169547. png_ptr->trans[i], back.blue);
  169548. }
  169549. }
  169550. }
  169551. else /* assume grayscale palette (what else could it be?) */
  169552. {
  169553. int i;
  169554. for (i = 0; i < num_palette; i++)
  169555. {
  169556. if (i == (png_byte)png_ptr->trans_values.gray)
  169557. {
  169558. palette[i].red = (png_byte)png_ptr->background.red;
  169559. palette[i].green = (png_byte)png_ptr->background.green;
  169560. palette[i].blue = (png_byte)png_ptr->background.blue;
  169561. }
  169562. }
  169563. }
  169564. }
  169565. #endif
  169566. }
  169567. #endif
  169568. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169569. void /* PRIVATE */
  169570. png_do_background(png_row_infop row_info, png_bytep row,
  169571. png_color_16p trans_values, png_color_16p background
  169572. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169573. , png_color_16p background_1,
  169574. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169575. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169576. png_uint_16pp gamma_16_to_1, int gamma_shift
  169577. #endif
  169578. )
  169579. {
  169580. png_bytep sp, dp;
  169581. png_uint_32 i;
  169582. png_uint_32 row_width=row_info->width;
  169583. int shift;
  169584. png_debug(1, "in png_do_background\n");
  169585. if (background != NULL &&
  169586. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169587. row != NULL && row_info != NULL &&
  169588. #endif
  169589. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169590. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169591. {
  169592. switch (row_info->color_type)
  169593. {
  169594. case PNG_COLOR_TYPE_GRAY:
  169595. {
  169596. switch (row_info->bit_depth)
  169597. {
  169598. case 1:
  169599. {
  169600. sp = row;
  169601. shift = 7;
  169602. for (i = 0; i < row_width; i++)
  169603. {
  169604. if ((png_uint_16)((*sp >> shift) & 0x01)
  169605. == trans_values->gray)
  169606. {
  169607. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169608. *sp |= (png_byte)(background->gray << shift);
  169609. }
  169610. if (!shift)
  169611. {
  169612. shift = 7;
  169613. sp++;
  169614. }
  169615. else
  169616. shift--;
  169617. }
  169618. break;
  169619. }
  169620. case 2:
  169621. {
  169622. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169623. if (gamma_table != NULL)
  169624. {
  169625. sp = row;
  169626. shift = 6;
  169627. for (i = 0; i < row_width; i++)
  169628. {
  169629. if ((png_uint_16)((*sp >> shift) & 0x03)
  169630. == trans_values->gray)
  169631. {
  169632. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169633. *sp |= (png_byte)(background->gray << shift);
  169634. }
  169635. else
  169636. {
  169637. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169638. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169639. (p << 4) | (p << 6)] >> 6) & 0x03);
  169640. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169641. *sp |= (png_byte)(g << shift);
  169642. }
  169643. if (!shift)
  169644. {
  169645. shift = 6;
  169646. sp++;
  169647. }
  169648. else
  169649. shift -= 2;
  169650. }
  169651. }
  169652. else
  169653. #endif
  169654. {
  169655. sp = row;
  169656. shift = 6;
  169657. for (i = 0; i < row_width; i++)
  169658. {
  169659. if ((png_uint_16)((*sp >> shift) & 0x03)
  169660. == trans_values->gray)
  169661. {
  169662. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169663. *sp |= (png_byte)(background->gray << shift);
  169664. }
  169665. if (!shift)
  169666. {
  169667. shift = 6;
  169668. sp++;
  169669. }
  169670. else
  169671. shift -= 2;
  169672. }
  169673. }
  169674. break;
  169675. }
  169676. case 4:
  169677. {
  169678. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169679. if (gamma_table != NULL)
  169680. {
  169681. sp = row;
  169682. shift = 4;
  169683. for (i = 0; i < row_width; i++)
  169684. {
  169685. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169686. == trans_values->gray)
  169687. {
  169688. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169689. *sp |= (png_byte)(background->gray << shift);
  169690. }
  169691. else
  169692. {
  169693. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169694. png_byte g = (png_byte)((gamma_table[p |
  169695. (p << 4)] >> 4) & 0x0f);
  169696. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169697. *sp |= (png_byte)(g << shift);
  169698. }
  169699. if (!shift)
  169700. {
  169701. shift = 4;
  169702. sp++;
  169703. }
  169704. else
  169705. shift -= 4;
  169706. }
  169707. }
  169708. else
  169709. #endif
  169710. {
  169711. sp = row;
  169712. shift = 4;
  169713. for (i = 0; i < row_width; i++)
  169714. {
  169715. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169716. == trans_values->gray)
  169717. {
  169718. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169719. *sp |= (png_byte)(background->gray << shift);
  169720. }
  169721. if (!shift)
  169722. {
  169723. shift = 4;
  169724. sp++;
  169725. }
  169726. else
  169727. shift -= 4;
  169728. }
  169729. }
  169730. break;
  169731. }
  169732. case 8:
  169733. {
  169734. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169735. if (gamma_table != NULL)
  169736. {
  169737. sp = row;
  169738. for (i = 0; i < row_width; i++, sp++)
  169739. {
  169740. if (*sp == trans_values->gray)
  169741. {
  169742. *sp = (png_byte)background->gray;
  169743. }
  169744. else
  169745. {
  169746. *sp = gamma_table[*sp];
  169747. }
  169748. }
  169749. }
  169750. else
  169751. #endif
  169752. {
  169753. sp = row;
  169754. for (i = 0; i < row_width; i++, sp++)
  169755. {
  169756. if (*sp == trans_values->gray)
  169757. {
  169758. *sp = (png_byte)background->gray;
  169759. }
  169760. }
  169761. }
  169762. break;
  169763. }
  169764. case 16:
  169765. {
  169766. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169767. if (gamma_16 != NULL)
  169768. {
  169769. sp = row;
  169770. for (i = 0; i < row_width; i++, sp += 2)
  169771. {
  169772. png_uint_16 v;
  169773. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169774. if (v == trans_values->gray)
  169775. {
  169776. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169777. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169778. }
  169779. else
  169780. {
  169781. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169782. *sp = (png_byte)((v >> 8) & 0xff);
  169783. *(sp + 1) = (png_byte)(v & 0xff);
  169784. }
  169785. }
  169786. }
  169787. else
  169788. #endif
  169789. {
  169790. sp = row;
  169791. for (i = 0; i < row_width; i++, sp += 2)
  169792. {
  169793. png_uint_16 v;
  169794. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169795. if (v == trans_values->gray)
  169796. {
  169797. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169798. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169799. }
  169800. }
  169801. }
  169802. break;
  169803. }
  169804. }
  169805. break;
  169806. }
  169807. case PNG_COLOR_TYPE_RGB:
  169808. {
  169809. if (row_info->bit_depth == 8)
  169810. {
  169811. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169812. if (gamma_table != NULL)
  169813. {
  169814. sp = row;
  169815. for (i = 0; i < row_width; i++, sp += 3)
  169816. {
  169817. if (*sp == trans_values->red &&
  169818. *(sp + 1) == trans_values->green &&
  169819. *(sp + 2) == trans_values->blue)
  169820. {
  169821. *sp = (png_byte)background->red;
  169822. *(sp + 1) = (png_byte)background->green;
  169823. *(sp + 2) = (png_byte)background->blue;
  169824. }
  169825. else
  169826. {
  169827. *sp = gamma_table[*sp];
  169828. *(sp + 1) = gamma_table[*(sp + 1)];
  169829. *(sp + 2) = gamma_table[*(sp + 2)];
  169830. }
  169831. }
  169832. }
  169833. else
  169834. #endif
  169835. {
  169836. sp = row;
  169837. for (i = 0; i < row_width; i++, sp += 3)
  169838. {
  169839. if (*sp == trans_values->red &&
  169840. *(sp + 1) == trans_values->green &&
  169841. *(sp + 2) == trans_values->blue)
  169842. {
  169843. *sp = (png_byte)background->red;
  169844. *(sp + 1) = (png_byte)background->green;
  169845. *(sp + 2) = (png_byte)background->blue;
  169846. }
  169847. }
  169848. }
  169849. }
  169850. else /* if (row_info->bit_depth == 16) */
  169851. {
  169852. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169853. if (gamma_16 != NULL)
  169854. {
  169855. sp = row;
  169856. for (i = 0; i < row_width; i++, sp += 6)
  169857. {
  169858. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169859. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169860. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169861. if (r == trans_values->red && g == trans_values->green &&
  169862. b == trans_values->blue)
  169863. {
  169864. *sp = (png_byte)((background->red >> 8) & 0xff);
  169865. *(sp + 1) = (png_byte)(background->red & 0xff);
  169866. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169867. *(sp + 3) = (png_byte)(background->green & 0xff);
  169868. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169869. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169870. }
  169871. else
  169872. {
  169873. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169874. *sp = (png_byte)((v >> 8) & 0xff);
  169875. *(sp + 1) = (png_byte)(v & 0xff);
  169876. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169877. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169878. *(sp + 3) = (png_byte)(v & 0xff);
  169879. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169880. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169881. *(sp + 5) = (png_byte)(v & 0xff);
  169882. }
  169883. }
  169884. }
  169885. else
  169886. #endif
  169887. {
  169888. sp = row;
  169889. for (i = 0; i < row_width; i++, sp += 6)
  169890. {
  169891. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169892. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169893. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169894. if (r == trans_values->red && g == trans_values->green &&
  169895. b == trans_values->blue)
  169896. {
  169897. *sp = (png_byte)((background->red >> 8) & 0xff);
  169898. *(sp + 1) = (png_byte)(background->red & 0xff);
  169899. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169900. *(sp + 3) = (png_byte)(background->green & 0xff);
  169901. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169902. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169903. }
  169904. }
  169905. }
  169906. }
  169907. break;
  169908. }
  169909. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169910. {
  169911. if (row_info->bit_depth == 8)
  169912. {
  169913. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169914. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169915. gamma_table != NULL)
  169916. {
  169917. sp = row;
  169918. dp = row;
  169919. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169920. {
  169921. png_uint_16 a = *(sp + 1);
  169922. if (a == 0xff)
  169923. {
  169924. *dp = gamma_table[*sp];
  169925. }
  169926. else if (a == 0)
  169927. {
  169928. *dp = (png_byte)background->gray;
  169929. }
  169930. else
  169931. {
  169932. png_byte v, w;
  169933. v = gamma_to_1[*sp];
  169934. png_composite(w, v, a, background_1->gray);
  169935. *dp = gamma_from_1[w];
  169936. }
  169937. }
  169938. }
  169939. else
  169940. #endif
  169941. {
  169942. sp = row;
  169943. dp = row;
  169944. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169945. {
  169946. png_byte a = *(sp + 1);
  169947. if (a == 0xff)
  169948. {
  169949. *dp = *sp;
  169950. }
  169951. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169952. else if (a == 0)
  169953. {
  169954. *dp = (png_byte)background->gray;
  169955. }
  169956. else
  169957. {
  169958. png_composite(*dp, *sp, a, background_1->gray);
  169959. }
  169960. #else
  169961. *dp = (png_byte)background->gray;
  169962. #endif
  169963. }
  169964. }
  169965. }
  169966. else /* if (png_ptr->bit_depth == 16) */
  169967. {
  169968. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169969. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169970. gamma_16_to_1 != NULL)
  169971. {
  169972. sp = row;
  169973. dp = row;
  169974. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169975. {
  169976. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169977. if (a == (png_uint_16)0xffff)
  169978. {
  169979. png_uint_16 v;
  169980. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169981. *dp = (png_byte)((v >> 8) & 0xff);
  169982. *(dp + 1) = (png_byte)(v & 0xff);
  169983. }
  169984. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169985. else if (a == 0)
  169986. #else
  169987. else
  169988. #endif
  169989. {
  169990. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169991. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169992. }
  169993. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169994. else
  169995. {
  169996. png_uint_16 g, v, w;
  169997. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169998. png_composite_16(v, g, a, background_1->gray);
  169999. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  170000. *dp = (png_byte)((w >> 8) & 0xff);
  170001. *(dp + 1) = (png_byte)(w & 0xff);
  170002. }
  170003. #endif
  170004. }
  170005. }
  170006. else
  170007. #endif
  170008. {
  170009. sp = row;
  170010. dp = row;
  170011. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170012. {
  170013. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170014. if (a == (png_uint_16)0xffff)
  170015. {
  170016. png_memcpy(dp, sp, 2);
  170017. }
  170018. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170019. else if (a == 0)
  170020. #else
  170021. else
  170022. #endif
  170023. {
  170024. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170025. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170026. }
  170027. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170028. else
  170029. {
  170030. png_uint_16 g, v;
  170031. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170032. png_composite_16(v, g, a, background_1->gray);
  170033. *dp = (png_byte)((v >> 8) & 0xff);
  170034. *(dp + 1) = (png_byte)(v & 0xff);
  170035. }
  170036. #endif
  170037. }
  170038. }
  170039. }
  170040. break;
  170041. }
  170042. case PNG_COLOR_TYPE_RGB_ALPHA:
  170043. {
  170044. if (row_info->bit_depth == 8)
  170045. {
  170046. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170047. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170048. gamma_table != NULL)
  170049. {
  170050. sp = row;
  170051. dp = row;
  170052. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170053. {
  170054. png_byte a = *(sp + 3);
  170055. if (a == 0xff)
  170056. {
  170057. *dp = gamma_table[*sp];
  170058. *(dp + 1) = gamma_table[*(sp + 1)];
  170059. *(dp + 2) = gamma_table[*(sp + 2)];
  170060. }
  170061. else if (a == 0)
  170062. {
  170063. *dp = (png_byte)background->red;
  170064. *(dp + 1) = (png_byte)background->green;
  170065. *(dp + 2) = (png_byte)background->blue;
  170066. }
  170067. else
  170068. {
  170069. png_byte v, w;
  170070. v = gamma_to_1[*sp];
  170071. png_composite(w, v, a, background_1->red);
  170072. *dp = gamma_from_1[w];
  170073. v = gamma_to_1[*(sp + 1)];
  170074. png_composite(w, v, a, background_1->green);
  170075. *(dp + 1) = gamma_from_1[w];
  170076. v = gamma_to_1[*(sp + 2)];
  170077. png_composite(w, v, a, background_1->blue);
  170078. *(dp + 2) = gamma_from_1[w];
  170079. }
  170080. }
  170081. }
  170082. else
  170083. #endif
  170084. {
  170085. sp = row;
  170086. dp = row;
  170087. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170088. {
  170089. png_byte a = *(sp + 3);
  170090. if (a == 0xff)
  170091. {
  170092. *dp = *sp;
  170093. *(dp + 1) = *(sp + 1);
  170094. *(dp + 2) = *(sp + 2);
  170095. }
  170096. else if (a == 0)
  170097. {
  170098. *dp = (png_byte)background->red;
  170099. *(dp + 1) = (png_byte)background->green;
  170100. *(dp + 2) = (png_byte)background->blue;
  170101. }
  170102. else
  170103. {
  170104. png_composite(*dp, *sp, a, background->red);
  170105. png_composite(*(dp + 1), *(sp + 1), a,
  170106. background->green);
  170107. png_composite(*(dp + 2), *(sp + 2), a,
  170108. background->blue);
  170109. }
  170110. }
  170111. }
  170112. }
  170113. else /* if (row_info->bit_depth == 16) */
  170114. {
  170115. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170116. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170117. gamma_16_to_1 != NULL)
  170118. {
  170119. sp = row;
  170120. dp = row;
  170121. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170122. {
  170123. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170124. << 8) + (png_uint_16)(*(sp + 7)));
  170125. if (a == (png_uint_16)0xffff)
  170126. {
  170127. png_uint_16 v;
  170128. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170129. *dp = (png_byte)((v >> 8) & 0xff);
  170130. *(dp + 1) = (png_byte)(v & 0xff);
  170131. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170132. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170133. *(dp + 3) = (png_byte)(v & 0xff);
  170134. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170135. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170136. *(dp + 5) = (png_byte)(v & 0xff);
  170137. }
  170138. else if (a == 0)
  170139. {
  170140. *dp = (png_byte)((background->red >> 8) & 0xff);
  170141. *(dp + 1) = (png_byte)(background->red & 0xff);
  170142. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170143. *(dp + 3) = (png_byte)(background->green & 0xff);
  170144. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170145. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170146. }
  170147. else
  170148. {
  170149. png_uint_16 v, w, x;
  170150. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170151. png_composite_16(w, v, a, background_1->red);
  170152. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170153. *dp = (png_byte)((x >> 8) & 0xff);
  170154. *(dp + 1) = (png_byte)(x & 0xff);
  170155. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170156. png_composite_16(w, v, a, background_1->green);
  170157. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170158. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  170159. *(dp + 3) = (png_byte)(x & 0xff);
  170160. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170161. png_composite_16(w, v, a, background_1->blue);
  170162. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  170163. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  170164. *(dp + 5) = (png_byte)(x & 0xff);
  170165. }
  170166. }
  170167. }
  170168. else
  170169. #endif
  170170. {
  170171. sp = row;
  170172. dp = row;
  170173. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170174. {
  170175. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170176. << 8) + (png_uint_16)(*(sp + 7)));
  170177. if (a == (png_uint_16)0xffff)
  170178. {
  170179. png_memcpy(dp, sp, 6);
  170180. }
  170181. else if (a == 0)
  170182. {
  170183. *dp = (png_byte)((background->red >> 8) & 0xff);
  170184. *(dp + 1) = (png_byte)(background->red & 0xff);
  170185. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170186. *(dp + 3) = (png_byte)(background->green & 0xff);
  170187. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170188. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170189. }
  170190. else
  170191. {
  170192. png_uint_16 v;
  170193. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170194. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  170195. + *(sp + 3));
  170196. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  170197. + *(sp + 5));
  170198. png_composite_16(v, r, a, background->red);
  170199. *dp = (png_byte)((v >> 8) & 0xff);
  170200. *(dp + 1) = (png_byte)(v & 0xff);
  170201. png_composite_16(v, g, a, background->green);
  170202. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170203. *(dp + 3) = (png_byte)(v & 0xff);
  170204. png_composite_16(v, b, a, background->blue);
  170205. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170206. *(dp + 5) = (png_byte)(v & 0xff);
  170207. }
  170208. }
  170209. }
  170210. }
  170211. break;
  170212. }
  170213. }
  170214. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  170215. {
  170216. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  170217. row_info->channels--;
  170218. row_info->pixel_depth = (png_byte)(row_info->channels *
  170219. row_info->bit_depth);
  170220. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170221. }
  170222. }
  170223. }
  170224. #endif
  170225. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170226. void /* PRIVATE */
  170227. png_do_gamma(png_row_infop row_info, png_bytep row,
  170228. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  170229. int gamma_shift)
  170230. {
  170231. png_bytep sp;
  170232. png_uint_32 i;
  170233. png_uint_32 row_width=row_info->width;
  170234. png_debug(1, "in png_do_gamma\n");
  170235. if (
  170236. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170237. row != NULL && row_info != NULL &&
  170238. #endif
  170239. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  170240. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  170241. {
  170242. switch (row_info->color_type)
  170243. {
  170244. case PNG_COLOR_TYPE_RGB:
  170245. {
  170246. if (row_info->bit_depth == 8)
  170247. {
  170248. sp = row;
  170249. for (i = 0; i < row_width; i++)
  170250. {
  170251. *sp = gamma_table[*sp];
  170252. sp++;
  170253. *sp = gamma_table[*sp];
  170254. sp++;
  170255. *sp = gamma_table[*sp];
  170256. sp++;
  170257. }
  170258. }
  170259. else /* if (row_info->bit_depth == 16) */
  170260. {
  170261. sp = row;
  170262. for (i = 0; i < row_width; i++)
  170263. {
  170264. png_uint_16 v;
  170265. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170266. *sp = (png_byte)((v >> 8) & 0xff);
  170267. *(sp + 1) = (png_byte)(v & 0xff);
  170268. sp += 2;
  170269. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170270. *sp = (png_byte)((v >> 8) & 0xff);
  170271. *(sp + 1) = (png_byte)(v & 0xff);
  170272. sp += 2;
  170273. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170274. *sp = (png_byte)((v >> 8) & 0xff);
  170275. *(sp + 1) = (png_byte)(v & 0xff);
  170276. sp += 2;
  170277. }
  170278. }
  170279. break;
  170280. }
  170281. case PNG_COLOR_TYPE_RGB_ALPHA:
  170282. {
  170283. if (row_info->bit_depth == 8)
  170284. {
  170285. sp = row;
  170286. for (i = 0; i < row_width; i++)
  170287. {
  170288. *sp = gamma_table[*sp];
  170289. sp++;
  170290. *sp = gamma_table[*sp];
  170291. sp++;
  170292. *sp = gamma_table[*sp];
  170293. sp++;
  170294. sp++;
  170295. }
  170296. }
  170297. else /* if (row_info->bit_depth == 16) */
  170298. {
  170299. sp = row;
  170300. for (i = 0; i < row_width; i++)
  170301. {
  170302. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170303. *sp = (png_byte)((v >> 8) & 0xff);
  170304. *(sp + 1) = (png_byte)(v & 0xff);
  170305. sp += 2;
  170306. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170307. *sp = (png_byte)((v >> 8) & 0xff);
  170308. *(sp + 1) = (png_byte)(v & 0xff);
  170309. sp += 2;
  170310. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170311. *sp = (png_byte)((v >> 8) & 0xff);
  170312. *(sp + 1) = (png_byte)(v & 0xff);
  170313. sp += 4;
  170314. }
  170315. }
  170316. break;
  170317. }
  170318. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170319. {
  170320. if (row_info->bit_depth == 8)
  170321. {
  170322. sp = row;
  170323. for (i = 0; i < row_width; i++)
  170324. {
  170325. *sp = gamma_table[*sp];
  170326. sp += 2;
  170327. }
  170328. }
  170329. else /* if (row_info->bit_depth == 16) */
  170330. {
  170331. sp = row;
  170332. for (i = 0; i < row_width; i++)
  170333. {
  170334. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170335. *sp = (png_byte)((v >> 8) & 0xff);
  170336. *(sp + 1) = (png_byte)(v & 0xff);
  170337. sp += 4;
  170338. }
  170339. }
  170340. break;
  170341. }
  170342. case PNG_COLOR_TYPE_GRAY:
  170343. {
  170344. if (row_info->bit_depth == 2)
  170345. {
  170346. sp = row;
  170347. for (i = 0; i < row_width; i += 4)
  170348. {
  170349. int a = *sp & 0xc0;
  170350. int b = *sp & 0x30;
  170351. int c = *sp & 0x0c;
  170352. int d = *sp & 0x03;
  170353. *sp = (png_byte)(
  170354. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170355. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170356. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170357. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170358. sp++;
  170359. }
  170360. }
  170361. if (row_info->bit_depth == 4)
  170362. {
  170363. sp = row;
  170364. for (i = 0; i < row_width; i += 2)
  170365. {
  170366. int msb = *sp & 0xf0;
  170367. int lsb = *sp & 0x0f;
  170368. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170369. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170370. sp++;
  170371. }
  170372. }
  170373. else if (row_info->bit_depth == 8)
  170374. {
  170375. sp = row;
  170376. for (i = 0; i < row_width; i++)
  170377. {
  170378. *sp = gamma_table[*sp];
  170379. sp++;
  170380. }
  170381. }
  170382. else if (row_info->bit_depth == 16)
  170383. {
  170384. sp = row;
  170385. for (i = 0; i < row_width; i++)
  170386. {
  170387. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170388. *sp = (png_byte)((v >> 8) & 0xff);
  170389. *(sp + 1) = (png_byte)(v & 0xff);
  170390. sp += 2;
  170391. }
  170392. }
  170393. break;
  170394. }
  170395. }
  170396. }
  170397. }
  170398. #endif
  170399. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170400. void /* PRIVATE */
  170401. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170402. png_colorp palette, png_bytep trans, int num_trans)
  170403. {
  170404. int shift, value;
  170405. png_bytep sp, dp;
  170406. png_uint_32 i;
  170407. png_uint_32 row_width=row_info->width;
  170408. png_debug(1, "in png_do_expand_palette\n");
  170409. if (
  170410. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170411. row != NULL && row_info != NULL &&
  170412. #endif
  170413. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170414. {
  170415. if (row_info->bit_depth < 8)
  170416. {
  170417. switch (row_info->bit_depth)
  170418. {
  170419. case 1:
  170420. {
  170421. sp = row + (png_size_t)((row_width - 1) >> 3);
  170422. dp = row + (png_size_t)row_width - 1;
  170423. shift = 7 - (int)((row_width + 7) & 0x07);
  170424. for (i = 0; i < row_width; i++)
  170425. {
  170426. if ((*sp >> shift) & 0x01)
  170427. *dp = 1;
  170428. else
  170429. *dp = 0;
  170430. if (shift == 7)
  170431. {
  170432. shift = 0;
  170433. sp--;
  170434. }
  170435. else
  170436. shift++;
  170437. dp--;
  170438. }
  170439. break;
  170440. }
  170441. case 2:
  170442. {
  170443. sp = row + (png_size_t)((row_width - 1) >> 2);
  170444. dp = row + (png_size_t)row_width - 1;
  170445. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170446. for (i = 0; i < row_width; i++)
  170447. {
  170448. value = (*sp >> shift) & 0x03;
  170449. *dp = (png_byte)value;
  170450. if (shift == 6)
  170451. {
  170452. shift = 0;
  170453. sp--;
  170454. }
  170455. else
  170456. shift += 2;
  170457. dp--;
  170458. }
  170459. break;
  170460. }
  170461. case 4:
  170462. {
  170463. sp = row + (png_size_t)((row_width - 1) >> 1);
  170464. dp = row + (png_size_t)row_width - 1;
  170465. shift = (int)((row_width & 0x01) << 2);
  170466. for (i = 0; i < row_width; i++)
  170467. {
  170468. value = (*sp >> shift) & 0x0f;
  170469. *dp = (png_byte)value;
  170470. if (shift == 4)
  170471. {
  170472. shift = 0;
  170473. sp--;
  170474. }
  170475. else
  170476. shift += 4;
  170477. dp--;
  170478. }
  170479. break;
  170480. }
  170481. }
  170482. row_info->bit_depth = 8;
  170483. row_info->pixel_depth = 8;
  170484. row_info->rowbytes = row_width;
  170485. }
  170486. switch (row_info->bit_depth)
  170487. {
  170488. case 8:
  170489. {
  170490. if (trans != NULL)
  170491. {
  170492. sp = row + (png_size_t)row_width - 1;
  170493. dp = row + (png_size_t)(row_width << 2) - 1;
  170494. for (i = 0; i < row_width; i++)
  170495. {
  170496. if ((int)(*sp) >= num_trans)
  170497. *dp-- = 0xff;
  170498. else
  170499. *dp-- = trans[*sp];
  170500. *dp-- = palette[*sp].blue;
  170501. *dp-- = palette[*sp].green;
  170502. *dp-- = palette[*sp].red;
  170503. sp--;
  170504. }
  170505. row_info->bit_depth = 8;
  170506. row_info->pixel_depth = 32;
  170507. row_info->rowbytes = row_width * 4;
  170508. row_info->color_type = 6;
  170509. row_info->channels = 4;
  170510. }
  170511. else
  170512. {
  170513. sp = row + (png_size_t)row_width - 1;
  170514. dp = row + (png_size_t)(row_width * 3) - 1;
  170515. for (i = 0; i < row_width; i++)
  170516. {
  170517. *dp-- = palette[*sp].blue;
  170518. *dp-- = palette[*sp].green;
  170519. *dp-- = palette[*sp].red;
  170520. sp--;
  170521. }
  170522. row_info->bit_depth = 8;
  170523. row_info->pixel_depth = 24;
  170524. row_info->rowbytes = row_width * 3;
  170525. row_info->color_type = 2;
  170526. row_info->channels = 3;
  170527. }
  170528. break;
  170529. }
  170530. }
  170531. }
  170532. }
  170533. void /* PRIVATE */
  170534. png_do_expand(png_row_infop row_info, png_bytep row,
  170535. png_color_16p trans_value)
  170536. {
  170537. int shift, value;
  170538. png_bytep sp, dp;
  170539. png_uint_32 i;
  170540. png_uint_32 row_width=row_info->width;
  170541. png_debug(1, "in png_do_expand\n");
  170542. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170543. if (row != NULL && row_info != NULL)
  170544. #endif
  170545. {
  170546. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170547. {
  170548. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170549. if (row_info->bit_depth < 8)
  170550. {
  170551. switch (row_info->bit_depth)
  170552. {
  170553. case 1:
  170554. {
  170555. gray = (png_uint_16)((gray&0x01)*0xff);
  170556. sp = row + (png_size_t)((row_width - 1) >> 3);
  170557. dp = row + (png_size_t)row_width - 1;
  170558. shift = 7 - (int)((row_width + 7) & 0x07);
  170559. for (i = 0; i < row_width; i++)
  170560. {
  170561. if ((*sp >> shift) & 0x01)
  170562. *dp = 0xff;
  170563. else
  170564. *dp = 0;
  170565. if (shift == 7)
  170566. {
  170567. shift = 0;
  170568. sp--;
  170569. }
  170570. else
  170571. shift++;
  170572. dp--;
  170573. }
  170574. break;
  170575. }
  170576. case 2:
  170577. {
  170578. gray = (png_uint_16)((gray&0x03)*0x55);
  170579. sp = row + (png_size_t)((row_width - 1) >> 2);
  170580. dp = row + (png_size_t)row_width - 1;
  170581. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170582. for (i = 0; i < row_width; i++)
  170583. {
  170584. value = (*sp >> shift) & 0x03;
  170585. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170586. (value << 6));
  170587. if (shift == 6)
  170588. {
  170589. shift = 0;
  170590. sp--;
  170591. }
  170592. else
  170593. shift += 2;
  170594. dp--;
  170595. }
  170596. break;
  170597. }
  170598. case 4:
  170599. {
  170600. gray = (png_uint_16)((gray&0x0f)*0x11);
  170601. sp = row + (png_size_t)((row_width - 1) >> 1);
  170602. dp = row + (png_size_t)row_width - 1;
  170603. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170604. for (i = 0; i < row_width; i++)
  170605. {
  170606. value = (*sp >> shift) & 0x0f;
  170607. *dp = (png_byte)(value | (value << 4));
  170608. if (shift == 4)
  170609. {
  170610. shift = 0;
  170611. sp--;
  170612. }
  170613. else
  170614. shift = 4;
  170615. dp--;
  170616. }
  170617. break;
  170618. }
  170619. }
  170620. row_info->bit_depth = 8;
  170621. row_info->pixel_depth = 8;
  170622. row_info->rowbytes = row_width;
  170623. }
  170624. if (trans_value != NULL)
  170625. {
  170626. if (row_info->bit_depth == 8)
  170627. {
  170628. gray = gray & 0xff;
  170629. sp = row + (png_size_t)row_width - 1;
  170630. dp = row + (png_size_t)(row_width << 1) - 1;
  170631. for (i = 0; i < row_width; i++)
  170632. {
  170633. if (*sp == gray)
  170634. *dp-- = 0;
  170635. else
  170636. *dp-- = 0xff;
  170637. *dp-- = *sp--;
  170638. }
  170639. }
  170640. else if (row_info->bit_depth == 16)
  170641. {
  170642. png_byte gray_high = (gray >> 8) & 0xff;
  170643. png_byte gray_low = gray & 0xff;
  170644. sp = row + row_info->rowbytes - 1;
  170645. dp = row + (row_info->rowbytes << 1) - 1;
  170646. for (i = 0; i < row_width; i++)
  170647. {
  170648. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170649. {
  170650. *dp-- = 0;
  170651. *dp-- = 0;
  170652. }
  170653. else
  170654. {
  170655. *dp-- = 0xff;
  170656. *dp-- = 0xff;
  170657. }
  170658. *dp-- = *sp--;
  170659. *dp-- = *sp--;
  170660. }
  170661. }
  170662. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170663. row_info->channels = 2;
  170664. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170665. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170666. row_width);
  170667. }
  170668. }
  170669. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170670. {
  170671. if (row_info->bit_depth == 8)
  170672. {
  170673. png_byte red = trans_value->red & 0xff;
  170674. png_byte green = trans_value->green & 0xff;
  170675. png_byte blue = trans_value->blue & 0xff;
  170676. sp = row + (png_size_t)row_info->rowbytes - 1;
  170677. dp = row + (png_size_t)(row_width << 2) - 1;
  170678. for (i = 0; i < row_width; i++)
  170679. {
  170680. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170681. *dp-- = 0;
  170682. else
  170683. *dp-- = 0xff;
  170684. *dp-- = *sp--;
  170685. *dp-- = *sp--;
  170686. *dp-- = *sp--;
  170687. }
  170688. }
  170689. else if (row_info->bit_depth == 16)
  170690. {
  170691. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170692. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170693. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170694. png_byte red_low = trans_value->red & 0xff;
  170695. png_byte green_low = trans_value->green & 0xff;
  170696. png_byte blue_low = trans_value->blue & 0xff;
  170697. sp = row + row_info->rowbytes - 1;
  170698. dp = row + (png_size_t)(row_width << 3) - 1;
  170699. for (i = 0; i < row_width; i++)
  170700. {
  170701. if (*(sp - 5) == red_high &&
  170702. *(sp - 4) == red_low &&
  170703. *(sp - 3) == green_high &&
  170704. *(sp - 2) == green_low &&
  170705. *(sp - 1) == blue_high &&
  170706. *(sp ) == blue_low)
  170707. {
  170708. *dp-- = 0;
  170709. *dp-- = 0;
  170710. }
  170711. else
  170712. {
  170713. *dp-- = 0xff;
  170714. *dp-- = 0xff;
  170715. }
  170716. *dp-- = *sp--;
  170717. *dp-- = *sp--;
  170718. *dp-- = *sp--;
  170719. *dp-- = *sp--;
  170720. *dp-- = *sp--;
  170721. *dp-- = *sp--;
  170722. }
  170723. }
  170724. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170725. row_info->channels = 4;
  170726. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170727. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170728. }
  170729. }
  170730. }
  170731. #endif
  170732. #if defined(PNG_READ_DITHER_SUPPORTED)
  170733. void /* PRIVATE */
  170734. png_do_dither(png_row_infop row_info, png_bytep row,
  170735. png_bytep palette_lookup, png_bytep dither_lookup)
  170736. {
  170737. png_bytep sp, dp;
  170738. png_uint_32 i;
  170739. png_uint_32 row_width=row_info->width;
  170740. png_debug(1, "in png_do_dither\n");
  170741. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170742. if (row != NULL && row_info != NULL)
  170743. #endif
  170744. {
  170745. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170746. palette_lookup && row_info->bit_depth == 8)
  170747. {
  170748. int r, g, b, p;
  170749. sp = row;
  170750. dp = row;
  170751. for (i = 0; i < row_width; i++)
  170752. {
  170753. r = *sp++;
  170754. g = *sp++;
  170755. b = *sp++;
  170756. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170757. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170758. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170759. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170760. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170761. (PNG_DITHER_BLUE_BITS)) |
  170762. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170763. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170764. *dp++ = palette_lookup[p];
  170765. }
  170766. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170767. row_info->channels = 1;
  170768. row_info->pixel_depth = row_info->bit_depth;
  170769. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170770. }
  170771. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170772. palette_lookup != NULL && row_info->bit_depth == 8)
  170773. {
  170774. int r, g, b, p;
  170775. sp = row;
  170776. dp = row;
  170777. for (i = 0; i < row_width; i++)
  170778. {
  170779. r = *sp++;
  170780. g = *sp++;
  170781. b = *sp++;
  170782. sp++;
  170783. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170784. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170785. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170786. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170787. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170788. (PNG_DITHER_BLUE_BITS)) |
  170789. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170790. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170791. *dp++ = palette_lookup[p];
  170792. }
  170793. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170794. row_info->channels = 1;
  170795. row_info->pixel_depth = row_info->bit_depth;
  170796. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170797. }
  170798. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170799. dither_lookup && row_info->bit_depth == 8)
  170800. {
  170801. sp = row;
  170802. for (i = 0; i < row_width; i++, sp++)
  170803. {
  170804. *sp = dither_lookup[*sp];
  170805. }
  170806. }
  170807. }
  170808. }
  170809. #endif
  170810. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170811. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170812. static PNG_CONST int png_gamma_shift[] =
  170813. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170814. void /* PRIVATE */
  170815. png_build_gamma_table(png_structp png_ptr)
  170816. {
  170817. png_debug(1, "in png_build_gamma_table\n");
  170818. if (png_ptr->bit_depth <= 8)
  170819. {
  170820. int i;
  170821. double g;
  170822. if (png_ptr->screen_gamma > .000001)
  170823. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170824. else
  170825. g = 1.0;
  170826. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170827. (png_uint_32)256);
  170828. for (i = 0; i < 256; i++)
  170829. {
  170830. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170831. g) * 255.0 + .5);
  170832. }
  170833. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170834. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170835. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170836. {
  170837. g = 1.0 / (png_ptr->gamma);
  170838. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170839. (png_uint_32)256);
  170840. for (i = 0; i < 256; i++)
  170841. {
  170842. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170843. g) * 255.0 + .5);
  170844. }
  170845. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170846. (png_uint_32)256);
  170847. if(png_ptr->screen_gamma > 0.000001)
  170848. g = 1.0 / png_ptr->screen_gamma;
  170849. else
  170850. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170851. for (i = 0; i < 256; i++)
  170852. {
  170853. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170854. g) * 255.0 + .5);
  170855. }
  170856. }
  170857. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170858. }
  170859. else
  170860. {
  170861. double g;
  170862. int i, j, shift, num;
  170863. int sig_bit;
  170864. png_uint_32 ig;
  170865. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170866. {
  170867. sig_bit = (int)png_ptr->sig_bit.red;
  170868. if ((int)png_ptr->sig_bit.green > sig_bit)
  170869. sig_bit = png_ptr->sig_bit.green;
  170870. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170871. sig_bit = png_ptr->sig_bit.blue;
  170872. }
  170873. else
  170874. {
  170875. sig_bit = (int)png_ptr->sig_bit.gray;
  170876. }
  170877. if (sig_bit > 0)
  170878. shift = 16 - sig_bit;
  170879. else
  170880. shift = 0;
  170881. if (png_ptr->transformations & PNG_16_TO_8)
  170882. {
  170883. if (shift < (16 - PNG_MAX_GAMMA_8))
  170884. shift = (16 - PNG_MAX_GAMMA_8);
  170885. }
  170886. if (shift > 8)
  170887. shift = 8;
  170888. if (shift < 0)
  170889. shift = 0;
  170890. png_ptr->gamma_shift = (png_byte)shift;
  170891. num = (1 << (8 - shift));
  170892. if (png_ptr->screen_gamma > .000001)
  170893. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170894. else
  170895. g = 1.0;
  170896. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170897. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170898. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170899. {
  170900. double fin, fout;
  170901. png_uint_32 last, max;
  170902. for (i = 0; i < num; i++)
  170903. {
  170904. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170905. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170906. }
  170907. g = 1.0 / g;
  170908. last = 0;
  170909. for (i = 0; i < 256; i++)
  170910. {
  170911. fout = ((double)i + 0.5) / 256.0;
  170912. fin = pow(fout, g);
  170913. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170914. while (last <= max)
  170915. {
  170916. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170917. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170918. (png_uint_16)i | ((png_uint_16)i << 8));
  170919. last++;
  170920. }
  170921. }
  170922. while (last < ((png_uint_32)num << 8))
  170923. {
  170924. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170925. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170926. last++;
  170927. }
  170928. }
  170929. else
  170930. {
  170931. for (i = 0; i < num; i++)
  170932. {
  170933. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170934. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170935. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170936. for (j = 0; j < 256; j++)
  170937. {
  170938. png_ptr->gamma_16_table[i][j] =
  170939. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170940. 65535.0, g) * 65535.0 + .5);
  170941. }
  170942. }
  170943. }
  170944. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170945. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170946. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170947. {
  170948. g = 1.0 / (png_ptr->gamma);
  170949. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170950. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170951. for (i = 0; i < num; i++)
  170952. {
  170953. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170954. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170955. ig = (((png_uint_32)i *
  170956. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170957. for (j = 0; j < 256; j++)
  170958. {
  170959. png_ptr->gamma_16_to_1[i][j] =
  170960. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170961. 65535.0, g) * 65535.0 + .5);
  170962. }
  170963. }
  170964. if(png_ptr->screen_gamma > 0.000001)
  170965. g = 1.0 / png_ptr->screen_gamma;
  170966. else
  170967. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170968. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170969. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170970. for (i = 0; i < num; i++)
  170971. {
  170972. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170973. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170974. ig = (((png_uint_32)i *
  170975. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170976. for (j = 0; j < 256; j++)
  170977. {
  170978. png_ptr->gamma_16_from_1[i][j] =
  170979. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170980. 65535.0, g) * 65535.0 + .5);
  170981. }
  170982. }
  170983. }
  170984. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170985. }
  170986. }
  170987. #endif
  170988. #endif
  170989. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170990. void /* PRIVATE */
  170991. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170992. {
  170993. png_debug(1, "in png_do_read_intrapixel\n");
  170994. if (
  170995. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170996. row != NULL && row_info != NULL &&
  170997. #endif
  170998. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170999. {
  171000. int bytes_per_pixel;
  171001. png_uint_32 row_width = row_info->width;
  171002. if (row_info->bit_depth == 8)
  171003. {
  171004. png_bytep rp;
  171005. png_uint_32 i;
  171006. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171007. bytes_per_pixel = 3;
  171008. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171009. bytes_per_pixel = 4;
  171010. else
  171011. return;
  171012. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171013. {
  171014. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  171015. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  171016. }
  171017. }
  171018. else if (row_info->bit_depth == 16)
  171019. {
  171020. png_bytep rp;
  171021. png_uint_32 i;
  171022. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171023. bytes_per_pixel = 6;
  171024. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171025. bytes_per_pixel = 8;
  171026. else
  171027. return;
  171028. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171029. {
  171030. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  171031. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  171032. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  171033. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  171034. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  171035. *(rp ) = (png_byte)((red >> 8) & 0xff);
  171036. *(rp+1) = (png_byte)(red & 0xff);
  171037. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  171038. *(rp+5) = (png_byte)(blue & 0xff);
  171039. }
  171040. }
  171041. }
  171042. }
  171043. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  171044. #endif /* PNG_READ_SUPPORTED */
  171045. /*** End of inlined file: pngrtran.c ***/
  171046. /*** Start of inlined file: pngrutil.c ***/
  171047. #define PNG_INTERNAL
  171048. #if defined(PNG_READ_SUPPORTED)
  171049. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  171050. # define WIN32_WCE_OLD
  171051. #endif
  171052. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171053. # if defined(WIN32_WCE_OLD)
  171054. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  171055. {
  171056. double result = 0;
  171057. int len;
  171058. wchar_t *str, *end;
  171059. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  171060. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  171061. if ( NULL != str )
  171062. {
  171063. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  171064. result = wcstod(str, &end);
  171065. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  171066. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  171067. png_free(png_ptr, str);
  171068. }
  171069. return result;
  171070. }
  171071. # else
  171072. # define png_strtod(p,a,b) strtod(a,b)
  171073. # endif
  171074. #endif
  171075. png_uint_32 PNGAPI
  171076. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  171077. {
  171078. png_uint_32 i = png_get_uint_32(buf);
  171079. if (i > PNG_UINT_31_MAX)
  171080. png_error(png_ptr, "PNG unsigned integer out of range.");
  171081. return (i);
  171082. }
  171083. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  171084. png_uint_32 PNGAPI
  171085. png_get_uint_32(png_bytep buf)
  171086. {
  171087. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  171088. ((png_uint_32)(*(buf + 1)) << 16) +
  171089. ((png_uint_32)(*(buf + 2)) << 8) +
  171090. (png_uint_32)(*(buf + 3));
  171091. return (i);
  171092. }
  171093. png_int_32 PNGAPI
  171094. png_get_int_32(png_bytep buf)
  171095. {
  171096. png_int_32 i = ((png_int_32)(*buf) << 24) +
  171097. ((png_int_32)(*(buf + 1)) << 16) +
  171098. ((png_int_32)(*(buf + 2)) << 8) +
  171099. (png_int_32)(*(buf + 3));
  171100. return (i);
  171101. }
  171102. png_uint_16 PNGAPI
  171103. png_get_uint_16(png_bytep buf)
  171104. {
  171105. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  171106. (png_uint_16)(*(buf + 1)));
  171107. return (i);
  171108. }
  171109. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  171110. void /* PRIVATE */
  171111. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  171112. {
  171113. if(png_ptr == NULL) return;
  171114. png_read_data(png_ptr, buf, length);
  171115. png_calculate_crc(png_ptr, buf, length);
  171116. }
  171117. int /* PRIVATE */
  171118. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  171119. {
  171120. png_size_t i;
  171121. png_size_t istop = png_ptr->zbuf_size;
  171122. for (i = (png_size_t)skip; i > istop; i -= istop)
  171123. {
  171124. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  171125. }
  171126. if (i)
  171127. {
  171128. png_crc_read(png_ptr, png_ptr->zbuf, i);
  171129. }
  171130. if (png_crc_error(png_ptr))
  171131. {
  171132. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  171133. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  171134. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  171135. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  171136. {
  171137. png_chunk_warning(png_ptr, "CRC error");
  171138. }
  171139. else
  171140. {
  171141. png_chunk_error(png_ptr, "CRC error");
  171142. }
  171143. return (1);
  171144. }
  171145. return (0);
  171146. }
  171147. int /* PRIVATE */
  171148. png_crc_error(png_structp png_ptr)
  171149. {
  171150. png_byte crc_bytes[4];
  171151. png_uint_32 crc;
  171152. int need_crc = 1;
  171153. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  171154. {
  171155. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  171156. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171157. need_crc = 0;
  171158. }
  171159. else /* critical */
  171160. {
  171161. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  171162. need_crc = 0;
  171163. }
  171164. png_read_data(png_ptr, crc_bytes, 4);
  171165. if (need_crc)
  171166. {
  171167. crc = png_get_uint_32(crc_bytes);
  171168. return ((int)(crc != png_ptr->crc));
  171169. }
  171170. else
  171171. return (0);
  171172. }
  171173. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  171174. defined(PNG_READ_iCCP_SUPPORTED)
  171175. png_charp /* PRIVATE */
  171176. png_decompress_chunk(png_structp png_ptr, int comp_type,
  171177. png_charp chunkdata, png_size_t chunklength,
  171178. png_size_t prefix_size, png_size_t *newlength)
  171179. {
  171180. static PNG_CONST char msg[] = "Error decoding compressed text";
  171181. png_charp text;
  171182. png_size_t text_size;
  171183. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  171184. {
  171185. int ret = Z_OK;
  171186. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  171187. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  171188. png_ptr->zstream.next_out = png_ptr->zbuf;
  171189. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171190. text_size = 0;
  171191. text = NULL;
  171192. while (png_ptr->zstream.avail_in)
  171193. {
  171194. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  171195. if (ret != Z_OK && ret != Z_STREAM_END)
  171196. {
  171197. if (png_ptr->zstream.msg != NULL)
  171198. png_warning(png_ptr, png_ptr->zstream.msg);
  171199. else
  171200. png_warning(png_ptr, msg);
  171201. inflateReset(&png_ptr->zstream);
  171202. png_ptr->zstream.avail_in = 0;
  171203. if (text == NULL)
  171204. {
  171205. text_size = prefix_size + png_sizeof(msg) + 1;
  171206. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  171207. if (text == NULL)
  171208. {
  171209. png_free(png_ptr,chunkdata);
  171210. png_error(png_ptr,"Not enough memory to decompress chunk");
  171211. }
  171212. png_memcpy(text, chunkdata, prefix_size);
  171213. }
  171214. text[text_size - 1] = 0x00;
  171215. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  171216. text_size = png_sizeof(msg) > text_size ? text_size :
  171217. png_sizeof(msg);
  171218. png_memcpy(text + prefix_size, msg, text_size + 1);
  171219. break;
  171220. }
  171221. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  171222. {
  171223. if (text == NULL)
  171224. {
  171225. text_size = prefix_size +
  171226. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171227. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  171228. if (text == NULL)
  171229. {
  171230. png_free(png_ptr,chunkdata);
  171231. png_error(png_ptr,"Not enough memory to decompress chunk.");
  171232. }
  171233. png_memcpy(text + prefix_size, png_ptr->zbuf,
  171234. text_size - prefix_size);
  171235. png_memcpy(text, chunkdata, prefix_size);
  171236. *(text + text_size) = 0x00;
  171237. }
  171238. else
  171239. {
  171240. png_charp tmp;
  171241. tmp = text;
  171242. text = (png_charp)png_malloc_warn(png_ptr,
  171243. (png_uint_32)(text_size +
  171244. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  171245. if (text == NULL)
  171246. {
  171247. png_free(png_ptr, tmp);
  171248. png_free(png_ptr, chunkdata);
  171249. png_error(png_ptr,"Not enough memory to decompress chunk..");
  171250. }
  171251. png_memcpy(text, tmp, text_size);
  171252. png_free(png_ptr, tmp);
  171253. png_memcpy(text + text_size, png_ptr->zbuf,
  171254. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  171255. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171256. *(text + text_size) = 0x00;
  171257. }
  171258. if (ret == Z_STREAM_END)
  171259. break;
  171260. else
  171261. {
  171262. png_ptr->zstream.next_out = png_ptr->zbuf;
  171263. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171264. }
  171265. }
  171266. }
  171267. if (ret != Z_STREAM_END)
  171268. {
  171269. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171270. char umsg[52];
  171271. if (ret == Z_BUF_ERROR)
  171272. png_snprintf(umsg, 52,
  171273. "Buffer error in compressed datastream in %s chunk",
  171274. png_ptr->chunk_name);
  171275. else if (ret == Z_DATA_ERROR)
  171276. png_snprintf(umsg, 52,
  171277. "Data error in compressed datastream in %s chunk",
  171278. png_ptr->chunk_name);
  171279. else
  171280. png_snprintf(umsg, 52,
  171281. "Incomplete compressed datastream in %s chunk",
  171282. png_ptr->chunk_name);
  171283. png_warning(png_ptr, umsg);
  171284. #else
  171285. png_warning(png_ptr,
  171286. "Incomplete compressed datastream in chunk other than IDAT");
  171287. #endif
  171288. text_size=prefix_size;
  171289. if (text == NULL)
  171290. {
  171291. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  171292. if (text == NULL)
  171293. {
  171294. png_free(png_ptr, chunkdata);
  171295. png_error(png_ptr,"Not enough memory for text.");
  171296. }
  171297. png_memcpy(text, chunkdata, prefix_size);
  171298. }
  171299. *(text + text_size) = 0x00;
  171300. }
  171301. inflateReset(&png_ptr->zstream);
  171302. png_ptr->zstream.avail_in = 0;
  171303. png_free(png_ptr, chunkdata);
  171304. chunkdata = text;
  171305. *newlength=text_size;
  171306. }
  171307. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171308. {
  171309. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171310. char umsg[50];
  171311. png_snprintf(umsg, 50,
  171312. "Unknown zTXt compression type %d", comp_type);
  171313. png_warning(png_ptr, umsg);
  171314. #else
  171315. png_warning(png_ptr, "Unknown zTXt compression type");
  171316. #endif
  171317. *(chunkdata + prefix_size) = 0x00;
  171318. *newlength=prefix_size;
  171319. }
  171320. return chunkdata;
  171321. }
  171322. #endif
  171323. void /* PRIVATE */
  171324. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171325. {
  171326. png_byte buf[13];
  171327. png_uint_32 width, height;
  171328. int bit_depth, color_type, compression_type, filter_type;
  171329. int interlace_type;
  171330. png_debug(1, "in png_handle_IHDR\n");
  171331. if (png_ptr->mode & PNG_HAVE_IHDR)
  171332. png_error(png_ptr, "Out of place IHDR");
  171333. if (length != 13)
  171334. png_error(png_ptr, "Invalid IHDR chunk");
  171335. png_ptr->mode |= PNG_HAVE_IHDR;
  171336. png_crc_read(png_ptr, buf, 13);
  171337. png_crc_finish(png_ptr, 0);
  171338. width = png_get_uint_31(png_ptr, buf);
  171339. height = png_get_uint_31(png_ptr, buf + 4);
  171340. bit_depth = buf[8];
  171341. color_type = buf[9];
  171342. compression_type = buf[10];
  171343. filter_type = buf[11];
  171344. interlace_type = buf[12];
  171345. png_ptr->width = width;
  171346. png_ptr->height = height;
  171347. png_ptr->bit_depth = (png_byte)bit_depth;
  171348. png_ptr->interlaced = (png_byte)interlace_type;
  171349. png_ptr->color_type = (png_byte)color_type;
  171350. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171351. png_ptr->filter_type = (png_byte)filter_type;
  171352. #endif
  171353. png_ptr->compression_type = (png_byte)compression_type;
  171354. switch (png_ptr->color_type)
  171355. {
  171356. case PNG_COLOR_TYPE_GRAY:
  171357. case PNG_COLOR_TYPE_PALETTE:
  171358. png_ptr->channels = 1;
  171359. break;
  171360. case PNG_COLOR_TYPE_RGB:
  171361. png_ptr->channels = 3;
  171362. break;
  171363. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171364. png_ptr->channels = 2;
  171365. break;
  171366. case PNG_COLOR_TYPE_RGB_ALPHA:
  171367. png_ptr->channels = 4;
  171368. break;
  171369. }
  171370. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171371. png_ptr->channels);
  171372. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171373. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171374. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171375. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171376. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171377. color_type, interlace_type, compression_type, filter_type);
  171378. }
  171379. void /* PRIVATE */
  171380. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171381. {
  171382. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171383. int num, i;
  171384. #ifndef PNG_NO_POINTER_INDEXING
  171385. png_colorp pal_ptr;
  171386. #endif
  171387. png_debug(1, "in png_handle_PLTE\n");
  171388. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171389. png_error(png_ptr, "Missing IHDR before PLTE");
  171390. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171391. {
  171392. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171393. png_crc_finish(png_ptr, length);
  171394. return;
  171395. }
  171396. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171397. png_error(png_ptr, "Duplicate PLTE chunk");
  171398. png_ptr->mode |= PNG_HAVE_PLTE;
  171399. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171400. {
  171401. png_warning(png_ptr,
  171402. "Ignoring PLTE chunk in grayscale PNG");
  171403. png_crc_finish(png_ptr, length);
  171404. return;
  171405. }
  171406. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171407. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171408. {
  171409. png_crc_finish(png_ptr, length);
  171410. return;
  171411. }
  171412. #endif
  171413. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171414. {
  171415. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171416. {
  171417. png_warning(png_ptr, "Invalid palette chunk");
  171418. png_crc_finish(png_ptr, length);
  171419. return;
  171420. }
  171421. else
  171422. {
  171423. png_error(png_ptr, "Invalid palette chunk");
  171424. }
  171425. }
  171426. num = (int)length / 3;
  171427. #ifndef PNG_NO_POINTER_INDEXING
  171428. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171429. {
  171430. png_byte buf[3];
  171431. png_crc_read(png_ptr, buf, 3);
  171432. pal_ptr->red = buf[0];
  171433. pal_ptr->green = buf[1];
  171434. pal_ptr->blue = buf[2];
  171435. }
  171436. #else
  171437. for (i = 0; i < num; i++)
  171438. {
  171439. png_byte buf[3];
  171440. png_crc_read(png_ptr, buf, 3);
  171441. palette[i].red = buf[0];
  171442. palette[i].green = buf[1];
  171443. palette[i].blue = buf[2];
  171444. }
  171445. #endif
  171446. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171447. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171448. #endif
  171449. {
  171450. png_crc_finish(png_ptr, 0);
  171451. }
  171452. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171453. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171454. {
  171455. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171456. {
  171457. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171458. {
  171459. png_chunk_error(png_ptr, "CRC error");
  171460. }
  171461. else
  171462. {
  171463. png_chunk_warning(png_ptr, "CRC error");
  171464. return;
  171465. }
  171466. }
  171467. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171468. {
  171469. png_chunk_warning(png_ptr, "CRC error");
  171470. }
  171471. }
  171472. #endif
  171473. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171474. #if defined(PNG_READ_tRNS_SUPPORTED)
  171475. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171476. {
  171477. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171478. {
  171479. if (png_ptr->num_trans > (png_uint_16)num)
  171480. {
  171481. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171482. png_ptr->num_trans = (png_uint_16)num;
  171483. }
  171484. if (info_ptr->num_trans > (png_uint_16)num)
  171485. {
  171486. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171487. info_ptr->num_trans = (png_uint_16)num;
  171488. }
  171489. }
  171490. }
  171491. #endif
  171492. }
  171493. void /* PRIVATE */
  171494. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171495. {
  171496. png_debug(1, "in png_handle_IEND\n");
  171497. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171498. {
  171499. png_error(png_ptr, "No image in file");
  171500. }
  171501. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171502. if (length != 0)
  171503. {
  171504. png_warning(png_ptr, "Incorrect IEND chunk length");
  171505. }
  171506. png_crc_finish(png_ptr, length);
  171507. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171508. }
  171509. #if defined(PNG_READ_gAMA_SUPPORTED)
  171510. void /* PRIVATE */
  171511. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171512. {
  171513. png_fixed_point igamma;
  171514. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171515. float file_gamma;
  171516. #endif
  171517. png_byte buf[4];
  171518. png_debug(1, "in png_handle_gAMA\n");
  171519. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171520. png_error(png_ptr, "Missing IHDR before gAMA");
  171521. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171522. {
  171523. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171524. png_crc_finish(png_ptr, length);
  171525. return;
  171526. }
  171527. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171528. png_warning(png_ptr, "Out of place gAMA chunk");
  171529. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171530. #if defined(PNG_READ_sRGB_SUPPORTED)
  171531. && !(info_ptr->valid & PNG_INFO_sRGB)
  171532. #endif
  171533. )
  171534. {
  171535. png_warning(png_ptr, "Duplicate gAMA chunk");
  171536. png_crc_finish(png_ptr, length);
  171537. return;
  171538. }
  171539. if (length != 4)
  171540. {
  171541. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171542. png_crc_finish(png_ptr, length);
  171543. return;
  171544. }
  171545. png_crc_read(png_ptr, buf, 4);
  171546. if (png_crc_finish(png_ptr, 0))
  171547. return;
  171548. igamma = (png_fixed_point)png_get_uint_32(buf);
  171549. if (igamma == 0)
  171550. {
  171551. png_warning(png_ptr,
  171552. "Ignoring gAMA chunk with gamma=0");
  171553. return;
  171554. }
  171555. #if defined(PNG_READ_sRGB_SUPPORTED)
  171556. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171557. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171558. {
  171559. png_warning(png_ptr,
  171560. "Ignoring incorrect gAMA value when sRGB is also present");
  171561. #ifndef PNG_NO_CONSOLE_IO
  171562. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171563. #endif
  171564. return;
  171565. }
  171566. #endif /* PNG_READ_sRGB_SUPPORTED */
  171567. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171568. file_gamma = (float)igamma / (float)100000.0;
  171569. # ifdef PNG_READ_GAMMA_SUPPORTED
  171570. png_ptr->gamma = file_gamma;
  171571. # endif
  171572. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171573. #endif
  171574. #ifdef PNG_FIXED_POINT_SUPPORTED
  171575. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171576. #endif
  171577. }
  171578. #endif
  171579. #if defined(PNG_READ_sBIT_SUPPORTED)
  171580. void /* PRIVATE */
  171581. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171582. {
  171583. png_size_t truelen;
  171584. png_byte buf[4];
  171585. png_debug(1, "in png_handle_sBIT\n");
  171586. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171587. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171588. png_error(png_ptr, "Missing IHDR before sBIT");
  171589. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171590. {
  171591. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171592. png_crc_finish(png_ptr, length);
  171593. return;
  171594. }
  171595. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171596. {
  171597. png_warning(png_ptr, "Out of place sBIT chunk");
  171598. }
  171599. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171600. {
  171601. png_warning(png_ptr, "Duplicate sBIT chunk");
  171602. png_crc_finish(png_ptr, length);
  171603. return;
  171604. }
  171605. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171606. truelen = 3;
  171607. else
  171608. truelen = (png_size_t)png_ptr->channels;
  171609. if (length != truelen || length > 4)
  171610. {
  171611. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171612. png_crc_finish(png_ptr, length);
  171613. return;
  171614. }
  171615. png_crc_read(png_ptr, buf, truelen);
  171616. if (png_crc_finish(png_ptr, 0))
  171617. return;
  171618. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171619. {
  171620. png_ptr->sig_bit.red = buf[0];
  171621. png_ptr->sig_bit.green = buf[1];
  171622. png_ptr->sig_bit.blue = buf[2];
  171623. png_ptr->sig_bit.alpha = buf[3];
  171624. }
  171625. else
  171626. {
  171627. png_ptr->sig_bit.gray = buf[0];
  171628. png_ptr->sig_bit.red = buf[0];
  171629. png_ptr->sig_bit.green = buf[0];
  171630. png_ptr->sig_bit.blue = buf[0];
  171631. png_ptr->sig_bit.alpha = buf[1];
  171632. }
  171633. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171634. }
  171635. #endif
  171636. #if defined(PNG_READ_cHRM_SUPPORTED)
  171637. void /* PRIVATE */
  171638. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171639. {
  171640. png_byte buf[4];
  171641. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171642. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171643. #endif
  171644. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171645. int_y_green, int_x_blue, int_y_blue;
  171646. png_uint_32 uint_x, uint_y;
  171647. png_debug(1, "in png_handle_cHRM\n");
  171648. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171649. png_error(png_ptr, "Missing IHDR before cHRM");
  171650. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171651. {
  171652. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171653. png_crc_finish(png_ptr, length);
  171654. return;
  171655. }
  171656. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171657. png_warning(png_ptr, "Missing PLTE before cHRM");
  171658. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171659. #if defined(PNG_READ_sRGB_SUPPORTED)
  171660. && !(info_ptr->valid & PNG_INFO_sRGB)
  171661. #endif
  171662. )
  171663. {
  171664. png_warning(png_ptr, "Duplicate cHRM chunk");
  171665. png_crc_finish(png_ptr, length);
  171666. return;
  171667. }
  171668. if (length != 32)
  171669. {
  171670. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171671. png_crc_finish(png_ptr, length);
  171672. return;
  171673. }
  171674. png_crc_read(png_ptr, buf, 4);
  171675. uint_x = png_get_uint_32(buf);
  171676. png_crc_read(png_ptr, buf, 4);
  171677. uint_y = png_get_uint_32(buf);
  171678. if (uint_x > 80000L || uint_y > 80000L ||
  171679. uint_x + uint_y > 100000L)
  171680. {
  171681. png_warning(png_ptr, "Invalid cHRM white point");
  171682. png_crc_finish(png_ptr, 24);
  171683. return;
  171684. }
  171685. int_x_white = (png_fixed_point)uint_x;
  171686. int_y_white = (png_fixed_point)uint_y;
  171687. png_crc_read(png_ptr, buf, 4);
  171688. uint_x = png_get_uint_32(buf);
  171689. png_crc_read(png_ptr, buf, 4);
  171690. uint_y = png_get_uint_32(buf);
  171691. if (uint_x + uint_y > 100000L)
  171692. {
  171693. png_warning(png_ptr, "Invalid cHRM red point");
  171694. png_crc_finish(png_ptr, 16);
  171695. return;
  171696. }
  171697. int_x_red = (png_fixed_point)uint_x;
  171698. int_y_red = (png_fixed_point)uint_y;
  171699. png_crc_read(png_ptr, buf, 4);
  171700. uint_x = png_get_uint_32(buf);
  171701. png_crc_read(png_ptr, buf, 4);
  171702. uint_y = png_get_uint_32(buf);
  171703. if (uint_x + uint_y > 100000L)
  171704. {
  171705. png_warning(png_ptr, "Invalid cHRM green point");
  171706. png_crc_finish(png_ptr, 8);
  171707. return;
  171708. }
  171709. int_x_green = (png_fixed_point)uint_x;
  171710. int_y_green = (png_fixed_point)uint_y;
  171711. png_crc_read(png_ptr, buf, 4);
  171712. uint_x = png_get_uint_32(buf);
  171713. png_crc_read(png_ptr, buf, 4);
  171714. uint_y = png_get_uint_32(buf);
  171715. if (uint_x + uint_y > 100000L)
  171716. {
  171717. png_warning(png_ptr, "Invalid cHRM blue point");
  171718. png_crc_finish(png_ptr, 0);
  171719. return;
  171720. }
  171721. int_x_blue = (png_fixed_point)uint_x;
  171722. int_y_blue = (png_fixed_point)uint_y;
  171723. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171724. white_x = (float)int_x_white / (float)100000.0;
  171725. white_y = (float)int_y_white / (float)100000.0;
  171726. red_x = (float)int_x_red / (float)100000.0;
  171727. red_y = (float)int_y_red / (float)100000.0;
  171728. green_x = (float)int_x_green / (float)100000.0;
  171729. green_y = (float)int_y_green / (float)100000.0;
  171730. blue_x = (float)int_x_blue / (float)100000.0;
  171731. blue_y = (float)int_y_blue / (float)100000.0;
  171732. #endif
  171733. #if defined(PNG_READ_sRGB_SUPPORTED)
  171734. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171735. {
  171736. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171737. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171738. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171739. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171740. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171741. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171742. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171743. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171744. {
  171745. png_warning(png_ptr,
  171746. "Ignoring incorrect cHRM value when sRGB is also present");
  171747. #ifndef PNG_NO_CONSOLE_IO
  171748. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171749. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171750. white_x, white_y, red_x, red_y);
  171751. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171752. green_x, green_y, blue_x, blue_y);
  171753. #else
  171754. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171755. int_x_white, int_y_white, int_x_red, int_y_red);
  171756. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171757. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171758. #endif
  171759. #endif /* PNG_NO_CONSOLE_IO */
  171760. }
  171761. png_crc_finish(png_ptr, 0);
  171762. return;
  171763. }
  171764. #endif /* PNG_READ_sRGB_SUPPORTED */
  171765. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171766. png_set_cHRM(png_ptr, info_ptr,
  171767. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171768. #endif
  171769. #ifdef PNG_FIXED_POINT_SUPPORTED
  171770. png_set_cHRM_fixed(png_ptr, info_ptr,
  171771. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171772. int_y_green, int_x_blue, int_y_blue);
  171773. #endif
  171774. if (png_crc_finish(png_ptr, 0))
  171775. return;
  171776. }
  171777. #endif
  171778. #if defined(PNG_READ_sRGB_SUPPORTED)
  171779. void /* PRIVATE */
  171780. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171781. {
  171782. int intent;
  171783. png_byte buf[1];
  171784. png_debug(1, "in png_handle_sRGB\n");
  171785. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171786. png_error(png_ptr, "Missing IHDR before sRGB");
  171787. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171788. {
  171789. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171790. png_crc_finish(png_ptr, length);
  171791. return;
  171792. }
  171793. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171794. png_warning(png_ptr, "Out of place sRGB chunk");
  171795. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171796. {
  171797. png_warning(png_ptr, "Duplicate sRGB chunk");
  171798. png_crc_finish(png_ptr, length);
  171799. return;
  171800. }
  171801. if (length != 1)
  171802. {
  171803. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171804. png_crc_finish(png_ptr, length);
  171805. return;
  171806. }
  171807. png_crc_read(png_ptr, buf, 1);
  171808. if (png_crc_finish(png_ptr, 0))
  171809. return;
  171810. intent = buf[0];
  171811. if (intent >= PNG_sRGB_INTENT_LAST)
  171812. {
  171813. png_warning(png_ptr, "Unknown sRGB intent");
  171814. return;
  171815. }
  171816. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171817. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171818. {
  171819. png_fixed_point igamma;
  171820. #ifdef PNG_FIXED_POINT_SUPPORTED
  171821. igamma=info_ptr->int_gamma;
  171822. #else
  171823. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171824. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171825. # endif
  171826. #endif
  171827. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171828. {
  171829. png_warning(png_ptr,
  171830. "Ignoring incorrect gAMA value when sRGB is also present");
  171831. #ifndef PNG_NO_CONSOLE_IO
  171832. # ifdef PNG_FIXED_POINT_SUPPORTED
  171833. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171834. # else
  171835. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171836. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171837. # endif
  171838. # endif
  171839. #endif
  171840. }
  171841. }
  171842. #endif /* PNG_READ_gAMA_SUPPORTED */
  171843. #ifdef PNG_READ_cHRM_SUPPORTED
  171844. #ifdef PNG_FIXED_POINT_SUPPORTED
  171845. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171846. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171847. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171848. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171849. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171850. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171851. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171852. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171853. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171854. {
  171855. png_warning(png_ptr,
  171856. "Ignoring incorrect cHRM value when sRGB is also present");
  171857. }
  171858. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171859. #endif /* PNG_READ_cHRM_SUPPORTED */
  171860. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171861. }
  171862. #endif /* PNG_READ_sRGB_SUPPORTED */
  171863. #if defined(PNG_READ_iCCP_SUPPORTED)
  171864. void /* PRIVATE */
  171865. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171866. {
  171867. png_charp chunkdata;
  171868. png_byte compression_type;
  171869. png_bytep pC;
  171870. png_charp profile;
  171871. png_uint_32 skip = 0;
  171872. png_uint_32 profile_size, profile_length;
  171873. png_size_t slength, prefix_length, data_length;
  171874. png_debug(1, "in png_handle_iCCP\n");
  171875. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171876. png_error(png_ptr, "Missing IHDR before iCCP");
  171877. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171878. {
  171879. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171880. png_crc_finish(png_ptr, length);
  171881. return;
  171882. }
  171883. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171884. png_warning(png_ptr, "Out of place iCCP chunk");
  171885. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171886. {
  171887. png_warning(png_ptr, "Duplicate iCCP chunk");
  171888. png_crc_finish(png_ptr, length);
  171889. return;
  171890. }
  171891. #ifdef PNG_MAX_MALLOC_64K
  171892. if (length > (png_uint_32)65535L)
  171893. {
  171894. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171895. skip = length - (png_uint_32)65535L;
  171896. length = (png_uint_32)65535L;
  171897. }
  171898. #endif
  171899. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171900. slength = (png_size_t)length;
  171901. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171902. if (png_crc_finish(png_ptr, skip))
  171903. {
  171904. png_free(png_ptr, chunkdata);
  171905. return;
  171906. }
  171907. chunkdata[slength] = 0x00;
  171908. for (profile = chunkdata; *profile; profile++)
  171909. ;
  171910. ++profile;
  171911. if ( profile >= chunkdata + slength - 1)
  171912. {
  171913. png_free(png_ptr, chunkdata);
  171914. png_warning(png_ptr, "Malformed iCCP chunk");
  171915. return;
  171916. }
  171917. compression_type = *profile++;
  171918. if (compression_type)
  171919. {
  171920. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171921. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171922. wrote nonzero) */
  171923. }
  171924. prefix_length = profile - chunkdata;
  171925. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171926. slength, prefix_length, &data_length);
  171927. profile_length = data_length - prefix_length;
  171928. if ( prefix_length > data_length || profile_length < 4)
  171929. {
  171930. png_free(png_ptr, chunkdata);
  171931. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171932. return;
  171933. }
  171934. pC = (png_bytep)(chunkdata+prefix_length);
  171935. profile_size = ((*(pC ))<<24) |
  171936. ((*(pC+1))<<16) |
  171937. ((*(pC+2))<< 8) |
  171938. ((*(pC+3)) );
  171939. if(profile_size < profile_length)
  171940. profile_length = profile_size;
  171941. if(profile_size > profile_length)
  171942. {
  171943. png_free(png_ptr, chunkdata);
  171944. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171945. return;
  171946. }
  171947. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171948. chunkdata + prefix_length, profile_length);
  171949. png_free(png_ptr, chunkdata);
  171950. }
  171951. #endif /* PNG_READ_iCCP_SUPPORTED */
  171952. #if defined(PNG_READ_sPLT_SUPPORTED)
  171953. void /* PRIVATE */
  171954. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171955. {
  171956. png_bytep chunkdata;
  171957. png_bytep entry_start;
  171958. png_sPLT_t new_palette;
  171959. #ifdef PNG_NO_POINTER_INDEXING
  171960. png_sPLT_entryp pp;
  171961. #endif
  171962. int data_length, entry_size, i;
  171963. png_uint_32 skip = 0;
  171964. png_size_t slength;
  171965. png_debug(1, "in png_handle_sPLT\n");
  171966. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171967. png_error(png_ptr, "Missing IHDR before sPLT");
  171968. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171969. {
  171970. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171971. png_crc_finish(png_ptr, length);
  171972. return;
  171973. }
  171974. #ifdef PNG_MAX_MALLOC_64K
  171975. if (length > (png_uint_32)65535L)
  171976. {
  171977. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171978. skip = length - (png_uint_32)65535L;
  171979. length = (png_uint_32)65535L;
  171980. }
  171981. #endif
  171982. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171983. slength = (png_size_t)length;
  171984. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171985. if (png_crc_finish(png_ptr, skip))
  171986. {
  171987. png_free(png_ptr, chunkdata);
  171988. return;
  171989. }
  171990. chunkdata[slength] = 0x00;
  171991. for (entry_start = chunkdata; *entry_start; entry_start++)
  171992. ;
  171993. ++entry_start;
  171994. if (entry_start > chunkdata + slength - 2)
  171995. {
  171996. png_free(png_ptr, chunkdata);
  171997. png_warning(png_ptr, "malformed sPLT chunk");
  171998. return;
  171999. }
  172000. new_palette.depth = *entry_start++;
  172001. entry_size = (new_palette.depth == 8 ? 6 : 10);
  172002. data_length = (slength - (entry_start - chunkdata));
  172003. if (data_length % entry_size)
  172004. {
  172005. png_free(png_ptr, chunkdata);
  172006. png_warning(png_ptr, "sPLT chunk has bad length");
  172007. return;
  172008. }
  172009. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  172010. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  172011. png_sizeof(png_sPLT_entry)))
  172012. {
  172013. png_warning(png_ptr, "sPLT chunk too long");
  172014. return;
  172015. }
  172016. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  172017. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  172018. if (new_palette.entries == NULL)
  172019. {
  172020. png_warning(png_ptr, "sPLT chunk requires too much memory");
  172021. return;
  172022. }
  172023. #ifndef PNG_NO_POINTER_INDEXING
  172024. for (i = 0; i < new_palette.nentries; i++)
  172025. {
  172026. png_sPLT_entryp pp = new_palette.entries + i;
  172027. if (new_palette.depth == 8)
  172028. {
  172029. pp->red = *entry_start++;
  172030. pp->green = *entry_start++;
  172031. pp->blue = *entry_start++;
  172032. pp->alpha = *entry_start++;
  172033. }
  172034. else
  172035. {
  172036. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  172037. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  172038. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  172039. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  172040. }
  172041. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172042. }
  172043. #else
  172044. pp = new_palette.entries;
  172045. for (i = 0; i < new_palette.nentries; i++)
  172046. {
  172047. if (new_palette.depth == 8)
  172048. {
  172049. pp[i].red = *entry_start++;
  172050. pp[i].green = *entry_start++;
  172051. pp[i].blue = *entry_start++;
  172052. pp[i].alpha = *entry_start++;
  172053. }
  172054. else
  172055. {
  172056. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  172057. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  172058. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  172059. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  172060. }
  172061. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172062. }
  172063. #endif
  172064. new_palette.name = (png_charp)chunkdata;
  172065. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  172066. png_free(png_ptr, chunkdata);
  172067. png_free(png_ptr, new_palette.entries);
  172068. }
  172069. #endif /* PNG_READ_sPLT_SUPPORTED */
  172070. #if defined(PNG_READ_tRNS_SUPPORTED)
  172071. void /* PRIVATE */
  172072. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172073. {
  172074. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  172075. int bit_mask;
  172076. png_debug(1, "in png_handle_tRNS\n");
  172077. bit_mask = (1 << png_ptr->bit_depth) - 1;
  172078. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172079. png_error(png_ptr, "Missing IHDR before tRNS");
  172080. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172081. {
  172082. png_warning(png_ptr, "Invalid tRNS after IDAT");
  172083. png_crc_finish(png_ptr, length);
  172084. return;
  172085. }
  172086. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  172087. {
  172088. png_warning(png_ptr, "Duplicate tRNS chunk");
  172089. png_crc_finish(png_ptr, length);
  172090. return;
  172091. }
  172092. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172093. {
  172094. png_byte buf[2];
  172095. if (length != 2)
  172096. {
  172097. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172098. png_crc_finish(png_ptr, length);
  172099. return;
  172100. }
  172101. png_crc_read(png_ptr, buf, 2);
  172102. png_ptr->num_trans = 1;
  172103. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  172104. }
  172105. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172106. {
  172107. png_byte buf[6];
  172108. if (length != 6)
  172109. {
  172110. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172111. png_crc_finish(png_ptr, length);
  172112. return;
  172113. }
  172114. png_crc_read(png_ptr, buf, (png_size_t)length);
  172115. png_ptr->num_trans = 1;
  172116. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  172117. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  172118. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  172119. }
  172120. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172121. {
  172122. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172123. {
  172124. png_warning(png_ptr, "Missing PLTE before tRNS");
  172125. }
  172126. if (length > (png_uint_32)png_ptr->num_palette ||
  172127. length > PNG_MAX_PALETTE_LENGTH)
  172128. {
  172129. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172130. png_crc_finish(png_ptr, length);
  172131. return;
  172132. }
  172133. if (length == 0)
  172134. {
  172135. png_warning(png_ptr, "Zero length tRNS chunk");
  172136. png_crc_finish(png_ptr, length);
  172137. return;
  172138. }
  172139. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  172140. png_ptr->num_trans = (png_uint_16)length;
  172141. }
  172142. else
  172143. {
  172144. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  172145. png_crc_finish(png_ptr, length);
  172146. return;
  172147. }
  172148. if (png_crc_finish(png_ptr, 0))
  172149. {
  172150. png_ptr->num_trans = 0;
  172151. return;
  172152. }
  172153. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  172154. &(png_ptr->trans_values));
  172155. }
  172156. #endif
  172157. #if defined(PNG_READ_bKGD_SUPPORTED)
  172158. void /* PRIVATE */
  172159. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172160. {
  172161. png_size_t truelen;
  172162. png_byte buf[6];
  172163. png_debug(1, "in png_handle_bKGD\n");
  172164. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172165. png_error(png_ptr, "Missing IHDR before bKGD");
  172166. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172167. {
  172168. png_warning(png_ptr, "Invalid bKGD after IDAT");
  172169. png_crc_finish(png_ptr, length);
  172170. return;
  172171. }
  172172. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  172173. !(png_ptr->mode & PNG_HAVE_PLTE))
  172174. {
  172175. png_warning(png_ptr, "Missing PLTE before bKGD");
  172176. png_crc_finish(png_ptr, length);
  172177. return;
  172178. }
  172179. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  172180. {
  172181. png_warning(png_ptr, "Duplicate bKGD chunk");
  172182. png_crc_finish(png_ptr, length);
  172183. return;
  172184. }
  172185. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172186. truelen = 1;
  172187. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  172188. truelen = 6;
  172189. else
  172190. truelen = 2;
  172191. if (length != truelen)
  172192. {
  172193. png_warning(png_ptr, "Incorrect bKGD chunk length");
  172194. png_crc_finish(png_ptr, length);
  172195. return;
  172196. }
  172197. png_crc_read(png_ptr, buf, truelen);
  172198. if (png_crc_finish(png_ptr, 0))
  172199. return;
  172200. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172201. {
  172202. png_ptr->background.index = buf[0];
  172203. if(info_ptr->num_palette)
  172204. {
  172205. if(buf[0] > info_ptr->num_palette)
  172206. {
  172207. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  172208. return;
  172209. }
  172210. png_ptr->background.red =
  172211. (png_uint_16)png_ptr->palette[buf[0]].red;
  172212. png_ptr->background.green =
  172213. (png_uint_16)png_ptr->palette[buf[0]].green;
  172214. png_ptr->background.blue =
  172215. (png_uint_16)png_ptr->palette[buf[0]].blue;
  172216. }
  172217. }
  172218. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  172219. {
  172220. png_ptr->background.red =
  172221. png_ptr->background.green =
  172222. png_ptr->background.blue =
  172223. png_ptr->background.gray = png_get_uint_16(buf);
  172224. }
  172225. else
  172226. {
  172227. png_ptr->background.red = png_get_uint_16(buf);
  172228. png_ptr->background.green = png_get_uint_16(buf + 2);
  172229. png_ptr->background.blue = png_get_uint_16(buf + 4);
  172230. }
  172231. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  172232. }
  172233. #endif
  172234. #if defined(PNG_READ_hIST_SUPPORTED)
  172235. void /* PRIVATE */
  172236. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172237. {
  172238. unsigned int num, i;
  172239. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  172240. png_debug(1, "in png_handle_hIST\n");
  172241. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172242. png_error(png_ptr, "Missing IHDR before hIST");
  172243. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172244. {
  172245. png_warning(png_ptr, "Invalid hIST after IDAT");
  172246. png_crc_finish(png_ptr, length);
  172247. return;
  172248. }
  172249. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172250. {
  172251. png_warning(png_ptr, "Missing PLTE before hIST");
  172252. png_crc_finish(png_ptr, length);
  172253. return;
  172254. }
  172255. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  172256. {
  172257. png_warning(png_ptr, "Duplicate hIST chunk");
  172258. png_crc_finish(png_ptr, length);
  172259. return;
  172260. }
  172261. num = length / 2 ;
  172262. if (num != (unsigned int) png_ptr->num_palette || num >
  172263. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  172264. {
  172265. png_warning(png_ptr, "Incorrect hIST chunk length");
  172266. png_crc_finish(png_ptr, length);
  172267. return;
  172268. }
  172269. for (i = 0; i < num; i++)
  172270. {
  172271. png_byte buf[2];
  172272. png_crc_read(png_ptr, buf, 2);
  172273. readbuf[i] = png_get_uint_16(buf);
  172274. }
  172275. if (png_crc_finish(png_ptr, 0))
  172276. return;
  172277. png_set_hIST(png_ptr, info_ptr, readbuf);
  172278. }
  172279. #endif
  172280. #if defined(PNG_READ_pHYs_SUPPORTED)
  172281. void /* PRIVATE */
  172282. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172283. {
  172284. png_byte buf[9];
  172285. png_uint_32 res_x, res_y;
  172286. int unit_type;
  172287. png_debug(1, "in png_handle_pHYs\n");
  172288. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172289. png_error(png_ptr, "Missing IHDR before pHYs");
  172290. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172291. {
  172292. png_warning(png_ptr, "Invalid pHYs after IDAT");
  172293. png_crc_finish(png_ptr, length);
  172294. return;
  172295. }
  172296. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  172297. {
  172298. png_warning(png_ptr, "Duplicate pHYs chunk");
  172299. png_crc_finish(png_ptr, length);
  172300. return;
  172301. }
  172302. if (length != 9)
  172303. {
  172304. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172305. png_crc_finish(png_ptr, length);
  172306. return;
  172307. }
  172308. png_crc_read(png_ptr, buf, 9);
  172309. if (png_crc_finish(png_ptr, 0))
  172310. return;
  172311. res_x = png_get_uint_32(buf);
  172312. res_y = png_get_uint_32(buf + 4);
  172313. unit_type = buf[8];
  172314. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172315. }
  172316. #endif
  172317. #if defined(PNG_READ_oFFs_SUPPORTED)
  172318. void /* PRIVATE */
  172319. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172320. {
  172321. png_byte buf[9];
  172322. png_int_32 offset_x, offset_y;
  172323. int unit_type;
  172324. png_debug(1, "in png_handle_oFFs\n");
  172325. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172326. png_error(png_ptr, "Missing IHDR before oFFs");
  172327. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172328. {
  172329. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172330. png_crc_finish(png_ptr, length);
  172331. return;
  172332. }
  172333. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172334. {
  172335. png_warning(png_ptr, "Duplicate oFFs chunk");
  172336. png_crc_finish(png_ptr, length);
  172337. return;
  172338. }
  172339. if (length != 9)
  172340. {
  172341. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172342. png_crc_finish(png_ptr, length);
  172343. return;
  172344. }
  172345. png_crc_read(png_ptr, buf, 9);
  172346. if (png_crc_finish(png_ptr, 0))
  172347. return;
  172348. offset_x = png_get_int_32(buf);
  172349. offset_y = png_get_int_32(buf + 4);
  172350. unit_type = buf[8];
  172351. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172352. }
  172353. #endif
  172354. #if defined(PNG_READ_pCAL_SUPPORTED)
  172355. void /* PRIVATE */
  172356. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172357. {
  172358. png_charp purpose;
  172359. png_int_32 X0, X1;
  172360. png_byte type, nparams;
  172361. png_charp buf, units, endptr;
  172362. png_charpp params;
  172363. png_size_t slength;
  172364. int i;
  172365. png_debug(1, "in png_handle_pCAL\n");
  172366. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172367. png_error(png_ptr, "Missing IHDR before pCAL");
  172368. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172369. {
  172370. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172371. png_crc_finish(png_ptr, length);
  172372. return;
  172373. }
  172374. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172375. {
  172376. png_warning(png_ptr, "Duplicate pCAL chunk");
  172377. png_crc_finish(png_ptr, length);
  172378. return;
  172379. }
  172380. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172381. length + 1);
  172382. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172383. if (purpose == NULL)
  172384. {
  172385. png_warning(png_ptr, "No memory for pCAL purpose.");
  172386. return;
  172387. }
  172388. slength = (png_size_t)length;
  172389. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172390. if (png_crc_finish(png_ptr, 0))
  172391. {
  172392. png_free(png_ptr, purpose);
  172393. return;
  172394. }
  172395. purpose[slength] = 0x00; /* null terminate the last string */
  172396. png_debug(3, "Finding end of pCAL purpose string\n");
  172397. for (buf = purpose; *buf; buf++)
  172398. ;
  172399. endptr = purpose + slength;
  172400. if (endptr <= buf + 12)
  172401. {
  172402. png_warning(png_ptr, "Invalid pCAL data");
  172403. png_free(png_ptr, purpose);
  172404. return;
  172405. }
  172406. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172407. X0 = png_get_int_32((png_bytep)buf+1);
  172408. X1 = png_get_int_32((png_bytep)buf+5);
  172409. type = buf[9];
  172410. nparams = buf[10];
  172411. units = buf + 11;
  172412. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172413. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172414. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172415. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172416. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172417. {
  172418. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172419. png_free(png_ptr, purpose);
  172420. return;
  172421. }
  172422. else if (type >= PNG_EQUATION_LAST)
  172423. {
  172424. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172425. }
  172426. for (buf = units; *buf; buf++)
  172427. ;
  172428. png_debug(3, "Allocating pCAL parameters array\n");
  172429. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172430. *png_sizeof(png_charp))) ;
  172431. if (params == NULL)
  172432. {
  172433. png_free(png_ptr, purpose);
  172434. png_warning(png_ptr, "No memory for pCAL params.");
  172435. return;
  172436. }
  172437. for (i = 0; i < (int)nparams; i++)
  172438. {
  172439. buf++; /* Skip the null string terminator from previous parameter. */
  172440. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172441. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172442. ;
  172443. if (buf > endptr)
  172444. {
  172445. png_warning(png_ptr, "Invalid pCAL data");
  172446. png_free(png_ptr, purpose);
  172447. png_free(png_ptr, params);
  172448. return;
  172449. }
  172450. }
  172451. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172452. units, params);
  172453. png_free(png_ptr, purpose);
  172454. png_free(png_ptr, params);
  172455. }
  172456. #endif
  172457. #if defined(PNG_READ_sCAL_SUPPORTED)
  172458. void /* PRIVATE */
  172459. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172460. {
  172461. png_charp buffer, ep;
  172462. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172463. double width, height;
  172464. png_charp vp;
  172465. #else
  172466. #ifdef PNG_FIXED_POINT_SUPPORTED
  172467. png_charp swidth, sheight;
  172468. #endif
  172469. #endif
  172470. png_size_t slength;
  172471. png_debug(1, "in png_handle_sCAL\n");
  172472. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172473. png_error(png_ptr, "Missing IHDR before sCAL");
  172474. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172475. {
  172476. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172477. png_crc_finish(png_ptr, length);
  172478. return;
  172479. }
  172480. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172481. {
  172482. png_warning(png_ptr, "Duplicate sCAL chunk");
  172483. png_crc_finish(png_ptr, length);
  172484. return;
  172485. }
  172486. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172487. length + 1);
  172488. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172489. if (buffer == NULL)
  172490. {
  172491. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172492. return;
  172493. }
  172494. slength = (png_size_t)length;
  172495. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172496. if (png_crc_finish(png_ptr, 0))
  172497. {
  172498. png_free(png_ptr, buffer);
  172499. return;
  172500. }
  172501. buffer[slength] = 0x00; /* null terminate the last string */
  172502. ep = buffer + 1; /* skip unit byte */
  172503. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172504. width = png_strtod(png_ptr, ep, &vp);
  172505. if (*vp)
  172506. {
  172507. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172508. return;
  172509. }
  172510. #else
  172511. #ifdef PNG_FIXED_POINT_SUPPORTED
  172512. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172513. if (swidth == NULL)
  172514. {
  172515. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172516. return;
  172517. }
  172518. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172519. #endif
  172520. #endif
  172521. for (ep = buffer; *ep; ep++)
  172522. ;
  172523. ep++;
  172524. if (buffer + slength < ep)
  172525. {
  172526. png_warning(png_ptr, "Truncated sCAL chunk");
  172527. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172528. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172529. png_free(png_ptr, swidth);
  172530. #endif
  172531. png_free(png_ptr, buffer);
  172532. return;
  172533. }
  172534. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172535. height = png_strtod(png_ptr, ep, &vp);
  172536. if (*vp)
  172537. {
  172538. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172539. return;
  172540. }
  172541. #else
  172542. #ifdef PNG_FIXED_POINT_SUPPORTED
  172543. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172544. if (swidth == NULL)
  172545. {
  172546. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172547. return;
  172548. }
  172549. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172550. #endif
  172551. #endif
  172552. if (buffer + slength < ep
  172553. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172554. || width <= 0. || height <= 0.
  172555. #endif
  172556. )
  172557. {
  172558. png_warning(png_ptr, "Invalid sCAL data");
  172559. png_free(png_ptr, buffer);
  172560. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172561. png_free(png_ptr, swidth);
  172562. png_free(png_ptr, sheight);
  172563. #endif
  172564. return;
  172565. }
  172566. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172567. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172568. #else
  172569. #ifdef PNG_FIXED_POINT_SUPPORTED
  172570. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172571. #endif
  172572. #endif
  172573. png_free(png_ptr, buffer);
  172574. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172575. png_free(png_ptr, swidth);
  172576. png_free(png_ptr, sheight);
  172577. #endif
  172578. }
  172579. #endif
  172580. #if defined(PNG_READ_tIME_SUPPORTED)
  172581. void /* PRIVATE */
  172582. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172583. {
  172584. png_byte buf[7];
  172585. png_time mod_time;
  172586. png_debug(1, "in png_handle_tIME\n");
  172587. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172588. png_error(png_ptr, "Out of place tIME chunk");
  172589. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172590. {
  172591. png_warning(png_ptr, "Duplicate tIME chunk");
  172592. png_crc_finish(png_ptr, length);
  172593. return;
  172594. }
  172595. if (png_ptr->mode & PNG_HAVE_IDAT)
  172596. png_ptr->mode |= PNG_AFTER_IDAT;
  172597. if (length != 7)
  172598. {
  172599. png_warning(png_ptr, "Incorrect tIME chunk length");
  172600. png_crc_finish(png_ptr, length);
  172601. return;
  172602. }
  172603. png_crc_read(png_ptr, buf, 7);
  172604. if (png_crc_finish(png_ptr, 0))
  172605. return;
  172606. mod_time.second = buf[6];
  172607. mod_time.minute = buf[5];
  172608. mod_time.hour = buf[4];
  172609. mod_time.day = buf[3];
  172610. mod_time.month = buf[2];
  172611. mod_time.year = png_get_uint_16(buf);
  172612. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172613. }
  172614. #endif
  172615. #if defined(PNG_READ_tEXt_SUPPORTED)
  172616. void /* PRIVATE */
  172617. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172618. {
  172619. png_textp text_ptr;
  172620. png_charp key;
  172621. png_charp text;
  172622. png_uint_32 skip = 0;
  172623. png_size_t slength;
  172624. int ret;
  172625. png_debug(1, "in png_handle_tEXt\n");
  172626. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172627. png_error(png_ptr, "Missing IHDR before tEXt");
  172628. if (png_ptr->mode & PNG_HAVE_IDAT)
  172629. png_ptr->mode |= PNG_AFTER_IDAT;
  172630. #ifdef PNG_MAX_MALLOC_64K
  172631. if (length > (png_uint_32)65535L)
  172632. {
  172633. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172634. skip = length - (png_uint_32)65535L;
  172635. length = (png_uint_32)65535L;
  172636. }
  172637. #endif
  172638. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172639. if (key == NULL)
  172640. {
  172641. png_warning(png_ptr, "No memory to process text chunk.");
  172642. return;
  172643. }
  172644. slength = (png_size_t)length;
  172645. png_crc_read(png_ptr, (png_bytep)key, slength);
  172646. if (png_crc_finish(png_ptr, skip))
  172647. {
  172648. png_free(png_ptr, key);
  172649. return;
  172650. }
  172651. key[slength] = 0x00;
  172652. for (text = key; *text; text++)
  172653. ;
  172654. if (text != key + slength)
  172655. text++;
  172656. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172657. (png_uint_32)png_sizeof(png_text));
  172658. if (text_ptr == NULL)
  172659. {
  172660. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172661. png_free(png_ptr, key);
  172662. return;
  172663. }
  172664. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172665. text_ptr->key = key;
  172666. #ifdef PNG_iTXt_SUPPORTED
  172667. text_ptr->lang = NULL;
  172668. text_ptr->lang_key = NULL;
  172669. text_ptr->itxt_length = 0;
  172670. #endif
  172671. text_ptr->text = text;
  172672. text_ptr->text_length = png_strlen(text);
  172673. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172674. png_free(png_ptr, key);
  172675. png_free(png_ptr, text_ptr);
  172676. if (ret)
  172677. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172678. }
  172679. #endif
  172680. #if defined(PNG_READ_zTXt_SUPPORTED)
  172681. void /* PRIVATE */
  172682. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172683. {
  172684. png_textp text_ptr;
  172685. png_charp chunkdata;
  172686. png_charp text;
  172687. int comp_type;
  172688. int ret;
  172689. png_size_t slength, prefix_len, data_len;
  172690. png_debug(1, "in png_handle_zTXt\n");
  172691. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172692. png_error(png_ptr, "Missing IHDR before zTXt");
  172693. if (png_ptr->mode & PNG_HAVE_IDAT)
  172694. png_ptr->mode |= PNG_AFTER_IDAT;
  172695. #ifdef PNG_MAX_MALLOC_64K
  172696. if (length > (png_uint_32)65535L)
  172697. {
  172698. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172699. png_crc_finish(png_ptr, length);
  172700. return;
  172701. }
  172702. #endif
  172703. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172704. if (chunkdata == NULL)
  172705. {
  172706. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172707. return;
  172708. }
  172709. slength = (png_size_t)length;
  172710. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172711. if (png_crc_finish(png_ptr, 0))
  172712. {
  172713. png_free(png_ptr, chunkdata);
  172714. return;
  172715. }
  172716. chunkdata[slength] = 0x00;
  172717. for (text = chunkdata; *text; text++)
  172718. ;
  172719. if (text >= chunkdata + slength - 2)
  172720. {
  172721. png_warning(png_ptr, "Truncated zTXt chunk");
  172722. png_free(png_ptr, chunkdata);
  172723. return;
  172724. }
  172725. else
  172726. {
  172727. comp_type = *(++text);
  172728. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172729. {
  172730. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172731. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172732. }
  172733. text++; /* skip the compression_method byte */
  172734. }
  172735. prefix_len = text - chunkdata;
  172736. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172737. (png_size_t)length, prefix_len, &data_len);
  172738. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172739. (png_uint_32)png_sizeof(png_text));
  172740. if (text_ptr == NULL)
  172741. {
  172742. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172743. png_free(png_ptr, chunkdata);
  172744. return;
  172745. }
  172746. text_ptr->compression = comp_type;
  172747. text_ptr->key = chunkdata;
  172748. #ifdef PNG_iTXt_SUPPORTED
  172749. text_ptr->lang = NULL;
  172750. text_ptr->lang_key = NULL;
  172751. text_ptr->itxt_length = 0;
  172752. #endif
  172753. text_ptr->text = chunkdata + prefix_len;
  172754. text_ptr->text_length = data_len;
  172755. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172756. png_free(png_ptr, text_ptr);
  172757. png_free(png_ptr, chunkdata);
  172758. if (ret)
  172759. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172760. }
  172761. #endif
  172762. #if defined(PNG_READ_iTXt_SUPPORTED)
  172763. void /* PRIVATE */
  172764. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172765. {
  172766. png_textp text_ptr;
  172767. png_charp chunkdata;
  172768. png_charp key, lang, text, lang_key;
  172769. int comp_flag;
  172770. int comp_type = 0;
  172771. int ret;
  172772. png_size_t slength, prefix_len, data_len;
  172773. png_debug(1, "in png_handle_iTXt\n");
  172774. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172775. png_error(png_ptr, "Missing IHDR before iTXt");
  172776. if (png_ptr->mode & PNG_HAVE_IDAT)
  172777. png_ptr->mode |= PNG_AFTER_IDAT;
  172778. #ifdef PNG_MAX_MALLOC_64K
  172779. if (length > (png_uint_32)65535L)
  172780. {
  172781. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172782. png_crc_finish(png_ptr, length);
  172783. return;
  172784. }
  172785. #endif
  172786. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172787. if (chunkdata == NULL)
  172788. {
  172789. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172790. return;
  172791. }
  172792. slength = (png_size_t)length;
  172793. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172794. if (png_crc_finish(png_ptr, 0))
  172795. {
  172796. png_free(png_ptr, chunkdata);
  172797. return;
  172798. }
  172799. chunkdata[slength] = 0x00;
  172800. for (lang = chunkdata; *lang; lang++)
  172801. ;
  172802. lang++; /* skip NUL separator */
  172803. if (lang >= chunkdata + slength - 3)
  172804. {
  172805. png_warning(png_ptr, "Truncated iTXt chunk");
  172806. png_free(png_ptr, chunkdata);
  172807. return;
  172808. }
  172809. else
  172810. {
  172811. comp_flag = *lang++;
  172812. comp_type = *lang++;
  172813. }
  172814. for (lang_key = lang; *lang_key; lang_key++)
  172815. ;
  172816. lang_key++; /* skip NUL separator */
  172817. if (lang_key >= chunkdata + slength)
  172818. {
  172819. png_warning(png_ptr, "Truncated iTXt chunk");
  172820. png_free(png_ptr, chunkdata);
  172821. return;
  172822. }
  172823. for (text = lang_key; *text; text++)
  172824. ;
  172825. text++; /* skip NUL separator */
  172826. if (text >= chunkdata + slength)
  172827. {
  172828. png_warning(png_ptr, "Malformed iTXt chunk");
  172829. png_free(png_ptr, chunkdata);
  172830. return;
  172831. }
  172832. prefix_len = text - chunkdata;
  172833. key=chunkdata;
  172834. if (comp_flag)
  172835. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172836. (size_t)length, prefix_len, &data_len);
  172837. else
  172838. data_len=png_strlen(chunkdata + prefix_len);
  172839. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172840. (png_uint_32)png_sizeof(png_text));
  172841. if (text_ptr == NULL)
  172842. {
  172843. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172844. png_free(png_ptr, chunkdata);
  172845. return;
  172846. }
  172847. text_ptr->compression = (int)comp_flag + 1;
  172848. text_ptr->lang_key = chunkdata+(lang_key-key);
  172849. text_ptr->lang = chunkdata+(lang-key);
  172850. text_ptr->itxt_length = data_len;
  172851. text_ptr->text_length = 0;
  172852. text_ptr->key = chunkdata;
  172853. text_ptr->text = chunkdata + prefix_len;
  172854. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172855. png_free(png_ptr, text_ptr);
  172856. png_free(png_ptr, chunkdata);
  172857. if (ret)
  172858. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172859. }
  172860. #endif
  172861. void /* PRIVATE */
  172862. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172863. {
  172864. png_uint_32 skip = 0;
  172865. png_debug(1, "in png_handle_unknown\n");
  172866. if (png_ptr->mode & PNG_HAVE_IDAT)
  172867. {
  172868. #ifdef PNG_USE_LOCAL_ARRAYS
  172869. PNG_CONST PNG_IDAT;
  172870. #endif
  172871. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172872. png_ptr->mode |= PNG_AFTER_IDAT;
  172873. }
  172874. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172875. if (!(png_ptr->chunk_name[0] & 0x20))
  172876. {
  172877. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172878. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172879. PNG_HANDLE_CHUNK_ALWAYS
  172880. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172881. && png_ptr->read_user_chunk_fn == NULL
  172882. #endif
  172883. )
  172884. #endif
  172885. png_chunk_error(png_ptr, "unknown critical chunk");
  172886. }
  172887. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172888. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172889. (png_ptr->read_user_chunk_fn != NULL))
  172890. {
  172891. #ifdef PNG_MAX_MALLOC_64K
  172892. if (length > (png_uint_32)65535L)
  172893. {
  172894. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172895. skip = length - (png_uint_32)65535L;
  172896. length = (png_uint_32)65535L;
  172897. }
  172898. #endif
  172899. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172900. (png_charp)png_ptr->chunk_name, 5);
  172901. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172902. png_ptr->unknown_chunk.size = (png_size_t)length;
  172903. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172904. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172905. if(png_ptr->read_user_chunk_fn != NULL)
  172906. {
  172907. int ret;
  172908. ret = (*(png_ptr->read_user_chunk_fn))
  172909. (png_ptr, &png_ptr->unknown_chunk);
  172910. if (ret < 0)
  172911. png_chunk_error(png_ptr, "error in user chunk");
  172912. if (ret == 0)
  172913. {
  172914. if (!(png_ptr->chunk_name[0] & 0x20))
  172915. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172916. PNG_HANDLE_CHUNK_ALWAYS)
  172917. png_chunk_error(png_ptr, "unknown critical chunk");
  172918. png_set_unknown_chunks(png_ptr, info_ptr,
  172919. &png_ptr->unknown_chunk, 1);
  172920. }
  172921. }
  172922. #else
  172923. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172924. #endif
  172925. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172926. png_ptr->unknown_chunk.data = NULL;
  172927. }
  172928. else
  172929. #endif
  172930. skip = length;
  172931. png_crc_finish(png_ptr, skip);
  172932. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172933. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172934. #endif
  172935. }
  172936. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172937. void /* PRIVATE */
  172938. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172939. {
  172940. png_debug(1, "in png_check_chunk_name\n");
  172941. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172942. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172943. {
  172944. png_chunk_error(png_ptr, "invalid chunk type");
  172945. }
  172946. }
  172947. void /* PRIVATE */
  172948. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172949. {
  172950. png_debug(1,"in png_combine_row\n");
  172951. if (mask == 0xff)
  172952. {
  172953. png_memcpy(row, png_ptr->row_buf + 1,
  172954. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172955. }
  172956. else
  172957. {
  172958. switch (png_ptr->row_info.pixel_depth)
  172959. {
  172960. case 1:
  172961. {
  172962. png_bytep sp = png_ptr->row_buf + 1;
  172963. png_bytep dp = row;
  172964. int s_inc, s_start, s_end;
  172965. int m = 0x80;
  172966. int shift;
  172967. png_uint_32 i;
  172968. png_uint_32 row_width = png_ptr->width;
  172969. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172970. if (png_ptr->transformations & PNG_PACKSWAP)
  172971. {
  172972. s_start = 0;
  172973. s_end = 7;
  172974. s_inc = 1;
  172975. }
  172976. else
  172977. #endif
  172978. {
  172979. s_start = 7;
  172980. s_end = 0;
  172981. s_inc = -1;
  172982. }
  172983. shift = s_start;
  172984. for (i = 0; i < row_width; i++)
  172985. {
  172986. if (m & mask)
  172987. {
  172988. int value;
  172989. value = (*sp >> shift) & 0x01;
  172990. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172991. *dp |= (png_byte)(value << shift);
  172992. }
  172993. if (shift == s_end)
  172994. {
  172995. shift = s_start;
  172996. sp++;
  172997. dp++;
  172998. }
  172999. else
  173000. shift += s_inc;
  173001. if (m == 1)
  173002. m = 0x80;
  173003. else
  173004. m >>= 1;
  173005. }
  173006. break;
  173007. }
  173008. case 2:
  173009. {
  173010. png_bytep sp = png_ptr->row_buf + 1;
  173011. png_bytep dp = row;
  173012. int s_start, s_end, s_inc;
  173013. int m = 0x80;
  173014. int shift;
  173015. png_uint_32 i;
  173016. png_uint_32 row_width = png_ptr->width;
  173017. int value;
  173018. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173019. if (png_ptr->transformations & PNG_PACKSWAP)
  173020. {
  173021. s_start = 0;
  173022. s_end = 6;
  173023. s_inc = 2;
  173024. }
  173025. else
  173026. #endif
  173027. {
  173028. s_start = 6;
  173029. s_end = 0;
  173030. s_inc = -2;
  173031. }
  173032. shift = s_start;
  173033. for (i = 0; i < row_width; i++)
  173034. {
  173035. if (m & mask)
  173036. {
  173037. value = (*sp >> shift) & 0x03;
  173038. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  173039. *dp |= (png_byte)(value << shift);
  173040. }
  173041. if (shift == s_end)
  173042. {
  173043. shift = s_start;
  173044. sp++;
  173045. dp++;
  173046. }
  173047. else
  173048. shift += s_inc;
  173049. if (m == 1)
  173050. m = 0x80;
  173051. else
  173052. m >>= 1;
  173053. }
  173054. break;
  173055. }
  173056. case 4:
  173057. {
  173058. png_bytep sp = png_ptr->row_buf + 1;
  173059. png_bytep dp = row;
  173060. int s_start, s_end, s_inc;
  173061. int m = 0x80;
  173062. int shift;
  173063. png_uint_32 i;
  173064. png_uint_32 row_width = png_ptr->width;
  173065. int value;
  173066. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173067. if (png_ptr->transformations & PNG_PACKSWAP)
  173068. {
  173069. s_start = 0;
  173070. s_end = 4;
  173071. s_inc = 4;
  173072. }
  173073. else
  173074. #endif
  173075. {
  173076. s_start = 4;
  173077. s_end = 0;
  173078. s_inc = -4;
  173079. }
  173080. shift = s_start;
  173081. for (i = 0; i < row_width; i++)
  173082. {
  173083. if (m & mask)
  173084. {
  173085. value = (*sp >> shift) & 0xf;
  173086. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  173087. *dp |= (png_byte)(value << shift);
  173088. }
  173089. if (shift == s_end)
  173090. {
  173091. shift = s_start;
  173092. sp++;
  173093. dp++;
  173094. }
  173095. else
  173096. shift += s_inc;
  173097. if (m == 1)
  173098. m = 0x80;
  173099. else
  173100. m >>= 1;
  173101. }
  173102. break;
  173103. }
  173104. default:
  173105. {
  173106. png_bytep sp = png_ptr->row_buf + 1;
  173107. png_bytep dp = row;
  173108. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  173109. png_uint_32 i;
  173110. png_uint_32 row_width = png_ptr->width;
  173111. png_byte m = 0x80;
  173112. for (i = 0; i < row_width; i++)
  173113. {
  173114. if (m & mask)
  173115. {
  173116. png_memcpy(dp, sp, pixel_bytes);
  173117. }
  173118. sp += pixel_bytes;
  173119. dp += pixel_bytes;
  173120. if (m == 1)
  173121. m = 0x80;
  173122. else
  173123. m >>= 1;
  173124. }
  173125. break;
  173126. }
  173127. }
  173128. }
  173129. }
  173130. #ifdef PNG_READ_INTERLACING_SUPPORTED
  173131. void /* PRIVATE */
  173132. png_do_read_interlace(png_structp png_ptr)
  173133. {
  173134. png_row_infop row_info = &(png_ptr->row_info);
  173135. png_bytep row = png_ptr->row_buf + 1;
  173136. int pass = png_ptr->pass;
  173137. png_uint_32 transformations = png_ptr->transformations;
  173138. #ifdef PNG_USE_LOCAL_ARRAYS
  173139. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173140. #endif
  173141. png_debug(1,"in png_do_read_interlace\n");
  173142. if (row != NULL && row_info != NULL)
  173143. {
  173144. png_uint_32 final_width;
  173145. final_width = row_info->width * png_pass_inc[pass];
  173146. switch (row_info->pixel_depth)
  173147. {
  173148. case 1:
  173149. {
  173150. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  173151. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  173152. int sshift, dshift;
  173153. int s_start, s_end, s_inc;
  173154. int jstop = png_pass_inc[pass];
  173155. png_byte v;
  173156. png_uint_32 i;
  173157. int j;
  173158. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173159. if (transformations & PNG_PACKSWAP)
  173160. {
  173161. sshift = (int)((row_info->width + 7) & 0x07);
  173162. dshift = (int)((final_width + 7) & 0x07);
  173163. s_start = 7;
  173164. s_end = 0;
  173165. s_inc = -1;
  173166. }
  173167. else
  173168. #endif
  173169. {
  173170. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  173171. dshift = 7 - (int)((final_width + 7) & 0x07);
  173172. s_start = 0;
  173173. s_end = 7;
  173174. s_inc = 1;
  173175. }
  173176. for (i = 0; i < row_info->width; i++)
  173177. {
  173178. v = (png_byte)((*sp >> sshift) & 0x01);
  173179. for (j = 0; j < jstop; j++)
  173180. {
  173181. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  173182. *dp |= (png_byte)(v << dshift);
  173183. if (dshift == s_end)
  173184. {
  173185. dshift = s_start;
  173186. dp--;
  173187. }
  173188. else
  173189. dshift += s_inc;
  173190. }
  173191. if (sshift == s_end)
  173192. {
  173193. sshift = s_start;
  173194. sp--;
  173195. }
  173196. else
  173197. sshift += s_inc;
  173198. }
  173199. break;
  173200. }
  173201. case 2:
  173202. {
  173203. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  173204. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  173205. int sshift, dshift;
  173206. int s_start, s_end, s_inc;
  173207. int jstop = png_pass_inc[pass];
  173208. png_uint_32 i;
  173209. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173210. if (transformations & PNG_PACKSWAP)
  173211. {
  173212. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  173213. dshift = (int)(((final_width + 3) & 0x03) << 1);
  173214. s_start = 6;
  173215. s_end = 0;
  173216. s_inc = -2;
  173217. }
  173218. else
  173219. #endif
  173220. {
  173221. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  173222. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  173223. s_start = 0;
  173224. s_end = 6;
  173225. s_inc = 2;
  173226. }
  173227. for (i = 0; i < row_info->width; i++)
  173228. {
  173229. png_byte v;
  173230. int j;
  173231. v = (png_byte)((*sp >> sshift) & 0x03);
  173232. for (j = 0; j < jstop; j++)
  173233. {
  173234. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  173235. *dp |= (png_byte)(v << dshift);
  173236. if (dshift == s_end)
  173237. {
  173238. dshift = s_start;
  173239. dp--;
  173240. }
  173241. else
  173242. dshift += s_inc;
  173243. }
  173244. if (sshift == s_end)
  173245. {
  173246. sshift = s_start;
  173247. sp--;
  173248. }
  173249. else
  173250. sshift += s_inc;
  173251. }
  173252. break;
  173253. }
  173254. case 4:
  173255. {
  173256. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  173257. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  173258. int sshift, dshift;
  173259. int s_start, s_end, s_inc;
  173260. png_uint_32 i;
  173261. int jstop = png_pass_inc[pass];
  173262. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173263. if (transformations & PNG_PACKSWAP)
  173264. {
  173265. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  173266. dshift = (int)(((final_width + 1) & 0x01) << 2);
  173267. s_start = 4;
  173268. s_end = 0;
  173269. s_inc = -4;
  173270. }
  173271. else
  173272. #endif
  173273. {
  173274. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  173275. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  173276. s_start = 0;
  173277. s_end = 4;
  173278. s_inc = 4;
  173279. }
  173280. for (i = 0; i < row_info->width; i++)
  173281. {
  173282. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  173283. int j;
  173284. for (j = 0; j < jstop; j++)
  173285. {
  173286. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  173287. *dp |= (png_byte)(v << dshift);
  173288. if (dshift == s_end)
  173289. {
  173290. dshift = s_start;
  173291. dp--;
  173292. }
  173293. else
  173294. dshift += s_inc;
  173295. }
  173296. if (sshift == s_end)
  173297. {
  173298. sshift = s_start;
  173299. sp--;
  173300. }
  173301. else
  173302. sshift += s_inc;
  173303. }
  173304. break;
  173305. }
  173306. default:
  173307. {
  173308. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173309. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173310. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173311. int jstop = png_pass_inc[pass];
  173312. png_uint_32 i;
  173313. for (i = 0; i < row_info->width; i++)
  173314. {
  173315. png_byte v[8];
  173316. int j;
  173317. png_memcpy(v, sp, pixel_bytes);
  173318. for (j = 0; j < jstop; j++)
  173319. {
  173320. png_memcpy(dp, v, pixel_bytes);
  173321. dp -= pixel_bytes;
  173322. }
  173323. sp -= pixel_bytes;
  173324. }
  173325. break;
  173326. }
  173327. }
  173328. row_info->width = final_width;
  173329. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173330. }
  173331. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173332. transformations = transformations; /* silence compiler warning */
  173333. #endif
  173334. }
  173335. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173336. void /* PRIVATE */
  173337. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173338. png_bytep prev_row, int filter)
  173339. {
  173340. png_debug(1, "in png_read_filter_row\n");
  173341. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173342. switch (filter)
  173343. {
  173344. case PNG_FILTER_VALUE_NONE:
  173345. break;
  173346. case PNG_FILTER_VALUE_SUB:
  173347. {
  173348. png_uint_32 i;
  173349. png_uint_32 istop = row_info->rowbytes;
  173350. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173351. png_bytep rp = row + bpp;
  173352. png_bytep lp = row;
  173353. for (i = bpp; i < istop; i++)
  173354. {
  173355. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173356. rp++;
  173357. }
  173358. break;
  173359. }
  173360. case PNG_FILTER_VALUE_UP:
  173361. {
  173362. png_uint_32 i;
  173363. png_uint_32 istop = row_info->rowbytes;
  173364. png_bytep rp = row;
  173365. png_bytep pp = prev_row;
  173366. for (i = 0; i < istop; i++)
  173367. {
  173368. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173369. rp++;
  173370. }
  173371. break;
  173372. }
  173373. case PNG_FILTER_VALUE_AVG:
  173374. {
  173375. png_uint_32 i;
  173376. png_bytep rp = row;
  173377. png_bytep pp = prev_row;
  173378. png_bytep lp = row;
  173379. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173380. png_uint_32 istop = row_info->rowbytes - bpp;
  173381. for (i = 0; i < bpp; i++)
  173382. {
  173383. *rp = (png_byte)(((int)(*rp) +
  173384. ((int)(*pp++) / 2 )) & 0xff);
  173385. rp++;
  173386. }
  173387. for (i = 0; i < istop; i++)
  173388. {
  173389. *rp = (png_byte)(((int)(*rp) +
  173390. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173391. rp++;
  173392. }
  173393. break;
  173394. }
  173395. case PNG_FILTER_VALUE_PAETH:
  173396. {
  173397. png_uint_32 i;
  173398. png_bytep rp = row;
  173399. png_bytep pp = prev_row;
  173400. png_bytep lp = row;
  173401. png_bytep cp = prev_row;
  173402. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173403. png_uint_32 istop=row_info->rowbytes - bpp;
  173404. for (i = 0; i < bpp; i++)
  173405. {
  173406. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173407. rp++;
  173408. }
  173409. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173410. {
  173411. int a, b, c, pa, pb, pc, p;
  173412. a = *lp++;
  173413. b = *pp++;
  173414. c = *cp++;
  173415. p = b - c;
  173416. pc = a - c;
  173417. #ifdef PNG_USE_ABS
  173418. pa = abs(p);
  173419. pb = abs(pc);
  173420. pc = abs(p + pc);
  173421. #else
  173422. pa = p < 0 ? -p : p;
  173423. pb = pc < 0 ? -pc : pc;
  173424. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173425. #endif
  173426. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173427. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173428. rp++;
  173429. }
  173430. break;
  173431. }
  173432. default:
  173433. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173434. *row=0;
  173435. break;
  173436. }
  173437. }
  173438. void /* PRIVATE */
  173439. png_read_finish_row(png_structp png_ptr)
  173440. {
  173441. #ifdef PNG_USE_LOCAL_ARRAYS
  173442. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173443. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173444. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173445. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173446. #endif
  173447. png_debug(1, "in png_read_finish_row\n");
  173448. png_ptr->row_number++;
  173449. if (png_ptr->row_number < png_ptr->num_rows)
  173450. return;
  173451. if (png_ptr->interlaced)
  173452. {
  173453. png_ptr->row_number = 0;
  173454. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173455. png_ptr->rowbytes + 1);
  173456. do
  173457. {
  173458. png_ptr->pass++;
  173459. if (png_ptr->pass >= 7)
  173460. break;
  173461. png_ptr->iwidth = (png_ptr->width +
  173462. png_pass_inc[png_ptr->pass] - 1 -
  173463. png_pass_start[png_ptr->pass]) /
  173464. png_pass_inc[png_ptr->pass];
  173465. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173466. png_ptr->iwidth) + 1;
  173467. if (!(png_ptr->transformations & PNG_INTERLACE))
  173468. {
  173469. png_ptr->num_rows = (png_ptr->height +
  173470. png_pass_yinc[png_ptr->pass] - 1 -
  173471. png_pass_ystart[png_ptr->pass]) /
  173472. png_pass_yinc[png_ptr->pass];
  173473. if (!(png_ptr->num_rows))
  173474. continue;
  173475. }
  173476. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173477. break;
  173478. } while (png_ptr->iwidth == 0);
  173479. if (png_ptr->pass < 7)
  173480. return;
  173481. }
  173482. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173483. {
  173484. #ifdef PNG_USE_LOCAL_ARRAYS
  173485. PNG_CONST PNG_IDAT;
  173486. #endif
  173487. char extra;
  173488. int ret;
  173489. png_ptr->zstream.next_out = (Bytef *)&extra;
  173490. png_ptr->zstream.avail_out = (uInt)1;
  173491. for(;;)
  173492. {
  173493. if (!(png_ptr->zstream.avail_in))
  173494. {
  173495. while (!png_ptr->idat_size)
  173496. {
  173497. png_byte chunk_length[4];
  173498. png_crc_finish(png_ptr, 0);
  173499. png_read_data(png_ptr, chunk_length, 4);
  173500. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173501. png_reset_crc(png_ptr);
  173502. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173503. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173504. png_error(png_ptr, "Not enough image data");
  173505. }
  173506. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173507. png_ptr->zstream.next_in = png_ptr->zbuf;
  173508. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173509. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173510. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173511. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173512. }
  173513. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173514. if (ret == Z_STREAM_END)
  173515. {
  173516. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173517. png_ptr->idat_size)
  173518. png_warning(png_ptr, "Extra compressed data");
  173519. png_ptr->mode |= PNG_AFTER_IDAT;
  173520. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173521. break;
  173522. }
  173523. if (ret != Z_OK)
  173524. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173525. "Decompression Error");
  173526. if (!(png_ptr->zstream.avail_out))
  173527. {
  173528. png_warning(png_ptr, "Extra compressed data.");
  173529. png_ptr->mode |= PNG_AFTER_IDAT;
  173530. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173531. break;
  173532. }
  173533. }
  173534. png_ptr->zstream.avail_out = 0;
  173535. }
  173536. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173537. png_warning(png_ptr, "Extra compression data");
  173538. inflateReset(&png_ptr->zstream);
  173539. png_ptr->mode |= PNG_AFTER_IDAT;
  173540. }
  173541. void /* PRIVATE */
  173542. png_read_start_row(png_structp png_ptr)
  173543. {
  173544. #ifdef PNG_USE_LOCAL_ARRAYS
  173545. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173546. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173547. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173548. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173549. #endif
  173550. int max_pixel_depth;
  173551. png_uint_32 row_bytes;
  173552. png_debug(1, "in png_read_start_row\n");
  173553. png_ptr->zstream.avail_in = 0;
  173554. png_init_read_transformations(png_ptr);
  173555. if (png_ptr->interlaced)
  173556. {
  173557. if (!(png_ptr->transformations & PNG_INTERLACE))
  173558. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173559. png_pass_ystart[0]) / png_pass_yinc[0];
  173560. else
  173561. png_ptr->num_rows = png_ptr->height;
  173562. png_ptr->iwidth = (png_ptr->width +
  173563. png_pass_inc[png_ptr->pass] - 1 -
  173564. png_pass_start[png_ptr->pass]) /
  173565. png_pass_inc[png_ptr->pass];
  173566. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173567. png_ptr->irowbytes = (png_size_t)row_bytes;
  173568. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173569. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173570. }
  173571. else
  173572. {
  173573. png_ptr->num_rows = png_ptr->height;
  173574. png_ptr->iwidth = png_ptr->width;
  173575. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173576. }
  173577. max_pixel_depth = png_ptr->pixel_depth;
  173578. #if defined(PNG_READ_PACK_SUPPORTED)
  173579. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173580. max_pixel_depth = 8;
  173581. #endif
  173582. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173583. if (png_ptr->transformations & PNG_EXPAND)
  173584. {
  173585. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173586. {
  173587. if (png_ptr->num_trans)
  173588. max_pixel_depth = 32;
  173589. else
  173590. max_pixel_depth = 24;
  173591. }
  173592. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173593. {
  173594. if (max_pixel_depth < 8)
  173595. max_pixel_depth = 8;
  173596. if (png_ptr->num_trans)
  173597. max_pixel_depth *= 2;
  173598. }
  173599. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173600. {
  173601. if (png_ptr->num_trans)
  173602. {
  173603. max_pixel_depth *= 4;
  173604. max_pixel_depth /= 3;
  173605. }
  173606. }
  173607. }
  173608. #endif
  173609. #if defined(PNG_READ_FILLER_SUPPORTED)
  173610. if (png_ptr->transformations & (PNG_FILLER))
  173611. {
  173612. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173613. max_pixel_depth = 32;
  173614. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173615. {
  173616. if (max_pixel_depth <= 8)
  173617. max_pixel_depth = 16;
  173618. else
  173619. max_pixel_depth = 32;
  173620. }
  173621. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173622. {
  173623. if (max_pixel_depth <= 32)
  173624. max_pixel_depth = 32;
  173625. else
  173626. max_pixel_depth = 64;
  173627. }
  173628. }
  173629. #endif
  173630. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173631. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173632. {
  173633. if (
  173634. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173635. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173636. #endif
  173637. #if defined(PNG_READ_FILLER_SUPPORTED)
  173638. (png_ptr->transformations & (PNG_FILLER)) ||
  173639. #endif
  173640. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173641. {
  173642. if (max_pixel_depth <= 16)
  173643. max_pixel_depth = 32;
  173644. else
  173645. max_pixel_depth = 64;
  173646. }
  173647. else
  173648. {
  173649. if (max_pixel_depth <= 8)
  173650. {
  173651. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173652. max_pixel_depth = 32;
  173653. else
  173654. max_pixel_depth = 24;
  173655. }
  173656. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173657. max_pixel_depth = 64;
  173658. else
  173659. max_pixel_depth = 48;
  173660. }
  173661. }
  173662. #endif
  173663. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173664. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173665. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173666. {
  173667. int user_pixel_depth=png_ptr->user_transform_depth*
  173668. png_ptr->user_transform_channels;
  173669. if(user_pixel_depth > max_pixel_depth)
  173670. max_pixel_depth=user_pixel_depth;
  173671. }
  173672. #endif
  173673. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173674. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173675. 1 + ((max_pixel_depth + 7) >> 3);
  173676. #ifdef PNG_MAX_MALLOC_64K
  173677. if (row_bytes > (png_uint_32)65536L)
  173678. png_error(png_ptr, "This image requires a row greater than 64KB");
  173679. #endif
  173680. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173681. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173682. #ifdef PNG_MAX_MALLOC_64K
  173683. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173684. png_error(png_ptr, "This image requires a row greater than 64KB");
  173685. #endif
  173686. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173687. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173688. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173689. png_ptr->rowbytes + 1));
  173690. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173691. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173692. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173693. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173694. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173695. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173696. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173697. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173698. }
  173699. #endif /* PNG_READ_SUPPORTED */
  173700. /*** End of inlined file: pngrutil.c ***/
  173701. /*** Start of inlined file: pngset.c ***/
  173702. #define PNG_INTERNAL
  173703. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173704. #if defined(PNG_bKGD_SUPPORTED)
  173705. void PNGAPI
  173706. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173707. {
  173708. png_debug1(1, "in %s storage function\n", "bKGD");
  173709. if (png_ptr == NULL || info_ptr == NULL)
  173710. return;
  173711. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173712. info_ptr->valid |= PNG_INFO_bKGD;
  173713. }
  173714. #endif
  173715. #if defined(PNG_cHRM_SUPPORTED)
  173716. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173717. void PNGAPI
  173718. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173719. double white_x, double white_y, double red_x, double red_y,
  173720. double green_x, double green_y, double blue_x, double blue_y)
  173721. {
  173722. png_debug1(1, "in %s storage function\n", "cHRM");
  173723. if (png_ptr == NULL || info_ptr == NULL)
  173724. return;
  173725. if (white_x < 0.0 || white_y < 0.0 ||
  173726. red_x < 0.0 || red_y < 0.0 ||
  173727. green_x < 0.0 || green_y < 0.0 ||
  173728. blue_x < 0.0 || blue_y < 0.0)
  173729. {
  173730. png_warning(png_ptr,
  173731. "Ignoring attempt to set negative chromaticity value");
  173732. return;
  173733. }
  173734. if (white_x > 21474.83 || white_y > 21474.83 ||
  173735. red_x > 21474.83 || red_y > 21474.83 ||
  173736. green_x > 21474.83 || green_y > 21474.83 ||
  173737. blue_x > 21474.83 || blue_y > 21474.83)
  173738. {
  173739. png_warning(png_ptr,
  173740. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173741. return;
  173742. }
  173743. info_ptr->x_white = (float)white_x;
  173744. info_ptr->y_white = (float)white_y;
  173745. info_ptr->x_red = (float)red_x;
  173746. info_ptr->y_red = (float)red_y;
  173747. info_ptr->x_green = (float)green_x;
  173748. info_ptr->y_green = (float)green_y;
  173749. info_ptr->x_blue = (float)blue_x;
  173750. info_ptr->y_blue = (float)blue_y;
  173751. #ifdef PNG_FIXED_POINT_SUPPORTED
  173752. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173753. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173754. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173755. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173756. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173757. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173758. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173759. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173760. #endif
  173761. info_ptr->valid |= PNG_INFO_cHRM;
  173762. }
  173763. #endif
  173764. #ifdef PNG_FIXED_POINT_SUPPORTED
  173765. void PNGAPI
  173766. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173767. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173768. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173769. png_fixed_point blue_x, png_fixed_point blue_y)
  173770. {
  173771. png_debug1(1, "in %s storage function\n", "cHRM");
  173772. if (png_ptr == NULL || info_ptr == NULL)
  173773. return;
  173774. if (white_x < 0 || white_y < 0 ||
  173775. red_x < 0 || red_y < 0 ||
  173776. green_x < 0 || green_y < 0 ||
  173777. blue_x < 0 || blue_y < 0)
  173778. {
  173779. png_warning(png_ptr,
  173780. "Ignoring attempt to set negative chromaticity value");
  173781. return;
  173782. }
  173783. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173784. if (white_x > (double) PNG_UINT_31_MAX ||
  173785. white_y > (double) PNG_UINT_31_MAX ||
  173786. red_x > (double) PNG_UINT_31_MAX ||
  173787. red_y > (double) PNG_UINT_31_MAX ||
  173788. green_x > (double) PNG_UINT_31_MAX ||
  173789. green_y > (double) PNG_UINT_31_MAX ||
  173790. blue_x > (double) PNG_UINT_31_MAX ||
  173791. blue_y > (double) PNG_UINT_31_MAX)
  173792. #else
  173793. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173794. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173795. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173796. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173797. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173798. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173799. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173800. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173801. #endif
  173802. {
  173803. png_warning(png_ptr,
  173804. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173805. return;
  173806. }
  173807. info_ptr->int_x_white = white_x;
  173808. info_ptr->int_y_white = white_y;
  173809. info_ptr->int_x_red = red_x;
  173810. info_ptr->int_y_red = red_y;
  173811. info_ptr->int_x_green = green_x;
  173812. info_ptr->int_y_green = green_y;
  173813. info_ptr->int_x_blue = blue_x;
  173814. info_ptr->int_y_blue = blue_y;
  173815. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173816. info_ptr->x_white = (float)(white_x/100000.);
  173817. info_ptr->y_white = (float)(white_y/100000.);
  173818. info_ptr->x_red = (float)( red_x/100000.);
  173819. info_ptr->y_red = (float)( red_y/100000.);
  173820. info_ptr->x_green = (float)(green_x/100000.);
  173821. info_ptr->y_green = (float)(green_y/100000.);
  173822. info_ptr->x_blue = (float)( blue_x/100000.);
  173823. info_ptr->y_blue = (float)( blue_y/100000.);
  173824. #endif
  173825. info_ptr->valid |= PNG_INFO_cHRM;
  173826. }
  173827. #endif
  173828. #endif
  173829. #if defined(PNG_gAMA_SUPPORTED)
  173830. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173831. void PNGAPI
  173832. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173833. {
  173834. double gamma;
  173835. png_debug1(1, "in %s storage function\n", "gAMA");
  173836. if (png_ptr == NULL || info_ptr == NULL)
  173837. return;
  173838. if (file_gamma > 21474.83)
  173839. {
  173840. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173841. gamma=21474.83;
  173842. }
  173843. else
  173844. gamma=file_gamma;
  173845. info_ptr->gamma = (float)gamma;
  173846. #ifdef PNG_FIXED_POINT_SUPPORTED
  173847. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173848. #endif
  173849. info_ptr->valid |= PNG_INFO_gAMA;
  173850. if(gamma == 0.0)
  173851. png_warning(png_ptr, "Setting gamma=0");
  173852. }
  173853. #endif
  173854. void PNGAPI
  173855. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173856. int_gamma)
  173857. {
  173858. png_fixed_point gamma;
  173859. png_debug1(1, "in %s storage function\n", "gAMA");
  173860. if (png_ptr == NULL || info_ptr == NULL)
  173861. return;
  173862. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173863. {
  173864. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173865. gamma=PNG_UINT_31_MAX;
  173866. }
  173867. else
  173868. {
  173869. if (int_gamma < 0)
  173870. {
  173871. png_warning(png_ptr, "Setting negative gamma to zero");
  173872. gamma=0;
  173873. }
  173874. else
  173875. gamma=int_gamma;
  173876. }
  173877. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173878. info_ptr->gamma = (float)(gamma/100000.);
  173879. #endif
  173880. #ifdef PNG_FIXED_POINT_SUPPORTED
  173881. info_ptr->int_gamma = gamma;
  173882. #endif
  173883. info_ptr->valid |= PNG_INFO_gAMA;
  173884. if(gamma == 0)
  173885. png_warning(png_ptr, "Setting gamma=0");
  173886. }
  173887. #endif
  173888. #if defined(PNG_hIST_SUPPORTED)
  173889. void PNGAPI
  173890. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173891. {
  173892. int i;
  173893. png_debug1(1, "in %s storage function\n", "hIST");
  173894. if (png_ptr == NULL || info_ptr == NULL)
  173895. return;
  173896. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173897. > PNG_MAX_PALETTE_LENGTH)
  173898. {
  173899. png_warning(png_ptr,
  173900. "Invalid palette size, hIST allocation skipped.");
  173901. return;
  173902. }
  173903. #ifdef PNG_FREE_ME_SUPPORTED
  173904. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173905. #endif
  173906. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173907. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173908. if (png_ptr->hist == NULL)
  173909. {
  173910. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173911. return;
  173912. }
  173913. for (i = 0; i < info_ptr->num_palette; i++)
  173914. png_ptr->hist[i] = hist[i];
  173915. info_ptr->hist = png_ptr->hist;
  173916. info_ptr->valid |= PNG_INFO_hIST;
  173917. #ifdef PNG_FREE_ME_SUPPORTED
  173918. info_ptr->free_me |= PNG_FREE_HIST;
  173919. #else
  173920. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173921. #endif
  173922. }
  173923. #endif
  173924. void PNGAPI
  173925. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173926. png_uint_32 width, png_uint_32 height, int bit_depth,
  173927. int color_type, int interlace_type, int compression_type,
  173928. int filter_type)
  173929. {
  173930. png_debug1(1, "in %s storage function\n", "IHDR");
  173931. if (png_ptr == NULL || info_ptr == NULL)
  173932. return;
  173933. if (width == 0 || height == 0)
  173934. png_error(png_ptr, "Image width or height is zero in IHDR");
  173935. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173936. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173937. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173938. #else
  173939. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173940. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173941. #endif
  173942. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173943. png_error(png_ptr, "Invalid image size in IHDR");
  173944. if ( width > (PNG_UINT_32_MAX
  173945. >> 3) /* 8-byte RGBA pixels */
  173946. - 64 /* bigrowbuf hack */
  173947. - 1 /* filter byte */
  173948. - 7*8 /* rounding of width to multiple of 8 pixels */
  173949. - 8) /* extra max_pixel_depth pad */
  173950. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173951. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173952. bit_depth != 8 && bit_depth != 16)
  173953. png_error(png_ptr, "Invalid bit depth in IHDR");
  173954. if (color_type < 0 || color_type == 1 ||
  173955. color_type == 5 || color_type > 6)
  173956. png_error(png_ptr, "Invalid color type in IHDR");
  173957. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173958. ((color_type == PNG_COLOR_TYPE_RGB ||
  173959. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173960. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173961. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173962. if (interlace_type >= PNG_INTERLACE_LAST)
  173963. png_error(png_ptr, "Unknown interlace method in IHDR");
  173964. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173965. png_error(png_ptr, "Unknown compression method in IHDR");
  173966. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173967. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173968. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173969. if(filter_type != PNG_FILTER_TYPE_BASE)
  173970. {
  173971. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173972. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173973. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173974. (color_type == PNG_COLOR_TYPE_RGB ||
  173975. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173976. png_error(png_ptr, "Unknown filter method in IHDR");
  173977. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173978. png_warning(png_ptr, "Invalid filter method in IHDR");
  173979. }
  173980. #else
  173981. if(filter_type != PNG_FILTER_TYPE_BASE)
  173982. png_error(png_ptr, "Unknown filter method in IHDR");
  173983. #endif
  173984. info_ptr->width = width;
  173985. info_ptr->height = height;
  173986. info_ptr->bit_depth = (png_byte)bit_depth;
  173987. info_ptr->color_type =(png_byte) color_type;
  173988. info_ptr->compression_type = (png_byte)compression_type;
  173989. info_ptr->filter_type = (png_byte)filter_type;
  173990. info_ptr->interlace_type = (png_byte)interlace_type;
  173991. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173992. info_ptr->channels = 1;
  173993. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173994. info_ptr->channels = 3;
  173995. else
  173996. info_ptr->channels = 1;
  173997. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173998. info_ptr->channels++;
  173999. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  174000. if (width > (PNG_UINT_32_MAX
  174001. >> 3) /* 8-byte RGBA pixels */
  174002. - 64 /* bigrowbuf hack */
  174003. - 1 /* filter byte */
  174004. - 7*8 /* rounding of width to multiple of 8 pixels */
  174005. - 8) /* extra max_pixel_depth pad */
  174006. info_ptr->rowbytes = (png_size_t)0;
  174007. else
  174008. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  174009. }
  174010. #if defined(PNG_oFFs_SUPPORTED)
  174011. void PNGAPI
  174012. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  174013. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  174014. {
  174015. png_debug1(1, "in %s storage function\n", "oFFs");
  174016. if (png_ptr == NULL || info_ptr == NULL)
  174017. return;
  174018. info_ptr->x_offset = offset_x;
  174019. info_ptr->y_offset = offset_y;
  174020. info_ptr->offset_unit_type = (png_byte)unit_type;
  174021. info_ptr->valid |= PNG_INFO_oFFs;
  174022. }
  174023. #endif
  174024. #if defined(PNG_pCAL_SUPPORTED)
  174025. void PNGAPI
  174026. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  174027. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  174028. png_charp units, png_charpp params)
  174029. {
  174030. png_uint_32 length;
  174031. int i;
  174032. png_debug1(1, "in %s storage function\n", "pCAL");
  174033. if (png_ptr == NULL || info_ptr == NULL)
  174034. return;
  174035. length = png_strlen(purpose) + 1;
  174036. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  174037. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  174038. if (info_ptr->pcal_purpose == NULL)
  174039. {
  174040. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  174041. return;
  174042. }
  174043. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  174044. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  174045. info_ptr->pcal_X0 = X0;
  174046. info_ptr->pcal_X1 = X1;
  174047. info_ptr->pcal_type = (png_byte)type;
  174048. info_ptr->pcal_nparams = (png_byte)nparams;
  174049. length = png_strlen(units) + 1;
  174050. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  174051. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  174052. if (info_ptr->pcal_units == NULL)
  174053. {
  174054. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  174055. return;
  174056. }
  174057. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  174058. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  174059. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  174060. if (info_ptr->pcal_params == NULL)
  174061. {
  174062. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  174063. return;
  174064. }
  174065. info_ptr->pcal_params[nparams] = NULL;
  174066. for (i = 0; i < nparams; i++)
  174067. {
  174068. length = png_strlen(params[i]) + 1;
  174069. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  174070. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  174071. if (info_ptr->pcal_params[i] == NULL)
  174072. {
  174073. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  174074. return;
  174075. }
  174076. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  174077. }
  174078. info_ptr->valid |= PNG_INFO_pCAL;
  174079. #ifdef PNG_FREE_ME_SUPPORTED
  174080. info_ptr->free_me |= PNG_FREE_PCAL;
  174081. #endif
  174082. }
  174083. #endif
  174084. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  174085. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174086. void PNGAPI
  174087. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  174088. int unit, double width, double height)
  174089. {
  174090. png_debug1(1, "in %s storage function\n", "sCAL");
  174091. if (png_ptr == NULL || info_ptr == NULL)
  174092. return;
  174093. info_ptr->scal_unit = (png_byte)unit;
  174094. info_ptr->scal_pixel_width = width;
  174095. info_ptr->scal_pixel_height = height;
  174096. info_ptr->valid |= PNG_INFO_sCAL;
  174097. }
  174098. #else
  174099. #ifdef PNG_FIXED_POINT_SUPPORTED
  174100. void PNGAPI
  174101. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  174102. int unit, png_charp swidth, png_charp sheight)
  174103. {
  174104. png_uint_32 length;
  174105. png_debug1(1, "in %s storage function\n", "sCAL");
  174106. if (png_ptr == NULL || info_ptr == NULL)
  174107. return;
  174108. info_ptr->scal_unit = (png_byte)unit;
  174109. length = png_strlen(swidth) + 1;
  174110. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174111. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  174112. if (info_ptr->scal_s_width == NULL)
  174113. {
  174114. png_warning(png_ptr,
  174115. "Memory allocation failed while processing sCAL.");
  174116. }
  174117. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  174118. length = png_strlen(sheight) + 1;
  174119. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174120. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  174121. if (info_ptr->scal_s_height == NULL)
  174122. {
  174123. png_free (png_ptr, info_ptr->scal_s_width);
  174124. png_warning(png_ptr,
  174125. "Memory allocation failed while processing sCAL.");
  174126. }
  174127. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  174128. info_ptr->valid |= PNG_INFO_sCAL;
  174129. #ifdef PNG_FREE_ME_SUPPORTED
  174130. info_ptr->free_me |= PNG_FREE_SCAL;
  174131. #endif
  174132. }
  174133. #endif
  174134. #endif
  174135. #endif
  174136. #if defined(PNG_pHYs_SUPPORTED)
  174137. void PNGAPI
  174138. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  174139. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  174140. {
  174141. png_debug1(1, "in %s storage function\n", "pHYs");
  174142. if (png_ptr == NULL || info_ptr == NULL)
  174143. return;
  174144. info_ptr->x_pixels_per_unit = res_x;
  174145. info_ptr->y_pixels_per_unit = res_y;
  174146. info_ptr->phys_unit_type = (png_byte)unit_type;
  174147. info_ptr->valid |= PNG_INFO_pHYs;
  174148. }
  174149. #endif
  174150. void PNGAPI
  174151. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  174152. png_colorp palette, int num_palette)
  174153. {
  174154. png_debug1(1, "in %s storage function\n", "PLTE");
  174155. if (png_ptr == NULL || info_ptr == NULL)
  174156. return;
  174157. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  174158. {
  174159. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174160. png_error(png_ptr, "Invalid palette length");
  174161. else
  174162. {
  174163. png_warning(png_ptr, "Invalid palette length");
  174164. return;
  174165. }
  174166. }
  174167. #ifdef PNG_FREE_ME_SUPPORTED
  174168. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  174169. #endif
  174170. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  174171. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  174172. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  174173. png_sizeof(png_color));
  174174. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  174175. info_ptr->palette = png_ptr->palette;
  174176. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  174177. #ifdef PNG_FREE_ME_SUPPORTED
  174178. info_ptr->free_me |= PNG_FREE_PLTE;
  174179. #else
  174180. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  174181. #endif
  174182. info_ptr->valid |= PNG_INFO_PLTE;
  174183. }
  174184. #if defined(PNG_sBIT_SUPPORTED)
  174185. void PNGAPI
  174186. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  174187. png_color_8p sig_bit)
  174188. {
  174189. png_debug1(1, "in %s storage function\n", "sBIT");
  174190. if (png_ptr == NULL || info_ptr == NULL)
  174191. return;
  174192. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  174193. info_ptr->valid |= PNG_INFO_sBIT;
  174194. }
  174195. #endif
  174196. #if defined(PNG_sRGB_SUPPORTED)
  174197. void PNGAPI
  174198. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  174199. {
  174200. png_debug1(1, "in %s storage function\n", "sRGB");
  174201. if (png_ptr == NULL || info_ptr == NULL)
  174202. return;
  174203. info_ptr->srgb_intent = (png_byte)intent;
  174204. info_ptr->valid |= PNG_INFO_sRGB;
  174205. }
  174206. void PNGAPI
  174207. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  174208. int intent)
  174209. {
  174210. #if defined(PNG_gAMA_SUPPORTED)
  174211. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174212. float file_gamma;
  174213. #endif
  174214. #ifdef PNG_FIXED_POINT_SUPPORTED
  174215. png_fixed_point int_file_gamma;
  174216. #endif
  174217. #endif
  174218. #if defined(PNG_cHRM_SUPPORTED)
  174219. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174220. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  174221. #endif
  174222. #ifdef PNG_FIXED_POINT_SUPPORTED
  174223. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  174224. int_green_y, int_blue_x, int_blue_y;
  174225. #endif
  174226. #endif
  174227. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  174228. if (png_ptr == NULL || info_ptr == NULL)
  174229. return;
  174230. png_set_sRGB(png_ptr, info_ptr, intent);
  174231. #if defined(PNG_gAMA_SUPPORTED)
  174232. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174233. file_gamma = (float).45455;
  174234. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  174235. #endif
  174236. #ifdef PNG_FIXED_POINT_SUPPORTED
  174237. int_file_gamma = 45455L;
  174238. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  174239. #endif
  174240. #endif
  174241. #if defined(PNG_cHRM_SUPPORTED)
  174242. #ifdef PNG_FIXED_POINT_SUPPORTED
  174243. int_white_x = 31270L;
  174244. int_white_y = 32900L;
  174245. int_red_x = 64000L;
  174246. int_red_y = 33000L;
  174247. int_green_x = 30000L;
  174248. int_green_y = 60000L;
  174249. int_blue_x = 15000L;
  174250. int_blue_y = 6000L;
  174251. png_set_cHRM_fixed(png_ptr, info_ptr,
  174252. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  174253. int_blue_x, int_blue_y);
  174254. #endif
  174255. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174256. white_x = (float).3127;
  174257. white_y = (float).3290;
  174258. red_x = (float).64;
  174259. red_y = (float).33;
  174260. green_x = (float).30;
  174261. green_y = (float).60;
  174262. blue_x = (float).15;
  174263. blue_y = (float).06;
  174264. png_set_cHRM(png_ptr, info_ptr,
  174265. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  174266. #endif
  174267. #endif
  174268. }
  174269. #endif
  174270. #if defined(PNG_iCCP_SUPPORTED)
  174271. void PNGAPI
  174272. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  174273. png_charp name, int compression_type,
  174274. png_charp profile, png_uint_32 proflen)
  174275. {
  174276. png_charp new_iccp_name;
  174277. png_charp new_iccp_profile;
  174278. png_debug1(1, "in %s storage function\n", "iCCP");
  174279. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  174280. return;
  174281. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  174282. if (new_iccp_name == NULL)
  174283. {
  174284. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  174285. return;
  174286. }
  174287. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  174288. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  174289. if (new_iccp_profile == NULL)
  174290. {
  174291. png_free (png_ptr, new_iccp_name);
  174292. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  174293. return;
  174294. }
  174295. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  174296. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  174297. info_ptr->iccp_proflen = proflen;
  174298. info_ptr->iccp_name = new_iccp_name;
  174299. info_ptr->iccp_profile = new_iccp_profile;
  174300. info_ptr->iccp_compression = (png_byte)compression_type;
  174301. #ifdef PNG_FREE_ME_SUPPORTED
  174302. info_ptr->free_me |= PNG_FREE_ICCP;
  174303. #endif
  174304. info_ptr->valid |= PNG_INFO_iCCP;
  174305. }
  174306. #endif
  174307. #if defined(PNG_TEXT_SUPPORTED)
  174308. void PNGAPI
  174309. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174310. int num_text)
  174311. {
  174312. int ret;
  174313. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174314. if (ret)
  174315. png_error(png_ptr, "Insufficient memory to store text");
  174316. }
  174317. int /* PRIVATE */
  174318. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174319. int num_text)
  174320. {
  174321. int i;
  174322. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174323. "text" : (png_const_charp)png_ptr->chunk_name));
  174324. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174325. return(0);
  174326. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174327. {
  174328. if (info_ptr->text != NULL)
  174329. {
  174330. png_textp old_text;
  174331. int old_max;
  174332. old_max = info_ptr->max_text;
  174333. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174334. old_text = info_ptr->text;
  174335. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174336. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174337. if (info_ptr->text == NULL)
  174338. {
  174339. png_free(png_ptr, old_text);
  174340. return(1);
  174341. }
  174342. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174343. png_sizeof(png_text)));
  174344. png_free(png_ptr, old_text);
  174345. }
  174346. else
  174347. {
  174348. info_ptr->max_text = num_text + 8;
  174349. info_ptr->num_text = 0;
  174350. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174351. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174352. if (info_ptr->text == NULL)
  174353. return(1);
  174354. #ifdef PNG_FREE_ME_SUPPORTED
  174355. info_ptr->free_me |= PNG_FREE_TEXT;
  174356. #endif
  174357. }
  174358. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174359. info_ptr->max_text);
  174360. }
  174361. for (i = 0; i < num_text; i++)
  174362. {
  174363. png_size_t text_length,key_len;
  174364. png_size_t lang_len,lang_key_len;
  174365. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174366. if (text_ptr[i].key == NULL)
  174367. continue;
  174368. key_len = png_strlen(text_ptr[i].key);
  174369. if(text_ptr[i].compression <= 0)
  174370. {
  174371. lang_len = 0;
  174372. lang_key_len = 0;
  174373. }
  174374. else
  174375. #ifdef PNG_iTXt_SUPPORTED
  174376. {
  174377. if (text_ptr[i].lang != NULL)
  174378. lang_len = png_strlen(text_ptr[i].lang);
  174379. else
  174380. lang_len = 0;
  174381. if (text_ptr[i].lang_key != NULL)
  174382. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174383. else
  174384. lang_key_len = 0;
  174385. }
  174386. #else
  174387. {
  174388. png_warning(png_ptr, "iTXt chunk not supported.");
  174389. continue;
  174390. }
  174391. #endif
  174392. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174393. {
  174394. text_length = 0;
  174395. #ifdef PNG_iTXt_SUPPORTED
  174396. if(text_ptr[i].compression > 0)
  174397. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174398. else
  174399. #endif
  174400. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174401. }
  174402. else
  174403. {
  174404. text_length = png_strlen(text_ptr[i].text);
  174405. textp->compression = text_ptr[i].compression;
  174406. }
  174407. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174408. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174409. if (textp->key == NULL)
  174410. return(1);
  174411. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174412. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174413. (int)textp->key);
  174414. png_memcpy(textp->key, text_ptr[i].key,
  174415. (png_size_t)(key_len));
  174416. *(textp->key+key_len) = '\0';
  174417. #ifdef PNG_iTXt_SUPPORTED
  174418. if (text_ptr[i].compression > 0)
  174419. {
  174420. textp->lang=textp->key + key_len + 1;
  174421. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174422. *(textp->lang+lang_len) = '\0';
  174423. textp->lang_key=textp->lang + lang_len + 1;
  174424. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174425. *(textp->lang_key+lang_key_len) = '\0';
  174426. textp->text=textp->lang_key + lang_key_len + 1;
  174427. }
  174428. else
  174429. #endif
  174430. {
  174431. #ifdef PNG_iTXt_SUPPORTED
  174432. textp->lang=NULL;
  174433. textp->lang_key=NULL;
  174434. #endif
  174435. textp->text=textp->key + key_len + 1;
  174436. }
  174437. if(text_length)
  174438. png_memcpy(textp->text, text_ptr[i].text,
  174439. (png_size_t)(text_length));
  174440. *(textp->text+text_length) = '\0';
  174441. #ifdef PNG_iTXt_SUPPORTED
  174442. if(textp->compression > 0)
  174443. {
  174444. textp->text_length = 0;
  174445. textp->itxt_length = text_length;
  174446. }
  174447. else
  174448. #endif
  174449. {
  174450. textp->text_length = text_length;
  174451. #ifdef PNG_iTXt_SUPPORTED
  174452. textp->itxt_length = 0;
  174453. #endif
  174454. }
  174455. info_ptr->num_text++;
  174456. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174457. }
  174458. return(0);
  174459. }
  174460. #endif
  174461. #if defined(PNG_tIME_SUPPORTED)
  174462. void PNGAPI
  174463. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174464. {
  174465. png_debug1(1, "in %s storage function\n", "tIME");
  174466. if (png_ptr == NULL || info_ptr == NULL ||
  174467. (png_ptr->mode & PNG_WROTE_tIME))
  174468. return;
  174469. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174470. info_ptr->valid |= PNG_INFO_tIME;
  174471. }
  174472. #endif
  174473. #if defined(PNG_tRNS_SUPPORTED)
  174474. void PNGAPI
  174475. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174476. png_bytep trans, int num_trans, png_color_16p trans_values)
  174477. {
  174478. png_debug1(1, "in %s storage function\n", "tRNS");
  174479. if (png_ptr == NULL || info_ptr == NULL)
  174480. return;
  174481. if (trans != NULL)
  174482. {
  174483. #ifdef PNG_FREE_ME_SUPPORTED
  174484. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174485. #endif
  174486. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174487. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174488. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174489. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174490. #ifdef PNG_FREE_ME_SUPPORTED
  174491. info_ptr->free_me |= PNG_FREE_TRNS;
  174492. #else
  174493. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174494. #endif
  174495. }
  174496. if (trans_values != NULL)
  174497. {
  174498. png_memcpy(&(info_ptr->trans_values), trans_values,
  174499. png_sizeof(png_color_16));
  174500. if (num_trans == 0)
  174501. num_trans = 1;
  174502. }
  174503. info_ptr->num_trans = (png_uint_16)num_trans;
  174504. info_ptr->valid |= PNG_INFO_tRNS;
  174505. }
  174506. #endif
  174507. #if defined(PNG_sPLT_SUPPORTED)
  174508. void PNGAPI
  174509. png_set_sPLT(png_structp png_ptr,
  174510. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174511. {
  174512. png_sPLT_tp np;
  174513. int i;
  174514. if (png_ptr == NULL || info_ptr == NULL)
  174515. return;
  174516. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174517. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174518. if (np == NULL)
  174519. {
  174520. png_warning(png_ptr, "No memory for sPLT palettes.");
  174521. return;
  174522. }
  174523. png_memcpy(np, info_ptr->splt_palettes,
  174524. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174525. png_free(png_ptr, info_ptr->splt_palettes);
  174526. info_ptr->splt_palettes=NULL;
  174527. for (i = 0; i < nentries; i++)
  174528. {
  174529. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174530. png_sPLT_tp from = entries + i;
  174531. to->name = (png_charp)png_malloc_warn(png_ptr,
  174532. png_strlen(from->name) + 1);
  174533. if (to->name == NULL)
  174534. {
  174535. png_warning(png_ptr,
  174536. "Out of memory while processing sPLT chunk");
  174537. }
  174538. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174539. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174540. from->nentries * png_sizeof(png_sPLT_entry));
  174541. png_memcpy(to->entries, from->entries,
  174542. from->nentries * png_sizeof(png_sPLT_entry));
  174543. if (to->entries == NULL)
  174544. {
  174545. png_warning(png_ptr,
  174546. "Out of memory while processing sPLT chunk");
  174547. png_free(png_ptr,to->name);
  174548. to->name = NULL;
  174549. }
  174550. to->nentries = from->nentries;
  174551. to->depth = from->depth;
  174552. }
  174553. info_ptr->splt_palettes = np;
  174554. info_ptr->splt_palettes_num += nentries;
  174555. info_ptr->valid |= PNG_INFO_sPLT;
  174556. #ifdef PNG_FREE_ME_SUPPORTED
  174557. info_ptr->free_me |= PNG_FREE_SPLT;
  174558. #endif
  174559. }
  174560. #endif /* PNG_sPLT_SUPPORTED */
  174561. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174562. void PNGAPI
  174563. png_set_unknown_chunks(png_structp png_ptr,
  174564. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174565. {
  174566. png_unknown_chunkp np;
  174567. int i;
  174568. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174569. return;
  174570. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174571. (info_ptr->unknown_chunks_num + num_unknowns) *
  174572. png_sizeof(png_unknown_chunk));
  174573. if (np == NULL)
  174574. {
  174575. png_warning(png_ptr,
  174576. "Out of memory while processing unknown chunk.");
  174577. return;
  174578. }
  174579. png_memcpy(np, info_ptr->unknown_chunks,
  174580. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174581. png_free(png_ptr, info_ptr->unknown_chunks);
  174582. info_ptr->unknown_chunks=NULL;
  174583. for (i = 0; i < num_unknowns; i++)
  174584. {
  174585. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174586. png_unknown_chunkp from = unknowns + i;
  174587. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174588. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174589. if (to->data == NULL)
  174590. {
  174591. png_warning(png_ptr,
  174592. "Out of memory while processing unknown chunk.");
  174593. }
  174594. else
  174595. {
  174596. png_memcpy(to->data, from->data, from->size);
  174597. to->size = from->size;
  174598. to->location = (png_byte)(png_ptr->mode & 0xff);
  174599. }
  174600. }
  174601. info_ptr->unknown_chunks = np;
  174602. info_ptr->unknown_chunks_num += num_unknowns;
  174603. #ifdef PNG_FREE_ME_SUPPORTED
  174604. info_ptr->free_me |= PNG_FREE_UNKN;
  174605. #endif
  174606. }
  174607. void PNGAPI
  174608. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174609. int chunk, int location)
  174610. {
  174611. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174612. (int)info_ptr->unknown_chunks_num)
  174613. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174614. }
  174615. #endif
  174616. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174617. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174618. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174619. void PNGAPI
  174620. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174621. {
  174622. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174623. if (png_ptr == NULL)
  174624. return;
  174625. png_ptr->mng_features_permitted = (png_byte)
  174626. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174627. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174628. }
  174629. #endif
  174630. #endif
  174631. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174632. png_uint_32 PNGAPI
  174633. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174634. {
  174635. png_debug(1, "in png_permit_mng_features\n");
  174636. if (png_ptr == NULL)
  174637. return (png_uint_32)0;
  174638. png_ptr->mng_features_permitted =
  174639. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174640. return (png_uint_32)png_ptr->mng_features_permitted;
  174641. }
  174642. #endif
  174643. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174644. void PNGAPI
  174645. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174646. chunk_list, int num_chunks)
  174647. {
  174648. png_bytep new_list, p;
  174649. int i, old_num_chunks;
  174650. if (png_ptr == NULL)
  174651. return;
  174652. if (num_chunks == 0)
  174653. {
  174654. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174655. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174656. else
  174657. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174658. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174659. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174660. else
  174661. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174662. return;
  174663. }
  174664. if (chunk_list == NULL)
  174665. return;
  174666. old_num_chunks=png_ptr->num_chunk_list;
  174667. new_list=(png_bytep)png_malloc(png_ptr,
  174668. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174669. if(png_ptr->chunk_list != NULL)
  174670. {
  174671. png_memcpy(new_list, png_ptr->chunk_list,
  174672. (png_size_t)(5*old_num_chunks));
  174673. png_free(png_ptr, png_ptr->chunk_list);
  174674. png_ptr->chunk_list=NULL;
  174675. }
  174676. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174677. (png_size_t)(5*num_chunks));
  174678. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174679. *p=(png_byte)keep;
  174680. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174681. png_ptr->chunk_list=new_list;
  174682. #ifdef PNG_FREE_ME_SUPPORTED
  174683. png_ptr->free_me |= PNG_FREE_LIST;
  174684. #endif
  174685. }
  174686. #endif
  174687. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174688. void PNGAPI
  174689. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174690. png_user_chunk_ptr read_user_chunk_fn)
  174691. {
  174692. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174693. if (png_ptr == NULL)
  174694. return;
  174695. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174696. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174697. }
  174698. #endif
  174699. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174700. void PNGAPI
  174701. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174702. {
  174703. png_debug1(1, "in %s storage function\n", "rows");
  174704. if (png_ptr == NULL || info_ptr == NULL)
  174705. return;
  174706. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174707. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174708. info_ptr->row_pointers = row_pointers;
  174709. if(row_pointers)
  174710. info_ptr->valid |= PNG_INFO_IDAT;
  174711. }
  174712. #endif
  174713. #ifdef PNG_WRITE_SUPPORTED
  174714. void PNGAPI
  174715. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174716. {
  174717. if (png_ptr == NULL)
  174718. return;
  174719. if(png_ptr->zbuf)
  174720. png_free(png_ptr, png_ptr->zbuf);
  174721. png_ptr->zbuf_size = (png_size_t)size;
  174722. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174723. png_ptr->zstream.next_out = png_ptr->zbuf;
  174724. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174725. }
  174726. #endif
  174727. void PNGAPI
  174728. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174729. {
  174730. if (png_ptr && info_ptr)
  174731. info_ptr->valid &= ~(mask);
  174732. }
  174733. #ifndef PNG_1_0_X
  174734. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174735. void PNGAPI
  174736. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174737. {
  174738. if (png_ptr != NULL)
  174739. png_ptr->asm_flags = 0;
  174740. }
  174741. void PNGAPI
  174742. png_set_mmx_thresholds (png_structp png_ptr,
  174743. png_byte mmx_bitdepth_threshold,
  174744. png_uint_32 mmx_rowbytes_threshold)
  174745. {
  174746. if (png_ptr == NULL)
  174747. return;
  174748. }
  174749. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174750. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174751. void PNGAPI
  174752. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174753. png_uint_32 user_height_max)
  174754. {
  174755. if(png_ptr == NULL) return;
  174756. png_ptr->user_width_max = user_width_max;
  174757. png_ptr->user_height_max = user_height_max;
  174758. }
  174759. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174760. #endif /* ?PNG_1_0_X */
  174761. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174762. /*** End of inlined file: pngset.c ***/
  174763. /*** Start of inlined file: pngtrans.c ***/
  174764. #define PNG_INTERNAL
  174765. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174766. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174767. void PNGAPI
  174768. png_set_bgr(png_structp png_ptr)
  174769. {
  174770. png_debug(1, "in png_set_bgr\n");
  174771. if(png_ptr == NULL) return;
  174772. png_ptr->transformations |= PNG_BGR;
  174773. }
  174774. #endif
  174775. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174776. void PNGAPI
  174777. png_set_swap(png_structp png_ptr)
  174778. {
  174779. png_debug(1, "in png_set_swap\n");
  174780. if(png_ptr == NULL) return;
  174781. if (png_ptr->bit_depth == 16)
  174782. png_ptr->transformations |= PNG_SWAP_BYTES;
  174783. }
  174784. #endif
  174785. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174786. void PNGAPI
  174787. png_set_packing(png_structp png_ptr)
  174788. {
  174789. png_debug(1, "in png_set_packing\n");
  174790. if(png_ptr == NULL) return;
  174791. if (png_ptr->bit_depth < 8)
  174792. {
  174793. png_ptr->transformations |= PNG_PACK;
  174794. png_ptr->usr_bit_depth = 8;
  174795. }
  174796. }
  174797. #endif
  174798. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174799. void PNGAPI
  174800. png_set_packswap(png_structp png_ptr)
  174801. {
  174802. png_debug(1, "in png_set_packswap\n");
  174803. if(png_ptr == NULL) return;
  174804. if (png_ptr->bit_depth < 8)
  174805. png_ptr->transformations |= PNG_PACKSWAP;
  174806. }
  174807. #endif
  174808. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174809. void PNGAPI
  174810. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174811. {
  174812. png_debug(1, "in png_set_shift\n");
  174813. if(png_ptr == NULL) return;
  174814. png_ptr->transformations |= PNG_SHIFT;
  174815. png_ptr->shift = *true_bits;
  174816. }
  174817. #endif
  174818. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174819. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174820. int PNGAPI
  174821. png_set_interlace_handling(png_structp png_ptr)
  174822. {
  174823. png_debug(1, "in png_set_interlace handling\n");
  174824. if (png_ptr && png_ptr->interlaced)
  174825. {
  174826. png_ptr->transformations |= PNG_INTERLACE;
  174827. return (7);
  174828. }
  174829. return (1);
  174830. }
  174831. #endif
  174832. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174833. void PNGAPI
  174834. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174835. {
  174836. png_debug(1, "in png_set_filler\n");
  174837. if(png_ptr == NULL) return;
  174838. png_ptr->transformations |= PNG_FILLER;
  174839. png_ptr->filler = (png_byte)filler;
  174840. if (filler_loc == PNG_FILLER_AFTER)
  174841. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174842. else
  174843. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174844. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174845. {
  174846. png_ptr->usr_channels = 4;
  174847. }
  174848. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174849. {
  174850. png_ptr->usr_channels = 2;
  174851. }
  174852. }
  174853. #if !defined(PNG_1_0_X)
  174854. void PNGAPI
  174855. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174856. {
  174857. png_debug(1, "in png_set_add_alpha\n");
  174858. if(png_ptr == NULL) return;
  174859. png_set_filler(png_ptr, filler, filler_loc);
  174860. png_ptr->transformations |= PNG_ADD_ALPHA;
  174861. }
  174862. #endif
  174863. #endif
  174864. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174865. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174866. void PNGAPI
  174867. png_set_swap_alpha(png_structp png_ptr)
  174868. {
  174869. png_debug(1, "in png_set_swap_alpha\n");
  174870. if(png_ptr == NULL) return;
  174871. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174872. }
  174873. #endif
  174874. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174875. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174876. void PNGAPI
  174877. png_set_invert_alpha(png_structp png_ptr)
  174878. {
  174879. png_debug(1, "in png_set_invert_alpha\n");
  174880. if(png_ptr == NULL) return;
  174881. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174882. }
  174883. #endif
  174884. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174885. void PNGAPI
  174886. png_set_invert_mono(png_structp png_ptr)
  174887. {
  174888. png_debug(1, "in png_set_invert_mono\n");
  174889. if(png_ptr == NULL) return;
  174890. png_ptr->transformations |= PNG_INVERT_MONO;
  174891. }
  174892. void /* PRIVATE */
  174893. png_do_invert(png_row_infop row_info, png_bytep row)
  174894. {
  174895. png_debug(1, "in png_do_invert\n");
  174896. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174897. if (row == NULL || row_info == NULL)
  174898. return;
  174899. #endif
  174900. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174901. {
  174902. png_bytep rp = row;
  174903. png_uint_32 i;
  174904. png_uint_32 istop = row_info->rowbytes;
  174905. for (i = 0; i < istop; i++)
  174906. {
  174907. *rp = (png_byte)(~(*rp));
  174908. rp++;
  174909. }
  174910. }
  174911. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174912. row_info->bit_depth == 8)
  174913. {
  174914. png_bytep rp = row;
  174915. png_uint_32 i;
  174916. png_uint_32 istop = row_info->rowbytes;
  174917. for (i = 0; i < istop; i+=2)
  174918. {
  174919. *rp = (png_byte)(~(*rp));
  174920. rp+=2;
  174921. }
  174922. }
  174923. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174924. row_info->bit_depth == 16)
  174925. {
  174926. png_bytep rp = row;
  174927. png_uint_32 i;
  174928. png_uint_32 istop = row_info->rowbytes;
  174929. for (i = 0; i < istop; i+=4)
  174930. {
  174931. *rp = (png_byte)(~(*rp));
  174932. *(rp+1) = (png_byte)(~(*(rp+1)));
  174933. rp+=4;
  174934. }
  174935. }
  174936. }
  174937. #endif
  174938. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174939. void /* PRIVATE */
  174940. png_do_swap(png_row_infop row_info, png_bytep row)
  174941. {
  174942. png_debug(1, "in png_do_swap\n");
  174943. if (
  174944. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174945. row != NULL && row_info != NULL &&
  174946. #endif
  174947. row_info->bit_depth == 16)
  174948. {
  174949. png_bytep rp = row;
  174950. png_uint_32 i;
  174951. png_uint_32 istop= row_info->width * row_info->channels;
  174952. for (i = 0; i < istop; i++, rp += 2)
  174953. {
  174954. png_byte t = *rp;
  174955. *rp = *(rp + 1);
  174956. *(rp + 1) = t;
  174957. }
  174958. }
  174959. }
  174960. #endif
  174961. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174962. static PNG_CONST png_byte onebppswaptable[256] = {
  174963. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174964. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174965. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174966. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174967. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174968. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174969. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174970. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174971. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174972. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174973. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174974. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174975. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174976. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174977. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174978. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174979. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174980. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174981. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174982. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174983. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174984. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174985. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174986. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174987. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174988. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174989. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174990. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174991. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174992. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174993. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174994. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174995. };
  174996. static PNG_CONST png_byte twobppswaptable[256] = {
  174997. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174998. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174999. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  175000. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  175001. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  175002. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  175003. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  175004. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  175005. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  175006. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  175007. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  175008. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  175009. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  175010. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  175011. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  175012. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  175013. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  175014. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  175015. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  175016. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  175017. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  175018. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  175019. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  175020. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  175021. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  175022. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  175023. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  175024. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  175025. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  175026. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  175027. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  175028. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  175029. };
  175030. static PNG_CONST png_byte fourbppswaptable[256] = {
  175031. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  175032. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  175033. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  175034. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  175035. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  175036. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  175037. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  175038. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  175039. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  175040. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  175041. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  175042. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  175043. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  175044. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  175045. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  175046. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  175047. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  175048. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  175049. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  175050. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  175051. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  175052. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  175053. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  175054. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  175055. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  175056. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  175057. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  175058. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  175059. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  175060. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  175061. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  175062. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  175063. };
  175064. void /* PRIVATE */
  175065. png_do_packswap(png_row_infop row_info, png_bytep row)
  175066. {
  175067. png_debug(1, "in png_do_packswap\n");
  175068. if (
  175069. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175070. row != NULL && row_info != NULL &&
  175071. #endif
  175072. row_info->bit_depth < 8)
  175073. {
  175074. png_bytep rp, end, table;
  175075. end = row + row_info->rowbytes;
  175076. if (row_info->bit_depth == 1)
  175077. table = (png_bytep)onebppswaptable;
  175078. else if (row_info->bit_depth == 2)
  175079. table = (png_bytep)twobppswaptable;
  175080. else if (row_info->bit_depth == 4)
  175081. table = (png_bytep)fourbppswaptable;
  175082. else
  175083. return;
  175084. for (rp = row; rp < end; rp++)
  175085. *rp = table[*rp];
  175086. }
  175087. }
  175088. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  175089. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  175090. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  175091. void /* PRIVATE */
  175092. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  175093. {
  175094. png_debug(1, "in png_do_strip_filler\n");
  175095. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175096. if (row != NULL && row_info != NULL)
  175097. #endif
  175098. {
  175099. png_bytep sp=row;
  175100. png_bytep dp=row;
  175101. png_uint_32 row_width=row_info->width;
  175102. png_uint_32 i;
  175103. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  175104. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  175105. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175106. row_info->channels == 4)
  175107. {
  175108. if (row_info->bit_depth == 8)
  175109. {
  175110. if (flags & PNG_FLAG_FILLER_AFTER)
  175111. {
  175112. dp+=3; sp+=4;
  175113. for (i = 1; i < row_width; i++)
  175114. {
  175115. *dp++ = *sp++;
  175116. *dp++ = *sp++;
  175117. *dp++ = *sp++;
  175118. sp++;
  175119. }
  175120. }
  175121. else
  175122. {
  175123. for (i = 0; i < row_width; i++)
  175124. {
  175125. sp++;
  175126. *dp++ = *sp++;
  175127. *dp++ = *sp++;
  175128. *dp++ = *sp++;
  175129. }
  175130. }
  175131. row_info->pixel_depth = 24;
  175132. row_info->rowbytes = row_width * 3;
  175133. }
  175134. else /* if (row_info->bit_depth == 16) */
  175135. {
  175136. if (flags & PNG_FLAG_FILLER_AFTER)
  175137. {
  175138. sp += 8; dp += 6;
  175139. for (i = 1; i < row_width; i++)
  175140. {
  175141. *dp++ = *sp++;
  175142. *dp++ = *sp++;
  175143. *dp++ = *sp++;
  175144. *dp++ = *sp++;
  175145. *dp++ = *sp++;
  175146. *dp++ = *sp++;
  175147. sp += 2;
  175148. }
  175149. }
  175150. else
  175151. {
  175152. for (i = 0; i < row_width; i++)
  175153. {
  175154. sp+=2;
  175155. *dp++ = *sp++;
  175156. *dp++ = *sp++;
  175157. *dp++ = *sp++;
  175158. *dp++ = *sp++;
  175159. *dp++ = *sp++;
  175160. *dp++ = *sp++;
  175161. }
  175162. }
  175163. row_info->pixel_depth = 48;
  175164. row_info->rowbytes = row_width * 6;
  175165. }
  175166. row_info->channels = 3;
  175167. }
  175168. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  175169. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175170. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175171. row_info->channels == 2)
  175172. {
  175173. if (row_info->bit_depth == 8)
  175174. {
  175175. if (flags & PNG_FLAG_FILLER_AFTER)
  175176. {
  175177. for (i = 0; i < row_width; i++)
  175178. {
  175179. *dp++ = *sp++;
  175180. sp++;
  175181. }
  175182. }
  175183. else
  175184. {
  175185. for (i = 0; i < row_width; i++)
  175186. {
  175187. sp++;
  175188. *dp++ = *sp++;
  175189. }
  175190. }
  175191. row_info->pixel_depth = 8;
  175192. row_info->rowbytes = row_width;
  175193. }
  175194. else /* if (row_info->bit_depth == 16) */
  175195. {
  175196. if (flags & PNG_FLAG_FILLER_AFTER)
  175197. {
  175198. sp += 4; dp += 2;
  175199. for (i = 1; i < row_width; i++)
  175200. {
  175201. *dp++ = *sp++;
  175202. *dp++ = *sp++;
  175203. sp += 2;
  175204. }
  175205. }
  175206. else
  175207. {
  175208. for (i = 0; i < row_width; i++)
  175209. {
  175210. sp += 2;
  175211. *dp++ = *sp++;
  175212. *dp++ = *sp++;
  175213. }
  175214. }
  175215. row_info->pixel_depth = 16;
  175216. row_info->rowbytes = row_width * 2;
  175217. }
  175218. row_info->channels = 1;
  175219. }
  175220. if (flags & PNG_FLAG_STRIP_ALPHA)
  175221. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  175222. }
  175223. }
  175224. #endif
  175225. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175226. void /* PRIVATE */
  175227. png_do_bgr(png_row_infop row_info, png_bytep row)
  175228. {
  175229. png_debug(1, "in png_do_bgr\n");
  175230. if (
  175231. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175232. row != NULL && row_info != NULL &&
  175233. #endif
  175234. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  175235. {
  175236. png_uint_32 row_width = row_info->width;
  175237. if (row_info->bit_depth == 8)
  175238. {
  175239. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175240. {
  175241. png_bytep rp;
  175242. png_uint_32 i;
  175243. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  175244. {
  175245. png_byte save = *rp;
  175246. *rp = *(rp + 2);
  175247. *(rp + 2) = save;
  175248. }
  175249. }
  175250. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175251. {
  175252. png_bytep rp;
  175253. png_uint_32 i;
  175254. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  175255. {
  175256. png_byte save = *rp;
  175257. *rp = *(rp + 2);
  175258. *(rp + 2) = save;
  175259. }
  175260. }
  175261. }
  175262. else if (row_info->bit_depth == 16)
  175263. {
  175264. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175265. {
  175266. png_bytep rp;
  175267. png_uint_32 i;
  175268. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  175269. {
  175270. png_byte save = *rp;
  175271. *rp = *(rp + 4);
  175272. *(rp + 4) = save;
  175273. save = *(rp + 1);
  175274. *(rp + 1) = *(rp + 5);
  175275. *(rp + 5) = save;
  175276. }
  175277. }
  175278. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175279. {
  175280. png_bytep rp;
  175281. png_uint_32 i;
  175282. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  175283. {
  175284. png_byte save = *rp;
  175285. *rp = *(rp + 4);
  175286. *(rp + 4) = save;
  175287. save = *(rp + 1);
  175288. *(rp + 1) = *(rp + 5);
  175289. *(rp + 5) = save;
  175290. }
  175291. }
  175292. }
  175293. }
  175294. }
  175295. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  175296. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  175297. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175298. defined(PNG_LEGACY_SUPPORTED)
  175299. void PNGAPI
  175300. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175301. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175302. {
  175303. png_debug(1, "in png_set_user_transform_info\n");
  175304. if(png_ptr == NULL) return;
  175305. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175306. png_ptr->user_transform_ptr = user_transform_ptr;
  175307. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175308. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175309. #else
  175310. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175311. png_warning(png_ptr,
  175312. "This version of libpng does not support user transform info");
  175313. #endif
  175314. }
  175315. #endif
  175316. png_voidp PNGAPI
  175317. png_get_user_transform_ptr(png_structp png_ptr)
  175318. {
  175319. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175320. if (png_ptr == NULL) return (NULL);
  175321. return ((png_voidp)png_ptr->user_transform_ptr);
  175322. #else
  175323. return (NULL);
  175324. #endif
  175325. }
  175326. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175327. /*** End of inlined file: pngtrans.c ***/
  175328. /*** Start of inlined file: pngwio.c ***/
  175329. #define PNG_INTERNAL
  175330. #ifdef PNG_WRITE_SUPPORTED
  175331. void /* PRIVATE */
  175332. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175333. {
  175334. if (png_ptr->write_data_fn != NULL )
  175335. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175336. else
  175337. png_error(png_ptr, "Call to NULL write function");
  175338. }
  175339. #if !defined(PNG_NO_STDIO)
  175340. #ifndef USE_FAR_KEYWORD
  175341. void PNGAPI
  175342. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175343. {
  175344. png_uint_32 check;
  175345. if(png_ptr == NULL) return;
  175346. #if defined(_WIN32_WCE)
  175347. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175348. check = 0;
  175349. #else
  175350. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175351. #endif
  175352. if (check != length)
  175353. png_error(png_ptr, "Write Error");
  175354. }
  175355. #else
  175356. #define NEAR_BUF_SIZE 1024
  175357. #define MIN(a,b) (a <= b ? a : b)
  175358. void PNGAPI
  175359. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175360. {
  175361. png_uint_32 check;
  175362. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175363. png_FILE_p io_ptr;
  175364. if(png_ptr == NULL) return;
  175365. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175366. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175367. if ((png_bytep)near_data == data)
  175368. {
  175369. #if defined(_WIN32_WCE)
  175370. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175371. check = 0;
  175372. #else
  175373. check = fwrite(near_data, 1, length, io_ptr);
  175374. #endif
  175375. }
  175376. else
  175377. {
  175378. png_byte buf[NEAR_BUF_SIZE];
  175379. png_size_t written, remaining, err;
  175380. check = 0;
  175381. remaining = length;
  175382. do
  175383. {
  175384. written = MIN(NEAR_BUF_SIZE, remaining);
  175385. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175386. #if defined(_WIN32_WCE)
  175387. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175388. err = 0;
  175389. #else
  175390. err = fwrite(buf, 1, written, io_ptr);
  175391. #endif
  175392. if (err != written)
  175393. break;
  175394. else
  175395. check += err;
  175396. data += written;
  175397. remaining -= written;
  175398. }
  175399. while (remaining != 0);
  175400. }
  175401. if (check != length)
  175402. png_error(png_ptr, "Write Error");
  175403. }
  175404. #endif
  175405. #endif
  175406. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175407. void /* PRIVATE */
  175408. png_flush(png_structp png_ptr)
  175409. {
  175410. if (png_ptr->output_flush_fn != NULL)
  175411. (*(png_ptr->output_flush_fn))(png_ptr);
  175412. }
  175413. #if !defined(PNG_NO_STDIO)
  175414. void PNGAPI
  175415. png_default_flush(png_structp png_ptr)
  175416. {
  175417. #if !defined(_WIN32_WCE)
  175418. png_FILE_p io_ptr;
  175419. #endif
  175420. if(png_ptr == NULL) return;
  175421. #if !defined(_WIN32_WCE)
  175422. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175423. if (io_ptr != NULL)
  175424. fflush(io_ptr);
  175425. #endif
  175426. }
  175427. #endif
  175428. #endif
  175429. void PNGAPI
  175430. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175431. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175432. {
  175433. if(png_ptr == NULL) return;
  175434. png_ptr->io_ptr = io_ptr;
  175435. #if !defined(PNG_NO_STDIO)
  175436. if (write_data_fn != NULL)
  175437. png_ptr->write_data_fn = write_data_fn;
  175438. else
  175439. png_ptr->write_data_fn = png_default_write_data;
  175440. #else
  175441. png_ptr->write_data_fn = write_data_fn;
  175442. #endif
  175443. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175444. #if !defined(PNG_NO_STDIO)
  175445. if (output_flush_fn != NULL)
  175446. png_ptr->output_flush_fn = output_flush_fn;
  175447. else
  175448. png_ptr->output_flush_fn = png_default_flush;
  175449. #else
  175450. png_ptr->output_flush_fn = output_flush_fn;
  175451. #endif
  175452. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175453. if (png_ptr->read_data_fn != NULL)
  175454. {
  175455. png_ptr->read_data_fn = NULL;
  175456. png_warning(png_ptr,
  175457. "Attempted to set both read_data_fn and write_data_fn in");
  175458. png_warning(png_ptr,
  175459. "the same structure. Resetting read_data_fn to NULL.");
  175460. }
  175461. }
  175462. #if defined(USE_FAR_KEYWORD)
  175463. #if defined(_MSC_VER)
  175464. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175465. {
  175466. void *near_ptr;
  175467. void FAR *far_ptr;
  175468. FP_OFF(near_ptr) = FP_OFF(ptr);
  175469. far_ptr = (void FAR *)near_ptr;
  175470. if(check != 0)
  175471. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175472. png_error(png_ptr,"segment lost in conversion");
  175473. return(near_ptr);
  175474. }
  175475. # else
  175476. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175477. {
  175478. void *near_ptr;
  175479. void FAR *far_ptr;
  175480. near_ptr = (void FAR *)ptr;
  175481. far_ptr = (void FAR *)near_ptr;
  175482. if(check != 0)
  175483. if(far_ptr != ptr)
  175484. png_error(png_ptr,"segment lost in conversion");
  175485. return(near_ptr);
  175486. }
  175487. # endif
  175488. # endif
  175489. #endif /* PNG_WRITE_SUPPORTED */
  175490. /*** End of inlined file: pngwio.c ***/
  175491. /*** Start of inlined file: pngwrite.c ***/
  175492. #define PNG_INTERNAL
  175493. #ifdef PNG_WRITE_SUPPORTED
  175494. void PNGAPI
  175495. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175496. {
  175497. png_debug(1, "in png_write_info_before_PLTE\n");
  175498. if (png_ptr == NULL || info_ptr == NULL)
  175499. return;
  175500. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175501. {
  175502. png_write_sig(png_ptr); /* write PNG signature */
  175503. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175504. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175505. {
  175506. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175507. png_ptr->mng_features_permitted=0;
  175508. }
  175509. #endif
  175510. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175511. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175512. info_ptr->filter_type,
  175513. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175514. info_ptr->interlace_type);
  175515. #else
  175516. 0);
  175517. #endif
  175518. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175519. if (info_ptr->valid & PNG_INFO_gAMA)
  175520. {
  175521. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175522. png_write_gAMA(png_ptr, info_ptr->gamma);
  175523. #else
  175524. #ifdef PNG_FIXED_POINT_SUPPORTED
  175525. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175526. # endif
  175527. #endif
  175528. }
  175529. #endif
  175530. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175531. if (info_ptr->valid & PNG_INFO_sRGB)
  175532. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175533. #endif
  175534. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175535. if (info_ptr->valid & PNG_INFO_iCCP)
  175536. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175537. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175538. #endif
  175539. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175540. if (info_ptr->valid & PNG_INFO_sBIT)
  175541. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175542. #endif
  175543. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175544. if (info_ptr->valid & PNG_INFO_cHRM)
  175545. {
  175546. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175547. png_write_cHRM(png_ptr,
  175548. info_ptr->x_white, info_ptr->y_white,
  175549. info_ptr->x_red, info_ptr->y_red,
  175550. info_ptr->x_green, info_ptr->y_green,
  175551. info_ptr->x_blue, info_ptr->y_blue);
  175552. #else
  175553. # ifdef PNG_FIXED_POINT_SUPPORTED
  175554. png_write_cHRM_fixed(png_ptr,
  175555. info_ptr->int_x_white, info_ptr->int_y_white,
  175556. info_ptr->int_x_red, info_ptr->int_y_red,
  175557. info_ptr->int_x_green, info_ptr->int_y_green,
  175558. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175559. # endif
  175560. #endif
  175561. }
  175562. #endif
  175563. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175564. if (info_ptr->unknown_chunks_num)
  175565. {
  175566. png_unknown_chunk *up;
  175567. png_debug(5, "writing extra chunks\n");
  175568. for (up = info_ptr->unknown_chunks;
  175569. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175570. up++)
  175571. {
  175572. int keep=png_handle_as_unknown(png_ptr, up->name);
  175573. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175574. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175575. !(up->location & PNG_HAVE_IDAT) &&
  175576. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175577. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175578. {
  175579. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175580. }
  175581. }
  175582. }
  175583. #endif
  175584. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175585. }
  175586. }
  175587. void PNGAPI
  175588. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175589. {
  175590. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175591. int i;
  175592. #endif
  175593. png_debug(1, "in png_write_info\n");
  175594. if (png_ptr == NULL || info_ptr == NULL)
  175595. return;
  175596. png_write_info_before_PLTE(png_ptr, info_ptr);
  175597. if (info_ptr->valid & PNG_INFO_PLTE)
  175598. png_write_PLTE(png_ptr, info_ptr->palette,
  175599. (png_uint_32)info_ptr->num_palette);
  175600. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175601. png_error(png_ptr, "Valid palette required for paletted images");
  175602. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175603. if (info_ptr->valid & PNG_INFO_tRNS)
  175604. {
  175605. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175606. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175607. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175608. {
  175609. int j;
  175610. for (j=0; j<(int)info_ptr->num_trans; j++)
  175611. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175612. }
  175613. #endif
  175614. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175615. info_ptr->num_trans, info_ptr->color_type);
  175616. }
  175617. #endif
  175618. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175619. if (info_ptr->valid & PNG_INFO_bKGD)
  175620. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175621. #endif
  175622. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175623. if (info_ptr->valid & PNG_INFO_hIST)
  175624. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175625. #endif
  175626. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175627. if (info_ptr->valid & PNG_INFO_oFFs)
  175628. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175629. info_ptr->offset_unit_type);
  175630. #endif
  175631. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175632. if (info_ptr->valid & PNG_INFO_pCAL)
  175633. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175634. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175635. info_ptr->pcal_units, info_ptr->pcal_params);
  175636. #endif
  175637. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175638. if (info_ptr->valid & PNG_INFO_sCAL)
  175639. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175640. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175641. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175642. #else
  175643. #ifdef PNG_FIXED_POINT_SUPPORTED
  175644. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175645. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175646. #else
  175647. png_warning(png_ptr,
  175648. "png_write_sCAL not supported; sCAL chunk not written.");
  175649. #endif
  175650. #endif
  175651. #endif
  175652. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175653. if (info_ptr->valid & PNG_INFO_pHYs)
  175654. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175655. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175656. #endif
  175657. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175658. if (info_ptr->valid & PNG_INFO_tIME)
  175659. {
  175660. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175661. png_ptr->mode |= PNG_WROTE_tIME;
  175662. }
  175663. #endif
  175664. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175665. if (info_ptr->valid & PNG_INFO_sPLT)
  175666. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175667. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175668. #endif
  175669. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175670. for (i = 0; i < info_ptr->num_text; i++)
  175671. {
  175672. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175673. info_ptr->text[i].compression);
  175674. if (info_ptr->text[i].compression > 0)
  175675. {
  175676. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175677. png_write_iTXt(png_ptr,
  175678. info_ptr->text[i].compression,
  175679. info_ptr->text[i].key,
  175680. info_ptr->text[i].lang,
  175681. info_ptr->text[i].lang_key,
  175682. info_ptr->text[i].text);
  175683. #else
  175684. png_warning(png_ptr, "Unable to write international text");
  175685. #endif
  175686. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175687. }
  175688. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175689. {
  175690. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175691. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175692. info_ptr->text[i].text, 0,
  175693. info_ptr->text[i].compression);
  175694. #else
  175695. png_warning(png_ptr, "Unable to write compressed text");
  175696. #endif
  175697. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175698. }
  175699. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175700. {
  175701. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175702. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175703. info_ptr->text[i].text,
  175704. 0);
  175705. #else
  175706. png_warning(png_ptr, "Unable to write uncompressed text");
  175707. #endif
  175708. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175709. }
  175710. }
  175711. #endif
  175712. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175713. if (info_ptr->unknown_chunks_num)
  175714. {
  175715. png_unknown_chunk *up;
  175716. png_debug(5, "writing extra chunks\n");
  175717. for (up = info_ptr->unknown_chunks;
  175718. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175719. up++)
  175720. {
  175721. int keep=png_handle_as_unknown(png_ptr, up->name);
  175722. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175723. up->location && (up->location & PNG_HAVE_PLTE) &&
  175724. !(up->location & PNG_HAVE_IDAT) &&
  175725. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175726. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175727. {
  175728. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175729. }
  175730. }
  175731. }
  175732. #endif
  175733. }
  175734. void PNGAPI
  175735. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175736. {
  175737. png_debug(1, "in png_write_end\n");
  175738. if (png_ptr == NULL)
  175739. return;
  175740. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175741. png_error(png_ptr, "No IDATs written into file");
  175742. if (info_ptr != NULL)
  175743. {
  175744. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175745. int i; /* local index variable */
  175746. #endif
  175747. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175748. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175749. !(png_ptr->mode & PNG_WROTE_tIME))
  175750. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175751. #endif
  175752. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175753. for (i = 0; i < info_ptr->num_text; i++)
  175754. {
  175755. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175756. info_ptr->text[i].compression);
  175757. if (info_ptr->text[i].compression > 0)
  175758. {
  175759. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175760. png_write_iTXt(png_ptr,
  175761. info_ptr->text[i].compression,
  175762. info_ptr->text[i].key,
  175763. info_ptr->text[i].lang,
  175764. info_ptr->text[i].lang_key,
  175765. info_ptr->text[i].text);
  175766. #else
  175767. png_warning(png_ptr, "Unable to write international text");
  175768. #endif
  175769. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175770. }
  175771. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175772. {
  175773. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175774. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175775. info_ptr->text[i].text, 0,
  175776. info_ptr->text[i].compression);
  175777. #else
  175778. png_warning(png_ptr, "Unable to write compressed text");
  175779. #endif
  175780. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175781. }
  175782. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175783. {
  175784. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175785. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175786. info_ptr->text[i].text, 0);
  175787. #else
  175788. png_warning(png_ptr, "Unable to write uncompressed text");
  175789. #endif
  175790. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175791. }
  175792. }
  175793. #endif
  175794. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175795. if (info_ptr->unknown_chunks_num)
  175796. {
  175797. png_unknown_chunk *up;
  175798. png_debug(5, "writing extra chunks\n");
  175799. for (up = info_ptr->unknown_chunks;
  175800. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175801. up++)
  175802. {
  175803. int keep=png_handle_as_unknown(png_ptr, up->name);
  175804. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175805. up->location && (up->location & PNG_AFTER_IDAT) &&
  175806. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175807. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175808. {
  175809. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175810. }
  175811. }
  175812. }
  175813. #endif
  175814. }
  175815. png_ptr->mode |= PNG_AFTER_IDAT;
  175816. png_write_IEND(png_ptr);
  175817. }
  175818. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175819. #if !defined(_WIN32_WCE)
  175820. void PNGAPI
  175821. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175822. {
  175823. png_debug(1, "in png_convert_from_struct_tm\n");
  175824. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175825. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175826. ptime->day = (png_byte)ttime->tm_mday;
  175827. ptime->hour = (png_byte)ttime->tm_hour;
  175828. ptime->minute = (png_byte)ttime->tm_min;
  175829. ptime->second = (png_byte)ttime->tm_sec;
  175830. }
  175831. void PNGAPI
  175832. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175833. {
  175834. struct tm *tbuf;
  175835. png_debug(1, "in png_convert_from_time_t\n");
  175836. tbuf = gmtime(&ttime);
  175837. png_convert_from_struct_tm(ptime, tbuf);
  175838. }
  175839. #endif
  175840. #endif
  175841. png_structp PNGAPI
  175842. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175843. png_error_ptr error_fn, png_error_ptr warn_fn)
  175844. {
  175845. #ifdef PNG_USER_MEM_SUPPORTED
  175846. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175847. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175848. }
  175849. png_structp PNGAPI
  175850. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175851. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175852. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175853. {
  175854. #endif /* PNG_USER_MEM_SUPPORTED */
  175855. png_structp png_ptr;
  175856. #ifdef PNG_SETJMP_SUPPORTED
  175857. #ifdef USE_FAR_KEYWORD
  175858. jmp_buf jmpbuf;
  175859. #endif
  175860. #endif
  175861. int i;
  175862. png_debug(1, "in png_create_write_struct\n");
  175863. #ifdef PNG_USER_MEM_SUPPORTED
  175864. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175865. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175866. #else
  175867. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175868. #endif /* PNG_USER_MEM_SUPPORTED */
  175869. if (png_ptr == NULL)
  175870. return (NULL);
  175871. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175872. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175873. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175874. #endif
  175875. #ifdef PNG_SETJMP_SUPPORTED
  175876. #ifdef USE_FAR_KEYWORD
  175877. if (setjmp(jmpbuf))
  175878. #else
  175879. if (setjmp(png_ptr->jmpbuf))
  175880. #endif
  175881. {
  175882. png_free(png_ptr, png_ptr->zbuf);
  175883. png_ptr->zbuf=NULL;
  175884. png_destroy_struct(png_ptr);
  175885. return (NULL);
  175886. }
  175887. #ifdef USE_FAR_KEYWORD
  175888. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175889. #endif
  175890. #endif
  175891. #ifdef PNG_USER_MEM_SUPPORTED
  175892. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175893. #endif /* PNG_USER_MEM_SUPPORTED */
  175894. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175895. i=0;
  175896. do
  175897. {
  175898. if(user_png_ver[i] != png_libpng_ver[i])
  175899. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175900. } while (png_libpng_ver[i++]);
  175901. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175902. {
  175903. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175904. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175905. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175906. {
  175907. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175908. char msg[80];
  175909. if (user_png_ver)
  175910. {
  175911. png_snprintf(msg, 80,
  175912. "Application was compiled with png.h from libpng-%.20s",
  175913. user_png_ver);
  175914. png_warning(png_ptr, msg);
  175915. }
  175916. png_snprintf(msg, 80,
  175917. "Application is running with png.c from libpng-%.20s",
  175918. png_libpng_ver);
  175919. png_warning(png_ptr, msg);
  175920. #endif
  175921. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175922. png_ptr->flags=0;
  175923. #endif
  175924. png_error(png_ptr,
  175925. "Incompatible libpng version in application and library");
  175926. }
  175927. }
  175928. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175929. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175930. (png_uint_32)png_ptr->zbuf_size);
  175931. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175932. png_flush_ptr_NULL);
  175933. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175934. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175935. 1, png_doublep_NULL, png_doublep_NULL);
  175936. #endif
  175937. #ifdef PNG_SETJMP_SUPPORTED
  175938. #ifdef USE_FAR_KEYWORD
  175939. if (setjmp(jmpbuf))
  175940. PNG_ABORT();
  175941. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175942. #else
  175943. if (setjmp(png_ptr->jmpbuf))
  175944. PNG_ABORT();
  175945. #endif
  175946. #endif
  175947. return (png_ptr);
  175948. }
  175949. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175950. #undef png_write_init
  175951. void PNGAPI
  175952. png_write_init(png_structp png_ptr)
  175953. {
  175954. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175955. }
  175956. void PNGAPI
  175957. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175958. png_size_t png_struct_size, png_size_t png_info_size)
  175959. {
  175960. if(png_ptr == NULL) return;
  175961. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175962. if(png_sizeof(png_struct) > png_struct_size ||
  175963. png_sizeof(png_info) > png_info_size)
  175964. {
  175965. char msg[80];
  175966. png_ptr->warning_fn=NULL;
  175967. if (user_png_ver)
  175968. {
  175969. png_snprintf(msg, 80,
  175970. "Application was compiled with png.h from libpng-%.20s",
  175971. user_png_ver);
  175972. png_warning(png_ptr, msg);
  175973. }
  175974. png_snprintf(msg, 80,
  175975. "Application is running with png.c from libpng-%.20s",
  175976. png_libpng_ver);
  175977. png_warning(png_ptr, msg);
  175978. }
  175979. #endif
  175980. if(png_sizeof(png_struct) > png_struct_size)
  175981. {
  175982. png_ptr->error_fn=NULL;
  175983. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175984. png_ptr->flags=0;
  175985. #endif
  175986. png_error(png_ptr,
  175987. "The png struct allocated by the application for writing is too small.");
  175988. }
  175989. if(png_sizeof(png_info) > png_info_size)
  175990. {
  175991. png_ptr->error_fn=NULL;
  175992. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175993. png_ptr->flags=0;
  175994. #endif
  175995. png_error(png_ptr,
  175996. "The info struct allocated by the application for writing is too small.");
  175997. }
  175998. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175999. }
  176000. #endif /* PNG_1_0_X || PNG_1_2_X */
  176001. void PNGAPI
  176002. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  176003. png_size_t png_struct_size)
  176004. {
  176005. png_structp png_ptr=*ptr_ptr;
  176006. #ifdef PNG_SETJMP_SUPPORTED
  176007. jmp_buf tmp_jmp; /* to save current jump buffer */
  176008. #endif
  176009. int i = 0;
  176010. if (png_ptr == NULL)
  176011. return;
  176012. do
  176013. {
  176014. if (user_png_ver[i] != png_libpng_ver[i])
  176015. {
  176016. #ifdef PNG_LEGACY_SUPPORTED
  176017. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  176018. #else
  176019. png_ptr->warning_fn=NULL;
  176020. png_warning(png_ptr,
  176021. "Application uses deprecated png_write_init() and should be recompiled.");
  176022. break;
  176023. #endif
  176024. }
  176025. } while (png_libpng_ver[i++]);
  176026. png_debug(1, "in png_write_init_3\n");
  176027. #ifdef PNG_SETJMP_SUPPORTED
  176028. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176029. #endif
  176030. if (png_sizeof(png_struct) > png_struct_size)
  176031. {
  176032. png_destroy_struct(png_ptr);
  176033. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  176034. *ptr_ptr = png_ptr;
  176035. }
  176036. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176037. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  176038. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  176039. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  176040. #endif
  176041. #ifdef PNG_SETJMP_SUPPORTED
  176042. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176043. #endif
  176044. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176045. png_flush_ptr_NULL);
  176046. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176047. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176048. (png_uint_32)png_ptr->zbuf_size);
  176049. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176050. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176051. 1, png_doublep_NULL, png_doublep_NULL);
  176052. #endif
  176053. }
  176054. void PNGAPI
  176055. png_write_rows(png_structp png_ptr, png_bytepp row,
  176056. png_uint_32 num_rows)
  176057. {
  176058. png_uint_32 i; /* row counter */
  176059. png_bytepp rp; /* row pointer */
  176060. png_debug(1, "in png_write_rows\n");
  176061. if (png_ptr == NULL)
  176062. return;
  176063. for (i = 0, rp = row; i < num_rows; i++, rp++)
  176064. {
  176065. png_write_row(png_ptr, *rp);
  176066. }
  176067. }
  176068. void PNGAPI
  176069. png_write_image(png_structp png_ptr, png_bytepp image)
  176070. {
  176071. png_uint_32 i; /* row index */
  176072. int pass, num_pass; /* pass variables */
  176073. png_bytepp rp; /* points to current row */
  176074. if (png_ptr == NULL)
  176075. return;
  176076. png_debug(1, "in png_write_image\n");
  176077. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176078. num_pass = png_set_interlace_handling(png_ptr);
  176079. #else
  176080. num_pass = 1;
  176081. #endif
  176082. for (pass = 0; pass < num_pass; pass++)
  176083. {
  176084. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  176085. {
  176086. png_write_row(png_ptr, *rp);
  176087. }
  176088. }
  176089. }
  176090. void PNGAPI
  176091. png_write_row(png_structp png_ptr, png_bytep row)
  176092. {
  176093. if (png_ptr == NULL)
  176094. return;
  176095. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  176096. png_ptr->row_number, png_ptr->pass);
  176097. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  176098. {
  176099. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  176100. png_error(png_ptr,
  176101. "png_write_info was never called before png_write_row.");
  176102. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  176103. if (png_ptr->transformations & PNG_INVERT_MONO)
  176104. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  176105. #endif
  176106. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  176107. if (png_ptr->transformations & PNG_FILLER)
  176108. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  176109. #endif
  176110. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  176111. if (png_ptr->transformations & PNG_PACKSWAP)
  176112. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  176113. #endif
  176114. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  176115. if (png_ptr->transformations & PNG_PACK)
  176116. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  176117. #endif
  176118. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  176119. if (png_ptr->transformations & PNG_SHIFT)
  176120. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  176121. #endif
  176122. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  176123. if (png_ptr->transformations & PNG_BGR)
  176124. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  176125. #endif
  176126. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  176127. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176128. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  176129. #endif
  176130. png_write_start_row(png_ptr);
  176131. }
  176132. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176133. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  176134. {
  176135. switch (png_ptr->pass)
  176136. {
  176137. case 0:
  176138. if (png_ptr->row_number & 0x07)
  176139. {
  176140. png_write_finish_row(png_ptr);
  176141. return;
  176142. }
  176143. break;
  176144. case 1:
  176145. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  176146. {
  176147. png_write_finish_row(png_ptr);
  176148. return;
  176149. }
  176150. break;
  176151. case 2:
  176152. if ((png_ptr->row_number & 0x07) != 4)
  176153. {
  176154. png_write_finish_row(png_ptr);
  176155. return;
  176156. }
  176157. break;
  176158. case 3:
  176159. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  176160. {
  176161. png_write_finish_row(png_ptr);
  176162. return;
  176163. }
  176164. break;
  176165. case 4:
  176166. if ((png_ptr->row_number & 0x03) != 2)
  176167. {
  176168. png_write_finish_row(png_ptr);
  176169. return;
  176170. }
  176171. break;
  176172. case 5:
  176173. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  176174. {
  176175. png_write_finish_row(png_ptr);
  176176. return;
  176177. }
  176178. break;
  176179. case 6:
  176180. if (!(png_ptr->row_number & 0x01))
  176181. {
  176182. png_write_finish_row(png_ptr);
  176183. return;
  176184. }
  176185. break;
  176186. }
  176187. }
  176188. #endif
  176189. png_ptr->row_info.color_type = png_ptr->color_type;
  176190. png_ptr->row_info.width = png_ptr->usr_width;
  176191. png_ptr->row_info.channels = png_ptr->usr_channels;
  176192. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  176193. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  176194. png_ptr->row_info.channels);
  176195. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  176196. png_ptr->row_info.width);
  176197. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  176198. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  176199. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  176200. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  176201. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  176202. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  176203. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  176204. png_ptr->row_info.rowbytes);
  176205. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176206. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  176207. (png_ptr->transformations & PNG_INTERLACE))
  176208. {
  176209. png_do_write_interlace(&(png_ptr->row_info),
  176210. png_ptr->row_buf + 1, png_ptr->pass);
  176211. if (!(png_ptr->row_info.width))
  176212. {
  176213. png_write_finish_row(png_ptr);
  176214. return;
  176215. }
  176216. }
  176217. #endif
  176218. if (png_ptr->transformations)
  176219. png_do_write_transformations(png_ptr);
  176220. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176221. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176222. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  176223. {
  176224. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176225. }
  176226. #endif
  176227. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  176228. if (png_ptr->write_row_fn != NULL)
  176229. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  176230. }
  176231. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  176232. void PNGAPI
  176233. png_set_flush(png_structp png_ptr, int nrows)
  176234. {
  176235. png_debug(1, "in png_set_flush\n");
  176236. if (png_ptr == NULL)
  176237. return;
  176238. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  176239. }
  176240. void PNGAPI
  176241. png_write_flush(png_structp png_ptr)
  176242. {
  176243. int wrote_IDAT;
  176244. png_debug(1, "in png_write_flush\n");
  176245. if (png_ptr == NULL)
  176246. return;
  176247. if (png_ptr->row_number >= png_ptr->num_rows)
  176248. return;
  176249. do
  176250. {
  176251. int ret;
  176252. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  176253. wrote_IDAT = 0;
  176254. if (ret != Z_OK)
  176255. {
  176256. if (png_ptr->zstream.msg != NULL)
  176257. png_error(png_ptr, png_ptr->zstream.msg);
  176258. else
  176259. png_error(png_ptr, "zlib error");
  176260. }
  176261. if (!(png_ptr->zstream.avail_out))
  176262. {
  176263. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176264. png_ptr->zbuf_size);
  176265. png_ptr->zstream.next_out = png_ptr->zbuf;
  176266. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176267. wrote_IDAT = 1;
  176268. }
  176269. } while(wrote_IDAT == 1);
  176270. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  176271. {
  176272. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176273. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176274. png_ptr->zstream.next_out = png_ptr->zbuf;
  176275. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176276. }
  176277. png_ptr->flush_rows = 0;
  176278. png_flush(png_ptr);
  176279. }
  176280. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  176281. void PNGAPI
  176282. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  176283. {
  176284. png_structp png_ptr = NULL;
  176285. png_infop info_ptr = NULL;
  176286. #ifdef PNG_USER_MEM_SUPPORTED
  176287. png_free_ptr free_fn = NULL;
  176288. png_voidp mem_ptr = NULL;
  176289. #endif
  176290. png_debug(1, "in png_destroy_write_struct\n");
  176291. if (png_ptr_ptr != NULL)
  176292. {
  176293. png_ptr = *png_ptr_ptr;
  176294. #ifdef PNG_USER_MEM_SUPPORTED
  176295. free_fn = png_ptr->free_fn;
  176296. mem_ptr = png_ptr->mem_ptr;
  176297. #endif
  176298. }
  176299. if (info_ptr_ptr != NULL)
  176300. info_ptr = *info_ptr_ptr;
  176301. if (info_ptr != NULL)
  176302. {
  176303. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176304. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176305. if (png_ptr->num_chunk_list)
  176306. {
  176307. png_free(png_ptr, png_ptr->chunk_list);
  176308. png_ptr->chunk_list=NULL;
  176309. png_ptr->num_chunk_list=0;
  176310. }
  176311. #endif
  176312. #ifdef PNG_USER_MEM_SUPPORTED
  176313. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176314. (png_voidp)mem_ptr);
  176315. #else
  176316. png_destroy_struct((png_voidp)info_ptr);
  176317. #endif
  176318. *info_ptr_ptr = NULL;
  176319. }
  176320. if (png_ptr != NULL)
  176321. {
  176322. png_write_destroy(png_ptr);
  176323. #ifdef PNG_USER_MEM_SUPPORTED
  176324. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176325. (png_voidp)mem_ptr);
  176326. #else
  176327. png_destroy_struct((png_voidp)png_ptr);
  176328. #endif
  176329. *png_ptr_ptr = NULL;
  176330. }
  176331. }
  176332. void /* PRIVATE */
  176333. png_write_destroy(png_structp png_ptr)
  176334. {
  176335. #ifdef PNG_SETJMP_SUPPORTED
  176336. jmp_buf tmp_jmp; /* save jump buffer */
  176337. #endif
  176338. png_error_ptr error_fn;
  176339. png_error_ptr warning_fn;
  176340. png_voidp error_ptr;
  176341. #ifdef PNG_USER_MEM_SUPPORTED
  176342. png_free_ptr free_fn;
  176343. #endif
  176344. png_debug(1, "in png_write_destroy\n");
  176345. deflateEnd(&png_ptr->zstream);
  176346. png_free(png_ptr, png_ptr->zbuf);
  176347. png_free(png_ptr, png_ptr->row_buf);
  176348. png_free(png_ptr, png_ptr->prev_row);
  176349. png_free(png_ptr, png_ptr->sub_row);
  176350. png_free(png_ptr, png_ptr->up_row);
  176351. png_free(png_ptr, png_ptr->avg_row);
  176352. png_free(png_ptr, png_ptr->paeth_row);
  176353. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176354. png_free(png_ptr, png_ptr->time_buffer);
  176355. #endif
  176356. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176357. png_free(png_ptr, png_ptr->prev_filters);
  176358. png_free(png_ptr, png_ptr->filter_weights);
  176359. png_free(png_ptr, png_ptr->inv_filter_weights);
  176360. png_free(png_ptr, png_ptr->filter_costs);
  176361. png_free(png_ptr, png_ptr->inv_filter_costs);
  176362. #endif
  176363. #ifdef PNG_SETJMP_SUPPORTED
  176364. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176365. #endif
  176366. error_fn = png_ptr->error_fn;
  176367. warning_fn = png_ptr->warning_fn;
  176368. error_ptr = png_ptr->error_ptr;
  176369. #ifdef PNG_USER_MEM_SUPPORTED
  176370. free_fn = png_ptr->free_fn;
  176371. #endif
  176372. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176373. png_ptr->error_fn = error_fn;
  176374. png_ptr->warning_fn = warning_fn;
  176375. png_ptr->error_ptr = error_ptr;
  176376. #ifdef PNG_USER_MEM_SUPPORTED
  176377. png_ptr->free_fn = free_fn;
  176378. #endif
  176379. #ifdef PNG_SETJMP_SUPPORTED
  176380. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176381. #endif
  176382. }
  176383. void PNGAPI
  176384. png_set_filter(png_structp png_ptr, int method, int filters)
  176385. {
  176386. png_debug(1, "in png_set_filter\n");
  176387. if (png_ptr == NULL)
  176388. return;
  176389. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176390. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176391. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176392. method = PNG_FILTER_TYPE_BASE;
  176393. #endif
  176394. if (method == PNG_FILTER_TYPE_BASE)
  176395. {
  176396. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176397. {
  176398. #ifndef PNG_NO_WRITE_FILTER
  176399. case 5:
  176400. case 6:
  176401. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176402. #endif /* PNG_NO_WRITE_FILTER */
  176403. case PNG_FILTER_VALUE_NONE:
  176404. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176405. #ifndef PNG_NO_WRITE_FILTER
  176406. case PNG_FILTER_VALUE_SUB:
  176407. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176408. case PNG_FILTER_VALUE_UP:
  176409. png_ptr->do_filter=PNG_FILTER_UP; break;
  176410. case PNG_FILTER_VALUE_AVG:
  176411. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176412. case PNG_FILTER_VALUE_PAETH:
  176413. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176414. default: png_ptr->do_filter = (png_byte)filters; break;
  176415. #else
  176416. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176417. #endif /* PNG_NO_WRITE_FILTER */
  176418. }
  176419. if (png_ptr->row_buf != NULL)
  176420. {
  176421. #ifndef PNG_NO_WRITE_FILTER
  176422. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176423. {
  176424. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176425. (png_ptr->rowbytes + 1));
  176426. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176427. }
  176428. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176429. {
  176430. if (png_ptr->prev_row == NULL)
  176431. {
  176432. png_warning(png_ptr, "Can't add Up filter after starting");
  176433. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176434. }
  176435. else
  176436. {
  176437. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176438. (png_ptr->rowbytes + 1));
  176439. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176440. }
  176441. }
  176442. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176443. {
  176444. if (png_ptr->prev_row == NULL)
  176445. {
  176446. png_warning(png_ptr, "Can't add Average filter after starting");
  176447. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176448. }
  176449. else
  176450. {
  176451. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176452. (png_ptr->rowbytes + 1));
  176453. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176454. }
  176455. }
  176456. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176457. png_ptr->paeth_row == NULL)
  176458. {
  176459. if (png_ptr->prev_row == NULL)
  176460. {
  176461. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176462. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176463. }
  176464. else
  176465. {
  176466. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176467. (png_ptr->rowbytes + 1));
  176468. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176469. }
  176470. }
  176471. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176472. #endif /* PNG_NO_WRITE_FILTER */
  176473. png_ptr->do_filter = PNG_FILTER_NONE;
  176474. }
  176475. }
  176476. else
  176477. png_error(png_ptr, "Unknown custom filter method");
  176478. }
  176479. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176480. void PNGAPI
  176481. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176482. int num_weights, png_doublep filter_weights,
  176483. png_doublep filter_costs)
  176484. {
  176485. int i;
  176486. png_debug(1, "in png_set_filter_heuristics\n");
  176487. if (png_ptr == NULL)
  176488. return;
  176489. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176490. {
  176491. png_warning(png_ptr, "Unknown filter heuristic method");
  176492. return;
  176493. }
  176494. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176495. {
  176496. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176497. }
  176498. if (num_weights < 0 || filter_weights == NULL ||
  176499. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176500. {
  176501. num_weights = 0;
  176502. }
  176503. png_ptr->num_prev_filters = (png_byte)num_weights;
  176504. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176505. if (num_weights > 0)
  176506. {
  176507. if (png_ptr->prev_filters == NULL)
  176508. {
  176509. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176510. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176511. for (i = 0; i < num_weights; i++)
  176512. {
  176513. png_ptr->prev_filters[i] = 255;
  176514. }
  176515. }
  176516. if (png_ptr->filter_weights == NULL)
  176517. {
  176518. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176519. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176520. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176521. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176522. for (i = 0; i < num_weights; i++)
  176523. {
  176524. png_ptr->inv_filter_weights[i] =
  176525. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176526. }
  176527. }
  176528. for (i = 0; i < num_weights; i++)
  176529. {
  176530. if (filter_weights[i] < 0.0)
  176531. {
  176532. png_ptr->inv_filter_weights[i] =
  176533. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176534. }
  176535. else
  176536. {
  176537. png_ptr->inv_filter_weights[i] =
  176538. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176539. png_ptr->filter_weights[i] =
  176540. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176541. }
  176542. }
  176543. }
  176544. if (png_ptr->filter_costs == NULL)
  176545. {
  176546. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176547. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176548. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176549. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176550. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176551. {
  176552. png_ptr->inv_filter_costs[i] =
  176553. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176554. }
  176555. }
  176556. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176557. {
  176558. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176559. {
  176560. png_ptr->inv_filter_costs[i] =
  176561. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176562. }
  176563. else if (filter_costs[i] >= 1.0)
  176564. {
  176565. png_ptr->inv_filter_costs[i] =
  176566. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176567. png_ptr->filter_costs[i] =
  176568. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176569. }
  176570. }
  176571. }
  176572. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176573. void PNGAPI
  176574. png_set_compression_level(png_structp png_ptr, int level)
  176575. {
  176576. png_debug(1, "in png_set_compression_level\n");
  176577. if (png_ptr == NULL)
  176578. return;
  176579. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176580. png_ptr->zlib_level = level;
  176581. }
  176582. void PNGAPI
  176583. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176584. {
  176585. png_debug(1, "in png_set_compression_mem_level\n");
  176586. if (png_ptr == NULL)
  176587. return;
  176588. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176589. png_ptr->zlib_mem_level = mem_level;
  176590. }
  176591. void PNGAPI
  176592. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176593. {
  176594. png_debug(1, "in png_set_compression_strategy\n");
  176595. if (png_ptr == NULL)
  176596. return;
  176597. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176598. png_ptr->zlib_strategy = strategy;
  176599. }
  176600. void PNGAPI
  176601. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176602. {
  176603. if (png_ptr == NULL)
  176604. return;
  176605. if (window_bits > 15)
  176606. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176607. else if (window_bits < 8)
  176608. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176609. #ifndef WBITS_8_OK
  176610. if (window_bits == 8)
  176611. {
  176612. png_warning(png_ptr, "Compression window is being reset to 512");
  176613. window_bits=9;
  176614. }
  176615. #endif
  176616. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176617. png_ptr->zlib_window_bits = window_bits;
  176618. }
  176619. void PNGAPI
  176620. png_set_compression_method(png_structp png_ptr, int method)
  176621. {
  176622. png_debug(1, "in png_set_compression_method\n");
  176623. if (png_ptr == NULL)
  176624. return;
  176625. if (method != 8)
  176626. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176627. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176628. png_ptr->zlib_method = method;
  176629. }
  176630. void PNGAPI
  176631. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176632. {
  176633. if (png_ptr == NULL)
  176634. return;
  176635. png_ptr->write_row_fn = write_row_fn;
  176636. }
  176637. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176638. void PNGAPI
  176639. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176640. write_user_transform_fn)
  176641. {
  176642. png_debug(1, "in png_set_write_user_transform_fn\n");
  176643. if (png_ptr == NULL)
  176644. return;
  176645. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176646. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176647. }
  176648. #endif
  176649. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176650. void PNGAPI
  176651. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176652. int transforms, voidp params)
  176653. {
  176654. if (png_ptr == NULL || info_ptr == NULL)
  176655. return;
  176656. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176657. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176658. png_set_invert_alpha(png_ptr);
  176659. #endif
  176660. png_write_info(png_ptr, info_ptr);
  176661. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176662. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176663. png_set_invert_mono(png_ptr);
  176664. #endif
  176665. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176666. if ((transforms & PNG_TRANSFORM_SHIFT)
  176667. && (info_ptr->valid & PNG_INFO_sBIT))
  176668. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176669. #endif
  176670. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176671. if (transforms & PNG_TRANSFORM_PACKING)
  176672. png_set_packing(png_ptr);
  176673. #endif
  176674. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176675. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176676. png_set_swap_alpha(png_ptr);
  176677. #endif
  176678. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176679. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176680. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176681. #endif
  176682. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176683. if (transforms & PNG_TRANSFORM_BGR)
  176684. png_set_bgr(png_ptr);
  176685. #endif
  176686. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176687. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176688. png_set_swap(png_ptr);
  176689. #endif
  176690. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176691. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176692. png_set_packswap(png_ptr);
  176693. #endif
  176694. if (info_ptr->valid & PNG_INFO_IDAT)
  176695. png_write_image(png_ptr, info_ptr->row_pointers);
  176696. png_write_end(png_ptr, info_ptr);
  176697. transforms = transforms; /* quiet compiler warnings */
  176698. params = params;
  176699. }
  176700. #endif
  176701. #endif /* PNG_WRITE_SUPPORTED */
  176702. /*** End of inlined file: pngwrite.c ***/
  176703. /*** Start of inlined file: pngwtran.c ***/
  176704. #define PNG_INTERNAL
  176705. #ifdef PNG_WRITE_SUPPORTED
  176706. void /* PRIVATE */
  176707. png_do_write_transformations(png_structp png_ptr)
  176708. {
  176709. png_debug(1, "in png_do_write_transformations\n");
  176710. if (png_ptr == NULL)
  176711. return;
  176712. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176713. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176714. if(png_ptr->write_user_transform_fn != NULL)
  176715. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176716. (png_ptr, /* png_ptr */
  176717. &(png_ptr->row_info), /* row_info: */
  176718. png_ptr->row_buf + 1); /* start of pixel data for row */
  176719. #endif
  176720. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176721. if (png_ptr->transformations & PNG_FILLER)
  176722. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176723. png_ptr->flags);
  176724. #endif
  176725. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176726. if (png_ptr->transformations & PNG_PACKSWAP)
  176727. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176728. #endif
  176729. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176730. if (png_ptr->transformations & PNG_PACK)
  176731. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176732. (png_uint_32)png_ptr->bit_depth);
  176733. #endif
  176734. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176735. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176736. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176737. #endif
  176738. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176739. if (png_ptr->transformations & PNG_SHIFT)
  176740. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176741. &(png_ptr->shift));
  176742. #endif
  176743. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176744. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176745. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176746. #endif
  176747. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176748. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176749. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176750. #endif
  176751. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176752. if (png_ptr->transformations & PNG_BGR)
  176753. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176754. #endif
  176755. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176756. if (png_ptr->transformations & PNG_INVERT_MONO)
  176757. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176758. #endif
  176759. }
  176760. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176761. void /* PRIVATE */
  176762. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176763. {
  176764. png_debug(1, "in png_do_pack\n");
  176765. if (row_info->bit_depth == 8 &&
  176766. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176767. row != NULL && row_info != NULL &&
  176768. #endif
  176769. row_info->channels == 1)
  176770. {
  176771. switch ((int)bit_depth)
  176772. {
  176773. case 1:
  176774. {
  176775. png_bytep sp, dp;
  176776. int mask, v;
  176777. png_uint_32 i;
  176778. png_uint_32 row_width = row_info->width;
  176779. sp = row;
  176780. dp = row;
  176781. mask = 0x80;
  176782. v = 0;
  176783. for (i = 0; i < row_width; i++)
  176784. {
  176785. if (*sp != 0)
  176786. v |= mask;
  176787. sp++;
  176788. if (mask > 1)
  176789. mask >>= 1;
  176790. else
  176791. {
  176792. mask = 0x80;
  176793. *dp = (png_byte)v;
  176794. dp++;
  176795. v = 0;
  176796. }
  176797. }
  176798. if (mask != 0x80)
  176799. *dp = (png_byte)v;
  176800. break;
  176801. }
  176802. case 2:
  176803. {
  176804. png_bytep sp, dp;
  176805. int shift, v;
  176806. png_uint_32 i;
  176807. png_uint_32 row_width = row_info->width;
  176808. sp = row;
  176809. dp = row;
  176810. shift = 6;
  176811. v = 0;
  176812. for (i = 0; i < row_width; i++)
  176813. {
  176814. png_byte value;
  176815. value = (png_byte)(*sp & 0x03);
  176816. v |= (value << shift);
  176817. if (shift == 0)
  176818. {
  176819. shift = 6;
  176820. *dp = (png_byte)v;
  176821. dp++;
  176822. v = 0;
  176823. }
  176824. else
  176825. shift -= 2;
  176826. sp++;
  176827. }
  176828. if (shift != 6)
  176829. *dp = (png_byte)v;
  176830. break;
  176831. }
  176832. case 4:
  176833. {
  176834. png_bytep sp, dp;
  176835. int shift, v;
  176836. png_uint_32 i;
  176837. png_uint_32 row_width = row_info->width;
  176838. sp = row;
  176839. dp = row;
  176840. shift = 4;
  176841. v = 0;
  176842. for (i = 0; i < row_width; i++)
  176843. {
  176844. png_byte value;
  176845. value = (png_byte)(*sp & 0x0f);
  176846. v |= (value << shift);
  176847. if (shift == 0)
  176848. {
  176849. shift = 4;
  176850. *dp = (png_byte)v;
  176851. dp++;
  176852. v = 0;
  176853. }
  176854. else
  176855. shift -= 4;
  176856. sp++;
  176857. }
  176858. if (shift != 4)
  176859. *dp = (png_byte)v;
  176860. break;
  176861. }
  176862. }
  176863. row_info->bit_depth = (png_byte)bit_depth;
  176864. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176865. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176866. row_info->width);
  176867. }
  176868. }
  176869. #endif
  176870. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176871. void /* PRIVATE */
  176872. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176873. {
  176874. png_debug(1, "in png_do_shift\n");
  176875. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176876. if (row != NULL && row_info != NULL &&
  176877. #else
  176878. if (
  176879. #endif
  176880. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176881. {
  176882. int shift_start[4], shift_dec[4];
  176883. int channels = 0;
  176884. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176885. {
  176886. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176887. shift_dec[channels] = bit_depth->red;
  176888. channels++;
  176889. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176890. shift_dec[channels] = bit_depth->green;
  176891. channels++;
  176892. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176893. shift_dec[channels] = bit_depth->blue;
  176894. channels++;
  176895. }
  176896. else
  176897. {
  176898. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176899. shift_dec[channels] = bit_depth->gray;
  176900. channels++;
  176901. }
  176902. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176903. {
  176904. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176905. shift_dec[channels] = bit_depth->alpha;
  176906. channels++;
  176907. }
  176908. if (row_info->bit_depth < 8)
  176909. {
  176910. png_bytep bp = row;
  176911. png_uint_32 i;
  176912. png_byte mask;
  176913. png_uint_32 row_bytes = row_info->rowbytes;
  176914. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176915. mask = 0x55;
  176916. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176917. mask = 0x11;
  176918. else
  176919. mask = 0xff;
  176920. for (i = 0; i < row_bytes; i++, bp++)
  176921. {
  176922. png_uint_16 v;
  176923. int j;
  176924. v = *bp;
  176925. *bp = 0;
  176926. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176927. {
  176928. if (j > 0)
  176929. *bp |= (png_byte)((v << j) & 0xff);
  176930. else
  176931. *bp |= (png_byte)((v >> (-j)) & mask);
  176932. }
  176933. }
  176934. }
  176935. else if (row_info->bit_depth == 8)
  176936. {
  176937. png_bytep bp = row;
  176938. png_uint_32 i;
  176939. png_uint_32 istop = channels * row_info->width;
  176940. for (i = 0; i < istop; i++, bp++)
  176941. {
  176942. png_uint_16 v;
  176943. int j;
  176944. int c = (int)(i%channels);
  176945. v = *bp;
  176946. *bp = 0;
  176947. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176948. {
  176949. if (j > 0)
  176950. *bp |= (png_byte)((v << j) & 0xff);
  176951. else
  176952. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176953. }
  176954. }
  176955. }
  176956. else
  176957. {
  176958. png_bytep bp;
  176959. png_uint_32 i;
  176960. png_uint_32 istop = channels * row_info->width;
  176961. for (bp = row, i = 0; i < istop; i++)
  176962. {
  176963. int c = (int)(i%channels);
  176964. png_uint_16 value, v;
  176965. int j;
  176966. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176967. value = 0;
  176968. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176969. {
  176970. if (j > 0)
  176971. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176972. else
  176973. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176974. }
  176975. *bp++ = (png_byte)(value >> 8);
  176976. *bp++ = (png_byte)(value & 0xff);
  176977. }
  176978. }
  176979. }
  176980. }
  176981. #endif
  176982. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176983. void /* PRIVATE */
  176984. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176985. {
  176986. png_debug(1, "in png_do_write_swap_alpha\n");
  176987. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176988. if (row != NULL && row_info != NULL)
  176989. #endif
  176990. {
  176991. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176992. {
  176993. if (row_info->bit_depth == 8)
  176994. {
  176995. png_bytep sp, dp;
  176996. png_uint_32 i;
  176997. png_uint_32 row_width = row_info->width;
  176998. for (i = 0, sp = dp = row; i < row_width; i++)
  176999. {
  177000. png_byte save = *(sp++);
  177001. *(dp++) = *(sp++);
  177002. *(dp++) = *(sp++);
  177003. *(dp++) = *(sp++);
  177004. *(dp++) = save;
  177005. }
  177006. }
  177007. else
  177008. {
  177009. png_bytep sp, dp;
  177010. png_uint_32 i;
  177011. png_uint_32 row_width = row_info->width;
  177012. for (i = 0, sp = dp = row; i < row_width; i++)
  177013. {
  177014. png_byte save[2];
  177015. save[0] = *(sp++);
  177016. save[1] = *(sp++);
  177017. *(dp++) = *(sp++);
  177018. *(dp++) = *(sp++);
  177019. *(dp++) = *(sp++);
  177020. *(dp++) = *(sp++);
  177021. *(dp++) = *(sp++);
  177022. *(dp++) = *(sp++);
  177023. *(dp++) = save[0];
  177024. *(dp++) = save[1];
  177025. }
  177026. }
  177027. }
  177028. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177029. {
  177030. if (row_info->bit_depth == 8)
  177031. {
  177032. png_bytep sp, dp;
  177033. png_uint_32 i;
  177034. png_uint_32 row_width = row_info->width;
  177035. for (i = 0, sp = dp = row; i < row_width; i++)
  177036. {
  177037. png_byte save = *(sp++);
  177038. *(dp++) = *(sp++);
  177039. *(dp++) = save;
  177040. }
  177041. }
  177042. else
  177043. {
  177044. png_bytep sp, dp;
  177045. png_uint_32 i;
  177046. png_uint_32 row_width = row_info->width;
  177047. for (i = 0, sp = dp = row; i < row_width; i++)
  177048. {
  177049. png_byte save[2];
  177050. save[0] = *(sp++);
  177051. save[1] = *(sp++);
  177052. *(dp++) = *(sp++);
  177053. *(dp++) = *(sp++);
  177054. *(dp++) = save[0];
  177055. *(dp++) = save[1];
  177056. }
  177057. }
  177058. }
  177059. }
  177060. }
  177061. #endif
  177062. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177063. void /* PRIVATE */
  177064. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  177065. {
  177066. png_debug(1, "in png_do_write_invert_alpha\n");
  177067. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177068. if (row != NULL && row_info != NULL)
  177069. #endif
  177070. {
  177071. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177072. {
  177073. if (row_info->bit_depth == 8)
  177074. {
  177075. png_bytep sp, dp;
  177076. png_uint_32 i;
  177077. png_uint_32 row_width = row_info->width;
  177078. for (i = 0, sp = dp = row; i < row_width; i++)
  177079. {
  177080. sp+=3; dp = sp;
  177081. *(dp++) = (png_byte)(255 - *(sp++));
  177082. }
  177083. }
  177084. else
  177085. {
  177086. png_bytep sp, dp;
  177087. png_uint_32 i;
  177088. png_uint_32 row_width = row_info->width;
  177089. for (i = 0, sp = dp = row; i < row_width; i++)
  177090. {
  177091. sp+=6; dp = sp;
  177092. *(dp++) = (png_byte)(255 - *(sp++));
  177093. *(dp++) = (png_byte)(255 - *(sp++));
  177094. }
  177095. }
  177096. }
  177097. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177098. {
  177099. if (row_info->bit_depth == 8)
  177100. {
  177101. png_bytep sp, dp;
  177102. png_uint_32 i;
  177103. png_uint_32 row_width = row_info->width;
  177104. for (i = 0, sp = dp = row; i < row_width; i++)
  177105. {
  177106. *(dp++) = *(sp++);
  177107. *(dp++) = (png_byte)(255 - *(sp++));
  177108. }
  177109. }
  177110. else
  177111. {
  177112. png_bytep sp, dp;
  177113. png_uint_32 i;
  177114. png_uint_32 row_width = row_info->width;
  177115. for (i = 0, sp = dp = row; i < row_width; i++)
  177116. {
  177117. sp+=2; dp = sp;
  177118. *(dp++) = (png_byte)(255 - *(sp++));
  177119. *(dp++) = (png_byte)(255 - *(sp++));
  177120. }
  177121. }
  177122. }
  177123. }
  177124. }
  177125. #endif
  177126. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177127. void /* PRIVATE */
  177128. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  177129. {
  177130. png_debug(1, "in png_do_write_intrapixel\n");
  177131. if (
  177132. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177133. row != NULL && row_info != NULL &&
  177134. #endif
  177135. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  177136. {
  177137. int bytes_per_pixel;
  177138. png_uint_32 row_width = row_info->width;
  177139. if (row_info->bit_depth == 8)
  177140. {
  177141. png_bytep rp;
  177142. png_uint_32 i;
  177143. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177144. bytes_per_pixel = 3;
  177145. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177146. bytes_per_pixel = 4;
  177147. else
  177148. return;
  177149. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177150. {
  177151. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  177152. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  177153. }
  177154. }
  177155. else if (row_info->bit_depth == 16)
  177156. {
  177157. png_bytep rp;
  177158. png_uint_32 i;
  177159. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177160. bytes_per_pixel = 6;
  177161. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177162. bytes_per_pixel = 8;
  177163. else
  177164. return;
  177165. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177166. {
  177167. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  177168. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  177169. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  177170. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  177171. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  177172. *(rp ) = (png_byte)((red >> 8) & 0xff);
  177173. *(rp+1) = (png_byte)(red & 0xff);
  177174. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  177175. *(rp+5) = (png_byte)(blue & 0xff);
  177176. }
  177177. }
  177178. }
  177179. }
  177180. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  177181. #endif /* PNG_WRITE_SUPPORTED */
  177182. /*** End of inlined file: pngwtran.c ***/
  177183. /*** Start of inlined file: pngwutil.c ***/
  177184. #define PNG_INTERNAL
  177185. #ifdef PNG_WRITE_SUPPORTED
  177186. void PNGAPI
  177187. png_save_uint_32(png_bytep buf, png_uint_32 i)
  177188. {
  177189. buf[0] = (png_byte)((i >> 24) & 0xff);
  177190. buf[1] = (png_byte)((i >> 16) & 0xff);
  177191. buf[2] = (png_byte)((i >> 8) & 0xff);
  177192. buf[3] = (png_byte)(i & 0xff);
  177193. }
  177194. void PNGAPI
  177195. png_save_int_32(png_bytep buf, png_int_32 i)
  177196. {
  177197. buf[0] = (png_byte)((i >> 24) & 0xff);
  177198. buf[1] = (png_byte)((i >> 16) & 0xff);
  177199. buf[2] = (png_byte)((i >> 8) & 0xff);
  177200. buf[3] = (png_byte)(i & 0xff);
  177201. }
  177202. void PNGAPI
  177203. png_save_uint_16(png_bytep buf, unsigned int i)
  177204. {
  177205. buf[0] = (png_byte)((i >> 8) & 0xff);
  177206. buf[1] = (png_byte)(i & 0xff);
  177207. }
  177208. void PNGAPI
  177209. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  177210. png_bytep data, png_size_t length)
  177211. {
  177212. if(png_ptr == NULL) return;
  177213. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  177214. png_write_chunk_data(png_ptr, data, length);
  177215. png_write_chunk_end(png_ptr);
  177216. }
  177217. void PNGAPI
  177218. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  177219. png_uint_32 length)
  177220. {
  177221. png_byte buf[4];
  177222. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  177223. if(png_ptr == NULL) return;
  177224. png_save_uint_32(buf, length);
  177225. png_write_data(png_ptr, buf, (png_size_t)4);
  177226. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  177227. png_reset_crc(png_ptr);
  177228. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  177229. }
  177230. void PNGAPI
  177231. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  177232. {
  177233. if(png_ptr == NULL) return;
  177234. if (data != NULL && length > 0)
  177235. {
  177236. png_calculate_crc(png_ptr, data, length);
  177237. png_write_data(png_ptr, data, length);
  177238. }
  177239. }
  177240. void PNGAPI
  177241. png_write_chunk_end(png_structp png_ptr)
  177242. {
  177243. png_byte buf[4];
  177244. if(png_ptr == NULL) return;
  177245. png_save_uint_32(buf, png_ptr->crc);
  177246. png_write_data(png_ptr, buf, (png_size_t)4);
  177247. }
  177248. void /* PRIVATE */
  177249. png_write_sig(png_structp png_ptr)
  177250. {
  177251. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  177252. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  177253. (png_size_t)8 - png_ptr->sig_bytes);
  177254. if(png_ptr->sig_bytes < 3)
  177255. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  177256. }
  177257. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  177258. typedef struct
  177259. {
  177260. char *input; /* the uncompressed input data */
  177261. int input_len; /* its length */
  177262. int num_output_ptr; /* number of output pointers used */
  177263. int max_output_ptr; /* size of output_ptr */
  177264. png_charpp output_ptr; /* array of pointers to output */
  177265. } compression_state;
  177266. static int /* PRIVATE */
  177267. png_text_compress(png_structp png_ptr,
  177268. png_charp text, png_size_t text_len, int compression,
  177269. compression_state *comp)
  177270. {
  177271. int ret;
  177272. comp->num_output_ptr = 0;
  177273. comp->max_output_ptr = 0;
  177274. comp->output_ptr = NULL;
  177275. comp->input = NULL;
  177276. comp->input_len = 0;
  177277. if (compression == PNG_TEXT_COMPRESSION_NONE)
  177278. {
  177279. comp->input = text;
  177280. comp->input_len = text_len;
  177281. return((int)text_len);
  177282. }
  177283. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  177284. {
  177285. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177286. char msg[50];
  177287. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  177288. png_warning(png_ptr, msg);
  177289. #else
  177290. png_warning(png_ptr, "Unknown compression type");
  177291. #endif
  177292. }
  177293. png_ptr->zstream.avail_in = (uInt)text_len;
  177294. png_ptr->zstream.next_in = (Bytef *)text;
  177295. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177296. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  177297. do
  177298. {
  177299. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177300. if (ret != Z_OK)
  177301. {
  177302. if (png_ptr->zstream.msg != NULL)
  177303. png_error(png_ptr, png_ptr->zstream.msg);
  177304. else
  177305. png_error(png_ptr, "zlib error");
  177306. }
  177307. if (!(png_ptr->zstream.avail_out))
  177308. {
  177309. if (comp->num_output_ptr >= comp->max_output_ptr)
  177310. {
  177311. int old_max;
  177312. old_max = comp->max_output_ptr;
  177313. comp->max_output_ptr = comp->num_output_ptr + 4;
  177314. if (comp->output_ptr != NULL)
  177315. {
  177316. png_charpp old_ptr;
  177317. old_ptr = comp->output_ptr;
  177318. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177319. (png_uint_32)(comp->max_output_ptr *
  177320. png_sizeof (png_charpp)));
  177321. png_memcpy(comp->output_ptr, old_ptr, old_max
  177322. * png_sizeof (png_charp));
  177323. png_free(png_ptr, old_ptr);
  177324. }
  177325. else
  177326. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177327. (png_uint_32)(comp->max_output_ptr *
  177328. png_sizeof (png_charp)));
  177329. }
  177330. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177331. (png_uint_32)png_ptr->zbuf_size);
  177332. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177333. png_ptr->zbuf_size);
  177334. comp->num_output_ptr++;
  177335. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177336. png_ptr->zstream.next_out = png_ptr->zbuf;
  177337. }
  177338. } while (png_ptr->zstream.avail_in);
  177339. do
  177340. {
  177341. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177342. if (ret == Z_OK)
  177343. {
  177344. if (!(png_ptr->zstream.avail_out))
  177345. {
  177346. if (comp->num_output_ptr >= comp->max_output_ptr)
  177347. {
  177348. int old_max;
  177349. old_max = comp->max_output_ptr;
  177350. comp->max_output_ptr = comp->num_output_ptr + 4;
  177351. if (comp->output_ptr != NULL)
  177352. {
  177353. png_charpp old_ptr;
  177354. old_ptr = comp->output_ptr;
  177355. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177356. (png_uint_32)(comp->max_output_ptr *
  177357. png_sizeof (png_charpp)));
  177358. png_memcpy(comp->output_ptr, old_ptr,
  177359. old_max * png_sizeof (png_charp));
  177360. png_free(png_ptr, old_ptr);
  177361. }
  177362. else
  177363. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177364. (png_uint_32)(comp->max_output_ptr *
  177365. png_sizeof (png_charp)));
  177366. }
  177367. comp->output_ptr[comp->num_output_ptr] =
  177368. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177369. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177370. png_ptr->zbuf_size);
  177371. comp->num_output_ptr++;
  177372. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177373. png_ptr->zstream.next_out = png_ptr->zbuf;
  177374. }
  177375. }
  177376. else if (ret != Z_STREAM_END)
  177377. {
  177378. if (png_ptr->zstream.msg != NULL)
  177379. png_error(png_ptr, png_ptr->zstream.msg);
  177380. else
  177381. png_error(png_ptr, "zlib error");
  177382. }
  177383. } while (ret != Z_STREAM_END);
  177384. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177385. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177386. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177387. return((int)text_len);
  177388. }
  177389. static void /* PRIVATE */
  177390. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177391. {
  177392. int i;
  177393. if (comp->input)
  177394. {
  177395. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177396. (png_size_t)comp->input_len);
  177397. return;
  177398. }
  177399. for (i = 0; i < comp->num_output_ptr; i++)
  177400. {
  177401. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177402. png_ptr->zbuf_size);
  177403. png_free(png_ptr, comp->output_ptr[i]);
  177404. comp->output_ptr[i]=NULL;
  177405. }
  177406. if (comp->max_output_ptr != 0)
  177407. png_free(png_ptr, comp->output_ptr);
  177408. comp->output_ptr=NULL;
  177409. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177410. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177411. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177412. deflateReset(&png_ptr->zstream);
  177413. png_ptr->zstream.data_type = Z_BINARY;
  177414. }
  177415. #endif
  177416. void /* PRIVATE */
  177417. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177418. int bit_depth, int color_type, int compression_type, int filter_type,
  177419. int interlace_type)
  177420. {
  177421. #ifdef PNG_USE_LOCAL_ARRAYS
  177422. PNG_IHDR;
  177423. #endif
  177424. png_byte buf[13]; /* buffer to store the IHDR info */
  177425. png_debug(1, "in png_write_IHDR\n");
  177426. switch (color_type)
  177427. {
  177428. case PNG_COLOR_TYPE_GRAY:
  177429. switch (bit_depth)
  177430. {
  177431. case 1:
  177432. case 2:
  177433. case 4:
  177434. case 8:
  177435. case 16: png_ptr->channels = 1; break;
  177436. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177437. }
  177438. break;
  177439. case PNG_COLOR_TYPE_RGB:
  177440. if (bit_depth != 8 && bit_depth != 16)
  177441. png_error(png_ptr, "Invalid bit depth for RGB image");
  177442. png_ptr->channels = 3;
  177443. break;
  177444. case PNG_COLOR_TYPE_PALETTE:
  177445. switch (bit_depth)
  177446. {
  177447. case 1:
  177448. case 2:
  177449. case 4:
  177450. case 8: png_ptr->channels = 1; break;
  177451. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177452. }
  177453. break;
  177454. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177455. if (bit_depth != 8 && bit_depth != 16)
  177456. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177457. png_ptr->channels = 2;
  177458. break;
  177459. case PNG_COLOR_TYPE_RGB_ALPHA:
  177460. if (bit_depth != 8 && bit_depth != 16)
  177461. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177462. png_ptr->channels = 4;
  177463. break;
  177464. default:
  177465. png_error(png_ptr, "Invalid image color type specified");
  177466. }
  177467. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177468. {
  177469. png_warning(png_ptr, "Invalid compression type specified");
  177470. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177471. }
  177472. if (
  177473. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177474. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177475. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177476. (color_type == PNG_COLOR_TYPE_RGB ||
  177477. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177478. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177479. #endif
  177480. filter_type != PNG_FILTER_TYPE_BASE)
  177481. {
  177482. png_warning(png_ptr, "Invalid filter type specified");
  177483. filter_type = PNG_FILTER_TYPE_BASE;
  177484. }
  177485. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177486. if (interlace_type != PNG_INTERLACE_NONE &&
  177487. interlace_type != PNG_INTERLACE_ADAM7)
  177488. {
  177489. png_warning(png_ptr, "Invalid interlace type specified");
  177490. interlace_type = PNG_INTERLACE_ADAM7;
  177491. }
  177492. #else
  177493. interlace_type=PNG_INTERLACE_NONE;
  177494. #endif
  177495. png_ptr->bit_depth = (png_byte)bit_depth;
  177496. png_ptr->color_type = (png_byte)color_type;
  177497. png_ptr->interlaced = (png_byte)interlace_type;
  177498. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177499. png_ptr->filter_type = (png_byte)filter_type;
  177500. #endif
  177501. png_ptr->compression_type = (png_byte)compression_type;
  177502. png_ptr->width = width;
  177503. png_ptr->height = height;
  177504. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177505. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177506. png_ptr->usr_width = png_ptr->width;
  177507. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177508. png_ptr->usr_channels = png_ptr->channels;
  177509. png_save_uint_32(buf, width);
  177510. png_save_uint_32(buf + 4, height);
  177511. buf[8] = (png_byte)bit_depth;
  177512. buf[9] = (png_byte)color_type;
  177513. buf[10] = (png_byte)compression_type;
  177514. buf[11] = (png_byte)filter_type;
  177515. buf[12] = (png_byte)interlace_type;
  177516. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177517. png_ptr->zstream.zalloc = png_zalloc;
  177518. png_ptr->zstream.zfree = png_zfree;
  177519. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177520. if (!(png_ptr->do_filter))
  177521. {
  177522. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177523. png_ptr->bit_depth < 8)
  177524. png_ptr->do_filter = PNG_FILTER_NONE;
  177525. else
  177526. png_ptr->do_filter = PNG_ALL_FILTERS;
  177527. }
  177528. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177529. {
  177530. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177531. png_ptr->zlib_strategy = Z_FILTERED;
  177532. else
  177533. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177534. }
  177535. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177536. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177537. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177538. png_ptr->zlib_mem_level = 8;
  177539. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177540. png_ptr->zlib_window_bits = 15;
  177541. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177542. png_ptr->zlib_method = 8;
  177543. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177544. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177545. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177546. png_error(png_ptr, "zlib failed to initialize compressor");
  177547. png_ptr->zstream.next_out = png_ptr->zbuf;
  177548. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177549. png_ptr->zstream.data_type = Z_BINARY;
  177550. png_ptr->mode = PNG_HAVE_IHDR;
  177551. }
  177552. void /* PRIVATE */
  177553. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177554. {
  177555. #ifdef PNG_USE_LOCAL_ARRAYS
  177556. PNG_PLTE;
  177557. #endif
  177558. png_uint_32 i;
  177559. png_colorp pal_ptr;
  177560. png_byte buf[3];
  177561. png_debug(1, "in png_write_PLTE\n");
  177562. if ((
  177563. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177564. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177565. #endif
  177566. num_pal == 0) || num_pal > 256)
  177567. {
  177568. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177569. {
  177570. png_error(png_ptr, "Invalid number of colors in palette");
  177571. }
  177572. else
  177573. {
  177574. png_warning(png_ptr, "Invalid number of colors in palette");
  177575. return;
  177576. }
  177577. }
  177578. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177579. {
  177580. png_warning(png_ptr,
  177581. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177582. return;
  177583. }
  177584. png_ptr->num_palette = (png_uint_16)num_pal;
  177585. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177586. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177587. #ifndef PNG_NO_POINTER_INDEXING
  177588. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177589. {
  177590. buf[0] = pal_ptr->red;
  177591. buf[1] = pal_ptr->green;
  177592. buf[2] = pal_ptr->blue;
  177593. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177594. }
  177595. #else
  177596. pal_ptr=palette;
  177597. for (i = 0; i < num_pal; i++)
  177598. {
  177599. buf[0] = pal_ptr[i].red;
  177600. buf[1] = pal_ptr[i].green;
  177601. buf[2] = pal_ptr[i].blue;
  177602. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177603. }
  177604. #endif
  177605. png_write_chunk_end(png_ptr);
  177606. png_ptr->mode |= PNG_HAVE_PLTE;
  177607. }
  177608. void /* PRIVATE */
  177609. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177610. {
  177611. #ifdef PNG_USE_LOCAL_ARRAYS
  177612. PNG_IDAT;
  177613. #endif
  177614. png_debug(1, "in png_write_IDAT\n");
  177615. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177616. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177617. {
  177618. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177619. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177620. {
  177621. if (length >= 2 &&
  177622. png_ptr->height < 16384 && png_ptr->width < 16384)
  177623. {
  177624. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177625. ((png_ptr->width *
  177626. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177627. unsigned int z_cinfo = z_cmf >> 4;
  177628. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177629. while (uncompressed_idat_size <= half_z_window_size &&
  177630. half_z_window_size >= 256)
  177631. {
  177632. z_cinfo--;
  177633. half_z_window_size >>= 1;
  177634. }
  177635. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177636. if (data[0] != (png_byte)z_cmf)
  177637. {
  177638. data[0] = (png_byte)z_cmf;
  177639. data[1] &= 0xe0;
  177640. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177641. }
  177642. }
  177643. }
  177644. else
  177645. png_error(png_ptr,
  177646. "Invalid zlib compression method or flags in IDAT");
  177647. }
  177648. png_write_chunk(png_ptr, png_IDAT, data, length);
  177649. png_ptr->mode |= PNG_HAVE_IDAT;
  177650. }
  177651. void /* PRIVATE */
  177652. png_write_IEND(png_structp png_ptr)
  177653. {
  177654. #ifdef PNG_USE_LOCAL_ARRAYS
  177655. PNG_IEND;
  177656. #endif
  177657. png_debug(1, "in png_write_IEND\n");
  177658. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177659. (png_size_t)0);
  177660. png_ptr->mode |= PNG_HAVE_IEND;
  177661. }
  177662. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177663. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177664. void /* PRIVATE */
  177665. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177666. {
  177667. #ifdef PNG_USE_LOCAL_ARRAYS
  177668. PNG_gAMA;
  177669. #endif
  177670. png_uint_32 igamma;
  177671. png_byte buf[4];
  177672. png_debug(1, "in png_write_gAMA\n");
  177673. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177674. png_save_uint_32(buf, igamma);
  177675. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177676. }
  177677. #endif
  177678. #ifdef PNG_FIXED_POINT_SUPPORTED
  177679. void /* PRIVATE */
  177680. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177681. {
  177682. #ifdef PNG_USE_LOCAL_ARRAYS
  177683. PNG_gAMA;
  177684. #endif
  177685. png_byte buf[4];
  177686. png_debug(1, "in png_write_gAMA\n");
  177687. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177688. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177689. }
  177690. #endif
  177691. #endif
  177692. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177693. void /* PRIVATE */
  177694. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177695. {
  177696. #ifdef PNG_USE_LOCAL_ARRAYS
  177697. PNG_sRGB;
  177698. #endif
  177699. png_byte buf[1];
  177700. png_debug(1, "in png_write_sRGB\n");
  177701. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177702. png_warning(png_ptr,
  177703. "Invalid sRGB rendering intent specified");
  177704. buf[0]=(png_byte)srgb_intent;
  177705. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177706. }
  177707. #endif
  177708. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177709. void /* PRIVATE */
  177710. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177711. png_charp profile, int profile_len)
  177712. {
  177713. #ifdef PNG_USE_LOCAL_ARRAYS
  177714. PNG_iCCP;
  177715. #endif
  177716. png_size_t name_len;
  177717. png_charp new_name;
  177718. compression_state comp;
  177719. int embedded_profile_len = 0;
  177720. png_debug(1, "in png_write_iCCP\n");
  177721. comp.num_output_ptr = 0;
  177722. comp.max_output_ptr = 0;
  177723. comp.output_ptr = NULL;
  177724. comp.input = NULL;
  177725. comp.input_len = 0;
  177726. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177727. &new_name)) == 0)
  177728. {
  177729. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177730. return;
  177731. }
  177732. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177733. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177734. if (profile == NULL)
  177735. profile_len = 0;
  177736. if (profile_len > 3)
  177737. embedded_profile_len =
  177738. ((*( (png_bytep)profile ))<<24) |
  177739. ((*( (png_bytep)profile+1))<<16) |
  177740. ((*( (png_bytep)profile+2))<< 8) |
  177741. ((*( (png_bytep)profile+3)) );
  177742. if (profile_len < embedded_profile_len)
  177743. {
  177744. png_warning(png_ptr,
  177745. "Embedded profile length too large in iCCP chunk");
  177746. return;
  177747. }
  177748. if (profile_len > embedded_profile_len)
  177749. {
  177750. png_warning(png_ptr,
  177751. "Truncating profile to actual length in iCCP chunk");
  177752. profile_len = embedded_profile_len;
  177753. }
  177754. if (profile_len)
  177755. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177756. PNG_COMPRESSION_TYPE_BASE, &comp);
  177757. png_write_chunk_start(png_ptr, png_iCCP,
  177758. (png_uint_32)name_len+profile_len+2);
  177759. new_name[name_len+1]=0x00;
  177760. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177761. if (profile_len)
  177762. png_write_compressed_data_out(png_ptr, &comp);
  177763. png_write_chunk_end(png_ptr);
  177764. png_free(png_ptr, new_name);
  177765. }
  177766. #endif
  177767. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177768. void /* PRIVATE */
  177769. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177770. {
  177771. #ifdef PNG_USE_LOCAL_ARRAYS
  177772. PNG_sPLT;
  177773. #endif
  177774. png_size_t name_len;
  177775. png_charp new_name;
  177776. png_byte entrybuf[10];
  177777. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177778. int palette_size = entry_size * spalette->nentries;
  177779. png_sPLT_entryp ep;
  177780. #ifdef PNG_NO_POINTER_INDEXING
  177781. int i;
  177782. #endif
  177783. png_debug(1, "in png_write_sPLT\n");
  177784. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177785. spalette->name, &new_name))==0)
  177786. {
  177787. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177788. return;
  177789. }
  177790. png_write_chunk_start(png_ptr, png_sPLT,
  177791. (png_uint_32)(name_len + 2 + palette_size));
  177792. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177793. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177794. #ifndef PNG_NO_POINTER_INDEXING
  177795. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177796. {
  177797. if (spalette->depth == 8)
  177798. {
  177799. entrybuf[0] = (png_byte)ep->red;
  177800. entrybuf[1] = (png_byte)ep->green;
  177801. entrybuf[2] = (png_byte)ep->blue;
  177802. entrybuf[3] = (png_byte)ep->alpha;
  177803. png_save_uint_16(entrybuf + 4, ep->frequency);
  177804. }
  177805. else
  177806. {
  177807. png_save_uint_16(entrybuf + 0, ep->red);
  177808. png_save_uint_16(entrybuf + 2, ep->green);
  177809. png_save_uint_16(entrybuf + 4, ep->blue);
  177810. png_save_uint_16(entrybuf + 6, ep->alpha);
  177811. png_save_uint_16(entrybuf + 8, ep->frequency);
  177812. }
  177813. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177814. }
  177815. #else
  177816. ep=spalette->entries;
  177817. for (i=0; i>spalette->nentries; i++)
  177818. {
  177819. if (spalette->depth == 8)
  177820. {
  177821. entrybuf[0] = (png_byte)ep[i].red;
  177822. entrybuf[1] = (png_byte)ep[i].green;
  177823. entrybuf[2] = (png_byte)ep[i].blue;
  177824. entrybuf[3] = (png_byte)ep[i].alpha;
  177825. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177826. }
  177827. else
  177828. {
  177829. png_save_uint_16(entrybuf + 0, ep[i].red);
  177830. png_save_uint_16(entrybuf + 2, ep[i].green);
  177831. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177832. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177833. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177834. }
  177835. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177836. }
  177837. #endif
  177838. png_write_chunk_end(png_ptr);
  177839. png_free(png_ptr, new_name);
  177840. }
  177841. #endif
  177842. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177843. void /* PRIVATE */
  177844. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177845. {
  177846. #ifdef PNG_USE_LOCAL_ARRAYS
  177847. PNG_sBIT;
  177848. #endif
  177849. png_byte buf[4];
  177850. png_size_t size;
  177851. png_debug(1, "in png_write_sBIT\n");
  177852. if (color_type & PNG_COLOR_MASK_COLOR)
  177853. {
  177854. png_byte maxbits;
  177855. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177856. png_ptr->usr_bit_depth);
  177857. if (sbit->red == 0 || sbit->red > maxbits ||
  177858. sbit->green == 0 || sbit->green > maxbits ||
  177859. sbit->blue == 0 || sbit->blue > maxbits)
  177860. {
  177861. png_warning(png_ptr, "Invalid sBIT depth specified");
  177862. return;
  177863. }
  177864. buf[0] = sbit->red;
  177865. buf[1] = sbit->green;
  177866. buf[2] = sbit->blue;
  177867. size = 3;
  177868. }
  177869. else
  177870. {
  177871. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177872. {
  177873. png_warning(png_ptr, "Invalid sBIT depth specified");
  177874. return;
  177875. }
  177876. buf[0] = sbit->gray;
  177877. size = 1;
  177878. }
  177879. if (color_type & PNG_COLOR_MASK_ALPHA)
  177880. {
  177881. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177882. {
  177883. png_warning(png_ptr, "Invalid sBIT depth specified");
  177884. return;
  177885. }
  177886. buf[size++] = sbit->alpha;
  177887. }
  177888. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177889. }
  177890. #endif
  177891. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177892. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177893. void /* PRIVATE */
  177894. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177895. double red_x, double red_y, double green_x, double green_y,
  177896. double blue_x, double blue_y)
  177897. {
  177898. #ifdef PNG_USE_LOCAL_ARRAYS
  177899. PNG_cHRM;
  177900. #endif
  177901. png_byte buf[32];
  177902. png_uint_32 itemp;
  177903. png_debug(1, "in png_write_cHRM\n");
  177904. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177905. white_x + white_y > 1.0)
  177906. {
  177907. png_warning(png_ptr, "Invalid cHRM white point specified");
  177908. #if !defined(PNG_NO_CONSOLE_IO)
  177909. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177910. #endif
  177911. return;
  177912. }
  177913. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177914. png_save_uint_32(buf, itemp);
  177915. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177916. png_save_uint_32(buf + 4, itemp);
  177917. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177918. {
  177919. png_warning(png_ptr, "Invalid cHRM red point specified");
  177920. return;
  177921. }
  177922. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177923. png_save_uint_32(buf + 8, itemp);
  177924. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177925. png_save_uint_32(buf + 12, itemp);
  177926. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177927. {
  177928. png_warning(png_ptr, "Invalid cHRM green point specified");
  177929. return;
  177930. }
  177931. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177932. png_save_uint_32(buf + 16, itemp);
  177933. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177934. png_save_uint_32(buf + 20, itemp);
  177935. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177936. {
  177937. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177938. return;
  177939. }
  177940. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177941. png_save_uint_32(buf + 24, itemp);
  177942. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177943. png_save_uint_32(buf + 28, itemp);
  177944. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177945. }
  177946. #endif
  177947. #ifdef PNG_FIXED_POINT_SUPPORTED
  177948. void /* PRIVATE */
  177949. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177950. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177951. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177952. png_fixed_point blue_y)
  177953. {
  177954. #ifdef PNG_USE_LOCAL_ARRAYS
  177955. PNG_cHRM;
  177956. #endif
  177957. png_byte buf[32];
  177958. png_debug(1, "in png_write_cHRM\n");
  177959. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177960. {
  177961. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177962. #if !defined(PNG_NO_CONSOLE_IO)
  177963. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177964. #endif
  177965. return;
  177966. }
  177967. png_save_uint_32(buf, (png_uint_32)white_x);
  177968. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177969. if (red_x + red_y > 100000L)
  177970. {
  177971. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177972. return;
  177973. }
  177974. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177975. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177976. if (green_x + green_y > 100000L)
  177977. {
  177978. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177979. return;
  177980. }
  177981. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177982. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177983. if (blue_x + blue_y > 100000L)
  177984. {
  177985. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177986. return;
  177987. }
  177988. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177989. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177990. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177991. }
  177992. #endif
  177993. #endif
  177994. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177995. void /* PRIVATE */
  177996. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177997. int num_trans, int color_type)
  177998. {
  177999. #ifdef PNG_USE_LOCAL_ARRAYS
  178000. PNG_tRNS;
  178001. #endif
  178002. png_byte buf[6];
  178003. png_debug(1, "in png_write_tRNS\n");
  178004. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178005. {
  178006. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  178007. {
  178008. png_warning(png_ptr,"Invalid number of transparent colors specified");
  178009. return;
  178010. }
  178011. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  178012. }
  178013. else if (color_type == PNG_COLOR_TYPE_GRAY)
  178014. {
  178015. if(tran->gray >= (1 << png_ptr->bit_depth))
  178016. {
  178017. png_warning(png_ptr,
  178018. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  178019. return;
  178020. }
  178021. png_save_uint_16(buf, tran->gray);
  178022. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  178023. }
  178024. else if (color_type == PNG_COLOR_TYPE_RGB)
  178025. {
  178026. png_save_uint_16(buf, tran->red);
  178027. png_save_uint_16(buf + 2, tran->green);
  178028. png_save_uint_16(buf + 4, tran->blue);
  178029. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178030. {
  178031. png_warning(png_ptr,
  178032. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  178033. return;
  178034. }
  178035. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  178036. }
  178037. else
  178038. {
  178039. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  178040. }
  178041. }
  178042. #endif
  178043. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  178044. void /* PRIVATE */
  178045. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  178046. {
  178047. #ifdef PNG_USE_LOCAL_ARRAYS
  178048. PNG_bKGD;
  178049. #endif
  178050. png_byte buf[6];
  178051. png_debug(1, "in png_write_bKGD\n");
  178052. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178053. {
  178054. if (
  178055. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  178056. (png_ptr->num_palette ||
  178057. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  178058. #endif
  178059. back->index > png_ptr->num_palette)
  178060. {
  178061. png_warning(png_ptr, "Invalid background palette index");
  178062. return;
  178063. }
  178064. buf[0] = back->index;
  178065. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  178066. }
  178067. else if (color_type & PNG_COLOR_MASK_COLOR)
  178068. {
  178069. png_save_uint_16(buf, back->red);
  178070. png_save_uint_16(buf + 2, back->green);
  178071. png_save_uint_16(buf + 4, back->blue);
  178072. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178073. {
  178074. png_warning(png_ptr,
  178075. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  178076. return;
  178077. }
  178078. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  178079. }
  178080. else
  178081. {
  178082. if(back->gray >= (1 << png_ptr->bit_depth))
  178083. {
  178084. png_warning(png_ptr,
  178085. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  178086. return;
  178087. }
  178088. png_save_uint_16(buf, back->gray);
  178089. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  178090. }
  178091. }
  178092. #endif
  178093. #if defined(PNG_WRITE_hIST_SUPPORTED)
  178094. void /* PRIVATE */
  178095. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  178096. {
  178097. #ifdef PNG_USE_LOCAL_ARRAYS
  178098. PNG_hIST;
  178099. #endif
  178100. int i;
  178101. png_byte buf[3];
  178102. png_debug(1, "in png_write_hIST\n");
  178103. if (num_hist > (int)png_ptr->num_palette)
  178104. {
  178105. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  178106. png_ptr->num_palette);
  178107. png_warning(png_ptr, "Invalid number of histogram entries specified");
  178108. return;
  178109. }
  178110. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  178111. for (i = 0; i < num_hist; i++)
  178112. {
  178113. png_save_uint_16(buf, hist[i]);
  178114. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  178115. }
  178116. png_write_chunk_end(png_ptr);
  178117. }
  178118. #endif
  178119. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  178120. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  178121. png_size_t /* PRIVATE */
  178122. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  178123. {
  178124. png_size_t key_len;
  178125. png_charp kp, dp;
  178126. int kflag;
  178127. int kwarn=0;
  178128. png_debug(1, "in png_check_keyword\n");
  178129. *new_key = NULL;
  178130. if (key == NULL || (key_len = png_strlen(key)) == 0)
  178131. {
  178132. png_warning(png_ptr, "zero length keyword");
  178133. return ((png_size_t)0);
  178134. }
  178135. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  178136. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  178137. if (*new_key == NULL)
  178138. {
  178139. png_warning(png_ptr, "Out of memory while procesing keyword");
  178140. return ((png_size_t)0);
  178141. }
  178142. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  178143. {
  178144. if ((png_byte)*kp < 0x20 ||
  178145. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  178146. {
  178147. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  178148. char msg[40];
  178149. png_snprintf(msg, 40,
  178150. "invalid keyword character 0x%02X", (png_byte)*kp);
  178151. png_warning(png_ptr, msg);
  178152. #else
  178153. png_warning(png_ptr, "invalid character in keyword");
  178154. #endif
  178155. *dp = ' ';
  178156. }
  178157. else
  178158. {
  178159. *dp = *kp;
  178160. }
  178161. }
  178162. *dp = '\0';
  178163. kp = *new_key + key_len - 1;
  178164. if (*kp == ' ')
  178165. {
  178166. png_warning(png_ptr, "trailing spaces removed from keyword");
  178167. while (*kp == ' ')
  178168. {
  178169. *(kp--) = '\0';
  178170. key_len--;
  178171. }
  178172. }
  178173. kp = *new_key;
  178174. if (*kp == ' ')
  178175. {
  178176. png_warning(png_ptr, "leading spaces removed from keyword");
  178177. while (*kp == ' ')
  178178. {
  178179. kp++;
  178180. key_len--;
  178181. }
  178182. }
  178183. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  178184. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  178185. {
  178186. if (*kp == ' ' && kflag == 0)
  178187. {
  178188. *(dp++) = *kp;
  178189. kflag = 1;
  178190. }
  178191. else if (*kp == ' ')
  178192. {
  178193. key_len--;
  178194. kwarn=1;
  178195. }
  178196. else
  178197. {
  178198. *(dp++) = *kp;
  178199. kflag = 0;
  178200. }
  178201. }
  178202. *dp = '\0';
  178203. if(kwarn)
  178204. png_warning(png_ptr, "extra interior spaces removed from keyword");
  178205. if (key_len == 0)
  178206. {
  178207. png_free(png_ptr, *new_key);
  178208. *new_key=NULL;
  178209. png_warning(png_ptr, "Zero length keyword");
  178210. }
  178211. if (key_len > 79)
  178212. {
  178213. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  178214. new_key[79] = '\0';
  178215. key_len = 79;
  178216. }
  178217. return (key_len);
  178218. }
  178219. #endif
  178220. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  178221. void /* PRIVATE */
  178222. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  178223. png_size_t text_len)
  178224. {
  178225. #ifdef PNG_USE_LOCAL_ARRAYS
  178226. PNG_tEXt;
  178227. #endif
  178228. png_size_t key_len;
  178229. png_charp new_key;
  178230. png_debug(1, "in png_write_tEXt\n");
  178231. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178232. {
  178233. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  178234. return;
  178235. }
  178236. if (text == NULL || *text == '\0')
  178237. text_len = 0;
  178238. else
  178239. text_len = png_strlen(text);
  178240. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  178241. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178242. if (text_len)
  178243. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  178244. png_write_chunk_end(png_ptr);
  178245. png_free(png_ptr, new_key);
  178246. }
  178247. #endif
  178248. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  178249. void /* PRIVATE */
  178250. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  178251. png_size_t text_len, int compression)
  178252. {
  178253. #ifdef PNG_USE_LOCAL_ARRAYS
  178254. PNG_zTXt;
  178255. #endif
  178256. png_size_t key_len;
  178257. char buf[1];
  178258. png_charp new_key;
  178259. compression_state comp;
  178260. png_debug(1, "in png_write_zTXt\n");
  178261. comp.num_output_ptr = 0;
  178262. comp.max_output_ptr = 0;
  178263. comp.output_ptr = NULL;
  178264. comp.input = NULL;
  178265. comp.input_len = 0;
  178266. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178267. {
  178268. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  178269. return;
  178270. }
  178271. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  178272. {
  178273. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  178274. png_free(png_ptr, new_key);
  178275. return;
  178276. }
  178277. text_len = png_strlen(text);
  178278. text_len = png_text_compress(png_ptr, text, text_len, compression,
  178279. &comp);
  178280. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  178281. (key_len+text_len+2));
  178282. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178283. png_free(png_ptr, new_key);
  178284. buf[0] = (png_byte)compression;
  178285. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  178286. png_write_compressed_data_out(png_ptr, &comp);
  178287. png_write_chunk_end(png_ptr);
  178288. }
  178289. #endif
  178290. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  178291. void /* PRIVATE */
  178292. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  178293. png_charp lang, png_charp lang_key, png_charp text)
  178294. {
  178295. #ifdef PNG_USE_LOCAL_ARRAYS
  178296. PNG_iTXt;
  178297. #endif
  178298. png_size_t lang_len, key_len, lang_key_len, text_len;
  178299. png_charp new_lang, new_key;
  178300. png_byte cbuf[2];
  178301. compression_state comp;
  178302. png_debug(1, "in png_write_iTXt\n");
  178303. comp.num_output_ptr = 0;
  178304. comp.max_output_ptr = 0;
  178305. comp.output_ptr = NULL;
  178306. comp.input = NULL;
  178307. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178308. {
  178309. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178310. return;
  178311. }
  178312. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178313. {
  178314. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178315. new_lang = NULL;
  178316. lang_len = 0;
  178317. }
  178318. if (lang_key == NULL)
  178319. lang_key_len = 0;
  178320. else
  178321. lang_key_len = png_strlen(lang_key);
  178322. if (text == NULL)
  178323. text_len = 0;
  178324. else
  178325. text_len = png_strlen(text);
  178326. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178327. &comp);
  178328. png_write_chunk_start(png_ptr, png_iTXt,
  178329. (png_uint_32)(
  178330. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178331. + key_len
  178332. + lang_len
  178333. + lang_key_len
  178334. + text_len));
  178335. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178336. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178337. compression == PNG_TEXT_COMPRESSION_NONE)
  178338. cbuf[0] = 0;
  178339. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178340. cbuf[0] = 1;
  178341. cbuf[1] = 0;
  178342. png_write_chunk_data(png_ptr, cbuf, 2);
  178343. cbuf[0] = 0;
  178344. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178345. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178346. png_write_compressed_data_out(png_ptr, &comp);
  178347. png_write_chunk_end(png_ptr);
  178348. png_free(png_ptr, new_key);
  178349. if (new_lang)
  178350. png_free(png_ptr, new_lang);
  178351. }
  178352. #endif
  178353. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178354. void /* PRIVATE */
  178355. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178356. int unit_type)
  178357. {
  178358. #ifdef PNG_USE_LOCAL_ARRAYS
  178359. PNG_oFFs;
  178360. #endif
  178361. png_byte buf[9];
  178362. png_debug(1, "in png_write_oFFs\n");
  178363. if (unit_type >= PNG_OFFSET_LAST)
  178364. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178365. png_save_int_32(buf, x_offset);
  178366. png_save_int_32(buf + 4, y_offset);
  178367. buf[8] = (png_byte)unit_type;
  178368. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178369. }
  178370. #endif
  178371. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178372. void /* PRIVATE */
  178373. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178374. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178375. {
  178376. #ifdef PNG_USE_LOCAL_ARRAYS
  178377. PNG_pCAL;
  178378. #endif
  178379. png_size_t purpose_len, units_len, total_len;
  178380. png_uint_32p params_len;
  178381. png_byte buf[10];
  178382. png_charp new_purpose;
  178383. int i;
  178384. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178385. if (type >= PNG_EQUATION_LAST)
  178386. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178387. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178388. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178389. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178390. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178391. total_len = purpose_len + units_len + 10;
  178392. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178393. *png_sizeof(png_uint_32)));
  178394. for (i = 0; i < nparams; i++)
  178395. {
  178396. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178397. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178398. total_len += (png_size_t)params_len[i];
  178399. }
  178400. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178401. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178402. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178403. png_save_int_32(buf, X0);
  178404. png_save_int_32(buf + 4, X1);
  178405. buf[8] = (png_byte)type;
  178406. buf[9] = (png_byte)nparams;
  178407. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178408. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178409. png_free(png_ptr, new_purpose);
  178410. for (i = 0; i < nparams; i++)
  178411. {
  178412. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178413. (png_size_t)params_len[i]);
  178414. }
  178415. png_free(png_ptr, params_len);
  178416. png_write_chunk_end(png_ptr);
  178417. }
  178418. #endif
  178419. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178420. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178421. void /* PRIVATE */
  178422. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178423. {
  178424. #ifdef PNG_USE_LOCAL_ARRAYS
  178425. PNG_sCAL;
  178426. #endif
  178427. char buf[64];
  178428. png_size_t total_len;
  178429. png_debug(1, "in png_write_sCAL\n");
  178430. buf[0] = (char)unit;
  178431. #if defined(_WIN32_WCE)
  178432. {
  178433. wchar_t wc_buf[32];
  178434. size_t wc_len;
  178435. swprintf(wc_buf, TEXT("%12.12e"), width);
  178436. wc_len = wcslen(wc_buf);
  178437. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178438. total_len = wc_len + 2;
  178439. swprintf(wc_buf, TEXT("%12.12e"), height);
  178440. wc_len = wcslen(wc_buf);
  178441. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178442. NULL, NULL);
  178443. total_len += wc_len;
  178444. }
  178445. #else
  178446. png_snprintf(buf + 1, 63, "%12.12e", width);
  178447. total_len = 1 + png_strlen(buf + 1) + 1;
  178448. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178449. total_len += png_strlen(buf + total_len);
  178450. #endif
  178451. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178452. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178453. }
  178454. #else
  178455. #ifdef PNG_FIXED_POINT_SUPPORTED
  178456. void /* PRIVATE */
  178457. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178458. png_charp height)
  178459. {
  178460. #ifdef PNG_USE_LOCAL_ARRAYS
  178461. PNG_sCAL;
  178462. #endif
  178463. png_byte buf[64];
  178464. png_size_t wlen, hlen, total_len;
  178465. png_debug(1, "in png_write_sCAL_s\n");
  178466. wlen = png_strlen(width);
  178467. hlen = png_strlen(height);
  178468. total_len = wlen + hlen + 2;
  178469. if (total_len > 64)
  178470. {
  178471. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178472. return;
  178473. }
  178474. buf[0] = (png_byte)unit;
  178475. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178476. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178477. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178478. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178479. }
  178480. #endif
  178481. #endif
  178482. #endif
  178483. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178484. void /* PRIVATE */
  178485. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178486. png_uint_32 y_pixels_per_unit,
  178487. int unit_type)
  178488. {
  178489. #ifdef PNG_USE_LOCAL_ARRAYS
  178490. PNG_pHYs;
  178491. #endif
  178492. png_byte buf[9];
  178493. png_debug(1, "in png_write_pHYs\n");
  178494. if (unit_type >= PNG_RESOLUTION_LAST)
  178495. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178496. png_save_uint_32(buf, x_pixels_per_unit);
  178497. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178498. buf[8] = (png_byte)unit_type;
  178499. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178500. }
  178501. #endif
  178502. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178503. void /* PRIVATE */
  178504. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178505. {
  178506. #ifdef PNG_USE_LOCAL_ARRAYS
  178507. PNG_tIME;
  178508. #endif
  178509. png_byte buf[7];
  178510. png_debug(1, "in png_write_tIME\n");
  178511. if (mod_time->month > 12 || mod_time->month < 1 ||
  178512. mod_time->day > 31 || mod_time->day < 1 ||
  178513. mod_time->hour > 23 || mod_time->second > 60)
  178514. {
  178515. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178516. return;
  178517. }
  178518. png_save_uint_16(buf, mod_time->year);
  178519. buf[2] = mod_time->month;
  178520. buf[3] = mod_time->day;
  178521. buf[4] = mod_time->hour;
  178522. buf[5] = mod_time->minute;
  178523. buf[6] = mod_time->second;
  178524. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178525. }
  178526. #endif
  178527. void /* PRIVATE */
  178528. png_write_start_row(png_structp png_ptr)
  178529. {
  178530. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178531. #ifdef PNG_USE_LOCAL_ARRAYS
  178532. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178533. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178534. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178535. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178536. #endif
  178537. #endif
  178538. png_size_t buf_size;
  178539. png_debug(1, "in png_write_start_row\n");
  178540. buf_size = (png_size_t)(PNG_ROWBYTES(
  178541. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178542. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178543. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178544. #ifndef PNG_NO_WRITE_FILTERING
  178545. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178546. {
  178547. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178548. (png_ptr->rowbytes + 1));
  178549. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178550. }
  178551. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178552. {
  178553. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178554. png_memset(png_ptr->prev_row, 0, buf_size);
  178555. if (png_ptr->do_filter & PNG_FILTER_UP)
  178556. {
  178557. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178558. (png_ptr->rowbytes + 1));
  178559. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178560. }
  178561. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178562. {
  178563. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178564. (png_ptr->rowbytes + 1));
  178565. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178566. }
  178567. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178568. {
  178569. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178570. (png_ptr->rowbytes + 1));
  178571. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178572. }
  178573. #endif /* PNG_NO_WRITE_FILTERING */
  178574. }
  178575. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178576. if (png_ptr->interlaced)
  178577. {
  178578. if (!(png_ptr->transformations & PNG_INTERLACE))
  178579. {
  178580. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178581. png_pass_ystart[0]) / png_pass_yinc[0];
  178582. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178583. png_pass_start[0]) / png_pass_inc[0];
  178584. }
  178585. else
  178586. {
  178587. png_ptr->num_rows = png_ptr->height;
  178588. png_ptr->usr_width = png_ptr->width;
  178589. }
  178590. }
  178591. else
  178592. #endif
  178593. {
  178594. png_ptr->num_rows = png_ptr->height;
  178595. png_ptr->usr_width = png_ptr->width;
  178596. }
  178597. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178598. png_ptr->zstream.next_out = png_ptr->zbuf;
  178599. }
  178600. void /* PRIVATE */
  178601. png_write_finish_row(png_structp png_ptr)
  178602. {
  178603. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178604. #ifdef PNG_USE_LOCAL_ARRAYS
  178605. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178606. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178607. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178608. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178609. #endif
  178610. #endif
  178611. int ret;
  178612. png_debug(1, "in png_write_finish_row\n");
  178613. png_ptr->row_number++;
  178614. if (png_ptr->row_number < png_ptr->num_rows)
  178615. return;
  178616. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178617. if (png_ptr->interlaced)
  178618. {
  178619. png_ptr->row_number = 0;
  178620. if (png_ptr->transformations & PNG_INTERLACE)
  178621. {
  178622. png_ptr->pass++;
  178623. }
  178624. else
  178625. {
  178626. do
  178627. {
  178628. png_ptr->pass++;
  178629. if (png_ptr->pass >= 7)
  178630. break;
  178631. png_ptr->usr_width = (png_ptr->width +
  178632. png_pass_inc[png_ptr->pass] - 1 -
  178633. png_pass_start[png_ptr->pass]) /
  178634. png_pass_inc[png_ptr->pass];
  178635. png_ptr->num_rows = (png_ptr->height +
  178636. png_pass_yinc[png_ptr->pass] - 1 -
  178637. png_pass_ystart[png_ptr->pass]) /
  178638. png_pass_yinc[png_ptr->pass];
  178639. if (png_ptr->transformations & PNG_INTERLACE)
  178640. break;
  178641. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178642. }
  178643. if (png_ptr->pass < 7)
  178644. {
  178645. if (png_ptr->prev_row != NULL)
  178646. png_memset(png_ptr->prev_row, 0,
  178647. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178648. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178649. return;
  178650. }
  178651. }
  178652. #endif
  178653. do
  178654. {
  178655. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178656. if (ret == Z_OK)
  178657. {
  178658. if (!(png_ptr->zstream.avail_out))
  178659. {
  178660. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178661. png_ptr->zstream.next_out = png_ptr->zbuf;
  178662. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178663. }
  178664. }
  178665. else if (ret != Z_STREAM_END)
  178666. {
  178667. if (png_ptr->zstream.msg != NULL)
  178668. png_error(png_ptr, png_ptr->zstream.msg);
  178669. else
  178670. png_error(png_ptr, "zlib error");
  178671. }
  178672. } while (ret != Z_STREAM_END);
  178673. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178674. {
  178675. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178676. png_ptr->zstream.avail_out);
  178677. }
  178678. deflateReset(&png_ptr->zstream);
  178679. png_ptr->zstream.data_type = Z_BINARY;
  178680. }
  178681. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178682. void /* PRIVATE */
  178683. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178684. {
  178685. #ifdef PNG_USE_LOCAL_ARRAYS
  178686. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178687. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178688. #endif
  178689. png_debug(1, "in png_do_write_interlace\n");
  178690. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178691. if (row != NULL && row_info != NULL && pass < 6)
  178692. #else
  178693. if (pass < 6)
  178694. #endif
  178695. {
  178696. switch (row_info->pixel_depth)
  178697. {
  178698. case 1:
  178699. {
  178700. png_bytep sp;
  178701. png_bytep dp;
  178702. int shift;
  178703. int d;
  178704. int value;
  178705. png_uint_32 i;
  178706. png_uint_32 row_width = row_info->width;
  178707. dp = row;
  178708. d = 0;
  178709. shift = 7;
  178710. for (i = png_pass_start[pass]; i < row_width;
  178711. i += png_pass_inc[pass])
  178712. {
  178713. sp = row + (png_size_t)(i >> 3);
  178714. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178715. d |= (value << shift);
  178716. if (shift == 0)
  178717. {
  178718. shift = 7;
  178719. *dp++ = (png_byte)d;
  178720. d = 0;
  178721. }
  178722. else
  178723. shift--;
  178724. }
  178725. if (shift != 7)
  178726. *dp = (png_byte)d;
  178727. break;
  178728. }
  178729. case 2:
  178730. {
  178731. png_bytep sp;
  178732. png_bytep dp;
  178733. int shift;
  178734. int d;
  178735. int value;
  178736. png_uint_32 i;
  178737. png_uint_32 row_width = row_info->width;
  178738. dp = row;
  178739. shift = 6;
  178740. d = 0;
  178741. for (i = png_pass_start[pass]; i < row_width;
  178742. i += png_pass_inc[pass])
  178743. {
  178744. sp = row + (png_size_t)(i >> 2);
  178745. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178746. d |= (value << shift);
  178747. if (shift == 0)
  178748. {
  178749. shift = 6;
  178750. *dp++ = (png_byte)d;
  178751. d = 0;
  178752. }
  178753. else
  178754. shift -= 2;
  178755. }
  178756. if (shift != 6)
  178757. *dp = (png_byte)d;
  178758. break;
  178759. }
  178760. case 4:
  178761. {
  178762. png_bytep sp;
  178763. png_bytep dp;
  178764. int shift;
  178765. int d;
  178766. int value;
  178767. png_uint_32 i;
  178768. png_uint_32 row_width = row_info->width;
  178769. dp = row;
  178770. shift = 4;
  178771. d = 0;
  178772. for (i = png_pass_start[pass]; i < row_width;
  178773. i += png_pass_inc[pass])
  178774. {
  178775. sp = row + (png_size_t)(i >> 1);
  178776. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178777. d |= (value << shift);
  178778. if (shift == 0)
  178779. {
  178780. shift = 4;
  178781. *dp++ = (png_byte)d;
  178782. d = 0;
  178783. }
  178784. else
  178785. shift -= 4;
  178786. }
  178787. if (shift != 4)
  178788. *dp = (png_byte)d;
  178789. break;
  178790. }
  178791. default:
  178792. {
  178793. png_bytep sp;
  178794. png_bytep dp;
  178795. png_uint_32 i;
  178796. png_uint_32 row_width = row_info->width;
  178797. png_size_t pixel_bytes;
  178798. dp = row;
  178799. pixel_bytes = (row_info->pixel_depth >> 3);
  178800. for (i = png_pass_start[pass]; i < row_width;
  178801. i += png_pass_inc[pass])
  178802. {
  178803. sp = row + (png_size_t)i * pixel_bytes;
  178804. if (dp != sp)
  178805. png_memcpy(dp, sp, pixel_bytes);
  178806. dp += pixel_bytes;
  178807. }
  178808. break;
  178809. }
  178810. }
  178811. row_info->width = (row_info->width +
  178812. png_pass_inc[pass] - 1 -
  178813. png_pass_start[pass]) /
  178814. png_pass_inc[pass];
  178815. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178816. row_info->width);
  178817. }
  178818. }
  178819. #endif
  178820. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178821. #define PNG_HISHIFT 10
  178822. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178823. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178824. void /* PRIVATE */
  178825. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178826. {
  178827. png_bytep best_row;
  178828. #ifndef PNG_NO_WRITE_FILTER
  178829. png_bytep prev_row, row_buf;
  178830. png_uint_32 mins, bpp;
  178831. png_byte filter_to_do = png_ptr->do_filter;
  178832. png_uint_32 row_bytes = row_info->rowbytes;
  178833. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178834. int num_p_filters = (int)png_ptr->num_prev_filters;
  178835. #endif
  178836. png_debug(1, "in png_write_find_filter\n");
  178837. bpp = (row_info->pixel_depth + 7) >> 3;
  178838. prev_row = png_ptr->prev_row;
  178839. #endif
  178840. best_row = png_ptr->row_buf;
  178841. #ifndef PNG_NO_WRITE_FILTER
  178842. row_buf = best_row;
  178843. mins = PNG_MAXSUM;
  178844. if ((filter_to_do & PNG_FILTER_NONE) &&
  178845. filter_to_do != PNG_FILTER_NONE)
  178846. {
  178847. png_bytep rp;
  178848. png_uint_32 sum = 0;
  178849. png_uint_32 i;
  178850. int v;
  178851. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178852. {
  178853. v = *rp;
  178854. sum += (v < 128) ? v : 256 - v;
  178855. }
  178856. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178857. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178858. {
  178859. png_uint_32 sumhi, sumlo;
  178860. int j;
  178861. sumlo = sum & PNG_LOMASK;
  178862. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178863. for (j = 0; j < num_p_filters; j++)
  178864. {
  178865. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178866. {
  178867. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178868. PNG_WEIGHT_SHIFT;
  178869. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178870. PNG_WEIGHT_SHIFT;
  178871. }
  178872. }
  178873. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178874. PNG_COST_SHIFT;
  178875. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178876. PNG_COST_SHIFT;
  178877. if (sumhi > PNG_HIMASK)
  178878. sum = PNG_MAXSUM;
  178879. else
  178880. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178881. }
  178882. #endif
  178883. mins = sum;
  178884. }
  178885. if (filter_to_do == PNG_FILTER_SUB)
  178886. {
  178887. png_bytep rp, lp, dp;
  178888. png_uint_32 i;
  178889. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178890. i++, rp++, dp++)
  178891. {
  178892. *dp = *rp;
  178893. }
  178894. for (lp = row_buf + 1; i < row_bytes;
  178895. i++, rp++, lp++, dp++)
  178896. {
  178897. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178898. }
  178899. best_row = png_ptr->sub_row;
  178900. }
  178901. else if (filter_to_do & PNG_FILTER_SUB)
  178902. {
  178903. png_bytep rp, dp, lp;
  178904. png_uint_32 sum = 0, lmins = mins;
  178905. png_uint_32 i;
  178906. int v;
  178907. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178908. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178909. {
  178910. int j;
  178911. png_uint_32 lmhi, lmlo;
  178912. lmlo = lmins & PNG_LOMASK;
  178913. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178914. for (j = 0; j < num_p_filters; j++)
  178915. {
  178916. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178917. {
  178918. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178919. PNG_WEIGHT_SHIFT;
  178920. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178921. PNG_WEIGHT_SHIFT;
  178922. }
  178923. }
  178924. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178925. PNG_COST_SHIFT;
  178926. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178927. PNG_COST_SHIFT;
  178928. if (lmhi > PNG_HIMASK)
  178929. lmins = PNG_MAXSUM;
  178930. else
  178931. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178932. }
  178933. #endif
  178934. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178935. i++, rp++, dp++)
  178936. {
  178937. v = *dp = *rp;
  178938. sum += (v < 128) ? v : 256 - v;
  178939. }
  178940. for (lp = row_buf + 1; i < row_bytes;
  178941. i++, rp++, lp++, dp++)
  178942. {
  178943. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178944. sum += (v < 128) ? v : 256 - v;
  178945. if (sum > lmins) /* We are already worse, don't continue. */
  178946. break;
  178947. }
  178948. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178949. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178950. {
  178951. int j;
  178952. png_uint_32 sumhi, sumlo;
  178953. sumlo = sum & PNG_LOMASK;
  178954. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178955. for (j = 0; j < num_p_filters; j++)
  178956. {
  178957. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178958. {
  178959. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178960. PNG_WEIGHT_SHIFT;
  178961. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178962. PNG_WEIGHT_SHIFT;
  178963. }
  178964. }
  178965. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178966. PNG_COST_SHIFT;
  178967. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178968. PNG_COST_SHIFT;
  178969. if (sumhi > PNG_HIMASK)
  178970. sum = PNG_MAXSUM;
  178971. else
  178972. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178973. }
  178974. #endif
  178975. if (sum < mins)
  178976. {
  178977. mins = sum;
  178978. best_row = png_ptr->sub_row;
  178979. }
  178980. }
  178981. if (filter_to_do == PNG_FILTER_UP)
  178982. {
  178983. png_bytep rp, dp, pp;
  178984. png_uint_32 i;
  178985. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178986. pp = prev_row + 1; i < row_bytes;
  178987. i++, rp++, pp++, dp++)
  178988. {
  178989. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178990. }
  178991. best_row = png_ptr->up_row;
  178992. }
  178993. else if (filter_to_do & PNG_FILTER_UP)
  178994. {
  178995. png_bytep rp, dp, pp;
  178996. png_uint_32 sum = 0, lmins = mins;
  178997. png_uint_32 i;
  178998. int v;
  178999. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179000. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179001. {
  179002. int j;
  179003. png_uint_32 lmhi, lmlo;
  179004. lmlo = lmins & PNG_LOMASK;
  179005. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179006. for (j = 0; j < num_p_filters; j++)
  179007. {
  179008. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179009. {
  179010. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179011. PNG_WEIGHT_SHIFT;
  179012. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179013. PNG_WEIGHT_SHIFT;
  179014. }
  179015. }
  179016. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179017. PNG_COST_SHIFT;
  179018. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179019. PNG_COST_SHIFT;
  179020. if (lmhi > PNG_HIMASK)
  179021. lmins = PNG_MAXSUM;
  179022. else
  179023. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179024. }
  179025. #endif
  179026. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179027. pp = prev_row + 1; i < row_bytes; i++)
  179028. {
  179029. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179030. sum += (v < 128) ? v : 256 - v;
  179031. if (sum > lmins) /* We are already worse, don't continue. */
  179032. break;
  179033. }
  179034. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179035. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179036. {
  179037. int j;
  179038. png_uint_32 sumhi, sumlo;
  179039. sumlo = sum & PNG_LOMASK;
  179040. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179041. for (j = 0; j < num_p_filters; j++)
  179042. {
  179043. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179044. {
  179045. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179046. PNG_WEIGHT_SHIFT;
  179047. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179048. PNG_WEIGHT_SHIFT;
  179049. }
  179050. }
  179051. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179052. PNG_COST_SHIFT;
  179053. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179054. PNG_COST_SHIFT;
  179055. if (sumhi > PNG_HIMASK)
  179056. sum = PNG_MAXSUM;
  179057. else
  179058. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179059. }
  179060. #endif
  179061. if (sum < mins)
  179062. {
  179063. mins = sum;
  179064. best_row = png_ptr->up_row;
  179065. }
  179066. }
  179067. if (filter_to_do == PNG_FILTER_AVG)
  179068. {
  179069. png_bytep rp, dp, pp, lp;
  179070. png_uint_32 i;
  179071. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179072. pp = prev_row + 1; i < bpp; i++)
  179073. {
  179074. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179075. }
  179076. for (lp = row_buf + 1; i < row_bytes; i++)
  179077. {
  179078. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  179079. & 0xff);
  179080. }
  179081. best_row = png_ptr->avg_row;
  179082. }
  179083. else if (filter_to_do & PNG_FILTER_AVG)
  179084. {
  179085. png_bytep rp, dp, pp, lp;
  179086. png_uint_32 sum = 0, lmins = mins;
  179087. png_uint_32 i;
  179088. int v;
  179089. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179090. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179091. {
  179092. int j;
  179093. png_uint_32 lmhi, lmlo;
  179094. lmlo = lmins & PNG_LOMASK;
  179095. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179096. for (j = 0; j < num_p_filters; j++)
  179097. {
  179098. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  179099. {
  179100. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179101. PNG_WEIGHT_SHIFT;
  179102. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179103. PNG_WEIGHT_SHIFT;
  179104. }
  179105. }
  179106. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179107. PNG_COST_SHIFT;
  179108. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179109. PNG_COST_SHIFT;
  179110. if (lmhi > PNG_HIMASK)
  179111. lmins = PNG_MAXSUM;
  179112. else
  179113. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179114. }
  179115. #endif
  179116. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179117. pp = prev_row + 1; i < bpp; i++)
  179118. {
  179119. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179120. sum += (v < 128) ? v : 256 - v;
  179121. }
  179122. for (lp = row_buf + 1; i < row_bytes; i++)
  179123. {
  179124. v = *dp++ =
  179125. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  179126. sum += (v < 128) ? v : 256 - v;
  179127. if (sum > lmins) /* We are already worse, don't continue. */
  179128. break;
  179129. }
  179130. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179131. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179132. {
  179133. int j;
  179134. png_uint_32 sumhi, sumlo;
  179135. sumlo = sum & PNG_LOMASK;
  179136. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179137. for (j = 0; j < num_p_filters; j++)
  179138. {
  179139. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179140. {
  179141. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179142. PNG_WEIGHT_SHIFT;
  179143. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179144. PNG_WEIGHT_SHIFT;
  179145. }
  179146. }
  179147. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179148. PNG_COST_SHIFT;
  179149. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179150. PNG_COST_SHIFT;
  179151. if (sumhi > PNG_HIMASK)
  179152. sum = PNG_MAXSUM;
  179153. else
  179154. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179155. }
  179156. #endif
  179157. if (sum < mins)
  179158. {
  179159. mins = sum;
  179160. best_row = png_ptr->avg_row;
  179161. }
  179162. }
  179163. if (filter_to_do == PNG_FILTER_PAETH)
  179164. {
  179165. png_bytep rp, dp, pp, cp, lp;
  179166. png_uint_32 i;
  179167. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179168. pp = prev_row + 1; i < bpp; i++)
  179169. {
  179170. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179171. }
  179172. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179173. {
  179174. int a, b, c, pa, pb, pc, p;
  179175. b = *pp++;
  179176. c = *cp++;
  179177. a = *lp++;
  179178. p = b - c;
  179179. pc = a - c;
  179180. #ifdef PNG_USE_ABS
  179181. pa = abs(p);
  179182. pb = abs(pc);
  179183. pc = abs(p + pc);
  179184. #else
  179185. pa = p < 0 ? -p : p;
  179186. pb = pc < 0 ? -pc : pc;
  179187. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179188. #endif
  179189. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179190. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179191. }
  179192. best_row = png_ptr->paeth_row;
  179193. }
  179194. else if (filter_to_do & PNG_FILTER_PAETH)
  179195. {
  179196. png_bytep rp, dp, pp, cp, lp;
  179197. png_uint_32 sum = 0, lmins = mins;
  179198. png_uint_32 i;
  179199. int v;
  179200. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179201. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179202. {
  179203. int j;
  179204. png_uint_32 lmhi, lmlo;
  179205. lmlo = lmins & PNG_LOMASK;
  179206. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179207. for (j = 0; j < num_p_filters; j++)
  179208. {
  179209. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179210. {
  179211. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179212. PNG_WEIGHT_SHIFT;
  179213. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179214. PNG_WEIGHT_SHIFT;
  179215. }
  179216. }
  179217. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179218. PNG_COST_SHIFT;
  179219. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179220. PNG_COST_SHIFT;
  179221. if (lmhi > PNG_HIMASK)
  179222. lmins = PNG_MAXSUM;
  179223. else
  179224. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179225. }
  179226. #endif
  179227. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179228. pp = prev_row + 1; i < bpp; i++)
  179229. {
  179230. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179231. sum += (v < 128) ? v : 256 - v;
  179232. }
  179233. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179234. {
  179235. int a, b, c, pa, pb, pc, p;
  179236. b = *pp++;
  179237. c = *cp++;
  179238. a = *lp++;
  179239. #ifndef PNG_SLOW_PAETH
  179240. p = b - c;
  179241. pc = a - c;
  179242. #ifdef PNG_USE_ABS
  179243. pa = abs(p);
  179244. pb = abs(pc);
  179245. pc = abs(p + pc);
  179246. #else
  179247. pa = p < 0 ? -p : p;
  179248. pb = pc < 0 ? -pc : pc;
  179249. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179250. #endif
  179251. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179252. #else /* PNG_SLOW_PAETH */
  179253. p = a + b - c;
  179254. pa = abs(p - a);
  179255. pb = abs(p - b);
  179256. pc = abs(p - c);
  179257. if (pa <= pb && pa <= pc)
  179258. p = a;
  179259. else if (pb <= pc)
  179260. p = b;
  179261. else
  179262. p = c;
  179263. #endif /* PNG_SLOW_PAETH */
  179264. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179265. sum += (v < 128) ? v : 256 - v;
  179266. if (sum > lmins) /* We are already worse, don't continue. */
  179267. break;
  179268. }
  179269. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179270. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179271. {
  179272. int j;
  179273. png_uint_32 sumhi, sumlo;
  179274. sumlo = sum & PNG_LOMASK;
  179275. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179276. for (j = 0; j < num_p_filters; j++)
  179277. {
  179278. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179279. {
  179280. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179281. PNG_WEIGHT_SHIFT;
  179282. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179283. PNG_WEIGHT_SHIFT;
  179284. }
  179285. }
  179286. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179287. PNG_COST_SHIFT;
  179288. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179289. PNG_COST_SHIFT;
  179290. if (sumhi > PNG_HIMASK)
  179291. sum = PNG_MAXSUM;
  179292. else
  179293. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179294. }
  179295. #endif
  179296. if (sum < mins)
  179297. {
  179298. best_row = png_ptr->paeth_row;
  179299. }
  179300. }
  179301. #endif /* PNG_NO_WRITE_FILTER */
  179302. png_write_filtered_row(png_ptr, best_row);
  179303. #ifndef PNG_NO_WRITE_FILTER
  179304. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179305. if (png_ptr->num_prev_filters > 0)
  179306. {
  179307. int j;
  179308. for (j = 1; j < num_p_filters; j++)
  179309. {
  179310. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179311. }
  179312. png_ptr->prev_filters[j] = best_row[0];
  179313. }
  179314. #endif
  179315. #endif /* PNG_NO_WRITE_FILTER */
  179316. }
  179317. void /* PRIVATE */
  179318. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179319. {
  179320. png_debug(1, "in png_write_filtered_row\n");
  179321. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179322. png_ptr->zstream.next_in = filtered_row;
  179323. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179324. do
  179325. {
  179326. int ret; /* return of zlib */
  179327. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179328. if (ret != Z_OK)
  179329. {
  179330. if (png_ptr->zstream.msg != NULL)
  179331. png_error(png_ptr, png_ptr->zstream.msg);
  179332. else
  179333. png_error(png_ptr, "zlib error");
  179334. }
  179335. if (!(png_ptr->zstream.avail_out))
  179336. {
  179337. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179338. png_ptr->zstream.next_out = png_ptr->zbuf;
  179339. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179340. }
  179341. } while (png_ptr->zstream.avail_in);
  179342. if (png_ptr->prev_row != NULL)
  179343. {
  179344. png_bytep tptr;
  179345. tptr = png_ptr->prev_row;
  179346. png_ptr->prev_row = png_ptr->row_buf;
  179347. png_ptr->row_buf = tptr;
  179348. }
  179349. png_write_finish_row(png_ptr);
  179350. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179351. png_ptr->flush_rows++;
  179352. if (png_ptr->flush_dist > 0 &&
  179353. png_ptr->flush_rows >= png_ptr->flush_dist)
  179354. {
  179355. png_write_flush(png_ptr);
  179356. }
  179357. #endif
  179358. }
  179359. #endif /* PNG_WRITE_SUPPORTED */
  179360. /*** End of inlined file: pngwutil.c ***/
  179361. }
  179362. #else
  179363. #define PNG_INTERNAL
  179364. #define PNG_SETJMP_NOT_SUPPORTED
  179365. #include <png.h>
  179366. #include <pngconf.h>
  179367. #endif
  179368. }
  179369. #ifdef _MSC_VER
  179370. #pragma warning (pop)
  179371. #endif
  179372. BEGIN_JUCE_NAMESPACE
  179373. using namespace pnglibNamespace;
  179374. using ::calloc;
  179375. using ::malloc;
  179376. using ::free;
  179377. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179378. {
  179379. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179380. in->read (data, (int) length);
  179381. }
  179382. struct PNGErrorStruct {};
  179383. static void pngErrorCallback (png_structp, png_const_charp)
  179384. {
  179385. throw PNGErrorStruct();
  179386. }
  179387. Image* juce_loadPNGImageFromStream (InputStream& in)
  179388. {
  179389. Image* image = 0;
  179390. png_structp pngReadStruct;
  179391. png_infop pngInfoStruct;
  179392. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179393. if (pngReadStruct != 0)
  179394. {
  179395. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179396. if (pngInfoStruct == 0)
  179397. {
  179398. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179399. return 0;
  179400. }
  179401. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179402. // read the header..
  179403. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179404. png_uint_32 width, height;
  179405. int bitDepth, colorType, interlaceType;
  179406. png_read_info (pngReadStruct, pngInfoStruct);
  179407. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179408. &width, &height,
  179409. &bitDepth, &colorType,
  179410. &interlaceType, 0, 0);
  179411. if (bitDepth == 16)
  179412. png_set_strip_16 (pngReadStruct);
  179413. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179414. png_set_expand (pngReadStruct);
  179415. if (bitDepth < 8)
  179416. png_set_expand (pngReadStruct);
  179417. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179418. png_set_expand (pngReadStruct);
  179419. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179420. png_set_gray_to_rgb (pngReadStruct);
  179421. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179422. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179423. || pngInfoStruct->num_trans > 0;
  179424. // Load the image into a temp buffer in the pnglib format..
  179425. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179426. {
  179427. HeapBlock <png_bytep> rows (height);
  179428. for (int y = (int) height; --y >= 0;)
  179429. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179430. png_read_image (pngReadStruct, rows);
  179431. png_read_end (pngReadStruct, pngInfoStruct);
  179432. }
  179433. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179434. // now convert the data to a juce image format..
  179435. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179436. (int) width, (int) height, hasAlphaChan);
  179437. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179438. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179439. uint8* srcRow = tempBuffer;
  179440. uint8* destRow = destData.data;
  179441. for (int y = 0; y < (int) height; ++y)
  179442. {
  179443. const uint8* src = srcRow;
  179444. srcRow += (width << 2);
  179445. uint8* dest = destRow;
  179446. destRow += destData.lineStride;
  179447. if (hasAlphaChan)
  179448. {
  179449. for (int i = (int) width; --i >= 0;)
  179450. {
  179451. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179452. ((PixelARGB*) dest)->premultiply();
  179453. dest += destData.pixelStride;
  179454. src += 4;
  179455. }
  179456. }
  179457. else
  179458. {
  179459. for (int i = (int) width; --i >= 0;)
  179460. {
  179461. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179462. dest += destData.pixelStride;
  179463. src += 4;
  179464. }
  179465. }
  179466. }
  179467. }
  179468. return image;
  179469. }
  179470. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179471. {
  179472. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179473. const bool ok = out->write (data, (int) length);
  179474. (void) ok;
  179475. jassert (ok);
  179476. }
  179477. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179478. {
  179479. const int width = image.getWidth();
  179480. const int height = image.getHeight();
  179481. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179482. if (pngWriteStruct == 0)
  179483. return false;
  179484. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179485. if (pngInfoStruct == 0)
  179486. {
  179487. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179488. return false;
  179489. }
  179490. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179491. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179492. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179493. : PNG_COLOR_TYPE_RGB,
  179494. PNG_INTERLACE_NONE,
  179495. PNG_COMPRESSION_TYPE_BASE,
  179496. PNG_FILTER_TYPE_BASE);
  179497. HeapBlock <png_byte> rowData (width * 4);
  179498. png_color_8 sig_bit;
  179499. sig_bit.red = 8;
  179500. sig_bit.green = 8;
  179501. sig_bit.blue = 8;
  179502. sig_bit.alpha = 8;
  179503. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179504. png_write_info (pngWriteStruct, pngInfoStruct);
  179505. png_set_shift (pngWriteStruct, &sig_bit);
  179506. png_set_packing (pngWriteStruct);
  179507. const Image::BitmapData srcData (image, 0, 0, width, height);
  179508. for (int y = 0; y < height; ++y)
  179509. {
  179510. uint8* dst = (uint8*) rowData;
  179511. const uint8* src = srcData.getLinePointer (y);
  179512. if (image.hasAlphaChannel())
  179513. {
  179514. for (int i = width; --i >= 0;)
  179515. {
  179516. PixelARGB p (*(const PixelARGB*) src);
  179517. p.unpremultiply();
  179518. *dst++ = p.getRed();
  179519. *dst++ = p.getGreen();
  179520. *dst++ = p.getBlue();
  179521. *dst++ = p.getAlpha();
  179522. src += srcData.pixelStride;
  179523. }
  179524. }
  179525. else
  179526. {
  179527. for (int i = width; --i >= 0;)
  179528. {
  179529. *dst++ = ((const PixelRGB*) src)->getRed();
  179530. *dst++ = ((const PixelRGB*) src)->getGreen();
  179531. *dst++ = ((const PixelRGB*) src)->getBlue();
  179532. src += srcData.pixelStride;
  179533. }
  179534. }
  179535. png_write_rows (pngWriteStruct, &rowData, 1);
  179536. }
  179537. png_write_end (pngWriteStruct, pngInfoStruct);
  179538. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179539. out.flush();
  179540. return true;
  179541. }
  179542. END_JUCE_NAMESPACE
  179543. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179544. #endif
  179545. //==============================================================================
  179546. #if JUCE_BUILD_NATIVE
  179547. #if JUCE_WINDOWS
  179548. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179549. BEGIN_JUCE_NAMESPACE
  179550. #define JUCE_INCLUDED_FILE 1
  179551. // Now include the actual code files..
  179552. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179553. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179554. // compiled on its own).
  179555. #if JUCE_INCLUDED_FILE
  179556. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179557. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179558. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179559. #ifndef DOXYGEN
  179560. // use with DynamicLibraryLoader to simplify importing functions
  179561. //
  179562. // functionName: function to import
  179563. // localFunctionName: name you want to use to actually call it (must be different)
  179564. // returnType: the return type
  179565. // object: the DynamicLibraryLoader to use
  179566. // params: list of params (bracketed)
  179567. //
  179568. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179569. typedef returnType (WINAPI *type##localFunctionName) params; \
  179570. type##localFunctionName localFunctionName \
  179571. = (type##localFunctionName)object.findProcAddress (#functionName);
  179572. // loads and unloads a DLL automatically
  179573. class JUCE_API DynamicLibraryLoader
  179574. {
  179575. public:
  179576. DynamicLibraryLoader (const String& name);
  179577. ~DynamicLibraryLoader();
  179578. void* findProcAddress (const String& functionName);
  179579. private:
  179580. void* libHandle;
  179581. };
  179582. #endif
  179583. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179584. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179585. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179586. {
  179587. libHandle = LoadLibrary (name);
  179588. }
  179589. DynamicLibraryLoader::~DynamicLibraryLoader()
  179590. {
  179591. FreeLibrary ((HMODULE) libHandle);
  179592. }
  179593. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179594. {
  179595. return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179596. }
  179597. #endif
  179598. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179599. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179600. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179601. // compiled on its own).
  179602. #if JUCE_INCLUDED_FILE
  179603. extern void juce_initialiseThreadEvents();
  179604. void Logger::outputDebugString (const String& text) throw()
  179605. {
  179606. OutputDebugString (text + T("\n"));
  179607. }
  179608. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  179609. {
  179610. String text;
  179611. va_list args;
  179612. va_start (args, format);
  179613. text.vprintf(format, args);
  179614. outputDebugString (text);
  179615. }
  179616. static int64 hiResTicksPerSecond;
  179617. static double hiResTicksScaleFactor;
  179618. #if JUCE_USE_INTRINSICS
  179619. // CPU info functions using intrinsics...
  179620. #pragma intrinsic (__cpuid)
  179621. #pragma intrinsic (__rdtsc)
  179622. const String SystemStats::getCpuVendor() throw()
  179623. {
  179624. int info [4];
  179625. __cpuid (info, 0);
  179626. char v [12];
  179627. memcpy (v, info + 1, 4);
  179628. memcpy (v + 4, info + 3, 4);
  179629. memcpy (v + 8, info + 2, 4);
  179630. return String (v, 12);
  179631. }
  179632. #else
  179633. // CPU info functions using old fashioned inline asm...
  179634. static void juce_getCpuVendor (char* const v)
  179635. {
  179636. int vendor[4];
  179637. zeromem (vendor, 16);
  179638. #ifdef JUCE_64BIT
  179639. #else
  179640. #ifndef __MINGW32__
  179641. __try
  179642. #endif
  179643. {
  179644. #if JUCE_GCC
  179645. unsigned int dummy = 0;
  179646. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179647. #else
  179648. __asm
  179649. {
  179650. mov eax, 0
  179651. cpuid
  179652. mov [vendor], ebx
  179653. mov [vendor + 4], edx
  179654. mov [vendor + 8], ecx
  179655. }
  179656. #endif
  179657. }
  179658. #ifndef __MINGW32__
  179659. __except (EXCEPTION_EXECUTE_HANDLER)
  179660. {
  179661. *v = 0;
  179662. }
  179663. #endif
  179664. #endif
  179665. memcpy (v, vendor, 16);
  179666. }
  179667. const String SystemStats::getCpuVendor() throw()
  179668. {
  179669. char v [16];
  179670. juce_getCpuVendor (v);
  179671. return String (v, 16);
  179672. }
  179673. #endif
  179674. struct CPUFlags
  179675. {
  179676. bool hasMMX : 1;
  179677. bool hasSSE : 1;
  179678. bool hasSSE2 : 1;
  179679. bool has3DNow : 1;
  179680. };
  179681. static CPUFlags cpuFlags;
  179682. bool SystemStats::hasMMX() throw()
  179683. {
  179684. return cpuFlags.hasMMX;
  179685. }
  179686. bool SystemStats::hasSSE() throw()
  179687. {
  179688. return cpuFlags.hasSSE;
  179689. }
  179690. bool SystemStats::hasSSE2() throw()
  179691. {
  179692. return cpuFlags.hasSSE2;
  179693. }
  179694. bool SystemStats::has3DNow() throw()
  179695. {
  179696. return cpuFlags.has3DNow;
  179697. }
  179698. void SystemStats::initialiseStats() throw()
  179699. {
  179700. juce_initialiseThreadEvents();
  179701. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179702. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179703. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179704. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179705. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179706. #else
  179707. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179708. #endif
  179709. LARGE_INTEGER f;
  179710. QueryPerformanceFrequency (&f);
  179711. hiResTicksPerSecond = f.QuadPart;
  179712. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179713. String s (SystemStats::getJUCEVersion());
  179714. #ifdef JUCE_DEBUG
  179715. const MMRESULT res = timeBeginPeriod (1);
  179716. jassert (res == TIMERR_NOERROR);
  179717. #else
  179718. timeBeginPeriod (1);
  179719. #endif
  179720. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179721. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179722. #endif
  179723. }
  179724. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179725. {
  179726. OSVERSIONINFO info;
  179727. info.dwOSVersionInfoSize = sizeof (info);
  179728. GetVersionEx (&info);
  179729. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179730. {
  179731. switch (info.dwMajorVersion)
  179732. {
  179733. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179734. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179735. default: jassertfalse; break; // !! not a supported OS!
  179736. }
  179737. }
  179738. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179739. {
  179740. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179741. return Win98;
  179742. }
  179743. return UnknownOS;
  179744. }
  179745. const String SystemStats::getOperatingSystemName() throw()
  179746. {
  179747. const char* name = "Unknown OS";
  179748. switch (getOperatingSystemType())
  179749. {
  179750. case Windows7: name = "Windows 7"; break;
  179751. case WinVista: name = "Windows Vista"; break;
  179752. case WinXP: name = "Windows XP"; break;
  179753. case Win2000: name = "Windows 2000"; break;
  179754. case Win98: name = "Windows 98"; break;
  179755. default: jassertfalse; break; // !! new type of OS?
  179756. }
  179757. return name;
  179758. }
  179759. bool SystemStats::isOperatingSystem64Bit() throw()
  179760. {
  179761. #ifdef _WIN64
  179762. return true;
  179763. #else
  179764. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179765. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179766. BOOL isWow64 = FALSE;
  179767. return (fnIsWow64Process != 0)
  179768. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179769. && (isWow64 != FALSE);
  179770. #endif
  179771. }
  179772. int SystemStats::getMemorySizeInMegabytes() throw()
  179773. {
  179774. MEMORYSTATUSEX mem;
  179775. mem.dwLength = sizeof (mem);
  179776. GlobalMemoryStatusEx (&mem);
  179777. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179778. }
  179779. int SystemStats::getNumCpus() throw()
  179780. {
  179781. SYSTEM_INFO systemInfo;
  179782. GetSystemInfo (&systemInfo);
  179783. return systemInfo.dwNumberOfProcessors;
  179784. }
  179785. uint32 juce_millisecondsSinceStartup() throw()
  179786. {
  179787. return (uint32) GetTickCount();
  179788. }
  179789. int64 Time::getHighResolutionTicks() throw()
  179790. {
  179791. LARGE_INTEGER ticks;
  179792. QueryPerformanceCounter (&ticks);
  179793. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179794. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179795. // fix for a very obscure PCI hardware bug that can make the counter
  179796. // sometimes jump forwards by a few seconds..
  179797. static int64 hiResTicksOffset = 0;
  179798. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179799. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179800. hiResTicksOffset = newOffset;
  179801. return ticks.QuadPart + hiResTicksOffset;
  179802. }
  179803. double Time::getMillisecondCounterHiRes() throw()
  179804. {
  179805. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179806. }
  179807. int64 Time::getHighResolutionTicksPerSecond() throw()
  179808. {
  179809. return hiResTicksPerSecond;
  179810. }
  179811. int64 SystemStats::getClockCycleCounter() throw()
  179812. {
  179813. #if JUCE_USE_INTRINSICS
  179814. // MS intrinsics version...
  179815. return __rdtsc();
  179816. #elif JUCE_GCC
  179817. // GNU inline asm version...
  179818. unsigned int hi = 0, lo = 0;
  179819. __asm__ __volatile__ (
  179820. "xor %%eax, %%eax \n\
  179821. xor %%edx, %%edx \n\
  179822. rdtsc \n\
  179823. movl %%eax, %[lo] \n\
  179824. movl %%edx, %[hi]"
  179825. :
  179826. : [hi] "m" (hi),
  179827. [lo] "m" (lo)
  179828. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179829. return (int64) ((((uint64) hi) << 32) | lo);
  179830. #else
  179831. // MSVC inline asm version...
  179832. unsigned int hi = 0, lo = 0;
  179833. __asm
  179834. {
  179835. xor eax, eax
  179836. xor edx, edx
  179837. rdtsc
  179838. mov lo, eax
  179839. mov hi, edx
  179840. }
  179841. return (int64) ((((uint64) hi) << 32) | lo);
  179842. #endif
  179843. }
  179844. int SystemStats::getCpuSpeedInMegaherz() throw()
  179845. {
  179846. const int64 cycles = SystemStats::getClockCycleCounter();
  179847. const uint32 millis = Time::getMillisecondCounter();
  179848. int lastResult = 0;
  179849. for (;;)
  179850. {
  179851. int n = 1000000;
  179852. while (--n > 0) {}
  179853. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179854. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179855. if (millisElapsed > 80)
  179856. {
  179857. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179858. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179859. return newResult;
  179860. lastResult = newResult;
  179861. }
  179862. }
  179863. }
  179864. bool Time::setSystemTimeToThisTime() const throw()
  179865. {
  179866. SYSTEMTIME st;
  179867. st.wDayOfWeek = 0;
  179868. st.wYear = (WORD) getYear();
  179869. st.wMonth = (WORD) (getMonth() + 1);
  179870. st.wDay = (WORD) getDayOfMonth();
  179871. st.wHour = (WORD) getHours();
  179872. st.wMinute = (WORD) getMinutes();
  179873. st.wSecond = (WORD) getSeconds();
  179874. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179875. // do this twice because of daylight saving conversion problems - the
  179876. // first one sets it up, the second one kicks it in.
  179877. return SetLocalTime (&st) != 0
  179878. && SetLocalTime (&st) != 0;
  179879. }
  179880. int SystemStats::getPageSize() throw()
  179881. {
  179882. SYSTEM_INFO systemInfo;
  179883. GetSystemInfo (&systemInfo);
  179884. return systemInfo.dwPageSize;
  179885. }
  179886. const String SystemStats::getLogonName()
  179887. {
  179888. TCHAR text [256];
  179889. DWORD len = numElementsInArray (text) - 2;
  179890. zerostruct (text);
  179891. GetUserName (text, &len);
  179892. return String (text, len);
  179893. }
  179894. const String SystemStats::getFullUserName()
  179895. {
  179896. return getLogonName();
  179897. }
  179898. #endif
  179899. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179900. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179901. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179902. // compiled on its own).
  179903. #if JUCE_INCLUDED_FILE
  179904. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179905. extern HWND juce_messageWindowHandle;
  179906. #endif
  179907. #if ! JUCE_USE_INTRINSICS
  179908. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179909. // older ones we have to actually call the ops as win32 functions..
  179910. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179911. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179912. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179913. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179914. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179915. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179916. #endif
  179917. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179918. CriticalSection::CriticalSection() throw()
  179919. {
  179920. // (just to check the MS haven't changed this structure and broken things...)
  179921. #if _MSC_VER >= 1400
  179922. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179923. #else
  179924. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179925. #endif
  179926. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179927. }
  179928. CriticalSection::~CriticalSection() throw()
  179929. {
  179930. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179931. }
  179932. void CriticalSection::enter() const throw()
  179933. {
  179934. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179935. }
  179936. bool CriticalSection::tryEnter() const throw()
  179937. {
  179938. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179939. }
  179940. void CriticalSection::exit() const throw()
  179941. {
  179942. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179943. }
  179944. WaitableEvent::WaitableEvent() throw()
  179945. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179946. {
  179947. }
  179948. WaitableEvent::~WaitableEvent() throw()
  179949. {
  179950. CloseHandle (internal);
  179951. }
  179952. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179953. {
  179954. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179955. }
  179956. void WaitableEvent::signal() const throw()
  179957. {
  179958. SetEvent (internal);
  179959. }
  179960. void WaitableEvent::reset() const throw()
  179961. {
  179962. ResetEvent (internal);
  179963. }
  179964. void JUCE_API juce_threadEntryPoint (void*);
  179965. static unsigned int __stdcall threadEntryProc (void* userData)
  179966. {
  179967. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179968. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179969. GetCurrentThreadId(), TRUE);
  179970. #endif
  179971. juce_threadEntryPoint (userData);
  179972. _endthreadex (0);
  179973. return 0;
  179974. }
  179975. void juce_CloseThreadHandle (void* handle)
  179976. {
  179977. CloseHandle ((HANDLE) handle);
  179978. }
  179979. void* juce_createThread (void* userData)
  179980. {
  179981. unsigned int threadId;
  179982. return (void*) _beginthreadex (0, 0,
  179983. &threadEntryProc,
  179984. userData,
  179985. 0, &threadId);
  179986. }
  179987. void juce_killThread (void* handle)
  179988. {
  179989. if (handle != 0)
  179990. {
  179991. #ifdef JUCE_DEBUG
  179992. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179993. #endif
  179994. TerminateThread (handle, 0);
  179995. }
  179996. }
  179997. void juce_setCurrentThreadName (const String& name)
  179998. {
  179999. #if defined (JUCE_DEBUG) && JUCE_MSVC
  180000. struct
  180001. {
  180002. DWORD dwType;
  180003. LPCSTR szName;
  180004. DWORD dwThreadID;
  180005. DWORD dwFlags;
  180006. } info;
  180007. info.dwType = 0x1000;
  180008. info.szName = name.toCString();
  180009. info.dwThreadID = GetCurrentThreadId();
  180010. info.dwFlags = 0;
  180011. #define MS_VC_EXCEPTION 0x406d1388
  180012. __try
  180013. {
  180014. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  180015. }
  180016. __except (EXCEPTION_CONTINUE_EXECUTION)
  180017. {}
  180018. #else
  180019. (void) name;
  180020. #endif
  180021. }
  180022. Thread::ThreadID Thread::getCurrentThreadId()
  180023. {
  180024. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  180025. }
  180026. // priority 1 to 10 where 5=normal, 1=low
  180027. bool juce_setThreadPriority (void* threadHandle, int priority)
  180028. {
  180029. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  180030. if (priority < 1)
  180031. pri = THREAD_PRIORITY_IDLE;
  180032. else if (priority < 2)
  180033. pri = THREAD_PRIORITY_LOWEST;
  180034. else if (priority < 5)
  180035. pri = THREAD_PRIORITY_BELOW_NORMAL;
  180036. else if (priority < 7)
  180037. pri = THREAD_PRIORITY_NORMAL;
  180038. else if (priority < 9)
  180039. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  180040. else if (priority < 10)
  180041. pri = THREAD_PRIORITY_HIGHEST;
  180042. if (threadHandle == 0)
  180043. threadHandle = GetCurrentThread();
  180044. return SetThreadPriority (threadHandle, pri) != FALSE;
  180045. }
  180046. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  180047. {
  180048. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  180049. }
  180050. static HANDLE sleepEvent = 0;
  180051. void juce_initialiseThreadEvents()
  180052. {
  180053. if (sleepEvent == 0)
  180054. #ifdef JUCE_DEBUG
  180055. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  180056. #else
  180057. sleepEvent = CreateEvent (0, 0, 0, 0);
  180058. #endif
  180059. }
  180060. void Thread::yield()
  180061. {
  180062. Sleep (0);
  180063. }
  180064. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  180065. {
  180066. if (millisecs >= 10)
  180067. {
  180068. Sleep (millisecs);
  180069. }
  180070. else
  180071. {
  180072. jassert (sleepEvent != 0);
  180073. // unlike Sleep() this is guaranteed to return to the current thread after
  180074. // the time expires, so we'll use this for short waits, which are more likely
  180075. // to need to be accurate
  180076. WaitForSingleObject (sleepEvent, millisecs);
  180077. }
  180078. }
  180079. static int lastProcessPriority = -1;
  180080. // called by WindowDriver because Windows does wierd things to process priority
  180081. // when you swap apps, and this forces an update when the app is brought to the front.
  180082. void juce_repeatLastProcessPriority()
  180083. {
  180084. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  180085. {
  180086. DWORD p;
  180087. switch (lastProcessPriority)
  180088. {
  180089. case Process::LowPriority:
  180090. p = IDLE_PRIORITY_CLASS;
  180091. break;
  180092. case Process::NormalPriority:
  180093. p = NORMAL_PRIORITY_CLASS;
  180094. break;
  180095. case Process::HighPriority:
  180096. p = HIGH_PRIORITY_CLASS;
  180097. break;
  180098. case Process::RealtimePriority:
  180099. p = REALTIME_PRIORITY_CLASS;
  180100. break;
  180101. default:
  180102. jassertfalse // bad priority value
  180103. return;
  180104. }
  180105. SetPriorityClass (GetCurrentProcess(), p);
  180106. }
  180107. }
  180108. void Process::setPriority (ProcessPriority prior)
  180109. {
  180110. if (lastProcessPriority != (int) prior)
  180111. {
  180112. lastProcessPriority = (int) prior;
  180113. juce_repeatLastProcessPriority();
  180114. }
  180115. }
  180116. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  180117. {
  180118. return IsDebuggerPresent() != FALSE;
  180119. }
  180120. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  180121. {
  180122. return juce_isRunningUnderDebugger();
  180123. }
  180124. void Process::raisePrivilege()
  180125. {
  180126. jassertfalse // xxx not implemented
  180127. }
  180128. void Process::lowerPrivilege()
  180129. {
  180130. jassertfalse // xxx not implemented
  180131. }
  180132. void Process::terminate()
  180133. {
  180134. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180135. _CrtDumpMemoryLeaks();
  180136. #endif
  180137. // bullet in the head in case there's a problem shutting down..
  180138. ExitProcess (0);
  180139. }
  180140. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  180141. {
  180142. void* result = 0;
  180143. JUCE_TRY
  180144. {
  180145. result = (void*) LoadLibrary (name);
  180146. }
  180147. JUCE_CATCH_ALL
  180148. return result;
  180149. }
  180150. void PlatformUtilities::freeDynamicLibrary (void* h)
  180151. {
  180152. JUCE_TRY
  180153. {
  180154. if (h != 0)
  180155. FreeLibrary ((HMODULE) h);
  180156. }
  180157. JUCE_CATCH_ALL
  180158. }
  180159. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  180160. {
  180161. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  180162. }
  180163. InterProcessLock::InterProcessLock (const String& name_)
  180164. : internal (0),
  180165. name (name_),
  180166. reentrancyLevel (0)
  180167. {
  180168. }
  180169. InterProcessLock::~InterProcessLock()
  180170. {
  180171. exit();
  180172. }
  180173. bool InterProcessLock::enter (const int timeOutMillisecs)
  180174. {
  180175. if (reentrancyLevel++ == 0)
  180176. {
  180177. internal = CreateMutex (0, TRUE, "Global\\" + name);
  180178. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  180179. {
  180180. if (timeOutMillisecs == 0
  180181. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  180182. == WAIT_TIMEOUT)
  180183. {
  180184. ReleaseMutex (internal);
  180185. CloseHandle (internal);
  180186. internal = 0;
  180187. }
  180188. }
  180189. }
  180190. return (internal != 0);
  180191. }
  180192. void InterProcessLock::exit()
  180193. {
  180194. if (--reentrancyLevel == 0 && internal != 0)
  180195. {
  180196. ReleaseMutex (internal);
  180197. CloseHandle (internal);
  180198. internal = 0;
  180199. }
  180200. }
  180201. #endif
  180202. /*** End of inlined file: juce_win32_Threads.cpp ***/
  180203. /*** Start of inlined file: juce_win32_Files.cpp ***/
  180204. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180205. // compiled on its own).
  180206. #if JUCE_INCLUDED_FILE
  180207. #ifndef CSIDL_MYMUSIC
  180208. #define CSIDL_MYMUSIC 0x000d
  180209. #endif
  180210. #ifndef CSIDL_MYVIDEO
  180211. #define CSIDL_MYVIDEO 0x000e
  180212. #endif
  180213. const tchar File::separator = T('\\');
  180214. const tchar* File::separatorString = T("\\");
  180215. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  180216. {
  180217. if (fileName.isEmpty())
  180218. return false;
  180219. const DWORD attr = GetFileAttributes (fileName);
  180220. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  180221. : (attr != 0xffffffff);
  180222. }
  180223. bool juce_isDirectory (const String& fileName)
  180224. {
  180225. const DWORD attr = GetFileAttributes (fileName);
  180226. return (attr != 0xffffffff)
  180227. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180228. }
  180229. bool juce_canWriteToFile (const String& fileName)
  180230. {
  180231. const DWORD attr = GetFileAttributes (fileName);
  180232. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  180233. }
  180234. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  180235. {
  180236. DWORD attr = GetFileAttributes (fileName);
  180237. if (attr == 0xffffffff)
  180238. return false;
  180239. if (isReadOnly != juce_canWriteToFile (fileName))
  180240. return true;
  180241. if (isReadOnly)
  180242. attr |= FILE_ATTRIBUTE_READONLY;
  180243. else
  180244. attr &= ~FILE_ATTRIBUTE_READONLY;
  180245. return SetFileAttributes (fileName, attr) != FALSE;
  180246. }
  180247. bool File::isHidden() const
  180248. {
  180249. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  180250. }
  180251. bool juce_deleteFile (const String& fileName)
  180252. {
  180253. if (juce_isDirectory (fileName))
  180254. return RemoveDirectory (fileName) != 0;
  180255. return DeleteFile (fileName) != 0;
  180256. }
  180257. bool File::moveToTrash() const
  180258. {
  180259. if (! exists())
  180260. return true;
  180261. SHFILEOPSTRUCT fos;
  180262. zerostruct (fos);
  180263. // The string we pass in must be double null terminated..
  180264. String doubleNullTermPath (getFullPathName() + " ");
  180265. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  180266. p [getFullPathName().length()] = 0;
  180267. fos.wFunc = FO_DELETE;
  180268. fos.hwnd = (HWND) 0;
  180269. fos.pFrom = p;
  180270. fos.pTo = NULL;
  180271. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  180272. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  180273. return SHFileOperation (&fos) == 0;
  180274. }
  180275. bool juce_moveFile (const String& source, const String& dest)
  180276. {
  180277. return MoveFile (source, dest) != 0;
  180278. }
  180279. bool juce_copyFile (const String& source, const String& dest)
  180280. {
  180281. return CopyFile (source, dest, false) != 0;
  180282. }
  180283. void juce_createDirectory (const String& fileName)
  180284. {
  180285. if (! juce_fileExists (fileName, true))
  180286. {
  180287. CreateDirectory (fileName, 0);
  180288. }
  180289. }
  180290. // return 0 if not possible
  180291. void* juce_fileOpen (const String& fileName, bool forWriting)
  180292. {
  180293. HANDLE h;
  180294. if (forWriting)
  180295. {
  180296. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  180297. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  180298. if (h != INVALID_HANDLE_VALUE)
  180299. SetFilePointer (h, 0, 0, FILE_END);
  180300. else
  180301. h = 0;
  180302. }
  180303. else
  180304. {
  180305. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180306. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180307. if (h == INVALID_HANDLE_VALUE)
  180308. h = 0;
  180309. }
  180310. return (void*) h;
  180311. }
  180312. void juce_fileClose (void* handle)
  180313. {
  180314. CloseHandle (handle);
  180315. }
  180316. int juce_fileRead (void* handle, void* buffer, int size)
  180317. {
  180318. DWORD num = 0;
  180319. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180320. return num;
  180321. }
  180322. int juce_fileWrite (void* handle, const void* buffer, int size)
  180323. {
  180324. DWORD num;
  180325. WriteFile ((HANDLE) handle,
  180326. buffer, size,
  180327. &num, 0);
  180328. return num;
  180329. }
  180330. int64 juce_fileSetPosition (void* handle, int64 pos)
  180331. {
  180332. LARGE_INTEGER li;
  180333. li.QuadPart = pos;
  180334. li.LowPart = SetFilePointer ((HANDLE) handle,
  180335. li.LowPart,
  180336. &li.HighPart,
  180337. FILE_BEGIN); // (returns -1 if it fails)
  180338. return li.QuadPart;
  180339. }
  180340. int64 juce_fileGetPosition (void* handle)
  180341. {
  180342. LARGE_INTEGER li;
  180343. li.QuadPart = 0;
  180344. li.LowPart = SetFilePointer ((HANDLE) handle,
  180345. 0, &li.HighPart,
  180346. FILE_CURRENT); // (returns -1 if it fails)
  180347. return jmax ((int64) 0, li.QuadPart);
  180348. }
  180349. void juce_fileFlush (void* handle)
  180350. {
  180351. FlushFileBuffers ((HANDLE) handle);
  180352. }
  180353. int64 juce_getFileSize (const String& fileName)
  180354. {
  180355. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180356. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180357. {
  180358. return (((int64) attributes.nFileSizeHigh) << 32)
  180359. | attributes.nFileSizeLow;
  180360. }
  180361. return 0;
  180362. }
  180363. static int64 fileTimeToTime (const FILETIME* const ft)
  180364. {
  180365. // tell me if this fails!
  180366. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180367. #if JUCE_GCC
  180368. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180369. #else
  180370. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180371. #endif
  180372. }
  180373. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180374. {
  180375. #if JUCE_GCC
  180376. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180377. #else
  180378. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180379. #endif
  180380. }
  180381. void juce_getFileTimes (const String& fileName,
  180382. int64& modificationTime,
  180383. int64& accessTime,
  180384. int64& creationTime)
  180385. {
  180386. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180387. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180388. {
  180389. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180390. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180391. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180392. }
  180393. else
  180394. {
  180395. creationTime = accessTime = modificationTime = 0;
  180396. }
  180397. }
  180398. bool juce_setFileTimes (const String& fileName,
  180399. int64 modificationTime,
  180400. int64 accessTime,
  180401. int64 creationTime)
  180402. {
  180403. FILETIME m, a, c;
  180404. if (modificationTime > 0)
  180405. timeToFileTime (modificationTime, &m);
  180406. if (accessTime > 0)
  180407. timeToFileTime (accessTime, &a);
  180408. if (creationTime > 0)
  180409. timeToFileTime (creationTime, &c);
  180410. void* const h = juce_fileOpen (fileName, true);
  180411. bool ok = false;
  180412. if (h != 0)
  180413. {
  180414. ok = SetFileTime ((HANDLE) h,
  180415. (creationTime > 0) ? &c : 0,
  180416. (accessTime > 0) ? &a : 0,
  180417. (modificationTime > 0) ? &m : 0) != 0;
  180418. juce_fileClose (h);
  180419. }
  180420. return ok;
  180421. }
  180422. // return '\0' separated list of strings
  180423. const StringArray juce_getFileSystemRoots()
  180424. {
  180425. TCHAR buffer [2048];
  180426. buffer[0] = 0;
  180427. buffer[1] = 0;
  180428. GetLogicalDriveStrings (2048, buffer);
  180429. TCHAR* n = buffer;
  180430. StringArray roots;
  180431. while (*n != 0)
  180432. {
  180433. roots.add (String (n));
  180434. while (*n++ != 0)
  180435. {
  180436. }
  180437. }
  180438. roots.sort (true);
  180439. return roots;
  180440. }
  180441. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180442. int& volumeSerialNumber)
  180443. {
  180444. TCHAR n [4];
  180445. n[0] = *(const TCHAR*) filenameOnVolume;
  180446. n[1] = L':';
  180447. n[2] = L'\\';
  180448. n[3] = 0;
  180449. TCHAR dest [64];
  180450. DWORD serialNum;
  180451. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180452. {
  180453. dest[0] = 0;
  180454. serialNum = 0;
  180455. }
  180456. volumeSerialNumber = serialNum;
  180457. return String (dest);
  180458. }
  180459. static int64 getDiskSpaceInfo (String fn, const bool total)
  180460. {
  180461. if (fn[1] == T(':'))
  180462. fn = fn.substring (0, 2) + T("\\");
  180463. ULARGE_INTEGER spc, tot, totFree;
  180464. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180465. return (int64) (total ? tot.QuadPart
  180466. : spc.QuadPart);
  180467. return 0;
  180468. }
  180469. int64 File::getBytesFreeOnVolume() const
  180470. {
  180471. return getDiskSpaceInfo (getFullPathName(), false);
  180472. }
  180473. int64 File::getVolumeTotalSize() const
  180474. {
  180475. return getDiskSpaceInfo (getFullPathName(), true);
  180476. }
  180477. static unsigned int getWindowsDriveType (const String& fileName)
  180478. {
  180479. TCHAR n[4];
  180480. n[0] = *(const TCHAR*) fileName;
  180481. n[1] = L':';
  180482. n[2] = L'\\';
  180483. n[3] = 0;
  180484. return GetDriveType (n);
  180485. }
  180486. bool File::isOnCDRomDrive() const
  180487. {
  180488. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180489. }
  180490. bool File::isOnHardDisk() const
  180491. {
  180492. if (fullPath.isEmpty())
  180493. return false;
  180494. const unsigned int n = getWindowsDriveType (getFullPathName());
  180495. if (fullPath.toLowerCase()[0] <= 'b'
  180496. && fullPath[1] == T(':'))
  180497. {
  180498. return n != DRIVE_REMOVABLE;
  180499. }
  180500. else
  180501. {
  180502. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180503. }
  180504. }
  180505. bool File::isOnRemovableDrive() const
  180506. {
  180507. if (fullPath.isEmpty())
  180508. return false;
  180509. const unsigned int n = getWindowsDriveType (getFullPathName());
  180510. return n == DRIVE_CDROM
  180511. || n == DRIVE_REMOTE
  180512. || n == DRIVE_REMOVABLE
  180513. || n == DRIVE_RAMDISK;
  180514. }
  180515. #define MAX_PATH_CHARS (MAX_PATH + 256)
  180516. static const File juce_getSpecialFolderPath (int type)
  180517. {
  180518. WCHAR path [MAX_PATH_CHARS];
  180519. if (SHGetSpecialFolderPath (0, path, type, 0))
  180520. return File (String (path));
  180521. return File::nonexistent;
  180522. }
  180523. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180524. {
  180525. int csidlType = 0;
  180526. switch (type)
  180527. {
  180528. case userHomeDirectory:
  180529. csidlType = CSIDL_PROFILE;
  180530. break;
  180531. case userDocumentsDirectory:
  180532. csidlType = CSIDL_PERSONAL;
  180533. break;
  180534. case userDesktopDirectory:
  180535. csidlType = CSIDL_DESKTOP;
  180536. break;
  180537. case userApplicationDataDirectory:
  180538. csidlType = CSIDL_APPDATA;
  180539. break;
  180540. case commonApplicationDataDirectory:
  180541. csidlType = CSIDL_COMMON_APPDATA;
  180542. break;
  180543. case globalApplicationsDirectory:
  180544. csidlType = CSIDL_PROGRAM_FILES;
  180545. break;
  180546. case userMusicDirectory:
  180547. csidlType = CSIDL_MYMUSIC;
  180548. break;
  180549. case userMoviesDirectory:
  180550. csidlType = CSIDL_MYVIDEO;
  180551. break;
  180552. case tempDirectory:
  180553. {
  180554. WCHAR dest [2048];
  180555. dest[0] = 0;
  180556. GetTempPath (2048, dest);
  180557. return File (String (dest));
  180558. }
  180559. case invokedExecutableFile:
  180560. case currentExecutableFile:
  180561. case currentApplicationFile:
  180562. {
  180563. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180564. WCHAR dest [MAX_PATH_CHARS];
  180565. dest[0] = 0;
  180566. GetModuleFileName (moduleHandle, dest, MAX_PATH_CHARS);
  180567. return File (String (dest));
  180568. }
  180569. break;
  180570. default:
  180571. jassertfalse // unknown type?
  180572. return File::nonexistent;
  180573. }
  180574. return juce_getSpecialFolderPath (csidlType);
  180575. }
  180576. const File File::getCurrentWorkingDirectory()
  180577. {
  180578. WCHAR dest [MAX_PATH_CHARS];
  180579. dest[0] = 0;
  180580. GetCurrentDirectory (MAX_PATH_CHARS, dest);
  180581. return File (String (dest));
  180582. }
  180583. bool File::setAsCurrentWorkingDirectory() const
  180584. {
  180585. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180586. }
  180587. const String File::getVersion() const
  180588. {
  180589. String result;
  180590. DWORD handle = 0;
  180591. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180592. HeapBlock <char> buffer;
  180593. buffer.calloc (bufferSize);
  180594. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180595. {
  180596. VS_FIXEDFILEINFO* vffi;
  180597. UINT len = 0;
  180598. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180599. {
  180600. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180601. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180602. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180603. << (int) LOWORD (vffi->dwFileVersionLS);
  180604. }
  180605. }
  180606. return result;
  180607. }
  180608. const File File::getLinkedTarget() const
  180609. {
  180610. File result (*this);
  180611. String p (getFullPathName());
  180612. if (! exists())
  180613. p += T(".lnk");
  180614. else if (getFileExtension() != T(".lnk"))
  180615. return result;
  180616. ComSmartPtr <IShellLink> shellLink;
  180617. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180618. {
  180619. ComSmartPtr <IPersistFile> persistFile;
  180620. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180621. {
  180622. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180623. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180624. {
  180625. WIN32_FIND_DATA winFindData;
  180626. WCHAR resolvedPath [MAX_PATH];
  180627. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180628. result = File (resolvedPath);
  180629. }
  180630. }
  180631. }
  180632. return result;
  180633. }
  180634. template <class FindDataType>
  180635. static void getFindFileInfo (FindDataType& findData,
  180636. String& filename, bool* const isDir, bool* const isHidden,
  180637. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180638. bool* const isReadOnly)
  180639. {
  180640. filename = findData.cFileName;
  180641. if (isDir != 0)
  180642. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180643. if (isHidden != 0)
  180644. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180645. if (fileSize != 0)
  180646. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180647. if (modTime != 0)
  180648. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180649. if (creationTime != 0)
  180650. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180651. if (isReadOnly != 0)
  180652. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180653. }
  180654. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180655. bool* isDir, bool* isHidden, int64* fileSize,
  180656. Time* modTime, Time* creationTime, bool* isReadOnly)
  180657. {
  180658. String wc (directory);
  180659. if (! wc.endsWithChar (File::separator))
  180660. wc += File::separator;
  180661. wc += wildCard;
  180662. WIN32_FIND_DATA findData;
  180663. HANDLE h = FindFirstFile (wc, &findData);
  180664. if (h != INVALID_HANDLE_VALUE)
  180665. {
  180666. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180667. modTime, creationTime, isReadOnly);
  180668. return h;
  180669. }
  180670. firstResult = String::empty;
  180671. return 0;
  180672. }
  180673. bool juce_findFileNext (void* handle, String& resultFile,
  180674. bool* isDir, bool* isHidden, int64* fileSize,
  180675. Time* modTime, Time* creationTime, bool* isReadOnly)
  180676. {
  180677. WIN32_FIND_DATA findData;
  180678. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180679. {
  180680. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180681. modTime, creationTime, isReadOnly);
  180682. return true;
  180683. }
  180684. resultFile = String::empty;
  180685. return false;
  180686. }
  180687. void juce_findFileClose (void* handle)
  180688. {
  180689. FindClose (handle);
  180690. }
  180691. bool juce_launchFile (const String& fileName,
  180692. const String& parameters)
  180693. {
  180694. HINSTANCE hInstance = 0;
  180695. JUCE_TRY
  180696. {
  180697. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180698. }
  180699. JUCE_CATCH_ALL
  180700. return hInstance > (HINSTANCE) 32;
  180701. }
  180702. void File::revealToUser() const
  180703. {
  180704. if (isDirectory())
  180705. startAsProcess();
  180706. else if (getParentDirectory().exists())
  180707. getParentDirectory().startAsProcess();
  180708. }
  180709. struct NamedPipeInternal
  180710. {
  180711. HANDLE pipeH;
  180712. HANDLE cancelEvent;
  180713. bool connected, createdPipe;
  180714. NamedPipeInternal()
  180715. : pipeH (0),
  180716. cancelEvent (0),
  180717. connected (false),
  180718. createdPipe (false)
  180719. {
  180720. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180721. }
  180722. ~NamedPipeInternal()
  180723. {
  180724. disconnect();
  180725. if (pipeH != 0)
  180726. CloseHandle (pipeH);
  180727. CloseHandle (cancelEvent);
  180728. }
  180729. bool connect (const int timeOutMs)
  180730. {
  180731. if (! createdPipe)
  180732. return true;
  180733. if (! connected)
  180734. {
  180735. OVERLAPPED over;
  180736. zerostruct (over);
  180737. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180738. if (ConnectNamedPipe (pipeH, &over))
  180739. {
  180740. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180741. }
  180742. else
  180743. {
  180744. const int err = GetLastError();
  180745. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180746. {
  180747. HANDLE handles[] = { over.hEvent, cancelEvent };
  180748. if (WaitForMultipleObjects (2, handles, FALSE,
  180749. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180750. connected = true;
  180751. }
  180752. else if (err == ERROR_PIPE_CONNECTED)
  180753. {
  180754. connected = true;
  180755. }
  180756. }
  180757. CloseHandle (over.hEvent);
  180758. }
  180759. return connected;
  180760. }
  180761. void disconnect()
  180762. {
  180763. if (connected)
  180764. {
  180765. DisconnectNamedPipe (pipeH);
  180766. connected = false;
  180767. }
  180768. }
  180769. };
  180770. void NamedPipe::close()
  180771. {
  180772. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180773. delete intern;
  180774. internal = 0;
  180775. }
  180776. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180777. {
  180778. close();
  180779. NamedPipeInternal* const intern = new NamedPipeInternal();
  180780. String file ("\\\\.\\pipe\\");
  180781. file += pipeName;
  180782. intern->createdPipe = createPipe;
  180783. if (createPipe)
  180784. {
  180785. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180786. PIPE_UNLIMITED_INSTANCES,
  180787. 4096, 4096, 0, NULL);
  180788. }
  180789. else
  180790. {
  180791. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  180792. FILE_FLAG_OVERLAPPED, 0);
  180793. }
  180794. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180795. {
  180796. internal = intern;
  180797. return true;
  180798. }
  180799. delete intern;
  180800. return false;
  180801. }
  180802. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180803. {
  180804. int bytesRead = -1;
  180805. bool waitAgain = true;
  180806. while (waitAgain && internal != 0)
  180807. {
  180808. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180809. waitAgain = false;
  180810. if (! intern->connect (timeOutMilliseconds))
  180811. break;
  180812. if (maxBytesToRead <= 0)
  180813. return 0;
  180814. OVERLAPPED over;
  180815. zerostruct (over);
  180816. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180817. unsigned long numRead;
  180818. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180819. {
  180820. bytesRead = (int) numRead;
  180821. }
  180822. else if (GetLastError() == ERROR_IO_PENDING)
  180823. {
  180824. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180825. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180826. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180827. : INFINITE);
  180828. if (waitResult != WAIT_OBJECT_0)
  180829. {
  180830. // if the operation timed out, let's cancel it...
  180831. CancelIo (intern->pipeH);
  180832. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180833. }
  180834. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180835. {
  180836. bytesRead = (int) numRead;
  180837. }
  180838. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180839. {
  180840. intern->disconnect();
  180841. waitAgain = true;
  180842. }
  180843. }
  180844. else
  180845. {
  180846. waitAgain = internal != 0;
  180847. Sleep (5);
  180848. }
  180849. CloseHandle (over.hEvent);
  180850. }
  180851. return bytesRead;
  180852. }
  180853. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180854. {
  180855. int bytesWritten = -1;
  180856. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180857. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180858. {
  180859. if (numBytesToWrite <= 0)
  180860. return 0;
  180861. OVERLAPPED over;
  180862. zerostruct (over);
  180863. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180864. unsigned long numWritten;
  180865. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180866. {
  180867. bytesWritten = (int) numWritten;
  180868. }
  180869. else if (GetLastError() == ERROR_IO_PENDING)
  180870. {
  180871. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180872. DWORD waitResult;
  180873. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180874. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180875. : INFINITE);
  180876. if (waitResult != WAIT_OBJECT_0)
  180877. {
  180878. CancelIo (intern->pipeH);
  180879. WaitForSingleObject (over.hEvent, INFINITE);
  180880. }
  180881. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180882. {
  180883. bytesWritten = (int) numWritten;
  180884. }
  180885. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180886. {
  180887. intern->disconnect();
  180888. }
  180889. }
  180890. CloseHandle (over.hEvent);
  180891. }
  180892. return bytesWritten;
  180893. }
  180894. void NamedPipe::cancelPendingReads()
  180895. {
  180896. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180897. if (intern != 0)
  180898. SetEvent (intern->cancelEvent);
  180899. }
  180900. #endif
  180901. /*** End of inlined file: juce_win32_Files.cpp ***/
  180902. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180903. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180904. // compiled on its own).
  180905. #if JUCE_INCLUDED_FILE
  180906. #ifndef INTERNET_FLAG_NEED_FILE
  180907. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180908. #endif
  180909. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180910. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180911. #endif
  180912. bool juce_isOnLine()
  180913. {
  180914. DWORD connectionType;
  180915. return InternetGetConnectedState (&connectionType, 0) != 0
  180916. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180917. }
  180918. struct ConnectionAndRequestStruct
  180919. {
  180920. HINTERNET connection, request;
  180921. };
  180922. static HINTERNET sessionHandle = 0;
  180923. #ifndef WORKAROUND_TIMEOUT_BUG
  180924. //#define WORKAROUND_TIMEOUT_BUG 1
  180925. #endif
  180926. #if WORKAROUND_TIMEOUT_BUG
  180927. // Required because of a Microsoft bug in setting a timeout
  180928. class InternetConnectThread : public Thread
  180929. {
  180930. public:
  180931. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180932. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180933. {
  180934. startThread();
  180935. }
  180936. ~InternetConnectThread()
  180937. {
  180938. stopThread (60000);
  180939. }
  180940. void run()
  180941. {
  180942. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180943. uc.nPort, _T(""), _T(""),
  180944. isFtp ? INTERNET_SERVICE_FTP
  180945. : INTERNET_SERVICE_HTTP,
  180946. 0, 0);
  180947. notify();
  180948. }
  180949. juce_UseDebuggingNewOperator
  180950. private:
  180951. URL_COMPONENTS& uc;
  180952. HINTERNET& connection;
  180953. const bool isFtp;
  180954. InternetConnectThread (const InternetConnectThread&);
  180955. InternetConnectThread& operator= (const InternetConnectThread&);
  180956. };
  180957. #endif
  180958. void* juce_openInternetFile (const String& url,
  180959. const String& headers,
  180960. const MemoryBlock& postData,
  180961. const bool isPost,
  180962. URL::OpenStreamProgressCallback* callback,
  180963. void* callbackContext,
  180964. int timeOutMs)
  180965. {
  180966. if (sessionHandle == 0)
  180967. sessionHandle = InternetOpen (_T("juce"),
  180968. INTERNET_OPEN_TYPE_PRECONFIG,
  180969. 0, 0, 0);
  180970. if (sessionHandle != 0)
  180971. {
  180972. // break up the url..
  180973. TCHAR file[1024], server[1024];
  180974. URL_COMPONENTS uc;
  180975. zerostruct (uc);
  180976. uc.dwStructSize = sizeof (uc);
  180977. uc.dwUrlPathLength = sizeof (file);
  180978. uc.dwHostNameLength = sizeof (server);
  180979. uc.lpszUrlPath = file;
  180980. uc.lpszHostName = server;
  180981. if (InternetCrackUrl (url, 0, 0, &uc))
  180982. {
  180983. int disable = 1;
  180984. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180985. if (timeOutMs == 0)
  180986. timeOutMs = 30000;
  180987. else if (timeOutMs < 0)
  180988. timeOutMs = -1;
  180989. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180990. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  180991. #if WORKAROUND_TIMEOUT_BUG
  180992. HINTERNET connection = 0;
  180993. {
  180994. InternetConnectThread connectThread (uc, connection, isFtp);
  180995. connectThread.wait (timeOutMs);
  180996. if (connection == 0)
  180997. {
  180998. InternetCloseHandle (sessionHandle);
  180999. sessionHandle = 0;
  181000. }
  181001. }
  181002. #else
  181003. HINTERNET connection = InternetConnect (sessionHandle,
  181004. uc.lpszHostName,
  181005. uc.nPort,
  181006. _T(""), _T(""),
  181007. isFtp ? INTERNET_SERVICE_FTP
  181008. : INTERNET_SERVICE_HTTP,
  181009. 0, 0);
  181010. #endif
  181011. if (connection != 0)
  181012. {
  181013. if (isFtp)
  181014. {
  181015. HINTERNET request = FtpOpenFile (connection,
  181016. uc.lpszUrlPath,
  181017. GENERIC_READ,
  181018. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  181019. 0);
  181020. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  181021. result->connection = connection;
  181022. result->request = request;
  181023. return result;
  181024. }
  181025. else
  181026. {
  181027. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  181028. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  181029. if (url.startsWithIgnoreCase (T("https:")))
  181030. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  181031. // IE7 seems to automatically work out when it's https)
  181032. HINTERNET request = HttpOpenRequest (connection,
  181033. isPost ? _T("POST")
  181034. : _T("GET"),
  181035. uc.lpszUrlPath,
  181036. 0, 0, mimeTypes, flags, 0);
  181037. if (request != 0)
  181038. {
  181039. INTERNET_BUFFERS buffers;
  181040. zerostruct (buffers);
  181041. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  181042. buffers.lpcszHeader = (LPCTSTR) headers;
  181043. buffers.dwHeadersLength = headers.length();
  181044. buffers.dwBufferTotal = (DWORD) postData.getSize();
  181045. ConnectionAndRequestStruct* result = 0;
  181046. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  181047. {
  181048. int bytesSent = 0;
  181049. for (;;)
  181050. {
  181051. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  181052. DWORD bytesDone = 0;
  181053. if (bytesToDo > 0
  181054. && ! InternetWriteFile (request,
  181055. ((const char*) postData.getData()) + bytesSent,
  181056. bytesToDo, &bytesDone))
  181057. {
  181058. break;
  181059. }
  181060. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  181061. {
  181062. result = new ConnectionAndRequestStruct();
  181063. result->connection = connection;
  181064. result->request = request;
  181065. HttpEndRequest (request, 0, 0, 0);
  181066. return result;
  181067. }
  181068. bytesSent += bytesDone;
  181069. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  181070. break;
  181071. }
  181072. }
  181073. InternetCloseHandle (request);
  181074. }
  181075. InternetCloseHandle (connection);
  181076. }
  181077. }
  181078. }
  181079. }
  181080. return 0;
  181081. }
  181082. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  181083. {
  181084. DWORD bytesRead = 0;
  181085. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181086. if (crs != 0)
  181087. InternetReadFile (crs->request,
  181088. buffer, bytesToRead,
  181089. &bytesRead);
  181090. return bytesRead;
  181091. }
  181092. int juce_seekInInternetFile (void* handle, int newPosition)
  181093. {
  181094. if (handle != 0)
  181095. {
  181096. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181097. return InternetSetFilePointer (crs->request,
  181098. newPosition, 0,
  181099. FILE_BEGIN, 0);
  181100. }
  181101. else
  181102. {
  181103. return -1;
  181104. }
  181105. }
  181106. int64 juce_getInternetFileContentLength (void* handle)
  181107. {
  181108. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181109. if (crs != 0)
  181110. {
  181111. DWORD index = 0;
  181112. DWORD result = 0;
  181113. DWORD size = sizeof (result);
  181114. if (HttpQueryInfo (crs->request,
  181115. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  181116. &result,
  181117. &size,
  181118. &index))
  181119. {
  181120. return (int64) result;
  181121. }
  181122. }
  181123. return -1;
  181124. }
  181125. void juce_closeInternetFile (void* handle)
  181126. {
  181127. if (handle != 0)
  181128. {
  181129. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  181130. InternetCloseHandle (crs->request);
  181131. InternetCloseHandle (crs->connection);
  181132. delete crs;
  181133. }
  181134. }
  181135. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  181136. {
  181137. int numFound = 0;
  181138. DynamicLibraryLoader dll ("iphlpapi.dll");
  181139. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  181140. if (getAdaptersInfo != 0)
  181141. {
  181142. ULONG len = sizeof (IP_ADAPTER_INFO);
  181143. MemoryBlock mb;
  181144. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181145. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  181146. {
  181147. mb.setSize (len);
  181148. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181149. }
  181150. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  181151. {
  181152. PIP_ADAPTER_INFO adapter = adapterInfo;
  181153. while (adapter != 0)
  181154. {
  181155. int64 mac = 0;
  181156. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  181157. mac = (mac << 8) | adapter->Address[i];
  181158. if (littleEndian)
  181159. mac = (int64) ByteOrder::swap ((uint64) mac);
  181160. if (numFound < maxNum && mac != 0)
  181161. addresses [numFound++] = mac;
  181162. adapter = adapter->Next;
  181163. }
  181164. }
  181165. }
  181166. return numFound;
  181167. }
  181168. struct ASTAT
  181169. {
  181170. ADAPTER_STATUS adapt;
  181171. NAME_BUFFER NameBuff [30];
  181172. };
  181173. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  181174. {
  181175. int numFound = 0;
  181176. DynamicLibraryLoader dll ("netapi32.dll");
  181177. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  181178. if (NetbiosCall != 0)
  181179. {
  181180. NCB ncb;
  181181. zerostruct (ncb);
  181182. ASTAT astat;
  181183. zerostruct (astat);
  181184. LANA_ENUM enums;
  181185. zerostruct (enums);
  181186. ncb.ncb_command = NCBENUM;
  181187. ncb.ncb_buffer = (unsigned char*) &enums;
  181188. ncb.ncb_length = sizeof (LANA_ENUM);
  181189. NetbiosCall (&ncb);
  181190. for (int i = 0; i < enums.length; ++i)
  181191. {
  181192. zerostruct (ncb);
  181193. ncb.ncb_command = NCBRESET;
  181194. ncb.ncb_lana_num = enums.lana[i];
  181195. if (NetbiosCall (&ncb) == 0)
  181196. {
  181197. zerostruct (ncb);
  181198. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  181199. ncb.ncb_command = NCBASTAT;
  181200. ncb.ncb_lana_num = enums.lana[i];
  181201. ncb.ncb_buffer = (unsigned char*) &astat;
  181202. ncb.ncb_length = sizeof (ASTAT);
  181203. if (NetbiosCall (&ncb) == 0)
  181204. {
  181205. if (astat.adapt.adapter_type == 0xfe)
  181206. {
  181207. uint64 mac = 0;
  181208. for (int i = 6; --i >= 0;)
  181209. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  181210. if (numFound < maxNum && mac != 0)
  181211. addresses [numFound++] = mac;
  181212. }
  181213. }
  181214. }
  181215. }
  181216. }
  181217. return numFound;
  181218. }
  181219. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  181220. {
  181221. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  181222. if (numFound == 0)
  181223. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  181224. return numFound;
  181225. }
  181226. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  181227. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  181228. const String& emailSubject,
  181229. const String& bodyText,
  181230. const StringArray& filesToAttach)
  181231. {
  181232. HMODULE h = LoadLibraryA ("MAPI32.dll");
  181233. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  181234. bool ok = false;
  181235. if (mapiSendMail != 0)
  181236. {
  181237. MapiMessage message;
  181238. zerostruct (message);
  181239. message.lpszSubject = (LPSTR) emailSubject.toCString();
  181240. message.lpszNoteText = (LPSTR) bodyText.toCString();
  181241. MapiRecipDesc recip;
  181242. zerostruct (recip);
  181243. recip.ulRecipClass = MAPI_TO;
  181244. String targetEmailAddress_ (targetEmailAddress);
  181245. if (targetEmailAddress_.isEmpty())
  181246. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  181247. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  181248. message.nRecipCount = 1;
  181249. message.lpRecips = &recip;
  181250. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  181251. mb.fillWith (0);
  181252. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  181253. message.nFileCount = filesToAttach.size();
  181254. message.lpFiles = files;
  181255. for (int i = 0; i < filesToAttach.size(); ++i)
  181256. {
  181257. files[i].nPosition = (ULONG) -1;
  181258. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  181259. }
  181260. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  181261. }
  181262. FreeLibrary (h);
  181263. return ok;
  181264. }
  181265. #endif
  181266. /*** End of inlined file: juce_win32_Network.cpp ***/
  181267. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  181268. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181269. // compiled on its own).
  181270. #if JUCE_INCLUDED_FILE
  181271. static HKEY findKeyForPath (String name,
  181272. const bool createForWriting,
  181273. String& valueName)
  181274. {
  181275. HKEY rootKey = 0;
  181276. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  181277. rootKey = HKEY_CURRENT_USER;
  181278. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  181279. rootKey = HKEY_LOCAL_MACHINE;
  181280. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  181281. rootKey = HKEY_CLASSES_ROOT;
  181282. if (rootKey != 0)
  181283. {
  181284. name = name.substring (name.indexOfChar (T('\\')) + 1);
  181285. const int lastSlash = name.lastIndexOfChar (T('\\'));
  181286. valueName = name.substring (lastSlash + 1);
  181287. name = name.substring (0, lastSlash);
  181288. HKEY key;
  181289. DWORD result;
  181290. if (createForWriting)
  181291. {
  181292. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  181293. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  181294. return key;
  181295. }
  181296. else
  181297. {
  181298. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  181299. return key;
  181300. }
  181301. }
  181302. return 0;
  181303. }
  181304. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181305. const String& defaultValue)
  181306. {
  181307. String valueName, result (defaultValue);
  181308. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181309. if (k != 0)
  181310. {
  181311. WCHAR buffer [2048];
  181312. unsigned long bufferSize = sizeof (buffer);
  181313. DWORD type = REG_SZ;
  181314. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181315. {
  181316. if (type == REG_SZ)
  181317. result = buffer;
  181318. else if (type == REG_DWORD)
  181319. result = String ((int) *(DWORD*) buffer);
  181320. }
  181321. RegCloseKey (k);
  181322. }
  181323. return result;
  181324. }
  181325. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181326. const String& value)
  181327. {
  181328. String valueName;
  181329. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181330. if (k != 0)
  181331. {
  181332. RegSetValueEx (k, valueName, 0, REG_SZ,
  181333. (const BYTE*) (const WCHAR*) value,
  181334. sizeof (WCHAR) * (value.length() + 1));
  181335. RegCloseKey (k);
  181336. }
  181337. }
  181338. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181339. {
  181340. bool exists = false;
  181341. String valueName;
  181342. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181343. if (k != 0)
  181344. {
  181345. unsigned char buffer [2048];
  181346. unsigned long bufferSize = sizeof (buffer);
  181347. DWORD type = 0;
  181348. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181349. exists = true;
  181350. RegCloseKey (k);
  181351. }
  181352. return exists;
  181353. }
  181354. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181355. {
  181356. String valueName;
  181357. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181358. if (k != 0)
  181359. {
  181360. RegDeleteValue (k, valueName);
  181361. RegCloseKey (k);
  181362. }
  181363. }
  181364. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181365. {
  181366. String valueName;
  181367. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181368. if (k != 0)
  181369. {
  181370. RegDeleteKey (k, valueName);
  181371. RegCloseKey (k);
  181372. }
  181373. }
  181374. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181375. const String& symbolicDescription,
  181376. const String& fullDescription,
  181377. const File& targetExecutable,
  181378. int iconResourceNumber)
  181379. {
  181380. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181381. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181382. if (iconResourceNumber != 0)
  181383. setRegistryValue (key + "\\DefaultIcon\\",
  181384. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181385. setRegistryValue (key + "\\", fullDescription);
  181386. setRegistryValue (key + "\\shell\\open\\command\\",
  181387. targetExecutable.getFullPathName() + " %1");
  181388. }
  181389. bool juce_IsRunningInWine()
  181390. {
  181391. HKEY key;
  181392. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181393. {
  181394. RegCloseKey (key);
  181395. return true;
  181396. }
  181397. return false;
  181398. }
  181399. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181400. {
  181401. String s (::GetCommandLineW());
  181402. StringArray tokens;
  181403. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181404. return tokens.joinIntoString (T(" "), 1);
  181405. }
  181406. static void* currentModuleHandle = 0;
  181407. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181408. {
  181409. if (currentModuleHandle == 0)
  181410. currentModuleHandle = GetModuleHandle (0);
  181411. return currentModuleHandle;
  181412. }
  181413. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181414. {
  181415. currentModuleHandle = newHandle;
  181416. }
  181417. void PlatformUtilities::fpuReset()
  181418. {
  181419. #if JUCE_MSVC
  181420. _clearfp();
  181421. #endif
  181422. }
  181423. void PlatformUtilities::beep()
  181424. {
  181425. MessageBeep (MB_OK);
  181426. }
  181427. #endif
  181428. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181429. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181430. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181431. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181432. // compiled on its own).
  181433. #if JUCE_INCLUDED_FILE
  181434. static const unsigned int specialId = WM_APP + 0x4400;
  181435. static const unsigned int broadcastId = WM_APP + 0x4403;
  181436. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181437. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181438. HWND juce_messageWindowHandle = 0;
  181439. extern long improbableWindowNumber; // defined in windowing.cpp
  181440. #ifndef WM_APPCOMMAND
  181441. #define WM_APPCOMMAND 0x0319
  181442. #endif
  181443. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181444. const UINT message,
  181445. const WPARAM wParam,
  181446. const LPARAM lParam) throw()
  181447. {
  181448. JUCE_TRY
  181449. {
  181450. if (h == juce_messageWindowHandle)
  181451. {
  181452. if (message == specialCallbackId)
  181453. {
  181454. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181455. return (LRESULT) (*func) ((void*) lParam);
  181456. }
  181457. else if (message == specialId)
  181458. {
  181459. // these are trapped early in the dispatch call, but must also be checked
  181460. // here in case there are windows modal dialog boxes doing their own
  181461. // dispatch loop and not calling our version
  181462. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181463. return 0;
  181464. }
  181465. else if (message == broadcastId)
  181466. {
  181467. const ScopedPointer <String> messageString ((String*) lParam);
  181468. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181469. return 0;
  181470. }
  181471. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181472. {
  181473. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181474. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181475. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181476. return 0;
  181477. }
  181478. }
  181479. }
  181480. JUCE_CATCH_EXCEPTION
  181481. return DefWindowProc (h, message, wParam, lParam);
  181482. }
  181483. static bool isEventBlockedByModalComps (MSG& m)
  181484. {
  181485. if (Component::getNumCurrentlyModalComponents() == 0
  181486. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181487. return false;
  181488. switch (m.message)
  181489. {
  181490. case WM_MOUSEMOVE:
  181491. case WM_NCMOUSEMOVE:
  181492. case 0x020A: /* WM_MOUSEWHEEL */
  181493. case 0x020E: /* WM_MOUSEHWHEEL */
  181494. case WM_KEYUP:
  181495. case WM_SYSKEYUP:
  181496. case WM_CHAR:
  181497. case WM_APPCOMMAND:
  181498. case WM_LBUTTONUP:
  181499. case WM_MBUTTONUP:
  181500. case WM_RBUTTONUP:
  181501. case WM_MOUSEACTIVATE:
  181502. case WM_NCMOUSEHOVER:
  181503. case WM_MOUSEHOVER:
  181504. return true;
  181505. case WM_NCLBUTTONDOWN:
  181506. case WM_NCLBUTTONDBLCLK:
  181507. case WM_NCRBUTTONDOWN:
  181508. case WM_NCRBUTTONDBLCLK:
  181509. case WM_NCMBUTTONDOWN:
  181510. case WM_NCMBUTTONDBLCLK:
  181511. case WM_LBUTTONDOWN:
  181512. case WM_LBUTTONDBLCLK:
  181513. case WM_MBUTTONDOWN:
  181514. case WM_MBUTTONDBLCLK:
  181515. case WM_RBUTTONDOWN:
  181516. case WM_RBUTTONDBLCLK:
  181517. case WM_KEYDOWN:
  181518. case WM_SYSKEYDOWN:
  181519. {
  181520. Component* const modal = Component::getCurrentlyModalComponent (0);
  181521. if (modal != 0)
  181522. modal->inputAttemptWhenModal();
  181523. return true;
  181524. }
  181525. default:
  181526. break;
  181527. }
  181528. return false;
  181529. }
  181530. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181531. {
  181532. MSG m;
  181533. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181534. return false;
  181535. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181536. {
  181537. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181538. {
  181539. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181540. }
  181541. else if (m.message == WM_QUIT)
  181542. {
  181543. if (JUCEApplication::getInstance())
  181544. JUCEApplication::getInstance()->systemRequestedQuit();
  181545. }
  181546. else if (! isEventBlockedByModalComps (m))
  181547. {
  181548. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181549. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181550. {
  181551. // if it's someone else's window being clicked on, and the focus is
  181552. // currently on a juce window, pass the kb focus over..
  181553. HWND currentFocus = GetFocus();
  181554. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181555. SetFocus (m.hwnd);
  181556. }
  181557. TranslateMessage (&m);
  181558. DispatchMessage (&m);
  181559. }
  181560. }
  181561. return true;
  181562. }
  181563. bool juce_postMessageToSystemQueue (void* message)
  181564. {
  181565. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181566. }
  181567. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181568. void* userData)
  181569. {
  181570. if (MessageManager::getInstance()->isThisTheMessageThread())
  181571. {
  181572. return (*callback) (userData);
  181573. }
  181574. else
  181575. {
  181576. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181577. // deadlock because the message manager is blocked from running, and can't
  181578. // call your function..
  181579. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181580. return (void*) SendMessage (juce_messageWindowHandle,
  181581. specialCallbackId,
  181582. (WPARAM) callback,
  181583. (LPARAM) userData);
  181584. }
  181585. }
  181586. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181587. {
  181588. if (hwnd != juce_messageWindowHandle)
  181589. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181590. return TRUE;
  181591. }
  181592. void MessageManager::broadcastMessage (const String& value) throw()
  181593. {
  181594. VoidArray windows;
  181595. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181596. const String localCopy (value);
  181597. COPYDATASTRUCT data;
  181598. data.dwData = broadcastId;
  181599. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181600. data.lpData = (void*) (const juce_wchar*) localCopy;
  181601. for (int i = windows.size(); --i >= 0;)
  181602. {
  181603. HWND hwnd = (HWND) windows.getUnchecked(i);
  181604. TCHAR windowName [64]; // no need to read longer strings than this
  181605. GetWindowText (hwnd, windowName, 64);
  181606. windowName [63] = 0;
  181607. if (String (windowName) == String (messageWindowName))
  181608. {
  181609. DWORD_PTR result;
  181610. SendMessageTimeout (hwnd, WM_COPYDATA,
  181611. (WPARAM) juce_messageWindowHandle,
  181612. (LPARAM) &data,
  181613. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181614. 8000,
  181615. &result);
  181616. }
  181617. }
  181618. }
  181619. static const String getMessageWindowClassName()
  181620. {
  181621. // this name has to be different for each app/dll instance because otherwise
  181622. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181623. // window class).
  181624. static int number = 0;
  181625. if (number == 0)
  181626. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181627. return T("JUCEcs_") + String (number);
  181628. }
  181629. void MessageManager::doPlatformSpecificInitialisation()
  181630. {
  181631. OleInitialize (0);
  181632. const String className (getMessageWindowClassName());
  181633. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181634. WNDCLASSEX wc;
  181635. zerostruct (wc);
  181636. wc.cbSize = sizeof (wc);
  181637. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181638. wc.cbWndExtra = 4;
  181639. wc.hInstance = hmod;
  181640. wc.lpszClassName = className;
  181641. RegisterClassEx (&wc);
  181642. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181643. messageWindowName,
  181644. 0, 0, 0, 0, 0, 0, 0,
  181645. hmod, 0);
  181646. }
  181647. void MessageManager::doPlatformSpecificShutdown()
  181648. {
  181649. DestroyWindow (juce_messageWindowHandle);
  181650. UnregisterClass (getMessageWindowClassName(), 0);
  181651. OleUninitialize();
  181652. }
  181653. #endif
  181654. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181655. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181656. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181657. // compiled on its own).
  181658. #if JUCE_INCLUDED_FILE
  181659. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181660. // these are in the windows SDK, but need to be repeated here for GCC..
  181661. #ifndef GET_APPCOMMAND_LPARAM
  181662. #define FAPPCOMMAND_MASK 0xF000
  181663. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181664. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181665. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181666. #define APPCOMMAND_MEDIA_STOP 13
  181667. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181668. #define WM_APPCOMMAND 0x0319
  181669. #endif
  181670. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181671. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181672. extern bool juce_IsRunningInWine();
  181673. #ifndef ULW_ALPHA
  181674. #define ULW_ALPHA 0x00000002
  181675. #endif
  181676. #ifndef AC_SRC_ALPHA
  181677. #define AC_SRC_ALPHA 0x01
  181678. #endif
  181679. #define DEBUG_REPAINT_TIMES 0
  181680. static HPALETTE palette = 0;
  181681. static bool createPaletteIfNeeded = true;
  181682. static bool shouldDeactivateTitleBar = true;
  181683. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181684. #define WM_TRAYNOTIFY WM_USER + 100
  181685. using ::abs;
  181686. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181687. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181688. bool Desktop::canUseSemiTransparentWindows() throw()
  181689. {
  181690. if (updateLayeredWindow == 0)
  181691. {
  181692. if (! juce_IsRunningInWine())
  181693. {
  181694. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181695. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181696. }
  181697. }
  181698. return updateLayeredWindow != 0;
  181699. }
  181700. #undef DefWindowProc
  181701. #define DefWindowProc DefWindowProcW
  181702. const int extendedKeyModifier = 0x10000;
  181703. const int KeyPress::spaceKey = VK_SPACE;
  181704. const int KeyPress::returnKey = VK_RETURN;
  181705. const int KeyPress::escapeKey = VK_ESCAPE;
  181706. const int KeyPress::backspaceKey = VK_BACK;
  181707. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181708. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181709. const int KeyPress::tabKey = VK_TAB;
  181710. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181711. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181712. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181713. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181714. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181715. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181716. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181717. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181718. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181719. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181720. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181721. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181722. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181723. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181724. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181725. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181726. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181727. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181728. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181729. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181730. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181731. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181732. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181733. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181734. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181735. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181736. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181737. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181738. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181739. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181740. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181741. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181742. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181743. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181744. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181745. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181746. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181747. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181748. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181749. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181750. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181751. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181752. const int KeyPress::playKey = 0x30000;
  181753. const int KeyPress::stopKey = 0x30001;
  181754. const int KeyPress::fastForwardKey = 0x30002;
  181755. const int KeyPress::rewindKey = 0x30003;
  181756. class WindowsBitmapImage : public Image
  181757. {
  181758. public:
  181759. HBITMAP hBitmap;
  181760. BITMAPV4HEADER bitmapInfo;
  181761. HDC hdc;
  181762. unsigned char* bitmapData;
  181763. WindowsBitmapImage (const PixelFormat format_,
  181764. const int w, const int h, const bool clearImage)
  181765. : Image (format_, w, h)
  181766. {
  181767. jassert (format_ == RGB || format_ == ARGB);
  181768. pixelStride = (format_ == RGB) ? 3 : 4;
  181769. zerostruct (bitmapInfo);
  181770. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181771. bitmapInfo.bV4Width = w;
  181772. bitmapInfo.bV4Height = h;
  181773. bitmapInfo.bV4Planes = 1;
  181774. bitmapInfo.bV4CSType = 1;
  181775. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181776. if (format_ == ARGB)
  181777. {
  181778. bitmapInfo.bV4AlphaMask = 0xff000000;
  181779. bitmapInfo.bV4RedMask = 0xff0000;
  181780. bitmapInfo.bV4GreenMask = 0xff00;
  181781. bitmapInfo.bV4BlueMask = 0xff;
  181782. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181783. }
  181784. else
  181785. {
  181786. bitmapInfo.bV4V4Compression = BI_RGB;
  181787. }
  181788. lineStride = -((w * pixelStride + 3) & ~3);
  181789. HDC dc = GetDC (0);
  181790. hdc = CreateCompatibleDC (dc);
  181791. ReleaseDC (0, dc);
  181792. SetMapMode (hdc, MM_TEXT);
  181793. hBitmap = CreateDIBSection (hdc,
  181794. (BITMAPINFO*) &(bitmapInfo),
  181795. DIB_RGB_COLORS,
  181796. (void**) &bitmapData,
  181797. 0, 0);
  181798. SelectObject (hdc, hBitmap);
  181799. if (format_ == ARGB && clearImage)
  181800. zeromem (bitmapData, abs (h * lineStride));
  181801. imageData = bitmapData - (lineStride * (h - 1));
  181802. }
  181803. ~WindowsBitmapImage()
  181804. {
  181805. DeleteDC (hdc);
  181806. DeleteObject (hBitmap);
  181807. }
  181808. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181809. const int x, const int y,
  181810. const RectangleList& maskedRegion) throw()
  181811. {
  181812. static HDRAWDIB hdd = 0;
  181813. static bool needToCreateDrawDib = true;
  181814. if (needToCreateDrawDib)
  181815. {
  181816. needToCreateDrawDib = false;
  181817. HDC dc = GetDC (0);
  181818. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181819. ReleaseDC (0, dc);
  181820. // only open if we're not palettised
  181821. if (n > 8)
  181822. hdd = DrawDibOpen();
  181823. }
  181824. if (createPaletteIfNeeded)
  181825. {
  181826. HDC dc = GetDC (0);
  181827. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181828. ReleaseDC (0, dc);
  181829. if (n <= 8)
  181830. palette = CreateHalftonePalette (dc);
  181831. createPaletteIfNeeded = false;
  181832. }
  181833. if (palette != 0)
  181834. {
  181835. SelectPalette (dc, palette, FALSE);
  181836. RealizePalette (dc);
  181837. SetStretchBltMode (dc, HALFTONE);
  181838. }
  181839. SetMapMode (dc, MM_TEXT);
  181840. if (transparent)
  181841. {
  181842. POINT p, pos;
  181843. SIZE size;
  181844. RECT windowBounds;
  181845. GetWindowRect (hwnd, &windowBounds);
  181846. p.x = -x;
  181847. p.y = -y;
  181848. pos.x = windowBounds.left;
  181849. pos.y = windowBounds.top;
  181850. size.cx = windowBounds.right - windowBounds.left;
  181851. size.cy = windowBounds.bottom - windowBounds.top;
  181852. BLENDFUNCTION bf;
  181853. bf.AlphaFormat = AC_SRC_ALPHA;
  181854. bf.BlendFlags = 0;
  181855. bf.BlendOp = AC_SRC_OVER;
  181856. bf.SourceConstantAlpha = 0xff;
  181857. if (! maskedRegion.isEmpty())
  181858. {
  181859. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181860. {
  181861. const Rectangle<int>& r = *i.getRectangle();
  181862. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181863. }
  181864. }
  181865. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181866. }
  181867. else
  181868. {
  181869. int savedDC = 0;
  181870. if (! maskedRegion.isEmpty())
  181871. {
  181872. savedDC = SaveDC (dc);
  181873. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181874. {
  181875. const Rectangle<int>& r = *i.getRectangle();
  181876. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181877. }
  181878. }
  181879. const int w = getWidth();
  181880. const int h = getHeight();
  181881. if (hdd == 0)
  181882. {
  181883. StretchDIBits (dc,
  181884. x, y, w, h,
  181885. 0, 0, w, h,
  181886. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181887. DIB_RGB_COLORS, SRCCOPY);
  181888. }
  181889. else
  181890. {
  181891. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181892. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181893. 0, 0, w, h, 0);
  181894. }
  181895. if (! maskedRegion.isEmpty())
  181896. RestoreDC (dc, savedDC);
  181897. }
  181898. }
  181899. juce_UseDebuggingNewOperator
  181900. private:
  181901. WindowsBitmapImage (const WindowsBitmapImage&);
  181902. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181903. };
  181904. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181905. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181906. {
  181907. SHORT k = (SHORT) keyCode;
  181908. if ((keyCode & extendedKeyModifier) == 0
  181909. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  181910. k += (SHORT) T('A') - (SHORT) T('a');
  181911. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181912. (SHORT) '+', VK_OEM_PLUS,
  181913. (SHORT) '-', VK_OEM_MINUS,
  181914. (SHORT) '.', VK_OEM_PERIOD,
  181915. (SHORT) ';', VK_OEM_1,
  181916. (SHORT) ':', VK_OEM_1,
  181917. (SHORT) '/', VK_OEM_2,
  181918. (SHORT) '?', VK_OEM_2,
  181919. (SHORT) '[', VK_OEM_4,
  181920. (SHORT) ']', VK_OEM_6 };
  181921. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181922. if (k == translatedValues [i])
  181923. k = translatedValues [i + 1];
  181924. return (GetKeyState (k) & 0x8000) != 0;
  181925. }
  181926. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181927. {
  181928. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181929. return callback (userData);
  181930. else
  181931. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181932. }
  181933. class Win32ComponentPeer : public ComponentPeer
  181934. {
  181935. public:
  181936. Win32ComponentPeer (Component* const component,
  181937. const int windowStyleFlags)
  181938. : ComponentPeer (component, windowStyleFlags),
  181939. dontRepaint (false),
  181940. fullScreen (false),
  181941. isDragging (false),
  181942. isMouseOver (false),
  181943. hasCreatedCaret (false),
  181944. currentWindowIcon (0),
  181945. taskBarIcon (0),
  181946. dropTarget (0)
  181947. {
  181948. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  181949. setTitle (component->getName());
  181950. if ((windowStyleFlags & windowHasDropShadow) != 0
  181951. && Desktop::canUseSemiTransparentWindows())
  181952. {
  181953. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181954. if (shadower != 0)
  181955. shadower->setOwner (component);
  181956. }
  181957. else
  181958. {
  181959. shadower = 0;
  181960. }
  181961. }
  181962. ~Win32ComponentPeer()
  181963. {
  181964. setTaskBarIcon (0);
  181965. deleteAndZero (shadower);
  181966. // do this before the next bit to avoid messages arriving for this window
  181967. // before it's destroyed
  181968. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181969. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181970. if (currentWindowIcon != 0)
  181971. DestroyIcon (currentWindowIcon);
  181972. if (dropTarget != 0)
  181973. {
  181974. dropTarget->Release();
  181975. dropTarget = 0;
  181976. }
  181977. }
  181978. void* getNativeHandle() const
  181979. {
  181980. return (void*) hwnd;
  181981. }
  181982. void setVisible (bool shouldBeVisible)
  181983. {
  181984. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181985. if (shouldBeVisible)
  181986. InvalidateRect (hwnd, 0, 0);
  181987. else
  181988. lastPaintTime = 0;
  181989. }
  181990. void setTitle (const String& title)
  181991. {
  181992. SetWindowText (hwnd, title);
  181993. }
  181994. void setPosition (int x, int y)
  181995. {
  181996. offsetWithinParent (x, y);
  181997. SetWindowPos (hwnd, 0,
  181998. x - windowBorder.getLeft(),
  181999. y - windowBorder.getTop(),
  182000. 0, 0,
  182001. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182002. }
  182003. void repaintNowIfTransparent()
  182004. {
  182005. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  182006. handlePaintMessage();
  182007. }
  182008. void updateBorderSize()
  182009. {
  182010. WINDOWINFO info;
  182011. info.cbSize = sizeof (info);
  182012. if (GetWindowInfo (hwnd, &info))
  182013. {
  182014. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  182015. info.rcClient.left - info.rcWindow.left,
  182016. info.rcWindow.bottom - info.rcClient.bottom,
  182017. info.rcWindow.right - info.rcClient.right);
  182018. }
  182019. }
  182020. void setSize (int w, int h)
  182021. {
  182022. SetWindowPos (hwnd, 0, 0, 0,
  182023. w + windowBorder.getLeftAndRight(),
  182024. h + windowBorder.getTopAndBottom(),
  182025. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182026. updateBorderSize();
  182027. repaintNowIfTransparent();
  182028. }
  182029. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  182030. {
  182031. fullScreen = isNowFullScreen;
  182032. offsetWithinParent (x, y);
  182033. SetWindowPos (hwnd, 0,
  182034. x - windowBorder.getLeft(),
  182035. y - windowBorder.getTop(),
  182036. w + windowBorder.getLeftAndRight(),
  182037. h + windowBorder.getTopAndBottom(),
  182038. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182039. updateBorderSize();
  182040. repaintNowIfTransparent();
  182041. }
  182042. const Rectangle<int> getBounds() const
  182043. {
  182044. RECT r;
  182045. GetWindowRect (hwnd, &r);
  182046. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  182047. HWND parentH = GetParent (hwnd);
  182048. if (parentH != 0)
  182049. {
  182050. GetWindowRect (parentH, &r);
  182051. bounds.translate (-r.left, -r.top);
  182052. }
  182053. return windowBorder.subtractedFrom (bounds);
  182054. }
  182055. const Point<int> getScreenPosition() const
  182056. {
  182057. RECT r;
  182058. GetWindowRect (hwnd, &r);
  182059. return Point<int> (r.left + windowBorder.getLeft(),
  182060. r.top + windowBorder.getTop());
  182061. }
  182062. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  182063. {
  182064. return relativePosition + getScreenPosition();
  182065. }
  182066. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  182067. {
  182068. return screenPosition - getScreenPosition();
  182069. }
  182070. void setMinimised (bool shouldBeMinimised)
  182071. {
  182072. if (shouldBeMinimised != isMinimised())
  182073. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  182074. }
  182075. bool isMinimised() const
  182076. {
  182077. WINDOWPLACEMENT wp;
  182078. wp.length = sizeof (WINDOWPLACEMENT);
  182079. GetWindowPlacement (hwnd, &wp);
  182080. return wp.showCmd == SW_SHOWMINIMIZED;
  182081. }
  182082. void setFullScreen (bool shouldBeFullScreen)
  182083. {
  182084. setMinimised (false);
  182085. if (fullScreen != shouldBeFullScreen)
  182086. {
  182087. fullScreen = shouldBeFullScreen;
  182088. const ComponentDeletionWatcher deletionChecker (component);
  182089. if (! fullScreen)
  182090. {
  182091. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  182092. if (hasTitleBar())
  182093. ShowWindow (hwnd, SW_SHOWNORMAL);
  182094. if (! boundsCopy.isEmpty())
  182095. {
  182096. setBounds (boundsCopy.getX(),
  182097. boundsCopy.getY(),
  182098. boundsCopy.getWidth(),
  182099. boundsCopy.getHeight(),
  182100. false);
  182101. }
  182102. }
  182103. else
  182104. {
  182105. if (hasTitleBar())
  182106. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  182107. else
  182108. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  182109. }
  182110. if (! deletionChecker.hasBeenDeleted())
  182111. handleMovedOrResized();
  182112. }
  182113. }
  182114. bool isFullScreen() const
  182115. {
  182116. if (! hasTitleBar())
  182117. return fullScreen;
  182118. WINDOWPLACEMENT wp;
  182119. wp.length = sizeof (wp);
  182120. GetWindowPlacement (hwnd, &wp);
  182121. return wp.showCmd == SW_SHOWMAXIMIZED;
  182122. }
  182123. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  182124. {
  182125. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  182126. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  182127. return false;
  182128. RECT r;
  182129. GetWindowRect (hwnd, &r);
  182130. POINT p;
  182131. p.x = position.getX() + r.left + windowBorder.getLeft();
  182132. p.y = position.getY() + r.top + windowBorder.getTop();
  182133. HWND w = WindowFromPoint (p);
  182134. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  182135. }
  182136. const BorderSize getFrameSize() const
  182137. {
  182138. return windowBorder;
  182139. }
  182140. bool setAlwaysOnTop (bool alwaysOnTop)
  182141. {
  182142. const bool oldDeactivate = shouldDeactivateTitleBar;
  182143. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182144. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  182145. 0, 0, 0, 0,
  182146. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182147. shouldDeactivateTitleBar = oldDeactivate;
  182148. if (shadower != 0)
  182149. shadower->componentBroughtToFront (*component);
  182150. return true;
  182151. }
  182152. void toFront (bool makeActive)
  182153. {
  182154. setMinimised (false);
  182155. const bool oldDeactivate = shouldDeactivateTitleBar;
  182156. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182157. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  182158. : &toFrontCallback2,
  182159. (void*) hwnd);
  182160. shouldDeactivateTitleBar = oldDeactivate;
  182161. if (! makeActive)
  182162. {
  182163. // in this case a broughttofront call won't have occured, so do it now..
  182164. handleBroughtToFront();
  182165. }
  182166. }
  182167. void toBehind (ComponentPeer* other)
  182168. {
  182169. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  182170. jassert (otherPeer != 0); // wrong type of window?
  182171. if (otherPeer != 0)
  182172. {
  182173. setMinimised (false);
  182174. // must be careful not to try to put a topmost window behind a normal one, or win32
  182175. // promotes the normal one to be topmost!
  182176. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  182177. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  182178. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182179. else if (otherPeer->getComponent()->isAlwaysOnTop())
  182180. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  182181. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182182. }
  182183. }
  182184. bool isFocused() const
  182185. {
  182186. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  182187. }
  182188. void grabFocus()
  182189. {
  182190. const bool oldDeactivate = shouldDeactivateTitleBar;
  182191. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182192. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  182193. shouldDeactivateTitleBar = oldDeactivate;
  182194. }
  182195. void textInputRequired (const Point<int>&)
  182196. {
  182197. if (! hasCreatedCaret)
  182198. {
  182199. hasCreatedCaret = true;
  182200. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  182201. }
  182202. ShowCaret (hwnd);
  182203. SetCaretPos (0, 0);
  182204. }
  182205. void repaint (int x, int y, int w, int h)
  182206. {
  182207. const RECT r = { x, y, x + w, y + h };
  182208. InvalidateRect (hwnd, &r, FALSE);
  182209. }
  182210. void performAnyPendingRepaintsNow()
  182211. {
  182212. MSG m;
  182213. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  182214. DispatchMessage (&m);
  182215. }
  182216. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  182217. {
  182218. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  182219. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  182220. return 0;
  182221. }
  182222. void setTaskBarIcon (const Image* const image)
  182223. {
  182224. if (image != 0)
  182225. {
  182226. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  182227. if (taskBarIcon == 0)
  182228. {
  182229. taskBarIcon = new NOTIFYICONDATA();
  182230. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  182231. taskBarIcon->hWnd = (HWND) hwnd;
  182232. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  182233. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  182234. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  182235. taskBarIcon->hIcon = hicon;
  182236. taskBarIcon->szTip[0] = 0;
  182237. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  182238. }
  182239. else
  182240. {
  182241. HICON oldIcon = taskBarIcon->hIcon;
  182242. taskBarIcon->hIcon = hicon;
  182243. taskBarIcon->uFlags = NIF_ICON;
  182244. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182245. DestroyIcon (oldIcon);
  182246. }
  182247. DestroyIcon (hicon);
  182248. }
  182249. else if (taskBarIcon != 0)
  182250. {
  182251. taskBarIcon->uFlags = 0;
  182252. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  182253. DestroyIcon (taskBarIcon->hIcon);
  182254. deleteAndZero (taskBarIcon);
  182255. }
  182256. }
  182257. void setTaskBarIconToolTip (const String& toolTip) const
  182258. {
  182259. if (taskBarIcon != 0)
  182260. {
  182261. taskBarIcon->uFlags = NIF_TIP;
  182262. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  182263. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182264. }
  182265. }
  182266. bool isInside (HWND h) const
  182267. {
  182268. return GetAncestor (hwnd, GA_ROOT) == h;
  182269. }
  182270. static void updateKeyModifiers() throw()
  182271. {
  182272. int keyMods = 0;
  182273. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  182274. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  182275. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  182276. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  182277. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182278. }
  182279. static void updateModifiersFromWParam (const WPARAM wParam)
  182280. {
  182281. int mouseMods = 0;
  182282. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  182283. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  182284. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  182285. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  182286. updateKeyModifiers();
  182287. }
  182288. static int64 getMouseEventTime()
  182289. {
  182290. static int64 eventTimeOffset = 0;
  182291. static DWORD lastMessageTime = 0;
  182292. const DWORD thisMessageTime = GetMessageTime();
  182293. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  182294. {
  182295. lastMessageTime = thisMessageTime;
  182296. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  182297. }
  182298. return eventTimeOffset + thisMessageTime;
  182299. }
  182300. juce_UseDebuggingNewOperator
  182301. bool dontRepaint;
  182302. static ModifierKeys currentModifiers;
  182303. static ModifierKeys modifiersAtLastCallback;
  182304. private:
  182305. HWND hwnd;
  182306. DropShadower* shadower;
  182307. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182308. BorderSize windowBorder;
  182309. HICON currentWindowIcon;
  182310. NOTIFYICONDATA* taskBarIcon;
  182311. IDropTarget* dropTarget;
  182312. class TemporaryImage : public Timer
  182313. {
  182314. public:
  182315. TemporaryImage()
  182316. : image (0)
  182317. {
  182318. }
  182319. ~TemporaryImage()
  182320. {
  182321. delete image;
  182322. }
  182323. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182324. {
  182325. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182326. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182327. {
  182328. delete image;
  182329. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182330. }
  182331. startTimer (3000);
  182332. return image;
  182333. }
  182334. void timerCallback()
  182335. {
  182336. stopTimer();
  182337. deleteAndZero (image);
  182338. }
  182339. private:
  182340. WindowsBitmapImage* image;
  182341. TemporaryImage (const TemporaryImage&);
  182342. TemporaryImage& operator= (const TemporaryImage&);
  182343. };
  182344. TemporaryImage offscreenImageGenerator;
  182345. class WindowClassHolder : public DeletedAtShutdown
  182346. {
  182347. public:
  182348. WindowClassHolder()
  182349. : windowClassName ("JUCE_")
  182350. {
  182351. // this name has to be different for each app/dll instance because otherwise
  182352. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182353. // window class).
  182354. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182355. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182356. TCHAR moduleFile [1024];
  182357. moduleFile[0] = 0;
  182358. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182359. WORD iconNum = 0;
  182360. WNDCLASSEX wcex;
  182361. wcex.cbSize = sizeof (wcex);
  182362. wcex.style = CS_OWNDC;
  182363. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182364. wcex.lpszClassName = windowClassName;
  182365. wcex.cbClsExtra = 0;
  182366. wcex.cbWndExtra = 32;
  182367. wcex.hInstance = moduleHandle;
  182368. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182369. iconNum = 1;
  182370. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182371. wcex.hCursor = 0;
  182372. wcex.hbrBackground = 0;
  182373. wcex.lpszMenuName = 0;
  182374. RegisterClassEx (&wcex);
  182375. }
  182376. ~WindowClassHolder()
  182377. {
  182378. if (ComponentPeer::getNumPeers() == 0)
  182379. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182380. clearSingletonInstance();
  182381. }
  182382. String windowClassName;
  182383. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182384. };
  182385. static void* createWindowCallback (void* userData)
  182386. {
  182387. ((Win32ComponentPeer*) userData)->createWindow();
  182388. return 0;
  182389. }
  182390. void createWindow()
  182391. {
  182392. DWORD exstyle = WS_EX_ACCEPTFILES;
  182393. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182394. if (hasTitleBar())
  182395. {
  182396. type |= WS_OVERLAPPED;
  182397. exstyle |= WS_EX_APPWINDOW;
  182398. if ((styleFlags & windowHasCloseButton) != 0)
  182399. {
  182400. type |= WS_SYSMENU;
  182401. }
  182402. else
  182403. {
  182404. // annoyingly, windows won't let you have a min/max button without a close button
  182405. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182406. }
  182407. if ((styleFlags & windowIsResizable) != 0)
  182408. type |= WS_THICKFRAME;
  182409. }
  182410. else
  182411. {
  182412. type |= WS_POPUP | WS_SYSMENU;
  182413. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182414. exstyle |= WS_EX_TOOLWINDOW;
  182415. else
  182416. exstyle |= WS_EX_APPWINDOW;
  182417. }
  182418. if ((styleFlags & windowHasMinimiseButton) != 0)
  182419. type |= WS_MINIMIZEBOX;
  182420. if ((styleFlags & windowHasMaximiseButton) != 0)
  182421. type |= WS_MAXIMIZEBOX;
  182422. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182423. exstyle |= WS_EX_TRANSPARENT;
  182424. if ((styleFlags & windowIsSemiTransparent) != 0
  182425. && Desktop::canUseSemiTransparentWindows())
  182426. exstyle |= WS_EX_LAYERED;
  182427. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182428. if (hwnd != 0)
  182429. {
  182430. SetWindowLongPtr (hwnd, 0, 0);
  182431. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182432. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182433. if (dropTarget == 0)
  182434. dropTarget = new JuceDropTarget (this);
  182435. RegisterDragDrop (hwnd, dropTarget);
  182436. updateBorderSize();
  182437. // Calling this function here is (for some reason) necessary to make Windows
  182438. // correctly enable the menu items that we specify in the wm_initmenu message.
  182439. GetSystemMenu (hwnd, false);
  182440. }
  182441. else
  182442. {
  182443. jassertfalse
  182444. }
  182445. }
  182446. static void* destroyWindowCallback (void* handle)
  182447. {
  182448. RevokeDragDrop ((HWND) handle);
  182449. DestroyWindow ((HWND) handle);
  182450. return 0;
  182451. }
  182452. static void* toFrontCallback1 (void* h)
  182453. {
  182454. SetForegroundWindow ((HWND) h);
  182455. return 0;
  182456. }
  182457. static void* toFrontCallback2 (void* h)
  182458. {
  182459. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182460. return 0;
  182461. }
  182462. static void* setFocusCallback (void* h)
  182463. {
  182464. SetFocus ((HWND) h);
  182465. return 0;
  182466. }
  182467. static void* getFocusCallback (void*)
  182468. {
  182469. return (void*) GetFocus();
  182470. }
  182471. void offsetWithinParent (int& x, int& y) const
  182472. {
  182473. if (isTransparent())
  182474. {
  182475. HWND parentHwnd = GetParent (hwnd);
  182476. if (parentHwnd != 0)
  182477. {
  182478. RECT parentRect;
  182479. GetWindowRect (parentHwnd, &parentRect);
  182480. x += parentRect.left;
  182481. y += parentRect.top;
  182482. }
  182483. }
  182484. }
  182485. bool isTransparent() const
  182486. {
  182487. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182488. }
  182489. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182490. void setIcon (const Image& newIcon)
  182491. {
  182492. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182493. if (hicon != 0)
  182494. {
  182495. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182496. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182497. if (currentWindowIcon != 0)
  182498. DestroyIcon (currentWindowIcon);
  182499. currentWindowIcon = hicon;
  182500. }
  182501. }
  182502. void handlePaintMessage()
  182503. {
  182504. #if DEBUG_REPAINT_TIMES
  182505. const double paintStart = Time::getMillisecondCounterHiRes();
  182506. #endif
  182507. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182508. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182509. PAINTSTRUCT paintStruct;
  182510. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182511. // message and become re-entrant, but that's OK
  182512. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182513. // corrupt the image it's using to paint into, so do a check here.
  182514. static bool reentrant = false;
  182515. if (reentrant)
  182516. {
  182517. DeleteObject (rgn);
  182518. EndPaint (hwnd, &paintStruct);
  182519. return;
  182520. }
  182521. reentrant = true;
  182522. // this is the rectangle to update..
  182523. int x = paintStruct.rcPaint.left;
  182524. int y = paintStruct.rcPaint.top;
  182525. int w = paintStruct.rcPaint.right - x;
  182526. int h = paintStruct.rcPaint.bottom - y;
  182527. const bool transparent = isTransparent();
  182528. if (transparent)
  182529. {
  182530. // it's not possible to have a transparent window with a title bar at the moment!
  182531. jassert (! hasTitleBar());
  182532. RECT r;
  182533. GetWindowRect (hwnd, &r);
  182534. x = y = 0;
  182535. w = r.right - r.left;
  182536. h = r.bottom - r.top;
  182537. }
  182538. if (w > 0 && h > 0)
  182539. {
  182540. clearMaskedRegion();
  182541. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182542. RectangleList contextClip;
  182543. bool needToPaintAll = true;
  182544. if (regionType == COMPLEXREGION && ! transparent)
  182545. {
  182546. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182547. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182548. DeleteObject (clipRgn);
  182549. char rgnData [8192];
  182550. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182551. if (res > 0 && res <= sizeof (rgnData))
  182552. {
  182553. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182554. if (hdr->iType == RDH_RECTANGLES
  182555. && hdr->rcBound.right - hdr->rcBound.left >= w
  182556. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182557. {
  182558. needToPaintAll = false;
  182559. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182560. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182561. while (--num >= 0)
  182562. {
  182563. // (need to move this one pixel to the left because of a win32 bug)
  182564. const int cx = jmax (x, (int) rects->left - 1);
  182565. const int cy = rects->top;
  182566. const int cw = rects->right - cx;
  182567. const int ch = rects->bottom - rects->top;
  182568. if (cx + cw - x <= w && cy + ch - y <= h)
  182569. {
  182570. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182571. }
  182572. else
  182573. {
  182574. needToPaintAll = true;
  182575. break;
  182576. }
  182577. ++rects;
  182578. }
  182579. }
  182580. }
  182581. }
  182582. if (needToPaintAll)
  182583. {
  182584. contextClip.clear();
  182585. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182586. }
  182587. if (transparent)
  182588. {
  182589. RectangleList::Iterator i (contextClip);
  182590. while (i.next())
  182591. {
  182592. const Rectangle<int>& r = *i.getRectangle();
  182593. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182594. }
  182595. }
  182596. // if the component's not opaque, this won't draw properly unless the platform can support this
  182597. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182598. updateCurrentModifiers();
  182599. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182600. context.clipToRectangleList (contextClip);
  182601. context.setOrigin (-x, -y);
  182602. handlePaint (context);
  182603. if (! dontRepaint)
  182604. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182605. }
  182606. DeleteObject (rgn);
  182607. EndPaint (hwnd, &paintStruct);
  182608. reentrant = false;
  182609. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182610. _fpreset(); // because some graphics cards can unmask FP exceptions
  182611. #endif
  182612. lastPaintTime = Time::getMillisecondCounter();
  182613. #if DEBUG_REPAINT_TIMES
  182614. const double elapsed = Time::getMillisecondCounterHiRes() - paintStart;
  182615. Logger::outputDebugString (T("repaint time: ") + String (elapsed, 2));
  182616. #endif
  182617. }
  182618. void doMouseEvent (const Point<int>& position)
  182619. {
  182620. handleMouseEvent (position, currentModifiers, getMouseEventTime());
  182621. }
  182622. void doMouseMove (const Point<int>& position)
  182623. {
  182624. if (! isMouseOver)
  182625. {
  182626. isMouseOver = true;
  182627. updateKeyModifiers();
  182628. TRACKMOUSEEVENT tme;
  182629. tme.cbSize = sizeof (tme);
  182630. tme.dwFlags = TME_LEAVE;
  182631. tme.hwndTrack = hwnd;
  182632. tme.dwHoverTime = 0;
  182633. if (! TrackMouseEvent (&tme))
  182634. jassertfalse;
  182635. }
  182636. else if (! isDragging)
  182637. {
  182638. if (! contains (position, false))
  182639. return;
  182640. }
  182641. doMouseEvent (position);
  182642. }
  182643. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182644. {
  182645. if (GetCapture() != hwnd)
  182646. SetCapture (hwnd);
  182647. doMouseMove (position);
  182648. updateModifiersFromWParam (wParam);
  182649. isDragging = true;
  182650. doMouseEvent (position);
  182651. }
  182652. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182653. {
  182654. updateModifiersFromWParam (wParam);
  182655. isDragging = false;
  182656. // release the mouse capture if the user has released all buttons
  182657. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182658. ReleaseCapture();
  182659. doMouseEvent (position);
  182660. }
  182661. void doCaptureChanged()
  182662. {
  182663. if (isDragging)
  182664. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182665. }
  182666. void doMouseExit()
  182667. {
  182668. isMouseOver = false;
  182669. doMouseEvent (getCurrentMousePos());
  182670. }
  182671. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182672. {
  182673. updateKeyModifiers();
  182674. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * HIWORD (wParam));
  182675. handleMouseWheel (position, getMouseEventTime(),
  182676. isVertical ? 0.0f : amount,
  182677. isVertical ? amount : 0.0f);
  182678. }
  182679. void sendModifierKeyChangeIfNeeded()
  182680. {
  182681. if (modifiersAtLastCallback != currentModifiers)
  182682. {
  182683. modifiersAtLastCallback = currentModifiers;
  182684. handleModifierKeysChange();
  182685. }
  182686. }
  182687. bool doKeyUp (const WPARAM key)
  182688. {
  182689. updateKeyModifiers();
  182690. switch (key)
  182691. {
  182692. case VK_SHIFT:
  182693. case VK_CONTROL:
  182694. case VK_MENU:
  182695. case VK_CAPITAL:
  182696. case VK_LWIN:
  182697. case VK_RWIN:
  182698. case VK_APPS:
  182699. case VK_NUMLOCK:
  182700. case VK_SCROLL:
  182701. case VK_LSHIFT:
  182702. case VK_RSHIFT:
  182703. case VK_LCONTROL:
  182704. case VK_LMENU:
  182705. case VK_RCONTROL:
  182706. case VK_RMENU:
  182707. sendModifierKeyChangeIfNeeded();
  182708. }
  182709. return handleKeyUpOrDown (false)
  182710. || Component::getCurrentlyModalComponent() != 0;
  182711. }
  182712. bool doKeyDown (const WPARAM key)
  182713. {
  182714. updateKeyModifiers();
  182715. bool used = false;
  182716. switch (key)
  182717. {
  182718. case VK_SHIFT:
  182719. case VK_LSHIFT:
  182720. case VK_RSHIFT:
  182721. case VK_CONTROL:
  182722. case VK_LCONTROL:
  182723. case VK_RCONTROL:
  182724. case VK_MENU:
  182725. case VK_LMENU:
  182726. case VK_RMENU:
  182727. case VK_LWIN:
  182728. case VK_RWIN:
  182729. case VK_CAPITAL:
  182730. case VK_NUMLOCK:
  182731. case VK_SCROLL:
  182732. case VK_APPS:
  182733. sendModifierKeyChangeIfNeeded();
  182734. break;
  182735. case VK_LEFT:
  182736. case VK_RIGHT:
  182737. case VK_UP:
  182738. case VK_DOWN:
  182739. case VK_PRIOR:
  182740. case VK_NEXT:
  182741. case VK_HOME:
  182742. case VK_END:
  182743. case VK_DELETE:
  182744. case VK_INSERT:
  182745. case VK_F1:
  182746. case VK_F2:
  182747. case VK_F3:
  182748. case VK_F4:
  182749. case VK_F5:
  182750. case VK_F6:
  182751. case VK_F7:
  182752. case VK_F8:
  182753. case VK_F9:
  182754. case VK_F10:
  182755. case VK_F11:
  182756. case VK_F12:
  182757. case VK_F13:
  182758. case VK_F14:
  182759. case VK_F15:
  182760. case VK_F16:
  182761. used = handleKeyUpOrDown (true);
  182762. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182763. break;
  182764. case VK_ADD:
  182765. case VK_SUBTRACT:
  182766. case VK_MULTIPLY:
  182767. case VK_DIVIDE:
  182768. case VK_SEPARATOR:
  182769. case VK_DECIMAL:
  182770. used = handleKeyUpOrDown (true);
  182771. break;
  182772. default:
  182773. used = handleKeyUpOrDown (true);
  182774. {
  182775. MSG msg;
  182776. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182777. {
  182778. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182779. // manually generate the key-press event that matches this key-down.
  182780. const UINT keyChar = MapVirtualKey (key, 2);
  182781. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182782. }
  182783. }
  182784. break;
  182785. }
  182786. if (Component::getCurrentlyModalComponent() != 0)
  182787. used = true;
  182788. return used;
  182789. }
  182790. bool doKeyChar (int key, const LPARAM flags)
  182791. {
  182792. updateKeyModifiers();
  182793. juce_wchar textChar = (juce_wchar) key;
  182794. const int virtualScanCode = (flags >> 16) & 0xff;
  182795. if (key >= '0' && key <= '9')
  182796. {
  182797. switch (virtualScanCode) // check for a numeric keypad scan-code
  182798. {
  182799. case 0x52:
  182800. case 0x4f:
  182801. case 0x50:
  182802. case 0x51:
  182803. case 0x4b:
  182804. case 0x4c:
  182805. case 0x4d:
  182806. case 0x47:
  182807. case 0x48:
  182808. case 0x49:
  182809. key = (key - '0') + KeyPress::numberPad0;
  182810. break;
  182811. default:
  182812. break;
  182813. }
  182814. }
  182815. else
  182816. {
  182817. // convert the scan code to an unmodified character code..
  182818. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182819. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182820. keyChar = LOWORD (keyChar);
  182821. if (keyChar != 0)
  182822. key = (int) keyChar;
  182823. // avoid sending junk text characters for some control-key combinations
  182824. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182825. textChar = 0;
  182826. }
  182827. return handleKeyPress (key, textChar);
  182828. }
  182829. bool doAppCommand (const LPARAM lParam)
  182830. {
  182831. int key = 0;
  182832. switch (GET_APPCOMMAND_LPARAM (lParam))
  182833. {
  182834. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182835. key = KeyPress::playKey;
  182836. break;
  182837. case APPCOMMAND_MEDIA_STOP:
  182838. key = KeyPress::stopKey;
  182839. break;
  182840. case APPCOMMAND_MEDIA_NEXTTRACK:
  182841. key = KeyPress::fastForwardKey;
  182842. break;
  182843. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182844. key = KeyPress::rewindKey;
  182845. break;
  182846. }
  182847. if (key != 0)
  182848. {
  182849. updateKeyModifiers();
  182850. if (hwnd == GetActiveWindow())
  182851. {
  182852. handleKeyPress (key, 0);
  182853. return true;
  182854. }
  182855. }
  182856. return false;
  182857. }
  182858. class JuceDropTarget : public IDropTarget
  182859. {
  182860. public:
  182861. JuceDropTarget (Win32ComponentPeer* const owner_)
  182862. : owner (owner_),
  182863. refCount (1)
  182864. {
  182865. }
  182866. virtual ~JuceDropTarget()
  182867. {
  182868. jassert (refCount == 0);
  182869. }
  182870. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182871. {
  182872. if (id == IID_IUnknown || id == IID_IDropTarget)
  182873. {
  182874. AddRef();
  182875. *result = this;
  182876. return S_OK;
  182877. }
  182878. *result = 0;
  182879. return E_NOINTERFACE;
  182880. }
  182881. ULONG __stdcall AddRef() { return ++refCount; }
  182882. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182883. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182884. {
  182885. updateFileList (pDataObject);
  182886. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182887. *pdwEffect = DROPEFFECT_COPY;
  182888. return S_OK;
  182889. }
  182890. HRESULT __stdcall DragLeave()
  182891. {
  182892. owner->handleFileDragExit (files);
  182893. return S_OK;
  182894. }
  182895. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182896. {
  182897. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182898. *pdwEffect = DROPEFFECT_COPY;
  182899. return S_OK;
  182900. }
  182901. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182902. {
  182903. updateFileList (pDataObject);
  182904. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182905. *pdwEffect = DROPEFFECT_COPY;
  182906. return S_OK;
  182907. }
  182908. private:
  182909. Win32ComponentPeer* const owner;
  182910. int refCount;
  182911. StringArray files;
  182912. void updateFileList (IDataObject* const pDataObject)
  182913. {
  182914. files.clear();
  182915. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182916. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182917. if (pDataObject->GetData (&format, &medium) == S_OK)
  182918. {
  182919. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182920. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182921. unsigned int i = 0;
  182922. if (pDropFiles->fWide)
  182923. {
  182924. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182925. for (;;)
  182926. {
  182927. unsigned int len = 0;
  182928. while (i + len < totalLen && fname [i + len] != 0)
  182929. ++len;
  182930. if (len == 0)
  182931. break;
  182932. files.add (String (fname + i, len));
  182933. i += len + 1;
  182934. }
  182935. }
  182936. else
  182937. {
  182938. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182939. for (;;)
  182940. {
  182941. unsigned int len = 0;
  182942. while (i + len < totalLen && fname [i + len] != 0)
  182943. ++len;
  182944. if (len == 0)
  182945. break;
  182946. files.add (String (fname + i, len));
  182947. i += len + 1;
  182948. }
  182949. }
  182950. GlobalUnlock (medium.hGlobal);
  182951. }
  182952. }
  182953. JuceDropTarget (const JuceDropTarget&);
  182954. JuceDropTarget& operator= (const JuceDropTarget&);
  182955. };
  182956. void doSettingChange()
  182957. {
  182958. Desktop::getInstance().refreshMonitorSizes();
  182959. if (fullScreen && ! isMinimised())
  182960. {
  182961. const Rectangle<int> r (component->getParentMonitorArea());
  182962. SetWindowPos (hwnd, 0,
  182963. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182964. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182965. }
  182966. }
  182967. public:
  182968. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182969. {
  182970. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182971. if (peer != 0)
  182972. return peer->peerWindowProc (h, message, wParam, lParam);
  182973. return DefWindowProc (h, message, wParam, lParam);
  182974. }
  182975. private:
  182976. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182977. {
  182978. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182979. }
  182980. const Point<int> getCurrentMousePos() throw()
  182981. {
  182982. RECT wr;
  182983. GetWindowRect (hwnd, &wr);
  182984. const DWORD mp = GetMessagePos();
  182985. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182986. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182987. }
  182988. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182989. {
  182990. if (isValidPeer (this))
  182991. {
  182992. switch (message)
  182993. {
  182994. case WM_NCHITTEST:
  182995. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182996. return HTTRANSPARENT;
  182997. if (hasTitleBar())
  182998. break;
  182999. return HTCLIENT;
  183000. case WM_PAINT:
  183001. handlePaintMessage();
  183002. return 0;
  183003. case WM_NCPAINT:
  183004. if (wParam != 1)
  183005. handlePaintMessage();
  183006. if (hasTitleBar())
  183007. break;
  183008. return 0;
  183009. case WM_ERASEBKGND:
  183010. case WM_NCCALCSIZE:
  183011. if (hasTitleBar())
  183012. break;
  183013. return 1;
  183014. case WM_MOUSEMOVE:
  183015. doMouseMove (getPointFromLParam (lParam));
  183016. return 0;
  183017. case WM_MOUSELEAVE:
  183018. doMouseExit();
  183019. return 0;
  183020. case WM_LBUTTONDOWN:
  183021. case WM_MBUTTONDOWN:
  183022. case WM_RBUTTONDOWN:
  183023. doMouseDown (getPointFromLParam (lParam), wParam);
  183024. return 0;
  183025. case WM_LBUTTONUP:
  183026. case WM_MBUTTONUP:
  183027. case WM_RBUTTONUP:
  183028. doMouseUp (getPointFromLParam (lParam), wParam);
  183029. return 0;
  183030. case WM_CAPTURECHANGED:
  183031. doCaptureChanged();
  183032. return 0;
  183033. case WM_NCMOUSEMOVE:
  183034. if (hasTitleBar())
  183035. break;
  183036. return 0;
  183037. case 0x020A: /* WM_MOUSEWHEEL */
  183038. doMouseWheel (getCurrentMousePos(), wParam, true);
  183039. return 0;
  183040. case 0x020E: /* WM_MOUSEHWHEEL */
  183041. doMouseWheel (getCurrentMousePos(), wParam, false);
  183042. return 0;
  183043. case WM_WINDOWPOSCHANGING:
  183044. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  183045. {
  183046. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  183047. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  183048. {
  183049. if (constrainer != 0)
  183050. {
  183051. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  183052. component->getY() - windowBorder.getTop(),
  183053. component->getWidth() + windowBorder.getLeftAndRight(),
  183054. component->getHeight() + windowBorder.getTopAndBottom());
  183055. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  183056. constrainer->checkBounds (pos, current,
  183057. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  183058. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  183059. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  183060. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  183061. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  183062. wp->x = pos.getX();
  183063. wp->y = pos.getY();
  183064. wp->cx = pos.getWidth();
  183065. wp->cy = pos.getHeight();
  183066. }
  183067. }
  183068. }
  183069. return 0;
  183070. case WM_WINDOWPOSCHANGED:
  183071. handleMovedOrResized();
  183072. if (dontRepaint)
  183073. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  183074. return 0;
  183075. case WM_KEYDOWN:
  183076. case WM_SYSKEYDOWN:
  183077. if (doKeyDown (wParam))
  183078. return 0;
  183079. break;
  183080. case WM_KEYUP:
  183081. case WM_SYSKEYUP:
  183082. if (doKeyUp (wParam))
  183083. return 0;
  183084. break;
  183085. case WM_CHAR:
  183086. if (doKeyChar ((int) wParam, lParam))
  183087. return 0;
  183088. break;
  183089. case WM_APPCOMMAND:
  183090. if (doAppCommand (lParam))
  183091. return TRUE;
  183092. break;
  183093. case WM_SETFOCUS:
  183094. updateKeyModifiers();
  183095. handleFocusGain();
  183096. break;
  183097. case WM_KILLFOCUS:
  183098. if (hasCreatedCaret)
  183099. {
  183100. hasCreatedCaret = false;
  183101. DestroyCaret();
  183102. }
  183103. handleFocusLoss();
  183104. break;
  183105. case WM_ACTIVATEAPP:
  183106. // Windows does weird things to process priority when you swap apps,
  183107. // so this forces an update when the app is brought to the front
  183108. if (wParam != FALSE)
  183109. juce_repeatLastProcessPriority();
  183110. else
  183111. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  183112. juce_CheckCurrentlyFocusedTopLevelWindow();
  183113. modifiersAtLastCallback = -1;
  183114. return 0;
  183115. case WM_ACTIVATE:
  183116. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  183117. {
  183118. modifiersAtLastCallback = -1;
  183119. updateKeyModifiers();
  183120. if (isMinimised())
  183121. {
  183122. component->repaint();
  183123. handleMovedOrResized();
  183124. if (! ComponentPeer::isValidPeer (this))
  183125. return 0;
  183126. }
  183127. if (LOWORD (wParam) == WA_CLICKACTIVE
  183128. && component->isCurrentlyBlockedByAnotherModalComponent())
  183129. {
  183130. const Point<int> mousePos (component->getMouseXYRelative());
  183131. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  183132. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  183133. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  183134. return 0;
  183135. }
  183136. handleBroughtToFront();
  183137. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183138. Component::getCurrentlyModalComponent()->toFront (true);
  183139. return 0;
  183140. }
  183141. break;
  183142. case WM_NCACTIVATE:
  183143. // while a temporary window is being shown, prevent Windows from deactivating the
  183144. // title bars of our main windows.
  183145. if (wParam == 0 && ! shouldDeactivateTitleBar)
  183146. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  183147. break;
  183148. case WM_MOUSEACTIVATE:
  183149. if (! component->getMouseClickGrabsKeyboardFocus())
  183150. return MA_NOACTIVATE;
  183151. break;
  183152. case WM_SHOWWINDOW:
  183153. if (wParam != 0)
  183154. handleBroughtToFront();
  183155. break;
  183156. case WM_CLOSE:
  183157. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  183158. handleUserClosingWindow();
  183159. return 0;
  183160. case WM_QUERYENDSESSION:
  183161. if (JUCEApplication::getInstance() != 0)
  183162. {
  183163. JUCEApplication::getInstance()->systemRequestedQuit();
  183164. return MessageManager::getInstance()->hasStopMessageBeenSent();
  183165. }
  183166. return TRUE;
  183167. case WM_TRAYNOTIFY:
  183168. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183169. {
  183170. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  183171. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183172. {
  183173. Component* const current = Component::getCurrentlyModalComponent();
  183174. if (current != 0)
  183175. current->inputAttemptWhenModal();
  183176. }
  183177. }
  183178. else
  183179. {
  183180. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  183181. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  183182. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  183183. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  183184. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  183185. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  183186. eventMods = eventMods.withoutMouseButtons();
  183187. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  183188. Point<int>(), eventMods, component, getMouseEventTime(),
  183189. Point<int>(), getMouseEventTime(), 1, false);
  183190. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  183191. {
  183192. SetFocus (hwnd);
  183193. SetForegroundWindow (hwnd);
  183194. component->mouseDown (e);
  183195. }
  183196. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  183197. {
  183198. component->mouseUp (e);
  183199. }
  183200. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183201. {
  183202. component->mouseDoubleClick (e);
  183203. }
  183204. else if (lParam == WM_MOUSEMOVE)
  183205. {
  183206. component->mouseMove (e);
  183207. }
  183208. }
  183209. break;
  183210. case WM_SYNCPAINT:
  183211. return 0;
  183212. case WM_PALETTECHANGED:
  183213. InvalidateRect (h, 0, 0);
  183214. break;
  183215. case WM_DISPLAYCHANGE:
  183216. InvalidateRect (h, 0, 0);
  183217. createPaletteIfNeeded = true;
  183218. // intentional fall-through...
  183219. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  183220. doSettingChange();
  183221. break;
  183222. case WM_INITMENU:
  183223. if (! hasTitleBar())
  183224. {
  183225. if (isFullScreen())
  183226. {
  183227. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  183228. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  183229. }
  183230. else if (! isMinimised())
  183231. {
  183232. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  183233. }
  183234. }
  183235. break;
  183236. case WM_SYSCOMMAND:
  183237. switch (wParam & 0xfff0)
  183238. {
  183239. case SC_CLOSE:
  183240. if (sendInputAttemptWhenModalMessage())
  183241. return 0;
  183242. if (hasTitleBar())
  183243. {
  183244. PostMessage (h, WM_CLOSE, 0, 0);
  183245. return 0;
  183246. }
  183247. break;
  183248. case SC_KEYMENU:
  183249. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  183250. // obscure situations that can arise if a modal loop is started from an alt-key
  183251. // keypress).
  183252. if (hasTitleBar() && h == GetCapture())
  183253. ReleaseCapture();
  183254. break;
  183255. case SC_MAXIMIZE:
  183256. if (sendInputAttemptWhenModalMessage())
  183257. return 0;
  183258. setFullScreen (true);
  183259. return 0;
  183260. case SC_MINIMIZE:
  183261. if (sendInputAttemptWhenModalMessage())
  183262. return 0;
  183263. if (! hasTitleBar())
  183264. {
  183265. setMinimised (true);
  183266. return 0;
  183267. }
  183268. break;
  183269. case SC_RESTORE:
  183270. if (sendInputAttemptWhenModalMessage())
  183271. return 0;
  183272. if (hasTitleBar())
  183273. {
  183274. if (isFullScreen())
  183275. {
  183276. setFullScreen (false);
  183277. return 0;
  183278. }
  183279. }
  183280. else
  183281. {
  183282. if (isMinimised())
  183283. setMinimised (false);
  183284. else if (isFullScreen())
  183285. setFullScreen (false);
  183286. return 0;
  183287. }
  183288. break;
  183289. }
  183290. break;
  183291. case WM_NCLBUTTONDOWN:
  183292. case WM_NCRBUTTONDOWN:
  183293. case WM_NCMBUTTONDOWN:
  183294. sendInputAttemptWhenModalMessage();
  183295. break;
  183296. //case WM_IME_STARTCOMPOSITION;
  183297. // return 0;
  183298. case WM_GETDLGCODE:
  183299. return DLGC_WANTALLKEYS;
  183300. default:
  183301. break;
  183302. }
  183303. }
  183304. return DefWindowProc (h, message, wParam, lParam);
  183305. }
  183306. bool sendInputAttemptWhenModalMessage()
  183307. {
  183308. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183309. {
  183310. Component* const current = Component::getCurrentlyModalComponent();
  183311. if (current != 0)
  183312. current->inputAttemptWhenModal();
  183313. return true;
  183314. }
  183315. return false;
  183316. }
  183317. Win32ComponentPeer (const Win32ComponentPeer&);
  183318. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183319. };
  183320. ModifierKeys Win32ComponentPeer::currentModifiers;
  183321. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  183322. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183323. {
  183324. return new Win32ComponentPeer (this, styleFlags);
  183325. }
  183326. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183327. void ModifierKeys::updateCurrentModifiers() throw()
  183328. {
  183329. currentModifiers = Win32ComponentPeer::currentModifiers;
  183330. }
  183331. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  183332. {
  183333. Win32ComponentPeer::updateKeyModifiers();
  183334. int keyMods = 0;
  183335. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  183336. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  183337. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  183338. Win32ComponentPeer::currentModifiers
  183339. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  183340. return Win32ComponentPeer::currentModifiers;
  183341. }
  183342. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183343. {
  183344. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183345. if (wp != 0)
  183346. wp->setTaskBarIcon (&newImage);
  183347. }
  183348. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183349. {
  183350. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183351. if (wp != 0)
  183352. wp->setTaskBarIconToolTip (tooltip);
  183353. }
  183354. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183355. {
  183356. DWORD val = GetWindowLong (h, styleType);
  183357. if (bitIsSet)
  183358. val |= feature;
  183359. else
  183360. val &= ~feature;
  183361. SetWindowLongPtr (h, styleType, val);
  183362. SetWindowPos (h, 0, 0, 0, 0, 0,
  183363. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183364. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183365. }
  183366. bool Process::isForegroundProcess()
  183367. {
  183368. HWND fg = GetForegroundWindow();
  183369. if (fg == 0)
  183370. return true;
  183371. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183372. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183373. // have to see if any of our windows are children of the foreground window
  183374. fg = GetAncestor (fg, GA_ROOT);
  183375. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183376. {
  183377. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183378. if (wp != 0 && wp->isInside (fg))
  183379. return true;
  183380. }
  183381. return false;
  183382. }
  183383. bool AlertWindow::showNativeDialogBox (const String& title,
  183384. const String& bodyText,
  183385. bool isOkCancel)
  183386. {
  183387. return MessageBox (0, bodyText, title,
  183388. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183389. : MB_OK)) == IDOK;
  183390. }
  183391. const Point<int> Desktop::getMousePosition()
  183392. {
  183393. POINT mousePos;
  183394. GetCursorPos (&mousePos);
  183395. return Point<int> (mousePos.x, mousePos.y);
  183396. }
  183397. void Desktop::setMousePosition (const Point<int>& newPosition)
  183398. {
  183399. SetCursorPos (newPosition.getX(), newPosition.getY());
  183400. }
  183401. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183402. {
  183403. return new Image (format, imageWidth, imageHeight, clearImage);
  183404. }
  183405. class ScreenSaverDefeater : public Timer,
  183406. public DeletedAtShutdown
  183407. {
  183408. public:
  183409. ScreenSaverDefeater() throw()
  183410. {
  183411. startTimer (10000);
  183412. timerCallback();
  183413. }
  183414. ~ScreenSaverDefeater() {}
  183415. void timerCallback()
  183416. {
  183417. if (Process::isForegroundProcess())
  183418. {
  183419. // simulate a shift key getting pressed..
  183420. INPUT input[2];
  183421. input[0].type = INPUT_KEYBOARD;
  183422. input[0].ki.wVk = VK_SHIFT;
  183423. input[0].ki.dwFlags = 0;
  183424. input[0].ki.dwExtraInfo = 0;
  183425. input[1].type = INPUT_KEYBOARD;
  183426. input[1].ki.wVk = VK_SHIFT;
  183427. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183428. input[1].ki.dwExtraInfo = 0;
  183429. SendInput (2, input, sizeof (INPUT));
  183430. }
  183431. }
  183432. };
  183433. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183434. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183435. {
  183436. if (isEnabled)
  183437. {
  183438. deleteAndZero (screenSaverDefeater);
  183439. }
  183440. else if (screenSaverDefeater == 0)
  183441. {
  183442. screenSaverDefeater = new ScreenSaverDefeater();
  183443. }
  183444. }
  183445. bool Desktop::isScreenSaverEnabled() throw()
  183446. {
  183447. return screenSaverDefeater == 0;
  183448. }
  183449. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183450. {
  183451. if (enableOrDisable)
  183452. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183453. }
  183454. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183455. {
  183456. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183457. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183458. return TRUE;
  183459. }
  183460. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183461. {
  183462. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183463. // make sure the first in the list is the main monitor
  183464. for (int i = 1; i < monitorCoords.size(); ++i)
  183465. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183466. monitorCoords.swap (i, 0);
  183467. if (monitorCoords.size() == 0)
  183468. {
  183469. RECT r;
  183470. GetWindowRect (GetDesktopWindow(), &r);
  183471. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183472. }
  183473. if (clipToWorkArea)
  183474. {
  183475. // clip the main monitor to the active non-taskbar area
  183476. RECT r;
  183477. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183478. Rectangle<int>& screen = monitorCoords.getReference (0);
  183479. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183480. jmax (screen.getY(), (int) r.top));
  183481. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183482. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183483. }
  183484. }
  183485. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183486. {
  183487. Image* im = 0;
  183488. if (bitmap != 0)
  183489. {
  183490. BITMAP bm;
  183491. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183492. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183493. {
  183494. HDC tempDC = GetDC (0);
  183495. HDC dc = CreateCompatibleDC (tempDC);
  183496. ReleaseDC (0, tempDC);
  183497. SelectObject (dc, bitmap);
  183498. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183499. for (int y = bm.bmHeight; --y >= 0;)
  183500. {
  183501. for (int x = bm.bmWidth; --x >= 0;)
  183502. {
  183503. COLORREF col = GetPixel (dc, x, y);
  183504. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183505. (uint8) GetGValue (col),
  183506. (uint8) GetBValue (col)));
  183507. }
  183508. }
  183509. DeleteDC (dc);
  183510. }
  183511. }
  183512. return im;
  183513. }
  183514. static Image* createImageFromHICON (HICON icon) throw()
  183515. {
  183516. ICONINFO info;
  183517. if (GetIconInfo (icon, &info))
  183518. {
  183519. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183520. if (mask == 0)
  183521. return 0;
  183522. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183523. if (image == 0)
  183524. return mask;
  183525. for (int y = image->getHeight(); --y >= 0;)
  183526. {
  183527. for (int x = image->getWidth(); --x >= 0;)
  183528. {
  183529. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183530. if (brightness > 0.0f)
  183531. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183532. }
  183533. }
  183534. delete mask;
  183535. return image;
  183536. }
  183537. return 0;
  183538. }
  183539. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183540. {
  183541. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183542. ICONINFO info;
  183543. info.fIcon = isIcon;
  183544. info.xHotspot = hotspotX;
  183545. info.yHotspot = hotspotY;
  183546. info.hbmMask = mask;
  183547. HICON hi = 0;
  183548. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183549. {
  183550. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183551. Graphics g (bitmap);
  183552. g.drawImageAt (&image, 0, 0);
  183553. info.hbmColor = bitmap.hBitmap;
  183554. hi = CreateIconIndirect (&info);
  183555. }
  183556. else
  183557. {
  183558. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183559. HDC colDC = CreateCompatibleDC (GetDC (0));
  183560. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183561. SelectObject (colDC, colour);
  183562. SelectObject (alphaDC, mask);
  183563. for (int y = image.getHeight(); --y >= 0;)
  183564. {
  183565. for (int x = image.getWidth(); --x >= 0;)
  183566. {
  183567. const Colour c (image.getPixelAt (x, y));
  183568. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183569. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183570. }
  183571. }
  183572. DeleteDC (colDC);
  183573. DeleteDC (alphaDC);
  183574. info.hbmColor = colour;
  183575. hi = CreateIconIndirect (&info);
  183576. DeleteObject (colour);
  183577. }
  183578. DeleteObject (mask);
  183579. return hi;
  183580. }
  183581. Image* juce_createIconForFile (const File& file)
  183582. {
  183583. Image* image = 0;
  183584. WCHAR filename [1024];
  183585. file.getFullPathName().copyToUnicode (filename, 1023);
  183586. WORD iconNum = 0;
  183587. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183588. filename, &iconNum);
  183589. if (icon != 0)
  183590. {
  183591. image = createImageFromHICON (icon);
  183592. DestroyIcon (icon);
  183593. }
  183594. return image;
  183595. }
  183596. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183597. {
  183598. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183599. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183600. const Image* im = &image;
  183601. Image* newIm = 0;
  183602. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183603. {
  183604. im = newIm = image.createCopy (maxW, maxH);
  183605. hotspotX = (hotspotX * maxW) / image.getWidth();
  183606. hotspotY = (hotspotY * maxH) / image.getHeight();
  183607. }
  183608. void* cursorH = 0;
  183609. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183610. if (os == SystemStats::WinXP)
  183611. {
  183612. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183613. }
  183614. else
  183615. {
  183616. const int stride = (maxW + 7) >> 3;
  183617. HeapBlock <uint8> andPlane, xorPlane;
  183618. andPlane.calloc (stride * maxH);
  183619. xorPlane.calloc (stride * maxH);
  183620. int index = 0;
  183621. for (int y = 0; y < maxH; ++y)
  183622. {
  183623. for (int x = 0; x < maxW; ++x)
  183624. {
  183625. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183626. const Colour pixelColour (im->getPixelAt (x, y));
  183627. if (pixelColour.getAlpha() < 127)
  183628. andPlane [index + (x >> 3)] |= bit;
  183629. else if (pixelColour.getBrightness() >= 0.5f)
  183630. xorPlane [index + (x >> 3)] |= bit;
  183631. }
  183632. index += stride;
  183633. }
  183634. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183635. }
  183636. delete newIm;
  183637. return cursorH;
  183638. }
  183639. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183640. {
  183641. if (cursorHandle != 0 && ! isStandard)
  183642. DestroyCursor ((HCURSOR) cursorHandle);
  183643. }
  183644. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183645. {
  183646. LPCTSTR cursorName = IDC_ARROW;
  183647. switch (type)
  183648. {
  183649. case MouseCursor::NormalCursor:
  183650. cursorName = IDC_ARROW;
  183651. break;
  183652. case MouseCursor::NoCursor:
  183653. return 0;
  183654. case MouseCursor::DraggingHandCursor:
  183655. {
  183656. static void* dragHandCursor = 0;
  183657. if (dragHandCursor == 0)
  183658. {
  183659. static const unsigned char dragHandData[] =
  183660. { 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,
  183661. 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,
  183662. 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 };
  183663. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183664. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183665. }
  183666. return dragHandCursor;
  183667. }
  183668. case MouseCursor::WaitCursor:
  183669. cursorName = IDC_WAIT;
  183670. break;
  183671. case MouseCursor::IBeamCursor:
  183672. cursorName = IDC_IBEAM;
  183673. break;
  183674. case MouseCursor::PointingHandCursor:
  183675. cursorName = MAKEINTRESOURCE(32649);
  183676. break;
  183677. case MouseCursor::LeftRightResizeCursor:
  183678. case MouseCursor::LeftEdgeResizeCursor:
  183679. case MouseCursor::RightEdgeResizeCursor:
  183680. cursorName = IDC_SIZEWE;
  183681. break;
  183682. case MouseCursor::UpDownResizeCursor:
  183683. case MouseCursor::TopEdgeResizeCursor:
  183684. case MouseCursor::BottomEdgeResizeCursor:
  183685. cursorName = IDC_SIZENS;
  183686. break;
  183687. case MouseCursor::TopLeftCornerResizeCursor:
  183688. case MouseCursor::BottomRightCornerResizeCursor:
  183689. cursorName = IDC_SIZENWSE;
  183690. break;
  183691. case MouseCursor::TopRightCornerResizeCursor:
  183692. case MouseCursor::BottomLeftCornerResizeCursor:
  183693. cursorName = IDC_SIZENESW;
  183694. break;
  183695. case MouseCursor::UpDownLeftRightResizeCursor:
  183696. cursorName = IDC_SIZEALL;
  183697. break;
  183698. case MouseCursor::CrosshairCursor:
  183699. cursorName = IDC_CROSS;
  183700. break;
  183701. case MouseCursor::CopyingCursor:
  183702. // can't seem to find one of these in the win32 list..
  183703. break;
  183704. }
  183705. HCURSOR cursorH = LoadCursor (0, cursorName);
  183706. if (cursorH == 0)
  183707. cursorH = LoadCursor (0, IDC_ARROW);
  183708. return (void*) cursorH;
  183709. }
  183710. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183711. {
  183712. SetCursor ((HCURSOR) getHandle());
  183713. }
  183714. void MouseCursor::showInAllWindows() const throw()
  183715. {
  183716. showInWindow (0);
  183717. }
  183718. class JuceDropSource : public IDropSource
  183719. {
  183720. int refCount;
  183721. public:
  183722. JuceDropSource()
  183723. : refCount (1)
  183724. {
  183725. }
  183726. virtual ~JuceDropSource()
  183727. {
  183728. jassert (refCount == 0);
  183729. }
  183730. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183731. {
  183732. if (id == IID_IUnknown || id == IID_IDropSource)
  183733. {
  183734. AddRef();
  183735. *result = this;
  183736. return S_OK;
  183737. }
  183738. *result = 0;
  183739. return E_NOINTERFACE;
  183740. }
  183741. ULONG __stdcall AddRef() { return ++refCount; }
  183742. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183743. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183744. {
  183745. if (escapePressed)
  183746. return DRAGDROP_S_CANCEL;
  183747. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183748. return DRAGDROP_S_DROP;
  183749. return S_OK;
  183750. }
  183751. HRESULT __stdcall GiveFeedback (DWORD)
  183752. {
  183753. return DRAGDROP_S_USEDEFAULTCURSORS;
  183754. }
  183755. };
  183756. class JuceEnumFormatEtc : public IEnumFORMATETC
  183757. {
  183758. public:
  183759. JuceEnumFormatEtc (const FORMATETC* const format_)
  183760. : refCount (1),
  183761. format (format_),
  183762. index (0)
  183763. {
  183764. }
  183765. virtual ~JuceEnumFormatEtc()
  183766. {
  183767. jassert (refCount == 0);
  183768. }
  183769. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183770. {
  183771. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183772. {
  183773. AddRef();
  183774. *result = this;
  183775. return S_OK;
  183776. }
  183777. *result = 0;
  183778. return E_NOINTERFACE;
  183779. }
  183780. ULONG __stdcall AddRef() { return ++refCount; }
  183781. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183782. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183783. {
  183784. if (result == 0)
  183785. return E_POINTER;
  183786. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183787. newOne->index = index;
  183788. *result = newOne;
  183789. return S_OK;
  183790. }
  183791. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183792. {
  183793. if (pceltFetched != 0)
  183794. *pceltFetched = 0;
  183795. else if (celt != 1)
  183796. return S_FALSE;
  183797. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183798. {
  183799. copyFormatEtc (lpFormatEtc [0], *format);
  183800. ++index;
  183801. if (pceltFetched != 0)
  183802. *pceltFetched = 1;
  183803. return S_OK;
  183804. }
  183805. return S_FALSE;
  183806. }
  183807. HRESULT __stdcall Skip (ULONG celt)
  183808. {
  183809. if (index + (int) celt >= 1)
  183810. return S_FALSE;
  183811. index += celt;
  183812. return S_OK;
  183813. }
  183814. HRESULT __stdcall Reset()
  183815. {
  183816. index = 0;
  183817. return S_OK;
  183818. }
  183819. private:
  183820. int refCount;
  183821. const FORMATETC* const format;
  183822. int index;
  183823. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183824. {
  183825. dest = source;
  183826. if (source.ptd != 0)
  183827. {
  183828. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183829. *(dest.ptd) = *(source.ptd);
  183830. }
  183831. }
  183832. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183833. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183834. };
  183835. class JuceDataObject : public IDataObject
  183836. {
  183837. JuceDropSource* const dropSource;
  183838. const FORMATETC* const format;
  183839. const STGMEDIUM* const medium;
  183840. int refCount;
  183841. JuceDataObject (const JuceDataObject&);
  183842. JuceDataObject& operator= (const JuceDataObject&);
  183843. public:
  183844. JuceDataObject (JuceDropSource* const dropSource_,
  183845. const FORMATETC* const format_,
  183846. const STGMEDIUM* const medium_)
  183847. : dropSource (dropSource_),
  183848. format (format_),
  183849. medium (medium_),
  183850. refCount (1)
  183851. {
  183852. }
  183853. virtual ~JuceDataObject()
  183854. {
  183855. jassert (refCount == 0);
  183856. }
  183857. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183858. {
  183859. if (id == IID_IUnknown || id == IID_IDataObject)
  183860. {
  183861. AddRef();
  183862. *result = this;
  183863. return S_OK;
  183864. }
  183865. *result = 0;
  183866. return E_NOINTERFACE;
  183867. }
  183868. ULONG __stdcall AddRef() { return ++refCount; }
  183869. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183870. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183871. {
  183872. if ((pFormatEtc->tymed & format->tymed) != 0
  183873. && pFormatEtc->cfFormat == format->cfFormat
  183874. && pFormatEtc->dwAspect == format->dwAspect)
  183875. {
  183876. pMedium->tymed = format->tymed;
  183877. pMedium->pUnkForRelease = 0;
  183878. if (format->tymed == TYMED_HGLOBAL)
  183879. {
  183880. const SIZE_T len = GlobalSize (medium->hGlobal);
  183881. void* const src = GlobalLock (medium->hGlobal);
  183882. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183883. memcpy (dst, src, len);
  183884. GlobalUnlock (medium->hGlobal);
  183885. pMedium->hGlobal = dst;
  183886. return S_OK;
  183887. }
  183888. }
  183889. return DV_E_FORMATETC;
  183890. }
  183891. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183892. {
  183893. if (f == 0)
  183894. return E_INVALIDARG;
  183895. if (f->tymed == format->tymed
  183896. && f->cfFormat == format->cfFormat
  183897. && f->dwAspect == format->dwAspect)
  183898. return S_OK;
  183899. return DV_E_FORMATETC;
  183900. }
  183901. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183902. {
  183903. pFormatEtcOut->ptd = 0;
  183904. return E_NOTIMPL;
  183905. }
  183906. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183907. {
  183908. if (result == 0)
  183909. return E_POINTER;
  183910. if (direction == DATADIR_GET)
  183911. {
  183912. *result = new JuceEnumFormatEtc (format);
  183913. return S_OK;
  183914. }
  183915. *result = 0;
  183916. return E_NOTIMPL;
  183917. }
  183918. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183919. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183920. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183921. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183922. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183923. };
  183924. static HDROP createHDrop (const StringArray& fileNames) throw()
  183925. {
  183926. int totalChars = 0;
  183927. for (int i = fileNames.size(); --i >= 0;)
  183928. totalChars += fileNames[i].length() + 1;
  183929. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183930. sizeof (DROPFILES)
  183931. + sizeof (WCHAR) * (totalChars + 2));
  183932. if (hDrop != 0)
  183933. {
  183934. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183935. pDropFiles->pFiles = sizeof (DROPFILES);
  183936. pDropFiles->fWide = true;
  183937. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183938. for (int i = 0; i < fileNames.size(); ++i)
  183939. {
  183940. fileNames[i].copyToUnicode (fname, 2048);
  183941. fname += fileNames[i].length() + 1;
  183942. }
  183943. *fname = 0;
  183944. GlobalUnlock (hDrop);
  183945. }
  183946. return hDrop;
  183947. }
  183948. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183949. {
  183950. JuceDropSource* const source = new JuceDropSource();
  183951. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183952. DWORD effect;
  183953. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183954. data->Release();
  183955. source->Release();
  183956. return res == DRAGDROP_S_DROP;
  183957. }
  183958. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183959. {
  183960. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183961. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183962. medium.hGlobal = createHDrop (files);
  183963. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183964. : DROPEFFECT_COPY);
  183965. }
  183966. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183967. {
  183968. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183969. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183970. const int numChars = text.length();
  183971. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183972. char* d = (char*) GlobalLock (medium.hGlobal);
  183973. text.copyToUnicode ((WCHAR*) d, numChars + 1);
  183974. format.cfFormat = CF_UNICODETEXT;
  183975. GlobalUnlock (medium.hGlobal);
  183976. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183977. }
  183978. #endif
  183979. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183980. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183981. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183982. // compiled on its own).
  183983. #if JUCE_INCLUDED_FILE
  183984. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183985. NEWTEXTMETRICEXW*,
  183986. int type,
  183987. LPARAM lParam)
  183988. {
  183989. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183990. {
  183991. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183992. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  183993. }
  183994. return 1;
  183995. }
  183996. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183997. NEWTEXTMETRICEXW*,
  183998. int type,
  183999. LPARAM lParam)
  184000. {
  184001. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184002. {
  184003. LOGFONTW lf;
  184004. zerostruct (lf);
  184005. lf.lfWeight = FW_DONTCARE;
  184006. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184007. lf.lfQuality = DEFAULT_QUALITY;
  184008. lf.lfCharSet = DEFAULT_CHARSET;
  184009. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184010. lf.lfPitchAndFamily = FF_DONTCARE;
  184011. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184012. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  184013. HDC dc = CreateCompatibleDC (0);
  184014. EnumFontFamiliesEx (dc, &lf,
  184015. (FONTENUMPROCW) &wfontEnum2,
  184016. lParam, 0);
  184017. DeleteDC (dc);
  184018. }
  184019. return 1;
  184020. }
  184021. const StringArray Font::findAllTypefaceNames() throw()
  184022. {
  184023. StringArray results;
  184024. HDC dc = CreateCompatibleDC (0);
  184025. {
  184026. LOGFONTW lf;
  184027. zerostruct (lf);
  184028. lf.lfWeight = FW_DONTCARE;
  184029. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184030. lf.lfQuality = DEFAULT_QUALITY;
  184031. lf.lfCharSet = DEFAULT_CHARSET;
  184032. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184033. lf.lfPitchAndFamily = FF_DONTCARE;
  184034. lf.lfFaceName[0] = 0;
  184035. EnumFontFamiliesEx (dc, &lf,
  184036. (FONTENUMPROCW) &wfontEnum1,
  184037. (LPARAM) &results, 0);
  184038. }
  184039. DeleteDC (dc);
  184040. results.sort (true);
  184041. return results;
  184042. }
  184043. extern bool juce_IsRunningInWine();
  184044. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  184045. {
  184046. if (juce_IsRunningInWine())
  184047. {
  184048. // If we're running in Wine, then use fonts that might be available on Linux..
  184049. defaultSans = "Bitstream Vera Sans";
  184050. defaultSerif = "Bitstream Vera Serif";
  184051. defaultFixed = "Bitstream Vera Sans Mono";
  184052. }
  184053. else
  184054. {
  184055. defaultSans = "Verdana";
  184056. defaultSerif = "Times";
  184057. defaultFixed = "Lucida Console";
  184058. }
  184059. }
  184060. class FontDCHolder : private DeletedAtShutdown
  184061. {
  184062. public:
  184063. FontDCHolder() throw()
  184064. : dc (0), numKPs (0), size (0),
  184065. bold (false), italic (false)
  184066. {
  184067. }
  184068. ~FontDCHolder() throw()
  184069. {
  184070. if (dc != 0)
  184071. {
  184072. DeleteDC (dc);
  184073. DeleteObject (fontH);
  184074. }
  184075. clearSingletonInstance();
  184076. }
  184077. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  184078. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  184079. {
  184080. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  184081. {
  184082. fontName = fontName_;
  184083. bold = bold_;
  184084. italic = italic_;
  184085. size = size_;
  184086. if (dc != 0)
  184087. {
  184088. DeleteDC (dc);
  184089. DeleteObject (fontH);
  184090. kps.free();
  184091. }
  184092. fontH = 0;
  184093. dc = CreateCompatibleDC (0);
  184094. SetMapperFlags (dc, 0);
  184095. SetMapMode (dc, MM_TEXT);
  184096. LOGFONTW lfw;
  184097. zerostruct (lfw);
  184098. lfw.lfCharSet = DEFAULT_CHARSET;
  184099. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184100. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184101. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  184102. lfw.lfQuality = PROOF_QUALITY;
  184103. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  184104. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  184105. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  184106. lfw.lfHeight = size > 0 ? size : -256;
  184107. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  184108. if (standardSizedFont != 0)
  184109. {
  184110. if (SelectObject (dc, standardSizedFont) != 0)
  184111. {
  184112. fontH = standardSizedFont;
  184113. if (size == 0)
  184114. {
  184115. OUTLINETEXTMETRIC otm;
  184116. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  184117. {
  184118. lfw.lfHeight = -(int) otm.otmEMSquare;
  184119. fontH = CreateFontIndirect (&lfw);
  184120. SelectObject (dc, fontH);
  184121. DeleteObject (standardSizedFont);
  184122. }
  184123. }
  184124. }
  184125. else
  184126. {
  184127. jassertfalse
  184128. }
  184129. }
  184130. else
  184131. {
  184132. jassertfalse
  184133. }
  184134. }
  184135. return dc;
  184136. }
  184137. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  184138. {
  184139. if (kps == 0)
  184140. {
  184141. numKPs = GetKerningPairs (dc, 0, 0);
  184142. kps.calloc (numKPs);
  184143. GetKerningPairs (dc, numKPs, kps);
  184144. }
  184145. numKPs_ = numKPs;
  184146. return kps;
  184147. }
  184148. private:
  184149. HFONT fontH;
  184150. HDC dc;
  184151. String fontName;
  184152. HeapBlock <KERNINGPAIR> kps;
  184153. int numKPs, size;
  184154. bool bold, italic;
  184155. FontDCHolder (const FontDCHolder&);
  184156. FontDCHolder& operator= (const FontDCHolder&);
  184157. };
  184158. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  184159. class WindowsTypeface : public CustomTypeface
  184160. {
  184161. public:
  184162. WindowsTypeface (const Font& font)
  184163. {
  184164. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  184165. font.isBold(), font.isItalic(), 0);
  184166. TEXTMETRIC tm;
  184167. tm.tmAscent = tm.tmHeight = 1;
  184168. tm.tmDefaultChar = 0;
  184169. GetTextMetrics (dc, &tm);
  184170. setCharacteristics (font.getTypefaceName(),
  184171. tm.tmAscent / (float) tm.tmHeight,
  184172. font.isBold(), font.isItalic(),
  184173. tm.tmDefaultChar);
  184174. }
  184175. bool loadGlyphIfPossible (const juce_wchar character)
  184176. {
  184177. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  184178. GLYPHMETRICS gm;
  184179. {
  184180. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  184181. WORD index = 0;
  184182. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  184183. && index == 0xffff)
  184184. {
  184185. return false;
  184186. }
  184187. }
  184188. Path glyphPath;
  184189. TEXTMETRIC tm;
  184190. if (! GetTextMetrics (dc, &tm))
  184191. {
  184192. addGlyph (character, glyphPath, 0);
  184193. return true;
  184194. }
  184195. const float height = (float) tm.tmHeight;
  184196. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  184197. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  184198. &gm, 0, 0, &identityMatrix);
  184199. if (bufSize > 0)
  184200. {
  184201. HeapBlock <char> data (bufSize);
  184202. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  184203. bufSize, data, &identityMatrix);
  184204. const TTPOLYGONHEADER* pheader = (TTPOLYGONHEADER*) data;
  184205. const float scaleX = 1.0f / height;
  184206. const float scaleY = -1.0f / height;
  184207. while ((char*) pheader < data + bufSize)
  184208. {
  184209. #define remapX(v) (scaleX * (v).x.value)
  184210. #define remapY(v) (scaleY * (v).y.value)
  184211. float x = remapX (pheader->pfxStart);
  184212. float y = remapY (pheader->pfxStart);
  184213. glyphPath.startNewSubPath (x, y);
  184214. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  184215. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  184216. while ((const char*) curve < curveEnd)
  184217. {
  184218. if (curve->wType == TT_PRIM_LINE)
  184219. {
  184220. for (int i = 0; i < curve->cpfx; ++i)
  184221. {
  184222. x = remapX (curve->apfx [i]);
  184223. y = remapY (curve->apfx [i]);
  184224. glyphPath.lineTo (x, y);
  184225. }
  184226. }
  184227. else if (curve->wType == TT_PRIM_QSPLINE)
  184228. {
  184229. for (int i = 0; i < curve->cpfx - 1; ++i)
  184230. {
  184231. const float x2 = remapX (curve->apfx [i]);
  184232. const float y2 = remapY (curve->apfx [i]);
  184233. float x3, y3;
  184234. if (i < curve->cpfx - 2)
  184235. {
  184236. x3 = 0.5f * (x2 + remapX (curve->apfx [i + 1]));
  184237. y3 = 0.5f * (y2 + remapY (curve->apfx [i + 1]));
  184238. }
  184239. else
  184240. {
  184241. x3 = remapX (curve->apfx [i + 1]);
  184242. y3 = remapY (curve->apfx [i + 1]);
  184243. }
  184244. glyphPath.quadraticTo (x2, y2, x3, y3);
  184245. x = x3;
  184246. y = y3;
  184247. }
  184248. }
  184249. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  184250. }
  184251. pheader = (const TTPOLYGONHEADER*) curve;
  184252. glyphPath.closeSubPath();
  184253. }
  184254. }
  184255. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  184256. int numKPs;
  184257. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  184258. for (int i = 0; i < numKPs; ++i)
  184259. {
  184260. if (kps[i].wFirst == character)
  184261. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  184262. kps[i].iKernAmount / height);
  184263. }
  184264. return true;
  184265. }
  184266. };
  184267. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  184268. {
  184269. return new WindowsTypeface (font);
  184270. }
  184271. #endif
  184272. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  184273. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  184274. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184275. // compiled on its own).
  184276. #if JUCE_INCLUDED_FILE
  184277. static const void* defaultDirPath = 0;
  184278. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  184279. static Component* currentExtraFileWin = 0;
  184280. static bool areThereAnyAlwaysOnTopWindows()
  184281. {
  184282. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  184283. {
  184284. Component* c = Desktop::getInstance().getComponent (i);
  184285. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  184286. return true;
  184287. }
  184288. return false;
  184289. }
  184290. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  184291. {
  184292. if (msg == BFFM_INITIALIZED)
  184293. {
  184294. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  184295. }
  184296. else if (msg == BFFM_VALIDATEFAILEDW)
  184297. {
  184298. returnedString = (LPCWSTR) lParam;
  184299. }
  184300. else if (msg == BFFM_VALIDATEFAILEDA)
  184301. {
  184302. returnedString = (const char*) lParam;
  184303. }
  184304. return 0;
  184305. }
  184306. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184307. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184308. {
  184309. if (currentExtraFileWin != 0)
  184310. {
  184311. if (uiMsg == WM_INITDIALOG)
  184312. {
  184313. HWND dialogH = GetParent (hdlg);
  184314. jassert (dialogH != 0);
  184315. if (dialogH == 0)
  184316. dialogH = hdlg;
  184317. RECT r, cr;
  184318. GetWindowRect (dialogH, &r);
  184319. GetClientRect (dialogH, &cr);
  184320. SetWindowPos (dialogH, 0,
  184321. r.left, r.top,
  184322. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184323. jmax (150, (int) (r.bottom - r.top)),
  184324. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184325. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184326. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184327. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184328. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184329. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184330. }
  184331. else if (uiMsg == WM_NOTIFY)
  184332. {
  184333. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184334. if (ofn->hdr.code == CDN_SELCHANGE)
  184335. {
  184336. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184337. if (comp != 0)
  184338. {
  184339. TCHAR path [MAX_PATH * 2];
  184340. path[0] = 0;
  184341. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184342. const String fn ((const WCHAR*) path);
  184343. comp->selectedFileChanged (File (fn));
  184344. }
  184345. }
  184346. }
  184347. }
  184348. return 0;
  184349. }
  184350. class FPComponentHolder : public Component
  184351. {
  184352. public:
  184353. FPComponentHolder()
  184354. {
  184355. setVisible (true);
  184356. setOpaque (true);
  184357. }
  184358. ~FPComponentHolder()
  184359. {
  184360. }
  184361. void paint (Graphics& g)
  184362. {
  184363. g.fillAll (Colours::lightgrey);
  184364. }
  184365. private:
  184366. FPComponentHolder (const FPComponentHolder&);
  184367. FPComponentHolder& operator= (const FPComponentHolder&);
  184368. };
  184369. void FileChooser::showPlatformDialog (Array<File>& results,
  184370. const String& title,
  184371. const File& currentFileOrDirectory,
  184372. const String& filter,
  184373. bool selectsDirectory,
  184374. bool /*selectsFiles*/,
  184375. bool isSaveDialogue,
  184376. bool warnAboutOverwritingExistingFiles,
  184377. bool selectMultipleFiles,
  184378. FilePreviewComponent* extraInfoComponent)
  184379. {
  184380. const int numCharsAvailable = 32768;
  184381. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184382. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184383. int fnameIdx = 0;
  184384. JUCE_TRY
  184385. {
  184386. // use a modal window as the parent for this dialog box
  184387. // to block input from other app windows
  184388. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184389. Component w (String::empty);
  184390. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184391. mainMon.getY() + mainMon.getHeight() / 4,
  184392. 0, 0);
  184393. w.setOpaque (true);
  184394. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184395. w.addToDesktop (0);
  184396. if (extraInfoComponent == 0)
  184397. w.enterModalState();
  184398. String initialDir;
  184399. if (currentFileOrDirectory.isDirectory())
  184400. {
  184401. initialDir = currentFileOrDirectory.getFullPathName();
  184402. }
  184403. else
  184404. {
  184405. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  184406. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184407. }
  184408. if (currentExtraFileWin->isValidComponent())
  184409. {
  184410. jassertfalse
  184411. return;
  184412. }
  184413. if (selectsDirectory)
  184414. {
  184415. LPITEMIDLIST list = 0;
  184416. filenameSpace.fillWith (0);
  184417. {
  184418. BROWSEINFO bi;
  184419. zerostruct (bi);
  184420. bi.hwndOwner = (HWND) w.getWindowHandle();
  184421. bi.pszDisplayName = fname;
  184422. bi.lpszTitle = title;
  184423. bi.lpfn = browseCallbackProc;
  184424. #ifdef BIF_USENEWUI
  184425. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184426. #else
  184427. bi.ulFlags = 0x50;
  184428. #endif
  184429. defaultDirPath = (const WCHAR*) initialDir;
  184430. list = SHBrowseForFolder (&bi);
  184431. if (! SHGetPathFromIDListW (list, fname))
  184432. {
  184433. fname[0] = 0;
  184434. returnedString = String::empty;
  184435. }
  184436. }
  184437. LPMALLOC al;
  184438. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184439. al->Free (list);
  184440. defaultDirPath = 0;
  184441. if (returnedString.isNotEmpty())
  184442. {
  184443. const String stringFName (fname);
  184444. results.add (File (stringFName).getSiblingFile (returnedString));
  184445. returnedString = String::empty;
  184446. return;
  184447. }
  184448. }
  184449. else
  184450. {
  184451. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184452. if (warnAboutOverwritingExistingFiles)
  184453. flags |= OFN_OVERWRITEPROMPT;
  184454. if (selectMultipleFiles)
  184455. flags |= OFN_ALLOWMULTISELECT;
  184456. if (extraInfoComponent != 0)
  184457. {
  184458. flags |= OFN_ENABLEHOOK;
  184459. currentExtraFileWin = new FPComponentHolder();
  184460. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184461. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184462. extraInfoComponent->getHeight());
  184463. currentExtraFileWin->addToDesktop (0);
  184464. currentExtraFileWin->enterModalState();
  184465. }
  184466. {
  184467. WCHAR filters [1024];
  184468. zeromem (filters, sizeof (filters));
  184469. filter.copyToUnicode (filters, 1024);
  184470. filter.copyToUnicode (filters + filter.length() + 1,
  184471. 1022 - filter.length());
  184472. OPENFILENAMEW of;
  184473. zerostruct (of);
  184474. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184475. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184476. #else
  184477. of.lStructSize = sizeof (of);
  184478. #endif
  184479. of.hwndOwner = (HWND) w.getWindowHandle();
  184480. of.lpstrFilter = filters;
  184481. of.nFilterIndex = 1;
  184482. of.lpstrFile = fname;
  184483. of.nMaxFile = numCharsAvailable;
  184484. of.lpstrInitialDir = initialDir;
  184485. of.lpstrTitle = title;
  184486. of.Flags = flags;
  184487. if (extraInfoComponent != 0)
  184488. of.lpfnHook = &openCallback;
  184489. if (isSaveDialogue)
  184490. {
  184491. if (! GetSaveFileName (&of))
  184492. fname[0] = 0;
  184493. else
  184494. fnameIdx = of.nFileOffset;
  184495. }
  184496. else
  184497. {
  184498. if (! GetOpenFileName (&of))
  184499. fname[0] = 0;
  184500. else
  184501. fnameIdx = of.nFileOffset;
  184502. }
  184503. }
  184504. }
  184505. }
  184506. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184507. catch (...)
  184508. {
  184509. fname[0] = 0;
  184510. }
  184511. #endif
  184512. deleteAndZero (currentExtraFileWin);
  184513. const WCHAR* const files = fname;
  184514. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184515. {
  184516. const WCHAR* filename = files + fnameIdx;
  184517. while (*filename != 0)
  184518. {
  184519. const String filepath (String (files) + T("\\") + String (filename));
  184520. results.add (File (filepath));
  184521. filename += CharacterFunctions::length (filename) + 1;
  184522. }
  184523. }
  184524. else if (files[0] != 0)
  184525. {
  184526. results.add (File (files));
  184527. }
  184528. }
  184529. #endif
  184530. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184531. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184532. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184533. // compiled on its own).
  184534. #if JUCE_INCLUDED_FILE
  184535. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184536. {
  184537. if (OpenClipboard (0) != 0)
  184538. {
  184539. if (EmptyClipboard() != 0)
  184540. {
  184541. const int len = text.length();
  184542. if (len > 0)
  184543. {
  184544. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184545. (len + 1) * sizeof (wchar_t));
  184546. if (bufH != 0)
  184547. {
  184548. WCHAR* const data = (WCHAR*) GlobalLock (bufH);
  184549. text.copyToUnicode (data, len);
  184550. GlobalUnlock (bufH);
  184551. SetClipboardData (CF_UNICODETEXT, bufH);
  184552. }
  184553. }
  184554. }
  184555. CloseClipboard();
  184556. }
  184557. }
  184558. const String SystemClipboard::getTextFromClipboard() throw()
  184559. {
  184560. String result;
  184561. if (OpenClipboard (0) != 0)
  184562. {
  184563. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184564. if (bufH != 0)
  184565. {
  184566. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184567. if (data != 0)
  184568. {
  184569. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184570. GlobalUnlock (bufH);
  184571. }
  184572. }
  184573. CloseClipboard();
  184574. }
  184575. return result;
  184576. }
  184577. #endif
  184578. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184579. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184580. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184581. // compiled on its own).
  184582. #if JUCE_INCLUDED_FILE
  184583. namespace ActiveXHelpers
  184584. {
  184585. class JuceIStorage : public IStorage
  184586. {
  184587. int refCount;
  184588. public:
  184589. JuceIStorage() : refCount (1) {}
  184590. virtual ~JuceIStorage()
  184591. {
  184592. jassert (refCount == 0);
  184593. }
  184594. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184595. {
  184596. if (id == IID_IUnknown || id == IID_IStorage)
  184597. {
  184598. AddRef();
  184599. *result = this;
  184600. return S_OK;
  184601. }
  184602. *result = 0;
  184603. return E_NOINTERFACE;
  184604. }
  184605. ULONG __stdcall AddRef() { return ++refCount; }
  184606. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184607. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184608. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184609. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184610. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184611. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184612. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184613. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184614. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184615. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184616. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184617. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184618. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184619. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184620. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184621. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184622. juce_UseDebuggingNewOperator
  184623. };
  184624. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184625. {
  184626. int refCount;
  184627. HWND window;
  184628. public:
  184629. JuceOleInPlaceFrame (HWND window_)
  184630. : refCount (1),
  184631. window (window_)
  184632. {
  184633. }
  184634. virtual ~JuceOleInPlaceFrame()
  184635. {
  184636. jassert (refCount == 0);
  184637. }
  184638. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184639. {
  184640. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184641. {
  184642. AddRef();
  184643. *result = this;
  184644. return S_OK;
  184645. }
  184646. *result = 0;
  184647. return E_NOINTERFACE;
  184648. }
  184649. ULONG __stdcall AddRef() { return ++refCount; }
  184650. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184651. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184652. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184653. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184654. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184655. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184656. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184657. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184658. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184659. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184660. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184661. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184662. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184663. juce_UseDebuggingNewOperator
  184664. };
  184665. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184666. {
  184667. int refCount;
  184668. HWND window;
  184669. JuceOleInPlaceFrame* frame;
  184670. public:
  184671. JuceIOleInPlaceSite (HWND window_)
  184672. : refCount (1),
  184673. window (window_)
  184674. {
  184675. frame = new JuceOleInPlaceFrame (window);
  184676. }
  184677. virtual ~JuceIOleInPlaceSite()
  184678. {
  184679. jassert (refCount == 0);
  184680. frame->Release();
  184681. }
  184682. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184683. {
  184684. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184685. {
  184686. AddRef();
  184687. *result = this;
  184688. return S_OK;
  184689. }
  184690. *result = 0;
  184691. return E_NOINTERFACE;
  184692. }
  184693. ULONG __stdcall AddRef() { return ++refCount; }
  184694. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184695. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184696. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184697. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184698. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184699. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184700. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184701. {
  184702. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184703. *lplpFrame = frame;
  184704. *lplpDoc = 0;
  184705. lpFrameInfo->fMDIApp = FALSE;
  184706. lpFrameInfo->hwndFrame = window;
  184707. lpFrameInfo->haccel = 0;
  184708. lpFrameInfo->cAccelEntries = 0;
  184709. return S_OK;
  184710. }
  184711. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184712. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184713. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184714. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184715. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184716. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184717. juce_UseDebuggingNewOperator
  184718. };
  184719. class JuceIOleClientSite : public IOleClientSite
  184720. {
  184721. int refCount;
  184722. JuceIOleInPlaceSite* inplaceSite;
  184723. public:
  184724. JuceIOleClientSite (HWND window)
  184725. : refCount (1)
  184726. {
  184727. inplaceSite = new JuceIOleInPlaceSite (window);
  184728. }
  184729. virtual ~JuceIOleClientSite()
  184730. {
  184731. jassert (refCount == 0);
  184732. inplaceSite->Release();
  184733. }
  184734. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184735. {
  184736. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184737. {
  184738. AddRef();
  184739. *result = this;
  184740. return S_OK;
  184741. }
  184742. else if (id == IID_IOleInPlaceSite)
  184743. {
  184744. inplaceSite->AddRef();
  184745. *result = inplaceSite;
  184746. return S_OK;
  184747. }
  184748. *result = 0;
  184749. return E_NOINTERFACE;
  184750. }
  184751. ULONG __stdcall AddRef() { return ++refCount; }
  184752. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184753. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184754. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184755. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184756. HRESULT __stdcall ShowObject() { return S_OK; }
  184757. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184758. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184759. juce_UseDebuggingNewOperator
  184760. };
  184761. static VoidArray activeXComps;
  184762. static HWND getHWND (const ActiveXControlComponent* const component)
  184763. {
  184764. HWND hwnd = 0;
  184765. const IID iid = IID_IOleWindow;
  184766. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184767. if (window != 0)
  184768. {
  184769. window->GetWindow (&hwnd);
  184770. window->Release();
  184771. }
  184772. return hwnd;
  184773. }
  184774. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184775. {
  184776. RECT activeXRect, peerRect;
  184777. GetWindowRect (hwnd, &activeXRect);
  184778. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184779. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184780. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184781. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184782. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184783. switch (message)
  184784. {
  184785. case WM_MOUSEMOVE:
  184786. case WM_LBUTTONDOWN:
  184787. case WM_MBUTTONDOWN:
  184788. case WM_RBUTTONDOWN:
  184789. case WM_LBUTTONUP:
  184790. case WM_MBUTTONUP:
  184791. case WM_RBUTTONUP:
  184792. peer->handleMouseEvent (mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184793. break;
  184794. default:
  184795. break;
  184796. }
  184797. }
  184798. }
  184799. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184800. {
  184801. ActiveXControlComponent* const owner;
  184802. bool wasShowing;
  184803. public:
  184804. HWND controlHWND;
  184805. IStorage* storage;
  184806. IOleClientSite* clientSite;
  184807. IOleObject* control;
  184808. ActiveXControlData (HWND hwnd,
  184809. ActiveXControlComponent* const owner_)
  184810. : ComponentMovementWatcher (owner_),
  184811. owner (owner_),
  184812. wasShowing (owner_ != 0 && owner_->isShowing()),
  184813. controlHWND (0),
  184814. storage (new ActiveXHelpers::JuceIStorage()),
  184815. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184816. control (0)
  184817. {
  184818. }
  184819. ~ActiveXControlData()
  184820. {
  184821. if (control != 0)
  184822. {
  184823. control->Close (OLECLOSE_NOSAVE);
  184824. control->Release();
  184825. }
  184826. clientSite->Release();
  184827. storage->Release();
  184828. }
  184829. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184830. {
  184831. Component* const topComp = owner->getTopLevelComponent();
  184832. if (topComp->getPeer() != 0)
  184833. {
  184834. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184835. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184836. }
  184837. }
  184838. void componentPeerChanged()
  184839. {
  184840. const bool isShowingNow = owner->isShowing();
  184841. if (wasShowing != isShowingNow)
  184842. {
  184843. wasShowing = isShowingNow;
  184844. owner->setControlVisible (isShowingNow);
  184845. }
  184846. componentMovedOrResized (true, true);
  184847. }
  184848. void componentVisibilityChanged (Component&)
  184849. {
  184850. componentPeerChanged();
  184851. }
  184852. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184853. {
  184854. return ((ActiveXControlData*) ax->control) != 0
  184855. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184856. }
  184857. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184858. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184859. {
  184860. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184861. {
  184862. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184863. if (doesWindowMatch (ax, hwnd))
  184864. {
  184865. switch (message)
  184866. {
  184867. case WM_MOUSEMOVE:
  184868. case WM_LBUTTONDOWN:
  184869. case WM_MBUTTONDOWN:
  184870. case WM_RBUTTONDOWN:
  184871. case WM_LBUTTONUP:
  184872. case WM_MBUTTONUP:
  184873. case WM_RBUTTONUP:
  184874. case WM_LBUTTONDBLCLK:
  184875. case WM_MBUTTONDBLCLK:
  184876. case WM_RBUTTONDBLCLK:
  184877. if (ax->isShowing())
  184878. {
  184879. ComponentPeer* const peer = ax->getPeer();
  184880. if (peer != 0)
  184881. {
  184882. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184883. if (! ax->areMouseEventsAllowed())
  184884. return 0;
  184885. }
  184886. }
  184887. break;
  184888. default:
  184889. break;
  184890. }
  184891. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184892. }
  184893. }
  184894. return DefWindowProc (hwnd, message, wParam, lParam);
  184895. }
  184896. };
  184897. ActiveXControlComponent::ActiveXControlComponent()
  184898. : originalWndProc (0),
  184899. control (0),
  184900. mouseEventsAllowed (true)
  184901. {
  184902. ActiveXHelpers::activeXComps.add (this);
  184903. }
  184904. ActiveXControlComponent::~ActiveXControlComponent()
  184905. {
  184906. deleteControl();
  184907. ActiveXHelpers::activeXComps.removeValue (this);
  184908. }
  184909. void ActiveXControlComponent::paint (Graphics& g)
  184910. {
  184911. if (control == 0)
  184912. g.fillAll (Colours::lightgrey);
  184913. }
  184914. bool ActiveXControlComponent::createControl (const void* controlIID)
  184915. {
  184916. deleteControl();
  184917. ComponentPeer* const peer = getPeer();
  184918. // the component must have already been added to a real window when you call this!
  184919. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184920. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184921. {
  184922. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184923. HWND hwnd = (HWND) peer->getNativeHandle();
  184924. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184925. HRESULT hr;
  184926. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184927. info->clientSite, info->storage,
  184928. (void**) &(info->control))) == S_OK)
  184929. {
  184930. info->control->SetHostNames (L"Juce", 0);
  184931. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184932. {
  184933. RECT rect;
  184934. rect.left = pos.getX();
  184935. rect.top = pos.getY();
  184936. rect.right = pos.getX() + getWidth();
  184937. rect.bottom = pos.getY() + getHeight();
  184938. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184939. {
  184940. control = info.release();
  184941. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184942. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184943. if (((ActiveXControlData*) control)->controlHWND != 0)
  184944. {
  184945. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184946. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184947. }
  184948. return true;
  184949. }
  184950. }
  184951. }
  184952. }
  184953. return false;
  184954. }
  184955. void ActiveXControlComponent::deleteControl()
  184956. {
  184957. ActiveXControlData* const info = (ActiveXControlData*) control;
  184958. if (info != 0)
  184959. {
  184960. delete info;
  184961. control = 0;
  184962. originalWndProc = 0;
  184963. }
  184964. }
  184965. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184966. {
  184967. ActiveXControlData* const info = (ActiveXControlData*) control;
  184968. void* result = 0;
  184969. if (info != 0 && info->control != 0
  184970. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184971. return result;
  184972. return 0;
  184973. }
  184974. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184975. {
  184976. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184977. if (hwnd != 0)
  184978. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184979. }
  184980. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184981. {
  184982. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184983. if (hwnd != 0)
  184984. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184985. }
  184986. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184987. {
  184988. mouseEventsAllowed = eventsCanReachControl;
  184989. }
  184990. #endif
  184991. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184992. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184993. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184994. // compiled on its own).
  184995. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184996. using namespace QTOLibrary;
  184997. using namespace QTOControlLib;
  184998. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184999. static bool isQTAvailable = false;
  185000. struct QTMovieCompInternal
  185001. {
  185002. QTMovieCompInternal()
  185003. : dataHandle (0)
  185004. {
  185005. }
  185006. ~QTMovieCompInternal()
  185007. {
  185008. clearHandle();
  185009. }
  185010. IQTControlPtr qtControlInternal;
  185011. IQTMoviePtr qtMovieInternal;
  185012. Handle dataHandle;
  185013. void clearHandle()
  185014. {
  185015. if (dataHandle != 0)
  185016. {
  185017. DisposeHandle (dataHandle);
  185018. dataHandle = 0;
  185019. }
  185020. }
  185021. };
  185022. #define qtControl (((QTMovieCompInternal*) internal)->qtControlInternal)
  185023. #define qtMovie (((QTMovieCompInternal*) internal)->qtMovieInternal)
  185024. QuickTimeMovieComponent::QuickTimeMovieComponent()
  185025. : movieLoaded (false),
  185026. controllerVisible (true)
  185027. {
  185028. internal = new QTMovieCompInternal();
  185029. setMouseEventsAllowed (false);
  185030. }
  185031. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  185032. {
  185033. closeMovie();
  185034. qtControl = 0;
  185035. deleteControl();
  185036. delete internal;
  185037. internal = 0;
  185038. }
  185039. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  185040. {
  185041. if (! isQTAvailable)
  185042. {
  185043. isQTAvailable = (InitializeQTML (0) == noErr)
  185044. && (EnterMovies() == noErr);
  185045. }
  185046. return isQTAvailable;
  185047. }
  185048. void QuickTimeMovieComponent::createControlIfNeeded()
  185049. {
  185050. if (isShowing() && ! isControlCreated())
  185051. {
  185052. const IID qtIID = __uuidof (QTControl);
  185053. if (createControl (&qtIID))
  185054. {
  185055. const IID qtInterfaceIID = __uuidof (IQTControl);
  185056. qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  185057. if (qtControl != 0)
  185058. {
  185059. qtControl->Release(); // it has one ref too many at this point
  185060. qtControl->QuickTimeInitialize();
  185061. qtControl->PutSizing (qtMovieFitsControl);
  185062. if (movieFile != File::nonexistent)
  185063. loadMovie (movieFile, controllerVisible);
  185064. }
  185065. }
  185066. }
  185067. }
  185068. bool QuickTimeMovieComponent::isControlCreated() const
  185069. {
  185070. return isControlOpen();
  185071. }
  185072. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  185073. const bool isControllerVisible)
  185074. {
  185075. movieFile = File::nonexistent;
  185076. movieLoaded = false;
  185077. qtMovie = 0;
  185078. controllerVisible = isControllerVisible;
  185079. createControlIfNeeded();
  185080. if (isControlCreated())
  185081. {
  185082. if (qtControl != 0)
  185083. {
  185084. qtControl->Put_MovieHandle (0);
  185085. ((QTMovieCompInternal*) internal)->clearHandle();
  185086. Movie movie;
  185087. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, ((QTMovieCompInternal*) internal)->dataHandle))
  185088. {
  185089. qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  185090. qtMovie = qtControl->GetMovie();
  185091. if (qtMovie != 0)
  185092. qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  185093. : qtMovieControllerTypeNone);
  185094. }
  185095. if (movie == 0)
  185096. ((QTMovieCompInternal*) internal)->clearHandle();
  185097. }
  185098. movieLoaded = (qtMovie != 0);
  185099. }
  185100. else
  185101. {
  185102. // You're trying to open a movie when the control hasn't yet been created, probably because
  185103. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  185104. jassertfalse
  185105. }
  185106. delete movieStream;
  185107. return movieLoaded;
  185108. }
  185109. void QuickTimeMovieComponent::closeMovie()
  185110. {
  185111. stop();
  185112. movieFile = File::nonexistent;
  185113. movieLoaded = false;
  185114. qtMovie = 0;
  185115. if (qtControl != 0)
  185116. qtControl->Put_MovieHandle (0);
  185117. ((QTMovieCompInternal*) internal)->clearHandle();
  185118. }
  185119. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  185120. {
  185121. return movieFile;
  185122. }
  185123. bool QuickTimeMovieComponent::isMovieOpen() const
  185124. {
  185125. return movieLoaded;
  185126. }
  185127. double QuickTimeMovieComponent::getMovieDuration() const
  185128. {
  185129. if (qtMovie != 0)
  185130. return qtMovie->GetDuration() / (double) qtMovie->GetTimeScale();
  185131. return 0.0;
  185132. }
  185133. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  185134. {
  185135. if (qtMovie != 0)
  185136. {
  185137. struct QTRECT r = qtMovie->GetNaturalRect();
  185138. width = r.right - r.left;
  185139. height = r.bottom - r.top;
  185140. }
  185141. else
  185142. {
  185143. width = height = 0;
  185144. }
  185145. }
  185146. void QuickTimeMovieComponent::play()
  185147. {
  185148. if (qtMovie != 0)
  185149. qtMovie->Play();
  185150. }
  185151. void QuickTimeMovieComponent::stop()
  185152. {
  185153. if (qtMovie != 0)
  185154. qtMovie->Stop();
  185155. }
  185156. bool QuickTimeMovieComponent::isPlaying() const
  185157. {
  185158. return qtMovie != 0 && qtMovie->GetRate() != 0.0f;
  185159. }
  185160. void QuickTimeMovieComponent::setPosition (const double seconds)
  185161. {
  185162. if (qtMovie != 0)
  185163. qtMovie->PutTime ((long) (seconds * qtMovie->GetTimeScale()));
  185164. }
  185165. double QuickTimeMovieComponent::getPosition() const
  185166. {
  185167. if (qtMovie != 0)
  185168. return qtMovie->GetTime() / (double) qtMovie->GetTimeScale();
  185169. return 0.0;
  185170. }
  185171. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  185172. {
  185173. if (qtMovie != 0)
  185174. qtMovie->PutRate (newSpeed);
  185175. }
  185176. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  185177. {
  185178. if (qtMovie != 0)
  185179. {
  185180. qtMovie->PutAudioVolume (newVolume);
  185181. qtMovie->PutAudioMute (newVolume <= 0);
  185182. }
  185183. }
  185184. float QuickTimeMovieComponent::getMovieVolume() const
  185185. {
  185186. if (qtMovie != 0)
  185187. return qtMovie->GetAudioVolume();
  185188. return 0.0f;
  185189. }
  185190. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  185191. {
  185192. if (qtMovie != 0)
  185193. qtMovie->PutLoop (shouldLoop);
  185194. }
  185195. bool QuickTimeMovieComponent::isLooping() const
  185196. {
  185197. return qtMovie != 0 && qtMovie->GetLoop();
  185198. }
  185199. bool QuickTimeMovieComponent::isControllerVisible() const
  185200. {
  185201. return controllerVisible;
  185202. }
  185203. void QuickTimeMovieComponent::parentHierarchyChanged()
  185204. {
  185205. createControlIfNeeded();
  185206. QTCompBaseClass::parentHierarchyChanged();
  185207. }
  185208. void QuickTimeMovieComponent::visibilityChanged()
  185209. {
  185210. createControlIfNeeded();
  185211. QTCompBaseClass::visibilityChanged();
  185212. }
  185213. void QuickTimeMovieComponent::paint (Graphics& g)
  185214. {
  185215. if (! isControlCreated())
  185216. g.fillAll (Colours::black);
  185217. }
  185218. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  185219. {
  185220. Handle dataRef = 0;
  185221. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  185222. if (err == noErr)
  185223. {
  185224. Str255 suffix;
  185225. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  185226. StringPtr name = suffix;
  185227. err = PtrAndHand (name, dataRef, name[0] + 1);
  185228. if (err == noErr)
  185229. {
  185230. long atoms[3];
  185231. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  185232. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  185233. atoms[2] = EndianU32_NtoB (MovieFileType);
  185234. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  185235. if (err == noErr)
  185236. return dataRef;
  185237. }
  185238. DisposeHandle (dataRef);
  185239. }
  185240. return 0;
  185241. }
  185242. static CFStringRef juceStringToCFString (const String& s)
  185243. {
  185244. const int len = s.length();
  185245. const juce_wchar* const t = (const juce_wchar*) s;
  185246. HeapBlock <UniChar> temp (len + 2);
  185247. for (int i = 0; i <= len; ++i)
  185248. temp[i] = t[i];
  185249. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  185250. }
  185251. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  185252. {
  185253. Boolean trueBool = true;
  185254. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185255. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  185256. props[prop].propValueSize = sizeof (trueBool);
  185257. props[prop].propValueAddress = &trueBool;
  185258. ++prop;
  185259. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185260. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  185261. props[prop].propValueSize = sizeof (trueBool);
  185262. props[prop].propValueAddress = &trueBool;
  185263. ++prop;
  185264. Boolean isActive = true;
  185265. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  185266. props[prop].propID = kQTNewMoviePropertyID_Active;
  185267. props[prop].propValueSize = sizeof (isActive);
  185268. props[prop].propValueAddress = &isActive;
  185269. ++prop;
  185270. MacSetPort (0);
  185271. jassert (prop <= 5);
  185272. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  185273. return err == noErr;
  185274. }
  185275. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  185276. {
  185277. if (input == 0)
  185278. return false;
  185279. dataHandle = 0;
  185280. bool ok = false;
  185281. QTNewMoviePropertyElement props[5];
  185282. zeromem (props, sizeof (props));
  185283. int prop = 0;
  185284. DataReferenceRecord dr;
  185285. props[prop].propClass = kQTPropertyClass_DataLocation;
  185286. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  185287. props[prop].propValueSize = sizeof (dr);
  185288. props[prop].propValueAddress = (void*) &dr;
  185289. ++prop;
  185290. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  185291. if (fin != 0)
  185292. {
  185293. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  185294. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  185295. &dr.dataRef, &dr.dataRefType);
  185296. ok = openMovie (props, prop, movie);
  185297. DisposeHandle (dr.dataRef);
  185298. CFRelease (filePath);
  185299. }
  185300. else
  185301. {
  185302. // sanity-check because this currently needs to load the whole stream into memory..
  185303. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  185304. dataHandle = NewHandle ((Size) input->getTotalLength());
  185305. HLock (dataHandle);
  185306. // read the entire stream into memory - this is a pain, but can't get it to work
  185307. // properly using a custom callback to supply the data.
  185308. input->read (*dataHandle, (int) input->getTotalLength());
  185309. HUnlock (dataHandle);
  185310. // different types to get QT to try. (We should really be a bit smarter here by
  185311. // working out in advance which one the stream contains, rather than just trying
  185312. // each one)
  185313. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185314. "\04.avi", "\04.m4a" };
  185315. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185316. {
  185317. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185318. dr.dataRefType = HandleDataHandlerSubType;
  185319. ok = openMovie (props, prop, movie);
  185320. DisposeHandle (dr.dataRef);
  185321. }
  185322. }
  185323. return ok;
  185324. }
  185325. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185326. const bool isControllerVisible)
  185327. {
  185328. const bool ok = loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible);
  185329. movieFile = movieFile_;
  185330. return ok;
  185331. }
  185332. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185333. const bool isControllerVisible)
  185334. {
  185335. return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible);
  185336. }
  185337. void QuickTimeMovieComponent::goToStart()
  185338. {
  185339. setPosition (0.0);
  185340. }
  185341. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  185342. const RectanglePlacement& placement)
  185343. {
  185344. int normalWidth, normalHeight;
  185345. getMovieNormalSize (normalWidth, normalHeight);
  185346. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185347. {
  185348. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185349. placement.applyTo (x, y, w, h,
  185350. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185351. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185352. if (w > 0 && h > 0)
  185353. {
  185354. setBounds (roundToInt (x), roundToInt (y),
  185355. roundToInt (w), roundToInt (h));
  185356. }
  185357. }
  185358. else
  185359. {
  185360. setBounds (spaceToFitWithin);
  185361. }
  185362. }
  185363. #endif
  185364. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185365. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185366. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185367. // compiled on its own).
  185368. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185369. class WebBrowserComponentInternal : public ActiveXControlComponent
  185370. {
  185371. public:
  185372. WebBrowserComponentInternal()
  185373. : browser (0),
  185374. connectionPoint (0),
  185375. adviseCookie (0)
  185376. {
  185377. }
  185378. ~WebBrowserComponentInternal()
  185379. {
  185380. if (connectionPoint != 0)
  185381. connectionPoint->Unadvise (adviseCookie);
  185382. if (browser != 0)
  185383. browser->Release();
  185384. }
  185385. void createBrowser()
  185386. {
  185387. createControl (&CLSID_WebBrowser);
  185388. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185389. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185390. if (connectionPointContainer != 0)
  185391. {
  185392. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185393. &connectionPoint);
  185394. if (connectionPoint != 0)
  185395. {
  185396. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185397. jassert (owner != 0);
  185398. EventHandler* handler = new EventHandler (owner);
  185399. connectionPoint->Advise (handler, &adviseCookie);
  185400. }
  185401. }
  185402. }
  185403. void goToURL (const String& url,
  185404. const StringArray* headers,
  185405. const MemoryBlock* postData)
  185406. {
  185407. if (browser != 0)
  185408. {
  185409. LPSAFEARRAY sa = 0;
  185410. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185411. VariantInit (&flags);
  185412. VariantInit (&frame);
  185413. VariantInit (&postDataVar);
  185414. VariantInit (&headersVar);
  185415. if (headers != 0)
  185416. {
  185417. V_VT (&headersVar) = VT_BSTR;
  185418. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185419. }
  185420. if (postData != 0 && postData->getSize() > 0)
  185421. {
  185422. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185423. if (sa != 0)
  185424. {
  185425. void* data = 0;
  185426. SafeArrayAccessData (sa, &data);
  185427. jassert (data != 0);
  185428. if (data != 0)
  185429. {
  185430. postData->copyTo (data, 0, postData->getSize());
  185431. SafeArrayUnaccessData (sa);
  185432. VARIANT postDataVar2;
  185433. VariantInit (&postDataVar2);
  185434. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185435. V_ARRAY (&postDataVar2) = sa;
  185436. postDataVar = postDataVar2;
  185437. }
  185438. }
  185439. }
  185440. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185441. &flags, &frame,
  185442. &postDataVar, &headersVar);
  185443. if (sa != 0)
  185444. SafeArrayDestroy (sa);
  185445. VariantClear (&flags);
  185446. VariantClear (&frame);
  185447. VariantClear (&postDataVar);
  185448. VariantClear (&headersVar);
  185449. }
  185450. }
  185451. IWebBrowser2* browser;
  185452. juce_UseDebuggingNewOperator
  185453. private:
  185454. IConnectionPoint* connectionPoint;
  185455. DWORD adviseCookie;
  185456. class EventHandler : public IDispatch,
  185457. public ComponentMovementWatcher
  185458. {
  185459. public:
  185460. EventHandler (WebBrowserComponent* owner_)
  185461. : ComponentMovementWatcher (owner_),
  185462. owner (owner_),
  185463. refCount (0)
  185464. {
  185465. }
  185466. ~EventHandler()
  185467. {
  185468. }
  185469. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185470. {
  185471. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185472. {
  185473. AddRef();
  185474. *result = this;
  185475. return S_OK;
  185476. }
  185477. *result = 0;
  185478. return E_NOINTERFACE;
  185479. }
  185480. ULONG __stdcall AddRef() { return ++refCount; }
  185481. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185482. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185483. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185484. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185485. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185486. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185487. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185488. UINT __RPC_FAR* /*puArgErr*/)
  185489. {
  185490. switch (dispIdMember)
  185491. {
  185492. case DISPID_BEFORENAVIGATE2:
  185493. {
  185494. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185495. String url;
  185496. if ((vurl->vt & VT_BYREF) != 0)
  185497. url = *vurl->pbstrVal;
  185498. else
  185499. url = vurl->bstrVal;
  185500. *pDispParams->rgvarg->pboolVal
  185501. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185502. : VARIANT_TRUE;
  185503. return S_OK;
  185504. }
  185505. default:
  185506. break;
  185507. }
  185508. return E_NOTIMPL;
  185509. }
  185510. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185511. void componentPeerChanged() {}
  185512. void componentVisibilityChanged (Component&)
  185513. {
  185514. owner->visibilityChanged();
  185515. }
  185516. juce_UseDebuggingNewOperator
  185517. private:
  185518. WebBrowserComponent* const owner;
  185519. int refCount;
  185520. EventHandler (const EventHandler&);
  185521. EventHandler& operator= (const EventHandler&);
  185522. };
  185523. };
  185524. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185525. : browser (0),
  185526. blankPageShown (false),
  185527. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185528. {
  185529. setOpaque (true);
  185530. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185531. }
  185532. WebBrowserComponent::~WebBrowserComponent()
  185533. {
  185534. delete browser;
  185535. }
  185536. void WebBrowserComponent::goToURL (const String& url,
  185537. const StringArray* headers,
  185538. const MemoryBlock* postData)
  185539. {
  185540. lastURL = url;
  185541. lastHeaders.clear();
  185542. if (headers != 0)
  185543. lastHeaders = *headers;
  185544. lastPostData.setSize (0);
  185545. if (postData != 0)
  185546. lastPostData = *postData;
  185547. blankPageShown = false;
  185548. browser->goToURL (url, headers, postData);
  185549. }
  185550. void WebBrowserComponent::stop()
  185551. {
  185552. if (browser->browser != 0)
  185553. browser->browser->Stop();
  185554. }
  185555. void WebBrowserComponent::goBack()
  185556. {
  185557. lastURL = String::empty;
  185558. blankPageShown = false;
  185559. if (browser->browser != 0)
  185560. browser->browser->GoBack();
  185561. }
  185562. void WebBrowserComponent::goForward()
  185563. {
  185564. lastURL = String::empty;
  185565. if (browser->browser != 0)
  185566. browser->browser->GoForward();
  185567. }
  185568. void WebBrowserComponent::refresh()
  185569. {
  185570. if (browser->browser != 0)
  185571. browser->browser->Refresh();
  185572. }
  185573. void WebBrowserComponent::paint (Graphics& g)
  185574. {
  185575. if (browser->browser == 0)
  185576. g.fillAll (Colours::white);
  185577. }
  185578. void WebBrowserComponent::checkWindowAssociation()
  185579. {
  185580. if (isShowing())
  185581. {
  185582. if (browser->browser == 0 && getPeer() != 0)
  185583. {
  185584. browser->createBrowser();
  185585. reloadLastURL();
  185586. }
  185587. else
  185588. {
  185589. if (blankPageShown)
  185590. goBack();
  185591. }
  185592. }
  185593. else
  185594. {
  185595. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185596. {
  185597. // when the component becomes invisible, some stuff like flash
  185598. // carries on playing audio, so we need to force it onto a blank
  185599. // page to avoid this..
  185600. blankPageShown = true;
  185601. browser->goToURL ("about:blank", 0, 0);
  185602. }
  185603. }
  185604. }
  185605. void WebBrowserComponent::reloadLastURL()
  185606. {
  185607. if (lastURL.isNotEmpty())
  185608. {
  185609. goToURL (lastURL, &lastHeaders, &lastPostData);
  185610. lastURL = String::empty;
  185611. }
  185612. }
  185613. void WebBrowserComponent::parentHierarchyChanged()
  185614. {
  185615. checkWindowAssociation();
  185616. }
  185617. void WebBrowserComponent::resized()
  185618. {
  185619. browser->setSize (getWidth(), getHeight());
  185620. }
  185621. void WebBrowserComponent::visibilityChanged()
  185622. {
  185623. checkWindowAssociation();
  185624. }
  185625. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185626. {
  185627. return true;
  185628. }
  185629. #endif
  185630. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185631. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185632. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185633. // compiled on its own).
  185634. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185635. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185636. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185637. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185638. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185639. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185640. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185641. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185642. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185643. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185644. #define WGL_ACCELERATION_ARB 0x2003
  185645. #define WGL_SWAP_METHOD_ARB 0x2007
  185646. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185647. #define WGL_PIXEL_TYPE_ARB 0x2013
  185648. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185649. #define WGL_COLOR_BITS_ARB 0x2014
  185650. #define WGL_RED_BITS_ARB 0x2015
  185651. #define WGL_GREEN_BITS_ARB 0x2017
  185652. #define WGL_BLUE_BITS_ARB 0x2019
  185653. #define WGL_ALPHA_BITS_ARB 0x201B
  185654. #define WGL_DEPTH_BITS_ARB 0x2022
  185655. #define WGL_STENCIL_BITS_ARB 0x2023
  185656. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185657. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185658. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185659. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185660. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185661. #define WGL_STEREO_ARB 0x2012
  185662. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185663. #define WGL_SAMPLES_ARB 0x2042
  185664. #define WGL_TYPE_RGBA_ARB 0x202B
  185665. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185666. {
  185667. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185668. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185669. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185670. else
  185671. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185672. }
  185673. class WindowedGLContext : public OpenGLContext
  185674. {
  185675. public:
  185676. WindowedGLContext (Component* const component_,
  185677. HGLRC contextToShareWith,
  185678. const OpenGLPixelFormat& pixelFormat)
  185679. : renderContext (0),
  185680. nativeWindow (0),
  185681. dc (0),
  185682. component (component_)
  185683. {
  185684. jassert (component != 0);
  185685. createNativeWindow();
  185686. // Use a default pixel format that should be supported everywhere
  185687. PIXELFORMATDESCRIPTOR pfd;
  185688. zerostruct (pfd);
  185689. pfd.nSize = sizeof (pfd);
  185690. pfd.nVersion = 1;
  185691. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185692. pfd.iPixelType = PFD_TYPE_RGBA;
  185693. pfd.cColorBits = 24;
  185694. pfd.cDepthBits = 16;
  185695. const int format = ChoosePixelFormat (dc, &pfd);
  185696. if (format != 0)
  185697. SetPixelFormat (dc, format, &pfd);
  185698. renderContext = wglCreateContext (dc);
  185699. makeActive();
  185700. setPixelFormat (pixelFormat);
  185701. if (contextToShareWith != 0 && renderContext != 0)
  185702. wglShareLists (contextToShareWith, renderContext);
  185703. }
  185704. ~WindowedGLContext()
  185705. {
  185706. makeInactive();
  185707. wglDeleteContext (renderContext);
  185708. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185709. delete nativeWindow;
  185710. }
  185711. bool makeActive() const throw()
  185712. {
  185713. jassert (renderContext != 0);
  185714. return wglMakeCurrent (dc, renderContext) != 0;
  185715. }
  185716. bool makeInactive() const throw()
  185717. {
  185718. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185719. }
  185720. bool isActive() const throw()
  185721. {
  185722. return wglGetCurrentContext() == renderContext;
  185723. }
  185724. const OpenGLPixelFormat getPixelFormat() const
  185725. {
  185726. OpenGLPixelFormat pf;
  185727. makeActive();
  185728. StringArray availableExtensions;
  185729. getWglExtensions (dc, availableExtensions);
  185730. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185731. return pf;
  185732. }
  185733. void* getRawContext() const throw()
  185734. {
  185735. return renderContext;
  185736. }
  185737. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185738. {
  185739. makeActive();
  185740. PIXELFORMATDESCRIPTOR pfd;
  185741. zerostruct (pfd);
  185742. pfd.nSize = sizeof (pfd);
  185743. pfd.nVersion = 1;
  185744. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185745. pfd.iPixelType = PFD_TYPE_RGBA;
  185746. pfd.iLayerType = PFD_MAIN_PLANE;
  185747. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185748. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185749. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185750. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185751. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185752. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185753. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185754. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185755. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185756. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185757. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185758. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185759. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185760. int format = 0;
  185761. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185762. StringArray availableExtensions;
  185763. getWglExtensions (dc, availableExtensions);
  185764. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185765. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185766. {
  185767. int attributes[64];
  185768. int n = 0;
  185769. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185770. attributes[n++] = GL_TRUE;
  185771. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185772. attributes[n++] = GL_TRUE;
  185773. attributes[n++] = WGL_ACCELERATION_ARB;
  185774. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185775. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185776. attributes[n++] = GL_TRUE;
  185777. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185778. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185779. attributes[n++] = WGL_COLOR_BITS_ARB;
  185780. attributes[n++] = pfd.cColorBits;
  185781. attributes[n++] = WGL_RED_BITS_ARB;
  185782. attributes[n++] = pixelFormat.redBits;
  185783. attributes[n++] = WGL_GREEN_BITS_ARB;
  185784. attributes[n++] = pixelFormat.greenBits;
  185785. attributes[n++] = WGL_BLUE_BITS_ARB;
  185786. attributes[n++] = pixelFormat.blueBits;
  185787. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185788. attributes[n++] = pixelFormat.alphaBits;
  185789. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185790. attributes[n++] = pixelFormat.depthBufferBits;
  185791. if (pixelFormat.stencilBufferBits > 0)
  185792. {
  185793. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185794. attributes[n++] = pixelFormat.stencilBufferBits;
  185795. }
  185796. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185797. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185798. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185799. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185800. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185801. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185802. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185803. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185804. if (availableExtensions.contains ("WGL_ARB_multisample")
  185805. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185806. {
  185807. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185808. attributes[n++] = 1;
  185809. attributes[n++] = WGL_SAMPLES_ARB;
  185810. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185811. }
  185812. attributes[n++] = 0;
  185813. UINT formatsCount;
  185814. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185815. (void) ok;
  185816. jassert (ok);
  185817. }
  185818. else
  185819. {
  185820. format = ChoosePixelFormat (dc, &pfd);
  185821. }
  185822. if (format != 0)
  185823. {
  185824. makeInactive();
  185825. // win32 can't change the pixel format of a window, so need to delete the
  185826. // old one and create a new one..
  185827. jassert (nativeWindow != 0);
  185828. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185829. delete nativeWindow;
  185830. createNativeWindow();
  185831. if (SetPixelFormat (dc, format, &pfd))
  185832. {
  185833. wglDeleteContext (renderContext);
  185834. renderContext = wglCreateContext (dc);
  185835. jassert (renderContext != 0);
  185836. return renderContext != 0;
  185837. }
  185838. }
  185839. return false;
  185840. }
  185841. void updateWindowPosition (int x, int y, int w, int h, int)
  185842. {
  185843. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185844. x, y, w, h,
  185845. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185846. }
  185847. void repaint()
  185848. {
  185849. const Rectangle<int> bounds (nativeWindow->getBounds());
  185850. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185851. }
  185852. void swapBuffers()
  185853. {
  185854. SwapBuffers (dc);
  185855. }
  185856. bool setSwapInterval (const int numFramesPerSwap)
  185857. {
  185858. makeActive();
  185859. StringArray availableExtensions;
  185860. getWglExtensions (dc, availableExtensions);
  185861. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185862. return availableExtensions.contains ("WGL_EXT_swap_control")
  185863. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185864. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185865. }
  185866. int getSwapInterval() const
  185867. {
  185868. makeActive();
  185869. StringArray availableExtensions;
  185870. getWglExtensions (dc, availableExtensions);
  185871. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185872. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185873. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185874. return wglGetSwapIntervalEXT();
  185875. return 0;
  185876. }
  185877. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185878. {
  185879. jassert (isActive());
  185880. StringArray availableExtensions;
  185881. getWglExtensions (dc, availableExtensions);
  185882. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185883. int numTypes = 0;
  185884. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185885. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185886. {
  185887. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185888. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185889. jassertfalse
  185890. }
  185891. else
  185892. {
  185893. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185894. }
  185895. OpenGLPixelFormat pf;
  185896. for (int i = 0; i < numTypes; ++i)
  185897. {
  185898. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185899. {
  185900. bool alreadyListed = false;
  185901. for (int j = results.size(); --j >= 0;)
  185902. if (pf == *results.getUnchecked(j))
  185903. alreadyListed = true;
  185904. if (! alreadyListed)
  185905. results.add (new OpenGLPixelFormat (pf));
  185906. }
  185907. }
  185908. }
  185909. void* getNativeWindowHandle() const
  185910. {
  185911. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185912. }
  185913. juce_UseDebuggingNewOperator
  185914. HGLRC renderContext;
  185915. private:
  185916. Win32ComponentPeer* nativeWindow;
  185917. Component* const component;
  185918. HDC dc;
  185919. void createNativeWindow()
  185920. {
  185921. nativeWindow = new Win32ComponentPeer (component, 0);
  185922. nativeWindow->dontRepaint = true;
  185923. nativeWindow->setVisible (true);
  185924. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185925. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185926. if (peer != 0)
  185927. {
  185928. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185929. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185930. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185931. }
  185932. dc = GetDC (hwnd);
  185933. }
  185934. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185935. OpenGLPixelFormat& result,
  185936. const StringArray& availableExtensions) const throw()
  185937. {
  185938. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185939. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185940. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185941. {
  185942. int attributes[32];
  185943. int numAttributes = 0;
  185944. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185945. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185946. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185947. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185948. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185949. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185950. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185951. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185952. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185953. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185954. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185955. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185956. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185957. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185958. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185959. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185960. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185961. int values[32];
  185962. zeromem (values, sizeof (values));
  185963. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185964. {
  185965. int n = 0;
  185966. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185967. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185968. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185969. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185970. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185971. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185972. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185973. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185974. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185975. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185976. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185977. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185978. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185979. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185980. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185981. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185982. return isValidFormat;
  185983. }
  185984. else
  185985. {
  185986. jassertfalse
  185987. }
  185988. }
  185989. else
  185990. {
  185991. PIXELFORMATDESCRIPTOR pfd;
  185992. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185993. {
  185994. result.redBits = pfd.cRedBits;
  185995. result.greenBits = pfd.cGreenBits;
  185996. result.blueBits = pfd.cBlueBits;
  185997. result.alphaBits = pfd.cAlphaBits;
  185998. result.depthBufferBits = pfd.cDepthBits;
  185999. result.stencilBufferBits = pfd.cStencilBits;
  186000. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  186001. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  186002. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  186003. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  186004. result.fullSceneAntiAliasingNumSamples = 0;
  186005. return true;
  186006. }
  186007. else
  186008. {
  186009. jassertfalse
  186010. }
  186011. }
  186012. return false;
  186013. }
  186014. WindowedGLContext (const WindowedGLContext&);
  186015. WindowedGLContext& operator= (const WindowedGLContext&);
  186016. };
  186017. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  186018. const OpenGLPixelFormat& pixelFormat,
  186019. const OpenGLContext* const contextToShareWith)
  186020. {
  186021. WindowedGLContext* c = new WindowedGLContext (component,
  186022. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  186023. pixelFormat);
  186024. if (c->renderContext == 0)
  186025. deleteAndZero (c);
  186026. return c;
  186027. }
  186028. void* OpenGLComponent::getNativeWindowHandle() const
  186029. {
  186030. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  186031. }
  186032. void juce_glViewport (const int w, const int h)
  186033. {
  186034. glViewport (0, 0, w, h);
  186035. }
  186036. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  186037. OwnedArray <OpenGLPixelFormat>& results)
  186038. {
  186039. Component tempComp;
  186040. {
  186041. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  186042. wc.makeActive();
  186043. wc.findAlternativeOpenGLPixelFormats (results);
  186044. }
  186045. }
  186046. #endif
  186047. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  186048. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  186049. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  186050. // compiled on its own).
  186051. #if JUCE_INCLUDED_FILE
  186052. #if JUCE_USE_CDREADER
  186053. //***************************************************************************
  186054. // %%% TARGET STATUS VALUES %%%
  186055. //***************************************************************************
  186056. #define STATUS_GOOD 0x00 // Status Good
  186057. #define STATUS_CHKCOND 0x02 // Check Condition
  186058. #define STATUS_CONDMET 0x04 // Condition Met
  186059. #define STATUS_BUSY 0x08 // Busy
  186060. #define STATUS_INTERM 0x10 // Intermediate
  186061. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  186062. #define STATUS_RESCONF 0x18 // Reservation conflict
  186063. #define STATUS_COMTERM 0x22 // Command Terminated
  186064. #define STATUS_QFULL 0x28 // Queue full
  186065. //***************************************************************************
  186066. // %%% SCSI MISCELLANEOUS EQUATES %%%
  186067. //***************************************************************************
  186068. #define MAXLUN 7 // Maximum Logical Unit Id
  186069. #define MAXTARG 7 // Maximum Target Id
  186070. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  186071. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  186072. //***************************************************************************
  186073. // %%% Commands for all Device Types %%%
  186074. //***************************************************************************
  186075. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  186076. #define SCSI_COMPARE 0x39 // Compare (O)
  186077. #define SCSI_COPY 0x18 // Copy (O)
  186078. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  186079. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  186080. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  186081. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  186082. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  186083. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  186084. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  186085. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  186086. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  186087. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  186088. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  186089. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  186090. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  186091. //***************************************************************************
  186092. // %%% Commands Unique to Direct Access Devices %%%
  186093. //***************************************************************************
  186094. #define SCSI_COMPARE 0x39 // Compare (O)
  186095. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  186096. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  186097. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  186098. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  186099. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  186100. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  186101. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  186102. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  186103. #define SCSI_READ_LONG 0x3E // Read Long (O)
  186104. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  186105. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  186106. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  186107. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  186108. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  186109. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  186110. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  186111. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  186112. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  186113. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  186114. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  186115. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  186116. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  186117. #define SCSI_VERIFY 0x2F // Verify (O)
  186118. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  186119. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  186120. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  186121. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  186122. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  186123. //***************************************************************************
  186124. // %%% Commands Unique to Sequential Access Devices %%%
  186125. //***************************************************************************
  186126. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  186127. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  186128. #define SCSI_LOCATE 0x2B // Locate (O)
  186129. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  186130. #define SCSI_READ_POS 0x34 // Read Position (O)
  186131. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  186132. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  186133. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  186134. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  186135. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  186136. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  186137. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  186138. //***************************************************************************
  186139. // %%% Commands Unique to Printer Devices %%%
  186140. //***************************************************************************
  186141. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  186142. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  186143. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  186144. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  186145. //***************************************************************************
  186146. // %%% Commands Unique to Processor Devices %%%
  186147. //***************************************************************************
  186148. #define SCSI_RECEIVE 0x08 // Receive (O)
  186149. #define SCSI_SEND 0x0A // Send (O)
  186150. //***************************************************************************
  186151. // %%% Commands Unique to Write-Once Devices %%%
  186152. //***************************************************************************
  186153. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  186154. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  186155. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  186156. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  186157. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  186158. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  186159. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  186160. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  186161. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  186162. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  186163. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  186164. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  186165. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  186166. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  186167. //***************************************************************************
  186168. // %%% Commands Unique to CD-ROM Devices %%%
  186169. //***************************************************************************
  186170. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  186171. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  186172. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  186173. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  186174. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  186175. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  186176. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  186177. #define SCSI_READHEADER 0x44 // Read Header (O)
  186178. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  186179. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  186180. //***************************************************************************
  186181. // %%% Commands Unique to Scanner Devices %%%
  186182. //***************************************************************************
  186183. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  186184. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  186185. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  186186. #define SCSI_SCAN 0x1B // Scan (O)
  186187. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  186188. //***************************************************************************
  186189. // %%% Commands Unique to Optical Memory Devices %%%
  186190. //***************************************************************************
  186191. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  186192. //***************************************************************************
  186193. // %%% Commands Unique to Medium Changer Devices %%%
  186194. //***************************************************************************
  186195. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  186196. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  186197. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  186198. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  186199. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  186200. //***************************************************************************
  186201. // %%% Commands Unique to Communication Devices %%%
  186202. //***************************************************************************
  186203. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  186204. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  186205. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  186206. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  186207. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  186208. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  186209. //***************************************************************************
  186210. // %%% Request Sense Data Format %%%
  186211. //***************************************************************************
  186212. typedef struct {
  186213. BYTE ErrorCode; // Error Code (70H or 71H)
  186214. BYTE SegmentNum; // Number of current segment descriptor
  186215. BYTE SenseKey; // Sense Key(See bit definitions too)
  186216. BYTE InfoByte0; // Information MSB
  186217. BYTE InfoByte1; // Information MID
  186218. BYTE InfoByte2; // Information MID
  186219. BYTE InfoByte3; // Information LSB
  186220. BYTE AddSenLen; // Additional Sense Length
  186221. BYTE ComSpecInf0; // Command Specific Information MSB
  186222. BYTE ComSpecInf1; // Command Specific Information MID
  186223. BYTE ComSpecInf2; // Command Specific Information MID
  186224. BYTE ComSpecInf3; // Command Specific Information LSB
  186225. BYTE AddSenseCode; // Additional Sense Code
  186226. BYTE AddSenQual; // Additional Sense Code Qualifier
  186227. BYTE FieldRepUCode; // Field Replaceable Unit Code
  186228. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  186229. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  186230. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  186231. BYTE AddSenseBytes; // Additional Sense Bytes
  186232. } SENSE_DATA_FMT;
  186233. //***************************************************************************
  186234. // %%% REQUEST SENSE ERROR CODE %%%
  186235. //***************************************************************************
  186236. #define SERROR_CURRENT 0x70 // Current Errors
  186237. #define SERROR_DEFERED 0x71 // Deferred Errors
  186238. //***************************************************************************
  186239. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  186240. //***************************************************************************
  186241. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  186242. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  186243. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  186244. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  186245. //***************************************************************************
  186246. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  186247. //***************************************************************************
  186248. #define KEY_NOSENSE 0x00 // No Sense
  186249. #define KEY_RECERROR 0x01 // Recovered Error
  186250. #define KEY_NOTREADY 0x02 // Not Ready
  186251. #define KEY_MEDIUMERR 0x03 // Medium Error
  186252. #define KEY_HARDERROR 0x04 // Hardware Error
  186253. #define KEY_ILLGLREQ 0x05 // Illegal Request
  186254. #define KEY_UNITATT 0x06 // Unit Attention
  186255. #define KEY_DATAPROT 0x07 // Data Protect
  186256. #define KEY_BLANKCHK 0x08 // Blank Check
  186257. #define KEY_VENDSPEC 0x09 // Vendor Specific
  186258. #define KEY_COPYABORT 0x0A // Copy Abort
  186259. #define KEY_EQUAL 0x0C // Equal (Search)
  186260. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  186261. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  186262. #define KEY_RESERVED 0x0F // Reserved
  186263. //***************************************************************************
  186264. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  186265. //***************************************************************************
  186266. #define DTYPE_DASD 0x00 // Disk Device
  186267. #define DTYPE_SEQD 0x01 // Tape Device
  186268. #define DTYPE_PRNT 0x02 // Printer
  186269. #define DTYPE_PROC 0x03 // Processor
  186270. #define DTYPE_WORM 0x04 // Write-once read-multiple
  186271. #define DTYPE_CROM 0x05 // CD-ROM device
  186272. #define DTYPE_SCAN 0x06 // Scanner device
  186273. #define DTYPE_OPTI 0x07 // Optical memory device
  186274. #define DTYPE_JUKE 0x08 // Medium Changer device
  186275. #define DTYPE_COMM 0x09 // Communications device
  186276. #define DTYPE_RESL 0x0A // Reserved (low)
  186277. #define DTYPE_RESH 0x1E // Reserved (high)
  186278. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  186279. //***************************************************************************
  186280. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  186281. //***************************************************************************
  186282. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  186283. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  186284. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  186285. #define ANSI_RESLO 0x3 // Reserved (low)
  186286. #define ANSI_RESHI 0x7 // Reserved (high)
  186287. typedef struct
  186288. {
  186289. USHORT Length;
  186290. UCHAR ScsiStatus;
  186291. UCHAR PathId;
  186292. UCHAR TargetId;
  186293. UCHAR Lun;
  186294. UCHAR CdbLength;
  186295. UCHAR SenseInfoLength;
  186296. UCHAR DataIn;
  186297. ULONG DataTransferLength;
  186298. ULONG TimeOutValue;
  186299. ULONG DataBufferOffset;
  186300. ULONG SenseInfoOffset;
  186301. UCHAR Cdb[16];
  186302. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186303. typedef struct
  186304. {
  186305. USHORT Length;
  186306. UCHAR ScsiStatus;
  186307. UCHAR PathId;
  186308. UCHAR TargetId;
  186309. UCHAR Lun;
  186310. UCHAR CdbLength;
  186311. UCHAR SenseInfoLength;
  186312. UCHAR DataIn;
  186313. ULONG DataTransferLength;
  186314. ULONG TimeOutValue;
  186315. PVOID DataBuffer;
  186316. ULONG SenseInfoOffset;
  186317. UCHAR Cdb[16];
  186318. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186319. typedef struct
  186320. {
  186321. SCSI_PASS_THROUGH_DIRECT spt;
  186322. ULONG Filler;
  186323. UCHAR ucSenseBuf[32];
  186324. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186325. typedef struct
  186326. {
  186327. ULONG Length;
  186328. UCHAR PortNumber;
  186329. UCHAR PathId;
  186330. UCHAR TargetId;
  186331. UCHAR Lun;
  186332. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186333. #define METHOD_BUFFERED 0
  186334. #define METHOD_IN_DIRECT 1
  186335. #define METHOD_OUT_DIRECT 2
  186336. #define METHOD_NEITHER 3
  186337. #define FILE_ANY_ACCESS 0
  186338. #ifndef FILE_READ_ACCESS
  186339. #define FILE_READ_ACCESS (0x0001)
  186340. #endif
  186341. #ifndef FILE_WRITE_ACCESS
  186342. #define FILE_WRITE_ACCESS (0x0002)
  186343. #endif
  186344. #define IOCTL_SCSI_BASE 0x00000004
  186345. #define SCSI_IOCTL_DATA_OUT 0
  186346. #define SCSI_IOCTL_DATA_IN 1
  186347. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186348. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186349. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186350. )
  186351. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186352. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186353. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186354. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186355. #define SENSE_LEN 14
  186356. #define SRB_DIR_SCSI 0x00
  186357. #define SRB_POSTING 0x01
  186358. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186359. #define SRB_DIR_IN 0x08
  186360. #define SRB_DIR_OUT 0x10
  186361. #define SRB_EVENT_NOTIFY 0x40
  186362. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186363. #define MAX_SRB_TIMEOUT 1080001u
  186364. #define DEFAULT_SRB_TIMEOUT 1080001u
  186365. #define SC_HA_INQUIRY 0x00
  186366. #define SC_GET_DEV_TYPE 0x01
  186367. #define SC_EXEC_SCSI_CMD 0x02
  186368. #define SC_ABORT_SRB 0x03
  186369. #define SC_RESET_DEV 0x04
  186370. #define SC_SET_HA_PARMS 0x05
  186371. #define SC_GET_DISK_INFO 0x06
  186372. #define SC_RESCAN_SCSI_BUS 0x07
  186373. #define SC_GETSET_TIMEOUTS 0x08
  186374. #define SS_PENDING 0x00
  186375. #define SS_COMP 0x01
  186376. #define SS_ABORTED 0x02
  186377. #define SS_ABORT_FAIL 0x03
  186378. #define SS_ERR 0x04
  186379. #define SS_INVALID_CMD 0x80
  186380. #define SS_INVALID_HA 0x81
  186381. #define SS_NO_DEVICE 0x82
  186382. #define SS_INVALID_SRB 0xE0
  186383. #define SS_OLD_MANAGER 0xE1
  186384. #define SS_BUFFER_ALIGN 0xE1
  186385. #define SS_ILLEGAL_MODE 0xE2
  186386. #define SS_NO_ASPI 0xE3
  186387. #define SS_FAILED_INIT 0xE4
  186388. #define SS_ASPI_IS_BUSY 0xE5
  186389. #define SS_BUFFER_TO_BIG 0xE6
  186390. #define SS_BUFFER_TOO_BIG 0xE6
  186391. #define SS_MISMATCHED_COMPONENTS 0xE7
  186392. #define SS_NO_ADAPTERS 0xE8
  186393. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186394. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186395. #define SS_BAD_INSTALL 0xEB
  186396. #define HASTAT_OK 0x00
  186397. #define HASTAT_SEL_TO 0x11
  186398. #define HASTAT_DO_DU 0x12
  186399. #define HASTAT_BUS_FREE 0x13
  186400. #define HASTAT_PHASE_ERR 0x14
  186401. #define HASTAT_TIMEOUT 0x09
  186402. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186403. #define HASTAT_MESSAGE_REJECT 0x0D
  186404. #define HASTAT_BUS_RESET 0x0E
  186405. #define HASTAT_PARITY_ERROR 0x0F
  186406. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186407. #define PACKED
  186408. #pragma pack(1)
  186409. typedef struct
  186410. {
  186411. BYTE SRB_Cmd;
  186412. BYTE SRB_Status;
  186413. BYTE SRB_HaID;
  186414. BYTE SRB_Flags;
  186415. DWORD SRB_Hdr_Rsvd;
  186416. BYTE HA_Count;
  186417. BYTE HA_SCSI_ID;
  186418. BYTE HA_ManagerId[16];
  186419. BYTE HA_Identifier[16];
  186420. BYTE HA_Unique[16];
  186421. WORD HA_Rsvd1;
  186422. BYTE pad[20];
  186423. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186424. typedef struct
  186425. {
  186426. BYTE SRB_Cmd;
  186427. BYTE SRB_Status;
  186428. BYTE SRB_HaID;
  186429. BYTE SRB_Flags;
  186430. DWORD SRB_Hdr_Rsvd;
  186431. BYTE SRB_Target;
  186432. BYTE SRB_Lun;
  186433. BYTE SRB_DeviceType;
  186434. BYTE SRB_Rsvd1;
  186435. BYTE pad[68];
  186436. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186437. typedef struct
  186438. {
  186439. BYTE SRB_Cmd;
  186440. BYTE SRB_Status;
  186441. BYTE SRB_HaID;
  186442. BYTE SRB_Flags;
  186443. DWORD SRB_Hdr_Rsvd;
  186444. BYTE SRB_Target;
  186445. BYTE SRB_Lun;
  186446. WORD SRB_Rsvd1;
  186447. DWORD SRB_BufLen;
  186448. BYTE FAR *SRB_BufPointer;
  186449. BYTE SRB_SenseLen;
  186450. BYTE SRB_CDBLen;
  186451. BYTE SRB_HaStat;
  186452. BYTE SRB_TargStat;
  186453. VOID FAR *SRB_PostProc;
  186454. BYTE SRB_Rsvd2[20];
  186455. BYTE CDBByte[16];
  186456. BYTE SenseArea[SENSE_LEN+2];
  186457. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186458. typedef struct
  186459. {
  186460. BYTE SRB_Cmd;
  186461. BYTE SRB_Status;
  186462. BYTE SRB_HaId;
  186463. BYTE SRB_Flags;
  186464. DWORD SRB_Hdr_Rsvd;
  186465. } PACKED SRB, *PSRB, FAR *LPSRB;
  186466. #pragma pack()
  186467. struct CDDeviceInfo
  186468. {
  186469. char vendor[9];
  186470. char productId[17];
  186471. char rev[5];
  186472. char vendorSpec[21];
  186473. BYTE ha;
  186474. BYTE tgt;
  186475. BYTE lun;
  186476. char scsiDriveLetter; // will be 0 if not using scsi
  186477. };
  186478. class CDReadBuffer
  186479. {
  186480. public:
  186481. int startFrame;
  186482. int numFrames;
  186483. int dataStartOffset;
  186484. int dataLength;
  186485. BYTE* buffer;
  186486. int bufferSize;
  186487. int index;
  186488. bool wantsIndex;
  186489. CDReadBuffer (const int numberOfFrames)
  186490. : startFrame (0),
  186491. numFrames (0),
  186492. dataStartOffset (0),
  186493. dataLength (0),
  186494. index (0),
  186495. wantsIndex (false)
  186496. {
  186497. bufferSize = 2352 * numberOfFrames;
  186498. buffer = (BYTE*) malloc (bufferSize);
  186499. }
  186500. ~CDReadBuffer()
  186501. {
  186502. free (buffer);
  186503. }
  186504. bool isZero() const
  186505. {
  186506. BYTE* p = buffer + dataStartOffset;
  186507. for (int i = dataLength; --i >= 0;)
  186508. if (*p++ != 0)
  186509. return false;
  186510. return true;
  186511. }
  186512. };
  186513. class CDDeviceHandle;
  186514. class CDController
  186515. {
  186516. public:
  186517. CDController();
  186518. virtual ~CDController();
  186519. virtual bool read (CDReadBuffer* t) = 0;
  186520. virtual void shutDown();
  186521. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186522. int getLastIndex();
  186523. public:
  186524. bool initialised;
  186525. CDDeviceHandle* deviceInfo;
  186526. int framesToCheck, framesOverlap;
  186527. void prepare (SRB_ExecSCSICmd& s);
  186528. void perform (SRB_ExecSCSICmd& s);
  186529. void setPaused (bool paused);
  186530. };
  186531. #pragma pack(1)
  186532. struct TOCTRACK
  186533. {
  186534. BYTE rsvd;
  186535. BYTE ADR;
  186536. BYTE trackNumber;
  186537. BYTE rsvd2;
  186538. BYTE addr[4];
  186539. };
  186540. struct TOC
  186541. {
  186542. WORD tocLen;
  186543. BYTE firstTrack;
  186544. BYTE lastTrack;
  186545. TOCTRACK tracks[100];
  186546. };
  186547. #pragma pack()
  186548. enum
  186549. {
  186550. READTYPE_ANY = 0,
  186551. READTYPE_ATAPI1 = 1,
  186552. READTYPE_ATAPI2 = 2,
  186553. READTYPE_READ6 = 3,
  186554. READTYPE_READ10 = 4,
  186555. READTYPE_READ_D8 = 5,
  186556. READTYPE_READ_D4 = 6,
  186557. READTYPE_READ_D4_1 = 7,
  186558. READTYPE_READ10_2 = 8
  186559. };
  186560. class CDDeviceHandle
  186561. {
  186562. public:
  186563. CDDeviceHandle (const CDDeviceInfo* const device)
  186564. : scsiHandle (0),
  186565. readType (READTYPE_ANY),
  186566. controller (0)
  186567. {
  186568. memcpy (&info, device, sizeof (info));
  186569. }
  186570. ~CDDeviceHandle()
  186571. {
  186572. if (controller != 0)
  186573. {
  186574. controller->shutDown();
  186575. delete controller;
  186576. }
  186577. if (scsiHandle != 0)
  186578. CloseHandle (scsiHandle);
  186579. }
  186580. bool readTOC (TOC* lpToc, bool useMSF);
  186581. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186582. void openDrawer (bool shouldBeOpen);
  186583. CDDeviceInfo info;
  186584. HANDLE scsiHandle;
  186585. BYTE readType;
  186586. private:
  186587. CDController* controller;
  186588. bool testController (const int readType,
  186589. CDController* const newController,
  186590. CDReadBuffer* const bufferToUse);
  186591. };
  186592. DWORD (*fGetASPI32SupportInfo)(void);
  186593. DWORD (*fSendASPI32Command)(LPSRB);
  186594. static HINSTANCE winAspiLib = 0;
  186595. static bool usingScsi = false;
  186596. static bool initialised = false;
  186597. static bool InitialiseCDRipper()
  186598. {
  186599. if (! initialised)
  186600. {
  186601. initialised = true;
  186602. OSVERSIONINFO info;
  186603. info.dwOSVersionInfoSize = sizeof (info);
  186604. GetVersionEx (&info);
  186605. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186606. if (! usingScsi)
  186607. {
  186608. fGetASPI32SupportInfo = 0;
  186609. fSendASPI32Command = 0;
  186610. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186611. if (winAspiLib != 0)
  186612. {
  186613. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186614. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186615. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186616. return false;
  186617. }
  186618. else
  186619. {
  186620. usingScsi = true;
  186621. }
  186622. }
  186623. }
  186624. return true;
  186625. }
  186626. static void DeinitialiseCDRipper()
  186627. {
  186628. if (winAspiLib != 0)
  186629. {
  186630. fGetASPI32SupportInfo = 0;
  186631. fSendASPI32Command = 0;
  186632. FreeLibrary (winAspiLib);
  186633. winAspiLib = 0;
  186634. }
  186635. initialised = false;
  186636. }
  186637. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186638. {
  186639. TCHAR devicePath[8];
  186640. devicePath[0] = '\\';
  186641. devicePath[1] = '\\';
  186642. devicePath[2] = '.';
  186643. devicePath[3] = '\\';
  186644. devicePath[4] = driveLetter;
  186645. devicePath[5] = ':';
  186646. devicePath[6] = 0;
  186647. OSVERSIONINFO info;
  186648. info.dwOSVersionInfoSize = sizeof (info);
  186649. GetVersionEx (&info);
  186650. DWORD flags = GENERIC_READ;
  186651. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186652. flags = GENERIC_READ | GENERIC_WRITE;
  186653. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186654. if (h == INVALID_HANDLE_VALUE)
  186655. {
  186656. flags ^= GENERIC_WRITE;
  186657. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186658. }
  186659. return h;
  186660. }
  186661. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186662. const char driveLetter,
  186663. HANDLE& deviceHandle,
  186664. const bool retryOnFailure = true)
  186665. {
  186666. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186667. zerostruct (s);
  186668. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186669. s.spt.CdbLength = srb->SRB_CDBLen;
  186670. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186671. ? SCSI_IOCTL_DATA_IN
  186672. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186673. ? SCSI_IOCTL_DATA_OUT
  186674. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186675. s.spt.DataTransferLength = srb->SRB_BufLen;
  186676. s.spt.TimeOutValue = 5;
  186677. s.spt.DataBuffer = srb->SRB_BufPointer;
  186678. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186679. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186680. srb->SRB_Status = SS_ERR;
  186681. srb->SRB_TargStat = 0x0004;
  186682. DWORD bytesReturned = 0;
  186683. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186684. &s, sizeof (s),
  186685. &s, sizeof (s),
  186686. &bytesReturned, 0) != 0)
  186687. {
  186688. srb->SRB_Status = SS_COMP;
  186689. }
  186690. else if (retryOnFailure)
  186691. {
  186692. const DWORD error = GetLastError();
  186693. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186694. {
  186695. if (error != ERROR_INVALID_HANDLE)
  186696. CloseHandle (deviceHandle);
  186697. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186698. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186699. }
  186700. }
  186701. return srb->SRB_Status;
  186702. }
  186703. // Controller types..
  186704. class ControllerType1 : public CDController
  186705. {
  186706. public:
  186707. ControllerType1() {}
  186708. ~ControllerType1() {}
  186709. bool read (CDReadBuffer* rb)
  186710. {
  186711. if (rb->numFrames * 2352 > rb->bufferSize)
  186712. return false;
  186713. SRB_ExecSCSICmd s;
  186714. prepare (s);
  186715. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186716. s.SRB_BufLen = rb->bufferSize;
  186717. s.SRB_BufPointer = rb->buffer;
  186718. s.SRB_CDBLen = 12;
  186719. s.CDBByte[0] = 0xBE;
  186720. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186721. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186722. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186723. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186724. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186725. perform (s);
  186726. if (s.SRB_Status != SS_COMP)
  186727. return false;
  186728. rb->dataLength = rb->numFrames * 2352;
  186729. rb->dataStartOffset = 0;
  186730. return true;
  186731. }
  186732. };
  186733. class ControllerType2 : public CDController
  186734. {
  186735. public:
  186736. ControllerType2() {}
  186737. ~ControllerType2() {}
  186738. void shutDown()
  186739. {
  186740. if (initialised)
  186741. {
  186742. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186743. SRB_ExecSCSICmd s;
  186744. prepare (s);
  186745. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186746. s.SRB_BufLen = 0x0C;
  186747. s.SRB_BufPointer = bufPointer;
  186748. s.SRB_CDBLen = 6;
  186749. s.CDBByte[0] = 0x15;
  186750. s.CDBByte[4] = 0x0C;
  186751. perform (s);
  186752. }
  186753. }
  186754. bool init()
  186755. {
  186756. SRB_ExecSCSICmd s;
  186757. s.SRB_Status = SS_ERR;
  186758. if (deviceInfo->readType == READTYPE_READ10_2)
  186759. {
  186760. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186761. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186762. for (int i = 0; i < 2; ++i)
  186763. {
  186764. prepare (s);
  186765. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186766. s.SRB_BufLen = 0x14;
  186767. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186768. s.SRB_CDBLen = 6;
  186769. s.CDBByte[0] = 0x15;
  186770. s.CDBByte[1] = 0x10;
  186771. s.CDBByte[4] = 0x14;
  186772. perform (s);
  186773. if (s.SRB_Status != SS_COMP)
  186774. return false;
  186775. }
  186776. }
  186777. else
  186778. {
  186779. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186780. prepare (s);
  186781. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186782. s.SRB_BufLen = 0x0C;
  186783. s.SRB_BufPointer = bufPointer;
  186784. s.SRB_CDBLen = 6;
  186785. s.CDBByte[0] = 0x15;
  186786. s.CDBByte[4] = 0x0C;
  186787. perform (s);
  186788. }
  186789. return s.SRB_Status == SS_COMP;
  186790. }
  186791. bool read (CDReadBuffer* rb)
  186792. {
  186793. if (rb->numFrames * 2352 > rb->bufferSize)
  186794. return false;
  186795. if (!initialised)
  186796. {
  186797. initialised = init();
  186798. if (!initialised)
  186799. return false;
  186800. }
  186801. SRB_ExecSCSICmd s;
  186802. prepare (s);
  186803. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186804. s.SRB_BufLen = rb->bufferSize;
  186805. s.SRB_BufPointer = rb->buffer;
  186806. s.SRB_CDBLen = 10;
  186807. s.CDBByte[0] = 0x28;
  186808. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186809. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186810. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186811. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186812. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186813. perform (s);
  186814. if (s.SRB_Status != SS_COMP)
  186815. return false;
  186816. rb->dataLength = rb->numFrames * 2352;
  186817. rb->dataStartOffset = 0;
  186818. return true;
  186819. }
  186820. };
  186821. class ControllerType3 : public CDController
  186822. {
  186823. public:
  186824. ControllerType3() {}
  186825. ~ControllerType3() {}
  186826. bool read (CDReadBuffer* rb)
  186827. {
  186828. if (rb->numFrames * 2352 > rb->bufferSize)
  186829. return false;
  186830. if (!initialised)
  186831. {
  186832. setPaused (false);
  186833. initialised = true;
  186834. }
  186835. SRB_ExecSCSICmd s;
  186836. prepare (s);
  186837. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186838. s.SRB_BufLen = rb->numFrames * 2352;
  186839. s.SRB_BufPointer = rb->buffer;
  186840. s.SRB_CDBLen = 12;
  186841. s.CDBByte[0] = 0xD8;
  186842. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186843. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186844. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186845. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186846. perform (s);
  186847. if (s.SRB_Status != SS_COMP)
  186848. return false;
  186849. rb->dataLength = rb->numFrames * 2352;
  186850. rb->dataStartOffset = 0;
  186851. return true;
  186852. }
  186853. };
  186854. class ControllerType4 : public CDController
  186855. {
  186856. public:
  186857. ControllerType4() {}
  186858. ~ControllerType4() {}
  186859. bool selectD4Mode()
  186860. {
  186861. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186862. SRB_ExecSCSICmd s;
  186863. prepare (s);
  186864. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186865. s.SRB_CDBLen = 6;
  186866. s.SRB_BufLen = 12;
  186867. s.SRB_BufPointer = bufPointer;
  186868. s.CDBByte[0] = 0x15;
  186869. s.CDBByte[1] = 0x10;
  186870. s.CDBByte[4] = 0x08;
  186871. perform (s);
  186872. return s.SRB_Status == SS_COMP;
  186873. }
  186874. bool read (CDReadBuffer* rb)
  186875. {
  186876. if (rb->numFrames * 2352 > rb->bufferSize)
  186877. return false;
  186878. if (!initialised)
  186879. {
  186880. setPaused (true);
  186881. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186882. selectD4Mode();
  186883. initialised = true;
  186884. }
  186885. SRB_ExecSCSICmd s;
  186886. prepare (s);
  186887. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186888. s.SRB_BufLen = rb->bufferSize;
  186889. s.SRB_BufPointer = rb->buffer;
  186890. s.SRB_CDBLen = 10;
  186891. s.CDBByte[0] = 0xD4;
  186892. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186893. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186894. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186895. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186896. perform (s);
  186897. if (s.SRB_Status != SS_COMP)
  186898. return false;
  186899. rb->dataLength = rb->numFrames * 2352;
  186900. rb->dataStartOffset = 0;
  186901. return true;
  186902. }
  186903. };
  186904. CDController::CDController() : initialised (false)
  186905. {
  186906. }
  186907. CDController::~CDController()
  186908. {
  186909. }
  186910. void CDController::prepare (SRB_ExecSCSICmd& s)
  186911. {
  186912. zerostruct (s);
  186913. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186914. s.SRB_HaID = deviceInfo->info.ha;
  186915. s.SRB_Target = deviceInfo->info.tgt;
  186916. s.SRB_Lun = deviceInfo->info.lun;
  186917. s.SRB_SenseLen = SENSE_LEN;
  186918. }
  186919. void CDController::perform (SRB_ExecSCSICmd& s)
  186920. {
  186921. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186922. s.SRB_PostProc = (void*)event;
  186923. ResetEvent (event);
  186924. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186925. deviceInfo->info.scsiDriveLetter,
  186926. deviceInfo->scsiHandle)
  186927. : fSendASPI32Command ((LPSRB)&s);
  186928. if (status == SS_PENDING)
  186929. WaitForSingleObject (event, 4000);
  186930. CloseHandle (event);
  186931. }
  186932. void CDController::setPaused (bool paused)
  186933. {
  186934. SRB_ExecSCSICmd s;
  186935. prepare (s);
  186936. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186937. s.SRB_CDBLen = 10;
  186938. s.CDBByte[0] = 0x4B;
  186939. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186940. perform (s);
  186941. }
  186942. void CDController::shutDown()
  186943. {
  186944. }
  186945. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186946. {
  186947. if (overlapBuffer != 0)
  186948. {
  186949. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186950. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186951. if (doJitter
  186952. && overlapBuffer->startFrame > 0
  186953. && overlapBuffer->numFrames > 0
  186954. && overlapBuffer->dataLength > 0)
  186955. {
  186956. const int numFrames = rb->numFrames;
  186957. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186958. {
  186959. rb->startFrame -= framesOverlap;
  186960. if (framesToCheck < framesOverlap
  186961. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186962. rb->numFrames += framesOverlap;
  186963. }
  186964. else
  186965. {
  186966. overlapBuffer->dataLength = 0;
  186967. overlapBuffer->startFrame = 0;
  186968. overlapBuffer->numFrames = 0;
  186969. }
  186970. }
  186971. if (! read (rb))
  186972. return false;
  186973. if (doJitter)
  186974. {
  186975. const int checkLen = framesToCheck * 2352;
  186976. const int maxToCheck = rb->dataLength - checkLen;
  186977. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186978. return true;
  186979. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186980. bool found = false;
  186981. for (int i = 0; i < maxToCheck; ++i)
  186982. {
  186983. if (!memcmp (p, rb->buffer + i, checkLen))
  186984. {
  186985. i += checkLen;
  186986. rb->dataStartOffset = i;
  186987. rb->dataLength -= i;
  186988. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186989. found = true;
  186990. break;
  186991. }
  186992. }
  186993. rb->numFrames = rb->dataLength / 2352;
  186994. rb->dataLength = 2352 * rb->numFrames;
  186995. if (!found)
  186996. return false;
  186997. }
  186998. if (canDoJitter)
  186999. {
  187000. memcpy (overlapBuffer->buffer,
  187001. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  187002. 2352 * framesToCheck);
  187003. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  187004. overlapBuffer->numFrames = framesToCheck;
  187005. overlapBuffer->dataLength = 2352 * framesToCheck;
  187006. overlapBuffer->dataStartOffset = 0;
  187007. }
  187008. else
  187009. {
  187010. overlapBuffer->startFrame = 0;
  187011. overlapBuffer->numFrames = 0;
  187012. overlapBuffer->dataLength = 0;
  187013. }
  187014. return true;
  187015. }
  187016. else
  187017. {
  187018. return read (rb);
  187019. }
  187020. }
  187021. int CDController::getLastIndex()
  187022. {
  187023. char qdata[100];
  187024. SRB_ExecSCSICmd s;
  187025. prepare (s);
  187026. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187027. s.SRB_BufLen = sizeof (qdata);
  187028. s.SRB_BufPointer = (BYTE*)qdata;
  187029. s.SRB_CDBLen = 12;
  187030. s.CDBByte[0] = 0x42;
  187031. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187032. s.CDBByte[2] = 64;
  187033. s.CDBByte[3] = 1; // get current position
  187034. s.CDBByte[7] = 0;
  187035. s.CDBByte[8] = (BYTE)sizeof (qdata);
  187036. perform (s);
  187037. if (s.SRB_Status == SS_COMP)
  187038. return qdata[7];
  187039. return 0;
  187040. }
  187041. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  187042. {
  187043. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187044. SRB_ExecSCSICmd s;
  187045. zerostruct (s);
  187046. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187047. s.SRB_HaID = info.ha;
  187048. s.SRB_Target = info.tgt;
  187049. s.SRB_Lun = info.lun;
  187050. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187051. s.SRB_BufLen = 0x324;
  187052. s.SRB_BufPointer = (BYTE*)lpToc;
  187053. s.SRB_SenseLen = 0x0E;
  187054. s.SRB_CDBLen = 0x0A;
  187055. s.SRB_PostProc = (void*)event;
  187056. s.CDBByte[0] = 0x43;
  187057. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  187058. s.CDBByte[7] = 0x03;
  187059. s.CDBByte[8] = 0x24;
  187060. ResetEvent (event);
  187061. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187062. : fSendASPI32Command ((LPSRB)&s);
  187063. if (status == SS_PENDING)
  187064. WaitForSingleObject (event, 4000);
  187065. CloseHandle (event);
  187066. return (s.SRB_Status == SS_COMP);
  187067. }
  187068. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  187069. CDReadBuffer* const overlapBuffer)
  187070. {
  187071. if (controller == 0)
  187072. {
  187073. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  187074. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  187075. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  187076. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  187077. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  187078. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  187079. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  187080. }
  187081. buffer->index = 0;
  187082. if ((controller != 0)
  187083. && controller->readAudio (buffer, overlapBuffer))
  187084. {
  187085. if (buffer->wantsIndex)
  187086. buffer->index = controller->getLastIndex();
  187087. return true;
  187088. }
  187089. return false;
  187090. }
  187091. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  187092. {
  187093. if (shouldBeOpen)
  187094. {
  187095. if (controller != 0)
  187096. {
  187097. controller->shutDown();
  187098. delete controller;
  187099. controller = 0;
  187100. }
  187101. if (scsiHandle != 0)
  187102. {
  187103. CloseHandle (scsiHandle);
  187104. scsiHandle = 0;
  187105. }
  187106. }
  187107. SRB_ExecSCSICmd s;
  187108. zerostruct (s);
  187109. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187110. s.SRB_HaID = info.ha;
  187111. s.SRB_Target = info.tgt;
  187112. s.SRB_Lun = info.lun;
  187113. s.SRB_SenseLen = SENSE_LEN;
  187114. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187115. s.SRB_BufLen = 0;
  187116. s.SRB_BufPointer = 0;
  187117. s.SRB_CDBLen = 12;
  187118. s.CDBByte[0] = 0x1b;
  187119. s.CDBByte[1] = (BYTE)(info.lun << 5);
  187120. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  187121. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187122. s.SRB_PostProc = (void*)event;
  187123. ResetEvent (event);
  187124. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187125. : fSendASPI32Command ((LPSRB)&s);
  187126. if (status == SS_PENDING)
  187127. WaitForSingleObject (event, 4000);
  187128. CloseHandle (event);
  187129. }
  187130. bool CDDeviceHandle::testController (const int type,
  187131. CDController* const newController,
  187132. CDReadBuffer* const rb)
  187133. {
  187134. controller = newController;
  187135. readType = (BYTE)type;
  187136. controller->deviceInfo = this;
  187137. controller->framesToCheck = 1;
  187138. controller->framesOverlap = 3;
  187139. bool passed = false;
  187140. memset (rb->buffer, 0xcd, rb->bufferSize);
  187141. if (controller->read (rb))
  187142. {
  187143. passed = true;
  187144. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  187145. int wrong = 0;
  187146. for (int i = rb->dataLength / 4; --i >= 0;)
  187147. {
  187148. if (*p++ == (int) 0xcdcdcdcd)
  187149. {
  187150. if (++wrong == 4)
  187151. {
  187152. passed = false;
  187153. break;
  187154. }
  187155. }
  187156. else
  187157. {
  187158. wrong = 0;
  187159. }
  187160. }
  187161. }
  187162. if (! passed)
  187163. {
  187164. controller->shutDown();
  187165. delete controller;
  187166. controller = 0;
  187167. }
  187168. return passed;
  187169. }
  187170. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  187171. {
  187172. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187173. const int bufSize = 128;
  187174. BYTE buffer[bufSize];
  187175. zeromem (buffer, bufSize);
  187176. SRB_ExecSCSICmd s;
  187177. zerostruct (s);
  187178. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187179. s.SRB_HaID = ha;
  187180. s.SRB_Target = tgt;
  187181. s.SRB_Lun = lun;
  187182. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187183. s.SRB_BufLen = bufSize;
  187184. s.SRB_BufPointer = buffer;
  187185. s.SRB_SenseLen = SENSE_LEN;
  187186. s.SRB_CDBLen = 6;
  187187. s.SRB_PostProc = (void*)event;
  187188. s.CDBByte[0] = SCSI_INQUIRY;
  187189. s.CDBByte[4] = 100;
  187190. ResetEvent (event);
  187191. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  187192. WaitForSingleObject (event, 4000);
  187193. CloseHandle (event);
  187194. if (s.SRB_Status == SS_COMP)
  187195. {
  187196. memcpy (dev->vendor, &buffer[8], 8);
  187197. memcpy (dev->productId, &buffer[16], 16);
  187198. memcpy (dev->rev, &buffer[32], 4);
  187199. memcpy (dev->vendorSpec, &buffer[36], 20);
  187200. }
  187201. }
  187202. static int FindCDDevices (CDDeviceInfo* const list,
  187203. int maxItems)
  187204. {
  187205. int count = 0;
  187206. if (usingScsi)
  187207. {
  187208. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  187209. {
  187210. TCHAR drivePath[8];
  187211. drivePath[0] = driveLetter;
  187212. drivePath[1] = ':';
  187213. drivePath[2] = '\\';
  187214. drivePath[3] = 0;
  187215. if (GetDriveType (drivePath) == DRIVE_CDROM)
  187216. {
  187217. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  187218. if (h != INVALID_HANDLE_VALUE)
  187219. {
  187220. BYTE buffer[100], passThroughStruct[1024];
  187221. zeromem (buffer, sizeof (buffer));
  187222. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187223. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  187224. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  187225. p->spt.CdbLength = 6;
  187226. p->spt.SenseInfoLength = 24;
  187227. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  187228. p->spt.DataTransferLength = 100;
  187229. p->spt.TimeOutValue = 2;
  187230. p->spt.DataBuffer = buffer;
  187231. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187232. p->spt.Cdb[0] = 0x12;
  187233. p->spt.Cdb[4] = 100;
  187234. DWORD bytesReturned = 0;
  187235. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187236. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187237. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187238. &bytesReturned, 0) != 0)
  187239. {
  187240. zeromem (&list[count], sizeof (CDDeviceInfo));
  187241. list[count].scsiDriveLetter = driveLetter;
  187242. memcpy (list[count].vendor, &buffer[8], 8);
  187243. memcpy (list[count].productId, &buffer[16], 16);
  187244. memcpy (list[count].rev, &buffer[32], 4);
  187245. memcpy (list[count].vendorSpec, &buffer[36], 20);
  187246. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187247. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  187248. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  187249. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  187250. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  187251. &bytesReturned, 0) != 0)
  187252. {
  187253. list[count].ha = scsiAddr->PortNumber;
  187254. list[count].tgt = scsiAddr->TargetId;
  187255. list[count].lun = scsiAddr->Lun;
  187256. ++count;
  187257. }
  187258. }
  187259. CloseHandle (h);
  187260. }
  187261. }
  187262. }
  187263. }
  187264. else
  187265. {
  187266. const DWORD d = fGetASPI32SupportInfo();
  187267. BYTE status = HIBYTE (LOWORD (d));
  187268. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  187269. return 0;
  187270. const int numAdapters = LOBYTE (LOWORD (d));
  187271. for (BYTE ha = 0; ha < numAdapters; ++ha)
  187272. {
  187273. SRB_HAInquiry s;
  187274. zerostruct (s);
  187275. s.SRB_Cmd = SC_HA_INQUIRY;
  187276. s.SRB_HaID = ha;
  187277. fSendASPI32Command ((LPSRB)&s);
  187278. if (s.SRB_Status == SS_COMP)
  187279. {
  187280. maxItems = (int)s.HA_Unique[3];
  187281. if (maxItems == 0)
  187282. maxItems = 8;
  187283. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  187284. {
  187285. for (BYTE lun = 0; lun < 8; ++lun)
  187286. {
  187287. SRB_GDEVBlock sb;
  187288. zerostruct (sb);
  187289. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  187290. sb.SRB_HaID = ha;
  187291. sb.SRB_Target = tgt;
  187292. sb.SRB_Lun = lun;
  187293. fSendASPI32Command ((LPSRB) &sb);
  187294. if (sb.SRB_Status == SS_COMP
  187295. && sb.SRB_DeviceType == DTYPE_CROM)
  187296. {
  187297. zeromem (&list[count], sizeof (CDDeviceInfo));
  187298. list[count].ha = ha;
  187299. list[count].tgt = tgt;
  187300. list[count].lun = lun;
  187301. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  187302. ++count;
  187303. }
  187304. }
  187305. }
  187306. }
  187307. }
  187308. }
  187309. return count;
  187310. }
  187311. static int ripperUsers = 0;
  187312. static bool initialisedOk = false;
  187313. class DeinitialiseTimer : private Timer,
  187314. private DeletedAtShutdown
  187315. {
  187316. DeinitialiseTimer (const DeinitialiseTimer&);
  187317. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187318. public:
  187319. DeinitialiseTimer()
  187320. {
  187321. startTimer (4000);
  187322. }
  187323. ~DeinitialiseTimer()
  187324. {
  187325. if (--ripperUsers == 0)
  187326. DeinitialiseCDRipper();
  187327. }
  187328. void timerCallback()
  187329. {
  187330. delete this;
  187331. }
  187332. juce_UseDebuggingNewOperator
  187333. };
  187334. static void incUserCount()
  187335. {
  187336. if (ripperUsers++ == 0)
  187337. initialisedOk = InitialiseCDRipper();
  187338. }
  187339. static void decUserCount()
  187340. {
  187341. new DeinitialiseTimer();
  187342. }
  187343. struct CDDeviceWrapper
  187344. {
  187345. CDDeviceHandle* cdH;
  187346. CDReadBuffer* overlapBuffer;
  187347. bool jitter;
  187348. };
  187349. static int getAddressOf (const TOCTRACK* const t)
  187350. {
  187351. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187352. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187353. }
  187354. static int getMSFAddressOf (const TOCTRACK* const t)
  187355. {
  187356. return 60 * t->addr[1] + t->addr[2];
  187357. }
  187358. static const int samplesPerFrame = 44100 / 75;
  187359. static const int bytesPerFrame = samplesPerFrame * 4;
  187360. const StringArray AudioCDReader::getAvailableCDNames()
  187361. {
  187362. StringArray results;
  187363. incUserCount();
  187364. if (initialisedOk)
  187365. {
  187366. CDDeviceInfo list[8];
  187367. const int num = FindCDDevices (list, 8);
  187368. decUserCount();
  187369. for (int i = 0; i < num; ++i)
  187370. {
  187371. String s;
  187372. if (list[i].scsiDriveLetter > 0)
  187373. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187374. s << String (list[i].vendor).trim()
  187375. << T(" ") << String (list[i].productId).trim()
  187376. << T(" ") << String (list[i].rev).trim();
  187377. results.add (s);
  187378. }
  187379. }
  187380. return results;
  187381. }
  187382. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187383. {
  187384. SRB_GDEVBlock s;
  187385. zerostruct (s);
  187386. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187387. s.SRB_HaID = device->ha;
  187388. s.SRB_Target = device->tgt;
  187389. s.SRB_Lun = device->lun;
  187390. if (usingScsi)
  187391. {
  187392. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187393. if (h != INVALID_HANDLE_VALUE)
  187394. {
  187395. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187396. cdh->scsiHandle = h;
  187397. return cdh;
  187398. }
  187399. }
  187400. else
  187401. {
  187402. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187403. && s.SRB_DeviceType == DTYPE_CROM)
  187404. {
  187405. return new CDDeviceHandle (device);
  187406. }
  187407. }
  187408. return 0;
  187409. }
  187410. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187411. {
  187412. incUserCount();
  187413. if (initialisedOk)
  187414. {
  187415. CDDeviceInfo list[8];
  187416. const int num = FindCDDevices (list, 8);
  187417. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187418. {
  187419. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187420. if (handle != 0)
  187421. {
  187422. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187423. d->cdH = handle;
  187424. d->overlapBuffer = new CDReadBuffer(3);
  187425. return new AudioCDReader (d);
  187426. }
  187427. }
  187428. }
  187429. decUserCount();
  187430. return 0;
  187431. }
  187432. AudioCDReader::AudioCDReader (void* handle_)
  187433. : AudioFormatReader (0, T("CD Audio")),
  187434. handle (handle_),
  187435. indexingEnabled (false),
  187436. lastIndex (0),
  187437. firstFrameInBuffer (0),
  187438. samplesInBuffer (0)
  187439. {
  187440. jassert (handle_ != 0);
  187441. refreshTrackLengths();
  187442. sampleRate = 44100.0;
  187443. bitsPerSample = 16;
  187444. lengthInSamples = getPositionOfTrackStart (numTracks);
  187445. numChannels = 2;
  187446. usesFloatingPointData = false;
  187447. buffer.setSize (4 * bytesPerFrame, true);
  187448. }
  187449. AudioCDReader::~AudioCDReader()
  187450. {
  187451. CDDeviceWrapper* const device = (CDDeviceWrapper*)handle;
  187452. delete device->cdH;
  187453. delete device->overlapBuffer;
  187454. delete device;
  187455. decUserCount();
  187456. }
  187457. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187458. int64 startSampleInFile, int numSamples)
  187459. {
  187460. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187461. bool ok = true;
  187462. while (numSamples > 0)
  187463. {
  187464. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187465. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187466. if (startSampleInFile >= bufferStartSample
  187467. && startSampleInFile < bufferEndSample)
  187468. {
  187469. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187470. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187471. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187472. const short* src = (const short*) buffer.getData();
  187473. src += 2 * (startSampleInFile - bufferStartSample);
  187474. for (int i = 0; i < toDo; ++i)
  187475. {
  187476. l[i] = src [i << 1] << 16;
  187477. if (r != 0)
  187478. r[i] = src [(i << 1) + 1] << 16;
  187479. }
  187480. startOffsetInDestBuffer += toDo;
  187481. startSampleInFile += toDo;
  187482. numSamples -= toDo;
  187483. }
  187484. else
  187485. {
  187486. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187487. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187488. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187489. {
  187490. device->overlapBuffer->dataLength = 0;
  187491. device->overlapBuffer->startFrame = 0;
  187492. device->overlapBuffer->numFrames = 0;
  187493. device->jitter = false;
  187494. }
  187495. firstFrameInBuffer = frameNeeded;
  187496. lastIndex = 0;
  187497. CDReadBuffer readBuffer (framesInBuffer + 4);
  187498. readBuffer.wantsIndex = indexingEnabled;
  187499. int i;
  187500. for (i = 5; --i >= 0;)
  187501. {
  187502. readBuffer.startFrame = frameNeeded;
  187503. readBuffer.numFrames = framesInBuffer;
  187504. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187505. break;
  187506. else
  187507. device->overlapBuffer->dataLength = 0;
  187508. }
  187509. if (i >= 0)
  187510. {
  187511. memcpy ((char*) buffer.getData(),
  187512. readBuffer.buffer + readBuffer.dataStartOffset,
  187513. readBuffer.dataLength);
  187514. samplesInBuffer = readBuffer.dataLength >> 2;
  187515. lastIndex = readBuffer.index;
  187516. }
  187517. else
  187518. {
  187519. int* l = destSamples[0] + startOffsetInDestBuffer;
  187520. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187521. while (--numSamples >= 0)
  187522. {
  187523. *l++ = 0;
  187524. if (r != 0)
  187525. *r++ = 0;
  187526. }
  187527. // sometimes the read fails for just the very last couple of blocks, so
  187528. // we'll ignore and errors in the last half-second of the disk..
  187529. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187530. break;
  187531. }
  187532. }
  187533. }
  187534. return ok;
  187535. }
  187536. bool AudioCDReader::isCDStillPresent() const
  187537. {
  187538. TOC toc;
  187539. zerostruct (toc);
  187540. return ((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false);
  187541. }
  187542. int AudioCDReader::getNumTracks() const
  187543. {
  187544. return numTracks;
  187545. }
  187546. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187547. {
  187548. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187549. : 0;
  187550. }
  187551. void AudioCDReader::refreshTrackLengths()
  187552. {
  187553. zeromem (trackStarts, sizeof (trackStarts));
  187554. zeromem (audioTracks, sizeof (audioTracks));
  187555. TOC toc;
  187556. zerostruct (toc);
  187557. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187558. {
  187559. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187560. for (int i = 0; i <= numTracks; ++i)
  187561. {
  187562. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187563. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187564. }
  187565. }
  187566. else
  187567. {
  187568. numTracks = 0;
  187569. }
  187570. }
  187571. bool AudioCDReader::isTrackAudio (int trackNum) const
  187572. {
  187573. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187574. : false;
  187575. }
  187576. void AudioCDReader::enableIndexScanning (bool b)
  187577. {
  187578. indexingEnabled = b;
  187579. }
  187580. int AudioCDReader::getLastIndex() const
  187581. {
  187582. return lastIndex;
  187583. }
  187584. const int framesPerIndexRead = 4;
  187585. int AudioCDReader::getIndexAt (int samplePos)
  187586. {
  187587. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187588. const int frameNeeded = samplePos / samplesPerFrame;
  187589. device->overlapBuffer->dataLength = 0;
  187590. device->overlapBuffer->startFrame = 0;
  187591. device->overlapBuffer->numFrames = 0;
  187592. device->jitter = false;
  187593. firstFrameInBuffer = 0;
  187594. lastIndex = 0;
  187595. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187596. readBuffer.wantsIndex = true;
  187597. int i;
  187598. for (i = 5; --i >= 0;)
  187599. {
  187600. readBuffer.startFrame = frameNeeded;
  187601. readBuffer.numFrames = framesPerIndexRead;
  187602. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187603. break;
  187604. }
  187605. if (i >= 0)
  187606. return readBuffer.index;
  187607. return -1;
  187608. }
  187609. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187610. {
  187611. Array <int> indexes;
  187612. const int trackStart = getPositionOfTrackStart (trackNumber);
  187613. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187614. bool needToScan = true;
  187615. if (trackEnd - trackStart > 20 * 44100)
  187616. {
  187617. // check the end of the track for indexes before scanning the whole thing
  187618. needToScan = false;
  187619. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187620. bool seenAnIndex = false;
  187621. while (pos <= trackEnd - samplesPerFrame)
  187622. {
  187623. const int index = getIndexAt (pos);
  187624. if (index == 0)
  187625. {
  187626. // lead-out, so skip back a bit if we've not found any indexes yet..
  187627. if (seenAnIndex)
  187628. break;
  187629. pos -= 44100 * 5;
  187630. if (pos < trackStart)
  187631. break;
  187632. }
  187633. else
  187634. {
  187635. if (index > 0)
  187636. seenAnIndex = true;
  187637. if (index > 1)
  187638. {
  187639. needToScan = true;
  187640. break;
  187641. }
  187642. pos += samplesPerFrame * framesPerIndexRead;
  187643. }
  187644. }
  187645. }
  187646. if (needToScan)
  187647. {
  187648. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187649. int pos = trackStart;
  187650. int last = -1;
  187651. while (pos < trackEnd - samplesPerFrame * 10)
  187652. {
  187653. const int frameNeeded = pos / samplesPerFrame;
  187654. device->overlapBuffer->dataLength = 0;
  187655. device->overlapBuffer->startFrame = 0;
  187656. device->overlapBuffer->numFrames = 0;
  187657. device->jitter = false;
  187658. firstFrameInBuffer = 0;
  187659. CDReadBuffer readBuffer (4);
  187660. readBuffer.wantsIndex = true;
  187661. int i;
  187662. for (i = 5; --i >= 0;)
  187663. {
  187664. readBuffer.startFrame = frameNeeded;
  187665. readBuffer.numFrames = framesPerIndexRead;
  187666. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187667. break;
  187668. }
  187669. if (i < 0)
  187670. break;
  187671. if (readBuffer.index > last && readBuffer.index > 1)
  187672. {
  187673. last = readBuffer.index;
  187674. indexes.add (pos);
  187675. }
  187676. pos += samplesPerFrame * framesPerIndexRead;
  187677. }
  187678. indexes.removeValue (trackStart);
  187679. }
  187680. return indexes;
  187681. }
  187682. int AudioCDReader::getCDDBId()
  187683. {
  187684. refreshTrackLengths();
  187685. if (numTracks > 0)
  187686. {
  187687. TOC toc;
  187688. zerostruct (toc);
  187689. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187690. {
  187691. int n = 0;
  187692. for (int i = numTracks; --i >= 0;)
  187693. {
  187694. int j = getMSFAddressOf (&toc.tracks[i]);
  187695. while (j > 0)
  187696. {
  187697. n += (j % 10);
  187698. j /= 10;
  187699. }
  187700. }
  187701. if (n != 0)
  187702. {
  187703. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187704. - getMSFAddressOf (&toc.tracks[0]);
  187705. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187706. }
  187707. }
  187708. }
  187709. return 0;
  187710. }
  187711. void AudioCDReader::ejectDisk()
  187712. {
  187713. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187714. }
  187715. #endif
  187716. #if JUCE_USE_CDBURNER
  187717. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187718. {
  187719. CoInitialize (0);
  187720. IDiscMaster* dm;
  187721. IDiscRecorder* result = 0;
  187722. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187723. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187724. IID_IDiscMaster,
  187725. (void**) &dm)))
  187726. {
  187727. if (SUCCEEDED (dm->Open()))
  187728. {
  187729. IEnumDiscRecorders* drEnum = 0;
  187730. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187731. {
  187732. IDiscRecorder* dr = 0;
  187733. DWORD dummy;
  187734. int index = 0;
  187735. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187736. {
  187737. if (indexToOpen == index)
  187738. {
  187739. result = dr;
  187740. break;
  187741. }
  187742. else if (list != 0)
  187743. {
  187744. BSTR path;
  187745. if (SUCCEEDED (dr->GetPath (&path)))
  187746. list->add ((const WCHAR*) path);
  187747. }
  187748. ++index;
  187749. dr->Release();
  187750. }
  187751. drEnum->Release();
  187752. }
  187753. if (master == 0)
  187754. dm->Close();
  187755. }
  187756. if (master != 0)
  187757. *master = dm;
  187758. else
  187759. dm->Release();
  187760. }
  187761. return result;
  187762. }
  187763. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187764. public Timer
  187765. {
  187766. public:
  187767. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187768. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187769. listener (0), progress (0), shouldCancel (false), refCount (1)
  187770. {
  187771. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187772. jassert (SUCCEEDED (hr));
  187773. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187774. //jassert (SUCCEEDED (hr));
  187775. lastState = getDiskState();
  187776. startTimer (2000);
  187777. }
  187778. ~Pimpl() {}
  187779. void releaseObjects()
  187780. {
  187781. discRecorder->Close();
  187782. if (redbook != 0)
  187783. redbook->Release();
  187784. discRecorder->Release();
  187785. discMaster->Release();
  187786. Release();
  187787. }
  187788. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187789. {
  187790. if (result == 0)
  187791. return E_POINTER;
  187792. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187793. {
  187794. AddRef();
  187795. *result = this;
  187796. return S_OK;
  187797. }
  187798. *result = 0;
  187799. return E_NOINTERFACE;
  187800. }
  187801. ULONG __stdcall AddRef() { return ++refCount; }
  187802. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187803. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187804. {
  187805. if (listener != 0 && ! shouldCancel)
  187806. shouldCancel = listener->audioCDBurnProgress (progress);
  187807. *pbCancel = shouldCancel;
  187808. return S_OK;
  187809. }
  187810. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187811. {
  187812. progress = nCompleted / (float) nTotal;
  187813. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187814. return E_NOTIMPL;
  187815. }
  187816. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187817. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187818. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187819. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187820. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187821. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187822. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187823. class ScopedDiscOpener
  187824. {
  187825. public:
  187826. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187827. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187828. private:
  187829. Pimpl& pimpl;
  187830. ScopedDiscOpener (const ScopedDiscOpener&);
  187831. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187832. };
  187833. DiskState getDiskState()
  187834. {
  187835. const ScopedDiscOpener opener (*this);
  187836. long type, flags;
  187837. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187838. if (FAILED (hr))
  187839. return unknown;
  187840. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187841. return writableDiskPresent;
  187842. if (type == 0)
  187843. return noDisc;
  187844. else
  187845. return readOnlyDiskPresent;
  187846. }
  187847. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187848. {
  187849. ComSmartPtr<IPropertyStorage> prop;
  187850. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187851. return defaultReturn;
  187852. PROPSPEC iPropSpec;
  187853. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187854. iPropSpec.lpwstr = name;
  187855. PROPVARIANT iPropVariant;
  187856. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187857. ? defaultReturn : (int) iPropVariant.lVal;
  187858. }
  187859. bool setIntProperty (const LPOLESTR name, const int value) const
  187860. {
  187861. ComSmartPtr<IPropertyStorage> prop;
  187862. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187863. return false;
  187864. PROPSPEC iPropSpec;
  187865. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187866. iPropSpec.lpwstr = name;
  187867. PROPVARIANT iPropVariant;
  187868. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187869. return false;
  187870. iPropVariant.lVal = (long) value;
  187871. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187872. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187873. }
  187874. void timerCallback()
  187875. {
  187876. const DiskState state = getDiskState();
  187877. if (state != lastState)
  187878. {
  187879. lastState = state;
  187880. owner.sendChangeMessage (&owner);
  187881. }
  187882. }
  187883. AudioCDBurner& owner;
  187884. DiskState lastState;
  187885. IDiscMaster* discMaster;
  187886. IDiscRecorder* discRecorder;
  187887. IRedbookDiscMaster* redbook;
  187888. AudioCDBurner::BurnProgressListener* listener;
  187889. float progress;
  187890. bool shouldCancel;
  187891. private:
  187892. int refCount;
  187893. };
  187894. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187895. {
  187896. IDiscMaster* discMaster = 0;
  187897. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187898. if (discRecorder != 0)
  187899. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187900. }
  187901. AudioCDBurner::~AudioCDBurner()
  187902. {
  187903. if (pimpl != 0)
  187904. pimpl.release()->releaseObjects();
  187905. }
  187906. const StringArray AudioCDBurner::findAvailableDevices()
  187907. {
  187908. StringArray devs;
  187909. enumCDBurners (&devs, -1, 0);
  187910. return devs;
  187911. }
  187912. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187913. {
  187914. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187915. if (b->pimpl == 0)
  187916. b = 0;
  187917. return b.release();
  187918. }
  187919. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187920. {
  187921. return pimpl->getDiskState();
  187922. }
  187923. bool AudioCDBurner::isDiskPresent() const
  187924. {
  187925. return getDiskState() == writableDiskPresent;
  187926. }
  187927. bool AudioCDBurner::openTray()
  187928. {
  187929. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187930. return SUCCEEDED (pimpl->discRecorder->Eject());
  187931. }
  187932. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187933. {
  187934. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187935. DiskState oldState = getDiskState();
  187936. DiskState newState = oldState;
  187937. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187938. {
  187939. newState = getDiskState();
  187940. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187941. }
  187942. return newState;
  187943. }
  187944. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187945. {
  187946. Array<int> results;
  187947. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187948. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187949. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187950. if (speeds[i] <= maxSpeed)
  187951. results.add (speeds[i]);
  187952. results.addIfNotAlreadyThere (maxSpeed);
  187953. return results;
  187954. }
  187955. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187956. {
  187957. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187958. return false;
  187959. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187960. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187961. }
  187962. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187963. {
  187964. long blocksFree = 0;
  187965. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187966. return blocksFree;
  187967. }
  187968. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187969. bool performFakeBurnForTesting, int writeSpeed)
  187970. {
  187971. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187972. pimpl->listener = listener;
  187973. pimpl->progress = 0;
  187974. pimpl->shouldCancel = false;
  187975. UINT_PTR cookie;
  187976. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187977. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187978. ejectDiscAfterwards);
  187979. String error;
  187980. if (hr != S_OK)
  187981. {
  187982. const char* e = "Couldn't open or write to the CD device";
  187983. if (hr == IMAPI_E_USERABORT)
  187984. e = "User cancelled the write operation";
  187985. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187986. e = "No Disk present";
  187987. error = e;
  187988. }
  187989. pimpl->discMaster->ProgressUnadvise (cookie);
  187990. pimpl->listener = 0;
  187991. return error;
  187992. }
  187993. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187994. {
  187995. if (audioSource == 0)
  187996. return false;
  187997. ScopedPointer<AudioSource> source (audioSource);
  187998. long bytesPerBlock;
  187999. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  188000. const int samplesPerBlock = bytesPerBlock / 4;
  188001. bool ok = true;
  188002. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  188003. HeapBlock <byte> buffer (bytesPerBlock);
  188004. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  188005. int samplesDone = 0;
  188006. source->prepareToPlay (samplesPerBlock, 44100.0);
  188007. while (ok)
  188008. {
  188009. {
  188010. AudioSourceChannelInfo info;
  188011. info.buffer = &sourceBuffer;
  188012. info.numSamples = samplesPerBlock;
  188013. info.startSample = 0;
  188014. sourceBuffer.clear();
  188015. source->getNextAudioBlock (info);
  188016. }
  188017. zeromem (buffer, bytesPerBlock);
  188018. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  188019. buffer, samplesPerBlock, 4);
  188020. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  188021. buffer + 2, samplesPerBlock, 4);
  188022. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  188023. if (FAILED (hr))
  188024. ok = false;
  188025. samplesDone += samplesPerBlock;
  188026. if (samplesDone >= numSamples)
  188027. break;
  188028. }
  188029. hr = pimpl->redbook->CloseAudioTrack();
  188030. return ok && hr == S_OK;
  188031. }
  188032. #endif
  188033. #endif
  188034. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  188035. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  188036. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188037. // compiled on its own).
  188038. #if JUCE_INCLUDED_FILE
  188039. static const int midiBufferSize = 1024 * 10;
  188040. static const int numInHeaders = 32;
  188041. static const int inBufferSize = 256;
  188042. static Array <void*, CriticalSection> activeMidiThreads;
  188043. using ::free;
  188044. class MidiInThread : public Thread
  188045. {
  188046. public:
  188047. MidiInThread (MidiInput* const input_,
  188048. MidiInputCallback* const callback_)
  188049. : Thread ("Juce Midi"),
  188050. hIn (0),
  188051. input (input_),
  188052. callback (callback_),
  188053. isStarted (false),
  188054. startTime (0),
  188055. pendingLength(0)
  188056. {
  188057. for (int i = numInHeaders; --i >= 0;)
  188058. {
  188059. zeromem (&hdr[i], sizeof (MIDIHDR));
  188060. hdr[i].lpData = inData[i];
  188061. hdr[i].dwBufferLength = inBufferSize;
  188062. }
  188063. };
  188064. ~MidiInThread()
  188065. {
  188066. stop();
  188067. if (hIn != 0)
  188068. {
  188069. int count = 5;
  188070. while (--count >= 0)
  188071. {
  188072. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  188073. break;
  188074. Sleep (20);
  188075. }
  188076. }
  188077. }
  188078. void handle (const uint32 message, const uint32 timeStamp) throw()
  188079. {
  188080. const int byte = message & 0xff;
  188081. if (byte < 0x80)
  188082. return;
  188083. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  188084. const double time = timeStampToTime (timeStamp);
  188085. {
  188086. const ScopedLock sl (lock);
  188087. if (pendingLength < midiBufferSize - 12)
  188088. {
  188089. char* const p = pending + pendingLength;
  188090. *(double*) p = time;
  188091. *(uint32*) (p + 8) = numBytes;
  188092. *(uint32*) (p + 12) = message;
  188093. pendingLength += 12 + numBytes;
  188094. }
  188095. else
  188096. {
  188097. jassertfalse // midi buffer overflow! You might need to increase the size..
  188098. }
  188099. }
  188100. notify();
  188101. }
  188102. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  188103. {
  188104. const int num = hdr->dwBytesRecorded;
  188105. if (num > 0)
  188106. {
  188107. const double time = timeStampToTime (timeStamp);
  188108. {
  188109. const ScopedLock sl (lock);
  188110. if (pendingLength < midiBufferSize - (8 + num))
  188111. {
  188112. char* const p = pending + pendingLength;
  188113. *(double*) p = time;
  188114. *(uint32*) (p + 8) = num;
  188115. memcpy (p + 12, hdr->lpData, num);
  188116. pendingLength += 12 + num;
  188117. }
  188118. else
  188119. {
  188120. jassertfalse // midi buffer overflow! You might need to increase the size..
  188121. }
  188122. }
  188123. notify();
  188124. }
  188125. }
  188126. void writeBlock (const int i) throw()
  188127. {
  188128. hdr[i].dwBytesRecorded = 0;
  188129. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188130. jassert (res == MMSYSERR_NOERROR);
  188131. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  188132. jassert (res == MMSYSERR_NOERROR);
  188133. }
  188134. void run()
  188135. {
  188136. MemoryBlock pendingCopy (64);
  188137. while (! threadShouldExit())
  188138. {
  188139. for (int i = 0; i < numInHeaders; ++i)
  188140. {
  188141. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188142. {
  188143. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188144. (void) res;
  188145. jassert (res == MMSYSERR_NOERROR);
  188146. writeBlock (i);
  188147. }
  188148. }
  188149. int len;
  188150. {
  188151. const ScopedLock sl (lock);
  188152. len = pendingLength;
  188153. if (len > 0)
  188154. {
  188155. pendingCopy.ensureSize (len);
  188156. pendingCopy.copyFrom (pending, 0, len);
  188157. pendingLength = 0;
  188158. }
  188159. }
  188160. //xxx needs to figure out if blocks are broken up or not
  188161. if (len == 0)
  188162. {
  188163. wait (500);
  188164. }
  188165. else
  188166. {
  188167. const char* p = (const char*) pendingCopy.getData();
  188168. while (len > 0)
  188169. {
  188170. const double time = *(const double*) p;
  188171. const int messageLen = *(const int*) (p + 8);
  188172. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  188173. callback->handleIncomingMidiMessage (input, message);
  188174. p += 12 + messageLen;
  188175. len -= 12 + messageLen;
  188176. }
  188177. }
  188178. }
  188179. }
  188180. void start() throw()
  188181. {
  188182. jassert (hIn != 0);
  188183. if (hIn != 0 && ! isStarted)
  188184. {
  188185. stop();
  188186. activeMidiThreads.addIfNotAlreadyThere (this);
  188187. int i;
  188188. for (i = 0; i < numInHeaders; ++i)
  188189. writeBlock (i);
  188190. startTime = Time::getMillisecondCounter();
  188191. MMRESULT res = midiInStart (hIn);
  188192. jassert (res == MMSYSERR_NOERROR);
  188193. if (res == MMSYSERR_NOERROR)
  188194. {
  188195. isStarted = true;
  188196. pendingLength = 0;
  188197. startThread (6);
  188198. }
  188199. }
  188200. }
  188201. void stop() throw()
  188202. {
  188203. if (isStarted)
  188204. {
  188205. stopThread (5000);
  188206. midiInReset (hIn);
  188207. midiInStop (hIn);
  188208. activeMidiThreads.removeValue (this);
  188209. { const ScopedLock sl (lock); }
  188210. for (int i = numInHeaders; --i >= 0;)
  188211. {
  188212. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188213. {
  188214. int c = 10;
  188215. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  188216. Sleep (20);
  188217. jassert (c >= 0);
  188218. }
  188219. }
  188220. isStarted = false;
  188221. pendingLength = 0;
  188222. }
  188223. }
  188224. juce_UseDebuggingNewOperator
  188225. HMIDIIN hIn;
  188226. private:
  188227. MidiInput* input;
  188228. MidiInputCallback* callback;
  188229. bool isStarted;
  188230. uint32 startTime;
  188231. CriticalSection lock;
  188232. MIDIHDR hdr [numInHeaders];
  188233. char inData [numInHeaders] [inBufferSize];
  188234. int pendingLength;
  188235. char pending [midiBufferSize];
  188236. double timeStampToTime (uint32 timeStamp) throw()
  188237. {
  188238. timeStamp += startTime;
  188239. const uint32 now = Time::getMillisecondCounter();
  188240. if (timeStamp > now)
  188241. {
  188242. if (timeStamp > now + 2)
  188243. --startTime;
  188244. timeStamp = now;
  188245. }
  188246. return 0.001 * timeStamp;
  188247. }
  188248. MidiInThread (const MidiInThread&);
  188249. MidiInThread& operator= (const MidiInThread&);
  188250. };
  188251. static void CALLBACK midiInCallback (HMIDIIN,
  188252. UINT uMsg,
  188253. DWORD_PTR dwInstance,
  188254. DWORD_PTR midiMessage,
  188255. DWORD_PTR timeStamp)
  188256. {
  188257. MidiInThread* const thread = (MidiInThread*) dwInstance;
  188258. if (thread != 0 && activeMidiThreads.contains (thread))
  188259. {
  188260. if (uMsg == MIM_DATA)
  188261. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  188262. else if (uMsg == MIM_LONGDATA)
  188263. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  188264. }
  188265. }
  188266. const StringArray MidiInput::getDevices()
  188267. {
  188268. StringArray s;
  188269. const int num = midiInGetNumDevs();
  188270. for (int i = 0; i < num; ++i)
  188271. {
  188272. MIDIINCAPS mc;
  188273. zerostruct (mc);
  188274. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188275. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188276. }
  188277. return s;
  188278. }
  188279. int MidiInput::getDefaultDeviceIndex()
  188280. {
  188281. return 0;
  188282. }
  188283. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  188284. {
  188285. if (callback == 0)
  188286. return 0;
  188287. UINT deviceId = MIDI_MAPPER;
  188288. int n = 0;
  188289. String name;
  188290. const int num = midiInGetNumDevs();
  188291. for (int i = 0; i < num; ++i)
  188292. {
  188293. MIDIINCAPS mc;
  188294. zerostruct (mc);
  188295. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188296. {
  188297. if (index == n)
  188298. {
  188299. deviceId = i;
  188300. name = String (mc.szPname, sizeof (mc.szPname));
  188301. break;
  188302. }
  188303. ++n;
  188304. }
  188305. }
  188306. ScopedPointer <MidiInput> in (new MidiInput (name));
  188307. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188308. HMIDIIN h;
  188309. HRESULT err = midiInOpen (&h, deviceId,
  188310. (DWORD_PTR) &midiInCallback,
  188311. (DWORD_PTR) (MidiInThread*) thread,
  188312. CALLBACK_FUNCTION);
  188313. if (err == MMSYSERR_NOERROR)
  188314. {
  188315. thread->hIn = h;
  188316. in->internal = (void*) thread.release();
  188317. return in.release();
  188318. }
  188319. return 0;
  188320. }
  188321. MidiInput::MidiInput (const String& name_)
  188322. : name (name_),
  188323. internal (0)
  188324. {
  188325. }
  188326. MidiInput::~MidiInput()
  188327. {
  188328. if (internal != 0)
  188329. {
  188330. MidiInThread* const thread = (MidiInThread*) internal;
  188331. delete thread;
  188332. }
  188333. }
  188334. void MidiInput::start()
  188335. {
  188336. ((MidiInThread*) internal)->start();
  188337. }
  188338. void MidiInput::stop()
  188339. {
  188340. ((MidiInThread*) internal)->stop();
  188341. }
  188342. struct MidiOutHandle
  188343. {
  188344. int refCount;
  188345. UINT deviceId;
  188346. HMIDIOUT handle;
  188347. juce_UseDebuggingNewOperator
  188348. };
  188349. static Array <MidiOutHandle*> midiOutputHandles;
  188350. const StringArray MidiOutput::getDevices()
  188351. {
  188352. StringArray s;
  188353. const int num = midiOutGetNumDevs();
  188354. for (int i = 0; i < num; ++i)
  188355. {
  188356. MIDIOUTCAPS mc;
  188357. zerostruct (mc);
  188358. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188359. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188360. }
  188361. return s;
  188362. }
  188363. int MidiOutput::getDefaultDeviceIndex()
  188364. {
  188365. const int num = midiOutGetNumDevs();
  188366. int n = 0;
  188367. for (int i = 0; i < num; ++i)
  188368. {
  188369. MIDIOUTCAPS mc;
  188370. zerostruct (mc);
  188371. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188372. {
  188373. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188374. return n;
  188375. ++n;
  188376. }
  188377. }
  188378. return 0;
  188379. }
  188380. MidiOutput* MidiOutput::openDevice (int index)
  188381. {
  188382. UINT deviceId = MIDI_MAPPER;
  188383. const int num = midiOutGetNumDevs();
  188384. int i, n = 0;
  188385. for (i = 0; i < num; ++i)
  188386. {
  188387. MIDIOUTCAPS mc;
  188388. zerostruct (mc);
  188389. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188390. {
  188391. // use the microsoft sw synth as a default - best not to allow deviceId
  188392. // to be MIDI_MAPPER, or else device sharing breaks
  188393. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188394. deviceId = i;
  188395. if (index == n)
  188396. {
  188397. deviceId = i;
  188398. break;
  188399. }
  188400. ++n;
  188401. }
  188402. }
  188403. for (i = midiOutputHandles.size(); --i >= 0;)
  188404. {
  188405. MidiOutHandle* const han = midiOutputHandles.getUnchecked(i);
  188406. if (han != 0 && han->deviceId == deviceId)
  188407. {
  188408. han->refCount++;
  188409. MidiOutput* const out = new MidiOutput();
  188410. out->internal = (void*) han;
  188411. return out;
  188412. }
  188413. }
  188414. for (i = 4; --i >= 0;)
  188415. {
  188416. HMIDIOUT h = 0;
  188417. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188418. if (res == MMSYSERR_NOERROR)
  188419. {
  188420. MidiOutHandle* const han = new MidiOutHandle();
  188421. han->deviceId = deviceId;
  188422. han->refCount = 1;
  188423. han->handle = h;
  188424. midiOutputHandles.add (han);
  188425. MidiOutput* const out = new MidiOutput();
  188426. out->internal = (void*) han;
  188427. return out;
  188428. }
  188429. else if (res == MMSYSERR_ALLOCATED)
  188430. {
  188431. Sleep (100);
  188432. }
  188433. else
  188434. {
  188435. break;
  188436. }
  188437. }
  188438. return 0;
  188439. }
  188440. MidiOutput::~MidiOutput()
  188441. {
  188442. MidiOutHandle* const h = (MidiOutHandle*) internal;
  188443. if (midiOutputHandles.contains (h) && --(h->refCount) == 0)
  188444. {
  188445. midiOutClose (h->handle);
  188446. midiOutputHandles.removeValue (h);
  188447. delete h;
  188448. }
  188449. }
  188450. void MidiOutput::reset()
  188451. {
  188452. const MidiOutHandle* const h = (MidiOutHandle*) internal;
  188453. midiOutReset (h->handle);
  188454. }
  188455. bool MidiOutput::getVolume (float& leftVol,
  188456. float& rightVol)
  188457. {
  188458. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188459. DWORD n;
  188460. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188461. {
  188462. const unsigned short* const nn = (const unsigned short*) &n;
  188463. rightVol = nn[0] / (float) 0xffff;
  188464. leftVol = nn[1] / (float) 0xffff;
  188465. return true;
  188466. }
  188467. else
  188468. {
  188469. rightVol = leftVol = 1.0f;
  188470. return false;
  188471. }
  188472. }
  188473. void MidiOutput::setVolume (float leftVol,
  188474. float rightVol)
  188475. {
  188476. const MidiOutHandle* const handle = (MidiOutHandle*) internal;
  188477. DWORD n;
  188478. unsigned short* const nn = (unsigned short*) &n;
  188479. nn[0] = (unsigned short) jlimit (0, 0xffff, (int)(rightVol * 0xffff));
  188480. nn[1] = (unsigned short) jlimit (0, 0xffff, (int)(leftVol * 0xffff));
  188481. midiOutSetVolume (handle->handle, n);
  188482. }
  188483. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188484. {
  188485. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188486. if (message.getRawDataSize() > 3
  188487. || message.isSysEx())
  188488. {
  188489. MIDIHDR h;
  188490. zerostruct (h);
  188491. h.lpData = (char*) message.getRawData();
  188492. h.dwBufferLength = message.getRawDataSize();
  188493. h.dwBytesRecorded = message.getRawDataSize();
  188494. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188495. {
  188496. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188497. if (res == MMSYSERR_NOERROR)
  188498. {
  188499. while ((h.dwFlags & MHDR_DONE) == 0)
  188500. Sleep (1);
  188501. int count = 500; // 1 sec timeout
  188502. while (--count >= 0)
  188503. {
  188504. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188505. if (res == MIDIERR_STILLPLAYING)
  188506. Sleep (2);
  188507. else
  188508. break;
  188509. }
  188510. }
  188511. }
  188512. }
  188513. else
  188514. {
  188515. midiOutShortMsg (handle->handle,
  188516. *(unsigned int*) message.getRawData());
  188517. }
  188518. }
  188519. #endif
  188520. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188521. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188522. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188523. // compiled on its own).
  188524. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188525. #undef WINDOWS
  188526. // #define ASIO_DEBUGGING
  188527. #ifdef ASIO_DEBUGGING
  188528. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188529. #else
  188530. #define log(a) {}
  188531. #endif
  188532. #ifdef ASIO_DEBUGGING
  188533. static void logError (const String& context, long error)
  188534. {
  188535. String err ("unknown error");
  188536. if (error == ASE_NotPresent)
  188537. err = "Not Present";
  188538. else if (error == ASE_HWMalfunction)
  188539. err = "Hardware Malfunction";
  188540. else if (error == ASE_InvalidParameter)
  188541. err = "Invalid Parameter";
  188542. else if (error == ASE_InvalidMode)
  188543. err = "Invalid Mode";
  188544. else if (error == ASE_SPNotAdvancing)
  188545. err = "Sample position not advancing";
  188546. else if (error == ASE_NoClock)
  188547. err = "No Clock";
  188548. else if (error == ASE_NoMemory)
  188549. err = "Out of memory";
  188550. log (T("!!error: ") + context + T(" - ") + err);
  188551. }
  188552. #else
  188553. #define logError(a, b) {}
  188554. #endif
  188555. class ASIOAudioIODevice;
  188556. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188557. static const int maxASIOChannels = 160;
  188558. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188559. private Timer
  188560. {
  188561. public:
  188562. Component ourWindow;
  188563. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188564. const String& optionalDllForDirectLoading_)
  188565. : AudioIODevice (name_, T("ASIO")),
  188566. asioObject (0),
  188567. classId (classId_),
  188568. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188569. currentBitDepth (16),
  188570. currentSampleRate (0),
  188571. isOpen_ (false),
  188572. isStarted (false),
  188573. postOutput (true),
  188574. insideControlPanelModalLoop (false),
  188575. shouldUsePreferredSize (false)
  188576. {
  188577. name = name_;
  188578. ourWindow.addToDesktop (0);
  188579. windowHandle = ourWindow.getWindowHandle();
  188580. jassert (currentASIODev [slotNumber] == 0);
  188581. currentASIODev [slotNumber] = this;
  188582. openDevice();
  188583. }
  188584. ~ASIOAudioIODevice()
  188585. {
  188586. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188587. if (currentASIODev[i] == this)
  188588. currentASIODev[i] = 0;
  188589. close();
  188590. log ("ASIO - exiting");
  188591. removeCurrentDriver();
  188592. }
  188593. void updateSampleRates()
  188594. {
  188595. // find a list of sample rates..
  188596. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188597. sampleRates.clear();
  188598. if (asioObject != 0)
  188599. {
  188600. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188601. {
  188602. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188603. if (err == 0)
  188604. {
  188605. sampleRates.add ((int) possibleSampleRates[index]);
  188606. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188607. }
  188608. else if (err != ASE_NoClock)
  188609. {
  188610. logError (T("CanSampleRate"), err);
  188611. }
  188612. }
  188613. if (sampleRates.size() == 0)
  188614. {
  188615. double cr = 0;
  188616. const long err = asioObject->getSampleRate (&cr);
  188617. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188618. if (err == 0)
  188619. sampleRates.add ((int) cr);
  188620. }
  188621. }
  188622. }
  188623. const StringArray getOutputChannelNames()
  188624. {
  188625. return outputChannelNames;
  188626. }
  188627. const StringArray getInputChannelNames()
  188628. {
  188629. return inputChannelNames;
  188630. }
  188631. int getNumSampleRates()
  188632. {
  188633. return sampleRates.size();
  188634. }
  188635. double getSampleRate (int index)
  188636. {
  188637. return sampleRates [index];
  188638. }
  188639. int getNumBufferSizesAvailable()
  188640. {
  188641. return bufferSizes.size();
  188642. }
  188643. int getBufferSizeSamples (int index)
  188644. {
  188645. return bufferSizes [index];
  188646. }
  188647. int getDefaultBufferSize()
  188648. {
  188649. return preferredSize;
  188650. }
  188651. const String open (const BitArray& inputChannels,
  188652. const BitArray& outputChannels,
  188653. double sr,
  188654. int bufferSizeSamples)
  188655. {
  188656. close();
  188657. currentCallback = 0;
  188658. if (bufferSizeSamples <= 0)
  188659. shouldUsePreferredSize = true;
  188660. if (asioObject == 0 || ! isASIOOpen)
  188661. {
  188662. log ("Warning: device not open");
  188663. const String err (openDevice());
  188664. if (asioObject == 0 || ! isASIOOpen)
  188665. return err;
  188666. }
  188667. isStarted = false;
  188668. bufferIndex = -1;
  188669. long err = 0;
  188670. long newPreferredSize = 0;
  188671. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188672. minSize = 0;
  188673. maxSize = 0;
  188674. newPreferredSize = 0;
  188675. granularity = 0;
  188676. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188677. {
  188678. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188679. shouldUsePreferredSize = true;
  188680. preferredSize = newPreferredSize;
  188681. }
  188682. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188683. // dynamic changes to the buffer size...
  188684. shouldUsePreferredSize = shouldUsePreferredSize
  188685. || getName().containsIgnoreCase (T("Digidesign"));
  188686. if (shouldUsePreferredSize)
  188687. {
  188688. log ("Using preferred size for buffer..");
  188689. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188690. {
  188691. bufferSizeSamples = preferredSize;
  188692. }
  188693. else
  188694. {
  188695. bufferSizeSamples = 1024;
  188696. logError ("GetBufferSize1", err);
  188697. }
  188698. shouldUsePreferredSize = false;
  188699. }
  188700. int sampleRate = roundDoubleToInt (sr);
  188701. currentSampleRate = sampleRate;
  188702. currentBlockSizeSamples = bufferSizeSamples;
  188703. currentChansOut.clear();
  188704. currentChansIn.clear();
  188705. zeromem (inBuffers, sizeof (inBuffers));
  188706. zeromem (outBuffers, sizeof (outBuffers));
  188707. updateSampleRates();
  188708. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188709. sampleRate = sampleRates[0];
  188710. jassert (sampleRate != 0);
  188711. if (sampleRate == 0)
  188712. sampleRate = 44100;
  188713. long numSources = 32;
  188714. ASIOClockSource clocks[32];
  188715. zeromem (clocks, sizeof (clocks));
  188716. asioObject->getClockSources (clocks, &numSources);
  188717. bool isSourceSet = false;
  188718. // careful not to remove this loop because it does more than just logging!
  188719. int i;
  188720. for (i = 0; i < numSources; ++i)
  188721. {
  188722. String s ("clock: ");
  188723. s += clocks[i].name;
  188724. if (clocks[i].isCurrentSource)
  188725. {
  188726. isSourceSet = true;
  188727. s << " (cur)";
  188728. }
  188729. log (s);
  188730. }
  188731. if (numSources > 1 && ! isSourceSet)
  188732. {
  188733. log ("setting clock source");
  188734. asioObject->setClockSource (clocks[0].index);
  188735. Thread::sleep (20);
  188736. }
  188737. else
  188738. {
  188739. if (numSources == 0)
  188740. {
  188741. log ("ASIO - no clock sources!");
  188742. }
  188743. }
  188744. double cr = 0;
  188745. err = asioObject->getSampleRate (&cr);
  188746. if (err == 0)
  188747. {
  188748. currentSampleRate = cr;
  188749. }
  188750. else
  188751. {
  188752. logError ("GetSampleRate", err);
  188753. currentSampleRate = 0;
  188754. }
  188755. error = String::empty;
  188756. needToReset = false;
  188757. isReSync = false;
  188758. err = 0;
  188759. bool buffersCreated = false;
  188760. if (currentSampleRate != sampleRate)
  188761. {
  188762. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188763. err = asioObject->setSampleRate (sampleRate);
  188764. if (err == ASE_NoClock && numSources > 0)
  188765. {
  188766. log ("trying to set a clock source..");
  188767. Thread::sleep (10);
  188768. err = asioObject->setClockSource (clocks[0].index);
  188769. if (err != 0)
  188770. {
  188771. logError ("SetClock", err);
  188772. }
  188773. Thread::sleep (10);
  188774. err = asioObject->setSampleRate (sampleRate);
  188775. }
  188776. }
  188777. if (err == 0)
  188778. {
  188779. currentSampleRate = sampleRate;
  188780. if (needToReset)
  188781. {
  188782. if (isReSync)
  188783. {
  188784. log ("Resync request");
  188785. }
  188786. log ("! Resetting ASIO after sample rate change");
  188787. removeCurrentDriver();
  188788. loadDriver();
  188789. const String error (initDriver());
  188790. if (error.isNotEmpty())
  188791. {
  188792. log (T("ASIOInit: ") + error);
  188793. }
  188794. needToReset = false;
  188795. isReSync = false;
  188796. }
  188797. numActiveInputChans = 0;
  188798. numActiveOutputChans = 0;
  188799. ASIOBufferInfo* info = bufferInfos;
  188800. int i;
  188801. for (i = 0; i < totalNumInputChans; ++i)
  188802. {
  188803. if (inputChannels[i])
  188804. {
  188805. currentChansIn.setBit (i);
  188806. info->isInput = 1;
  188807. info->channelNum = i;
  188808. info->buffers[0] = info->buffers[1] = 0;
  188809. ++info;
  188810. ++numActiveInputChans;
  188811. }
  188812. }
  188813. for (i = 0; i < totalNumOutputChans; ++i)
  188814. {
  188815. if (outputChannels[i])
  188816. {
  188817. currentChansOut.setBit (i);
  188818. info->isInput = 0;
  188819. info->channelNum = i;
  188820. info->buffers[0] = info->buffers[1] = 0;
  188821. ++info;
  188822. ++numActiveOutputChans;
  188823. }
  188824. }
  188825. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188826. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188827. if (currentASIODev[0] == this)
  188828. {
  188829. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188830. callbacks.asioMessage = &asioMessagesCallback0;
  188831. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188832. }
  188833. else if (currentASIODev[1] == this)
  188834. {
  188835. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188836. callbacks.asioMessage = &asioMessagesCallback1;
  188837. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188838. }
  188839. else if (currentASIODev[2] == this)
  188840. {
  188841. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188842. callbacks.asioMessage = &asioMessagesCallback2;
  188843. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188844. }
  188845. else
  188846. {
  188847. jassertfalse
  188848. }
  188849. log ("disposing buffers");
  188850. err = asioObject->disposeBuffers();
  188851. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188852. err = asioObject->createBuffers (bufferInfos,
  188853. totalBuffers,
  188854. currentBlockSizeSamples,
  188855. &callbacks);
  188856. if (err != 0)
  188857. {
  188858. currentBlockSizeSamples = preferredSize;
  188859. logError ("create buffers 2", err);
  188860. asioObject->disposeBuffers();
  188861. err = asioObject->createBuffers (bufferInfos,
  188862. totalBuffers,
  188863. currentBlockSizeSamples,
  188864. &callbacks);
  188865. }
  188866. if (err == 0)
  188867. {
  188868. buffersCreated = true;
  188869. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188870. int n = 0;
  188871. Array <int> types;
  188872. currentBitDepth = 16;
  188873. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188874. {
  188875. if (inputChannels[i])
  188876. {
  188877. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188878. ASIOChannelInfo channelInfo;
  188879. zerostruct (channelInfo);
  188880. channelInfo.channel = i;
  188881. channelInfo.isInput = 1;
  188882. asioObject->getChannelInfo (&channelInfo);
  188883. types.addIfNotAlreadyThere (channelInfo.type);
  188884. typeToFormatParameters (channelInfo.type,
  188885. inputChannelBitDepths[n],
  188886. inputChannelBytesPerSample[n],
  188887. inputChannelIsFloat[n],
  188888. inputChannelLittleEndian[n]);
  188889. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188890. ++n;
  188891. }
  188892. }
  188893. jassert (numActiveInputChans == n);
  188894. n = 0;
  188895. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188896. {
  188897. if (outputChannels[i])
  188898. {
  188899. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188900. ASIOChannelInfo channelInfo;
  188901. zerostruct (channelInfo);
  188902. channelInfo.channel = i;
  188903. channelInfo.isInput = 0;
  188904. asioObject->getChannelInfo (&channelInfo);
  188905. types.addIfNotAlreadyThere (channelInfo.type);
  188906. typeToFormatParameters (channelInfo.type,
  188907. outputChannelBitDepths[n],
  188908. outputChannelBytesPerSample[n],
  188909. outputChannelIsFloat[n],
  188910. outputChannelLittleEndian[n]);
  188911. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188912. ++n;
  188913. }
  188914. }
  188915. jassert (numActiveOutputChans == n);
  188916. for (i = types.size(); --i >= 0;)
  188917. {
  188918. log (T("channel format: ") + String (types[i]));
  188919. }
  188920. jassert (n <= totalBuffers);
  188921. for (i = 0; i < numActiveOutputChans; ++i)
  188922. {
  188923. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188924. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188925. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188926. {
  188927. log ("!! Null buffers");
  188928. }
  188929. else
  188930. {
  188931. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188932. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188933. }
  188934. }
  188935. inputLatency = outputLatency = 0;
  188936. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188937. {
  188938. log ("ASIO - no latencies");
  188939. }
  188940. else
  188941. {
  188942. log (T("ASIO latencies: ")
  188943. + String ((int) outputLatency)
  188944. + T(", ")
  188945. + String ((int) inputLatency));
  188946. }
  188947. isOpen_ = true;
  188948. log ("starting ASIO");
  188949. calledback = false;
  188950. err = asioObject->start();
  188951. if (err != 0)
  188952. {
  188953. isOpen_ = false;
  188954. log ("ASIO - stop on failure");
  188955. Thread::sleep (10);
  188956. asioObject->stop();
  188957. error = "Can't start device";
  188958. Thread::sleep (10);
  188959. }
  188960. else
  188961. {
  188962. int count = 300;
  188963. while (--count > 0 && ! calledback)
  188964. Thread::sleep (10);
  188965. isStarted = true;
  188966. if (! calledback)
  188967. {
  188968. error = "Device didn't start correctly";
  188969. log ("ASIO didn't callback - stopping..");
  188970. asioObject->stop();
  188971. }
  188972. }
  188973. }
  188974. else
  188975. {
  188976. error = "Can't create i/o buffers";
  188977. }
  188978. }
  188979. else
  188980. {
  188981. error = "Can't set sample rate: ";
  188982. error << sampleRate;
  188983. }
  188984. if (error.isNotEmpty())
  188985. {
  188986. logError (error, err);
  188987. if (asioObject != 0 && buffersCreated)
  188988. asioObject->disposeBuffers();
  188989. Thread::sleep (20);
  188990. isStarted = false;
  188991. isOpen_ = false;
  188992. close();
  188993. }
  188994. needToReset = false;
  188995. isReSync = false;
  188996. return error;
  188997. }
  188998. void close()
  188999. {
  189000. error = String::empty;
  189001. stopTimer();
  189002. stop();
  189003. if (isASIOOpen && isOpen_)
  189004. {
  189005. const ScopedLock sl (callbackLock);
  189006. isOpen_ = false;
  189007. isStarted = false;
  189008. needToReset = false;
  189009. isReSync = false;
  189010. log ("ASIO - stopping");
  189011. if (asioObject != 0)
  189012. {
  189013. Thread::sleep (20);
  189014. asioObject->stop();
  189015. Thread::sleep (10);
  189016. asioObject->disposeBuffers();
  189017. }
  189018. Thread::sleep (10);
  189019. }
  189020. }
  189021. bool isOpen()
  189022. {
  189023. return isOpen_ || insideControlPanelModalLoop;
  189024. }
  189025. int getCurrentBufferSizeSamples()
  189026. {
  189027. return currentBlockSizeSamples;
  189028. }
  189029. double getCurrentSampleRate()
  189030. {
  189031. return currentSampleRate;
  189032. }
  189033. const BitArray getActiveOutputChannels() const
  189034. {
  189035. return currentChansOut;
  189036. }
  189037. const BitArray getActiveInputChannels() const
  189038. {
  189039. return currentChansIn;
  189040. }
  189041. int getCurrentBitDepth()
  189042. {
  189043. return currentBitDepth;
  189044. }
  189045. int getOutputLatencyInSamples()
  189046. {
  189047. return outputLatency + currentBlockSizeSamples / 4;
  189048. }
  189049. int getInputLatencyInSamples()
  189050. {
  189051. return inputLatency + currentBlockSizeSamples / 4;
  189052. }
  189053. void start (AudioIODeviceCallback* callback)
  189054. {
  189055. if (callback != 0)
  189056. {
  189057. callback->audioDeviceAboutToStart (this);
  189058. const ScopedLock sl (callbackLock);
  189059. currentCallback = callback;
  189060. }
  189061. }
  189062. void stop()
  189063. {
  189064. AudioIODeviceCallback* const lastCallback = currentCallback;
  189065. {
  189066. const ScopedLock sl (callbackLock);
  189067. currentCallback = 0;
  189068. }
  189069. if (lastCallback != 0)
  189070. lastCallback->audioDeviceStopped();
  189071. }
  189072. bool isPlaying()
  189073. {
  189074. return isASIOOpen && (currentCallback != 0);
  189075. }
  189076. const String getLastError()
  189077. {
  189078. return error;
  189079. }
  189080. bool hasControlPanel() const
  189081. {
  189082. return true;
  189083. }
  189084. bool showControlPanel()
  189085. {
  189086. log ("ASIO - showing control panel");
  189087. Component modalWindow (String::empty);
  189088. modalWindow.setOpaque (true);
  189089. modalWindow.addToDesktop (0);
  189090. modalWindow.enterModalState();
  189091. bool done = false;
  189092. JUCE_TRY
  189093. {
  189094. // are there are devices that need to be closed before showing their control panel?
  189095. // close();
  189096. insideControlPanelModalLoop = true;
  189097. const uint32 started = Time::getMillisecondCounter();
  189098. if (asioObject != 0)
  189099. {
  189100. asioObject->controlPanel();
  189101. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  189102. log (T("spent: ") + String (spent));
  189103. if (spent > 300)
  189104. {
  189105. shouldUsePreferredSize = true;
  189106. done = true;
  189107. }
  189108. }
  189109. }
  189110. JUCE_CATCH_ALL
  189111. insideControlPanelModalLoop = false;
  189112. return done;
  189113. }
  189114. void resetRequest() throw()
  189115. {
  189116. needToReset = true;
  189117. }
  189118. void resyncRequest() throw()
  189119. {
  189120. needToReset = true;
  189121. isReSync = true;
  189122. }
  189123. void timerCallback()
  189124. {
  189125. if (! insideControlPanelModalLoop)
  189126. {
  189127. stopTimer();
  189128. // used to cause a reset
  189129. log ("! ASIO restart request!");
  189130. if (isOpen_)
  189131. {
  189132. AudioIODeviceCallback* const oldCallback = currentCallback;
  189133. close();
  189134. open (BitArray (currentChansIn), BitArray (currentChansOut),
  189135. currentSampleRate, currentBlockSizeSamples);
  189136. if (oldCallback != 0)
  189137. start (oldCallback);
  189138. }
  189139. }
  189140. else
  189141. {
  189142. startTimer (100);
  189143. }
  189144. }
  189145. juce_UseDebuggingNewOperator
  189146. private:
  189147. IASIO* volatile asioObject;
  189148. ASIOCallbacks callbacks;
  189149. void* windowHandle;
  189150. CLSID classId;
  189151. const String optionalDllForDirectLoading;
  189152. String error;
  189153. long totalNumInputChans, totalNumOutputChans;
  189154. StringArray inputChannelNames, outputChannelNames;
  189155. Array<int> sampleRates, bufferSizes;
  189156. long inputLatency, outputLatency;
  189157. long minSize, maxSize, preferredSize, granularity;
  189158. int volatile currentBlockSizeSamples;
  189159. int volatile currentBitDepth;
  189160. double volatile currentSampleRate;
  189161. BitArray currentChansOut, currentChansIn;
  189162. AudioIODeviceCallback* volatile currentCallback;
  189163. CriticalSection callbackLock;
  189164. ASIOBufferInfo bufferInfos [maxASIOChannels];
  189165. float* inBuffers [maxASIOChannels];
  189166. float* outBuffers [maxASIOChannels];
  189167. int inputChannelBitDepths [maxASIOChannels];
  189168. int outputChannelBitDepths [maxASIOChannels];
  189169. int inputChannelBytesPerSample [maxASIOChannels];
  189170. int outputChannelBytesPerSample [maxASIOChannels];
  189171. bool inputChannelIsFloat [maxASIOChannels];
  189172. bool outputChannelIsFloat [maxASIOChannels];
  189173. bool inputChannelLittleEndian [maxASIOChannels];
  189174. bool outputChannelLittleEndian [maxASIOChannels];
  189175. WaitableEvent event1;
  189176. HeapBlock <float> tempBuffer;
  189177. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  189178. bool isOpen_, isStarted;
  189179. bool volatile isASIOOpen;
  189180. bool volatile calledback;
  189181. bool volatile littleEndian, postOutput, needToReset, isReSync;
  189182. bool volatile insideControlPanelModalLoop;
  189183. bool volatile shouldUsePreferredSize;
  189184. void removeCurrentDriver()
  189185. {
  189186. if (asioObject != 0)
  189187. {
  189188. asioObject->Release();
  189189. asioObject = 0;
  189190. }
  189191. }
  189192. bool loadDriver()
  189193. {
  189194. removeCurrentDriver();
  189195. JUCE_TRY
  189196. {
  189197. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  189198. classId, (void**) &asioObject) == S_OK)
  189199. {
  189200. return true;
  189201. }
  189202. // If a class isn't registered but we have a path for it, we can fallback to
  189203. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  189204. if (optionalDllForDirectLoading.isNotEmpty())
  189205. {
  189206. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  189207. if (h != 0)
  189208. {
  189209. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  189210. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  189211. if (dllGetClassObject != 0)
  189212. {
  189213. IClassFactory* classFactory = 0;
  189214. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  189215. if (classFactory != 0)
  189216. {
  189217. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  189218. classFactory->Release();
  189219. }
  189220. return asioObject != 0;
  189221. }
  189222. }
  189223. }
  189224. }
  189225. JUCE_CATCH_ALL
  189226. asioObject = 0;
  189227. return false;
  189228. }
  189229. const String initDriver()
  189230. {
  189231. if (asioObject != 0)
  189232. {
  189233. char buffer [256];
  189234. zeromem (buffer, sizeof (buffer));
  189235. if (! asioObject->init (windowHandle))
  189236. {
  189237. asioObject->getErrorMessage (buffer);
  189238. return String (buffer, sizeof (buffer) - 1);
  189239. }
  189240. // just in case any daft drivers expect this to be called..
  189241. asioObject->getDriverName (buffer);
  189242. return String::empty;
  189243. }
  189244. return "No Driver";
  189245. }
  189246. const String openDevice()
  189247. {
  189248. // use this in case the driver starts opening dialog boxes..
  189249. Component modalWindow (String::empty);
  189250. modalWindow.setOpaque (true);
  189251. modalWindow.addToDesktop (0);
  189252. modalWindow.enterModalState();
  189253. // open the device and get its info..
  189254. log (T("opening ASIO device: ") + getName());
  189255. needToReset = false;
  189256. isReSync = false;
  189257. outputChannelNames.clear();
  189258. inputChannelNames.clear();
  189259. bufferSizes.clear();
  189260. sampleRates.clear();
  189261. isASIOOpen = false;
  189262. isOpen_ = false;
  189263. totalNumInputChans = 0;
  189264. totalNumOutputChans = 0;
  189265. numActiveInputChans = 0;
  189266. numActiveOutputChans = 0;
  189267. currentCallback = 0;
  189268. error = String::empty;
  189269. if (getName().isEmpty())
  189270. return error;
  189271. long err = 0;
  189272. if (loadDriver())
  189273. {
  189274. if ((error = initDriver()).isEmpty())
  189275. {
  189276. numActiveInputChans = 0;
  189277. numActiveOutputChans = 0;
  189278. totalNumInputChans = 0;
  189279. totalNumOutputChans = 0;
  189280. if (asioObject != 0
  189281. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  189282. {
  189283. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  189284. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189285. {
  189286. // find a list of buffer sizes..
  189287. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  189288. if (granularity >= 0)
  189289. {
  189290. granularity = jmax (1, (int) granularity);
  189291. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  189292. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  189293. }
  189294. else if (granularity < 0)
  189295. {
  189296. for (int i = 0; i < 18; ++i)
  189297. {
  189298. const int s = (1 << i);
  189299. if (s >= minSize && s <= maxSize)
  189300. bufferSizes.add (s);
  189301. }
  189302. }
  189303. if (! bufferSizes.contains (preferredSize))
  189304. bufferSizes.insert (0, preferredSize);
  189305. double currentRate = 0;
  189306. asioObject->getSampleRate (&currentRate);
  189307. if (currentRate <= 0.0 || currentRate > 192001.0)
  189308. {
  189309. log ("setting sample rate");
  189310. err = asioObject->setSampleRate (44100.0);
  189311. if (err != 0)
  189312. {
  189313. logError ("setting sample rate", err);
  189314. }
  189315. asioObject->getSampleRate (&currentRate);
  189316. }
  189317. currentSampleRate = currentRate;
  189318. postOutput = (asioObject->outputReady() == 0);
  189319. if (postOutput)
  189320. {
  189321. log ("ASIO outputReady = ok");
  189322. }
  189323. updateSampleRates();
  189324. // ..because cubase does it at this point
  189325. inputLatency = outputLatency = 0;
  189326. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189327. {
  189328. log ("ASIO - no latencies");
  189329. }
  189330. log (String ("latencies: ")
  189331. + String ((int) inputLatency)
  189332. + T(", ") + String ((int) outputLatency));
  189333. // create some dummy buffers now.. because cubase does..
  189334. numActiveInputChans = 0;
  189335. numActiveOutputChans = 0;
  189336. ASIOBufferInfo* info = bufferInfos;
  189337. int i, numChans = 0;
  189338. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189339. {
  189340. info->isInput = 1;
  189341. info->channelNum = i;
  189342. info->buffers[0] = info->buffers[1] = 0;
  189343. ++info;
  189344. ++numChans;
  189345. }
  189346. const int outputBufferIndex = numChans;
  189347. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189348. {
  189349. info->isInput = 0;
  189350. info->channelNum = i;
  189351. info->buffers[0] = info->buffers[1] = 0;
  189352. ++info;
  189353. ++numChans;
  189354. }
  189355. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189356. if (currentASIODev[0] == this)
  189357. {
  189358. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189359. callbacks.asioMessage = &asioMessagesCallback0;
  189360. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189361. }
  189362. else if (currentASIODev[1] == this)
  189363. {
  189364. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189365. callbacks.asioMessage = &asioMessagesCallback1;
  189366. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189367. }
  189368. else if (currentASIODev[2] == this)
  189369. {
  189370. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189371. callbacks.asioMessage = &asioMessagesCallback2;
  189372. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189373. }
  189374. else
  189375. {
  189376. jassertfalse
  189377. }
  189378. log (T("creating buffers (dummy): ") + String (numChans)
  189379. + T(", ") + String ((int) preferredSize));
  189380. if (preferredSize > 0)
  189381. {
  189382. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189383. if (err != 0)
  189384. {
  189385. logError ("dummy buffers", err);
  189386. }
  189387. }
  189388. long newInps = 0, newOuts = 0;
  189389. asioObject->getChannels (&newInps, &newOuts);
  189390. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189391. {
  189392. totalNumInputChans = newInps;
  189393. totalNumOutputChans = newOuts;
  189394. log (String ((int) totalNumInputChans) + T(" in; ")
  189395. + String ((int) totalNumOutputChans) + T(" out"));
  189396. }
  189397. updateSampleRates();
  189398. ASIOChannelInfo channelInfo;
  189399. channelInfo.type = 0;
  189400. for (i = 0; i < totalNumInputChans; ++i)
  189401. {
  189402. zerostruct (channelInfo);
  189403. channelInfo.channel = i;
  189404. channelInfo.isInput = 1;
  189405. asioObject->getChannelInfo (&channelInfo);
  189406. inputChannelNames.add (String (channelInfo.name));
  189407. }
  189408. for (i = 0; i < totalNumOutputChans; ++i)
  189409. {
  189410. zerostruct (channelInfo);
  189411. channelInfo.channel = i;
  189412. channelInfo.isInput = 0;
  189413. asioObject->getChannelInfo (&channelInfo);
  189414. outputChannelNames.add (String (channelInfo.name));
  189415. typeToFormatParameters (channelInfo.type,
  189416. outputChannelBitDepths[i],
  189417. outputChannelBytesPerSample[i],
  189418. outputChannelIsFloat[i],
  189419. outputChannelLittleEndian[i]);
  189420. if (i < 2)
  189421. {
  189422. // clear the channels that are used with the dummy stuff
  189423. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189424. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189425. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189426. }
  189427. }
  189428. outputChannelNames.trim();
  189429. inputChannelNames.trim();
  189430. outputChannelNames.appendNumbersToDuplicates (false, true);
  189431. inputChannelNames.appendNumbersToDuplicates (false, true);
  189432. // start and stop because cubase does it..
  189433. asioObject->getLatencies (&inputLatency, &outputLatency);
  189434. if ((err = asioObject->start()) != 0)
  189435. {
  189436. // ignore an error here, as it might start later after setting other stuff up
  189437. logError ("ASIO start", err);
  189438. }
  189439. Thread::sleep (100);
  189440. asioObject->stop();
  189441. }
  189442. else
  189443. {
  189444. error = "Can't detect buffer sizes";
  189445. }
  189446. }
  189447. else
  189448. {
  189449. error = "Can't detect asio channels";
  189450. }
  189451. }
  189452. }
  189453. else
  189454. {
  189455. error = "No such device";
  189456. }
  189457. if (error.isNotEmpty())
  189458. {
  189459. logError (error, err);
  189460. if (asioObject != 0)
  189461. asioObject->disposeBuffers();
  189462. removeCurrentDriver();
  189463. isASIOOpen = false;
  189464. }
  189465. else
  189466. {
  189467. isASIOOpen = true;
  189468. log ("ASIO device open");
  189469. }
  189470. isOpen_ = false;
  189471. needToReset = false;
  189472. isReSync = false;
  189473. return error;
  189474. }
  189475. void callback (const long index) throw()
  189476. {
  189477. if (isStarted)
  189478. {
  189479. bufferIndex = index;
  189480. processBuffer();
  189481. }
  189482. else
  189483. {
  189484. if (postOutput && (asioObject != 0))
  189485. asioObject->outputReady();
  189486. }
  189487. calledback = true;
  189488. }
  189489. void processBuffer() throw()
  189490. {
  189491. const ASIOBufferInfo* const infos = bufferInfos;
  189492. const int bi = bufferIndex;
  189493. const ScopedLock sl (callbackLock);
  189494. if (needToReset)
  189495. {
  189496. needToReset = false;
  189497. if (isReSync)
  189498. {
  189499. log ("! ASIO resync");
  189500. isReSync = false;
  189501. }
  189502. else
  189503. {
  189504. startTimer (20);
  189505. }
  189506. }
  189507. if (bi >= 0)
  189508. {
  189509. const int samps = currentBlockSizeSamples;
  189510. if (currentCallback != 0)
  189511. {
  189512. int i;
  189513. for (i = 0; i < numActiveInputChans; ++i)
  189514. {
  189515. float* const dst = inBuffers[i];
  189516. jassert (dst != 0);
  189517. const char* const src = (const char*) (infos[i].buffers[bi]);
  189518. if (inputChannelIsFloat[i])
  189519. {
  189520. memcpy (dst, src, samps * sizeof (float));
  189521. }
  189522. else
  189523. {
  189524. jassert (dst == tempBuffer + (samps * i));
  189525. switch (inputChannelBitDepths[i])
  189526. {
  189527. case 16:
  189528. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189529. samps, inputChannelLittleEndian[i]);
  189530. break;
  189531. case 24:
  189532. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189533. samps, inputChannelLittleEndian[i]);
  189534. break;
  189535. case 32:
  189536. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189537. samps, inputChannelLittleEndian[i]);
  189538. break;
  189539. case 64:
  189540. jassertfalse
  189541. break;
  189542. }
  189543. }
  189544. }
  189545. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189546. numActiveInputChans,
  189547. outBuffers,
  189548. numActiveOutputChans,
  189549. samps);
  189550. for (i = 0; i < numActiveOutputChans; ++i)
  189551. {
  189552. float* const src = outBuffers[i];
  189553. jassert (src != 0);
  189554. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189555. if (outputChannelIsFloat[i])
  189556. {
  189557. memcpy (dst, src, samps * sizeof (float));
  189558. }
  189559. else
  189560. {
  189561. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189562. switch (outputChannelBitDepths[i])
  189563. {
  189564. case 16:
  189565. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189566. samps, outputChannelLittleEndian[i]);
  189567. break;
  189568. case 24:
  189569. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189570. samps, outputChannelLittleEndian[i]);
  189571. break;
  189572. case 32:
  189573. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189574. samps, outputChannelLittleEndian[i]);
  189575. break;
  189576. case 64:
  189577. jassertfalse
  189578. break;
  189579. }
  189580. }
  189581. }
  189582. }
  189583. else
  189584. {
  189585. for (int i = 0; i < numActiveOutputChans; ++i)
  189586. {
  189587. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189588. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189589. }
  189590. }
  189591. }
  189592. if (postOutput)
  189593. asioObject->outputReady();
  189594. }
  189595. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189596. {
  189597. if (currentASIODev[0] != 0)
  189598. currentASIODev[0]->callback (index);
  189599. return 0;
  189600. }
  189601. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189602. {
  189603. if (currentASIODev[1] != 0)
  189604. currentASIODev[1]->callback (index);
  189605. return 0;
  189606. }
  189607. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189608. {
  189609. if (currentASIODev[2] != 0)
  189610. currentASIODev[2]->callback (index);
  189611. return 0;
  189612. }
  189613. static void bufferSwitchCallback0 (long index, long) throw()
  189614. {
  189615. if (currentASIODev[0] != 0)
  189616. currentASIODev[0]->callback (index);
  189617. }
  189618. static void bufferSwitchCallback1 (long index, long) throw()
  189619. {
  189620. if (currentASIODev[1] != 0)
  189621. currentASIODev[1]->callback (index);
  189622. }
  189623. static void bufferSwitchCallback2 (long index, long) throw()
  189624. {
  189625. if (currentASIODev[2] != 0)
  189626. currentASIODev[2]->callback (index);
  189627. }
  189628. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189629. {
  189630. return asioMessagesCallback (selector, value, 0);
  189631. }
  189632. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189633. {
  189634. return asioMessagesCallback (selector, value, 1);
  189635. }
  189636. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189637. {
  189638. return asioMessagesCallback (selector, value, 2);
  189639. }
  189640. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189641. {
  189642. switch (selector)
  189643. {
  189644. case kAsioSelectorSupported:
  189645. if (value == kAsioResetRequest
  189646. || value == kAsioEngineVersion
  189647. || value == kAsioResyncRequest
  189648. || value == kAsioLatenciesChanged
  189649. || value == kAsioSupportsInputMonitor)
  189650. return 1;
  189651. break;
  189652. case kAsioBufferSizeChange:
  189653. break;
  189654. case kAsioResetRequest:
  189655. if (currentASIODev[deviceIndex] != 0)
  189656. currentASIODev[deviceIndex]->resetRequest();
  189657. return 1;
  189658. case kAsioResyncRequest:
  189659. if (currentASIODev[deviceIndex] != 0)
  189660. currentASIODev[deviceIndex]->resyncRequest();
  189661. return 1;
  189662. case kAsioLatenciesChanged:
  189663. return 1;
  189664. case kAsioEngineVersion:
  189665. return 2;
  189666. case kAsioSupportsTimeInfo:
  189667. case kAsioSupportsTimeCode:
  189668. return 0;
  189669. }
  189670. return 0;
  189671. }
  189672. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189673. {
  189674. }
  189675. static void convertInt16ToFloat (const char* src,
  189676. float* dest,
  189677. const int srcStrideBytes,
  189678. int numSamples,
  189679. const bool littleEndian) throw()
  189680. {
  189681. const double g = 1.0 / 32768.0;
  189682. if (littleEndian)
  189683. {
  189684. while (--numSamples >= 0)
  189685. {
  189686. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189687. src += srcStrideBytes;
  189688. }
  189689. }
  189690. else
  189691. {
  189692. while (--numSamples >= 0)
  189693. {
  189694. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189695. src += srcStrideBytes;
  189696. }
  189697. }
  189698. }
  189699. static void convertFloatToInt16 (const float* src,
  189700. char* dest,
  189701. const int dstStrideBytes,
  189702. int numSamples,
  189703. const bool littleEndian) throw()
  189704. {
  189705. const double maxVal = (double) 0x7fff;
  189706. if (littleEndian)
  189707. {
  189708. while (--numSamples >= 0)
  189709. {
  189710. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189711. dest += dstStrideBytes;
  189712. }
  189713. }
  189714. else
  189715. {
  189716. while (--numSamples >= 0)
  189717. {
  189718. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189719. dest += dstStrideBytes;
  189720. }
  189721. }
  189722. }
  189723. static void convertInt24ToFloat (const char* src,
  189724. float* dest,
  189725. const int srcStrideBytes,
  189726. int numSamples,
  189727. const bool littleEndian) throw()
  189728. {
  189729. const double g = 1.0 / 0x7fffff;
  189730. if (littleEndian)
  189731. {
  189732. while (--numSamples >= 0)
  189733. {
  189734. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189735. src += srcStrideBytes;
  189736. }
  189737. }
  189738. else
  189739. {
  189740. while (--numSamples >= 0)
  189741. {
  189742. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189743. src += srcStrideBytes;
  189744. }
  189745. }
  189746. }
  189747. static void convertFloatToInt24 (const float* src,
  189748. char* dest,
  189749. const int dstStrideBytes,
  189750. int numSamples,
  189751. const bool littleEndian) throw()
  189752. {
  189753. const double maxVal = (double) 0x7fffff;
  189754. if (littleEndian)
  189755. {
  189756. while (--numSamples >= 0)
  189757. {
  189758. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189759. dest += dstStrideBytes;
  189760. }
  189761. }
  189762. else
  189763. {
  189764. while (--numSamples >= 0)
  189765. {
  189766. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189767. dest += dstStrideBytes;
  189768. }
  189769. }
  189770. }
  189771. static void convertInt32ToFloat (const char* src,
  189772. float* dest,
  189773. const int srcStrideBytes,
  189774. int numSamples,
  189775. const bool littleEndian) throw()
  189776. {
  189777. const double g = 1.0 / 0x7fffffff;
  189778. if (littleEndian)
  189779. {
  189780. while (--numSamples >= 0)
  189781. {
  189782. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189783. src += srcStrideBytes;
  189784. }
  189785. }
  189786. else
  189787. {
  189788. while (--numSamples >= 0)
  189789. {
  189790. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189791. src += srcStrideBytes;
  189792. }
  189793. }
  189794. }
  189795. static void convertFloatToInt32 (const float* src,
  189796. char* dest,
  189797. const int dstStrideBytes,
  189798. int numSamples,
  189799. const bool littleEndian) throw()
  189800. {
  189801. const double maxVal = (double) 0x7fffffff;
  189802. if (littleEndian)
  189803. {
  189804. while (--numSamples >= 0)
  189805. {
  189806. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189807. dest += dstStrideBytes;
  189808. }
  189809. }
  189810. else
  189811. {
  189812. while (--numSamples >= 0)
  189813. {
  189814. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189815. dest += dstStrideBytes;
  189816. }
  189817. }
  189818. }
  189819. static void typeToFormatParameters (const long type,
  189820. int& bitDepth,
  189821. int& byteStride,
  189822. bool& formatIsFloat,
  189823. bool& littleEndian) throw()
  189824. {
  189825. bitDepth = 0;
  189826. littleEndian = false;
  189827. formatIsFloat = false;
  189828. switch (type)
  189829. {
  189830. case ASIOSTInt16MSB:
  189831. case ASIOSTInt16LSB:
  189832. case ASIOSTInt32MSB16:
  189833. case ASIOSTInt32LSB16:
  189834. bitDepth = 16; break;
  189835. case ASIOSTFloat32MSB:
  189836. case ASIOSTFloat32LSB:
  189837. formatIsFloat = true;
  189838. bitDepth = 32; break;
  189839. case ASIOSTInt32MSB:
  189840. case ASIOSTInt32LSB:
  189841. bitDepth = 32; break;
  189842. case ASIOSTInt24MSB:
  189843. case ASIOSTInt24LSB:
  189844. case ASIOSTInt32MSB24:
  189845. case ASIOSTInt32LSB24:
  189846. case ASIOSTInt32MSB18:
  189847. case ASIOSTInt32MSB20:
  189848. case ASIOSTInt32LSB18:
  189849. case ASIOSTInt32LSB20:
  189850. bitDepth = 24; break;
  189851. case ASIOSTFloat64MSB:
  189852. case ASIOSTFloat64LSB:
  189853. default:
  189854. bitDepth = 64;
  189855. break;
  189856. }
  189857. switch (type)
  189858. {
  189859. case ASIOSTInt16MSB:
  189860. case ASIOSTInt32MSB16:
  189861. case ASIOSTFloat32MSB:
  189862. case ASIOSTFloat64MSB:
  189863. case ASIOSTInt32MSB:
  189864. case ASIOSTInt32MSB18:
  189865. case ASIOSTInt32MSB20:
  189866. case ASIOSTInt32MSB24:
  189867. case ASIOSTInt24MSB:
  189868. littleEndian = false; break;
  189869. case ASIOSTInt16LSB:
  189870. case ASIOSTInt32LSB16:
  189871. case ASIOSTFloat32LSB:
  189872. case ASIOSTFloat64LSB:
  189873. case ASIOSTInt32LSB:
  189874. case ASIOSTInt32LSB18:
  189875. case ASIOSTInt32LSB20:
  189876. case ASIOSTInt32LSB24:
  189877. case ASIOSTInt24LSB:
  189878. littleEndian = true; break;
  189879. default:
  189880. break;
  189881. }
  189882. switch (type)
  189883. {
  189884. case ASIOSTInt16LSB:
  189885. case ASIOSTInt16MSB:
  189886. byteStride = 2; break;
  189887. case ASIOSTInt24LSB:
  189888. case ASIOSTInt24MSB:
  189889. byteStride = 3; break;
  189890. case ASIOSTInt32MSB16:
  189891. case ASIOSTInt32LSB16:
  189892. case ASIOSTInt32MSB:
  189893. case ASIOSTInt32MSB18:
  189894. case ASIOSTInt32MSB20:
  189895. case ASIOSTInt32MSB24:
  189896. case ASIOSTInt32LSB:
  189897. case ASIOSTInt32LSB18:
  189898. case ASIOSTInt32LSB20:
  189899. case ASIOSTInt32LSB24:
  189900. case ASIOSTFloat32LSB:
  189901. case ASIOSTFloat32MSB:
  189902. byteStride = 4; break;
  189903. case ASIOSTFloat64MSB:
  189904. case ASIOSTFloat64LSB:
  189905. byteStride = 8; break;
  189906. default:
  189907. break;
  189908. }
  189909. }
  189910. };
  189911. class ASIOAudioIODeviceType : public AudioIODeviceType
  189912. {
  189913. public:
  189914. ASIOAudioIODeviceType()
  189915. : AudioIODeviceType (T("ASIO")),
  189916. hasScanned (false)
  189917. {
  189918. CoInitialize (0);
  189919. }
  189920. ~ASIOAudioIODeviceType()
  189921. {
  189922. }
  189923. void scanForDevices()
  189924. {
  189925. hasScanned = true;
  189926. deviceNames.clear();
  189927. classIds.clear();
  189928. HKEY hk = 0;
  189929. int index = 0;
  189930. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189931. {
  189932. for (;;)
  189933. {
  189934. char name [256];
  189935. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189936. {
  189937. addDriverInfo (name, hk);
  189938. }
  189939. else
  189940. {
  189941. break;
  189942. }
  189943. }
  189944. RegCloseKey (hk);
  189945. }
  189946. }
  189947. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  189948. {
  189949. jassert (hasScanned); // need to call scanForDevices() before doing this
  189950. return deviceNames;
  189951. }
  189952. int getDefaultDeviceIndex (const bool) const
  189953. {
  189954. jassert (hasScanned); // need to call scanForDevices() before doing this
  189955. for (int i = deviceNames.size(); --i >= 0;)
  189956. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  189957. return i; // asio4all is a safe choice for a default..
  189958. #if JUCE_DEBUG
  189959. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  189960. return 1; // (the digi m-box driver crashes the app when you run
  189961. // it in the debugger, which can be a bit annoying)
  189962. #endif
  189963. return 0;
  189964. }
  189965. static int findFreeSlot()
  189966. {
  189967. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189968. if (currentASIODev[i] == 0)
  189969. return i;
  189970. jassertfalse; // unfortunately you can only have a finite number
  189971. // of ASIO devices open at the same time..
  189972. return -1;
  189973. }
  189974. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  189975. {
  189976. jassert (hasScanned); // need to call scanForDevices() before doing this
  189977. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189978. }
  189979. bool hasSeparateInputsAndOutputs() const { return false; }
  189980. AudioIODevice* createDevice (const String& outputDeviceName,
  189981. const String& inputDeviceName)
  189982. {
  189983. // ASIO can't open two different devices for input and output - they must be the same one.
  189984. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189985. jassert (hasScanned); // need to call scanForDevices() before doing this
  189986. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189987. : inputDeviceName);
  189988. if (index >= 0)
  189989. {
  189990. const int freeSlot = findFreeSlot();
  189991. if (freeSlot >= 0)
  189992. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189993. }
  189994. return 0;
  189995. }
  189996. juce_UseDebuggingNewOperator
  189997. private:
  189998. StringArray deviceNames;
  189999. OwnedArray <CLSID> classIds;
  190000. bool hasScanned;
  190001. static bool checkClassIsOk (const String& classId)
  190002. {
  190003. HKEY hk = 0;
  190004. bool ok = false;
  190005. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  190006. {
  190007. int index = 0;
  190008. for (;;)
  190009. {
  190010. WCHAR buf [512];
  190011. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  190012. {
  190013. if (classId.equalsIgnoreCase (buf))
  190014. {
  190015. HKEY subKey, pathKey;
  190016. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190017. {
  190018. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  190019. {
  190020. WCHAR pathName [1024];
  190021. DWORD dtype = REG_SZ;
  190022. DWORD dsize = sizeof (pathName);
  190023. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  190024. ok = File (pathName).exists();
  190025. RegCloseKey (pathKey);
  190026. }
  190027. RegCloseKey (subKey);
  190028. }
  190029. break;
  190030. }
  190031. }
  190032. else
  190033. {
  190034. break;
  190035. }
  190036. }
  190037. RegCloseKey (hk);
  190038. }
  190039. return ok;
  190040. }
  190041. void addDriverInfo (const String& keyName, HKEY hk)
  190042. {
  190043. HKEY subKey;
  190044. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190045. {
  190046. WCHAR buf [256];
  190047. zerostruct (buf);
  190048. DWORD dtype = REG_SZ;
  190049. DWORD dsize = sizeof (buf);
  190050. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190051. {
  190052. if (dsize > 0 && checkClassIsOk (buf))
  190053. {
  190054. CLSID classId;
  190055. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  190056. {
  190057. dtype = REG_SZ;
  190058. dsize = sizeof (buf);
  190059. String deviceName;
  190060. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190061. deviceName = buf;
  190062. else
  190063. deviceName = keyName;
  190064. log (T("found ") + deviceName);
  190065. deviceNames.add (deviceName);
  190066. classIds.add (new CLSID (classId));
  190067. }
  190068. }
  190069. RegCloseKey (subKey);
  190070. }
  190071. }
  190072. }
  190073. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  190074. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  190075. };
  190076. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  190077. {
  190078. return new ASIOAudioIODeviceType();
  190079. }
  190080. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  190081. void* guid,
  190082. const String& optionalDllForDirectLoading)
  190083. {
  190084. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  190085. if (freeSlot < 0)
  190086. return 0;
  190087. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  190088. }
  190089. #undef log
  190090. #endif
  190091. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  190092. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  190093. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190094. // compiled on its own).
  190095. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  190096. END_JUCE_NAMESPACE
  190097. extern "C"
  190098. {
  190099. // Declare just the minimum number of interfaces for the DSound objects that we need..
  190100. typedef struct typeDSBUFFERDESC
  190101. {
  190102. DWORD dwSize;
  190103. DWORD dwFlags;
  190104. DWORD dwBufferBytes;
  190105. DWORD dwReserved;
  190106. LPWAVEFORMATEX lpwfxFormat;
  190107. GUID guid3DAlgorithm;
  190108. } DSBUFFERDESC;
  190109. struct IDirectSoundBuffer;
  190110. #undef INTERFACE
  190111. #define INTERFACE IDirectSound
  190112. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  190113. {
  190114. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190115. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190116. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190117. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  190118. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190119. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  190120. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  190121. STDMETHOD(Compact) (THIS) PURE;
  190122. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  190123. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  190124. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190125. };
  190126. #undef INTERFACE
  190127. #define INTERFACE IDirectSoundBuffer
  190128. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  190129. {
  190130. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190131. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190132. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190133. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190134. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190135. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190136. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  190137. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  190138. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  190139. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190140. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  190141. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190142. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  190143. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  190144. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  190145. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  190146. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  190147. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  190148. STDMETHOD(Stop) (THIS) PURE;
  190149. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190150. STDMETHOD(Restore) (THIS) PURE;
  190151. };
  190152. typedef struct typeDSCBUFFERDESC
  190153. {
  190154. DWORD dwSize;
  190155. DWORD dwFlags;
  190156. DWORD dwBufferBytes;
  190157. DWORD dwReserved;
  190158. LPWAVEFORMATEX lpwfxFormat;
  190159. } DSCBUFFERDESC;
  190160. struct IDirectSoundCaptureBuffer;
  190161. #undef INTERFACE
  190162. #define INTERFACE IDirectSoundCapture
  190163. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  190164. {
  190165. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190166. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190167. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190168. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  190169. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190170. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190171. };
  190172. #undef INTERFACE
  190173. #define INTERFACE IDirectSoundCaptureBuffer
  190174. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  190175. {
  190176. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190177. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190178. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190179. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190180. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190181. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190182. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190183. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  190184. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190185. STDMETHOD(Start) (THIS_ DWORD) PURE;
  190186. STDMETHOD(Stop) (THIS) PURE;
  190187. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190188. };
  190189. };
  190190. BEGIN_JUCE_NAMESPACE
  190191. static const String getDSErrorMessage (HRESULT hr)
  190192. {
  190193. const char* result = 0;
  190194. switch (hr)
  190195. {
  190196. case MAKE_HRESULT(1, 0x878, 10):
  190197. result = "Device already allocated";
  190198. break;
  190199. case MAKE_HRESULT(1, 0x878, 30):
  190200. result = "Control unavailable";
  190201. break;
  190202. case E_INVALIDARG:
  190203. result = "Invalid parameter";
  190204. break;
  190205. case MAKE_HRESULT(1, 0x878, 50):
  190206. result = "Invalid call";
  190207. break;
  190208. case E_FAIL:
  190209. result = "Generic error";
  190210. break;
  190211. case MAKE_HRESULT(1, 0x878, 70):
  190212. result = "Priority level error";
  190213. break;
  190214. case E_OUTOFMEMORY:
  190215. result = "Out of memory";
  190216. break;
  190217. case MAKE_HRESULT(1, 0x878, 100):
  190218. result = "Bad format";
  190219. break;
  190220. case E_NOTIMPL:
  190221. result = "Unsupported function";
  190222. break;
  190223. case MAKE_HRESULT(1, 0x878, 120):
  190224. result = "No driver";
  190225. break;
  190226. case MAKE_HRESULT(1, 0x878, 130):
  190227. result = "Already initialised";
  190228. break;
  190229. case CLASS_E_NOAGGREGATION:
  190230. result = "No aggregation";
  190231. break;
  190232. case MAKE_HRESULT(1, 0x878, 150):
  190233. result = "Buffer lost";
  190234. break;
  190235. case MAKE_HRESULT(1, 0x878, 160):
  190236. result = "Another app has priority";
  190237. break;
  190238. case MAKE_HRESULT(1, 0x878, 170):
  190239. result = "Uninitialised";
  190240. break;
  190241. case E_NOINTERFACE:
  190242. result = "No interface";
  190243. break;
  190244. case S_OK:
  190245. result = "No error";
  190246. break;
  190247. default:
  190248. return "Unknown error: " + String ((int) hr);
  190249. }
  190250. return result;
  190251. }
  190252. #define DS_DEBUGGING 1
  190253. #ifdef DS_DEBUGGING
  190254. #define CATCH JUCE_CATCH_EXCEPTION
  190255. #undef log
  190256. #define log(a) Logger::writeToLog(a);
  190257. #undef logError
  190258. #define logError(a) logDSError(a, __LINE__);
  190259. static void logDSError (HRESULT hr, int lineNum)
  190260. {
  190261. if (hr != S_OK)
  190262. {
  190263. String error ("DS error at line ");
  190264. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  190265. log (error);
  190266. }
  190267. }
  190268. #else
  190269. #define CATCH JUCE_CATCH_ALL
  190270. #define log(a)
  190271. #define logError(a)
  190272. #endif
  190273. #define DSOUND_FUNCTION(functionName, params) \
  190274. typedef HRESULT (WINAPI *type##functionName) params; \
  190275. static type##functionName ds##functionName = 0;
  190276. #define DSOUND_FUNCTION_LOAD(functionName) \
  190277. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  190278. jassert (ds##functionName != 0);
  190279. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  190280. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  190281. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  190282. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  190283. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190284. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190285. static void initialiseDSoundFunctions()
  190286. {
  190287. if (dsDirectSoundCreate == 0)
  190288. {
  190289. HMODULE h = LoadLibraryA ("dsound.dll");
  190290. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  190291. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  190292. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  190293. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  190294. }
  190295. }
  190296. class DSoundInternalOutChannel
  190297. {
  190298. String name;
  190299. LPGUID guid;
  190300. int sampleRate, bufferSizeSamples;
  190301. float* leftBuffer;
  190302. float* rightBuffer;
  190303. IDirectSound* pDirectSound;
  190304. IDirectSoundBuffer* pOutputBuffer;
  190305. DWORD writeOffset;
  190306. int totalBytesPerBuffer;
  190307. int bytesPerBuffer;
  190308. unsigned int lastPlayCursor;
  190309. public:
  190310. int bitDepth;
  190311. bool doneFlag;
  190312. DSoundInternalOutChannel (const String& name_,
  190313. LPGUID guid_,
  190314. int rate,
  190315. int bufferSize,
  190316. float* left,
  190317. float* right)
  190318. : name (name_),
  190319. guid (guid_),
  190320. sampleRate (rate),
  190321. bufferSizeSamples (bufferSize),
  190322. leftBuffer (left),
  190323. rightBuffer (right),
  190324. pDirectSound (0),
  190325. pOutputBuffer (0),
  190326. bitDepth (16)
  190327. {
  190328. }
  190329. ~DSoundInternalOutChannel()
  190330. {
  190331. close();
  190332. }
  190333. void close()
  190334. {
  190335. HRESULT hr;
  190336. if (pOutputBuffer != 0)
  190337. {
  190338. JUCE_TRY
  190339. {
  190340. log (T("closing dsound out: ") + name);
  190341. hr = pOutputBuffer->Stop();
  190342. logError (hr);
  190343. }
  190344. CATCH
  190345. JUCE_TRY
  190346. {
  190347. hr = pOutputBuffer->Release();
  190348. logError (hr);
  190349. }
  190350. CATCH
  190351. pOutputBuffer = 0;
  190352. }
  190353. if (pDirectSound != 0)
  190354. {
  190355. JUCE_TRY
  190356. {
  190357. hr = pDirectSound->Release();
  190358. logError (hr);
  190359. }
  190360. CATCH
  190361. pDirectSound = 0;
  190362. }
  190363. }
  190364. const String open()
  190365. {
  190366. log (T("opening dsound out device: ") + name
  190367. + T(" rate=") + String (sampleRate)
  190368. + T(" bits=") + String (bitDepth)
  190369. + T(" buf=") + String (bufferSizeSamples));
  190370. pDirectSound = 0;
  190371. pOutputBuffer = 0;
  190372. writeOffset = 0;
  190373. String error;
  190374. HRESULT hr = E_NOINTERFACE;
  190375. if (dsDirectSoundCreate != 0)
  190376. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190377. if (hr == S_OK)
  190378. {
  190379. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190380. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190381. const int numChannels = 2;
  190382. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190383. logError (hr);
  190384. if (hr == S_OK)
  190385. {
  190386. IDirectSoundBuffer* pPrimaryBuffer;
  190387. DSBUFFERDESC primaryDesc;
  190388. zerostruct (primaryDesc);
  190389. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190390. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190391. primaryDesc.dwBufferBytes = 0;
  190392. primaryDesc.lpwfxFormat = 0;
  190393. log ("opening dsound out step 2");
  190394. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190395. logError (hr);
  190396. if (hr == S_OK)
  190397. {
  190398. WAVEFORMATEX wfFormat;
  190399. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190400. wfFormat.nChannels = (unsigned short) numChannels;
  190401. wfFormat.nSamplesPerSec = sampleRate;
  190402. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190403. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190404. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190405. wfFormat.cbSize = 0;
  190406. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190407. logError (hr);
  190408. if (hr == S_OK)
  190409. {
  190410. DSBUFFERDESC secondaryDesc;
  190411. zerostruct (secondaryDesc);
  190412. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190413. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190414. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190415. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190416. secondaryDesc.lpwfxFormat = &wfFormat;
  190417. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190418. logError (hr);
  190419. if (hr == S_OK)
  190420. {
  190421. log ("opening dsound out step 3");
  190422. DWORD dwDataLen;
  190423. unsigned char* pDSBuffData;
  190424. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190425. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190426. logError (hr);
  190427. if (hr == S_OK)
  190428. {
  190429. zeromem (pDSBuffData, dwDataLen);
  190430. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190431. if (hr == S_OK)
  190432. {
  190433. hr = pOutputBuffer->SetCurrentPosition (0);
  190434. if (hr == S_OK)
  190435. {
  190436. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190437. if (hr == S_OK)
  190438. return String::empty;
  190439. }
  190440. }
  190441. }
  190442. }
  190443. }
  190444. }
  190445. }
  190446. }
  190447. error = getDSErrorMessage (hr);
  190448. close();
  190449. return error;
  190450. }
  190451. void synchronisePosition()
  190452. {
  190453. if (pOutputBuffer != 0)
  190454. {
  190455. DWORD playCursor;
  190456. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190457. }
  190458. }
  190459. bool service()
  190460. {
  190461. if (pOutputBuffer == 0)
  190462. return true;
  190463. DWORD playCursor, writeCursor;
  190464. for (;;)
  190465. {
  190466. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190467. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190468. {
  190469. pOutputBuffer->Restore();
  190470. continue;
  190471. }
  190472. if (hr == S_OK)
  190473. break;
  190474. logError (hr);
  190475. jassertfalse
  190476. return true;
  190477. }
  190478. int playWriteGap = writeCursor - playCursor;
  190479. if (playWriteGap < 0)
  190480. playWriteGap += totalBytesPerBuffer;
  190481. int bytesEmpty = playCursor - writeOffset;
  190482. if (bytesEmpty < 0)
  190483. bytesEmpty += totalBytesPerBuffer;
  190484. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190485. {
  190486. writeOffset = writeCursor;
  190487. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190488. }
  190489. if (bytesEmpty >= bytesPerBuffer)
  190490. {
  190491. LPBYTE lpbuf1 = 0;
  190492. LPBYTE lpbuf2 = 0;
  190493. DWORD dwSize1 = 0;
  190494. DWORD dwSize2 = 0;
  190495. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190496. bytesPerBuffer,
  190497. (void**) &lpbuf1, &dwSize1,
  190498. (void**) &lpbuf2, &dwSize2, 0);
  190499. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190500. {
  190501. pOutputBuffer->Restore();
  190502. hr = pOutputBuffer->Lock (writeOffset,
  190503. bytesPerBuffer,
  190504. (void**) &lpbuf1, &dwSize1,
  190505. (void**) &lpbuf2, &dwSize2, 0);
  190506. }
  190507. if (hr == S_OK)
  190508. {
  190509. if (bitDepth == 16)
  190510. {
  190511. const float gainL = 32767.0f;
  190512. const float gainR = 32767.0f;
  190513. int* dest = (int*)lpbuf1;
  190514. const float* left = leftBuffer;
  190515. const float* right = rightBuffer;
  190516. int samples1 = dwSize1 >> 2;
  190517. int samples2 = dwSize2 >> 2;
  190518. if (left == 0)
  190519. {
  190520. while (--samples1 >= 0)
  190521. {
  190522. int r = roundToInt (gainR * *right++);
  190523. if (r < -32768)
  190524. r = -32768;
  190525. else if (r > 32767)
  190526. r = 32767;
  190527. *dest++ = (r << 16);
  190528. }
  190529. dest = (int*)lpbuf2;
  190530. while (--samples2 >= 0)
  190531. {
  190532. int r = roundToInt (gainR * *right++);
  190533. if (r < -32768)
  190534. r = -32768;
  190535. else if (r > 32767)
  190536. r = 32767;
  190537. *dest++ = (r << 16);
  190538. }
  190539. }
  190540. else if (right == 0)
  190541. {
  190542. while (--samples1 >= 0)
  190543. {
  190544. int l = roundToInt (gainL * *left++);
  190545. if (l < -32768)
  190546. l = -32768;
  190547. else if (l > 32767)
  190548. l = 32767;
  190549. l &= 0xffff;
  190550. *dest++ = l;
  190551. }
  190552. dest = (int*)lpbuf2;
  190553. while (--samples2 >= 0)
  190554. {
  190555. int l = roundToInt (gainL * *left++);
  190556. if (l < -32768)
  190557. l = -32768;
  190558. else if (l > 32767)
  190559. l = 32767;
  190560. l &= 0xffff;
  190561. *dest++ = l;
  190562. }
  190563. }
  190564. else
  190565. {
  190566. while (--samples1 >= 0)
  190567. {
  190568. int l = roundToInt (gainL * *left++);
  190569. if (l < -32768)
  190570. l = -32768;
  190571. else if (l > 32767)
  190572. l = 32767;
  190573. l &= 0xffff;
  190574. int r = roundToInt (gainR * *right++);
  190575. if (r < -32768)
  190576. r = -32768;
  190577. else if (r > 32767)
  190578. r = 32767;
  190579. *dest++ = (r << 16) | l;
  190580. }
  190581. dest = (int*)lpbuf2;
  190582. while (--samples2 >= 0)
  190583. {
  190584. int l = roundToInt (gainL * *left++);
  190585. if (l < -32768)
  190586. l = -32768;
  190587. else if (l > 32767)
  190588. l = 32767;
  190589. l &= 0xffff;
  190590. int r = roundToInt (gainR * *right++);
  190591. if (r < -32768)
  190592. r = -32768;
  190593. else if (r > 32767)
  190594. r = 32767;
  190595. *dest++ = (r << 16) | l;
  190596. }
  190597. }
  190598. }
  190599. else
  190600. {
  190601. jassertfalse
  190602. }
  190603. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190604. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190605. }
  190606. else
  190607. {
  190608. jassertfalse
  190609. logError (hr);
  190610. }
  190611. bytesEmpty -= bytesPerBuffer;
  190612. return true;
  190613. }
  190614. else
  190615. {
  190616. return false;
  190617. }
  190618. }
  190619. };
  190620. struct DSoundInternalInChannel
  190621. {
  190622. String name;
  190623. LPGUID guid;
  190624. int sampleRate, bufferSizeSamples;
  190625. float* leftBuffer;
  190626. float* rightBuffer;
  190627. IDirectSound* pDirectSound;
  190628. IDirectSoundCapture* pDirectSoundCapture;
  190629. IDirectSoundCaptureBuffer* pInputBuffer;
  190630. public:
  190631. unsigned int readOffset;
  190632. int bytesPerBuffer, totalBytesPerBuffer;
  190633. int bitDepth;
  190634. bool doneFlag;
  190635. DSoundInternalInChannel (const String& name_,
  190636. LPGUID guid_,
  190637. int rate,
  190638. int bufferSize,
  190639. float* left,
  190640. float* right)
  190641. : name (name_),
  190642. guid (guid_),
  190643. sampleRate (rate),
  190644. bufferSizeSamples (bufferSize),
  190645. leftBuffer (left),
  190646. rightBuffer (right),
  190647. pDirectSound (0),
  190648. pDirectSoundCapture (0),
  190649. pInputBuffer (0),
  190650. bitDepth (16)
  190651. {
  190652. }
  190653. ~DSoundInternalInChannel()
  190654. {
  190655. close();
  190656. }
  190657. void close()
  190658. {
  190659. HRESULT hr;
  190660. if (pInputBuffer != 0)
  190661. {
  190662. JUCE_TRY
  190663. {
  190664. log (T("closing dsound in: ") + name);
  190665. hr = pInputBuffer->Stop();
  190666. logError (hr);
  190667. }
  190668. CATCH
  190669. JUCE_TRY
  190670. {
  190671. hr = pInputBuffer->Release();
  190672. logError (hr);
  190673. }
  190674. CATCH
  190675. pInputBuffer = 0;
  190676. }
  190677. if (pDirectSoundCapture != 0)
  190678. {
  190679. JUCE_TRY
  190680. {
  190681. hr = pDirectSoundCapture->Release();
  190682. logError (hr);
  190683. }
  190684. CATCH
  190685. pDirectSoundCapture = 0;
  190686. }
  190687. if (pDirectSound != 0)
  190688. {
  190689. JUCE_TRY
  190690. {
  190691. hr = pDirectSound->Release();
  190692. logError (hr);
  190693. }
  190694. CATCH
  190695. pDirectSound = 0;
  190696. }
  190697. }
  190698. const String open()
  190699. {
  190700. log (T("opening dsound in device: ") + name
  190701. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190702. pDirectSound = 0;
  190703. pDirectSoundCapture = 0;
  190704. pInputBuffer = 0;
  190705. readOffset = 0;
  190706. totalBytesPerBuffer = 0;
  190707. String error;
  190708. HRESULT hr = E_NOINTERFACE;
  190709. if (dsDirectSoundCaptureCreate != 0)
  190710. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190711. logError (hr);
  190712. if (hr == S_OK)
  190713. {
  190714. const int numChannels = 2;
  190715. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190716. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190717. WAVEFORMATEX wfFormat;
  190718. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190719. wfFormat.nChannels = (unsigned short)numChannels;
  190720. wfFormat.nSamplesPerSec = sampleRate;
  190721. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190722. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190723. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190724. wfFormat.cbSize = 0;
  190725. DSCBUFFERDESC captureDesc;
  190726. zerostruct (captureDesc);
  190727. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190728. captureDesc.dwFlags = 0;
  190729. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190730. captureDesc.lpwfxFormat = &wfFormat;
  190731. log (T("opening dsound in step 2"));
  190732. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190733. logError (hr);
  190734. if (hr == S_OK)
  190735. {
  190736. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190737. logError (hr);
  190738. if (hr == S_OK)
  190739. return String::empty;
  190740. }
  190741. }
  190742. error = getDSErrorMessage (hr);
  190743. close();
  190744. return error;
  190745. }
  190746. void synchronisePosition()
  190747. {
  190748. if (pInputBuffer != 0)
  190749. {
  190750. DWORD capturePos;
  190751. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190752. }
  190753. }
  190754. bool service()
  190755. {
  190756. if (pInputBuffer == 0)
  190757. return true;
  190758. DWORD capturePos, readPos;
  190759. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190760. logError (hr);
  190761. if (hr != S_OK)
  190762. return true;
  190763. int bytesFilled = readPos - readOffset;
  190764. if (bytesFilled < 0)
  190765. bytesFilled += totalBytesPerBuffer;
  190766. if (bytesFilled >= bytesPerBuffer)
  190767. {
  190768. LPBYTE lpbuf1 = 0;
  190769. LPBYTE lpbuf2 = 0;
  190770. DWORD dwsize1 = 0;
  190771. DWORD dwsize2 = 0;
  190772. HRESULT hr = pInputBuffer->Lock (readOffset,
  190773. bytesPerBuffer,
  190774. (void**) &lpbuf1, &dwsize1,
  190775. (void**) &lpbuf2, &dwsize2, 0);
  190776. if (hr == S_OK)
  190777. {
  190778. if (bitDepth == 16)
  190779. {
  190780. const float g = 1.0f / 32768.0f;
  190781. float* destL = leftBuffer;
  190782. float* destR = rightBuffer;
  190783. int samples1 = dwsize1 >> 2;
  190784. int samples2 = dwsize2 >> 2;
  190785. const short* src = (const short*)lpbuf1;
  190786. if (destL == 0)
  190787. {
  190788. while (--samples1 >= 0)
  190789. {
  190790. ++src;
  190791. *destR++ = *src++ * g;
  190792. }
  190793. src = (const short*)lpbuf2;
  190794. while (--samples2 >= 0)
  190795. {
  190796. ++src;
  190797. *destR++ = *src++ * g;
  190798. }
  190799. }
  190800. else if (destR == 0)
  190801. {
  190802. while (--samples1 >= 0)
  190803. {
  190804. *destL++ = *src++ * g;
  190805. ++src;
  190806. }
  190807. src = (const short*)lpbuf2;
  190808. while (--samples2 >= 0)
  190809. {
  190810. *destL++ = *src++ * g;
  190811. ++src;
  190812. }
  190813. }
  190814. else
  190815. {
  190816. while (--samples1 >= 0)
  190817. {
  190818. *destL++ = *src++ * g;
  190819. *destR++ = *src++ * g;
  190820. }
  190821. src = (const short*)lpbuf2;
  190822. while (--samples2 >= 0)
  190823. {
  190824. *destL++ = *src++ * g;
  190825. *destR++ = *src++ * g;
  190826. }
  190827. }
  190828. }
  190829. else
  190830. {
  190831. jassertfalse
  190832. }
  190833. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190834. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190835. }
  190836. else
  190837. {
  190838. logError (hr);
  190839. jassertfalse
  190840. }
  190841. bytesFilled -= bytesPerBuffer;
  190842. return true;
  190843. }
  190844. else
  190845. {
  190846. return false;
  190847. }
  190848. }
  190849. };
  190850. class DSoundAudioIODevice : public AudioIODevice,
  190851. public Thread
  190852. {
  190853. public:
  190854. DSoundAudioIODevice (const String& deviceName,
  190855. const int outputDeviceIndex_,
  190856. const int inputDeviceIndex_)
  190857. : AudioIODevice (deviceName, "DirectSound"),
  190858. Thread ("Juce DSound"),
  190859. isOpen_ (false),
  190860. isStarted (false),
  190861. outputDeviceIndex (outputDeviceIndex_),
  190862. inputDeviceIndex (inputDeviceIndex_),
  190863. numInputBuffers (0),
  190864. numOutputBuffers (0),
  190865. totalSamplesOut (0),
  190866. sampleRate (0.0),
  190867. inputBuffers (0),
  190868. outputBuffers (0),
  190869. callback (0),
  190870. bufferSizeSamples (0)
  190871. {
  190872. if (outputDeviceIndex_ >= 0)
  190873. {
  190874. outChannels.add (TRANS("Left"));
  190875. outChannels.add (TRANS("Right"));
  190876. }
  190877. if (inputDeviceIndex_ >= 0)
  190878. {
  190879. inChannels.add (TRANS("Left"));
  190880. inChannels.add (TRANS("Right"));
  190881. }
  190882. }
  190883. ~DSoundAudioIODevice()
  190884. {
  190885. close();
  190886. }
  190887. const StringArray getOutputChannelNames()
  190888. {
  190889. return outChannels;
  190890. }
  190891. const StringArray getInputChannelNames()
  190892. {
  190893. return inChannels;
  190894. }
  190895. int getNumSampleRates()
  190896. {
  190897. return 4;
  190898. }
  190899. double getSampleRate (int index)
  190900. {
  190901. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190902. return samps [jlimit (0, 3, index)];
  190903. }
  190904. int getNumBufferSizesAvailable()
  190905. {
  190906. return 50;
  190907. }
  190908. int getBufferSizeSamples (int index)
  190909. {
  190910. int n = 64;
  190911. for (int i = 0; i < index; ++i)
  190912. n += (n < 512) ? 32
  190913. : ((n < 1024) ? 64
  190914. : ((n < 2048) ? 128 : 256));
  190915. return n;
  190916. }
  190917. int getDefaultBufferSize()
  190918. {
  190919. return 2560;
  190920. }
  190921. const String open (const BitArray& inputChannels,
  190922. const BitArray& outputChannels,
  190923. double sampleRate,
  190924. int bufferSizeSamples)
  190925. {
  190926. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190927. isOpen_ = lastError.isEmpty();
  190928. return lastError;
  190929. }
  190930. void close()
  190931. {
  190932. stop();
  190933. if (isOpen_)
  190934. {
  190935. closeDevice();
  190936. isOpen_ = false;
  190937. }
  190938. }
  190939. bool isOpen()
  190940. {
  190941. return isOpen_ && isThreadRunning();
  190942. }
  190943. int getCurrentBufferSizeSamples()
  190944. {
  190945. return bufferSizeSamples;
  190946. }
  190947. double getCurrentSampleRate()
  190948. {
  190949. return sampleRate;
  190950. }
  190951. int getCurrentBitDepth()
  190952. {
  190953. int i, bits = 256;
  190954. for (i = inChans.size(); --i >= 0;)
  190955. bits = jmin (bits, inChans[i]->bitDepth);
  190956. for (i = outChans.size(); --i >= 0;)
  190957. bits = jmin (bits, outChans[i]->bitDepth);
  190958. if (bits > 32)
  190959. bits = 16;
  190960. return bits;
  190961. }
  190962. const BitArray getActiveOutputChannels() const
  190963. {
  190964. return enabledOutputs;
  190965. }
  190966. const BitArray getActiveInputChannels() const
  190967. {
  190968. return enabledInputs;
  190969. }
  190970. int getOutputLatencyInSamples()
  190971. {
  190972. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190973. }
  190974. int getInputLatencyInSamples()
  190975. {
  190976. return getOutputLatencyInSamples();
  190977. }
  190978. void start (AudioIODeviceCallback* call)
  190979. {
  190980. if (isOpen_ && call != 0 && ! isStarted)
  190981. {
  190982. if (! isThreadRunning())
  190983. {
  190984. // something gone wrong and the thread's stopped..
  190985. isOpen_ = false;
  190986. return;
  190987. }
  190988. call->audioDeviceAboutToStart (this);
  190989. const ScopedLock sl (startStopLock);
  190990. callback = call;
  190991. isStarted = true;
  190992. }
  190993. }
  190994. void stop()
  190995. {
  190996. if (isStarted)
  190997. {
  190998. AudioIODeviceCallback* const callbackLocal = callback;
  190999. {
  191000. const ScopedLock sl (startStopLock);
  191001. isStarted = false;
  191002. }
  191003. if (callbackLocal != 0)
  191004. callbackLocal->audioDeviceStopped();
  191005. }
  191006. }
  191007. bool isPlaying()
  191008. {
  191009. return isStarted && isOpen_ && isThreadRunning();
  191010. }
  191011. const String getLastError()
  191012. {
  191013. return lastError;
  191014. }
  191015. juce_UseDebuggingNewOperator
  191016. StringArray inChannels, outChannels;
  191017. int outputDeviceIndex, inputDeviceIndex;
  191018. private:
  191019. bool isOpen_;
  191020. bool isStarted;
  191021. String lastError;
  191022. OwnedArray <DSoundInternalInChannel> inChans;
  191023. OwnedArray <DSoundInternalOutChannel> outChans;
  191024. WaitableEvent startEvent;
  191025. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  191026. int volatile totalSamplesOut;
  191027. int64 volatile lastBlockTime;
  191028. double sampleRate;
  191029. BitArray enabledInputs, enabledOutputs;
  191030. HeapBlock <float*> inputBuffers, outputBuffers;
  191031. AudioIODeviceCallback* callback;
  191032. CriticalSection startStopLock;
  191033. DSoundAudioIODevice (const DSoundAudioIODevice&);
  191034. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  191035. const String openDevice (const BitArray& inputChannels,
  191036. const BitArray& outputChannels,
  191037. double sampleRate_,
  191038. int bufferSizeSamples_);
  191039. void closeDevice()
  191040. {
  191041. isStarted = false;
  191042. stopThread (5000);
  191043. inChans.clear();
  191044. outChans.clear();
  191045. int i;
  191046. for (i = 0; i < numInputBuffers; ++i)
  191047. juce_free (inputBuffers[i]);
  191048. inputBuffers.free();
  191049. numInputBuffers = 0;
  191050. for (i = 0; i < numOutputBuffers; ++i)
  191051. juce_free (outputBuffers[i]);
  191052. outputBuffers.free();
  191053. numOutputBuffers = 0;
  191054. }
  191055. void resync()
  191056. {
  191057. if (! threadShouldExit())
  191058. {
  191059. sleep (5);
  191060. int i;
  191061. for (i = 0; i < outChans.size(); ++i)
  191062. outChans.getUnchecked(i)->synchronisePosition();
  191063. for (i = 0; i < inChans.size(); ++i)
  191064. inChans.getUnchecked(i)->synchronisePosition();
  191065. }
  191066. }
  191067. public:
  191068. void run()
  191069. {
  191070. while (! threadShouldExit())
  191071. {
  191072. if (wait (100))
  191073. break;
  191074. }
  191075. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  191076. const int maxTimeMS = jmax (5, 3 * latencyMs);
  191077. while (! threadShouldExit())
  191078. {
  191079. int numToDo = 0;
  191080. uint32 startTime = Time::getMillisecondCounter();
  191081. int i;
  191082. for (i = inChans.size(); --i >= 0;)
  191083. {
  191084. inChans.getUnchecked(i)->doneFlag = false;
  191085. ++numToDo;
  191086. }
  191087. for (i = outChans.size(); --i >= 0;)
  191088. {
  191089. outChans.getUnchecked(i)->doneFlag = false;
  191090. ++numToDo;
  191091. }
  191092. if (numToDo > 0)
  191093. {
  191094. const int maxCount = 3;
  191095. int count = maxCount;
  191096. for (;;)
  191097. {
  191098. for (i = inChans.size(); --i >= 0;)
  191099. {
  191100. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  191101. if ((! in->doneFlag) && in->service())
  191102. {
  191103. in->doneFlag = true;
  191104. --numToDo;
  191105. }
  191106. }
  191107. for (i = outChans.size(); --i >= 0;)
  191108. {
  191109. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  191110. if ((! out->doneFlag) && out->service())
  191111. {
  191112. out->doneFlag = true;
  191113. --numToDo;
  191114. }
  191115. }
  191116. if (numToDo <= 0)
  191117. break;
  191118. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  191119. {
  191120. resync();
  191121. break;
  191122. }
  191123. if (--count <= 0)
  191124. {
  191125. Sleep (1);
  191126. count = maxCount;
  191127. }
  191128. if (threadShouldExit())
  191129. return;
  191130. }
  191131. }
  191132. else
  191133. {
  191134. sleep (1);
  191135. }
  191136. const ScopedLock sl (startStopLock);
  191137. if (isStarted)
  191138. {
  191139. JUCE_TRY
  191140. {
  191141. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191142. numInputBuffers,
  191143. outputBuffers,
  191144. numOutputBuffers,
  191145. bufferSizeSamples);
  191146. }
  191147. JUCE_CATCH_EXCEPTION
  191148. totalSamplesOut += bufferSizeSamples;
  191149. }
  191150. else
  191151. {
  191152. for (i = 0; i < numOutputBuffers; ++i)
  191153. if (outputBuffers[i] != 0)
  191154. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  191155. totalSamplesOut = 0;
  191156. sleep (1);
  191157. }
  191158. }
  191159. }
  191160. };
  191161. class DSoundAudioIODeviceType : public AudioIODeviceType
  191162. {
  191163. public:
  191164. DSoundAudioIODeviceType()
  191165. : AudioIODeviceType (T("DirectSound")),
  191166. hasScanned (false)
  191167. {
  191168. initialiseDSoundFunctions();
  191169. }
  191170. ~DSoundAudioIODeviceType()
  191171. {
  191172. }
  191173. void scanForDevices()
  191174. {
  191175. hasScanned = true;
  191176. outputDeviceNames.clear();
  191177. outputGuids.clear();
  191178. inputDeviceNames.clear();
  191179. inputGuids.clear();
  191180. if (dsDirectSoundEnumerateW != 0)
  191181. {
  191182. dsDirectSoundEnumerateW (outputEnumProcW, this);
  191183. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  191184. }
  191185. }
  191186. const StringArray getDeviceNames (const bool wantInputNames) const
  191187. {
  191188. jassert (hasScanned); // need to call scanForDevices() before doing this
  191189. return wantInputNames ? inputDeviceNames
  191190. : outputDeviceNames;
  191191. }
  191192. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191193. {
  191194. jassert (hasScanned); // need to call scanForDevices() before doing this
  191195. return 0;
  191196. }
  191197. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191198. {
  191199. jassert (hasScanned); // need to call scanForDevices() before doing this
  191200. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  191201. if (d == 0)
  191202. return -1;
  191203. return asInput ? d->inputDeviceIndex
  191204. : d->outputDeviceIndex;
  191205. }
  191206. bool hasSeparateInputsAndOutputs() const { return true; }
  191207. AudioIODevice* createDevice (const String& outputDeviceName,
  191208. const String& inputDeviceName)
  191209. {
  191210. jassert (hasScanned); // need to call scanForDevices() before doing this
  191211. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191212. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191213. if (outputIndex >= 0 || inputIndex >= 0)
  191214. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191215. : inputDeviceName,
  191216. outputIndex, inputIndex);
  191217. return 0;
  191218. }
  191219. juce_UseDebuggingNewOperator
  191220. StringArray outputDeviceNames;
  191221. OwnedArray <GUID> outputGuids;
  191222. StringArray inputDeviceNames;
  191223. OwnedArray <GUID> inputGuids;
  191224. private:
  191225. bool hasScanned;
  191226. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  191227. {
  191228. desc = desc.trim();
  191229. if (desc.isNotEmpty())
  191230. {
  191231. const String origDesc (desc);
  191232. int n = 2;
  191233. while (outputDeviceNames.contains (desc))
  191234. desc = origDesc + T(" (") + String (n++) + T(")");
  191235. outputDeviceNames.add (desc);
  191236. if (lpGUID != 0)
  191237. outputGuids.add (new GUID (*lpGUID));
  191238. else
  191239. outputGuids.add (0);
  191240. }
  191241. return TRUE;
  191242. }
  191243. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191244. {
  191245. return ((DSoundAudioIODeviceType*) object)
  191246. ->outputEnumProc (lpGUID, String (description));
  191247. }
  191248. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191249. {
  191250. return ((DSoundAudioIODeviceType*) object)
  191251. ->outputEnumProc (lpGUID, String (description));
  191252. }
  191253. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  191254. {
  191255. desc = desc.trim();
  191256. if (desc.isNotEmpty())
  191257. {
  191258. const String origDesc (desc);
  191259. int n = 2;
  191260. while (inputDeviceNames.contains (desc))
  191261. desc = origDesc + T(" (") + String (n++) + T(")");
  191262. inputDeviceNames.add (desc);
  191263. if (lpGUID != 0)
  191264. inputGuids.add (new GUID (*lpGUID));
  191265. else
  191266. inputGuids.add (0);
  191267. }
  191268. return TRUE;
  191269. }
  191270. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191271. {
  191272. return ((DSoundAudioIODeviceType*) object)
  191273. ->inputEnumProc (lpGUID, String (description));
  191274. }
  191275. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191276. {
  191277. return ((DSoundAudioIODeviceType*) object)
  191278. ->inputEnumProc (lpGUID, String (description));
  191279. }
  191280. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  191281. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  191282. };
  191283. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  191284. const BitArray& outputChannels,
  191285. double sampleRate_,
  191286. int bufferSizeSamples_)
  191287. {
  191288. closeDevice();
  191289. totalSamplesOut = 0;
  191290. sampleRate = sampleRate_;
  191291. if (bufferSizeSamples_ <= 0)
  191292. bufferSizeSamples_ = 960; // use as a default size if none is set.
  191293. bufferSizeSamples = bufferSizeSamples_ & ~7;
  191294. DSoundAudioIODeviceType dlh;
  191295. dlh.scanForDevices();
  191296. enabledInputs = inputChannels;
  191297. enabledInputs.setRange (inChannels.size(),
  191298. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  191299. false);
  191300. numInputBuffers = enabledInputs.countNumberOfSetBits();
  191301. inputBuffers.calloc (numInputBuffers + 2);
  191302. int i, numIns = 0;
  191303. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191304. {
  191305. float* left = 0;
  191306. float* right = 0;
  191307. if (enabledInputs[i])
  191308. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191309. if (enabledInputs[i + 1])
  191310. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191311. if (left != 0 || right != 0)
  191312. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191313. dlh.inputGuids [inputDeviceIndex],
  191314. (int) sampleRate, bufferSizeSamples,
  191315. left, right));
  191316. }
  191317. enabledOutputs = outputChannels;
  191318. enabledOutputs.setRange (outChannels.size(),
  191319. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191320. false);
  191321. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191322. outputBuffers.calloc (numOutputBuffers + 2);
  191323. int numOuts = 0;
  191324. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191325. {
  191326. float* left = 0;
  191327. float* right = 0;
  191328. if (enabledOutputs[i])
  191329. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191330. if (enabledOutputs[i + 1])
  191331. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191332. if (left != 0 || right != 0)
  191333. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191334. dlh.outputGuids [outputDeviceIndex],
  191335. (int) sampleRate, bufferSizeSamples,
  191336. left, right));
  191337. }
  191338. String error;
  191339. // boost our priority while opening the devices to try to get better sync between them
  191340. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191341. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191342. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191343. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191344. for (i = 0; i < outChans.size(); ++i)
  191345. {
  191346. error = outChans[i]->open();
  191347. if (error.isNotEmpty())
  191348. {
  191349. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191350. + T(": \"") + error + T("\"");
  191351. break;
  191352. }
  191353. }
  191354. if (error.isEmpty())
  191355. {
  191356. for (i = 0; i < inChans.size(); ++i)
  191357. {
  191358. error = inChans[i]->open();
  191359. if (error.isNotEmpty())
  191360. {
  191361. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191362. + T(": \"") + error + T("\"");
  191363. break;
  191364. }
  191365. }
  191366. }
  191367. if (error.isEmpty())
  191368. {
  191369. totalSamplesOut = 0;
  191370. for (i = 0; i < outChans.size(); ++i)
  191371. outChans.getUnchecked(i)->synchronisePosition();
  191372. for (i = 0; i < inChans.size(); ++i)
  191373. inChans.getUnchecked(i)->synchronisePosition();
  191374. startThread (9);
  191375. sleep (10);
  191376. notify();
  191377. }
  191378. else
  191379. {
  191380. log (error);
  191381. }
  191382. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191383. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191384. return error;
  191385. }
  191386. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191387. {
  191388. return new DSoundAudioIODeviceType();
  191389. }
  191390. #undef log
  191391. #endif
  191392. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191393. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191394. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191395. // compiled on its own).
  191396. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191397. #if 1
  191398. const String getAudioErrorDesc (HRESULT hr)
  191399. {
  191400. const char* e = 0;
  191401. switch (hr)
  191402. {
  191403. case E_POINTER: e = "E_POINTER"; break;
  191404. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191405. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191406. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191407. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191408. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191409. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191410. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191411. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191412. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191413. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191414. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191415. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191416. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191417. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191418. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191419. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191420. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191421. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191422. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191423. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191424. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191425. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191426. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191427. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191428. default: return String::toHexString ((int) hr);
  191429. }
  191430. return e;
  191431. }
  191432. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191433. #define OK(a) wasapi_checkResult(a)
  191434. static bool wasapi_checkResult (HRESULT hr)
  191435. {
  191436. logFailure (hr);
  191437. return SUCCEEDED (hr);
  191438. }
  191439. #else
  191440. #define logFailure(hr) {}
  191441. #define OK(a) SUCCEEDED(a)
  191442. #endif
  191443. static const String wasapi_getDeviceID (IMMDevice* const device)
  191444. {
  191445. String s;
  191446. WCHAR* deviceId = 0;
  191447. if (OK (device->GetId (&deviceId)))
  191448. {
  191449. s = String (deviceId);
  191450. CoTaskMemFree (deviceId);
  191451. }
  191452. return s;
  191453. }
  191454. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191455. {
  191456. EDataFlow flow = eRender;
  191457. ComSmartPtr <IMMEndpoint> endPoint;
  191458. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191459. (void) OK (endPoint->GetDataFlow (&flow));
  191460. return flow;
  191461. }
  191462. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191463. {
  191464. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191465. }
  191466. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191467. {
  191468. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191469. : sizeof (WAVEFORMATEX));
  191470. }
  191471. class WASAPIDeviceBase
  191472. {
  191473. public:
  191474. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191475. : device (device_),
  191476. sampleRate (0),
  191477. numChannels (0),
  191478. actualNumChannels (0),
  191479. defaultSampleRate (0),
  191480. minBufferSize (0),
  191481. defaultBufferSize (0),
  191482. latencySamples (0),
  191483. useExclusiveMode (useExclusiveMode_)
  191484. {
  191485. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191486. ComSmartPtr <IAudioClient> tempClient (createClient());
  191487. if (tempClient == 0)
  191488. return;
  191489. REFERENCE_TIME defaultPeriod, minPeriod;
  191490. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191491. return;
  191492. WAVEFORMATEX* mixFormat = 0;
  191493. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191494. return;
  191495. WAVEFORMATEXTENSIBLE format;
  191496. wasapi_copyWavFormat (format, mixFormat);
  191497. CoTaskMemFree (mixFormat);
  191498. actualNumChannels = numChannels = format.Format.nChannels;
  191499. defaultSampleRate = format.Format.nSamplesPerSec;
  191500. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191501. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191502. FloatElementComparator<double> comparator;
  191503. rates.addSorted (comparator, defaultSampleRate);
  191504. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191505. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191506. {
  191507. if (ratesToTest[i] == defaultSampleRate)
  191508. continue;
  191509. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191510. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191511. (WAVEFORMATEX*) &format, 0)))
  191512. if (! rates.contains (ratesToTest[i]))
  191513. rates.addSorted (comparator, ratesToTest[i]);
  191514. }
  191515. }
  191516. ~WASAPIDeviceBase()
  191517. {
  191518. device = 0;
  191519. CloseHandle (clientEvent);
  191520. }
  191521. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191522. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191523. {
  191524. sampleRate = newSampleRate;
  191525. channels = newChannels;
  191526. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191527. numChannels = channels.getHighestBit() + 1;
  191528. if (numChannels == 0)
  191529. return true;
  191530. client = createClient();
  191531. if (client != 0
  191532. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191533. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191534. {
  191535. channelMaps.clear();
  191536. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191537. if (channels[i])
  191538. channelMaps.add (i);
  191539. REFERENCE_TIME latency;
  191540. if (OK (client->GetStreamLatency (&latency)))
  191541. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191542. (void) OK (client->GetBufferSize (&actualBufferSize));
  191543. return OK (client->SetEventHandle (clientEvent));
  191544. }
  191545. return false;
  191546. }
  191547. void closeClient()
  191548. {
  191549. if (client != 0)
  191550. client->Stop();
  191551. client = 0;
  191552. ResetEvent (clientEvent);
  191553. }
  191554. ComSmartPtr <IMMDevice> device;
  191555. ComSmartPtr <IAudioClient> client;
  191556. double sampleRate, defaultSampleRate;
  191557. int numChannels, actualNumChannels;
  191558. int minBufferSize, defaultBufferSize, latencySamples;
  191559. const bool useExclusiveMode;
  191560. Array <double> rates;
  191561. HANDLE clientEvent;
  191562. BitArray channels;
  191563. AudioDataConverters::DataFormat dataFormat;
  191564. Array <int> channelMaps;
  191565. UINT32 actualBufferSize;
  191566. int bytesPerSample;
  191567. private:
  191568. const ComSmartPtr <IAudioClient> createClient()
  191569. {
  191570. ComSmartPtr <IAudioClient> client;
  191571. if (device != 0)
  191572. {
  191573. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191574. logFailure (hr);
  191575. }
  191576. return client;
  191577. }
  191578. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191579. {
  191580. WAVEFORMATEXTENSIBLE format;
  191581. zerostruct (format);
  191582. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191583. {
  191584. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191585. }
  191586. else
  191587. {
  191588. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191589. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191590. }
  191591. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191592. format.Format.nChannels = (WORD) numChannels;
  191593. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191594. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191595. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191596. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191597. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191598. switch (numChannels)
  191599. {
  191600. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191601. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191602. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191603. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191604. 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;
  191605. default: break;
  191606. }
  191607. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191608. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191609. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191610. logFailure (hr);
  191611. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191612. {
  191613. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191614. hr = S_OK;
  191615. }
  191616. CoTaskMemFree (nearestFormat);
  191617. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191618. if (useExclusiveMode)
  191619. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191620. GUID session;
  191621. if (hr == S_OK
  191622. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191623. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191624. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191625. {
  191626. actualNumChannels = format.Format.nChannels;
  191627. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191628. bytesPerSample = format.Format.wBitsPerSample / 8;
  191629. dataFormat = isFloat ? AudioDataConverters::float32LE
  191630. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191631. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191632. : AudioDataConverters::int16LE)));
  191633. return true;
  191634. }
  191635. return false;
  191636. }
  191637. };
  191638. class WASAPIInputDevice : public WASAPIDeviceBase
  191639. {
  191640. public:
  191641. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191642. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191643. reservoir (1, 1)
  191644. {
  191645. }
  191646. ~WASAPIInputDevice()
  191647. {
  191648. close();
  191649. }
  191650. bool open (const double newSampleRate, const BitArray& newChannels)
  191651. {
  191652. reservoirSize = 0;
  191653. reservoirCapacity = 16384;
  191654. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191655. return openClient (newSampleRate, newChannels)
  191656. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191657. }
  191658. void close()
  191659. {
  191660. closeClient();
  191661. captureClient = 0;
  191662. reservoir.setSize (0);
  191663. }
  191664. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191665. {
  191666. if (numChannels <= 0)
  191667. return;
  191668. int offset = 0;
  191669. while (bufferSize > 0)
  191670. {
  191671. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191672. {
  191673. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191674. for (int i = 0; i < numDestBuffers; ++i)
  191675. {
  191676. float* const dest = destBuffers[i] + offset;
  191677. const int srcChan = channelMaps.getUnchecked(i);
  191678. switch (dataFormat)
  191679. {
  191680. case AudioDataConverters::float32LE:
  191681. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191682. break;
  191683. case AudioDataConverters::int32LE:
  191684. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191685. break;
  191686. case AudioDataConverters::int24LE:
  191687. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191688. break;
  191689. case AudioDataConverters::int16LE:
  191690. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191691. break;
  191692. default: jassertfalse; break;
  191693. }
  191694. }
  191695. bufferSize -= samplesToDo;
  191696. offset += samplesToDo;
  191697. reservoirSize -= samplesToDo;
  191698. }
  191699. else
  191700. {
  191701. UINT32 packetLength = 0;
  191702. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191703. break;
  191704. if (packetLength == 0)
  191705. {
  191706. if (thread.threadShouldExit())
  191707. break;
  191708. Thread::sleep (1);
  191709. continue;
  191710. }
  191711. uint8* inputData = 0;
  191712. UINT32 numSamplesAvailable;
  191713. DWORD flags;
  191714. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191715. {
  191716. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191717. for (int i = 0; i < numDestBuffers; ++i)
  191718. {
  191719. float* const dest = destBuffers[i] + offset;
  191720. const int srcChan = channelMaps.getUnchecked(i);
  191721. switch (dataFormat)
  191722. {
  191723. case AudioDataConverters::float32LE:
  191724. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191725. break;
  191726. case AudioDataConverters::int32LE:
  191727. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191728. break;
  191729. case AudioDataConverters::int24LE:
  191730. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191731. break;
  191732. case AudioDataConverters::int16LE:
  191733. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191734. break;
  191735. default: jassertfalse; break;
  191736. }
  191737. }
  191738. bufferSize -= samplesToDo;
  191739. offset += samplesToDo;
  191740. if (samplesToDo < (int) numSamplesAvailable)
  191741. {
  191742. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191743. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191744. bytesPerSample * actualNumChannels * reservoirSize);
  191745. }
  191746. captureClient->ReleaseBuffer (numSamplesAvailable);
  191747. }
  191748. }
  191749. }
  191750. }
  191751. ComSmartPtr <IAudioCaptureClient> captureClient;
  191752. MemoryBlock reservoir;
  191753. int reservoirSize, reservoirCapacity;
  191754. };
  191755. class WASAPIOutputDevice : public WASAPIDeviceBase
  191756. {
  191757. public:
  191758. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191759. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191760. {
  191761. }
  191762. ~WASAPIOutputDevice()
  191763. {
  191764. close();
  191765. }
  191766. bool open (const double newSampleRate, const BitArray& newChannels)
  191767. {
  191768. return openClient (newSampleRate, newChannels)
  191769. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191770. }
  191771. void close()
  191772. {
  191773. closeClient();
  191774. renderClient = 0;
  191775. }
  191776. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191777. {
  191778. if (numChannels <= 0)
  191779. return;
  191780. int offset = 0;
  191781. while (bufferSize > 0)
  191782. {
  191783. UINT32 padding = 0;
  191784. if (! OK (client->GetCurrentPadding (&padding)))
  191785. return;
  191786. int samplesToDo = useExclusiveMode ? bufferSize
  191787. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191788. if (samplesToDo <= 0)
  191789. {
  191790. if (thread.threadShouldExit())
  191791. break;
  191792. Thread::sleep (0);
  191793. continue;
  191794. }
  191795. uint8* outputData = 0;
  191796. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191797. {
  191798. for (int i = 0; i < numSrcBuffers; ++i)
  191799. {
  191800. const float* const source = srcBuffers[i] + offset;
  191801. const int destChan = channelMaps.getUnchecked(i);
  191802. switch (dataFormat)
  191803. {
  191804. case AudioDataConverters::float32LE:
  191805. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191806. break;
  191807. case AudioDataConverters::int32LE:
  191808. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191809. break;
  191810. case AudioDataConverters::int24LE:
  191811. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191812. break;
  191813. case AudioDataConverters::int16LE:
  191814. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191815. break;
  191816. default: jassertfalse; break;
  191817. }
  191818. }
  191819. renderClient->ReleaseBuffer (samplesToDo, 0);
  191820. offset += samplesToDo;
  191821. bufferSize -= samplesToDo;
  191822. }
  191823. }
  191824. }
  191825. ComSmartPtr <IAudioRenderClient> renderClient;
  191826. };
  191827. class WASAPIAudioIODevice : public AudioIODevice,
  191828. public Thread
  191829. {
  191830. public:
  191831. WASAPIAudioIODevice (const String& deviceName,
  191832. const String& outputDeviceId_,
  191833. const String& inputDeviceId_,
  191834. const bool useExclusiveMode_)
  191835. : AudioIODevice (deviceName, "Windows Audio"),
  191836. Thread ("Juce WASAPI"),
  191837. isOpen_ (false),
  191838. isStarted (false),
  191839. outputDevice (0),
  191840. outputDeviceId (outputDeviceId_),
  191841. inputDevice (0),
  191842. inputDeviceId (inputDeviceId_),
  191843. useExclusiveMode (useExclusiveMode_),
  191844. currentBufferSizeSamples (0),
  191845. currentSampleRate (0),
  191846. callback (0)
  191847. {
  191848. }
  191849. ~WASAPIAudioIODevice()
  191850. {
  191851. close();
  191852. deleteAndZero (inputDevice);
  191853. deleteAndZero (outputDevice);
  191854. }
  191855. bool initialise()
  191856. {
  191857. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191858. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191859. latencyIn = latencyOut = 0;
  191860. Array <double> ratesIn, ratesOut;
  191861. if (createDevices())
  191862. {
  191863. jassert (inputDevice != 0 || outputDevice != 0);
  191864. if (inputDevice != 0 && outputDevice != 0)
  191865. {
  191866. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191867. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191868. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191869. sampleRates = inputDevice->rates;
  191870. sampleRates.removeValuesNotIn (outputDevice->rates);
  191871. }
  191872. else
  191873. {
  191874. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191875. defaultSampleRate = d->defaultSampleRate;
  191876. minBufferSize = d->minBufferSize;
  191877. defaultBufferSize = d->defaultBufferSize;
  191878. sampleRates = d->rates;
  191879. }
  191880. IntegerElementComparator<int> comparator;
  191881. bufferSizes.addSorted (comparator, defaultBufferSize);
  191882. if (minBufferSize != defaultBufferSize)
  191883. bufferSizes.addSorted (comparator, minBufferSize);
  191884. int n = 64;
  191885. for (int i = 0; i < 40; ++i)
  191886. {
  191887. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191888. bufferSizes.addSorted (comparator, n);
  191889. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191890. }
  191891. return true;
  191892. }
  191893. return false;
  191894. }
  191895. const StringArray getOutputChannelNames()
  191896. {
  191897. StringArray outChannels;
  191898. if (outputDevice != 0)
  191899. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191900. outChannels.add ("Output channel " + String (i));
  191901. return outChannels;
  191902. }
  191903. const StringArray getInputChannelNames()
  191904. {
  191905. StringArray inChannels;
  191906. if (inputDevice != 0)
  191907. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191908. inChannels.add ("Input channel " + String (i));
  191909. return inChannels;
  191910. }
  191911. int getNumSampleRates() { return sampleRates.size(); }
  191912. double getSampleRate (int index) { return sampleRates [index]; }
  191913. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191914. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191915. int getDefaultBufferSize() { return defaultBufferSize; }
  191916. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191917. double getCurrentSampleRate() { return currentSampleRate; }
  191918. int getCurrentBitDepth() { return 32; }
  191919. int getOutputLatencyInSamples() { return latencyOut; }
  191920. int getInputLatencyInSamples() { return latencyIn; }
  191921. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  191922. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  191923. const String getLastError() { return lastError; }
  191924. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  191925. double sampleRate, int bufferSizeSamples)
  191926. {
  191927. close();
  191928. lastError = String::empty;
  191929. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191930. {
  191931. lastError = "The input and output devices don't share a common sample rate!";
  191932. return lastError;
  191933. }
  191934. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191935. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191936. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191937. {
  191938. lastError = "Couldn't open the input device!";
  191939. return lastError;
  191940. }
  191941. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191942. {
  191943. close();
  191944. lastError = "Couldn't open the output device!";
  191945. return lastError;
  191946. }
  191947. if (inputDevice != 0)
  191948. ResetEvent (inputDevice->clientEvent);
  191949. if (outputDevice != 0)
  191950. ResetEvent (outputDevice->clientEvent);
  191951. startThread (8);
  191952. Thread::sleep (5);
  191953. if (inputDevice != 0 && inputDevice->client != 0)
  191954. {
  191955. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191956. HRESULT hr = inputDevice->client->Start();
  191957. logFailure (hr); //xxx handle this
  191958. }
  191959. if (outputDevice != 0 && outputDevice->client != 0)
  191960. {
  191961. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191962. HRESULT hr = outputDevice->client->Start();
  191963. logFailure (hr); //xxx handle this
  191964. }
  191965. isOpen_ = true;
  191966. return lastError;
  191967. }
  191968. void close()
  191969. {
  191970. stop();
  191971. if (inputDevice != 0)
  191972. SetEvent (inputDevice->clientEvent);
  191973. if (outputDevice != 0)
  191974. SetEvent (outputDevice->clientEvent);
  191975. stopThread (5000);
  191976. if (inputDevice != 0)
  191977. inputDevice->close();
  191978. if (outputDevice != 0)
  191979. outputDevice->close();
  191980. isOpen_ = false;
  191981. }
  191982. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191983. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191984. void start (AudioIODeviceCallback* call)
  191985. {
  191986. if (isOpen_ && call != 0 && ! isStarted)
  191987. {
  191988. if (! isThreadRunning())
  191989. {
  191990. // something's gone wrong and the thread's stopped..
  191991. isOpen_ = false;
  191992. return;
  191993. }
  191994. call->audioDeviceAboutToStart (this);
  191995. const ScopedLock sl (startStopLock);
  191996. callback = call;
  191997. isStarted = true;
  191998. }
  191999. }
  192000. void stop()
  192001. {
  192002. if (isStarted)
  192003. {
  192004. AudioIODeviceCallback* const callbackLocal = callback;
  192005. {
  192006. const ScopedLock sl (startStopLock);
  192007. isStarted = false;
  192008. }
  192009. if (callbackLocal != 0)
  192010. callbackLocal->audioDeviceStopped();
  192011. }
  192012. }
  192013. void setMMThreadPriority()
  192014. {
  192015. DynamicLibraryLoader dll ("avrt.dll");
  192016. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  192017. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  192018. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  192019. {
  192020. DWORD dummy = 0;
  192021. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  192022. if (h != 0)
  192023. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  192024. }
  192025. }
  192026. void run()
  192027. {
  192028. setMMThreadPriority();
  192029. const int bufferSize = currentBufferSizeSamples;
  192030. HANDLE events[2];
  192031. int numEvents = 0;
  192032. if (inputDevice != 0)
  192033. events [numEvents++] = inputDevice->clientEvent;
  192034. if (outputDevice != 0)
  192035. events [numEvents++] = outputDevice->clientEvent;
  192036. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  192037. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  192038. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  192039. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  192040. float** const inputBuffers = ins.getArrayOfChannels();
  192041. float** const outputBuffers = outs.getArrayOfChannels();
  192042. ins.clear();
  192043. while (! threadShouldExit())
  192044. {
  192045. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  192046. : WaitForMultipleObjects (numEvents, events, true, 1000);
  192047. if (result == WAIT_TIMEOUT)
  192048. continue;
  192049. if (threadShouldExit())
  192050. break;
  192051. if (inputDevice != 0)
  192052. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  192053. // Make the callback..
  192054. {
  192055. const ScopedLock sl (startStopLock);
  192056. if (isStarted)
  192057. {
  192058. JUCE_TRY
  192059. {
  192060. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  192061. numInputBuffers,
  192062. outputBuffers,
  192063. numOutputBuffers,
  192064. bufferSize);
  192065. }
  192066. JUCE_CATCH_EXCEPTION
  192067. }
  192068. else
  192069. {
  192070. outs.clear();
  192071. }
  192072. }
  192073. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  192074. continue;
  192075. if (outputDevice != 0)
  192076. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  192077. }
  192078. }
  192079. juce_UseDebuggingNewOperator
  192080. String outputDeviceId, inputDeviceId;
  192081. String lastError;
  192082. private:
  192083. // Device stats...
  192084. WASAPIInputDevice* inputDevice;
  192085. WASAPIOutputDevice* outputDevice;
  192086. const bool useExclusiveMode;
  192087. double defaultSampleRate;
  192088. int minBufferSize, defaultBufferSize;
  192089. int latencyIn, latencyOut;
  192090. Array <double> sampleRates;
  192091. Array <int> bufferSizes;
  192092. // Active state...
  192093. bool isOpen_, isStarted;
  192094. int currentBufferSizeSamples;
  192095. double currentSampleRate;
  192096. AudioIODeviceCallback* callback;
  192097. CriticalSection startStopLock;
  192098. bool createDevices()
  192099. {
  192100. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192101. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192102. return false;
  192103. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192104. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  192105. return false;
  192106. UINT32 numDevices = 0;
  192107. if (! OK (deviceCollection->GetCount (&numDevices)))
  192108. return false;
  192109. for (UINT32 i = 0; i < numDevices; ++i)
  192110. {
  192111. ComSmartPtr <IMMDevice> device;
  192112. if (! OK (deviceCollection->Item (i, &device)))
  192113. continue;
  192114. const String deviceId (wasapi_getDeviceID (device));
  192115. if (deviceId.isEmpty())
  192116. continue;
  192117. const EDataFlow flow = wasapi_getDataFlow (device);
  192118. if (deviceId == inputDeviceId && flow == eCapture)
  192119. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  192120. else if (deviceId == outputDeviceId && flow == eRender)
  192121. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  192122. }
  192123. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  192124. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  192125. }
  192126. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  192127. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  192128. };
  192129. class WASAPIAudioIODeviceType : public AudioIODeviceType
  192130. {
  192131. public:
  192132. WASAPIAudioIODeviceType()
  192133. : AudioIODeviceType (T("Windows Audio")),
  192134. hasScanned (false)
  192135. {
  192136. }
  192137. ~WASAPIAudioIODeviceType()
  192138. {
  192139. }
  192140. void scanForDevices()
  192141. {
  192142. hasScanned = true;
  192143. outputDeviceNames.clear();
  192144. inputDeviceNames.clear();
  192145. outputDeviceIds.clear();
  192146. inputDeviceIds.clear();
  192147. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192148. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192149. return;
  192150. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  192151. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  192152. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192153. UINT32 numDevices = 0;
  192154. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  192155. && OK (deviceCollection->GetCount (&numDevices))))
  192156. return;
  192157. for (UINT32 i = 0; i < numDevices; ++i)
  192158. {
  192159. ComSmartPtr <IMMDevice> device;
  192160. if (! OK (deviceCollection->Item (i, &device)))
  192161. continue;
  192162. const String deviceId (wasapi_getDeviceID (device));
  192163. DWORD state = 0;
  192164. if (! OK (device->GetState (&state)))
  192165. continue;
  192166. if (state != DEVICE_STATE_ACTIVE)
  192167. continue;
  192168. String name;
  192169. {
  192170. ComSmartPtr <IPropertyStore> properties;
  192171. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  192172. continue;
  192173. PROPVARIANT value;
  192174. PropVariantInit (&value);
  192175. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  192176. name = value.pwszVal;
  192177. PropVariantClear (&value);
  192178. }
  192179. const EDataFlow flow = wasapi_getDataFlow (device);
  192180. if (flow == eRender)
  192181. {
  192182. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  192183. outputDeviceIds.insert (index, deviceId);
  192184. outputDeviceNames.insert (index, name);
  192185. }
  192186. else if (flow == eCapture)
  192187. {
  192188. const int index = (deviceId == defaultCapture) ? 0 : -1;
  192189. inputDeviceIds.insert (index, deviceId);
  192190. inputDeviceNames.insert (index, name);
  192191. }
  192192. }
  192193. inputDeviceNames.appendNumbersToDuplicates (false, false);
  192194. outputDeviceNames.appendNumbersToDuplicates (false, false);
  192195. }
  192196. const StringArray getDeviceNames (const bool wantInputNames) const
  192197. {
  192198. jassert (hasScanned); // need to call scanForDevices() before doing this
  192199. return wantInputNames ? inputDeviceNames
  192200. : outputDeviceNames;
  192201. }
  192202. int getDefaultDeviceIndex (const bool /*forInput*/) const
  192203. {
  192204. jassert (hasScanned); // need to call scanForDevices() before doing this
  192205. return 0;
  192206. }
  192207. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  192208. {
  192209. jassert (hasScanned); // need to call scanForDevices() before doing this
  192210. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  192211. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  192212. : outputDeviceIds.indexOf (d->outputDeviceId));
  192213. }
  192214. bool hasSeparateInputsAndOutputs() const { return true; }
  192215. AudioIODevice* createDevice (const String& outputDeviceName,
  192216. const String& inputDeviceName)
  192217. {
  192218. jassert (hasScanned); // need to call scanForDevices() before doing this
  192219. const bool useExclusiveMode = false;
  192220. WASAPIAudioIODevice* d = 0;
  192221. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  192222. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  192223. if (outputIndex >= 0 || inputIndex >= 0)
  192224. {
  192225. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  192226. : inputDeviceName,
  192227. outputDeviceIds [outputIndex],
  192228. inputDeviceIds [inputIndex],
  192229. useExclusiveMode);
  192230. if (! d->initialise())
  192231. deleteAndZero (d);
  192232. }
  192233. return d;
  192234. }
  192235. juce_UseDebuggingNewOperator
  192236. StringArray outputDeviceNames, outputDeviceIds;
  192237. StringArray inputDeviceNames, inputDeviceIds;
  192238. private:
  192239. bool hasScanned;
  192240. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  192241. {
  192242. String s;
  192243. IMMDevice* dev = 0;
  192244. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  192245. eMultimedia, &dev)))
  192246. {
  192247. WCHAR* deviceId = 0;
  192248. if (OK (dev->GetId (&deviceId)))
  192249. {
  192250. s = String (deviceId);
  192251. CoTaskMemFree (deviceId);
  192252. }
  192253. dev->Release();
  192254. }
  192255. return s;
  192256. }
  192257. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  192258. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  192259. };
  192260. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  192261. {
  192262. return new WASAPIAudioIODeviceType();
  192263. }
  192264. #undef logFailure
  192265. #undef OK
  192266. #endif
  192267. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  192268. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  192269. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  192270. // compiled on its own).
  192271. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  192272. class DShowCameraDeviceInteral : public ChangeBroadcaster
  192273. {
  192274. public:
  192275. DShowCameraDeviceInteral (CameraDevice* const owner_,
  192276. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  192277. const ComSmartPtr <IBaseFilter>& filter_,
  192278. int minWidth, int minHeight,
  192279. int maxWidth, int maxHeight)
  192280. : owner (owner_),
  192281. captureGraphBuilder (captureGraphBuilder_),
  192282. filter (filter_),
  192283. ok (false),
  192284. imageNeedsFlipping (false),
  192285. width (0),
  192286. height (0),
  192287. activeUsers (0),
  192288. recordNextFrameTime (false),
  192289. activeImage (0),
  192290. loadingImage (0)
  192291. {
  192292. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  192293. if (FAILED (hr))
  192294. return;
  192295. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  192296. if (FAILED (hr))
  192297. return;
  192298. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  192299. if (FAILED (hr))
  192300. return;
  192301. {
  192302. ComSmartPtr <IAMStreamConfig> streamConfig;
  192303. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  192304. IID_IAMStreamConfig, (void**) &streamConfig);
  192305. if (streamConfig != 0)
  192306. {
  192307. getVideoSizes (streamConfig);
  192308. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192309. return;
  192310. }
  192311. }
  192312. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192313. if (FAILED (hr))
  192314. return;
  192315. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192316. if (FAILED (hr))
  192317. return;
  192318. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192319. if (FAILED (hr))
  192320. return;
  192321. if (! connectFilters (filter, smartTee))
  192322. return;
  192323. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192324. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192325. if (FAILED (hr))
  192326. return;
  192327. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192328. if (FAILED (hr))
  192329. return;
  192330. AM_MEDIA_TYPE mt;
  192331. zerostruct (mt);
  192332. mt.majortype = MEDIATYPE_Video;
  192333. mt.subtype = MEDIASUBTYPE_RGB24;
  192334. mt.formattype = FORMAT_VideoInfo;
  192335. sampleGrabber->SetMediaType (&mt);
  192336. callback = new GrabberCallback (*this);
  192337. sampleGrabber->SetCallback (callback, 1);
  192338. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192339. if (FAILED (hr))
  192340. return;
  192341. ComSmartPtr <IPin> grabberInputPin;
  192342. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192343. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192344. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192345. return;
  192346. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192347. if (FAILED (hr))
  192348. return;
  192349. zerostruct (mt);
  192350. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192351. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192352. width = pVih->bmiHeader.biWidth;
  192353. height = pVih->bmiHeader.biHeight;
  192354. ComSmartPtr <IBaseFilter> nullFilter;
  192355. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192356. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192357. if (connectFilters (sampleGrabberBase, nullFilter)
  192358. && addGraphToRot())
  192359. {
  192360. activeImage = new Image (Image::RGB, width, height, true);
  192361. loadingImage = new Image (Image::RGB, width, height, true);
  192362. ok = true;
  192363. }
  192364. }
  192365. ~DShowCameraDeviceInteral()
  192366. {
  192367. if (mediaControl != 0)
  192368. mediaControl->Stop();
  192369. removeGraphFromRot();
  192370. for (int i = viewerComps.size(); --i >= 0;)
  192371. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192372. callback = 0;
  192373. graphBuilder = 0;
  192374. sampleGrabber = 0;
  192375. mediaControl = 0;
  192376. filter = 0;
  192377. captureGraphBuilder = 0;
  192378. smartTee = 0;
  192379. smartTeePreviewOutputPin = 0;
  192380. smartTeeCaptureOutputPin = 0;
  192381. asfWriter = 0;
  192382. delete activeImage;
  192383. delete loadingImage;
  192384. }
  192385. void addUser()
  192386. {
  192387. if (ok && activeUsers++ == 0)
  192388. mediaControl->Run();
  192389. }
  192390. void removeUser()
  192391. {
  192392. if (ok && --activeUsers == 0)
  192393. mediaControl->Stop();
  192394. }
  192395. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192396. {
  192397. if (recordNextFrameTime)
  192398. {
  192399. const double defaultCameraLatency = 0.1;
  192400. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192401. recordNextFrameTime = false;
  192402. ComSmartPtr <IPin> pin;
  192403. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192404. {
  192405. ComSmartPtr <IAMPushSource> pushSource;
  192406. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192407. if (pushSource != 0)
  192408. {
  192409. REFERENCE_TIME latency = 0;
  192410. hr = pushSource->GetLatency (&latency);
  192411. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192412. }
  192413. }
  192414. }
  192415. {
  192416. const int lineStride = width * 3;
  192417. const ScopedLock sl (imageSwapLock);
  192418. {
  192419. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192420. for (int i = 0; i < height; ++i)
  192421. memcpy (destData.getLinePointer ((height - 1) - i),
  192422. buffer + lineStride * i,
  192423. lineStride);
  192424. }
  192425. imageNeedsFlipping = true;
  192426. }
  192427. if (listeners.size() > 0)
  192428. callListeners (*loadingImage);
  192429. sendChangeMessage (this);
  192430. }
  192431. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192432. {
  192433. if (imageNeedsFlipping)
  192434. {
  192435. const ScopedLock sl (imageSwapLock);
  192436. swapVariables (loadingImage, activeImage);
  192437. imageNeedsFlipping = false;
  192438. }
  192439. RectanglePlacement rp (RectanglePlacement::centred);
  192440. double dx = 0, dy = 0, dw = width, dh = height;
  192441. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192442. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192443. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192444. g.saveState();
  192445. g.excludeClipRegion (rx, ry, rw, rh);
  192446. g.fillAll (Colours::black);
  192447. g.restoreState();
  192448. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192449. }
  192450. bool createFileCaptureFilter (const File& file)
  192451. {
  192452. removeFileCaptureFilter();
  192453. file.deleteFile();
  192454. mediaControl->Stop();
  192455. firstRecordedTime = Time();
  192456. recordNextFrameTime = true;
  192457. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  192458. if (SUCCEEDED (hr))
  192459. {
  192460. ComSmartPtr <IFileSinkFilter> fileSink;
  192461. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192462. if (SUCCEEDED (hr))
  192463. {
  192464. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  192465. if (SUCCEEDED (hr))
  192466. {
  192467. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  192468. if (SUCCEEDED (hr))
  192469. {
  192470. ComSmartPtr <IConfigAsfWriter> asfConfig;
  192471. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  192472. asfConfig->SetIndexMode (true);
  192473. ComSmartPtr <IWMProfileManager> profileManager;
  192474. hr = WMCreateProfileManager (&profileManager);
  192475. // This gibberish is the DirectShow profile for a video-only wmv file.
  192476. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  192477. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  192478. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  192479. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  192480. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  192481. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  192482. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  192483. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  192484. prof = prof.replace (T("$WIDTH"), String (width))
  192485. .replace (T("$HEIGHT"), String (height));
  192486. ComSmartPtr <IWMProfile> currentProfile;
  192487. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  192488. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  192489. if (SUCCEEDED (hr))
  192490. {
  192491. ComSmartPtr <IPin> asfWriterInputPin;
  192492. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  192493. {
  192494. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  192495. if (SUCCEEDED (hr)
  192496. && ok && activeUsers > 0
  192497. && SUCCEEDED (mediaControl->Run()))
  192498. {
  192499. return true;
  192500. }
  192501. }
  192502. }
  192503. }
  192504. }
  192505. }
  192506. }
  192507. removeFileCaptureFilter();
  192508. if (ok && activeUsers > 0)
  192509. mediaControl->Run();
  192510. return false;
  192511. }
  192512. void removeFileCaptureFilter()
  192513. {
  192514. mediaControl->Stop();
  192515. if (asfWriter != 0)
  192516. {
  192517. graphBuilder->RemoveFilter (asfWriter);
  192518. asfWriter = 0;
  192519. }
  192520. if (ok && activeUsers > 0)
  192521. mediaControl->Run();
  192522. }
  192523. void addListener (CameraImageListener* listenerToAdd)
  192524. {
  192525. const ScopedLock sl (listenerLock);
  192526. if (listeners.size() == 0)
  192527. addUser();
  192528. listeners.addIfNotAlreadyThere (listenerToAdd);
  192529. }
  192530. void removeListener (CameraImageListener* listenerToRemove)
  192531. {
  192532. const ScopedLock sl (listenerLock);
  192533. listeners.removeValue (listenerToRemove);
  192534. if (listeners.size() == 0)
  192535. removeUser();
  192536. }
  192537. void callListeners (Image& image)
  192538. {
  192539. const ScopedLock sl (listenerLock);
  192540. for (int i = listeners.size(); --i >= 0;)
  192541. {
  192542. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192543. if (l != 0)
  192544. l->imageReceived (image);
  192545. }
  192546. }
  192547. class DShowCaptureViewerComp : public Component,
  192548. public ChangeListener
  192549. {
  192550. public:
  192551. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192552. : owner (owner_)
  192553. {
  192554. setOpaque (true);
  192555. owner->addChangeListener (this);
  192556. owner->addUser();
  192557. owner->viewerComps.add (this);
  192558. setSize (owner_->width, owner_->height);
  192559. }
  192560. ~DShowCaptureViewerComp()
  192561. {
  192562. if (owner != 0)
  192563. {
  192564. owner->viewerComps.removeValue (this);
  192565. owner->removeUser();
  192566. owner->removeChangeListener (this);
  192567. }
  192568. }
  192569. void ownerDeleted()
  192570. {
  192571. owner = 0;
  192572. }
  192573. void paint (Graphics& g)
  192574. {
  192575. g.setColour (Colours::black);
  192576. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192577. if (owner != 0)
  192578. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192579. else
  192580. g.fillAll (Colours::black);
  192581. }
  192582. void changeListenerCallback (void*)
  192583. {
  192584. repaint();
  192585. }
  192586. private:
  192587. DShowCameraDeviceInteral* owner;
  192588. };
  192589. bool ok;
  192590. int width, height;
  192591. Time firstRecordedTime;
  192592. VoidArray viewerComps;
  192593. private:
  192594. CameraDevice* const owner;
  192595. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192596. ComSmartPtr <IBaseFilter> filter;
  192597. ComSmartPtr <IBaseFilter> smartTee;
  192598. ComSmartPtr <IGraphBuilder> graphBuilder;
  192599. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192600. ComSmartPtr <IMediaControl> mediaControl;
  192601. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192602. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192603. ComSmartPtr <IBaseFilter> asfWriter;
  192604. int activeUsers;
  192605. Array <int> widths, heights;
  192606. DWORD graphRegistrationID;
  192607. CriticalSection imageSwapLock;
  192608. bool imageNeedsFlipping;
  192609. Image* loadingImage;
  192610. Image* activeImage;
  192611. bool recordNextFrameTime;
  192612. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192613. {
  192614. widths.clear();
  192615. heights.clear();
  192616. int count = 0, size = 0;
  192617. streamConfig->GetNumberOfCapabilities (&count, &size);
  192618. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192619. {
  192620. for (int i = 0; i < count; ++i)
  192621. {
  192622. VIDEO_STREAM_CONFIG_CAPS scc;
  192623. AM_MEDIA_TYPE* config;
  192624. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192625. if (SUCCEEDED (hr))
  192626. {
  192627. const int w = scc.InputSize.cx;
  192628. const int h = scc.InputSize.cy;
  192629. bool duplicate = false;
  192630. for (int j = widths.size(); --j >= 0;)
  192631. {
  192632. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192633. {
  192634. duplicate = true;
  192635. break;
  192636. }
  192637. }
  192638. if (! duplicate)
  192639. {
  192640. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192641. widths.add (w);
  192642. heights.add (h);
  192643. }
  192644. deleteMediaType (config);
  192645. }
  192646. }
  192647. }
  192648. }
  192649. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192650. const int minWidth, const int minHeight,
  192651. const int maxWidth, const int maxHeight)
  192652. {
  192653. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192654. streamConfig->GetNumberOfCapabilities (&count, &size);
  192655. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192656. {
  192657. AM_MEDIA_TYPE* config;
  192658. VIDEO_STREAM_CONFIG_CAPS scc;
  192659. for (int i = 0; i < count; ++i)
  192660. {
  192661. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192662. if (SUCCEEDED (hr))
  192663. {
  192664. if (scc.InputSize.cx >= minWidth
  192665. && scc.InputSize.cy >= minHeight
  192666. && scc.InputSize.cx <= maxWidth
  192667. && scc.InputSize.cy <= maxHeight)
  192668. {
  192669. int area = scc.InputSize.cx * scc.InputSize.cy;
  192670. if (area > bestArea)
  192671. {
  192672. bestIndex = i;
  192673. bestArea = area;
  192674. }
  192675. }
  192676. deleteMediaType (config);
  192677. }
  192678. }
  192679. if (bestIndex >= 0)
  192680. {
  192681. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192682. hr = streamConfig->SetFormat (config);
  192683. deleteMediaType (config);
  192684. return SUCCEEDED (hr);
  192685. }
  192686. }
  192687. return false;
  192688. }
  192689. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192690. {
  192691. ComSmartPtr <IEnumPins> enumerator;
  192692. ComSmartPtr <IPin> pin;
  192693. filter->EnumPins (&enumerator);
  192694. while (enumerator->Next (1, &pin, 0) == S_OK)
  192695. {
  192696. PIN_DIRECTION dir;
  192697. pin->QueryDirection (&dir);
  192698. if (wantedDirection == dir)
  192699. {
  192700. PIN_INFO info;
  192701. zerostruct (info);
  192702. pin->QueryPinInfo (&info);
  192703. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192704. {
  192705. pin.p->AddRef();
  192706. *result = pin;
  192707. return true;
  192708. }
  192709. }
  192710. }
  192711. return false;
  192712. }
  192713. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192714. {
  192715. ComSmartPtr <IPin> in, out;
  192716. return getPin (first, PINDIR_OUTPUT, &out)
  192717. && getPin (second, PINDIR_INPUT, &in)
  192718. && SUCCEEDED (graphBuilder->Connect (out, in));
  192719. }
  192720. bool addGraphToRot()
  192721. {
  192722. ComSmartPtr <IRunningObjectTable> rot;
  192723. if (FAILED (GetRunningObjectTable (0, &rot)))
  192724. return false;
  192725. ComSmartPtr <IMoniker> moniker;
  192726. WCHAR buffer[128];
  192727. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192728. if (FAILED (hr))
  192729. return false;
  192730. graphRegistrationID = 0;
  192731. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192732. }
  192733. void removeGraphFromRot()
  192734. {
  192735. ComSmartPtr <IRunningObjectTable> rot;
  192736. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192737. rot->Revoke (graphRegistrationID);
  192738. }
  192739. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192740. {
  192741. if (pmt->cbFormat != 0)
  192742. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192743. if (pmt->pUnk != 0)
  192744. pmt->pUnk->Release();
  192745. CoTaskMemFree (pmt);
  192746. }
  192747. class GrabberCallback : public ISampleGrabberCB
  192748. {
  192749. public:
  192750. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192751. : owner (owner_)
  192752. {
  192753. }
  192754. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192755. {
  192756. if (id == IID_IUnknown)
  192757. *result = dynamic_cast <IUnknown*> (this);
  192758. else if (id == IID_ISampleGrabberCB)
  192759. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192760. else
  192761. {
  192762. *result = 0;
  192763. return E_NOINTERFACE;
  192764. }
  192765. AddRef();
  192766. return S_OK;
  192767. }
  192768. ULONG __stdcall AddRef() { return ++refCount; }
  192769. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192770. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192771. {
  192772. return E_FAIL;
  192773. }
  192774. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192775. {
  192776. owner.handleFrame (time, buffer, bufferSize);
  192777. return S_OK;
  192778. }
  192779. private:
  192780. int refCount;
  192781. DShowCameraDeviceInteral& owner;
  192782. GrabberCallback (const GrabberCallback&);
  192783. GrabberCallback& operator= (const GrabberCallback&);
  192784. };
  192785. ComSmartPtr <GrabberCallback> callback;
  192786. VoidArray listeners;
  192787. CriticalSection listenerLock;
  192788. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192789. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192790. };
  192791. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192792. : name (name_)
  192793. {
  192794. isRecording = false;
  192795. }
  192796. CameraDevice::~CameraDevice()
  192797. {
  192798. stopRecording();
  192799. delete (DShowCameraDeviceInteral*) internal;
  192800. internal = 0;
  192801. }
  192802. Component* CameraDevice::createViewerComponent()
  192803. {
  192804. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192805. }
  192806. const String CameraDevice::getFileExtension()
  192807. {
  192808. return ".wmv";
  192809. }
  192810. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192811. {
  192812. stopRecording();
  192813. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192814. d->addUser();
  192815. isRecording = d->createFileCaptureFilter (file);
  192816. }
  192817. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192818. {
  192819. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192820. return d->firstRecordedTime;
  192821. }
  192822. void CameraDevice::stopRecording()
  192823. {
  192824. if (isRecording)
  192825. {
  192826. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192827. d->removeFileCaptureFilter();
  192828. d->removeUser();
  192829. isRecording = false;
  192830. }
  192831. }
  192832. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192833. {
  192834. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192835. if (listenerToAdd != 0)
  192836. d->addListener (listenerToAdd);
  192837. }
  192838. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192839. {
  192840. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192841. if (listenerToRemove != 0)
  192842. d->removeListener (listenerToRemove);
  192843. }
  192844. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192845. const int deviceIndexToOpen,
  192846. String& name)
  192847. {
  192848. int index = 0;
  192849. ComSmartPtr <IBaseFilter> result;
  192850. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192851. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192852. if (SUCCEEDED (hr))
  192853. {
  192854. ComSmartPtr <IEnumMoniker> enumerator;
  192855. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192856. if (SUCCEEDED (hr) && enumerator != 0)
  192857. {
  192858. ComSmartPtr <IBaseFilter> captureFilter;
  192859. ComSmartPtr <IMoniker> moniker;
  192860. ULONG fetched;
  192861. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192862. {
  192863. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192864. if (SUCCEEDED (hr))
  192865. {
  192866. ComSmartPtr <IPropertyBag> propertyBag;
  192867. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192868. if (SUCCEEDED (hr))
  192869. {
  192870. VARIANT var;
  192871. var.vt = VT_BSTR;
  192872. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192873. propertyBag = 0;
  192874. if (SUCCEEDED (hr))
  192875. {
  192876. if (names != 0)
  192877. names->add (var.bstrVal);
  192878. if (index == deviceIndexToOpen)
  192879. {
  192880. name = var.bstrVal;
  192881. result = captureFilter;
  192882. captureFilter = 0;
  192883. break;
  192884. }
  192885. ++index;
  192886. }
  192887. moniker = 0;
  192888. }
  192889. captureFilter = 0;
  192890. }
  192891. }
  192892. }
  192893. }
  192894. return result;
  192895. }
  192896. const StringArray CameraDevice::getAvailableDevices()
  192897. {
  192898. StringArray devs;
  192899. String dummy;
  192900. enumerateCameras (&devs, -1, dummy);
  192901. return devs;
  192902. }
  192903. CameraDevice* CameraDevice::openDevice (int index,
  192904. int minWidth, int minHeight,
  192905. int maxWidth, int maxHeight)
  192906. {
  192907. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192908. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192909. if (SUCCEEDED (hr))
  192910. {
  192911. String name;
  192912. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192913. if (filter != 0)
  192914. {
  192915. CameraDevice* const cam = new CameraDevice (name, index);
  192916. DShowCameraDeviceInteral* const intern
  192917. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192918. minWidth, minHeight, maxWidth, maxHeight);
  192919. cam->internal = intern;
  192920. if (intern->ok)
  192921. return cam;
  192922. else
  192923. delete cam;
  192924. }
  192925. }
  192926. return 0;
  192927. }
  192928. #endif
  192929. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192930. #endif
  192931. // Auto-link the other win32 libs that are needed by library calls..
  192932. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192933. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192934. // Auto-links to various win32 libs that are needed by library calls..
  192935. #pragma comment(lib, "kernel32.lib")
  192936. #pragma comment(lib, "user32.lib")
  192937. #pragma comment(lib, "shell32.lib")
  192938. #pragma comment(lib, "gdi32.lib")
  192939. #pragma comment(lib, "vfw32.lib")
  192940. #pragma comment(lib, "comdlg32.lib")
  192941. #pragma comment(lib, "winmm.lib")
  192942. #pragma comment(lib, "wininet.lib")
  192943. #pragma comment(lib, "ole32.lib")
  192944. #pragma comment(lib, "oleaut32.lib")
  192945. #pragma comment(lib, "advapi32.lib")
  192946. #pragma comment(lib, "ws2_32.lib")
  192947. #pragma comment(lib, "comsupp.lib")
  192948. #pragma comment(lib, "version.lib")
  192949. #if JUCE_OPENGL
  192950. #pragma comment(lib, "OpenGL32.Lib")
  192951. #pragma comment(lib, "GlU32.Lib")
  192952. #endif
  192953. #if JUCE_QUICKTIME
  192954. #pragma comment (lib, "QTMLClient.lib")
  192955. #endif
  192956. #if JUCE_USE_CAMERA
  192957. #pragma comment (lib, "Strmiids.lib")
  192958. #pragma comment (lib, "wmvcore.lib")
  192959. #endif
  192960. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192961. #endif
  192962. END_JUCE_NAMESPACE
  192963. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192964. #endif
  192965. #if JUCE_LINUX
  192966. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192967. BEGIN_JUCE_NAMESPACE
  192968. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192969. #define SUPPORT_AFFINITIES 1
  192970. #endif
  192971. #define JUCE_INCLUDED_FILE 1
  192972. // Now include the actual code files..
  192973. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192974. CriticalSection::CriticalSection() throw()
  192975. {
  192976. pthread_mutexattr_t atts;
  192977. pthread_mutexattr_init (&atts);
  192978. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192979. pthread_mutex_init (&internal, &atts);
  192980. }
  192981. CriticalSection::~CriticalSection() throw()
  192982. {
  192983. pthread_mutex_destroy (&internal);
  192984. }
  192985. void CriticalSection::enter() const throw()
  192986. {
  192987. pthread_mutex_lock (&internal);
  192988. }
  192989. bool CriticalSection::tryEnter() const throw()
  192990. {
  192991. return pthread_mutex_trylock (&internal) == 0;
  192992. }
  192993. void CriticalSection::exit() const throw()
  192994. {
  192995. pthread_mutex_unlock (&internal);
  192996. }
  192997. struct EventStruct
  192998. {
  192999. pthread_cond_t condition;
  193000. pthread_mutex_t mutex;
  193001. bool triggered;
  193002. };
  193003. WaitableEvent::WaitableEvent() throw()
  193004. {
  193005. EventStruct* const es = new EventStruct();
  193006. es->triggered = false;
  193007. pthread_cond_init (&es->condition, 0);
  193008. pthread_mutex_init (&es->mutex, 0);
  193009. internal = es;
  193010. }
  193011. WaitableEvent::~WaitableEvent() throw()
  193012. {
  193013. EventStruct* const es = (EventStruct*) internal;
  193014. pthread_cond_destroy (&es->condition);
  193015. pthread_mutex_destroy (&es->mutex);
  193016. delete es;
  193017. }
  193018. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  193019. {
  193020. EventStruct* const es = (EventStruct*) internal;
  193021. pthread_mutex_lock (&es->mutex);
  193022. if (timeOutMillisecs < 0)
  193023. {
  193024. while (! es->triggered)
  193025. pthread_cond_wait (&es->condition, &es->mutex);
  193026. }
  193027. else
  193028. {
  193029. while (! es->triggered)
  193030. {
  193031. struct timeval t;
  193032. gettimeofday (&t, 0);
  193033. struct timespec time;
  193034. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  193035. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  193036. if (time.tv_nsec >= 1000000000)
  193037. {
  193038. time.tv_nsec -= 1000000000;
  193039. time.tv_sec++;
  193040. }
  193041. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  193042. {
  193043. pthread_mutex_unlock (&es->mutex);
  193044. return false;
  193045. }
  193046. }
  193047. }
  193048. es->triggered = false;
  193049. pthread_mutex_unlock (&es->mutex);
  193050. return true;
  193051. }
  193052. void WaitableEvent::signal() const throw()
  193053. {
  193054. EventStruct* const es = (EventStruct*) internal;
  193055. pthread_mutex_lock (&es->mutex);
  193056. es->triggered = true;
  193057. pthread_cond_broadcast (&es->condition);
  193058. pthread_mutex_unlock (&es->mutex);
  193059. }
  193060. void WaitableEvent::reset() const throw()
  193061. {
  193062. EventStruct* const es = (EventStruct*) internal;
  193063. pthread_mutex_lock (&es->mutex);
  193064. es->triggered = false;
  193065. pthread_mutex_unlock (&es->mutex);
  193066. }
  193067. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  193068. {
  193069. struct timespec time;
  193070. time.tv_sec = millisecs / 1000;
  193071. time.tv_nsec = (millisecs % 1000) * 1000000;
  193072. nanosleep (&time, 0);
  193073. }
  193074. const tchar File::separator = T('/');
  193075. const tchar* File::separatorString = T("/");
  193076. const File File::getCurrentWorkingDirectory()
  193077. {
  193078. HeapBlock<char> heapBuffer;
  193079. char localBuffer [1024];
  193080. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  193081. int bufferSize = 4096;
  193082. while (cwd == 0 && errno == ERANGE)
  193083. {
  193084. heapBuffer.malloc (bufferSize);
  193085. cwd = getcwd (heapBuffer, bufferSize - 1);
  193086. bufferSize += 1024;
  193087. }
  193088. return File (String::fromUTF8 (cwd));
  193089. }
  193090. bool File::setAsCurrentWorkingDirectory() const
  193091. {
  193092. return chdir (getFullPathName().toUTF8()) == 0;
  193093. }
  193094. bool juce_copyFile (const String& s, const String& d);
  193095. static bool juce_stat (const String& fileName, struct stat& info)
  193096. {
  193097. return fileName.isNotEmpty()
  193098. && (stat (fileName.toUTF8(), &info) == 0);
  193099. }
  193100. bool juce_isDirectory (const String& fileName)
  193101. {
  193102. struct stat info;
  193103. return fileName.isEmpty()
  193104. || (juce_stat (fileName, info)
  193105. && ((info.st_mode & S_IFDIR) != 0));
  193106. }
  193107. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  193108. {
  193109. if (fileName.isEmpty())
  193110. return false;
  193111. const char* const fileNameUTF8 = fileName.toUTF8();
  193112. bool exists = access (fileNameUTF8, F_OK) == 0;
  193113. if (exists && dontCountDirectories)
  193114. {
  193115. struct stat info;
  193116. const int res = stat (fileNameUTF8, &info);
  193117. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  193118. exists = false;
  193119. }
  193120. return exists;
  193121. }
  193122. int64 juce_getFileSize (const String& fileName)
  193123. {
  193124. struct stat info;
  193125. return juce_stat (fileName, info) ? info.st_size : 0;
  193126. }
  193127. bool juce_canWriteToFile (const String& fileName)
  193128. {
  193129. return access (fileName.toUTF8(), W_OK) == 0;
  193130. }
  193131. bool juce_deleteFile (const String& fileName)
  193132. {
  193133. if (juce_isDirectory (fileName))
  193134. return rmdir ((const char*) fileName.toUTF8()) == 0;
  193135. else
  193136. return remove ((const char*) fileName.toUTF8()) == 0;
  193137. }
  193138. bool juce_moveFile (const String& source, const String& dest)
  193139. {
  193140. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  193141. return true;
  193142. if (juce_canWriteToFile (source)
  193143. && juce_copyFile (source, dest))
  193144. {
  193145. if (juce_deleteFile (source))
  193146. return true;
  193147. juce_deleteFile (dest);
  193148. }
  193149. return false;
  193150. }
  193151. void juce_createDirectory (const String& fileName)
  193152. {
  193153. mkdir (fileName.toUTF8(), 0777);
  193154. }
  193155. void* juce_fileOpen (const String& fileName, bool forWriting)
  193156. {
  193157. int flags = O_RDONLY;
  193158. if (forWriting)
  193159. {
  193160. if (juce_fileExists (fileName, false))
  193161. {
  193162. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  193163. if (f != -1)
  193164. lseek (f, 0, SEEK_END);
  193165. return (void*) f;
  193166. }
  193167. else
  193168. {
  193169. flags = O_RDWR + O_CREAT;
  193170. }
  193171. }
  193172. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  193173. }
  193174. void juce_fileClose (void* handle)
  193175. {
  193176. if (handle != 0)
  193177. close ((int) (pointer_sized_int) handle);
  193178. }
  193179. int juce_fileRead (void* handle, void* buffer, int size)
  193180. {
  193181. if (handle != 0)
  193182. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  193183. return 0;
  193184. }
  193185. int juce_fileWrite (void* handle, const void* buffer, int size)
  193186. {
  193187. if (handle != 0)
  193188. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  193189. return 0;
  193190. }
  193191. int64 juce_fileSetPosition (void* handle, int64 pos)
  193192. {
  193193. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  193194. return pos;
  193195. return -1;
  193196. }
  193197. int64 juce_fileGetPosition (void* handle)
  193198. {
  193199. if (handle != 0)
  193200. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  193201. else
  193202. return -1;
  193203. }
  193204. void juce_fileFlush (void* handle)
  193205. {
  193206. if (handle != 0)
  193207. fsync ((int) (pointer_sized_int) handle);
  193208. }
  193209. const File juce_getExecutableFile()
  193210. {
  193211. Dl_info exeInfo;
  193212. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  193213. return File (String::fromUTF8 (exeInfo.dli_fname));
  193214. }
  193215. // if this file doesn't exist, find a parent of it that does..
  193216. static bool doStatFS (const File* file, struct statfs& result)
  193217. {
  193218. File f (*file);
  193219. for (int i = 5; --i >= 0;)
  193220. {
  193221. if (f.exists())
  193222. break;
  193223. f = f.getParentDirectory();
  193224. }
  193225. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  193226. }
  193227. int64 File::getBytesFreeOnVolume() const
  193228. {
  193229. struct statfs buf;
  193230. if (doStatFS (this, buf))
  193231. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  193232. return 0;
  193233. }
  193234. int64 File::getVolumeTotalSize() const
  193235. {
  193236. struct statfs buf;
  193237. if (doStatFS (this, buf))
  193238. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  193239. return 0;
  193240. }
  193241. const String juce_getVolumeLabel (const String& filenameOnVolume,
  193242. int& volumeSerialNumber)
  193243. {
  193244. volumeSerialNumber = 0;
  193245. #if JUCE_MAC
  193246. struct VolAttrBuf
  193247. {
  193248. u_int32_t length;
  193249. attrreference_t mountPointRef;
  193250. char mountPointSpace [MAXPATHLEN];
  193251. } attrBuf;
  193252. struct attrlist attrList;
  193253. zerostruct (attrList);
  193254. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  193255. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  193256. File f (filenameOnVolume);
  193257. for (;;)
  193258. {
  193259. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  193260. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  193261. {
  193262. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  193263. (int) attrBuf.mountPointRef.attr_length);
  193264. }
  193265. const File parent (f.getParentDirectory());
  193266. if (f == parent)
  193267. break;
  193268. f = parent;
  193269. }
  193270. #endif
  193271. return String::empty;
  193272. }
  193273. void juce_runSystemCommand (const String& command)
  193274. {
  193275. int result = system ((const char*) command.toUTF8());
  193276. (void) result;
  193277. }
  193278. const String juce_getOutputFromCommand (const String& command)
  193279. {
  193280. // slight bodge here, as we just pipe the output into a temp file and read it...
  193281. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  193282. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  193283. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  193284. String result (tempFile.loadFileAsString());
  193285. tempFile.deleteFile();
  193286. return result;
  193287. }
  193288. InterProcessLock::InterProcessLock (const String& name_)
  193289. : internal (0),
  193290. name (name_),
  193291. reentrancyLevel (0)
  193292. {
  193293. #if JUCE_MAC
  193294. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  193295. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  193296. #else
  193297. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  193298. #endif
  193299. temp.create();
  193300. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  193301. }
  193302. InterProcessLock::~InterProcessLock()
  193303. {
  193304. while (reentrancyLevel > 0)
  193305. this->exit();
  193306. close (internal);
  193307. }
  193308. bool InterProcessLock::enter (const int timeOutMillisecs)
  193309. {
  193310. if (internal == 0)
  193311. return false;
  193312. if (reentrancyLevel != 0)
  193313. return true;
  193314. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193315. struct flock fl;
  193316. zerostruct (fl);
  193317. fl.l_whence = SEEK_SET;
  193318. fl.l_type = F_WRLCK;
  193319. for (;;)
  193320. {
  193321. const int result = fcntl (internal, F_SETLK, &fl);
  193322. if (result >= 0)
  193323. {
  193324. ++reentrancyLevel;
  193325. return true;
  193326. }
  193327. if (errno != EINTR)
  193328. {
  193329. if (timeOutMillisecs == 0
  193330. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193331. break;
  193332. Thread::sleep (10);
  193333. }
  193334. }
  193335. return false;
  193336. }
  193337. void InterProcessLock::exit()
  193338. {
  193339. if (reentrancyLevel > 0 && internal != 0)
  193340. {
  193341. --reentrancyLevel;
  193342. struct flock fl;
  193343. zerostruct (fl);
  193344. fl.l_whence = SEEK_SET;
  193345. fl.l_type = F_UNLCK;
  193346. for (;;)
  193347. {
  193348. const int result = fcntl (internal, F_SETLKW, &fl);
  193349. if (result >= 0 || errno != EINTR)
  193350. break;
  193351. }
  193352. }
  193353. }
  193354. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193355. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193356. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193357. // compiled on its own).
  193358. #if JUCE_INCLUDED_FILE
  193359. #define U_ISOFS_SUPER_MAGIC (short) 0x9660 // linux/iso_fs.h
  193360. #define U_MSDOS_SUPER_MAGIC (short) 0x4d44 // linux/msdos_fs.h
  193361. #define U_NFS_SUPER_MAGIC (short) 0x6969 // linux/nfs_fs.h
  193362. #define U_SMB_SUPER_MAGIC (short) 0x517B // linux/smb_fs.h
  193363. void juce_getFileTimes (const String& fileName,
  193364. int64& modificationTime,
  193365. int64& accessTime,
  193366. int64& creationTime)
  193367. {
  193368. modificationTime = 0;
  193369. accessTime = 0;
  193370. creationTime = 0;
  193371. struct stat info;
  193372. const int res = stat (fileName.toUTF8(), &info);
  193373. if (res == 0)
  193374. {
  193375. modificationTime = (int64) info.st_mtime * 1000;
  193376. accessTime = (int64) info.st_atime * 1000;
  193377. creationTime = (int64) info.st_ctime * 1000;
  193378. }
  193379. }
  193380. bool juce_setFileTimes (const String& fileName,
  193381. int64 modificationTime,
  193382. int64 accessTime,
  193383. int64 creationTime)
  193384. {
  193385. struct utimbuf times;
  193386. times.actime = (time_t) (accessTime / 1000);
  193387. times.modtime = (time_t) (modificationTime / 1000);
  193388. return utime (fileName.toUTF8(), &times) == 0;
  193389. }
  193390. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193391. {
  193392. struct stat info;
  193393. const int res = stat (fileName.toUTF8(), &info);
  193394. if (res != 0)
  193395. return false;
  193396. info.st_mode &= 0777; // Just permissions
  193397. if( isReadOnly )
  193398. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193399. else
  193400. // Give everybody write permission?
  193401. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193402. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193403. }
  193404. bool juce_copyFile (const String& s, const String& d)
  193405. {
  193406. const File source (s), dest (d);
  193407. FileInputStream* in = source.createInputStream();
  193408. bool ok = false;
  193409. if (in != 0)
  193410. {
  193411. if (dest.deleteFile())
  193412. {
  193413. FileOutputStream* const out = dest.createOutputStream();
  193414. if (out != 0)
  193415. {
  193416. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193417. delete out;
  193418. ok = (bytesCopied == source.getSize());
  193419. if (! ok)
  193420. dest.deleteFile();
  193421. }
  193422. }
  193423. delete in;
  193424. }
  193425. return ok;
  193426. }
  193427. const StringArray juce_getFileSystemRoots()
  193428. {
  193429. StringArray s;
  193430. s.add (T("/"));
  193431. return s;
  193432. }
  193433. bool File::isOnCDRomDrive() const
  193434. {
  193435. struct statfs buf;
  193436. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193437. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193438. // Assume not if this fails for some reason
  193439. return false;
  193440. }
  193441. bool File::isOnHardDisk() const
  193442. {
  193443. struct statfs buf;
  193444. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193445. {
  193446. switch (buf.f_type)
  193447. {
  193448. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193449. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193450. case U_NFS_SUPER_MAGIC: // Network NFS
  193451. case U_SMB_SUPER_MAGIC: // Network Samba
  193452. return false;
  193453. default:
  193454. // Assume anything else is a hard-disk (but note it could
  193455. // be a RAM disk. There isn't a good way of determining
  193456. // this for sure)
  193457. return true;
  193458. }
  193459. }
  193460. // Assume so if this fails for some reason
  193461. return true;
  193462. }
  193463. bool File::isOnRemovableDrive() const
  193464. {
  193465. jassertfalse // xxx not implemented for linux!
  193466. return false;
  193467. }
  193468. bool File::isHidden() const
  193469. {
  193470. return getFileName().startsWithChar (T('.'));
  193471. }
  193472. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193473. const File File::getSpecialLocation (const SpecialLocationType type)
  193474. {
  193475. switch (type)
  193476. {
  193477. case userHomeDirectory:
  193478. {
  193479. const char* homeDir = getenv ("HOME");
  193480. if (homeDir == 0)
  193481. {
  193482. struct passwd* const pw = getpwuid (getuid());
  193483. if (pw != 0)
  193484. homeDir = pw->pw_dir;
  193485. }
  193486. return File (String::fromUTF8 (homeDir));
  193487. }
  193488. case userDocumentsDirectory:
  193489. case userMusicDirectory:
  193490. case userMoviesDirectory:
  193491. case userApplicationDataDirectory:
  193492. return File ("~");
  193493. case userDesktopDirectory:
  193494. return File ("~/Desktop");
  193495. case commonApplicationDataDirectory:
  193496. return File ("/var");
  193497. case globalApplicationsDirectory:
  193498. return File ("/usr");
  193499. case tempDirectory:
  193500. {
  193501. File tmp ("/var/tmp");
  193502. if (! tmp.isDirectory())
  193503. {
  193504. tmp = T("/tmp");
  193505. if (! tmp.isDirectory())
  193506. tmp = File::getCurrentWorkingDirectory();
  193507. }
  193508. return tmp;
  193509. }
  193510. case invokedExecutableFile:
  193511. if (juce_Argv0 != 0)
  193512. return File (String::fromUTF8 (juce_Argv0));
  193513. // deliberate fall-through...
  193514. case currentExecutableFile:
  193515. case currentApplicationFile:
  193516. return juce_getExecutableFile();
  193517. default:
  193518. jassertfalse // unknown type?
  193519. break;
  193520. }
  193521. return File::nonexistent;
  193522. }
  193523. const String File::getVersion() const
  193524. {
  193525. return String::empty; // xxx not yet implemented
  193526. }
  193527. const File File::getLinkedTarget() const
  193528. {
  193529. char buffer [4096];
  193530. size_t numChars = readlink (getFullPathName().toUTF8(),
  193531. buffer, sizeof (buffer));
  193532. if (numChars > 0 && numChars <= sizeof (buffer))
  193533. return File (String::fromUTF8 (buffer, (int) numChars));
  193534. return *this;
  193535. }
  193536. bool File::moveToTrash() const
  193537. {
  193538. if (! exists())
  193539. return true;
  193540. File trashCan (T("~/.Trash"));
  193541. if (! trashCan.isDirectory())
  193542. trashCan = T("~/.local/share/Trash/files");
  193543. if (! trashCan.isDirectory())
  193544. return false;
  193545. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193546. getFileExtension()));
  193547. }
  193548. struct FindFileStruct
  193549. {
  193550. String parentDir, wildCard;
  193551. DIR* dir;
  193552. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193553. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193554. {
  193555. const char* const wildcardUTF8 = wildCard.toUTF8();
  193556. for (;;)
  193557. {
  193558. struct dirent* const de = readdir (dir);
  193559. if (de == 0)
  193560. break;
  193561. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193562. {
  193563. result = String::fromUTF8 (de->d_name);
  193564. const String path (parentDir + result);
  193565. if (isDir != 0 || fileSize != 0)
  193566. {
  193567. struct stat info;
  193568. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193569. if (isDir != 0)
  193570. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193571. if (isHidden != 0)
  193572. *isHidden = (de->d_name[0] == '.');
  193573. if (fileSize != 0)
  193574. *fileSize = statOk ? info.st_size : 0;
  193575. }
  193576. if (modTime != 0 || creationTime != 0)
  193577. {
  193578. int64 m, a, c;
  193579. juce_getFileTimes (path, m, a, c);
  193580. if (modTime != 0)
  193581. *modTime = m;
  193582. if (creationTime != 0)
  193583. *creationTime = c;
  193584. }
  193585. if (isReadOnly != 0)
  193586. *isReadOnly = ! juce_canWriteToFile (path);
  193587. return true;
  193588. }
  193589. }
  193590. return false;
  193591. }
  193592. };
  193593. // returns 0 on failure
  193594. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193595. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193596. Time* creationTime, bool* isReadOnly)
  193597. {
  193598. DIR* d = opendir (directory.toUTF8());
  193599. if (d != 0)
  193600. {
  193601. FindFileStruct* ff = new FindFileStruct();
  193602. ff->parentDir = directory;
  193603. if (!ff->parentDir.endsWithChar (File::separator))
  193604. ff->parentDir += File::separator;
  193605. ff->wildCard = wildCard;
  193606. if (wildCard == T("*.*"))
  193607. ff->wildCard = T("*");
  193608. ff->dir = d;
  193609. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193610. {
  193611. return ff;
  193612. }
  193613. else
  193614. {
  193615. firstResultFile = String::empty;
  193616. isDir = false;
  193617. isHidden = false;
  193618. closedir (d);
  193619. delete ff;
  193620. }
  193621. }
  193622. return 0;
  193623. }
  193624. bool juce_findFileNext (void* handle, String& resultFile,
  193625. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193626. {
  193627. FindFileStruct* const ff = (FindFileStruct*) handle;
  193628. if (ff != 0)
  193629. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193630. return false;
  193631. }
  193632. void juce_findFileClose (void* handle)
  193633. {
  193634. FindFileStruct* const ff = (FindFileStruct*) handle;
  193635. if (ff != 0)
  193636. {
  193637. closedir (ff->dir);
  193638. delete ff;
  193639. }
  193640. }
  193641. bool juce_launchFile (const String& fileName,
  193642. const String& parameters)
  193643. {
  193644. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193645. cmdString << " " << parameters;
  193646. if (URL::isProbablyAWebsiteURL (fileName)
  193647. || cmdString.startsWithIgnoreCase (T("file:"))
  193648. || URL::isProbablyAnEmailAddress (fileName))
  193649. {
  193650. // create a command that tries to launch a bunch of likely browsers
  193651. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193652. StringArray cmdLines;
  193653. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193654. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193655. cmdString = cmdLines.joinIntoString (T(" || "));
  193656. }
  193657. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193658. const int cpid = fork();
  193659. if (cpid == 0)
  193660. {
  193661. setsid();
  193662. // Child process
  193663. execve (argv[0], (char**) argv, environ);
  193664. exit (0);
  193665. }
  193666. return cpid >= 0;
  193667. }
  193668. void File::revealToUser() const
  193669. {
  193670. if (isDirectory())
  193671. startAsProcess();
  193672. else if (getParentDirectory().exists())
  193673. getParentDirectory().startAsProcess();
  193674. }
  193675. #endif
  193676. /*** End of inlined file: juce_linux_Files.cpp ***/
  193677. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193678. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193679. // compiled on its own).
  193680. #if JUCE_INCLUDED_FILE
  193681. struct NamedPipeInternal
  193682. {
  193683. String pipeInName, pipeOutName;
  193684. int pipeIn, pipeOut;
  193685. bool volatile createdPipe, blocked, stopReadOperation;
  193686. static void signalHandler (int) {}
  193687. };
  193688. void NamedPipe::cancelPendingReads()
  193689. {
  193690. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193691. {
  193692. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193693. intern->stopReadOperation = true;
  193694. char buffer [1] = { 0 };
  193695. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193696. (void) bytesWritten;
  193697. int timeout = 2000;
  193698. while (intern->blocked && --timeout >= 0)
  193699. Thread::sleep (2);
  193700. intern->stopReadOperation = false;
  193701. }
  193702. }
  193703. void NamedPipe::close()
  193704. {
  193705. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193706. if (intern != 0)
  193707. {
  193708. internal = 0;
  193709. if (intern->pipeIn != -1)
  193710. ::close (intern->pipeIn);
  193711. if (intern->pipeOut != -1)
  193712. ::close (intern->pipeOut);
  193713. if (intern->createdPipe)
  193714. {
  193715. unlink (intern->pipeInName.toUTF8());
  193716. unlink (intern->pipeOutName.toUTF8());
  193717. }
  193718. delete intern;
  193719. }
  193720. }
  193721. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193722. {
  193723. close();
  193724. NamedPipeInternal* const intern = new NamedPipeInternal();
  193725. internal = intern;
  193726. intern->createdPipe = createPipe;
  193727. intern->blocked = false;
  193728. intern->stopReadOperation = false;
  193729. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193730. siginterrupt (SIGPIPE, 1);
  193731. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193732. intern->pipeInName = pipePath + T("_in");
  193733. intern->pipeOutName = pipePath + T("_out");
  193734. intern->pipeIn = -1;
  193735. intern->pipeOut = -1;
  193736. if (createPipe)
  193737. {
  193738. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193739. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193740. {
  193741. delete intern;
  193742. internal = 0;
  193743. return false;
  193744. }
  193745. }
  193746. return true;
  193747. }
  193748. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193749. {
  193750. int bytesRead = -1;
  193751. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193752. if (intern != 0)
  193753. {
  193754. intern->blocked = true;
  193755. if (intern->pipeIn == -1)
  193756. {
  193757. if (intern->createdPipe)
  193758. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193759. else
  193760. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193761. if (intern->pipeIn == -1)
  193762. {
  193763. intern->blocked = false;
  193764. return -1;
  193765. }
  193766. }
  193767. bytesRead = 0;
  193768. char* p = (char*) destBuffer;
  193769. while (bytesRead < maxBytesToRead)
  193770. {
  193771. const int bytesThisTime = maxBytesToRead - bytesRead;
  193772. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193773. if (numRead <= 0 || intern->stopReadOperation)
  193774. {
  193775. bytesRead = -1;
  193776. break;
  193777. }
  193778. bytesRead += numRead;
  193779. p += bytesRead;
  193780. }
  193781. intern->blocked = false;
  193782. }
  193783. return bytesRead;
  193784. }
  193785. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193786. {
  193787. int bytesWritten = -1;
  193788. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193789. if (intern != 0)
  193790. {
  193791. if (intern->pipeOut == -1)
  193792. {
  193793. if (intern->createdPipe)
  193794. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193795. else
  193796. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193797. if (intern->pipeOut == -1)
  193798. {
  193799. return -1;
  193800. }
  193801. }
  193802. const char* p = (const char*) sourceBuffer;
  193803. bytesWritten = 0;
  193804. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193805. while (bytesWritten < numBytesToWrite
  193806. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193807. {
  193808. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193809. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193810. if (numWritten <= 0)
  193811. {
  193812. bytesWritten = -1;
  193813. break;
  193814. }
  193815. bytesWritten += numWritten;
  193816. p += bytesWritten;
  193817. }
  193818. }
  193819. return bytesWritten;
  193820. }
  193821. #endif
  193822. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193823. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193824. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193825. // compiled on its own).
  193826. #if JUCE_INCLUDED_FILE
  193827. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  193828. {
  193829. int numResults = 0;
  193830. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193831. if (s != -1)
  193832. {
  193833. char buf [1024];
  193834. struct ifconf ifc;
  193835. ifc.ifc_len = sizeof (buf);
  193836. ifc.ifc_buf = buf;
  193837. ioctl (s, SIOCGIFCONF, &ifc);
  193838. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193839. {
  193840. struct ifreq ifr;
  193841. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193842. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193843. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193844. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193845. && numResults < maxNum)
  193846. {
  193847. int64 a = 0;
  193848. for (int j = 6; --j >= 0;)
  193849. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193850. *addresses++ = a;
  193851. ++numResults;
  193852. }
  193853. }
  193854. close (s);
  193855. }
  193856. return numResults;
  193857. }
  193858. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193859. const String& emailSubject,
  193860. const String& bodyText,
  193861. const StringArray& filesToAttach)
  193862. {
  193863. jassertfalse // xxx todo
  193864. return false;
  193865. }
  193866. class JUCE_HTTPSocketStream
  193867. {
  193868. public:
  193869. JUCE_HTTPSocketStream()
  193870. : readPosition (0),
  193871. socketHandle (-1),
  193872. levelsOfRedirection (0),
  193873. timeoutSeconds (15)
  193874. {
  193875. }
  193876. ~JUCE_HTTPSocketStream()
  193877. {
  193878. closeSocket();
  193879. }
  193880. bool open (const String& url,
  193881. const String& headers,
  193882. const MemoryBlock& postData,
  193883. const bool isPost,
  193884. URL::OpenStreamProgressCallback* callback,
  193885. void* callbackContext,
  193886. int timeOutMs)
  193887. {
  193888. closeSocket();
  193889. uint32 timeOutTime = Time::getMillisecondCounter();
  193890. if (timeOutMs == 0)
  193891. timeOutTime += 60000;
  193892. else if (timeOutMs < 0)
  193893. timeOutTime = 0xffffffff;
  193894. else
  193895. timeOutTime += timeOutMs;
  193896. String hostName, hostPath;
  193897. int hostPort;
  193898. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193899. return false;
  193900. const struct hostent* host = 0;
  193901. int port = 0;
  193902. String proxyName, proxyPath;
  193903. int proxyPort = 0;
  193904. String proxyURL (getenv ("http_proxy"));
  193905. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193906. {
  193907. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193908. return false;
  193909. host = gethostbyname ((const char*) proxyName.toUTF8());
  193910. port = proxyPort;
  193911. }
  193912. else
  193913. {
  193914. host = gethostbyname ((const char*) hostName.toUTF8());
  193915. port = hostPort;
  193916. }
  193917. if (host == 0)
  193918. return false;
  193919. struct sockaddr_in address;
  193920. zerostruct (address);
  193921. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193922. address.sin_family = host->h_addrtype;
  193923. address.sin_port = htons (port);
  193924. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193925. if (socketHandle == -1)
  193926. return false;
  193927. int receiveBufferSize = 16384;
  193928. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193929. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193930. #if JUCE_MAC
  193931. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193932. #endif
  193933. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193934. {
  193935. closeSocket();
  193936. return false;
  193937. }
  193938. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193939. proxyName, proxyPort,
  193940. hostPath, url,
  193941. headers, postData,
  193942. isPost));
  193943. size_t totalHeaderSent = 0;
  193944. while (totalHeaderSent < requestHeader.getSize())
  193945. {
  193946. if (Time::getMillisecondCounter() > timeOutTime)
  193947. {
  193948. closeSocket();
  193949. return false;
  193950. }
  193951. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193952. if (send (socketHandle,
  193953. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193954. numToSend, 0)
  193955. != numToSend)
  193956. {
  193957. closeSocket();
  193958. return false;
  193959. }
  193960. totalHeaderSent += numToSend;
  193961. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193962. {
  193963. closeSocket();
  193964. return false;
  193965. }
  193966. }
  193967. const String responseHeader (readResponse (timeOutTime));
  193968. if (responseHeader.isNotEmpty())
  193969. {
  193970. //DBG (responseHeader);
  193971. StringArray lines;
  193972. lines.addLines (responseHeader);
  193973. // NB - using charToString() here instead of just T(" "), because that was
  193974. // causing a mysterious gcc internal compiler error...
  193975. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  193976. .substring (0, 3).getIntValue();
  193977. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  193978. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  193979. String location (findHeaderItem (lines, T("Location:")));
  193980. if (statusCode >= 300 && statusCode < 400
  193981. && location.isNotEmpty())
  193982. {
  193983. if (! location.startsWithIgnoreCase (T("http://")))
  193984. location = T("http://") + location;
  193985. if (levelsOfRedirection++ < 3)
  193986. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193987. }
  193988. else
  193989. {
  193990. levelsOfRedirection = 0;
  193991. return true;
  193992. }
  193993. }
  193994. closeSocket();
  193995. return false;
  193996. }
  193997. int read (void* buffer, int bytesToRead)
  193998. {
  193999. fd_set readbits;
  194000. FD_ZERO (&readbits);
  194001. FD_SET (socketHandle, &readbits);
  194002. struct timeval tv;
  194003. tv.tv_sec = timeoutSeconds;
  194004. tv.tv_usec = 0;
  194005. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194006. return 0; // (timeout)
  194007. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  194008. readPosition += bytesRead;
  194009. return bytesRead;
  194010. }
  194011. int readPosition;
  194012. juce_UseDebuggingNewOperator
  194013. private:
  194014. int socketHandle, levelsOfRedirection;
  194015. const int timeoutSeconds;
  194016. void closeSocket()
  194017. {
  194018. if (socketHandle >= 0)
  194019. close (socketHandle);
  194020. socketHandle = -1;
  194021. }
  194022. const MemoryBlock createRequestHeader (const String& hostName,
  194023. const int hostPort,
  194024. const String& proxyName,
  194025. const int proxyPort,
  194026. const String& hostPath,
  194027. const String& originalURL,
  194028. const String& headers,
  194029. const MemoryBlock& postData,
  194030. const bool isPost)
  194031. {
  194032. String header (isPost ? "POST " : "GET ");
  194033. if (proxyName.isEmpty())
  194034. {
  194035. header << hostPath << " HTTP/1.0\r\nHost: "
  194036. << hostName << ':' << hostPort;
  194037. }
  194038. else
  194039. {
  194040. header << originalURL << " HTTP/1.0\r\nHost: "
  194041. << proxyName << ':' << proxyPort;
  194042. }
  194043. header << "\r\nUser-Agent: JUCE/"
  194044. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  194045. << "\r\nConnection: Close\r\nContent-Length: "
  194046. << postData.getSize() << "\r\n"
  194047. << headers << "\r\n";
  194048. MemoryBlock mb;
  194049. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  194050. mb.append (postData.getData(), postData.getSize());
  194051. return mb;
  194052. }
  194053. const String readResponse (const uint32 timeOutTime)
  194054. {
  194055. int bytesRead = 0, numConsecutiveLFs = 0;
  194056. MemoryBlock buffer (1024, true);
  194057. while (numConsecutiveLFs < 2 && bytesRead < 32768
  194058. && Time::getMillisecondCounter() <= timeOutTime)
  194059. {
  194060. fd_set readbits;
  194061. FD_ZERO (&readbits);
  194062. FD_SET (socketHandle, &readbits);
  194063. struct timeval tv;
  194064. tv.tv_sec = timeoutSeconds;
  194065. tv.tv_usec = 0;
  194066. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194067. return String::empty; // (timeout)
  194068. buffer.ensureSize (bytesRead + 8, true);
  194069. char* const dest = (char*) buffer.getData() + bytesRead;
  194070. if (recv (socketHandle, dest, 1, 0) == -1)
  194071. return String::empty;
  194072. const char lastByte = *dest;
  194073. ++bytesRead;
  194074. if (lastByte == '\n')
  194075. ++numConsecutiveLFs;
  194076. else if (lastByte != '\r')
  194077. numConsecutiveLFs = 0;
  194078. }
  194079. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  194080. if (header.startsWithIgnoreCase (T("HTTP/")))
  194081. return header.trimEnd();
  194082. return String::empty;
  194083. }
  194084. static bool decomposeURL (const String& url,
  194085. String& host, String& path, int& port)
  194086. {
  194087. if (! url.startsWithIgnoreCase (T("http://")))
  194088. return false;
  194089. const int nextSlash = url.indexOfChar (7, '/');
  194090. int nextColon = url.indexOfChar (7, ':');
  194091. if (nextColon > nextSlash && nextSlash > 0)
  194092. nextColon = -1;
  194093. if (nextColon >= 0)
  194094. {
  194095. host = url.substring (7, nextColon);
  194096. if (nextSlash >= 0)
  194097. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  194098. else
  194099. port = url.substring (nextColon + 1).getIntValue();
  194100. }
  194101. else
  194102. {
  194103. port = 80;
  194104. if (nextSlash >= 0)
  194105. host = url.substring (7, nextSlash);
  194106. else
  194107. host = url.substring (7);
  194108. }
  194109. if (nextSlash >= 0)
  194110. path = url.substring (nextSlash);
  194111. else
  194112. path = T("/");
  194113. return true;
  194114. }
  194115. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  194116. {
  194117. for (int i = 0; i < lines.size(); ++i)
  194118. if (lines[i].startsWithIgnoreCase (itemName))
  194119. return lines[i].substring (itemName.length()).trim();
  194120. return String::empty;
  194121. }
  194122. };
  194123. bool juce_isOnLine()
  194124. {
  194125. return true;
  194126. }
  194127. void* juce_openInternetFile (const String& url,
  194128. const String& headers,
  194129. const MemoryBlock& postData,
  194130. const bool isPost,
  194131. URL::OpenStreamProgressCallback* callback,
  194132. void* callbackContext,
  194133. int timeOutMs)
  194134. {
  194135. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  194136. if (s->open (url, headers, postData, isPost,
  194137. callback, callbackContext, timeOutMs))
  194138. return s;
  194139. delete s;
  194140. return 0;
  194141. }
  194142. void juce_closeInternetFile (void* handle)
  194143. {
  194144. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194145. if (s != 0)
  194146. delete s;
  194147. }
  194148. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  194149. {
  194150. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194151. if (s != 0)
  194152. return s->read (buffer, bytesToRead);
  194153. return 0;
  194154. }
  194155. int64 juce_getInternetFileContentLength (void* handle)
  194156. {
  194157. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194158. if (s != 0)
  194159. {
  194160. //xxx todo
  194161. jassertfalse
  194162. }
  194163. return -1;
  194164. }
  194165. int juce_seekInInternetFile (void* handle, int newPosition)
  194166. {
  194167. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194168. if (s != 0)
  194169. return s->readPosition;
  194170. return 0;
  194171. }
  194172. #endif
  194173. /*** End of inlined file: juce_linux_Network.cpp ***/
  194174. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  194175. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194176. // compiled on its own).
  194177. #if JUCE_INCLUDED_FILE
  194178. void Logger::outputDebugString (const String& text) throw()
  194179. {
  194180. fputs (text.toUTF8(), stdout);
  194181. fputs ("\n", stdout);
  194182. }
  194183. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  194184. {
  194185. String text;
  194186. va_list args;
  194187. va_start (args, format);
  194188. text.vprintf(format, args);
  194189. outputDebugString(text);
  194190. }
  194191. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  194192. {
  194193. return Linux;
  194194. }
  194195. const String SystemStats::getOperatingSystemName() throw()
  194196. {
  194197. return T("Linux");
  194198. }
  194199. bool SystemStats::isOperatingSystem64Bit() throw()
  194200. {
  194201. #if JUCE_64BIT
  194202. return true;
  194203. #else
  194204. //xxx not sure how to find this out?..
  194205. return false;
  194206. #endif
  194207. }
  194208. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  194209. {
  194210. String info;
  194211. char buf [256];
  194212. FILE* f = fopen ("/proc/cpuinfo", "r");
  194213. while (f != 0 && fgets (buf, sizeof(buf), f))
  194214. {
  194215. if (strncmp (buf, key, strlen (key)) == 0)
  194216. {
  194217. char* p = buf;
  194218. while (*p && *p != '\n')
  194219. ++p;
  194220. if (*p != 0)
  194221. *p = 0;
  194222. p = buf;
  194223. while (*p != 0 && *p != ':')
  194224. ++p;
  194225. if (*p != 0 && *(p + 1) != 0)
  194226. info = p + 2;
  194227. if (! lastOne)
  194228. break;
  194229. }
  194230. }
  194231. fclose (f);
  194232. return info;
  194233. }
  194234. bool SystemStats::hasMMX() throw()
  194235. {
  194236. return getCpuInfo ("flags").contains (T("mmx"));
  194237. }
  194238. bool SystemStats::hasSSE() throw()
  194239. {
  194240. return getCpuInfo ("flags").contains (T("sse"));
  194241. }
  194242. bool SystemStats::hasSSE2() throw()
  194243. {
  194244. return getCpuInfo ("flags").contains (T("sse2"));
  194245. }
  194246. bool SystemStats::has3DNow() throw()
  194247. {
  194248. return getCpuInfo ("flags").contains (T("3dnow"));
  194249. }
  194250. const String SystemStats::getCpuVendor() throw()
  194251. {
  194252. return getCpuInfo ("vendor_id");
  194253. }
  194254. int SystemStats::getCpuSpeedInMegaherz() throw()
  194255. {
  194256. const String speed (getCpuInfo ("cpu MHz"));
  194257. return (int) (speed.getFloatValue() + 0.5f);
  194258. }
  194259. int SystemStats::getMemorySizeInMegabytes() throw()
  194260. {
  194261. struct sysinfo sysi;
  194262. if (sysinfo (&sysi) == 0)
  194263. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  194264. return 0;
  194265. }
  194266. uint32 juce_millisecondsSinceStartup() throw()
  194267. {
  194268. static unsigned int calibrate = 0;
  194269. static bool calibrated = false;
  194270. timeval t;
  194271. unsigned int ret = 0;
  194272. if (! gettimeofday (&t, 0))
  194273. {
  194274. if (! calibrated)
  194275. {
  194276. struct sysinfo sysi;
  194277. if (sysinfo (&sysi) == 0)
  194278. // Safe to assume system was not brought up earlier than 1970!
  194279. calibrate = t.tv_sec - sysi.uptime;
  194280. calibrated = true;
  194281. }
  194282. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  194283. }
  194284. return ret;
  194285. }
  194286. double Time::getMillisecondCounterHiRes() throw()
  194287. {
  194288. return getHighResolutionTicks() * 0.001;
  194289. }
  194290. int64 Time::getHighResolutionTicks() throw()
  194291. {
  194292. timeval t;
  194293. if (gettimeofday (&t, 0))
  194294. return 0;
  194295. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  194296. }
  194297. int64 Time::getHighResolutionTicksPerSecond() throw()
  194298. {
  194299. // Microseconds
  194300. return 1000000;
  194301. }
  194302. bool Time::setSystemTimeToThisTime() const throw()
  194303. {
  194304. timeval t;
  194305. t.tv_sec = millisSinceEpoch % 1000000;
  194306. t.tv_usec = millisSinceEpoch - t.tv_sec;
  194307. return settimeofday (&t, NULL) ? false : true;
  194308. }
  194309. int SystemStats::getPageSize() throw()
  194310. {
  194311. static int systemPageSize = 0;
  194312. if (systemPageSize == 0)
  194313. systemPageSize = sysconf (_SC_PAGESIZE);
  194314. return systemPageSize;
  194315. }
  194316. int SystemStats::getNumCpus() throw()
  194317. {
  194318. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194319. return lastCpu + 1;
  194320. }
  194321. const String SystemStats::getLogonName()
  194322. {
  194323. const char* user = getenv ("USER");
  194324. if (user == 0)
  194325. {
  194326. struct passwd* const pw = getpwuid (getuid());
  194327. if (pw != 0)
  194328. user = pw->pw_name;
  194329. }
  194330. return String::fromUTF8 (user);
  194331. }
  194332. const String SystemStats::getFullUserName()
  194333. {
  194334. return getLogonName();
  194335. }
  194336. void SystemStats::initialiseStats() throw()
  194337. {
  194338. // Process starts off as root when running suid
  194339. Process::lowerPrivilege();
  194340. String s (SystemStats::getJUCEVersion());
  194341. }
  194342. void PlatformUtilities::fpuReset()
  194343. {
  194344. }
  194345. #endif
  194346. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  194347. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  194348. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194349. // compiled on its own).
  194350. #if JUCE_INCLUDED_FILE
  194351. void JUCE_API juce_threadEntryPoint (void*);
  194352. void* threadEntryProc (void* value)
  194353. {
  194354. // New threads start off as root when running suid
  194355. Process::lowerPrivilege();
  194356. juce_threadEntryPoint (value);
  194357. return 0;
  194358. }
  194359. void* juce_createThread (void* userData)
  194360. {
  194361. pthread_t handle = 0;
  194362. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194363. {
  194364. pthread_detach (handle);
  194365. return (void*)handle;
  194366. }
  194367. return 0;
  194368. }
  194369. void juce_killThread (void* handle)
  194370. {
  194371. if (handle != 0)
  194372. pthread_cancel ((pthread_t)handle);
  194373. }
  194374. void juce_setCurrentThreadName (const String& /*name*/)
  194375. {
  194376. }
  194377. Thread::ThreadID Thread::getCurrentThreadId()
  194378. {
  194379. return (ThreadID) pthread_self();
  194380. }
  194381. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194382. // priority of the current thread
  194383. bool juce_setThreadPriority (void* handle, int priority)
  194384. {
  194385. struct sched_param param;
  194386. int policy, maxp, minp, pri;
  194387. if (handle == 0)
  194388. handle = (void*) pthread_self();
  194389. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194390. && policy != SCHED_OTHER)
  194391. {
  194392. minp = sched_get_priority_min(policy);
  194393. maxp = sched_get_priority_max(policy);
  194394. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194395. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194396. // Realtime process priority
  194397. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194398. else
  194399. // High process priority
  194400. param.__sched_priority = minp + pri;
  194401. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194402. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194403. }
  194404. return false;
  194405. }
  194406. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194407. {
  194408. #if SUPPORT_AFFINITIES
  194409. cpu_set_t affinity;
  194410. CPU_ZERO (&affinity);
  194411. for (int i = 0; i < 32; ++i)
  194412. if ((affinityMask & (1 << i)) != 0)
  194413. CPU_SET (i, &affinity);
  194414. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194415. sched_yield();
  194416. #else
  194417. /* affinities aren't supported because either the appropriate header files weren't found,
  194418. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194419. */
  194420. jassertfalse
  194421. #endif
  194422. }
  194423. void Thread::yield()
  194424. {
  194425. sched_yield();
  194426. }
  194427. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194428. void Process::setPriority (ProcessPriority prior)
  194429. {
  194430. struct sched_param param;
  194431. int policy, maxp, minp;
  194432. const int p = (int) prior;
  194433. if (p <= 1)
  194434. policy = SCHED_OTHER;
  194435. else
  194436. policy = SCHED_RR;
  194437. minp = sched_get_priority_min (policy);
  194438. maxp = sched_get_priority_max (policy);
  194439. if (p < 2)
  194440. param.__sched_priority = 0;
  194441. else if (p == 2 )
  194442. // Set to middle of lower realtime priority range
  194443. param.__sched_priority = minp + (maxp - minp) / 4;
  194444. else
  194445. // Set to middle of higher realtime priority range
  194446. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194447. pthread_setschedparam (pthread_self(), policy, &param);
  194448. }
  194449. void Process::terminate()
  194450. {
  194451. exit (0);
  194452. }
  194453. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194454. {
  194455. static char testResult = 0;
  194456. if (testResult == 0)
  194457. {
  194458. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194459. if (testResult >= 0)
  194460. {
  194461. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194462. testResult = 1;
  194463. }
  194464. }
  194465. return testResult < 0;
  194466. }
  194467. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194468. {
  194469. return juce_isRunningUnderDebugger();
  194470. }
  194471. void Process::raisePrivilege()
  194472. {
  194473. // If running suid root, change effective user
  194474. // to root
  194475. if (geteuid() != 0 && getuid() == 0)
  194476. {
  194477. setreuid (geteuid(), getuid());
  194478. setregid (getegid(), getgid());
  194479. }
  194480. }
  194481. void Process::lowerPrivilege()
  194482. {
  194483. // If runing suid root, change effective user
  194484. // back to real user
  194485. if (geteuid() == 0 && getuid() != 0)
  194486. {
  194487. setreuid (geteuid(), getuid());
  194488. setregid (getegid(), getgid());
  194489. }
  194490. }
  194491. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194492. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194493. {
  194494. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194495. }
  194496. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194497. {
  194498. dlclose(handle);
  194499. }
  194500. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194501. {
  194502. return dlsym (libraryHandle, procedureName.toCString());
  194503. }
  194504. #endif
  194505. #endif
  194506. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194507. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194508. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194509. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194510. // compiled on its own).
  194511. #if JUCE_INCLUDED_FILE
  194512. #ifdef JUCE_DEBUG
  194513. #define JUCE_DEBUG_XERRORS 1
  194514. #endif
  194515. extern Display* display;
  194516. extern Window juce_messageWindowHandle;
  194517. static String localClipboardContent;
  194518. static Atom atom_UTF8_STRING;
  194519. static Atom atom_CLIPBOARD;
  194520. static Atom atom_TARGETS;
  194521. static void initSelectionAtoms()
  194522. {
  194523. static bool isInitialised = false;
  194524. if (! isInitialised)
  194525. {
  194526. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194527. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194528. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194529. }
  194530. }
  194531. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194532. // works only for strings shorter than 1000000 bytes
  194533. static String juce_readWindowProperty (Window window, Atom prop,
  194534. Atom fmt, // XA_STRING or UTF8_STRING
  194535. bool deleteAfterReading)
  194536. {
  194537. String returnData;
  194538. char* clipData;
  194539. Atom actualType;
  194540. int actualFormat;
  194541. unsigned long numItems, bytesLeft;
  194542. if (XGetWindowProperty (display, window, prop,
  194543. 0L /* offset */, 1000000 /* length (max) */, False,
  194544. AnyPropertyType /* format */,
  194545. &actualType, &actualFormat, &numItems, &bytesLeft,
  194546. (unsigned char**) &clipData) == Success)
  194547. {
  194548. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194549. {
  194550. returnData = String::fromUTF8 (clipData, numItems);
  194551. }
  194552. else if (actualType == XA_STRING && actualFormat == 8)
  194553. {
  194554. returnData = String (clipData, numItems);
  194555. }
  194556. if (clipData != 0)
  194557. XFree (clipData);
  194558. jassert (bytesLeft == 0 || numItems == 1000000);
  194559. }
  194560. if (deleteAfterReading)
  194561. XDeleteProperty (display, window, prop);
  194562. return returnData;
  194563. }
  194564. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194565. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194566. {
  194567. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194568. // The selection owner will be asked to set the JUCE_SEL property on the
  194569. // juce_messageWindowHandle with the selection content
  194570. XConvertSelection (display, selection, requested_format, property_name,
  194571. juce_messageWindowHandle, CurrentTime);
  194572. int timeoutMs = 200; // will wait at most for 200 ms
  194573. do
  194574. {
  194575. XEvent event;
  194576. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194577. {
  194578. if (event.xselection.property == property_name)
  194579. {
  194580. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194581. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194582. event.xselection.property,
  194583. requested_format, true);
  194584. return true;
  194585. }
  194586. else
  194587. {
  194588. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194589. }
  194590. }
  194591. // not very elegant.. we could do a select() or something like that...
  194592. // however clipboard content requesting is inherently slow on x11, it
  194593. // often takes 50ms or more so...
  194594. Thread::sleep (4);
  194595. timeoutMs -= 4;
  194596. }
  194597. while (timeoutMs > 0);
  194598. DBG("timeout for juce_requestSelectionContent");
  194599. return false;
  194600. }
  194601. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194602. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194603. {
  194604. initSelectionAtoms();
  194605. // the selection content is sent to the target window as a window property
  194606. XSelectionEvent reply;
  194607. reply.type = SelectionNotify;
  194608. reply.display = evt.display;
  194609. reply.requestor = evt.requestor;
  194610. reply.selection = evt.selection;
  194611. reply.target = evt.target;
  194612. reply.property = None; // == "fail"
  194613. reply.time = evt.time;
  194614. HeapBlock <char> data;
  194615. int propertyFormat = 0, numDataItems = 0;
  194616. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194617. {
  194618. if (evt.target == XA_STRING)
  194619. {
  194620. // format data according to system locale
  194621. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194622. data.calloc (numDataItems + 1);
  194623. localClipboardContent.copyToCString (data, numDataItems);
  194624. propertyFormat = 8; // bits/item
  194625. }
  194626. else if (evt.target == atom_UTF8_STRING)
  194627. {
  194628. // translate to utf8
  194629. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194630. data.calloc (numDataItems + 1);
  194631. localClipboardContent.copyToUTF8 (data, numDataItems);
  194632. propertyFormat = 8; // bits/item
  194633. }
  194634. else if (evt.target == atom_TARGETS)
  194635. {
  194636. // another application wants to know what we are able to send
  194637. numDataItems = 2;
  194638. propertyFormat = 32; // atoms are 32-bit
  194639. data.calloc (numDataItems * 4);
  194640. ((Atom*) data)[0] = atom_UTF8_STRING;
  194641. ((Atom*) data)[1] = XA_STRING;
  194642. }
  194643. }
  194644. else
  194645. {
  194646. DBG ("requested unsupported clipboard");
  194647. }
  194648. if (data != 0)
  194649. {
  194650. const int maxReasonableSelectionSize = 1000000;
  194651. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194652. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194653. {
  194654. XChangeProperty (evt.display, evt.requestor,
  194655. evt.property, evt.target,
  194656. propertyFormat /* 8 or 32 */, PropModeReplace,
  194657. (const unsigned char*) data, numDataItems);
  194658. reply.property = evt.property; // " == success"
  194659. }
  194660. }
  194661. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194662. }
  194663. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194664. {
  194665. initSelectionAtoms();
  194666. localClipboardContent = clipText;
  194667. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194668. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194669. }
  194670. const String SystemClipboard::getTextFromClipboard() throw()
  194671. {
  194672. initSelectionAtoms();
  194673. String content;
  194674. Atom selection = XA_PRIMARY;
  194675. Window selectionOwner = None;
  194676. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194677. {
  194678. selection = atom_CLIPBOARD;
  194679. selectionOwner = XGetSelectionOwner (display, selection);
  194680. }
  194681. if (selectionOwner != None)
  194682. {
  194683. if (selectionOwner == juce_messageWindowHandle)
  194684. {
  194685. content = localClipboardContent;
  194686. }
  194687. else
  194688. {
  194689. // first try: we want an utf8 string
  194690. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194691. if (! ok)
  194692. {
  194693. // second chance, ask for a good old locale-dependent string ..
  194694. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194695. }
  194696. }
  194697. }
  194698. return content;
  194699. }
  194700. #endif
  194701. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194702. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194703. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194704. // compiled on its own).
  194705. #if JUCE_INCLUDED_FILE
  194706. #ifdef JUCE_DEBUG
  194707. #define JUCE_DEBUG_XERRORS 1
  194708. #endif
  194709. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194710. Window juce_messageWindowHandle = None;
  194711. #define SpecialAtom "JUCESpecialAtom"
  194712. #define BroadcastAtom "JUCEBroadcastAtom"
  194713. #define SpecialCallbackAtom "JUCESpecialCallbackAtom"
  194714. static Atom specialId;
  194715. static Atom broadcastId;
  194716. static Atom specialCallbackId;
  194717. // This is referenced from Windowing.cpp
  194718. XContext improbableNumber;
  194719. // Defined in Windowing.cpp
  194720. extern void juce_windowMessageReceive (XEvent* event);
  194721. // Defined in Clipboard.cpp
  194722. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt);
  194723. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194724. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194725. class InternalMessageQueue
  194726. {
  194727. public:
  194728. InternalMessageQueue()
  194729. : bytesInSocket (0)
  194730. {
  194731. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194732. (void) ret; jassert (ret == 0);
  194733. setNonBlocking (fd[0]);
  194734. setNonBlocking (fd[1]);
  194735. }
  194736. ~InternalMessageQueue()
  194737. {
  194738. close (fd[0]);
  194739. close (fd[1]);
  194740. }
  194741. void postMessage (Message* msg)
  194742. {
  194743. const int maxBytesInSocketQueue = 128;
  194744. ScopedLock sl (lock);
  194745. queue.add (msg);
  194746. if (bytesInSocket < maxBytesInSocketQueue)
  194747. {
  194748. ++bytesInSocket;
  194749. ScopedUnlock ul (lock);
  194750. const unsigned char x = 0xff;
  194751. size_t bytesWritten = write (fd[0], &x, 1);
  194752. (void) bytesWritten;
  194753. }
  194754. }
  194755. bool isEmpty() const
  194756. {
  194757. ScopedLock sl (lock);
  194758. return queue.size() == 0;
  194759. }
  194760. Message* popNextMessage()
  194761. {
  194762. ScopedLock sl (lock);
  194763. if (bytesInSocket > 0)
  194764. {
  194765. --bytesInSocket;
  194766. ScopedUnlock ul (lock);
  194767. unsigned char x;
  194768. size_t numBytes = read (fd[1], &x, 1);
  194769. (void) numBytes;
  194770. }
  194771. Message* m = queue[0];
  194772. queue.remove (0, false /* deleteObject */);
  194773. return m;
  194774. }
  194775. int getWaitHandle() const { return fd[1]; }
  194776. private:
  194777. CriticalSection lock;
  194778. OwnedArray <Message> queue;
  194779. int fd[2];
  194780. int bytesInSocket;
  194781. static bool setNonBlocking (int handle)
  194782. {
  194783. int socketFlags = fcntl (handle, F_GETFL, 0);
  194784. if (socketFlags == -1)
  194785. return false;
  194786. socketFlags |= O_NONBLOCK;
  194787. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194788. }
  194789. };
  194790. struct MessageThreadFuncCall
  194791. {
  194792. enum { uniqueID = 0x73774623 };
  194793. MessageCallbackFunction* func;
  194794. void* parameter;
  194795. void* result;
  194796. CriticalSection lock;
  194797. WaitableEvent event;
  194798. };
  194799. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194800. // error handling in X11
  194801. static bool errorOccurred = false;
  194802. static bool keyboardBreakOccurred = false;
  194803. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194804. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194805. // Usually happens when client-server connection is broken
  194806. static int ioErrorHandler (Display* display)
  194807. {
  194808. DBG (T("ERROR: connection to X server broken.. terminating."));
  194809. errorOccurred = true;
  194810. if (JUCEApplication::getInstance() != 0)
  194811. Process::terminate();
  194812. return 0;
  194813. }
  194814. // A protocol error has occurred
  194815. static int errorHandler (Display* display, XErrorEvent* event)
  194816. {
  194817. #ifdef JUCE_DEBUG_XERRORS
  194818. char errorStr[64] = { 0 };
  194819. char requestStr[64] = { 0 };
  194820. XGetErrorText (display, event->error_code, errorStr, 64);
  194821. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194822. "Unknown", requestStr, 64);
  194823. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194824. #endif
  194825. return 0;
  194826. }
  194827. // Breakin from keyboard
  194828. static void signalHandler (int sig)
  194829. {
  194830. if (sig == SIGINT)
  194831. {
  194832. keyboardBreakOccurred = true;
  194833. return;
  194834. }
  194835. static bool reentrant = false;
  194836. if (! reentrant)
  194837. {
  194838. reentrant = true;
  194839. // Illegal instruction
  194840. fflush (stdout);
  194841. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194842. errorOccurred = true;
  194843. if (JUCEApplication::getInstance() != 0)
  194844. Process::terminate();
  194845. }
  194846. else
  194847. {
  194848. if (JUCEApplication::getInstance() != 0)
  194849. exit(0);
  194850. }
  194851. }
  194852. void MessageManager::doPlatformSpecificInitialisation()
  194853. {
  194854. // Initialise xlib for multiple thread support
  194855. static bool initThreadCalled = false;
  194856. if (! initThreadCalled)
  194857. {
  194858. if (! XInitThreads())
  194859. {
  194860. // This is fatal! Print error and closedown
  194861. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194862. if (JUCEApplication::getInstance() != 0)
  194863. Process::terminate();
  194864. return;
  194865. }
  194866. initThreadCalled = true;
  194867. }
  194868. // This is called if the client/server connection is broken
  194869. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194870. // This is called if a protocol error occurs
  194871. oldErrorHandler = XSetErrorHandler (errorHandler);
  194872. // Install signal handler for break-in
  194873. struct sigaction saction;
  194874. sigset_t maskSet;
  194875. sigemptyset (&maskSet);
  194876. saction.sa_handler = signalHandler;
  194877. saction.sa_mask = maskSet;
  194878. saction.sa_flags = 0;
  194879. sigaction (SIGINT, &saction, NULL);
  194880. #ifndef _DEBUG
  194881. // Setup signal handlers for various fatal errors
  194882. sigaction (SIGILL, &saction, NULL);
  194883. sigaction (SIGBUS, &saction, NULL);
  194884. sigaction (SIGFPE, &saction, NULL);
  194885. sigaction (SIGSEGV, &saction, NULL);
  194886. sigaction (SIGSYS, &saction, NULL);
  194887. #endif
  194888. // Create the internal message queue
  194889. juce_internalMessageQueue = new InternalMessageQueue();
  194890. // Try to connect to a display
  194891. String displayName (getenv ("DISPLAY"));
  194892. if (displayName.isEmpty())
  194893. displayName = ":0.0";
  194894. display = XOpenDisplay (displayName.toCString());
  194895. if (display == 0)
  194896. {
  194897. // This is not fatal! we can run headless.
  194898. return;
  194899. }
  194900. // Get defaults for various properties
  194901. int screen = DefaultScreen (display);
  194902. Window root = RootWindow (display, screen);
  194903. Visual* visual = DefaultVisual (display, screen);
  194904. // Create atoms for our ClientMessages (these cannot be deleted)
  194905. specialId = XInternAtom (display, SpecialAtom, false);
  194906. broadcastId = XInternAtom (display, BroadcastAtom, false);
  194907. specialCallbackId = XInternAtom (display, SpecialCallbackAtom, false);
  194908. // Create a context to store user data associated with Windows we
  194909. // create in WindowDriver
  194910. improbableNumber = XUniqueContext();
  194911. // We're only interested in client messages for this window
  194912. // which are always sent
  194913. XSetWindowAttributes swa;
  194914. swa.event_mask = NoEventMask;
  194915. // Create our message window (this will never be mapped)
  194916. juce_messageWindowHandle = XCreateWindow (display, root,
  194917. 0, 0, 1, 1, 0, 0, InputOnly,
  194918. visual, CWEventMask, &swa);
  194919. }
  194920. void MessageManager::doPlatformSpecificShutdown()
  194921. {
  194922. deleteAndZero (juce_internalMessageQueue);
  194923. if (display != 0 && ! errorOccurred)
  194924. {
  194925. XDestroyWindow (display, juce_messageWindowHandle);
  194926. XCloseDisplay (display);
  194927. // reset pointers
  194928. juce_messageWindowHandle = 0;
  194929. display = 0;
  194930. // Restore original error handlers
  194931. XSetIOErrorHandler (oldIOErrorHandler);
  194932. oldIOErrorHandler = 0;
  194933. XSetErrorHandler (oldErrorHandler);
  194934. oldErrorHandler = 0;
  194935. }
  194936. }
  194937. bool juce_postMessageToSystemQueue (void* message)
  194938. {
  194939. if (errorOccurred)
  194940. return false;
  194941. juce_internalMessageQueue->postMessage ((Message*) message);
  194942. return true;
  194943. }
  194944. void MessageManager::broadcastMessage (const String& value) throw()
  194945. {
  194946. }
  194947. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194948. void* parameter)
  194949. {
  194950. if (errorOccurred)
  194951. return 0;
  194952. if (! isThisTheMessageThread())
  194953. {
  194954. MessageThreadFuncCall messageCallContext;
  194955. messageCallContext.func = func;
  194956. messageCallContext.parameter = parameter;
  194957. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194958. 0, 0, &messageCallContext));
  194959. // Wait for it to complete before continuing
  194960. messageCallContext.event.wait();
  194961. return messageCallContext.result;
  194962. }
  194963. else
  194964. {
  194965. // Just call the function directly
  194966. return func (parameter);
  194967. }
  194968. }
  194969. // Wait for an event (either XEvent, or an internal Message)
  194970. static bool juce_sleepUntilEvent (const int timeoutMs)
  194971. {
  194972. if (! juce_internalMessageQueue->isEmpty())
  194973. return true;
  194974. if (display != 0)
  194975. {
  194976. ScopedXLock xlock;
  194977. if (XPending (display))
  194978. return true;
  194979. }
  194980. struct timeval tv;
  194981. tv.tv_sec = 0;
  194982. tv.tv_usec = timeoutMs * 1000;
  194983. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194984. int fdmax = fd0;
  194985. fd_set readset;
  194986. FD_ZERO (&readset);
  194987. FD_SET (fd0, &readset);
  194988. if (display != 0)
  194989. {
  194990. ScopedXLock xlock;
  194991. int fd1 = XConnectionNumber (display);
  194992. FD_SET (fd1, &readset);
  194993. fdmax = jmax (fd0, fd1);
  194994. }
  194995. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194996. return (ret > 0); // ret <= 0 if error or timeout
  194997. }
  194998. // Handle next XEvent (if any)
  194999. static bool juce_dispatchNextXEvent()
  195000. {
  195001. if (display == 0)
  195002. return false;
  195003. XEvent evt;
  195004. {
  195005. ScopedXLock xlock;
  195006. if (! XPending (display))
  195007. return false;
  195008. XNextEvent (display, &evt);
  195009. }
  195010. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  195011. {
  195012. juce_handleSelectionRequest (evt.xselectionrequest);
  195013. }
  195014. else if (evt.xany.window != juce_messageWindowHandle)
  195015. {
  195016. juce_windowMessageReceive (&evt);
  195017. }
  195018. return true;
  195019. }
  195020. // Handle next internal Message (if any)
  195021. static bool juce_dispatchNextInternalMessage()
  195022. {
  195023. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  195024. if (msg == 0)
  195025. return false;
  195026. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  195027. {
  195028. // Handle callback message
  195029. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  195030. call->result = (*(call->func)) (call->parameter);
  195031. call->event.signal();
  195032. }
  195033. else
  195034. {
  195035. // Handle "normal" messages
  195036. MessageManager::getInstance()->deliverMessage (msg.release());
  195037. }
  195038. return true;
  195039. }
  195040. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  195041. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  195042. {
  195043. for (;;)
  195044. {
  195045. if (errorOccurred)
  195046. break;
  195047. if (keyboardBreakOccurred)
  195048. {
  195049. errorOccurred = true;
  195050. if (JUCEApplication::getInstance() != 0)
  195051. Process::terminate();
  195052. break;
  195053. }
  195054. static int totalEventCount = 0;
  195055. ++totalEventCount;
  195056. // The purpose here is to give either priority to XEvents or
  195057. // to internal messages This is necessary to keep a "good"
  195058. // behaviour when the cpu is overloaded
  195059. if (totalEventCount & 1)
  195060. {
  195061. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  195062. return true;
  195063. }
  195064. else
  195065. {
  195066. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  195067. return true;
  195068. }
  195069. if (returnIfNoPendingMessages) // early exit
  195070. break;
  195071. // the timeout is to be on the safe side, but it does not seem to be useful
  195072. juce_sleepUntilEvent (2000);
  195073. }
  195074. return false;
  195075. }
  195076. #endif
  195077. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  195078. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  195079. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195080. // compiled on its own).
  195081. #if JUCE_INCLUDED_FILE
  195082. class FreeTypeFontFace
  195083. {
  195084. public:
  195085. enum FontStyle
  195086. {
  195087. Plain = 0,
  195088. Bold = 1,
  195089. Italic = 2
  195090. };
  195091. struct FontNameIndex
  195092. {
  195093. String fileName;
  195094. int faceIndex;
  195095. };
  195096. FreeTypeFontFace (const String& familyName) throw()
  195097. : hasSerif (false),
  195098. monospaced (false)
  195099. {
  195100. family = familyName;
  195101. }
  195102. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  195103. {
  195104. if (names [(int) style].fileName.isEmpty())
  195105. {
  195106. names [(int) style].fileName = name;
  195107. names [(int) style].faceIndex = faceIndex;
  195108. }
  195109. }
  195110. const String& getFamilyName() const throw() { return family; }
  195111. const String& getFileName (const int style, int& faceIndex) const throw()
  195112. {
  195113. faceIndex = names[style].faceIndex;
  195114. return names[style].fileName;
  195115. }
  195116. void setMonospaced (bool mono) throw() { monospaced = mono; }
  195117. bool getMonospaced() const throw() { return monospaced; }
  195118. void setSerif (const bool serif) throw() { hasSerif = serif; }
  195119. bool getSerif() const throw() { return hasSerif; }
  195120. private:
  195121. String family;
  195122. FontNameIndex names[4];
  195123. bool hasSerif, monospaced;
  195124. };
  195125. class FreeTypeInterface : public DeletedAtShutdown
  195126. {
  195127. public:
  195128. FreeTypeInterface() throw()
  195129. : lastFace (0),
  195130. lastBold (false),
  195131. lastItalic (false)
  195132. {
  195133. if (FT_Init_FreeType (&ftLib) != 0)
  195134. {
  195135. ftLib = 0;
  195136. DBG (T("Failed to initialize FreeType"));
  195137. }
  195138. StringArray fontDirs;
  195139. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  195140. fontDirs.removeEmptyStrings (true);
  195141. if (fontDirs.size() == 0)
  195142. {
  195143. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  195144. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  195145. if (fontsInfo != 0)
  195146. {
  195147. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  195148. {
  195149. fontDirs.add (e->getAllSubText().trim());
  195150. }
  195151. delete fontsInfo;
  195152. }
  195153. }
  195154. if (fontDirs.size() == 0)
  195155. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  195156. for (int i = 0; i < fontDirs.size(); ++i)
  195157. enumerateFaces (fontDirs[i]);
  195158. }
  195159. ~FreeTypeInterface() throw()
  195160. {
  195161. if (lastFace != 0)
  195162. FT_Done_Face (lastFace);
  195163. if (ftLib != 0)
  195164. FT_Done_FreeType (ftLib);
  195165. clearSingletonInstance();
  195166. }
  195167. FreeTypeFontFace* findOrCreate (const String& familyName,
  195168. const bool create = false) throw()
  195169. {
  195170. for (int i = 0; i < faces.size(); i++)
  195171. if (faces[i]->getFamilyName() == familyName)
  195172. return faces[i];
  195173. if (! create)
  195174. return NULL;
  195175. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  195176. faces.add (newFace);
  195177. return newFace;
  195178. }
  195179. // Enumerate all font faces available in a given directory
  195180. void enumerateFaces (const String& path) throw()
  195181. {
  195182. File dirPath (path);
  195183. if (path.isEmpty() || ! dirPath.isDirectory())
  195184. return;
  195185. DirectoryIterator di (dirPath, true);
  195186. while (di.next())
  195187. {
  195188. File possible (di.getFile());
  195189. if (possible.hasFileExtension (T("ttf"))
  195190. || possible.hasFileExtension (T("pfb"))
  195191. || possible.hasFileExtension (T("pcf")))
  195192. {
  195193. FT_Face face;
  195194. int faceIndex = 0;
  195195. int numFaces = 0;
  195196. do
  195197. {
  195198. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  195199. faceIndex, &face) == 0)
  195200. {
  195201. if (faceIndex == 0)
  195202. numFaces = face->num_faces;
  195203. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  195204. {
  195205. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  195206. int style = (int) FreeTypeFontFace::Plain;
  195207. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  195208. style |= (int) FreeTypeFontFace::Bold;
  195209. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  195210. style |= (int) FreeTypeFontFace::Italic;
  195211. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  195212. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  195213. // Surely there must be a better way to do this?
  195214. const String name (face->family_name);
  195215. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  195216. || name.containsIgnoreCase (T("Verdana"))
  195217. || name.containsIgnoreCase (T("Arial"))));
  195218. }
  195219. FT_Done_Face (face);
  195220. }
  195221. ++faceIndex;
  195222. }
  195223. while (faceIndex < numFaces);
  195224. }
  195225. }
  195226. }
  195227. // Create a FreeType face object for a given font
  195228. FT_Face createFT_Face (const String& fontName,
  195229. const bool bold,
  195230. const bool italic) throw()
  195231. {
  195232. FT_Face face = 0;
  195233. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  195234. {
  195235. face = lastFace;
  195236. }
  195237. else
  195238. {
  195239. if (lastFace != 0)
  195240. {
  195241. FT_Done_Face (lastFace);
  195242. lastFace = 0;
  195243. }
  195244. lastFontName = fontName;
  195245. lastBold = bold;
  195246. lastItalic = italic;
  195247. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  195248. if (ftFace != 0)
  195249. {
  195250. int style = (int) FreeTypeFontFace::Plain;
  195251. if (bold)
  195252. style |= (int) FreeTypeFontFace::Bold;
  195253. if (italic)
  195254. style |= (int) FreeTypeFontFace::Italic;
  195255. int faceIndex;
  195256. String fileName (ftFace->getFileName (style, faceIndex));
  195257. if (fileName.isEmpty())
  195258. {
  195259. style ^= (int) FreeTypeFontFace::Bold;
  195260. fileName = ftFace->getFileName (style, faceIndex);
  195261. if (fileName.isEmpty())
  195262. {
  195263. style ^= (int) FreeTypeFontFace::Bold;
  195264. style ^= (int) FreeTypeFontFace::Italic;
  195265. fileName = ftFace->getFileName (style, faceIndex);
  195266. if (! fileName.length())
  195267. {
  195268. style ^= (int) FreeTypeFontFace::Bold;
  195269. fileName = ftFace->getFileName (style, faceIndex);
  195270. }
  195271. }
  195272. }
  195273. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  195274. {
  195275. face = lastFace;
  195276. // If there isn't a unicode charmap then select the first one.
  195277. if (FT_Select_Charmap (face, ft_encoding_unicode))
  195278. FT_Set_Charmap (face, face->charmaps[0]);
  195279. }
  195280. }
  195281. }
  195282. return face;
  195283. }
  195284. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  195285. {
  195286. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  195287. const float height = (float) (face->ascender - face->descender);
  195288. const float scaleX = 1.0f / height;
  195289. const float scaleY = -1.0f / height;
  195290. Path destShape;
  195291. #define CONVERTX(val) (scaleX * (val).x)
  195292. #define CONVERTY(val) (scaleY * (val).y)
  195293. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  195294. || face->glyph->format != ft_glyph_format_outline)
  195295. {
  195296. return false;
  195297. }
  195298. const FT_Outline* const outline = &face->glyph->outline;
  195299. const short* const contours = outline->contours;
  195300. const char* const tags = outline->tags;
  195301. FT_Vector* const points = outline->points;
  195302. for (int c = 0; c < outline->n_contours; c++)
  195303. {
  195304. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  195305. const int endPoint = contours[c];
  195306. for (int p = startPoint; p <= endPoint; p++)
  195307. {
  195308. const float x = CONVERTX (points[p]);
  195309. const float y = CONVERTY (points[p]);
  195310. if (p == startPoint)
  195311. {
  195312. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195313. {
  195314. float x2 = CONVERTX (points [endPoint]);
  195315. float y2 = CONVERTY (points [endPoint]);
  195316. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  195317. {
  195318. x2 = (x + x2) * 0.5f;
  195319. y2 = (y + y2) * 0.5f;
  195320. }
  195321. destShape.startNewSubPath (x2, y2);
  195322. }
  195323. else
  195324. {
  195325. destShape.startNewSubPath (x, y);
  195326. }
  195327. }
  195328. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195329. {
  195330. if (p != startPoint)
  195331. destShape.lineTo (x, y);
  195332. }
  195333. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195334. {
  195335. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195336. float x2 = CONVERTX (points [nextIndex]);
  195337. float y2 = CONVERTY (points [nextIndex]);
  195338. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195339. {
  195340. x2 = (x + x2) * 0.5f;
  195341. y2 = (y + y2) * 0.5f;
  195342. }
  195343. else
  195344. {
  195345. ++p;
  195346. }
  195347. destShape.quadraticTo (x, y, x2, y2);
  195348. }
  195349. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195350. {
  195351. if (p >= endPoint)
  195352. return false;
  195353. const int next1 = p + 1;
  195354. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195355. const float x2 = CONVERTX (points [next1]);
  195356. const float y2 = CONVERTY (points [next1]);
  195357. const float x3 = CONVERTX (points [next2]);
  195358. const float y3 = CONVERTY (points [next2]);
  195359. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195360. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195361. return false;
  195362. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195363. p += 2;
  195364. }
  195365. }
  195366. destShape.closeSubPath();
  195367. }
  195368. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195369. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195370. addKerning (face, dest, character, glyphIndex);
  195371. return true;
  195372. }
  195373. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195374. {
  195375. const float height = (float) (face->ascender - face->descender);
  195376. uint32 rightGlyphIndex;
  195377. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195378. while (rightGlyphIndex != 0)
  195379. {
  195380. FT_Vector kerning;
  195381. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195382. {
  195383. if (kerning.x != 0)
  195384. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195385. }
  195386. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195387. }
  195388. }
  195389. // Add a glyph to a font
  195390. bool addGlyphToFont (const uint32 character,
  195391. const tchar* fontName, bool bold, bool italic,
  195392. CustomTypeface& dest) throw()
  195393. {
  195394. FT_Face face = createFT_Face (fontName, bold, italic);
  195395. if (face != 0)
  195396. return addGlyph (face, dest, character);
  195397. return false;
  195398. }
  195399. void getFamilyNames (StringArray& familyNames) const throw()
  195400. {
  195401. for (int i = 0; i < faces.size(); i++)
  195402. familyNames.add (faces[i]->getFamilyName());
  195403. }
  195404. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195405. {
  195406. for (int i = 0; i < faces.size(); i++)
  195407. if (faces[i]->getMonospaced())
  195408. monoSpaced.add (faces[i]->getFamilyName());
  195409. }
  195410. void getSerifNames (StringArray& serif) const throw()
  195411. {
  195412. for (int i = 0; i < faces.size(); i++)
  195413. if (faces[i]->getSerif())
  195414. serif.add (faces[i]->getFamilyName());
  195415. }
  195416. void getSansSerifNames (StringArray& sansSerif) const throw()
  195417. {
  195418. for (int i = 0; i < faces.size(); i++)
  195419. if (! faces[i]->getSerif())
  195420. sansSerif.add (faces[i]->getFamilyName());
  195421. }
  195422. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195423. private:
  195424. FT_Library ftLib;
  195425. FT_Face lastFace;
  195426. String lastFontName;
  195427. bool lastBold, lastItalic;
  195428. OwnedArray<FreeTypeFontFace> faces;
  195429. };
  195430. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195431. class FreetypeTypeface : public CustomTypeface
  195432. {
  195433. public:
  195434. FreetypeTypeface (const Font& font)
  195435. {
  195436. FT_Face face = FreeTypeInterface::getInstance()
  195437. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195438. if (face == 0)
  195439. {
  195440. #ifdef JUCE_DEBUG
  195441. String msg (T("Failed to create typeface: "));
  195442. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195443. DBG (msg);
  195444. #endif
  195445. }
  195446. else
  195447. {
  195448. setCharacteristics (font.getTypefaceName(),
  195449. face->ascender / (float) (face->ascender - face->descender),
  195450. font.isBold(), font.isItalic(),
  195451. L' ');
  195452. }
  195453. }
  195454. bool loadGlyphIfPossible (const juce_wchar character)
  195455. {
  195456. return FreeTypeInterface::getInstance()
  195457. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195458. }
  195459. };
  195460. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195461. {
  195462. return new FreetypeTypeface (font);
  195463. }
  195464. const StringArray Font::findAllTypefaceNames() throw()
  195465. {
  195466. StringArray s;
  195467. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195468. s.sort (true);
  195469. return s;
  195470. }
  195471. static const String pickBestFont (const StringArray& names,
  195472. const char* const choicesString)
  195473. {
  195474. StringArray choices;
  195475. choices.addTokens (String (choicesString), T(","), 0);
  195476. choices.trim();
  195477. choices.removeEmptyStrings();
  195478. int i, j;
  195479. for (j = 0; j < choices.size(); ++j)
  195480. if (names.contains (choices[j], true))
  195481. return choices[j];
  195482. for (j = 0; j < choices.size(); ++j)
  195483. for (i = 0; i < names.size(); i++)
  195484. if (names[i].startsWithIgnoreCase (choices[j]))
  195485. return names[i];
  195486. for (j = 0; j < choices.size(); ++j)
  195487. for (i = 0; i < names.size(); i++)
  195488. if (names[i].containsIgnoreCase (choices[j]))
  195489. return names[i];
  195490. return names[0];
  195491. }
  195492. static const String linux_getDefaultSansSerifFontName()
  195493. {
  195494. StringArray allFonts;
  195495. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195496. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195497. }
  195498. static const String linux_getDefaultSerifFontName()
  195499. {
  195500. StringArray allFonts;
  195501. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195502. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195503. }
  195504. static const String linux_getDefaultMonospacedFontName()
  195505. {
  195506. StringArray allFonts;
  195507. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195508. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195509. }
  195510. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195511. {
  195512. defaultSans = linux_getDefaultSansSerifFontName();
  195513. defaultSerif = linux_getDefaultSerifFontName();
  195514. defaultFixed = linux_getDefaultMonospacedFontName();
  195515. }
  195516. #endif
  195517. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195518. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195519. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195520. // compiled on its own).
  195521. #if JUCE_INCLUDED_FILE
  195522. #define TAKE_FOCUS 0
  195523. #define DELETE_WINDOW 1
  195524. #define SYSTEM_TRAY_REQUEST_DOCK 0
  195525. #define SYSTEM_TRAY_BEGIN_MESSAGE 1
  195526. #define SYSTEM_TRAY_CANCEL_MESSAGE 2
  195527. static const int repaintTimerPeriod = 1000 / 100; // 100 fps maximum
  195528. static Atom wm_ChangeState = None;
  195529. static Atom wm_State = None;
  195530. static Atom wm_Protocols = None;
  195531. static Atom wm_ProtocolList [2] = { None, None };
  195532. static Atom wm_ActiveWin = None;
  195533. #define ourDndVersion 3
  195534. static Atom XA_XdndAware = None;
  195535. static Atom XA_XdndEnter = None;
  195536. static Atom XA_XdndLeave = None;
  195537. static Atom XA_XdndPosition = None;
  195538. static Atom XA_XdndStatus = None;
  195539. static Atom XA_XdndDrop = None;
  195540. static Atom XA_XdndFinished = None;
  195541. static Atom XA_XdndSelection = None;
  195542. static Atom XA_XdndProxy = None;
  195543. static Atom XA_XdndTypeList = None;
  195544. static Atom XA_XdndActionList = None;
  195545. static Atom XA_XdndActionDescription = None;
  195546. static Atom XA_XdndActionCopy = None;
  195547. static Atom XA_XdndActionMove = None;
  195548. static Atom XA_XdndActionLink = None;
  195549. static Atom XA_XdndActionAsk = None;
  195550. static Atom XA_XdndActionPrivate = None;
  195551. static Atom XA_JXSelectionWindowProperty = None;
  195552. static Atom XA_MimeTextPlain = None;
  195553. static Atom XA_MimeTextUriList = None;
  195554. static Atom XA_MimeRootDrop = None;
  195555. static XErrorHandler oldHandler = 0;
  195556. static int trappedErrorCode = 0;
  195557. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195558. {
  195559. trappedErrorCode = err->error_code;
  195560. return 0;
  195561. }
  195562. static void trapErrors()
  195563. {
  195564. trappedErrorCode = 0;
  195565. oldHandler = XSetErrorHandler (errorTrapHandler);
  195566. }
  195567. static bool untrapErrors()
  195568. {
  195569. XSetErrorHandler (oldHandler);
  195570. return (trappedErrorCode == 0);
  195571. }
  195572. static bool isActiveApplication = false;
  195573. bool Process::isForegroundProcess()
  195574. {
  195575. return isActiveApplication;
  195576. }
  195577. // These are defined in juce_linux_Messaging.cpp
  195578. extern Display* display;
  195579. extern XContext improbableNumber;
  195580. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195581. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195582. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195583. enum MouseButtons
  195584. {
  195585. NoButton = 0,
  195586. LeftButton = 1,
  195587. MiddleButton = 2,
  195588. RightButton = 3,
  195589. WheelUp = 4,
  195590. WheelDown = 5
  195591. };
  195592. static int AltMask = 0;
  195593. static int NumLockMask = 0;
  195594. static bool numLock = 0;
  195595. static bool capsLock = 0;
  195596. static char keyStates [32];
  195597. static void updateKeyStates (const int keycode, const bool press) throw()
  195598. {
  195599. const int keybyte = keycode >> 3;
  195600. const int keybit = (1 << (keycode & 7));
  195601. if (press)
  195602. keyStates [keybyte] |= keybit;
  195603. else
  195604. keyStates [keybyte] &= ~keybit;
  195605. }
  195606. static bool keyDown (const int keycode) throw()
  195607. {
  195608. const int keybyte = keycode >> 3;
  195609. const int keybit = (1 << (keycode & 7));
  195610. return (keyStates [keybyte] & keybit) != 0;
  195611. }
  195612. static const int extendedKeyModifier = 0x10000000;
  195613. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195614. {
  195615. int keysym;
  195616. if (keyCode & extendedKeyModifier)
  195617. {
  195618. keysym = 0xff00 | (keyCode & 0xff);
  195619. }
  195620. else
  195621. {
  195622. keysym = keyCode;
  195623. if (keysym == (XK_Tab & 0xff)
  195624. || keysym == (XK_Return & 0xff)
  195625. || keysym == (XK_Escape & 0xff)
  195626. || keysym == (XK_BackSpace & 0xff))
  195627. {
  195628. keysym |= 0xff00;
  195629. }
  195630. }
  195631. ScopedXLock xlock;
  195632. return keyDown (XKeysymToKeycode (display, keysym));
  195633. }
  195634. #if JUCE_USE_XSHM
  195635. static bool isShmAvailable() throw()
  195636. {
  195637. ScopedXLock xlock;
  195638. static bool isChecked = false;
  195639. static bool isAvailable = false;
  195640. if (! isChecked)
  195641. {
  195642. isChecked = true;
  195643. int major, minor;
  195644. Bool pixmaps;
  195645. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195646. {
  195647. trapErrors();
  195648. XShmSegmentInfo segmentInfo;
  195649. zerostruct (segmentInfo);
  195650. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195651. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195652. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195653. xImage->bytes_per_line * xImage->height,
  195654. IPC_CREAT | 0777)) >= 0)
  195655. {
  195656. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195657. if (segmentInfo.shmaddr != (void*) -1)
  195658. {
  195659. segmentInfo.readOnly = False;
  195660. xImage->data = segmentInfo.shmaddr;
  195661. XSync (display, False);
  195662. if (XShmAttach (display, &segmentInfo) != 0)
  195663. {
  195664. XSync (display, False);
  195665. XShmDetach (display, &segmentInfo);
  195666. isAvailable = true;
  195667. }
  195668. }
  195669. XFlush (display);
  195670. XDestroyImage (xImage);
  195671. shmdt (segmentInfo.shmaddr);
  195672. }
  195673. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195674. isAvailable &= untrapErrors();
  195675. }
  195676. }
  195677. return isAvailable;
  195678. }
  195679. #endif
  195680. class XBitmapImage : public Image
  195681. {
  195682. public:
  195683. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195684. const bool clearImage, const bool is16Bit_)
  195685. : Image (format_, w, h),
  195686. is16Bit (is16Bit_)
  195687. {
  195688. jassert (format_ == RGB || format_ == ARGB);
  195689. pixelStride = (format_ == RGB) ? 3 : 4;
  195690. lineStride = ((w * pixelStride + 3) & ~3);
  195691. ScopedXLock xlock;
  195692. Visual* const visual = DefaultVisual (display, DefaultScreen (display));
  195693. #if JUCE_USE_XSHM
  195694. usingXShm = false;
  195695. if ((! is16Bit) && isShmAvailable())
  195696. {
  195697. zerostruct (segmentInfo);
  195698. xImage = XShmCreateImage (display, visual, 24, ZPixmap, 0, &segmentInfo, w, h);
  195699. if (xImage != 0)
  195700. {
  195701. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195702. xImage->bytes_per_line * xImage->height,
  195703. IPC_CREAT | 0777)) >= 0)
  195704. {
  195705. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195706. if (segmentInfo.shmaddr != (void*) -1)
  195707. {
  195708. segmentInfo.readOnly = False;
  195709. xImage->data = segmentInfo.shmaddr;
  195710. imageData = (uint8*) segmentInfo.shmaddr;
  195711. XSync (display, False);
  195712. if (XShmAttach (display, &segmentInfo) != 0)
  195713. {
  195714. XSync (display, False);
  195715. usingXShm = true;
  195716. }
  195717. else
  195718. {
  195719. jassertfalse
  195720. }
  195721. }
  195722. else
  195723. {
  195724. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195725. }
  195726. }
  195727. }
  195728. }
  195729. if (! usingXShm)
  195730. #endif
  195731. {
  195732. imageDataAllocated.malloc (lineStride * h);
  195733. imageData = imageDataAllocated;
  195734. if (format_ == ARGB && clearImage)
  195735. zeromem (imageData, h * lineStride);
  195736. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195737. xImage->width = w;
  195738. xImage->height = h;
  195739. xImage->xoffset = 0;
  195740. xImage->format = ZPixmap;
  195741. xImage->data = (char*) imageData;
  195742. xImage->byte_order = ImageByteOrder (display);
  195743. xImage->bitmap_unit = BitmapUnit (display);
  195744. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195745. xImage->bitmap_pad = 32;
  195746. xImage->depth = pixelStride * 8;
  195747. xImage->bytes_per_line = lineStride;
  195748. xImage->bits_per_pixel = pixelStride * 8;
  195749. xImage->red_mask = 0x00FF0000;
  195750. xImage->green_mask = 0x0000FF00;
  195751. xImage->blue_mask = 0x000000FF;
  195752. if (is16Bit)
  195753. {
  195754. const int pixelStride = 2;
  195755. const int lineStride = ((w * pixelStride + 3) & ~3);
  195756. imageData16Bit.malloc (lineStride * h);
  195757. xImage->data = imageData16Bit;
  195758. xImage->bitmap_pad = 16;
  195759. xImage->depth = pixelStride * 8;
  195760. xImage->bytes_per_line = lineStride;
  195761. xImage->bits_per_pixel = pixelStride * 8;
  195762. xImage->red_mask = visual->red_mask;
  195763. xImage->green_mask = visual->green_mask;
  195764. xImage->blue_mask = visual->blue_mask;
  195765. }
  195766. if (! XInitImage (xImage))
  195767. {
  195768. jassertfalse
  195769. }
  195770. }
  195771. }
  195772. ~XBitmapImage()
  195773. {
  195774. ScopedXLock xlock;
  195775. #if JUCE_USE_XSHM
  195776. if (usingXShm)
  195777. {
  195778. XShmDetach (display, &segmentInfo);
  195779. XFlush (display);
  195780. XDestroyImage (xImage);
  195781. shmdt (segmentInfo.shmaddr);
  195782. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195783. }
  195784. else
  195785. #endif
  195786. {
  195787. xImage->data = 0;
  195788. XDestroyImage (xImage);
  195789. }
  195790. }
  195791. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195792. {
  195793. ScopedXLock xlock;
  195794. static GC gc = 0;
  195795. if (gc == 0)
  195796. gc = DefaultGC (display, DefaultScreen (display));
  195797. if (is16Bit)
  195798. {
  195799. const uint32 rMask = xImage->red_mask;
  195800. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195801. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195802. const uint32 gMask = xImage->green_mask;
  195803. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195804. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195805. const uint32 bMask = xImage->blue_mask;
  195806. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195807. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195808. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195809. for (int y = sy; y < sy + dh; ++y)
  195810. {
  195811. const uint8* p = srcData.getPixelPointer (sx, y);
  195812. for (int x = sx; x < sx + dw; ++x)
  195813. {
  195814. const PixelRGB* const pixel = (const PixelRGB*) p;
  195815. p += srcData.pixelStride;
  195816. XPutPixel (xImage, x, y,
  195817. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195818. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195819. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195820. }
  195821. }
  195822. }
  195823. // blit results to screen.
  195824. #if JUCE_USE_XSHM
  195825. if (usingXShm)
  195826. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195827. else
  195828. #endif
  195829. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195830. }
  195831. juce_UseDebuggingNewOperator
  195832. private:
  195833. XImage* xImage;
  195834. const bool is16Bit;
  195835. HeapBlock <char> imageData16Bit;
  195836. #if JUCE_USE_XSHM
  195837. XShmSegmentInfo segmentInfo;
  195838. bool usingXShm;
  195839. #endif
  195840. static int getShiftNeeded (const uint32 mask) throw()
  195841. {
  195842. for (int i = 32; --i >= 0;)
  195843. if (((mask >> i) & 1) != 0)
  195844. return i - 7;
  195845. jassertfalse
  195846. return 0;
  195847. }
  195848. };
  195849. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195850. class LinuxComponentPeer : public ComponentPeer
  195851. {
  195852. public:
  195853. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195854. : ComponentPeer (component, windowStyleFlags),
  195855. windowH (0),
  195856. parentWindow (0),
  195857. wx (0),
  195858. wy (0),
  195859. ww (0),
  195860. wh (0),
  195861. taskbarImage (0),
  195862. fullScreen (false),
  195863. mapped (false)
  195864. {
  195865. // it's dangerous to create a window on a thread other than the message thread..
  195866. checkMessageManagerIsLocked
  195867. repainter = new LinuxRepaintManager (this);
  195868. createWindow();
  195869. setTitle (component->getName());
  195870. }
  195871. ~LinuxComponentPeer()
  195872. {
  195873. // it's dangerous to delete a window on a thread other than the message thread..
  195874. checkMessageManagerIsLocked
  195875. deleteTaskBarIcon();
  195876. deleteIconPixmaps();
  195877. destroyWindow();
  195878. windowH = 0;
  195879. }
  195880. void* getNativeHandle() const
  195881. {
  195882. return (void*) windowH;
  195883. }
  195884. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195885. {
  195886. XPointer peer = 0;
  195887. ScopedXLock xlock;
  195888. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195889. {
  195890. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195891. peer = 0;
  195892. }
  195893. return (LinuxComponentPeer*) peer;
  195894. }
  195895. void setVisible (bool shouldBeVisible)
  195896. {
  195897. ScopedXLock xlock;
  195898. if (shouldBeVisible)
  195899. XMapWindow (display, windowH);
  195900. else
  195901. XUnmapWindow (display, windowH);
  195902. }
  195903. void setTitle (const String& title)
  195904. {
  195905. setWindowTitle (windowH, title);
  195906. }
  195907. void setPosition (int x, int y)
  195908. {
  195909. setBounds (x, y, ww, wh, false);
  195910. }
  195911. void setSize (int w, int h)
  195912. {
  195913. setBounds (wx, wy, w, h, false);
  195914. }
  195915. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  195916. {
  195917. fullScreen = isNowFullScreen;
  195918. if (windowH != 0)
  195919. {
  195920. const ComponentDeletionWatcher deletionChecker (component);
  195921. wx = x;
  195922. wy = y;
  195923. ww = jmax (1, w);
  195924. wh = jmax (1, h);
  195925. ScopedXLock xlock;
  195926. // Make sure the Window manager does what we want
  195927. XSizeHints* hints = XAllocSizeHints();
  195928. hints->flags = USSize | USPosition;
  195929. hints->width = ww;
  195930. hints->height = wh;
  195931. hints->x = wx;
  195932. hints->y = wy;
  195933. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195934. {
  195935. hints->min_width = hints->max_width = hints->width;
  195936. hints->min_height = hints->max_height = hints->height;
  195937. hints->flags |= PMinSize | PMaxSize;
  195938. }
  195939. XSetWMNormalHints (display, windowH, hints);
  195940. XFree (hints);
  195941. XMoveResizeWindow (display, windowH,
  195942. wx - windowBorder.getLeft(),
  195943. wy - windowBorder.getTop(), ww, wh);
  195944. if (! deletionChecker.hasBeenDeleted())
  195945. {
  195946. updateBorderSize();
  195947. handleMovedOrResized();
  195948. }
  195949. }
  195950. }
  195951. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195952. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195953. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195954. {
  195955. return relativePosition + getScreenPosition();
  195956. }
  195957. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195958. {
  195959. return screenPosition - getScreenPosition();
  195960. }
  195961. void setMinimised (bool shouldBeMinimised)
  195962. {
  195963. if (shouldBeMinimised)
  195964. {
  195965. Window root = RootWindow (display, DefaultScreen (display));
  195966. XClientMessageEvent clientMsg;
  195967. clientMsg.display = display;
  195968. clientMsg.window = windowH;
  195969. clientMsg.type = ClientMessage;
  195970. clientMsg.format = 32;
  195971. clientMsg.message_type = wm_ChangeState;
  195972. clientMsg.data.l[0] = IconicState;
  195973. ScopedXLock xlock;
  195974. XSendEvent (display, root, false,
  195975. SubstructureRedirectMask | SubstructureNotifyMask,
  195976. (XEvent*) &clientMsg);
  195977. }
  195978. else
  195979. {
  195980. setVisible (true);
  195981. }
  195982. }
  195983. bool isMinimised() const
  195984. {
  195985. bool minimised = false;
  195986. unsigned char* stateProp;
  195987. unsigned long nitems, bytesLeft;
  195988. Atom actualType;
  195989. int actualFormat;
  195990. ScopedXLock xlock;
  195991. if (XGetWindowProperty (display, windowH, wm_State, 0, 64, False,
  195992. wm_State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195993. &stateProp) == Success
  195994. && actualType == wm_State
  195995. && actualFormat == 32
  195996. && nitems > 0)
  195997. {
  195998. if (((unsigned long*) stateProp)[0] == IconicState)
  195999. minimised = true;
  196000. XFree (stateProp);
  196001. }
  196002. return minimised;
  196003. }
  196004. void setFullScreen (const bool shouldBeFullScreen)
  196005. {
  196006. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  196007. setMinimised (false);
  196008. if (fullScreen != shouldBeFullScreen)
  196009. {
  196010. if (shouldBeFullScreen)
  196011. r = Desktop::getInstance().getMainMonitorArea();
  196012. if (! r.isEmpty())
  196013. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  196014. getComponent()->repaint();
  196015. }
  196016. }
  196017. bool isFullScreen() const
  196018. {
  196019. return fullScreen;
  196020. }
  196021. bool isChildWindowOf (Window possibleParent) const
  196022. {
  196023. Window* windowList = 0;
  196024. uint32 windowListSize = 0;
  196025. Window parent, root;
  196026. ScopedXLock xlock;
  196027. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  196028. {
  196029. if (windowList != 0)
  196030. XFree (windowList);
  196031. return parent == possibleParent;
  196032. }
  196033. return false;
  196034. }
  196035. bool isFrontWindow() const
  196036. {
  196037. Window* windowList = 0;
  196038. uint32 windowListSize = 0;
  196039. bool result = false;
  196040. ScopedXLock xlock;
  196041. Window parent, root = RootWindow (display, DefaultScreen (display));
  196042. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  196043. {
  196044. for (int i = windowListSize; --i >= 0;)
  196045. {
  196046. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  196047. if (peer != 0)
  196048. {
  196049. result = (peer == this);
  196050. break;
  196051. }
  196052. }
  196053. }
  196054. if (windowList != 0)
  196055. XFree (windowList);
  196056. return result;
  196057. }
  196058. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  196059. {
  196060. int x = position.getX();
  196061. int y = position.getY();
  196062. if (((unsigned int) x) >= (unsigned int) ww
  196063. || ((unsigned int) y) >= (unsigned int) wh)
  196064. return false;
  196065. bool inFront = false;
  196066. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  196067. {
  196068. Component* const c = Desktop::getInstance().getComponent (i);
  196069. if (inFront)
  196070. {
  196071. if (c->contains (x + wx - c->getScreenX(),
  196072. y + wy - c->getScreenY()))
  196073. {
  196074. return false;
  196075. }
  196076. }
  196077. else if (c == getComponent())
  196078. {
  196079. inFront = true;
  196080. }
  196081. }
  196082. if (trueIfInAChildWindow)
  196083. return true;
  196084. ::Window root, child;
  196085. unsigned int bw, depth;
  196086. int wx, wy, w, h;
  196087. ScopedXLock xlock;
  196088. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196089. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  196090. &bw, &depth))
  196091. {
  196092. return false;
  196093. }
  196094. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  196095. return false;
  196096. return child == None;
  196097. }
  196098. const BorderSize getFrameSize() const
  196099. {
  196100. return BorderSize();
  196101. }
  196102. bool setAlwaysOnTop (bool alwaysOnTop)
  196103. {
  196104. if (windowH != 0)
  196105. {
  196106. const bool wasVisible = component->isVisible();
  196107. if (wasVisible)
  196108. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196109. {
  196110. ScopedXLock xlock;
  196111. XSetWindowAttributes swa;
  196112. swa.override_redirect = alwaysOnTop ? True : False;
  196113. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196114. }
  196115. if (wasVisible)
  196116. setVisible (true);
  196117. }
  196118. return true;
  196119. }
  196120. void toFront (bool makeActive)
  196121. {
  196122. if (makeActive)
  196123. {
  196124. setVisible (true);
  196125. grabFocus();
  196126. }
  196127. XEvent ev;
  196128. ev.xclient.type = ClientMessage;
  196129. ev.xclient.serial = 0;
  196130. ev.xclient.send_event = True;
  196131. ev.xclient.message_type = wm_ActiveWin;
  196132. ev.xclient.window = windowH;
  196133. ev.xclient.format = 32;
  196134. ev.xclient.data.l[0] = 2;
  196135. ev.xclient.data.l[1] = CurrentTime;
  196136. ev.xclient.data.l[2] = 0;
  196137. ev.xclient.data.l[3] = 0;
  196138. ev.xclient.data.l[4] = 0;
  196139. {
  196140. ScopedXLock xlock;
  196141. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196142. False,
  196143. SubstructureRedirectMask | SubstructureNotifyMask,
  196144. &ev);
  196145. XWindowAttributes attr;
  196146. XGetWindowAttributes (display, windowH, &attr);
  196147. if (attr.override_redirect)
  196148. XRaiseWindow (display, windowH);
  196149. XSync (display, False);
  196150. }
  196151. handleBroughtToFront();
  196152. }
  196153. void toBehind (ComponentPeer* other)
  196154. {
  196155. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196156. jassert (otherPeer != 0); // wrong type of window?
  196157. if (otherPeer != 0)
  196158. {
  196159. setMinimised (false);
  196160. Window newStack[] = { otherPeer->windowH, windowH };
  196161. ScopedXLock xlock;
  196162. XRestackWindows (display, newStack, 2);
  196163. }
  196164. }
  196165. bool isFocused() const
  196166. {
  196167. int revert;
  196168. Window focusedWindow = 0;
  196169. ScopedXLock xlock;
  196170. XGetInputFocus (display, &focusedWindow, &revert);
  196171. return focusedWindow == windowH;
  196172. }
  196173. void grabFocus()
  196174. {
  196175. XWindowAttributes atts;
  196176. ScopedXLock xlock;
  196177. if (windowH != 0
  196178. && XGetWindowAttributes (display, windowH, &atts)
  196179. && atts.map_state == IsViewable
  196180. && ! isFocused())
  196181. {
  196182. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196183. isActiveApplication = true;
  196184. }
  196185. }
  196186. void textInputRequired (const Point<int>&)
  196187. {
  196188. }
  196189. void repaint (int x, int y, int w, int h)
  196190. {
  196191. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196192. 0, 0,
  196193. getComponent()->getWidth(),
  196194. getComponent()->getHeight()))
  196195. {
  196196. repainter->repaint (x, y, w, h);
  196197. }
  196198. }
  196199. void performAnyPendingRepaintsNow()
  196200. {
  196201. repainter->performAnyPendingRepaintsNow();
  196202. }
  196203. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  196204. {
  196205. ScopedXLock xlock;
  196206. const int width = image.getWidth();
  196207. const int height = image.getHeight();
  196208. HeapBlock <uint32> colour (width * height);
  196209. int index = 0;
  196210. for (int y = 0; y < height; ++y)
  196211. for (int x = 0; x < width; ++x)
  196212. colour[index++] = image.getPixelAt (x, y).getARGB();
  196213. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  196214. 0, (char*) colour, width, height, 32, 0);
  196215. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  196216. width, height, 24);
  196217. GC gc = XCreateGC (display, pixmap, 0, 0);
  196218. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  196219. XFreeGC (display, gc);
  196220. return pixmap;
  196221. }
  196222. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  196223. {
  196224. ScopedXLock xlock;
  196225. const int width = image.getWidth();
  196226. const int height = image.getHeight();
  196227. const int stride = (width + 7) >> 3;
  196228. HeapBlock <uint8> mask;
  196229. mask.calloc (stride * height);
  196230. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  196231. for (int y = 0; y < height; ++y)
  196232. {
  196233. for (int x = 0; x < width; ++x)
  196234. {
  196235. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  196236. const int offset = y * stride + (x >> 3);
  196237. if (image.getPixelAt (x, y).getAlpha() >= 128)
  196238. mask[offset] |= bit;
  196239. }
  196240. }
  196241. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  196242. (char*) mask, width, height, 1, 0, 1);
  196243. }
  196244. void setIcon (const Image& newIcon)
  196245. {
  196246. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196247. HeapBlock <unsigned long> data (dataSize);
  196248. int index = 0;
  196249. data[index++] = newIcon.getWidth();
  196250. data[index++] = newIcon.getHeight();
  196251. for (int y = 0; y < newIcon.getHeight(); ++y)
  196252. for (int x = 0; x < newIcon.getWidth(); ++x)
  196253. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196254. ScopedXLock xlock;
  196255. XChangeProperty (display, windowH,
  196256. XInternAtom (display, "_NET_WM_ICON", False),
  196257. XA_CARDINAL, 32, PropModeReplace,
  196258. (unsigned char*) data, dataSize);
  196259. deleteIconPixmaps();
  196260. XWMHints* wmHints = XGetWMHints (display, windowH);
  196261. if (wmHints == 0)
  196262. wmHints = XAllocWMHints();
  196263. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196264. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196265. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196266. XSetWMHints (display, windowH, wmHints);
  196267. XFree (wmHints);
  196268. XSync (display, False);
  196269. }
  196270. void deleteIconPixmaps()
  196271. {
  196272. ScopedXLock xlock;
  196273. XWMHints* wmHints = XGetWMHints (display, windowH);
  196274. if (wmHints != 0)
  196275. {
  196276. if ((wmHints->flags & IconPixmapHint) != 0)
  196277. {
  196278. wmHints->flags &= ~IconPixmapHint;
  196279. XFreePixmap (display, wmHints->icon_pixmap);
  196280. }
  196281. if ((wmHints->flags & IconMaskHint) != 0)
  196282. {
  196283. wmHints->flags &= ~IconMaskHint;
  196284. XFreePixmap (display, wmHints->icon_mask);
  196285. }
  196286. XSetWMHints (display, windowH, wmHints);
  196287. XFree (wmHints);
  196288. }
  196289. }
  196290. void handleWindowMessage (XEvent* event)
  196291. {
  196292. switch (event->xany.type)
  196293. {
  196294. case 2: // 'KeyPress'
  196295. {
  196296. ScopedXLock xlock;
  196297. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196298. updateKeyStates (keyEvent->keycode, true);
  196299. char utf8 [64];
  196300. zeromem (utf8, sizeof (utf8));
  196301. KeySym sym;
  196302. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196303. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1);
  196304. int keyCode = (int) unicodeChar;
  196305. if (keyCode < 0x20)
  196306. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  196307. const ModifierKeys oldMods (currentModifiers);
  196308. bool keyPressed = false;
  196309. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196310. if ((sym & 0xff00) == 0xff00)
  196311. {
  196312. // Translate keypad
  196313. if (sym == XK_KP_Divide)
  196314. keyCode = XK_slash;
  196315. else if (sym == XK_KP_Multiply)
  196316. keyCode = XK_asterisk;
  196317. else if (sym == XK_KP_Subtract)
  196318. keyCode = XK_hyphen;
  196319. else if (sym == XK_KP_Add)
  196320. keyCode = XK_plus;
  196321. else if (sym == XK_KP_Enter)
  196322. keyCode = XK_Return;
  196323. else if (sym == XK_KP_Decimal)
  196324. keyCode = numLock ? XK_period : XK_Delete;
  196325. else if (sym == XK_KP_0)
  196326. keyCode = numLock ? XK_0 : XK_Insert;
  196327. else if (sym == XK_KP_1)
  196328. keyCode = numLock ? XK_1 : XK_End;
  196329. else if (sym == XK_KP_2)
  196330. keyCode = numLock ? XK_2 : XK_Down;
  196331. else if (sym == XK_KP_3)
  196332. keyCode = numLock ? XK_3 : XK_Page_Down;
  196333. else if (sym == XK_KP_4)
  196334. keyCode = numLock ? XK_4 : XK_Left;
  196335. else if (sym == XK_KP_5)
  196336. keyCode = XK_5;
  196337. else if (sym == XK_KP_6)
  196338. keyCode = numLock ? XK_6 : XK_Right;
  196339. else if (sym == XK_KP_7)
  196340. keyCode = numLock ? XK_7 : XK_Home;
  196341. else if (sym == XK_KP_8)
  196342. keyCode = numLock ? XK_8 : XK_Up;
  196343. else if (sym == XK_KP_9)
  196344. keyCode = numLock ? XK_9 : XK_Page_Up;
  196345. switch (sym)
  196346. {
  196347. case XK_Left:
  196348. case XK_Right:
  196349. case XK_Up:
  196350. case XK_Down:
  196351. case XK_Page_Up:
  196352. case XK_Page_Down:
  196353. case XK_End:
  196354. case XK_Home:
  196355. case XK_Delete:
  196356. case XK_Insert:
  196357. keyPressed = true;
  196358. keyCode = (sym & 0xff) | extendedKeyModifier;
  196359. break;
  196360. case XK_Tab:
  196361. case XK_Return:
  196362. case XK_Escape:
  196363. case XK_BackSpace:
  196364. keyPressed = true;
  196365. keyCode &= 0xff;
  196366. break;
  196367. default:
  196368. {
  196369. if (sym >= XK_F1 && sym <= XK_F16)
  196370. {
  196371. keyPressed = true;
  196372. keyCode = (sym & 0xff) | extendedKeyModifier;
  196373. }
  196374. break;
  196375. }
  196376. }
  196377. }
  196378. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196379. keyPressed = true;
  196380. if (oldMods != currentModifiers)
  196381. handleModifierKeysChange();
  196382. if (keyDownChange)
  196383. handleKeyUpOrDown (true);
  196384. if (keyPressed)
  196385. handleKeyPress (keyCode, unicodeChar);
  196386. break;
  196387. }
  196388. case KeyRelease:
  196389. {
  196390. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196391. updateKeyStates (keyEvent->keycode, false);
  196392. ScopedXLock xlock;
  196393. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196394. const ModifierKeys oldMods (currentModifiers);
  196395. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196396. if (oldMods != currentModifiers)
  196397. handleModifierKeysChange();
  196398. if (keyDownChange)
  196399. handleKeyUpOrDown (false);
  196400. break;
  196401. }
  196402. case ButtonPress:
  196403. {
  196404. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196405. updateKeyModifiers (buttonPressEvent->state);
  196406. bool buttonMsg = false;
  196407. const int map = pointerMap [buttonPressEvent->button - Button1];
  196408. if (map == WheelUp || map == WheelDown)
  196409. {
  196410. handleMouseWheel (Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196411. getEventTime (buttonPressEvent->time), 0, map == WheelDown ? -84.0f : 84.0f);
  196412. }
  196413. if (map == LeftButton)
  196414. {
  196415. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196416. buttonMsg = true;
  196417. }
  196418. else if (map == RightButton)
  196419. {
  196420. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196421. buttonMsg = true;
  196422. }
  196423. else if (map == MiddleButton)
  196424. {
  196425. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196426. buttonMsg = true;
  196427. }
  196428. if (buttonMsg)
  196429. {
  196430. toFront (true);
  196431. handleMouseEvent (Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196432. getEventTime (buttonPressEvent->time));
  196433. }
  196434. clearLastMousePos();
  196435. break;
  196436. }
  196437. case ButtonRelease:
  196438. {
  196439. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196440. updateKeyModifiers (buttonRelEvent->state);
  196441. const int map = pointerMap [buttonRelEvent->button - Button1];
  196442. if (map == LeftButton)
  196443. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196444. else if (map == RightButton)
  196445. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196446. else if (map == MiddleButton)
  196447. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196448. handleMouseEvent (Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196449. getEventTime (buttonRelEvent->time));
  196450. clearLastMousePos();
  196451. break;
  196452. }
  196453. case MotionNotify:
  196454. {
  196455. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196456. updateKeyModifiers (movedEvent->state);
  196457. const Point<int> mousePos (Desktop::getMousePosition());
  196458. if (lastMousePos != mousePos)
  196459. {
  196460. lastMousePos = mousePos;
  196461. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196462. {
  196463. Window wRoot = 0, wParent = 0;
  196464. {
  196465. ScopedXLock xlock;
  196466. unsigned int numChildren;
  196467. Window* wChild = 0;
  196468. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196469. }
  196470. if (wParent != 0
  196471. && wParent != windowH
  196472. && wParent != wRoot)
  196473. {
  196474. parentWindow = wParent;
  196475. updateBounds();
  196476. }
  196477. else
  196478. {
  196479. parentWindow = 0;
  196480. }
  196481. }
  196482. handleMouseEvent (mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196483. }
  196484. break;
  196485. }
  196486. case EnterNotify:
  196487. {
  196488. clearLastMousePos();
  196489. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196490. if (! currentModifiers.isAnyMouseButtonDown())
  196491. {
  196492. updateKeyModifiers (enterEvent->state);
  196493. handleMouseEvent (Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196494. }
  196495. break;
  196496. }
  196497. case LeaveNotify:
  196498. {
  196499. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196500. // Suppress the normal leave if we've got a pointer grab, or if
  196501. // it's a bogus one caused by clicking a mouse button when running
  196502. // in a Window manager
  196503. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196504. || leaveEvent->mode == NotifyUngrab)
  196505. {
  196506. updateKeyModifiers (leaveEvent->state);
  196507. handleMouseEvent (Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196508. }
  196509. break;
  196510. }
  196511. case FocusIn:
  196512. {
  196513. isActiveApplication = true;
  196514. if (isFocused())
  196515. handleFocusGain();
  196516. break;
  196517. }
  196518. case FocusOut:
  196519. {
  196520. isActiveApplication = false;
  196521. if (! isFocused())
  196522. handleFocusLoss();
  196523. break;
  196524. }
  196525. case Expose:
  196526. {
  196527. // Batch together all pending expose events
  196528. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196529. XEvent nextEvent;
  196530. ScopedXLock xlock;
  196531. if (exposeEvent->window != windowH)
  196532. {
  196533. Window child;
  196534. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196535. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196536. &child);
  196537. }
  196538. repaint (exposeEvent->x, exposeEvent->y,
  196539. exposeEvent->width, exposeEvent->height);
  196540. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196541. {
  196542. XPeekEvent (display, (XEvent*) &nextEvent);
  196543. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196544. break;
  196545. XNextEvent (display, (XEvent*) &nextEvent);
  196546. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196547. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196548. nextExposeEvent->width, nextExposeEvent->height);
  196549. }
  196550. break;
  196551. }
  196552. case CirculateNotify:
  196553. case CreateNotify:
  196554. case DestroyNotify:
  196555. // Think we can ignore these
  196556. break;
  196557. case ConfigureNotify:
  196558. {
  196559. updateBounds();
  196560. updateBorderSize();
  196561. handleMovedOrResized();
  196562. // if the native title bar is dragged, need to tell any active menus, etc.
  196563. if ((styleFlags & windowHasTitleBar) != 0
  196564. && component->isCurrentlyBlockedByAnotherModalComponent())
  196565. {
  196566. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196567. if (currentModalComp != 0)
  196568. currentModalComp->inputAttemptWhenModal();
  196569. }
  196570. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196571. if (confEvent->window == windowH
  196572. && confEvent->above != 0
  196573. && isFrontWindow())
  196574. {
  196575. handleBroughtToFront();
  196576. }
  196577. break;
  196578. }
  196579. case ReparentNotify:
  196580. case GravityNotify:
  196581. {
  196582. parentWindow = 0;
  196583. Window wRoot = 0;
  196584. Window* wChild = 0;
  196585. unsigned int numChildren;
  196586. {
  196587. ScopedXLock xlock;
  196588. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196589. }
  196590. if (parentWindow == windowH || parentWindow == wRoot)
  196591. parentWindow = 0;
  196592. updateBounds();
  196593. updateBorderSize();
  196594. handleMovedOrResized();
  196595. break;
  196596. }
  196597. case MapNotify:
  196598. mapped = true;
  196599. handleBroughtToFront();
  196600. break;
  196601. case UnmapNotify:
  196602. mapped = false;
  196603. break;
  196604. case MappingNotify:
  196605. {
  196606. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196607. if (mappingEvent->request != MappingPointer)
  196608. {
  196609. // Deal with modifier/keyboard mapping
  196610. ScopedXLock xlock;
  196611. XRefreshKeyboardMapping (mappingEvent);
  196612. updateModifierMappings();
  196613. }
  196614. break;
  196615. }
  196616. case ClientMessage:
  196617. {
  196618. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196619. if (clientMsg->message_type == wm_Protocols && clientMsg->format == 32)
  196620. {
  196621. const Atom atom = (Atom) clientMsg->data.l[0];
  196622. if (atom == wm_ProtocolList [TAKE_FOCUS])
  196623. {
  196624. XWindowAttributes atts;
  196625. ScopedXLock xlock;
  196626. if (clientMsg->window != 0
  196627. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196628. {
  196629. if (atts.map_state == IsViewable)
  196630. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196631. }
  196632. }
  196633. else if (atom == wm_ProtocolList [DELETE_WINDOW])
  196634. {
  196635. handleUserClosingWindow();
  196636. }
  196637. }
  196638. else if (clientMsg->message_type == XA_XdndEnter)
  196639. {
  196640. handleDragAndDropEnter (clientMsg);
  196641. }
  196642. else if (clientMsg->message_type == XA_XdndLeave)
  196643. {
  196644. resetDragAndDrop();
  196645. }
  196646. else if (clientMsg->message_type == XA_XdndPosition)
  196647. {
  196648. handleDragAndDropPosition (clientMsg);
  196649. }
  196650. else if (clientMsg->message_type == XA_XdndDrop)
  196651. {
  196652. handleDragAndDropDrop (clientMsg);
  196653. }
  196654. else if (clientMsg->message_type == XA_XdndStatus)
  196655. {
  196656. handleDragAndDropStatus (clientMsg);
  196657. }
  196658. else if (clientMsg->message_type == XA_XdndFinished)
  196659. {
  196660. resetDragAndDrop();
  196661. }
  196662. break;
  196663. }
  196664. case SelectionNotify:
  196665. handleDragAndDropSelection (event);
  196666. break;
  196667. case SelectionClear:
  196668. case SelectionRequest:
  196669. break;
  196670. default:
  196671. #if JUCE_USE_XSHM
  196672. {
  196673. ScopedXLock xlock;
  196674. if (event->xany.type == XShmGetEventBase (display))
  196675. repainter->notifyPaintCompleted();
  196676. }
  196677. #endif
  196678. break;
  196679. }
  196680. }
  196681. void showMouseCursor (Cursor cursor) throw()
  196682. {
  196683. ScopedXLock xlock;
  196684. XDefineCursor (display, windowH, cursor);
  196685. }
  196686. void setTaskBarIcon (const Image& image)
  196687. {
  196688. ScopedXLock xlock;
  196689. deleteTaskBarIcon();
  196690. taskbarImage = image.createCopy();
  196691. Screen* const screen = XDefaultScreenOfDisplay (display);
  196692. const int screenNumber = XScreenNumberOfScreen (screen);
  196693. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196694. screenAtom << screenNumber;
  196695. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196696. XGrabServer (display);
  196697. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196698. if (managerWin != None)
  196699. XSelectInput (display, managerWin, StructureNotifyMask);
  196700. XUngrabServer (display);
  196701. XFlush (display);
  196702. if (managerWin != None)
  196703. {
  196704. XEvent ev;
  196705. zerostruct (ev);
  196706. ev.xclient.type = ClientMessage;
  196707. ev.xclient.window = managerWin;
  196708. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196709. ev.xclient.format = 32;
  196710. ev.xclient.data.l[0] = CurrentTime;
  196711. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196712. ev.xclient.data.l[2] = windowH;
  196713. ev.xclient.data.l[3] = 0;
  196714. ev.xclient.data.l[4] = 0;
  196715. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196716. XSync (display, False);
  196717. }
  196718. // For older KDE's ...
  196719. long atomData = 1;
  196720. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196721. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196722. // For more recent KDE's...
  196723. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196724. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196725. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196726. XSizeHints* hints = XAllocSizeHints();
  196727. hints->flags = PMinSize;
  196728. hints->min_width = 22;
  196729. hints->min_height = 22;
  196730. XSetWMNormalHints (display, windowH, hints);
  196731. XFree (hints);
  196732. }
  196733. void deleteTaskBarIcon()
  196734. {
  196735. deleteAndZero (taskbarImage);
  196736. }
  196737. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196738. juce_UseDebuggingNewOperator
  196739. bool dontRepaint;
  196740. static ModifierKeys currentModifiers;
  196741. private:
  196742. class LinuxRepaintManager : public Timer
  196743. {
  196744. public:
  196745. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196746. : peer (peer_),
  196747. lastTimeImageUsed (0)
  196748. {
  196749. #if JUCE_USE_XSHM
  196750. shmCompletedDrawing = true;
  196751. useARGBImagesForRendering = isShmAvailable();
  196752. if (useARGBImagesForRendering)
  196753. {
  196754. ScopedXLock xlock;
  196755. XShmSegmentInfo segmentinfo;
  196756. XImage* const testImage
  196757. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196758. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196759. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196760. XDestroyImage (testImage);
  196761. }
  196762. #endif
  196763. }
  196764. ~LinuxRepaintManager()
  196765. {
  196766. }
  196767. void timerCallback()
  196768. {
  196769. #if JUCE_USE_XSHM
  196770. if (! shmCompletedDrawing)
  196771. return;
  196772. #endif
  196773. if (! regionsNeedingRepaint.isEmpty())
  196774. {
  196775. stopTimer();
  196776. performAnyPendingRepaintsNow();
  196777. }
  196778. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196779. {
  196780. stopTimer();
  196781. image = 0;
  196782. }
  196783. }
  196784. void repaint (int x, int y, int w, int h)
  196785. {
  196786. if (! isTimerRunning())
  196787. startTimer (repaintTimerPeriod);
  196788. regionsNeedingRepaint.add (x, y, w, h);
  196789. }
  196790. void performAnyPendingRepaintsNow()
  196791. {
  196792. #if JUCE_USE_XSHM
  196793. if (! shmCompletedDrawing)
  196794. {
  196795. startTimer (repaintTimerPeriod);
  196796. return;
  196797. }
  196798. #endif
  196799. peer->clearMaskedRegion();
  196800. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196801. regionsNeedingRepaint.clear();
  196802. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196803. if (! totalArea.isEmpty())
  196804. {
  196805. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196806. || image->getHeight() < totalArea.getHeight())
  196807. {
  196808. #if JUCE_USE_XSHM
  196809. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196810. : Image::RGB,
  196811. #else
  196812. image = new XBitmapImage (Image::RGB,
  196813. #endif
  196814. (totalArea.getWidth() + 31) & ~31,
  196815. (totalArea.getHeight() + 31) & ~31,
  196816. false,
  196817. peer->depthIs16Bit);
  196818. }
  196819. startTimer (repaintTimerPeriod);
  196820. LowLevelGraphicsSoftwareRenderer context (*image);
  196821. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196822. if (context.clipToRectangleList (originalRepaintRegion))
  196823. peer->handlePaint (context);
  196824. if (! peer->maskedRegion.isEmpty())
  196825. originalRepaintRegion.subtract (peer->maskedRegion);
  196826. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196827. {
  196828. #if JUCE_USE_XSHM
  196829. shmCompletedDrawing = false;
  196830. #endif
  196831. const Rectangle<int>& r = *i.getRectangle();
  196832. image->blitToWindow (peer->windowH,
  196833. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196834. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196835. }
  196836. }
  196837. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196838. startTimer (repaintTimerPeriod);
  196839. }
  196840. #if JUCE_USE_XSHM
  196841. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196842. #endif
  196843. private:
  196844. LinuxComponentPeer* const peer;
  196845. ScopedPointer <XBitmapImage> image;
  196846. uint32 lastTimeImageUsed;
  196847. RectangleList regionsNeedingRepaint;
  196848. #if JUCE_USE_XSHM
  196849. bool useARGBImagesForRendering, shmCompletedDrawing;
  196850. #endif
  196851. LinuxRepaintManager (const LinuxRepaintManager&);
  196852. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196853. };
  196854. ScopedPointer <LinuxRepaintManager> repainter;
  196855. friend class LinuxRepaintManager;
  196856. Window windowH, parentWindow;
  196857. int wx, wy, ww, wh;
  196858. Image* taskbarImage;
  196859. bool fullScreen, mapped, depthIs16Bit;
  196860. BorderSize windowBorder;
  196861. struct MotifWmHints
  196862. {
  196863. unsigned long flags;
  196864. unsigned long functions;
  196865. unsigned long decorations;
  196866. long input_mode;
  196867. unsigned long status;
  196868. };
  196869. static void updateKeyModifiers (const int status) throw()
  196870. {
  196871. int keyMods = 0;
  196872. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196873. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196874. if (status & AltMask) keyMods |= ModifierKeys::altModifier;
  196875. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196876. numLock = ((status & NumLockMask) != 0);
  196877. capsLock = ((status & LockMask) != 0);
  196878. }
  196879. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196880. {
  196881. int modifier = 0;
  196882. bool isModifier = true;
  196883. switch (sym)
  196884. {
  196885. case XK_Shift_L:
  196886. case XK_Shift_R:
  196887. modifier = ModifierKeys::shiftModifier;
  196888. break;
  196889. case XK_Control_L:
  196890. case XK_Control_R:
  196891. modifier = ModifierKeys::ctrlModifier;
  196892. break;
  196893. case XK_Alt_L:
  196894. case XK_Alt_R:
  196895. modifier = ModifierKeys::altModifier;
  196896. break;
  196897. case XK_Num_Lock:
  196898. if (press)
  196899. numLock = ! numLock;
  196900. break;
  196901. case XK_Caps_Lock:
  196902. if (press)
  196903. capsLock = ! capsLock;
  196904. break;
  196905. case XK_Scroll_Lock:
  196906. break;
  196907. default:
  196908. isModifier = false;
  196909. break;
  196910. }
  196911. if (modifier != 0)
  196912. {
  196913. if (press)
  196914. currentModifiers = currentModifiers.withFlags (modifier);
  196915. else
  196916. currentModifiers = currentModifiers.withoutFlags (modifier);
  196917. }
  196918. return isModifier;
  196919. }
  196920. // Alt and Num lock are not defined by standard X
  196921. // modifier constants: check what they're mapped to
  196922. static void updateModifierMappings() throw()
  196923. {
  196924. ScopedXLock xlock;
  196925. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196926. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196927. AltMask = 0;
  196928. NumLockMask = 0;
  196929. XModifierKeymap* mapping = XGetModifierMapping (display);
  196930. if (mapping)
  196931. {
  196932. for (int i = 0; i < 8; i++)
  196933. {
  196934. if (mapping->modifiermap [i << 1] == altLeftCode)
  196935. AltMask = 1 << i;
  196936. else if (mapping->modifiermap [i << 1] == numLockCode)
  196937. NumLockMask = 1 << i;
  196938. }
  196939. XFreeModifiermap (mapping);
  196940. }
  196941. }
  196942. void removeWindowDecorations (Window wndH)
  196943. {
  196944. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196945. if (hints != None)
  196946. {
  196947. MotifWmHints motifHints;
  196948. zerostruct (motifHints);
  196949. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196950. motifHints.decorations = 0;
  196951. ScopedXLock xlock;
  196952. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196953. (unsigned char*) &motifHints, 4);
  196954. }
  196955. hints = XInternAtom (display, "_WIN_HINTS", True);
  196956. if (hints != None)
  196957. {
  196958. long gnomeHints = 0;
  196959. ScopedXLock xlock;
  196960. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196961. (unsigned char*) &gnomeHints, 1);
  196962. }
  196963. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196964. if (hints != None)
  196965. {
  196966. long kwmHints = 2; /*KDE_tinyDecoration*/
  196967. ScopedXLock xlock;
  196968. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196969. (unsigned char*) &kwmHints, 1);
  196970. }
  196971. hints = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  196972. if (hints != None)
  196973. {
  196974. ScopedXLock xlock;
  196975. int netHints [2];
  196976. int numHints = 0;
  196977. if ((styleFlags & windowIsTemporary) != 0)
  196978. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_MENU", True);
  196979. else
  196980. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196981. if (netHints [numHints] != 0)
  196982. ++numHints;
  196983. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196984. if (netHints [numHints] != 0)
  196985. ++numHints;
  196986. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196987. (unsigned char*) &netHints, numHints);
  196988. }
  196989. }
  196990. void addWindowButtons (Window wndH)
  196991. {
  196992. ScopedXLock xlock;
  196993. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196994. if (hints != None)
  196995. {
  196996. MotifWmHints motifHints;
  196997. zerostruct (motifHints);
  196998. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196999. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  197000. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  197001. if ((styleFlags & windowHasCloseButton) != 0)
  197002. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  197003. if ((styleFlags & windowHasMinimiseButton) != 0)
  197004. {
  197005. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  197006. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  197007. }
  197008. if ((styleFlags & windowHasMaximiseButton) != 0)
  197009. {
  197010. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  197011. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  197012. }
  197013. if ((styleFlags & windowIsResizable) != 0)
  197014. {
  197015. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  197016. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  197017. }
  197018. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  197019. }
  197020. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  197021. if (hints != None)
  197022. {
  197023. int netHints [6];
  197024. int num = 0;
  197025. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  197026. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  197027. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  197028. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  197029. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197030. (unsigned char*) &netHints, num);
  197031. }
  197032. }
  197033. void createWindow()
  197034. {
  197035. ScopedXLock xlock;
  197036. static bool atomsInitialised = false;
  197037. if (! atomsInitialised)
  197038. {
  197039. atomsInitialised = true;
  197040. wm_Protocols = XInternAtom (display, "WM_PROTOCOLS", 1);
  197041. wm_ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", 1);
  197042. wm_ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", 1);
  197043. wm_ChangeState = XInternAtom (display, "WM_CHANGE_STATE", 1);
  197044. wm_State = XInternAtom (display, "WM_STATE", 1);
  197045. wm_ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  197046. XA_XdndAware = XInternAtom (display, "XdndAware", 0);
  197047. XA_XdndEnter = XInternAtom (display, "XdndEnter", 0);
  197048. XA_XdndLeave = XInternAtom (display, "XdndLeave", 0);
  197049. XA_XdndPosition = XInternAtom (display, "XdndPosition", 0);
  197050. XA_XdndStatus = XInternAtom (display, "XdndStatus", 0);
  197051. XA_XdndDrop = XInternAtom (display, "XdndDrop", 0);
  197052. XA_XdndFinished = XInternAtom (display, "XdndFinished", 0);
  197053. XA_XdndSelection = XInternAtom (display, "XdndSelection", 0);
  197054. XA_XdndProxy = XInternAtom (display, "XdndProxy", 0);
  197055. XA_XdndTypeList = XInternAtom (display, "XdndTypeList", 0);
  197056. XA_XdndActionList = XInternAtom (display, "XdndActionList", 0);
  197057. XA_XdndActionCopy = XInternAtom (display, "XdndActionCopy", 0);
  197058. XA_XdndActionMove = XInternAtom (display, "XdndActionMove", 0);
  197059. XA_XdndActionLink = XInternAtom (display, "XdndActionLink", 0);
  197060. XA_XdndActionAsk = XInternAtom (display, "XdndActionAsk", 0);
  197061. XA_XdndActionPrivate = XInternAtom (display, "XdndActionPrivate", 0);
  197062. XA_XdndActionDescription = XInternAtom (display, "XdndActionDescription", 0);
  197063. XA_JXSelectionWindowProperty = XInternAtom (display, "JXSelectionWindowProperty", 0);
  197064. XA_MimeTextPlain = XInternAtom (display, "text/plain", 0);
  197065. XA_MimeTextUriList = XInternAtom (display, "text/uri-list", 0);
  197066. XA_MimeRootDrop = XInternAtom (display, "application/x-rootwindow-drop", 0);
  197067. }
  197068. resetDragAndDrop();
  197069. XA_OtherMime = XA_MimeTextPlain; // xxx why??
  197070. allowedMimeTypeAtoms [0] = XA_MimeTextPlain;
  197071. allowedMimeTypeAtoms [1] = XA_OtherMime;
  197072. allowedMimeTypeAtoms [2] = XA_MimeTextUriList;
  197073. allowedActions [0] = XA_XdndActionMove;
  197074. allowedActions [1] = XA_XdndActionCopy;
  197075. allowedActions [2] = XA_XdndActionLink;
  197076. allowedActions [3] = XA_XdndActionAsk;
  197077. allowedActions [4] = XA_XdndActionPrivate;
  197078. // Get defaults for various properties
  197079. const int screen = DefaultScreen (display);
  197080. Window root = RootWindow (display, screen);
  197081. // Attempt to create a 24-bit window on the default screen. If this is not
  197082. // possible then exit
  197083. XVisualInfo desiredVisual;
  197084. desiredVisual.screen = screen;
  197085. desiredVisual.depth = 24;
  197086. depthIs16Bit = false;
  197087. int numVisuals;
  197088. XVisualInfo* visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197089. &desiredVisual, &numVisuals);
  197090. if (numVisuals < 1 || visuals == 0)
  197091. {
  197092. XFree (visuals);
  197093. desiredVisual.depth = 16;
  197094. visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197095. &desiredVisual, &numVisuals);
  197096. if (numVisuals < 1 || visuals == 0)
  197097. {
  197098. Logger::outputDebugString ("ERROR: System doesn't support 24 or 16 bit RGB display.\n");
  197099. Process::terminate();
  197100. }
  197101. depthIs16Bit = true;
  197102. }
  197103. XFree (visuals);
  197104. // Set up the window attributes
  197105. XSetWindowAttributes swa;
  197106. swa.border_pixel = 0;
  197107. swa.background_pixmap = None;
  197108. swa.colormap = DefaultColormap (display, screen);
  197109. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  197110. swa.event_mask = eventMask;
  197111. Window wndH = XCreateWindow (display, root,
  197112. 0, 0, 1, 1,
  197113. 0, 0, InputOutput, (Visual*) CopyFromParent,
  197114. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  197115. &swa);
  197116. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  197117. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  197118. GrabModeAsync, GrabModeAsync, None, None);
  197119. // Set the window context to identify the window handle object
  197120. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  197121. {
  197122. // Failed
  197123. jassertfalse
  197124. Logger::outputDebugString ("Failed to create context information for window.\n");
  197125. XDestroyWindow (display, wndH);
  197126. wndH = 0;
  197127. }
  197128. // Set window manager hints
  197129. XWMHints* wmHints = XAllocWMHints();
  197130. wmHints->flags = InputHint | StateHint;
  197131. wmHints->input = True; // Locally active input model
  197132. wmHints->initial_state = NormalState;
  197133. XSetWMHints (display, wndH, wmHints);
  197134. XFree (wmHints);
  197135. if ((styleFlags & windowIsSemiTransparent) != 0)
  197136. {
  197137. //xxx
  197138. }
  197139. if ((styleFlags & windowAppearsOnTaskbar) != 0)
  197140. {
  197141. //xxx
  197142. }
  197143. //XSetTransientForHint (display, wndH, RootWindow (display, DefaultScreen (display)));
  197144. if ((styleFlags & windowHasTitleBar) == 0)
  197145. removeWindowDecorations (wndH);
  197146. else
  197147. addWindowButtons (wndH);
  197148. // Set window manager protocols
  197149. XChangeProperty (display, wndH, wm_Protocols, XA_ATOM, 32, PropModeReplace,
  197150. (unsigned char*) wm_ProtocolList, 2);
  197151. // Set drag and drop flags
  197152. XChangeProperty (display, wndH, XA_XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197153. (const unsigned char*) allowedMimeTypeAtoms, numElementsInArray (allowedMimeTypeAtoms));
  197154. XChangeProperty (display, wndH, XA_XdndActionList, XA_ATOM, 32, PropModeReplace,
  197155. (const unsigned char*) allowedActions, numElementsInArray (allowedActions));
  197156. XChangeProperty (display, wndH, XA_XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197157. (const unsigned char*) "", 0);
  197158. unsigned long dndVersion = ourDndVersion;
  197159. XChangeProperty (display, wndH, XA_XdndAware, XA_ATOM, 32, PropModeReplace,
  197160. (const unsigned char*) &dndVersion, 1);
  197161. // Set window name
  197162. setWindowTitle (wndH, getComponent()->getName());
  197163. // Initialise the pointer and keyboard mapping
  197164. // This is not the same as the logical pointer mapping the X server uses:
  197165. // we don't mess with this.
  197166. static bool mappingInitialised = false;
  197167. if (! mappingInitialised)
  197168. {
  197169. mappingInitialised = true;
  197170. const int numButtons = XGetPointerMapping (display, 0, 0);
  197171. if (numButtons == 2)
  197172. {
  197173. pointerMap[0] = LeftButton;
  197174. pointerMap[1] = RightButton;
  197175. pointerMap[2] = pointerMap[3] = pointerMap[4] = NoButton;
  197176. }
  197177. else if (numButtons >= 3)
  197178. {
  197179. pointerMap[0] = LeftButton;
  197180. pointerMap[1] = MiddleButton;
  197181. pointerMap[2] = RightButton;
  197182. if (numButtons >= 5)
  197183. {
  197184. pointerMap[3] = WheelUp;
  197185. pointerMap[4] = WheelDown;
  197186. }
  197187. }
  197188. updateModifierMappings();
  197189. }
  197190. windowH = wndH;
  197191. }
  197192. void destroyWindow()
  197193. {
  197194. ScopedXLock xlock;
  197195. XPointer handlePointer;
  197196. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197197. XDeleteContext (display, (XID) windowH, improbableNumber);
  197198. XDestroyWindow (display, windowH);
  197199. // Wait for it to complete and then remove any events for this
  197200. // window from the event queue.
  197201. XSync (display, false);
  197202. XEvent event;
  197203. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197204. {}
  197205. }
  197206. static int64 getEventTime (::Time t)
  197207. {
  197208. static int64 eventTimeOffset = 0x12345678;
  197209. const int64 thisMessageTime = t;
  197210. if (eventTimeOffset == 0x12345678)
  197211. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197212. return eventTimeOffset + thisMessageTime;
  197213. }
  197214. static void setWindowTitle (Window xwin, const String& title)
  197215. {
  197216. XTextProperty nameProperty;
  197217. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  197218. ScopedXLock xlock;
  197219. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197220. {
  197221. XSetWMName (display, xwin, &nameProperty);
  197222. XSetWMIconName (display, xwin, &nameProperty);
  197223. XFree (nameProperty.value);
  197224. }
  197225. }
  197226. void updateBorderSize()
  197227. {
  197228. if ((styleFlags & windowHasTitleBar) == 0)
  197229. {
  197230. windowBorder = BorderSize (0);
  197231. }
  197232. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197233. {
  197234. ScopedXLock xlock;
  197235. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197236. if (hints != None)
  197237. {
  197238. unsigned char* data = 0;
  197239. unsigned long nitems, bytesLeft;
  197240. Atom actualType;
  197241. int actualFormat;
  197242. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197243. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197244. &data) == Success)
  197245. {
  197246. const unsigned long* const sizes = (const unsigned long*) data;
  197247. if (actualFormat == 32)
  197248. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197249. (int) sizes[3], (int) sizes[1]);
  197250. XFree (data);
  197251. }
  197252. }
  197253. }
  197254. }
  197255. void updateBounds()
  197256. {
  197257. jassert (windowH != 0);
  197258. if (windowH != 0)
  197259. {
  197260. Window root, child;
  197261. unsigned int bw, depth;
  197262. ScopedXLock xlock;
  197263. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197264. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197265. &bw, &depth))
  197266. {
  197267. wx = wy = ww = wh = 0;
  197268. }
  197269. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197270. {
  197271. wx = wy = 0;
  197272. }
  197273. }
  197274. }
  197275. void resetDragAndDrop()
  197276. {
  197277. dragAndDropFiles.clear();
  197278. lastDropPos = Point<int> (-1, -1);
  197279. dragAndDropCurrentMimeType = 0;
  197280. dragAndDropSourceWindow = 0;
  197281. srcMimeTypeAtomList.clear();
  197282. }
  197283. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197284. {
  197285. msg.type = ClientMessage;
  197286. msg.display = display;
  197287. msg.window = dragAndDropSourceWindow;
  197288. msg.format = 32;
  197289. msg.data.l[0] = windowH;
  197290. ScopedXLock xlock;
  197291. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197292. }
  197293. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197294. {
  197295. XClientMessageEvent msg;
  197296. zerostruct (msg);
  197297. msg.message_type = XA_XdndStatus;
  197298. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197299. msg.data.l[4] = dropAction;
  197300. sendDragAndDropMessage (msg);
  197301. }
  197302. void sendDragAndDropLeave()
  197303. {
  197304. XClientMessageEvent msg;
  197305. zerostruct (msg);
  197306. msg.message_type = XA_XdndLeave;
  197307. sendDragAndDropMessage (msg);
  197308. }
  197309. void sendDragAndDropFinish()
  197310. {
  197311. XClientMessageEvent msg;
  197312. zerostruct (msg);
  197313. msg.message_type = XA_XdndFinished;
  197314. sendDragAndDropMessage (msg);
  197315. }
  197316. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197317. {
  197318. if ((clientMsg->data.l[1] & 1) == 0)
  197319. {
  197320. sendDragAndDropLeave();
  197321. if (dragAndDropFiles.size() > 0)
  197322. handleFileDragExit (dragAndDropFiles);
  197323. dragAndDropFiles.clear();
  197324. }
  197325. }
  197326. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197327. {
  197328. if (dragAndDropSourceWindow == 0)
  197329. return;
  197330. dragAndDropSourceWindow = clientMsg->data.l[0];
  197331. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  197332. (int) clientMsg->data.l[2] & 0xffff);
  197333. dropPos -= getScreenPosition();
  197334. if (lastDropPos != dropPos)
  197335. {
  197336. lastDropPos = dropPos;
  197337. dragAndDropTimestamp = clientMsg->data.l[3];
  197338. Atom targetAction = XA_XdndActionCopy;
  197339. for (int i = numElementsInArray (allowedActions); --i >= 0;)
  197340. {
  197341. if ((Atom) clientMsg->data.l[4] == allowedActions[i])
  197342. {
  197343. targetAction = allowedActions[i];
  197344. break;
  197345. }
  197346. }
  197347. sendDragAndDropStatus (true, targetAction);
  197348. if (dragAndDropFiles.size() == 0)
  197349. updateDraggedFileList (clientMsg);
  197350. if (dragAndDropFiles.size() > 0)
  197351. handleFileDragMove (dragAndDropFiles, dropPos);
  197352. }
  197353. }
  197354. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197355. {
  197356. if (dragAndDropFiles.size() == 0)
  197357. updateDraggedFileList (clientMsg);
  197358. const StringArray files (dragAndDropFiles);
  197359. const Point<int> lastPos (lastDropPos);
  197360. sendDragAndDropFinish();
  197361. resetDragAndDrop();
  197362. if (files.size() > 0)
  197363. handleFileDragDrop (files, lastPos);
  197364. }
  197365. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197366. {
  197367. dragAndDropFiles.clear();
  197368. srcMimeTypeAtomList.clear();
  197369. dragAndDropCurrentMimeType = 0;
  197370. const int dndCurrentVersion = (int) (clientMsg->data.l[1] & 0xff000000) >> 24;
  197371. if (dndCurrentVersion < 3 || dndCurrentVersion > ourDndVersion)
  197372. {
  197373. dragAndDropSourceWindow = 0;
  197374. return;
  197375. }
  197376. dragAndDropSourceWindow = clientMsg->data.l[0];
  197377. if ((clientMsg->data.l[1] & 1) != 0)
  197378. {
  197379. Atom actual;
  197380. int format;
  197381. unsigned long count = 0, remaining = 0;
  197382. unsigned char* data = 0;
  197383. ScopedXLock xlock;
  197384. XGetWindowProperty (display, dragAndDropSourceWindow, XA_XdndTypeList,
  197385. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197386. &count, &remaining, &data);
  197387. if (data != 0)
  197388. {
  197389. if (actual == XA_ATOM && format == 32 && count != 0)
  197390. {
  197391. const unsigned long* const types = (const unsigned long*) data;
  197392. for (unsigned int i = 0; i < count; ++i)
  197393. if (types[i] != None)
  197394. srcMimeTypeAtomList.add (types[i]);
  197395. }
  197396. XFree (data);
  197397. }
  197398. }
  197399. if (srcMimeTypeAtomList.size() == 0)
  197400. {
  197401. for (int i = 2; i < 5; ++i)
  197402. if (clientMsg->data.l[i] != None)
  197403. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197404. if (srcMimeTypeAtomList.size() == 0)
  197405. {
  197406. dragAndDropSourceWindow = 0;
  197407. return;
  197408. }
  197409. }
  197410. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197411. for (int j = 0; j < numElementsInArray (allowedMimeTypeAtoms); ++j)
  197412. if (srcMimeTypeAtomList[i] == allowedMimeTypeAtoms[j])
  197413. dragAndDropCurrentMimeType = allowedMimeTypeAtoms[j];
  197414. handleDragAndDropPosition (clientMsg);
  197415. }
  197416. void handleDragAndDropSelection (const XEvent* const evt)
  197417. {
  197418. dragAndDropFiles.clear();
  197419. if (evt->xselection.property != 0)
  197420. {
  197421. StringArray lines;
  197422. {
  197423. MemoryBlock dropData;
  197424. for (;;)
  197425. {
  197426. Atom actual;
  197427. uint8* data = 0;
  197428. unsigned long count = 0, remaining = 0;
  197429. int format = 0;
  197430. ScopedXLock xlock;
  197431. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197432. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197433. &format, &count, &remaining, &data) == Success)
  197434. {
  197435. dropData.append (data, count * format / 8);
  197436. XFree (data);
  197437. if (remaining == 0)
  197438. break;
  197439. }
  197440. else
  197441. {
  197442. XFree (data);
  197443. break;
  197444. }
  197445. }
  197446. lines.addLines (dropData.toString());
  197447. }
  197448. for (int i = 0; i < lines.size(); ++i)
  197449. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197450. dragAndDropFiles.trim();
  197451. dragAndDropFiles.removeEmptyStrings();
  197452. }
  197453. }
  197454. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197455. {
  197456. dragAndDropFiles.clear();
  197457. if (dragAndDropSourceWindow != None
  197458. && dragAndDropCurrentMimeType != 0)
  197459. {
  197460. dragAndDropTimestamp = clientMsg->data.l[2];
  197461. ScopedXLock xlock;
  197462. XConvertSelection (display,
  197463. XA_XdndSelection,
  197464. dragAndDropCurrentMimeType,
  197465. XA_JXSelectionWindowProperty,
  197466. windowH,
  197467. dragAndDropTimestamp);
  197468. }
  197469. }
  197470. StringArray dragAndDropFiles;
  197471. int dragAndDropTimestamp;
  197472. Point<int> lastDropPos;
  197473. Atom XA_OtherMime, dragAndDropCurrentMimeType;
  197474. Window dragAndDropSourceWindow;
  197475. unsigned int allowedActions[5];
  197476. unsigned int allowedMimeTypeAtoms[3];
  197477. Array <Atom> srcMimeTypeAtomList;
  197478. static int pointerMap[5];
  197479. static Point<int> lastMousePos;
  197480. static void clearLastMousePos() throw()
  197481. {
  197482. lastMousePos = Point<int> (0x100000, 0x100000);
  197483. }
  197484. };
  197485. ModifierKeys LinuxComponentPeer::currentModifiers;
  197486. int LinuxComponentPeer::pointerMap[5];
  197487. Point<int> LinuxComponentPeer::lastMousePos;
  197488. void ModifierKeys::updateCurrentModifiers() throw()
  197489. {
  197490. currentModifiers = LinuxComponentPeer::currentModifiers;
  197491. }
  197492. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197493. {
  197494. Window root, child;
  197495. int x, y, winx, winy;
  197496. unsigned int mask;
  197497. int mouseMods = 0;
  197498. ScopedXLock xlock;
  197499. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197500. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197501. {
  197502. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197503. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197504. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197505. }
  197506. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197507. return LinuxComponentPeer::currentModifiers;
  197508. }
  197509. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197510. {
  197511. if (enableOrDisable)
  197512. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197513. }
  197514. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197515. {
  197516. return new LinuxComponentPeer (this, styleFlags);
  197517. }
  197518. // (this callback is hooked up in the messaging code)
  197519. void juce_windowMessageReceive (XEvent* event)
  197520. {
  197521. if (event->xany.window != None)
  197522. {
  197523. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197524. if (ComponentPeer::isValidPeer (peer))
  197525. peer->handleWindowMessage (event);
  197526. }
  197527. else
  197528. {
  197529. switch (event->xany.type)
  197530. {
  197531. case KeymapNotify:
  197532. {
  197533. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197534. memcpy (keyStates, keymapEvent->key_vector, 32);
  197535. break;
  197536. }
  197537. default:
  197538. break;
  197539. }
  197540. }
  197541. }
  197542. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197543. {
  197544. if (display == 0)
  197545. return;
  197546. #if JUCE_USE_XINERAMA
  197547. int major_opcode, first_event, first_error;
  197548. ScopedXLock xlock;
  197549. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197550. {
  197551. typedef Bool (*tXineramaIsActive) (Display*);
  197552. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197553. static tXineramaIsActive xXineramaIsActive = 0;
  197554. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197555. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197556. {
  197557. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197558. if (h != 0)
  197559. {
  197560. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197561. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197562. }
  197563. }
  197564. if (xXineramaIsActive != 0
  197565. && xXineramaQueryScreens != 0
  197566. && xXineramaIsActive (display))
  197567. {
  197568. int numMonitors = 0;
  197569. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197570. if (screens != 0)
  197571. {
  197572. for (int i = numMonitors; --i >= 0;)
  197573. {
  197574. int index = screens[i].screen_number;
  197575. if (index >= 0)
  197576. {
  197577. while (monitorCoords.size() < index)
  197578. monitorCoords.add (Rectangle<int>());
  197579. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197580. screens[i].y_org,
  197581. screens[i].width,
  197582. screens[i].height));
  197583. }
  197584. }
  197585. XFree (screens);
  197586. }
  197587. }
  197588. }
  197589. if (monitorCoords.size() == 0)
  197590. #endif
  197591. {
  197592. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197593. if (hints != None)
  197594. {
  197595. const int numMonitors = ScreenCount (display);
  197596. for (int i = 0; i < numMonitors; ++i)
  197597. {
  197598. Window root = RootWindow (display, i);
  197599. unsigned long nitems, bytesLeft;
  197600. Atom actualType;
  197601. int actualFormat;
  197602. unsigned char* data = 0;
  197603. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197604. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197605. &data) == Success)
  197606. {
  197607. const long* const position = (const long*) data;
  197608. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197609. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197610. position[2], position[3]));
  197611. XFree (data);
  197612. }
  197613. }
  197614. }
  197615. if (monitorCoords.size() == 0)
  197616. {
  197617. monitorCoords.add (Rectangle<int> (0, 0,
  197618. DisplayWidth (display, DefaultScreen (display)),
  197619. DisplayHeight (display, DefaultScreen (display))));
  197620. }
  197621. }
  197622. }
  197623. bool Desktop::canUseSemiTransparentWindows() throw()
  197624. {
  197625. return false;
  197626. }
  197627. const Point<int> Desktop::getMousePosition()
  197628. {
  197629. Window root, child;
  197630. int x, y, winx, winy;
  197631. unsigned int mask;
  197632. ScopedXLock xlock;
  197633. if (XQueryPointer (display,
  197634. RootWindow (display, DefaultScreen (display)),
  197635. &root, &child,
  197636. &x, &y, &winx, &winy, &mask) == False)
  197637. {
  197638. // Pointer not on the default screen
  197639. x = y = -1;
  197640. }
  197641. return Point<int> (x, y);
  197642. }
  197643. void Desktop::setMousePosition (const Point<int>& newPosition)
  197644. {
  197645. ScopedXLock xlock;
  197646. Window root = RootWindow (display, DefaultScreen (display));
  197647. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197648. }
  197649. static bool screenSaverAllowed = true;
  197650. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197651. {
  197652. if (screenSaverAllowed != isEnabled)
  197653. {
  197654. screenSaverAllowed = isEnabled;
  197655. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197656. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197657. if (xScreenSaverSuspend == 0)
  197658. {
  197659. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197660. if (h != 0)
  197661. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197662. }
  197663. ScopedXLock xlock;
  197664. if (xScreenSaverSuspend != 0)
  197665. xScreenSaverSuspend (display, ! isEnabled);
  197666. }
  197667. }
  197668. bool Desktop::isScreenSaverEnabled() throw()
  197669. {
  197670. return screenSaverAllowed;
  197671. }
  197672. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197673. {
  197674. ScopedXLock xlock;
  197675. Window root = RootWindow (display, DefaultScreen (display));
  197676. const unsigned int imageW = image.getWidth();
  197677. const unsigned int imageH = image.getHeight();
  197678. unsigned int cursorW, cursorH;
  197679. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197680. return 0;
  197681. Image im (Image::ARGB, cursorW, cursorH, true);
  197682. Graphics g (im);
  197683. if (imageW > cursorW || imageH > cursorH)
  197684. {
  197685. hotspotX = (hotspotX * cursorW) / imageW;
  197686. hotspotY = (hotspotY * cursorH) / imageH;
  197687. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197688. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197689. false);
  197690. }
  197691. else
  197692. {
  197693. g.drawImageAt (&image, 0, 0);
  197694. }
  197695. const int stride = (cursorW + 7) >> 3;
  197696. HeapBlock <uint8> maskPlane, sourcePlane;
  197697. maskPlane.calloc (stride * cursorH);
  197698. sourcePlane.calloc (stride * cursorH);
  197699. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197700. for (int y = cursorH; --y >= 0;)
  197701. {
  197702. for (int x = cursorW; --x >= 0;)
  197703. {
  197704. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197705. const int offset = y * stride + (x >> 3);
  197706. const Colour c (im.getPixelAt (x, y));
  197707. if (c.getAlpha() >= 128)
  197708. maskPlane[offset] |= mask;
  197709. if (c.getBrightness() >= 0.5f)
  197710. sourcePlane[offset] |= mask;
  197711. }
  197712. }
  197713. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, (char*) sourcePlane, cursorW, cursorH, 0xffff, 0, 1);
  197714. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, (char*) maskPlane, cursorW, cursorH, 0xffff, 0, 1);
  197715. XColor white, black;
  197716. black.red = black.green = black.blue = 0;
  197717. white.red = white.green = white.blue = 0xffff;
  197718. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197719. XFreePixmap (display, sourcePixmap);
  197720. XFreePixmap (display, maskPixmap);
  197721. return result;
  197722. }
  197723. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197724. {
  197725. ScopedXLock xlock;
  197726. if (cursorHandle != None)
  197727. XFreeCursor (display, (Cursor) cursorHandle);
  197728. }
  197729. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197730. {
  197731. unsigned int shape;
  197732. switch (type)
  197733. {
  197734. case MouseCursor::NoCursor:
  197735. {
  197736. const Image im (Image::ARGB, 16, 16, true);
  197737. return juce_createMouseCursorFromImage (im, 0, 0);
  197738. }
  197739. case MouseCursor::NormalCursor:
  197740. return (void*) None; // Use parent cursor
  197741. case MouseCursor::DraggingHandCursor:
  197742. {
  197743. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197744. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197745. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197746. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197747. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197748. const int dragHandDataSize = 99;
  197749. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197750. return juce_createMouseCursorFromImage (*im, 8, 7);
  197751. }
  197752. case MouseCursor::CopyingCursor:
  197753. {
  197754. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197755. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197756. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197757. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197758. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197759. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197760. const int copyCursorSize = 119;
  197761. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197762. return juce_createMouseCursorFromImage (*im, 1, 3);
  197763. }
  197764. case MouseCursor::WaitCursor:
  197765. shape = XC_watch;
  197766. break;
  197767. case MouseCursor::IBeamCursor:
  197768. shape = XC_xterm;
  197769. break;
  197770. case MouseCursor::PointingHandCursor:
  197771. shape = XC_hand2;
  197772. break;
  197773. case MouseCursor::LeftRightResizeCursor:
  197774. shape = XC_sb_h_double_arrow;
  197775. break;
  197776. case MouseCursor::UpDownResizeCursor:
  197777. shape = XC_sb_v_double_arrow;
  197778. break;
  197779. case MouseCursor::UpDownLeftRightResizeCursor:
  197780. shape = XC_fleur;
  197781. break;
  197782. case MouseCursor::TopEdgeResizeCursor:
  197783. shape = XC_top_side;
  197784. break;
  197785. case MouseCursor::BottomEdgeResizeCursor:
  197786. shape = XC_bottom_side;
  197787. break;
  197788. case MouseCursor::LeftEdgeResizeCursor:
  197789. shape = XC_left_side;
  197790. break;
  197791. case MouseCursor::RightEdgeResizeCursor:
  197792. shape = XC_right_side;
  197793. break;
  197794. case MouseCursor::TopLeftCornerResizeCursor:
  197795. shape = XC_top_left_corner;
  197796. break;
  197797. case MouseCursor::TopRightCornerResizeCursor:
  197798. shape = XC_top_right_corner;
  197799. break;
  197800. case MouseCursor::BottomLeftCornerResizeCursor:
  197801. shape = XC_bottom_left_corner;
  197802. break;
  197803. case MouseCursor::BottomRightCornerResizeCursor:
  197804. shape = XC_bottom_right_corner;
  197805. break;
  197806. case MouseCursor::CrosshairCursor:
  197807. shape = XC_crosshair;
  197808. break;
  197809. default:
  197810. return (void*) None; // Use parent cursor
  197811. }
  197812. ScopedXLock xlock;
  197813. return (void*) XCreateFontCursor (display, shape);
  197814. }
  197815. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197816. {
  197817. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197818. if (lp != 0)
  197819. lp->showMouseCursor ((Cursor) getHandle());
  197820. }
  197821. void MouseCursor::showInAllWindows() const throw()
  197822. {
  197823. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197824. showInWindow (ComponentPeer::getPeer (i));
  197825. }
  197826. Image* juce_createIconForFile (const File& file)
  197827. {
  197828. return 0;
  197829. }
  197830. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197831. {
  197832. return new Image (format, imageWidth, imageHeight, clearImage);
  197833. }
  197834. #if JUCE_OPENGL
  197835. class WindowedGLContext : public OpenGLContext
  197836. {
  197837. public:
  197838. WindowedGLContext (Component* const component,
  197839. const OpenGLPixelFormat& pixelFormat_,
  197840. GLXContext sharedContext)
  197841. : renderContext (0),
  197842. embeddedWindow (0),
  197843. pixelFormat (pixelFormat_)
  197844. {
  197845. jassert (component != 0);
  197846. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197847. if (peer == 0)
  197848. return;
  197849. ScopedXLock xlock;
  197850. XSync (display, False);
  197851. GLint attribs [64];
  197852. int n = 0;
  197853. attribs[n++] = GLX_RGBA;
  197854. attribs[n++] = GLX_DOUBLEBUFFER;
  197855. attribs[n++] = GLX_RED_SIZE;
  197856. attribs[n++] = pixelFormat.redBits;
  197857. attribs[n++] = GLX_GREEN_SIZE;
  197858. attribs[n++] = pixelFormat.greenBits;
  197859. attribs[n++] = GLX_BLUE_SIZE;
  197860. attribs[n++] = pixelFormat.blueBits;
  197861. attribs[n++] = GLX_ALPHA_SIZE;
  197862. attribs[n++] = pixelFormat.alphaBits;
  197863. attribs[n++] = GLX_DEPTH_SIZE;
  197864. attribs[n++] = pixelFormat.depthBufferBits;
  197865. attribs[n++] = GLX_STENCIL_SIZE;
  197866. attribs[n++] = pixelFormat.stencilBufferBits;
  197867. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197868. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197869. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197870. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197871. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197872. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197873. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197874. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197875. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197876. attribs[n++] = None;
  197877. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197878. if (bestVisual == 0)
  197879. return;
  197880. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197881. Window windowH = (Window) peer->getNativeHandle();
  197882. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197883. XSetWindowAttributes swa;
  197884. swa.colormap = colourMap;
  197885. swa.border_pixel = 0;
  197886. swa.event_mask = ExposureMask | StructureNotifyMask;
  197887. embeddedWindow = XCreateWindow (display, windowH,
  197888. 0, 0, 1, 1, 0,
  197889. bestVisual->depth,
  197890. InputOutput,
  197891. bestVisual->visual,
  197892. CWBorderPixel | CWColormap | CWEventMask,
  197893. &swa);
  197894. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197895. XMapWindow (display, embeddedWindow);
  197896. XFreeColormap (display, colourMap);
  197897. XFree (bestVisual);
  197898. XSync (display, False);
  197899. }
  197900. ~WindowedGLContext()
  197901. {
  197902. makeInactive();
  197903. ScopedXLock xlock;
  197904. glXDestroyContext (display, renderContext);
  197905. XUnmapWindow (display, embeddedWindow);
  197906. XDestroyWindow (display, embeddedWindow);
  197907. }
  197908. bool makeActive() const throw()
  197909. {
  197910. jassert (renderContext != 0);
  197911. ScopedXLock xlock;
  197912. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197913. && XSync (display, False);
  197914. }
  197915. bool makeInactive() const throw()
  197916. {
  197917. ScopedXLock xlock;
  197918. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197919. }
  197920. bool isActive() const throw()
  197921. {
  197922. ScopedXLock xlock;
  197923. return glXGetCurrentContext() == renderContext;
  197924. }
  197925. const OpenGLPixelFormat getPixelFormat() const
  197926. {
  197927. return pixelFormat;
  197928. }
  197929. void* getRawContext() const throw()
  197930. {
  197931. return renderContext;
  197932. }
  197933. void updateWindowPosition (int x, int y, int w, int h, int)
  197934. {
  197935. ScopedXLock xlock;
  197936. XMoveResizeWindow (display, embeddedWindow,
  197937. x, y, jmax (1, w), jmax (1, h));
  197938. }
  197939. void swapBuffers()
  197940. {
  197941. ScopedXLock xlock;
  197942. glXSwapBuffers (display, embeddedWindow);
  197943. }
  197944. bool setSwapInterval (const int numFramesPerSwap)
  197945. {
  197946. // xxx needs doing..
  197947. return false;
  197948. }
  197949. int getSwapInterval() const
  197950. {
  197951. // xxx needs doing..
  197952. return 0;
  197953. }
  197954. void repaint()
  197955. {
  197956. }
  197957. juce_UseDebuggingNewOperator
  197958. GLXContext renderContext;
  197959. private:
  197960. Window embeddedWindow;
  197961. OpenGLPixelFormat pixelFormat;
  197962. WindowedGLContext (const WindowedGLContext&);
  197963. WindowedGLContext& operator= (const WindowedGLContext&);
  197964. };
  197965. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  197966. const OpenGLPixelFormat& pixelFormat,
  197967. const OpenGLContext* const contextToShareWith)
  197968. {
  197969. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  197970. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  197971. if (c->renderContext == 0)
  197972. deleteAndZero (c);
  197973. return c;
  197974. }
  197975. void juce_glViewport (const int w, const int h)
  197976. {
  197977. glViewport (0, 0, w, h);
  197978. }
  197979. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197980. OwnedArray <OpenGLPixelFormat>& results)
  197981. {
  197982. results.add (new OpenGLPixelFormat()); // xxx
  197983. }
  197984. #endif
  197985. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197986. {
  197987. jassertfalse // not implemented!
  197988. return false;
  197989. }
  197990. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197991. {
  197992. jassertfalse // not implemented!
  197993. return false;
  197994. }
  197995. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197996. {
  197997. if (! isOnDesktop ())
  197998. addToDesktop (0);
  197999. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198000. if (wp != 0)
  198001. {
  198002. wp->setTaskBarIcon (newImage);
  198003. setVisible (true);
  198004. toFront (false);
  198005. repaint();
  198006. }
  198007. }
  198008. void SystemTrayIconComponent::paint (Graphics& g)
  198009. {
  198010. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198011. if (wp != 0)
  198012. {
  198013. const Image* const image = wp->getTaskbarIcon();
  198014. if (image != 0)
  198015. {
  198016. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  198017. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  198018. false);
  198019. }
  198020. }
  198021. }
  198022. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  198023. {
  198024. // xxx not yet implemented!
  198025. }
  198026. void PlatformUtilities::beep()
  198027. {
  198028. std::cout << "\a" << std::flush;
  198029. }
  198030. bool AlertWindow::showNativeDialogBox (const String& title,
  198031. const String& bodyText,
  198032. bool isOkCancel)
  198033. {
  198034. // xxx this is supposed to pop up an alert!
  198035. Logger::outputDebugString (title + ": " + bodyText);
  198036. // use a non-native one for the time being..
  198037. if (isOkCancel)
  198038. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  198039. else
  198040. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  198041. return true;
  198042. }
  198043. const int KeyPress::spaceKey = XK_space & 0xff;
  198044. const int KeyPress::returnKey = XK_Return & 0xff;
  198045. const int KeyPress::escapeKey = XK_Escape & 0xff;
  198046. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  198047. const int KeyPress::leftKey = (XK_Left & 0xff) | extendedKeyModifier;
  198048. const int KeyPress::rightKey = (XK_Right & 0xff) | extendedKeyModifier;
  198049. const int KeyPress::upKey = (XK_Up & 0xff) | extendedKeyModifier;
  198050. const int KeyPress::downKey = (XK_Down & 0xff) | extendedKeyModifier;
  198051. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | extendedKeyModifier;
  198052. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | extendedKeyModifier;
  198053. const int KeyPress::endKey = (XK_End & 0xff) | extendedKeyModifier;
  198054. const int KeyPress::homeKey = (XK_Home & 0xff) | extendedKeyModifier;
  198055. const int KeyPress::insertKey = (XK_Insert & 0xff) | extendedKeyModifier;
  198056. const int KeyPress::deleteKey = (XK_Delete & 0xff) | extendedKeyModifier;
  198057. const int KeyPress::tabKey = XK_Tab & 0xff;
  198058. const int KeyPress::F1Key = (XK_F1 & 0xff) | extendedKeyModifier;
  198059. const int KeyPress::F2Key = (XK_F2 & 0xff) | extendedKeyModifier;
  198060. const int KeyPress::F3Key = (XK_F3 & 0xff) | extendedKeyModifier;
  198061. const int KeyPress::F4Key = (XK_F4 & 0xff) | extendedKeyModifier;
  198062. const int KeyPress::F5Key = (XK_F5 & 0xff) | extendedKeyModifier;
  198063. const int KeyPress::F6Key = (XK_F6 & 0xff) | extendedKeyModifier;
  198064. const int KeyPress::F7Key = (XK_F7 & 0xff) | extendedKeyModifier;
  198065. const int KeyPress::F8Key = (XK_F8 & 0xff) | extendedKeyModifier;
  198066. const int KeyPress::F9Key = (XK_F9 & 0xff) | extendedKeyModifier;
  198067. const int KeyPress::F10Key = (XK_F10 & 0xff) | extendedKeyModifier;
  198068. const int KeyPress::F11Key = (XK_F11 & 0xff) | extendedKeyModifier;
  198069. const int KeyPress::F12Key = (XK_F12 & 0xff) | extendedKeyModifier;
  198070. const int KeyPress::F13Key = (XK_F13 & 0xff) | extendedKeyModifier;
  198071. const int KeyPress::F14Key = (XK_F14 & 0xff) | extendedKeyModifier;
  198072. const int KeyPress::F15Key = (XK_F15 & 0xff) | extendedKeyModifier;
  198073. const int KeyPress::F16Key = (XK_F16 & 0xff) | extendedKeyModifier;
  198074. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | extendedKeyModifier;
  198075. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | extendedKeyModifier;
  198076. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | extendedKeyModifier;
  198077. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | extendedKeyModifier;
  198078. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | extendedKeyModifier;
  198079. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | extendedKeyModifier;
  198080. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | extendedKeyModifier;
  198081. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| extendedKeyModifier;
  198082. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| extendedKeyModifier;
  198083. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| extendedKeyModifier;
  198084. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| extendedKeyModifier;
  198085. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| extendedKeyModifier;
  198086. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| extendedKeyModifier;
  198087. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| extendedKeyModifier;
  198088. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| extendedKeyModifier;
  198089. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| extendedKeyModifier;
  198090. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| extendedKeyModifier;
  198091. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| extendedKeyModifier;
  198092. const int KeyPress::playKey = (0xffeeff00) | extendedKeyModifier;
  198093. const int KeyPress::stopKey = (0xffeeff01) | extendedKeyModifier;
  198094. const int KeyPress::fastForwardKey = (0xffeeff02) | extendedKeyModifier;
  198095. const int KeyPress::rewindKey = (0xffeeff03) | extendedKeyModifier;
  198096. #endif
  198097. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  198098. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  198099. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198100. // compiled on its own).
  198101. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  198102. static const int maxNumChans = 64;
  198103. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  198104. {
  198105. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  198106. snd_pcm_hw_params_t* hwParams;
  198107. snd_pcm_hw_params_alloca (&hwParams);
  198108. for (int i = 0; ratesToTry[i] != 0; ++i)
  198109. {
  198110. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  198111. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  198112. {
  198113. rates.addIfNotAlreadyThere (ratesToTry[i]);
  198114. }
  198115. }
  198116. }
  198117. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  198118. {
  198119. snd_pcm_hw_params_t *params;
  198120. snd_pcm_hw_params_alloca (&params);
  198121. if (snd_pcm_hw_params_any (handle, params) >= 0)
  198122. {
  198123. snd_pcm_hw_params_get_channels_min (params, minChans);
  198124. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198125. }
  198126. }
  198127. static void getDeviceProperties (const String& deviceID,
  198128. unsigned int& minChansOut,
  198129. unsigned int& maxChansOut,
  198130. unsigned int& minChansIn,
  198131. unsigned int& maxChansIn,
  198132. Array <int>& rates)
  198133. {
  198134. if (deviceID.isEmpty())
  198135. return;
  198136. snd_ctl_t* handle;
  198137. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (T(","), false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198138. {
  198139. snd_pcm_info_t* info;
  198140. snd_pcm_info_alloca (&info);
  198141. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198142. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198143. snd_pcm_info_set_subdevice (info, 0);
  198144. if (snd_ctl_pcm_info (handle, info) >= 0)
  198145. {
  198146. snd_pcm_t* pcmHandle;
  198147. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198148. {
  198149. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198150. getDeviceSampleRates (pcmHandle, rates);
  198151. snd_pcm_close (pcmHandle);
  198152. }
  198153. }
  198154. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198155. if (snd_ctl_pcm_info (handle, info) >= 0)
  198156. {
  198157. snd_pcm_t* pcmHandle;
  198158. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198159. {
  198160. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198161. if (rates.size() == 0)
  198162. getDeviceSampleRates (pcmHandle, rates);
  198163. snd_pcm_close (pcmHandle);
  198164. }
  198165. }
  198166. snd_ctl_close (handle);
  198167. }
  198168. }
  198169. class ALSADevice
  198170. {
  198171. public:
  198172. ALSADevice (const String& deviceID,
  198173. const bool forInput)
  198174. : handle (0),
  198175. bitDepth (16),
  198176. numChannelsRunning (0),
  198177. isInput (forInput),
  198178. sampleFormat (AudioDataConverters::int16LE)
  198179. {
  198180. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  198181. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198182. SND_PCM_ASYNC));
  198183. }
  198184. ~ALSADevice()
  198185. {
  198186. if (handle != 0)
  198187. snd_pcm_close (handle);
  198188. }
  198189. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198190. {
  198191. if (handle == 0)
  198192. return false;
  198193. snd_pcm_hw_params_t* hwParams;
  198194. snd_pcm_hw_params_alloca (&hwParams);
  198195. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198196. return false;
  198197. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198198. isInterleaved = false;
  198199. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198200. isInterleaved = true;
  198201. else
  198202. {
  198203. jassertfalse
  198204. return false;
  198205. }
  198206. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198207. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198208. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198209. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198210. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198211. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198212. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198213. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198214. bitDepth = 0;
  198215. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198216. {
  198217. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198218. {
  198219. bitDepth = formatsToTry [i + 1];
  198220. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198221. break;
  198222. }
  198223. }
  198224. if (bitDepth == 0)
  198225. {
  198226. error = "device doesn't support a compatible PCM format";
  198227. DBG (T("ALSA error: ") + error + T("\n"));
  198228. return false;
  198229. }
  198230. int dir = 0;
  198231. unsigned int periods = 4;
  198232. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198233. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198234. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198235. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198236. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198237. || failed (snd_pcm_hw_params (handle, hwParams)))
  198238. {
  198239. return false;
  198240. }
  198241. snd_pcm_sw_params_t* swParams;
  198242. snd_pcm_sw_params_alloca (&swParams);
  198243. snd_pcm_uframes_t boundary;
  198244. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198245. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198246. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198247. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198248. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198249. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198250. || failed (snd_pcm_sw_params (handle, swParams)))
  198251. {
  198252. return false;
  198253. }
  198254. numChannelsRunning = numChannels;
  198255. return true;
  198256. }
  198257. bool write (float** const data, const int numSamples)
  198258. {
  198259. if (isInterleaved)
  198260. {
  198261. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198262. float* interleaved = (float*) scratch;
  198263. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198264. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198265. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198266. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198267. return false;
  198268. }
  198269. else
  198270. {
  198271. for (int i = 0; i < numChannelsRunning; ++i)
  198272. if (data[i] != 0)
  198273. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198274. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198275. if (failed (num))
  198276. {
  198277. if (num == -EPIPE)
  198278. {
  198279. if (failed (snd_pcm_prepare (handle)))
  198280. return false;
  198281. }
  198282. else if (num != -ESTRPIPE)
  198283. return false;
  198284. }
  198285. }
  198286. return true;
  198287. }
  198288. bool read (float** const data, const int numSamples)
  198289. {
  198290. if (isInterleaved)
  198291. {
  198292. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198293. float* interleaved = (float*) scratch;
  198294. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198295. if (failed (num))
  198296. {
  198297. if (num == -EPIPE)
  198298. {
  198299. if (failed (snd_pcm_prepare (handle)))
  198300. return false;
  198301. }
  198302. else if (num != -ESTRPIPE)
  198303. return false;
  198304. }
  198305. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198306. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198307. }
  198308. else
  198309. {
  198310. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198311. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198312. return false;
  198313. for (int i = 0; i < numChannelsRunning; ++i)
  198314. if (data[i] != 0)
  198315. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198316. }
  198317. return true;
  198318. }
  198319. juce_UseDebuggingNewOperator
  198320. snd_pcm_t* handle;
  198321. String error;
  198322. int bitDepth, numChannelsRunning;
  198323. private:
  198324. const bool isInput;
  198325. bool isInterleaved;
  198326. MemoryBlock scratch;
  198327. AudioDataConverters::DataFormat sampleFormat;
  198328. bool failed (const int errorNum)
  198329. {
  198330. if (errorNum >= 0)
  198331. return false;
  198332. error = snd_strerror (errorNum);
  198333. DBG (T("ALSA error: ") + error + T("\n"));
  198334. return true;
  198335. }
  198336. };
  198337. class ALSAThread : public Thread
  198338. {
  198339. public:
  198340. ALSAThread (const String& inputId_,
  198341. const String& outputId_)
  198342. : Thread ("Juce ALSA"),
  198343. sampleRate (0),
  198344. bufferSize (0),
  198345. callback (0),
  198346. inputId (inputId_),
  198347. outputId (outputId_),
  198348. outputDevice (0),
  198349. inputDevice (0),
  198350. numCallbacks (0),
  198351. totalNumInputChannels (0),
  198352. totalNumOutputChannels (0)
  198353. {
  198354. zeromem (outputChannelData, sizeof (outputChannelData));
  198355. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198356. zeromem (inputChannelData, sizeof (inputChannelData));
  198357. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198358. initialiseRatesAndChannels();
  198359. }
  198360. ~ALSAThread()
  198361. {
  198362. close();
  198363. }
  198364. void open (BitArray inputChannels,
  198365. BitArray outputChannels,
  198366. const double sampleRate_,
  198367. const int bufferSize_)
  198368. {
  198369. close();
  198370. error = String::empty;
  198371. sampleRate = sampleRate_;
  198372. bufferSize = bufferSize_;
  198373. currentInputChans.clear();
  198374. currentOutputChans.clear();
  198375. if (inputChannels.getHighestBit() >= 0)
  198376. {
  198377. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198378. {
  198379. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198380. if (inputChannels[i])
  198381. {
  198382. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198383. currentInputChans.setBit (i);
  198384. }
  198385. }
  198386. }
  198387. if (outputChannels.getHighestBit() >= 0)
  198388. {
  198389. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198390. {
  198391. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198392. if (outputChannels[i])
  198393. {
  198394. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198395. currentOutputChans.setBit (i);
  198396. }
  198397. }
  198398. }
  198399. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198400. {
  198401. outputDevice = new ALSADevice (outputId, false);
  198402. if (outputDevice->error.isNotEmpty())
  198403. {
  198404. error = outputDevice->error;
  198405. deleteAndZero (outputDevice);
  198406. return;
  198407. }
  198408. currentOutputChans.setRange (0, minChansOut, true);
  198409. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198410. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198411. bufferSize))
  198412. {
  198413. error = outputDevice->error;
  198414. deleteAndZero (outputDevice);
  198415. return;
  198416. }
  198417. }
  198418. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198419. {
  198420. inputDevice = new ALSADevice (inputId, true);
  198421. if (inputDevice->error.isNotEmpty())
  198422. {
  198423. error = inputDevice->error;
  198424. deleteAndZero (inputDevice);
  198425. return;
  198426. }
  198427. currentInputChans.setRange (0, minChansIn, true);
  198428. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198429. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198430. bufferSize))
  198431. {
  198432. error = inputDevice->error;
  198433. deleteAndZero (inputDevice);
  198434. return;
  198435. }
  198436. }
  198437. if (outputDevice == 0 && inputDevice == 0)
  198438. {
  198439. error = "no channels";
  198440. return;
  198441. }
  198442. if (outputDevice != 0 && inputDevice != 0)
  198443. {
  198444. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198445. }
  198446. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198447. return;
  198448. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198449. return;
  198450. startThread (9);
  198451. int count = 1000;
  198452. while (numCallbacks == 0)
  198453. {
  198454. sleep (5);
  198455. if (--count < 0 || ! isThreadRunning())
  198456. {
  198457. error = "device didn't start";
  198458. break;
  198459. }
  198460. }
  198461. }
  198462. void close()
  198463. {
  198464. stopThread (6000);
  198465. deleteAndZero (inputDevice);
  198466. deleteAndZero (outputDevice);
  198467. for (int i = 0; i < maxNumChans; ++i)
  198468. {
  198469. juce_free (inputChannelData [i]);
  198470. juce_free (outputChannelData [i]);
  198471. }
  198472. zeromem (outputChannelData, sizeof (outputChannelData));
  198473. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198474. zeromem (inputChannelData, sizeof (inputChannelData));
  198475. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198476. totalNumOutputChannels = 0;
  198477. totalNumInputChannels = 0;
  198478. numCallbacks = 0;
  198479. }
  198480. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198481. {
  198482. const ScopedLock sl (callbackLock);
  198483. callback = newCallback;
  198484. }
  198485. void run()
  198486. {
  198487. while (! threadShouldExit())
  198488. {
  198489. if (inputDevice != 0)
  198490. {
  198491. if (! inputDevice->read (inputChannelData, bufferSize))
  198492. {
  198493. DBG ("ALSA: read failure");
  198494. break;
  198495. }
  198496. }
  198497. if (threadShouldExit())
  198498. break;
  198499. {
  198500. const ScopedLock sl (callbackLock);
  198501. ++numCallbacks;
  198502. if (callback != 0)
  198503. {
  198504. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198505. totalNumInputChannels,
  198506. outputChannelDataForCallback,
  198507. totalNumOutputChannels,
  198508. bufferSize);
  198509. }
  198510. else
  198511. {
  198512. for (int i = 0; i < totalNumOutputChannels; ++i)
  198513. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198514. }
  198515. }
  198516. if (outputDevice != 0)
  198517. {
  198518. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198519. if (threadShouldExit())
  198520. break;
  198521. failed (snd_pcm_avail_update (outputDevice->handle));
  198522. if (! outputDevice->write (outputChannelData, bufferSize))
  198523. {
  198524. DBG ("ALSA: write failure");
  198525. break;
  198526. }
  198527. }
  198528. }
  198529. }
  198530. int getBitDepth() const throw()
  198531. {
  198532. if (outputDevice != 0)
  198533. return outputDevice->bitDepth;
  198534. if (inputDevice != 0)
  198535. return inputDevice->bitDepth;
  198536. return 16;
  198537. }
  198538. juce_UseDebuggingNewOperator
  198539. String error;
  198540. double sampleRate;
  198541. int bufferSize;
  198542. BitArray currentInputChans, currentOutputChans;
  198543. Array <int> sampleRates;
  198544. StringArray channelNamesOut, channelNamesIn;
  198545. AudioIODeviceCallback* callback;
  198546. private:
  198547. const String inputId, outputId;
  198548. ALSADevice* outputDevice;
  198549. ALSADevice* inputDevice;
  198550. int numCallbacks;
  198551. CriticalSection callbackLock;
  198552. float* outputChannelData [maxNumChans];
  198553. float* outputChannelDataForCallback [maxNumChans];
  198554. int totalNumInputChannels;
  198555. float* inputChannelData [maxNumChans];
  198556. float* inputChannelDataForCallback [maxNumChans];
  198557. int totalNumOutputChannels;
  198558. unsigned int minChansOut, maxChansOut;
  198559. unsigned int minChansIn, maxChansIn;
  198560. bool failed (const int errorNum) throw()
  198561. {
  198562. if (errorNum >= 0)
  198563. return false;
  198564. error = snd_strerror (errorNum);
  198565. DBG (T("ALSA error: ") + error + T("\n"));
  198566. return true;
  198567. }
  198568. void initialiseRatesAndChannels() throw()
  198569. {
  198570. sampleRates.clear();
  198571. channelNamesOut.clear();
  198572. channelNamesIn.clear();
  198573. minChansOut = 0;
  198574. maxChansOut = 0;
  198575. minChansIn = 0;
  198576. maxChansIn = 0;
  198577. unsigned int dummy = 0;
  198578. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198579. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198580. unsigned int i;
  198581. for (i = 0; i < maxChansOut; ++i)
  198582. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198583. for (i = 0; i < maxChansIn; ++i)
  198584. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198585. }
  198586. };
  198587. class ALSAAudioIODevice : public AudioIODevice
  198588. {
  198589. public:
  198590. ALSAAudioIODevice (const String& deviceName,
  198591. const String& inputId_,
  198592. const String& outputId_)
  198593. : AudioIODevice (deviceName, T("ALSA")),
  198594. inputId (inputId_),
  198595. outputId (outputId_),
  198596. isOpen_ (false),
  198597. isStarted (false),
  198598. internal (0)
  198599. {
  198600. internal = new ALSAThread (inputId, outputId);
  198601. }
  198602. ~ALSAAudioIODevice()
  198603. {
  198604. delete internal;
  198605. }
  198606. const StringArray getOutputChannelNames()
  198607. {
  198608. return internal->channelNamesOut;
  198609. }
  198610. const StringArray getInputChannelNames()
  198611. {
  198612. return internal->channelNamesIn;
  198613. }
  198614. int getNumSampleRates()
  198615. {
  198616. return internal->sampleRates.size();
  198617. }
  198618. double getSampleRate (int index)
  198619. {
  198620. return internal->sampleRates [index];
  198621. }
  198622. int getNumBufferSizesAvailable()
  198623. {
  198624. return 50;
  198625. }
  198626. int getBufferSizeSamples (int index)
  198627. {
  198628. int n = 16;
  198629. for (int i = 0; i < index; ++i)
  198630. n += n < 64 ? 16
  198631. : (n < 512 ? 32
  198632. : (n < 1024 ? 64
  198633. : (n < 2048 ? 128 : 256)));
  198634. return n;
  198635. }
  198636. int getDefaultBufferSize()
  198637. {
  198638. return 512;
  198639. }
  198640. const String open (const BitArray& inputChannels,
  198641. const BitArray& outputChannels,
  198642. double sampleRate,
  198643. int bufferSizeSamples)
  198644. {
  198645. close();
  198646. if (bufferSizeSamples <= 0)
  198647. bufferSizeSamples = getDefaultBufferSize();
  198648. if (sampleRate <= 0)
  198649. {
  198650. for (int i = 0; i < getNumSampleRates(); ++i)
  198651. {
  198652. if (getSampleRate (i) >= 44100)
  198653. {
  198654. sampleRate = getSampleRate (i);
  198655. break;
  198656. }
  198657. }
  198658. }
  198659. internal->open (inputChannels, outputChannels,
  198660. sampleRate, bufferSizeSamples);
  198661. isOpen_ = internal->error.isEmpty();
  198662. return internal->error;
  198663. }
  198664. void close()
  198665. {
  198666. stop();
  198667. internal->close();
  198668. isOpen_ = false;
  198669. }
  198670. bool isOpen()
  198671. {
  198672. return isOpen_;
  198673. }
  198674. int getCurrentBufferSizeSamples()
  198675. {
  198676. return internal->bufferSize;
  198677. }
  198678. double getCurrentSampleRate()
  198679. {
  198680. return internal->sampleRate;
  198681. }
  198682. int getCurrentBitDepth()
  198683. {
  198684. return internal->getBitDepth();
  198685. }
  198686. const BitArray getActiveOutputChannels() const
  198687. {
  198688. return internal->currentOutputChans;
  198689. }
  198690. const BitArray getActiveInputChannels() const
  198691. {
  198692. return internal->currentInputChans;
  198693. }
  198694. int getOutputLatencyInSamples()
  198695. {
  198696. return 0;
  198697. }
  198698. int getInputLatencyInSamples()
  198699. {
  198700. return 0;
  198701. }
  198702. void start (AudioIODeviceCallback* callback)
  198703. {
  198704. if (! isOpen_)
  198705. callback = 0;
  198706. internal->setCallback (callback);
  198707. if (callback != 0)
  198708. callback->audioDeviceAboutToStart (this);
  198709. isStarted = (callback != 0);
  198710. }
  198711. void stop()
  198712. {
  198713. AudioIODeviceCallback* const oldCallback = internal->callback;
  198714. start (0);
  198715. if (oldCallback != 0)
  198716. oldCallback->audioDeviceStopped();
  198717. }
  198718. bool isPlaying()
  198719. {
  198720. return isStarted && internal->error.isEmpty();
  198721. }
  198722. const String getLastError()
  198723. {
  198724. return internal->error;
  198725. }
  198726. String inputId, outputId;
  198727. private:
  198728. bool isOpen_, isStarted;
  198729. ALSAThread* internal;
  198730. };
  198731. class ALSAAudioIODeviceType : public AudioIODeviceType
  198732. {
  198733. public:
  198734. ALSAAudioIODeviceType()
  198735. : AudioIODeviceType (T("ALSA")),
  198736. hasScanned (false)
  198737. {
  198738. }
  198739. ~ALSAAudioIODeviceType()
  198740. {
  198741. }
  198742. void scanForDevices()
  198743. {
  198744. if (hasScanned)
  198745. return;
  198746. hasScanned = true;
  198747. inputNames.clear();
  198748. inputIds.clear();
  198749. outputNames.clear();
  198750. outputIds.clear();
  198751. snd_ctl_t* handle;
  198752. snd_ctl_card_info_t* info;
  198753. snd_ctl_card_info_alloca (&info);
  198754. int cardNum = -1;
  198755. while (outputIds.size() + inputIds.size() <= 32)
  198756. {
  198757. snd_card_next (&cardNum);
  198758. if (cardNum < 0)
  198759. break;
  198760. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198761. {
  198762. if (snd_ctl_card_info (handle, info) >= 0)
  198763. {
  198764. String cardId (snd_ctl_card_info_get_id (info));
  198765. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198766. cardId = String (cardNum);
  198767. int device = -1;
  198768. for (;;)
  198769. {
  198770. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198771. break;
  198772. String id, name;
  198773. id << "hw:" << cardId << ',' << device;
  198774. bool isInput, isOutput;
  198775. if (testDevice (id, isInput, isOutput))
  198776. {
  198777. name << snd_ctl_card_info_get_name (info);
  198778. if (name.isEmpty())
  198779. name = id;
  198780. if (isInput)
  198781. {
  198782. inputNames.add (name);
  198783. inputIds.add (id);
  198784. }
  198785. if (isOutput)
  198786. {
  198787. outputNames.add (name);
  198788. outputIds.add (id);
  198789. }
  198790. }
  198791. }
  198792. }
  198793. snd_ctl_close (handle);
  198794. }
  198795. }
  198796. inputNames.appendNumbersToDuplicates (false, true);
  198797. outputNames.appendNumbersToDuplicates (false, true);
  198798. }
  198799. const StringArray getDeviceNames (const bool wantInputNames) const
  198800. {
  198801. jassert (hasScanned); // need to call scanForDevices() before doing this
  198802. return wantInputNames ? inputNames : outputNames;
  198803. }
  198804. int getDefaultDeviceIndex (const bool forInput) const
  198805. {
  198806. jassert (hasScanned); // need to call scanForDevices() before doing this
  198807. return 0;
  198808. }
  198809. bool hasSeparateInputsAndOutputs() const { return true; }
  198810. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198811. {
  198812. jassert (hasScanned); // need to call scanForDevices() before doing this
  198813. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198814. if (d == 0)
  198815. return -1;
  198816. return asInput ? inputIds.indexOf (d->inputId)
  198817. : outputIds.indexOf (d->outputId);
  198818. }
  198819. AudioIODevice* createDevice (const String& outputDeviceName,
  198820. const String& inputDeviceName)
  198821. {
  198822. jassert (hasScanned); // need to call scanForDevices() before doing this
  198823. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198824. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198825. String deviceName (outputIndex >= 0 ? outputDeviceName
  198826. : inputDeviceName);
  198827. if (inputIndex >= 0 || outputIndex >= 0)
  198828. return new ALSAAudioIODevice (deviceName,
  198829. inputIds [inputIndex],
  198830. outputIds [outputIndex]);
  198831. return 0;
  198832. }
  198833. juce_UseDebuggingNewOperator
  198834. private:
  198835. StringArray inputNames, outputNames, inputIds, outputIds;
  198836. bool hasScanned;
  198837. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198838. {
  198839. unsigned int minChansOut = 0, maxChansOut = 0;
  198840. unsigned int minChansIn = 0, maxChansIn = 0;
  198841. Array <int> rates;
  198842. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198843. DBG (T("ALSA device: ") + id
  198844. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198845. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198846. + T(" rates=") + String (rates.size()));
  198847. isInput = maxChansIn > 0;
  198848. isOutput = maxChansOut > 0;
  198849. return (isInput || isOutput) && rates.size() > 0;
  198850. }
  198851. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198852. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198853. };
  198854. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198855. {
  198856. return new ALSAAudioIODeviceType();
  198857. }
  198858. #endif
  198859. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198860. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198861. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198862. // compiled on its own).
  198863. #ifdef JUCE_INCLUDED_FILE
  198864. #if JUCE_JACK
  198865. static void* juce_libjack_handle = 0;
  198866. void* juce_load_jack_function (const char* const name)
  198867. {
  198868. if (juce_libjack_handle == 0)
  198869. return 0;
  198870. return dlsym (juce_libjack_handle, name);
  198871. }
  198872. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198873. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198874. return_type fn_name argument_types { \
  198875. static fn_name##_ptr_t fn = 0; \
  198876. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198877. if (fn) return (*fn)arguments; \
  198878. else return 0; \
  198879. }
  198880. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198881. typedef void (*fn_name##_ptr_t)argument_types; \
  198882. void fn_name argument_types { \
  198883. static fn_name##_ptr_t fn = 0; \
  198884. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198885. if (fn) (*fn)arguments; \
  198886. }
  198887. 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));
  198888. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198889. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198890. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198891. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198892. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198893. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198894. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198895. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198896. 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));
  198897. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198898. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198899. 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));
  198900. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198901. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198902. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198903. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198904. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198905. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198906. #if JUCE_DEBUG
  198907. #define JACK_LOGGING_ENABLED 1
  198908. #endif
  198909. #if JACK_LOGGING_ENABLED
  198910. static void jack_Log (const String& s)
  198911. {
  198912. std::cerr << s << std::endl;
  198913. }
  198914. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198915. {
  198916. if (status & JackServerFailed || status & JackServerError)
  198917. jack_Log ("Unable to connect to JACK server");
  198918. if (status & JackVersionError)
  198919. jack_Log ("Client's protocol version does not match");
  198920. if (status & JackInvalidOption)
  198921. jack_Log ("The operation contained an invalid or unsupported option");
  198922. if (status & JackNameNotUnique)
  198923. jack_Log ("The desired client name was not unique");
  198924. if (status & JackNoSuchClient)
  198925. jack_Log ("Requested client does not exist");
  198926. if (status & JackInitFailure)
  198927. jack_Log ("Unable to initialize client");
  198928. }
  198929. #else
  198930. #define dumpJackErrorMessage(a) {}
  198931. #define jack_Log(...) {}
  198932. #endif
  198933. #ifndef JUCE_JACK_CLIENT_NAME
  198934. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198935. #endif
  198936. class JackAudioIODevice : public AudioIODevice
  198937. {
  198938. public:
  198939. JackAudioIODevice (const String& deviceName,
  198940. const String& inputId_,
  198941. const String& outputId_)
  198942. : AudioIODevice (deviceName, T("JACK")),
  198943. inputId (inputId_),
  198944. outputId (outputId_),
  198945. isOpen_ (false),
  198946. callback (0),
  198947. totalNumberOfInputChannels (0),
  198948. totalNumberOfOutputChannels (0)
  198949. {
  198950. jassert (deviceName.isNotEmpty());
  198951. jack_status_t status;
  198952. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198953. if (client == 0)
  198954. {
  198955. dumpJackErrorMessage (status);
  198956. }
  198957. else
  198958. {
  198959. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198960. // open input ports
  198961. const StringArray inputChannels (getInputChannelNames());
  198962. for (int i = 0; i < inputChannels.size(); i++)
  198963. {
  198964. String inputName;
  198965. inputName << "in_" << ++totalNumberOfInputChannels;
  198966. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198967. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198968. }
  198969. // open output ports
  198970. const StringArray outputChannels (getOutputChannelNames());
  198971. for (int i = 0; i < outputChannels.size (); i++)
  198972. {
  198973. String outputName;
  198974. outputName << "out_" << ++totalNumberOfOutputChannels;
  198975. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198976. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198977. }
  198978. inChans.calloc (totalNumberOfInputChannels + 2);
  198979. outChans.calloc (totalNumberOfOutputChannels + 2);
  198980. }
  198981. }
  198982. ~JackAudioIODevice()
  198983. {
  198984. close();
  198985. if (client != 0)
  198986. {
  198987. JUCE_NAMESPACE::jack_client_close (client);
  198988. client = 0;
  198989. }
  198990. }
  198991. const StringArray getChannelNames (bool forInput) const
  198992. {
  198993. StringArray names;
  198994. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198995. forInput ? JackPortIsInput : JackPortIsOutput);
  198996. if (ports != 0)
  198997. {
  198998. int j = 0;
  198999. while (ports[j] != 0)
  199000. {
  199001. const String portName (ports [j++]);
  199002. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199003. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  199004. }
  199005. free (ports);
  199006. }
  199007. return names;
  199008. }
  199009. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  199010. const StringArray getInputChannelNames() { return getChannelNames (true); }
  199011. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  199012. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  199013. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  199014. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  199015. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  199016. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  199017. double sampleRate, int bufferSizeSamples)
  199018. {
  199019. if (client == 0)
  199020. {
  199021. lastError = T("No JACK client running");
  199022. return lastError;
  199023. }
  199024. lastError = String::empty;
  199025. close();
  199026. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  199027. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  199028. JUCE_NAMESPACE::jack_activate (client);
  199029. isOpen_ = true;
  199030. if (! inputChannels.isEmpty())
  199031. {
  199032. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199033. if (ports != 0)
  199034. {
  199035. const int numInputChannels = inputChannels.getHighestBit () + 1;
  199036. for (int i = 0; i < numInputChannels; ++i)
  199037. {
  199038. const String portName (ports[i]);
  199039. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199040. {
  199041. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  199042. if (error != 0)
  199043. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199044. }
  199045. }
  199046. free (ports);
  199047. }
  199048. }
  199049. if (! outputChannels.isEmpty())
  199050. {
  199051. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199052. if (ports != 0)
  199053. {
  199054. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  199055. for (int i = 0; i < numOutputChannels; ++i)
  199056. {
  199057. const String portName (ports[i]);
  199058. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199059. {
  199060. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  199061. if (error != 0)
  199062. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199063. }
  199064. }
  199065. free (ports);
  199066. }
  199067. }
  199068. return lastError;
  199069. }
  199070. void close()
  199071. {
  199072. stop();
  199073. if (client != 0)
  199074. {
  199075. JUCE_NAMESPACE::jack_deactivate (client);
  199076. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  199077. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  199078. }
  199079. isOpen_ = false;
  199080. }
  199081. void start (AudioIODeviceCallback* newCallback)
  199082. {
  199083. if (isOpen_ && newCallback != callback)
  199084. {
  199085. if (newCallback != 0)
  199086. newCallback->audioDeviceAboutToStart (this);
  199087. AudioIODeviceCallback* const oldCallback = callback;
  199088. {
  199089. const ScopedLock sl (callbackLock);
  199090. callback = newCallback;
  199091. }
  199092. if (oldCallback != 0)
  199093. oldCallback->audioDeviceStopped();
  199094. }
  199095. }
  199096. void stop()
  199097. {
  199098. start (0);
  199099. }
  199100. bool isOpen() { return isOpen_; }
  199101. bool isPlaying() { return callback != 0; }
  199102. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  199103. double getCurrentSampleRate() { return getSampleRate (0); }
  199104. int getCurrentBitDepth() { return 32; }
  199105. const String getLastError() { return lastError; }
  199106. const BitArray getActiveOutputChannels() const
  199107. {
  199108. BitArray outputBits;
  199109. for (int i = 0; i < outputPorts.size(); i++)
  199110. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  199111. outputBits.setBit (i);
  199112. return outputBits;
  199113. }
  199114. const BitArray getActiveInputChannels() const
  199115. {
  199116. BitArray inputBits;
  199117. for (int i = 0; i < inputPorts.size(); i++)
  199118. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  199119. inputBits.setBit (i);
  199120. return inputBits;
  199121. }
  199122. int getOutputLatencyInSamples()
  199123. {
  199124. int latency = 0;
  199125. for (int i = 0; i < outputPorts.size(); i++)
  199126. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199127. return latency;
  199128. }
  199129. int getInputLatencyInSamples()
  199130. {
  199131. int latency = 0;
  199132. for (int i = 0; i < inputPorts.size(); i++)
  199133. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199134. return latency;
  199135. }
  199136. String inputId, outputId;
  199137. private:
  199138. void process (const int numSamples)
  199139. {
  199140. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199141. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199142. {
  199143. jack_default_audio_sample_t* in
  199144. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199145. if (in != 0)
  199146. inChans [numActiveInChans++] = (float*) in;
  199147. }
  199148. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199149. {
  199150. jack_default_audio_sample_t* out
  199151. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199152. if (out != 0)
  199153. outChans [numActiveOutChans++] = (float*) out;
  199154. }
  199155. const ScopedLock sl (callbackLock);
  199156. if (callback != 0)
  199157. {
  199158. callback->audioDeviceIOCallback ((const float**) inChans, numActiveInChans,
  199159. outChans, numActiveOutChans, numSamples);
  199160. }
  199161. else
  199162. {
  199163. for (i = 0; i < numActiveOutChans; ++i)
  199164. zeromem (outChans[i], sizeof (float) * numSamples);
  199165. }
  199166. }
  199167. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199168. {
  199169. if (callbackArgument != 0)
  199170. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199171. return 0;
  199172. }
  199173. static void threadInitCallback (void* callbackArgument)
  199174. {
  199175. jack_Log ("JackAudioIODevice::initialise");
  199176. }
  199177. static void shutdownCallback (void* callbackArgument)
  199178. {
  199179. jack_Log ("JackAudioIODevice::shutdown");
  199180. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199181. if (device != 0)
  199182. {
  199183. device->client = 0;
  199184. device->close();
  199185. }
  199186. }
  199187. static void errorCallback (const char* msg)
  199188. {
  199189. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199190. }
  199191. bool isOpen_;
  199192. jack_client_t* client;
  199193. String lastError;
  199194. AudioIODeviceCallback* callback;
  199195. CriticalSection callbackLock;
  199196. HeapBlock <float*> inChans, outChans;
  199197. int totalNumberOfInputChannels;
  199198. int totalNumberOfOutputChannels;
  199199. VoidArray inputPorts, outputPorts;
  199200. };
  199201. class JackAudioIODeviceType : public AudioIODeviceType
  199202. {
  199203. public:
  199204. JackAudioIODeviceType()
  199205. : AudioIODeviceType (T("JACK")),
  199206. hasScanned (false)
  199207. {
  199208. }
  199209. ~JackAudioIODeviceType()
  199210. {
  199211. }
  199212. void scanForDevices()
  199213. {
  199214. hasScanned = true;
  199215. inputNames.clear();
  199216. inputIds.clear();
  199217. outputNames.clear();
  199218. outputIds.clear();
  199219. if (juce_libjack_handle == 0)
  199220. {
  199221. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199222. if (juce_libjack_handle == 0)
  199223. return;
  199224. }
  199225. // open a dummy client
  199226. jack_status_t status;
  199227. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199228. if (client == 0)
  199229. {
  199230. dumpJackErrorMessage (status);
  199231. }
  199232. else
  199233. {
  199234. // scan for output devices
  199235. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199236. if (ports != 0)
  199237. {
  199238. int j = 0;
  199239. while (ports[j] != 0)
  199240. {
  199241. String clientName (ports[j]);
  199242. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199243. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199244. && ! inputNames.contains (clientName))
  199245. {
  199246. inputNames.add (clientName);
  199247. inputIds.add (ports [j]);
  199248. }
  199249. ++j;
  199250. }
  199251. free (ports);
  199252. }
  199253. // scan for input devices
  199254. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199255. if (ports != 0)
  199256. {
  199257. int j = 0;
  199258. while (ports[j] != 0)
  199259. {
  199260. String clientName (ports[j]);
  199261. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199262. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199263. && ! outputNames.contains (clientName))
  199264. {
  199265. outputNames.add (clientName);
  199266. outputIds.add (ports [j]);
  199267. }
  199268. ++j;
  199269. }
  199270. free (ports);
  199271. }
  199272. JUCE_NAMESPACE::jack_client_close (client);
  199273. }
  199274. }
  199275. const StringArray getDeviceNames (const bool wantInputNames) const
  199276. {
  199277. jassert (hasScanned); // need to call scanForDevices() before doing this
  199278. return wantInputNames ? inputNames : outputNames;
  199279. }
  199280. int getDefaultDeviceIndex (const bool forInput) const
  199281. {
  199282. jassert (hasScanned); // need to call scanForDevices() before doing this
  199283. return 0;
  199284. }
  199285. bool hasSeparateInputsAndOutputs() const { return true; }
  199286. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199287. {
  199288. jassert (hasScanned); // need to call scanForDevices() before doing this
  199289. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199290. if (d == 0)
  199291. return -1;
  199292. return asInput ? inputIds.indexOf (d->inputId)
  199293. : outputIds.indexOf (d->outputId);
  199294. }
  199295. AudioIODevice* createDevice (const String& outputDeviceName,
  199296. const String& inputDeviceName)
  199297. {
  199298. jassert (hasScanned); // need to call scanForDevices() before doing this
  199299. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199300. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199301. if (inputIndex >= 0 || outputIndex >= 0)
  199302. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199303. : inputDeviceName,
  199304. inputIds [inputIndex],
  199305. outputIds [outputIndex]);
  199306. return 0;
  199307. }
  199308. juce_UseDebuggingNewOperator
  199309. private:
  199310. StringArray inputNames, outputNames, inputIds, outputIds;
  199311. bool hasScanned;
  199312. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199313. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199314. };
  199315. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199316. {
  199317. return new JackAudioIODeviceType();
  199318. }
  199319. #else // if JACK is turned off..
  199320. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199321. #endif
  199322. #endif
  199323. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199324. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199325. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199326. // compiled on its own).
  199327. #if JUCE_INCLUDED_FILE
  199328. #if JUCE_ALSA
  199329. static snd_seq_t* iterateDevices (const bool forInput,
  199330. StringArray& deviceNamesFound,
  199331. const int deviceIndexToOpen)
  199332. {
  199333. snd_seq_t* returnedHandle = 0;
  199334. snd_seq_t* seqHandle;
  199335. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199336. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199337. {
  199338. snd_seq_system_info_t* systemInfo;
  199339. snd_seq_client_info_t* clientInfo;
  199340. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199341. {
  199342. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199343. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199344. {
  199345. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199346. while (--numClients >= 0 && returnedHandle == 0)
  199347. {
  199348. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199349. {
  199350. snd_seq_port_info_t* portInfo;
  199351. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199352. {
  199353. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199354. const int client = snd_seq_client_info_get_client (clientInfo);
  199355. snd_seq_port_info_set_client (portInfo, client);
  199356. snd_seq_port_info_set_port (portInfo, -1);
  199357. while (--numPorts >= 0)
  199358. {
  199359. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199360. && (snd_seq_port_info_get_capability (portInfo)
  199361. & (forInput ? SND_SEQ_PORT_CAP_READ
  199362. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199363. {
  199364. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199365. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199366. {
  199367. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199368. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199369. if (sourcePort != -1)
  199370. {
  199371. snd_seq_set_client_name (seqHandle,
  199372. forInput ? "Juce Midi Input"
  199373. : "Juce Midi Output");
  199374. const int portId
  199375. = snd_seq_create_simple_port (seqHandle,
  199376. forInput ? "Juce Midi In Port"
  199377. : "Juce Midi Out Port",
  199378. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199379. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199380. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199381. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199382. returnedHandle = seqHandle;
  199383. }
  199384. }
  199385. }
  199386. }
  199387. snd_seq_port_info_free (portInfo);
  199388. }
  199389. }
  199390. }
  199391. snd_seq_client_info_free (clientInfo);
  199392. }
  199393. snd_seq_system_info_free (systemInfo);
  199394. }
  199395. if (returnedHandle == 0)
  199396. snd_seq_close (seqHandle);
  199397. }
  199398. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199399. return returnedHandle;
  199400. }
  199401. static snd_seq_t* createDevice (const bool forInput,
  199402. const String& deviceNameToOpen)
  199403. {
  199404. snd_seq_t* seqHandle = 0;
  199405. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199406. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199407. {
  199408. snd_seq_set_client_name (seqHandle,
  199409. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199410. const int portId
  199411. = snd_seq_create_simple_port (seqHandle,
  199412. forInput ? "in"
  199413. : "out",
  199414. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199415. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199416. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199417. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199418. if (portId < 0)
  199419. {
  199420. snd_seq_close (seqHandle);
  199421. seqHandle = 0;
  199422. }
  199423. }
  199424. return seqHandle;
  199425. }
  199426. class MidiOutputDevice
  199427. {
  199428. public:
  199429. MidiOutputDevice (MidiOutput* const midiOutput_,
  199430. snd_seq_t* const seqHandle_)
  199431. :
  199432. midiOutput (midiOutput_),
  199433. seqHandle (seqHandle_),
  199434. maxEventSize (16 * 1024)
  199435. {
  199436. jassert (seqHandle != 0 && midiOutput != 0);
  199437. snd_midi_event_new (maxEventSize, &midiParser);
  199438. }
  199439. ~MidiOutputDevice()
  199440. {
  199441. snd_midi_event_free (midiParser);
  199442. snd_seq_close (seqHandle);
  199443. }
  199444. void sendMessageNow (const MidiMessage& message)
  199445. {
  199446. if (message.getRawDataSize() > maxEventSize)
  199447. {
  199448. maxEventSize = message.getRawDataSize();
  199449. snd_midi_event_free (midiParser);
  199450. snd_midi_event_new (maxEventSize, &midiParser);
  199451. }
  199452. snd_seq_event_t event;
  199453. snd_seq_ev_clear (&event);
  199454. snd_midi_event_encode (midiParser,
  199455. message.getRawData(),
  199456. message.getRawDataSize(),
  199457. &event);
  199458. snd_midi_event_reset_encode (midiParser);
  199459. snd_seq_ev_set_source (&event, 0);
  199460. snd_seq_ev_set_subs (&event);
  199461. snd_seq_ev_set_direct (&event);
  199462. snd_seq_event_output (seqHandle, &event);
  199463. snd_seq_drain_output (seqHandle);
  199464. }
  199465. juce_UseDebuggingNewOperator
  199466. private:
  199467. MidiOutput* const midiOutput;
  199468. snd_seq_t* const seqHandle;
  199469. snd_midi_event_t* midiParser;
  199470. int maxEventSize;
  199471. };
  199472. const StringArray MidiOutput::getDevices()
  199473. {
  199474. StringArray devices;
  199475. iterateDevices (false, devices, -1);
  199476. return devices;
  199477. }
  199478. int MidiOutput::getDefaultDeviceIndex()
  199479. {
  199480. return 0;
  199481. }
  199482. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199483. {
  199484. MidiOutput* newDevice = 0;
  199485. StringArray devices;
  199486. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199487. if (handle != 0)
  199488. {
  199489. newDevice = new MidiOutput();
  199490. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199491. }
  199492. return newDevice;
  199493. }
  199494. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199495. {
  199496. MidiOutput* newDevice = 0;
  199497. snd_seq_t* const handle = createDevice (false, deviceName);
  199498. if (handle != 0)
  199499. {
  199500. newDevice = new MidiOutput();
  199501. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199502. }
  199503. return newDevice;
  199504. }
  199505. MidiOutput::~MidiOutput()
  199506. {
  199507. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199508. delete device;
  199509. }
  199510. void MidiOutput::reset()
  199511. {
  199512. }
  199513. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199514. {
  199515. return false;
  199516. }
  199517. void MidiOutput::setVolume (float leftVol, float rightVol)
  199518. {
  199519. }
  199520. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199521. {
  199522. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199523. }
  199524. class MidiInputThread : public Thread
  199525. {
  199526. public:
  199527. MidiInputThread (MidiInput* const midiInput_,
  199528. snd_seq_t* const seqHandle_,
  199529. MidiInputCallback* const callback_)
  199530. : Thread (T("Juce MIDI Input")),
  199531. midiInput (midiInput_),
  199532. seqHandle (seqHandle_),
  199533. callback (callback_)
  199534. {
  199535. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199536. }
  199537. ~MidiInputThread()
  199538. {
  199539. snd_seq_close (seqHandle);
  199540. }
  199541. void run()
  199542. {
  199543. const int maxEventSize = 16 * 1024;
  199544. snd_midi_event_t* midiParser;
  199545. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199546. {
  199547. HeapBlock <uint8> buffer (maxEventSize);
  199548. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199549. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199550. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199551. while (! threadShouldExit())
  199552. {
  199553. if (poll (pfd, numPfds, 500) > 0)
  199554. {
  199555. snd_seq_event_t* inputEvent = 0;
  199556. snd_seq_nonblock (seqHandle, 1);
  199557. do
  199558. {
  199559. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199560. {
  199561. // xxx what about SYSEXes that are too big for the buffer?
  199562. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199563. snd_midi_event_reset_decode (midiParser);
  199564. if (numBytes > 0)
  199565. {
  199566. const MidiMessage message ((const uint8*) buffer,
  199567. numBytes,
  199568. Time::getMillisecondCounter() * 0.001);
  199569. callback->handleIncomingMidiMessage (midiInput, message);
  199570. }
  199571. snd_seq_free_event (inputEvent);
  199572. }
  199573. }
  199574. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199575. snd_seq_free_event (inputEvent);
  199576. }
  199577. }
  199578. snd_midi_event_free (midiParser);
  199579. }
  199580. };
  199581. juce_UseDebuggingNewOperator
  199582. private:
  199583. MidiInput* const midiInput;
  199584. snd_seq_t* const seqHandle;
  199585. MidiInputCallback* const callback;
  199586. };
  199587. MidiInput::MidiInput (const String& name_)
  199588. : name (name_),
  199589. internal (0)
  199590. {
  199591. }
  199592. MidiInput::~MidiInput()
  199593. {
  199594. stop();
  199595. MidiInputThread* const thread = (MidiInputThread*) internal;
  199596. delete thread;
  199597. }
  199598. void MidiInput::start()
  199599. {
  199600. ((MidiInputThread*) internal)->startThread();
  199601. }
  199602. void MidiInput::stop()
  199603. {
  199604. ((MidiInputThread*) internal)->stopThread (3000);
  199605. }
  199606. int MidiInput::getDefaultDeviceIndex()
  199607. {
  199608. return 0;
  199609. }
  199610. const StringArray MidiInput::getDevices()
  199611. {
  199612. StringArray devices;
  199613. iterateDevices (true, devices, -1);
  199614. return devices;
  199615. }
  199616. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199617. {
  199618. MidiInput* newDevice = 0;
  199619. StringArray devices;
  199620. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199621. if (handle != 0)
  199622. {
  199623. newDevice = new MidiInput (devices [deviceIndex]);
  199624. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199625. }
  199626. return newDevice;
  199627. }
  199628. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199629. {
  199630. MidiInput* newDevice = 0;
  199631. snd_seq_t* const handle = createDevice (true, deviceName);
  199632. if (handle != 0)
  199633. {
  199634. newDevice = new MidiInput (deviceName);
  199635. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199636. }
  199637. return newDevice;
  199638. }
  199639. #else
  199640. // (These are just stub functions if ALSA is unavailable...)
  199641. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199642. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199643. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199644. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199645. MidiOutput::~MidiOutput() {}
  199646. void MidiOutput::reset() {}
  199647. bool MidiOutput::getVolume (float&, float&) { return false; }
  199648. void MidiOutput::setVolume (float, float) {}
  199649. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199650. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199651. MidiInput::~MidiInput() {}
  199652. void MidiInput::start() {}
  199653. void MidiInput::stop() {}
  199654. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199655. const StringArray MidiInput::getDevices() { return StringArray(); }
  199656. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199657. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199658. #endif
  199659. #endif
  199660. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199661. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199662. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199663. // compiled on its own).
  199664. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199665. AudioCDReader::AudioCDReader()
  199666. : AudioFormatReader (0, T("CD Audio"))
  199667. {
  199668. }
  199669. const StringArray AudioCDReader::getAvailableCDNames()
  199670. {
  199671. StringArray names;
  199672. return names;
  199673. }
  199674. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199675. {
  199676. return 0;
  199677. }
  199678. AudioCDReader::~AudioCDReader()
  199679. {
  199680. }
  199681. void AudioCDReader::refreshTrackLengths()
  199682. {
  199683. }
  199684. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199685. int64 startSampleInFile, int numSamples)
  199686. {
  199687. return false;
  199688. }
  199689. bool AudioCDReader::isCDStillPresent() const
  199690. {
  199691. return false;
  199692. }
  199693. int AudioCDReader::getNumTracks() const
  199694. {
  199695. return 0;
  199696. }
  199697. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199698. {
  199699. return 0;
  199700. }
  199701. bool AudioCDReader::isTrackAudio (int trackNum) const
  199702. {
  199703. return false;
  199704. }
  199705. void AudioCDReader::enableIndexScanning (bool b)
  199706. {
  199707. }
  199708. int AudioCDReader::getLastIndex() const
  199709. {
  199710. return 0;
  199711. }
  199712. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199713. {
  199714. return Array<int>();
  199715. }
  199716. int AudioCDReader::getCDDBId()
  199717. {
  199718. return 0;
  199719. }
  199720. #endif
  199721. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199722. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199723. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199724. // compiled on its own).
  199725. #if JUCE_INCLUDED_FILE
  199726. void FileChooser::showPlatformDialog (Array<File>& results,
  199727. const String& title,
  199728. const File& file,
  199729. const String& filters,
  199730. bool isDirectory,
  199731. bool selectsFiles,
  199732. bool isSave,
  199733. bool warnAboutOverwritingExistingFiles,
  199734. bool selectMultipleFiles,
  199735. FilePreviewComponent* previewComponent)
  199736. {
  199737. const tchar* const separator = T(":");
  199738. String command ("zenity --file-selection");
  199739. if (title.isNotEmpty())
  199740. command << " --title=\"" << title << "\"";
  199741. if (file != File::nonexistent)
  199742. command << " --filename=\"" << file.getFullPathName () << "\"";
  199743. if (isDirectory)
  199744. command << " --directory";
  199745. if (isSave)
  199746. command << " --save";
  199747. if (selectMultipleFiles)
  199748. command << " --multiple --separator=\"" << separator << "\"";
  199749. command << " 2>&1";
  199750. MemoryOutputStream result;
  199751. int status = -1;
  199752. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  199753. if (stream != 0)
  199754. {
  199755. for (;;)
  199756. {
  199757. char buffer [1024];
  199758. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199759. if (bytesRead <= 0)
  199760. break;
  199761. result.write (buffer, bytesRead);
  199762. }
  199763. status = pclose (stream);
  199764. }
  199765. if (status == 0)
  199766. {
  199767. String resultString (String::fromUTF8 ((const char*) result.getData(), result.getDataSize()));
  199768. StringArray tokens;
  199769. if (selectMultipleFiles)
  199770. tokens.addTokens (resultString, separator, 0);
  199771. else
  199772. tokens.add (resultString);
  199773. for (int i = 0; i < tokens.size(); i++)
  199774. results.add (File (tokens[i]));
  199775. return;
  199776. }
  199777. //xxx ain't got one!
  199778. jassertfalse
  199779. }
  199780. #endif
  199781. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199782. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199783. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199784. // compiled on its own).
  199785. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199786. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199787. : browser (0),
  199788. blankPageShown (false),
  199789. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199790. {
  199791. setOpaque (true);
  199792. }
  199793. WebBrowserComponent::~WebBrowserComponent()
  199794. {
  199795. }
  199796. void WebBrowserComponent::goToURL (const String& url,
  199797. const StringArray* headers,
  199798. const MemoryBlock* postData)
  199799. {
  199800. lastURL = url;
  199801. lastHeaders.clear();
  199802. if (headers != 0)
  199803. lastHeaders = *headers;
  199804. lastPostData.setSize (0);
  199805. if (postData != 0)
  199806. lastPostData = *postData;
  199807. blankPageShown = false;
  199808. }
  199809. void WebBrowserComponent::stop()
  199810. {
  199811. }
  199812. void WebBrowserComponent::goBack()
  199813. {
  199814. lastURL = String::empty;
  199815. blankPageShown = false;
  199816. }
  199817. void WebBrowserComponent::goForward()
  199818. {
  199819. lastURL = String::empty;
  199820. }
  199821. void WebBrowserComponent::refresh()
  199822. {
  199823. }
  199824. void WebBrowserComponent::paint (Graphics& g)
  199825. {
  199826. g.fillAll (Colours::white);
  199827. }
  199828. void WebBrowserComponent::checkWindowAssociation()
  199829. {
  199830. }
  199831. void WebBrowserComponent::reloadLastURL()
  199832. {
  199833. if (lastURL.isNotEmpty())
  199834. {
  199835. goToURL (lastURL, &lastHeaders, &lastPostData);
  199836. lastURL = String::empty;
  199837. }
  199838. }
  199839. void WebBrowserComponent::parentHierarchyChanged()
  199840. {
  199841. checkWindowAssociation();
  199842. }
  199843. void WebBrowserComponent::resized()
  199844. {
  199845. }
  199846. void WebBrowserComponent::visibilityChanged()
  199847. {
  199848. checkWindowAssociation();
  199849. }
  199850. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199851. {
  199852. return true;
  199853. }
  199854. #endif
  199855. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199856. #endif
  199857. END_JUCE_NAMESPACE
  199858. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199859. #endif
  199860. #if JUCE_MAC || JUCE_IPHONE
  199861. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199862. BEGIN_JUCE_NAMESPACE
  199863. #undef Point
  199864. #define JUCE_INCLUDED_FILE 1
  199865. // Now include the actual code files..
  199866. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199867. #ifndef JUCE_ObjCExtraSuffix
  199868. #define JUCE_ObjCExtraSuffix 3
  199869. #endif
  199870. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199871. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199872. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199873. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199874. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199875. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199876. // compiled on its own).
  199877. #if JUCE_INCLUDED_FILE
  199878. static const String nsStringToJuce (NSString* s)
  199879. {
  199880. return String::fromUTF8 ([s UTF8String]);
  199881. }
  199882. static NSString* juceStringToNS (const String& s)
  199883. {
  199884. return [NSString stringWithUTF8String: s.toUTF8()];
  199885. }
  199886. static const String convertUTF16ToString (const UniChar* utf16)
  199887. {
  199888. String s;
  199889. while (*utf16 != 0)
  199890. s += (juce_wchar) *utf16++;
  199891. return s;
  199892. }
  199893. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199894. {
  199895. String result;
  199896. if (cfString != 0)
  199897. {
  199898. CFRange range = { 0, CFStringGetLength (cfString) };
  199899. HeapBlock <UniChar> u (range.length + 1);
  199900. CFStringGetCharacters (cfString, range, u);
  199901. u[range.length] = 0;
  199902. result = convertUTF16ToString (u);
  199903. }
  199904. return result;
  199905. }
  199906. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199907. {
  199908. const int len = s.length();
  199909. const juce_wchar* t = (const juce_wchar*) s;
  199910. HeapBlock <UniChar> temp (len + 2);
  199911. for (int i = 0; i <= len; ++i)
  199912. temp[i] = t[i];
  199913. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199914. }
  199915. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199916. {
  199917. #if JUCE_IPHONE
  199918. const ScopedAutoReleasePool pool;
  199919. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199920. #else
  199921. UnicodeMapping map;
  199922. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199923. kUnicodeNoSubset,
  199924. kTextEncodingDefaultFormat);
  199925. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199926. kUnicodeCanonicalCompVariant,
  199927. kTextEncodingDefaultFormat);
  199928. map.mappingVersion = kUnicodeUseLatestMapping;
  199929. UnicodeToTextInfo conversionInfo = 0;
  199930. String result;
  199931. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199932. {
  199933. const int len = s.length();
  199934. HeapBlock <UniChar> tempIn, tempOut;
  199935. tempIn.calloc (len + 2);
  199936. tempOut.calloc (len + 2);
  199937. for (int i = 0; i <= len; ++i)
  199938. tempIn[i] = s[i];
  199939. ByteCount bytesRead = 0;
  199940. ByteCount outputBufferSize = 0;
  199941. if (ConvertFromUnicodeToText (conversionInfo,
  199942. len * sizeof (UniChar), tempIn,
  199943. kUnicodeDefaultDirectionMask,
  199944. 0, 0, 0, 0,
  199945. len * sizeof (UniChar), &bytesRead,
  199946. &outputBufferSize, tempOut) == noErr)
  199947. {
  199948. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199949. tchar* t = const_cast <tchar*> ((const tchar*) result);
  199950. unsigned int i;
  199951. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199952. t[i] = (tchar) tempOut[i];
  199953. t[i] = 0;
  199954. }
  199955. DisposeUnicodeToTextInfo (&conversionInfo);
  199956. }
  199957. return result;
  199958. #endif
  199959. }
  199960. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199961. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  199962. {
  199963. #if JUCE_IPHONE
  199964. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199965. forPasteboardType: @"public.text"];
  199966. #else
  199967. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199968. owner: nil];
  199969. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199970. forType: NSStringPboardType];
  199971. #endif
  199972. }
  199973. const String SystemClipboard::getTextFromClipboard() throw()
  199974. {
  199975. #if JUCE_IPHONE
  199976. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199977. #else
  199978. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199979. #endif
  199980. return text == 0 ? String::empty
  199981. : nsStringToJuce (text);
  199982. }
  199983. #endif
  199984. #endif
  199985. /*** End of inlined file: juce_mac_Strings.mm ***/
  199986. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199987. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199988. // compiled on its own).
  199989. #if JUCE_INCLUDED_FILE
  199990. static int64 highResTimerFrequency = 0;
  199991. static double highResTimerToMillisecRatio = 0;
  199992. #if JUCE_INTEL
  199993. static void juce_getCpuVendor (char* const v) throw()
  199994. {
  199995. int vendor[4];
  199996. zerostruct (vendor);
  199997. int dummy = 0;
  199998. asm ("mov %%ebx, %%esi \n\t"
  199999. "cpuid \n\t"
  200000. "xchg %%esi, %%ebx"
  200001. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  200002. memcpy (v, vendor, 16);
  200003. }
  200004. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  200005. {
  200006. unsigned int cpu = 0;
  200007. unsigned int ext = 0;
  200008. unsigned int family = 0;
  200009. unsigned int dummy = 0;
  200010. asm ("mov %%ebx, %%esi \n\t"
  200011. "cpuid \n\t"
  200012. "xchg %%esi, %%ebx"
  200013. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  200014. familyModel = family;
  200015. extFeatures = ext;
  200016. return cpu;
  200017. }
  200018. struct CPUFlags
  200019. {
  200020. bool hasMMX : 1;
  200021. bool hasSSE : 1;
  200022. bool hasSSE2 : 1;
  200023. bool has3DNow : 1;
  200024. };
  200025. static CPUFlags cpuFlags;
  200026. #endif
  200027. void SystemStats::initialiseStats() throw()
  200028. {
  200029. static bool initialised = false;
  200030. if (! initialised)
  200031. {
  200032. initialised = true;
  200033. #if JUCE_MAC
  200034. // extremely annoying: adding this line stops the apple menu items from working. Of
  200035. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  200036. // any events.
  200037. //NSApplicationLoad();
  200038. [NSApplication sharedApplication];
  200039. #endif
  200040. #if JUCE_INTEL
  200041. {
  200042. unsigned int familyModel, extFeatures;
  200043. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  200044. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  200045. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  200046. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  200047. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  200048. }
  200049. #endif
  200050. mach_timebase_info_data_t timebase;
  200051. (void) mach_timebase_info (&timebase);
  200052. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  200053. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  200054. String s (SystemStats::getJUCEVersion());
  200055. rlimit lim;
  200056. getrlimit (RLIMIT_NOFILE, &lim);
  200057. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  200058. setrlimit (RLIMIT_NOFILE, &lim);
  200059. }
  200060. }
  200061. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  200062. {
  200063. return MacOSX;
  200064. }
  200065. const String SystemStats::getOperatingSystemName() throw()
  200066. {
  200067. return T("Mac OS X");
  200068. }
  200069. bool SystemStats::isOperatingSystem64Bit() throw()
  200070. {
  200071. #if JUCE_64BIT
  200072. return true;
  200073. #else
  200074. //xxx not sure how to find this out?..
  200075. return false;
  200076. #endif
  200077. }
  200078. int SystemStats::getMemorySizeInMegabytes() throw()
  200079. {
  200080. uint64 mem = 0;
  200081. size_t memSize = sizeof (mem);
  200082. int mib[] = { CTL_HW, HW_MEMSIZE };
  200083. sysctl (mib, 2, &mem, &memSize, 0, 0);
  200084. return (int) (mem / (1024 * 1024));
  200085. }
  200086. bool SystemStats::hasMMX() throw()
  200087. {
  200088. #if JUCE_INTEL
  200089. return cpuFlags.hasMMX;
  200090. #else
  200091. return false;
  200092. #endif
  200093. }
  200094. bool SystemStats::hasSSE() throw()
  200095. {
  200096. #if JUCE_INTEL
  200097. return cpuFlags.hasSSE;
  200098. #else
  200099. return false;
  200100. #endif
  200101. }
  200102. bool SystemStats::hasSSE2() throw()
  200103. {
  200104. #if JUCE_INTEL
  200105. return cpuFlags.hasSSE2;
  200106. #else
  200107. return false;
  200108. #endif
  200109. }
  200110. bool SystemStats::has3DNow() throw()
  200111. {
  200112. #if JUCE_INTEL
  200113. return cpuFlags.has3DNow;
  200114. #else
  200115. return false;
  200116. #endif
  200117. }
  200118. const String SystemStats::getCpuVendor() throw()
  200119. {
  200120. #if JUCE_INTEL
  200121. char v [16];
  200122. juce_getCpuVendor (v);
  200123. return String (v, 16);
  200124. #else
  200125. return String::empty;
  200126. #endif
  200127. }
  200128. int SystemStats::getCpuSpeedInMegaherz() throw()
  200129. {
  200130. uint64 speedHz = 0;
  200131. size_t speedSize = sizeof (speedHz);
  200132. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200133. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200134. #if JUCE_BIG_ENDIAN
  200135. if (speedSize == 4)
  200136. speedHz >>= 32;
  200137. #endif
  200138. return (int) (speedHz / 1000000);
  200139. }
  200140. int SystemStats::getNumCpus() throw()
  200141. {
  200142. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200143. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200144. #else
  200145. return MPProcessors();
  200146. #endif
  200147. }
  200148. const String SystemStats::getLogonName()
  200149. {
  200150. return nsStringToJuce (NSUserName());
  200151. }
  200152. const String SystemStats::getFullUserName()
  200153. {
  200154. return nsStringToJuce (NSFullUserName());
  200155. }
  200156. uint32 juce_millisecondsSinceStartup() throw()
  200157. {
  200158. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  200159. }
  200160. double Time::getMillisecondCounterHiRes() throw()
  200161. {
  200162. return mach_absolute_time() * highResTimerToMillisecRatio;
  200163. }
  200164. int64 Time::getHighResolutionTicks() throw()
  200165. {
  200166. return (int64) mach_absolute_time();
  200167. }
  200168. int64 Time::getHighResolutionTicksPerSecond() throw()
  200169. {
  200170. return highResTimerFrequency;
  200171. }
  200172. int64 SystemStats::getClockCycleCounter() throw()
  200173. {
  200174. return (int64) mach_absolute_time();
  200175. }
  200176. bool Time::setSystemTimeToThisTime() const throw()
  200177. {
  200178. jassertfalse
  200179. return false;
  200180. }
  200181. int SystemStats::getPageSize() throw()
  200182. {
  200183. return (int) NSPageSize();
  200184. }
  200185. void PlatformUtilities::fpuReset()
  200186. {
  200187. }
  200188. #endif
  200189. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200190. /*** Start of inlined file: juce_mac_Network.mm ***/
  200191. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200192. // compiled on its own).
  200193. #if JUCE_INCLUDED_FILE
  200194. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  200195. {
  200196. #ifndef IFT_ETHER
  200197. #define IFT_ETHER 6
  200198. #endif
  200199. ifaddrs* addrs = 0;
  200200. int numResults = 0;
  200201. if (getifaddrs (&addrs) == 0)
  200202. {
  200203. const ifaddrs* cursor = addrs;
  200204. while (cursor != 0 && numResults < maxNum)
  200205. {
  200206. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200207. if (sto->ss_family == AF_LINK)
  200208. {
  200209. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200210. if (sadd->sdl_type == IFT_ETHER)
  200211. {
  200212. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200213. uint64 a = 0;
  200214. for (int i = 6; --i >= 0;)
  200215. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200216. *addresses++ = (int64) a;
  200217. ++numResults;
  200218. }
  200219. }
  200220. cursor = cursor->ifa_next;
  200221. }
  200222. freeifaddrs (addrs);
  200223. }
  200224. return numResults;
  200225. }
  200226. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200227. const String& emailSubject,
  200228. const String& bodyText,
  200229. const StringArray& filesToAttach)
  200230. {
  200231. #if JUCE_IPHONE
  200232. //xxx probably need to use MFMailComposeViewController
  200233. jassertfalse
  200234. return false;
  200235. #else
  200236. const ScopedAutoReleasePool pool;
  200237. String script;
  200238. script << "tell application \"Mail\"\r\n"
  200239. "set newMessage to make new outgoing message with properties {subject:\""
  200240. << emailSubject.replace (T("\""), T("\\\""))
  200241. << "\", content:\""
  200242. << bodyText.replace (T("\""), T("\\\""))
  200243. << "\" & return & return}\r\n"
  200244. "tell newMessage\r\n"
  200245. "set visible to true\r\n"
  200246. "set sender to \"sdfsdfsdfewf\"\r\n"
  200247. "make new to recipient at end of to recipients with properties {address:\""
  200248. << targetEmailAddress
  200249. << "\"}\r\n";
  200250. for (int i = 0; i < filesToAttach.size(); ++i)
  200251. {
  200252. script << "tell content\r\n"
  200253. "make new attachment with properties {file name:\""
  200254. << filesToAttach[i].replace (T("\""), T("\\\""))
  200255. << "\"} at after the last paragraph\r\n"
  200256. "end tell\r\n";
  200257. }
  200258. script << "end tell\r\n"
  200259. "end tell\r\n";
  200260. NSAppleScript* s = [[NSAppleScript alloc]
  200261. initWithSource: juceStringToNS (script)];
  200262. NSDictionary* error = 0;
  200263. const bool ok = [s executeAndReturnError: &error] != nil;
  200264. [s release];
  200265. return ok;
  200266. #endif
  200267. }
  200268. END_JUCE_NAMESPACE
  200269. using namespace JUCE_NAMESPACE;
  200270. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200271. @interface JuceURLConnection : NSObject
  200272. {
  200273. @public
  200274. NSURLRequest* request;
  200275. NSURLConnection* connection;
  200276. NSMutableData* data;
  200277. Thread* runLoopThread;
  200278. bool initialised, hasFailed, hasFinished;
  200279. int position;
  200280. int64 contentLength;
  200281. NSLock* dataLock;
  200282. }
  200283. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200284. - (void) dealloc;
  200285. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200286. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200287. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200288. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200289. - (BOOL) isOpen;
  200290. - (int) read: (char*) dest numBytes: (int) num;
  200291. - (int) readPosition;
  200292. - (void) stop;
  200293. - (void) createConnection;
  200294. @end
  200295. class JuceURLConnectionMessageThread : public Thread
  200296. {
  200297. JuceURLConnection* owner;
  200298. public:
  200299. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200300. : Thread (T("http connection")),
  200301. owner (owner_)
  200302. {
  200303. }
  200304. ~JuceURLConnectionMessageThread()
  200305. {
  200306. stopThread (10000);
  200307. }
  200308. void run()
  200309. {
  200310. [owner createConnection];
  200311. while (! threadShouldExit())
  200312. {
  200313. const ScopedAutoReleasePool pool;
  200314. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200315. }
  200316. }
  200317. };
  200318. @implementation JuceURLConnection
  200319. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200320. withCallback: (URL::OpenStreamProgressCallback*) callback
  200321. withContext: (void*) context;
  200322. {
  200323. [super init];
  200324. request = req;
  200325. [request retain];
  200326. data = [[NSMutableData data] retain];
  200327. dataLock = [[NSLock alloc] init];
  200328. connection = 0;
  200329. initialised = false;
  200330. hasFailed = false;
  200331. hasFinished = false;
  200332. contentLength = -1;
  200333. runLoopThread = new JuceURLConnectionMessageThread (self);
  200334. runLoopThread->startThread();
  200335. while (runLoopThread->isThreadRunning() && ! initialised)
  200336. {
  200337. if (callback != 0)
  200338. callback (context, -1, (int) [[request HTTPBody] length]);
  200339. Thread::sleep (1);
  200340. }
  200341. return self;
  200342. }
  200343. - (void) dealloc
  200344. {
  200345. [self stop];
  200346. delete runLoopThread;
  200347. [connection release];
  200348. [data release];
  200349. [dataLock release];
  200350. [request release];
  200351. [super dealloc];
  200352. }
  200353. - (void) createConnection
  200354. {
  200355. connection = [[NSURLConnection alloc] initWithRequest: request
  200356. delegate: [self retain]];
  200357. if (connection == nil)
  200358. runLoopThread->signalThreadShouldExit();
  200359. }
  200360. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200361. {
  200362. [dataLock lock];
  200363. [data setLength: 0];
  200364. [dataLock unlock];
  200365. initialised = true;
  200366. contentLength = [response expectedContentLength];
  200367. }
  200368. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200369. {
  200370. DBG (nsStringToJuce ([error description]));
  200371. hasFailed = true;
  200372. initialised = true;
  200373. runLoopThread->signalThreadShouldExit();
  200374. }
  200375. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200376. {
  200377. [dataLock lock];
  200378. [data appendData: newData];
  200379. [dataLock unlock];
  200380. initialised = true;
  200381. }
  200382. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200383. {
  200384. hasFinished = true;
  200385. initialised = true;
  200386. runLoopThread->signalThreadShouldExit();
  200387. }
  200388. - (BOOL) isOpen
  200389. {
  200390. return connection != 0 && ! hasFailed;
  200391. }
  200392. - (int) readPosition
  200393. {
  200394. return position;
  200395. }
  200396. - (int) read: (char*) dest numBytes: (int) numNeeded
  200397. {
  200398. int numDone = 0;
  200399. while (numNeeded > 0)
  200400. {
  200401. int available = jmin (numNeeded, (int) [data length]);
  200402. if (available > 0)
  200403. {
  200404. [dataLock lock];
  200405. [data getBytes: dest length: available];
  200406. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200407. [dataLock unlock];
  200408. numDone += available;
  200409. numNeeded -= available;
  200410. dest += available;
  200411. }
  200412. else
  200413. {
  200414. if (hasFailed || hasFinished)
  200415. break;
  200416. Thread::sleep (1);
  200417. }
  200418. }
  200419. position += numDone;
  200420. return numDone;
  200421. }
  200422. - (void) stop
  200423. {
  200424. [connection cancel];
  200425. runLoopThread->stopThread (10000);
  200426. }
  200427. @end
  200428. BEGIN_JUCE_NAMESPACE
  200429. bool juce_isOnLine()
  200430. {
  200431. return true;
  200432. }
  200433. void* juce_openInternetFile (const String& url,
  200434. const String& headers,
  200435. const MemoryBlock& postData,
  200436. const bool isPost,
  200437. URL::OpenStreamProgressCallback* callback,
  200438. void* callbackContext,
  200439. int timeOutMs)
  200440. {
  200441. const ScopedAutoReleasePool pool;
  200442. NSMutableURLRequest* req = [NSMutableURLRequest
  200443. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200444. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200445. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200446. if (req == nil)
  200447. return 0;
  200448. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200449. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200450. StringArray headerLines;
  200451. headerLines.addLines (headers);
  200452. headerLines.removeEmptyStrings (true);
  200453. for (int i = 0; i < headerLines.size(); ++i)
  200454. {
  200455. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200456. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200457. if (key.isNotEmpty() && value.isNotEmpty())
  200458. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200459. }
  200460. if (isPost && postData.getSize() > 0)
  200461. {
  200462. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200463. length: postData.getSize()]];
  200464. }
  200465. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200466. withCallback: callback
  200467. withContext: callbackContext];
  200468. if ([s isOpen])
  200469. return s;
  200470. [s release];
  200471. return 0;
  200472. }
  200473. void juce_closeInternetFile (void* handle)
  200474. {
  200475. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200476. if (s != 0)
  200477. {
  200478. const ScopedAutoReleasePool pool;
  200479. [s stop];
  200480. [s release];
  200481. }
  200482. }
  200483. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200484. {
  200485. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200486. if (s != 0)
  200487. {
  200488. const ScopedAutoReleasePool pool;
  200489. return [s read: (char*) buffer numBytes: bytesToRead];
  200490. }
  200491. return 0;
  200492. }
  200493. int64 juce_getInternetFileContentLength (void* handle)
  200494. {
  200495. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200496. if (s != 0)
  200497. return s->contentLength;
  200498. return -1;
  200499. }
  200500. int juce_seekInInternetFile (void* handle, int newPosition)
  200501. {
  200502. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200503. if (s != 0)
  200504. return [s readPosition];
  200505. return 0;
  200506. }
  200507. #endif
  200508. /*** End of inlined file: juce_mac_Network.mm ***/
  200509. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200510. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200511. // compiled on its own).
  200512. #if JUCE_INCLUDED_FILE
  200513. struct NamedPipeInternal
  200514. {
  200515. String pipeInName, pipeOutName;
  200516. int pipeIn, pipeOut;
  200517. bool volatile createdPipe, blocked, stopReadOperation;
  200518. static void signalHandler (int) {}
  200519. };
  200520. void NamedPipe::cancelPendingReads()
  200521. {
  200522. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200523. {
  200524. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200525. intern->stopReadOperation = true;
  200526. char buffer [1] = { 0 };
  200527. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200528. (void) bytesWritten;
  200529. int timeout = 2000;
  200530. while (intern->blocked && --timeout >= 0)
  200531. Thread::sleep (2);
  200532. intern->stopReadOperation = false;
  200533. }
  200534. }
  200535. void NamedPipe::close()
  200536. {
  200537. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200538. if (intern != 0)
  200539. {
  200540. internal = 0;
  200541. if (intern->pipeIn != -1)
  200542. ::close (intern->pipeIn);
  200543. if (intern->pipeOut != -1)
  200544. ::close (intern->pipeOut);
  200545. if (intern->createdPipe)
  200546. {
  200547. unlink (intern->pipeInName.toUTF8());
  200548. unlink (intern->pipeOutName.toUTF8());
  200549. }
  200550. delete intern;
  200551. }
  200552. }
  200553. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200554. {
  200555. close();
  200556. NamedPipeInternal* const intern = new NamedPipeInternal();
  200557. internal = intern;
  200558. intern->createdPipe = createPipe;
  200559. intern->blocked = false;
  200560. intern->stopReadOperation = false;
  200561. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200562. siginterrupt (SIGPIPE, 1);
  200563. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200564. intern->pipeInName = pipePath + T("_in");
  200565. intern->pipeOutName = pipePath + T("_out");
  200566. intern->pipeIn = -1;
  200567. intern->pipeOut = -1;
  200568. if (createPipe)
  200569. {
  200570. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200571. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200572. {
  200573. delete intern;
  200574. internal = 0;
  200575. return false;
  200576. }
  200577. }
  200578. return true;
  200579. }
  200580. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200581. {
  200582. int bytesRead = -1;
  200583. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200584. if (intern != 0)
  200585. {
  200586. intern->blocked = true;
  200587. if (intern->pipeIn == -1)
  200588. {
  200589. if (intern->createdPipe)
  200590. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200591. else
  200592. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200593. if (intern->pipeIn == -1)
  200594. {
  200595. intern->blocked = false;
  200596. return -1;
  200597. }
  200598. }
  200599. bytesRead = 0;
  200600. char* p = (char*) destBuffer;
  200601. while (bytesRead < maxBytesToRead)
  200602. {
  200603. const int bytesThisTime = maxBytesToRead - bytesRead;
  200604. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200605. if (numRead <= 0 || intern->stopReadOperation)
  200606. {
  200607. bytesRead = -1;
  200608. break;
  200609. }
  200610. bytesRead += numRead;
  200611. p += bytesRead;
  200612. }
  200613. intern->blocked = false;
  200614. }
  200615. return bytesRead;
  200616. }
  200617. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200618. {
  200619. int bytesWritten = -1;
  200620. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200621. if (intern != 0)
  200622. {
  200623. if (intern->pipeOut == -1)
  200624. {
  200625. if (intern->createdPipe)
  200626. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200627. else
  200628. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200629. if (intern->pipeOut == -1)
  200630. {
  200631. return -1;
  200632. }
  200633. }
  200634. const char* p = (const char*) sourceBuffer;
  200635. bytesWritten = 0;
  200636. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200637. while (bytesWritten < numBytesToWrite
  200638. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200639. {
  200640. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200641. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200642. if (numWritten <= 0)
  200643. {
  200644. bytesWritten = -1;
  200645. break;
  200646. }
  200647. bytesWritten += numWritten;
  200648. p += bytesWritten;
  200649. }
  200650. }
  200651. return bytesWritten;
  200652. }
  200653. #endif
  200654. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200655. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200656. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200657. // compiled on its own).
  200658. #if JUCE_INCLUDED_FILE
  200659. void JUCE_API juce_threadEntryPoint (void*);
  200660. void* threadEntryProc (void* userData)
  200661. {
  200662. const ScopedAutoReleasePool pool;
  200663. juce_threadEntryPoint (userData);
  200664. return 0;
  200665. }
  200666. void* juce_createThread (void* userData)
  200667. {
  200668. pthread_t handle = 0;
  200669. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200670. {
  200671. pthread_detach (handle);
  200672. return (void*) handle;
  200673. }
  200674. return 0;
  200675. }
  200676. void juce_killThread (void* handle)
  200677. {
  200678. if (handle != 0)
  200679. pthread_cancel ((pthread_t) handle);
  200680. }
  200681. void juce_setCurrentThreadName (const String& /*name*/)
  200682. {
  200683. }
  200684. Thread::ThreadID Thread::getCurrentThreadId()
  200685. {
  200686. return (ThreadID) pthread_self();
  200687. }
  200688. bool juce_setThreadPriority (void* handle, int priority)
  200689. {
  200690. if (handle == 0)
  200691. handle = (void*) pthread_self();
  200692. struct sched_param param;
  200693. int policy;
  200694. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200695. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200696. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200697. }
  200698. void Thread::yield()
  200699. {
  200700. sched_yield();
  200701. }
  200702. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200703. {
  200704. // xxx
  200705. jassertfalse
  200706. }
  200707. bool Process::isForegroundProcess()
  200708. {
  200709. #if JUCE_MAC
  200710. return [NSApp isActive];
  200711. #else
  200712. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200713. #endif
  200714. }
  200715. void Process::raisePrivilege()
  200716. {
  200717. jassertfalse
  200718. }
  200719. void Process::lowerPrivilege()
  200720. {
  200721. jassertfalse
  200722. }
  200723. void Process::terminate()
  200724. {
  200725. exit (0);
  200726. }
  200727. void Process::setPriority (ProcessPriority p)
  200728. {
  200729. // xxx
  200730. }
  200731. #endif
  200732. /*** End of inlined file: juce_mac_Threads.mm ***/
  200733. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200734. CriticalSection::CriticalSection() throw()
  200735. {
  200736. pthread_mutexattr_t atts;
  200737. pthread_mutexattr_init (&atts);
  200738. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200739. pthread_mutex_init (&internal, &atts);
  200740. }
  200741. CriticalSection::~CriticalSection() throw()
  200742. {
  200743. pthread_mutex_destroy (&internal);
  200744. }
  200745. void CriticalSection::enter() const throw()
  200746. {
  200747. pthread_mutex_lock (&internal);
  200748. }
  200749. bool CriticalSection::tryEnter() const throw()
  200750. {
  200751. return pthread_mutex_trylock (&internal) == 0;
  200752. }
  200753. void CriticalSection::exit() const throw()
  200754. {
  200755. pthread_mutex_unlock (&internal);
  200756. }
  200757. struct EventStruct
  200758. {
  200759. pthread_cond_t condition;
  200760. pthread_mutex_t mutex;
  200761. bool triggered;
  200762. };
  200763. WaitableEvent::WaitableEvent() throw()
  200764. {
  200765. EventStruct* const es = new EventStruct();
  200766. es->triggered = false;
  200767. pthread_cond_init (&es->condition, 0);
  200768. pthread_mutex_init (&es->mutex, 0);
  200769. internal = es;
  200770. }
  200771. WaitableEvent::~WaitableEvent() throw()
  200772. {
  200773. EventStruct* const es = (EventStruct*) internal;
  200774. pthread_cond_destroy (&es->condition);
  200775. pthread_mutex_destroy (&es->mutex);
  200776. delete es;
  200777. }
  200778. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200779. {
  200780. EventStruct* const es = (EventStruct*) internal;
  200781. pthread_mutex_lock (&es->mutex);
  200782. if (timeOutMillisecs < 0)
  200783. {
  200784. while (! es->triggered)
  200785. pthread_cond_wait (&es->condition, &es->mutex);
  200786. }
  200787. else
  200788. {
  200789. while (! es->triggered)
  200790. {
  200791. struct timeval t;
  200792. gettimeofday (&t, 0);
  200793. struct timespec time;
  200794. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  200795. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200796. if (time.tv_nsec >= 1000000000)
  200797. {
  200798. time.tv_nsec -= 1000000000;
  200799. time.tv_sec++;
  200800. }
  200801. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  200802. {
  200803. pthread_mutex_unlock (&es->mutex);
  200804. return false;
  200805. }
  200806. }
  200807. }
  200808. es->triggered = false;
  200809. pthread_mutex_unlock (&es->mutex);
  200810. return true;
  200811. }
  200812. void WaitableEvent::signal() const throw()
  200813. {
  200814. EventStruct* const es = (EventStruct*) internal;
  200815. pthread_mutex_lock (&es->mutex);
  200816. es->triggered = true;
  200817. pthread_cond_broadcast (&es->condition);
  200818. pthread_mutex_unlock (&es->mutex);
  200819. }
  200820. void WaitableEvent::reset() const throw()
  200821. {
  200822. EventStruct* const es = (EventStruct*) internal;
  200823. pthread_mutex_lock (&es->mutex);
  200824. es->triggered = false;
  200825. pthread_mutex_unlock (&es->mutex);
  200826. }
  200827. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200828. {
  200829. struct timespec time;
  200830. time.tv_sec = millisecs / 1000;
  200831. time.tv_nsec = (millisecs % 1000) * 1000000;
  200832. nanosleep (&time, 0);
  200833. }
  200834. const tchar File::separator = T('/');
  200835. const tchar* File::separatorString = T("/");
  200836. const File File::getCurrentWorkingDirectory()
  200837. {
  200838. HeapBlock<char> heapBuffer;
  200839. char localBuffer [1024];
  200840. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200841. int bufferSize = 4096;
  200842. while (cwd == 0 && errno == ERANGE)
  200843. {
  200844. heapBuffer.malloc (bufferSize);
  200845. cwd = getcwd (heapBuffer, bufferSize - 1);
  200846. bufferSize += 1024;
  200847. }
  200848. return File (String::fromUTF8 (cwd));
  200849. }
  200850. bool File::setAsCurrentWorkingDirectory() const
  200851. {
  200852. return chdir (getFullPathName().toUTF8()) == 0;
  200853. }
  200854. bool juce_copyFile (const String& s, const String& d);
  200855. static bool juce_stat (const String& fileName, struct stat& info)
  200856. {
  200857. return fileName.isNotEmpty()
  200858. && (stat (fileName.toUTF8(), &info) == 0);
  200859. }
  200860. bool juce_isDirectory (const String& fileName)
  200861. {
  200862. struct stat info;
  200863. return fileName.isEmpty()
  200864. || (juce_stat (fileName, info)
  200865. && ((info.st_mode & S_IFDIR) != 0));
  200866. }
  200867. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200868. {
  200869. if (fileName.isEmpty())
  200870. return false;
  200871. const char* const fileNameUTF8 = fileName.toUTF8();
  200872. bool exists = access (fileNameUTF8, F_OK) == 0;
  200873. if (exists && dontCountDirectories)
  200874. {
  200875. struct stat info;
  200876. const int res = stat (fileNameUTF8, &info);
  200877. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200878. exists = false;
  200879. }
  200880. return exists;
  200881. }
  200882. int64 juce_getFileSize (const String& fileName)
  200883. {
  200884. struct stat info;
  200885. return juce_stat (fileName, info) ? info.st_size : 0;
  200886. }
  200887. bool juce_canWriteToFile (const String& fileName)
  200888. {
  200889. return access (fileName.toUTF8(), W_OK) == 0;
  200890. }
  200891. bool juce_deleteFile (const String& fileName)
  200892. {
  200893. if (juce_isDirectory (fileName))
  200894. return rmdir ((const char*) fileName.toUTF8()) == 0;
  200895. else
  200896. return remove ((const char*) fileName.toUTF8()) == 0;
  200897. }
  200898. bool juce_moveFile (const String& source, const String& dest)
  200899. {
  200900. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200901. return true;
  200902. if (juce_canWriteToFile (source)
  200903. && juce_copyFile (source, dest))
  200904. {
  200905. if (juce_deleteFile (source))
  200906. return true;
  200907. juce_deleteFile (dest);
  200908. }
  200909. return false;
  200910. }
  200911. void juce_createDirectory (const String& fileName)
  200912. {
  200913. mkdir (fileName.toUTF8(), 0777);
  200914. }
  200915. void* juce_fileOpen (const String& fileName, bool forWriting)
  200916. {
  200917. int flags = O_RDONLY;
  200918. if (forWriting)
  200919. {
  200920. if (juce_fileExists (fileName, false))
  200921. {
  200922. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  200923. if (f != -1)
  200924. lseek (f, 0, SEEK_END);
  200925. return (void*) f;
  200926. }
  200927. else
  200928. {
  200929. flags = O_RDWR + O_CREAT;
  200930. }
  200931. }
  200932. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  200933. }
  200934. void juce_fileClose (void* handle)
  200935. {
  200936. if (handle != 0)
  200937. close ((int) (pointer_sized_int) handle);
  200938. }
  200939. int juce_fileRead (void* handle, void* buffer, int size)
  200940. {
  200941. if (handle != 0)
  200942. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  200943. return 0;
  200944. }
  200945. int juce_fileWrite (void* handle, const void* buffer, int size)
  200946. {
  200947. if (handle != 0)
  200948. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200949. return 0;
  200950. }
  200951. int64 juce_fileSetPosition (void* handle, int64 pos)
  200952. {
  200953. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200954. return pos;
  200955. return -1;
  200956. }
  200957. int64 juce_fileGetPosition (void* handle)
  200958. {
  200959. if (handle != 0)
  200960. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200961. else
  200962. return -1;
  200963. }
  200964. void juce_fileFlush (void* handle)
  200965. {
  200966. if (handle != 0)
  200967. fsync ((int) (pointer_sized_int) handle);
  200968. }
  200969. const File juce_getExecutableFile()
  200970. {
  200971. Dl_info exeInfo;
  200972. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200973. return File (String::fromUTF8 (exeInfo.dli_fname));
  200974. }
  200975. // if this file doesn't exist, find a parent of it that does..
  200976. static bool doStatFS (const File* file, struct statfs& result)
  200977. {
  200978. File f (*file);
  200979. for (int i = 5; --i >= 0;)
  200980. {
  200981. if (f.exists())
  200982. break;
  200983. f = f.getParentDirectory();
  200984. }
  200985. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200986. }
  200987. int64 File::getBytesFreeOnVolume() const
  200988. {
  200989. struct statfs buf;
  200990. if (doStatFS (this, buf))
  200991. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200992. return 0;
  200993. }
  200994. int64 File::getVolumeTotalSize() const
  200995. {
  200996. struct statfs buf;
  200997. if (doStatFS (this, buf))
  200998. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200999. return 0;
  201000. }
  201001. const String juce_getVolumeLabel (const String& filenameOnVolume,
  201002. int& volumeSerialNumber)
  201003. {
  201004. volumeSerialNumber = 0;
  201005. #if JUCE_MAC
  201006. struct VolAttrBuf
  201007. {
  201008. u_int32_t length;
  201009. attrreference_t mountPointRef;
  201010. char mountPointSpace [MAXPATHLEN];
  201011. } attrBuf;
  201012. struct attrlist attrList;
  201013. zerostruct (attrList);
  201014. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  201015. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  201016. File f (filenameOnVolume);
  201017. for (;;)
  201018. {
  201019. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  201020. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  201021. {
  201022. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  201023. (int) attrBuf.mountPointRef.attr_length);
  201024. }
  201025. const File parent (f.getParentDirectory());
  201026. if (f == parent)
  201027. break;
  201028. f = parent;
  201029. }
  201030. #endif
  201031. return String::empty;
  201032. }
  201033. void juce_runSystemCommand (const String& command)
  201034. {
  201035. int result = system ((const char*) command.toUTF8());
  201036. (void) result;
  201037. }
  201038. const String juce_getOutputFromCommand (const String& command)
  201039. {
  201040. // slight bodge here, as we just pipe the output into a temp file and read it...
  201041. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  201042. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  201043. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  201044. String result (tempFile.loadFileAsString());
  201045. tempFile.deleteFile();
  201046. return result;
  201047. }
  201048. InterProcessLock::InterProcessLock (const String& name_)
  201049. : internal (0),
  201050. name (name_),
  201051. reentrancyLevel (0)
  201052. {
  201053. #if JUCE_MAC
  201054. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  201055. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  201056. #else
  201057. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  201058. #endif
  201059. temp.create();
  201060. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  201061. }
  201062. InterProcessLock::~InterProcessLock()
  201063. {
  201064. while (reentrancyLevel > 0)
  201065. this->exit();
  201066. close (internal);
  201067. }
  201068. bool InterProcessLock::enter (const int timeOutMillisecs)
  201069. {
  201070. if (internal == 0)
  201071. return false;
  201072. if (reentrancyLevel != 0)
  201073. return true;
  201074. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  201075. struct flock fl;
  201076. zerostruct (fl);
  201077. fl.l_whence = SEEK_SET;
  201078. fl.l_type = F_WRLCK;
  201079. for (;;)
  201080. {
  201081. const int result = fcntl (internal, F_SETLK, &fl);
  201082. if (result >= 0)
  201083. {
  201084. ++reentrancyLevel;
  201085. return true;
  201086. }
  201087. if (errno != EINTR)
  201088. {
  201089. if (timeOutMillisecs == 0
  201090. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  201091. break;
  201092. Thread::sleep (10);
  201093. }
  201094. }
  201095. return false;
  201096. }
  201097. void InterProcessLock::exit()
  201098. {
  201099. if (reentrancyLevel > 0 && internal != 0)
  201100. {
  201101. --reentrancyLevel;
  201102. struct flock fl;
  201103. zerostruct (fl);
  201104. fl.l_whence = SEEK_SET;
  201105. fl.l_type = F_UNLCK;
  201106. for (;;)
  201107. {
  201108. const int result = fcntl (internal, F_SETLKW, &fl);
  201109. if (result >= 0 || errno != EINTR)
  201110. break;
  201111. }
  201112. }
  201113. }
  201114. /*** End of inlined file: juce_posix_SharedCode.h ***/
  201115. /*** Start of inlined file: juce_mac_Files.mm ***/
  201116. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201117. // compiled on its own).
  201118. #if JUCE_INCLUDED_FILE
  201119. void juce_getFileTimes (const String& fileName,
  201120. int64& modificationTime,
  201121. int64& accessTime,
  201122. int64& creationTime)
  201123. {
  201124. modificationTime = 0;
  201125. accessTime = 0;
  201126. creationTime = 0;
  201127. struct stat info;
  201128. const int res = stat (fileName.toUTF8(), &info);
  201129. if (res == 0)
  201130. {
  201131. modificationTime = (int64) info.st_mtime * 1000;
  201132. accessTime = (int64) info.st_atime * 1000;
  201133. creationTime = (int64) info.st_ctime * 1000;
  201134. }
  201135. }
  201136. bool juce_setFileTimes (const String& fileName,
  201137. int64 modificationTime,
  201138. int64 accessTime,
  201139. int64 creationTime)
  201140. {
  201141. struct utimbuf times;
  201142. times.actime = (time_t) (accessTime / 1000);
  201143. times.modtime = (time_t) (modificationTime / 1000);
  201144. return utime (fileName.toUTF8(), &times) == 0;
  201145. }
  201146. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201147. {
  201148. struct stat info;
  201149. const int res = stat (fileName.toUTF8(), &info);
  201150. if (res != 0)
  201151. return false;
  201152. info.st_mode &= 0777; // Just permissions
  201153. if (isReadOnly)
  201154. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201155. else
  201156. // Give everybody write permission?
  201157. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201158. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201159. }
  201160. bool juce_copyFile (const String& src, const String& dst)
  201161. {
  201162. const ScopedAutoReleasePool pool;
  201163. NSFileManager* fm = [NSFileManager defaultManager];
  201164. return [fm fileExistsAtPath: juceStringToNS (src)]
  201165. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201166. && [fm copyItemAtPath: juceStringToNS (src)
  201167. toPath: juceStringToNS (dst)
  201168. error: nil];
  201169. #else
  201170. && [fm copyPath: juceStringToNS (src)
  201171. toPath: juceStringToNS (dst)
  201172. handler: nil];
  201173. #endif
  201174. }
  201175. const StringArray juce_getFileSystemRoots()
  201176. {
  201177. StringArray s;
  201178. s.add (T("/"));
  201179. return s;
  201180. }
  201181. static bool isFileOnDriveType (const File* const f, const char** types)
  201182. {
  201183. struct statfs buf;
  201184. if (doStatFS (f, buf))
  201185. {
  201186. const String type (buf.f_fstypename);
  201187. while (*types != 0)
  201188. if (type.equalsIgnoreCase (*types++))
  201189. return true;
  201190. }
  201191. return false;
  201192. }
  201193. bool File::isOnCDRomDrive() const
  201194. {
  201195. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201196. return isFileOnDriveType (this, (const char**) cdTypes);
  201197. }
  201198. bool File::isOnHardDisk() const
  201199. {
  201200. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201201. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201202. }
  201203. bool File::isOnRemovableDrive() const
  201204. {
  201205. #if JUCE_IPHONE
  201206. return false; // xxx is this possible?
  201207. #else
  201208. const ScopedAutoReleasePool pool;
  201209. BOOL removable = false;
  201210. [[NSWorkspace sharedWorkspace]
  201211. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201212. isRemovable: &removable
  201213. isWritable: nil
  201214. isUnmountable: nil
  201215. description: nil
  201216. type: nil];
  201217. return removable;
  201218. #endif
  201219. }
  201220. static bool juce_isHiddenFile (const String& path)
  201221. {
  201222. #if JUCE_IPHONE
  201223. return File (path).getFileName().startsWithChar (T('.'));
  201224. #else
  201225. FSRef ref;
  201226. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201227. return false;
  201228. FSCatalogInfo info;
  201229. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201230. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201231. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201232. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201233. #endif
  201234. }
  201235. bool File::isHidden() const
  201236. {
  201237. return juce_isHiddenFile (getFullPathName());
  201238. }
  201239. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201240. const File File::getSpecialLocation (const SpecialLocationType type)
  201241. {
  201242. const ScopedAutoReleasePool pool;
  201243. String resultPath;
  201244. switch (type)
  201245. {
  201246. case userHomeDirectory:
  201247. resultPath = nsStringToJuce (NSHomeDirectory());
  201248. break;
  201249. case userDocumentsDirectory:
  201250. resultPath = "~/Documents";
  201251. break;
  201252. case userDesktopDirectory:
  201253. resultPath = "~/Desktop";
  201254. break;
  201255. case userApplicationDataDirectory:
  201256. resultPath = "~/Library";
  201257. break;
  201258. case commonApplicationDataDirectory:
  201259. resultPath = "/Library";
  201260. break;
  201261. case globalApplicationsDirectory:
  201262. resultPath = "/Applications";
  201263. break;
  201264. case userMusicDirectory:
  201265. resultPath = "~/Music";
  201266. break;
  201267. case userMoviesDirectory:
  201268. resultPath = "~/Movies";
  201269. break;
  201270. case tempDirectory:
  201271. {
  201272. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201273. tmp.createDirectory();
  201274. return tmp.getFullPathName();
  201275. }
  201276. case invokedExecutableFile:
  201277. if (juce_Argv0 != 0)
  201278. return File (String::fromUTF8 (juce_Argv0));
  201279. // deliberate fall-through...
  201280. case currentExecutableFile:
  201281. return juce_getExecutableFile();
  201282. case currentApplicationFile:
  201283. {
  201284. const File exe (juce_getExecutableFile());
  201285. const File parent (exe.getParentDirectory());
  201286. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201287. ? parent.getParentDirectory().getParentDirectory()
  201288. : exe;
  201289. }
  201290. default:
  201291. jassertfalse // unknown type?
  201292. break;
  201293. }
  201294. if (resultPath.isNotEmpty())
  201295. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201296. return File::nonexistent;
  201297. }
  201298. const String File::getVersion() const
  201299. {
  201300. const ScopedAutoReleasePool pool;
  201301. String result;
  201302. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201303. if (bundle != 0)
  201304. {
  201305. NSDictionary* info = [bundle infoDictionary];
  201306. if (info != 0)
  201307. {
  201308. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201309. if (name != nil)
  201310. result = nsStringToJuce (name);
  201311. }
  201312. }
  201313. return result;
  201314. }
  201315. const File File::getLinkedTarget() const
  201316. {
  201317. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201318. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201319. #else
  201320. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201321. #endif
  201322. if (dest != nil)
  201323. return File (nsStringToJuce (dest));
  201324. return *this;
  201325. }
  201326. bool File::moveToTrash() const
  201327. {
  201328. if (! exists())
  201329. return true;
  201330. #if JUCE_IPHONE
  201331. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201332. #else
  201333. const ScopedAutoReleasePool pool;
  201334. NSString* p = juceStringToNS (getFullPathName());
  201335. return [[NSWorkspace sharedWorkspace]
  201336. performFileOperation: NSWorkspaceRecycleOperation
  201337. source: [p stringByDeletingLastPathComponent]
  201338. destination: @""
  201339. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201340. tag: nil ];
  201341. #endif
  201342. }
  201343. struct FindFileStruct
  201344. {
  201345. NSDirectoryEnumerator* enumerator;
  201346. String parentDir, wildCard;
  201347. };
  201348. bool juce_findFileNext (void* handle, String& resultFile,
  201349. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201350. {
  201351. ScopedAutoReleasePool pool;
  201352. FindFileStruct* ff = (FindFileStruct*) handle;
  201353. NSString* file;
  201354. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201355. for (;;)
  201356. {
  201357. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201358. return false;
  201359. [ff->enumerator skipDescendents];
  201360. resultFile = nsStringToJuce (file);
  201361. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201362. continue;
  201363. const String path (ff->parentDir + resultFile);
  201364. if (isDir != 0 || fileSize != 0)
  201365. {
  201366. struct stat info;
  201367. const bool statOk = juce_stat (path, info);
  201368. if (isDir != 0)
  201369. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201370. if (isHidden != 0)
  201371. *isHidden = juce_isHiddenFile (path);
  201372. if (fileSize != 0)
  201373. *fileSize = statOk ? info.st_size : 0;
  201374. }
  201375. if (modTime != 0 || creationTime != 0)
  201376. {
  201377. int64 m, a, c;
  201378. juce_getFileTimes (path, m, a, c);
  201379. if (modTime != 0)
  201380. *modTime = m;
  201381. if (creationTime != 0)
  201382. *creationTime = c;
  201383. }
  201384. if (isReadOnly != 0)
  201385. *isReadOnly = ! juce_canWriteToFile (path);
  201386. return true;
  201387. }
  201388. }
  201389. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201390. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201391. Time* creationTime, bool* isReadOnly)
  201392. {
  201393. ScopedAutoReleasePool pool;
  201394. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201395. if (e != 0)
  201396. {
  201397. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201398. ff->enumerator = [e retain];
  201399. ff->parentDir = directory;
  201400. ff->wildCard = wildCard;
  201401. if (! ff->parentDir.endsWithChar (File::separator))
  201402. ff->parentDir += File::separator;
  201403. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201404. return ff.release();
  201405. [e release];
  201406. }
  201407. return 0;
  201408. }
  201409. void juce_findFileClose (void* handle)
  201410. {
  201411. ScopedAutoReleasePool pool;
  201412. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201413. [ff->enumerator release];
  201414. }
  201415. bool juce_launchExecutable (const String& pathAndArguments)
  201416. {
  201417. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201418. const int cpid = fork();
  201419. if (cpid == 0)
  201420. {
  201421. // Child process
  201422. if (execve (argv[0], (char**) argv, 0) < 0)
  201423. exit (0);
  201424. }
  201425. else
  201426. {
  201427. if (cpid < 0)
  201428. return false;
  201429. }
  201430. return true;
  201431. }
  201432. bool juce_launchFile (const String& fileName, const String& parameters)
  201433. {
  201434. #if JUCE_IPHONE
  201435. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201436. #else
  201437. const ScopedAutoReleasePool pool;
  201438. if (parameters.isEmpty())
  201439. {
  201440. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201441. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201442. }
  201443. bool ok = false;
  201444. FSRef ref;
  201445. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201446. {
  201447. if (PlatformUtilities::isBundle (fileName))
  201448. {
  201449. NSMutableArray* urls = [NSMutableArray array];
  201450. StringArray docs;
  201451. docs.addTokens (parameters, true);
  201452. for (int i = 0; i < docs.size(); ++i)
  201453. [urls addObject: juceStringToNS (docs[i])];
  201454. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201455. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201456. options: 0
  201457. additionalEventParamDescriptor: nil
  201458. launchIdentifiers: nil];
  201459. }
  201460. else
  201461. {
  201462. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201463. }
  201464. }
  201465. return ok;
  201466. #endif
  201467. }
  201468. void File::revealToUser() const
  201469. {
  201470. #if ! JUCE_IPHONE
  201471. if (exists())
  201472. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201473. else if (getParentDirectory().exists())
  201474. getParentDirectory().revealToUser();
  201475. #endif
  201476. }
  201477. #if ! JUCE_IPHONE
  201478. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201479. {
  201480. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201481. }
  201482. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201483. {
  201484. char path [2048];
  201485. zerostruct (path);
  201486. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201487. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201488. return String::empty;
  201489. }
  201490. #endif
  201491. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201492. {
  201493. const ScopedAutoReleasePool pool;
  201494. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201495. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201496. #else
  201497. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201498. #endif
  201499. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201500. return [fileDict fileHFSTypeCode];
  201501. }
  201502. bool PlatformUtilities::isBundle (const String& filename)
  201503. {
  201504. #if JUCE_IPHONE
  201505. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201506. #else
  201507. const ScopedAutoReleasePool pool;
  201508. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201509. #endif
  201510. }
  201511. #endif
  201512. /*** End of inlined file: juce_mac_Files.mm ***/
  201513. #if JUCE_IPHONE
  201514. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201515. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201516. // compiled on its own).
  201517. #if JUCE_INCLUDED_FILE
  201518. static JUCEApplication* juce_intialisingApp;
  201519. END_JUCE_NAMESPACE
  201520. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201521. {
  201522. }
  201523. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201524. - (void) applicationWillResignActive: (UIApplication*) application;
  201525. @end
  201526. @implementation JuceAppStartupDelegate
  201527. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201528. {
  201529. String dummy;
  201530. if (! juce_intialisingApp->initialiseApp (dummy))
  201531. exit (0);
  201532. }
  201533. - (void) applicationWillResignActive: (UIApplication*) application
  201534. {
  201535. JUCEApplication::shutdownAppAndClearUp();
  201536. }
  201537. @end
  201538. BEGIN_JUCE_NAMESPACE
  201539. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201540. {
  201541. juce_intialisingApp = app;
  201542. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201543. }
  201544. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201545. {
  201546. pool = [[NSAutoreleasePool alloc] init];
  201547. }
  201548. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201549. {
  201550. [((NSAutoreleasePool*) pool) release];
  201551. }
  201552. void PlatformUtilities::beep()
  201553. {
  201554. //xxx
  201555. //AudioServicesPlaySystemSound ();
  201556. }
  201557. void PlatformUtilities::addItemToDock (const File& file)
  201558. {
  201559. }
  201560. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201561. END_JUCE_NAMESPACE
  201562. @interface JuceAlertBoxDelegate : NSObject
  201563. {
  201564. @public
  201565. bool clickedOk;
  201566. }
  201567. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201568. @end
  201569. @implementation JuceAlertBoxDelegate
  201570. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201571. {
  201572. clickedOk = (buttonIndex == 0);
  201573. alertView.hidden = true;
  201574. }
  201575. @end
  201576. BEGIN_JUCE_NAMESPACE
  201577. // (This function is used directly by other bits of code)
  201578. bool juce_iPhoneShowModalAlert (const String& title,
  201579. const String& bodyText,
  201580. NSString* okButtonText,
  201581. NSString* cancelButtonText)
  201582. {
  201583. const ScopedAutoReleasePool pool;
  201584. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201585. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201586. message: juceStringToNS (bodyText)
  201587. delegate: callback
  201588. cancelButtonTitle: okButtonText
  201589. otherButtonTitles: cancelButtonText, nil];
  201590. [alert retain];
  201591. [alert show];
  201592. while (! alert.hidden && alert.superview != nil)
  201593. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201594. const bool result = callback->clickedOk;
  201595. [alert release];
  201596. [callback release];
  201597. return result;
  201598. }
  201599. bool AlertWindow::showNativeDialogBox (const String& title,
  201600. const String& bodyText,
  201601. bool isOkCancel)
  201602. {
  201603. return juce_iPhoneShowModalAlert (title, bodyText,
  201604. @"OK",
  201605. isOkCancel ? @"Cancel" : nil);
  201606. }
  201607. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201608. {
  201609. jassertfalse // no such thing on the iphone!
  201610. return false;
  201611. }
  201612. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201613. {
  201614. jassertfalse // no such thing on the iphone!
  201615. return false;
  201616. }
  201617. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201618. {
  201619. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201620. }
  201621. bool Desktop::isScreenSaverEnabled() throw()
  201622. {
  201623. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201624. }
  201625. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201626. {
  201627. const ScopedAutoReleasePool pool;
  201628. monitorCoords.clear();
  201629. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201630. : [[UIScreen mainScreen] bounds];
  201631. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201632. (int) r.origin.y,
  201633. (int) r.size.width,
  201634. (int) r.size.height));
  201635. }
  201636. #endif
  201637. #endif
  201638. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201639. #else
  201640. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201641. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201642. // compiled on its own).
  201643. #if JUCE_INCLUDED_FILE
  201644. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201645. {
  201646. pool = [[NSAutoreleasePool alloc] init];
  201647. }
  201648. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201649. {
  201650. [((NSAutoreleasePool*) pool) release];
  201651. }
  201652. void PlatformUtilities::beep()
  201653. {
  201654. NSBeep();
  201655. }
  201656. void PlatformUtilities::addItemToDock (const File& file)
  201657. {
  201658. // check that it's not already there...
  201659. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201660. .containsIgnoreCase (file.getFullPathName()))
  201661. {
  201662. 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>"
  201663. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201664. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201665. }
  201666. }
  201667. int PlatformUtilities::getOSXMinorVersionNumber()
  201668. {
  201669. SInt32 versionMinor = 0;
  201670. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201671. (void) err;
  201672. jassert (err == noErr);
  201673. return (int) versionMinor;
  201674. }
  201675. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201676. bool AlertWindow::showNativeDialogBox (const String& title,
  201677. const String& bodyText,
  201678. bool isOkCancel)
  201679. {
  201680. const ScopedAutoReleasePool pool;
  201681. return NSRunAlertPanel (juceStringToNS (title),
  201682. juceStringToNS (bodyText),
  201683. @"Ok",
  201684. isOkCancel ? @"Cancel" : nil,
  201685. nil) == NSAlertDefaultReturn;
  201686. }
  201687. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201688. {
  201689. if (files.size() == 0)
  201690. return false;
  201691. Component* sourceComp = Component::getComponentUnderMouse();
  201692. if (sourceComp == 0)
  201693. {
  201694. jassertfalse // this method must be called in response to a
  201695. // component's mouseDrag event!
  201696. return false;
  201697. }
  201698. const ScopedAutoReleasePool pool;
  201699. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201700. if (view == 0)
  201701. return false;
  201702. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201703. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201704. owner: nil];
  201705. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201706. for (int i = 0; i < files.size(); ++i)
  201707. [filesArray addObject: juceStringToNS (files[i])];
  201708. [pboard setPropertyList: filesArray
  201709. forType: NSFilenamesPboardType];
  201710. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201711. fromView: nil];
  201712. dragPosition.x -= 16;
  201713. dragPosition.y -= 16;
  201714. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201715. at: dragPosition
  201716. offset: NSMakeSize (0, 0)
  201717. event: [[view window] currentEvent]
  201718. pasteboard: pboard
  201719. source: view
  201720. slideBack: YES];
  201721. return true;
  201722. }
  201723. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201724. {
  201725. jassertfalse // not implemented!
  201726. return false;
  201727. }
  201728. bool Desktop::canUseSemiTransparentWindows() throw()
  201729. {
  201730. return true;
  201731. }
  201732. const Point<int> Desktop::getMousePosition()
  201733. {
  201734. const ScopedAutoReleasePool pool;
  201735. const NSPoint p ([NSEvent mouseLocation]);
  201736. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201737. }
  201738. void Desktop::setMousePosition (const Point<int>& newPosition)
  201739. {
  201740. // this rubbish needs to be done around the warp call, to avoid causing a
  201741. // bizarre glitch..
  201742. CGAssociateMouseAndMouseCursorPosition (false);
  201743. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201744. CGAssociateMouseAndMouseCursorPosition (true);
  201745. }
  201746. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201747. class ScreenSaverDefeater : public Timer,
  201748. public DeletedAtShutdown
  201749. {
  201750. public:
  201751. ScreenSaverDefeater() throw()
  201752. {
  201753. startTimer (10000);
  201754. timerCallback();
  201755. }
  201756. ~ScreenSaverDefeater() {}
  201757. void timerCallback()
  201758. {
  201759. if (Process::isForegroundProcess())
  201760. UpdateSystemActivity (UsrActivity);
  201761. }
  201762. };
  201763. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201764. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201765. {
  201766. if (isEnabled)
  201767. {
  201768. deleteAndZero (screenSaverDefeater);
  201769. }
  201770. else if (screenSaverDefeater == 0)
  201771. {
  201772. screenSaverDefeater = new ScreenSaverDefeater();
  201773. }
  201774. }
  201775. bool Desktop::isScreenSaverEnabled() throw()
  201776. {
  201777. return screenSaverDefeater == 0;
  201778. }
  201779. #else
  201780. static IOPMAssertionID screenSaverDisablerID = 0;
  201781. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201782. {
  201783. if (isEnabled)
  201784. {
  201785. if (screenSaverDisablerID != 0)
  201786. {
  201787. IOPMAssertionRelease (screenSaverDisablerID);
  201788. screenSaverDisablerID = 0;
  201789. }
  201790. }
  201791. else
  201792. {
  201793. if (screenSaverDisablerID == 0)
  201794. {
  201795. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201796. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201797. CFSTR ("Juce"), &screenSaverDisablerID);
  201798. #else
  201799. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201800. &screenSaverDisablerID);
  201801. #endif
  201802. }
  201803. }
  201804. }
  201805. bool Desktop::isScreenSaverEnabled() throw()
  201806. {
  201807. return screenSaverDisablerID == 0;
  201808. }
  201809. #endif
  201810. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201811. {
  201812. const ScopedAutoReleasePool pool;
  201813. monitorCoords.clear();
  201814. NSArray* screens = [NSScreen screens];
  201815. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201816. for (unsigned int i = 0; i < [screens count]; ++i)
  201817. {
  201818. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201819. NSRect r = clipToWorkArea ? [s visibleFrame]
  201820. : [s frame];
  201821. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201822. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201823. (int) r.size.width,
  201824. (int) r.size.height));
  201825. }
  201826. jassert (monitorCoords.size() > 0);
  201827. }
  201828. #endif
  201829. #endif
  201830. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201831. #endif
  201832. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201833. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201834. // compiled on its own).
  201835. #if JUCE_INCLUDED_FILE
  201836. void Logger::outputDebugString (const String& text) throw()
  201837. {
  201838. std::cerr << (const char*) text.toUTF8() << std::endl;
  201839. }
  201840. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  201841. {
  201842. String text;
  201843. va_list args;
  201844. va_start (args, format);
  201845. text.vprintf (format, args);
  201846. outputDebugString (text);
  201847. }
  201848. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201849. {
  201850. static char testResult = 0;
  201851. if (testResult == 0)
  201852. {
  201853. struct kinfo_proc info;
  201854. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201855. size_t sz = sizeof (info);
  201856. sysctl (m, 4, &info, &sz, 0, 0);
  201857. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201858. }
  201859. return testResult > 0;
  201860. }
  201861. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201862. {
  201863. return juce_isRunningUnderDebugger();
  201864. }
  201865. #endif
  201866. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201867. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201868. #if JUCE_IPHONE
  201869. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201870. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201871. // compiled on its own).
  201872. #if JUCE_INCLUDED_FILE
  201873. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201874. #define SUPPORT_10_4_FONTS 1
  201875. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201876. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201877. #define SUPPORT_ONLY_10_4_FONTS 1
  201878. #endif
  201879. END_JUCE_NAMESPACE
  201880. @interface NSFont (PrivateHack)
  201881. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201882. @end
  201883. BEGIN_JUCE_NAMESPACE
  201884. #endif
  201885. class MacTypeface : public Typeface
  201886. {
  201887. public:
  201888. MacTypeface (const Font& font)
  201889. : Typeface (font.getTypefaceName())
  201890. {
  201891. const ScopedAutoReleasePool pool;
  201892. renderingTransform = CGAffineTransformIdentity;
  201893. bool needsItalicTransform = false;
  201894. #if JUCE_IPHONE
  201895. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201896. if (font.isItalic() || font.isBold())
  201897. {
  201898. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201899. for (NSString* i in familyFonts)
  201900. {
  201901. const String fn (nsStringToJuce (i));
  201902. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  201903. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  201904. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  201905. || afterDash.containsIgnoreCase (T("italic"))
  201906. || fn.endsWithIgnoreCase (T("oblique"))
  201907. || fn.endsWithIgnoreCase (T("italic"));
  201908. if (probablyBold == font.isBold()
  201909. && probablyItalic == font.isItalic())
  201910. {
  201911. fontName = i;
  201912. needsItalicTransform = false;
  201913. break;
  201914. }
  201915. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201916. {
  201917. fontName = i;
  201918. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201919. }
  201920. }
  201921. if (needsItalicTransform)
  201922. renderingTransform.c = 0.15f;
  201923. }
  201924. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201925. const int ascender = abs (CGFontGetAscent (fontRef));
  201926. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201927. ascent = ascender / totalHeight;
  201928. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201929. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201930. #else
  201931. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201932. if (font.isItalic())
  201933. {
  201934. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201935. toHaveTrait: NSItalicFontMask];
  201936. if (newFont == nsFont)
  201937. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201938. nsFont = newFont;
  201939. }
  201940. if (font.isBold())
  201941. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201942. [nsFont retain];
  201943. ascent = fabsf ((float) [nsFont ascender]);
  201944. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201945. ascent /= totalSize;
  201946. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201947. if (needsItalicTransform)
  201948. {
  201949. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201950. renderingTransform.c = 0.15f;
  201951. }
  201952. #if SUPPORT_ONLY_10_4_FONTS
  201953. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201954. if (atsFont == 0)
  201955. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201956. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201957. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201958. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201959. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201960. #else
  201961. #if SUPPORT_10_4_FONTS
  201962. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201963. {
  201964. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201965. if (atsFont == 0)
  201966. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201967. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201968. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201969. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201970. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201971. }
  201972. else
  201973. #endif
  201974. {
  201975. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201976. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201977. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201978. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201979. }
  201980. #endif
  201981. #endif
  201982. }
  201983. ~MacTypeface()
  201984. {
  201985. #if ! JUCE_IPHONE
  201986. [nsFont release];
  201987. #endif
  201988. if (fontRef != 0)
  201989. CGFontRelease (fontRef);
  201990. }
  201991. float getAscent() const
  201992. {
  201993. return ascent;
  201994. }
  201995. float getDescent() const
  201996. {
  201997. return 1.0f - ascent;
  201998. }
  201999. float getStringWidth (const String& text)
  202000. {
  202001. if (fontRef == 0 || text.isEmpty())
  202002. return 0;
  202003. const int length = text.length();
  202004. HeapBlock <CGGlyph> glyphs;
  202005. createGlyphsForString (text, length, glyphs);
  202006. float x = 0;
  202007. #if SUPPORT_ONLY_10_4_FONTS
  202008. HeapBlock <NSSize> advances (length);
  202009. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202010. for (int i = 0; i < length; ++i)
  202011. x += advances[i].width;
  202012. #else
  202013. #if SUPPORT_10_4_FONTS
  202014. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202015. {
  202016. HeapBlock <NSSize> advances (length);
  202017. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202018. for (int i = 0; i < length; ++i)
  202019. x += advances[i].width;
  202020. }
  202021. else
  202022. #endif
  202023. {
  202024. HeapBlock <int> advances (length);
  202025. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202026. for (int i = 0; i < length; ++i)
  202027. x += advances[i];
  202028. }
  202029. #endif
  202030. return x * unitsToHeightScaleFactor;
  202031. }
  202032. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  202033. {
  202034. xOffsets.add (0);
  202035. if (fontRef == 0 || text.isEmpty())
  202036. return;
  202037. const int length = text.length();
  202038. HeapBlock <CGGlyph> glyphs;
  202039. createGlyphsForString (text, length, glyphs);
  202040. #if SUPPORT_ONLY_10_4_FONTS
  202041. HeapBlock <NSSize> advances (length);
  202042. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202043. int x = 0;
  202044. for (int i = 0; i < length; ++i)
  202045. {
  202046. x += advances[i].width;
  202047. xOffsets.add (x * unitsToHeightScaleFactor);
  202048. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202049. }
  202050. #else
  202051. #if SUPPORT_10_4_FONTS
  202052. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202053. {
  202054. HeapBlock <NSSize> advances (length);
  202055. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202056. float x = 0;
  202057. for (int i = 0; i < length; ++i)
  202058. {
  202059. x += advances[i].width;
  202060. xOffsets.add (x * unitsToHeightScaleFactor);
  202061. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202062. }
  202063. }
  202064. else
  202065. #endif
  202066. {
  202067. HeapBlock <int> advances (length);
  202068. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202069. {
  202070. int x = 0;
  202071. for (int i = 0; i < length; ++i)
  202072. {
  202073. x += advances [i];
  202074. xOffsets.add (x * unitsToHeightScaleFactor);
  202075. resultGlyphs.add (glyphs[i]);
  202076. }
  202077. }
  202078. }
  202079. #endif
  202080. }
  202081. bool getOutlineForGlyph (int glyphNumber, Path& path)
  202082. {
  202083. #if JUCE_IPHONE
  202084. return false;
  202085. #else
  202086. if (nsFont == 0)
  202087. return false;
  202088. // we might need to apply a transform to the path, so it mustn't have anything else in it
  202089. jassert (path.isEmpty());
  202090. const ScopedAutoReleasePool pool;
  202091. NSBezierPath* bez = [NSBezierPath bezierPath];
  202092. [bez moveToPoint: NSMakePoint (0, 0)];
  202093. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  202094. inFont: nsFont];
  202095. for (int i = 0; i < [bez elementCount]; ++i)
  202096. {
  202097. NSPoint p[3];
  202098. switch ([bez elementAtIndex: i associatedPoints: p])
  202099. {
  202100. case NSMoveToBezierPathElement:
  202101. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  202102. break;
  202103. case NSLineToBezierPathElement:
  202104. path.lineTo ((float) p[0].x, (float) -p[0].y);
  202105. break;
  202106. case NSCurveToBezierPathElement:
  202107. 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);
  202108. break;
  202109. case NSClosePathBezierPathElement:
  202110. path.closeSubPath();
  202111. break;
  202112. default:
  202113. jassertfalse
  202114. break;
  202115. }
  202116. }
  202117. path.applyTransform (pathTransform);
  202118. return true;
  202119. #endif
  202120. }
  202121. juce_UseDebuggingNewOperator
  202122. CGFontRef fontRef;
  202123. float fontHeightToCGSizeFactor;
  202124. CGAffineTransform renderingTransform;
  202125. private:
  202126. float ascent, unitsToHeightScaleFactor;
  202127. #if JUCE_IPHONE
  202128. #else
  202129. NSFont* nsFont;
  202130. AffineTransform pathTransform;
  202131. #endif
  202132. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202133. {
  202134. #if SUPPORT_10_4_FONTS
  202135. #if ! SUPPORT_ONLY_10_4_FONTS
  202136. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202137. #endif
  202138. {
  202139. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202140. NSGlyph* const g = (NSGlyph*) glyphs;
  202141. for (int i = 0; i < length; ++i)
  202142. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202143. return;
  202144. }
  202145. #endif
  202146. #if ! SUPPORT_ONLY_10_4_FONTS
  202147. if (charToGlyphMapper == 0)
  202148. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202149. glyphs.malloc (length);
  202150. for (int i = 0; i < length; ++i)
  202151. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202152. #endif
  202153. }
  202154. #if ! SUPPORT_ONLY_10_4_FONTS
  202155. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202156. class CharToGlyphMapper
  202157. {
  202158. public:
  202159. CharToGlyphMapper (CGFontRef fontRef)
  202160. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202161. idRangeOffset (0), glyphIndexes (0)
  202162. {
  202163. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202164. if (cmapTable != 0)
  202165. {
  202166. const int numSubtables = getValue16 (cmapTable, 2);
  202167. for (int i = 0; i < numSubtables; ++i)
  202168. {
  202169. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202170. {
  202171. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202172. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202173. {
  202174. const int length = getValue16 (cmapTable, offset + 2);
  202175. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202176. segCount = segCountX2 / 2;
  202177. const int endCodeOffset = offset + 14;
  202178. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202179. const int idDeltaOffset = startCodeOffset + segCountX2;
  202180. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202181. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202182. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202183. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202184. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202185. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202186. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202187. }
  202188. break;
  202189. }
  202190. }
  202191. CFRelease (cmapTable);
  202192. }
  202193. }
  202194. ~CharToGlyphMapper()
  202195. {
  202196. if (endCode != 0)
  202197. {
  202198. CFRelease (endCode);
  202199. CFRelease (startCode);
  202200. CFRelease (idDelta);
  202201. CFRelease (idRangeOffset);
  202202. CFRelease (glyphIndexes);
  202203. }
  202204. }
  202205. int getGlyphForCharacter (const juce_wchar c) const
  202206. {
  202207. for (int i = 0; i < segCount; ++i)
  202208. {
  202209. if (getValue16 (endCode, i * 2) >= c)
  202210. {
  202211. const int start = getValue16 (startCode, i * 2);
  202212. if (start > c)
  202213. break;
  202214. const int delta = getValue16 (idDelta, i * 2);
  202215. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202216. if (rangeOffset == 0)
  202217. return delta + c;
  202218. else
  202219. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202220. }
  202221. }
  202222. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202223. return jmax (-1, c - 29);
  202224. }
  202225. private:
  202226. int segCount;
  202227. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202228. static uint16 getValue16 (CFDataRef data, const int index)
  202229. {
  202230. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202231. }
  202232. static uint32 getValue32 (CFDataRef data, const int index)
  202233. {
  202234. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202235. }
  202236. };
  202237. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202238. #endif
  202239. };
  202240. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202241. {
  202242. return new MacTypeface (font);
  202243. }
  202244. const StringArray Font::findAllTypefaceNames() throw()
  202245. {
  202246. StringArray names;
  202247. const ScopedAutoReleasePool pool;
  202248. #if JUCE_IPHONE
  202249. NSArray* fonts = [UIFont familyNames];
  202250. #else
  202251. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202252. #endif
  202253. for (unsigned int i = 0; i < [fonts count]; ++i)
  202254. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202255. names.sort (true);
  202256. return names;
  202257. }
  202258. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202259. {
  202260. #if JUCE_IPHONE
  202261. defaultSans = "Helvetica";
  202262. defaultSerif = "Times New Roman";
  202263. defaultFixed = "Courier New";
  202264. #else
  202265. defaultSans = "Lucida Grande";
  202266. defaultSerif = "Times New Roman";
  202267. defaultFixed = "Monaco";
  202268. #endif
  202269. }
  202270. #endif
  202271. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202272. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202273. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202274. // compiled on its own).
  202275. #if JUCE_INCLUDED_FILE
  202276. class CoreGraphicsImage : public Image
  202277. {
  202278. public:
  202279. CoreGraphicsImage (const PixelFormat format_,
  202280. const int imageWidth_,
  202281. const int imageHeight_,
  202282. const bool clearImage)
  202283. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202284. {
  202285. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202286. : CGColorSpaceCreateDeviceRGB();
  202287. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202288. colourSpace, getCGImageFlags (*this));
  202289. CGColorSpaceRelease (colourSpace);
  202290. }
  202291. ~CoreGraphicsImage()
  202292. {
  202293. CGContextRelease (context);
  202294. }
  202295. LowLevelGraphicsContext* createLowLevelContext();
  202296. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202297. {
  202298. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202299. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202300. {
  202301. return CGBitmapContextCreateImage (nativeImage->context);
  202302. }
  202303. else
  202304. {
  202305. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202306. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202307. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202308. 8, srcData.pixelStride * 8, srcData.lineStride,
  202309. colourSpace, getCGImageFlags (juceImage), provider,
  202310. 0, true, kCGRenderingIntentDefault);
  202311. CGDataProviderRelease (provider);
  202312. return imageRef;
  202313. }
  202314. }
  202315. #if JUCE_MAC
  202316. static NSImage* createNSImage (const Image& image)
  202317. {
  202318. const ScopedAutoReleasePool pool;
  202319. NSImage* im = [[NSImage alloc] init];
  202320. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202321. [im lockFocus];
  202322. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202323. CGImageRef imageRef = createImage (image, false, colourSpace);
  202324. CGColorSpaceRelease (colourSpace);
  202325. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202326. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202327. CGImageRelease (imageRef);
  202328. [im unlockFocus];
  202329. return im;
  202330. }
  202331. #endif
  202332. CGContextRef context;
  202333. private:
  202334. static CGBitmapInfo getCGImageFlags (const Image& image)
  202335. {
  202336. #if JUCE_BIG_ENDIAN
  202337. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202338. #else
  202339. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202340. #endif
  202341. }
  202342. };
  202343. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202344. {
  202345. #if USE_COREGRAPHICS_RENDERING
  202346. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202347. #else
  202348. return new Image (format, imageWidth, imageHeight, clearImage);
  202349. #endif
  202350. }
  202351. class CoreGraphicsContext : public LowLevelGraphicsContext
  202352. {
  202353. public:
  202354. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202355. : context (context_),
  202356. flipHeight (flipHeight_),
  202357. numGradientLookupEntries (0)
  202358. {
  202359. CGContextRetain (context);
  202360. CGContextSaveGState(context);
  202361. CGContextSetShouldSmoothFonts (context, true);
  202362. CGContextSetShouldAntialias (context, true);
  202363. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202364. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202365. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202366. gradientCallbacks.version = 0;
  202367. gradientCallbacks.evaluate = gradientCallback;
  202368. gradientCallbacks.releaseInfo = 0;
  202369. state = new SavedState();
  202370. }
  202371. ~CoreGraphicsContext()
  202372. {
  202373. CGContextRestoreGState (context);
  202374. CGContextRelease (context);
  202375. CGColorSpaceRelease (rgbColourSpace);
  202376. CGColorSpaceRelease (greyColourSpace);
  202377. }
  202378. bool isVectorDevice() const { return false; }
  202379. void setOrigin (int x, int y)
  202380. {
  202381. CGContextTranslateCTM (context, x, -y);
  202382. }
  202383. bool clipToRectangle (const Rectangle<int>& r)
  202384. {
  202385. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202386. return ! isClipEmpty();
  202387. }
  202388. bool clipToRectangleList (const RectangleList& clipRegion)
  202389. {
  202390. if (clipRegion.isEmpty())
  202391. {
  202392. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202393. return false;
  202394. }
  202395. else
  202396. {
  202397. const int numRects = clipRegion.getNumRectangles();
  202398. HeapBlock <CGRect> rects (numRects);
  202399. for (int i = 0; i < numRects; ++i)
  202400. {
  202401. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202402. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202403. }
  202404. CGContextClipToRects (context, rects, numRects);
  202405. return ! isClipEmpty();
  202406. }
  202407. }
  202408. void excludeClipRectangle (const Rectangle<int>& r)
  202409. {
  202410. RectangleList remaining (getClipBounds());
  202411. remaining.subtract (r);
  202412. clipToRectangleList (remaining);
  202413. }
  202414. void clipToPath (const Path& path, const AffineTransform& transform)
  202415. {
  202416. createPath (path, transform);
  202417. CGContextClip (context);
  202418. }
  202419. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202420. {
  202421. if (! transform.isSingularity())
  202422. {
  202423. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202424. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202425. flip();
  202426. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202427. applyTransform (t);
  202428. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202429. CGContextClipToMask (context, r, image);
  202430. applyTransform (t.inverted());
  202431. flip();
  202432. CGImageRelease (image);
  202433. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202434. }
  202435. }
  202436. bool clipRegionIntersects (const Rectangle<int>& r)
  202437. {
  202438. return getClipBounds().intersects (r);
  202439. }
  202440. const Rectangle<int> getClipBounds() const
  202441. {
  202442. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202443. return Rectangle<int> (roundToInt (bounds.origin.x),
  202444. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202445. roundToInt (bounds.size.width),
  202446. roundToInt (bounds.size.height));
  202447. }
  202448. bool isClipEmpty() const
  202449. {
  202450. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202451. }
  202452. void saveState()
  202453. {
  202454. CGContextSaveGState (context);
  202455. stateStack.add (new SavedState (*state));
  202456. }
  202457. void restoreState()
  202458. {
  202459. CGContextRestoreGState (context);
  202460. SavedState* const top = stateStack.getLast();
  202461. if (top != 0)
  202462. {
  202463. state = top;
  202464. stateStack.removeLast (1, false);
  202465. }
  202466. else
  202467. {
  202468. jassertfalse // trying to pop with an empty stack!
  202469. }
  202470. }
  202471. void setFill (const FillType& fillType)
  202472. {
  202473. state->fillType = fillType;
  202474. if (fillType.isColour())
  202475. {
  202476. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202477. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202478. CGContextSetAlpha (context, 1.0f);
  202479. }
  202480. }
  202481. void setOpacity (float newOpacity)
  202482. {
  202483. state->fillType.setOpacity (newOpacity);
  202484. setFill (state->fillType);
  202485. }
  202486. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202487. {
  202488. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202489. ? kCGInterpolationLow
  202490. : kCGInterpolationHigh);
  202491. }
  202492. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202493. {
  202494. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202495. if (replaceExistingContents)
  202496. {
  202497. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202498. CGContextClearRect (context, cgRect);
  202499. #else
  202500. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202501. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202502. CGContextClearRect (context, cgRect);
  202503. else
  202504. #endif
  202505. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202506. #endif
  202507. fillRect (r, false);
  202508. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202509. }
  202510. else
  202511. {
  202512. if (state->fillType.isColour())
  202513. {
  202514. CGContextFillRect (context, cgRect);
  202515. }
  202516. else if (state->fillType.isGradient())
  202517. {
  202518. CGContextSaveGState (context);
  202519. CGContextClipToRect (context, cgRect);
  202520. drawGradient();
  202521. CGContextRestoreGState (context);
  202522. }
  202523. else
  202524. {
  202525. CGContextSaveGState (context);
  202526. CGContextClipToRect (context, cgRect);
  202527. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202528. CGContextRestoreGState (context);
  202529. }
  202530. }
  202531. }
  202532. void fillPath (const Path& path, const AffineTransform& transform)
  202533. {
  202534. CGContextSaveGState (context);
  202535. if (state->fillType.isColour())
  202536. {
  202537. flip();
  202538. applyTransform (transform);
  202539. createPath (path);
  202540. if (path.isUsingNonZeroWinding())
  202541. CGContextFillPath (context);
  202542. else
  202543. CGContextEOFillPath (context);
  202544. }
  202545. else
  202546. {
  202547. createPath (path, transform);
  202548. if (path.isUsingNonZeroWinding())
  202549. CGContextClip (context);
  202550. else
  202551. CGContextEOClip (context);
  202552. if (state->fillType.isGradient())
  202553. drawGradient();
  202554. else
  202555. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202556. }
  202557. CGContextRestoreGState (context);
  202558. }
  202559. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202560. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202561. {
  202562. jassert (sourceImage.getBounds().contains (srcClip));
  202563. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202564. CGImageRef image = fullImage;
  202565. if (srcClip != sourceImage.getBounds())
  202566. {
  202567. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202568. srcClip.getWidth(), srcClip.getHeight()));
  202569. CGImageRelease (fullImage);
  202570. }
  202571. CGContextSaveGState (context);
  202572. CGContextSetAlpha (context, state->fillType.getOpacity());
  202573. flip();
  202574. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202575. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202576. if (fillEntireClipAsTiles)
  202577. {
  202578. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202579. CGContextDrawTiledImage (context, imageRect, image);
  202580. #else
  202581. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202582. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202583. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202584. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202585. CGContextDrawTiledImage (context, imageRect, image);
  202586. else
  202587. #endif
  202588. {
  202589. // Fallback to manually doing a tiled fill on 10.4
  202590. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202591. const int iw = srcClip.getWidth();
  202592. const int ih = srcClip.getHeight();
  202593. int x = 0, y = 0;
  202594. while (x > clip.origin.x) x -= iw;
  202595. while (y > clip.origin.y) y -= ih;
  202596. const int right = (int) (clip.origin.x + clip.size.width);
  202597. const int bottom = (int) (clip.origin.y + clip.size.height);
  202598. while (y < bottom)
  202599. {
  202600. for (int x2 = x; x2 < right; x2 += iw)
  202601. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202602. y += ih;
  202603. }
  202604. }
  202605. #endif
  202606. }
  202607. else
  202608. {
  202609. CGContextDrawImage (context, imageRect, image);
  202610. }
  202611. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202612. CGContextRestoreGState (context);
  202613. }
  202614. void drawLine (double x1, double y1, double x2, double y2)
  202615. {
  202616. CGContextSetLineCap (context, kCGLineCapSquare);
  202617. CGContextSetLineWidth (context, 1.0f);
  202618. CGContextSetRGBStrokeColor (context,
  202619. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202620. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202621. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202622. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202623. CGContextStrokeLineSegments (context, line, 1);
  202624. }
  202625. void drawVerticalLine (const int x, double top, double bottom)
  202626. {
  202627. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202628. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202629. #else
  202630. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202631. // the x co-ord slightly to trick it..
  202632. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202633. #endif
  202634. }
  202635. void drawHorizontalLine (const int y, double left, double right)
  202636. {
  202637. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202638. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202639. #else
  202640. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202641. // the x co-ord slightly to trick it..
  202642. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202643. #endif
  202644. }
  202645. void setFont (const Font& newFont)
  202646. {
  202647. if (state->font != newFont)
  202648. {
  202649. state->fontRef = 0;
  202650. state->font = newFont;
  202651. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202652. if (mf != 0)
  202653. {
  202654. state->fontRef = mf->fontRef;
  202655. CGContextSetFont (context, state->fontRef);
  202656. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202657. state->fontTransform = mf->renderingTransform;
  202658. state->fontTransform.a *= state->font.getHorizontalScale();
  202659. CGContextSetTextMatrix (context, state->fontTransform);
  202660. }
  202661. }
  202662. }
  202663. const Font getFont()
  202664. {
  202665. return state->font;
  202666. }
  202667. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202668. {
  202669. if (state->fontRef != 0 && state->fillType.isColour())
  202670. {
  202671. if (transform.isOnlyTranslation())
  202672. {
  202673. CGGlyph g = glyphNumber;
  202674. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202675. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202676. }
  202677. else
  202678. {
  202679. CGContextSaveGState (context);
  202680. flip();
  202681. applyTransform (transform);
  202682. CGAffineTransform t = state->fontTransform;
  202683. t.d = -t.d;
  202684. CGContextSetTextMatrix (context, t);
  202685. CGGlyph g = glyphNumber;
  202686. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202687. CGContextSetTextMatrix (context, state->fontTransform);
  202688. CGContextRestoreGState (context);
  202689. }
  202690. }
  202691. else
  202692. {
  202693. Path p;
  202694. Font& f = state->font;
  202695. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202696. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202697. .followedBy (transform));
  202698. }
  202699. }
  202700. private:
  202701. CGContextRef context;
  202702. const float flipHeight;
  202703. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202704. CGFunctionCallbacks gradientCallbacks;
  202705. struct SavedState
  202706. {
  202707. SavedState()
  202708. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202709. {
  202710. }
  202711. SavedState (const SavedState& other)
  202712. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202713. fontTransform (other.fontTransform)
  202714. {
  202715. }
  202716. ~SavedState()
  202717. {
  202718. }
  202719. FillType fillType;
  202720. Font font;
  202721. CGFontRef fontRef;
  202722. CGAffineTransform fontTransform;
  202723. };
  202724. ScopedPointer <SavedState> state;
  202725. OwnedArray <SavedState> stateStack;
  202726. HeapBlock <PixelARGB> gradientLookupTable;
  202727. int numGradientLookupEntries;
  202728. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202729. {
  202730. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202731. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202732. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202733. colour.unpremultiply();
  202734. outData[0] = colour.getRed() / 255.0f;
  202735. outData[1] = colour.getGreen() / 255.0f;
  202736. outData[2] = colour.getBlue() / 255.0f;
  202737. outData[3] = colour.getAlpha() / 255.0f;
  202738. }
  202739. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202740. {
  202741. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202742. --numGradientLookupEntries;
  202743. CGShadingRef result = 0;
  202744. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202745. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202746. if (gradient.isRadial)
  202747. {
  202748. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202749. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202750. function, true, true);
  202751. }
  202752. else
  202753. {
  202754. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202755. CGPointMake (gradient.x2, gradient.y2),
  202756. function, true, true);
  202757. }
  202758. CGFunctionRelease (function);
  202759. return result;
  202760. }
  202761. void drawGradient()
  202762. {
  202763. flip();
  202764. applyTransform (state->fillType.transform);
  202765. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202766. // you draw a gradient with high quality interp enabled).
  202767. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202768. CGContextSetAlpha (context, state->fillType.getOpacity());
  202769. CGContextDrawShading (context, shading);
  202770. CGShadingRelease (shading);
  202771. }
  202772. void createPath (const Path& path) const
  202773. {
  202774. CGContextBeginPath (context);
  202775. Path::Iterator i (path);
  202776. while (i.next())
  202777. {
  202778. switch (i.elementType)
  202779. {
  202780. case Path::Iterator::startNewSubPath:
  202781. CGContextMoveToPoint (context, i.x1, i.y1);
  202782. break;
  202783. case Path::Iterator::lineTo:
  202784. CGContextAddLineToPoint (context, i.x1, i.y1);
  202785. break;
  202786. case Path::Iterator::quadraticTo:
  202787. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202788. break;
  202789. case Path::Iterator::cubicTo:
  202790. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202791. break;
  202792. case Path::Iterator::closePath:
  202793. CGContextClosePath (context); break;
  202794. default:
  202795. jassertfalse
  202796. break;
  202797. }
  202798. }
  202799. }
  202800. void createPath (const Path& path, const AffineTransform& transform) const
  202801. {
  202802. CGContextBeginPath (context);
  202803. Path::Iterator i (path);
  202804. while (i.next())
  202805. {
  202806. switch (i.elementType)
  202807. {
  202808. case Path::Iterator::startNewSubPath:
  202809. transform.transformPoint (i.x1, i.y1);
  202810. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202811. break;
  202812. case Path::Iterator::lineTo:
  202813. transform.transformPoint (i.x1, i.y1);
  202814. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202815. break;
  202816. case Path::Iterator::quadraticTo:
  202817. transform.transformPoint (i.x1, i.y1);
  202818. transform.transformPoint (i.x2, i.y2);
  202819. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202820. break;
  202821. case Path::Iterator::cubicTo:
  202822. transform.transformPoint (i.x1, i.y1);
  202823. transform.transformPoint (i.x2, i.y2);
  202824. transform.transformPoint (i.x3, i.y3);
  202825. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202826. break;
  202827. case Path::Iterator::closePath:
  202828. CGContextClosePath (context); break;
  202829. default:
  202830. jassertfalse
  202831. break;
  202832. }
  202833. }
  202834. }
  202835. static Image* createAlphaChannelImage (const Image& im)
  202836. {
  202837. if (im.getFormat() == Image::SingleChannel)
  202838. return const_cast <Image*> (&im);
  202839. return im.createCopyOfAlphaChannel();
  202840. }
  202841. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202842. {
  202843. if (im.getFormat() != Image::SingleChannel)
  202844. delete alphaIm;
  202845. }
  202846. void flip() const
  202847. {
  202848. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202849. }
  202850. void applyTransform (const AffineTransform& transform) const
  202851. {
  202852. CGAffineTransform t;
  202853. t.a = transform.mat00;
  202854. t.b = transform.mat10;
  202855. t.c = transform.mat01;
  202856. t.d = transform.mat11;
  202857. t.tx = transform.mat02;
  202858. t.ty = transform.mat12;
  202859. CGContextConcatCTM (context, t);
  202860. }
  202861. float flipY (float y) const
  202862. {
  202863. return flipHeight - y;
  202864. }
  202865. };
  202866. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202867. {
  202868. return new CoreGraphicsContext (context, imageHeight);
  202869. }
  202870. #endif
  202871. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202872. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202873. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202874. // compiled on its own).
  202875. #if JUCE_INCLUDED_FILE
  202876. class UIViewComponentPeer;
  202877. END_JUCE_NAMESPACE
  202878. #define JuceUIView MakeObjCClassName(JuceUIView)
  202879. @interface JuceUIView : UIView
  202880. {
  202881. @public
  202882. UIViewComponentPeer* owner;
  202883. }
  202884. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202885. - (void) dealloc;
  202886. - (void) drawRect: (CGRect) r;
  202887. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202888. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202889. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202890. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202891. - (BOOL) becomeFirstResponder;
  202892. - (BOOL) resignFirstResponder;
  202893. - (BOOL) canBecomeFirstResponder;
  202894. - (void) asyncRepaint: (id) rect;
  202895. @end
  202896. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202897. @interface JuceUIWindow : UIWindow
  202898. {
  202899. @private
  202900. UIViewComponentPeer* owner;
  202901. bool isZooming;
  202902. }
  202903. - (void) setOwner: (UIViewComponentPeer*) owner;
  202904. - (void) becomeKeyWindow;
  202905. @end
  202906. BEGIN_JUCE_NAMESPACE
  202907. class UIViewComponentPeer : public ComponentPeer
  202908. {
  202909. public:
  202910. UIViewComponentPeer (Component* const component,
  202911. const int windowStyleFlags,
  202912. UIView* viewToAttachTo);
  202913. ~UIViewComponentPeer();
  202914. void* getNativeHandle() const;
  202915. void setVisible (bool shouldBeVisible);
  202916. void setTitle (const String& title);
  202917. void setPosition (int x, int y);
  202918. void setSize (int w, int h);
  202919. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  202920. const Rectangle<int> getBounds() const;
  202921. const Rectangle<int> getBounds (const bool global) const;
  202922. const Point<int> getScreenPosition() const;
  202923. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202924. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202925. void setMinimised (bool shouldBeMinimised);
  202926. bool isMinimised() const;
  202927. void setFullScreen (bool shouldBeFullScreen);
  202928. bool isFullScreen() const;
  202929. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202930. const BorderSize getFrameSize() const;
  202931. bool setAlwaysOnTop (bool alwaysOnTop);
  202932. void toFront (bool makeActiveWindow);
  202933. void toBehind (ComponentPeer* other);
  202934. void setIcon (const Image& newIcon);
  202935. virtual void drawRect (CGRect r);
  202936. virtual bool canBecomeKeyWindow();
  202937. virtual bool windowShouldClose();
  202938. virtual void redirectMovedOrResized();
  202939. virtual CGRect constrainRect (CGRect r);
  202940. virtual void viewFocusGain();
  202941. virtual void viewFocusLoss();
  202942. bool isFocused() const;
  202943. void grabFocus();
  202944. void textInputRequired (const Point<int>& position);
  202945. void repaint (int x, int y, int w, int h);
  202946. void performAnyPendingRepaintsNow();
  202947. juce_UseDebuggingNewOperator
  202948. UIWindow* window;
  202949. JuceUIView* view;
  202950. bool isSharedWindow, fullScreen, insideDrawRect;
  202951. static ModifierKeys currentModifiers;
  202952. };
  202953. END_JUCE_NAMESPACE
  202954. @implementation JuceUIView
  202955. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202956. withFrame: (CGRect) frame
  202957. {
  202958. [super initWithFrame: frame];
  202959. owner = owner_;
  202960. return self;
  202961. }
  202962. - (void) dealloc
  202963. {
  202964. [super dealloc];
  202965. }
  202966. - (void) drawRect: (CGRect) r
  202967. {
  202968. if (owner != 0)
  202969. owner->drawRect (r);
  202970. }
  202971. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  202972. {
  202973. return false;
  202974. }
  202975. ModifierKeys UIViewComponentPeer::currentModifiers;
  202976. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202977. {
  202978. return UIViewComponentPeer::currentModifiers;
  202979. }
  202980. void ModifierKeys::updateCurrentModifiers() throw()
  202981. {
  202982. currentModifiers = UIViewComponentPeer::currentModifiers;
  202983. }
  202984. static int64 getMouseTime (UIEvent* e)
  202985. {
  202986. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202987. + (int64) ([e timestamp] * 1000.0);
  202988. }
  202989. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202990. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202991. {
  202992. if (owner == 0)
  202993. return;
  202994. NSArray* const t = [[event touchesForView: self] allObjects];
  202995. switch ([t count])
  202996. {
  202997. case 1: // One finger..
  202998. {
  202999. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203000. const JUCE_NAMESPACE::Point<int> pos ((int) p.x, (int) p.y);
  203001. juce_lastMousePos = pos + owner->getScreenPosition();
  203002. owner->handleMouseEvent (pos, JUCE_NAMESPACE::UIViewComponentPeer::currentModifiers, getMouseTime (event));
  203003. JUCE_NAMESPACE::UIViewComponentPeer::currentModifiers
  203004. = JUCE_NAMESPACE::UIViewComponentPeer::currentModifiers.withoutMouseButtons()
  203005. .withFlags (JUCE_NAMESPACE::ModifierKeys::leftButtonModifier);
  203006. owner->handleMouseEvent (pos, JUCE_NAMESPACE::UIViewComponentPeer::currentModifiers, getMouseTime (event));
  203007. }
  203008. default:
  203009. //xxx multi-touch..
  203010. break;
  203011. }
  203012. }
  203013. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  203014. {
  203015. if (owner == 0)
  203016. return;
  203017. NSArray* const t = [[event touchesForView: self] allObjects];
  203018. switch ([t count])
  203019. {
  203020. case 1: // One finger..
  203021. {
  203022. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203023. const JUCE_NAMESPACE::Point<int> pos ((int) p.x, (int) p.y);
  203024. juce_lastMousePos = pos + owner->getScreenPosition();
  203025. owner->handleMouseEvent (pos, JUCE_NAMESPACE::UIViewComponentPeer::currentModifiers, getMouseTime (event));
  203026. }
  203027. default:
  203028. //xxx multi-touch..
  203029. break;
  203030. }
  203031. }
  203032. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  203033. {
  203034. if (owner == 0)
  203035. return;
  203036. NSArray* const t = [[event touchesForView: self] allObjects];
  203037. switch ([t count])
  203038. {
  203039. case 1: // One finger..
  203040. {
  203041. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203042. const JUCE_NAMESPACE::Point<int> pos ((int) p.x, (int) p.y);
  203043. juce_lastMousePos = pos + owner->getScreenPosition();
  203044. JUCE_NAMESPACE::UIViewComponentPeer::currentModifiers
  203045. = JUCE_NAMESPACE::UIViewComponentPeer::currentModifiers.withoutMouseButtons();
  203046. owner->handleMouseEvent (pos, JUCE_NAMESPACE::UIViewComponentPeer::currentModifiers, getMouseTime (event));
  203047. }
  203048. default:
  203049. //xxx multi-touch..
  203050. break;
  203051. }
  203052. }
  203053. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  203054. {
  203055. [self touchesEnded: touches withEvent: event];
  203056. }
  203057. - (BOOL) becomeFirstResponder
  203058. {
  203059. if (owner != 0)
  203060. owner->viewFocusGain();
  203061. return true;
  203062. }
  203063. - (BOOL) resignFirstResponder
  203064. {
  203065. if (owner != 0)
  203066. owner->viewFocusLoss();
  203067. return true;
  203068. }
  203069. - (BOOL) canBecomeFirstResponder
  203070. {
  203071. return owner != 0 && owner->canBecomeKeyWindow();
  203072. }
  203073. - (void) asyncRepaint: (id) rect
  203074. {
  203075. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  203076. [self setNeedsDisplayInRect: *r];
  203077. }
  203078. @end
  203079. @implementation JuceUIWindow
  203080. - (void) setOwner: (UIViewComponentPeer*) owner_
  203081. {
  203082. owner = owner_;
  203083. isZooming = false;
  203084. }
  203085. - (void) becomeKeyWindow
  203086. {
  203087. [super becomeKeyWindow];
  203088. if (owner != 0)
  203089. owner->grabFocus();
  203090. }
  203091. @end
  203092. BEGIN_JUCE_NAMESPACE
  203093. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  203094. const int windowStyleFlags,
  203095. UIView* viewToAttachTo)
  203096. : ComponentPeer (component, windowStyleFlags),
  203097. window (0),
  203098. view (0),
  203099. isSharedWindow (viewToAttachTo != 0),
  203100. fullScreen (false),
  203101. insideDrawRect (false)
  203102. {
  203103. CGRect r;
  203104. r.origin.x = 0;
  203105. r.origin.y = 0;
  203106. r.size.width = (float) component->getWidth();
  203107. r.size.height = (float) component->getHeight();
  203108. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  203109. if (isSharedWindow)
  203110. {
  203111. window = [viewToAttachTo window];
  203112. [viewToAttachTo addSubview: view];
  203113. setVisible (component->isVisible());
  203114. }
  203115. else
  203116. {
  203117. r.origin.x = (float) component->getX();
  203118. r.origin.y = (float) component->getY();
  203119. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  203120. window = [[JuceUIWindow alloc] init];
  203121. window.frame = r;
  203122. window.opaque = component->isOpaque();
  203123. view.opaque = component->isOpaque();
  203124. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203125. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203126. [((JuceUIWindow*) window) setOwner: this];
  203127. if (component->isAlwaysOnTop())
  203128. window.windowLevel = UIWindowLevelAlert;
  203129. [window addSubview: view];
  203130. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203131. view.hidden = ! component->isVisible();
  203132. window.hidden = ! component->isVisible();
  203133. }
  203134. setTitle (component->getName());
  203135. }
  203136. UIViewComponentPeer::~UIViewComponentPeer()
  203137. {
  203138. view->owner = 0;
  203139. [view removeFromSuperview];
  203140. [view release];
  203141. if (! isSharedWindow)
  203142. {
  203143. [((JuceUIWindow*) window) setOwner: 0];
  203144. [window release];
  203145. }
  203146. }
  203147. void* UIViewComponentPeer::getNativeHandle() const
  203148. {
  203149. return view;
  203150. }
  203151. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  203152. {
  203153. view.hidden = ! shouldBeVisible;
  203154. if (! isSharedWindow)
  203155. window.hidden = ! shouldBeVisible;
  203156. }
  203157. void UIViewComponentPeer::setTitle (const String& title)
  203158. {
  203159. // xxx is this possible?
  203160. }
  203161. void UIViewComponentPeer::setPosition (int x, int y)
  203162. {
  203163. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203164. }
  203165. void UIViewComponentPeer::setSize (int w, int h)
  203166. {
  203167. setBounds (component->getX(), component->getY(), w, h, false);
  203168. }
  203169. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203170. {
  203171. fullScreen = isNowFullScreen;
  203172. w = jmax (0, w);
  203173. h = jmax (0, h);
  203174. CGRect r;
  203175. r.origin.x = (float) x;
  203176. r.origin.y = (float) y;
  203177. r.size.width = (float) w;
  203178. r.size.height = (float) h;
  203179. if (isSharedWindow)
  203180. {
  203181. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203182. if ([view frame].size.width != r.size.width
  203183. || [view frame].size.height != r.size.height)
  203184. [view setNeedsDisplay];
  203185. view.frame = r;
  203186. }
  203187. else
  203188. {
  203189. window.frame = r;
  203190. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203191. }
  203192. }
  203193. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  203194. {
  203195. CGRect r = [view frame];
  203196. if (global && [view window] != 0)
  203197. {
  203198. r = [view convertRect: r toView: nil];
  203199. CGRect wr = [[view window] frame];
  203200. r.origin.x += wr.origin.x;
  203201. r.origin.y += wr.origin.y;
  203202. }
  203203. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  203204. (int) r.size.width, (int) r.size.height);
  203205. }
  203206. const Rectangle<int> UIViewComponentPeer::getBounds() const
  203207. {
  203208. return getBounds (! isSharedWindow);
  203209. }
  203210. const Point<int> UIViewComponentPeer::getScreenPosition() const
  203211. {
  203212. return getBounds (true).getPosition();
  203213. }
  203214. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  203215. {
  203216. return relativePosition + getScreenPosition();
  203217. }
  203218. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  203219. {
  203220. return screenPosition - getScreenPosition();
  203221. }
  203222. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203223. {
  203224. if (constrainer != 0)
  203225. {
  203226. CGRect current = [window frame];
  203227. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203228. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203229. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203230. (int) r.size.width, (int) r.size.height);
  203231. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203232. (int) current.size.width, (int) current.size.height);
  203233. constrainer->checkBounds (pos, original,
  203234. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203235. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203236. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203237. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203238. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203239. r.origin.x = pos.getX();
  203240. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203241. r.size.width = pos.getWidth();
  203242. r.size.height = pos.getHeight();
  203243. }
  203244. return r;
  203245. }
  203246. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203247. {
  203248. // xxx
  203249. }
  203250. bool UIViewComponentPeer::isMinimised() const
  203251. {
  203252. return false;
  203253. }
  203254. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203255. {
  203256. if (! isSharedWindow)
  203257. {
  203258. Rectangle<int> r (lastNonFullscreenBounds);
  203259. setMinimised (false);
  203260. if (fullScreen != shouldBeFullScreen)
  203261. {
  203262. if (shouldBeFullScreen)
  203263. r = Desktop::getInstance().getMainMonitorArea();
  203264. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203265. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203266. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203267. }
  203268. }
  203269. }
  203270. bool UIViewComponentPeer::isFullScreen() const
  203271. {
  203272. return fullScreen;
  203273. }
  203274. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  203275. {
  203276. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  203277. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  203278. return false;
  203279. CGPoint p;
  203280. p.x = (float) position.getX();
  203281. p.y = (float) position.getY();
  203282. UIView* v = [view hitTest: p withEvent: nil];
  203283. if (trueIfInAChildWindow)
  203284. return v != nil;
  203285. return v == view;
  203286. }
  203287. const BorderSize UIViewComponentPeer::getFrameSize() const
  203288. {
  203289. BorderSize b;
  203290. if (! isSharedWindow)
  203291. {
  203292. CGRect v = [view convertRect: [view frame] toView: nil];
  203293. CGRect w = [window frame];
  203294. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203295. b.setBottom ((int) v.origin.y);
  203296. b.setLeft ((int) v.origin.x);
  203297. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203298. }
  203299. return b;
  203300. }
  203301. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203302. {
  203303. if (! isSharedWindow)
  203304. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203305. return true;
  203306. }
  203307. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203308. {
  203309. if (isSharedWindow)
  203310. [[view superview] bringSubviewToFront: view];
  203311. if (window != 0 && component->isVisible())
  203312. [window makeKeyAndVisible];
  203313. }
  203314. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203315. {
  203316. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203317. if (isSharedWindow)
  203318. {
  203319. [[view superview] insertSubview: view belowSubview: o->view];
  203320. }
  203321. else
  203322. {
  203323. jassertfalse // don't know how to do this
  203324. }
  203325. }
  203326. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203327. {
  203328. // to do..
  203329. }
  203330. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203331. void UIViewComponentPeer::viewFocusGain()
  203332. {
  203333. if (currentlyFocusedPeer != this)
  203334. {
  203335. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203336. currentlyFocusedPeer->handleFocusLoss();
  203337. currentlyFocusedPeer = this;
  203338. handleFocusGain();
  203339. }
  203340. }
  203341. void UIViewComponentPeer::viewFocusLoss()
  203342. {
  203343. if (currentlyFocusedPeer == this)
  203344. {
  203345. currentlyFocusedPeer = 0;
  203346. handleFocusLoss();
  203347. }
  203348. }
  203349. void juce_HandleProcessFocusChange()
  203350. {
  203351. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203352. {
  203353. if (Process::isForegroundProcess())
  203354. {
  203355. currentlyFocusedPeer->handleFocusGain();
  203356. ComponentPeer::bringModalComponentToFront();
  203357. }
  203358. else
  203359. {
  203360. currentlyFocusedPeer->handleFocusLoss();
  203361. // turn kiosk mode off if we lose focus..
  203362. Desktop::getInstance().setKioskModeComponent (0);
  203363. }
  203364. }
  203365. }
  203366. bool UIViewComponentPeer::isFocused() const
  203367. {
  203368. return isSharedWindow ? this == currentlyFocusedPeer
  203369. : (window != 0 && [window isKeyWindow]);
  203370. }
  203371. void UIViewComponentPeer::grabFocus()
  203372. {
  203373. if (window != 0)
  203374. {
  203375. [window makeKeyWindow];
  203376. viewFocusGain();
  203377. }
  203378. }
  203379. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203380. {
  203381. }
  203382. void UIViewComponentPeer::drawRect (CGRect r)
  203383. {
  203384. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203385. return;
  203386. CGContextRef cg = UIGraphicsGetCurrentContext();
  203387. if (! component->isOpaque())
  203388. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203389. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203390. CoreGraphicsContext g (cg, view.bounds.size.height);
  203391. insideDrawRect = true;
  203392. handlePaint (g);
  203393. insideDrawRect = false;
  203394. }
  203395. bool UIViewComponentPeer::canBecomeKeyWindow()
  203396. {
  203397. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203398. }
  203399. bool UIViewComponentPeer::windowShouldClose()
  203400. {
  203401. if (! isValidPeer (this))
  203402. return YES;
  203403. handleUserClosingWindow();
  203404. return NO;
  203405. }
  203406. void UIViewComponentPeer::redirectMovedOrResized()
  203407. {
  203408. handleMovedOrResized();
  203409. }
  203410. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203411. {
  203412. }
  203413. class AsyncRepaintMessage : public CallbackMessage
  203414. {
  203415. public:
  203416. UIViewComponentPeer* const peer;
  203417. const Rectangle<int> rect;
  203418. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203419. : peer (peer_), rect (rect_)
  203420. {
  203421. }
  203422. void messageCallback()
  203423. {
  203424. if (ComponentPeer::isValidPeer (peer))
  203425. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203426. }
  203427. };
  203428. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203429. {
  203430. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203431. {
  203432. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203433. }
  203434. else
  203435. {
  203436. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203437. }
  203438. }
  203439. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203440. {
  203441. }
  203442. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203443. {
  203444. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203445. }
  203446. Image* juce_createIconForFile (const File& file)
  203447. {
  203448. return 0;
  203449. }
  203450. bool Desktop::canUseSemiTransparentWindows() throw()
  203451. {
  203452. return true;
  203453. }
  203454. const Point<int> Desktop::getMousePosition()
  203455. {
  203456. return juce_lastMousePos;
  203457. }
  203458. void Desktop::setMousePosition (const Point<int>&)
  203459. {
  203460. }
  203461. const int KeyPress::spaceKey = ' ';
  203462. const int KeyPress::returnKey = 0x0d;
  203463. const int KeyPress::escapeKey = 0x1b;
  203464. const int KeyPress::backspaceKey = 0x7f;
  203465. const int KeyPress::leftKey = 0x1000;
  203466. const int KeyPress::rightKey = 0x1001;
  203467. const int KeyPress::upKey = 0x1002;
  203468. const int KeyPress::downKey = 0x1003;
  203469. const int KeyPress::pageUpKey = 0x1004;
  203470. const int KeyPress::pageDownKey = 0x1005;
  203471. const int KeyPress::endKey = 0x1006;
  203472. const int KeyPress::homeKey = 0x1007;
  203473. const int KeyPress::deleteKey = 0x1008;
  203474. const int KeyPress::insertKey = -1;
  203475. const int KeyPress::tabKey = 9;
  203476. const int KeyPress::F1Key = 0x2001;
  203477. const int KeyPress::F2Key = 0x2002;
  203478. const int KeyPress::F3Key = 0x2003;
  203479. const int KeyPress::F4Key = 0x2004;
  203480. const int KeyPress::F5Key = 0x2005;
  203481. const int KeyPress::F6Key = 0x2006;
  203482. const int KeyPress::F7Key = 0x2007;
  203483. const int KeyPress::F8Key = 0x2008;
  203484. const int KeyPress::F9Key = 0x2009;
  203485. const int KeyPress::F10Key = 0x200a;
  203486. const int KeyPress::F11Key = 0x200b;
  203487. const int KeyPress::F12Key = 0x200c;
  203488. const int KeyPress::F13Key = 0x200d;
  203489. const int KeyPress::F14Key = 0x200e;
  203490. const int KeyPress::F15Key = 0x200f;
  203491. const int KeyPress::F16Key = 0x2010;
  203492. const int KeyPress::numberPad0 = 0x30020;
  203493. const int KeyPress::numberPad1 = 0x30021;
  203494. const int KeyPress::numberPad2 = 0x30022;
  203495. const int KeyPress::numberPad3 = 0x30023;
  203496. const int KeyPress::numberPad4 = 0x30024;
  203497. const int KeyPress::numberPad5 = 0x30025;
  203498. const int KeyPress::numberPad6 = 0x30026;
  203499. const int KeyPress::numberPad7 = 0x30027;
  203500. const int KeyPress::numberPad8 = 0x30028;
  203501. const int KeyPress::numberPad9 = 0x30029;
  203502. const int KeyPress::numberPadAdd = 0x3002a;
  203503. const int KeyPress::numberPadSubtract = 0x3002b;
  203504. const int KeyPress::numberPadMultiply = 0x3002c;
  203505. const int KeyPress::numberPadDivide = 0x3002d;
  203506. const int KeyPress::numberPadSeparator = 0x3002e;
  203507. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203508. const int KeyPress::numberPadEquals = 0x30030;
  203509. const int KeyPress::numberPadDelete = 0x30031;
  203510. const int KeyPress::playKey = 0x30000;
  203511. const int KeyPress::stopKey = 0x30001;
  203512. const int KeyPress::fastForwardKey = 0x30002;
  203513. const int KeyPress::rewindKey = 0x30003;
  203514. #endif
  203515. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203516. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203517. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203518. // compiled on its own).
  203519. #if JUCE_INCLUDED_FILE
  203520. struct CallbackMessagePayload
  203521. {
  203522. MessageCallbackFunction* function;
  203523. void* parameter;
  203524. void* volatile result;
  203525. bool volatile hasBeenExecuted;
  203526. };
  203527. END_JUCE_NAMESPACE
  203528. using namespace JUCE_NAMESPACE;
  203529. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203530. {
  203531. }
  203532. - (JuceAppDelegate*) init;
  203533. - (void) dealloc;
  203534. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203535. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203536. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203537. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203538. - (void) customEvent: (id) data;
  203539. - (void) performCallback: (id) info;
  203540. @end
  203541. @implementation JuceAppDelegate
  203542. - (JuceAppDelegate*) init
  203543. {
  203544. [super init];
  203545. [[UIApplication sharedApplication] setDelegate: self];
  203546. return self;
  203547. }
  203548. - (void) dealloc
  203549. {
  203550. [[UIApplication sharedApplication] setDelegate: nil];
  203551. [super dealloc];
  203552. }
  203553. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203554. {
  203555. if (JUCEApplication::getInstance() != 0)
  203556. {
  203557. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203558. return YES;
  203559. }
  203560. return NO;
  203561. }
  203562. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203563. {
  203564. juce_HandleProcessFocusChange();
  203565. }
  203566. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203567. {
  203568. juce_HandleProcessFocusChange();
  203569. }
  203570. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203571. {
  203572. juce_HandleProcessFocusChange();
  203573. }
  203574. - (void) customEvent: (id) n
  203575. {
  203576. NSData* data = (NSData*) n;
  203577. void* message = 0;
  203578. [data getBytes: &message length: sizeof (message)];
  203579. [data release];
  203580. if (message != 0)
  203581. MessageManager::getInstance()->deliverMessage (message);
  203582. }
  203583. - (void) performCallback: (id) info
  203584. {
  203585. if ([info isKindOfClass: [NSData class]])
  203586. {
  203587. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203588. if (pl != 0)
  203589. {
  203590. pl->result = (*pl->function) (pl->parameter);
  203591. pl->hasBeenExecuted = true;
  203592. }
  203593. }
  203594. else
  203595. {
  203596. jassertfalse // should never get here!
  203597. }
  203598. }
  203599. @end
  203600. BEGIN_JUCE_NAMESPACE
  203601. static JuceAppDelegate* juceAppDelegate = 0;
  203602. void MessageManager::runDispatchLoop()
  203603. {
  203604. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203605. runDispatchLoopUntil (-1);
  203606. }
  203607. void MessageManager::stopDispatchLoop()
  203608. {
  203609. exit (0); // iPhone apps get no mercy..
  203610. }
  203611. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203612. {
  203613. const ScopedAutoReleasePool pool;
  203614. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203615. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203616. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203617. while (! quitMessagePosted)
  203618. {
  203619. const ScopedAutoReleasePool pool;
  203620. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203621. beforeDate: endDate];
  203622. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203623. break;
  203624. }
  203625. return ! quitMessagePosted;
  203626. }
  203627. static CFRunLoopRef runLoop = 0;
  203628. static CFRunLoopSourceRef runLoopSource = 0;
  203629. static Array <void*, CriticalSection>* pendingMessages = 0;
  203630. static void runLoopSourceCallback (void*)
  203631. {
  203632. if (pendingMessages != 0)
  203633. {
  203634. int numDispatched = 0;
  203635. do
  203636. {
  203637. void* const nextMessage = pendingMessages->remove (0);
  203638. if (nextMessage == 0)
  203639. return;
  203640. const ScopedAutoReleasePool pool;
  203641. MessageManager::getInstance()->deliverMessage (nextMessage);
  203642. } while (++numDispatched <= 4);
  203643. CFRunLoopSourceSignal (runLoopSource);
  203644. CFRunLoopWakeUp (runLoop);
  203645. }
  203646. }
  203647. void MessageManager::doPlatformSpecificInitialisation()
  203648. {
  203649. pendingMessages = new Array <void*, CriticalSection>();
  203650. runLoop = CFRunLoopGetCurrent();
  203651. CFRunLoopSourceContext sourceContext;
  203652. zerostruct (sourceContext);
  203653. sourceContext.perform = runLoopSourceCallback;
  203654. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203655. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203656. if (juceAppDelegate == 0)
  203657. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203658. }
  203659. void MessageManager::doPlatformSpecificShutdown()
  203660. {
  203661. CFRunLoopSourceInvalidate (runLoopSource);
  203662. CFRelease (runLoopSource);
  203663. runLoopSource = 0;
  203664. if (pendingMessages != 0)
  203665. {
  203666. while (pendingMessages->size() > 0)
  203667. delete ((Message*) pendingMessages->remove(0));
  203668. deleteAndZero (pendingMessages);
  203669. }
  203670. if (juceAppDelegate != 0)
  203671. {
  203672. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203673. [juceAppDelegate release];
  203674. juceAppDelegate = 0;
  203675. }
  203676. }
  203677. bool juce_postMessageToSystemQueue (void* message)
  203678. {
  203679. if (pendingMessages != 0)
  203680. {
  203681. pendingMessages->add (message);
  203682. CFRunLoopSourceSignal (runLoopSource);
  203683. CFRunLoopWakeUp (runLoop);
  203684. }
  203685. return true;
  203686. }
  203687. void MessageManager::broadcastMessage (const String& value) throw()
  203688. {
  203689. }
  203690. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203691. void* data)
  203692. {
  203693. if (isThisTheMessageThread())
  203694. {
  203695. return (*callback) (data);
  203696. }
  203697. else
  203698. {
  203699. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203700. // deadlock because the message manager is blocked from running, so can never
  203701. // call your function..
  203702. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203703. const ScopedAutoReleasePool pool;
  203704. CallbackMessagePayload cmp;
  203705. cmp.function = callback;
  203706. cmp.parameter = data;
  203707. cmp.result = 0;
  203708. cmp.hasBeenExecuted = false;
  203709. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203710. withObject: [NSData dataWithBytesNoCopy: &cmp
  203711. length: sizeof (cmp)
  203712. freeWhenDone: NO]
  203713. waitUntilDone: YES];
  203714. return cmp.result;
  203715. }
  203716. }
  203717. #endif
  203718. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203719. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203720. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203721. // compiled on its own).
  203722. #if JUCE_INCLUDED_FILE
  203723. #if JUCE_MAC
  203724. END_JUCE_NAMESPACE
  203725. using namespace JUCE_NAMESPACE;
  203726. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203727. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203728. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203729. #else
  203730. @interface JuceFileChooserDelegate : NSObject
  203731. #endif
  203732. {
  203733. StringArray* filters;
  203734. }
  203735. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203736. - (void) dealloc;
  203737. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203738. @end
  203739. @implementation JuceFileChooserDelegate
  203740. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203741. {
  203742. [super init];
  203743. filters = filters_;
  203744. return self;
  203745. }
  203746. - (void) dealloc
  203747. {
  203748. delete filters;
  203749. [super dealloc];
  203750. }
  203751. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203752. {
  203753. const File f (nsStringToJuce (filename));
  203754. for (int i = filters->size(); --i >= 0;)
  203755. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203756. return true;
  203757. return f.isDirectory();
  203758. }
  203759. @end
  203760. BEGIN_JUCE_NAMESPACE
  203761. void FileChooser::showPlatformDialog (Array<File>& results,
  203762. const String& title,
  203763. const File& currentFileOrDirectory,
  203764. const String& filter,
  203765. bool selectsDirectory,
  203766. bool selectsFiles,
  203767. bool isSaveDialogue,
  203768. bool warnAboutOverwritingExistingFiles,
  203769. bool selectMultipleFiles,
  203770. FilePreviewComponent* extraInfoComponent)
  203771. {
  203772. const ScopedAutoReleasePool pool;
  203773. StringArray* filters = new StringArray();
  203774. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  203775. filters->trim();
  203776. filters->removeEmptyStrings();
  203777. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203778. [delegate autorelease];
  203779. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203780. : [NSOpenPanel openPanel];
  203781. [panel setTitle: juceStringToNS (title)];
  203782. if (! isSaveDialogue)
  203783. {
  203784. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203785. [openPanel setCanChooseDirectories: selectsDirectory];
  203786. [openPanel setCanChooseFiles: selectsFiles];
  203787. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203788. }
  203789. [panel setDelegate: delegate];
  203790. if (isSaveDialogue || selectsDirectory)
  203791. [panel setCanCreateDirectories: YES];
  203792. String directory, filename;
  203793. if (currentFileOrDirectory.isDirectory())
  203794. {
  203795. directory = currentFileOrDirectory.getFullPathName();
  203796. }
  203797. else
  203798. {
  203799. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203800. filename = currentFileOrDirectory.getFileName();
  203801. }
  203802. if ([panel runModalForDirectory: juceStringToNS (directory)
  203803. file: juceStringToNS (filename)]
  203804. == NSOKButton)
  203805. {
  203806. if (isSaveDialogue)
  203807. {
  203808. results.add (File (nsStringToJuce ([panel filename])));
  203809. }
  203810. else
  203811. {
  203812. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203813. NSArray* urls = [openPanel filenames];
  203814. for (unsigned int i = 0; i < [urls count]; ++i)
  203815. {
  203816. NSString* f = [urls objectAtIndex: i];
  203817. results.add (File (nsStringToJuce (f)));
  203818. }
  203819. }
  203820. }
  203821. [panel setDelegate: nil];
  203822. }
  203823. #else
  203824. void FileChooser::showPlatformDialog (Array<File>& results,
  203825. const String& title,
  203826. const File& currentFileOrDirectory,
  203827. const String& filter,
  203828. bool selectsDirectory,
  203829. bool selectsFiles,
  203830. bool isSaveDialogue,
  203831. bool warnAboutOverwritingExistingFiles,
  203832. bool selectMultipleFiles,
  203833. FilePreviewComponent* extraInfoComponent)
  203834. {
  203835. const ScopedAutoReleasePool pool;
  203836. jassertfalse //xxx to do
  203837. }
  203838. #endif
  203839. #endif
  203840. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203841. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203842. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203843. // compiled on its own).
  203844. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203845. #if JUCE_MAC
  203846. END_JUCE_NAMESPACE
  203847. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203848. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203849. {
  203850. CriticalSection* contextLock;
  203851. bool needsUpdate;
  203852. }
  203853. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203854. - (bool) makeActive;
  203855. - (void) makeInactive;
  203856. - (void) reshape;
  203857. @end
  203858. @implementation ThreadSafeNSOpenGLView
  203859. - (id) initWithFrame: (NSRect) frameRect
  203860. pixelFormat: (NSOpenGLPixelFormat*) format
  203861. {
  203862. contextLock = new CriticalSection();
  203863. self = [super initWithFrame: frameRect pixelFormat: format];
  203864. if (self != nil)
  203865. [[NSNotificationCenter defaultCenter] addObserver: self
  203866. selector: @selector (_surfaceNeedsUpdate:)
  203867. name: NSViewGlobalFrameDidChangeNotification
  203868. object: self];
  203869. return self;
  203870. }
  203871. - (void) dealloc
  203872. {
  203873. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203874. delete contextLock;
  203875. [super dealloc];
  203876. }
  203877. - (bool) makeActive
  203878. {
  203879. const ScopedLock sl (*contextLock);
  203880. if ([self openGLContext] == 0)
  203881. return false;
  203882. [[self openGLContext] makeCurrentContext];
  203883. if (needsUpdate)
  203884. {
  203885. [super update];
  203886. needsUpdate = false;
  203887. }
  203888. return true;
  203889. }
  203890. - (void) makeInactive
  203891. {
  203892. const ScopedLock sl (*contextLock);
  203893. [NSOpenGLContext clearCurrentContext];
  203894. }
  203895. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203896. {
  203897. const ScopedLock sl (*contextLock);
  203898. needsUpdate = true;
  203899. }
  203900. - (void) update
  203901. {
  203902. const ScopedLock sl (*contextLock);
  203903. needsUpdate = true;
  203904. }
  203905. - (void) reshape
  203906. {
  203907. const ScopedLock sl (*contextLock);
  203908. needsUpdate = true;
  203909. }
  203910. @end
  203911. BEGIN_JUCE_NAMESPACE
  203912. class WindowedGLContext : public OpenGLContext
  203913. {
  203914. public:
  203915. WindowedGLContext (Component* const component,
  203916. const OpenGLPixelFormat& pixelFormat_,
  203917. NSOpenGLContext* sharedContext)
  203918. : renderContext (0),
  203919. pixelFormat (pixelFormat_)
  203920. {
  203921. jassert (component != 0);
  203922. NSOpenGLPixelFormatAttribute attribs [64];
  203923. int n = 0;
  203924. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203925. attribs[n++] = NSOpenGLPFAAccelerated;
  203926. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203927. attribs[n++] = NSOpenGLPFAColorSize;
  203928. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203929. pixelFormat.greenBits,
  203930. pixelFormat.blueBits);
  203931. attribs[n++] = NSOpenGLPFAAlphaSize;
  203932. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203933. attribs[n++] = NSOpenGLPFADepthSize;
  203934. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203935. attribs[n++] = NSOpenGLPFAStencilSize;
  203936. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203937. attribs[n++] = NSOpenGLPFAAccumSize;
  203938. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203939. pixelFormat.accumulationBufferGreenBits,
  203940. pixelFormat.accumulationBufferBlueBits,
  203941. pixelFormat.accumulationBufferAlphaBits);
  203942. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203943. attribs[n++] = NSOpenGLPFASampleBuffers;
  203944. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203945. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203946. attribs[n++] = NSOpenGLPFANoRecovery;
  203947. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203948. NSOpenGLPixelFormat* format
  203949. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203950. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203951. pixelFormat: format];
  203952. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203953. shareContext: sharedContext] autorelease];
  203954. const GLint swapInterval = 1;
  203955. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203956. [view setOpenGLContext: renderContext];
  203957. [renderContext setView: view];
  203958. [format release];
  203959. viewHolder = new NSViewComponentInternal (view, component);
  203960. }
  203961. ~WindowedGLContext()
  203962. {
  203963. makeInactive();
  203964. [renderContext clearDrawable];
  203965. viewHolder = 0;
  203966. }
  203967. bool makeActive() const throw()
  203968. {
  203969. jassert (renderContext != 0);
  203970. [view makeActive];
  203971. return isActive();
  203972. }
  203973. bool makeInactive() const throw()
  203974. {
  203975. [view makeInactive];
  203976. return true;
  203977. }
  203978. bool isActive() const throw()
  203979. {
  203980. return [NSOpenGLContext currentContext] == renderContext;
  203981. }
  203982. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203983. void* getRawContext() const throw() { return renderContext; }
  203984. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203985. {
  203986. }
  203987. void swapBuffers()
  203988. {
  203989. [renderContext flushBuffer];
  203990. }
  203991. bool setSwapInterval (const int numFramesPerSwap)
  203992. {
  203993. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203994. forParameter: NSOpenGLCPSwapInterval];
  203995. return true;
  203996. }
  203997. int getSwapInterval() const
  203998. {
  203999. GLint numFrames = 0;
  204000. [renderContext getValues: &numFrames
  204001. forParameter: NSOpenGLCPSwapInterval];
  204002. return numFrames;
  204003. }
  204004. void repaint()
  204005. {
  204006. // we need to invalidate the juce view that holds this gl view, to make it
  204007. // cause a repaint callback
  204008. NSView* v = (NSView*) viewHolder->view;
  204009. NSRect r = [v frame];
  204010. // bit of a bodge here.. if we only invalidate the area of the gl component,
  204011. // it's completely covered by the NSOpenGLView, so the OS throws away the
  204012. // repaint message, thus never causing our paint() callback, and never repainting
  204013. // the comp. So invalidating just a little bit around the edge helps..
  204014. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  204015. }
  204016. void* getNativeWindowHandle() const { return viewHolder->view; }
  204017. juce_UseDebuggingNewOperator
  204018. NSOpenGLContext* renderContext;
  204019. ThreadSafeNSOpenGLView* view;
  204020. private:
  204021. OpenGLPixelFormat pixelFormat;
  204022. ScopedPointer <NSViewComponentInternal> viewHolder;
  204023. WindowedGLContext (const WindowedGLContext&);
  204024. WindowedGLContext& operator= (const WindowedGLContext&);
  204025. };
  204026. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204027. const OpenGLPixelFormat& pixelFormat,
  204028. const OpenGLContext* const contextToShareWith)
  204029. {
  204030. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  204031. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  204032. return (c->renderContext != 0) ? c.release() : 0;
  204033. }
  204034. void* OpenGLComponent::getNativeWindowHandle() const
  204035. {
  204036. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  204037. : 0;
  204038. }
  204039. void juce_glViewport (const int w, const int h)
  204040. {
  204041. glViewport (0, 0, w, h);
  204042. }
  204043. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204044. OwnedArray <OpenGLPixelFormat>& results)
  204045. {
  204046. /* GLint attribs [64];
  204047. int n = 0;
  204048. attribs[n++] = AGL_RGBA;
  204049. attribs[n++] = AGL_DOUBLEBUFFER;
  204050. attribs[n++] = AGL_ACCELERATED;
  204051. attribs[n++] = AGL_NO_RECOVERY;
  204052. attribs[n++] = AGL_NONE;
  204053. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  204054. while (p != 0)
  204055. {
  204056. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  204057. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  204058. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  204059. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  204060. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  204061. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  204062. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  204063. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  204064. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  204065. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  204066. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  204067. results.add (pf);
  204068. p = aglNextPixelFormat (p);
  204069. }*/
  204070. //jassertfalse //xxx can't see how you do this in cocoa!
  204071. }
  204072. #else
  204073. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204074. const OpenGLPixelFormat& pixelFormat,
  204075. const OpenGLContext* const contextToShareWith)
  204076. {
  204077. return 0;
  204078. }
  204079. void juce_glViewport (const int w, const int h)
  204080. {
  204081. //glViewport (0, 0, w, h);
  204082. }
  204083. #endif
  204084. #endif
  204085. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204086. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204087. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204088. // compiled on its own).
  204089. #if JUCE_INCLUDED_FILE
  204090. #if JUCE_MAC
  204091. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204092. {
  204093. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204094. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204095. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204096. [im release];
  204097. return (void*) c;
  204098. }
  204099. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204100. {
  204101. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  204102. jassert (im != 0);
  204103. if (im == 0)
  204104. return 0;
  204105. return juce_createMouseCursorFromImage (*im,
  204106. (int) (hx * im->getWidth()),
  204107. (int) (hy * im->getHeight()));
  204108. }
  204109. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204110. {
  204111. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204112. MemoryBlock mb;
  204113. if (f.getChildFile (filename).loadFileAsData (mb))
  204114. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204115. return 0;
  204116. }
  204117. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204118. {
  204119. const ScopedAutoReleasePool pool;
  204120. NSCursor* c = 0;
  204121. switch (type)
  204122. {
  204123. case MouseCursor::NormalCursor:
  204124. c = [NSCursor arrowCursor];
  204125. break;
  204126. case MouseCursor::NoCursor:
  204127. {
  204128. Image blank (Image::ARGB, 8, 8, true);
  204129. return juce_createMouseCursorFromImage (blank, 0, 0);
  204130. }
  204131. case MouseCursor::DraggingHandCursor:
  204132. c = [NSCursor openHandCursor];
  204133. break;
  204134. case MouseCursor::CopyingCursor:
  204135. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204136. case MouseCursor::WaitCursor:
  204137. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204138. break;
  204139. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204140. case MouseCursor::IBeamCursor:
  204141. c = [NSCursor IBeamCursor];
  204142. break;
  204143. case MouseCursor::PointingHandCursor:
  204144. c = [NSCursor pointingHandCursor];
  204145. break;
  204146. case MouseCursor::LeftRightResizeCursor:
  204147. c = [NSCursor resizeLeftRightCursor];
  204148. break;
  204149. case MouseCursor::LeftEdgeResizeCursor:
  204150. c = [NSCursor resizeLeftCursor];
  204151. break;
  204152. case MouseCursor::RightEdgeResizeCursor:
  204153. c = [NSCursor resizeRightCursor];
  204154. break;
  204155. case MouseCursor::UpDownResizeCursor:
  204156. case MouseCursor::TopEdgeResizeCursor:
  204157. case MouseCursor::BottomEdgeResizeCursor:
  204158. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204159. case MouseCursor::TopLeftCornerResizeCursor:
  204160. case MouseCursor::BottomRightCornerResizeCursor:
  204161. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204162. case MouseCursor::TopRightCornerResizeCursor:
  204163. case MouseCursor::BottomLeftCornerResizeCursor:
  204164. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204165. case MouseCursor::UpDownLeftRightResizeCursor:
  204166. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204167. case MouseCursor::CrosshairCursor:
  204168. c = [NSCursor crosshairCursor];
  204169. break;
  204170. }
  204171. [c retain];
  204172. return (void*) c;
  204173. }
  204174. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204175. {
  204176. NSCursor* c = (NSCursor*) cursorHandle;
  204177. [c release];
  204178. }
  204179. void MouseCursor::showInAllWindows() const throw()
  204180. {
  204181. showInWindow (0);
  204182. }
  204183. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204184. {
  204185. NSCursor* const c = (NSCursor*) getHandle();
  204186. [c set];
  204187. }
  204188. #else
  204189. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204190. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204191. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204192. void MouseCursor::showInAllWindows() const throw() {}
  204193. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204194. #endif
  204195. #endif
  204196. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204197. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204198. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204199. // compiled on its own).
  204200. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204201. #if JUCE_MAC
  204202. END_JUCE_NAMESPACE
  204203. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204204. @interface DownloadClickDetector : NSObject
  204205. {
  204206. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204207. }
  204208. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204209. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204210. request: (NSURLRequest*) request
  204211. frame: (WebFrame*) frame
  204212. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204213. @end
  204214. @implementation DownloadClickDetector
  204215. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204216. {
  204217. [super init];
  204218. ownerComponent = ownerComponent_;
  204219. return self;
  204220. }
  204221. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204222. request: (NSURLRequest*) request
  204223. frame: (WebFrame*) frame
  204224. decisionListener: (id <WebPolicyDecisionListener>) listener
  204225. {
  204226. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204227. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204228. [listener use];
  204229. else
  204230. [listener ignore];
  204231. }
  204232. @end
  204233. BEGIN_JUCE_NAMESPACE
  204234. class WebBrowserComponentInternal : public NSViewComponent
  204235. {
  204236. public:
  204237. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204238. {
  204239. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204240. frameName: @""
  204241. groupName: @""];
  204242. setView (webView);
  204243. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204244. [webView setPolicyDelegate: clickListener];
  204245. }
  204246. ~WebBrowserComponentInternal()
  204247. {
  204248. [webView setPolicyDelegate: nil];
  204249. [clickListener release];
  204250. setView (0);
  204251. }
  204252. void goToURL (const String& url,
  204253. const StringArray* headers,
  204254. const MemoryBlock* postData)
  204255. {
  204256. NSMutableURLRequest* r
  204257. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204258. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204259. timeoutInterval: 30.0];
  204260. if (postData != 0 && postData->getSize() > 0)
  204261. {
  204262. [r setHTTPMethod: @"POST"];
  204263. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204264. length: postData->getSize()]];
  204265. }
  204266. if (headers != 0)
  204267. {
  204268. for (int i = 0; i < headers->size(); ++i)
  204269. {
  204270. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204271. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204272. [r setValue: juceStringToNS (headerValue)
  204273. forHTTPHeaderField: juceStringToNS (headerName)];
  204274. }
  204275. }
  204276. stop();
  204277. [[webView mainFrame] loadRequest: r];
  204278. }
  204279. void goBack()
  204280. {
  204281. [webView goBack];
  204282. }
  204283. void goForward()
  204284. {
  204285. [webView goForward];
  204286. }
  204287. void stop()
  204288. {
  204289. [webView stopLoading: nil];
  204290. }
  204291. void refresh()
  204292. {
  204293. [webView reload: nil];
  204294. }
  204295. private:
  204296. WebView* webView;
  204297. DownloadClickDetector* clickListener;
  204298. };
  204299. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204300. : browser (0),
  204301. blankPageShown (false),
  204302. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204303. {
  204304. setOpaque (true);
  204305. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204306. }
  204307. WebBrowserComponent::~WebBrowserComponent()
  204308. {
  204309. deleteAndZero (browser);
  204310. }
  204311. void WebBrowserComponent::goToURL (const String& url,
  204312. const StringArray* headers,
  204313. const MemoryBlock* postData)
  204314. {
  204315. lastURL = url;
  204316. lastHeaders.clear();
  204317. if (headers != 0)
  204318. lastHeaders = *headers;
  204319. lastPostData.setSize (0);
  204320. if (postData != 0)
  204321. lastPostData = *postData;
  204322. blankPageShown = false;
  204323. browser->goToURL (url, headers, postData);
  204324. }
  204325. void WebBrowserComponent::stop()
  204326. {
  204327. browser->stop();
  204328. }
  204329. void WebBrowserComponent::goBack()
  204330. {
  204331. lastURL = String::empty;
  204332. blankPageShown = false;
  204333. browser->goBack();
  204334. }
  204335. void WebBrowserComponent::goForward()
  204336. {
  204337. lastURL = String::empty;
  204338. browser->goForward();
  204339. }
  204340. void WebBrowserComponent::refresh()
  204341. {
  204342. browser->refresh();
  204343. }
  204344. void WebBrowserComponent::paint (Graphics& g)
  204345. {
  204346. }
  204347. void WebBrowserComponent::checkWindowAssociation()
  204348. {
  204349. if (isShowing())
  204350. {
  204351. if (blankPageShown)
  204352. goBack();
  204353. }
  204354. else
  204355. {
  204356. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204357. {
  204358. // when the component becomes invisible, some stuff like flash
  204359. // carries on playing audio, so we need to force it onto a blank
  204360. // page to avoid this, (and send it back when it's made visible again).
  204361. blankPageShown = true;
  204362. browser->goToURL ("about:blank", 0, 0);
  204363. }
  204364. }
  204365. }
  204366. void WebBrowserComponent::reloadLastURL()
  204367. {
  204368. if (lastURL.isNotEmpty())
  204369. {
  204370. goToURL (lastURL, &lastHeaders, &lastPostData);
  204371. lastURL = String::empty;
  204372. }
  204373. }
  204374. void WebBrowserComponent::parentHierarchyChanged()
  204375. {
  204376. checkWindowAssociation();
  204377. }
  204378. void WebBrowserComponent::resized()
  204379. {
  204380. browser->setSize (getWidth(), getHeight());
  204381. }
  204382. void WebBrowserComponent::visibilityChanged()
  204383. {
  204384. checkWindowAssociation();
  204385. }
  204386. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204387. {
  204388. return true;
  204389. }
  204390. #else
  204391. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204392. {
  204393. }
  204394. WebBrowserComponent::~WebBrowserComponent()
  204395. {
  204396. }
  204397. void WebBrowserComponent::goToURL (const String& url,
  204398. const StringArray* headers,
  204399. const MemoryBlock* postData)
  204400. {
  204401. }
  204402. void WebBrowserComponent::stop()
  204403. {
  204404. }
  204405. void WebBrowserComponent::goBack()
  204406. {
  204407. }
  204408. void WebBrowserComponent::goForward()
  204409. {
  204410. }
  204411. void WebBrowserComponent::refresh()
  204412. {
  204413. }
  204414. void WebBrowserComponent::paint (Graphics& g)
  204415. {
  204416. }
  204417. void WebBrowserComponent::checkWindowAssociation()
  204418. {
  204419. }
  204420. void WebBrowserComponent::reloadLastURL()
  204421. {
  204422. }
  204423. void WebBrowserComponent::parentHierarchyChanged()
  204424. {
  204425. }
  204426. void WebBrowserComponent::resized()
  204427. {
  204428. }
  204429. void WebBrowserComponent::visibilityChanged()
  204430. {
  204431. }
  204432. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204433. {
  204434. return true;
  204435. }
  204436. #endif
  204437. #endif
  204438. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204439. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204440. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204441. // compiled on its own).
  204442. #if JUCE_INCLUDED_FILE
  204443. class IPhoneAudioIODevice : public AudioIODevice
  204444. {
  204445. public:
  204446. IPhoneAudioIODevice (const String& deviceName)
  204447. : AudioIODevice (deviceName, T("Audio")),
  204448. audioUnit (0),
  204449. isRunning (false),
  204450. callback (0),
  204451. actualBufferSize (0),
  204452. floatData (1, 2)
  204453. {
  204454. numInputChannels = 2;
  204455. numOutputChannels = 2;
  204456. preferredBufferSize = 0;
  204457. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204458. updateDeviceInfo();
  204459. }
  204460. ~IPhoneAudioIODevice()
  204461. {
  204462. close();
  204463. }
  204464. const StringArray getOutputChannelNames()
  204465. {
  204466. StringArray s;
  204467. s.add ("Left");
  204468. s.add ("Right");
  204469. return s;
  204470. }
  204471. const StringArray getInputChannelNames()
  204472. {
  204473. StringArray s;
  204474. if (audioInputIsAvailable)
  204475. {
  204476. s.add ("Left");
  204477. s.add ("Right");
  204478. }
  204479. return s;
  204480. }
  204481. int getNumSampleRates()
  204482. {
  204483. return 1;
  204484. }
  204485. double getSampleRate (int index)
  204486. {
  204487. return sampleRate;
  204488. }
  204489. int getNumBufferSizesAvailable()
  204490. {
  204491. return 1;
  204492. }
  204493. int getBufferSizeSamples (int index)
  204494. {
  204495. return getDefaultBufferSize();
  204496. }
  204497. int getDefaultBufferSize()
  204498. {
  204499. return 1024;
  204500. }
  204501. const String open (const BitArray& inputChannels,
  204502. const BitArray& outputChannels,
  204503. double sampleRate,
  204504. int bufferSize)
  204505. {
  204506. close();
  204507. lastError = String::empty;
  204508. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204509. // xxx set up channel mapping
  204510. activeOutputChans = outputChannels;
  204511. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204512. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204513. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204514. activeInputChans = inputChannels;
  204515. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204516. numInputChannels = activeInputChans.countNumberOfSetBits();
  204517. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204518. AudioSessionSetActive (true);
  204519. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204520. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204521. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204522. fixAudioRouteIfSetToReceiver();
  204523. updateDeviceInfo();
  204524. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204525. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204526. actualBufferSize = preferredBufferSize;
  204527. prepareFloatBuffers();
  204528. isRunning = true;
  204529. propertyChanged (0, 0, 0); // creates and starts the AU
  204530. lastError = audioUnit != 0 ? String::empty
  204531. : T("Couldn't open the device");
  204532. return lastError;
  204533. }
  204534. void close()
  204535. {
  204536. if (isRunning)
  204537. {
  204538. isRunning = false;
  204539. AudioSessionSetActive (false);
  204540. if (audioUnit != 0)
  204541. {
  204542. AudioComponentInstanceDispose (audioUnit);
  204543. audioUnit = 0;
  204544. }
  204545. }
  204546. }
  204547. bool isOpen()
  204548. {
  204549. return isRunning;
  204550. }
  204551. int getCurrentBufferSizeSamples()
  204552. {
  204553. return actualBufferSize;
  204554. }
  204555. double getCurrentSampleRate()
  204556. {
  204557. return sampleRate;
  204558. }
  204559. int getCurrentBitDepth()
  204560. {
  204561. return 16;
  204562. }
  204563. const BitArray getActiveOutputChannels() const
  204564. {
  204565. return activeOutputChans;
  204566. }
  204567. const BitArray getActiveInputChannels() const
  204568. {
  204569. return activeInputChans;
  204570. }
  204571. int getOutputLatencyInSamples()
  204572. {
  204573. return 0; //xxx
  204574. }
  204575. int getInputLatencyInSamples()
  204576. {
  204577. return 0; //xxx
  204578. }
  204579. void start (AudioIODeviceCallback* callback_)
  204580. {
  204581. if (isRunning && callback != callback_)
  204582. {
  204583. if (callback_ != 0)
  204584. callback_->audioDeviceAboutToStart (this);
  204585. const ScopedLock sl (callbackLock);
  204586. callback = callback_;
  204587. }
  204588. }
  204589. void stop()
  204590. {
  204591. if (isRunning)
  204592. {
  204593. AudioIODeviceCallback* lastCallback;
  204594. {
  204595. const ScopedLock sl (callbackLock);
  204596. lastCallback = callback;
  204597. callback = 0;
  204598. }
  204599. if (lastCallback != 0)
  204600. lastCallback->audioDeviceStopped();
  204601. }
  204602. }
  204603. bool isPlaying()
  204604. {
  204605. return isRunning && callback != 0;
  204606. }
  204607. const String getLastError()
  204608. {
  204609. return lastError;
  204610. }
  204611. private:
  204612. CriticalSection callbackLock;
  204613. Float64 sampleRate;
  204614. int numInputChannels, numOutputChannels;
  204615. int preferredBufferSize;
  204616. int actualBufferSize;
  204617. bool isRunning;
  204618. String lastError;
  204619. AudioStreamBasicDescription format;
  204620. AudioUnit audioUnit;
  204621. UInt32 audioInputIsAvailable;
  204622. AudioIODeviceCallback* callback;
  204623. BitArray activeOutputChans, activeInputChans;
  204624. AudioSampleBuffer floatData;
  204625. float* inputChannels[3];
  204626. float* outputChannels[3];
  204627. bool monoInputChannelNumber, monoOutputChannelNumber;
  204628. void prepareFloatBuffers()
  204629. {
  204630. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204631. zerostruct (inputChannels);
  204632. zerostruct (outputChannels);
  204633. for (int i = 0; i < numInputChannels; ++i)
  204634. inputChannels[i] = floatData.getSampleData (i);
  204635. for (int i = 0; i < numOutputChannels; ++i)
  204636. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204637. }
  204638. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204639. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204640. {
  204641. OSStatus err = noErr;
  204642. if (audioInputIsAvailable)
  204643. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204644. const ScopedLock sl (callbackLock);
  204645. if (callback != 0)
  204646. {
  204647. if (audioInputIsAvailable && numInputChannels > 0)
  204648. {
  204649. short* shortData = (short*) ioData->mBuffers[0].mData;
  204650. if (numInputChannels >= 2)
  204651. {
  204652. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204653. {
  204654. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204655. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204656. }
  204657. }
  204658. else
  204659. {
  204660. if (monoInputChannelNumber > 0)
  204661. ++shortData;
  204662. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204663. {
  204664. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204665. ++shortData;
  204666. }
  204667. }
  204668. }
  204669. else
  204670. {
  204671. for (int i = numInputChannels; --i >= 0;)
  204672. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204673. }
  204674. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204675. outputChannels, numOutputChannels,
  204676. (int) inNumberFrames);
  204677. short* shortData = (short*) ioData->mBuffers[0].mData;
  204678. int n = 0;
  204679. if (numOutputChannels >= 2)
  204680. {
  204681. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204682. {
  204683. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204684. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204685. }
  204686. }
  204687. else if (numOutputChannels == 1)
  204688. {
  204689. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204690. {
  204691. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204692. shortData [n++] = s;
  204693. shortData [n++] = s;
  204694. }
  204695. }
  204696. else
  204697. {
  204698. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204699. }
  204700. }
  204701. else
  204702. {
  204703. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204704. }
  204705. return err;
  204706. }
  204707. void updateDeviceInfo()
  204708. {
  204709. UInt32 size = sizeof (sampleRate);
  204710. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204711. size = sizeof (audioInputIsAvailable);
  204712. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204713. }
  204714. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204715. {
  204716. if (! isRunning)
  204717. return;
  204718. if (inPropertyValue != 0)
  204719. {
  204720. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204721. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204722. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204723. SInt32 routeChangeReason;
  204724. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204725. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204726. fixAudioRouteIfSetToReceiver();
  204727. }
  204728. updateDeviceInfo();
  204729. createAudioUnit();
  204730. AudioSessionSetActive (true);
  204731. if (audioUnit != 0)
  204732. {
  204733. UInt32 formatSize = sizeof (format);
  204734. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204735. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204736. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204737. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204738. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204739. AudioOutputUnitStart (audioUnit);
  204740. }
  204741. }
  204742. void interruptionListener (UInt32 inInterruption)
  204743. {
  204744. if (inInterruption == kAudioSessionEndInterruption)
  204745. {
  204746. isRunning = true;
  204747. AudioSessionSetActive (true);
  204748. AudioOutputUnitStart (audioUnit);
  204749. }
  204750. }
  204751. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204752. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204753. {
  204754. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204755. }
  204756. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204757. {
  204758. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204759. }
  204760. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204761. {
  204762. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204763. }
  204764. void resetFormat (const int numChannels)
  204765. {
  204766. memset (&format, 0, sizeof (format));
  204767. format.mFormatID = kAudioFormatLinearPCM;
  204768. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204769. format.mBitsPerChannel = 8 * sizeof (short);
  204770. format.mChannelsPerFrame = 2;
  204771. format.mFramesPerPacket = 1;
  204772. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204773. }
  204774. bool createAudioUnit()
  204775. {
  204776. if (audioUnit != 0)
  204777. {
  204778. AudioComponentInstanceDispose (audioUnit);
  204779. audioUnit = 0;
  204780. }
  204781. resetFormat (2);
  204782. AudioComponentDescription desc;
  204783. desc.componentType = kAudioUnitType_Output;
  204784. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204785. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204786. desc.componentFlags = 0;
  204787. desc.componentFlagsMask = 0;
  204788. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204789. AudioComponentInstanceNew (comp, &audioUnit);
  204790. if (audioUnit == 0)
  204791. return false;
  204792. const UInt32 one = 1;
  204793. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204794. AudioChannelLayout layout;
  204795. layout.mChannelBitmap = 0;
  204796. layout.mNumberChannelDescriptions = 0;
  204797. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204798. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204799. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204800. AURenderCallbackStruct inputProc;
  204801. inputProc.inputProc = processStatic;
  204802. inputProc.inputProcRefCon = this;
  204803. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204804. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204805. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204806. AudioUnitInitialize (audioUnit);
  204807. return true;
  204808. }
  204809. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204810. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204811. static void fixAudioRouteIfSetToReceiver()
  204812. {
  204813. CFStringRef audioRoute = 0;
  204814. UInt32 propertySize = sizeof (audioRoute);
  204815. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204816. {
  204817. NSString* route = (NSString*) audioRoute;
  204818. //DBG ("audio route: " + nsStringToJuce (route));
  204819. if ([route hasPrefix: @"Receiver"])
  204820. {
  204821. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204822. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204823. }
  204824. CFRelease (audioRoute);
  204825. }
  204826. }
  204827. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204828. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204829. };
  204830. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204831. {
  204832. public:
  204833. IPhoneAudioIODeviceType()
  204834. : AudioIODeviceType (T("iPhone Audio"))
  204835. {
  204836. }
  204837. ~IPhoneAudioIODeviceType()
  204838. {
  204839. }
  204840. void scanForDevices()
  204841. {
  204842. }
  204843. const StringArray getDeviceNames (const bool wantInputNames) const
  204844. {
  204845. StringArray s;
  204846. s.add ("iPhone Audio");
  204847. return s;
  204848. }
  204849. int getDefaultDeviceIndex (const bool forInput) const
  204850. {
  204851. return 0;
  204852. }
  204853. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  204854. {
  204855. return device != 0 ? 0 : -1;
  204856. }
  204857. bool hasSeparateInputsAndOutputs() const { return false; }
  204858. AudioIODevice* createDevice (const String& outputDeviceName,
  204859. const String& inputDeviceName)
  204860. {
  204861. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204862. {
  204863. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204864. : inputDeviceName);
  204865. }
  204866. return 0;
  204867. }
  204868. juce_UseDebuggingNewOperator
  204869. private:
  204870. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204871. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204872. };
  204873. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204874. {
  204875. return new IPhoneAudioIODeviceType();
  204876. }
  204877. #endif
  204878. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204879. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204880. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204881. // compiled on its own).
  204882. #if JUCE_INCLUDED_FILE
  204883. #if JUCE_MAC
  204884. #undef log
  204885. #define log(a) Logger::writeToLog(a)
  204886. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204887. {
  204888. if (err == noErr)
  204889. return true;
  204890. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  204891. jassertfalse
  204892. return false;
  204893. }
  204894. #undef OK
  204895. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204896. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204897. {
  204898. String result;
  204899. CFStringRef str = 0;
  204900. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204901. if (str != 0)
  204902. {
  204903. result = PlatformUtilities::cfStringToJuceString (str);
  204904. CFRelease (str);
  204905. str = 0;
  204906. }
  204907. MIDIEntityRef entity = 0;
  204908. MIDIEndpointGetEntity (endpoint, &entity);
  204909. if (entity == 0)
  204910. return result; // probably virtual
  204911. if (result.isEmpty())
  204912. {
  204913. // endpoint name has zero length - try the entity
  204914. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204915. if (str != 0)
  204916. {
  204917. result += PlatformUtilities::cfStringToJuceString (str);
  204918. CFRelease (str);
  204919. str = 0;
  204920. }
  204921. }
  204922. // now consider the device's name
  204923. MIDIDeviceRef device = 0;
  204924. MIDIEntityGetDevice (entity, &device);
  204925. if (device == 0)
  204926. return result;
  204927. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204928. if (str != 0)
  204929. {
  204930. const String s (PlatformUtilities::cfStringToJuceString (str));
  204931. CFRelease (str);
  204932. // if an external device has only one entity, throw away
  204933. // the endpoint name and just use the device name
  204934. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204935. {
  204936. result = s;
  204937. }
  204938. else if (! result.startsWithIgnoreCase (s))
  204939. {
  204940. // prepend the device name to the entity name
  204941. result = (s + T(" ") + result).trimEnd();
  204942. }
  204943. }
  204944. return result;
  204945. }
  204946. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204947. {
  204948. String result;
  204949. // Does the endpoint have connections?
  204950. CFDataRef connections = 0;
  204951. int numConnections = 0;
  204952. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204953. if (connections != 0)
  204954. {
  204955. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204956. if (numConnections > 0)
  204957. {
  204958. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204959. for (int i = 0; i < numConnections; ++i, ++pid)
  204960. {
  204961. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204962. MIDIObjectRef connObject;
  204963. MIDIObjectType connObjectType;
  204964. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204965. if (err == noErr)
  204966. {
  204967. String s;
  204968. if (connObjectType == kMIDIObjectType_ExternalSource
  204969. || connObjectType == kMIDIObjectType_ExternalDestination)
  204970. {
  204971. // Connected to an external device's endpoint (10.3 and later).
  204972. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204973. }
  204974. else
  204975. {
  204976. // Connected to an external device (10.2) (or something else, catch-all)
  204977. CFStringRef str = 0;
  204978. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204979. if (str != 0)
  204980. {
  204981. s = PlatformUtilities::cfStringToJuceString (str);
  204982. CFRelease (str);
  204983. }
  204984. }
  204985. if (s.isNotEmpty())
  204986. {
  204987. if (result.isNotEmpty())
  204988. result += (", ");
  204989. result += s;
  204990. }
  204991. }
  204992. }
  204993. }
  204994. CFRelease (connections);
  204995. }
  204996. if (result.isNotEmpty())
  204997. return result;
  204998. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204999. return getEndpointName (endpoint, false);
  205000. }
  205001. const StringArray MidiOutput::getDevices()
  205002. {
  205003. StringArray s;
  205004. const ItemCount num = MIDIGetNumberOfDestinations();
  205005. for (ItemCount i = 0; i < num; ++i)
  205006. {
  205007. MIDIEndpointRef dest = MIDIGetDestination (i);
  205008. if (dest != 0)
  205009. {
  205010. String name (getConnectedEndpointName (dest));
  205011. if (name.isEmpty())
  205012. name = "<error>";
  205013. s.add (name);
  205014. }
  205015. else
  205016. {
  205017. s.add ("<error>");
  205018. }
  205019. }
  205020. return s;
  205021. }
  205022. int MidiOutput::getDefaultDeviceIndex()
  205023. {
  205024. return 0;
  205025. }
  205026. static MIDIClientRef globalMidiClient;
  205027. static bool hasGlobalClientBeenCreated = false;
  205028. static bool makeSureClientExists()
  205029. {
  205030. if (! hasGlobalClientBeenCreated)
  205031. {
  205032. String name (T("JUCE"));
  205033. if (JUCEApplication::getInstance() != 0)
  205034. name = JUCEApplication::getInstance()->getApplicationName();
  205035. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205036. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205037. CFRelease (appName);
  205038. }
  205039. return hasGlobalClientBeenCreated;
  205040. }
  205041. class MidiPortAndEndpoint
  205042. {
  205043. public:
  205044. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205045. : port (port_), endPoint (endPoint_)
  205046. {
  205047. }
  205048. ~MidiPortAndEndpoint()
  205049. {
  205050. if (port != 0)
  205051. MIDIPortDispose (port);
  205052. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205053. MIDIEndpointDispose (endPoint);
  205054. }
  205055. MIDIPortRef port;
  205056. MIDIEndpointRef endPoint;
  205057. };
  205058. MidiOutput* MidiOutput::openDevice (int index)
  205059. {
  205060. MidiOutput* mo = 0;
  205061. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205062. {
  205063. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205064. CFStringRef pname;
  205065. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205066. {
  205067. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205068. if (makeSureClientExists())
  205069. {
  205070. MIDIPortRef port;
  205071. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205072. {
  205073. mo = new MidiOutput();
  205074. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205075. }
  205076. }
  205077. CFRelease (pname);
  205078. }
  205079. }
  205080. return mo;
  205081. }
  205082. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205083. {
  205084. MidiOutput* mo = 0;
  205085. if (makeSureClientExists())
  205086. {
  205087. MIDIEndpointRef endPoint;
  205088. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205089. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205090. {
  205091. mo = new MidiOutput();
  205092. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205093. }
  205094. CFRelease (name);
  205095. }
  205096. return mo;
  205097. }
  205098. MidiOutput::~MidiOutput()
  205099. {
  205100. delete (MidiPortAndEndpoint*) internal;
  205101. }
  205102. void MidiOutput::reset()
  205103. {
  205104. }
  205105. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205106. {
  205107. return false;
  205108. }
  205109. void MidiOutput::setVolume (float leftVol, float rightVol)
  205110. {
  205111. }
  205112. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205113. {
  205114. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205115. if (message.isSysEx())
  205116. {
  205117. const int maxPacketSize = 256;
  205118. int pos = 0, bytesLeft = message.getRawDataSize();
  205119. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205120. HeapBlock <MIDIPacketList> packets;
  205121. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205122. packets->numPackets = numPackets;
  205123. MIDIPacket* p = packets->packet;
  205124. for (int i = 0; i < numPackets; ++i)
  205125. {
  205126. p->timeStamp = 0;
  205127. p->length = jmin (maxPacketSize, bytesLeft);
  205128. memcpy (p->data, message.getRawData() + pos, p->length);
  205129. pos += p->length;
  205130. bytesLeft -= p->length;
  205131. p = MIDIPacketNext (p);
  205132. }
  205133. if (mpe->port != 0)
  205134. MIDISend (mpe->port, mpe->endPoint, packets);
  205135. else
  205136. MIDIReceived (mpe->endPoint, packets);
  205137. }
  205138. else
  205139. {
  205140. MIDIPacketList packets;
  205141. packets.numPackets = 1;
  205142. packets.packet[0].timeStamp = 0;
  205143. packets.packet[0].length = message.getRawDataSize();
  205144. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205145. if (mpe->port != 0)
  205146. MIDISend (mpe->port, mpe->endPoint, &packets);
  205147. else
  205148. MIDIReceived (mpe->endPoint, &packets);
  205149. }
  205150. }
  205151. const StringArray MidiInput::getDevices()
  205152. {
  205153. StringArray s;
  205154. const ItemCount num = MIDIGetNumberOfSources();
  205155. for (ItemCount i = 0; i < num; ++i)
  205156. {
  205157. MIDIEndpointRef source = MIDIGetSource (i);
  205158. if (source != 0)
  205159. {
  205160. String name (getConnectedEndpointName (source));
  205161. if (name.isEmpty())
  205162. name = "<error>";
  205163. s.add (name);
  205164. }
  205165. else
  205166. {
  205167. s.add ("<error>");
  205168. }
  205169. }
  205170. return s;
  205171. }
  205172. int MidiInput::getDefaultDeviceIndex()
  205173. {
  205174. return 0;
  205175. }
  205176. struct MidiPortAndCallback
  205177. {
  205178. MidiInput* input;
  205179. MidiPortAndEndpoint* portAndEndpoint;
  205180. MidiInputCallback* callback;
  205181. MemoryBlock pendingData;
  205182. int pendingBytes;
  205183. double pendingDataTime;
  205184. bool active;
  205185. void processSysex (const uint8*& d, int& size, const double time)
  205186. {
  205187. if (*d == 0xf0)
  205188. {
  205189. pendingBytes = 0;
  205190. pendingDataTime = time;
  205191. }
  205192. pendingData.ensureSize (pendingBytes + size, false);
  205193. uint8* totalMessage = (uint8*) pendingData.getData();
  205194. uint8* dest = totalMessage + pendingBytes;
  205195. while (size > 0)
  205196. {
  205197. if (pendingBytes > 0 && *d >= 0x80)
  205198. {
  205199. if (*d >= 0xfa || *d == 0xf8)
  205200. {
  205201. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205202. ++d;
  205203. --size;
  205204. }
  205205. else
  205206. {
  205207. if (*d == 0xf7)
  205208. {
  205209. *dest++ = *d++;
  205210. pendingBytes++;
  205211. --size;
  205212. }
  205213. break;
  205214. }
  205215. }
  205216. else
  205217. {
  205218. *dest++ = *d++;
  205219. pendingBytes++;
  205220. --size;
  205221. }
  205222. }
  205223. if (totalMessage [pendingBytes - 1] == 0xf7)
  205224. {
  205225. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205226. pendingBytes = 0;
  205227. }
  205228. else
  205229. {
  205230. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205231. }
  205232. }
  205233. };
  205234. namespace CoreMidiCallbacks
  205235. {
  205236. static CriticalSection callbackLock;
  205237. static VoidArray activeCallbacks;
  205238. }
  205239. static void midiInputProc (const MIDIPacketList* pktlist,
  205240. void* readProcRefCon,
  205241. void* srcConnRefCon)
  205242. {
  205243. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205244. const double originalTime = time;
  205245. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205246. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205247. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205248. {
  205249. const MIDIPacket* packet = &pktlist->packet[0];
  205250. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205251. {
  205252. const uint8* d = (const uint8*) (packet->data);
  205253. int size = packet->length;
  205254. while (size > 0)
  205255. {
  205256. time = originalTime;
  205257. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205258. {
  205259. mpc->processSysex (d, size, time);
  205260. }
  205261. else
  205262. {
  205263. int used = 0;
  205264. const MidiMessage m (d, size, used, 0, time);
  205265. if (used <= 0)
  205266. {
  205267. jassertfalse // malformed midi message
  205268. break;
  205269. }
  205270. else
  205271. {
  205272. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205273. }
  205274. size -= used;
  205275. d += used;
  205276. }
  205277. }
  205278. packet = MIDIPacketNext (packet);
  205279. }
  205280. }
  205281. }
  205282. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205283. {
  205284. MidiInput* mi = 0;
  205285. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205286. {
  205287. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205288. if (endPoint != 0)
  205289. {
  205290. CFStringRef pname;
  205291. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205292. {
  205293. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205294. if (makeSureClientExists())
  205295. {
  205296. MIDIPortRef port;
  205297. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205298. mpc->active = false;
  205299. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205300. {
  205301. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205302. {
  205303. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205304. mpc->callback = callback;
  205305. mpc->pendingBytes = 0;
  205306. mpc->pendingData.ensureSize (128);
  205307. mi = new MidiInput (getDevices() [index]);
  205308. mpc->input = mi;
  205309. mi->internal = (void*) mpc;
  205310. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205311. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205312. }
  205313. else
  205314. {
  205315. OK (MIDIPortDispose (port));
  205316. }
  205317. }
  205318. }
  205319. }
  205320. CFRelease (pname);
  205321. }
  205322. }
  205323. return mi;
  205324. }
  205325. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205326. {
  205327. MidiInput* mi = 0;
  205328. if (makeSureClientExists())
  205329. {
  205330. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205331. mpc->active = false;
  205332. MIDIEndpointRef endPoint;
  205333. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205334. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205335. {
  205336. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205337. mpc->callback = callback;
  205338. mpc->pendingBytes = 0;
  205339. mpc->pendingData.ensureSize (128);
  205340. mi = new MidiInput (deviceName);
  205341. mpc->input = mi;
  205342. mi->internal = (void*) mpc;
  205343. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205344. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205345. }
  205346. CFRelease (name);
  205347. }
  205348. return mi;
  205349. }
  205350. MidiInput::MidiInput (const String& name_)
  205351. : name (name_)
  205352. {
  205353. }
  205354. MidiInput::~MidiInput()
  205355. {
  205356. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205357. mpc->active = false;
  205358. {
  205359. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205360. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205361. }
  205362. if (mpc->portAndEndpoint->port != 0)
  205363. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205364. delete mpc->portAndEndpoint;
  205365. delete mpc;
  205366. }
  205367. void MidiInput::start()
  205368. {
  205369. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205370. ((MidiPortAndCallback*) internal)->active = true;
  205371. }
  205372. void MidiInput::stop()
  205373. {
  205374. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205375. ((MidiPortAndCallback*) internal)->active = false;
  205376. }
  205377. #undef log
  205378. #else
  205379. MidiOutput::~MidiOutput()
  205380. {
  205381. }
  205382. void MidiOutput::reset()
  205383. {
  205384. }
  205385. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205386. {
  205387. return false;
  205388. }
  205389. void MidiOutput::setVolume (float leftVol, float rightVol)
  205390. {
  205391. }
  205392. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205393. {
  205394. }
  205395. const StringArray MidiOutput::getDevices()
  205396. {
  205397. return StringArray();
  205398. }
  205399. MidiOutput* MidiOutput::openDevice (int index)
  205400. {
  205401. return 0;
  205402. }
  205403. const StringArray MidiInput::getDevices()
  205404. {
  205405. return StringArray();
  205406. }
  205407. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205408. {
  205409. return 0;
  205410. }
  205411. #endif
  205412. #endif
  205413. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205414. #else
  205415. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205416. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205417. // compiled on its own).
  205418. #if JUCE_INCLUDED_FILE
  205419. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205420. #define SUPPORT_10_4_FONTS 1
  205421. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205422. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205423. #define SUPPORT_ONLY_10_4_FONTS 1
  205424. #endif
  205425. END_JUCE_NAMESPACE
  205426. @interface NSFont (PrivateHack)
  205427. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205428. @end
  205429. BEGIN_JUCE_NAMESPACE
  205430. #endif
  205431. class MacTypeface : public Typeface
  205432. {
  205433. public:
  205434. MacTypeface (const Font& font)
  205435. : Typeface (font.getTypefaceName())
  205436. {
  205437. const ScopedAutoReleasePool pool;
  205438. renderingTransform = CGAffineTransformIdentity;
  205439. bool needsItalicTransform = false;
  205440. #if JUCE_IPHONE
  205441. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205442. if (font.isItalic() || font.isBold())
  205443. {
  205444. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205445. for (NSString* i in familyFonts)
  205446. {
  205447. const String fn (nsStringToJuce (i));
  205448. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205449. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205450. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205451. || afterDash.containsIgnoreCase (T("italic"))
  205452. || fn.endsWithIgnoreCase (T("oblique"))
  205453. || fn.endsWithIgnoreCase (T("italic"));
  205454. if (probablyBold == font.isBold()
  205455. && probablyItalic == font.isItalic())
  205456. {
  205457. fontName = i;
  205458. needsItalicTransform = false;
  205459. break;
  205460. }
  205461. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205462. {
  205463. fontName = i;
  205464. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205465. }
  205466. }
  205467. if (needsItalicTransform)
  205468. renderingTransform.c = 0.15f;
  205469. }
  205470. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205471. const int ascender = abs (CGFontGetAscent (fontRef));
  205472. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205473. ascent = ascender / totalHeight;
  205474. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205475. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205476. #else
  205477. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205478. if (font.isItalic())
  205479. {
  205480. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205481. toHaveTrait: NSItalicFontMask];
  205482. if (newFont == nsFont)
  205483. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205484. nsFont = newFont;
  205485. }
  205486. if (font.isBold())
  205487. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205488. [nsFont retain];
  205489. ascent = fabsf ((float) [nsFont ascender]);
  205490. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205491. ascent /= totalSize;
  205492. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205493. if (needsItalicTransform)
  205494. {
  205495. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205496. renderingTransform.c = 0.15f;
  205497. }
  205498. #if SUPPORT_ONLY_10_4_FONTS
  205499. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205500. if (atsFont == 0)
  205501. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205502. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205503. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205504. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205505. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205506. #else
  205507. #if SUPPORT_10_4_FONTS
  205508. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205509. {
  205510. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205511. if (atsFont == 0)
  205512. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205513. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205514. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205515. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205516. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205517. }
  205518. else
  205519. #endif
  205520. {
  205521. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205522. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205523. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205524. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205525. }
  205526. #endif
  205527. #endif
  205528. }
  205529. ~MacTypeface()
  205530. {
  205531. #if ! JUCE_IPHONE
  205532. [nsFont release];
  205533. #endif
  205534. if (fontRef != 0)
  205535. CGFontRelease (fontRef);
  205536. }
  205537. float getAscent() const
  205538. {
  205539. return ascent;
  205540. }
  205541. float getDescent() const
  205542. {
  205543. return 1.0f - ascent;
  205544. }
  205545. float getStringWidth (const String& text)
  205546. {
  205547. if (fontRef == 0 || text.isEmpty())
  205548. return 0;
  205549. const int length = text.length();
  205550. HeapBlock <CGGlyph> glyphs;
  205551. createGlyphsForString (text, length, glyphs);
  205552. float x = 0;
  205553. #if SUPPORT_ONLY_10_4_FONTS
  205554. HeapBlock <NSSize> advances (length);
  205555. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205556. for (int i = 0; i < length; ++i)
  205557. x += advances[i].width;
  205558. #else
  205559. #if SUPPORT_10_4_FONTS
  205560. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205561. {
  205562. HeapBlock <NSSize> advances (length);
  205563. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205564. for (int i = 0; i < length; ++i)
  205565. x += advances[i].width;
  205566. }
  205567. else
  205568. #endif
  205569. {
  205570. HeapBlock <int> advances (length);
  205571. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205572. for (int i = 0; i < length; ++i)
  205573. x += advances[i];
  205574. }
  205575. #endif
  205576. return x * unitsToHeightScaleFactor;
  205577. }
  205578. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205579. {
  205580. xOffsets.add (0);
  205581. if (fontRef == 0 || text.isEmpty())
  205582. return;
  205583. const int length = text.length();
  205584. HeapBlock <CGGlyph> glyphs;
  205585. createGlyphsForString (text, length, glyphs);
  205586. #if SUPPORT_ONLY_10_4_FONTS
  205587. HeapBlock <NSSize> advances (length);
  205588. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205589. int x = 0;
  205590. for (int i = 0; i < length; ++i)
  205591. {
  205592. x += advances[i].width;
  205593. xOffsets.add (x * unitsToHeightScaleFactor);
  205594. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205595. }
  205596. #else
  205597. #if SUPPORT_10_4_FONTS
  205598. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205599. {
  205600. HeapBlock <NSSize> advances (length);
  205601. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205602. float x = 0;
  205603. for (int i = 0; i < length; ++i)
  205604. {
  205605. x += advances[i].width;
  205606. xOffsets.add (x * unitsToHeightScaleFactor);
  205607. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205608. }
  205609. }
  205610. else
  205611. #endif
  205612. {
  205613. HeapBlock <int> advances (length);
  205614. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205615. {
  205616. int x = 0;
  205617. for (int i = 0; i < length; ++i)
  205618. {
  205619. x += advances [i];
  205620. xOffsets.add (x * unitsToHeightScaleFactor);
  205621. resultGlyphs.add (glyphs[i]);
  205622. }
  205623. }
  205624. }
  205625. #endif
  205626. }
  205627. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205628. {
  205629. #if JUCE_IPHONE
  205630. return false;
  205631. #else
  205632. if (nsFont == 0)
  205633. return false;
  205634. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205635. jassert (path.isEmpty());
  205636. const ScopedAutoReleasePool pool;
  205637. NSBezierPath* bez = [NSBezierPath bezierPath];
  205638. [bez moveToPoint: NSMakePoint (0, 0)];
  205639. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205640. inFont: nsFont];
  205641. for (int i = 0; i < [bez elementCount]; ++i)
  205642. {
  205643. NSPoint p[3];
  205644. switch ([bez elementAtIndex: i associatedPoints: p])
  205645. {
  205646. case NSMoveToBezierPathElement:
  205647. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205648. break;
  205649. case NSLineToBezierPathElement:
  205650. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205651. break;
  205652. case NSCurveToBezierPathElement:
  205653. 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);
  205654. break;
  205655. case NSClosePathBezierPathElement:
  205656. path.closeSubPath();
  205657. break;
  205658. default:
  205659. jassertfalse
  205660. break;
  205661. }
  205662. }
  205663. path.applyTransform (pathTransform);
  205664. return true;
  205665. #endif
  205666. }
  205667. juce_UseDebuggingNewOperator
  205668. CGFontRef fontRef;
  205669. float fontHeightToCGSizeFactor;
  205670. CGAffineTransform renderingTransform;
  205671. private:
  205672. float ascent, unitsToHeightScaleFactor;
  205673. #if JUCE_IPHONE
  205674. #else
  205675. NSFont* nsFont;
  205676. AffineTransform pathTransform;
  205677. #endif
  205678. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205679. {
  205680. #if SUPPORT_10_4_FONTS
  205681. #if ! SUPPORT_ONLY_10_4_FONTS
  205682. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205683. #endif
  205684. {
  205685. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205686. NSGlyph* const g = (NSGlyph*) glyphs;
  205687. for (int i = 0; i < length; ++i)
  205688. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205689. return;
  205690. }
  205691. #endif
  205692. #if ! SUPPORT_ONLY_10_4_FONTS
  205693. if (charToGlyphMapper == 0)
  205694. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205695. glyphs.malloc (length);
  205696. for (int i = 0; i < length; ++i)
  205697. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205698. #endif
  205699. }
  205700. #if ! SUPPORT_ONLY_10_4_FONTS
  205701. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205702. class CharToGlyphMapper
  205703. {
  205704. public:
  205705. CharToGlyphMapper (CGFontRef fontRef)
  205706. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205707. idRangeOffset (0), glyphIndexes (0)
  205708. {
  205709. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205710. if (cmapTable != 0)
  205711. {
  205712. const int numSubtables = getValue16 (cmapTable, 2);
  205713. for (int i = 0; i < numSubtables; ++i)
  205714. {
  205715. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205716. {
  205717. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205718. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205719. {
  205720. const int length = getValue16 (cmapTable, offset + 2);
  205721. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205722. segCount = segCountX2 / 2;
  205723. const int endCodeOffset = offset + 14;
  205724. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205725. const int idDeltaOffset = startCodeOffset + segCountX2;
  205726. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205727. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205728. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205729. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205730. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205731. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205732. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205733. }
  205734. break;
  205735. }
  205736. }
  205737. CFRelease (cmapTable);
  205738. }
  205739. }
  205740. ~CharToGlyphMapper()
  205741. {
  205742. if (endCode != 0)
  205743. {
  205744. CFRelease (endCode);
  205745. CFRelease (startCode);
  205746. CFRelease (idDelta);
  205747. CFRelease (idRangeOffset);
  205748. CFRelease (glyphIndexes);
  205749. }
  205750. }
  205751. int getGlyphForCharacter (const juce_wchar c) const
  205752. {
  205753. for (int i = 0; i < segCount; ++i)
  205754. {
  205755. if (getValue16 (endCode, i * 2) >= c)
  205756. {
  205757. const int start = getValue16 (startCode, i * 2);
  205758. if (start > c)
  205759. break;
  205760. const int delta = getValue16 (idDelta, i * 2);
  205761. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205762. if (rangeOffset == 0)
  205763. return delta + c;
  205764. else
  205765. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205766. }
  205767. }
  205768. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205769. return jmax (-1, c - 29);
  205770. }
  205771. private:
  205772. int segCount;
  205773. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205774. static uint16 getValue16 (CFDataRef data, const int index)
  205775. {
  205776. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205777. }
  205778. static uint32 getValue32 (CFDataRef data, const int index)
  205779. {
  205780. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205781. }
  205782. };
  205783. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205784. #endif
  205785. };
  205786. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205787. {
  205788. return new MacTypeface (font);
  205789. }
  205790. const StringArray Font::findAllTypefaceNames() throw()
  205791. {
  205792. StringArray names;
  205793. const ScopedAutoReleasePool pool;
  205794. #if JUCE_IPHONE
  205795. NSArray* fonts = [UIFont familyNames];
  205796. #else
  205797. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205798. #endif
  205799. for (unsigned int i = 0; i < [fonts count]; ++i)
  205800. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205801. names.sort (true);
  205802. return names;
  205803. }
  205804. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205805. {
  205806. #if JUCE_IPHONE
  205807. defaultSans = "Helvetica";
  205808. defaultSerif = "Times New Roman";
  205809. defaultFixed = "Courier New";
  205810. #else
  205811. defaultSans = "Lucida Grande";
  205812. defaultSerif = "Times New Roman";
  205813. defaultFixed = "Monaco";
  205814. #endif
  205815. }
  205816. #endif
  205817. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205818. // (must go before juce_mac_CoreGraphicsContext.mm)
  205819. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205820. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205821. // compiled on its own).
  205822. #if JUCE_INCLUDED_FILE
  205823. class CoreGraphicsImage : public Image
  205824. {
  205825. public:
  205826. CoreGraphicsImage (const PixelFormat format_,
  205827. const int imageWidth_,
  205828. const int imageHeight_,
  205829. const bool clearImage)
  205830. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205831. {
  205832. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  205833. : CGColorSpaceCreateDeviceRGB();
  205834. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205835. colourSpace, getCGImageFlags (*this));
  205836. CGColorSpaceRelease (colourSpace);
  205837. }
  205838. ~CoreGraphicsImage()
  205839. {
  205840. CGContextRelease (context);
  205841. }
  205842. LowLevelGraphicsContext* createLowLevelContext();
  205843. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205844. {
  205845. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205846. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205847. {
  205848. return CGBitmapContextCreateImage (nativeImage->context);
  205849. }
  205850. else
  205851. {
  205852. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205853. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205854. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205855. 8, srcData.pixelStride * 8, srcData.lineStride,
  205856. colourSpace, getCGImageFlags (juceImage), provider,
  205857. 0, true, kCGRenderingIntentDefault);
  205858. CGDataProviderRelease (provider);
  205859. return imageRef;
  205860. }
  205861. }
  205862. #if JUCE_MAC
  205863. static NSImage* createNSImage (const Image& image)
  205864. {
  205865. const ScopedAutoReleasePool pool;
  205866. NSImage* im = [[NSImage alloc] init];
  205867. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205868. [im lockFocus];
  205869. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205870. CGImageRef imageRef = createImage (image, false, colourSpace);
  205871. CGColorSpaceRelease (colourSpace);
  205872. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205873. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205874. CGImageRelease (imageRef);
  205875. [im unlockFocus];
  205876. return im;
  205877. }
  205878. #endif
  205879. CGContextRef context;
  205880. private:
  205881. static CGBitmapInfo getCGImageFlags (const Image& image)
  205882. {
  205883. #if JUCE_BIG_ENDIAN
  205884. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205885. #else
  205886. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205887. #endif
  205888. }
  205889. };
  205890. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205891. {
  205892. #if USE_COREGRAPHICS_RENDERING
  205893. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205894. #else
  205895. return new Image (format, imageWidth, imageHeight, clearImage);
  205896. #endif
  205897. }
  205898. class CoreGraphicsContext : public LowLevelGraphicsContext
  205899. {
  205900. public:
  205901. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205902. : context (context_),
  205903. flipHeight (flipHeight_),
  205904. numGradientLookupEntries (0)
  205905. {
  205906. CGContextRetain (context);
  205907. CGContextSaveGState(context);
  205908. CGContextSetShouldSmoothFonts (context, true);
  205909. CGContextSetShouldAntialias (context, true);
  205910. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205911. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205912. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205913. gradientCallbacks.version = 0;
  205914. gradientCallbacks.evaluate = gradientCallback;
  205915. gradientCallbacks.releaseInfo = 0;
  205916. state = new SavedState();
  205917. }
  205918. ~CoreGraphicsContext()
  205919. {
  205920. CGContextRestoreGState (context);
  205921. CGContextRelease (context);
  205922. CGColorSpaceRelease (rgbColourSpace);
  205923. CGColorSpaceRelease (greyColourSpace);
  205924. }
  205925. bool isVectorDevice() const { return false; }
  205926. void setOrigin (int x, int y)
  205927. {
  205928. CGContextTranslateCTM (context, x, -y);
  205929. }
  205930. bool clipToRectangle (const Rectangle<int>& r)
  205931. {
  205932. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205933. return ! isClipEmpty();
  205934. }
  205935. bool clipToRectangleList (const RectangleList& clipRegion)
  205936. {
  205937. if (clipRegion.isEmpty())
  205938. {
  205939. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205940. return false;
  205941. }
  205942. else
  205943. {
  205944. const int numRects = clipRegion.getNumRectangles();
  205945. HeapBlock <CGRect> rects (numRects);
  205946. for (int i = 0; i < numRects; ++i)
  205947. {
  205948. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205949. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205950. }
  205951. CGContextClipToRects (context, rects, numRects);
  205952. return ! isClipEmpty();
  205953. }
  205954. }
  205955. void excludeClipRectangle (const Rectangle<int>& r)
  205956. {
  205957. RectangleList remaining (getClipBounds());
  205958. remaining.subtract (r);
  205959. clipToRectangleList (remaining);
  205960. }
  205961. void clipToPath (const Path& path, const AffineTransform& transform)
  205962. {
  205963. createPath (path, transform);
  205964. CGContextClip (context);
  205965. }
  205966. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205967. {
  205968. if (! transform.isSingularity())
  205969. {
  205970. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205971. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205972. flip();
  205973. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205974. applyTransform (t);
  205975. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205976. CGContextClipToMask (context, r, image);
  205977. applyTransform (t.inverted());
  205978. flip();
  205979. CGImageRelease (image);
  205980. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205981. }
  205982. }
  205983. bool clipRegionIntersects (const Rectangle<int>& r)
  205984. {
  205985. return getClipBounds().intersects (r);
  205986. }
  205987. const Rectangle<int> getClipBounds() const
  205988. {
  205989. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205990. return Rectangle<int> (roundToInt (bounds.origin.x),
  205991. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205992. roundToInt (bounds.size.width),
  205993. roundToInt (bounds.size.height));
  205994. }
  205995. bool isClipEmpty() const
  205996. {
  205997. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205998. }
  205999. void saveState()
  206000. {
  206001. CGContextSaveGState (context);
  206002. stateStack.add (new SavedState (*state));
  206003. }
  206004. void restoreState()
  206005. {
  206006. CGContextRestoreGState (context);
  206007. SavedState* const top = stateStack.getLast();
  206008. if (top != 0)
  206009. {
  206010. state = top;
  206011. stateStack.removeLast (1, false);
  206012. }
  206013. else
  206014. {
  206015. jassertfalse // trying to pop with an empty stack!
  206016. }
  206017. }
  206018. void setFill (const FillType& fillType)
  206019. {
  206020. state->fillType = fillType;
  206021. if (fillType.isColour())
  206022. {
  206023. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206024. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206025. CGContextSetAlpha (context, 1.0f);
  206026. }
  206027. }
  206028. void setOpacity (float newOpacity)
  206029. {
  206030. state->fillType.setOpacity (newOpacity);
  206031. setFill (state->fillType);
  206032. }
  206033. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206034. {
  206035. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206036. ? kCGInterpolationLow
  206037. : kCGInterpolationHigh);
  206038. }
  206039. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206040. {
  206041. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206042. if (replaceExistingContents)
  206043. {
  206044. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206045. CGContextClearRect (context, cgRect);
  206046. #else
  206047. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206048. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206049. CGContextClearRect (context, cgRect);
  206050. else
  206051. #endif
  206052. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206053. #endif
  206054. fillRect (r, false);
  206055. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206056. }
  206057. else
  206058. {
  206059. if (state->fillType.isColour())
  206060. {
  206061. CGContextFillRect (context, cgRect);
  206062. }
  206063. else if (state->fillType.isGradient())
  206064. {
  206065. CGContextSaveGState (context);
  206066. CGContextClipToRect (context, cgRect);
  206067. drawGradient();
  206068. CGContextRestoreGState (context);
  206069. }
  206070. else
  206071. {
  206072. CGContextSaveGState (context);
  206073. CGContextClipToRect (context, cgRect);
  206074. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206075. CGContextRestoreGState (context);
  206076. }
  206077. }
  206078. }
  206079. void fillPath (const Path& path, const AffineTransform& transform)
  206080. {
  206081. CGContextSaveGState (context);
  206082. if (state->fillType.isColour())
  206083. {
  206084. flip();
  206085. applyTransform (transform);
  206086. createPath (path);
  206087. if (path.isUsingNonZeroWinding())
  206088. CGContextFillPath (context);
  206089. else
  206090. CGContextEOFillPath (context);
  206091. }
  206092. else
  206093. {
  206094. createPath (path, transform);
  206095. if (path.isUsingNonZeroWinding())
  206096. CGContextClip (context);
  206097. else
  206098. CGContextEOClip (context);
  206099. if (state->fillType.isGradient())
  206100. drawGradient();
  206101. else
  206102. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206103. }
  206104. CGContextRestoreGState (context);
  206105. }
  206106. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206107. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206108. {
  206109. jassert (sourceImage.getBounds().contains (srcClip));
  206110. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206111. CGImageRef image = fullImage;
  206112. if (srcClip != sourceImage.getBounds())
  206113. {
  206114. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206115. srcClip.getWidth(), srcClip.getHeight()));
  206116. CGImageRelease (fullImage);
  206117. }
  206118. CGContextSaveGState (context);
  206119. CGContextSetAlpha (context, state->fillType.getOpacity());
  206120. flip();
  206121. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206122. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206123. if (fillEntireClipAsTiles)
  206124. {
  206125. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206126. CGContextDrawTiledImage (context, imageRect, image);
  206127. #else
  206128. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206129. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206130. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206131. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206132. CGContextDrawTiledImage (context, imageRect, image);
  206133. else
  206134. #endif
  206135. {
  206136. // Fallback to manually doing a tiled fill on 10.4
  206137. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206138. const int iw = srcClip.getWidth();
  206139. const int ih = srcClip.getHeight();
  206140. int x = 0, y = 0;
  206141. while (x > clip.origin.x) x -= iw;
  206142. while (y > clip.origin.y) y -= ih;
  206143. const int right = (int) (clip.origin.x + clip.size.width);
  206144. const int bottom = (int) (clip.origin.y + clip.size.height);
  206145. while (y < bottom)
  206146. {
  206147. for (int x2 = x; x2 < right; x2 += iw)
  206148. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206149. y += ih;
  206150. }
  206151. }
  206152. #endif
  206153. }
  206154. else
  206155. {
  206156. CGContextDrawImage (context, imageRect, image);
  206157. }
  206158. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206159. CGContextRestoreGState (context);
  206160. }
  206161. void drawLine (double x1, double y1, double x2, double y2)
  206162. {
  206163. CGContextSetLineCap (context, kCGLineCapSquare);
  206164. CGContextSetLineWidth (context, 1.0f);
  206165. CGContextSetRGBStrokeColor (context,
  206166. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206167. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206168. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206169. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206170. CGContextStrokeLineSegments (context, line, 1);
  206171. }
  206172. void drawVerticalLine (const int x, double top, double bottom)
  206173. {
  206174. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206175. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206176. #else
  206177. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206178. // the x co-ord slightly to trick it..
  206179. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206180. #endif
  206181. }
  206182. void drawHorizontalLine (const int y, double left, double right)
  206183. {
  206184. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206185. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206186. #else
  206187. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206188. // the x co-ord slightly to trick it..
  206189. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206190. #endif
  206191. }
  206192. void setFont (const Font& newFont)
  206193. {
  206194. if (state->font != newFont)
  206195. {
  206196. state->fontRef = 0;
  206197. state->font = newFont;
  206198. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206199. if (mf != 0)
  206200. {
  206201. state->fontRef = mf->fontRef;
  206202. CGContextSetFont (context, state->fontRef);
  206203. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206204. state->fontTransform = mf->renderingTransform;
  206205. state->fontTransform.a *= state->font.getHorizontalScale();
  206206. CGContextSetTextMatrix (context, state->fontTransform);
  206207. }
  206208. }
  206209. }
  206210. const Font getFont()
  206211. {
  206212. return state->font;
  206213. }
  206214. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206215. {
  206216. if (state->fontRef != 0 && state->fillType.isColour())
  206217. {
  206218. if (transform.isOnlyTranslation())
  206219. {
  206220. CGGlyph g = glyphNumber;
  206221. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206222. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206223. }
  206224. else
  206225. {
  206226. CGContextSaveGState (context);
  206227. flip();
  206228. applyTransform (transform);
  206229. CGAffineTransform t = state->fontTransform;
  206230. t.d = -t.d;
  206231. CGContextSetTextMatrix (context, t);
  206232. CGGlyph g = glyphNumber;
  206233. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206234. CGContextSetTextMatrix (context, state->fontTransform);
  206235. CGContextRestoreGState (context);
  206236. }
  206237. }
  206238. else
  206239. {
  206240. Path p;
  206241. Font& f = state->font;
  206242. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206243. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206244. .followedBy (transform));
  206245. }
  206246. }
  206247. private:
  206248. CGContextRef context;
  206249. const float flipHeight;
  206250. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206251. CGFunctionCallbacks gradientCallbacks;
  206252. struct SavedState
  206253. {
  206254. SavedState()
  206255. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206256. {
  206257. }
  206258. SavedState (const SavedState& other)
  206259. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206260. fontTransform (other.fontTransform)
  206261. {
  206262. }
  206263. ~SavedState()
  206264. {
  206265. }
  206266. FillType fillType;
  206267. Font font;
  206268. CGFontRef fontRef;
  206269. CGAffineTransform fontTransform;
  206270. };
  206271. ScopedPointer <SavedState> state;
  206272. OwnedArray <SavedState> stateStack;
  206273. HeapBlock <PixelARGB> gradientLookupTable;
  206274. int numGradientLookupEntries;
  206275. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206276. {
  206277. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206278. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206279. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206280. colour.unpremultiply();
  206281. outData[0] = colour.getRed() / 255.0f;
  206282. outData[1] = colour.getGreen() / 255.0f;
  206283. outData[2] = colour.getBlue() / 255.0f;
  206284. outData[3] = colour.getAlpha() / 255.0f;
  206285. }
  206286. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206287. {
  206288. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206289. --numGradientLookupEntries;
  206290. CGShadingRef result = 0;
  206291. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206292. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206293. if (gradient.isRadial)
  206294. {
  206295. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206296. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206297. function, true, true);
  206298. }
  206299. else
  206300. {
  206301. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206302. CGPointMake (gradient.x2, gradient.y2),
  206303. function, true, true);
  206304. }
  206305. CGFunctionRelease (function);
  206306. return result;
  206307. }
  206308. void drawGradient()
  206309. {
  206310. flip();
  206311. applyTransform (state->fillType.transform);
  206312. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206313. // you draw a gradient with high quality interp enabled).
  206314. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206315. CGContextSetAlpha (context, state->fillType.getOpacity());
  206316. CGContextDrawShading (context, shading);
  206317. CGShadingRelease (shading);
  206318. }
  206319. void createPath (const Path& path) const
  206320. {
  206321. CGContextBeginPath (context);
  206322. Path::Iterator i (path);
  206323. while (i.next())
  206324. {
  206325. switch (i.elementType)
  206326. {
  206327. case Path::Iterator::startNewSubPath:
  206328. CGContextMoveToPoint (context, i.x1, i.y1);
  206329. break;
  206330. case Path::Iterator::lineTo:
  206331. CGContextAddLineToPoint (context, i.x1, i.y1);
  206332. break;
  206333. case Path::Iterator::quadraticTo:
  206334. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206335. break;
  206336. case Path::Iterator::cubicTo:
  206337. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206338. break;
  206339. case Path::Iterator::closePath:
  206340. CGContextClosePath (context); break;
  206341. default:
  206342. jassertfalse
  206343. break;
  206344. }
  206345. }
  206346. }
  206347. void createPath (const Path& path, const AffineTransform& transform) const
  206348. {
  206349. CGContextBeginPath (context);
  206350. Path::Iterator i (path);
  206351. while (i.next())
  206352. {
  206353. switch (i.elementType)
  206354. {
  206355. case Path::Iterator::startNewSubPath:
  206356. transform.transformPoint (i.x1, i.y1);
  206357. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206358. break;
  206359. case Path::Iterator::lineTo:
  206360. transform.transformPoint (i.x1, i.y1);
  206361. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206362. break;
  206363. case Path::Iterator::quadraticTo:
  206364. transform.transformPoint (i.x1, i.y1);
  206365. transform.transformPoint (i.x2, i.y2);
  206366. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206367. break;
  206368. case Path::Iterator::cubicTo:
  206369. transform.transformPoint (i.x1, i.y1);
  206370. transform.transformPoint (i.x2, i.y2);
  206371. transform.transformPoint (i.x3, i.y3);
  206372. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206373. break;
  206374. case Path::Iterator::closePath:
  206375. CGContextClosePath (context); break;
  206376. default:
  206377. jassertfalse
  206378. break;
  206379. }
  206380. }
  206381. }
  206382. static Image* createAlphaChannelImage (const Image& im)
  206383. {
  206384. if (im.getFormat() == Image::SingleChannel)
  206385. return const_cast <Image*> (&im);
  206386. return im.createCopyOfAlphaChannel();
  206387. }
  206388. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206389. {
  206390. if (im.getFormat() != Image::SingleChannel)
  206391. delete alphaIm;
  206392. }
  206393. void flip() const
  206394. {
  206395. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206396. }
  206397. void applyTransform (const AffineTransform& transform) const
  206398. {
  206399. CGAffineTransform t;
  206400. t.a = transform.mat00;
  206401. t.b = transform.mat10;
  206402. t.c = transform.mat01;
  206403. t.d = transform.mat11;
  206404. t.tx = transform.mat02;
  206405. t.ty = transform.mat12;
  206406. CGContextConcatCTM (context, t);
  206407. }
  206408. float flipY (float y) const
  206409. {
  206410. return flipHeight - y;
  206411. }
  206412. };
  206413. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206414. {
  206415. return new CoreGraphicsContext (context, imageHeight);
  206416. }
  206417. #endif
  206418. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206419. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206420. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206421. // compiled on its own).
  206422. #if JUCE_INCLUDED_FILE
  206423. class NSViewComponentPeer;
  206424. END_JUCE_NAMESPACE
  206425. #define JuceNSView MakeObjCClassName(JuceNSView)
  206426. @interface JuceNSView : NSView<NSTextInput>
  206427. {
  206428. @public
  206429. NSViewComponentPeer* owner;
  206430. NSNotificationCenter* notificationCenter;
  206431. String* stringBeingComposed;
  206432. bool textWasInserted;
  206433. }
  206434. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206435. - (void) dealloc;
  206436. - (BOOL) isOpaque;
  206437. - (void) drawRect: (NSRect) r;
  206438. - (void) mouseDown: (NSEvent*) ev;
  206439. - (void) asyncMouseDown: (NSEvent*) ev;
  206440. - (void) mouseUp: (NSEvent*) ev;
  206441. - (void) asyncMouseUp: (NSEvent*) ev;
  206442. - (void) mouseDragged: (NSEvent*) ev;
  206443. - (void) mouseMoved: (NSEvent*) ev;
  206444. - (void) mouseEntered: (NSEvent*) ev;
  206445. - (void) mouseExited: (NSEvent*) ev;
  206446. - (void) rightMouseDown: (NSEvent*) ev;
  206447. - (void) rightMouseDragged: (NSEvent*) ev;
  206448. - (void) rightMouseUp: (NSEvent*) ev;
  206449. - (void) otherMouseDown: (NSEvent*) ev;
  206450. - (void) otherMouseDragged: (NSEvent*) ev;
  206451. - (void) otherMouseUp: (NSEvent*) ev;
  206452. - (void) scrollWheel: (NSEvent*) ev;
  206453. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206454. - (void) frameChanged: (NSNotification*) n;
  206455. - (void) viewDidMoveToWindow;
  206456. - (void) keyDown: (NSEvent*) ev;
  206457. - (void) keyUp: (NSEvent*) ev;
  206458. // NSTextInput Methods
  206459. - (void) insertText: (id) aString;
  206460. - (void) doCommandBySelector: (SEL) aSelector;
  206461. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206462. - (void) unmarkText;
  206463. - (BOOL) hasMarkedText;
  206464. - (long) conversationIdentifier;
  206465. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206466. - (NSRange) markedRange;
  206467. - (NSRange) selectedRange;
  206468. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206469. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206470. - (NSArray*) validAttributesForMarkedText;
  206471. - (void) flagsChanged: (NSEvent*) ev;
  206472. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206473. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206474. #endif
  206475. - (BOOL) becomeFirstResponder;
  206476. - (BOOL) resignFirstResponder;
  206477. - (BOOL) acceptsFirstResponder;
  206478. - (void) asyncRepaint: (id) rect;
  206479. - (NSArray*) getSupportedDragTypes;
  206480. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206481. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206482. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206483. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206484. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206485. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206486. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206487. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206488. @end
  206489. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206490. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206491. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206492. #else
  206493. @interface JuceNSWindow : NSWindow
  206494. #endif
  206495. {
  206496. @private
  206497. NSViewComponentPeer* owner;
  206498. bool isZooming;
  206499. }
  206500. - (void) setOwner: (NSViewComponentPeer*) owner;
  206501. - (BOOL) canBecomeKeyWindow;
  206502. - (void) becomeKeyWindow;
  206503. - (BOOL) windowShouldClose: (id) window;
  206504. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206505. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206506. - (void) zoom: (id) sender;
  206507. @end
  206508. BEGIN_JUCE_NAMESPACE
  206509. class NSViewComponentPeer : public ComponentPeer
  206510. {
  206511. public:
  206512. NSViewComponentPeer (Component* const component,
  206513. const int windowStyleFlags,
  206514. NSView* viewToAttachTo);
  206515. ~NSViewComponentPeer();
  206516. void* getNativeHandle() const;
  206517. void setVisible (bool shouldBeVisible);
  206518. void setTitle (const String& title);
  206519. void setPosition (int x, int y);
  206520. void setSize (int w, int h);
  206521. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206522. const Rectangle<int> getBounds (const bool global) const;
  206523. const Rectangle<int> getBounds() const;
  206524. const Point<int> getScreenPosition() const;
  206525. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206526. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206527. void setMinimised (bool shouldBeMinimised);
  206528. bool isMinimised() const;
  206529. void setFullScreen (bool shouldBeFullScreen);
  206530. bool isFullScreen() const;
  206531. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206532. const BorderSize getFrameSize() const;
  206533. bool setAlwaysOnTop (bool alwaysOnTop);
  206534. void toFront (bool makeActiveWindow);
  206535. void toBehind (ComponentPeer* other);
  206536. void setIcon (const Image& newIcon);
  206537. const StringArray getAvailableRenderingEngines() throw();
  206538. int getCurrentRenderingEngine() throw();
  206539. void setCurrentRenderingEngine (int index) throw();
  206540. virtual void redirectMouseDown (NSEvent* ev);
  206541. virtual void redirectMouseUp (NSEvent* ev);
  206542. virtual void redirectMouseDrag (NSEvent* ev);
  206543. virtual void redirectMouseMove (NSEvent* ev);
  206544. virtual void redirectMouseEnter (NSEvent* ev);
  206545. virtual void redirectMouseExit (NSEvent* ev);
  206546. virtual void redirectMouseWheel (NSEvent* ev);
  206547. void sendMouseEvent (NSEvent* ev);
  206548. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206549. virtual bool redirectKeyDown (NSEvent* ev);
  206550. virtual bool redirectKeyUp (NSEvent* ev);
  206551. virtual void redirectModKeyChange (NSEvent* ev);
  206552. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206553. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206554. #endif
  206555. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206556. virtual bool isOpaque();
  206557. virtual void drawRect (NSRect r);
  206558. virtual bool canBecomeKeyWindow();
  206559. virtual bool windowShouldClose();
  206560. virtual void redirectMovedOrResized();
  206561. virtual void viewMovedToWindow();
  206562. virtual NSRect constrainRect (NSRect r);
  206563. static void showArrowCursorIfNeeded();
  206564. static void updateModifiers (NSEvent* e);
  206565. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206566. static int getKeyCodeFromEvent (NSEvent* ev)
  206567. {
  206568. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206569. int keyCode = unmodified[0];
  206570. if (keyCode == 0x19) // (backwards-tab)
  206571. keyCode = '\t';
  206572. else if (keyCode == 0x03) // (enter)
  206573. keyCode = '\r';
  206574. return keyCode;
  206575. }
  206576. static int64 getMouseTime (NSEvent* e)
  206577. {
  206578. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206579. + (int64) ([e timestamp] * 1000.0);
  206580. }
  206581. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206582. {
  206583. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206584. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206585. }
  206586. static int getModifierForButtonNumber (const NSInteger num)
  206587. {
  206588. return num == 0 ? ModifierKeys::leftButtonModifier
  206589. : (num == 1 ? ModifierKeys::rightButtonModifier
  206590. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206591. }
  206592. virtual void viewFocusGain();
  206593. virtual void viewFocusLoss();
  206594. bool isFocused() const;
  206595. void grabFocus();
  206596. void textInputRequired (const Point<int>& position);
  206597. void repaint (int x, int y, int w, int h);
  206598. void performAnyPendingRepaintsNow();
  206599. juce_UseDebuggingNewOperator
  206600. NSWindow* window;
  206601. JuceNSView* view;
  206602. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206603. static ModifierKeys currentModifiers;
  206604. static ComponentPeer* currentlyFocusedPeer;
  206605. static VoidArray keysCurrentlyDown;
  206606. };
  206607. END_JUCE_NAMESPACE
  206608. @implementation JuceNSView
  206609. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206610. withFrame: (NSRect) frame
  206611. {
  206612. [super initWithFrame: frame];
  206613. owner = owner_;
  206614. stringBeingComposed = 0;
  206615. textWasInserted = false;
  206616. notificationCenter = [NSNotificationCenter defaultCenter];
  206617. [notificationCenter addObserver: self
  206618. selector: @selector (frameChanged:)
  206619. name: NSViewFrameDidChangeNotification
  206620. object: self];
  206621. if (! owner_->isSharedWindow)
  206622. {
  206623. [notificationCenter addObserver: self
  206624. selector: @selector (frameChanged:)
  206625. name: NSWindowDidMoveNotification
  206626. object: owner_->window];
  206627. }
  206628. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206629. return self;
  206630. }
  206631. - (void) dealloc
  206632. {
  206633. [notificationCenter removeObserver: self];
  206634. delete stringBeingComposed;
  206635. [super dealloc];
  206636. }
  206637. - (void) drawRect: (NSRect) r
  206638. {
  206639. if (owner != 0)
  206640. owner->drawRect (r);
  206641. }
  206642. - (BOOL) isOpaque
  206643. {
  206644. return owner == 0 || owner->isOpaque();
  206645. }
  206646. - (void) mouseDown: (NSEvent*) ev
  206647. {
  206648. // In some host situations, the host will stop modal loops from working
  206649. // correctly if they're called from a mouse event, so we'll trigger
  206650. // the event asynchronously..
  206651. if (JUCEApplication::getInstance() == 0)
  206652. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206653. withObject: ev
  206654. waitUntilDone: NO];
  206655. else
  206656. [self asyncMouseDown: ev];
  206657. }
  206658. - (void) asyncMouseDown: (NSEvent*) ev
  206659. {
  206660. if (owner != 0)
  206661. owner->redirectMouseDown (ev);
  206662. }
  206663. - (void) mouseUp: (NSEvent*) ev
  206664. {
  206665. // In some host situations, the host will stop modal loops from working
  206666. // correctly if they're called from a mouse event, so we'll trigger
  206667. // the event asynchronously..
  206668. if (JUCEApplication::getInstance() == 0)
  206669. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206670. withObject: ev
  206671. waitUntilDone: NO];
  206672. else
  206673. [self asyncMouseUp: ev];
  206674. }
  206675. - (void) asyncMouseUp: (NSEvent*) ev
  206676. {
  206677. if (owner != 0)
  206678. owner->redirectMouseUp (ev);
  206679. }
  206680. - (void) mouseDragged: (NSEvent*) ev
  206681. {
  206682. if (owner != 0)
  206683. owner->redirectMouseDrag (ev);
  206684. }
  206685. - (void) mouseMoved: (NSEvent*) ev
  206686. {
  206687. if (owner != 0)
  206688. owner->redirectMouseMove (ev);
  206689. }
  206690. - (void) mouseEntered: (NSEvent*) ev
  206691. {
  206692. if (owner != 0)
  206693. owner->redirectMouseEnter (ev);
  206694. }
  206695. - (void) mouseExited: (NSEvent*) ev
  206696. {
  206697. if (owner != 0)
  206698. owner->redirectMouseExit (ev);
  206699. }
  206700. - (void) rightMouseDown: (NSEvent*) ev
  206701. {
  206702. [self mouseDown: ev];
  206703. }
  206704. - (void) rightMouseDragged: (NSEvent*) ev
  206705. {
  206706. [self mouseDragged: ev];
  206707. }
  206708. - (void) rightMouseUp: (NSEvent*) ev
  206709. {
  206710. [self mouseUp: ev];
  206711. }
  206712. - (void) otherMouseDown: (NSEvent*) ev
  206713. {
  206714. [self mouseDown: ev];
  206715. }
  206716. - (void) otherMouseDragged: (NSEvent*) ev
  206717. {
  206718. [self mouseDragged: ev];
  206719. }
  206720. - (void) otherMouseUp: (NSEvent*) ev
  206721. {
  206722. [self mouseUp: ev];
  206723. }
  206724. - (void) scrollWheel: (NSEvent*) ev
  206725. {
  206726. if (owner != 0)
  206727. owner->redirectMouseWheel (ev);
  206728. }
  206729. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206730. {
  206731. return YES;
  206732. }
  206733. - (void) frameChanged: (NSNotification*) n
  206734. {
  206735. if (owner != 0)
  206736. owner->redirectMovedOrResized();
  206737. }
  206738. - (void) viewDidMoveToWindow
  206739. {
  206740. if (owner != 0)
  206741. owner->viewMovedToWindow();
  206742. }
  206743. - (void) asyncRepaint: (id) rect
  206744. {
  206745. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206746. [self setNeedsDisplayInRect: *r];
  206747. }
  206748. - (void) keyDown: (NSEvent*) ev
  206749. {
  206750. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206751. textWasInserted = false;
  206752. if (target != 0)
  206753. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206754. else
  206755. deleteAndZero (stringBeingComposed);
  206756. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206757. [super keyDown: ev];
  206758. }
  206759. - (void) keyUp: (NSEvent*) ev
  206760. {
  206761. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206762. [super keyUp: ev];
  206763. }
  206764. - (void) insertText: (id) aString
  206765. {
  206766. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206767. if ([aString length] > 0)
  206768. {
  206769. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206770. if (target != 0)
  206771. {
  206772. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206773. textWasInserted = true;
  206774. }
  206775. }
  206776. deleteAndZero (stringBeingComposed);
  206777. }
  206778. - (void) doCommandBySelector: (SEL) aSelector
  206779. {
  206780. }
  206781. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206782. {
  206783. if (stringBeingComposed == 0)
  206784. stringBeingComposed = new String();
  206785. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206786. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206787. if (target != 0)
  206788. {
  206789. const Range<int> currentHighlight (target->getHighlightedRegion());
  206790. target->insertTextAtCaret (*stringBeingComposed);
  206791. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206792. textWasInserted = true;
  206793. }
  206794. }
  206795. - (void) unmarkText
  206796. {
  206797. if (stringBeingComposed != 0)
  206798. {
  206799. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206800. if (target != 0)
  206801. {
  206802. target->insertTextAtCaret (*stringBeingComposed);
  206803. textWasInserted = true;
  206804. }
  206805. }
  206806. deleteAndZero (stringBeingComposed);
  206807. }
  206808. - (BOOL) hasMarkedText
  206809. {
  206810. return stringBeingComposed != 0;
  206811. }
  206812. - (long) conversationIdentifier
  206813. {
  206814. return (long) (pointer_sized_int) self;
  206815. }
  206816. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206817. {
  206818. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206819. if (target != 0)
  206820. {
  206821. const Range<int> r ((int) theRange.location,
  206822. (int) (theRange.location + theRange.length));
  206823. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206824. }
  206825. return nil;
  206826. }
  206827. - (NSRange) markedRange
  206828. {
  206829. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206830. : NSMakeRange (NSNotFound, 0);
  206831. }
  206832. - (NSRange) selectedRange
  206833. {
  206834. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206835. if (target != 0)
  206836. {
  206837. const Range<int> highlight (target->getHighlightedRegion());
  206838. if (! highlight.isEmpty())
  206839. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206840. }
  206841. return NSMakeRange (NSNotFound, 0);
  206842. }
  206843. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206844. {
  206845. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206846. if (comp == 0)
  206847. return NSMakeRect (0, 0, 0, 0);
  206848. const Rectangle<int> bounds (comp->getScreenBounds());
  206849. return NSMakeRect (bounds.getX(),
  206850. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206851. bounds.getWidth(),
  206852. bounds.getHeight());
  206853. }
  206854. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206855. {
  206856. return NSNotFound;
  206857. }
  206858. - (NSArray*) validAttributesForMarkedText
  206859. {
  206860. return [NSArray array];
  206861. }
  206862. - (void) flagsChanged: (NSEvent*) ev
  206863. {
  206864. if (owner != 0)
  206865. owner->redirectModKeyChange (ev);
  206866. }
  206867. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206868. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206869. {
  206870. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206871. return true;
  206872. return [super performKeyEquivalent: ev];
  206873. }
  206874. #endif
  206875. - (BOOL) becomeFirstResponder
  206876. {
  206877. if (owner != 0)
  206878. owner->viewFocusGain();
  206879. return true;
  206880. }
  206881. - (BOOL) resignFirstResponder
  206882. {
  206883. if (owner != 0)
  206884. owner->viewFocusLoss();
  206885. return true;
  206886. }
  206887. - (BOOL) acceptsFirstResponder
  206888. {
  206889. return owner != 0 && owner->canBecomeKeyWindow();
  206890. }
  206891. - (NSArray*) getSupportedDragTypes
  206892. {
  206893. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206894. }
  206895. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206896. {
  206897. return owner != 0 && owner->sendDragCallback (type, sender);
  206898. }
  206899. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206900. {
  206901. if ([self sendDragCallback: 0 sender: sender])
  206902. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206903. else
  206904. return NSDragOperationNone;
  206905. }
  206906. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206907. {
  206908. if ([self sendDragCallback: 0 sender: sender])
  206909. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206910. else
  206911. return NSDragOperationNone;
  206912. }
  206913. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206914. {
  206915. [self sendDragCallback: 1 sender: sender];
  206916. }
  206917. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206918. {
  206919. [self sendDragCallback: 1 sender: sender];
  206920. }
  206921. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206922. {
  206923. return YES;
  206924. }
  206925. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206926. {
  206927. return [self sendDragCallback: 2 sender: sender];
  206928. }
  206929. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206930. {
  206931. }
  206932. @end
  206933. @implementation JuceNSWindow
  206934. - (void) setOwner: (NSViewComponentPeer*) owner_
  206935. {
  206936. owner = owner_;
  206937. isZooming = false;
  206938. }
  206939. - (BOOL) canBecomeKeyWindow
  206940. {
  206941. return owner != 0 && owner->canBecomeKeyWindow();
  206942. }
  206943. - (void) becomeKeyWindow
  206944. {
  206945. [super becomeKeyWindow];
  206946. if (owner != 0)
  206947. owner->grabFocus();
  206948. }
  206949. - (BOOL) windowShouldClose: (id) window
  206950. {
  206951. return owner == 0 || owner->windowShouldClose();
  206952. }
  206953. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206954. {
  206955. if (owner != 0)
  206956. frameRect = owner->constrainRect (frameRect);
  206957. return frameRect;
  206958. }
  206959. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206960. {
  206961. if (isZooming)
  206962. return proposedFrameSize;
  206963. NSRect frameRect = [self frame];
  206964. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206965. frameRect.size = proposedFrameSize;
  206966. if (owner != 0)
  206967. frameRect = owner->constrainRect (frameRect);
  206968. return frameRect.size;
  206969. }
  206970. - (void) zoom: (id) sender
  206971. {
  206972. isZooming = true;
  206973. [super zoom: sender];
  206974. isZooming = false;
  206975. }
  206976. - (void) windowWillMove: (NSNotification*) notification
  206977. {
  206978. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206979. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206980. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206981. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206982. }
  206983. @end
  206984. BEGIN_JUCE_NAMESPACE
  206985. ModifierKeys NSViewComponentPeer::currentModifiers;
  206986. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206987. VoidArray NSViewComponentPeer::keysCurrentlyDown;
  206988. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206989. {
  206990. if (NSViewComponentPeer::keysCurrentlyDown.contains ((void*) keyCode))
  206991. return true;
  206992. if (keyCode >= 'A' && keyCode <= 'Z'
  206993. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206994. return true;
  206995. if (keyCode >= 'a' && keyCode <= 'z'
  206996. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206997. return true;
  206998. return false;
  206999. }
  207000. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  207001. {
  207002. int m = 0;
  207003. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  207004. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  207005. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  207006. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  207007. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  207008. }
  207009. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  207010. {
  207011. updateModifiers (ev);
  207012. int keyCode = getKeyCodeFromEvent (ev);
  207013. if (keyCode != 0)
  207014. {
  207015. if (isKeyDown)
  207016. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  207017. else
  207018. keysCurrentlyDown.removeValue ((void*) keyCode);
  207019. }
  207020. }
  207021. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207022. {
  207023. return NSViewComponentPeer::currentModifiers;
  207024. }
  207025. void ModifierKeys::updateCurrentModifiers() throw()
  207026. {
  207027. currentModifiers = NSViewComponentPeer::currentModifiers;
  207028. }
  207029. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207030. const int windowStyleFlags,
  207031. NSView* viewToAttachTo)
  207032. : ComponentPeer (component_, windowStyleFlags),
  207033. window (0),
  207034. view (0),
  207035. isSharedWindow (viewToAttachTo != 0),
  207036. fullScreen (false),
  207037. insideDrawRect (false),
  207038. #if USE_COREGRAPHICS_RENDERING
  207039. usingCoreGraphics (true),
  207040. #else
  207041. usingCoreGraphics (false),
  207042. #endif
  207043. recursiveToFrontCall (false)
  207044. {
  207045. NSRect r;
  207046. r.origin.x = 0;
  207047. r.origin.y = 0;
  207048. r.size.width = (float) component->getWidth();
  207049. r.size.height = (float) component->getHeight();
  207050. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207051. [view setPostsFrameChangedNotifications: YES];
  207052. if (isSharedWindow)
  207053. {
  207054. window = [viewToAttachTo window];
  207055. [viewToAttachTo addSubview: view];
  207056. setVisible (component->isVisible());
  207057. }
  207058. else
  207059. {
  207060. r.origin.x = (float) component->getX();
  207061. r.origin.y = (float) component->getY();
  207062. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207063. unsigned int style = 0;
  207064. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207065. style = NSBorderlessWindowMask;
  207066. else
  207067. style = NSTitledWindowMask;
  207068. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207069. style |= NSMiniaturizableWindowMask;
  207070. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207071. style |= NSClosableWindowMask;
  207072. if ((windowStyleFlags & windowIsResizable) != 0)
  207073. style |= NSResizableWindowMask;
  207074. window = [[JuceNSWindow alloc] initWithContentRect: r
  207075. styleMask: style
  207076. backing: NSBackingStoreBuffered
  207077. defer: YES];
  207078. [((JuceNSWindow*) window) setOwner: this];
  207079. [window orderOut: nil];
  207080. [window setDelegate: (JuceNSWindow*) window];
  207081. [window setOpaque: component->isOpaque()];
  207082. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207083. if (component->isAlwaysOnTop())
  207084. [window setLevel: NSFloatingWindowLevel];
  207085. [window setContentView: view];
  207086. [window setAutodisplay: YES];
  207087. [window setAcceptsMouseMovedEvents: YES];
  207088. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207089. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207090. [window setReleasedWhenClosed: YES];
  207091. [window retain];
  207092. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207093. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207094. }
  207095. setTitle (component->getName());
  207096. }
  207097. NSViewComponentPeer::~NSViewComponentPeer()
  207098. {
  207099. view->owner = 0;
  207100. [view removeFromSuperview];
  207101. [view release];
  207102. if (! isSharedWindow)
  207103. {
  207104. [((JuceNSWindow*) window) setOwner: 0];
  207105. [window close];
  207106. [window release];
  207107. }
  207108. }
  207109. void* NSViewComponentPeer::getNativeHandle() const
  207110. {
  207111. return view;
  207112. }
  207113. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207114. {
  207115. if (isSharedWindow)
  207116. {
  207117. [view setHidden: ! shouldBeVisible];
  207118. }
  207119. else
  207120. {
  207121. if (shouldBeVisible)
  207122. {
  207123. [window orderFront: nil];
  207124. handleBroughtToFront();
  207125. }
  207126. else
  207127. {
  207128. [window orderOut: nil];
  207129. }
  207130. }
  207131. }
  207132. void NSViewComponentPeer::setTitle (const String& title)
  207133. {
  207134. const ScopedAutoReleasePool pool;
  207135. if (! isSharedWindow)
  207136. [window setTitle: juceStringToNS (title)];
  207137. }
  207138. void NSViewComponentPeer::setPosition (int x, int y)
  207139. {
  207140. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207141. }
  207142. void NSViewComponentPeer::setSize (int w, int h)
  207143. {
  207144. setBounds (component->getX(), component->getY(), w, h, false);
  207145. }
  207146. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207147. {
  207148. fullScreen = isNowFullScreen;
  207149. w = jmax (0, w);
  207150. h = jmax (0, h);
  207151. NSRect r;
  207152. r.origin.x = (float) x;
  207153. r.origin.y = (float) y;
  207154. r.size.width = (float) w;
  207155. r.size.height = (float) h;
  207156. if (isSharedWindow)
  207157. {
  207158. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207159. if ([view frame].size.width != r.size.width
  207160. || [view frame].size.height != r.size.height)
  207161. [view setNeedsDisplay: true];
  207162. [view setFrame: r];
  207163. }
  207164. else
  207165. {
  207166. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207167. [window setFrame: [window frameRectForContentRect: r]
  207168. display: true];
  207169. }
  207170. }
  207171. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207172. {
  207173. NSRect r = [view frame];
  207174. if (global && [view window] != 0)
  207175. {
  207176. r = [view convertRect: r toView: nil];
  207177. NSRect wr = [[view window] frame];
  207178. r.origin.x += wr.origin.x;
  207179. r.origin.y += wr.origin.y;
  207180. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207181. }
  207182. else
  207183. {
  207184. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207185. }
  207186. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207187. }
  207188. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207189. {
  207190. return getBounds (! isSharedWindow);
  207191. }
  207192. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207193. {
  207194. return getBounds (true).getPosition();
  207195. }
  207196. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207197. {
  207198. return relativePosition + getScreenPosition();
  207199. }
  207200. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207201. {
  207202. return screenPosition - getScreenPosition();
  207203. }
  207204. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207205. {
  207206. if (constrainer != 0)
  207207. {
  207208. NSRect current = [window frame];
  207209. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207210. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207211. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207212. (int) r.size.width, (int) r.size.height);
  207213. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207214. (int) current.size.width, (int) current.size.height);
  207215. constrainer->checkBounds (pos, original,
  207216. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207217. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207218. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207219. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207220. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207221. r.origin.x = pos.getX();
  207222. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207223. r.size.width = pos.getWidth();
  207224. r.size.height = pos.getHeight();
  207225. }
  207226. return r;
  207227. }
  207228. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207229. {
  207230. if (! isSharedWindow)
  207231. {
  207232. if (shouldBeMinimised)
  207233. [window miniaturize: nil];
  207234. else
  207235. [window deminiaturize: nil];
  207236. }
  207237. }
  207238. bool NSViewComponentPeer::isMinimised() const
  207239. {
  207240. return window != 0 && [window isMiniaturized];
  207241. }
  207242. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207243. {
  207244. if (! isSharedWindow)
  207245. {
  207246. Rectangle<int> r (lastNonFullscreenBounds);
  207247. setMinimised (false);
  207248. if (fullScreen != shouldBeFullScreen)
  207249. {
  207250. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207251. {
  207252. fullScreen = true;
  207253. [window performZoom: nil];
  207254. }
  207255. else
  207256. {
  207257. if (shouldBeFullScreen)
  207258. r = Desktop::getInstance().getMainMonitorArea();
  207259. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207260. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207261. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207262. }
  207263. }
  207264. }
  207265. }
  207266. bool NSViewComponentPeer::isFullScreen() const
  207267. {
  207268. return fullScreen;
  207269. }
  207270. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207271. {
  207272. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207273. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207274. return false;
  207275. NSPoint p;
  207276. p.x = (float) position.getX();
  207277. p.y = (float) position.getY();
  207278. NSView* v = [view hitTest: p];
  207279. if (trueIfInAChildWindow)
  207280. return v != nil;
  207281. return v == view;
  207282. }
  207283. const BorderSize NSViewComponentPeer::getFrameSize() const
  207284. {
  207285. BorderSize b;
  207286. if (! isSharedWindow)
  207287. {
  207288. NSRect v = [view convertRect: [view frame] toView: nil];
  207289. NSRect w = [window frame];
  207290. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207291. b.setBottom ((int) v.origin.y);
  207292. b.setLeft ((int) v.origin.x);
  207293. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207294. }
  207295. return b;
  207296. }
  207297. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207298. {
  207299. if (! isSharedWindow)
  207300. {
  207301. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207302. : NSNormalWindowLevel];
  207303. }
  207304. return true;
  207305. }
  207306. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207307. {
  207308. if (isSharedWindow)
  207309. {
  207310. [[view superview] addSubview: view
  207311. positioned: NSWindowAbove
  207312. relativeTo: nil];
  207313. }
  207314. if (window != 0 && component->isVisible())
  207315. {
  207316. if (makeActiveWindow)
  207317. [window makeKeyAndOrderFront: nil];
  207318. else
  207319. [window orderFront: nil];
  207320. if (! recursiveToFrontCall)
  207321. {
  207322. recursiveToFrontCall = true;
  207323. handleBroughtToFront();
  207324. recursiveToFrontCall = false;
  207325. }
  207326. }
  207327. }
  207328. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207329. {
  207330. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207331. if (isSharedWindow)
  207332. {
  207333. [[view superview] addSubview: view
  207334. positioned: NSWindowBelow
  207335. relativeTo: o->view];
  207336. }
  207337. else
  207338. {
  207339. [window orderWindow: NSWindowBelow
  207340. relativeTo: o->window != 0 ? [o->window windowNumber]
  207341. : nil ];
  207342. }
  207343. }
  207344. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207345. {
  207346. // to do..
  207347. }
  207348. void NSViewComponentPeer::viewFocusGain()
  207349. {
  207350. if (currentlyFocusedPeer != this)
  207351. {
  207352. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207353. currentlyFocusedPeer->handleFocusLoss();
  207354. currentlyFocusedPeer = this;
  207355. handleFocusGain();
  207356. }
  207357. }
  207358. void NSViewComponentPeer::viewFocusLoss()
  207359. {
  207360. if (currentlyFocusedPeer == this)
  207361. {
  207362. currentlyFocusedPeer = 0;
  207363. handleFocusLoss();
  207364. }
  207365. }
  207366. void juce_HandleProcessFocusChange()
  207367. {
  207368. NSViewComponentPeer::keysCurrentlyDown.clear();
  207369. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207370. {
  207371. if (Process::isForegroundProcess())
  207372. {
  207373. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207374. ComponentPeer::bringModalComponentToFront();
  207375. }
  207376. else
  207377. {
  207378. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207379. // turn kiosk mode off if we lose focus..
  207380. Desktop::getInstance().setKioskModeComponent (0);
  207381. }
  207382. }
  207383. }
  207384. bool NSViewComponentPeer::isFocused() const
  207385. {
  207386. return isSharedWindow ? this == currentlyFocusedPeer
  207387. : (window != 0 && [window isKeyWindow]);
  207388. }
  207389. void NSViewComponentPeer::grabFocus()
  207390. {
  207391. if (window != 0)
  207392. {
  207393. [window makeKeyWindow];
  207394. [window makeFirstResponder: view];
  207395. viewFocusGain();
  207396. }
  207397. }
  207398. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207399. {
  207400. }
  207401. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207402. {
  207403. String unicode (nsStringToJuce ([ev characters]));
  207404. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207405. int keyCode = getKeyCodeFromEvent (ev);
  207406. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207407. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207408. if (unicode.isNotEmpty() || keyCode != 0)
  207409. {
  207410. if (isKeyDown)
  207411. {
  207412. bool used = false;
  207413. while (unicode.length() > 0)
  207414. {
  207415. juce_wchar textCharacter = unicode[0];
  207416. unicode = unicode.substring (1);
  207417. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207418. textCharacter = 0;
  207419. used = handleKeyUpOrDown (true) || used;
  207420. used = handleKeyPress (keyCode, textCharacter) || used;
  207421. }
  207422. return used;
  207423. }
  207424. else
  207425. {
  207426. if (handleKeyUpOrDown (false))
  207427. return true;
  207428. }
  207429. }
  207430. return false;
  207431. }
  207432. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207433. {
  207434. updateKeysDown (ev, true);
  207435. bool used = handleKeyEvent (ev, true);
  207436. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207437. {
  207438. // for command keys, the key-up event is thrown away, so simulate one..
  207439. updateKeysDown (ev, false);
  207440. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207441. }
  207442. // (If we're running modally, don't allow unused keystrokes to be passed
  207443. // along to other blocked views..)
  207444. if (Component::getCurrentlyModalComponent() != 0)
  207445. used = true;
  207446. return used;
  207447. }
  207448. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207449. {
  207450. updateKeysDown (ev, false);
  207451. return handleKeyEvent (ev, false)
  207452. || Component::getCurrentlyModalComponent() != 0;
  207453. }
  207454. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207455. {
  207456. keysCurrentlyDown.clear();
  207457. handleKeyUpOrDown (true);
  207458. updateModifiers (ev);
  207459. handleModifierKeysChange();
  207460. }
  207461. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207462. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207463. {
  207464. if ([ev type] == NSKeyDown)
  207465. return redirectKeyDown (ev);
  207466. else if ([ev type] == NSKeyUp)
  207467. return redirectKeyUp (ev);
  207468. return false;
  207469. }
  207470. #endif
  207471. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207472. {
  207473. updateModifiers (ev);
  207474. handleMouseEvent (getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207475. }
  207476. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207477. {
  207478. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207479. sendMouseEvent (ev);
  207480. }
  207481. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207482. {
  207483. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207484. sendMouseEvent (ev);
  207485. showArrowCursorIfNeeded();
  207486. }
  207487. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207488. {
  207489. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207490. sendMouseEvent (ev);
  207491. }
  207492. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207493. {
  207494. currentModifiers = currentModifiers.withoutMouseButtons();
  207495. sendMouseEvent (ev);
  207496. showArrowCursorIfNeeded();
  207497. }
  207498. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207499. {
  207500. currentModifiers = currentModifiers.withoutMouseButtons();
  207501. sendMouseEvent (ev);
  207502. }
  207503. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207504. {
  207505. currentModifiers = currentModifiers.withoutMouseButtons();
  207506. sendMouseEvent (ev);
  207507. }
  207508. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207509. {
  207510. updateModifiers (ev);
  207511. handleMouseWheel (getMousePos (ev, view), getMouseTime (ev),
  207512. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207513. }
  207514. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207515. {
  207516. if (Component::getComponentUnderMouse() == 0
  207517. && Desktop::getInstance().findComponentAt (Desktop::getInstance().getMousePosition()) == 0)
  207518. {
  207519. [[NSCursor arrowCursor] set];
  207520. }
  207521. }
  207522. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207523. {
  207524. NSString* bestType
  207525. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207526. if (bestType == nil)
  207527. return false;
  207528. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207529. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207530. StringArray files;
  207531. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207532. if (list == nil)
  207533. return false;
  207534. if ([list isKindOfClass: [NSArray class]])
  207535. {
  207536. NSArray* items = (NSArray*) list;
  207537. for (unsigned int i = 0; i < [items count]; ++i)
  207538. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207539. }
  207540. if (files.size() == 0)
  207541. return false;
  207542. if (type == 0)
  207543. handleFileDragMove (files, pos);
  207544. else if (type == 1)
  207545. handleFileDragExit (files);
  207546. else if (type == 2)
  207547. handleFileDragDrop (files, pos);
  207548. return true;
  207549. }
  207550. bool NSViewComponentPeer::isOpaque()
  207551. {
  207552. if (! getComponent()->isValidComponent())
  207553. return true;
  207554. return getComponent()->isOpaque();
  207555. }
  207556. void NSViewComponentPeer::drawRect (NSRect r)
  207557. {
  207558. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207559. return;
  207560. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207561. if (! component->isOpaque())
  207562. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207563. #if USE_COREGRAPHICS_RENDERING
  207564. if (usingCoreGraphics)
  207565. {
  207566. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207567. insideDrawRect = true;
  207568. handlePaint (context);
  207569. insideDrawRect = false;
  207570. }
  207571. else
  207572. #endif
  207573. {
  207574. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207575. (int) (r.size.width + 0.5f),
  207576. (int) (r.size.height + 0.5f),
  207577. ! getComponent()->isOpaque());
  207578. LowLevelGraphicsSoftwareRenderer context (temp);
  207579. context.setOrigin (-roundToInt (r.origin.x),
  207580. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207581. const NSRect* rects = 0;
  207582. NSInteger numRects = 0;
  207583. [view getRectsBeingDrawn: &rects count: &numRects];
  207584. RectangleList clip;
  207585. for (int i = 0; i < numRects; ++i)
  207586. {
  207587. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207588. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207589. roundToInt (rects[i].size.width),
  207590. roundToInt (rects[i].size.height)));
  207591. }
  207592. if (context.clipToRectangleList (clip))
  207593. {
  207594. insideDrawRect = true;
  207595. handlePaint (context);
  207596. insideDrawRect = false;
  207597. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207598. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207599. CGColorSpaceRelease (colourSpace);
  207600. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207601. CGImageRelease (image);
  207602. }
  207603. }
  207604. }
  207605. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207606. {
  207607. StringArray s;
  207608. s.add ("Software Renderer");
  207609. #if USE_COREGRAPHICS_RENDERING
  207610. s.add ("CoreGraphics Renderer");
  207611. #endif
  207612. return s;
  207613. }
  207614. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207615. {
  207616. return usingCoreGraphics ? 1 : 0;
  207617. }
  207618. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207619. {
  207620. #if USE_COREGRAPHICS_RENDERING
  207621. if (usingCoreGraphics != (index > 0))
  207622. {
  207623. usingCoreGraphics = index > 0;
  207624. [view setNeedsDisplay: true];
  207625. }
  207626. #endif
  207627. }
  207628. bool NSViewComponentPeer::canBecomeKeyWindow()
  207629. {
  207630. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207631. }
  207632. bool NSViewComponentPeer::windowShouldClose()
  207633. {
  207634. if (! isValidPeer (this))
  207635. return YES;
  207636. handleUserClosingWindow();
  207637. return NO;
  207638. }
  207639. void NSViewComponentPeer::redirectMovedOrResized()
  207640. {
  207641. handleMovedOrResized();
  207642. }
  207643. void NSViewComponentPeer::viewMovedToWindow()
  207644. {
  207645. if (isSharedWindow)
  207646. window = [view window];
  207647. }
  207648. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207649. {
  207650. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207651. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207652. // is apparently still available in 64-bit apps..
  207653. if (enableOrDisable)
  207654. {
  207655. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207656. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207657. }
  207658. else
  207659. {
  207660. SetSystemUIMode (kUIModeNormal, 0);
  207661. }
  207662. }
  207663. class AsyncRepaintMessage : public CallbackMessage
  207664. {
  207665. public:
  207666. NSViewComponentPeer* const peer;
  207667. const Rectangle<int> rect;
  207668. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207669. : peer (peer_), rect (rect_)
  207670. {
  207671. }
  207672. void messageCallback()
  207673. {
  207674. if (ComponentPeer::isValidPeer (peer))
  207675. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207676. }
  207677. };
  207678. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207679. {
  207680. if (insideDrawRect)
  207681. {
  207682. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207683. }
  207684. else
  207685. {
  207686. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207687. (float) w, (float) h)];
  207688. }
  207689. }
  207690. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207691. {
  207692. [view displayIfNeeded];
  207693. }
  207694. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207695. {
  207696. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207697. }
  207698. Image* juce_createIconForFile (const File& file)
  207699. {
  207700. const ScopedAutoReleasePool pool;
  207701. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207702. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207703. [NSGraphicsContext saveGraphicsState];
  207704. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207705. [image drawAtPoint: NSMakePoint (0, 0)
  207706. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207707. operation: NSCompositeSourceOver fraction: 1.0f];
  207708. [[NSGraphicsContext currentContext] flushGraphics];
  207709. [NSGraphicsContext restoreGraphicsState];
  207710. return result;
  207711. }
  207712. const int KeyPress::spaceKey = ' ';
  207713. const int KeyPress::returnKey = 0x0d;
  207714. const int KeyPress::escapeKey = 0x1b;
  207715. const int KeyPress::backspaceKey = 0x7f;
  207716. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207717. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207718. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207719. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207720. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207721. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207722. const int KeyPress::endKey = NSEndFunctionKey;
  207723. const int KeyPress::homeKey = NSHomeFunctionKey;
  207724. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207725. const int KeyPress::insertKey = -1;
  207726. const int KeyPress::tabKey = 9;
  207727. const int KeyPress::F1Key = NSF1FunctionKey;
  207728. const int KeyPress::F2Key = NSF2FunctionKey;
  207729. const int KeyPress::F3Key = NSF3FunctionKey;
  207730. const int KeyPress::F4Key = NSF4FunctionKey;
  207731. const int KeyPress::F5Key = NSF5FunctionKey;
  207732. const int KeyPress::F6Key = NSF6FunctionKey;
  207733. const int KeyPress::F7Key = NSF7FunctionKey;
  207734. const int KeyPress::F8Key = NSF8FunctionKey;
  207735. const int KeyPress::F9Key = NSF9FunctionKey;
  207736. const int KeyPress::F10Key = NSF10FunctionKey;
  207737. const int KeyPress::F11Key = NSF1FunctionKey;
  207738. const int KeyPress::F12Key = NSF12FunctionKey;
  207739. const int KeyPress::F13Key = NSF13FunctionKey;
  207740. const int KeyPress::F14Key = NSF14FunctionKey;
  207741. const int KeyPress::F15Key = NSF15FunctionKey;
  207742. const int KeyPress::F16Key = NSF16FunctionKey;
  207743. const int KeyPress::numberPad0 = 0x30020;
  207744. const int KeyPress::numberPad1 = 0x30021;
  207745. const int KeyPress::numberPad2 = 0x30022;
  207746. const int KeyPress::numberPad3 = 0x30023;
  207747. const int KeyPress::numberPad4 = 0x30024;
  207748. const int KeyPress::numberPad5 = 0x30025;
  207749. const int KeyPress::numberPad6 = 0x30026;
  207750. const int KeyPress::numberPad7 = 0x30027;
  207751. const int KeyPress::numberPad8 = 0x30028;
  207752. const int KeyPress::numberPad9 = 0x30029;
  207753. const int KeyPress::numberPadAdd = 0x3002a;
  207754. const int KeyPress::numberPadSubtract = 0x3002b;
  207755. const int KeyPress::numberPadMultiply = 0x3002c;
  207756. const int KeyPress::numberPadDivide = 0x3002d;
  207757. const int KeyPress::numberPadSeparator = 0x3002e;
  207758. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207759. const int KeyPress::numberPadEquals = 0x30030;
  207760. const int KeyPress::numberPadDelete = 0x30031;
  207761. const int KeyPress::playKey = 0x30000;
  207762. const int KeyPress::stopKey = 0x30001;
  207763. const int KeyPress::fastForwardKey = 0x30002;
  207764. const int KeyPress::rewindKey = 0x30003;
  207765. #endif
  207766. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207767. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207768. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207769. // compiled on its own).
  207770. #if JUCE_INCLUDED_FILE
  207771. #if JUCE_MAC
  207772. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207773. {
  207774. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207775. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207776. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207777. [im release];
  207778. return (void*) c;
  207779. }
  207780. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207781. {
  207782. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  207783. jassert (im != 0);
  207784. if (im == 0)
  207785. return 0;
  207786. return juce_createMouseCursorFromImage (*im,
  207787. (int) (hx * im->getWidth()),
  207788. (int) (hy * im->getHeight()));
  207789. }
  207790. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207791. {
  207792. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207793. MemoryBlock mb;
  207794. if (f.getChildFile (filename).loadFileAsData (mb))
  207795. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207796. return 0;
  207797. }
  207798. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207799. {
  207800. const ScopedAutoReleasePool pool;
  207801. NSCursor* c = 0;
  207802. switch (type)
  207803. {
  207804. case MouseCursor::NormalCursor:
  207805. c = [NSCursor arrowCursor];
  207806. break;
  207807. case MouseCursor::NoCursor:
  207808. {
  207809. Image blank (Image::ARGB, 8, 8, true);
  207810. return juce_createMouseCursorFromImage (blank, 0, 0);
  207811. }
  207812. case MouseCursor::DraggingHandCursor:
  207813. c = [NSCursor openHandCursor];
  207814. break;
  207815. case MouseCursor::CopyingCursor:
  207816. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207817. case MouseCursor::WaitCursor:
  207818. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207819. break;
  207820. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207821. case MouseCursor::IBeamCursor:
  207822. c = [NSCursor IBeamCursor];
  207823. break;
  207824. case MouseCursor::PointingHandCursor:
  207825. c = [NSCursor pointingHandCursor];
  207826. break;
  207827. case MouseCursor::LeftRightResizeCursor:
  207828. c = [NSCursor resizeLeftRightCursor];
  207829. break;
  207830. case MouseCursor::LeftEdgeResizeCursor:
  207831. c = [NSCursor resizeLeftCursor];
  207832. break;
  207833. case MouseCursor::RightEdgeResizeCursor:
  207834. c = [NSCursor resizeRightCursor];
  207835. break;
  207836. case MouseCursor::UpDownResizeCursor:
  207837. case MouseCursor::TopEdgeResizeCursor:
  207838. case MouseCursor::BottomEdgeResizeCursor:
  207839. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207840. case MouseCursor::TopLeftCornerResizeCursor:
  207841. case MouseCursor::BottomRightCornerResizeCursor:
  207842. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207843. case MouseCursor::TopRightCornerResizeCursor:
  207844. case MouseCursor::BottomLeftCornerResizeCursor:
  207845. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207846. case MouseCursor::UpDownLeftRightResizeCursor:
  207847. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207848. case MouseCursor::CrosshairCursor:
  207849. c = [NSCursor crosshairCursor];
  207850. break;
  207851. }
  207852. [c retain];
  207853. return (void*) c;
  207854. }
  207855. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207856. {
  207857. NSCursor* c = (NSCursor*) cursorHandle;
  207858. [c release];
  207859. }
  207860. void MouseCursor::showInAllWindows() const throw()
  207861. {
  207862. showInWindow (0);
  207863. }
  207864. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207865. {
  207866. NSCursor* const c = (NSCursor*) getHandle();
  207867. [c set];
  207868. }
  207869. #else
  207870. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207871. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207872. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207873. void MouseCursor::showInAllWindows() const throw() {}
  207874. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207875. #endif
  207876. #endif
  207877. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207878. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207879. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207880. // compiled on its own).
  207881. #if JUCE_INCLUDED_FILE
  207882. class NSViewComponentInternal : public ComponentMovementWatcher
  207883. {
  207884. Component* const owner;
  207885. NSViewComponentPeer* currentPeer;
  207886. bool wasShowing;
  207887. public:
  207888. NSView* const view;
  207889. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207890. : ComponentMovementWatcher (owner_),
  207891. owner (owner_),
  207892. currentPeer (0),
  207893. wasShowing (false),
  207894. view (view_)
  207895. {
  207896. [view_ retain];
  207897. if (owner_->isShowing())
  207898. componentPeerChanged();
  207899. }
  207900. ~NSViewComponentInternal()
  207901. {
  207902. [view removeFromSuperview];
  207903. [view release];
  207904. }
  207905. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207906. {
  207907. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207908. // The ComponentMovementWatcher version of this method avoids calling
  207909. // us when the top-level comp is resized, but for an NSView we need to know this
  207910. // because with inverted co-ords, we need to update the position even if the
  207911. // top-left pos hasn't changed
  207912. if (comp.isOnDesktop() && wasResized)
  207913. componentMovedOrResized (wasMoved, wasResized);
  207914. }
  207915. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207916. {
  207917. Component* const topComp = owner->getTopLevelComponent();
  207918. if (topComp->getPeer() != 0)
  207919. {
  207920. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207921. NSRect r;
  207922. r.origin.x = (float) pos.getX();
  207923. r.origin.y = (float) pos.getY();
  207924. r.size.width = (float) owner->getWidth();
  207925. r.size.height = (float) owner->getHeight();
  207926. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207927. [view setFrame: r];
  207928. }
  207929. }
  207930. void componentPeerChanged()
  207931. {
  207932. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207933. if (currentPeer != peer)
  207934. {
  207935. [view removeFromSuperview];
  207936. currentPeer = peer;
  207937. if (peer != 0)
  207938. {
  207939. [peer->view addSubview: view];
  207940. componentMovedOrResized (false, false);
  207941. }
  207942. }
  207943. [view setHidden: ! owner->isShowing()];
  207944. }
  207945. void componentVisibilityChanged (Component&)
  207946. {
  207947. componentPeerChanged();
  207948. }
  207949. juce_UseDebuggingNewOperator
  207950. private:
  207951. NSViewComponentInternal (const NSViewComponentInternal&);
  207952. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207953. };
  207954. NSViewComponent::NSViewComponent()
  207955. {
  207956. }
  207957. NSViewComponent::~NSViewComponent()
  207958. {
  207959. }
  207960. void NSViewComponent::setView (void* view)
  207961. {
  207962. if (view != getView())
  207963. {
  207964. if (view != 0)
  207965. info = new NSViewComponentInternal ((NSView*) view, this);
  207966. else
  207967. info = 0;
  207968. }
  207969. }
  207970. void* NSViewComponent::getView() const
  207971. {
  207972. return info == 0 ? 0 : info->view;
  207973. }
  207974. void NSViewComponent::paint (Graphics& g)
  207975. {
  207976. }
  207977. #endif
  207978. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207979. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207980. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207981. // compiled on its own).
  207982. #if JUCE_INCLUDED_FILE
  207983. AppleRemoteDevice::AppleRemoteDevice()
  207984. : device (0),
  207985. queue (0),
  207986. remoteId (0)
  207987. {
  207988. }
  207989. AppleRemoteDevice::~AppleRemoteDevice()
  207990. {
  207991. stop();
  207992. }
  207993. static io_object_t getAppleRemoteDevice()
  207994. {
  207995. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207996. io_iterator_t iter = 0;
  207997. io_object_t iod = 0;
  207998. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207999. && iter != 0)
  208000. {
  208001. iod = IOIteratorNext (iter);
  208002. }
  208003. IOObjectRelease (iter);
  208004. return iod;
  208005. }
  208006. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208007. {
  208008. jassert (*device == 0);
  208009. io_name_t classname;
  208010. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208011. {
  208012. IOCFPlugInInterface** cfPlugInInterface = 0;
  208013. SInt32 score = 0;
  208014. if (IOCreatePlugInInterfaceForService (iod,
  208015. kIOHIDDeviceUserClientTypeID,
  208016. kIOCFPlugInInterfaceID,
  208017. &cfPlugInInterface,
  208018. &score) == kIOReturnSuccess)
  208019. {
  208020. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208021. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208022. device);
  208023. (void) hr;
  208024. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208025. }
  208026. }
  208027. return *device != 0;
  208028. }
  208029. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208030. {
  208031. if (queue != 0)
  208032. return true;
  208033. stop();
  208034. bool result = false;
  208035. io_object_t iod = getAppleRemoteDevice();
  208036. if (iod != 0)
  208037. {
  208038. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208039. result = true;
  208040. else
  208041. stop();
  208042. IOObjectRelease (iod);
  208043. }
  208044. return result;
  208045. }
  208046. void AppleRemoteDevice::stop()
  208047. {
  208048. if (queue != 0)
  208049. {
  208050. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208051. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208052. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208053. queue = 0;
  208054. }
  208055. if (device != 0)
  208056. {
  208057. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208058. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208059. device = 0;
  208060. }
  208061. }
  208062. bool AppleRemoteDevice::isActive() const
  208063. {
  208064. return queue != 0;
  208065. }
  208066. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208067. {
  208068. if (result == kIOReturnSuccess)
  208069. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208070. }
  208071. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208072. {
  208073. Array <int> cookies;
  208074. CFArrayRef elements;
  208075. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208076. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208077. return false;
  208078. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208079. {
  208080. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208081. // get the cookie
  208082. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208083. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208084. continue;
  208085. long number;
  208086. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208087. continue;
  208088. cookies.add ((int) number);
  208089. }
  208090. CFRelease (elements);
  208091. if ((*(IOHIDDeviceInterface**) device)
  208092. ->open ((IOHIDDeviceInterface**) device,
  208093. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208094. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208095. {
  208096. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208097. if (queue != 0)
  208098. {
  208099. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208100. for (int i = 0; i < cookies.size(); ++i)
  208101. {
  208102. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208103. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208104. }
  208105. CFRunLoopSourceRef eventSource;
  208106. if ((*(IOHIDQueueInterface**) queue)
  208107. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208108. {
  208109. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208110. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208111. {
  208112. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208113. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208114. return true;
  208115. }
  208116. }
  208117. }
  208118. }
  208119. return false;
  208120. }
  208121. void AppleRemoteDevice::handleCallbackInternal()
  208122. {
  208123. int totalValues = 0;
  208124. AbsoluteTime nullTime = { 0, 0 };
  208125. char cookies [12];
  208126. int numCookies = 0;
  208127. while (numCookies < numElementsInArray (cookies))
  208128. {
  208129. IOHIDEventStruct e;
  208130. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208131. break;
  208132. if ((int) e.elementCookie == 19)
  208133. {
  208134. remoteId = e.value;
  208135. buttonPressed (switched, false);
  208136. }
  208137. else
  208138. {
  208139. totalValues += e.value;
  208140. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208141. }
  208142. }
  208143. cookies [numCookies++] = 0;
  208144. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208145. static const char buttonPatterns[] =
  208146. {
  208147. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208148. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208149. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208150. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208151. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208152. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208153. 0x1f, 0x12, 0x04, 0x02, 0,
  208154. 0x1f, 0x12, 0x03, 0x02, 0,
  208155. 0x1f, 0x12, 0x1f, 0x12, 0,
  208156. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208157. 19, 0
  208158. };
  208159. int buttonNum = (int) menuButton;
  208160. int i = 0;
  208161. while (i < numElementsInArray (buttonPatterns))
  208162. {
  208163. if (strcmp (cookies, buttonPatterns + i) == 0)
  208164. {
  208165. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208166. break;
  208167. }
  208168. i += (int) strlen (buttonPatterns + i) + 1;
  208169. ++buttonNum;
  208170. }
  208171. }
  208172. #endif
  208173. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208174. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208175. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208176. // compiled on its own).
  208177. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208178. #if JUCE_MAC
  208179. END_JUCE_NAMESPACE
  208180. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208181. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208182. {
  208183. CriticalSection* contextLock;
  208184. bool needsUpdate;
  208185. }
  208186. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208187. - (bool) makeActive;
  208188. - (void) makeInactive;
  208189. - (void) reshape;
  208190. @end
  208191. @implementation ThreadSafeNSOpenGLView
  208192. - (id) initWithFrame: (NSRect) frameRect
  208193. pixelFormat: (NSOpenGLPixelFormat*) format
  208194. {
  208195. contextLock = new CriticalSection();
  208196. self = [super initWithFrame: frameRect pixelFormat: format];
  208197. if (self != nil)
  208198. [[NSNotificationCenter defaultCenter] addObserver: self
  208199. selector: @selector (_surfaceNeedsUpdate:)
  208200. name: NSViewGlobalFrameDidChangeNotification
  208201. object: self];
  208202. return self;
  208203. }
  208204. - (void) dealloc
  208205. {
  208206. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208207. delete contextLock;
  208208. [super dealloc];
  208209. }
  208210. - (bool) makeActive
  208211. {
  208212. const ScopedLock sl (*contextLock);
  208213. if ([self openGLContext] == 0)
  208214. return false;
  208215. [[self openGLContext] makeCurrentContext];
  208216. if (needsUpdate)
  208217. {
  208218. [super update];
  208219. needsUpdate = false;
  208220. }
  208221. return true;
  208222. }
  208223. - (void) makeInactive
  208224. {
  208225. const ScopedLock sl (*contextLock);
  208226. [NSOpenGLContext clearCurrentContext];
  208227. }
  208228. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208229. {
  208230. const ScopedLock sl (*contextLock);
  208231. needsUpdate = true;
  208232. }
  208233. - (void) update
  208234. {
  208235. const ScopedLock sl (*contextLock);
  208236. needsUpdate = true;
  208237. }
  208238. - (void) reshape
  208239. {
  208240. const ScopedLock sl (*contextLock);
  208241. needsUpdate = true;
  208242. }
  208243. @end
  208244. BEGIN_JUCE_NAMESPACE
  208245. class WindowedGLContext : public OpenGLContext
  208246. {
  208247. public:
  208248. WindowedGLContext (Component* const component,
  208249. const OpenGLPixelFormat& pixelFormat_,
  208250. NSOpenGLContext* sharedContext)
  208251. : renderContext (0),
  208252. pixelFormat (pixelFormat_)
  208253. {
  208254. jassert (component != 0);
  208255. NSOpenGLPixelFormatAttribute attribs [64];
  208256. int n = 0;
  208257. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208258. attribs[n++] = NSOpenGLPFAAccelerated;
  208259. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208260. attribs[n++] = NSOpenGLPFAColorSize;
  208261. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208262. pixelFormat.greenBits,
  208263. pixelFormat.blueBits);
  208264. attribs[n++] = NSOpenGLPFAAlphaSize;
  208265. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208266. attribs[n++] = NSOpenGLPFADepthSize;
  208267. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208268. attribs[n++] = NSOpenGLPFAStencilSize;
  208269. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208270. attribs[n++] = NSOpenGLPFAAccumSize;
  208271. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208272. pixelFormat.accumulationBufferGreenBits,
  208273. pixelFormat.accumulationBufferBlueBits,
  208274. pixelFormat.accumulationBufferAlphaBits);
  208275. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208276. attribs[n++] = NSOpenGLPFASampleBuffers;
  208277. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208278. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208279. attribs[n++] = NSOpenGLPFANoRecovery;
  208280. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208281. NSOpenGLPixelFormat* format
  208282. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208283. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208284. pixelFormat: format];
  208285. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208286. shareContext: sharedContext] autorelease];
  208287. const GLint swapInterval = 1;
  208288. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208289. [view setOpenGLContext: renderContext];
  208290. [renderContext setView: view];
  208291. [format release];
  208292. viewHolder = new NSViewComponentInternal (view, component);
  208293. }
  208294. ~WindowedGLContext()
  208295. {
  208296. makeInactive();
  208297. [renderContext clearDrawable];
  208298. viewHolder = 0;
  208299. }
  208300. bool makeActive() const throw()
  208301. {
  208302. jassert (renderContext != 0);
  208303. [view makeActive];
  208304. return isActive();
  208305. }
  208306. bool makeInactive() const throw()
  208307. {
  208308. [view makeInactive];
  208309. return true;
  208310. }
  208311. bool isActive() const throw()
  208312. {
  208313. return [NSOpenGLContext currentContext] == renderContext;
  208314. }
  208315. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208316. void* getRawContext() const throw() { return renderContext; }
  208317. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208318. {
  208319. }
  208320. void swapBuffers()
  208321. {
  208322. [renderContext flushBuffer];
  208323. }
  208324. bool setSwapInterval (const int numFramesPerSwap)
  208325. {
  208326. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208327. forParameter: NSOpenGLCPSwapInterval];
  208328. return true;
  208329. }
  208330. int getSwapInterval() const
  208331. {
  208332. GLint numFrames = 0;
  208333. [renderContext getValues: &numFrames
  208334. forParameter: NSOpenGLCPSwapInterval];
  208335. return numFrames;
  208336. }
  208337. void repaint()
  208338. {
  208339. // we need to invalidate the juce view that holds this gl view, to make it
  208340. // cause a repaint callback
  208341. NSView* v = (NSView*) viewHolder->view;
  208342. NSRect r = [v frame];
  208343. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208344. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208345. // repaint message, thus never causing our paint() callback, and never repainting
  208346. // the comp. So invalidating just a little bit around the edge helps..
  208347. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208348. }
  208349. void* getNativeWindowHandle() const { return viewHolder->view; }
  208350. juce_UseDebuggingNewOperator
  208351. NSOpenGLContext* renderContext;
  208352. ThreadSafeNSOpenGLView* view;
  208353. private:
  208354. OpenGLPixelFormat pixelFormat;
  208355. ScopedPointer <NSViewComponentInternal> viewHolder;
  208356. WindowedGLContext (const WindowedGLContext&);
  208357. WindowedGLContext& operator= (const WindowedGLContext&);
  208358. };
  208359. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208360. const OpenGLPixelFormat& pixelFormat,
  208361. const OpenGLContext* const contextToShareWith)
  208362. {
  208363. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208364. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208365. return (c->renderContext != 0) ? c.release() : 0;
  208366. }
  208367. void* OpenGLComponent::getNativeWindowHandle() const
  208368. {
  208369. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208370. : 0;
  208371. }
  208372. void juce_glViewport (const int w, const int h)
  208373. {
  208374. glViewport (0, 0, w, h);
  208375. }
  208376. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208377. OwnedArray <OpenGLPixelFormat>& results)
  208378. {
  208379. /* GLint attribs [64];
  208380. int n = 0;
  208381. attribs[n++] = AGL_RGBA;
  208382. attribs[n++] = AGL_DOUBLEBUFFER;
  208383. attribs[n++] = AGL_ACCELERATED;
  208384. attribs[n++] = AGL_NO_RECOVERY;
  208385. attribs[n++] = AGL_NONE;
  208386. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208387. while (p != 0)
  208388. {
  208389. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208390. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208391. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208392. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208393. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208394. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208395. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208396. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208397. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208398. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208399. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208400. results.add (pf);
  208401. p = aglNextPixelFormat (p);
  208402. }*/
  208403. //jassertfalse //xxx can't see how you do this in cocoa!
  208404. }
  208405. #else
  208406. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208407. const OpenGLPixelFormat& pixelFormat,
  208408. const OpenGLContext* const contextToShareWith)
  208409. {
  208410. return 0;
  208411. }
  208412. void juce_glViewport (const int w, const int h)
  208413. {
  208414. //glViewport (0, 0, w, h);
  208415. }
  208416. #endif
  208417. #endif
  208418. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208419. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208420. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208421. // compiled on its own).
  208422. #if JUCE_INCLUDED_FILE
  208423. class JuceMainMenuHandler;
  208424. END_JUCE_NAMESPACE
  208425. using namespace JUCE_NAMESPACE;
  208426. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208427. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208428. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208429. #else
  208430. @interface JuceMenuCallback : NSObject
  208431. #endif
  208432. {
  208433. JuceMainMenuHandler* owner;
  208434. }
  208435. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208436. - (void) dealloc;
  208437. - (void) menuItemInvoked: (id) menu;
  208438. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208439. @end
  208440. BEGIN_JUCE_NAMESPACE
  208441. class JuceMainMenuHandler : private MenuBarModelListener,
  208442. private DeletedAtShutdown
  208443. {
  208444. public:
  208445. static JuceMainMenuHandler* instance;
  208446. JuceMainMenuHandler()
  208447. : currentModel (0),
  208448. lastUpdateTime (0)
  208449. {
  208450. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208451. }
  208452. ~JuceMainMenuHandler()
  208453. {
  208454. setMenu (0);
  208455. jassert (instance == this);
  208456. instance = 0;
  208457. [callback release];
  208458. }
  208459. void setMenu (MenuBarModel* const newMenuBarModel)
  208460. {
  208461. if (currentModel != newMenuBarModel)
  208462. {
  208463. if (currentModel != 0)
  208464. currentModel->removeListener (this);
  208465. currentModel = newMenuBarModel;
  208466. if (currentModel != 0)
  208467. currentModel->addListener (this);
  208468. menuBarItemsChanged (0);
  208469. }
  208470. }
  208471. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208472. const String& name, const int menuId, const int tag)
  208473. {
  208474. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208475. action: nil
  208476. keyEquivalent: @""];
  208477. [item setTag: tag];
  208478. NSMenu* sub = createMenu (child, name, menuId, tag);
  208479. [parent setSubmenu: sub forItem: item];
  208480. [sub setAutoenablesItems: false];
  208481. [sub release];
  208482. }
  208483. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208484. const String& name, const int menuId, const int tag)
  208485. {
  208486. [parentItem setTag: tag];
  208487. NSMenu* menu = [parentItem submenu];
  208488. [menu setTitle: juceStringToNS (name)];
  208489. while ([menu numberOfItems] > 0)
  208490. [menu removeItemAtIndex: 0];
  208491. PopupMenu::MenuItemIterator iter (menuToCopy);
  208492. while (iter.next())
  208493. addMenuItem (iter, menu, menuId, tag);
  208494. [menu setAutoenablesItems: false];
  208495. [menu update];
  208496. }
  208497. void menuBarItemsChanged (MenuBarModel*)
  208498. {
  208499. lastUpdateTime = Time::getMillisecondCounter();
  208500. StringArray menuNames;
  208501. if (currentModel != 0)
  208502. menuNames = currentModel->getMenuBarNames();
  208503. NSMenu* menuBar = [NSApp mainMenu];
  208504. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208505. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208506. int menuId = 1;
  208507. for (int i = 0; i < menuNames.size(); ++i)
  208508. {
  208509. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208510. if (i >= [menuBar numberOfItems] - 1)
  208511. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208512. else
  208513. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208514. }
  208515. }
  208516. static void flashMenuBar (NSMenu* menu)
  208517. {
  208518. if ([[menu title] isEqualToString: @"Apple"])
  208519. return;
  208520. [menu retain];
  208521. const unichar f35Key = NSF35FunctionKey;
  208522. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208523. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208524. action: nil
  208525. keyEquivalent: f35String];
  208526. [item setTarget: nil];
  208527. [menu insertItem: item atIndex: [menu numberOfItems]];
  208528. [item release];
  208529. if ([menu indexOfItem: item] >= 0)
  208530. {
  208531. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208532. location: NSZeroPoint
  208533. modifierFlags: NSCommandKeyMask
  208534. timestamp: 0
  208535. windowNumber: 0
  208536. context: [NSGraphicsContext currentContext]
  208537. characters: f35String
  208538. charactersIgnoringModifiers: f35String
  208539. isARepeat: NO
  208540. keyCode: 0];
  208541. [menu performKeyEquivalent: f35Event];
  208542. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208543. }
  208544. [menu release];
  208545. }
  208546. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208547. {
  208548. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208549. {
  208550. NSMenuItem* m = [menu itemAtIndex: i];
  208551. if ([m tag] == info.commandID)
  208552. return m;
  208553. if ([m submenu] != 0)
  208554. {
  208555. NSMenuItem* found = findMenuItem ([m submenu], info);
  208556. if (found != 0)
  208557. return found;
  208558. }
  208559. }
  208560. return 0;
  208561. }
  208562. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208563. {
  208564. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208565. if (item != 0)
  208566. flashMenuBar ([item menu]);
  208567. }
  208568. void updateMenus()
  208569. {
  208570. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208571. menuBarItemsChanged (0);
  208572. }
  208573. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208574. {
  208575. if (currentModel != 0)
  208576. {
  208577. if (commandManager != 0)
  208578. {
  208579. ApplicationCommandTarget::InvocationInfo info (commandId);
  208580. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208581. commandManager->invoke (info, true);
  208582. }
  208583. currentModel->menuItemSelected (commandId, topLevelIndex);
  208584. }
  208585. }
  208586. MenuBarModel* currentModel;
  208587. uint32 lastUpdateTime;
  208588. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208589. const int topLevelMenuId, const int topLevelIndex)
  208590. {
  208591. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208592. if (text == 0)
  208593. text = @"";
  208594. if (iter.isSeparator)
  208595. {
  208596. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208597. }
  208598. else if (iter.isSectionHeader)
  208599. {
  208600. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208601. action: nil
  208602. keyEquivalent: @""];
  208603. [item setEnabled: false];
  208604. }
  208605. else if (iter.subMenu != 0)
  208606. {
  208607. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208608. action: nil
  208609. keyEquivalent: @""];
  208610. [item setTag: iter.itemId];
  208611. [item setEnabled: iter.isEnabled];
  208612. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208613. [sub setDelegate: nil];
  208614. [menuToAddTo setSubmenu: sub forItem: item];
  208615. [sub release];
  208616. }
  208617. else
  208618. {
  208619. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208620. action: @selector (menuItemInvoked:)
  208621. keyEquivalent: @""];
  208622. [item setTag: iter.itemId];
  208623. [item setEnabled: iter.isEnabled];
  208624. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208625. [item setTarget: (id) callback];
  208626. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208627. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208628. [item setRepresentedObject: info];
  208629. if (iter.commandManager != 0)
  208630. {
  208631. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208632. ->getKeyPressesAssignedToCommand (iter.itemId));
  208633. if (keyPresses.size() > 0)
  208634. {
  208635. const KeyPress& kp = keyPresses.getReference(0);
  208636. juce_wchar key = kp.getTextCharacter();
  208637. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208638. key = NSBackspaceCharacter;
  208639. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208640. key = NSDeleteCharacter;
  208641. else if (key == 0)
  208642. key = (juce_wchar) kp.getKeyCode();
  208643. unsigned int mods = 0;
  208644. if (kp.getModifiers().isShiftDown())
  208645. mods |= NSShiftKeyMask;
  208646. if (kp.getModifiers().isCtrlDown())
  208647. mods |= NSControlKeyMask;
  208648. if (kp.getModifiers().isAltDown())
  208649. mods |= NSAlternateKeyMask;
  208650. if (kp.getModifiers().isCommandDown())
  208651. mods |= NSCommandKeyMask;
  208652. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208653. [item setKeyEquivalentModifierMask: mods];
  208654. }
  208655. }
  208656. }
  208657. }
  208658. JuceMenuCallback* callback;
  208659. private:
  208660. NSMenu* createMenu (const PopupMenu menu,
  208661. const String& menuName,
  208662. const int topLevelMenuId,
  208663. const int topLevelIndex)
  208664. {
  208665. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208666. [m setAutoenablesItems: false];
  208667. [m setDelegate: callback];
  208668. PopupMenu::MenuItemIterator iter (menu);
  208669. while (iter.next())
  208670. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208671. [m update];
  208672. return m;
  208673. }
  208674. };
  208675. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208676. END_JUCE_NAMESPACE
  208677. @implementation JuceMenuCallback
  208678. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208679. {
  208680. [super init];
  208681. owner = owner_;
  208682. return self;
  208683. }
  208684. - (void) dealloc
  208685. {
  208686. [super dealloc];
  208687. }
  208688. - (void) menuItemInvoked: (id) menu
  208689. {
  208690. NSMenuItem* item = (NSMenuItem*) menu;
  208691. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208692. {
  208693. // 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
  208694. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208695. // into the focused component and let it trigger the menu item indirectly.
  208696. NSEvent* e = [NSApp currentEvent];
  208697. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208698. {
  208699. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent())
  208700. {
  208701. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208702. if (peer != 0)
  208703. {
  208704. if ([e type] == NSKeyDown)
  208705. peer->redirectKeyDown (e);
  208706. else
  208707. peer->redirectKeyUp (e);
  208708. return;
  208709. }
  208710. }
  208711. }
  208712. NSArray* info = (NSArray*) [item representedObject];
  208713. owner->invoke ((int) [item tag],
  208714. (ApplicationCommandManager*) (pointer_sized_int)
  208715. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208716. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208717. }
  208718. }
  208719. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208720. {
  208721. if (JuceMainMenuHandler::instance != 0)
  208722. JuceMainMenuHandler::instance->updateMenus();
  208723. }
  208724. @end
  208725. BEGIN_JUCE_NAMESPACE
  208726. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208727. const PopupMenu* extraItems)
  208728. {
  208729. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208730. {
  208731. PopupMenu::MenuItemIterator iter (*extraItems);
  208732. while (iter.next())
  208733. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208734. [menu addItem: [NSMenuItem separatorItem]];
  208735. }
  208736. NSMenuItem* item;
  208737. // Services...
  208738. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208739. action: nil keyEquivalent: @""];
  208740. [menu addItem: item];
  208741. [item release];
  208742. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208743. [menu setSubmenu: servicesMenu forItem: item];
  208744. [NSApp setServicesMenu: servicesMenu];
  208745. [servicesMenu release];
  208746. [menu addItem: [NSMenuItem separatorItem]];
  208747. // Hide + Show stuff...
  208748. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208749. action: @selector (hide:) keyEquivalent: @"h"];
  208750. [item setTarget: NSApp];
  208751. [menu addItem: item];
  208752. [item release];
  208753. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208754. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208755. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208756. [item setTarget: NSApp];
  208757. [menu addItem: item];
  208758. [item release];
  208759. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208760. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208761. [item setTarget: NSApp];
  208762. [menu addItem: item];
  208763. [item release];
  208764. [menu addItem: [NSMenuItem separatorItem]];
  208765. // Quit item....
  208766. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208767. action: @selector (terminate:) keyEquivalent: @"q"];
  208768. [item setTarget: NSApp];
  208769. [menu addItem: item];
  208770. [item release];
  208771. return menu;
  208772. }
  208773. // Since our app has no NIB, this initialises a standard app menu...
  208774. static void rebuildMainMenu (const PopupMenu* extraItems)
  208775. {
  208776. // this can't be used in a plugin!
  208777. jassert (JUCEApplication::getInstance() != 0);
  208778. if (JUCEApplication::getInstance() != 0)
  208779. {
  208780. const ScopedAutoReleasePool pool;
  208781. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208782. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208783. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208784. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208785. [mainMenu setSubmenu: appMenu forItem: item];
  208786. [NSApp setMainMenu: mainMenu];
  208787. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208788. [appMenu release];
  208789. [mainMenu release];
  208790. }
  208791. }
  208792. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208793. const PopupMenu* extraAppleMenuItems)
  208794. {
  208795. if (getMacMainMenu() != newMenuBarModel)
  208796. {
  208797. const ScopedAutoReleasePool pool;
  208798. if (newMenuBarModel == 0)
  208799. {
  208800. delete JuceMainMenuHandler::instance;
  208801. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208802. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208803. extraAppleMenuItems = 0;
  208804. }
  208805. else
  208806. {
  208807. if (JuceMainMenuHandler::instance == 0)
  208808. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208809. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208810. }
  208811. }
  208812. rebuildMainMenu (extraAppleMenuItems);
  208813. if (newMenuBarModel != 0)
  208814. newMenuBarModel->menuItemsChanged();
  208815. }
  208816. MenuBarModel* MenuBarModel::getMacMainMenu()
  208817. {
  208818. return JuceMainMenuHandler::instance != 0
  208819. ? JuceMainMenuHandler::instance->currentModel : 0;
  208820. }
  208821. void initialiseMainMenu()
  208822. {
  208823. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208824. rebuildMainMenu (0);
  208825. }
  208826. #endif
  208827. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208828. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208829. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208830. // compiled on its own).
  208831. #if JUCE_INCLUDED_FILE
  208832. #if JUCE_MAC
  208833. END_JUCE_NAMESPACE
  208834. using namespace JUCE_NAMESPACE;
  208835. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208836. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208837. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208838. #else
  208839. @interface JuceFileChooserDelegate : NSObject
  208840. #endif
  208841. {
  208842. StringArray* filters;
  208843. }
  208844. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208845. - (void) dealloc;
  208846. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208847. @end
  208848. @implementation JuceFileChooserDelegate
  208849. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208850. {
  208851. [super init];
  208852. filters = filters_;
  208853. return self;
  208854. }
  208855. - (void) dealloc
  208856. {
  208857. delete filters;
  208858. [super dealloc];
  208859. }
  208860. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208861. {
  208862. const File f (nsStringToJuce (filename));
  208863. for (int i = filters->size(); --i >= 0;)
  208864. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208865. return true;
  208866. return f.isDirectory();
  208867. }
  208868. @end
  208869. BEGIN_JUCE_NAMESPACE
  208870. void FileChooser::showPlatformDialog (Array<File>& results,
  208871. const String& title,
  208872. const File& currentFileOrDirectory,
  208873. const String& filter,
  208874. bool selectsDirectory,
  208875. bool selectsFiles,
  208876. bool isSaveDialogue,
  208877. bool warnAboutOverwritingExistingFiles,
  208878. bool selectMultipleFiles,
  208879. FilePreviewComponent* extraInfoComponent)
  208880. {
  208881. const ScopedAutoReleasePool pool;
  208882. StringArray* filters = new StringArray();
  208883. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  208884. filters->trim();
  208885. filters->removeEmptyStrings();
  208886. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208887. [delegate autorelease];
  208888. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208889. : [NSOpenPanel openPanel];
  208890. [panel setTitle: juceStringToNS (title)];
  208891. if (! isSaveDialogue)
  208892. {
  208893. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208894. [openPanel setCanChooseDirectories: selectsDirectory];
  208895. [openPanel setCanChooseFiles: selectsFiles];
  208896. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208897. }
  208898. [panel setDelegate: delegate];
  208899. if (isSaveDialogue || selectsDirectory)
  208900. [panel setCanCreateDirectories: YES];
  208901. String directory, filename;
  208902. if (currentFileOrDirectory.isDirectory())
  208903. {
  208904. directory = currentFileOrDirectory.getFullPathName();
  208905. }
  208906. else
  208907. {
  208908. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208909. filename = currentFileOrDirectory.getFileName();
  208910. }
  208911. if ([panel runModalForDirectory: juceStringToNS (directory)
  208912. file: juceStringToNS (filename)]
  208913. == NSOKButton)
  208914. {
  208915. if (isSaveDialogue)
  208916. {
  208917. results.add (File (nsStringToJuce ([panel filename])));
  208918. }
  208919. else
  208920. {
  208921. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208922. NSArray* urls = [openPanel filenames];
  208923. for (unsigned int i = 0; i < [urls count]; ++i)
  208924. {
  208925. NSString* f = [urls objectAtIndex: i];
  208926. results.add (File (nsStringToJuce (f)));
  208927. }
  208928. }
  208929. }
  208930. [panel setDelegate: nil];
  208931. }
  208932. #else
  208933. void FileChooser::showPlatformDialog (Array<File>& results,
  208934. const String& title,
  208935. const File& currentFileOrDirectory,
  208936. const String& filter,
  208937. bool selectsDirectory,
  208938. bool selectsFiles,
  208939. bool isSaveDialogue,
  208940. bool warnAboutOverwritingExistingFiles,
  208941. bool selectMultipleFiles,
  208942. FilePreviewComponent* extraInfoComponent)
  208943. {
  208944. const ScopedAutoReleasePool pool;
  208945. jassertfalse //xxx to do
  208946. }
  208947. #endif
  208948. #endif
  208949. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  208950. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  208951. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208952. // compiled on its own).
  208953. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  208954. #define theMovie ((QTMovie*) movie)
  208955. QuickTimeMovieComponent::QuickTimeMovieComponent()
  208956. : movie (0)
  208957. {
  208958. setOpaque (true);
  208959. setVisible (true);
  208960. QTMovieView* view = [[QTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  208961. setView (view);
  208962. }
  208963. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  208964. {
  208965. closeMovie();
  208966. setView (0);
  208967. }
  208968. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  208969. {
  208970. return true;
  208971. }
  208972. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  208973. {
  208974. // unfortunately, QTMovie objects can only be created on the main thread..
  208975. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  208976. QTMovie* movie = 0;
  208977. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  208978. if (fin != 0)
  208979. {
  208980. movieFile = fin->getFile();
  208981. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  208982. error: nil];
  208983. }
  208984. else
  208985. {
  208986. MemoryBlock temp;
  208987. movieStream->readIntoMemoryBlock (temp);
  208988. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  208989. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  208990. {
  208991. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  208992. length: temp.getSize()]
  208993. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  208994. MIMEType: @""]
  208995. error: nil];
  208996. if (movie != 0)
  208997. break;
  208998. }
  208999. }
  209000. return movie;
  209001. }
  209002. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209003. const bool isControllerVisible_)
  209004. {
  209005. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209006. }
  209007. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209008. const bool controllerVisible_)
  209009. {
  209010. closeMovie();
  209011. if (getPeer() == 0)
  209012. {
  209013. // To open a movie, this component must be visible inside a functioning window, so that
  209014. // the QT control can be assigned to the window.
  209015. jassertfalse
  209016. return false;
  209017. }
  209018. movie = openMovieFromStream (movieStream, movieFile);
  209019. [theMovie retain];
  209020. QTMovieView* view = (QTMovieView*) getView();
  209021. [view setMovie: theMovie];
  209022. [view setControllerVisible: controllerVisible_];
  209023. setLooping (looping);
  209024. return movie != nil;
  209025. }
  209026. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209027. const bool isControllerVisible_)
  209028. {
  209029. // unfortunately, QTMovie objects can only be created on the main thread..
  209030. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209031. closeMovie();
  209032. if (getPeer() == 0)
  209033. {
  209034. // To open a movie, this component must be visible inside a functioning window, so that
  209035. // the QT control can be assigned to the window.
  209036. jassertfalse
  209037. return false;
  209038. }
  209039. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209040. NSError* err;
  209041. if ([QTMovie canInitWithURL: url])
  209042. movie = [QTMovie movieWithURL: url error: &err];
  209043. [theMovie retain];
  209044. QTMovieView* view = (QTMovieView*) getView();
  209045. [view setMovie: theMovie];
  209046. [view setControllerVisible: controllerVisible];
  209047. setLooping (looping);
  209048. return movie != nil;
  209049. }
  209050. void QuickTimeMovieComponent::closeMovie()
  209051. {
  209052. stop();
  209053. QTMovieView* view = (QTMovieView*) getView();
  209054. [view setMovie: nil];
  209055. [theMovie release];
  209056. movie = 0;
  209057. movieFile = File::nonexistent;
  209058. }
  209059. bool QuickTimeMovieComponent::isMovieOpen() const
  209060. {
  209061. return movie != nil;
  209062. }
  209063. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209064. {
  209065. return movieFile;
  209066. }
  209067. void QuickTimeMovieComponent::play()
  209068. {
  209069. [theMovie play];
  209070. }
  209071. void QuickTimeMovieComponent::stop()
  209072. {
  209073. [theMovie stop];
  209074. }
  209075. bool QuickTimeMovieComponent::isPlaying() const
  209076. {
  209077. return movie != 0 && [theMovie rate] != 0;
  209078. }
  209079. void QuickTimeMovieComponent::setPosition (const double seconds)
  209080. {
  209081. if (movie != 0)
  209082. {
  209083. QTTime t;
  209084. t.timeValue = (uint64) (100000.0 * seconds);
  209085. t.timeScale = 100000;
  209086. t.flags = 0;
  209087. [theMovie setCurrentTime: t];
  209088. }
  209089. }
  209090. double QuickTimeMovieComponent::getPosition() const
  209091. {
  209092. if (movie == 0)
  209093. return 0.0;
  209094. QTTime t = [theMovie currentTime];
  209095. return t.timeValue / (double) t.timeScale;
  209096. }
  209097. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209098. {
  209099. [theMovie setRate: newSpeed];
  209100. }
  209101. double QuickTimeMovieComponent::getMovieDuration() const
  209102. {
  209103. if (movie == 0)
  209104. return 0.0;
  209105. QTTime t = [theMovie duration];
  209106. return t.timeValue / (double) t.timeScale;
  209107. }
  209108. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209109. {
  209110. looping = shouldLoop;
  209111. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209112. forKey: QTMovieLoopsAttribute];
  209113. }
  209114. bool QuickTimeMovieComponent::isLooping() const
  209115. {
  209116. return looping;
  209117. }
  209118. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209119. {
  209120. [theMovie setVolume: newVolume];
  209121. }
  209122. float QuickTimeMovieComponent::getMovieVolume() const
  209123. {
  209124. return movie != 0 ? [theMovie volume] : 0.0f;
  209125. }
  209126. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209127. {
  209128. width = 0;
  209129. height = 0;
  209130. if (movie != 0)
  209131. {
  209132. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209133. width = (int) s.width;
  209134. height = (int) s.height;
  209135. }
  209136. }
  209137. void QuickTimeMovieComponent::paint (Graphics& g)
  209138. {
  209139. if (movie == 0)
  209140. g.fillAll (Colours::black);
  209141. }
  209142. bool QuickTimeMovieComponent::isControllerVisible() const
  209143. {
  209144. return controllerVisible;
  209145. }
  209146. void QuickTimeMovieComponent::goToStart()
  209147. {
  209148. setPosition (0.0);
  209149. }
  209150. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209151. const RectanglePlacement& placement)
  209152. {
  209153. int normalWidth, normalHeight;
  209154. getMovieNormalSize (normalWidth, normalHeight);
  209155. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209156. {
  209157. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209158. placement.applyTo (x, y, w, h,
  209159. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209160. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209161. if (w > 0 && h > 0)
  209162. {
  209163. setBounds (roundToInt (x), roundToInt (y),
  209164. roundToInt (w), roundToInt (h));
  209165. }
  209166. }
  209167. else
  209168. {
  209169. setBounds (spaceToFitWithin);
  209170. }
  209171. }
  209172. #if ! (JUCE_MAC && JUCE_64BIT)
  209173. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209174. {
  209175. if (movieStream == 0)
  209176. return false;
  209177. File file;
  209178. QTMovie* movie = openMovieFromStream (movieStream, file);
  209179. if (movie != nil)
  209180. result = [movie quickTimeMovie];
  209181. return movie != nil;
  209182. }
  209183. #endif
  209184. #endif
  209185. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209186. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209187. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209188. // compiled on its own).
  209189. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209190. const int kilobytesPerSecond1x = 176;
  209191. END_JUCE_NAMESPACE
  209192. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209193. @interface OpenDiskDevice : NSObject
  209194. {
  209195. @public
  209196. DRDevice* device;
  209197. NSMutableArray* tracks;
  209198. bool underrunProtection;
  209199. }
  209200. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209201. - (void) dealloc;
  209202. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209203. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209204. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209205. @end
  209206. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209207. @interface AudioTrackProducer : NSObject
  209208. {
  209209. JUCE_NAMESPACE::AudioSource* source;
  209210. int readPosition, lengthInFrames;
  209211. }
  209212. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209213. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209214. - (void) dealloc;
  209215. - (void) setupTrackProperties: (DRTrack*) track;
  209216. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209217. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209218. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209219. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209220. toMedia:(NSDictionary*)mediaInfo;
  209221. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209222. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209223. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209224. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209225. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209226. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209227. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209228. ioFlags:(uint32_t*)flags;
  209229. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209230. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209231. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209232. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209233. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209234. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209235. ioFlags:(uint32_t*)flags;
  209236. @end
  209237. @implementation OpenDiskDevice
  209238. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209239. {
  209240. [super init];
  209241. device = device_;
  209242. tracks = [[NSMutableArray alloc] init];
  209243. underrunProtection = true;
  209244. return self;
  209245. }
  209246. - (void) dealloc
  209247. {
  209248. [tracks release];
  209249. [super dealloc];
  209250. }
  209251. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209252. {
  209253. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209254. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209255. [p setupTrackProperties: t];
  209256. [tracks addObject: t];
  209257. [t release];
  209258. [p release];
  209259. }
  209260. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209261. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209262. {
  209263. DRBurn* burn = [DRBurn burnForDevice: device];
  209264. if (! [device acquireExclusiveAccess])
  209265. {
  209266. *error = "Couldn't open or write to the CD device";
  209267. return;
  209268. }
  209269. [device acquireMediaReservation];
  209270. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209271. [d autorelease];
  209272. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209273. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209274. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209275. if (burnSpeed > 0)
  209276. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209277. if (! underrunProtection)
  209278. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209279. [burn setProperties: d];
  209280. [burn writeLayout: tracks];
  209281. for (;;)
  209282. {
  209283. JUCE_NAMESPACE::Thread::sleep (300);
  209284. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209285. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209286. {
  209287. [burn abort];
  209288. *error = "User cancelled the write operation";
  209289. break;
  209290. }
  209291. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209292. {
  209293. *error = "Write operation failed";
  209294. break;
  209295. }
  209296. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209297. {
  209298. break;
  209299. }
  209300. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209301. objectForKey: DRErrorStatusErrorStringKey];
  209302. if ([err length] > 0)
  209303. {
  209304. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209305. break;
  209306. }
  209307. }
  209308. [device releaseMediaReservation];
  209309. [device releaseExclusiveAccess];
  209310. }
  209311. @end
  209312. @implementation AudioTrackProducer
  209313. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209314. {
  209315. lengthInFrames = lengthInFrames_;
  209316. readPosition = 0;
  209317. return self;
  209318. }
  209319. - (void) setupTrackProperties: (DRTrack*) track
  209320. {
  209321. NSMutableDictionary* p = [[track properties] mutableCopy];
  209322. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209323. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209324. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209325. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209326. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209327. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209328. [track setProperties: p];
  209329. [p release];
  209330. }
  209331. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209332. {
  209333. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209334. if (s != nil)
  209335. s->source = source_;
  209336. return s;
  209337. }
  209338. - (void) dealloc
  209339. {
  209340. if (source != 0)
  209341. {
  209342. source->releaseResources();
  209343. delete source;
  209344. }
  209345. [super dealloc];
  209346. }
  209347. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209348. {
  209349. }
  209350. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209351. {
  209352. return true;
  209353. }
  209354. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209355. {
  209356. return lengthInFrames;
  209357. }
  209358. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209359. toMedia: (NSDictionary*) mediaInfo
  209360. {
  209361. if (source != 0)
  209362. source->prepareToPlay (44100 / 75, 44100);
  209363. readPosition = 0;
  209364. return true;
  209365. }
  209366. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209367. {
  209368. if (source != 0)
  209369. source->prepareToPlay (44100 / 75, 44100);
  209370. return true;
  209371. }
  209372. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209373. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209374. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209375. {
  209376. if (source != 0)
  209377. {
  209378. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209379. if (numSamples > 0)
  209380. {
  209381. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209382. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209383. info.buffer = &tempBuffer;
  209384. info.startSample = 0;
  209385. info.numSamples = numSamples;
  209386. source->getNextAudioBlock (info);
  209387. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209388. buffer, numSamples, 4);
  209389. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209390. buffer + 2, numSamples, 4);
  209391. readPosition += numSamples;
  209392. }
  209393. return numSamples * 4;
  209394. }
  209395. return 0;
  209396. }
  209397. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209398. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209399. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209400. ioFlags: (uint32_t*) flags
  209401. {
  209402. zeromem (buffer, bufferLength);
  209403. return bufferLength;
  209404. }
  209405. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209406. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209407. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209408. {
  209409. return true;
  209410. }
  209411. @end
  209412. BEGIN_JUCE_NAMESPACE
  209413. class AudioCDBurner::Pimpl : public Timer
  209414. {
  209415. public:
  209416. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209417. : device (0), owner (owner_)
  209418. {
  209419. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209420. if (dev != 0)
  209421. {
  209422. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209423. lastState = getDiskState();
  209424. startTimer (1000);
  209425. }
  209426. }
  209427. ~Pimpl()
  209428. {
  209429. stopTimer();
  209430. [device release];
  209431. }
  209432. void timerCallback()
  209433. {
  209434. const DiskState state = getDiskState();
  209435. if (state != lastState)
  209436. {
  209437. lastState = state;
  209438. owner.sendChangeMessage (&owner);
  209439. }
  209440. }
  209441. DiskState getDiskState() const
  209442. {
  209443. if ([device->device isValid])
  209444. {
  209445. NSDictionary* status = [device->device status];
  209446. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209447. if ([state isEqualTo: DRDeviceMediaStateNone])
  209448. {
  209449. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209450. return trayOpen;
  209451. return noDisc;
  209452. }
  209453. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209454. {
  209455. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209456. return writableDiskPresent;
  209457. else
  209458. return readOnlyDiskPresent;
  209459. }
  209460. }
  209461. return unknown;
  209462. }
  209463. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209464. const Array<int> getAvailableWriteSpeeds() const
  209465. {
  209466. Array<int> results;
  209467. if ([device->device isValid])
  209468. {
  209469. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209470. for (unsigned int i = 0; i < [speeds count]; ++i)
  209471. {
  209472. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209473. results.add (kbPerSec / kilobytesPerSecond1x);
  209474. }
  209475. }
  209476. return results;
  209477. }
  209478. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209479. {
  209480. if ([device->device isValid])
  209481. {
  209482. device->underrunProtection = shouldBeEnabled;
  209483. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209484. }
  209485. return false;
  209486. }
  209487. int getNumAvailableAudioBlocks() const
  209488. {
  209489. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209490. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209491. }
  209492. OpenDiskDevice* device;
  209493. private:
  209494. DiskState lastState;
  209495. AudioCDBurner& owner;
  209496. };
  209497. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209498. {
  209499. pimpl = new Pimpl (*this, deviceIndex);
  209500. }
  209501. AudioCDBurner::~AudioCDBurner()
  209502. {
  209503. }
  209504. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209505. {
  209506. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209507. if (b->pimpl->device == 0)
  209508. b = 0;
  209509. return b.release();
  209510. }
  209511. static NSArray* findDiskBurnerDevices()
  209512. {
  209513. NSMutableArray* results = [NSMutableArray array];
  209514. NSArray* devs = [DRDevice devices];
  209515. if (devs != 0)
  209516. {
  209517. int num = [devs count];
  209518. int i;
  209519. for (i = 0; i < num; ++i)
  209520. {
  209521. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209522. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209523. if (name != nil)
  209524. [results addObject: name];
  209525. }
  209526. }
  209527. return results;
  209528. }
  209529. const StringArray AudioCDBurner::findAvailableDevices()
  209530. {
  209531. NSArray* names = findDiskBurnerDevices();
  209532. StringArray s;
  209533. for (unsigned int i = 0; i < [names count]; ++i)
  209534. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209535. return s;
  209536. }
  209537. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209538. {
  209539. return pimpl->getDiskState();
  209540. }
  209541. bool AudioCDBurner::isDiskPresent() const
  209542. {
  209543. return getDiskState() == writableDiskPresent;
  209544. }
  209545. bool AudioCDBurner::openTray()
  209546. {
  209547. return pimpl->openTray();
  209548. }
  209549. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209550. {
  209551. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209552. DiskState oldState = getDiskState();
  209553. DiskState newState = oldState;
  209554. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209555. {
  209556. newState = getDiskState();
  209557. Thread::sleep (100);
  209558. }
  209559. return newState;
  209560. }
  209561. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209562. {
  209563. return pimpl->getAvailableWriteSpeeds();
  209564. }
  209565. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209566. {
  209567. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209568. }
  209569. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209570. {
  209571. return pimpl->getNumAvailableAudioBlocks();
  209572. }
  209573. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209574. {
  209575. if ([pimpl->device->device isValid])
  209576. {
  209577. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209578. return true;
  209579. }
  209580. return false;
  209581. }
  209582. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209583. bool ejectDiscAfterwards,
  209584. bool performFakeBurnForTesting,
  209585. int writeSpeed)
  209586. {
  209587. String error ("Couldn't open or write to the CD device");
  209588. if ([pimpl->device->device isValid])
  209589. {
  209590. error = String::empty;
  209591. [pimpl->device burn: listener
  209592. errorString: &error
  209593. ejectAfterwards: ejectDiscAfterwards
  209594. isFake: performFakeBurnForTesting
  209595. speed: writeSpeed];
  209596. }
  209597. return error;
  209598. }
  209599. #endif
  209600. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209601. void AudioCDReader::ejectDisk()
  209602. {
  209603. const ScopedAutoReleasePool p;
  209604. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209605. }
  209606. #endif
  209607. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209608. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209609. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209610. // compiled on its own).
  209611. #if JUCE_INCLUDED_FILE
  209612. struct CallbackMessagePayload
  209613. {
  209614. MessageCallbackFunction* function;
  209615. void* parameter;
  209616. void* volatile result;
  209617. bool volatile hasBeenExecuted;
  209618. };
  209619. class AppDelegateRedirector
  209620. {
  209621. public:
  209622. AppDelegateRedirector()
  209623. {
  209624. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209625. runLoop = CFRunLoopGetMain();
  209626. #else
  209627. runLoop = CFRunLoopGetCurrent();
  209628. #endif
  209629. CFRunLoopSourceContext sourceContext;
  209630. zerostruct (sourceContext);
  209631. sourceContext.info = this;
  209632. sourceContext.perform = runLoopSourceCallback;
  209633. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209634. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209635. }
  209636. virtual ~AppDelegateRedirector()
  209637. {
  209638. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209639. CFRunLoopSourceInvalidate (runLoopSource);
  209640. CFRelease (runLoopSource);
  209641. while (messages.size() > 0)
  209642. delete ((Message*) messages.remove(0));
  209643. }
  209644. virtual NSApplicationTerminateReply shouldTerminate()
  209645. {
  209646. if (JUCEApplication::getInstance() != 0)
  209647. {
  209648. JUCEApplication::getInstance()->systemRequestedQuit();
  209649. return NSTerminateCancel;
  209650. }
  209651. return NSTerminateNow;
  209652. }
  209653. virtual BOOL openFile (const NSString* filename)
  209654. {
  209655. if (JUCEApplication::getInstance() != 0)
  209656. {
  209657. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209658. return YES;
  209659. }
  209660. return NO;
  209661. }
  209662. virtual void openFiles (NSArray* filenames)
  209663. {
  209664. StringArray files;
  209665. for (unsigned int i = 0; i < [filenames count]; ++i)
  209666. {
  209667. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209668. if (filename.containsChar (T(' ')))
  209669. filename = filename.quoted('"');
  209670. files.add (filename);
  209671. }
  209672. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209673. {
  209674. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209675. }
  209676. }
  209677. virtual void focusChanged()
  209678. {
  209679. juce_HandleProcessFocusChange();
  209680. }
  209681. virtual void performCallback (CallbackMessagePayload* pl)
  209682. {
  209683. pl->result = (*pl->function) (pl->parameter);
  209684. pl->hasBeenExecuted = true;
  209685. }
  209686. virtual void deleteSelf()
  209687. {
  209688. delete this;
  209689. }
  209690. void postMessage (void* m)
  209691. {
  209692. messages.add (m);
  209693. CFRunLoopSourceSignal (runLoopSource);
  209694. CFRunLoopWakeUp (runLoop);
  209695. }
  209696. private:
  209697. CFRunLoopRef runLoop;
  209698. CFRunLoopSourceRef runLoopSource;
  209699. Array <void*, CriticalSection> messages;
  209700. void runLoopCallback()
  209701. {
  209702. int numDispatched = 0;
  209703. do
  209704. {
  209705. void* const nextMessage = messages.remove (0);
  209706. if (nextMessage == 0)
  209707. return;
  209708. const ScopedAutoReleasePool pool;
  209709. MessageManager::getInstance()->deliverMessage (nextMessage);
  209710. } while (++numDispatched <= 4);
  209711. CFRunLoopSourceSignal (runLoopSource);
  209712. CFRunLoopWakeUp (runLoop);
  209713. }
  209714. static void runLoopSourceCallback (void* info)
  209715. {
  209716. ((AppDelegateRedirector*) info)->runLoopCallback();
  209717. }
  209718. };
  209719. END_JUCE_NAMESPACE
  209720. using namespace JUCE_NAMESPACE;
  209721. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209722. @interface JuceAppDelegate : NSObject
  209723. {
  209724. @private
  209725. id oldDelegate;
  209726. @public
  209727. AppDelegateRedirector* redirector;
  209728. }
  209729. - (JuceAppDelegate*) init;
  209730. - (void) dealloc;
  209731. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209732. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209733. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209734. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209735. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209736. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209737. - (void) performCallback: (id) info;
  209738. - (void) dummyMethod;
  209739. @end
  209740. @implementation JuceAppDelegate
  209741. - (JuceAppDelegate*) init
  209742. {
  209743. [super init];
  209744. redirector = new AppDelegateRedirector();
  209745. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209746. if (JUCEApplication::getInstance() != 0)
  209747. {
  209748. oldDelegate = [NSApp delegate];
  209749. [NSApp setDelegate: self];
  209750. }
  209751. else
  209752. {
  209753. oldDelegate = 0;
  209754. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209755. name: NSApplicationDidResignActiveNotification object: NSApp];
  209756. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209757. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209758. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209759. name: NSApplicationWillUnhideNotification object: NSApp];
  209760. }
  209761. return self;
  209762. }
  209763. - (void) dealloc
  209764. {
  209765. if (oldDelegate != 0)
  209766. [NSApp setDelegate: oldDelegate];
  209767. redirector->deleteSelf();
  209768. [super dealloc];
  209769. }
  209770. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209771. {
  209772. return redirector->shouldTerminate();
  209773. }
  209774. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209775. {
  209776. return redirector->openFile (filename);
  209777. }
  209778. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209779. {
  209780. return redirector->openFiles (filenames);
  209781. }
  209782. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209783. {
  209784. redirector->focusChanged();
  209785. }
  209786. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209787. {
  209788. redirector->focusChanged();
  209789. }
  209790. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209791. {
  209792. redirector->focusChanged();
  209793. }
  209794. - (void) performCallback: (id) info
  209795. {
  209796. if ([info isKindOfClass: [NSData class]])
  209797. {
  209798. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209799. if (pl != 0)
  209800. redirector->performCallback (pl);
  209801. }
  209802. else
  209803. {
  209804. jassertfalse // should never get here!
  209805. }
  209806. }
  209807. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209808. @end
  209809. BEGIN_JUCE_NAMESPACE
  209810. static JuceAppDelegate* juceAppDelegate = 0;
  209811. void MessageManager::runDispatchLoop()
  209812. {
  209813. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209814. {
  209815. const ScopedAutoReleasePool pool;
  209816. // must only be called by the message thread!
  209817. jassert (isThisTheMessageThread());
  209818. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209819. @try
  209820. {
  209821. [NSApp run];
  209822. }
  209823. @catch (NSException* e)
  209824. {
  209825. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209826. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209827. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209828. }
  209829. @finally
  209830. {
  209831. }
  209832. #else
  209833. [NSApp run];
  209834. #endif
  209835. }
  209836. }
  209837. void MessageManager::stopDispatchLoop()
  209838. {
  209839. quitMessagePosted = true;
  209840. [NSApp stop: nil];
  209841. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209842. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209843. }
  209844. static bool isEventBlockedByModalComps (NSEvent* e)
  209845. {
  209846. if (Component::getNumCurrentlyModalComponents() == 0)
  209847. return false;
  209848. NSWindow* const w = [e window];
  209849. if (w == 0 || [w worksWhenModal])
  209850. return false;
  209851. bool isKey = false, isInputAttempt = false;
  209852. switch ([e type])
  209853. {
  209854. case NSKeyDown:
  209855. case NSKeyUp:
  209856. isKey = isInputAttempt = true;
  209857. break;
  209858. case NSLeftMouseDown:
  209859. case NSRightMouseDown:
  209860. case NSOtherMouseDown:
  209861. isInputAttempt = true;
  209862. break;
  209863. case NSLeftMouseDragged:
  209864. case NSRightMouseDragged:
  209865. case NSLeftMouseUp:
  209866. case NSRightMouseUp:
  209867. case NSOtherMouseUp:
  209868. case NSOtherMouseDragged:
  209869. if (Component::getComponentUnderMouse() != 0)
  209870. return false;
  209871. break;
  209872. case NSMouseMoved:
  209873. case NSMouseEntered:
  209874. case NSMouseExited:
  209875. case NSCursorUpdate:
  209876. case NSScrollWheel:
  209877. case NSTabletPoint:
  209878. case NSTabletProximity:
  209879. break;
  209880. default:
  209881. return false;
  209882. }
  209883. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209884. {
  209885. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209886. NSView* const compView = (NSView*) peer->getNativeHandle();
  209887. if ([compView window] == w)
  209888. {
  209889. if (isKey)
  209890. {
  209891. if (compView == [w firstResponder])
  209892. return false;
  209893. }
  209894. else
  209895. {
  209896. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209897. [compView bounds]))
  209898. return false;
  209899. }
  209900. }
  209901. }
  209902. if (isInputAttempt)
  209903. {
  209904. if (! [NSApp isActive])
  209905. [NSApp activateIgnoringOtherApps: YES];
  209906. Component* const modal = Component::getCurrentlyModalComponent (0);
  209907. if (modal != 0)
  209908. modal->inputAttemptWhenModal();
  209909. }
  209910. return true;
  209911. }
  209912. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209913. {
  209914. const ScopedAutoReleasePool pool;
  209915. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209916. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209917. while (! quitMessagePosted)
  209918. {
  209919. const ScopedAutoReleasePool pool2;
  209920. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209921. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209922. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209923. inMode: NSDefaultRunLoopMode
  209924. dequeue: YES];
  209925. if (e != 0 && ! isEventBlockedByModalComps (e))
  209926. [NSApp sendEvent: e];
  209927. if (Time::getMillisecondCounter() >= endTime)
  209928. break;
  209929. }
  209930. return ! quitMessagePosted;
  209931. }
  209932. void MessageManager::doPlatformSpecificInitialisation()
  209933. {
  209934. if (juceAppDelegate == 0)
  209935. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209936. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209937. // correctly (needed prior to 10.5)
  209938. if (! [NSThread isMultiThreaded])
  209939. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209940. toTarget: juceAppDelegate
  209941. withObject: nil];
  209942. initialiseMainMenu();
  209943. }
  209944. void MessageManager::doPlatformSpecificShutdown()
  209945. {
  209946. if (juceAppDelegate != 0)
  209947. {
  209948. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  209949. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  209950. [juceAppDelegate release];
  209951. juceAppDelegate = 0;
  209952. }
  209953. }
  209954. bool juce_postMessageToSystemQueue (void* message)
  209955. {
  209956. juceAppDelegate->redirector->postMessage (message);
  209957. return true;
  209958. }
  209959. void MessageManager::broadcastMessage (const String& value) throw()
  209960. {
  209961. }
  209962. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  209963. void* data)
  209964. {
  209965. if (isThisTheMessageThread())
  209966. {
  209967. return (*callback) (data);
  209968. }
  209969. else
  209970. {
  209971. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  209972. // deadlock because the message manager is blocked from running, so can never
  209973. // call your function..
  209974. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  209975. const ScopedAutoReleasePool pool;
  209976. CallbackMessagePayload cmp;
  209977. cmp.function = callback;
  209978. cmp.parameter = data;
  209979. cmp.result = 0;
  209980. cmp.hasBeenExecuted = false;
  209981. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  209982. withObject: [NSData dataWithBytesNoCopy: &cmp
  209983. length: sizeof (cmp)
  209984. freeWhenDone: NO]
  209985. waitUntilDone: YES];
  209986. return cmp.result;
  209987. }
  209988. }
  209989. #endif
  209990. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  209991. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  209992. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209993. // compiled on its own).
  209994. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  209995. #if JUCE_MAC
  209996. END_JUCE_NAMESPACE
  209997. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  209998. @interface DownloadClickDetector : NSObject
  209999. {
  210000. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210001. }
  210002. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210003. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210004. request: (NSURLRequest*) request
  210005. frame: (WebFrame*) frame
  210006. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210007. @end
  210008. @implementation DownloadClickDetector
  210009. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210010. {
  210011. [super init];
  210012. ownerComponent = ownerComponent_;
  210013. return self;
  210014. }
  210015. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210016. request: (NSURLRequest*) request
  210017. frame: (WebFrame*) frame
  210018. decisionListener: (id <WebPolicyDecisionListener>) listener
  210019. {
  210020. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210021. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210022. [listener use];
  210023. else
  210024. [listener ignore];
  210025. }
  210026. @end
  210027. BEGIN_JUCE_NAMESPACE
  210028. class WebBrowserComponentInternal : public NSViewComponent
  210029. {
  210030. public:
  210031. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210032. {
  210033. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210034. frameName: @""
  210035. groupName: @""];
  210036. setView (webView);
  210037. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210038. [webView setPolicyDelegate: clickListener];
  210039. }
  210040. ~WebBrowserComponentInternal()
  210041. {
  210042. [webView setPolicyDelegate: nil];
  210043. [clickListener release];
  210044. setView (0);
  210045. }
  210046. void goToURL (const String& url,
  210047. const StringArray* headers,
  210048. const MemoryBlock* postData)
  210049. {
  210050. NSMutableURLRequest* r
  210051. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210052. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210053. timeoutInterval: 30.0];
  210054. if (postData != 0 && postData->getSize() > 0)
  210055. {
  210056. [r setHTTPMethod: @"POST"];
  210057. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210058. length: postData->getSize()]];
  210059. }
  210060. if (headers != 0)
  210061. {
  210062. for (int i = 0; i < headers->size(); ++i)
  210063. {
  210064. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210065. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210066. [r setValue: juceStringToNS (headerValue)
  210067. forHTTPHeaderField: juceStringToNS (headerName)];
  210068. }
  210069. }
  210070. stop();
  210071. [[webView mainFrame] loadRequest: r];
  210072. }
  210073. void goBack()
  210074. {
  210075. [webView goBack];
  210076. }
  210077. void goForward()
  210078. {
  210079. [webView goForward];
  210080. }
  210081. void stop()
  210082. {
  210083. [webView stopLoading: nil];
  210084. }
  210085. void refresh()
  210086. {
  210087. [webView reload: nil];
  210088. }
  210089. private:
  210090. WebView* webView;
  210091. DownloadClickDetector* clickListener;
  210092. };
  210093. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210094. : browser (0),
  210095. blankPageShown (false),
  210096. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210097. {
  210098. setOpaque (true);
  210099. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210100. }
  210101. WebBrowserComponent::~WebBrowserComponent()
  210102. {
  210103. deleteAndZero (browser);
  210104. }
  210105. void WebBrowserComponent::goToURL (const String& url,
  210106. const StringArray* headers,
  210107. const MemoryBlock* postData)
  210108. {
  210109. lastURL = url;
  210110. lastHeaders.clear();
  210111. if (headers != 0)
  210112. lastHeaders = *headers;
  210113. lastPostData.setSize (0);
  210114. if (postData != 0)
  210115. lastPostData = *postData;
  210116. blankPageShown = false;
  210117. browser->goToURL (url, headers, postData);
  210118. }
  210119. void WebBrowserComponent::stop()
  210120. {
  210121. browser->stop();
  210122. }
  210123. void WebBrowserComponent::goBack()
  210124. {
  210125. lastURL = String::empty;
  210126. blankPageShown = false;
  210127. browser->goBack();
  210128. }
  210129. void WebBrowserComponent::goForward()
  210130. {
  210131. lastURL = String::empty;
  210132. browser->goForward();
  210133. }
  210134. void WebBrowserComponent::refresh()
  210135. {
  210136. browser->refresh();
  210137. }
  210138. void WebBrowserComponent::paint (Graphics& g)
  210139. {
  210140. }
  210141. void WebBrowserComponent::checkWindowAssociation()
  210142. {
  210143. if (isShowing())
  210144. {
  210145. if (blankPageShown)
  210146. goBack();
  210147. }
  210148. else
  210149. {
  210150. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210151. {
  210152. // when the component becomes invisible, some stuff like flash
  210153. // carries on playing audio, so we need to force it onto a blank
  210154. // page to avoid this, (and send it back when it's made visible again).
  210155. blankPageShown = true;
  210156. browser->goToURL ("about:blank", 0, 0);
  210157. }
  210158. }
  210159. }
  210160. void WebBrowserComponent::reloadLastURL()
  210161. {
  210162. if (lastURL.isNotEmpty())
  210163. {
  210164. goToURL (lastURL, &lastHeaders, &lastPostData);
  210165. lastURL = String::empty;
  210166. }
  210167. }
  210168. void WebBrowserComponent::parentHierarchyChanged()
  210169. {
  210170. checkWindowAssociation();
  210171. }
  210172. void WebBrowserComponent::resized()
  210173. {
  210174. browser->setSize (getWidth(), getHeight());
  210175. }
  210176. void WebBrowserComponent::visibilityChanged()
  210177. {
  210178. checkWindowAssociation();
  210179. }
  210180. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210181. {
  210182. return true;
  210183. }
  210184. #else
  210185. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210186. {
  210187. }
  210188. WebBrowserComponent::~WebBrowserComponent()
  210189. {
  210190. }
  210191. void WebBrowserComponent::goToURL (const String& url,
  210192. const StringArray* headers,
  210193. const MemoryBlock* postData)
  210194. {
  210195. }
  210196. void WebBrowserComponent::stop()
  210197. {
  210198. }
  210199. void WebBrowserComponent::goBack()
  210200. {
  210201. }
  210202. void WebBrowserComponent::goForward()
  210203. {
  210204. }
  210205. void WebBrowserComponent::refresh()
  210206. {
  210207. }
  210208. void WebBrowserComponent::paint (Graphics& g)
  210209. {
  210210. }
  210211. void WebBrowserComponent::checkWindowAssociation()
  210212. {
  210213. }
  210214. void WebBrowserComponent::reloadLastURL()
  210215. {
  210216. }
  210217. void WebBrowserComponent::parentHierarchyChanged()
  210218. {
  210219. }
  210220. void WebBrowserComponent::resized()
  210221. {
  210222. }
  210223. void WebBrowserComponent::visibilityChanged()
  210224. {
  210225. }
  210226. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210227. {
  210228. return true;
  210229. }
  210230. #endif
  210231. #endif
  210232. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210233. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210234. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210235. // compiled on its own).
  210236. #if JUCE_INCLUDED_FILE
  210237. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210238. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210239. #endif
  210240. #undef log
  210241. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210242. #define log(a) Logger::writeToLog (a)
  210243. #else
  210244. #define log(a)
  210245. #endif
  210246. #undef OK
  210247. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210248. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210249. {
  210250. if (err == noErr)
  210251. return true;
  210252. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210253. jassertfalse
  210254. return false;
  210255. }
  210256. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210257. #else
  210258. #define OK(a) (a == noErr)
  210259. #endif
  210260. class CoreAudioInternal : public Timer
  210261. {
  210262. public:
  210263. CoreAudioInternal (AudioDeviceID id)
  210264. : inputLatency (0),
  210265. outputLatency (0),
  210266. callback (0),
  210267. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210268. audioProcID (0),
  210269. #endif
  210270. inputDevice (0),
  210271. isSlaveDevice (false),
  210272. deviceID (id),
  210273. started (false),
  210274. sampleRate (0),
  210275. bufferSize (512),
  210276. numInputChans (0),
  210277. numOutputChans (0),
  210278. callbacksAllowed (true),
  210279. numInputChannelInfos (0),
  210280. numOutputChannelInfos (0)
  210281. {
  210282. jassert (deviceID != 0);
  210283. updateDetailsFromDevice();
  210284. AudioObjectPropertyAddress pa;
  210285. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210286. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210287. pa.mElement = kAudioObjectPropertyElementWildcard;
  210288. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210289. }
  210290. ~CoreAudioInternal()
  210291. {
  210292. AudioObjectPropertyAddress pa;
  210293. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210294. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210295. pa.mElement = kAudioObjectPropertyElementWildcard;
  210296. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210297. stop (false);
  210298. delete inputDevice;
  210299. }
  210300. void allocateTempBuffers()
  210301. {
  210302. const int tempBufSize = bufferSize + 4;
  210303. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210304. tempInputBuffers.calloc (numInputChans + 2);
  210305. tempOutputBuffers.calloc (numOutputChans + 2);
  210306. int i, count = 0;
  210307. for (i = 0; i < numInputChans; ++i)
  210308. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210309. for (i = 0; i < numOutputChans; ++i)
  210310. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210311. }
  210312. // returns the number of actual available channels
  210313. void fillInChannelInfo (const bool input)
  210314. {
  210315. int chanNum = 0;
  210316. UInt32 size;
  210317. AudioObjectPropertyAddress pa;
  210318. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210319. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210320. pa.mElement = kAudioObjectPropertyElementMaster;
  210321. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210322. {
  210323. HeapBlock <AudioBufferList> bufList;
  210324. bufList.calloc (size, 1);
  210325. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210326. {
  210327. const int numStreams = bufList->mNumberBuffers;
  210328. for (int i = 0; i < numStreams; ++i)
  210329. {
  210330. const AudioBuffer& b = bufList->mBuffers[i];
  210331. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210332. {
  210333. String name;
  210334. {
  210335. char channelName [256];
  210336. zerostruct (channelName);
  210337. UInt32 nameSize = sizeof (channelName);
  210338. UInt32 channelNum = chanNum + 1;
  210339. pa.mSelector = kAudioDevicePropertyChannelName;
  210340. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210341. name = String::fromUTF8 (channelName, nameSize);
  210342. }
  210343. if (input)
  210344. {
  210345. if (activeInputChans[chanNum])
  210346. {
  210347. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210348. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210349. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210350. ++numInputChannelInfos;
  210351. }
  210352. if (name.isEmpty())
  210353. name << "Input " << (chanNum + 1);
  210354. inChanNames.add (name);
  210355. }
  210356. else
  210357. {
  210358. if (activeOutputChans[chanNum])
  210359. {
  210360. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210361. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210362. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210363. ++numOutputChannelInfos;
  210364. }
  210365. if (name.isEmpty())
  210366. name << "Output " << (chanNum + 1);
  210367. outChanNames.add (name);
  210368. }
  210369. ++chanNum;
  210370. }
  210371. }
  210372. }
  210373. }
  210374. }
  210375. void updateDetailsFromDevice()
  210376. {
  210377. stopTimer();
  210378. if (deviceID == 0)
  210379. return;
  210380. const ScopedLock sl (callbackLock);
  210381. Float64 sr;
  210382. UInt32 size = sizeof (Float64);
  210383. AudioObjectPropertyAddress pa;
  210384. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210385. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210386. pa.mElement = kAudioObjectPropertyElementMaster;
  210387. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210388. sampleRate = sr;
  210389. UInt32 framesPerBuf;
  210390. size = sizeof (framesPerBuf);
  210391. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210392. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210393. {
  210394. bufferSize = framesPerBuf;
  210395. allocateTempBuffers();
  210396. }
  210397. bufferSizes.clear();
  210398. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210399. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210400. {
  210401. HeapBlock <AudioValueRange> ranges;
  210402. ranges.calloc (size, 1);
  210403. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210404. {
  210405. bufferSizes.add ((int) ranges[0].mMinimum);
  210406. for (int i = 32; i < 8192; i += 32)
  210407. {
  210408. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210409. {
  210410. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210411. {
  210412. bufferSizes.addIfNotAlreadyThere (i);
  210413. break;
  210414. }
  210415. }
  210416. }
  210417. if (bufferSize > 0)
  210418. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210419. }
  210420. }
  210421. if (bufferSizes.size() == 0 && bufferSize > 0)
  210422. bufferSizes.add (bufferSize);
  210423. sampleRates.clear();
  210424. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210425. String rates;
  210426. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210427. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210428. {
  210429. HeapBlock <AudioValueRange> ranges;
  210430. ranges.calloc (size, 1);
  210431. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210432. {
  210433. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210434. {
  210435. bool ok = false;
  210436. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210437. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210438. ok = true;
  210439. if (ok)
  210440. {
  210441. sampleRates.add (possibleRates[i]);
  210442. rates << possibleRates[i] << T(" ");
  210443. }
  210444. }
  210445. }
  210446. }
  210447. if (sampleRates.size() == 0 && sampleRate > 0)
  210448. {
  210449. sampleRates.add (sampleRate);
  210450. rates << sampleRate;
  210451. }
  210452. log (T("sr: ") + rates);
  210453. inputLatency = 0;
  210454. outputLatency = 0;
  210455. UInt32 lat;
  210456. size = sizeof (lat);
  210457. pa.mSelector = kAudioDevicePropertyLatency;
  210458. pa.mScope = kAudioDevicePropertyScopeInput;
  210459. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210460. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210461. inputLatency = (int) lat;
  210462. pa.mScope = kAudioDevicePropertyScopeOutput;
  210463. size = sizeof (lat);
  210464. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210465. outputLatency = (int) lat;
  210466. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210467. inChanNames.clear();
  210468. outChanNames.clear();
  210469. inputChannelInfo.calloc (numInputChans + 2);
  210470. numInputChannelInfos = 0;
  210471. outputChannelInfo.calloc (numOutputChans + 2);
  210472. numOutputChannelInfos = 0;
  210473. fillInChannelInfo (true);
  210474. fillInChannelInfo (false);
  210475. }
  210476. const StringArray getSources (bool input)
  210477. {
  210478. StringArray s;
  210479. HeapBlock <OSType> types;
  210480. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210481. for (int i = 0; i < num; ++i)
  210482. {
  210483. AudioValueTranslation avt;
  210484. char buffer[256];
  210485. avt.mInputData = (void*) &(types[i]);
  210486. avt.mInputDataSize = sizeof (UInt32);
  210487. avt.mOutputData = buffer;
  210488. avt.mOutputDataSize = 256;
  210489. UInt32 transSize = sizeof (avt);
  210490. AudioObjectPropertyAddress pa;
  210491. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210492. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210493. pa.mElement = kAudioObjectPropertyElementMaster;
  210494. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210495. {
  210496. DBG (buffer);
  210497. s.add (buffer);
  210498. }
  210499. }
  210500. return s;
  210501. }
  210502. int getCurrentSourceIndex (bool input) const
  210503. {
  210504. OSType currentSourceID = 0;
  210505. UInt32 size = sizeof (currentSourceID);
  210506. int result = -1;
  210507. AudioObjectPropertyAddress pa;
  210508. pa.mSelector = kAudioDevicePropertyDataSource;
  210509. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210510. pa.mElement = kAudioObjectPropertyElementMaster;
  210511. if (deviceID != 0)
  210512. {
  210513. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210514. {
  210515. HeapBlock <OSType> types;
  210516. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210517. for (int i = 0; i < num; ++i)
  210518. {
  210519. if (types[num] == currentSourceID)
  210520. {
  210521. result = i;
  210522. break;
  210523. }
  210524. }
  210525. }
  210526. }
  210527. return result;
  210528. }
  210529. void setCurrentSourceIndex (int index, bool input)
  210530. {
  210531. if (deviceID != 0)
  210532. {
  210533. HeapBlock <OSType> types;
  210534. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210535. if (((unsigned int) index) < (unsigned int) num)
  210536. {
  210537. AudioObjectPropertyAddress pa;
  210538. pa.mSelector = kAudioDevicePropertyDataSource;
  210539. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210540. pa.mElement = kAudioObjectPropertyElementMaster;
  210541. OSType typeId = types[index];
  210542. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210543. }
  210544. }
  210545. }
  210546. const String reopen (const BitArray& inputChannels,
  210547. const BitArray& outputChannels,
  210548. double newSampleRate,
  210549. int bufferSizeSamples)
  210550. {
  210551. String error;
  210552. log ("CoreAudio reopen");
  210553. callbacksAllowed = false;
  210554. stopTimer();
  210555. stop (false);
  210556. activeInputChans = inputChannels;
  210557. activeInputChans.setRange (inChanNames.size(),
  210558. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210559. false);
  210560. activeOutputChans = outputChannels;
  210561. activeOutputChans.setRange (outChanNames.size(),
  210562. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210563. false);
  210564. numInputChans = activeInputChans.countNumberOfSetBits();
  210565. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210566. // set sample rate
  210567. AudioObjectPropertyAddress pa;
  210568. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210569. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210570. pa.mElement = kAudioObjectPropertyElementMaster;
  210571. Float64 sr = newSampleRate;
  210572. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210573. {
  210574. error = "Couldn't change sample rate";
  210575. }
  210576. else
  210577. {
  210578. // change buffer size
  210579. UInt32 framesPerBuf = bufferSizeSamples;
  210580. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210581. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210582. {
  210583. error = "Couldn't change buffer size";
  210584. }
  210585. else
  210586. {
  210587. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210588. // correctly report their new settings until some random time in the future, so
  210589. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210590. // to make sure we're using the correct numbers..
  210591. updateDetailsFromDevice();
  210592. sampleRate = newSampleRate;
  210593. bufferSize = bufferSizeSamples;
  210594. if (sampleRates.size() == 0)
  210595. error = "Device has no available sample-rates";
  210596. else if (bufferSizes.size() == 0)
  210597. error = "Device has no available buffer-sizes";
  210598. else if (inputDevice != 0)
  210599. error = inputDevice->reopen (inputChannels,
  210600. outputChannels,
  210601. newSampleRate,
  210602. bufferSizeSamples);
  210603. }
  210604. }
  210605. callbacksAllowed = true;
  210606. return error;
  210607. }
  210608. bool start (AudioIODeviceCallback* cb)
  210609. {
  210610. if (! started)
  210611. {
  210612. callback = 0;
  210613. if (deviceID != 0)
  210614. {
  210615. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210616. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210617. #else
  210618. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210619. #endif
  210620. {
  210621. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210622. {
  210623. started = true;
  210624. }
  210625. else
  210626. {
  210627. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210628. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210629. #else
  210630. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210631. audioProcID = 0;
  210632. #endif
  210633. }
  210634. }
  210635. }
  210636. }
  210637. if (started)
  210638. {
  210639. const ScopedLock sl (callbackLock);
  210640. callback = cb;
  210641. }
  210642. if (inputDevice != 0)
  210643. return started && inputDevice->start (cb);
  210644. else
  210645. return started;
  210646. }
  210647. void stop (bool leaveInterruptRunning)
  210648. {
  210649. {
  210650. const ScopedLock sl (callbackLock);
  210651. callback = 0;
  210652. }
  210653. if (started
  210654. && (deviceID != 0)
  210655. && ! leaveInterruptRunning)
  210656. {
  210657. OK (AudioDeviceStop (deviceID, audioIOProc));
  210658. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210659. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210660. #else
  210661. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210662. audioProcID = 0;
  210663. #endif
  210664. started = false;
  210665. { const ScopedLock sl (callbackLock); }
  210666. // wait until it's definately stopped calling back..
  210667. for (int i = 40; --i >= 0;)
  210668. {
  210669. Thread::sleep (50);
  210670. UInt32 running = 0;
  210671. UInt32 size = sizeof (running);
  210672. AudioObjectPropertyAddress pa;
  210673. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210674. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210675. pa.mElement = kAudioObjectPropertyElementMaster;
  210676. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210677. if (running == 0)
  210678. break;
  210679. }
  210680. const ScopedLock sl (callbackLock);
  210681. }
  210682. if (inputDevice != 0)
  210683. inputDevice->stop (leaveInterruptRunning);
  210684. }
  210685. double getSampleRate() const
  210686. {
  210687. return sampleRate;
  210688. }
  210689. int getBufferSize() const
  210690. {
  210691. return bufferSize;
  210692. }
  210693. void audioCallback (const AudioBufferList* inInputData,
  210694. AudioBufferList* outOutputData)
  210695. {
  210696. int i;
  210697. const ScopedLock sl (callbackLock);
  210698. if (callback != 0)
  210699. {
  210700. if (inputDevice == 0)
  210701. {
  210702. for (i = numInputChans; --i >= 0;)
  210703. {
  210704. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210705. float* dest = tempInputBuffers [i];
  210706. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210707. + info.dataOffsetSamples;
  210708. const int stride = info.dataStrideSamples;
  210709. if (stride != 0) // if this is zero, info is invalid
  210710. {
  210711. for (int j = bufferSize; --j >= 0;)
  210712. {
  210713. *dest++ = *src;
  210714. src += stride;
  210715. }
  210716. }
  210717. }
  210718. }
  210719. if (! isSlaveDevice)
  210720. {
  210721. if (inputDevice == 0)
  210722. {
  210723. callback->audioDeviceIOCallback ((const float**) tempInputBuffers,
  210724. numInputChans,
  210725. tempOutputBuffers,
  210726. numOutputChans,
  210727. bufferSize);
  210728. }
  210729. else
  210730. {
  210731. jassert (inputDevice->bufferSize == bufferSize);
  210732. // Sometimes the two linked devices seem to get their callbacks in
  210733. // parallel, so we need to lock both devices to stop the input data being
  210734. // changed while inside our callback..
  210735. const ScopedLock sl2 (inputDevice->callbackLock);
  210736. callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers,
  210737. inputDevice->numInputChans,
  210738. tempOutputBuffers,
  210739. numOutputChans,
  210740. bufferSize);
  210741. }
  210742. for (i = numOutputChans; --i >= 0;)
  210743. {
  210744. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210745. const float* src = tempOutputBuffers [i];
  210746. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210747. + info.dataOffsetSamples;
  210748. const int stride = info.dataStrideSamples;
  210749. if (stride != 0) // if this is zero, info is invalid
  210750. {
  210751. for (int j = bufferSize; --j >= 0;)
  210752. {
  210753. *dest = *src++;
  210754. dest += stride;
  210755. }
  210756. }
  210757. }
  210758. }
  210759. }
  210760. else
  210761. {
  210762. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210763. {
  210764. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210765. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210766. + info.dataOffsetSamples;
  210767. const int stride = info.dataStrideSamples;
  210768. if (stride != 0) // if this is zero, info is invalid
  210769. {
  210770. for (int j = bufferSize; --j >= 0;)
  210771. {
  210772. *dest = 0.0f;
  210773. dest += stride;
  210774. }
  210775. }
  210776. }
  210777. }
  210778. }
  210779. // called by callbacks
  210780. void deviceDetailsChanged()
  210781. {
  210782. if (callbacksAllowed)
  210783. startTimer (100);
  210784. }
  210785. void timerCallback()
  210786. {
  210787. stopTimer();
  210788. log ("CoreAudio device changed callback");
  210789. const double oldSampleRate = sampleRate;
  210790. const int oldBufferSize = bufferSize;
  210791. updateDetailsFromDevice();
  210792. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210793. {
  210794. callbacksAllowed = false;
  210795. stop (false);
  210796. updateDetailsFromDevice();
  210797. callbacksAllowed = true;
  210798. }
  210799. }
  210800. CoreAudioInternal* getRelatedDevice() const
  210801. {
  210802. UInt32 size = 0;
  210803. ScopedPointer <CoreAudioInternal> result;
  210804. AudioObjectPropertyAddress pa;
  210805. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210806. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210807. pa.mElement = kAudioObjectPropertyElementMaster;
  210808. if (deviceID != 0
  210809. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210810. && size > 0)
  210811. {
  210812. HeapBlock <AudioDeviceID> devs;
  210813. devs.calloc (size, 1);
  210814. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210815. {
  210816. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210817. {
  210818. if (devs[i] != deviceID && devs[i] != 0)
  210819. {
  210820. result = new CoreAudioInternal (devs[i]);
  210821. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210822. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210823. if (thisIsInput != otherIsInput
  210824. || (inChanNames.size() + outChanNames.size() == 0)
  210825. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210826. break;
  210827. result = 0;
  210828. }
  210829. }
  210830. }
  210831. }
  210832. return result.release();
  210833. }
  210834. juce_UseDebuggingNewOperator
  210835. int inputLatency, outputLatency;
  210836. BitArray activeInputChans, activeOutputChans;
  210837. StringArray inChanNames, outChanNames;
  210838. Array <double> sampleRates;
  210839. Array <int> bufferSizes;
  210840. AudioIODeviceCallback* callback;
  210841. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210842. AudioDeviceIOProcID audioProcID;
  210843. #endif
  210844. CoreAudioInternal* inputDevice;
  210845. bool isSlaveDevice;
  210846. private:
  210847. CriticalSection callbackLock;
  210848. AudioDeviceID deviceID;
  210849. bool started;
  210850. double sampleRate;
  210851. int bufferSize;
  210852. HeapBlock <float> audioBuffer;
  210853. int numInputChans, numOutputChans;
  210854. bool callbacksAllowed;
  210855. struct CallbackDetailsForChannel
  210856. {
  210857. int streamNum;
  210858. int dataOffsetSamples;
  210859. int dataStrideSamples;
  210860. };
  210861. int numInputChannelInfos, numOutputChannelInfos;
  210862. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210863. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210864. CoreAudioInternal (const CoreAudioInternal&);
  210865. CoreAudioInternal& operator= (const CoreAudioInternal&);
  210866. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210867. const AudioTimeStamp* inNow,
  210868. const AudioBufferList* inInputData,
  210869. const AudioTimeStamp* inInputTime,
  210870. AudioBufferList* outOutputData,
  210871. const AudioTimeStamp* inOutputTime,
  210872. void* device)
  210873. {
  210874. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210875. return noErr;
  210876. }
  210877. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210878. {
  210879. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210880. switch (pa->mSelector)
  210881. {
  210882. case kAudioDevicePropertyBufferSize:
  210883. case kAudioDevicePropertyBufferFrameSize:
  210884. case kAudioDevicePropertyNominalSampleRate:
  210885. case kAudioDevicePropertyStreamFormat:
  210886. case kAudioDevicePropertyDeviceIsAlive:
  210887. intern->deviceDetailsChanged();
  210888. break;
  210889. case kAudioDevicePropertyBufferSizeRange:
  210890. case kAudioDevicePropertyVolumeScalar:
  210891. case kAudioDevicePropertyMute:
  210892. case kAudioDevicePropertyPlayThru:
  210893. case kAudioDevicePropertyDataSource:
  210894. case kAudioDevicePropertyDeviceIsRunning:
  210895. break;
  210896. }
  210897. return noErr;
  210898. }
  210899. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210900. {
  210901. AudioObjectPropertyAddress pa;
  210902. pa.mSelector = kAudioDevicePropertyDataSources;
  210903. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210904. pa.mElement = kAudioObjectPropertyElementMaster;
  210905. UInt32 size = 0;
  210906. if (deviceID != 0
  210907. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210908. {
  210909. types.calloc (size, 1);
  210910. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210911. return size / (int) sizeof (OSType);
  210912. }
  210913. return 0;
  210914. }
  210915. };
  210916. class CoreAudioIODevice : public AudioIODevice
  210917. {
  210918. public:
  210919. CoreAudioIODevice (const String& deviceName,
  210920. AudioDeviceID inputDeviceId,
  210921. const int inputIndex_,
  210922. AudioDeviceID outputDeviceId,
  210923. const int outputIndex_)
  210924. : AudioIODevice (deviceName, "CoreAudio"),
  210925. inputIndex (inputIndex_),
  210926. outputIndex (outputIndex_),
  210927. isOpen_ (false),
  210928. isStarted (false)
  210929. {
  210930. internal = 0;
  210931. CoreAudioInternal* device = 0;
  210932. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210933. {
  210934. jassert (inputDeviceId != 0);
  210935. device = new CoreAudioInternal (inputDeviceId);
  210936. }
  210937. else
  210938. {
  210939. device = new CoreAudioInternal (outputDeviceId);
  210940. if (inputDeviceId != 0)
  210941. {
  210942. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210943. device->inputDevice = secondDevice;
  210944. secondDevice->isSlaveDevice = true;
  210945. }
  210946. }
  210947. internal = device;
  210948. AudioObjectPropertyAddress pa;
  210949. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210950. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210951. pa.mElement = kAudioObjectPropertyElementWildcard;
  210952. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210953. }
  210954. ~CoreAudioIODevice()
  210955. {
  210956. AudioObjectPropertyAddress pa;
  210957. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210958. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210959. pa.mElement = kAudioObjectPropertyElementWildcard;
  210960. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210961. delete internal;
  210962. }
  210963. const StringArray getOutputChannelNames()
  210964. {
  210965. return internal->outChanNames;
  210966. }
  210967. const StringArray getInputChannelNames()
  210968. {
  210969. if (internal->inputDevice != 0)
  210970. return internal->inputDevice->inChanNames;
  210971. else
  210972. return internal->inChanNames;
  210973. }
  210974. int getNumSampleRates()
  210975. {
  210976. return internal->sampleRates.size();
  210977. }
  210978. double getSampleRate (int index)
  210979. {
  210980. return internal->sampleRates [index];
  210981. }
  210982. int getNumBufferSizesAvailable()
  210983. {
  210984. return internal->bufferSizes.size();
  210985. }
  210986. int getBufferSizeSamples (int index)
  210987. {
  210988. return internal->bufferSizes [index];
  210989. }
  210990. int getDefaultBufferSize()
  210991. {
  210992. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  210993. if (getBufferSizeSamples(i) >= 512)
  210994. return getBufferSizeSamples(i);
  210995. return 512;
  210996. }
  210997. const String open (const BitArray& inputChannels,
  210998. const BitArray& outputChannels,
  210999. double sampleRate,
  211000. int bufferSizeSamples)
  211001. {
  211002. isOpen_ = true;
  211003. if (bufferSizeSamples <= 0)
  211004. bufferSizeSamples = getDefaultBufferSize();
  211005. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211006. isOpen_ = lastError.isEmpty();
  211007. return lastError;
  211008. }
  211009. void close()
  211010. {
  211011. isOpen_ = false;
  211012. internal->stop (false);
  211013. }
  211014. bool isOpen()
  211015. {
  211016. return isOpen_;
  211017. }
  211018. int getCurrentBufferSizeSamples()
  211019. {
  211020. return internal != 0 ? internal->getBufferSize() : 512;
  211021. }
  211022. double getCurrentSampleRate()
  211023. {
  211024. return internal != 0 ? internal->getSampleRate() : 0;
  211025. }
  211026. int getCurrentBitDepth()
  211027. {
  211028. return 32; // no way to find out, so just assume it's high..
  211029. }
  211030. const BitArray getActiveOutputChannels() const
  211031. {
  211032. return internal != 0 ? internal->activeOutputChans : BitArray();
  211033. }
  211034. const BitArray getActiveInputChannels() const
  211035. {
  211036. BitArray chans;
  211037. if (internal != 0)
  211038. {
  211039. chans = internal->activeInputChans;
  211040. if (internal->inputDevice != 0)
  211041. chans.orWith (internal->inputDevice->activeInputChans);
  211042. }
  211043. return chans;
  211044. }
  211045. int getOutputLatencyInSamples()
  211046. {
  211047. if (internal == 0)
  211048. return 0;
  211049. // this seems like a good guess at getting the latency right - comparing
  211050. // this with a round-trip measurement, it gets it to within a few millisecs
  211051. // for the built-in mac soundcard
  211052. return internal->outputLatency + internal->getBufferSize() * 2;
  211053. }
  211054. int getInputLatencyInSamples()
  211055. {
  211056. if (internal == 0)
  211057. return 0;
  211058. return internal->inputLatency + internal->getBufferSize() * 2;
  211059. }
  211060. void start (AudioIODeviceCallback* callback)
  211061. {
  211062. if (internal != 0 && ! isStarted)
  211063. {
  211064. if (callback != 0)
  211065. callback->audioDeviceAboutToStart (this);
  211066. isStarted = true;
  211067. internal->start (callback);
  211068. }
  211069. }
  211070. void stop()
  211071. {
  211072. if (isStarted && internal != 0)
  211073. {
  211074. AudioIODeviceCallback* const lastCallback = internal->callback;
  211075. isStarted = false;
  211076. internal->stop (true);
  211077. if (lastCallback != 0)
  211078. lastCallback->audioDeviceStopped();
  211079. }
  211080. }
  211081. bool isPlaying()
  211082. {
  211083. if (internal->callback == 0)
  211084. isStarted = false;
  211085. return isStarted;
  211086. }
  211087. const String getLastError()
  211088. {
  211089. return lastError;
  211090. }
  211091. int inputIndex, outputIndex;
  211092. juce_UseDebuggingNewOperator
  211093. private:
  211094. CoreAudioInternal* internal;
  211095. bool isOpen_, isStarted;
  211096. String lastError;
  211097. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211098. {
  211099. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211100. switch (pa->mSelector)
  211101. {
  211102. case kAudioHardwarePropertyDevices:
  211103. intern->deviceDetailsChanged();
  211104. break;
  211105. case kAudioHardwarePropertyDefaultOutputDevice:
  211106. case kAudioHardwarePropertyDefaultInputDevice:
  211107. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211108. break;
  211109. }
  211110. return noErr;
  211111. }
  211112. CoreAudioIODevice (const CoreAudioIODevice&);
  211113. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211114. };
  211115. class CoreAudioIODeviceType : public AudioIODeviceType
  211116. {
  211117. public:
  211118. CoreAudioIODeviceType()
  211119. : AudioIODeviceType (T("CoreAudio")),
  211120. hasScanned (false)
  211121. {
  211122. }
  211123. ~CoreAudioIODeviceType()
  211124. {
  211125. }
  211126. void scanForDevices()
  211127. {
  211128. hasScanned = true;
  211129. inputDeviceNames.clear();
  211130. outputDeviceNames.clear();
  211131. inputIds.clear();
  211132. outputIds.clear();
  211133. UInt32 size;
  211134. AudioObjectPropertyAddress pa;
  211135. pa.mSelector = kAudioHardwarePropertyDevices;
  211136. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211137. pa.mElement = kAudioObjectPropertyElementMaster;
  211138. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211139. {
  211140. HeapBlock <AudioDeviceID> devs;
  211141. devs.calloc (size, 1);
  211142. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211143. {
  211144. static bool alreadyLogged = false;
  211145. const int num = size / (int) sizeof (AudioDeviceID);
  211146. for (int i = 0; i < num; ++i)
  211147. {
  211148. char name [1024];
  211149. size = sizeof (name);
  211150. pa.mSelector = kAudioDevicePropertyDeviceName;
  211151. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211152. {
  211153. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211154. if (! alreadyLogged)
  211155. log (T("CoreAudio device: ") + nameString);
  211156. const int numIns = getNumChannels (devs[i], true);
  211157. const int numOuts = getNumChannels (devs[i], false);
  211158. if (numIns > 0)
  211159. {
  211160. inputDeviceNames.add (nameString);
  211161. inputIds.add (devs[i]);
  211162. }
  211163. if (numOuts > 0)
  211164. {
  211165. outputDeviceNames.add (nameString);
  211166. outputIds.add (devs[i]);
  211167. }
  211168. }
  211169. }
  211170. alreadyLogged = true;
  211171. }
  211172. }
  211173. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211174. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211175. }
  211176. const StringArray getDeviceNames (const bool wantInputNames) const
  211177. {
  211178. jassert (hasScanned); // need to call scanForDevices() before doing this
  211179. if (wantInputNames)
  211180. return inputDeviceNames;
  211181. else
  211182. return outputDeviceNames;
  211183. }
  211184. int getDefaultDeviceIndex (const bool forInput) const
  211185. {
  211186. jassert (hasScanned); // need to call scanForDevices() before doing this
  211187. AudioDeviceID deviceID;
  211188. UInt32 size = sizeof (deviceID);
  211189. // if they're asking for any input channels at all, use the default input, so we
  211190. // get the built-in mic rather than the built-in output with no inputs..
  211191. AudioObjectPropertyAddress pa;
  211192. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211193. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211194. pa.mElement = kAudioObjectPropertyElementMaster;
  211195. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211196. {
  211197. if (forInput)
  211198. {
  211199. for (int i = inputIds.size(); --i >= 0;)
  211200. if (inputIds[i] == deviceID)
  211201. return i;
  211202. }
  211203. else
  211204. {
  211205. for (int i = outputIds.size(); --i >= 0;)
  211206. if (outputIds[i] == deviceID)
  211207. return i;
  211208. }
  211209. }
  211210. return 0;
  211211. }
  211212. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211213. {
  211214. jassert (hasScanned); // need to call scanForDevices() before doing this
  211215. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211216. if (d == 0)
  211217. return -1;
  211218. return asInput ? d->inputIndex
  211219. : d->outputIndex;
  211220. }
  211221. bool hasSeparateInputsAndOutputs() const { return true; }
  211222. AudioIODevice* createDevice (const String& outputDeviceName,
  211223. const String& inputDeviceName)
  211224. {
  211225. jassert (hasScanned); // need to call scanForDevices() before doing this
  211226. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211227. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211228. String deviceName (outputDeviceName);
  211229. if (deviceName.isEmpty())
  211230. deviceName = inputDeviceName;
  211231. if (index >= 0)
  211232. return new CoreAudioIODevice (deviceName,
  211233. inputIds [inputIndex],
  211234. inputIndex,
  211235. outputIds [outputIndex],
  211236. outputIndex);
  211237. return 0;
  211238. }
  211239. juce_UseDebuggingNewOperator
  211240. private:
  211241. StringArray inputDeviceNames, outputDeviceNames;
  211242. Array <AudioDeviceID> inputIds, outputIds;
  211243. bool hasScanned;
  211244. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211245. {
  211246. int total = 0;
  211247. UInt32 size;
  211248. AudioObjectPropertyAddress pa;
  211249. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211250. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211251. pa.mElement = kAudioObjectPropertyElementMaster;
  211252. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211253. {
  211254. HeapBlock <AudioBufferList> bufList;
  211255. bufList.calloc (size, 1);
  211256. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211257. {
  211258. const int numStreams = bufList->mNumberBuffers;
  211259. for (int i = 0; i < numStreams; ++i)
  211260. {
  211261. const AudioBuffer& b = bufList->mBuffers[i];
  211262. total += b.mNumberChannels;
  211263. }
  211264. }
  211265. }
  211266. return total;
  211267. }
  211268. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211269. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211270. };
  211271. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211272. {
  211273. return new CoreAudioIODeviceType();
  211274. }
  211275. #undef log
  211276. #endif
  211277. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211278. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211279. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211280. // compiled on its own).
  211281. #if JUCE_INCLUDED_FILE
  211282. #if JUCE_MAC
  211283. #undef log
  211284. #define log(a) Logger::writeToLog(a)
  211285. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211286. {
  211287. if (err == noErr)
  211288. return true;
  211289. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211290. jassertfalse
  211291. return false;
  211292. }
  211293. #undef OK
  211294. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211295. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211296. {
  211297. String result;
  211298. CFStringRef str = 0;
  211299. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211300. if (str != 0)
  211301. {
  211302. result = PlatformUtilities::cfStringToJuceString (str);
  211303. CFRelease (str);
  211304. str = 0;
  211305. }
  211306. MIDIEntityRef entity = 0;
  211307. MIDIEndpointGetEntity (endpoint, &entity);
  211308. if (entity == 0)
  211309. return result; // probably virtual
  211310. if (result.isEmpty())
  211311. {
  211312. // endpoint name has zero length - try the entity
  211313. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211314. if (str != 0)
  211315. {
  211316. result += PlatformUtilities::cfStringToJuceString (str);
  211317. CFRelease (str);
  211318. str = 0;
  211319. }
  211320. }
  211321. // now consider the device's name
  211322. MIDIDeviceRef device = 0;
  211323. MIDIEntityGetDevice (entity, &device);
  211324. if (device == 0)
  211325. return result;
  211326. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211327. if (str != 0)
  211328. {
  211329. const String s (PlatformUtilities::cfStringToJuceString (str));
  211330. CFRelease (str);
  211331. // if an external device has only one entity, throw away
  211332. // the endpoint name and just use the device name
  211333. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211334. {
  211335. result = s;
  211336. }
  211337. else if (! result.startsWithIgnoreCase (s))
  211338. {
  211339. // prepend the device name to the entity name
  211340. result = (s + T(" ") + result).trimEnd();
  211341. }
  211342. }
  211343. return result;
  211344. }
  211345. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211346. {
  211347. String result;
  211348. // Does the endpoint have connections?
  211349. CFDataRef connections = 0;
  211350. int numConnections = 0;
  211351. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211352. if (connections != 0)
  211353. {
  211354. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211355. if (numConnections > 0)
  211356. {
  211357. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211358. for (int i = 0; i < numConnections; ++i, ++pid)
  211359. {
  211360. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211361. MIDIObjectRef connObject;
  211362. MIDIObjectType connObjectType;
  211363. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211364. if (err == noErr)
  211365. {
  211366. String s;
  211367. if (connObjectType == kMIDIObjectType_ExternalSource
  211368. || connObjectType == kMIDIObjectType_ExternalDestination)
  211369. {
  211370. // Connected to an external device's endpoint (10.3 and later).
  211371. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211372. }
  211373. else
  211374. {
  211375. // Connected to an external device (10.2) (or something else, catch-all)
  211376. CFStringRef str = 0;
  211377. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211378. if (str != 0)
  211379. {
  211380. s = PlatformUtilities::cfStringToJuceString (str);
  211381. CFRelease (str);
  211382. }
  211383. }
  211384. if (s.isNotEmpty())
  211385. {
  211386. if (result.isNotEmpty())
  211387. result += (", ");
  211388. result += s;
  211389. }
  211390. }
  211391. }
  211392. }
  211393. CFRelease (connections);
  211394. }
  211395. if (result.isNotEmpty())
  211396. return result;
  211397. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211398. return getEndpointName (endpoint, false);
  211399. }
  211400. const StringArray MidiOutput::getDevices()
  211401. {
  211402. StringArray s;
  211403. const ItemCount num = MIDIGetNumberOfDestinations();
  211404. for (ItemCount i = 0; i < num; ++i)
  211405. {
  211406. MIDIEndpointRef dest = MIDIGetDestination (i);
  211407. if (dest != 0)
  211408. {
  211409. String name (getConnectedEndpointName (dest));
  211410. if (name.isEmpty())
  211411. name = "<error>";
  211412. s.add (name);
  211413. }
  211414. else
  211415. {
  211416. s.add ("<error>");
  211417. }
  211418. }
  211419. return s;
  211420. }
  211421. int MidiOutput::getDefaultDeviceIndex()
  211422. {
  211423. return 0;
  211424. }
  211425. static MIDIClientRef globalMidiClient;
  211426. static bool hasGlobalClientBeenCreated = false;
  211427. static bool makeSureClientExists()
  211428. {
  211429. if (! hasGlobalClientBeenCreated)
  211430. {
  211431. String name (T("JUCE"));
  211432. if (JUCEApplication::getInstance() != 0)
  211433. name = JUCEApplication::getInstance()->getApplicationName();
  211434. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211435. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211436. CFRelease (appName);
  211437. }
  211438. return hasGlobalClientBeenCreated;
  211439. }
  211440. class MidiPortAndEndpoint
  211441. {
  211442. public:
  211443. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211444. : port (port_), endPoint (endPoint_)
  211445. {
  211446. }
  211447. ~MidiPortAndEndpoint()
  211448. {
  211449. if (port != 0)
  211450. MIDIPortDispose (port);
  211451. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211452. MIDIEndpointDispose (endPoint);
  211453. }
  211454. MIDIPortRef port;
  211455. MIDIEndpointRef endPoint;
  211456. };
  211457. MidiOutput* MidiOutput::openDevice (int index)
  211458. {
  211459. MidiOutput* mo = 0;
  211460. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211461. {
  211462. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211463. CFStringRef pname;
  211464. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211465. {
  211466. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211467. if (makeSureClientExists())
  211468. {
  211469. MIDIPortRef port;
  211470. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211471. {
  211472. mo = new MidiOutput();
  211473. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211474. }
  211475. }
  211476. CFRelease (pname);
  211477. }
  211478. }
  211479. return mo;
  211480. }
  211481. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211482. {
  211483. MidiOutput* mo = 0;
  211484. if (makeSureClientExists())
  211485. {
  211486. MIDIEndpointRef endPoint;
  211487. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211488. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211489. {
  211490. mo = new MidiOutput();
  211491. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211492. }
  211493. CFRelease (name);
  211494. }
  211495. return mo;
  211496. }
  211497. MidiOutput::~MidiOutput()
  211498. {
  211499. delete (MidiPortAndEndpoint*) internal;
  211500. }
  211501. void MidiOutput::reset()
  211502. {
  211503. }
  211504. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211505. {
  211506. return false;
  211507. }
  211508. void MidiOutput::setVolume (float leftVol, float rightVol)
  211509. {
  211510. }
  211511. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211512. {
  211513. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211514. if (message.isSysEx())
  211515. {
  211516. const int maxPacketSize = 256;
  211517. int pos = 0, bytesLeft = message.getRawDataSize();
  211518. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211519. HeapBlock <MIDIPacketList> packets;
  211520. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211521. packets->numPackets = numPackets;
  211522. MIDIPacket* p = packets->packet;
  211523. for (int i = 0; i < numPackets; ++i)
  211524. {
  211525. p->timeStamp = 0;
  211526. p->length = jmin (maxPacketSize, bytesLeft);
  211527. memcpy (p->data, message.getRawData() + pos, p->length);
  211528. pos += p->length;
  211529. bytesLeft -= p->length;
  211530. p = MIDIPacketNext (p);
  211531. }
  211532. if (mpe->port != 0)
  211533. MIDISend (mpe->port, mpe->endPoint, packets);
  211534. else
  211535. MIDIReceived (mpe->endPoint, packets);
  211536. }
  211537. else
  211538. {
  211539. MIDIPacketList packets;
  211540. packets.numPackets = 1;
  211541. packets.packet[0].timeStamp = 0;
  211542. packets.packet[0].length = message.getRawDataSize();
  211543. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211544. if (mpe->port != 0)
  211545. MIDISend (mpe->port, mpe->endPoint, &packets);
  211546. else
  211547. MIDIReceived (mpe->endPoint, &packets);
  211548. }
  211549. }
  211550. const StringArray MidiInput::getDevices()
  211551. {
  211552. StringArray s;
  211553. const ItemCount num = MIDIGetNumberOfSources();
  211554. for (ItemCount i = 0; i < num; ++i)
  211555. {
  211556. MIDIEndpointRef source = MIDIGetSource (i);
  211557. if (source != 0)
  211558. {
  211559. String name (getConnectedEndpointName (source));
  211560. if (name.isEmpty())
  211561. name = "<error>";
  211562. s.add (name);
  211563. }
  211564. else
  211565. {
  211566. s.add ("<error>");
  211567. }
  211568. }
  211569. return s;
  211570. }
  211571. int MidiInput::getDefaultDeviceIndex()
  211572. {
  211573. return 0;
  211574. }
  211575. struct MidiPortAndCallback
  211576. {
  211577. MidiInput* input;
  211578. MidiPortAndEndpoint* portAndEndpoint;
  211579. MidiInputCallback* callback;
  211580. MemoryBlock pendingData;
  211581. int pendingBytes;
  211582. double pendingDataTime;
  211583. bool active;
  211584. void processSysex (const uint8*& d, int& size, const double time)
  211585. {
  211586. if (*d == 0xf0)
  211587. {
  211588. pendingBytes = 0;
  211589. pendingDataTime = time;
  211590. }
  211591. pendingData.ensureSize (pendingBytes + size, false);
  211592. uint8* totalMessage = (uint8*) pendingData.getData();
  211593. uint8* dest = totalMessage + pendingBytes;
  211594. while (size > 0)
  211595. {
  211596. if (pendingBytes > 0 && *d >= 0x80)
  211597. {
  211598. if (*d >= 0xfa || *d == 0xf8)
  211599. {
  211600. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211601. ++d;
  211602. --size;
  211603. }
  211604. else
  211605. {
  211606. if (*d == 0xf7)
  211607. {
  211608. *dest++ = *d++;
  211609. pendingBytes++;
  211610. --size;
  211611. }
  211612. break;
  211613. }
  211614. }
  211615. else
  211616. {
  211617. *dest++ = *d++;
  211618. pendingBytes++;
  211619. --size;
  211620. }
  211621. }
  211622. if (totalMessage [pendingBytes - 1] == 0xf7)
  211623. {
  211624. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211625. pendingBytes = 0;
  211626. }
  211627. else
  211628. {
  211629. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211630. }
  211631. }
  211632. };
  211633. namespace CoreMidiCallbacks
  211634. {
  211635. static CriticalSection callbackLock;
  211636. static VoidArray activeCallbacks;
  211637. }
  211638. static void midiInputProc (const MIDIPacketList* pktlist,
  211639. void* readProcRefCon,
  211640. void* srcConnRefCon)
  211641. {
  211642. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211643. const double originalTime = time;
  211644. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211645. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211646. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211647. {
  211648. const MIDIPacket* packet = &pktlist->packet[0];
  211649. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211650. {
  211651. const uint8* d = (const uint8*) (packet->data);
  211652. int size = packet->length;
  211653. while (size > 0)
  211654. {
  211655. time = originalTime;
  211656. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211657. {
  211658. mpc->processSysex (d, size, time);
  211659. }
  211660. else
  211661. {
  211662. int used = 0;
  211663. const MidiMessage m (d, size, used, 0, time);
  211664. if (used <= 0)
  211665. {
  211666. jassertfalse // malformed midi message
  211667. break;
  211668. }
  211669. else
  211670. {
  211671. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211672. }
  211673. size -= used;
  211674. d += used;
  211675. }
  211676. }
  211677. packet = MIDIPacketNext (packet);
  211678. }
  211679. }
  211680. }
  211681. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211682. {
  211683. MidiInput* mi = 0;
  211684. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211685. {
  211686. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211687. if (endPoint != 0)
  211688. {
  211689. CFStringRef pname;
  211690. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211691. {
  211692. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211693. if (makeSureClientExists())
  211694. {
  211695. MIDIPortRef port;
  211696. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211697. mpc->active = false;
  211698. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211699. {
  211700. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211701. {
  211702. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211703. mpc->callback = callback;
  211704. mpc->pendingBytes = 0;
  211705. mpc->pendingData.ensureSize (128);
  211706. mi = new MidiInput (getDevices() [index]);
  211707. mpc->input = mi;
  211708. mi->internal = (void*) mpc;
  211709. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211710. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211711. }
  211712. else
  211713. {
  211714. OK (MIDIPortDispose (port));
  211715. }
  211716. }
  211717. }
  211718. }
  211719. CFRelease (pname);
  211720. }
  211721. }
  211722. return mi;
  211723. }
  211724. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211725. {
  211726. MidiInput* mi = 0;
  211727. if (makeSureClientExists())
  211728. {
  211729. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211730. mpc->active = false;
  211731. MIDIEndpointRef endPoint;
  211732. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211733. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211734. {
  211735. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211736. mpc->callback = callback;
  211737. mpc->pendingBytes = 0;
  211738. mpc->pendingData.ensureSize (128);
  211739. mi = new MidiInput (deviceName);
  211740. mpc->input = mi;
  211741. mi->internal = (void*) mpc;
  211742. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211743. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211744. }
  211745. CFRelease (name);
  211746. }
  211747. return mi;
  211748. }
  211749. MidiInput::MidiInput (const String& name_)
  211750. : name (name_)
  211751. {
  211752. }
  211753. MidiInput::~MidiInput()
  211754. {
  211755. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211756. mpc->active = false;
  211757. {
  211758. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211759. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211760. }
  211761. if (mpc->portAndEndpoint->port != 0)
  211762. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211763. delete mpc->portAndEndpoint;
  211764. delete mpc;
  211765. }
  211766. void MidiInput::start()
  211767. {
  211768. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211769. ((MidiPortAndCallback*) internal)->active = true;
  211770. }
  211771. void MidiInput::stop()
  211772. {
  211773. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211774. ((MidiPortAndCallback*) internal)->active = false;
  211775. }
  211776. #undef log
  211777. #else
  211778. MidiOutput::~MidiOutput()
  211779. {
  211780. }
  211781. void MidiOutput::reset()
  211782. {
  211783. }
  211784. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211785. {
  211786. return false;
  211787. }
  211788. void MidiOutput::setVolume (float leftVol, float rightVol)
  211789. {
  211790. }
  211791. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211792. {
  211793. }
  211794. const StringArray MidiOutput::getDevices()
  211795. {
  211796. return StringArray();
  211797. }
  211798. MidiOutput* MidiOutput::openDevice (int index)
  211799. {
  211800. return 0;
  211801. }
  211802. const StringArray MidiInput::getDevices()
  211803. {
  211804. return StringArray();
  211805. }
  211806. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211807. {
  211808. return 0;
  211809. }
  211810. #endif
  211811. #endif
  211812. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211813. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211814. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211815. // compiled on its own).
  211816. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211817. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211818. class QTCameraDeviceInteral;
  211819. END_JUCE_NAMESPACE
  211820. @interface QTCaptureCallbackDelegate : NSObject
  211821. {
  211822. @public
  211823. CameraDevice* owner;
  211824. QTCameraDeviceInteral* internal;
  211825. int64 firstPresentationTime;
  211826. int64 averageTimeOffset;
  211827. }
  211828. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211829. - (void) dealloc;
  211830. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211831. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211832. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211833. fromConnection: (QTCaptureConnection*) connection;
  211834. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211835. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211836. fromConnection: (QTCaptureConnection*) connection;
  211837. @end
  211838. BEGIN_JUCE_NAMESPACE
  211839. class QTCameraDeviceInteral
  211840. {
  211841. public:
  211842. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211843. {
  211844. const ScopedAutoReleasePool pool;
  211845. session = [[QTCaptureSession alloc] init];
  211846. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211847. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211848. input = 0;
  211849. audioInput = 0;
  211850. audioDevice = 0;
  211851. fileOutput = 0;
  211852. imageOutput = 0;
  211853. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211854. internalDev: this];
  211855. NSError* err = 0;
  211856. [device retain];
  211857. [device open: &err];
  211858. if (err == 0)
  211859. {
  211860. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211861. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211862. [session addInput: input error: &err];
  211863. if (err == 0)
  211864. {
  211865. resetFile();
  211866. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211867. [imageOutput setDelegate: callbackDelegate];
  211868. if (err == 0)
  211869. {
  211870. [session startRunning];
  211871. return;
  211872. }
  211873. }
  211874. }
  211875. openingError = nsStringToJuce ([err description]);
  211876. DBG (openingError);
  211877. }
  211878. ~QTCameraDeviceInteral()
  211879. {
  211880. [session stopRunning];
  211881. [session removeOutput: imageOutput];
  211882. [session release];
  211883. [input release];
  211884. [device release];
  211885. [audioDevice release];
  211886. [audioInput release];
  211887. [fileOutput release];
  211888. [imageOutput release];
  211889. [callbackDelegate release];
  211890. }
  211891. void resetFile()
  211892. {
  211893. [fileOutput recordToOutputFileURL: nil];
  211894. [session removeOutput: fileOutput];
  211895. [fileOutput release];
  211896. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211897. [session removeInput: audioInput];
  211898. [audioInput release];
  211899. audioInput = 0;
  211900. [audioDevice release];
  211901. audioDevice = 0;
  211902. [fileOutput setDelegate: callbackDelegate];
  211903. }
  211904. void addDefaultAudioInput()
  211905. {
  211906. NSError* err = nil;
  211907. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211908. if ([audioDevice open: &err])
  211909. [audioDevice retain];
  211910. else
  211911. audioDevice = nil;
  211912. if (audioDevice != 0)
  211913. {
  211914. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211915. [session addInput: audioInput error: &err];
  211916. }
  211917. }
  211918. void addListener (CameraImageListener* listenerToAdd)
  211919. {
  211920. const ScopedLock sl (listenerLock);
  211921. if (listeners.size() == 0)
  211922. [session addOutput: imageOutput error: nil];
  211923. listeners.addIfNotAlreadyThere (listenerToAdd);
  211924. }
  211925. void removeListener (CameraImageListener* listenerToRemove)
  211926. {
  211927. const ScopedLock sl (listenerLock);
  211928. listeners.removeValue (listenerToRemove);
  211929. if (listeners.size() == 0)
  211930. [session removeOutput: imageOutput];
  211931. }
  211932. void callListeners (CIImage* frame, int w, int h)
  211933. {
  211934. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211935. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211936. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211937. CGContextFlush (image.context);
  211938. const ScopedLock sl (listenerLock);
  211939. for (int i = listeners.size(); --i >= 0;)
  211940. {
  211941. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211942. if (l != 0)
  211943. l->imageReceived (image);
  211944. }
  211945. }
  211946. QTCaptureDevice* device;
  211947. QTCaptureDeviceInput* input;
  211948. QTCaptureDevice* audioDevice;
  211949. QTCaptureDeviceInput* audioInput;
  211950. QTCaptureSession* session;
  211951. QTCaptureMovieFileOutput* fileOutput;
  211952. QTCaptureDecompressedVideoOutput* imageOutput;
  211953. QTCaptureCallbackDelegate* callbackDelegate;
  211954. String openingError;
  211955. VoidArray listeners;
  211956. CriticalSection listenerLock;
  211957. };
  211958. END_JUCE_NAMESPACE
  211959. @implementation QTCaptureCallbackDelegate
  211960. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  211961. internalDev: (QTCameraDeviceInteral*) d
  211962. {
  211963. [super init];
  211964. owner = owner_;
  211965. internal = d;
  211966. firstPresentationTime = 0;
  211967. averageTimeOffset = 0;
  211968. return self;
  211969. }
  211970. - (void) dealloc
  211971. {
  211972. [super dealloc];
  211973. }
  211974. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211975. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211976. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211977. fromConnection: (QTCaptureConnection*) connection
  211978. {
  211979. if (internal->listeners.size() > 0)
  211980. {
  211981. const ScopedAutoReleasePool pool;
  211982. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  211983. CVPixelBufferGetWidth (videoFrame),
  211984. CVPixelBufferGetHeight (videoFrame));
  211985. }
  211986. }
  211987. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211988. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211989. fromConnection: (QTCaptureConnection*) connection
  211990. {
  211991. const Time now (Time::getCurrentTime());
  211992. int64 presentationTime = ([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale;
  211993. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  211994. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  211995. #else
  211996. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  211997. #endif
  211998. if (hosttime != nil)
  211999. presentationTime = (int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000;
  212000. const int64 timeDiff = now.toMilliseconds() - presentationTime - 50;
  212001. if (firstPresentationTime == 0)
  212002. {
  212003. firstPresentationTime = presentationTime;
  212004. averageTimeOffset = timeDiff;
  212005. }
  212006. else
  212007. {
  212008. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212009. }
  212010. }
  212011. @end
  212012. BEGIN_JUCE_NAMESPACE
  212013. class QTCaptureViewerComp : public NSViewComponent
  212014. {
  212015. public:
  212016. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212017. {
  212018. const ScopedAutoReleasePool pool;
  212019. captureView = [[QTCaptureView alloc] init];
  212020. [captureView setCaptureSession: internal->session];
  212021. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212022. setView (captureView);
  212023. }
  212024. ~QTCaptureViewerComp()
  212025. {
  212026. setView (0);
  212027. [captureView setCaptureSession: nil];
  212028. [captureView release];
  212029. }
  212030. QTCaptureView* captureView;
  212031. };
  212032. CameraDevice::CameraDevice (const String& name_, int index)
  212033. : name (name_)
  212034. {
  212035. isRecording = false;
  212036. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  212037. internal = d;
  212038. }
  212039. CameraDevice::~CameraDevice()
  212040. {
  212041. stopRecording();
  212042. delete (QTCameraDeviceInteral*) internal;
  212043. internal = 0;
  212044. }
  212045. Component* CameraDevice::createViewerComponent()
  212046. {
  212047. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  212048. }
  212049. const String CameraDevice::getFileExtension()
  212050. {
  212051. return ".mov";
  212052. }
  212053. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212054. {
  212055. stopRecording();
  212056. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212057. d->callbackDelegate->firstPresentationTime = 0;
  212058. file.deleteFile();
  212059. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212060. // out wrong, so we'll put some audio in there too..,
  212061. d->addDefaultAudioInput();
  212062. [d->session addOutput: d->fileOutput error: nil];
  212063. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212064. for (;;)
  212065. {
  212066. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212067. if (connection == 0)
  212068. break;
  212069. QTCompressionOptions* options = 0;
  212070. NSString* mediaType = [connection mediaType];
  212071. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212072. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212073. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212074. : @"QTCompressionOptions240SizeH264Video"];
  212075. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212076. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212077. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212078. }
  212079. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212080. isRecording = true;
  212081. }
  212082. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212083. {
  212084. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212085. if (d->callbackDelegate->firstPresentationTime != 0)
  212086. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212087. return Time();
  212088. }
  212089. void CameraDevice::stopRecording()
  212090. {
  212091. if (isRecording)
  212092. {
  212093. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212094. d->resetFile();
  212095. isRecording = false;
  212096. }
  212097. }
  212098. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212099. {
  212100. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212101. if (listenerToAdd != 0)
  212102. d->addListener (listenerToAdd);
  212103. }
  212104. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212105. {
  212106. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212107. if (listenerToRemove != 0)
  212108. d->removeListener (listenerToRemove);
  212109. }
  212110. const StringArray CameraDevice::getAvailableDevices()
  212111. {
  212112. const ScopedAutoReleasePool pool;
  212113. StringArray results;
  212114. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212115. for (int i = 0; i < (int) [devs count]; ++i)
  212116. {
  212117. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212118. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212119. }
  212120. return results;
  212121. }
  212122. CameraDevice* CameraDevice::openDevice (int index,
  212123. int minWidth, int minHeight,
  212124. int maxWidth, int maxHeight)
  212125. {
  212126. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212127. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  212128. return d.release();
  212129. return 0;
  212130. }
  212131. #endif
  212132. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212133. #endif
  212134. #endif
  212135. END_JUCE_NAMESPACE
  212136. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212137. #endif
  212138. #endif